1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/settings.cpp
4 // Author: Robert Roebling
5 // Modified by: Mart Raudsepp (GetMetric)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/settings.h"
17 #include "wx/toplevel.h"
20 #include "wx/fontutil.h"
21 #include "wx/fontenum.h"
24 #include "wx/gtk/private/win_gtk.h"
25 #include "wx/gtk/private/gtk2-compat.h"
27 bool wxGetFrameExtents(GdkWindow
* window
, int* left
, int* right
, int* top
, int* bottom
);
29 // ----------------------------------------------------------------------------
30 // wxSystemSettings implementation
31 // ----------------------------------------------------------------------------
33 static wxFont gs_fontSystem
;
35 static GtkContainer
* ContainerWidget()
37 static GtkContainer
* s_widget
;
40 s_widget
= GTK_CONTAINER(gtk_fixed_new());
41 GtkWidget
* window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
42 gtk_container_add(GTK_CONTAINER(window
), GTK_WIDGET(s_widget
));
48 static void style_set(GtkWidget
*, GtkStyle
*, void*)
50 gs_fontSystem
= wxNullFont
;
54 static const GtkStyle
* ButtonStyle()
56 static GtkWidget
* s_widget
;
59 s_widget
= gtk_button_new();
60 gtk_container_add(ContainerWidget(), s_widget
);
61 gtk_widget_ensure_style(s_widget
);
62 g_signal_connect(s_widget
, "style_set", G_CALLBACK(style_set
), NULL
);
64 return gtk_widget_get_style(s_widget
);
67 static const GtkStyle
* ListStyle()
69 static GtkWidget
* s_widget
;
72 s_widget
= gtk_tree_view_new_with_model(
73 GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_INT
)));
74 gtk_container_add(ContainerWidget(), s_widget
);
75 gtk_widget_ensure_style(s_widget
);
77 return gtk_widget_get_style(s_widget
);
80 static const GtkStyle
* TextCtrlStyle()
82 static GtkWidget
* s_widget
;
85 s_widget
= gtk_text_view_new();
86 gtk_container_add(ContainerWidget(), s_widget
);
87 gtk_widget_ensure_style(s_widget
);
89 return gtk_widget_get_style(s_widget
);
92 static const GtkStyle
* MenuItemStyle()
94 static GtkWidget
* s_widget
;
97 s_widget
= gtk_menu_item_new();
98 gtk_container_add(ContainerWidget(), s_widget
);
99 gtk_widget_ensure_style(s_widget
);
101 return gtk_widget_get_style(s_widget
);
104 static const GtkStyle
* MenuBarStyle()
106 static GtkWidget
* s_widget
;
107 if (s_widget
== NULL
)
109 s_widget
= gtk_menu_bar_new();
110 gtk_container_add(ContainerWidget(), s_widget
);
111 gtk_widget_ensure_style(s_widget
);
113 return gtk_widget_get_style(s_widget
);
116 static const GtkStyle
* ToolTipStyle()
118 static GtkWidget
* s_widget
;
119 if (s_widget
== NULL
)
121 s_widget
= gtk_window_new(GTK_WINDOW_POPUP
);
122 const char* name
= "gtk-tooltip";
123 if (gtk_check_version(2, 11, 0))
124 name
= "gtk-tooltips";
125 gtk_widget_set_name(s_widget
, name
);
126 gtk_widget_ensure_style(s_widget
);
128 return gtk_widget_get_style(s_widget
);
131 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
136 case wxSYS_COLOUR_SCROLLBAR
:
137 case wxSYS_COLOUR_BACKGROUND
:
138 //case wxSYS_COLOUR_DESKTOP:
139 case wxSYS_COLOUR_INACTIVECAPTION
:
140 case wxSYS_COLOUR_MENU
:
141 case wxSYS_COLOUR_WINDOWFRAME
:
142 case wxSYS_COLOUR_ACTIVEBORDER
:
143 case wxSYS_COLOUR_INACTIVEBORDER
:
144 case wxSYS_COLOUR_BTNFACE
:
145 //case wxSYS_COLOUR_3DFACE:
146 case wxSYS_COLOUR_3DLIGHT
:
147 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_NORMAL
]);
150 case wxSYS_COLOUR_WINDOW
:
151 color
= wxColor(TextCtrlStyle()->base
[GTK_STATE_NORMAL
]);
154 case wxSYS_COLOUR_MENUBAR
:
155 color
= wxColor(MenuBarStyle()->bg
[GTK_STATE_NORMAL
]);
158 case wxSYS_COLOUR_3DDKSHADOW
:
162 case wxSYS_COLOUR_GRAYTEXT
:
163 case wxSYS_COLOUR_BTNSHADOW
:
164 //case wxSYS_COLOUR_3DSHADOW:
166 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
168 wxColour((unsigned char) (faceColour
.Red() * 2 / 3),
169 (unsigned char) (faceColour
.Green() * 2 / 3),
170 (unsigned char) (faceColour
.Blue() * 2 / 3));
174 case wxSYS_COLOUR_BTNHIGHLIGHT
:
175 //case wxSYS_COLOUR_BTNHILIGHT:
176 //case wxSYS_COLOUR_3DHIGHLIGHT:
177 //case wxSYS_COLOUR_3DHILIGHT:
181 case wxSYS_COLOUR_HIGHLIGHT
:
182 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_SELECTED
]);
185 case wxSYS_COLOUR_LISTBOX
:
186 color
= wxColor(ListStyle()->base
[GTK_STATE_NORMAL
]);
189 case wxSYS_COLOUR_LISTBOXTEXT
:
190 color
= wxColor(ListStyle()->text
[GTK_STATE_NORMAL
]);
193 case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
:
194 // This is for the text in a list control (or tree) when the
195 // item is selected, but not focused
196 color
= wxColor(ListStyle()->text
[GTK_STATE_ACTIVE
]);
199 case wxSYS_COLOUR_MENUTEXT
:
200 case wxSYS_COLOUR_WINDOWTEXT
:
201 case wxSYS_COLOUR_CAPTIONTEXT
:
202 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
203 case wxSYS_COLOUR_BTNTEXT
:
204 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_NORMAL
]);
207 case wxSYS_COLOUR_INFOBK
:
208 color
= wxColor(ToolTipStyle()->bg
[GTK_STATE_NORMAL
]);
211 case wxSYS_COLOUR_INFOTEXT
:
212 color
= wxColor(ToolTipStyle()->fg
[GTK_STATE_NORMAL
]);
215 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
216 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_SELECTED
]);
219 case wxSYS_COLOUR_APPWORKSPACE
:
220 color
= *wxWHITE
; // ?
223 case wxSYS_COLOUR_ACTIVECAPTION
:
224 case wxSYS_COLOUR_MENUHILIGHT
:
225 color
= wxColor(MenuItemStyle()->bg
[GTK_STATE_SELECTED
]);
228 case wxSYS_COLOUR_HOTLIGHT
:
229 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
230 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
235 case wxSYS_COLOUR_MAX
:
237 wxFAIL_MSG( wxT("unknown system colour index") );
242 wxASSERT(color
.IsOk());
246 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
251 case wxSYS_OEM_FIXED_FONT
:
252 case wxSYS_ANSI_FIXED_FONT
:
253 case wxSYS_SYSTEM_FIXED_FONT
:
254 font
= *wxNORMAL_FONT
;
257 case wxSYS_ANSI_VAR_FONT
:
258 case wxSYS_SYSTEM_FONT
:
259 case wxSYS_DEVICE_DEFAULT_FONT
:
260 case wxSYS_DEFAULT_GUI_FONT
:
261 if (!gs_fontSystem
.Ok())
263 wxNativeFontInfo info
;
264 info
.description
= ButtonStyle()->font_desc
;
265 gs_fontSystem
= wxFont(info
);
268 // (try to) heal the default font (on some common systems e.g. Ubuntu
269 // it's "Sans Serif" but the real font is called "Sans"):
270 if (!wxFontEnumerator::IsValidFacename(gs_fontSystem
.GetFaceName()) &&
271 gs_fontSystem
.GetFaceName() == "Sans Serif")
272 gs_fontSystem
.SetFaceName("Sans");
273 #endif // wxUSE_FONTENUM
275 info
.description
= NULL
;
277 font
= gs_fontSystem
;
284 wxASSERT( font
.IsOk() );
289 // helper: return the GtkSettings either for the screen the current window is
290 // on or for the default screen if window is NULL
291 static GtkSettings
*GetSettingsForWindowScreen(GdkWindow
*window
)
293 return window
? gtk_settings_get_for_screen(gdk_drawable_get_screen(window
))
294 : gtk_settings_get_default();
297 static int GetBorderWidth(wxSystemMetric index
, wxWindow
* win
)
301 wxPizza
* pizza
= WX_PIZZA(win
->m_wxwindow
);
303 pizza
->get_border_widths(x
, y
);
308 case wxSYS_FRAMESIZE_X
:
317 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
, wxWindow
* win
)
319 GdkWindow
*window
= NULL
;
321 window
= gtk_widget_get_window(win
->GetHandle());
329 case wxSYS_FRAMESIZE_X
:
330 case wxSYS_FRAMESIZE_Y
:
333 wxTopLevelWindow
*tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
335 return GetBorderWidth(index
, win
);
338 // Get the frame extents from the windowmanager.
339 // In most cases the top extent is the titlebar, so we use the bottom extent
342 if (wxGetFrameExtents(window
, NULL
, &right
, NULL
, &bottom
))
348 case wxSYS_FRAMESIZE_X
:
349 return right
; // width of right extent
351 return bottom
; // height of bottom extent
357 return -1; // no window specified
361 return gdk_display_get_default_cursor_size(
362 window
? gdk_drawable_get_display(window
)
363 : gdk_display_get_default());
367 gint dclick_distance
;
368 g_object_get(GetSettingsForWindowScreen(window
),
369 "gtk-double-click-distance", &dclick_distance
, NULL
);
371 return dclick_distance
* 2;
373 case wxSYS_DCLICK_MSEC
:
375 g_object_get(GetSettingsForWindowScreen(window
),
376 "gtk-double-click-time", &dclick
, NULL
);
382 g_object_get(GetSettingsForWindowScreen(window
),
383 "gtk-dnd-drag-threshold", &drag_threshold
, NULL
);
385 // The correct thing here would be to double the value
386 // since that is what the API wants. But the values
387 // are much bigger under GNOME than under Windows and
388 // just seem to much in many cases to be useful.
389 // drag_threshold *= 2;
391 return drag_threshold
;
399 return gdk_screen_get_width(gdk_drawable_get_screen(window
));
401 return gdk_screen_width();
405 return gdk_screen_get_height(gdk_drawable_get_screen(window
));
407 return gdk_screen_height();
409 case wxSYS_HSCROLL_Y
:
410 case wxSYS_VSCROLL_X
:
413 case wxSYS_CAPTION_Y
:
415 // No realized window specified, and no implementation for that case yet.
418 wxASSERT_MSG( wxDynamicCast(win
, wxTopLevelWindow
),
419 wxT("Asking for caption height of a non toplevel window") );
421 // Get the height of the top windowmanager border.
422 // This is the titlebar in most cases. The titlebar might be elsewhere, and
423 // we could check which is the thickest wm border to decide on which side the
424 // titlebar is, but this might lead to interesting behaviours in used code.
425 // Reconsider when we have a way to report to the user on which side it is.
428 if (wxGetFrameExtents(window
, NULL
, NULL
, &top
, NULL
))
430 return top
; // top frame extent
434 // Try a default approach without a window pointer, if possible
439 case wxSYS_PENWINDOWS_PRESENT
:
440 // No MS Windows for Pen computing extension available in X11 based gtk+.
444 return -1; // metric is unknown
448 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
452 case wxSYS_CAN_ICONIZE_FRAME
:
455 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: