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