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