Debian Codegraph @

modules/engines/ms-windows/msw_theme_main.c

raw
1 /* MS-Windows Engine (aka GTK-Wimp)
2 *
3 * Copyright (C) 2003, 2004 Raymond Penners <[email protected]>
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, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 #include <windows.h>
24
25 #include <gmodule.h>
26
27 #include "gtk/gtk.h"
28
29 #include "msw_style.h"
30 #include "msw_rc_style.h"
31 #include "xp_theme.h"
32
33 #ifndef WM_THEMECHANGED
34 #define WM_THEMECHANGED 0x031A /* winxp only */
35 #endif
36
37 static GModule *this_module = NULL;
38 static void (*msw_rc_reset_styles) (GtkSettings *settings) = NULL;
39 static GdkWindow *hidden_msg_window = NULL;
40
41 static GdkWindow *
42 create_hidden_msg_window (void)
43 {
44 GdkWindowAttr attributes;
45 gint attributes_mask;
46
47 attributes.x = -100;
48 attributes.y = -100;
49 attributes.width = 10;
50 attributes.height = 10;
51 attributes.window_type = GDK_WINDOW_TEMP;
52 attributes.wclass = GDK_INPUT_ONLY;
53 attributes.override_redirect = TRUE;
54 attributes.event_mask = 0;
55
56 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
57
58 return gdk_window_new (gdk_get_default_root_window (),
59 &attributes, attributes_mask);
60 }
61
62 static GdkFilterReturn
63 global_filter_func (void *xevent, GdkEvent *event, gpointer data)
64 {
65 MSG *msg = (MSG *) xevent;
66
67 switch (msg->message)
68 {
69 /* catch theme changes */
70 case WM_THEMECHANGED:
71 case WM_SYSCOLORCHANGE:
72
73 if (msw_rc_reset_styles != NULL)
74 {
75 xp_theme_reset ();
76 msw_style_init ();
77
78 /* force all gtkwidgets to redraw */
79 (*msw_rc_reset_styles) (gtk_settings_get_default ());
80 }
81
82 return GDK_FILTER_REMOVE;
83
84 case WM_SETTINGCHANGE:
85 /* catch cursor blink, etc... changes */
86 msw_style_setup_system_settings ();
87 return GDK_FILTER_REMOVE;
88
89 default:
90 return GDK_FILTER_CONTINUE;
91 }
92 }
93
94 G_MODULE_EXPORT void
95 theme_init (GTypeModule * module)
96 {
97 msw_rc_style_register_type (module);
98 msw_style_register_type (module);
99
100 /* this craziness is required because only gtk 2.4.x and later have
101 gtk_rc_reset_styles(). But we want to be able to run acceptly well on
102 any GTK 2.x.x platform. */
103 if (gtk_check_version (2, 4, 0) == NULL)
104 {
105 this_module = g_module_open (NULL, 0);
106
107 if (this_module)
108 g_module_symbol (this_module, "gtk_rc_reset_styles",
109 (gpointer *) (&msw_rc_reset_styles));
110 }
111
112 msw_style_init ();
113 hidden_msg_window = create_hidden_msg_window ();
114 gdk_window_add_filter (hidden_msg_window, global_filter_func, NULL);
115 }
116
117 G_MODULE_EXPORT void
118 theme_exit (void)
119 {
120 gdk_window_remove_filter (hidden_msg_window, global_filter_func, NULL);
121 gdk_window_destroy (hidden_msg_window);
122 hidden_msg_window = NULL;
123 msw_style_finalize ();
124
125 if (this_module)
126 {
127 g_module_close (this_module);
128 this_module = NULL;
129 }
130 }
131
132 G_MODULE_EXPORT GtkRcStyle *
133 theme_create_rc_style (void)
134 {
135 return g_object_new (MSW_TYPE_RC_STYLE, NULL);
136 }
137
138 /* The following function will be called by GTK+ when the module
139 * is loaded and checks to see if we are compatible with the
140 * version of GTK+ that loads us.
141 */
142 G_MODULE_EXPORT const gchar *
143 g_module_check_init (GModule *module)
144 {
145 return gtk_check_version (2, 0, 0);
146 }