diff --git a/Docs/src/attributes.but b/Docs/src/attributes.but index 1c445f69..b100e9b1 100644 --- a/Docs/src/attributes.but +++ b/Docs/src/attributes.but @@ -10,13 +10,13 @@ The commands below all adjust attributes of the installer. These attributes cont \c (left|right|top|bottom) (width|height) [padding] -Adds a branding image on the top, bottom, left, or right of the installer. Its size will be set according to the width/height specified, the installer width/height and the installers font. The final size will not always be what you requested; have a look at the output of the command for the actual size. Because this depends on the installers font, you should use \R{asetfont}{SetFont} before \R{aaddbrandingimage}{AddBrandingImage}. The default padding value is 2. +Adds a branding image on the top, bottom, left, or right of the installer. Its size will be set according to the width/height specified, the installer width/height and the installers font. The final size will not always be what you requested; have a look at the output of the command for the actual size. Because this depends on the installers font, you should use \R{asetfont}{SetFont} before AddBrandingImage. The default padding value is 2. The numbers can be suffixed with \c{u} to specify dialog units instead of pixels. -\R{aaddbrandingimage}{AddBrandingImage} only adds a placeholder for an image. To set the image itself at runtime, use \R{setbrandingimage}{SetBrandingImage}. +AddBrandingImage only adds a placeholder for an image. To set the image itself at runtime, use \R{setbrandingimage}{SetBrandingImage}. \c AddBrandingImage left 100 \c AddBrandingImage right 50 -\c AddBrandingImage top 20 +\c AddBrandingImage top 20u 3u \c AddBrandingImage bottom 35 \c AddBrandingImage left 100 5 diff --git a/Docs/src/history.but b/Docs/src/history.but index ce7152d0..535b6726 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -20,10 +20,12 @@ Released on ??? ??th, 20?? \b Added NTMARTA to preload list to fix rare Windows 7 security issue (\W{http://sf.net/p/nsis/bugs/1204}{bug #1204}) -\b MakeNSIS prints -CMDHELP to stdout (\W{http://sf.net/p/nsis/bugs/1203}{bug #1203}) +\b AddBrandingImage now supports dialog units \b Fixed !macroundef of last defined macro bug +\b MakeNSIS prints -CMDHELP to stdout (\W{http://sf.net/p/nsis/bugs/1203}{bug #1203}) + \S2{} Translations \b Added Hind\u012b{i} (\W{http://sf.net/p/nsis/patches/289}{patch #289}) diff --git a/Examples/gfx.nsi b/Examples/gfx.nsi index 9514ed21..05af8529 100644 --- a/Examples/gfx.nsi +++ b/Examples/gfx.nsi @@ -29,7 +29,7 @@ XPStyle on ; It is not enough to just add the placeholder, we must set the image too... ; We will later set the image in every pre-page function. ; We can also set just one persistent image in .onGUIInit -AddBrandingImage left 100 +AddBrandingImage left 100u ; Sets the font of the installer SetFont "Comic Sans MS" 8 diff --git a/SConstruct b/SConstruct index c885d091..15402c38 100644 --- a/SConstruct +++ b/SConstruct @@ -147,8 +147,7 @@ if 'msvc' in defenv['TOOLS'] or 'mstoolkit' in defenv['TOOLS']: ignore_tests = 'none' else: ignore_tests = ','.join(Split(""" -Examples/makensis.nsi -Examples/gfx.nsi""")) +Examples/makensis.nsi""")) # version opts.Add(('VERSION', 'Version of NSIS', cvs_version)) diff --git a/Source/DialogTemplate.h b/Source/DialogTemplate.h index 8471ae16..17dc0bea 100644 --- a/Source/DialogTemplate.h +++ b/Source/DialogTemplate.h @@ -124,6 +124,7 @@ public: void MoveAll(short x, short y); void Resize(short x, short y); #ifdef _WIN32 + static inline bool SupportsDialogUnitComputation() { return true; } void PixelsToDlgUnits(short& x, short& y); void PixelsToDlgUnits(SIZE& siz); void DlgUnitsToPixels(short& x, short& y); @@ -131,6 +132,10 @@ public: void RTrimToString(WORD id, TCHAR *str, int margins); void LTrimToString(WORD id, TCHAR *str, int margins); void CTrimToString(WORD id, TCHAR *str, int margins); +#else + static inline bool SupportsDialogUnitComputation() { return false; } + inline void PixelsToDlgUnits(short& x, short& y) { assert(0); } + inline void DlgUnitsToPixels(short& x, short& y) { assert(0); } #endif void ConvertToRTL(); BYTE* Save(DWORD& dwSize); diff --git a/Source/script.cpp b/Source/script.cpp index bb7fe37c..c7628db5 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -50,6 +50,24 @@ using namespace std; #define REGROOTKEYTOINT(hk) ( (INT) (((INT_PTR)(hk)) & 0xffffffff) ) // Masking off non-existing top bits to make GCC happy #define REGROOTKEYTOINTEX(hk, removeviewbits) ( REGROOTKEYTOINT(hk) & ~(removeviewbits ? (REGROOTVIEW32|REGROOTVIEW64) : 0) ) +#ifdef NSIS_CONFIG_VISIBLE_SUPPORT +typedef enum { LU_INVALID = -1, LU_PIXEL = 0, LU_DIALOG } LAYOUTUNIT; +static int ParseLayoutUnit(const TCHAR*Str, LAYOUTUNIT&LU) +{ + TCHAR buf[200]; + int succ, val = LineParser::parse_int(Str, &succ); + if (succ) return (LU = LU_PIXEL, val); + size_t cch = my_strncpy(buf, Str, COUNTOF(buf)); + if (cch > 1 && S7IsChEqualI('u', buf[cch-1])) // Something with a 'u' suffix? + { + buf[cch-1] = _T('\0'); + val = LineParser::parse_int(buf, &succ); + if (succ) return (LU = LU_DIALOG, val); + } + return (LU = LU_INVALID, -1); +} +#endif + #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT static bool LookupWinSysColorId(const TCHAR*Str, UINT&Clr) { @@ -2121,19 +2139,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return PS_OK; case TOK_ADDBRANDINGIMAGE: -#ifdef _WIN32 try { - int k=line.gettoken_enum(1,_T("top\0left\0bottom\0right\0")); - int wh=line.gettoken_int(2); + LAYOUTUNIT whtype, padtype; + int k = line.gettoken_enum(1,_T("top\0left\0bottom\0right\0")), defpadding = 2; + int wh = ParseLayoutUnit(line.gettoken_str(2), whtype); if (k == -1) PRINTHELP(); - int padding = 2; - if (line.getnumtokens() == 4) - padding = line.gettoken_int(3); - + int padding = (line.getnumtokens() >= 4) ? ParseLayoutUnit(line.gettoken_str(3), padtype) : (padtype = whtype, defpadding); + if (whtype == LU_INVALID || whtype != padtype) + throw runtime_error("Invalid number!"); init_res_editor(); BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG); CDialogTemplate dt(dlg, build_unicode, uDefCodePage); res_editor->FreeResource(dlg); + if (whtype != LU_DIALOG && !CDialogTemplate::SupportsDialogUnitComputation()) + throw runtime_error("Must use dialog units on non-Win32 platforms!"); DialogItemTemplate brandingCtl = {0,}; brandingCtl.dwStyle = SS_BITMAP | WS_CHILD | WS_VISIBLE; @@ -2142,32 +2161,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) brandingCtl.szTitle = NULL; brandingCtl.wId = IDC_BRANDIMAGE; brandingCtl.sHeight = brandingCtl.sWidth = wh; - dt.PixelsToDlgUnits(brandingCtl.sWidth, brandingCtl.sHeight); - if (k%2) { - // left (1) / right (3) - + if (whtype == LU_PIXEL) dt.PixelsToDlgUnits(brandingCtl.sWidth, brandingCtl.sHeight); + if (k%2) { // left (1) / right (3) if (k & 2) // right brandingCtl.sX += dt.GetWidth(); else // left dt.MoveAll(brandingCtl.sWidth + (padding * 2), 0); dt.Resize(brandingCtl.sWidth + (padding * 2), 0); - brandingCtl.sHeight = dt.GetHeight() - (padding * 2); } - else { - // top (0) / bottom (2) - + else { // top (0) / bottom (2) if (k & 2) // bottom brandingCtl.sY += dt.GetHeight(); else // top dt.MoveAll(0, brandingCtl.sHeight + (padding * 2)); dt.Resize(0, brandingCtl.sHeight + (padding * 2)); - brandingCtl.sWidth = dt.GetWidth() - (padding * 2); } - dt.AddItem(brandingCtl); DWORD dwDlgSize; @@ -2175,8 +2187,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize); dt.FreeSavedTemplate(dlg); - dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight); - SCRIPT_MSG(_T("AddBrandingImage: %") NPRIs _T(" %ux%u\n"), line.gettoken_str(1), brandingCtl.sWidth, brandingCtl.sHeight); + if (whtype == LU_PIXEL) dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight); + const char* unitstr = whtype == LU_PIXEL ? "pixels" : "dialog units"; + SCRIPT_MSG(_T("AddBrandingImage: %") NPRIs _T(" %ux%u %") NPRIns _T("\n"), line.gettoken_str(1), brandingCtl.sWidth, brandingCtl.sHeight, unitstr); branding_image_found = true; branding_image_id = IDC_BRANDIMAGE; @@ -2186,10 +2199,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) return PS_ERROR; } return PS_OK; -#else - ERROR_MSG(_T("Error: AddBrandingImage is disabled for non Win32 platforms.\n")); - return PS_ERROR; -#endif //~ _WIN32 case TOK_SETFONT: { unsigned char failed = 0;