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