]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/settings.cpp
don't use deprecated IntToString function
[wxWidgets.git] / src / gtk1 / settings.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3523b9cf 2// Name: gtk/settings.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
3523b9cf 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "settings.h"
13#endif
14
15#include "wx/settings.h"
1ecc4d80 16#include "wx/debug.h"
0ab5e0e8 17#include "wx/module.h"
d06b34a7 18#include "wx/cmndata.h"
2b5f62a0 19#include "wx/fontutil.h"
d06b34a7 20
aed8ac3f 21#include <gdk/gdk.h>
d06b34a7 22#include <gdk/gdkprivate.h>
aed8ac3f 23#include <gtk/gtk.h>
83624f79 24
c801d85f
KB
25#define SHIFT (8*(sizeof(short int)-sizeof(char)))
26
94129723 27//wxColour *g_systemWinColour = (wxColour *) NULL;
74f55195
VS
28wxColour *g_systemBtnFaceColour = (wxColour *) NULL;
29wxColour *g_systemBtnShadowColour = (wxColour *) NULL;
30wxColour *g_systemBtnHighlightColour = (wxColour *) NULL;
31wxColour *g_systemHighlightColour = (wxColour *) NULL;
32wxColour *g_systemHighlightTextColour = (wxColour *) NULL;
33wxColour *g_systemListBoxColour = (wxColour *) NULL;
37d403aa 34wxColour *g_systemBtnTextColour = (wxColour *) NULL;
c801d85f 35
c67daf87 36wxFont *g_systemFont = (wxFont *) NULL;
a3622daa 37
0ab5e0e8
VS
38// ----------------------------------------------------------------------------
39// wxSystemSettingsModule
40// ----------------------------------------------------------------------------
41
42class wxSystemSettingsModule : public wxModule
1ecc4d80 43{
0ab5e0e8
VS
44public:
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
61IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
62
63// ----------------------------------------------------------------------------
64// wxSystemSettings implementation
65// ----------------------------------------------------------------------------
a3622daa 66
643ccf62 67// kind of widget to use in GetColourFromGTKWidget
dbcbe229 68enum wxGtkWidgetType
643ccf62 69{
dbcbe229
VZ
70 wxGTK_BUTTON,
71 wxGTK_LIST
72};
73
74// the colour we need
75enum wxGtkColourType
76{
77 wxGTK_FG,
78 wxGTK_BG,
79 wxGTK_BASE
643ccf62
VZ
80};
81
984152a6 82// wxSystemSettings::GetColour() helper: get the colours from a GTK+
643ccf62 83// widget style, return true if we did get them, false to use defaults
dbcbe229
VZ
84static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
85 wxGtkWidgetType type = wxGTK_BUTTON,
86 GtkStateType state = GTK_STATE_NORMAL,
87 wxGtkColourType colour = wxGTK_BG)
643ccf62 88{
dbcbe229
VZ
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
643ccf62
VZ
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 {
dbcbe229
VZ
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
3523b9cf
VZ
131 red = col[state].red;
132 green = col[state].green;
133 blue = col[state].blue;
643ccf62
VZ
134
135 ok = TRUE;
136 }
137 else
138 {
139 ok = FALSE;
140 }
141
142 gtk_widget_destroy( widget );
143
144 return ok;
145}
146
0ab5e0e8 147wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
c801d85f 148{
db434467 149 switch (index)
c801d85f 150 {
db434467
RR
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:
221ed576 160 case wxSYS_COLOUR_MENUBAR:
5b211fbf 161 case wxSYS_COLOUR_3DLIGHT:
37d403aa
JS
162 if (!g_systemBtnFaceColour)
163 {
643ccf62 164 int red, green, blue;
dbcbe229 165 if ( !GetColourFromGTKWidget(red, green, blue) )
37d403aa 166 {
643ccf62
VZ
167 red =
168 green = 0;
169 blue = 0x9c40;
37d403aa 170 }
37d403aa 171
643ccf62
VZ
172 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
173 green >> SHIFT,
174 blue >> SHIFT );
37d403aa
JS
175 }
176 return *g_systemBtnFaceColour;
643ccf62 177
db434467 178 case wxSYS_COLOUR_WINDOW:
db434467 179 return *wxWHITE;
643ccf62 180
37d403aa 181 case wxSYS_COLOUR_3DDKSHADOW:
37d403aa 182 return *wxBLACK;
643ccf62 183
db434467
RR
184 case wxSYS_COLOUR_GRAYTEXT:
185 case wxSYS_COLOUR_BTNSHADOW:
37d403aa 186 //case wxSYS_COLOUR_3DSHADOW:
37d403aa
JS
187 if (!g_systemBtnShadowColour)
188 {
984152a6 189 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
37d403aa 190 g_systemBtnShadowColour =
7a5e6267
JS
191 new wxColour((unsigned char) (faceColour.Red() * 0.666),
192 (unsigned char) (faceColour.Green() * 0.666),
193 (unsigned char) (faceColour.Blue() * 0.666));
db434467 194 }
643ccf62 195
db434467 196 return *g_systemBtnShadowColour;
643ccf62 197
37d403aa
JS
198 case wxSYS_COLOUR_3DHIGHLIGHT:
199 //case wxSYS_COLOUR_BTNHIGHLIGHT:
37d403aa
JS
200 return * wxWHITE;
201/* I think this should normally be white (JACS 8/2000)
643ccf62
VZ
202
203 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
db434467
RR
204 if (!g_systemBtnHighlightColour)
205 {
643ccf62
VZ
206 g_systemBtnHighlightColour =
207 new wxColour( 0xea60 >> SHIFT,
208 0xea60 >> SHIFT,
209 0xea60 >> SHIFT );
db434467
RR
210 }
211 return *g_systemBtnHighlightColour;
37d403aa 212*/
643ccf62 213
db434467 214 case wxSYS_COLOUR_HIGHLIGHT:
db434467
RR
215 if (!g_systemHighlightColour)
216 {
643ccf62 217 int red, green, blue;
dbcbe229
VZ
218 if ( !GetColourFromGTKWidget(red, green, blue,
219 wxGTK_BUTTON,
220 GTK_STATE_SELECTED) )
e6527f9d 221 {
643ccf62
VZ
222 red =
223 green = 0;
224 blue = 0x9c40;
e6527f9d 225 }
db434467 226
643ccf62
VZ
227 g_systemHighlightColour = new wxColour( red >> SHIFT,
228 green >> SHIFT,
229 blue >> SHIFT );
db434467
RR
230 }
231 return *g_systemHighlightColour;
643ccf62 232
74f55195 233 case wxSYS_COLOUR_LISTBOX:
74f55195
VS
234 if (!g_systemListBoxColour)
235 {
643ccf62 236 int red, green, blue;
dbcbe229
VZ
237 if ( GetColourFromGTKWidget(red, green, blue,
238 wxGTK_LIST,
239 GTK_STATE_NORMAL,
240 wxGTK_BASE) )
74f55195 241 {
643ccf62
VZ
242 g_systemListBoxColour = new wxColour( red >> SHIFT,
243 green >> SHIFT,
244 blue >> SHIFT );
74f55195
VS
245 }
246 else
643ccf62 247 {
74f55195 248 g_systemListBoxColour = new wxColour(*wxWHITE);
643ccf62 249 }
74f55195
VS
250 }
251 return *g_systemListBoxColour;
643ccf62
VZ
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:
37d403aa
JS
259 if (!g_systemBtnTextColour)
260 {
dbcbe229
VZ
261 int red, green, blue;
262 if ( !GetColourFromGTKWidget(red, green, blue,
263 wxGTK_BUTTON,
264 GTK_STATE_NORMAL,
265 wxGTK_FG) )
37d403aa 266 {
dbcbe229
VZ
267 red =
268 green =
269 blue = 0;
37d403aa 270 }
dbcbe229
VZ
271
272 g_systemBtnTextColour = new wxColour( red >> SHIFT,
273 green >> SHIFT,
274 blue >> SHIFT );
37d403aa
JS
275 }
276 return *g_systemBtnTextColour;
643ccf62 277
17d61cbf
VZ
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
643ccf62
VZ
284 case wxSYS_COLOUR_HIGHLIGHTTEXT:
285 if (!g_systemHighlightTextColour)
286 {
984152a6 287 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
643ccf62
VZ
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
643ccf62
VZ
295 case wxSYS_COLOUR_APPWORKSPACE:
296 return *wxWHITE; // ?
221ed576
VZ
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") );
ff7b1510 308 }
643ccf62 309
c801d85f 310 return *wxWHITE;
ff7b1510 311}
c801d85f 312
0ab5e0e8 313wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
c801d85f 314{
2d17d68f 315 switch (index)
c801d85f 316 {
2d17d68f
RR
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)
d06b34a7 329 {
2b5f62a0 330#ifdef __WXGTK20__
e7370dac
VS
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 );
2b5f62a0 348#else
f6bcfd97 349 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
2b5f62a0 350#endif
d06b34a7 351 }
2d17d68f
RR
352 return *g_systemFont;
353 }
c801d85f 354
0ab5e0e8
VS
355 default:
356 return wxNullFont;
357 }
c801d85f 358}
c801d85f 359
0ab5e0e8 360int wxSystemSettingsNative::GetMetric( wxSystemMetric index )
c801d85f 361{
1ecc4d80
RR
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;
17d61cbf
VZ
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;
f618020a
MB
372 // MBN: ditto for icons
373 case wxSYS_ICON_X: return 32;
374 case wxSYS_ICON_Y: return 32;
0ab5e0e8
VS
375 default:
376 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
377 return 0;
1ecc4d80 378 }
c67daf87 379}
253293c1 380
0ab5e0e8 381bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1
VS
382{
383 switch (index)
384 {
385 case wxSYS_CAN_ICONIZE_FRAME:
0ab5e0e8
VS
386 return FALSE;
387 break;
253293c1 388 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
0ab5e0e8
VS
389 return TRUE;
390 break;
253293c1
VS
391 default:
392 return FALSE;
393 }
394}