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