]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/settings.cpp
applied the bit's of #473508 that were still relevant, and fixed a couple of
[wxWidgets.git] / src / gtk / 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"
c801d85f 17
d06b34a7
RR
18#include "wx/cmndata.h"
19
aed8ac3f 20#include <gdk/gdk.h>
d06b34a7 21#include <gdk/gdkprivate.h>
aed8ac3f 22#include <gtk/gtk.h>
83624f79 23
f6bcfd97
BP
24extern GdkFont *GtkGetDefaultGuiFont();
25
d06b34a7 26
c801d85f
KB
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
94129723 65//wxColour *g_systemWinColour = (wxColour *) NULL;
74f55195
VS
66wxColour *g_systemBtnFaceColour = (wxColour *) NULL;
67wxColour *g_systemBtnShadowColour = (wxColour *) NULL;
68wxColour *g_systemBtnHighlightColour = (wxColour *) NULL;
69wxColour *g_systemHighlightColour = (wxColour *) NULL;
70wxColour *g_systemHighlightTextColour = (wxColour *) NULL;
71wxColour *g_systemListBoxColour = (wxColour *) NULL;
37d403aa 72wxColour *g_systemBtnTextColour = (wxColour *) NULL;
c801d85f 73
c67daf87 74wxFont *g_systemFont = (wxFont *) NULL;
a3622daa 75
643ccf62 76void wxSystemSettings::Done()
1ecc4d80 77{
94129723 78// delete g_systemWinColour;
72a16063
RR
79 delete g_systemBtnFaceColour;
80 delete g_systemBtnShadowColour;
81 delete g_systemBtnHighlightColour;
82 delete g_systemHighlightColour;
74f55195
VS
83 delete g_systemHighlightTextColour;
84 delete g_systemListBoxColour;
72a16063 85 delete g_systemFont;
37d403aa 86 delete g_systemBtnTextColour;
a3622daa
VZ
87}
88
643ccf62 89// kind of widget to use in GetColourFromGTKWidget
dbcbe229 90enum wxGtkWidgetType
643ccf62 91{
dbcbe229
VZ
92 wxGTK_BUTTON,
93 wxGTK_LIST
94};
95
96// the colour we need
97enum wxGtkColourType
98{
99 wxGTK_FG,
100 wxGTK_BG,
101 wxGTK_BASE
643ccf62
VZ
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
dbcbe229
VZ
106static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
107 wxGtkWidgetType type = wxGTK_BUTTON,
108 GtkStateType state = GTK_STATE_NORMAL,
109 wxGtkColourType colour = wxGTK_BG)
643ccf62 110{
dbcbe229
VZ
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
643ccf62
VZ
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 {
dbcbe229
VZ
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
3523b9cf
VZ
153 red = col[state].red;
154 green = col[state].green;
155 blue = col[state].blue;
643ccf62
VZ
156
157 ok = TRUE;
158 }
159 else
160 {
161 ok = FALSE;
162 }
163
164 gtk_widget_destroy( widget );
165
166 return ok;
167}
168
c801d85f
KB
169wxColour wxSystemSettings::GetSystemColour( int index )
170{
db434467 171 switch (index)
c801d85f 172 {
db434467
RR
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:
5b211fbf 182 case wxSYS_COLOUR_3DLIGHT:
37d403aa
JS
183 if (!g_systemBtnFaceColour)
184 {
643ccf62 185 int red, green, blue;
dbcbe229 186 if ( !GetColourFromGTKWidget(red, green, blue) )
37d403aa 187 {
643ccf62
VZ
188 red =
189 green = 0;
190 blue = 0x9c40;
37d403aa 191 }
37d403aa 192
643ccf62
VZ
193 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
194 green >> SHIFT,
195 blue >> SHIFT );
37d403aa
JS
196 }
197 return *g_systemBtnFaceColour;
643ccf62 198
db434467 199 case wxSYS_COLOUR_WINDOW:
db434467 200 return *wxWHITE;
643ccf62 201
37d403aa 202 case wxSYS_COLOUR_3DDKSHADOW:
37d403aa 203 return *wxBLACK;
643ccf62 204
db434467
RR
205 case wxSYS_COLOUR_GRAYTEXT:
206 case wxSYS_COLOUR_BTNSHADOW:
37d403aa 207 //case wxSYS_COLOUR_3DSHADOW:
37d403aa
JS
208 if (!g_systemBtnShadowColour)
209 {
210 wxColour faceColour(GetSystemColour(wxSYS_COLOUR_3DFACE));
211 g_systemBtnShadowColour =
7a5e6267
JS
212 new wxColour((unsigned char) (faceColour.Red() * 0.666),
213 (unsigned char) (faceColour.Green() * 0.666),
214 (unsigned char) (faceColour.Blue() * 0.666));
db434467 215 }
643ccf62 216
db434467 217 return *g_systemBtnShadowColour;
643ccf62 218
37d403aa
JS
219 case wxSYS_COLOUR_3DHIGHLIGHT:
220 //case wxSYS_COLOUR_BTNHIGHLIGHT:
37d403aa
JS
221 return * wxWHITE;
222/* I think this should normally be white (JACS 8/2000)
643ccf62
VZ
223
224 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
db434467
RR
225 if (!g_systemBtnHighlightColour)
226 {
643ccf62
VZ
227 g_systemBtnHighlightColour =
228 new wxColour( 0xea60 >> SHIFT,
229 0xea60 >> SHIFT,
230 0xea60 >> SHIFT );
db434467
RR
231 }
232 return *g_systemBtnHighlightColour;
37d403aa 233*/
643ccf62 234
db434467 235 case wxSYS_COLOUR_HIGHLIGHT:
db434467
RR
236 if (!g_systemHighlightColour)
237 {
643ccf62 238 int red, green, blue;
dbcbe229
VZ
239 if ( !GetColourFromGTKWidget(red, green, blue,
240 wxGTK_BUTTON,
241 GTK_STATE_SELECTED) )
e6527f9d 242 {
643ccf62
VZ
243 red =
244 green = 0;
245 blue = 0x9c40;
e6527f9d 246 }
db434467 247
643ccf62
VZ
248 g_systemHighlightColour = new wxColour( red >> SHIFT,
249 green >> SHIFT,
250 blue >> SHIFT );
db434467
RR
251 }
252 return *g_systemHighlightColour;
643ccf62 253
74f55195 254 case wxSYS_COLOUR_LISTBOX:
74f55195
VS
255 if (!g_systemListBoxColour)
256 {
643ccf62 257 int red, green, blue;
dbcbe229
VZ
258 if ( GetColourFromGTKWidget(red, green, blue,
259 wxGTK_LIST,
260 GTK_STATE_NORMAL,
261 wxGTK_BASE) )
74f55195 262 {
643ccf62
VZ
263 g_systemListBoxColour = new wxColour( red >> SHIFT,
264 green >> SHIFT,
265 blue >> SHIFT );
74f55195
VS
266 }
267 else
643ccf62 268 {
74f55195 269 g_systemListBoxColour = new wxColour(*wxWHITE);
643ccf62 270 }
74f55195
VS
271 }
272 return *g_systemListBoxColour;
643ccf62
VZ
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:
37d403aa
JS
280 if (!g_systemBtnTextColour)
281 {
dbcbe229
VZ
282 int red, green, blue;
283 if ( !GetColourFromGTKWidget(red, green, blue,
284 wxGTK_BUTTON,
285 GTK_STATE_NORMAL,
286 wxGTK_FG) )
37d403aa 287 {
dbcbe229
VZ
288 red =
289 green =
290 blue = 0;
37d403aa 291 }
dbcbe229
VZ
292
293 g_systemBtnTextColour = new wxColour( red >> SHIFT,
294 green >> SHIFT,
295 blue >> SHIFT );
37d403aa
JS
296 }
297 return *g_systemBtnTextColour;
643ccf62
VZ
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; // ?
ff7b1510 313 }
643ccf62 314
c801d85f 315 return *wxWHITE;
ff7b1510 316}
c801d85f 317
643ccf62 318wxFont wxSystemSettings::GetSystemFont( int index )
c801d85f 319{
2d17d68f 320 switch (index)
c801d85f 321 {
2d17d68f
RR
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)
d06b34a7 334 {
d06b34a7 335#if 0
f6bcfd97 336 GdkFont *gdk_font = GtkGetDefaultGuiFont();
d06b34a7
RR
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 }
d06b34a7 345 gtk_widget_destroy( widget );
f6bcfd97
BP
346#endif
347
348 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
643ccf62 349
d06b34a7 350 }
2d17d68f
RR
351 return *g_systemFont;
352 }
ff7b1510 353 }
c801d85f 354
2d17d68f 355 return wxNullFont;
c801d85f 356}
c801d85f
KB
357
358int wxSystemSettings::GetSystemMetric( int index )
359{
1ecc4d80
RR
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 }
643ccf62 367
223d09f6 368 wxCHECK_MSG( index, 0, wxT("wxSystemSettings::GetSystemMetric not fully implemented") );
643ccf62 369
1ecc4d80 370 return 0;
c67daf87 371}
253293c1
VS
372
373bool 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}