]>
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 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f | 13 | #include "wx/settings.h" |
e7c80f9e | 14 | |
ce5d92e1 | 15 | #ifndef WX_PRECOMP |
1832043f | 16 | #include "wx/toplevel.h" |
ce5d92e1 WS |
17 | #endif |
18 | ||
2b5f62a0 | 19 | #include "wx/fontutil.h" |
e3527f7b | 20 | #include "wx/fontenum.h" |
d06b34a7 | 21 | |
aed8ac3f | 22 | #include <gtk/gtk.h> |
53357e24 | 23 | #include "wx/gtk/private/win_gtk.h" |
385e8575 | 24 | #include "wx/gtk/private/gtk2-compat.h" |
83624f79 | 25 | |
166b4de7 | 26 | bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom); |
9b0b5ba7 | 27 | |
0ab5e0e8 | 28 | // ---------------------------------------------------------------------------- |
0d0b57ac | 29 | // wxSystemSettings implementation |
0ab5e0e8 VS |
30 | // ---------------------------------------------------------------------------- |
31 | ||
0d0b57ac PC |
32 | static wxFont gs_fontSystem; |
33 | ||
34 | static GtkContainer* ContainerWidget() | |
a51d7c4b | 35 | { |
0d0b57ac PC |
36 | static GtkContainer* s_widget; |
37 | if (s_widget == NULL) | |
38 | { | |
39 | s_widget = GTK_CONTAINER(gtk_fixed_new()); | |
40 | GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
41 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(s_widget)); | |
42 | } | |
43 | return s_widget; | |
a51d7c4b JS |
44 | } |
45 | ||
0d0b57ac | 46 | extern "C" { |
9dc44eff PC |
47 | #ifdef __WXGTK3__ |
48 | static void style_updated(GtkWidget*, void*) | |
49 | #else | |
0d0b57ac | 50 | static void style_set(GtkWidget*, GtkStyle*, void*) |
9dc44eff | 51 | #endif |
643ccf62 | 52 | { |
0d0b57ac PC |
53 | gs_fontSystem = wxNullFont; |
54 | } | |
55 | } | |
56 | ||
9dc44eff | 57 | static GtkWidget* ButtonWidget() |
643ccf62 | 58 | { |
0d0b57ac PC |
59 | static GtkWidget* s_widget; |
60 | if (s_widget == NULL) | |
dbcbe229 | 61 | { |
0d0b57ac PC |
62 | s_widget = gtk_button_new(); |
63 | gtk_container_add(ContainerWidget(), s_widget); | |
9dc44eff PC |
64 | #ifdef __WXGTK3__ |
65 | g_signal_connect(s_widget, "style_updated", G_CALLBACK(style_updated), NULL); | |
66 | #else | |
0d0b57ac PC |
67 | gtk_widget_ensure_style(s_widget); |
68 | g_signal_connect(s_widget, "style_set", G_CALLBACK(style_set), NULL); | |
9dc44eff | 69 | #endif |
dbcbe229 | 70 | } |
9dc44eff | 71 | return s_widget; |
0d0b57ac | 72 | } |
dbcbe229 | 73 | |
9dc44eff | 74 | static GtkWidget* ListWidget() |
0d0b57ac PC |
75 | { |
76 | static GtkWidget* s_widget; | |
77 | if (s_widget == NULL) | |
78 | { | |
79 | s_widget = gtk_tree_view_new_with_model( | |
80 | GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_INT))); | |
81 | gtk_container_add(ContainerWidget(), s_widget); | |
9dc44eff | 82 | #ifndef __WXGTK3__ |
0d0b57ac | 83 | gtk_widget_ensure_style(s_widget); |
9dc44eff | 84 | #endif |
0d0b57ac | 85 | } |
9dc44eff | 86 | return s_widget; |
0d0b57ac | 87 | } |
643ccf62 | 88 | |
9dc44eff | 89 | static GtkWidget* TextCtrlWidget() |
0d0b57ac PC |
90 | { |
91 | static GtkWidget* s_widget; | |
92 | if (s_widget == NULL) | |
643ccf62 | 93 | { |
0d0b57ac PC |
94 | s_widget = gtk_text_view_new(); |
95 | gtk_container_add(ContainerWidget(), s_widget); | |
9dc44eff | 96 | #ifndef __WXGTK3__ |
0d0b57ac | 97 | gtk_widget_ensure_style(s_widget); |
9dc44eff | 98 | #endif |
643ccf62 | 99 | } |
9dc44eff | 100 | return s_widget; |
0d0b57ac | 101 | } |
643ccf62 | 102 | |
9dc44eff | 103 | static GtkWidget* MenuItemWidget() |
0d0b57ac PC |
104 | { |
105 | static GtkWidget* s_widget; | |
106 | if (s_widget == NULL) | |
107 | { | |
108 | s_widget = gtk_menu_item_new(); | |
109 | gtk_container_add(ContainerWidget(), s_widget); | |
9dc44eff | 110 | #ifndef __WXGTK3__ |
0d0b57ac | 111 | gtk_widget_ensure_style(s_widget); |
9dc44eff | 112 | #endif |
0d0b57ac | 113 | } |
9dc44eff | 114 | return s_widget; |
0d0b57ac | 115 | } |
643ccf62 | 116 | |
9dc44eff | 117 | static GtkWidget* MenuBarWidget() |
0d0b57ac PC |
118 | { |
119 | static GtkWidget* s_widget; | |
120 | if (s_widget == NULL) | |
121 | { | |
122 | s_widget = gtk_menu_bar_new(); | |
123 | gtk_container_add(ContainerWidget(), s_widget); | |
9dc44eff | 124 | #ifndef __WXGTK3__ |
0d0b57ac | 125 | gtk_widget_ensure_style(s_widget); |
9dc44eff | 126 | #endif |
0d0b57ac | 127 | } |
9dc44eff | 128 | return s_widget; |
643ccf62 VZ |
129 | } |
130 | ||
9dc44eff | 131 | static GtkWidget* ToolTipWidget() |
c05cc2c7 | 132 | { |
0d0b57ac PC |
133 | static GtkWidget* s_widget; |
134 | if (s_widget == NULL) | |
135 | { | |
136 | s_widget = gtk_window_new(GTK_WINDOW_POPUP); | |
137 | const char* name = "gtk-tooltip"; | |
9dc44eff | 138 | #ifndef __WXGTK3__ |
0d0b57ac PC |
139 | if (gtk_check_version(2, 11, 0)) |
140 | name = "gtk-tooltips"; | |
9dc44eff | 141 | #endif |
0d0b57ac | 142 | gtk_widget_set_name(s_widget, name); |
9dc44eff | 143 | #ifndef __WXGTK3__ |
0d0b57ac | 144 | gtk_widget_ensure_style(s_widget); |
9dc44eff PC |
145 | #endif |
146 | } | |
147 | return s_widget; | |
148 | } | |
149 | ||
150 | #ifdef __WXGTK3__ | |
151 | static void bg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) | |
152 | { | |
153 | GtkStyleContext* sc = gtk_widget_get_style_context(widget); | |
154 | gtk_style_context_get_background_color(sc, state, &gdkRGBA); | |
155 | } | |
156 | static void fg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) | |
157 | { | |
158 | GtkStyleContext* sc = gtk_widget_get_style_context(widget); | |
159 | gtk_style_context_get_color(sc, state, &gdkRGBA); | |
160 | } | |
161 | static void border(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) | |
162 | { | |
163 | GtkStyleContext* sc = gtk_widget_get_style_context(widget); | |
164 | gtk_style_context_get_border_color(sc, state, &gdkRGBA); | |
165 | } | |
166 | ||
167 | wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) | |
168 | { | |
169 | GdkRGBA gdkRGBA = { 0, 0, 0, 1 }; | |
170 | switch (index) | |
171 | { | |
172 | case wxSYS_COLOUR_3DLIGHT: | |
173 | case wxSYS_COLOUR_ACTIVEBORDER: | |
174 | case wxSYS_COLOUR_BTNFACE: | |
175 | case wxSYS_COLOUR_DESKTOP: | |
176 | case wxSYS_COLOUR_INACTIVEBORDER: | |
177 | case wxSYS_COLOUR_INACTIVECAPTION: | |
178 | case wxSYS_COLOUR_SCROLLBAR: | |
179 | case wxSYS_COLOUR_WINDOWFRAME: | |
180 | bg(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
181 | break; | |
182 | case wxSYS_COLOUR_BTNHIGHLIGHT: | |
183 | case wxSYS_COLOUR_HIGHLIGHT: | |
184 | bg(ButtonWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA); | |
185 | break; | |
186 | case wxSYS_COLOUR_BTNSHADOW: | |
187 | border(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
188 | break; | |
189 | case wxSYS_COLOUR_BTNTEXT: | |
190 | case wxSYS_COLOUR_WINDOWTEXT: | |
191 | fg(ButtonWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
192 | break; | |
193 | case wxSYS_COLOUR_GRAYTEXT: | |
194 | case wxSYS_COLOUR_INACTIVECAPTIONTEXT: | |
195 | fg(ButtonWidget(), GTK_STATE_FLAG_INSENSITIVE, gdkRGBA); | |
196 | break; | |
197 | case wxSYS_COLOUR_HIGHLIGHTTEXT: | |
198 | fg(ButtonWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA); | |
199 | break; | |
200 | case wxSYS_COLOUR_HOTLIGHT: | |
201 | { | |
202 | static GtkWidget* s_widget; | |
203 | if (s_widget == NULL) | |
204 | { | |
205 | s_widget = gtk_link_button_new(""); | |
206 | gtk_container_add(ContainerWidget(), s_widget); | |
207 | } | |
208 | fg(s_widget, GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
209 | } | |
210 | break; | |
211 | case wxSYS_COLOUR_INFOBK: | |
212 | bg(ToolTipWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
213 | break; | |
214 | case wxSYS_COLOUR_INFOTEXT: | |
215 | fg(ToolTipWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
216 | break; | |
217 | case wxSYS_COLOUR_LISTBOX: | |
218 | bg(ListWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
219 | break; | |
220 | case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT: | |
221 | fg(ListWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA); | |
222 | break; | |
223 | case wxSYS_COLOUR_LISTBOXTEXT: | |
224 | fg(ListWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
225 | break; | |
226 | case wxSYS_COLOUR_MENU: | |
227 | bg(MenuItemWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
228 | break; | |
229 | case wxSYS_COLOUR_MENUBAR: | |
230 | bg(MenuBarWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
231 | break; | |
232 | case wxSYS_COLOUR_ACTIVECAPTION: | |
233 | case wxSYS_COLOUR_MENUHILIGHT: | |
234 | bg(MenuItemWidget(), GTK_STATE_FLAG_SELECTED, gdkRGBA); | |
235 | break; | |
236 | case wxSYS_COLOUR_MENUTEXT: | |
237 | fg(MenuItemWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
238 | break; | |
239 | case wxSYS_COLOUR_APPWORKSPACE: | |
240 | case wxSYS_COLOUR_WINDOW: | |
241 | bg(TextCtrlWidget(), GTK_STATE_FLAG_NORMAL, gdkRGBA); | |
242 | break; | |
243 | case wxSYS_COLOUR_CAPTIONTEXT: | |
244 | { | |
245 | GdkRGBA c = { 1, 1, 1, 1 }; | |
246 | gdkRGBA = c; | |
247 | } | |
248 | break; | |
249 | default: | |
250 | wxFAIL_MSG("unknown system colour index"); | |
251 | // fallthrough | |
252 | case wxSYS_COLOUR_3DDKSHADOW: | |
253 | case wxSYS_COLOUR_GRADIENTACTIVECAPTION: | |
254 | case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: | |
255 | // black | |
256 | break; | |
0d0b57ac | 257 | } |
9dc44eff PC |
258 | return wxColour(gdkRGBA); |
259 | } | |
260 | #else | |
261 | static const GtkStyle* ButtonStyle() | |
262 | { | |
263 | return gtk_widget_get_style(ButtonWidget()); | |
264 | } | |
265 | ||
266 | static const GtkStyle* ListStyle() | |
267 | { | |
268 | return gtk_widget_get_style(ListWidget()); | |
269 | } | |
270 | ||
271 | static const GtkStyle* TextCtrlStyle() | |
272 | { | |
273 | return gtk_widget_get_style(TextCtrlWidget()); | |
274 | } | |
275 | ||
276 | static const GtkStyle* MenuItemStyle() | |
277 | { | |
278 | return gtk_widget_get_style(MenuItemWidget()); | |
279 | } | |
280 | ||
281 | static const GtkStyle* MenuBarStyle() | |
282 | { | |
283 | return gtk_widget_get_style(MenuBarWidget()); | |
284 | } | |
285 | ||
286 | static const GtkStyle* ToolTipStyle() | |
287 | { | |
288 | return gtk_widget_get_style(ToolTipWidget()); | |
c05cc2c7 RR |
289 | } |
290 | ||
0ab5e0e8 | 291 | wxColour wxSystemSettingsNative::GetColour( wxSystemColour index ) |
c801d85f | 292 | { |
b0ae510a | 293 | wxColor color; |
db434467 | 294 | switch (index) |
c801d85f | 295 | { |
db434467 RR |
296 | case wxSYS_COLOUR_SCROLLBAR: |
297 | case wxSYS_COLOUR_BACKGROUND: | |
0d0b57ac | 298 | //case wxSYS_COLOUR_DESKTOP: |
db434467 RR |
299 | case wxSYS_COLOUR_INACTIVECAPTION: |
300 | case wxSYS_COLOUR_MENU: | |
301 | case wxSYS_COLOUR_WINDOWFRAME: | |
302 | case wxSYS_COLOUR_ACTIVEBORDER: | |
303 | case wxSYS_COLOUR_INACTIVEBORDER: | |
304 | case wxSYS_COLOUR_BTNFACE: | |
0d0b57ac | 305 | //case wxSYS_COLOUR_3DFACE: |
5b211fbf | 306 | case wxSYS_COLOUR_3DLIGHT: |
0d0b57ac | 307 | color = wxColor(ButtonStyle()->bg[GTK_STATE_NORMAL]); |
b0ae510a | 308 | break; |
643ccf62 | 309 | |
db434467 | 310 | case wxSYS_COLOUR_WINDOW: |
0d0b57ac | 311 | color = wxColor(TextCtrlStyle()->base[GTK_STATE_NORMAL]); |
b0ae510a | 312 | break; |
643ccf62 | 313 | |
3ab6b7e6 | 314 | case wxSYS_COLOUR_MENUBAR: |
0d0b57ac | 315 | color = wxColor(MenuBarStyle()->bg[GTK_STATE_NORMAL]); |
3ab6b7e6 VZ |
316 | break; |
317 | ||
37d403aa | 318 | case wxSYS_COLOUR_3DDKSHADOW: |
b0ae510a PC |
319 | color = *wxBLACK; |
320 | break; | |
643ccf62 | 321 | |
db434467 RR |
322 | case wxSYS_COLOUR_GRAYTEXT: |
323 | case wxSYS_COLOUR_BTNSHADOW: | |
37d403aa | 324 | //case wxSYS_COLOUR_3DSHADOW: |
37d403aa | 325 | { |
984152a6 | 326 | wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE)); |
0d0b57ac | 327 | color = |
b0ae510a PC |
328 | wxColour((unsigned char) (faceColour.Red() * 2 / 3), |
329 | (unsigned char) (faceColour.Green() * 2 / 3), | |
330 | (unsigned char) (faceColour.Blue() * 2 / 3)); | |
db434467 | 331 | } |
b0ae510a | 332 | break; |
643ccf62 | 333 | |
0d0b57ac PC |
334 | case wxSYS_COLOUR_BTNHIGHLIGHT: |
335 | //case wxSYS_COLOUR_BTNHILIGHT: | |
336 | //case wxSYS_COLOUR_3DHIGHLIGHT: | |
337 | //case wxSYS_COLOUR_3DHILIGHT: | |
b0ae510a PC |
338 | color = *wxWHITE; |
339 | break; | |
643ccf62 | 340 | |
db434467 | 341 | case wxSYS_COLOUR_HIGHLIGHT: |
0d0b57ac | 342 | color = wxColor(ButtonStyle()->bg[GTK_STATE_SELECTED]); |
b0ae510a | 343 | break; |
643ccf62 | 344 | |
74f55195 | 345 | case wxSYS_COLOUR_LISTBOX: |
0d0b57ac | 346 | color = wxColor(ListStyle()->base[GTK_STATE_NORMAL]); |
b0ae510a | 347 | break; |
643ccf62 | 348 | |
9f2968ad VZ |
349 | case wxSYS_COLOUR_LISTBOXTEXT: |
350 | color = wxColor(ListStyle()->text[GTK_STATE_NORMAL]); | |
351 | break; | |
352 | ||
887b919b JS |
353 | case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT: |
354 | // This is for the text in a list control (or tree) when the | |
355 | // item is selected, but not focused | |
356 | color = wxColor(ListStyle()->text[GTK_STATE_ACTIVE]); | |
357 | break; | |
358 | ||
643ccf62 VZ |
359 | case wxSYS_COLOUR_MENUTEXT: |
360 | case wxSYS_COLOUR_WINDOWTEXT: | |
361 | case wxSYS_COLOUR_CAPTIONTEXT: | |
362 | case wxSYS_COLOUR_INACTIVECAPTIONTEXT: | |
363 | case wxSYS_COLOUR_BTNTEXT: | |
0d0b57ac | 364 | color = wxColor(ButtonStyle()->fg[GTK_STATE_NORMAL]); |
b0ae510a | 365 | break; |
643ccf62 | 366 | |
17d61cbf | 367 | case wxSYS_COLOUR_INFOBK: |
0d0b57ac | 368 | color = wxColor(ToolTipStyle()->bg[GTK_STATE_NORMAL]); |
b0ae510a | 369 | break; |
c05cc2c7 RR |
370 | |
371 | case wxSYS_COLOUR_INFOTEXT: | |
0d0b57ac | 372 | color = wxColor(ToolTipStyle()->fg[GTK_STATE_NORMAL]); |
b0ae510a | 373 | break; |
17d61cbf | 374 | |
643ccf62 | 375 | case wxSYS_COLOUR_HIGHLIGHTTEXT: |
0d0b57ac | 376 | color = wxColor(ButtonStyle()->fg[GTK_STATE_SELECTED]); |
b0ae510a | 377 | break; |
643ccf62 | 378 | |
643ccf62 | 379 | case wxSYS_COLOUR_APPWORKSPACE: |
b0ae510a PC |
380 | color = *wxWHITE; // ? |
381 | break; | |
221ed576 | 382 | |
9d6a9fdd RR |
383 | case wxSYS_COLOUR_ACTIVECAPTION: |
384 | case wxSYS_COLOUR_MENUHILIGHT: | |
0d0b57ac | 385 | color = wxColor(MenuItemStyle()->bg[GTK_STATE_SELECTED]); |
b0ae510a | 386 | break; |
9d6a9fdd | 387 | |
221ed576 VZ |
388 | case wxSYS_COLOUR_HOTLIGHT: |
389 | case wxSYS_COLOUR_GRADIENTACTIVECAPTION: | |
390 | case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: | |
221ed576 | 391 | // TODO |
b0ae510a PC |
392 | color = *wxBLACK; |
393 | break; | |
221ed576 VZ |
394 | |
395 | case wxSYS_COLOUR_MAX: | |
396 | default: | |
9a83f860 | 397 | wxFAIL_MSG( wxT("unknown system colour index") ); |
b0ae510a PC |
398 | color = *wxWHITE; |
399 | break; | |
e24b680c | 400 | } |
643ccf62 | 401 | |
e3527f7b | 402 | wxASSERT(color.IsOk()); |
b0ae510a | 403 | return color; |
ff7b1510 | 404 | } |
9dc44eff | 405 | #endif |
c801d85f | 406 | |
0ab5e0e8 | 407 | wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) |
c801d85f | 408 | { |
b0ae510a | 409 | wxFont font; |
2d17d68f | 410 | switch (index) |
c801d85f | 411 | { |
2d17d68f RR |
412 | case wxSYS_OEM_FIXED_FONT: |
413 | case wxSYS_ANSI_FIXED_FONT: | |
414 | case wxSYS_SYSTEM_FIXED_FONT: | |
b0ae510a PC |
415 | font = *wxNORMAL_FONT; |
416 | break; | |
417 | ||
2d17d68f RR |
418 | case wxSYS_ANSI_VAR_FONT: |
419 | case wxSYS_SYSTEM_FONT: | |
420 | case wxSYS_DEVICE_DEFAULT_FONT: | |
421 | case wxSYS_DEFAULT_GUI_FONT: | |
a1b806b9 | 422 | if (!gs_fontSystem.IsOk()) |
d06b34a7 | 423 | { |
0d0b57ac | 424 | wxNativeFontInfo info; |
9dc44eff PC |
425 | #ifdef __WXGTK3__ |
426 | GtkStyleContext* sc = gtk_widget_get_style_context(ButtonWidget()); | |
427 | info.description = const_cast<PangoFontDescription*>( | |
428 | gtk_style_context_get_font(sc, GTK_STATE_FLAG_NORMAL)); | |
429 | #else | |
0d0b57ac | 430 | info.description = ButtonStyle()->font_desc; |
9dc44eff | 431 | #endif |
0d0b57ac | 432 | gs_fontSystem = wxFont(info); |
03647350 | 433 | |
330b3189 | 434 | #if wxUSE_FONTENUM |
e3527f7b FM |
435 | // (try to) heal the default font (on some common systems e.g. Ubuntu |
436 | // it's "Sans Serif" but the real font is called "Sans"): | |
437 | if (!wxFontEnumerator::IsValidFacename(gs_fontSystem.GetFaceName()) && | |
438 | gs_fontSystem.GetFaceName() == "Sans Serif") | |
439 | gs_fontSystem.SetFaceName("Sans"); | |
330b3189 | 440 | #endif // wxUSE_FONTENUM |
03647350 | 441 | |
0d0b57ac | 442 | info.description = NULL; |
d06b34a7 | 443 | } |
0d0b57ac | 444 | font = gs_fontSystem; |
b0ae510a | 445 | break; |
c801d85f | 446 | |
0ab5e0e8 | 447 | default: |
b0ae510a | 448 | break; |
0ab5e0e8 | 449 | } |
e3527f7b | 450 | |
330b3189 | 451 | wxASSERT( font.IsOk() ); |
e3527f7b | 452 | |
b0ae510a | 453 | return font; |
c801d85f | 454 | } |
c801d85f | 455 | |
ff654490 VZ |
456 | // helper: return the GtkSettings either for the screen the current window is |
457 | // on or for the default screen if window is NULL | |
458 | static GtkSettings *GetSettingsForWindowScreen(GdkWindow *window) | |
459 | { | |
9dc44eff | 460 | return window ? gtk_settings_get_for_screen(gdk_window_get_screen(window)) |
ff654490 VZ |
461 | : gtk_settings_get_default(); |
462 | } | |
463 | ||
53357e24 PC |
464 | static int GetBorderWidth(wxSystemMetric index, wxWindow* win) |
465 | { | |
466 | if (win->m_wxwindow) | |
467 | { | |
468 | wxPizza* pizza = WX_PIZZA(win->m_wxwindow); | |
9dc44eff PC |
469 | GtkBorder border; |
470 | pizza->get_border(border); | |
53357e24 PC |
471 | switch (index) |
472 | { | |
473 | case wxSYS_BORDER_X: | |
474 | case wxSYS_EDGE_X: | |
475 | case wxSYS_FRAMESIZE_X: | |
9dc44eff | 476 | return border.left; |
53357e24 | 477 | default: |
9dc44eff | 478 | return border.top; |
53357e24 PC |
479 | } |
480 | } | |
481 | return -1; | |
482 | } | |
483 | ||
b0ae510a PC |
484 | int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) |
485 | { | |
9b0b5ba7 | 486 | GdkWindow *window = NULL; |
385e8575 PC |
487 | if (win) |
488 | window = gtk_widget_get_window(win->GetHandle()); | |
9b0b5ba7 | 489 | |
1ecc4d80 RR |
490 | switch (index) |
491 | { | |
9b0b5ba7 RR |
492 | case wxSYS_BORDER_X: |
493 | case wxSYS_BORDER_Y: | |
494 | case wxSYS_EDGE_X: | |
495 | case wxSYS_EDGE_Y: | |
496 | case wxSYS_FRAMESIZE_X: | |
497 | case wxSYS_FRAMESIZE_Y: | |
53357e24 | 498 | if (win) |
9b0b5ba7 RR |
499 | { |
500 | wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); | |
501 | if (!tlw) | |
53357e24 PC |
502 | return GetBorderWidth(index, win); |
503 | else if (window) | |
9b0b5ba7 | 504 | { |
9b0b5ba7 RR |
505 | // Get the frame extents from the windowmanager. |
506 | // In most cases the top extent is the titlebar, so we use the bottom extent | |
507 | // for the heights. | |
37cafc6a | 508 | int right, bottom; |
166b4de7 | 509 | if (wxGetFrameExtents(window, NULL, &right, NULL, &bottom)) |
9b0b5ba7 | 510 | { |
37cafc6a | 511 | switch (index) |
9b0b5ba7 | 512 | { |
37cafc6a PC |
513 | case wxSYS_BORDER_X: |
514 | case wxSYS_EDGE_X: | |
515 | case wxSYS_FRAMESIZE_X: | |
516 | return right; // width of right extent | |
517 | default: | |
518 | return bottom; // height of bottom extent | |
9b0b5ba7 | 519 | } |
9b0b5ba7 RR |
520 | } |
521 | } | |
522 | } | |
523 | ||
524 | return -1; // no window specified | |
525 | ||
526 | case wxSYS_CURSOR_X: | |
527 | case wxSYS_CURSOR_Y: | |
ff654490 | 528 | return gdk_display_get_default_cursor_size( |
9dc44eff | 529 | window ? gdk_window_get_display(window) |
ff654490 | 530 | : gdk_display_get_default()); |
17d61cbf | 531 | |
44fd6f72 VS |
532 | case wxSYS_DCLICK_X: |
533 | case wxSYS_DCLICK_Y: | |
534 | gint dclick_distance; | |
ff654490 VZ |
535 | g_object_get(GetSettingsForWindowScreen(window), |
536 | "gtk-double-click-distance", &dclick_distance, NULL); | |
9b0b5ba7 RR |
537 | |
538 | return dclick_distance * 2; | |
44fd6f72 | 539 | |
5595181f VZ |
540 | case wxSYS_DCLICK_MSEC: |
541 | gint dclick; | |
ff654490 | 542 | g_object_get(GetSettingsForWindowScreen(window), |
5595181f VZ |
543 | "gtk-double-click-time", &dclick, NULL); |
544 | return dclick; | |
545 | ||
44fd6f72 VS |
546 | case wxSYS_DRAG_X: |
547 | case wxSYS_DRAG_Y: | |
548 | gint drag_threshold; | |
ff654490 VZ |
549 | g_object_get(GetSettingsForWindowScreen(window), |
550 | "gtk-dnd-drag-threshold", &drag_threshold, NULL); | |
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 | |
ff654490 VZ |
560 | case wxSYS_ICON_X: |
561 | case wxSYS_ICON_Y: | |
562 | return 32; | |
9b0b5ba7 RR |
563 | |
564 | case wxSYS_SCREEN_X: | |
ff654490 | 565 | if (window) |
9dc44eff | 566 | return gdk_screen_get_width(gdk_window_get_screen(window)); |
9b0b5ba7 | 567 | else |
9b0b5ba7 RR |
568 | return gdk_screen_width(); |
569 | ||
570 | case wxSYS_SCREEN_Y: | |
ff654490 | 571 | if (window) |
9dc44eff | 572 | return gdk_screen_get_height(gdk_window_get_screen(window)); |
9b0b5ba7 | 573 | else |
9b0b5ba7 RR |
574 | return gdk_screen_height(); |
575 | ||
ff654490 VZ |
576 | case wxSYS_HSCROLL_Y: |
577 | case wxSYS_VSCROLL_X: | |
578 | return 15; | |
9b0b5ba7 | 579 | |
9b0b5ba7 RR |
580 | case wxSYS_CAPTION_Y: |
581 | if (!window) | |
582 | // No realized window specified, and no implementation for that case yet. | |
583 | return -1; | |
584 | ||
9b0b5ba7 RR |
585 | wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), |
586 | wxT("Asking for caption height of a non toplevel window") ); | |
587 | ||
588 | // Get the height of the top windowmanager border. | |
589 | // This is the titlebar in most cases. The titlebar might be elsewhere, and | |
590 | // we could check which is the thickest wm border to decide on which side the | |
591 | // titlebar is, but this might lead to interesting behaviours in used code. | |
592 | // Reconsider when we have a way to report to the user on which side it is. | |
9b0b5ba7 | 593 | { |
37cafc6a | 594 | int top; |
166b4de7 | 595 | if (wxGetFrameExtents(window, NULL, NULL, &top, NULL)) |
9b0b5ba7 | 596 | { |
37cafc6a | 597 | return top; // top frame extent |
9b0b5ba7 | 598 | } |
9b0b5ba7 RR |
599 | } |
600 | ||
601 | // Try a default approach without a window pointer, if possible | |
602 | // ... | |
603 | ||
604 | return -1; | |
9b0b5ba7 RR |
605 | |
606 | case wxSYS_PENWINDOWS_PRESENT: | |
607 | // No MS Windows for Pen computing extension available in X11 based gtk+. | |
608 | return 0; | |
609 | ||
610 | default: | |
1d451c5b | 611 | return -1; // metric is unknown |
1ecc4d80 | 612 | } |
c67daf87 | 613 | } |
253293c1 | 614 | |
0ab5e0e8 | 615 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 VS |
616 | { |
617 | switch (index) | |
618 | { | |
17a1ebd1 | 619 | case wxSYS_CAN_ICONIZE_FRAME: |
e7c80f9e | 620 | return false; |
17a1ebd1 | 621 | |
253293c1 | 622 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
e7c80f9e | 623 | return true; |
17a1ebd1 | 624 | |
253293c1 | 625 | default: |
e7c80f9e | 626 | return false; |
253293c1 VS |
627 | } |
628 | } |