]>
Commit | Line | Data |
---|---|---|
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 | ||
14f355c2 | 11 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
12 | #pragma implementation "settings.h" |
13 | #endif | |
14 | ||
14f355c2 VS |
15 | // For compilers that support precompilation, includes "wx.h". |
16 | #include "wx/wxprec.h" | |
17 | ||
c801d85f | 18 | #include "wx/settings.h" |
1ecc4d80 | 19 | #include "wx/debug.h" |
0ab5e0e8 | 20 | #include "wx/module.h" |
d06b34a7 | 21 | #include "wx/cmndata.h" |
2b5f62a0 | 22 | #include "wx/fontutil.h" |
d06b34a7 | 23 | |
aed8ac3f | 24 | #include <gdk/gdk.h> |
d06b34a7 | 25 | #include <gdk/gdkprivate.h> |
aed8ac3f | 26 | #include <gtk/gtk.h> |
83624f79 | 27 | |
c801d85f KB |
28 | #define SHIFT (8*(sizeof(short int)-sizeof(char))) |
29 | ||
94129723 | 30 | //wxColour *g_systemWinColour = (wxColour *) NULL; |
74f55195 VS |
31 | wxColour *g_systemBtnFaceColour = (wxColour *) NULL; |
32 | wxColour *g_systemBtnShadowColour = (wxColour *) NULL; | |
33 | wxColour *g_systemBtnHighlightColour = (wxColour *) NULL; | |
34 | wxColour *g_systemHighlightColour = (wxColour *) NULL; | |
35 | wxColour *g_systemHighlightTextColour = (wxColour *) NULL; | |
36 | wxColour *g_systemListBoxColour = (wxColour *) NULL; | |
37d403aa | 37 | wxColour *g_systemBtnTextColour = (wxColour *) NULL; |
c801d85f | 38 | |
c67daf87 | 39 | wxFont *g_systemFont = (wxFont *) NULL; |
a3622daa | 40 | |
0ab5e0e8 VS |
41 | // ---------------------------------------------------------------------------- |
42 | // wxSystemSettingsModule | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | class wxSystemSettingsModule : public wxModule | |
1ecc4d80 | 46 | { |
0ab5e0e8 VS |
47 | public: |
48 | bool OnInit() { return TRUE; } | |
49 | void OnExit() | |
50 | { | |
51 | //delete g_systemWinColour; | |
52 | delete g_systemBtnFaceColour; | |
53 | delete g_systemBtnShadowColour; | |
54 | delete g_systemBtnHighlightColour; | |
55 | delete g_systemHighlightColour; | |
56 | delete g_systemHighlightTextColour; | |
57 | delete g_systemListBoxColour; | |
58 | delete g_systemFont; | |
59 | delete g_systemBtnTextColour; | |
60 | } | |
61 | DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule) | |
62 | }; | |
63 | ||
64 | IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // wxSystemSettings implementation | |
68 | // ---------------------------------------------------------------------------- | |
a3622daa | 69 | |
643ccf62 | 70 | // kind of widget to use in GetColourFromGTKWidget |
dbcbe229 | 71 | enum wxGtkWidgetType |
643ccf62 | 72 | { |
dbcbe229 VZ |
73 | wxGTK_BUTTON, |
74 | wxGTK_LIST | |
75 | }; | |
76 | ||
77 | // the colour we need | |
78 | enum wxGtkColourType | |
79 | { | |
80 | wxGTK_FG, | |
81 | wxGTK_BG, | |
82 | wxGTK_BASE | |
643ccf62 VZ |
83 | }; |
84 | ||
984152a6 | 85 | // wxSystemSettings::GetColour() helper: get the colours from a GTK+ |
643ccf62 | 86 | // widget style, return true if we did get them, false to use defaults |
dbcbe229 VZ |
87 | static bool GetColourFromGTKWidget(int& red, int& green, int& blue, |
88 | wxGtkWidgetType type = wxGTK_BUTTON, | |
89 | GtkStateType state = GTK_STATE_NORMAL, | |
90 | wxGtkColourType colour = wxGTK_BG) | |
643ccf62 | 91 | { |
dbcbe229 VZ |
92 | GtkWidget *widget; |
93 | switch ( type ) | |
94 | { | |
95 | default: | |
96 | wxFAIL_MSG( _T("unexpected GTK widget type") ); | |
97 | // fall through | |
98 | ||
99 | case wxGTK_BUTTON: | |
100 | widget = gtk_button_new(); | |
101 | break; | |
102 | ||
103 | case wxGTK_LIST: | |
104 | widget = gtk_list_new(); | |
105 | } | |
106 | ||
643ccf62 VZ |
107 | GtkStyle *def = gtk_rc_get_style( widget ); |
108 | if ( !def ) | |
109 | def = gtk_widget_get_default_style(); | |
110 | ||
111 | bool ok; | |
112 | if ( def ) | |
113 | { | |
dbcbe229 VZ |
114 | GdkColor *col; |
115 | switch ( colour ) | |
116 | { | |
117 | default: | |
118 | wxFAIL_MSG( _T("unexpected GTK colour type") ); | |
119 | // fall through | |
120 | ||
121 | case wxGTK_FG: | |
122 | col = def->fg; | |
123 | break; | |
124 | ||
125 | case wxGTK_BG: | |
126 | col = def->bg; | |
127 | break; | |
128 | ||
129 | case wxGTK_BASE: | |
130 | col = def->base; | |
131 | break; | |
132 | } | |
133 | ||
3523b9cf VZ |
134 | red = col[state].red; |
135 | green = col[state].green; | |
136 | blue = col[state].blue; | |
643ccf62 VZ |
137 | |
138 | ok = TRUE; | |
139 | } | |
140 | else | |
141 | { | |
142 | ok = FALSE; | |
143 | } | |
144 | ||
145 | gtk_widget_destroy( widget ); | |
146 | ||
147 | return ok; | |
148 | } | |
149 | ||
0ab5e0e8 | 150 | wxColour wxSystemSettingsNative::GetColour( wxSystemColour index ) |
c801d85f | 151 | { |
db434467 | 152 | switch (index) |
c801d85f | 153 | { |
db434467 RR |
154 | case wxSYS_COLOUR_SCROLLBAR: |
155 | case wxSYS_COLOUR_BACKGROUND: | |
156 | case wxSYS_COLOUR_ACTIVECAPTION: | |
157 | case wxSYS_COLOUR_INACTIVECAPTION: | |
158 | case wxSYS_COLOUR_MENU: | |
159 | case wxSYS_COLOUR_WINDOWFRAME: | |
160 | case wxSYS_COLOUR_ACTIVEBORDER: | |
161 | case wxSYS_COLOUR_INACTIVEBORDER: | |
162 | case wxSYS_COLOUR_BTNFACE: | |
221ed576 | 163 | case wxSYS_COLOUR_MENUBAR: |
5b211fbf | 164 | case wxSYS_COLOUR_3DLIGHT: |
37d403aa JS |
165 | if (!g_systemBtnFaceColour) |
166 | { | |
643ccf62 | 167 | int red, green, blue; |
dbcbe229 | 168 | if ( !GetColourFromGTKWidget(red, green, blue) ) |
37d403aa | 169 | { |
643ccf62 VZ |
170 | red = |
171 | green = 0; | |
172 | blue = 0x9c40; | |
37d403aa | 173 | } |
37d403aa | 174 | |
643ccf62 VZ |
175 | g_systemBtnFaceColour = new wxColour( red >> SHIFT, |
176 | green >> SHIFT, | |
177 | blue >> SHIFT ); | |
37d403aa JS |
178 | } |
179 | return *g_systemBtnFaceColour; | |
643ccf62 | 180 | |
db434467 | 181 | case wxSYS_COLOUR_WINDOW: |
db434467 | 182 | return *wxWHITE; |
643ccf62 | 183 | |
37d403aa | 184 | case wxSYS_COLOUR_3DDKSHADOW: |
37d403aa | 185 | return *wxBLACK; |
643ccf62 | 186 | |
db434467 RR |
187 | case wxSYS_COLOUR_GRAYTEXT: |
188 | case wxSYS_COLOUR_BTNSHADOW: | |
37d403aa | 189 | //case wxSYS_COLOUR_3DSHADOW: |
37d403aa JS |
190 | if (!g_systemBtnShadowColour) |
191 | { | |
984152a6 | 192 | wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE)); |
37d403aa | 193 | g_systemBtnShadowColour = |
7a5e6267 JS |
194 | new wxColour((unsigned char) (faceColour.Red() * 0.666), |
195 | (unsigned char) (faceColour.Green() * 0.666), | |
196 | (unsigned char) (faceColour.Blue() * 0.666)); | |
db434467 | 197 | } |
643ccf62 | 198 | |
db434467 | 199 | return *g_systemBtnShadowColour; |
643ccf62 | 200 | |
37d403aa JS |
201 | case wxSYS_COLOUR_3DHIGHLIGHT: |
202 | //case wxSYS_COLOUR_BTNHIGHLIGHT: | |
37d403aa JS |
203 | return * wxWHITE; |
204 | /* I think this should normally be white (JACS 8/2000) | |
643ccf62 VZ |
205 | |
206 | Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01) | |
db434467 RR |
207 | if (!g_systemBtnHighlightColour) |
208 | { | |
643ccf62 VZ |
209 | g_systemBtnHighlightColour = |
210 | new wxColour( 0xea60 >> SHIFT, | |
211 | 0xea60 >> SHIFT, | |
212 | 0xea60 >> SHIFT ); | |
db434467 RR |
213 | } |
214 | return *g_systemBtnHighlightColour; | |
37d403aa | 215 | */ |
643ccf62 | 216 | |
db434467 | 217 | case wxSYS_COLOUR_HIGHLIGHT: |
db434467 RR |
218 | if (!g_systemHighlightColour) |
219 | { | |
643ccf62 | 220 | int red, green, blue; |
dbcbe229 VZ |
221 | if ( !GetColourFromGTKWidget(red, green, blue, |
222 | wxGTK_BUTTON, | |
223 | GTK_STATE_SELECTED) ) | |
e6527f9d | 224 | { |
643ccf62 VZ |
225 | red = |
226 | green = 0; | |
227 | blue = 0x9c40; | |
e6527f9d | 228 | } |
db434467 | 229 | |
643ccf62 VZ |
230 | g_systemHighlightColour = new wxColour( red >> SHIFT, |
231 | green >> SHIFT, | |
232 | blue >> SHIFT ); | |
db434467 RR |
233 | } |
234 | return *g_systemHighlightColour; | |
643ccf62 | 235 | |
74f55195 | 236 | case wxSYS_COLOUR_LISTBOX: |
74f55195 VS |
237 | if (!g_systemListBoxColour) |
238 | { | |
643ccf62 | 239 | int red, green, blue; |
dbcbe229 VZ |
240 | if ( GetColourFromGTKWidget(red, green, blue, |
241 | wxGTK_LIST, | |
242 | GTK_STATE_NORMAL, | |
243 | wxGTK_BASE) ) | |
74f55195 | 244 | { |
643ccf62 VZ |
245 | g_systemListBoxColour = new wxColour( red >> SHIFT, |
246 | green >> SHIFT, | |
247 | blue >> SHIFT ); | |
74f55195 VS |
248 | } |
249 | else | |
643ccf62 | 250 | { |
74f55195 | 251 | g_systemListBoxColour = new wxColour(*wxWHITE); |
643ccf62 | 252 | } |
74f55195 VS |
253 | } |
254 | return *g_systemListBoxColour; | |
643ccf62 VZ |
255 | |
256 | case wxSYS_COLOUR_MENUTEXT: | |
257 | case wxSYS_COLOUR_WINDOWTEXT: | |
258 | case wxSYS_COLOUR_CAPTIONTEXT: | |
259 | case wxSYS_COLOUR_INACTIVECAPTIONTEXT: | |
260 | case wxSYS_COLOUR_BTNTEXT: | |
261 | case wxSYS_COLOUR_INFOTEXT: | |
37d403aa JS |
262 | if (!g_systemBtnTextColour) |
263 | { | |
dbcbe229 VZ |
264 | int red, green, blue; |
265 | if ( !GetColourFromGTKWidget(red, green, blue, | |
266 | wxGTK_BUTTON, | |
267 | GTK_STATE_NORMAL, | |
268 | wxGTK_FG) ) | |
37d403aa | 269 | { |
dbcbe229 VZ |
270 | red = |
271 | green = | |
272 | blue = 0; | |
37d403aa | 273 | } |
dbcbe229 VZ |
274 | |
275 | g_systemBtnTextColour = new wxColour( red >> SHIFT, | |
276 | green >> SHIFT, | |
277 | blue >> SHIFT ); | |
37d403aa JS |
278 | } |
279 | return *g_systemBtnTextColour; | |
643ccf62 | 280 | |
17d61cbf VZ |
281 | // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for |
282 | // tooltip windows - Robert, please change this code to use the | |
283 | // real GTK tooltips when/if you can (TODO) | |
284 | case wxSYS_COLOUR_INFOBK: | |
285 | return wxColour(255, 255, 225); | |
286 | ||
643ccf62 VZ |
287 | case wxSYS_COLOUR_HIGHLIGHTTEXT: |
288 | if (!g_systemHighlightTextColour) | |
289 | { | |
984152a6 | 290 | wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT); |
643ccf62 VZ |
291 | if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200) |
292 | g_systemHighlightTextColour = new wxColour(*wxBLACK); | |
293 | else | |
294 | g_systemHighlightTextColour = new wxColour(*wxWHITE); | |
295 | } | |
296 | return *g_systemHighlightTextColour; | |
297 | ||
643ccf62 VZ |
298 | case wxSYS_COLOUR_APPWORKSPACE: |
299 | return *wxWHITE; // ? | |
221ed576 VZ |
300 | |
301 | case wxSYS_COLOUR_HOTLIGHT: | |
302 | case wxSYS_COLOUR_GRADIENTACTIVECAPTION: | |
303 | case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: | |
304 | case wxSYS_COLOUR_MENUHILIGHT: | |
305 | // TODO | |
306 | return *wxBLACK; | |
307 | ||
308 | case wxSYS_COLOUR_MAX: | |
309 | default: | |
310 | wxFAIL_MSG( _T("unknown system colour index") ); | |
ff7b1510 | 311 | } |
643ccf62 | 312 | |
c801d85f | 313 | return *wxWHITE; |
ff7b1510 | 314 | } |
c801d85f | 315 | |
0ab5e0e8 | 316 | wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) |
c801d85f | 317 | { |
2d17d68f | 318 | switch (index) |
c801d85f | 319 | { |
2d17d68f RR |
320 | case wxSYS_OEM_FIXED_FONT: |
321 | case wxSYS_ANSI_FIXED_FONT: | |
322 | case wxSYS_SYSTEM_FIXED_FONT: | |
323 | { | |
324 | return *wxNORMAL_FONT; | |
325 | } | |
326 | case wxSYS_ANSI_VAR_FONT: | |
327 | case wxSYS_SYSTEM_FONT: | |
328 | case wxSYS_DEVICE_DEFAULT_FONT: | |
329 | case wxSYS_DEFAULT_GUI_FONT: | |
330 | { | |
331 | if (!g_systemFont) | |
d06b34a7 | 332 | { |
2b5f62a0 | 333 | #ifdef __WXGTK20__ |
e7370dac VS |
334 | GtkWidget *widget = gtk_button_new(); |
335 | GtkStyle *def = gtk_rc_get_style( widget ); | |
2269ff56 | 336 | if ( !def || !def->font_desc ) |
e7370dac | 337 | def = gtk_widget_get_default_style(); |
2269ff56 | 338 | if ( def && def->font_desc ) |
e7370dac VS |
339 | { |
340 | wxNativeFontInfo info; | |
341 | info.description = def->font_desc; | |
342 | g_systemFont = new wxFont(info); | |
343 | } | |
344 | else | |
345 | { | |
346 | const gchar *font_name = | |
347 | _gtk_rc_context_get_default_font_name(gtk_settings_get_default()); | |
348 | g_systemFont = new wxFont(wxString::FromAscii(font_name)); | |
349 | } | |
350 | gtk_widget_destroy( widget ); | |
2b5f62a0 | 351 | #else |
f6bcfd97 | 352 | g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); |
2b5f62a0 | 353 | #endif |
d06b34a7 | 354 | } |
2d17d68f RR |
355 | return *g_systemFont; |
356 | } | |
c801d85f | 357 | |
0ab5e0e8 VS |
358 | default: |
359 | return wxNullFont; | |
360 | } | |
c801d85f | 361 | } |
c801d85f | 362 | |
0ab5e0e8 | 363 | int wxSystemSettingsNative::GetMetric( wxSystemMetric index ) |
c801d85f | 364 | { |
1ecc4d80 RR |
365 | switch (index) |
366 | { | |
367 | case wxSYS_SCREEN_X: return gdk_screen_width(); | |
368 | case wxSYS_SCREEN_Y: return gdk_screen_height(); | |
369 | case wxSYS_HSCROLL_Y: return 15; | |
370 | case wxSYS_VSCROLL_X: return 15; | |
17d61cbf VZ |
371 | |
372 | // VZ: is there any way to get the cursor size with GDK? | |
373 | case wxSYS_CURSOR_X: return 16; | |
374 | case wxSYS_CURSOR_Y: return 16; | |
f618020a MB |
375 | // MBN: ditto for icons |
376 | case wxSYS_ICON_X: return 32; | |
377 | case wxSYS_ICON_Y: return 32; | |
0ab5e0e8 VS |
378 | default: |
379 | wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") ); | |
380 | return 0; | |
1ecc4d80 | 381 | } |
c67daf87 | 382 | } |
253293c1 | 383 | |
0ab5e0e8 | 384 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 VS |
385 | { |
386 | switch (index) | |
387 | { | |
388 | case wxSYS_CAN_ICONIZE_FRAME: | |
0ab5e0e8 VS |
389 | return FALSE; |
390 | break; | |
253293c1 | 391 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
0ab5e0e8 VS |
392 | return TRUE; |
393 | break; | |
253293c1 VS |
394 | default: |
395 | return FALSE; | |
396 | } | |
397 | } |