diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2011-03-22 20:51:18 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2011-03-22 20:51:18 (GMT) |
commit | 55784b18ea124c76cbfa25dd2540f403d6dc7307 (patch) | |
tree | 97fe2e57dc173312782e5051428b622fa5d47135 | |
parent | df466875b0f3eb256859b9029416cc17c6d5df1f (diff) | |
parent | f4f7b7eaba2b66b5890c3790e937ef806dfb2827 (diff) | |
download | tk-55784b18ea124c76cbfa25dd2540f403d6dc7307.zip tk-55784b18ea124c76cbfa25dd2540f403d6dc7307.tar.gz tk-55784b18ea124c76cbfa25dd2540f403d6dc7307.tar.bz2 |
[Bug 3000002]: enable use of system sizes for vsapi elements
Added additional flags to the vsapi element engine to enable specifying
the system metrics to use when calculating the size of certain elements.
This was being done already for the XP theme but the scripted definitions
using the vsapi engine for vista/win7 could not use such flags.
This fixes scrollbars not reflecting the users configured scrollbar size.
Reported-by: Mark Garvey <dunkfan@users.sourceforge.net>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
-rw-r--r-- | library/ttk/vistaTheme.tcl | 48 | ||||
-rw-r--r-- | win/ttkWinXPTheme.c | 72 |
2 files changed, 93 insertions, 27 deletions
diff --git a/library/ttk/vistaTheme.tcl b/library/ttk/vistaTheme.tcl index 811a1a4..99410cb 100644 --- a/library/ttk/vistaTheme.tcl +++ b/library/ttk/vistaTheme.tcl @@ -15,14 +15,6 @@ if {"vista" ni [ttk::style theme names]} { namespace eval ttk::theme::vista { ttk::style theme settings vista { - - # We should ask the system for these, but for now... - set SM { - SM_CXVSCROLL 17 SM_CYVSCROLL 0 - SM_CXHSCROLL 0 SM_CYHSCROLL 17 - } - set cx [expr {[dict get $SM SM_CXVSCROLL] / 2}] - set cy [expr {[dict get $SM SM_CYVSCROLL] / 2}] ttk::style configure . \ -background SystemButtonFace \ @@ -42,9 +34,9 @@ namespace eval ttk::theme::vista { ttk::style configure TMenubutton -padding {8 4} ttk::style element create Menubutton.dropdown vsapi \ - TOOLBAR 4 {{selected active} 6 {selected !active} 5 + TOOLBAR 4 {{selected active} 6 {selected !active} 5 disabled 4 pressed 3 active 2 {} 1} \ - -padding [list $cx $cy] + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style configure TNotebook -tabmargins {2 2 2 0} ttk::style map TNotebook.Tab \ @@ -59,7 +51,7 @@ namespace eval ttk::theme::vista { # Label and Toolbutton ttk::style configure TLabelframe.Label -foreground "#0046d5" - + ttk::style configure Toolbutton -padding {4 4} # Combobox @@ -70,7 +62,7 @@ namespace eval ttk::theme::vista { COMBOBOX 4 {disabled 4 focus 3 active 2 hover 2 {} 1} ttk::style element create Combobox.rightdownarrow vsapi \ COMBOBOX 6 {disabled 4 pressed 3 active 2 {} 1} \ - -padding [list $cx $cy] + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style layout TCombobox { Combobox.border -sticky nswe -border 0 -children { Combobox.rightdownarrow -side right -sticky ns @@ -120,20 +112,22 @@ namespace eval ttk::theme::vista { ; # Spinbox - ttk::style configure TSpinbox -padding 0 ;#{2 0 15 1} + ttk::style configure TSpinbox -padding 0 ttk::style element create Spinbox.field vsapi \ EDIT 9 {disabled 4 focus 3 hover 2 {} 1} -padding {1 1 1 2} ttk::style element create Spinbox.background vsapi \ EDIT 3 {disabled 3 readonly 3 focus 4 hover 2 {} 1} ttk::style element create Spinbox.innerbg vsapi \ EDIT 3 {disabled 3 readonly 3 focus 4 hover 2 {} 1}\ - -padding {2 0 15 1} + -padding {2 0 15 2} ttk::style element create Spinbox.uparrow vsapi \ SPIN 1 {disabled 4 pressed 3 active 2 {} 1} \ - -height 5 -width 8 + -padding 1 -halfheight 1 \ + -syssize { SM_CXVSCROLL SM_CYVSCROLL } ttk::style element create Spinbox.downarrow vsapi \ SPIN 2 {disabled 4 pressed 3 active 2 {} 1} \ - -height 5 -width 8 + -padding 1 -halfheight 1 \ + -syssize { SM_CXVSCROLL SM_CYVSCROLL } ttk::style layout TSpinbox { Spinbox.field -sticky nswe -children { Spinbox.background -sticky news -children { @@ -155,23 +149,30 @@ namespace eval ttk::theme::vista { # SCROLLBAR elements (Vista includes a state for 'hover') ttk::style element create Vertical.Scrollbar.uparrow vsapi \ - SCROLLBAR 1 {disabled 4 pressed 3 active 2 hover 17 {} 1} + SCROLLBAR 1 {disabled 4 pressed 3 active 2 hover 17 {} 1} \ + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style element create Vertical.Scrollbar.downarrow vsapi \ - SCROLLBAR 1 {disabled 8 pressed 7 active 6 hover 18 {} 5} + SCROLLBAR 1 {disabled 8 pressed 7 active 6 hover 18 {} 5} \ + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style element create Vertical.Scrollbar.trough vsapi \ SCROLLBAR 7 {disabled 4 pressed 3 active 2 hover 5 {} 1} ttk::style element create Vertical.Scrollbar.thumb vsapi \ - SCROLLBAR 3 {disabled 4 pressed 3 active 2 hover 5 {} 1} + SCROLLBAR 3 {disabled 4 pressed 3 active 2 hover 5 {} 1} \ + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style element create Vertical.Scrollbar.grip vsapi \ - SCROLLBAR 9 {disabled 4 pressed 3 active 2 hover 5 {} 1} + SCROLLBAR 9 {disabled 4 pressed 3 active 2 hover 5 {} 1} \ + -syssize {SM_CXVSCROLL SM_CYVSCROLL} ttk::style element create Horizontal.Scrollbar.leftarrow vsapi \ - SCROLLBAR 1 {disabled 12 pressed 11 active 10 hover 19 {} 9} + SCROLLBAR 1 {disabled 12 pressed 11 active 10 hover 19 {} 9} \ + -syssize {SM_CXHSCROLL SM_CYHSCROLL} ttk::style element create Horizontal.Scrollbar.rightarrow vsapi \ - SCROLLBAR 1 {disabled 16 pressed 15 active 14 hover 20 {} 13} + SCROLLBAR 1 {disabled 16 pressed 15 active 14 hover 20 {} 13} \ + -syssize {SM_CXHSCROLL SM_CYHSCROLL} ttk::style element create Horizontal.Scrollbar.trough vsapi \ SCROLLBAR 5 {disabled 4 pressed 3 active 2 hover 5 {} 1} ttk::style element create Horizontal.Scrollbar.thumb vsapi \ - SCROLLBAR 2 {disabled 4 pressed 3 active 2 hover 5 {} 1} + SCROLLBAR 2 {disabled 4 pressed 3 active 2 hover 5 {} 1} \ + -syssize {SM_CXHSCROLL SM_CYHSCROLL} ttk::style element create Horizontal.Scrollbar.grip vsapi \ SCROLLBAR 8 {disabled 4 pressed 3 active 2 hover 5 {} 1} @@ -218,7 +219,6 @@ namespace eval ttk::theme::vista { # Treeview ttk::style configure Item -padding {4 0 0 0} - unset -nocomplain cx cy package provide ttk::theme::vista 1.0 } } diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index ff97e38..de86fa0 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -386,6 +386,8 @@ typedef struct /* XP element specifications */ # define IGNORE_THEMESIZE 0x80000000 /* See NOTE-GetThemePartSize */ # define PAD_MARGINS 0x40000000 /* See NOTE-GetThemeMargins */ # define HEAP_ELEMENT 0x20000000 /* ElementInfo is on heap */ +# define HALF_HEIGHT 0x10000000 /* Used by GenericSizedElements */ +# define HALF_WIDTH 0x08000000 /* Used by GenericSizedElements */ } ElementInfo; typedef struct @@ -588,6 +590,10 @@ GenericSizedElementSize( (elementData->info->flags >> 8) & 0xff); *heightPtr = elementData->procs->GetThemeSysSize(NULL, elementData->info->flags & 0xff); + if (elementData->info->flags & HALF_HEIGHT) + *heightPtr /= 2; + if (elementData->info->flags & HALF_WIDTH) + *widthPtr /= 2; } static Ttk_ElementSpec GenericSizedElementSpec = { @@ -1035,6 +1041,42 @@ static ElementInfo ElementInfoTable[] = { }; #undef PAD + +static int +GetSysFlagFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr) +{ + static const char *names[] = { + "SM_CXBORDER", "SM_CYBORDER", "SM_CXVSCROLL", "SM_CYVSCROLL", + "SM_CXHSCROLL", "SM_CYHSCROLL", "SM_CXMENUCHECK", "SM_CYMENUCHECK", + "SM_CXMENUSIZE", "SM_CYMENUSIZE", "SM_CXSIZE", "SM_CYSIZE", "SM_CXSMSIZE", + "SM_CYSMSIZE" + }; + int flags[] = { + SM_CXBORDER, SM_CYBORDER, SM_CXVSCROLL, SM_CYVSCROLL, + SM_CXHSCROLL, SM_CYHSCROLL, SM_CXMENUCHECK, SM_CYMENUCHECK, + SM_CXMENUSIZE, SM_CYMENUSIZE, SM_CXSIZE, SM_CYSIZE, SM_CXSMSIZE, + SM_CYSMSIZE + }; + + Tcl_Obj **objv; + int i, objc; + + if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) + return TCL_ERROR; + if (objc != 2) { + Tcl_SetResult(interp, "wrong # args", TCL_STATIC); + return TCL_ERROR; + } + for (i = 0; i < objc; ++i) { + int option; + if (Tcl_GetIndexFromObj(interp, objv[i], names, "system constant", 0, &option) + != TCL_OK) + return TCL_ERROR; + *resultPtr |= (flags[option] << (8 * (1 - i))); + } + return TCL_OK; +} + /*---------------------------------------------------------------------- * Windows Visual Styles API Element Factory * @@ -1067,10 +1109,13 @@ Ttk_CreateVsapiElement( int length = 0; char *name; LPWSTR wname; + Ttk_ElementSpec *elementSpec = &GenericElementSpec; const char *optionStrings[] = - { "-padding","-width","-height","-margins",NULL }; - enum { O_PADDING, O_WIDTH, O_HEIGHT, O_MARGINS }; + { "-padding","-width","-height","-margins", "-syssize", + "-halfheight", "-halfwidth", NULL }; + enum { O_PADDING, O_WIDTH, O_HEIGHT, O_MARGINS, O_SYSSIZE, + O_HALFHEIGHT, O_HALFWIDTH }; if (objc < 2) { Tcl_AppendResult(interp, @@ -1122,6 +1167,27 @@ Ttk_CreateVsapiElement( pad.top = pad.bottom = tmp; flags |= IGNORE_THEMESIZE; break; + case O_SYSSIZE: + if (GetSysFlagFromObj(interp, objv[i+1], &tmp) != TCL_OK) { + return TCL_ERROR; + } + elementSpec = &GenericSizedElementSpec; + flags |= (tmp & 0xFFFF); + break; + case O_HALFHEIGHT: + if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) { + return TCL_ERROR; + } + if (tmp) + flags |= HALF_HEIGHT; + break; + case O_HALFWIDTH: + if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) { + return TCL_ERROR; + } + if (tmp) + flags |= HALF_WIDTH; + break; } } } @@ -1155,7 +1221,7 @@ Ttk_CreateVsapiElement( } elementPtr = ckalloc(sizeof(ElementInfo)); - elementPtr->elementSpec = &GenericElementSpec; + elementPtr->elementSpec = elementSpec; elementPtr->partId = partId; elementPtr->statemap = stateTable; elementPtr->padding = pad; |