]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/settings.cpp
Deallocate wxThreadSpecificInfo when wxThread ends.
[wxWidgets.git] / src / gtk1 / settings.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e7c80f9e 2// Name: src/gtk1/settings.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
9b0b5ba7 5// Modified by: Mart Raudsepp (GetMetric)
f96aa4d9 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/settings.h"
e7c80f9e 14
ce5d92e1 15#ifndef WX_PRECOMP
1832043f 16 #include "wx/toplevel.h"
ce5d92e1
WS
17#endif
18
2b5f62a0 19#include "wx/fontutil.h"
d06b34a7 20
aed8ac3f 21#include <gdk/gdk.h>
9b0b5ba7 22#include <gdk/gdkx.h>
d06b34a7 23#include <gdk/gdkprivate.h>
aed8ac3f 24#include <gtk/gtk.h>
83624f79 25
9b0b5ba7
RR
26#include <X11/Xatom.h>
27
c801d85f
KB
28#define SHIFT (8*(sizeof(short int)-sizeof(char)))
29
0ab5e0e8 30// ----------------------------------------------------------------------------
94a09ea5 31// wxSystemObjects
0ab5e0e8
VS
32// ----------------------------------------------------------------------------
33
94a09ea5 34struct wxSystemObjects
1ecc4d80 35{
c1ef87c3
VZ
36 wxColour m_colBtnFace,
37 m_colBtnShadow,
38 m_colBtnHighlight,
39 m_colHighlight,
40 m_colHighlightText,
41 m_colListBox,
9d6a9fdd 42 m_colBtnText,
c05cc2c7
RR
43 m_colMenuItemHighlight,
44 m_colTooltip,
45 m_colTooltipText;
c1ef87c3
VZ
46
47 wxFont m_fontSystem;
0ab5e0e8
VS
48};
49
94a09ea5 50static wxSystemObjects gs_objects;
c1ef87c3 51
0ab5e0e8
VS
52// ----------------------------------------------------------------------------
53// wxSystemSettings implementation
54// ----------------------------------------------------------------------------
a3622daa 55
643ccf62 56// kind of widget to use in GetColourFromGTKWidget
dbcbe229 57enum wxGtkWidgetType
643ccf62 58{
dbcbe229 59 wxGTK_BUTTON,
9d6a9fdd
RR
60 wxGTK_LIST,
61 wxGTK_MENUITEM
dbcbe229
VZ
62};
63
64// the colour we need
65enum wxGtkColourType
66{
67 wxGTK_FG,
68 wxGTK_BG,
69 wxGTK_BASE
643ccf62
VZ
70};
71
984152a6 72// wxSystemSettings::GetColour() helper: get the colours from a GTK+
643ccf62 73// widget style, return true if we did get them, false to use defaults
dbcbe229
VZ
74static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
75 wxGtkWidgetType type = wxGTK_BUTTON,
76 GtkStateType state = GTK_STATE_NORMAL,
77 wxGtkColourType colour = wxGTK_BG)
643ccf62 78{
dbcbe229
VZ
79 GtkWidget *widget;
80 switch ( type )
81 {
82 default:
9a83f860 83 wxFAIL_MSG( wxT("unexpected GTK widget type") );
dbcbe229
VZ
84 // fall through
85
86 case wxGTK_BUTTON:
87 widget = gtk_button_new();
88 break;
89
90 case wxGTK_LIST:
91 widget = gtk_list_new();
e24b680c
VZ
92 break;
93
9d6a9fdd
RR
94 case wxGTK_MENUITEM:
95 widget = gtk_menu_item_new();
dbcbe229
VZ
96 }
97
643ccf62
VZ
98 GtkStyle *def = gtk_rc_get_style( widget );
99 if ( !def )
100 def = gtk_widget_get_default_style();
101
102 bool ok;
103 if ( def )
104 {
dbcbe229
VZ
105 GdkColor *col;
106 switch ( colour )
107 {
108 default:
9a83f860 109 wxFAIL_MSG( wxT("unexpected GTK colour type") );
dbcbe229
VZ
110 // fall through
111
112 case wxGTK_FG:
113 col = def->fg;
114 break;
115
116 case wxGTK_BG:
117 col = def->bg;
118 break;
119
120 case wxGTK_BASE:
121 col = def->base;
122 break;
123 }
124
3523b9cf
VZ
125 red = col[state].red;
126 green = col[state].green;
127 blue = col[state].blue;
643ccf62 128
e7c80f9e 129 ok = true;
643ccf62
VZ
130 }
131 else
132 {
e7c80f9e 133 ok = false;
643ccf62
VZ
134 }
135
136 gtk_widget_destroy( widget );
137
138 return ok;
139}
140
c05cc2c7
RR
141static void GetTooltipColors()
142{
143 GtkTooltips* tooltips = gtk_tooltips_new();
144 gtk_tooltips_force_window(tooltips);
145 gtk_widget_ensure_style(tooltips->tip_window);
146 GdkColor c = tooltips->tip_window->style->bg[GTK_STATE_NORMAL];
147 gs_objects.m_colTooltip = wxColor(c.red >> SHIFT, c.green >> SHIFT, c.blue >> SHIFT);
148 c = tooltips->tip_window->style->fg[GTK_STATE_NORMAL];
149 gs_objects.m_colTooltipText = wxColor(c.red >> SHIFT, c.green >> SHIFT, c.blue >> SHIFT);
5c33522f 150 gtk_object_sink(reinterpret_cast<GtkObject*>(tooltips));
c05cc2c7
RR
151}
152
0ab5e0e8 153wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
c801d85f 154{
db434467 155 switch (index)
c801d85f 156 {
db434467
RR
157 case wxSYS_COLOUR_SCROLLBAR:
158 case wxSYS_COLOUR_BACKGROUND:
db434467
RR
159 case wxSYS_COLOUR_INACTIVECAPTION:
160 case wxSYS_COLOUR_MENU:
161 case wxSYS_COLOUR_WINDOWFRAME:
162 case wxSYS_COLOUR_ACTIVEBORDER:
163 case wxSYS_COLOUR_INACTIVEBORDER:
164 case wxSYS_COLOUR_BTNFACE:
221ed576 165 case wxSYS_COLOUR_MENUBAR:
5b211fbf 166 case wxSYS_COLOUR_3DLIGHT:
a1b806b9 167 if (!gs_objects.m_colBtnFace.IsOk())
37d403aa 168 {
643ccf62 169 int red, green, blue;
dbcbe229 170 if ( !GetColourFromGTKWidget(red, green, blue) )
37d403aa 171 {
643ccf62
VZ
172 red =
173 green = 0;
174 blue = 0x9c40;
37d403aa 175 }
37d403aa 176
94a09ea5 177 gs_objects.m_colBtnFace = wxColour( red >> SHIFT,
c1ef87c3
VZ
178 green >> SHIFT,
179 blue >> SHIFT );
37d403aa 180 }
94a09ea5 181 return gs_objects.m_colBtnFace;
643ccf62 182
db434467 183 case wxSYS_COLOUR_WINDOW:
db434467 184 return *wxWHITE;
643ccf62 185
37d403aa 186 case wxSYS_COLOUR_3DDKSHADOW:
37d403aa 187 return *wxBLACK;
643ccf62 188
db434467
RR
189 case wxSYS_COLOUR_GRAYTEXT:
190 case wxSYS_COLOUR_BTNSHADOW:
37d403aa 191 //case wxSYS_COLOUR_3DSHADOW:
a1b806b9 192 if (!gs_objects.m_colBtnShadow.IsOk())
37d403aa 193 {
984152a6 194 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
94a09ea5 195 gs_objects.m_colBtnShadow =
c1ef87c3
VZ
196 wxColour((unsigned char) (faceColour.Red() * 0.666),
197 (unsigned char) (faceColour.Green() * 0.666),
198 (unsigned char) (faceColour.Blue() * 0.666));
db434467 199 }
643ccf62 200
94a09ea5 201 return gs_objects.m_colBtnShadow;
643ccf62 202
37d403aa
JS
203 case wxSYS_COLOUR_3DHIGHLIGHT:
204 //case wxSYS_COLOUR_BTNHIGHLIGHT:
37d403aa 205 return * wxWHITE;
643ccf62 206
db434467 207 case wxSYS_COLOUR_HIGHLIGHT:
a1b806b9 208 if (!gs_objects.m_colHighlight.IsOk())
db434467 209 {
643ccf62 210 int red, green, blue;
dbcbe229
VZ
211 if ( !GetColourFromGTKWidget(red, green, blue,
212 wxGTK_BUTTON,
213 GTK_STATE_SELECTED) )
e6527f9d 214 {
643ccf62
VZ
215 red =
216 green = 0;
217 blue = 0x9c40;
e6527f9d 218 }
db434467 219
94a09ea5 220 gs_objects.m_colHighlight = wxColour( red >> SHIFT,
643ccf62
VZ
221 green >> SHIFT,
222 blue >> SHIFT );
db434467 223 }
94a09ea5 224 return gs_objects.m_colHighlight;
643ccf62 225
74f55195 226 case wxSYS_COLOUR_LISTBOX:
a1b806b9 227 if (!gs_objects.m_colListBox.IsOk())
74f55195 228 {
643ccf62 229 int red, green, blue;
dbcbe229
VZ
230 if ( GetColourFromGTKWidget(red, green, blue,
231 wxGTK_LIST,
232 GTK_STATE_NORMAL,
233 wxGTK_BASE) )
74f55195 234 {
94a09ea5 235 gs_objects.m_colListBox = wxColour( red >> SHIFT,
643ccf62
VZ
236 green >> SHIFT,
237 blue >> SHIFT );
74f55195
VS
238 }
239 else
643ccf62 240 {
94a09ea5 241 gs_objects.m_colListBox = wxColour(*wxWHITE);
643ccf62 242 }
74f55195 243 }
94a09ea5 244 return gs_objects.m_colListBox;
643ccf62
VZ
245
246 case wxSYS_COLOUR_MENUTEXT:
247 case wxSYS_COLOUR_WINDOWTEXT:
248 case wxSYS_COLOUR_CAPTIONTEXT:
249 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
250 case wxSYS_COLOUR_BTNTEXT:
9f2968ad 251 case wxSYS_COLOUR_LISTBOXTEXT:
a1b806b9 252 if (!gs_objects.m_colBtnText.IsOk())
37d403aa 253 {
dbcbe229
VZ
254 int red, green, blue;
255 if ( !GetColourFromGTKWidget(red, green, blue,
256 wxGTK_BUTTON,
257 GTK_STATE_NORMAL,
258 wxGTK_FG) )
37d403aa 259 {
dbcbe229
VZ
260 red =
261 green =
262 blue = 0;
37d403aa 263 }
dbcbe229 264
94a09ea5 265 gs_objects.m_colBtnText = wxColour( red >> SHIFT,
dbcbe229
VZ
266 green >> SHIFT,
267 blue >> SHIFT );
37d403aa 268 }
94a09ea5 269 return gs_objects.m_colBtnText;
643ccf62 270
17d61cbf 271 case wxSYS_COLOUR_INFOBK:
a1b806b9 272 if (!gs_objects.m_colTooltip.IsOk()) {
c05cc2c7
RR
273 GetTooltipColors();
274 }
275 return gs_objects.m_colTooltip;
276
277 case wxSYS_COLOUR_INFOTEXT:
a1b806b9 278 if (!gs_objects.m_colTooltipText.IsOk()) {
c05cc2c7
RR
279 GetTooltipColors();
280 }
281 return gs_objects.m_colTooltipText;
17d61cbf 282
887b919b 283 case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT:
643ccf62 284 case wxSYS_COLOUR_HIGHLIGHTTEXT:
a1b806b9 285 if (!gs_objects.m_colHighlightText.IsOk())
643ccf62 286 {
984152a6 287 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
643ccf62 288 if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200)
94a09ea5 289 gs_objects.m_colHighlightText = wxColour(*wxBLACK);
643ccf62 290 else
94a09ea5 291 gs_objects.m_colHighlightText = wxColour(*wxWHITE);
643ccf62 292 }
94a09ea5 293 return gs_objects.m_colHighlightText;
643ccf62 294
643ccf62
VZ
295 case wxSYS_COLOUR_APPWORKSPACE:
296 return *wxWHITE; // ?
221ed576 297
9d6a9fdd
RR
298 case wxSYS_COLOUR_ACTIVECAPTION:
299 case wxSYS_COLOUR_MENUHILIGHT:
a1b806b9 300 if (!gs_objects.m_colMenuItemHighlight.IsOk())
9d6a9fdd
RR
301 {
302 int red, green, blue;
303 if ( !GetColourFromGTKWidget(red, green, blue,
304 wxGTK_MENUITEM,
305 GTK_STATE_SELECTED,
306 wxGTK_BG) )
307 {
308 red =
309 green =
310 blue = 0;
311 }
312
313 gs_objects.m_colMenuItemHighlight = wxColour( red >> SHIFT,
314 green >> SHIFT,
315 blue >> SHIFT );
316 }
317 return gs_objects.m_colMenuItemHighlight;
318
221ed576
VZ
319 case wxSYS_COLOUR_HOTLIGHT:
320 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
321 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
221ed576
VZ
322 // TODO
323 return *wxBLACK;
324
325 case wxSYS_COLOUR_MAX:
326 default:
9a83f860 327 wxFAIL_MSG( wxT("unknown system colour index") );
e24b680c 328 }
643ccf62 329
e24b680c 330 return *wxWHITE;
ff7b1510 331}
c801d85f 332
0ab5e0e8 333wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
c801d85f 334{
2d17d68f 335 switch (index)
c801d85f 336 {
2d17d68f
RR
337 case wxSYS_OEM_FIXED_FONT:
338 case wxSYS_ANSI_FIXED_FONT:
339 case wxSYS_SYSTEM_FIXED_FONT:
340 {
341 return *wxNORMAL_FONT;
342 }
343 case wxSYS_ANSI_VAR_FONT:
344 case wxSYS_SYSTEM_FONT:
345 case wxSYS_DEVICE_DEFAULT_FONT:
346 case wxSYS_DEFAULT_GUI_FONT:
347 {
a1b806b9 348 if (!gs_objects.m_fontSystem.IsOk())
d06b34a7 349 {
94a09ea5 350 gs_objects.m_fontSystem = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
d06b34a7 351 }
94a09ea5 352 return gs_objects.m_fontSystem;
2d17d68f 353 }
c801d85f 354
0ab5e0e8
VS
355 default:
356 return wxNullFont;
357 }
c801d85f 358}
c801d85f 359
89954433
VZ
360int
361wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win))
c801d85f 362{
1ecc4d80
RR
363 switch (index)
364 {
9b0b5ba7
RR
365 case wxSYS_CURSOR_X:
366 case wxSYS_CURSOR_Y:
3cbab641 367 return 16;
9b0b5ba7 368
f618020a
MB
369 // MBN: ditto for icons
370 case wxSYS_ICON_X: return 32;
371 case wxSYS_ICON_Y: return 32;
9b0b5ba7
RR
372
373 case wxSYS_SCREEN_X:
3cbab641 374 return gdk_screen_width();
9b0b5ba7
RR
375
376 case wxSYS_SCREEN_Y:
3cbab641 377 return gdk_screen_height();
9b0b5ba7
RR
378
379 case wxSYS_HSCROLL_Y: return 15;
380 case wxSYS_VSCROLL_X: return 15;
381
382// a gtk1 implementation should be possible too if gtk2 efficiency/convenience functions aren't used
3cbab641 383#if 0
9b0b5ba7
RR
384 case wxSYS_CAPTION_Y:
385 if (!window)
386 // No realized window specified, and no implementation for that case yet.
387 return -1;
388
389 // Check if wm supports frame extents - we can't know the caption height if it does not.
390#if GTK_CHECK_VERSION(2,2,0)
391 if (!gtk_check_version(2,2,0))
392 {
393 if (!gdk_x11_screen_supports_net_wm_hint(
394 gdk_drawable_get_screen(window),
395 gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) )
396 return -1;
397 }
398 else
399#endif
400 {
401 if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false)))
402 return -1;
403 }
404
405 wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow),
406 wxT("Asking for caption height of a non toplevel window") );
407
408 // Get the height of the top windowmanager border.
409 // This is the titlebar in most cases. The titlebar might be elsewhere, and
410 // we could check which is the thickest wm border to decide on which side the
411 // titlebar is, but this might lead to interesting behaviours in used code.
412 // Reconsider when we have a way to report to the user on which side it is.
413
414 Atom type;
415 gint format;
416 gulong nitems;
9b0b5ba7 417
5ac8ce9e
RR
418#if GTK_CHECK_VERSION(2,2,0)
419 if (!gtk_check_version(2,2,0))
420 {
421 gulong bytes_after;
422 success = (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window)),
9b0b5ba7
RR
423 GDK_WINDOW_XWINDOW(window),
424 gdk_x11_get_xatom_by_name_for_display (
425 gdk_drawable_get_display(window),
426 "_NET_FRAME_EXTENTS" ),
427 0, // left, right, top, bottom, CARDINAL[4]/32
428 G_MAXLONG, // size of long
429 false, // do not delete property
430 XA_CARDINAL, // 32 bit
431 &type, &format, &nitems, &bytes_after, &data
5ac8ce9e
RR
432 ) == Success);
433 }
434#endif
435 if (success)
9b0b5ba7
RR
436 {
437 int caption_height = -1;
438
439 if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 3) && (data))
440 {
441 long *borders;
442 borders = (long*)data;
443 caption_height = borders[2]; // top frame extent
444 }
445
446 if (data)
447 XFree(data);
448
449 return caption_height;
450 }
451
452 // Try a default approach without a window pointer, if possible
453 // ...
454
455 return -1;
456#endif // gtk2
457
458 case wxSYS_PENWINDOWS_PRESENT:
459 // No MS Windows for Pen computing extension available in X11 based gtk+.
460 return 0;
461
462 default:
1d451c5b 463 return -1; // metric is unknown
1ecc4d80 464 }
c67daf87 465}
253293c1 466
0ab5e0e8 467bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1
VS
468{
469 switch (index)
470 {
17a1ebd1 471 case wxSYS_CAN_ICONIZE_FRAME:
e7c80f9e 472 return false;
17a1ebd1 473
253293c1 474 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
e7c80f9e 475 return true;
17a1ebd1 476
253293c1 477 default:
e7c80f9e 478 return false;
253293c1
VS
479 }
480}