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