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