]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
3523b9cf | 2 | // Name: gtk/settings.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
9b0b5ba7 | 5 | // Modified by: Mart Raudsepp (GetMetric) |
f96aa4d9 RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
13 | #pragma implementation "settings.h" |
14 | #endif | |
15 | ||
14f355c2 VS |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
c801d85f | 19 | #include "wx/settings.h" |
1ecc4d80 | 20 | #include "wx/debug.h" |
d06b34a7 | 21 | #include "wx/cmndata.h" |
2b5f62a0 | 22 | #include "wx/fontutil.h" |
9b0b5ba7 | 23 | #include "wx/toplevel.h" |
d06b34a7 | 24 | |
aed8ac3f | 25 | #include <gdk/gdk.h> |
9b0b5ba7 | 26 | #include <gdk/gdkx.h> |
d06b34a7 | 27 | #include <gdk/gdkprivate.h> |
aed8ac3f | 28 | #include <gtk/gtk.h> |
83624f79 | 29 | |
9b0b5ba7 RR |
30 | #include <X11/Xatom.h> |
31 | ||
c801d85f KB |
32 | #define SHIFT (8*(sizeof(short int)-sizeof(char))) |
33 | ||
0ab5e0e8 | 34 | // ---------------------------------------------------------------------------- |
94a09ea5 | 35 | // wxSystemObjects |
0ab5e0e8 VS |
36 | // ---------------------------------------------------------------------------- |
37 | ||
94a09ea5 | 38 | struct wxSystemObjects |
1ecc4d80 | 39 | { |
c1ef87c3 VZ |
40 | wxColour m_colBtnFace, |
41 | m_colBtnShadow, | |
42 | m_colBtnHighlight, | |
43 | m_colHighlight, | |
44 | m_colHighlightText, | |
45 | m_colListBox, | |
9d6a9fdd RR |
46 | m_colBtnText, |
47 | m_colMenuItemHighlight; | |
c1ef87c3 VZ |
48 | |
49 | wxFont m_fontSystem; | |
0ab5e0e8 VS |
50 | }; |
51 | ||
94a09ea5 | 52 | static wxSystemObjects gs_objects; |
c1ef87c3 | 53 | |
0ab5e0e8 VS |
54 | // ---------------------------------------------------------------------------- |
55 | // wxSystemSettings implementation | |
56 | // ---------------------------------------------------------------------------- | |
a3622daa | 57 | |
643ccf62 | 58 | // kind of widget to use in GetColourFromGTKWidget |
dbcbe229 | 59 | enum wxGtkWidgetType |
643ccf62 | 60 | { |
dbcbe229 | 61 | wxGTK_BUTTON, |
9d6a9fdd RR |
62 | wxGTK_LIST, |
63 | wxGTK_MENUITEM | |
dbcbe229 VZ |
64 | }; |
65 | ||
66 | // the colour we need | |
67 | enum wxGtkColourType | |
68 | { | |
69 | wxGTK_FG, | |
70 | wxGTK_BG, | |
71 | wxGTK_BASE | |
643ccf62 VZ |
72 | }; |
73 | ||
984152a6 | 74 | // wxSystemSettings::GetColour() helper: get the colours from a GTK+ |
643ccf62 | 75 | // widget style, return true if we did get them, false to use defaults |
dbcbe229 VZ |
76 | static bool GetColourFromGTKWidget(int& red, int& green, int& blue, |
77 | wxGtkWidgetType type = wxGTK_BUTTON, | |
78 | GtkStateType state = GTK_STATE_NORMAL, | |
79 | wxGtkColourType colour = wxGTK_BG) | |
643ccf62 | 80 | { |
dbcbe229 VZ |
81 | GtkWidget *widget; |
82 | switch ( type ) | |
83 | { | |
84 | default: | |
85 | wxFAIL_MSG( _T("unexpected GTK widget type") ); | |
86 | // fall through | |
87 | ||
88 | case wxGTK_BUTTON: | |
89 | widget = gtk_button_new(); | |
90 | break; | |
91 | ||
92 | case wxGTK_LIST: | |
93 | widget = gtk_list_new(); | |
9d6a9fdd RR |
94 | |
95 | case wxGTK_MENUITEM: | |
96 | widget = gtk_menu_item_new(); | |
dbcbe229 VZ |
97 | } |
98 | ||
643ccf62 VZ |
99 | GtkStyle *def = gtk_rc_get_style( widget ); |
100 | if ( !def ) | |
101 | def = gtk_widget_get_default_style(); | |
102 | ||
103 | bool ok; | |
104 | if ( def ) | |
105 | { | |
dbcbe229 VZ |
106 | GdkColor *col; |
107 | switch ( colour ) | |
108 | { | |
109 | default: | |
110 | wxFAIL_MSG( _T("unexpected GTK colour type") ); | |
111 | // fall through | |
112 | ||
113 | case wxGTK_FG: | |
114 | col = def->fg; | |
115 | break; | |
116 | ||
117 | case wxGTK_BG: | |
118 | col = def->bg; | |
119 | break; | |
120 | ||
121 | case wxGTK_BASE: | |
122 | col = def->base; | |
123 | break; | |
124 | } | |
125 | ||
3523b9cf VZ |
126 | red = col[state].red; |
127 | green = col[state].green; | |
128 | blue = col[state].blue; | |
643ccf62 VZ |
129 | |
130 | ok = TRUE; | |
131 | } | |
132 | else | |
133 | { | |
134 | ok = FALSE; | |
135 | } | |
136 | ||
137 | gtk_widget_destroy( widget ); | |
138 | ||
139 | return ok; | |
140 | } | |
141 | ||
0ab5e0e8 | 142 | wxColour wxSystemSettingsNative::GetColour( wxSystemColour index ) |
c801d85f | 143 | { |
db434467 | 144 | switch (index) |
c801d85f | 145 | { |
db434467 RR |
146 | case wxSYS_COLOUR_SCROLLBAR: |
147 | case wxSYS_COLOUR_BACKGROUND: | |
db434467 RR |
148 | case wxSYS_COLOUR_INACTIVECAPTION: |
149 | case wxSYS_COLOUR_MENU: | |
150 | case wxSYS_COLOUR_WINDOWFRAME: | |
151 | case wxSYS_COLOUR_ACTIVEBORDER: | |
152 | case wxSYS_COLOUR_INACTIVEBORDER: | |
153 | case wxSYS_COLOUR_BTNFACE: | |
221ed576 | 154 | case wxSYS_COLOUR_MENUBAR: |
5b211fbf | 155 | case wxSYS_COLOUR_3DLIGHT: |
94a09ea5 | 156 | if (!gs_objects.m_colBtnFace.Ok()) |
37d403aa | 157 | { |
643ccf62 | 158 | int red, green, blue; |
dbcbe229 | 159 | if ( !GetColourFromGTKWidget(red, green, blue) ) |
37d403aa | 160 | { |
643ccf62 VZ |
161 | red = |
162 | green = 0; | |
163 | blue = 0x9c40; | |
37d403aa | 164 | } |
37d403aa | 165 | |
94a09ea5 | 166 | gs_objects.m_colBtnFace = wxColour( red >> SHIFT, |
c1ef87c3 VZ |
167 | green >> SHIFT, |
168 | blue >> SHIFT ); | |
37d403aa | 169 | } |
94a09ea5 | 170 | return gs_objects.m_colBtnFace; |
643ccf62 | 171 | |
db434467 | 172 | case wxSYS_COLOUR_WINDOW: |
db434467 | 173 | return *wxWHITE; |
643ccf62 | 174 | |
37d403aa | 175 | case wxSYS_COLOUR_3DDKSHADOW: |
37d403aa | 176 | return *wxBLACK; |
643ccf62 | 177 | |
db434467 RR |
178 | case wxSYS_COLOUR_GRAYTEXT: |
179 | case wxSYS_COLOUR_BTNSHADOW: | |
37d403aa | 180 | //case wxSYS_COLOUR_3DSHADOW: |
94a09ea5 | 181 | if (!gs_objects.m_colBtnShadow.Ok()) |
37d403aa | 182 | { |
984152a6 | 183 | wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE)); |
94a09ea5 | 184 | gs_objects.m_colBtnShadow = |
c1ef87c3 VZ |
185 | wxColour((unsigned char) (faceColour.Red() * 0.666), |
186 | (unsigned char) (faceColour.Green() * 0.666), | |
187 | (unsigned char) (faceColour.Blue() * 0.666)); | |
db434467 | 188 | } |
643ccf62 | 189 | |
94a09ea5 | 190 | return gs_objects.m_colBtnShadow; |
643ccf62 | 191 | |
37d403aa JS |
192 | case wxSYS_COLOUR_3DHIGHLIGHT: |
193 | //case wxSYS_COLOUR_BTNHIGHLIGHT: | |
37d403aa | 194 | return * wxWHITE; |
643ccf62 | 195 | |
db434467 | 196 | case wxSYS_COLOUR_HIGHLIGHT: |
94a09ea5 | 197 | if (!gs_objects.m_colHighlight.Ok()) |
db434467 | 198 | { |
643ccf62 | 199 | int red, green, blue; |
dbcbe229 VZ |
200 | if ( !GetColourFromGTKWidget(red, green, blue, |
201 | wxGTK_BUTTON, | |
202 | GTK_STATE_SELECTED) ) | |
e6527f9d | 203 | { |
643ccf62 VZ |
204 | red = |
205 | green = 0; | |
206 | blue = 0x9c40; | |
e6527f9d | 207 | } |
db434467 | 208 | |
94a09ea5 | 209 | gs_objects.m_colHighlight = wxColour( red >> SHIFT, |
643ccf62 VZ |
210 | green >> SHIFT, |
211 | blue >> SHIFT ); | |
db434467 | 212 | } |
94a09ea5 | 213 | return gs_objects.m_colHighlight; |
643ccf62 | 214 | |
74f55195 | 215 | case wxSYS_COLOUR_LISTBOX: |
94a09ea5 | 216 | if (!gs_objects.m_colListBox.Ok()) |
74f55195 | 217 | { |
643ccf62 | 218 | int red, green, blue; |
dbcbe229 VZ |
219 | if ( GetColourFromGTKWidget(red, green, blue, |
220 | wxGTK_LIST, | |
221 | GTK_STATE_NORMAL, | |
222 | wxGTK_BASE) ) | |
74f55195 | 223 | { |
94a09ea5 | 224 | gs_objects.m_colListBox = wxColour( red >> SHIFT, |
643ccf62 VZ |
225 | green >> SHIFT, |
226 | blue >> SHIFT ); | |
74f55195 VS |
227 | } |
228 | else | |
643ccf62 | 229 | { |
94a09ea5 | 230 | gs_objects.m_colListBox = wxColour(*wxWHITE); |
643ccf62 | 231 | } |
74f55195 | 232 | } |
94a09ea5 | 233 | return gs_objects.m_colListBox; |
643ccf62 VZ |
234 | |
235 | case wxSYS_COLOUR_MENUTEXT: | |
236 | case wxSYS_COLOUR_WINDOWTEXT: | |
237 | case wxSYS_COLOUR_CAPTIONTEXT: | |
238 | case wxSYS_COLOUR_INACTIVECAPTIONTEXT: | |
239 | case wxSYS_COLOUR_BTNTEXT: | |
240 | case wxSYS_COLOUR_INFOTEXT: | |
94a09ea5 | 241 | if (!gs_objects.m_colBtnText.Ok()) |
37d403aa | 242 | { |
dbcbe229 VZ |
243 | int red, green, blue; |
244 | if ( !GetColourFromGTKWidget(red, green, blue, | |
245 | wxGTK_BUTTON, | |
246 | GTK_STATE_NORMAL, | |
247 | wxGTK_FG) ) | |
37d403aa | 248 | { |
dbcbe229 VZ |
249 | red = |
250 | green = | |
251 | blue = 0; | |
37d403aa | 252 | } |
dbcbe229 | 253 | |
94a09ea5 | 254 | gs_objects.m_colBtnText = wxColour( red >> SHIFT, |
dbcbe229 VZ |
255 | green >> SHIFT, |
256 | blue >> SHIFT ); | |
37d403aa | 257 | } |
94a09ea5 | 258 | return gs_objects.m_colBtnText; |
643ccf62 | 259 | |
17d61cbf VZ |
260 | // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for |
261 | // tooltip windows - Robert, please change this code to use the | |
262 | // real GTK tooltips when/if you can (TODO) | |
263 | case wxSYS_COLOUR_INFOBK: | |
264 | return wxColour(255, 255, 225); | |
265 | ||
643ccf62 | 266 | case wxSYS_COLOUR_HIGHLIGHTTEXT: |
94a09ea5 | 267 | if (!gs_objects.m_colHighlightText.Ok()) |
643ccf62 | 268 | { |
984152a6 | 269 | wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT); |
643ccf62 | 270 | if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200) |
94a09ea5 | 271 | gs_objects.m_colHighlightText = wxColour(*wxBLACK); |
643ccf62 | 272 | else |
94a09ea5 | 273 | gs_objects.m_colHighlightText = wxColour(*wxWHITE); |
643ccf62 | 274 | } |
94a09ea5 | 275 | return gs_objects.m_colHighlightText; |
643ccf62 | 276 | |
643ccf62 VZ |
277 | case wxSYS_COLOUR_APPWORKSPACE: |
278 | return *wxWHITE; // ? | |
221ed576 | 279 | |
9d6a9fdd RR |
280 | case wxSYS_COLOUR_ACTIVECAPTION: |
281 | case wxSYS_COLOUR_MENUHILIGHT: | |
282 | if (!gs_objects.m_colMenuItemHighlight.Ok()) | |
283 | { | |
284 | int red, green, blue; | |
285 | if ( !GetColourFromGTKWidget(red, green, blue, | |
286 | wxGTK_MENUITEM, | |
287 | GTK_STATE_SELECTED, | |
288 | wxGTK_BG) ) | |
289 | { | |
290 | red = | |
291 | green = | |
292 | blue = 0; | |
293 | } | |
294 | ||
295 | gs_objects.m_colMenuItemHighlight = wxColour( red >> SHIFT, | |
296 | green >> SHIFT, | |
297 | blue >> SHIFT ); | |
298 | } | |
299 | return gs_objects.m_colMenuItemHighlight; | |
300 | ||
221ed576 VZ |
301 | case wxSYS_COLOUR_HOTLIGHT: |
302 | case wxSYS_COLOUR_GRADIENTACTIVECAPTION: | |
303 | case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: | |
221ed576 VZ |
304 | // TODO |
305 | return *wxBLACK; | |
306 | ||
307 | case wxSYS_COLOUR_MAX: | |
308 | default: | |
309 | wxFAIL_MSG( _T("unknown system colour index") ); | |
ff7b1510 | 310 | } |
643ccf62 | 311 | |
c801d85f | 312 | return *wxWHITE; |
ff7b1510 | 313 | } |
c801d85f | 314 | |
0ab5e0e8 | 315 | wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) |
c801d85f | 316 | { |
2d17d68f | 317 | switch (index) |
c801d85f | 318 | { |
2d17d68f RR |
319 | case wxSYS_OEM_FIXED_FONT: |
320 | case wxSYS_ANSI_FIXED_FONT: | |
321 | case wxSYS_SYSTEM_FIXED_FONT: | |
322 | { | |
323 | return *wxNORMAL_FONT; | |
324 | } | |
325 | case wxSYS_ANSI_VAR_FONT: | |
326 | case wxSYS_SYSTEM_FONT: | |
327 | case wxSYS_DEVICE_DEFAULT_FONT: | |
328 | case wxSYS_DEFAULT_GUI_FONT: | |
329 | { | |
94a09ea5 | 330 | if (!gs_objects.m_fontSystem.Ok()) |
d06b34a7 | 331 | { |
2b5f62a0 | 332 | #ifdef __WXGTK20__ |
e7370dac VS |
333 | GtkWidget *widget = gtk_button_new(); |
334 | GtkStyle *def = gtk_rc_get_style( widget ); | |
2269ff56 | 335 | if ( !def || !def->font_desc ) |
e7370dac | 336 | def = gtk_widget_get_default_style(); |
2269ff56 | 337 | if ( def && def->font_desc ) |
e7370dac VS |
338 | { |
339 | wxNativeFontInfo info; | |
fdf7514a VS |
340 | info.description = |
341 | pango_font_description_copy(def->font_desc); | |
94a09ea5 | 342 | gs_objects.m_fontSystem = wxFont(info); |
e7370dac VS |
343 | } |
344 | else | |
345 | { | |
119cd341 RR |
346 | GtkSettings *settings = gtk_settings_get_default(); |
347 | gchar *font_name = NULL; | |
348 | g_object_get ( settings, | |
349 | "gtk-font-name", | |
350 | &font_name, | |
351 | NULL); | |
352 | if (!font_name) | |
353 | gs_objects.m_fontSystem = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); | |
354 | else | |
355 | gs_objects.m_fontSystem = wxFont(wxString::FromAscii(font_name)); | |
356 | g_free (font_name); | |
e7370dac VS |
357 | } |
358 | gtk_widget_destroy( widget ); | |
2b5f62a0 | 359 | #else |
94a09ea5 | 360 | gs_objects.m_fontSystem = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); |
2b5f62a0 | 361 | #endif |
d06b34a7 | 362 | } |
94a09ea5 | 363 | return gs_objects.m_fontSystem; |
2d17d68f | 364 | } |
c801d85f | 365 | |
0ab5e0e8 VS |
366 | default: |
367 | return wxNullFont; | |
368 | } | |
c801d85f | 369 | } |
c801d85f | 370 | |
9b0b5ba7 | 371 | int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) |
c801d85f | 372 | { |
9b0b5ba7 RR |
373 | #ifdef __WXGTK20__ |
374 | guchar *data = NULL; | |
375 | GdkWindow *window = NULL; | |
376 | if(win && GTK_WIDGET_REALIZED(win->GetHandle())) | |
377 | window = win->GetHandle()->window; | |
378 | #endif | |
379 | ||
1ecc4d80 RR |
380 | switch (index) |
381 | { | |
9b0b5ba7 RR |
382 | case wxSYS_BORDER_X: |
383 | case wxSYS_BORDER_Y: | |
384 | case wxSYS_EDGE_X: | |
385 | case wxSYS_EDGE_Y: | |
386 | case wxSYS_FRAMESIZE_X: | |
387 | case wxSYS_FRAMESIZE_Y: | |
388 | // If a window is specified/realized, and it is a toplevel window, we can query from wm. | |
389 | // The returned border thickness is outside the client area in that case. | |
390 | if (window) | |
391 | { | |
392 | wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); | |
393 | if (!tlw) | |
394 | return -1; // not a tlw, not sure how to approach | |
395 | else | |
396 | { | |
397 | // Check if wm supports frame extents - we can't know | |
398 | // the border widths if it does not. | |
399 | #if GTK_CHECK_VERSION(2,2,0) | |
400 | if (!gtk_check_version(2,2,0)) | |
401 | { | |
402 | if (!gdk_x11_screen_supports_net_wm_hint( | |
403 | gdk_drawable_get_screen(window), | |
404 | gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) ) | |
405 | return -1; | |
406 | } | |
407 | else | |
408 | #endif | |
409 | { | |
410 | if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false))) | |
411 | return -1; | |
412 | } | |
413 | ||
414 | // Get the frame extents from the windowmanager. | |
415 | // In most cases the top extent is the titlebar, so we use the bottom extent | |
416 | // for the heights. | |
417 | ||
418 | Atom type; | |
419 | gint format; | |
420 | gulong nitems; | |
421 | gulong bytes_after; | |
422 | ||
423 | if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window)), | |
424 | GDK_WINDOW_XWINDOW(window), | |
425 | gdk_x11_get_xatom_by_name_for_display ( | |
426 | gdk_drawable_get_display(window), | |
427 | "_NET_FRAME_EXTENTS" ), | |
428 | 0, // left, right, top, bottom, CARDINAL[4]/32 | |
429 | G_MAXLONG, // size of long | |
430 | false, // do not delete property | |
431 | XA_CARDINAL, // 32 bit | |
432 | &type, &format, &nitems, &bytes_after, &data | |
433 | ) == Success) | |
434 | { | |
435 | int border_return = -1; | |
436 | ||
437 | if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 4) && (data)) | |
438 | { | |
439 | long *borders; | |
440 | borders = (long*)data; | |
441 | switch(index) | |
442 | { | |
443 | case wxSYS_BORDER_X: | |
444 | case wxSYS_EDGE_X: | |
445 | case wxSYS_FRAMESIZE_X: | |
446 | border_return = borders[1]; // width of right extent | |
447 | break; | |
448 | default: | |
449 | border_return = borders[3]; // height of bottom extent | |
450 | break; | |
451 | } | |
452 | } | |
453 | ||
454 | if (data) | |
455 | XFree(data); | |
456 | ||
457 | return border_return; | |
458 | } | |
459 | } | |
460 | } | |
461 | ||
462 | return -1; // no window specified | |
463 | ||
464 | case wxSYS_CURSOR_X: | |
465 | case wxSYS_CURSOR_Y: | |
466 | #ifdef __WXGTK24__ | |
467 | if (!gtk_check_version(2,4,0)) | |
468 | { | |
469 | if (window) | |
470 | return gdk_display_get_default_cursor_size(gdk_drawable_get_display(window)); | |
471 | else | |
472 | return gdk_display_get_default_cursor_size(gdk_display_get_default()); | |
473 | } | |
474 | else | |
475 | #endif | |
476 | return 16; | |
17d61cbf | 477 | |
9b0b5ba7 | 478 | #ifdef __WXGTK20__ |
44fd6f72 VS |
479 | case wxSYS_DCLICK_X: |
480 | case wxSYS_DCLICK_Y: | |
481 | gint dclick_distance; | |
9b0b5ba7 RR |
482 | #if GTK_CHECK_VERSION(2,2,0) |
483 | if (window && !gtk_check_version(2,2,0)) | |
484 | g_object_get(gtk_settings_get_for_screen(gdk_drawable_get_screen(window)), | |
485 | "gtk-double-click-distance", &dclick_distance, NULL); | |
486 | else | |
44fd6f72 | 487 | #endif |
9b0b5ba7 RR |
488 | g_object_get(gtk_settings_get_default(), |
489 | "gtk-double-click-distance", &dclick_distance, NULL); | |
490 | ||
491 | return dclick_distance * 2; | |
492 | #endif // gtk2 | |
44fd6f72 | 493 | |
9b0b5ba7 | 494 | #ifdef __WXGTK20__ |
44fd6f72 VS |
495 | case wxSYS_DRAG_X: |
496 | case wxSYS_DRAG_Y: | |
497 | gint drag_threshold; | |
9b0b5ba7 RR |
498 | #if GTK_CHECK_VERSION(2,2,0) |
499 | if (window && !gtk_check_version(2,2,0)) | |
500 | { | |
501 | g_object_get( | |
502 | gtk_settings_get_for_screen(gdk_drawable_get_screen(window)), | |
503 | "gtk-dnd-drag-threshold", | |
504 | &drag_threshold, NULL); | |
505 | } | |
506 | else | |
44fd6f72 | 507 | #endif |
9b0b5ba7 RR |
508 | { |
509 | g_object_get(gtk_settings_get_default(), | |
510 | "gtk-dnd-drag-threshold", &drag_threshold, NULL); | |
511 | } | |
44fd6f72 | 512 | |
9b0b5ba7 | 513 | return drag_threshold * 2; |
44fd6f72 | 514 | #endif |
9b0b5ba7 | 515 | |
f618020a MB |
516 | // MBN: ditto for icons |
517 | case wxSYS_ICON_X: return 32; | |
518 | case wxSYS_ICON_Y: return 32; | |
9b0b5ba7 RR |
519 | |
520 | case wxSYS_SCREEN_X: | |
521 | #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2,2,0) | |
522 | if (window && !gtk_check_version(2,2,0)) | |
523 | return gdk_screen_get_width(gdk_drawable_get_screen(window)); | |
524 | else | |
525 | #endif | |
526 | return gdk_screen_width(); | |
527 | ||
528 | case wxSYS_SCREEN_Y: | |
529 | #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2,2,0) | |
530 | if (window && !gtk_check_version(2,2,0)) | |
531 | return gdk_screen_get_height(gdk_drawable_get_screen(window)); | |
532 | else | |
533 | #endif | |
534 | return gdk_screen_height(); | |
535 | ||
536 | case wxSYS_HSCROLL_Y: return 15; | |
537 | case wxSYS_VSCROLL_X: return 15; | |
538 | ||
539 | // a gtk1 implementation should be possible too if gtk2 efficiency/convenience functions aren't used | |
540 | #ifdef __WXGTK20__ | |
541 | case wxSYS_CAPTION_Y: | |
542 | if (!window) | |
543 | // No realized window specified, and no implementation for that case yet. | |
544 | return -1; | |
545 | ||
546 | // Check if wm supports frame extents - we can't know the caption height if it does not. | |
547 | #if GTK_CHECK_VERSION(2,2,0) | |
548 | if (!gtk_check_version(2,2,0)) | |
549 | { | |
550 | if (!gdk_x11_screen_supports_net_wm_hint( | |
551 | gdk_drawable_get_screen(window), | |
552 | gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) ) | |
553 | return -1; | |
554 | } | |
555 | else | |
556 | #endif | |
557 | { | |
558 | if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false))) | |
559 | return -1; | |
560 | } | |
561 | ||
562 | wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), | |
563 | wxT("Asking for caption height of a non toplevel window") ); | |
564 | ||
565 | // Get the height of the top windowmanager border. | |
566 | // This is the titlebar in most cases. The titlebar might be elsewhere, and | |
567 | // we could check which is the thickest wm border to decide on which side the | |
568 | // titlebar is, but this might lead to interesting behaviours in used code. | |
569 | // Reconsider when we have a way to report to the user on which side it is. | |
570 | ||
571 | Atom type; | |
572 | gint format; | |
573 | gulong nitems; | |
574 | gulong bytes_after; | |
575 | ||
576 | if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window)), | |
577 | GDK_WINDOW_XWINDOW(window), | |
578 | gdk_x11_get_xatom_by_name_for_display ( | |
579 | gdk_drawable_get_display(window), | |
580 | "_NET_FRAME_EXTENTS" ), | |
581 | 0, // left, right, top, bottom, CARDINAL[4]/32 | |
582 | G_MAXLONG, // size of long | |
583 | false, // do not delete property | |
584 | XA_CARDINAL, // 32 bit | |
585 | &type, &format, &nitems, &bytes_after, &data | |
586 | ) == Success) | |
587 | { | |
588 | int caption_height = -1; | |
589 | ||
590 | if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 3) && (data)) | |
591 | { | |
592 | long *borders; | |
593 | borders = (long*)data; | |
594 | caption_height = borders[2]; // top frame extent | |
595 | } | |
596 | ||
597 | if (data) | |
598 | XFree(data); | |
599 | ||
600 | return caption_height; | |
601 | } | |
602 | ||
603 | // Try a default approach without a window pointer, if possible | |
604 | // ... | |
605 | ||
606 | return -1; | |
607 | #endif // gtk2 | |
608 | ||
609 | case wxSYS_PENWINDOWS_PRESENT: | |
610 | // No MS Windows for Pen computing extension available in X11 based gtk+. | |
611 | return 0; | |
612 | ||
613 | default: | |
1d451c5b | 614 | return -1; // metric is unknown |
1ecc4d80 | 615 | } |
c67daf87 | 616 | } |
253293c1 | 617 | |
0ab5e0e8 | 618 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 VS |
619 | { |
620 | switch (index) | |
621 | { | |
622 | case wxSYS_CAN_ICONIZE_FRAME: | |
0ab5e0e8 VS |
623 | return FALSE; |
624 | break; | |
253293c1 | 625 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
0ab5e0e8 VS |
626 | return TRUE; |
627 | break; | |
253293c1 VS |
628 | default: |
629 | return FALSE; | |
630 | } | |
631 | } |