]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/settings.cpp
Applied patch [ 735304 ] wxDisplay::ChangeMode - does not resize full-screen windows
[wxWidgets.git] / src / gtk / settings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/settings.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "settings.h"
13 #endif
14
15 #include "wx/settings.h"
16 #include "wx/debug.h"
17 #include "wx/module.h"
18 #include "wx/cmndata.h"
19 #include "wx/fontutil.h"
20
21 #include <gdk/gdk.h>
22 #include <gdk/gdkprivate.h>
23 #include <gtk/gtk.h>
24
25 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
26
27 //wxColour *g_systemWinColour = (wxColour *) NULL;
28 wxColour *g_systemBtnFaceColour = (wxColour *) NULL;
29 wxColour *g_systemBtnShadowColour = (wxColour *) NULL;
30 wxColour *g_systemBtnHighlightColour = (wxColour *) NULL;
31 wxColour *g_systemHighlightColour = (wxColour *) NULL;
32 wxColour *g_systemHighlightTextColour = (wxColour *) NULL;
33 wxColour *g_systemListBoxColour = (wxColour *) NULL;
34 wxColour *g_systemBtnTextColour = (wxColour *) NULL;
35
36 wxFont *g_systemFont = (wxFont *) NULL;
37
38 // ----------------------------------------------------------------------------
39 // wxSystemSettingsModule
40 // ----------------------------------------------------------------------------
41
42 class wxSystemSettingsModule : public wxModule
43 {
44 public:
45 bool OnInit() { return TRUE; }
46 void OnExit()
47 {
48 //delete g_systemWinColour;
49 delete g_systemBtnFaceColour;
50 delete g_systemBtnShadowColour;
51 delete g_systemBtnHighlightColour;
52 delete g_systemHighlightColour;
53 delete g_systemHighlightTextColour;
54 delete g_systemListBoxColour;
55 delete g_systemFont;
56 delete g_systemBtnTextColour;
57 }
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
59 };
60
61 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
62
63 // ----------------------------------------------------------------------------
64 // wxSystemSettings implementation
65 // ----------------------------------------------------------------------------
66
67 // kind of widget to use in GetColourFromGTKWidget
68 enum wxGtkWidgetType
69 {
70 wxGTK_BUTTON,
71 wxGTK_LIST
72 };
73
74 // the colour we need
75 enum wxGtkColourType
76 {
77 wxGTK_FG,
78 wxGTK_BG,
79 wxGTK_BASE
80 };
81
82 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
83 // widget style, return true if we did get them, false to use defaults
84 static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
85 wxGtkWidgetType type = wxGTK_BUTTON,
86 GtkStateType state = GTK_STATE_NORMAL,
87 wxGtkColourType colour = wxGTK_BG)
88 {
89 GtkWidget *widget;
90 switch ( type )
91 {
92 default:
93 wxFAIL_MSG( _T("unexpected GTK widget type") );
94 // fall through
95
96 case wxGTK_BUTTON:
97 widget = gtk_button_new();
98 break;
99
100 case wxGTK_LIST:
101 widget = gtk_list_new();
102 }
103
104 GtkStyle *def = gtk_rc_get_style( widget );
105 if ( !def )
106 def = gtk_widget_get_default_style();
107
108 bool ok;
109 if ( def )
110 {
111 GdkColor *col;
112 switch ( colour )
113 {
114 default:
115 wxFAIL_MSG( _T("unexpected GTK colour type") );
116 // fall through
117
118 case wxGTK_FG:
119 col = def->fg;
120 break;
121
122 case wxGTK_BG:
123 col = def->bg;
124 break;
125
126 case wxGTK_BASE:
127 col = def->base;
128 break;
129 }
130
131 red = col[state].red;
132 green = col[state].green;
133 blue = col[state].blue;
134
135 ok = TRUE;
136 }
137 else
138 {
139 ok = FALSE;
140 }
141
142 gtk_widget_destroy( widget );
143
144 return ok;
145 }
146
147 wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
148 {
149 switch (index)
150 {
151 case wxSYS_COLOUR_SCROLLBAR:
152 case wxSYS_COLOUR_BACKGROUND:
153 case wxSYS_COLOUR_ACTIVECAPTION:
154 case wxSYS_COLOUR_INACTIVECAPTION:
155 case wxSYS_COLOUR_MENU:
156 case wxSYS_COLOUR_WINDOWFRAME:
157 case wxSYS_COLOUR_ACTIVEBORDER:
158 case wxSYS_COLOUR_INACTIVEBORDER:
159 case wxSYS_COLOUR_BTNFACE:
160 case wxSYS_COLOUR_MENUBAR:
161 case wxSYS_COLOUR_3DLIGHT:
162 if (!g_systemBtnFaceColour)
163 {
164 int red, green, blue;
165 if ( !GetColourFromGTKWidget(red, green, blue) )
166 {
167 red =
168 green = 0;
169 blue = 0x9c40;
170 }
171
172 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
173 green >> SHIFT,
174 blue >> SHIFT );
175 }
176 return *g_systemBtnFaceColour;
177
178 case wxSYS_COLOUR_WINDOW:
179 return *wxWHITE;
180
181 case wxSYS_COLOUR_3DDKSHADOW:
182 return *wxBLACK;
183
184 case wxSYS_COLOUR_GRAYTEXT:
185 case wxSYS_COLOUR_BTNSHADOW:
186 //case wxSYS_COLOUR_3DSHADOW:
187 if (!g_systemBtnShadowColour)
188 {
189 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
190 g_systemBtnShadowColour =
191 new wxColour((unsigned char) (faceColour.Red() * 0.666),
192 (unsigned char) (faceColour.Green() * 0.666),
193 (unsigned char) (faceColour.Blue() * 0.666));
194 }
195
196 return *g_systemBtnShadowColour;
197
198 case wxSYS_COLOUR_3DHIGHLIGHT:
199 //case wxSYS_COLOUR_BTNHIGHLIGHT:
200 return * wxWHITE;
201 /* I think this should normally be white (JACS 8/2000)
202
203 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
204 if (!g_systemBtnHighlightColour)
205 {
206 g_systemBtnHighlightColour =
207 new wxColour( 0xea60 >> SHIFT,
208 0xea60 >> SHIFT,
209 0xea60 >> SHIFT );
210 }
211 return *g_systemBtnHighlightColour;
212 */
213
214 case wxSYS_COLOUR_HIGHLIGHT:
215 if (!g_systemHighlightColour)
216 {
217 int red, green, blue;
218 if ( !GetColourFromGTKWidget(red, green, blue,
219 wxGTK_BUTTON,
220 GTK_STATE_SELECTED) )
221 {
222 red =
223 green = 0;
224 blue = 0x9c40;
225 }
226
227 g_systemHighlightColour = new wxColour( red >> SHIFT,
228 green >> SHIFT,
229 blue >> SHIFT );
230 }
231 return *g_systemHighlightColour;
232
233 case wxSYS_COLOUR_LISTBOX:
234 if (!g_systemListBoxColour)
235 {
236 int red, green, blue;
237 if ( GetColourFromGTKWidget(red, green, blue,
238 wxGTK_LIST,
239 GTK_STATE_NORMAL,
240 wxGTK_BASE) )
241 {
242 g_systemListBoxColour = new wxColour( red >> SHIFT,
243 green >> SHIFT,
244 blue >> SHIFT );
245 }
246 else
247 {
248 g_systemListBoxColour = new wxColour(*wxWHITE);
249 }
250 }
251 return *g_systemListBoxColour;
252
253 case wxSYS_COLOUR_MENUTEXT:
254 case wxSYS_COLOUR_WINDOWTEXT:
255 case wxSYS_COLOUR_CAPTIONTEXT:
256 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
257 case wxSYS_COLOUR_BTNTEXT:
258 case wxSYS_COLOUR_INFOTEXT:
259 if (!g_systemBtnTextColour)
260 {
261 int red, green, blue;
262 if ( !GetColourFromGTKWidget(red, green, blue,
263 wxGTK_BUTTON,
264 GTK_STATE_NORMAL,
265 wxGTK_FG) )
266 {
267 red =
268 green =
269 blue = 0;
270 }
271
272 g_systemBtnTextColour = new wxColour( red >> SHIFT,
273 green >> SHIFT,
274 blue >> SHIFT );
275 }
276 return *g_systemBtnTextColour;
277
278 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
279 // tooltip windows - Robert, please change this code to use the
280 // real GTK tooltips when/if you can (TODO)
281 case wxSYS_COLOUR_INFOBK:
282 return wxColour(255, 255, 225);
283
284 case wxSYS_COLOUR_HIGHLIGHTTEXT:
285 if (!g_systemHighlightTextColour)
286 {
287 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
288 if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200)
289 g_systemHighlightTextColour = new wxColour(*wxBLACK);
290 else
291 g_systemHighlightTextColour = new wxColour(*wxWHITE);
292 }
293 return *g_systemHighlightTextColour;
294
295 case wxSYS_COLOUR_APPWORKSPACE:
296 return *wxWHITE; // ?
297
298 case wxSYS_COLOUR_HOTLIGHT:
299 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
300 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
301 case wxSYS_COLOUR_MENUHILIGHT:
302 // TODO
303 return *wxBLACK;
304
305 case wxSYS_COLOUR_MAX:
306 default:
307 wxFAIL_MSG( _T("unknown system colour index") );
308 }
309
310 return *wxWHITE;
311 }
312
313 wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
314 {
315 switch (index)
316 {
317 case wxSYS_OEM_FIXED_FONT:
318 case wxSYS_ANSI_FIXED_FONT:
319 case wxSYS_SYSTEM_FIXED_FONT:
320 {
321 return *wxNORMAL_FONT;
322 }
323 case wxSYS_ANSI_VAR_FONT:
324 case wxSYS_SYSTEM_FONT:
325 case wxSYS_DEVICE_DEFAULT_FONT:
326 case wxSYS_DEFAULT_GUI_FONT:
327 {
328 if (!g_systemFont)
329 {
330 #ifdef __WXGTK20__
331 GtkWidget *widget = gtk_button_new();
332 GtkStyle *def = gtk_rc_get_style( widget );
333 if (!def)
334 def = gtk_widget_get_default_style();
335 if (def)
336 {
337 wxNativeFontInfo info;
338 info.description = def->font_desc;
339 g_systemFont = new wxFont(info);
340 }
341 else
342 {
343 const gchar *font_name =
344 _gtk_rc_context_get_default_font_name(gtk_settings_get_default());
345 g_systemFont = new wxFont(wxString::FromAscii(font_name));
346 }
347 gtk_widget_destroy( widget );
348 #else
349 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
350 #endif
351 }
352 return *g_systemFont;
353 }
354
355 default:
356 return wxNullFont;
357 }
358 }
359
360 int wxSystemSettingsNative::GetMetric( wxSystemMetric index )
361 {
362 switch (index)
363 {
364 case wxSYS_SCREEN_X: return gdk_screen_width();
365 case wxSYS_SCREEN_Y: return gdk_screen_height();
366 case wxSYS_HSCROLL_Y: return 15;
367 case wxSYS_VSCROLL_X: return 15;
368
369 // VZ: is there any way to get the cursor size with GDK?
370 case wxSYS_CURSOR_X: return 16;
371 case wxSYS_CURSOR_Y: return 16;
372 // MBN: ditto for icons
373 case wxSYS_ICON_X: return 32;
374 case wxSYS_ICON_Y: return 32;
375 default:
376 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
377 return 0;
378 }
379 }
380
381 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
382 {
383 switch (index)
384 {
385 case wxSYS_CAN_ICONIZE_FRAME:
386 return FALSE;
387 break;
388 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
389 return TRUE;
390 break;
391 default:
392 return FALSE;
393 }
394 }