From f30fccea2dea24ae6c8a5c323532347d1d544ba7 Mon Sep 17 00:00:00 2001 From: csaba Date: Thu, 9 May 2024 18:39:12 +0000 Subject: Improvements related to the "classic" theme, submitted by Emiliano Gavilan (see ticket [aa2dd4c16d]). --- generic/ttk/ttkClassicTheme.c | 58 +++++++++++++++++++++++++++++++++++-------- generic/ttk/ttkElements.c | 26 +++++++++++++------ library/ttk/classicTheme.tcl | 25 +++++++++++-------- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/generic/ttk/ttkClassicTheme.c b/generic/ttk/ttkClassicTheme.c index 4d42448..cff6aca 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 const Ttk_ElementOptionSpec HighlightElementOptions[] = { @@ -26,6 +27,8 @@ static const Ttk_ElementOptionSpec HighlightElementOptions[] = { offsetof(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND }, { "-highlightthickness",TK_OPTION_PIXELS, offsetof(HighlightElement,highlightThicknessObj), "0" }, + { "-default", TK_OPTION_ANY, + offsetof(HighlightElement,defaultStateObj), "disabled" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -54,12 +57,18 @@ static void HighlightElementDraw( { HighlightElement *hl = (HighlightElement *)elementRecord; int highlightThickness = 0; + Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED; XColor *highlightColor = Tk_GetColorFromObj(tkwin, hl->highlightColorObj); Tcl_GetIntFromObj(NULL,hl->highlightThicknessObj,&highlightThickness); if (highlightColor && highlightThickness > 0) { + Ttk_GetButtonDefaultStateFromObj(NULL, hl->defaultStateObj, &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); + } } } @@ -615,8 +624,10 @@ static void SliderElementDraw( border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj); Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient); - Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth); Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief); +#if 0 + Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth); +#endif Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height, @@ -826,17 +837,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 3791f87..d75bbe4 100644 --- a/generic/ttk/ttkElements.c +++ b/generic/ttk/ttkElements.c @@ -359,6 +359,7 @@ static const Ttk_ElementSpec PaddingElementSpec = { typedef struct { Tcl_Obj *focusColorObj; Tcl_Obj *focusThicknessObj; + Tcl_Obj *focusSolidObj; } FocusElement; /* @@ -366,7 +367,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; @@ -374,11 +376,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); @@ -390,6 +397,8 @@ static const Ttk_ElementOptionSpec FocusElementOptions[] = { offsetof(FocusElement,focusColorObj), "black" }, { "-focusthickness",TK_OPTION_PIXELS, offsetof(FocusElement,focusThicknessObj), "1" }, + { "-focussolid",TK_OPTION_BOOLEAN, + offsetof(FocusElement,focusSolidObj), "0" }, { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; @@ -418,10 +427,13 @@ static void FocusElementDraw( { FocusElement *focus = (FocusElement *)elementRecord; int focusThickness = 0; + int focusSolid = 0; if (state & TTK_STATE_FOCUS) { Tcl_GetIntFromObj(NULL,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/library/ttk/classicTheme.tcl b/library/ttk/classicTheme.tcl index 30c6c8b..9477a24 100644 --- a/library/ttk/classicTheme.tcl +++ b/library/ttk/classicTheme.tcl @@ -12,7 +12,7 @@ namespace eval ttk::theme::classic { -window "#ffffff" -alternate "#f0f0f0" -activebg "#ececec" - -troughbg "#c3c3c3" + -troughbg "#b3b3b3" -selectbg "#c3c3c3" -selectfg "#000000" -disabledfg "#a3a3a3" @@ -32,7 +32,9 @@ namespace eval ttk::theme::classic { -highlightcolor $colors(-frame) \ -highlightthickness 1 \ -selectborderwidth 1 \ - -insertwidth 2 + -insertwidth 2 \ + -borderwidth 1 \ + -focuswidth 0 # To match pre-Xft X11 appearance, use: # ttk::style configure . -font {Helvetica 12 bold} @@ -49,7 +51,7 @@ namespace eval ttk::theme::classic { ttk::style map TButton -relief {{!disabled pressed} sunken} ttk::style configure TCheckbutton -indicatorrelief raised \ - -indicatormargin {0 1.5p 3p 1.5p} + -indicatormargin {0 1.5p 3p 1.5p} -borderwidth 1 ttk::style map TCheckbutton \ -indicatorcolor [list \ pressed $colors(-frame) \ @@ -58,7 +60,7 @@ namespace eval ttk::theme::classic { -indicatorrelief {alternate raised selected sunken pressed sunken} ttk::style configure TRadiobutton -indicatorrelief raised \ - -indicatormargin {0 1.5p 3p 1.5p} + -indicatormargin {0 1.5p 3p 1.5p} -borderwidth 1 ttk::style map TRadiobutton \ -indicatorcolor [list \ pressed $colors(-frame) \ @@ -73,32 +75,35 @@ namespace eval ttk::theme::classic { ttk::style map TEntry -fieldbackground \ [list readonly $colors(-frame) disabled $colors(-frame)] - ttk::style configure TCombobox -padding 1 -arrowsize 11.75p + ttk::style element create Combobox.downarrow from default + ttk::style configure TCombobox -padding 1 -arrowsize 9p 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 7.5p -padding {1.5p 0 7.5p 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 \ - -arrowsize 11.25p -width 11.25p -troughborderwidth 2 + ttk::style configure TScrollbar -relief raised -arrowsize 9p -width 9p ttk::style map TScrollbar -relief {{pressed !disabled} sunken} ttk::style configure TScale -sliderrelief raised \ - -sliderlength 22.5p -sliderthickness 11.25p -troughborderwidth 2 + -sliderlength 22.5p -sliderthickness 11.25p ttk::style map TScale -sliderrelief {{pressed !disabled} sunken} ttk::style configure TProgressbar -background SteelBlue \ - -barsize 22.5p -thickness 11.25p -troughborderwidth 2 + -barsize 22.5p -thickness 11.25p 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: -- cgit v0.12