From 7c66a791c69ad49ed86c08fc6d247956ead72c40 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 12 Jun 2023 22:16:45 +0000 Subject: Better implementation of 'ttk::style configure . -insertofftime'. Cursor blinking times need to be adjusted only when the theme is changed, not each time WidgetWorldChanged() is called. --- generic/ttk/ttkBlink.c | 28 ++++++++++++++++++++++++---- generic/ttk/ttkWidget.c | 15 +-------------- generic/ttk/ttkWidget.h | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/generic/ttk/ttkBlink.c b/generic/ttk/ttkBlink.c index b1ba3f9..a7f81bf 100644 --- a/generic/ttk/ttkBlink.c +++ b/generic/ttk/ttkBlink.c @@ -10,12 +10,10 @@ * to display the cursor or not (e.g., readonly or disabled states); * TtkBlinkCursor() does not account for this. * - * TODO: - * Add script-level access to configure application-wide blink rate. */ #include "tkInt.h" -#include "ttkTheme.h" +#include "ttkThemeInt.h" #include "ttkWidget.h" #define DEF_CURSOR_ON_TIME 600 /* milliseconds */ @@ -154,7 +152,7 @@ CursorEventProc(ClientData clientData, XEvent *eventPtr) } } -void TtkSetBlinkOffTime(WidgetCore* corePtr, int offTime) +void TtkSetBlinkCursorOffTime(WidgetCore* corePtr, int offTime) { CursorManager* cm = GetCursorManager(corePtr->interp); @@ -162,6 +160,28 @@ void TtkSetBlinkOffTime(WidgetCore* corePtr, int offTime) } /* + * TtkAdjustBlinkCursor -- + * Set cursor blink off time from the -insertofftime value + * for the "." style. For instance to set blinking off: + * ttk::style configure . -insertofftime 0 + * + */ +void TtkBlinkCursorTimes(WidgetCore* corePtr) +{ + Ttk_Theme theme; + Ttk_Style style = NULL; + Tcl_Obj* result; + int offTime; + + theme = Ttk_GetCurrentTheme(corePtr->interp); + style = Ttk_GetStyle(theme, "."); + result = Ttk_StyleDefault(style, "-insertofftime"); + if (result) { + Tcl_GetIntFromObj(corePtr->interp, result, &offTime); + TtkSetBlinkCursorOffTime(corePtr, offTime); + } +} +/* * TtkBlinkCursor (main routine) -- * Arrange to blink the cursor on and off whenever the * widget has focus. diff --git a/generic/ttk/ttkWidget.c b/generic/ttk/ttkWidget.c index 4f035bf..ba2856c 100644 --- a/generic/ttk/ttkWidget.c +++ b/generic/ttk/ttkWidget.c @@ -126,21 +126,7 @@ static void WidgetWorldChanged(ClientData clientData) { WidgetCore *corePtr = (WidgetCore *)clientData; (void)UpdateLayout(corePtr->interp, corePtr); - Ttk_Theme theme; - Ttk_Style style = NULL; - Tcl_Obj* result; - int offTime; - SizeChanged(corePtr); - - theme = Ttk_GetCurrentTheme(corePtr->interp); - style = Ttk_GetStyle(theme, "."); - result = Ttk_StyleDefault(style, "-insertofftime"); - if (result) { - Tcl_GetIntFromObj(corePtr->interp, result, &offTime); - TtkSetBlinkOffTime(corePtr, offTime); - } - TtkRedisplayWidget(corePtr); } @@ -336,6 +322,7 @@ static void CoreEventProc(ClientData clientData, XEvent *eventPtr) case VirtualEvent: { const char *name = ((XVirtualEvent *)eventPtr)->name; if ((name != NULL) && !strcmp("ThemeChanged", name)) { + TtkBlinkCursorTimes(corePtr); WidgetWorldChanged(corePtr); } break; diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index c3a1f6d..0bb04e0 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -155,8 +155,8 @@ MODULE_SCOPE void TtkResizeWidget(WidgetCore *); MODULE_SCOPE void TtkTrackElementState(WidgetCore *); -MODULE_SCOPE void TtkSetBlinkOffTime(WidgetCore* corePtr, int offTime); MODULE_SCOPE void TtkBlinkCursor(WidgetCore *); +MODULE_SCOPE void TtkBlinkCursorTimes(WidgetCore* corePtr); /* * -state option values (compatibility) -- cgit v0.12