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