|
8 | 8 |
|
9 | 9 | #include "gttk_Utilities.h" |
10 | 10 | #include "gttk_TkHeaders.h" |
| 11 | +#include <gtk/gtkmodules.h> |
11 | 12 | #include <string.h> |
12 | 13 |
|
13 | 14 | static int gttk_GtkAppCreated = 0; |
@@ -81,6 +82,25 @@ int gttk_ThemeName(ClientData clientData, Tcl_Interp *interp, |
81 | 82 | return TCL_OK; |
82 | 83 | }; /* gttk_ThemeName */ |
83 | 84 |
|
| 85 | +int gttk_set_gtk_theme(ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { |
| 86 | + /** @brief Tcl command 'setGtkTheme': Set the GTK theme from Tcl */ |
| 87 | + if (objc != 2) { |
| 88 | + Tcl_WrongNumArgs(interp, 1, objv, "fileName"); |
| 89 | + return TCL_ERROR; |
| 90 | + } |
| 91 | + // Get the argument and format it into the proper string |
| 92 | + const char* name = Tcl_GetStringFromObj(objv[1], NULL); |
| 93 | + // Make GTK parse the resource string |
| 94 | + Tcl_MutexLock(>tkMutex); |
| 95 | + GtkSettings* settings = gtk_settings_get_default(); |
| 96 | + gtk_settings_set_string_property(settings, "gtk-theme-name", name, NULL); |
| 97 | + gtk_rc_reset_styles(settings); |
| 98 | + |
| 99 | + Tcl_MutexUnlock(>tkMutex); |
| 100 | + |
| 101 | + return TCL_OK; |
| 102 | +} // gttk_set_gtk_theme |
| 103 | + |
84 | 104 | int gttk_SettingsProperty(ClientData clientData, Tcl_Interp *interp, |
85 | 105 | int objc, Tcl_Obj *const objv[]) { |
86 | 106 | static const char *Methods[] = { |
@@ -810,44 +830,23 @@ _Gttk_Init(Tcl_Interp *interp) |
810 | 830 | Tcl_CreateExitHandler(>tk_ExitProc, 0); |
811 | 831 | //Tcl_CreateThreadExitHandler(>tk_ExitProc, 0); |
812 | 832 |
|
813 | | - /* |
814 | | - * Register the TileGtk package... |
815 | | - */ |
816 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtkEnum", |
817 | | - gttk_GtkEnum, (ClientData) wc, NULL); |
818 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::settingsProperty", |
819 | | - gttk_SettingsProperty, (ClientData) wc, NULL); |
820 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::widgetStyleProperty", |
821 | | - gttk_WidgetStyleProperty, (ClientData) wc, NULL); |
822 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::widgetProperty", |
823 | | - gttk_WidgetProperty, (ClientData) wc, NULL); |
824 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::currentThemeName", |
825 | | - gttk_ThemeName, (ClientData) wc, NULL); |
826 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtkDirectory", |
827 | | - gttk_GtkDirectory, (ClientData) wc, NULL); |
828 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::setStyle", |
829 | | - gttk_SetStyle, (ClientData) wc, NULL); |
830 | | - Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtk_method", |
831 | | - gttk_gtk_method, (ClientData) wc, NULL); |
832 | | - Tcl_CreateObjCommand(interp, |
833 | | - "ttk::theme::gttk::currentThemeColour", |
834 | | - gttk_ThemeColour, (ClientData) wc, NULL); |
835 | | - Tcl_CreateObjCommand(interp, |
836 | | - "ttk::theme::gttk::currentThemeColourKeys", |
837 | | - gttk_ColourKeys, (ClientData) wc, NULL); |
| 833 | + // Register ttk::theme::gttk Tcl commands |
| 834 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtkEnum", gttk_GtkEnum, (ClientData) wc, NULL); |
| 835 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::settingsProperty", gttk_SettingsProperty, (ClientData) wc, NULL); |
| 836 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::widgetStyleProperty", gttk_WidgetStyleProperty, (ClientData) wc, NULL); |
| 837 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::widgetProperty", gttk_WidgetProperty, (ClientData) wc, NULL); |
| 838 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::currentThemeName", gttk_ThemeName, (ClientData) wc, NULL); |
| 839 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtkDirectory", gttk_GtkDirectory, (ClientData) wc, NULL); |
| 840 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::setStyle", gttk_SetStyle, (ClientData) wc, NULL); |
| 841 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::gtk_method", gttk_gtk_method, (ClientData) wc, NULL); |
| 842 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::currentThemeColour", gttk_ThemeColour, (ClientData) wc, NULL); |
| 843 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::currentThemeColourKeys", gttk_ColourKeys, (ClientData) wc, NULL); |
| 844 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::setGtkTheme", gttk_set_gtk_theme, (ClientData) wc, NULL); |
838 | 845 | #if 0 |
839 | | - Tcl_CreateObjCommand(interp, |
840 | | - "ttk::theme::gttk::setPalette", |
841 | | - gttk_SetPalette, (ClientData) wc, NULL); |
842 | | - Tcl_CreateObjCommand(interp, |
843 | | - "ttk::theme::gttk::getPixelMetric", |
844 | | - gttk_GetPixelMetric, (ClientData) wc, NULL); |
845 | | - Tcl_CreateObjCommand(interp, |
846 | | - "ttk::theme::gttk::getStyleHint", |
847 | | - gttk_GetStyleHint, (ClientData) wc, NULL); |
848 | | - Tcl_CreateObjCommand(interp, |
849 | | - "ttk::theme::gttk::getSubControlMetrics", |
850 | | - gttk_GetSubControlMetrics, (ClientData) wc, NULL); |
| 846 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::setPalette", gttk_SetPalette, (ClientData) wc, NULL); |
| 847 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::getPixelMetric", gttk_GetPixelMetric, (ClientData) wc, NULL); |
| 848 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::getStyleHint", gttk_GetStyleHint, (ClientData) wc, NULL); |
| 849 | + Tcl_CreateObjCommand(interp, "ttk::theme::gttk::getSubControlMetrics", gttk_GetSubControlMetrics, (ClientData) wc, NULL); |
851 | 850 | #endif |
852 | 851 | /* Save the name of the current theme... */ |
853 | 852 | strcpy(tmpScript, "namespace eval ttk::theme::gttk { variable theme "); |
|
0 commit comments