]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/settings.cpp
added SetString(), deprecated SetLabel()
[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_MENUBAR:
160 case wxSYS_COLOUR_3DLIGHT:
161 if (!g_systemBtnFaceColour)
162 {
163 int red, green, blue;
164 if ( !GetColourFromGTKWidget(red, green, blue) )
165 {
166 red =
167 green = 0;
168 blue = 0x9c40;
169 }
170
171 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
172 green >> SHIFT,
173 blue >> SHIFT );
174 }
175 return *g_systemBtnFaceColour;
176
177 case wxSYS_COLOUR_WINDOW:
178 return *wxWHITE;
179
180 case wxSYS_COLOUR_3DDKSHADOW:
181 return *wxBLACK;
182
183 case wxSYS_COLOUR_GRAYTEXT:
184 case wxSYS_COLOUR_BTNSHADOW:
185 //case wxSYS_COLOUR_3DSHADOW:
186 if (!g_systemBtnShadowColour)
187 {
188 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
189 g_systemBtnShadowColour =
190 new wxColour((unsigned char) (faceColour.Red() * 0.666),
191 (unsigned char) (faceColour.Green() * 0.666),
192 (unsigned char) (faceColour.Blue() * 0.666));
193 }
194
195 return *g_systemBtnShadowColour;
196
197 case wxSYS_COLOUR_3DHIGHLIGHT:
198 //case wxSYS_COLOUR_BTNHIGHLIGHT:
199 return * wxWHITE;
200 /* I think this should normally be white (JACS 8/2000)
201
202 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
203 if (!g_systemBtnHighlightColour)
204 {
205 g_systemBtnHighlightColour =
206 new wxColour( 0xea60 >> SHIFT,
207 0xea60 >> SHIFT,
208 0xea60 >> SHIFT );
209 }
210 return *g_systemBtnHighlightColour;
211 */
212
213 case wxSYS_COLOUR_HIGHLIGHT:
214 if (!g_systemHighlightColour)
215 {
216 int red, green, blue;
217 if ( !GetColourFromGTKWidget(red, green, blue,
218 wxGTK_BUTTON,
219 GTK_STATE_SELECTED) )
220 {
221 red =
222 green = 0;
223 blue = 0x9c40;
224 }
225
226 g_systemHighlightColour = new wxColour( red >> SHIFT,
227 green >> SHIFT,
228 blue >> SHIFT );
229 }
230 return *g_systemHighlightColour;
231
232 case wxSYS_COLOUR_LISTBOX:
233 if (!g_systemListBoxColour)
234 {
235 int red, green, blue;
236 if ( GetColourFromGTKWidget(red, green, blue,
237 wxGTK_LIST,
238 GTK_STATE_NORMAL,
239 wxGTK_BASE) )
240 {
241 g_systemListBoxColour = new wxColour( red >> SHIFT,
242 green >> SHIFT,
243 blue >> SHIFT );
244 }
245 else
246 {
247 g_systemListBoxColour = new wxColour(*wxWHITE);
248 }
249 }
250 return *g_systemListBoxColour;
251
252 case wxSYS_COLOUR_MENUTEXT:
253 case wxSYS_COLOUR_WINDOWTEXT:
254 case wxSYS_COLOUR_CAPTIONTEXT:
255 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
256 case wxSYS_COLOUR_BTNTEXT:
257 case wxSYS_COLOUR_INFOTEXT:
258 if (!g_systemBtnTextColour)
259 {
260 int red, green, blue;
261 if ( !GetColourFromGTKWidget(red, green, blue,
262 wxGTK_BUTTON,
263 GTK_STATE_NORMAL,
264 wxGTK_FG) )
265 {
266 red =
267 green =
268 blue = 0;
269 }
270
271 g_systemBtnTextColour = new wxColour( red >> SHIFT,
272 green >> SHIFT,
273 blue >> SHIFT );
274 }
275 return *g_systemBtnTextColour;
276
277 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
278 // tooltip windows - Robert, please change this code to use the
279 // real GTK tooltips when/if you can (TODO)
280 case wxSYS_COLOUR_INFOBK:
281 return wxColour(255, 255, 225);
282
283 case wxSYS_COLOUR_HIGHLIGHTTEXT:
284 if (!g_systemHighlightTextColour)
285 {
286 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
287 if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200)
288 g_systemHighlightTextColour = new wxColour(*wxBLACK);
289 else
290 g_systemHighlightTextColour = new wxColour(*wxWHITE);
291 }
292 return *g_systemHighlightTextColour;
293
294 case wxSYS_COLOUR_APPWORKSPACE:
295 return *wxWHITE; // ?
296
297 case wxSYS_COLOUR_HOTLIGHT:
298 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
299 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
300 case wxSYS_COLOUR_MENUHILIGHT:
301 // TODO
302 return *wxBLACK;
303
304 case wxSYS_COLOUR_MAX:
305 default:
306 wxFAIL_MSG( _T("unknown system colour index") );
307 }
308
309 return *wxWHITE;
310 }
311
312 wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
313 {
314 switch (index)
315 {
316 case wxSYS_OEM_FIXED_FONT:
317 case wxSYS_ANSI_FIXED_FONT:
318 case wxSYS_SYSTEM_FIXED_FONT:
319 {
320 return *wxNORMAL_FONT;
321 }
322 case wxSYS_ANSI_VAR_FONT:
323 case wxSYS_SYSTEM_FONT:
324 case wxSYS_DEVICE_DEFAULT_FONT:
325 case wxSYS_DEFAULT_GUI_FONT:
326 {
327 if (!g_systemFont)
328 {
329 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
330
331 }
332 return *g_systemFont;
333 }
334
335 default:
336 return wxNullFont;
337 }
338 }
339
340 int wxSystemSettingsNative::GetMetric( wxSystemMetric index )
341 {
342 switch (index)
343 {
344 case wxSYS_SCREEN_X: return gdk_screen_width();
345 case wxSYS_SCREEN_Y: return gdk_screen_height();
346 case wxSYS_HSCROLL_Y: return 15;
347 case wxSYS_VSCROLL_X: return 15;
348
349 // VZ: is there any way to get the cursor size with GDK?
350 case wxSYS_CURSOR_X: return 16;
351 case wxSYS_CURSOR_Y: return 16;
352
353 default:
354 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
355 return 0;
356 }
357 }
358
359 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
360 {
361 switch (index)
362 {
363 case wxSYS_CAN_ICONIZE_FRAME:
364 return FALSE;
365 break;
366 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
367 return TRUE;
368 break;
369 default:
370 return FALSE;
371 }
372 }