]>
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 | |
aed8ac3f | 23 | #include <gtk/gtk.h> |
53357e24 | 24 | #include "wx/gtk/private/win_gtk.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 PC |
46 | extern "C" { |
47 | static void style_set(GtkWidget*, GtkStyle*, void*) | |
643ccf62 | 48 | { |
0d0b57ac PC |
49 | gs_fontSystem = wxNullFont; |
50 | } | |
51 | } | |
52 | ||
53 | static const GtkStyle* ButtonStyle() | |
643ccf62 | 54 | { |
0d0b57ac PC |
55 | static GtkWidget* s_widget; |
56 | if (s_widget == NULL) | |
dbcbe229 | 57 | { |
0d0b57ac PC |
58 | s_widget = gtk_button_new(); |
59 | gtk_container_add(ContainerWidget(), s_widget); | |
60 | gtk_widget_ensure_style(s_widget); | |
61 | g_signal_connect(s_widget, "style_set", G_CALLBACK(style_set), NULL); | |
dbcbe229 | 62 | } |
0d0b57ac PC |
63 | return s_widget->style; |
64 | } | |
dbcbe229 | 65 | |
0d0b57ac PC |
66 | static const GtkStyle* ListStyle() |
67 | { | |
68 | static GtkWidget* s_widget; | |
69 | if (s_widget == NULL) | |
70 | { | |
71 | s_widget = gtk_tree_view_new_with_model( | |
72 | GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_INT))); | |
73 | gtk_container_add(ContainerWidget(), s_widget); | |
74 | gtk_widget_ensure_style(s_widget); | |
75 | } | |
76 | return s_widget->style; | |
77 | } | |
643ccf62 | 78 | |
0d0b57ac PC |
79 | static const GtkStyle* TextCtrlStyle() |
80 | { | |
81 | static GtkWidget* s_widget; | |
82 | if (s_widget == NULL) | |
643ccf62 | 83 | { |
0d0b57ac PC |
84 | s_widget = gtk_text_view_new(); |
85 | gtk_container_add(ContainerWidget(), s_widget); | |
86 | gtk_widget_ensure_style(s_widget); | |
643ccf62 | 87 | } |
0d0b57ac PC |
88 | return s_widget->style; |
89 | } | |
643ccf62 | 90 | |
0d0b57ac PC |
91 | static const GtkStyle* MenuItemStyle() |
92 | { | |
93 | static GtkWidget* s_widget; | |
94 | if (s_widget == NULL) | |
95 | { | |
96 | s_widget = gtk_menu_item_new(); | |
97 | gtk_container_add(ContainerWidget(), s_widget); | |
98 | gtk_widget_ensure_style(s_widget); | |
99 | } | |
100 | return s_widget->style; | |
101 | } | |
643ccf62 | 102 | |
0d0b57ac PC |
103 | static const GtkStyle* MenuBarStyle() |
104 | { | |
105 | static GtkWidget* s_widget; | |
106 | if (s_widget == NULL) | |
107 | { | |
108 | s_widget = gtk_menu_bar_new(); | |
109 | gtk_container_add(ContainerWidget(), s_widget); | |
110 | gtk_widget_ensure_style(s_widget); | |
111 | } | |
112 | return s_widget->style; | |
643ccf62 VZ |
113 | } |
114 | ||
0d0b57ac | 115 | static const GtkStyle* ToolTipStyle() |
c05cc2c7 | 116 | { |
0d0b57ac PC |
117 | static GtkWidget* s_widget; |
118 | if (s_widget == NULL) | |
119 | { | |
120 | s_widget = gtk_window_new(GTK_WINDOW_POPUP); | |
121 | const char* name = "gtk-tooltip"; | |
122 | if (gtk_check_version(2, 11, 0)) | |
123 | name = "gtk-tooltips"; | |
124 | gtk_widget_set_name(s_widget, name); | |
125 | gtk_widget_ensure_style(s_widget); | |
126 | } | |
127 | return s_widget->style; | |
c05cc2c7 RR |
128 | } |
129 | ||
0ab5e0e8 | 130 | wxColour wxSystemSettingsNative::GetColour( wxSystemColour index ) |
c801d85f | 131 | { |
b0ae510a | 132 | wxColor color; |
db434467 | 133 | switch (index) |
c801d85f | 134 | { |
db434467 RR |
135 | case wxSYS_COLOUR_SCROLLBAR: |
136 | case wxSYS_COLOUR_BACKGROUND: | |
0d0b57ac | 137 | //case wxSYS_COLOUR_DESKTOP: |
db434467 RR |
138 | case wxSYS_COLOUR_INACTIVECAPTION: |
139 | case wxSYS_COLOUR_MENU: | |
140 | case wxSYS_COLOUR_WINDOWFRAME: | |
141 | case wxSYS_COLOUR_ACTIVEBORDER: | |
142 | case wxSYS_COLOUR_INACTIVEBORDER: | |
143 | case wxSYS_COLOUR_BTNFACE: | |
0d0b57ac | 144 | //case wxSYS_COLOUR_3DFACE: |
5b211fbf | 145 | case wxSYS_COLOUR_3DLIGHT: |
0d0b57ac | 146 | color = wxColor(ButtonStyle()->bg[GTK_STATE_NORMAL]); |
b0ae510a | 147 | break; |
643ccf62 | 148 | |
db434467 | 149 | case wxSYS_COLOUR_WINDOW: |
0d0b57ac | 150 | color = wxColor(TextCtrlStyle()->base[GTK_STATE_NORMAL]); |
b0ae510a | 151 | break; |
643ccf62 | 152 | |
3ab6b7e6 | 153 | case wxSYS_COLOUR_MENUBAR: |
0d0b57ac | 154 | color = wxColor(MenuBarStyle()->bg[GTK_STATE_NORMAL]); |
3ab6b7e6 VZ |
155 | break; |
156 | ||
37d403aa | 157 | case wxSYS_COLOUR_3DDKSHADOW: |
b0ae510a PC |
158 | color = *wxBLACK; |
159 | break; | |
643ccf62 | 160 | |
db434467 RR |
161 | case wxSYS_COLOUR_GRAYTEXT: |
162 | case wxSYS_COLOUR_BTNSHADOW: | |
37d403aa | 163 | //case wxSYS_COLOUR_3DSHADOW: |
37d403aa | 164 | { |
984152a6 | 165 | wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE)); |
0d0b57ac | 166 | color = |
b0ae510a PC |
167 | wxColour((unsigned char) (faceColour.Red() * 2 / 3), |
168 | (unsigned char) (faceColour.Green() * 2 / 3), | |
169 | (unsigned char) (faceColour.Blue() * 2 / 3)); | |
db434467 | 170 | } |
b0ae510a | 171 | break; |
643ccf62 | 172 | |
0d0b57ac PC |
173 | case wxSYS_COLOUR_BTNHIGHLIGHT: |
174 | //case wxSYS_COLOUR_BTNHILIGHT: | |
175 | //case wxSYS_COLOUR_3DHIGHLIGHT: | |
176 | //case wxSYS_COLOUR_3DHILIGHT: | |
b0ae510a PC |
177 | color = *wxWHITE; |
178 | break; | |
643ccf62 | 179 | |
db434467 | 180 | case wxSYS_COLOUR_HIGHLIGHT: |
0d0b57ac | 181 | color = wxColor(ButtonStyle()->bg[GTK_STATE_SELECTED]); |
b0ae510a | 182 | break; |
643ccf62 | 183 | |
74f55195 | 184 | case wxSYS_COLOUR_LISTBOX: |
0d0b57ac | 185 | color = wxColor(ListStyle()->base[GTK_STATE_NORMAL]); |
b0ae510a | 186 | break; |
643ccf62 | 187 | |
9f2968ad VZ |
188 | case wxSYS_COLOUR_LISTBOXTEXT: |
189 | color = wxColor(ListStyle()->text[GTK_STATE_NORMAL]); | |
190 | break; | |
191 | ||
643ccf62 VZ |
192 | case wxSYS_COLOUR_MENUTEXT: |
193 | case wxSYS_COLOUR_WINDOWTEXT: | |
194 | case wxSYS_COLOUR_CAPTIONTEXT: | |
195 | case wxSYS_COLOUR_INACTIVECAPTIONTEXT: | |
196 | case wxSYS_COLOUR_BTNTEXT: | |
0d0b57ac | 197 | color = wxColor(ButtonStyle()->fg[GTK_STATE_NORMAL]); |
b0ae510a | 198 | break; |
643ccf62 | 199 | |
17d61cbf | 200 | case wxSYS_COLOUR_INFOBK: |
0d0b57ac | 201 | color = wxColor(ToolTipStyle()->bg[GTK_STATE_NORMAL]); |
b0ae510a | 202 | break; |
c05cc2c7 RR |
203 | |
204 | case wxSYS_COLOUR_INFOTEXT: | |
0d0b57ac | 205 | color = wxColor(ToolTipStyle()->fg[GTK_STATE_NORMAL]); |
b0ae510a | 206 | break; |
17d61cbf | 207 | |
643ccf62 | 208 | case wxSYS_COLOUR_HIGHLIGHTTEXT: |
0d0b57ac | 209 | color = wxColor(ButtonStyle()->fg[GTK_STATE_SELECTED]); |
b0ae510a | 210 | break; |
643ccf62 | 211 | |
643ccf62 | 212 | case wxSYS_COLOUR_APPWORKSPACE: |
b0ae510a PC |
213 | color = *wxWHITE; // ? |
214 | break; | |
221ed576 | 215 | |
9d6a9fdd RR |
216 | case wxSYS_COLOUR_ACTIVECAPTION: |
217 | case wxSYS_COLOUR_MENUHILIGHT: | |
0d0b57ac | 218 | color = wxColor(MenuItemStyle()->bg[GTK_STATE_SELECTED]); |
b0ae510a | 219 | break; |
9d6a9fdd | 220 | |
221ed576 VZ |
221 | case wxSYS_COLOUR_HOTLIGHT: |
222 | case wxSYS_COLOUR_GRADIENTACTIVECAPTION: | |
223 | case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: | |
221ed576 | 224 | // TODO |
b0ae510a PC |
225 | color = *wxBLACK; |
226 | break; | |
221ed576 VZ |
227 | |
228 | case wxSYS_COLOUR_MAX: | |
229 | default: | |
230 | wxFAIL_MSG( _T("unknown system colour index") ); | |
b0ae510a PC |
231 | color = *wxWHITE; |
232 | break; | |
e24b680c | 233 | } |
643ccf62 | 234 | |
b0ae510a | 235 | return color; |
ff7b1510 | 236 | } |
c801d85f | 237 | |
0ab5e0e8 | 238 | wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) |
c801d85f | 239 | { |
b0ae510a | 240 | wxFont font; |
2d17d68f | 241 | switch (index) |
c801d85f | 242 | { |
2d17d68f RR |
243 | case wxSYS_OEM_FIXED_FONT: |
244 | case wxSYS_ANSI_FIXED_FONT: | |
245 | case wxSYS_SYSTEM_FIXED_FONT: | |
b0ae510a PC |
246 | font = *wxNORMAL_FONT; |
247 | break; | |
248 | ||
2d17d68f RR |
249 | case wxSYS_ANSI_VAR_FONT: |
250 | case wxSYS_SYSTEM_FONT: | |
251 | case wxSYS_DEVICE_DEFAULT_FONT: | |
252 | case wxSYS_DEFAULT_GUI_FONT: | |
0d0b57ac | 253 | if (!gs_fontSystem.Ok()) |
d06b34a7 | 254 | { |
0d0b57ac PC |
255 | wxNativeFontInfo info; |
256 | info.description = ButtonStyle()->font_desc; | |
257 | gs_fontSystem = wxFont(info); | |
258 | info.description = NULL; | |
d06b34a7 | 259 | } |
0d0b57ac | 260 | font = gs_fontSystem; |
b0ae510a | 261 | break; |
c801d85f | 262 | |
0ab5e0e8 | 263 | default: |
b0ae510a | 264 | break; |
0ab5e0e8 | 265 | } |
b0ae510a | 266 | return font; |
c801d85f | 267 | } |
c801d85f | 268 | |
ff654490 VZ |
269 | // helper: return the GtkSettings either for the screen the current window is |
270 | // on or for the default screen if window is NULL | |
271 | static GtkSettings *GetSettingsForWindowScreen(GdkWindow *window) | |
272 | { | |
273 | return window ? gtk_settings_get_for_screen(gdk_drawable_get_screen(window)) | |
274 | : gtk_settings_get_default(); | |
275 | } | |
276 | ||
53357e24 PC |
277 | static int GetBorderWidth(wxSystemMetric index, wxWindow* win) |
278 | { | |
279 | if (win->m_wxwindow) | |
280 | { | |
281 | wxPizza* pizza = WX_PIZZA(win->m_wxwindow); | |
282 | int x, y; | |
283 | pizza->get_border_widths(x, y); | |
284 | switch (index) | |
285 | { | |
286 | case wxSYS_BORDER_X: | |
287 | case wxSYS_EDGE_X: | |
288 | case wxSYS_FRAMESIZE_X: | |
289 | return x; | |
290 | default: | |
291 | return y; | |
292 | } | |
293 | } | |
294 | return -1; | |
295 | } | |
296 | ||
b0ae510a PC |
297 | int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) |
298 | { | |
9b0b5ba7 RR |
299 | GdkWindow *window = NULL; |
300 | if(win && GTK_WIDGET_REALIZED(win->GetHandle())) | |
301 | window = win->GetHandle()->window; | |
9b0b5ba7 | 302 | |
1ecc4d80 RR |
303 | switch (index) |
304 | { | |
9b0b5ba7 RR |
305 | case wxSYS_BORDER_X: |
306 | case wxSYS_BORDER_Y: | |
307 | case wxSYS_EDGE_X: | |
308 | case wxSYS_EDGE_Y: | |
309 | case wxSYS_FRAMESIZE_X: | |
310 | case wxSYS_FRAMESIZE_Y: | |
53357e24 | 311 | if (win) |
9b0b5ba7 RR |
312 | { |
313 | wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); | |
314 | if (!tlw) | |
53357e24 PC |
315 | return GetBorderWidth(index, win); |
316 | else if (window) | |
9b0b5ba7 | 317 | { |
9b0b5ba7 RR |
318 | // Get the frame extents from the windowmanager. |
319 | // In most cases the top extent is the titlebar, so we use the bottom extent | |
320 | // for the heights. | |
37cafc6a | 321 | int right, bottom; |
166b4de7 | 322 | if (wxGetFrameExtents(window, NULL, &right, NULL, &bottom)) |
9b0b5ba7 | 323 | { |
37cafc6a | 324 | switch (index) |
9b0b5ba7 | 325 | { |
37cafc6a PC |
326 | case wxSYS_BORDER_X: |
327 | case wxSYS_EDGE_X: | |
328 | case wxSYS_FRAMESIZE_X: | |
329 | return right; // width of right extent | |
330 | default: | |
331 | return bottom; // height of bottom extent | |
9b0b5ba7 | 332 | } |
9b0b5ba7 RR |
333 | } |
334 | } | |
335 | } | |
336 | ||
337 | return -1; // no window specified | |
338 | ||
339 | case wxSYS_CURSOR_X: | |
340 | case wxSYS_CURSOR_Y: | |
ff654490 VZ |
341 | return gdk_display_get_default_cursor_size( |
342 | window ? gdk_drawable_get_display(window) | |
343 | : gdk_display_get_default()); | |
17d61cbf | 344 | |
44fd6f72 VS |
345 | case wxSYS_DCLICK_X: |
346 | case wxSYS_DCLICK_Y: | |
347 | gint dclick_distance; | |
ff654490 VZ |
348 | g_object_get(GetSettingsForWindowScreen(window), |
349 | "gtk-double-click-distance", &dclick_distance, NULL); | |
9b0b5ba7 RR |
350 | |
351 | return dclick_distance * 2; | |
44fd6f72 | 352 | |
5595181f VZ |
353 | case wxSYS_DCLICK_MSEC: |
354 | gint dclick; | |
ff654490 | 355 | g_object_get(GetSettingsForWindowScreen(window), |
5595181f VZ |
356 | "gtk-double-click-time", &dclick, NULL); |
357 | return dclick; | |
358 | ||
44fd6f72 VS |
359 | case wxSYS_DRAG_X: |
360 | case wxSYS_DRAG_Y: | |
361 | gint drag_threshold; | |
ff654490 VZ |
362 | g_object_get(GetSettingsForWindowScreen(window), |
363 | "gtk-dnd-drag-threshold", &drag_threshold, NULL); | |
44fd6f72 | 364 | |
9fcdfe05 RR |
365 | // The correct thing here would be to double the value |
366 | // since that is what the API wants. But the values | |
367 | // are much bigger under GNOME than under Windows and | |
368 | // just seem to much in many cases to be useful. | |
f4322df6 | 369 | // drag_threshold *= 2; |
9fcdfe05 | 370 | |
1e7373d0 | 371 | return drag_threshold; |
9b0b5ba7 | 372 | |
ff654490 VZ |
373 | case wxSYS_ICON_X: |
374 | case wxSYS_ICON_Y: | |
375 | return 32; | |
9b0b5ba7 RR |
376 | |
377 | case wxSYS_SCREEN_X: | |
ff654490 | 378 | if (window) |
9b0b5ba7 RR |
379 | return gdk_screen_get_width(gdk_drawable_get_screen(window)); |
380 | else | |
9b0b5ba7 RR |
381 | return gdk_screen_width(); |
382 | ||
383 | case wxSYS_SCREEN_Y: | |
ff654490 | 384 | if (window) |
9b0b5ba7 RR |
385 | return gdk_screen_get_height(gdk_drawable_get_screen(window)); |
386 | else | |
9b0b5ba7 RR |
387 | return gdk_screen_height(); |
388 | ||
ff654490 VZ |
389 | case wxSYS_HSCROLL_Y: |
390 | case wxSYS_VSCROLL_X: | |
391 | return 15; | |
9b0b5ba7 | 392 | |
9b0b5ba7 RR |
393 | case wxSYS_CAPTION_Y: |
394 | if (!window) | |
395 | // No realized window specified, and no implementation for that case yet. | |
396 | return -1; | |
397 | ||
9b0b5ba7 RR |
398 | wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), |
399 | wxT("Asking for caption height of a non toplevel window") ); | |
400 | ||
401 | // Get the height of the top windowmanager border. | |
402 | // This is the titlebar in most cases. The titlebar might be elsewhere, and | |
403 | // we could check which is the thickest wm border to decide on which side the | |
404 | // titlebar is, but this might lead to interesting behaviours in used code. | |
405 | // Reconsider when we have a way to report to the user on which side it is. | |
9b0b5ba7 | 406 | { |
37cafc6a | 407 | int top; |
166b4de7 | 408 | if (wxGetFrameExtents(window, NULL, NULL, &top, NULL)) |
9b0b5ba7 | 409 | { |
37cafc6a | 410 | return top; // top frame extent |
9b0b5ba7 | 411 | } |
9b0b5ba7 RR |
412 | } |
413 | ||
414 | // Try a default approach without a window pointer, if possible | |
415 | // ... | |
416 | ||
417 | return -1; | |
9b0b5ba7 RR |
418 | |
419 | case wxSYS_PENWINDOWS_PRESENT: | |
420 | // No MS Windows for Pen computing extension available in X11 based gtk+. | |
421 | return 0; | |
422 | ||
423 | default: | |
1d451c5b | 424 | return -1; // metric is unknown |
1ecc4d80 | 425 | } |
c67daf87 | 426 | } |
253293c1 | 427 | |
0ab5e0e8 | 428 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 VS |
429 | { |
430 | switch (index) | |
431 | { | |
17a1ebd1 | 432 | case wxSYS_CAN_ICONIZE_FRAME: |
e7c80f9e | 433 | return false; |
17a1ebd1 | 434 | |
253293c1 | 435 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
e7c80f9e | 436 | return true; |
17a1ebd1 | 437 | |
253293c1 | 438 | default: |
e7c80f9e | 439 | return false; |
253293c1 VS |
440 | } |
441 | } |