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