From a71541bb870cbc4e7db85dcc1bb35d02b097e385 Mon Sep 17 00:00:00 2001 From: anders_k Date: Sat, 22 Oct 2016 18:12:28 +0000 Subject: [PATCH] Added SetCtlColors Windows COLOR_* constants support git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6795 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Modern UI 2/Interface.nsh | 8 +-- Docs/src/history.but | 4 +- Docs/src/ui.but | 17 ++++-- Source/script.cpp | 92 ++++++++++++++++--------------- 4 files changed, 65 insertions(+), 56 deletions(-) diff --git a/Contrib/Modern UI 2/Interface.nsh b/Contrib/Modern UI 2/Interface.nsh index 83e6f50c..4333e783 100644 --- a/Contrib/Modern UI 2/Interface.nsh +++ b/Contrib/Modern UI 2/Interface.nsh @@ -237,7 +237,7 @@ Var mui.Button.Back GetDlgItem $mui.Header.Text $HWNDPARENT 1037 CreateFont $mui.Header.Text.Font "$(^Font)" "$(^FontSize)" "700" SendMessage $mui.Header.Text ${WM_SETFONT} $mui.Header.Text.Font 0 - + GetDlgItem $mui.Header.SubText $HWNDPARENT 1038 !ifndef MUI_HEADER_TRANSPARENT_TEXT @@ -247,7 +247,7 @@ Var mui.Button.Back SetCtlColors $mui.Header.Text "" "transparent" SetCtlColors $mui.Header.SubText "" "transparent" !endif - + ;Header image !insertmacro MUI_HEADERIMAGE_INIT "${UNINSTALLER}" 1046 @@ -267,11 +267,11 @@ Var mui.Button.Back GetDlgItem $mui.Branding.Text $HWNDPARENT 1256 SetCtlColors $mui.Branding.Text /BRANDING SendMessage $mui.Branding.Text ${WM_SETTEXT} 0 "STR:$(^Branding) " - + ;Lines GetDlgItem $mui.Line.Standard $HWNDPARENT 1035 GetDlgItem $mui.Line.FullWindow $HWNDPARENT 1045 - + ;Buttons GetDlgItem $mui.Button.Next $HWNDPARENT 1 GetDlgItem $mui.Button.Cancel $HWNDPARENT 2 diff --git a/Docs/src/history.but b/Docs/src/history.but index 14dbeb9f..81d8f625 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -8,6 +8,8 @@ Released on ? ?th, 201? \S2{} Minor Changes +\b SetCtlColors now supports Windows color constants + \b Fixed buffer size bug in winchar.cpp (\W{http://sf.net/p/nsis/patches/271}{patch #271}) \S2{} Translations @@ -3223,7 +3225,7 @@ Released on December 6th, 2002 \b !ifdef and friends can now be used in macros -\b \R{sendmessage}{SendMessage} can send strings (put STR: before a param) and supports timeouts +\b \R{sendmessage}{SendMessage} can send strings (put cw{STR:} before a param) and supports timeouts \b Right mouse button "Copy to clipboard" context menu for the Details window diff --git a/Docs/src/ui.but b/Docs/src/ui.but index 826b71e9..21f077ac 100644 --- a/Docs/src/ui.but +++ b/Docs/src/ui.but @@ -120,16 +120,21 @@ Sets mode at which commands print their status. None has commands be quiet, list \S2{setctlcolors} SetCtlColors -\c hwnd [/BRANDING] [text_color] [transparent|bg_color] +\c hwnd [/BRANDING] [text_color|SYSCLR:text_color_id] [transparent|bg_color|SYSCLR:bg_color_id] -Sets the text and background color of a static control, edit control, button or a dialog. \e{text_color} and \e{bg_color} don't accept variables. Use \R{getdlgitem}{GetDlgItem} to get the handle (HWND) of the control. To make the control transparent specify "transparent" as the background color value. You can also specify /BRANDING with or without text color and background color to make the control completely gray (or any other color you choose). This is used by the branding text control in the MUI. +Sets the text and background color of a static control, edit control, button or a dialog. \e{text_color} and \e{bg_color} don't accept variables. Use \R{getdlgitem}{GetDlgItem} to get the handle (HWND) of the control. To make the control transparent specify \c{transparent} as the background color value. Prefix the color value with \cw{SYSCLR:} to specify a Windows \cw{COLOR_*} constant. You can also specify \cw{/BRANDING} with or without text color and background color to make the control completely gray (or any other color you choose). This is used by the branding text control in the MUI. -\c FindWindow $0 "#32770" "" $HWNDPARENT -\c GetDlgItem $0 $0 1006 -\c SetCtlColors $0 0xFF0000 0x00FF00 +\c Page Components "" CmpntPageShow +\c Function CmpntPageShow +\c FindWindow $1 "#32770" "" $HWNDPARENT +\c GetDlgItem $0 $1 1006 +\c SetCtlColors $0 0xFF0000 0x00FF00 ; Red on Green +\c GetDlgItem $0 $1 1022 +\c SetCtlColors $0 SYSCLR:23 SYSCLR:24 +\c FunctionEnd \NsisWarnBlockContainerBegin -\\Warning:\\ Setting the background color of check boxes to "transparent" may not function properly when using \c{\R{axpstyle}{XPStyle} on}. The background may be completely black, instead of transparent, when using certain Windows themes. +\\Warning:\\ Setting the background color of check boxes to \c{transparent} may not function properly when using \c{\R{axpstyle}{XPStyle} on}. The background may be completely black instead of transparent when using certain Windows themes. \NsisWarnBlockContainerEnd \S2{setsilent} SetSilent diff --git a/Source/script.cpp b/Source/script.cpp index ed8dda04..34b56033 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -77,6 +77,36 @@ static UINT read_line_helper(NStreamLineReader&lr, TCHAR*buf, UINT cch) return ++cch - eof; } +#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT +static bool LookupWinSysColorId(const TCHAR*Str, UINT&Clr) +{ + static const struct { const TCHAR*Name; UINT Id; } map[] = { // Note: This list is incomplete. + { TEXT("WINDOW"), 5 }, { TEXT("WINDOWTEXT"), 8 }, + { TEXT("3DFACE"), 15 }, { TEXT("BTNTEXT"), 18 }, // "Three-dimensional display elements and dialog box" + { TEXT("HIGHLIGHT"), 13 }, { TEXT("HIGHLIGHTTEXT"), 14 }, // "Item(s) selected in a control" + { TEXT("GRAYTEXT"), 17 }, // "Grayed (disabled) text" + { TEXT("HOTLIGHT"), 26 }, // "Color for a hyperlink or hot-tracked item" (Win98+) + }; + for (UINT i = 0; i < COUNTOF(map); ++i) + if (!_tcsicmp(map[i].Name, Str)) return (Clr = map[i].Id, true); + return false; +} +static UINT ParseCtlColor(const TCHAR*Str, int&CCFlags, int CCFlagmask) +{ + UINT clr, v; + TCHAR buf[7+!0], *pEnd; + my_strncpy(buf, Str, 7+!0), buf[7] = '\0'; + if (!_tcscmp(_T("SYSCLR:"), buf)) + { + CCFlags |= ((CC_TEXT_SYS|CC_BK_SYS) & CCFlagmask); // ExeHead must call GetSysColor + if (!LookupWinSysColorId(Str+7, clr)) clr = _tcstoul(Str+7, &pEnd, 0); + } + else + v = _tcstoul(Str, &pEnd, 16), clr = ((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); + return clr; +} +#endif + #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 TCHAR *CEXEBuild::set_file_predefine(const TCHAR *filename) @@ -4458,69 +4488,41 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ent.which=EW_SETCTLCOLORS; ent.offsets[0]=add_string(line.gettoken_str(1)); ctlcolors c={0, }; - int a = 2; - if (!_tcsicmp(line.gettoken_str(2),_T("/BRANDING"))) - a++; - TCHAR *p; - if (a == 2 && line.getnumtokens() == 5) { + int a = 2, ctok = line.getnumtokens(); + if (!_tcsicmp(line.gettoken_str(2),_T("/BRANDING"))) a+=1; + if (!_tcsicmp(line.gettoken_str(2),_T("/RESET"))) { if (ctok != 3) return PS_ERROR; else a+=2; } + if (a == 2 && ctok == 5) { ERROR_MSG(_T("Error: SetCtlColors expected 3 parameters, got 4\n")); return PS_ERROR; } - if (!_tcsicmp(line.gettoken_str(a+1),_T("transparent"))) { - c.flags|=CC_BKB; - c.lbStyle=BS_NULL; - c.bkmode=TRANSPARENT; + c.flags|=CC_BKB, c.lbStyle=BS_NULL, c.bkmode=TRANSPARENT; } - else { - p=line.gettoken_str(a+1); - if (*p) { - int v=_tcstoul(p,&p,16); - c.bkc=((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); - c.flags|=CC_BK|CC_BKB; - } - c.lbStyle=BS_SOLID; - c.bkmode=OPAQUE; + else { // Parse background color + c.lbStyle=BS_SOLID, c.bkmode=OPAQUE; + if (*(p=line.gettoken_str(a+1))) + c.flags|=CC_BK|CC_BKB, c.bkc=ParseCtlColor(p, c.flags, CC_BK_SYS); } - - p=line.gettoken_str(a); - if (*p) { - int v=_tcstoul(p,&p,16); - c.text=((v&0xff)<<16)|(v&0xff00)|((v&0xff0000)>>16); - c.flags|=CC_TEXT; - } - - if (a == 3) - { + if (*(p=line.gettoken_str(a))) // Set text color? + c.flags|=CC_TEXT, c.text=ParseCtlColor(p, c.flags, CC_TEXT_SYS); + if (a == 3) { // Handle /BRANDING c.flags|=CC_BK|CC_BKB; c.lbStyle=BS_NULL; - if (!*line.gettoken_str(a+1)) - { - c.bkc=COLOR_BTNFACE; - c.flags|=CC_BK_SYS; - } + if (!*line.gettoken_str(a+1)) c.bkc=COLOR_BTNFACE, c.flags|=CC_BK_SYS; c.flags|=CC_TEXT; - if (!*line.gettoken_str(a)) - { - c.text=COLOR_BTNFACE; - c.flags|=CC_TEXT_SYS; - } + if (!*line.gettoken_str(a)) c.text=COLOR_BTNFACE, c.flags|=CC_TEXT_SYS; c.bkmode=OPAQUE; } - + if (a == 4) c.bkmode=OPAQUE, c.flags=0, c.bkb = 0; // Experimental and undocumented /RESET, a formal way of doing SetCtlColors $hCtl "" "" assert(sizeof(ctlcolors64) > sizeof(ctlcolors)); int i, l=cur_ctlcolors->getlen()/sizeof(ctlcolors), pad=is_target_64bit()?sizeof(ctlcolors64)-sizeof(ctlcolors):0; - for (i=0; iget()+i,&c,sizeof(ctlcolors))) { ent.offsets[1]=i*(sizeof(ctlcolors)+pad); break; } - } - if (i>=l) { - ent.offsets[1]=cur_ctlcolors->add(&c,sizeof(ctlcolors))+(l*pad); - } - + if (i>=l) ent.offsets[1]=cur_ctlcolors->add(&c,sizeof(ctlcolors))+(l*pad); SCRIPT_MSG(_T("SetCtlColors: hwnd=%") NPRIs _T(" %") NPRIs _T("text=%") NPRIs _T(" background=%") NPRIs _T("\n"),line.gettoken_str(1),a==2?_T(""):_T("/BRANDING "),line.gettoken_str(a),line.gettoken_str(a+1)); } return add_entry(&ent);