]> Pileus Git - ~andy/gtk/blob - modules/engines/ms-windows/msw_theme_main.c
Change FSF Address
[~andy/gtk] / modules / engines / ms-windows / msw_theme_main.c
1 /* MS-Windows Engine (aka GTK-Wimp)
2  *
3  * Copyright (C) 2003, 2004 Raymond Penners <raymond@dotsphinx.com>
4  * Includes code adapted from redmond95 by Owen Taylor, and
5  * gtk-nativewin by Evan Martin
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <windows.h>
22
23 #include <gmodule.h>
24
25 #include "gtk/gtk.h"
26
27 #include "msw_style.h"
28 #include "msw_rc_style.h"
29 #include "xp_theme.h"
30
31 #ifndef WM_THEMECHANGED
32 #define WM_THEMECHANGED 0x031A  /* winxp only */
33 #endif
34
35 static GModule *this_module = NULL;
36 static void (*msw_rc_reset_styles) (GtkSettings *settings) = NULL;
37 static GdkWindow *hidden_msg_window = NULL;
38
39 static GdkWindow *
40 create_hidden_msg_window (void)
41 {
42   GdkWindowAttr attributes;
43   gint attributes_mask;
44
45   attributes.x = -100;
46   attributes.y = -100;
47   attributes.width = 10;
48   attributes.height = 10;
49   attributes.window_type = GDK_WINDOW_TEMP;
50   attributes.wclass = GDK_INPUT_ONLY;
51   attributes.override_redirect = TRUE;
52   attributes.event_mask = 0;
53
54   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
55
56   return gdk_window_new (gdk_get_default_root_window (),
57                          &attributes, attributes_mask);
58 }
59
60 static GdkFilterReturn
61 global_filter_func (void *xevent, GdkEvent *event, gpointer data)
62 {
63   MSG *msg = (MSG *) xevent;
64
65   switch (msg->message)
66     {
67       /* catch theme changes */
68     case WM_THEMECHANGED:
69     case WM_SYSCOLORCHANGE:
70
71       if (msw_rc_reset_styles != NULL)
72         {
73           xp_theme_reset ();
74           msw_style_init ();
75
76           /* force all gtkwidgets to redraw */
77           (*msw_rc_reset_styles) (gtk_settings_get_default ());
78         }
79
80       return GDK_FILTER_REMOVE;
81
82     case WM_SETTINGCHANGE:
83       /* catch cursor blink, etc... changes */
84       msw_style_setup_system_settings ();
85       return GDK_FILTER_REMOVE;
86
87     default:
88       return GDK_FILTER_CONTINUE;
89     }
90 }
91
92 G_MODULE_EXPORT void
93 theme_init (GTypeModule * module)
94 {
95   msw_rc_style_register_type (module);
96   msw_style_register_type (module);
97
98   /* this craziness is required because only gtk 2.4.x and later have
99      gtk_rc_reset_styles(). But we want to be able to run acceptly well on
100      any GTK 2.x.x platform. */
101   if (gtk_check_version (2, 4, 0) == NULL)
102     {
103       this_module = g_module_open (NULL, 0);
104
105       if (this_module)
106         g_module_symbol (this_module, "gtk_rc_reset_styles",
107                          (gpointer *) (&msw_rc_reset_styles));
108     }
109
110   msw_style_init ();
111   hidden_msg_window = create_hidden_msg_window ();
112   gdk_window_add_filter (hidden_msg_window, global_filter_func, NULL);
113 }
114
115 G_MODULE_EXPORT void
116 theme_exit (void)
117 {
118   gdk_window_remove_filter (hidden_msg_window, global_filter_func, NULL);
119   gdk_window_destroy (hidden_msg_window);
120   hidden_msg_window = NULL;
121   msw_style_finalize ();
122
123   if (this_module)
124     {
125       g_module_close (this_module);
126       this_module = NULL;
127     }
128 }
129
130 G_MODULE_EXPORT GtkRcStyle *
131 theme_create_rc_style (void)
132 {
133   return g_object_new (MSW_TYPE_RC_STYLE, NULL);
134 }
135
136 /* The following function will be called by GTK+ when the module
137  * is loaded and checks to see if we are compatible with the
138  * version of GTK+ that loads us.
139  */
140 G_MODULE_EXPORT const gchar *
141 g_module_check_init (GModule *module)
142 {
143   return gtk_check_version (2, 0, 0);
144 }