AddBrandingImage now supports dialog units, even on POSIX

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7033 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2018-11-01 21:20:53 +00:00
parent 993b491786
commit 48703ab513
6 changed files with 45 additions and 30 deletions

View file

@ -10,13 +10,13 @@ The commands below all adjust attributes of the installer. These attributes cont
\c (left|right|top|bottom) (width|height) [padding] \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 left 100
\c AddBrandingImage right 50 \c AddBrandingImage right 50
\c AddBrandingImage top 20 \c AddBrandingImage top 20u 3u
\c AddBrandingImage bottom 35 \c AddBrandingImage bottom 35
\c AddBrandingImage left 100 5 \c AddBrandingImage left 100 5

View file

@ -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 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 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 \S2{} Translations
\b Added Hind\u012b{i} (\W{http://sf.net/p/nsis/patches/289}{patch #289}) \b Added Hind\u012b{i} (\W{http://sf.net/p/nsis/patches/289}{patch #289})

View file

@ -29,7 +29,7 @@ XPStyle on
; It is not enough to just add the placeholder, we must set the image too... ; 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 will later set the image in every pre-page function.
; We can also set just one persistent image in .onGUIInit ; We can also set just one persistent image in .onGUIInit
AddBrandingImage left 100 AddBrandingImage left 100u
; Sets the font of the installer ; Sets the font of the installer
SetFont "Comic Sans MS" 8 SetFont "Comic Sans MS" 8

View file

@ -147,8 +147,7 @@ if 'msvc' in defenv['TOOLS'] or 'mstoolkit' in defenv['TOOLS']:
ignore_tests = 'none' ignore_tests = 'none'
else: else:
ignore_tests = ','.join(Split(""" ignore_tests = ','.join(Split("""
Examples/makensis.nsi Examples/makensis.nsi"""))
Examples/gfx.nsi"""))
# version # version
opts.Add(('VERSION', 'Version of NSIS', cvs_version)) opts.Add(('VERSION', 'Version of NSIS', cvs_version))

View file

@ -124,6 +124,7 @@ public:
void MoveAll(short x, short y); void MoveAll(short x, short y);
void Resize(short x, short y); void Resize(short x, short y);
#ifdef _WIN32 #ifdef _WIN32
static inline bool SupportsDialogUnitComputation() { return true; }
void PixelsToDlgUnits(short& x, short& y); void PixelsToDlgUnits(short& x, short& y);
void PixelsToDlgUnits(SIZE& siz); void PixelsToDlgUnits(SIZE& siz);
void DlgUnitsToPixels(short& x, short& y); void DlgUnitsToPixels(short& x, short& y);
@ -131,6 +132,10 @@ public:
void RTrimToString(WORD id, TCHAR *str, int margins); void RTrimToString(WORD id, TCHAR *str, int margins);
void LTrimToString(WORD id, TCHAR *str, int margins); void LTrimToString(WORD id, TCHAR *str, int margins);
void CTrimToString(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 #endif
void ConvertToRTL(); void ConvertToRTL();
BYTE* Save(DWORD& dwSize); BYTE* Save(DWORD& dwSize);

View file

@ -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 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) ) #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 #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
static bool LookupWinSysColorId(const TCHAR*Str, UINT&Clr) static bool LookupWinSysColorId(const TCHAR*Str, UINT&Clr)
{ {
@ -2121,19 +2139,20 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
} }
return PS_OK; return PS_OK;
case TOK_ADDBRANDINGIMAGE: case TOK_ADDBRANDINGIMAGE:
#ifdef _WIN32
try { try {
int k=line.gettoken_enum(1,_T("top\0left\0bottom\0right\0")); LAYOUTUNIT whtype, padtype;
int wh=line.gettoken_int(2); 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(); if (k == -1) PRINTHELP();
int padding = 2; int padding = (line.getnumtokens() >= 4) ? ParseLayoutUnit(line.gettoken_str(3), padtype) : (padtype = whtype, defpadding);
if (line.getnumtokens() == 4) if (whtype == LU_INVALID || whtype != padtype)
padding = line.gettoken_int(3); throw runtime_error("Invalid number!");
init_res_editor(); init_res_editor();
BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG); BYTE* dlg = res_editor->GetResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG);
CDialogTemplate dt(dlg, build_unicode, uDefCodePage); CDialogTemplate dt(dlg, build_unicode, uDefCodePage);
res_editor->FreeResource(dlg); res_editor->FreeResource(dlg);
if (whtype != LU_DIALOG && !CDialogTemplate::SupportsDialogUnitComputation())
throw runtime_error("Must use dialog units on non-Win32 platforms!");
DialogItemTemplate brandingCtl = {0,}; DialogItemTemplate brandingCtl = {0,};
brandingCtl.dwStyle = SS_BITMAP | WS_CHILD | WS_VISIBLE; brandingCtl.dwStyle = SS_BITMAP | WS_CHILD | WS_VISIBLE;
@ -2142,32 +2161,25 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
brandingCtl.szTitle = NULL; brandingCtl.szTitle = NULL;
brandingCtl.wId = IDC_BRANDIMAGE; brandingCtl.wId = IDC_BRANDIMAGE;
brandingCtl.sHeight = brandingCtl.sWidth = wh; brandingCtl.sHeight = brandingCtl.sWidth = wh;
dt.PixelsToDlgUnits(brandingCtl.sWidth, brandingCtl.sHeight); if (whtype == LU_PIXEL) dt.PixelsToDlgUnits(brandingCtl.sWidth, brandingCtl.sHeight);
if (k%2) { if (k%2) { // left (1) / right (3)
// left (1) / right (3)
if (k & 2) // right if (k & 2) // right
brandingCtl.sX += dt.GetWidth(); brandingCtl.sX += dt.GetWidth();
else // left else // left
dt.MoveAll(brandingCtl.sWidth + (padding * 2), 0); dt.MoveAll(brandingCtl.sWidth + (padding * 2), 0);
dt.Resize(brandingCtl.sWidth + (padding * 2), 0); dt.Resize(brandingCtl.sWidth + (padding * 2), 0);
brandingCtl.sHeight = dt.GetHeight() - (padding * 2); brandingCtl.sHeight = dt.GetHeight() - (padding * 2);
} }
else { else { // top (0) / bottom (2)
// top (0) / bottom (2)
if (k & 2) // bottom if (k & 2) // bottom
brandingCtl.sY += dt.GetHeight(); brandingCtl.sY += dt.GetHeight();
else // top else // top
dt.MoveAll(0, brandingCtl.sHeight + (padding * 2)); dt.MoveAll(0, brandingCtl.sHeight + (padding * 2));
dt.Resize(0, brandingCtl.sHeight + (padding * 2)); dt.Resize(0, brandingCtl.sHeight + (padding * 2));
brandingCtl.sWidth = dt.GetWidth() - (padding * 2); brandingCtl.sWidth = dt.GetWidth() - (padding * 2);
} }
dt.AddItem(brandingCtl); dt.AddItem(brandingCtl);
DWORD dwDlgSize; 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); res_editor->UpdateResource(RT_DIALOG, IDD_INST, NSIS_DEFAULT_LANG, dlg, dwDlgSize);
dt.FreeSavedTemplate(dlg); dt.FreeSavedTemplate(dlg);
dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight); if (whtype == LU_PIXEL) dt.DlgUnitsToPixels(brandingCtl.sWidth, brandingCtl.sHeight);
SCRIPT_MSG(_T("AddBrandingImage: %") NPRIs _T(" %ux%u\n"), line.gettoken_str(1), 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_found = true;
branding_image_id = IDC_BRANDIMAGE; branding_image_id = IDC_BRANDIMAGE;
@ -2186,10 +2199,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_ERROR; return PS_ERROR;
} }
return PS_OK; return PS_OK;
#else
ERROR_MSG(_T("Error: AddBrandingImage is disabled for non Win32 platforms.\n"));
return PS_ERROR;
#endif //~ _WIN32
case TOK_SETFONT: case TOK_SETFONT:
{ {
unsigned char failed = 0; unsigned char failed = 0;