diff options
author | csaba <csaba> | 2024-05-10 17:40:14 (GMT) |
---|---|---|
committer | csaba <csaba> | 2024-05-10 17:40:14 (GMT) |
commit | 011e9715c03060cc192949137206d00055032c33 (patch) | |
tree | 260468038dceedf3a70fe96674f913374b2059e2 | |
parent | dac0d44e8ac09f7ff824c1ff952201122b60245e (diff) | |
download | tk-011e9715c03060cc192949137206d00055032c33.zip tk-011e9715c03060cc192949137206d00055032c33.tar.gz tk-011e9715c03060cc192949137206d00055032c33.tar.bz2 |
Backported most improvements related to the "classic" theme, submitted by Emiliano Gavilan.
-rw-r--r-- | generic/ttk/ttkClassicTheme.c | 61 | ||||
-rw-r--r-- | generic/ttk/ttkElements.c | 26 | ||||
-rw-r--r-- | generic/ttk/ttkEntry.c | 12 | ||||
-rw-r--r-- | library/ttk/classicTheme.tcl | 24 |
4 files changed, 89 insertions, 34 deletions
diff --git a/generic/ttk/ttkClassicTheme.c b/generic/ttk/ttkClassicTheme.c index 854ef78..279ac1a 100644 --- a/generic/ttk/ttkClassicTheme.c +++ b/generic/ttk/ttkClassicTheme.c @@ -19,6 +19,7 @@ typedef struct { Tcl_Obj *highlightColorObj; Tcl_Obj *highlightThicknessObj; + Tcl_Obj *defaultStateObj; } HighlightElement; static Ttk_ElementOptionSpec HighlightElementOptions[] = { @@ -26,6 +27,8 @@ static Ttk_ElementOptionSpec HighlightElementOptions[] = { Tk_Offset(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND }, { "-highlightthickness",TK_OPTION_PIXELS, Tk_Offset(HighlightElement,highlightThicknessObj), "0" }, + { "-default", TK_OPTION_ANY, + offsetof(HighlightElement,defaultStateObj), "disabled" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -40,7 +43,8 @@ static void HighlightElementSize( HighlightElement *hl = (HighlightElement *)elementRecord; int highlightThickness = 0; - Tk_GetPixelsFromObj(NULL, tkwin, hl->highlightThicknessObj, &highlightThickness); + Tk_GetPixelsFromObj(NULL, tkwin, hl->highlightThicknessObj, + &highlightThickness); *paddingPtr = Ttk_UniformPadding((short)highlightThickness); } @@ -55,11 +59,19 @@ static void HighlightElementDraw( HighlightElement *hl = (HighlightElement *)elementRecord; int highlightThickness = 0; XColor *highlightColor = Tk_GetColorFromObj(tkwin, hl->highlightColorObj); + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; - Tk_GetPixelsFromObj(NULL, tkwin, hl->highlightThicknessObj, &highlightThickness); + Tk_GetPixelsFromObj(NULL, tkwin, hl->highlightThicknessObj, + &highlightThickness); if (highlightColor && highlightThickness > 0) { + Ttk_GetButtonDefaultStateFromObj(NULL, hl->defaultStateObj, + (int *)&defaultState); GC gc = Tk_GCForColor(highlightColor, d); - Tk_DrawFocusHighlight(tkwin, gc, highlightThickness, d); + if (defaultState == TTK_BUTTON_DEFAULT_NORMAL) { + TkDrawInsetFocusHighlight(tkwin, gc, highlightThickness, d, 5); + } else { + Tk_DrawFocusHighlight(tkwin, gc, highlightThickness, d); + } } } @@ -471,17 +483,44 @@ TTK_LAYOUT("TEntry", TTK_GROUP("Entry.padding", TTK_FILL_BOTH, TTK_NODE("Entry.textarea", TTK_FILL_BOTH))))) -/* Notebook tabs -- omit focus ring */ -TTK_LAYOUT("Tab", - TTK_GROUP("Notebook.tab", TTK_FILL_BOTH, - TTK_GROUP("Notebook.padding", TTK_FILL_BOTH, - TTK_NODE("Notebook.label", TTK_FILL_BOTH)))) +/* "classic" combobox, includes highlight border */ +TTK_LAYOUT("TCombobox", + TTK_GROUP("Combobox.highlight", TTK_FILL_BOTH, + TTK_GROUP("Combobox.field", TTK_FILL_BOTH, + TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y) + TTK_GROUP("Combobox.padding", TTK_FILL_BOTH, + TTK_NODE("Combobox.textarea", TTK_FILL_BOTH))))) + +/* "classic" spinbox, includes highlight border */ +TTK_LAYOUT("TSpinbox", + TTK_GROUP("Spinbox.highlight", TTK_FILL_BOTH, + TTK_GROUP("Spinbox.field", TTK_FILL_BOTH|TTK_FILL_X, + TTK_GROUP("null", TTK_PACK_RIGHT, + TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP|TTK_STICK_E) + TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM|TTK_STICK_E)) + TTK_GROUP("Spinbox.padding", TTK_FILL_BOTH, + TTK_NODE("Spinbox.textarea", TTK_FILL_BOTH))))) + +/* "classic" scale, includes highlight border */ +TTK_LAYOUT("Vertical.TScale", + TTK_GROUP("Vertical.Scale.highlight", TTK_FILL_BOTH, + TTK_GROUP("Vertical.Scale.trough", TTK_FILL_BOTH, + TTK_NODE("Vertical.Scale.slider", TTK_PACK_TOP)))) + +TTK_LAYOUT("Horizontal.TScale", + TTK_GROUP("Horizontal.Scale.highlight", TTK_FILL_BOTH, + TTK_GROUP("Horizontal.Scale.trough", TTK_FILL_BOTH, + TTK_NODE("Horizontal.Scale.slider", TTK_PACK_LEFT)))) + +/* put highlight border around treeview */ +TTK_LAYOUT("Treeview", + TTK_GROUP("Treeview.highlight", TTK_FILL_BOTH, + TTK_GROUP("Treeview.field", TTK_FILL_BOTH|TTK_BORDER, + TTK_GROUP("Treeview.padding", TTK_FILL_BOTH, + TTK_NODE("Treeview.treearea", TTK_FILL_BOTH))))) TTK_END_LAYOUT_TABLE -/* POSSIBLY: include Scale layouts w/focus border - */ - /*------------------------------------------------------------------------ * TtkClassicTheme_Init -- * Install classic theme. diff --git a/generic/ttk/ttkElements.c b/generic/ttk/ttkElements.c index 19bd71a..126feb1 100644 --- a/generic/ttk/ttkElements.c +++ b/generic/ttk/ttkElements.c @@ -274,6 +274,7 @@ static Ttk_ElementSpec PaddingElementSpec = { typedef struct { Tcl_Obj *focusColorObj; Tcl_Obj *focusThicknessObj; + Tcl_Obj *focusSolidObj; } FocusElement; /* @@ -281,7 +282,8 @@ typedef struct { * Draw a dotted rectangle to indicate focus. */ static void DrawFocusRing( - Tk_Window tkwin, Drawable d, Tcl_Obj *colorObj, Ttk_Box b) + Tk_Window tkwin, Drawable d, Tcl_Obj *colorObj, int thickness, int solid, + Ttk_Box b) { XColor *color = Tk_GetColorFromObj(tkwin, colorObj); unsigned long mask = 0UL; @@ -289,11 +291,16 @@ static void DrawFocusRing( GC gc; gcvalues.foreground = color->pixel; - gcvalues.line_style = LineOnOffDash; - gcvalues.line_width = 1; - gcvalues.dashes = 1; - gcvalues.dash_offset = 1; - mask = GCForeground | GCLineStyle | GCDashList | GCDashOffset | GCLineWidth; + gcvalues.line_width = thickness < 1 ? 1 : thickness; + if (solid) { + gcvalues.line_style = LineSolid; + mask = GCForeground | GCLineStyle | GCLineWidth; + } else { + gcvalues.line_style = LineOnOffDash; + gcvalues.dashes = 1; + gcvalues.dash_offset = 1; + mask = GCForeground | GCLineStyle | GCDashList | GCDashOffset | GCLineWidth; + } gc = Tk_GetGC(tkwin, mask, &gcvalues); XDrawRectangle(Tk_Display(tkwin), d, gc, b.x, b.y, b.width-1, b.height-1); @@ -305,6 +312,8 @@ static Ttk_ElementOptionSpec FocusElementOptions[] = { Tk_Offset(FocusElement,focusColorObj), "black" }, { "-focusthickness",TK_OPTION_PIXELS, Tk_Offset(FocusElement,focusThicknessObj), "1" }, + { "-focussolid",TK_OPTION_BOOLEAN, + offsetof(FocusElement,focusSolidObj), "0" }, { NULL, 0, 0, NULL } }; @@ -325,10 +334,13 @@ static void FocusElementDraw( { FocusElement *focus = elementRecord; int focusThickness = 0; + int focusSolid = 0; if (state & TTK_STATE_FOCUS) { Tk_GetPixelsFromObj(NULL, tkwin, focus->focusThicknessObj, &focusThickness); - DrawFocusRing(tkwin, d, focus->focusColorObj, b); + Tcl_GetBooleanFromObj(NULL, focus->focusSolidObj, &focusSolid); + DrawFocusRing(tkwin, d, focus->focusColorObj, focusThickness, + focusSolid, b); } } diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index 85ec1da..4ff6716 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -2123,12 +2123,12 @@ TTK_BEGIN_LAYOUT(ComboboxLayout) TTK_END_LAYOUT TTK_BEGIN_LAYOUT(SpinboxLayout) - TTK_GROUP("Spinbox.field", TTK_PACK_TOP|TTK_FILL_X, - TTK_GROUP("null", TTK_PACK_RIGHT, - TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP|TTK_STICK_E) - TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM|TTK_STICK_E)) - TTK_GROUP("Spinbox.padding", TTK_FILL_BOTH, - TTK_NODE("Spinbox.textarea", TTK_FILL_BOTH))) + TTK_GROUP("Spinbox.field", TTK_PACK_TOP|TTK_FILL_X, + TTK_GROUP("null", TTK_PACK_RIGHT, + TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP|TTK_STICK_E) + TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM|TTK_STICK_E)) + TTK_GROUP("Spinbox.padding", TTK_FILL_BOTH, + TTK_NODE("Spinbox.textarea", TTK_FILL_BOTH))) TTK_END_LAYOUT /*------------------------------------------------------------------------ diff --git a/library/ttk/classicTheme.tcl b/library/ttk/classicTheme.tcl index f237fba..2fcfd57 100644 --- a/library/ttk/classicTheme.tcl +++ b/library/ttk/classicTheme.tcl @@ -6,11 +6,12 @@ namespace eval ttk::theme::classic { - variable colors; array set colors { + variable colors + array set colors { -frame "#d9d9d9" -window "#ffffff" -activebg "#ececec" - -troughbg "#c3c3c3" + -troughbg "#b3b3b3" -selectbg "#c3c3c3" -selectfg "#000000" -disabledfg "#a3a3a3" @@ -31,7 +32,7 @@ namespace eval ttk::theme::classic { -highlightthickness 1 \ -selectborderwidth 1 \ -insertwidth 2 \ - ; + -borderwidth 1 # To match pre-Xft X11 appearance, use: # ttk::style configure . -font {Helvetica 12 bold} @@ -53,8 +54,7 @@ namespace eval ttk::theme::classic { pressed $colors(-frame) \ alternate $colors(-altindicator) \ selected $colors(-indicator)] \ - -indicatorrelief {alternate raised selected sunken pressed sunken} \ - ; + -indicatorrelief {alternate raised selected sunken pressed sunken} ttk::style configure TRadiobutton -indicatorrelief raised ttk::style map TRadiobutton \ @@ -62,27 +62,30 @@ namespace eval ttk::theme::classic { pressed $colors(-frame) \ alternate $colors(-altindicator) \ selected $colors(-indicator)] \ - -indicatorrelief {alternate raised selected sunken pressed sunken} \ - ; + -indicatorrelief {alternate raised selected sunken pressed sunken} ttk::style configure TMenubutton -relief raised -padding "3m 1m" ttk::style configure TEntry -relief sunken -padding 1 -font TkTextFont ttk::style map TEntry -fieldbackground \ [list readonly $colors(-frame) disabled $colors(-frame)] - ttk::style configure TCombobox -padding 1 + + ttk::style element create Combobox.downarrow from default + ttk::style configure TCombobox -padding 1 -arrowsize 12 ttk::style map TCombobox -fieldbackground \ [list readonly $colors(-frame) disabled $colors(-frame)] ttk::style configure ComboboxPopdownFrame \ -relief solid -borderwidth 1 + ttk::style element create Spinbox.uparrow from default + ttk::style element create Spinbox.downarrow from default ttk::style configure TSpinbox -arrowsize 10 -padding {2 0 10 0} ttk::style map TSpinbox -fieldbackground \ [list readonly $colors(-frame) disabled $colors(-frame)] ttk::style configure TLabelframe -borderwidth 2 -relief groove - ttk::style configure TScrollbar -relief raised + ttk::style configure TScrollbar -relief raised -arrowsize 12 -width 12 ttk::style map TScrollbar -relief {{pressed !disabled} sunken} ttk::style configure TScale -sliderrelief raised @@ -91,7 +94,8 @@ namespace eval ttk::theme::classic { ttk::style configure TProgressbar -background SteelBlue ttk::style configure TNotebook.Tab \ -padding {3m 1m} \ - -background $colors(-troughbg) + -background $colors(-troughbg) \ + -focussolid 1 ttk::style map TNotebook.Tab -background [list selected $colors(-frame)] # Treeview: |