]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/settings.cpp
More refreshes are deferred to idle time.
[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
c801d85f
KB
24#define SHIFT (8*(sizeof(short int)-sizeof(char)))
25
94129723 26//wxColour *g_systemWinColour = (wxColour *) NULL;
74f55195
VS
27wxColour *g_systemBtnFaceColour = (wxColour *) NULL;
28wxColour *g_systemBtnShadowColour = (wxColour *) NULL;
29wxColour *g_systemBtnHighlightColour = (wxColour *) NULL;
30wxColour *g_systemHighlightColour = (wxColour *) NULL;
31wxColour *g_systemHighlightTextColour = (wxColour *) NULL;
32wxColour *g_systemListBoxColour = (wxColour *) NULL;
37d403aa 33wxColour *g_systemBtnTextColour = (wxColour *) NULL;
c801d85f 34
c67daf87 35wxFont *g_systemFont = (wxFont *) NULL;
a3622daa 36
0ab5e0e8
VS
37// ----------------------------------------------------------------------------
38// wxSystemSettingsModule
39// ----------------------------------------------------------------------------
40
41class wxSystemSettingsModule : public wxModule
1ecc4d80 42{
0ab5e0e8
VS
43public:
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
60IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
61
62// ----------------------------------------------------------------------------
63// wxSystemSettings implementation
64// ----------------------------------------------------------------------------
a3622daa 65
643ccf62 66// kind of widget to use in GetColourFromGTKWidget
dbcbe229 67enum wxGtkWidgetType
643ccf62 68{
dbcbe229
VZ
69 wxGTK_BUTTON,
70 wxGTK_LIST
71};
72
73// the colour we need
74enum wxGtkColourType
75{
76 wxGTK_FG,
77 wxGTK_BG,
78 wxGTK_BASE
643ccf62
VZ
79};
80
984152a6 81// wxSystemSettings::GetColour() helper: get the colours from a GTK+
643ccf62 82// widget style, return true if we did get them, false to use defaults
dbcbe229
VZ
83static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
84 wxGtkWidgetType type = wxGTK_BUTTON,
85 GtkStateType state = GTK_STATE_NORMAL,
86 wxGtkColourType colour = wxGTK_BG)
643ccf62 87{
dbcbe229
VZ
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
643ccf62
VZ
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 {
dbcbe229
VZ
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
3523b9cf
VZ
130 red = col[state].red;
131 green = col[state].green;
132 blue = col[state].blue;
643ccf62
VZ
133
134 ok = TRUE;
135 }
136 else
137 {
138 ok = FALSE;
139 }
140
141 gtk_widget_destroy( widget );
142
143 return ok;
144}
145
0ab5e0e8 146wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
c801d85f 147{
db434467 148 switch (index)
c801d85f 149 {
db434467
RR
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:
221ed576 159 case wxSYS_COLOUR_MENUBAR:
5b211fbf 160 case wxSYS_COLOUR_3DLIGHT:
37d403aa
JS
161 if (!g_systemBtnFaceColour)
162 {
643ccf62 163 int red, green, blue;
dbcbe229 164 if ( !GetColourFromGTKWidget(red, green, blue) )
37d403aa 165 {
643ccf62
VZ
166 red =
167 green = 0;
168 blue = 0x9c40;
37d403aa 169 }
37d403aa 170
643ccf62
VZ
171 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
172 green >> SHIFT,
173 blue >> SHIFT );
37d403aa
JS
174 }
175 return *g_systemBtnFaceColour;
643ccf62 176
db434467 177 case wxSYS_COLOUR_WINDOW:
db434467 178 return *wxWHITE;
643ccf62 179
37d403aa 180 case wxSYS_COLOUR_3DDKSHADOW:
37d403aa 181 return *wxBLACK;
643ccf62 182
db434467
RR
183 case wxSYS_COLOUR_GRAYTEXT:
184 case wxSYS_COLOUR_BTNSHADOW:
37d403aa 185 //case wxSYS_COLOUR_3DSHADOW:
37d403aa
JS
186 if (!g_systemBtnShadowColour)
187 {
984152a6 188 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
37d403aa 189 g_systemBtnShadowColour =
7a5e6267
JS
190 new wxColour((unsigned char) (faceColour.Red() * 0.666),
191 (unsigned char) (faceColour.Green() * 0.666),
192 (unsigned char) (faceColour.Blue() * 0.666));
db434467 193 }
643ccf62 194
db434467 195 return *g_systemBtnShadowColour;
643ccf62 196
37d403aa
JS
197 case wxSYS_COLOUR_3DHIGHLIGHT:
198 //case wxSYS_COLOUR_BTNHIGHLIGHT:
37d403aa
JS
199 return * wxWHITE;
200/* I think this should normally be white (JACS 8/2000)
643ccf62
VZ
201
202 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
db434467
RR
203 if (!g_systemBtnHighlightColour)
204 {
643ccf62
VZ
205 g_systemBtnHighlightColour =
206 new wxColour( 0xea60 >> SHIFT,
207 0xea60 >> SHIFT,
208 0xea60 >> SHIFT );
db434467
RR
209 }
210 return *g_systemBtnHighlightColour;
37d403aa 211*/
643ccf62 212
db434467 213 case wxSYS_COLOUR_HIGHLIGHT:
db434467
RR
214 if (!g_systemHighlightColour)
215 {
643ccf62 216 int red, green, blue;
dbcbe229
VZ
217 if ( !GetColourFromGTKWidget(red, green, blue,
218 wxGTK_BUTTON,
219 GTK_STATE_SELECTED) )
e6527f9d 220 {
643ccf62
VZ
221 red =
222 green = 0;
223 blue = 0x9c40;
e6527f9d 224 }
db434467 225
643ccf62
VZ
226 g_systemHighlightColour = new wxColour( red >> SHIFT,
227 green >> SHIFT,
228 blue >> SHIFT );
db434467
RR
229 }
230 return *g_systemHighlightColour;
643ccf62 231
74f55195 232 case wxSYS_COLOUR_LISTBOX:
74f55195
VS
233 if (!g_systemListBoxColour)
234 {
643ccf62 235 int red, green, blue;
dbcbe229
VZ
236 if ( GetColourFromGTKWidget(red, green, blue,
237 wxGTK_LIST,
238 GTK_STATE_NORMAL,
239 wxGTK_BASE) )
74f55195 240 {
643ccf62
VZ
241 g_systemListBoxColour = new wxColour( red >> SHIFT,
242 green >> SHIFT,
243 blue >> SHIFT );
74f55195
VS
244 }
245 else
643ccf62 246 {
74f55195 247 g_systemListBoxColour = new wxColour(*wxWHITE);
643ccf62 248 }
74f55195
VS
249 }
250 return *g_systemListBoxColour;
643ccf62
VZ
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:
37d403aa
JS
258 if (!g_systemBtnTextColour)
259 {
dbcbe229
VZ
260 int red, green, blue;
261 if ( !GetColourFromGTKWidget(red, green, blue,
262 wxGTK_BUTTON,
263 GTK_STATE_NORMAL,
264 wxGTK_FG) )
37d403aa 265 {
dbcbe229
VZ
266 red =
267 green =
268 blue = 0;
37d403aa 269 }
dbcbe229
VZ
270
271 g_systemBtnTextColour = new wxColour( red >> SHIFT,
272 green >> SHIFT,
273 blue >> SHIFT );
37d403aa
JS
274 }
275 return *g_systemBtnTextColour;
643ccf62 276
17d61cbf
VZ
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
643ccf62
VZ
283 case wxSYS_COLOUR_HIGHLIGHTTEXT:
284 if (!g_systemHighlightTextColour)
285 {
984152a6 286 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
643ccf62
VZ
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
643ccf62
VZ
294 case wxSYS_COLOUR_APPWORKSPACE:
295 return *wxWHITE; // ?
221ed576
VZ
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") );
ff7b1510 307 }
643ccf62 308
c801d85f 309 return *wxWHITE;
ff7b1510 310}
c801d85f 311
0ab5e0e8 312wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
c801d85f 313{
2d17d68f 314 switch (index)
c801d85f 315 {
2d17d68f
RR
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)
d06b34a7 328 {
f6bcfd97 329 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
643ccf62 330
d06b34a7 331 }
2d17d68f
RR
332 return *g_systemFont;
333 }
c801d85f 334
0ab5e0e8
VS
335 default:
336 return wxNullFont;
337 }
c801d85f 338}
c801d85f 339
0ab5e0e8 340int wxSystemSettingsNative::GetMetric( wxSystemMetric index )
c801d85f 341{
1ecc4d80
RR
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;
17d61cbf
VZ
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
0ab5e0e8
VS
353 default:
354 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
355 return 0;
1ecc4d80 356 }
c67daf87 357}
253293c1 358
0ab5e0e8 359bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1
VS
360{
361 switch (index)
362 {
363 case wxSYS_CAN_ICONIZE_FRAME:
0ab5e0e8
VS
364 return FALSE;
365 break;
253293c1 366 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
0ab5e0e8
VS
367 return TRUE;
368 break;
253293c1
VS
369 default:
370 return FALSE;
371 }
372}