]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/settings.cpp
changed wxSystemSettings::HasFrameDecorations to more general GetCapability(index)
[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
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 void wxSystemSettings::Done()
77 {
78 // delete g_systemWinColour;
79 delete g_systemBtnFaceColour;
80 delete g_systemBtnShadowColour;
81 delete g_systemBtnHighlightColour;
82 delete g_systemHighlightColour;
83 delete g_systemHighlightTextColour;
84 delete g_systemListBoxColour;
85 delete g_systemFont;
86 delete g_systemBtnTextColour;
87 }
88
89 // kind of widget to use in GetColourFromGTKWidget
90 enum wxGtkWidgetType
91 {
92 wxGTK_BUTTON,
93 wxGTK_LIST
94 };
95
96 // the colour we need
97 enum wxGtkColourType
98 {
99 wxGTK_FG,
100 wxGTK_BG,
101 wxGTK_BASE
102 };
103
104 // wxSystemSettings::GetSystemColour() helper: get the colours from a GTK+
105 // widget style, return true if we did get them, false to use defaults
106 static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
107 wxGtkWidgetType type = wxGTK_BUTTON,
108 GtkStateType state = GTK_STATE_NORMAL,
109 wxGtkColourType colour = wxGTK_BG)
110 {
111 GtkWidget *widget;
112 switch ( type )
113 {
114 default:
115 wxFAIL_MSG( _T("unexpected GTK widget type") );
116 // fall through
117
118 case wxGTK_BUTTON:
119 widget = gtk_button_new();
120 break;
121
122 case wxGTK_LIST:
123 widget = gtk_list_new();
124 }
125
126 GtkStyle *def = gtk_rc_get_style( widget );
127 if ( !def )
128 def = gtk_widget_get_default_style();
129
130 bool ok;
131 if ( def )
132 {
133 GdkColor *col;
134 switch ( colour )
135 {
136 default:
137 wxFAIL_MSG( _T("unexpected GTK colour type") );
138 // fall through
139
140 case wxGTK_FG:
141 col = def->fg;
142 break;
143
144 case wxGTK_BG:
145 col = def->bg;
146 break;
147
148 case wxGTK_BASE:
149 col = def->base;
150 break;
151 }
152
153 red = col[state].red;
154 green = col[state].green;
155 blue = col[state].blue;
156
157 ok = TRUE;
158 }
159 else
160 {
161 ok = FALSE;
162 }
163
164 gtk_widget_destroy( widget );
165
166 return ok;
167 }
168
169 wxColour wxSystemSettings::GetSystemColour( int index )
170 {
171 switch (index)
172 {
173 case wxSYS_COLOUR_SCROLLBAR:
174 case wxSYS_COLOUR_BACKGROUND:
175 case wxSYS_COLOUR_ACTIVECAPTION:
176 case wxSYS_COLOUR_INACTIVECAPTION:
177 case wxSYS_COLOUR_MENU:
178 case wxSYS_COLOUR_WINDOWFRAME:
179 case wxSYS_COLOUR_ACTIVEBORDER:
180 case wxSYS_COLOUR_INACTIVEBORDER:
181 case wxSYS_COLOUR_BTNFACE:
182 case wxSYS_COLOUR_3DLIGHT:
183 if (!g_systemBtnFaceColour)
184 {
185 int red, green, blue;
186 if ( !GetColourFromGTKWidget(red, green, blue) )
187 {
188 red =
189 green = 0;
190 blue = 0x9c40;
191 }
192
193 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
194 green >> SHIFT,
195 blue >> SHIFT );
196 }
197 return *g_systemBtnFaceColour;
198
199 case wxSYS_COLOUR_WINDOW:
200 return *wxWHITE;
201
202 case wxSYS_COLOUR_3DDKSHADOW:
203 return *wxBLACK;
204
205 case wxSYS_COLOUR_GRAYTEXT:
206 case wxSYS_COLOUR_BTNSHADOW:
207 //case wxSYS_COLOUR_3DSHADOW:
208 if (!g_systemBtnShadowColour)
209 {
210 wxColour faceColour(GetSystemColour(wxSYS_COLOUR_3DFACE));
211 g_systemBtnShadowColour =
212 new wxColour((unsigned char) (faceColour.Red() * 0.666),
213 (unsigned char) (faceColour.Green() * 0.666),
214 (unsigned char) (faceColour.Blue() * 0.666));
215 }
216
217 return *g_systemBtnShadowColour;
218
219 case wxSYS_COLOUR_3DHIGHLIGHT:
220 //case wxSYS_COLOUR_BTNHIGHLIGHT:
221 return * wxWHITE;
222 /* I think this should normally be white (JACS 8/2000)
223
224 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
225 if (!g_systemBtnHighlightColour)
226 {
227 g_systemBtnHighlightColour =
228 new wxColour( 0xea60 >> SHIFT,
229 0xea60 >> SHIFT,
230 0xea60 >> SHIFT );
231 }
232 return *g_systemBtnHighlightColour;
233 */
234
235 case wxSYS_COLOUR_HIGHLIGHT:
236 if (!g_systemHighlightColour)
237 {
238 int red, green, blue;
239 if ( !GetColourFromGTKWidget(red, green, blue,
240 wxGTK_BUTTON,
241 GTK_STATE_SELECTED) )
242 {
243 red =
244 green = 0;
245 blue = 0x9c40;
246 }
247
248 g_systemHighlightColour = new wxColour( red >> SHIFT,
249 green >> SHIFT,
250 blue >> SHIFT );
251 }
252 return *g_systemHighlightColour;
253
254 case wxSYS_COLOUR_LISTBOX:
255 if (!g_systemListBoxColour)
256 {
257 int red, green, blue;
258 if ( GetColourFromGTKWidget(red, green, blue,
259 wxGTK_LIST,
260 GTK_STATE_NORMAL,
261 wxGTK_BASE) )
262 {
263 g_systemListBoxColour = new wxColour( red >> SHIFT,
264 green >> SHIFT,
265 blue >> SHIFT );
266 }
267 else
268 {
269 g_systemListBoxColour = new wxColour(*wxWHITE);
270 }
271 }
272 return *g_systemListBoxColour;
273
274 case wxSYS_COLOUR_MENUTEXT:
275 case wxSYS_COLOUR_WINDOWTEXT:
276 case wxSYS_COLOUR_CAPTIONTEXT:
277 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
278 case wxSYS_COLOUR_BTNTEXT:
279 case wxSYS_COLOUR_INFOTEXT:
280 if (!g_systemBtnTextColour)
281 {
282 int red, green, blue;
283 if ( !GetColourFromGTKWidget(red, green, blue,
284 wxGTK_BUTTON,
285 GTK_STATE_NORMAL,
286 wxGTK_FG) )
287 {
288 red =
289 green =
290 blue = 0;
291 }
292
293 g_systemBtnTextColour = new wxColour( red >> SHIFT,
294 green >> SHIFT,
295 blue >> SHIFT );
296 }
297 return *g_systemBtnTextColour;
298
299 case wxSYS_COLOUR_HIGHLIGHTTEXT:
300 if (!g_systemHighlightTextColour)
301 {
302 wxColour hclr = GetSystemColour(wxSYS_COLOUR_HIGHLIGHT);
303 if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200)
304 g_systemHighlightTextColour = new wxColour(*wxBLACK);
305 else
306 g_systemHighlightTextColour = new wxColour(*wxWHITE);
307 }
308 return *g_systemHighlightTextColour;
309
310 case wxSYS_COLOUR_INFOBK:
311 case wxSYS_COLOUR_APPWORKSPACE:
312 return *wxWHITE; // ?
313 }
314
315 return *wxWHITE;
316 }
317
318 wxFont wxSystemSettings::GetSystemFont( int index )
319 {
320 switch (index)
321 {
322 case wxSYS_OEM_FIXED_FONT:
323 case wxSYS_ANSI_FIXED_FONT:
324 case wxSYS_SYSTEM_FIXED_FONT:
325 {
326 return *wxNORMAL_FONT;
327 }
328 case wxSYS_ANSI_VAR_FONT:
329 case wxSYS_SYSTEM_FONT:
330 case wxSYS_DEVICE_DEFAULT_FONT:
331 case wxSYS_DEFAULT_GUI_FONT:
332 {
333 if (!g_systemFont)
334 {
335 #if 0
336 GdkFont *gdk_font = GtkGetDefaultGuiFont();
337 if (gdk_font)
338 {
339 GSList *font_list = ((GdkFontPrivate*)gdk_font)->names;
340 char *name = (char*)font_list->data;
341 wxString font_string( name );
342 wxFontData font_data;
343 g_systemFont = new wxFont( font_string, font_data );
344 }
345 gtk_widget_destroy( widget );
346 #endif
347
348 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
349
350 }
351 return *g_systemFont;
352 }
353 }
354
355 return wxNullFont;
356 }
357
358 int wxSystemSettings::GetSystemMetric( int index )
359 {
360 switch (index)
361 {
362 case wxSYS_SCREEN_X: return gdk_screen_width();
363 case wxSYS_SCREEN_Y: return gdk_screen_height();
364 case wxSYS_HSCROLL_Y: return 15;
365 case wxSYS_VSCROLL_X: return 15;
366 }
367
368 wxCHECK_MSG( index, 0, wxT("wxSystemSettings::GetSystemMetric not fully implemented") );
369
370 return 0;
371 }
372
373 bool wxSystemSettings::GetCapability(int index)
374 {
375 switch (index)
376 {
377 case wxSYS_CAN_ICONIZE_FRAME:
378 return FALSE; break;
379 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
380 return TRUE; break;
381 default:
382 return FALSE;
383 }
384 }