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
This commit is contained in:
anders_k 2016-10-22 18:12:28 +00:00
parent 6fc995ed70
commit a71541bb87
4 changed files with 65 additions and 56 deletions

View file

@ -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

View file

@ -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
\\<b\\>Warning:\\</b\\> 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.
\\<b\\>Warning:\\</b\\> 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

View file

@ -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;
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);
}
c.lbStyle=BS_SOLID;
c.bkmode=OPAQUE;
}
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; i<l; i++) {
for (i=0; i<l; i++)
if (!memcmp((ctlcolors*)cur_ctlcolors->get()+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);