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"
26 bool wxGetFrameExtents(GdkWindow
* window
, int* left
, int* right
, int* top
, int* bottom
);
28 // ----------------------------------------------------------------------------
29 // wxSystemSettings implementation
30 // ----------------------------------------------------------------------------
32 static wxFont gs_fontSystem
;
34 static GtkContainer
* ContainerWidget()
36 static GtkContainer
* s_widget
;
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
));
47 static void style_set(GtkWidget
*, GtkStyle
*, void*)
49 gs_fontSystem
= wxNullFont
;
53 static const GtkStyle
* ButtonStyle()
55 static GtkWidget
* s_widget
;
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
);
63 return s_widget
->style
;
66 static const GtkStyle
* ListStyle()
68 static GtkWidget
* s_widget
;
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
);
76 return s_widget
->style
;
79 static const GtkStyle
* TextCtrlStyle()
81 static GtkWidget
* s_widget
;
84 s_widget
= gtk_text_view_new();
85 gtk_container_add(ContainerWidget(), s_widget
);
86 gtk_widget_ensure_style(s_widget
);
88 return s_widget
->style
;
91 static const GtkStyle
* MenuItemStyle()
93 static GtkWidget
* s_widget
;
96 s_widget
= gtk_menu_item_new();
97 gtk_container_add(ContainerWidget(), s_widget
);
98 gtk_widget_ensure_style(s_widget
);
100 return s_widget
->style
;
103 static const GtkStyle
* MenuBarStyle()
105 static GtkWidget
* s_widget
;
106 if (s_widget
== NULL
)
108 s_widget
= gtk_menu_bar_new();
109 gtk_container_add(ContainerWidget(), s_widget
);
110 gtk_widget_ensure_style(s_widget
);
112 return s_widget
->style
;
115 static const GtkStyle
* ToolTipStyle()
117 static GtkWidget
* s_widget
;
118 if (s_widget
== NULL
)
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
);
127 return s_widget
->style
;
130 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
135 case wxSYS_COLOUR_SCROLLBAR
:
136 case wxSYS_COLOUR_BACKGROUND
:
137 //case wxSYS_COLOUR_DESKTOP:
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
:
144 //case wxSYS_COLOUR_3DFACE:
145 case wxSYS_COLOUR_3DLIGHT
:
146 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_NORMAL
]);
149 case wxSYS_COLOUR_WINDOW
:
150 color
= wxColor(TextCtrlStyle()->base
[GTK_STATE_NORMAL
]);
153 case wxSYS_COLOUR_MENUBAR
:
154 color
= wxColor(MenuBarStyle()->bg
[GTK_STATE_NORMAL
]);
157 case wxSYS_COLOUR_3DDKSHADOW
:
161 case wxSYS_COLOUR_GRAYTEXT
:
162 case wxSYS_COLOUR_BTNSHADOW
:
163 //case wxSYS_COLOUR_3DSHADOW:
165 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
167 wxColour((unsigned char) (faceColour
.Red() * 2 / 3),
168 (unsigned char) (faceColour
.Green() * 2 / 3),
169 (unsigned char) (faceColour
.Blue() * 2 / 3));
173 case wxSYS_COLOUR_BTNHIGHLIGHT
:
174 //case wxSYS_COLOUR_BTNHILIGHT:
175 //case wxSYS_COLOUR_3DHIGHLIGHT:
176 //case wxSYS_COLOUR_3DHILIGHT:
180 case wxSYS_COLOUR_HIGHLIGHT
:
181 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_SELECTED
]);
184 case wxSYS_COLOUR_LISTBOX
:
185 color
= wxColor(ListStyle()->base
[GTK_STATE_NORMAL
]);
188 case wxSYS_COLOUR_LISTBOXTEXT
:
189 color
= wxColor(ListStyle()->text
[GTK_STATE_NORMAL
]);
192 case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
:
193 // This is for the text in a list control (or tree) when the
194 // item is selected, but not focused
195 color
= wxColor(ListStyle()->text
[GTK_STATE_ACTIVE
]);
198 case wxSYS_COLOUR_MENUTEXT
:
199 case wxSYS_COLOUR_WINDOWTEXT
:
200 case wxSYS_COLOUR_CAPTIONTEXT
:
201 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
202 case wxSYS_COLOUR_BTNTEXT
:
203 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_NORMAL
]);
206 case wxSYS_COLOUR_INFOBK
:
207 color
= wxColor(ToolTipStyle()->bg
[GTK_STATE_NORMAL
]);
210 case wxSYS_COLOUR_INFOTEXT
:
211 color
= wxColor(ToolTipStyle()->fg
[GTK_STATE_NORMAL
]);
214 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
215 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_SELECTED
]);
218 case wxSYS_COLOUR_APPWORKSPACE
:
219 color
= *wxWHITE
; // ?
222 case wxSYS_COLOUR_ACTIVECAPTION
:
223 case wxSYS_COLOUR_MENUHILIGHT
:
224 color
= wxColor(MenuItemStyle()->bg
[GTK_STATE_SELECTED
]);
227 case wxSYS_COLOUR_HOTLIGHT
:
228 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
229 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
234 case wxSYS_COLOUR_MAX
:
236 wxFAIL_MSG( wxT("unknown system colour index") );
241 wxASSERT(color
.IsOk());
245 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
250 case wxSYS_OEM_FIXED_FONT
:
251 case wxSYS_ANSI_FIXED_FONT
:
252 case wxSYS_SYSTEM_FIXED_FONT
:
253 font
= *wxNORMAL_FONT
;
256 case wxSYS_ANSI_VAR_FONT
:
257 case wxSYS_SYSTEM_FONT
:
258 case wxSYS_DEVICE_DEFAULT_FONT
:
259 case wxSYS_DEFAULT_GUI_FONT
:
260 if (!gs_fontSystem
.Ok())
262 wxNativeFontInfo info
;
263 info
.description
= ButtonStyle()->font_desc
;
264 gs_fontSystem
= wxFont(info
);
267 // (try to) heal the default font (on some common systems e.g. Ubuntu
268 // it's "Sans Serif" but the real font is called "Sans"):
269 if (!wxFontEnumerator::IsValidFacename(gs_fontSystem
.GetFaceName()) &&
270 gs_fontSystem
.GetFaceName() == "Sans Serif")
271 gs_fontSystem
.SetFaceName("Sans");
272 #endif // wxUSE_FONTENUM
274 info
.description
= NULL
;
276 font
= gs_fontSystem
;
283 wxASSERT( font
.IsOk() );
288 // helper: return the GtkSettings either for the screen the current window is
289 // on or for the default screen if window is NULL
290 static GtkSettings
*GetSettingsForWindowScreen(GdkWindow
*window
)
292 return window
? gtk_settings_get_for_screen(gdk_drawable_get_screen(window
))
293 : gtk_settings_get_default();
296 static int GetBorderWidth(wxSystemMetric index
, wxWindow
* win
)
300 wxPizza
* pizza
= WX_PIZZA(win
->m_wxwindow
);
302 pizza
->get_border_widths(x
, y
);
307 case wxSYS_FRAMESIZE_X
:
316 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
, wxWindow
* win
)
318 GdkWindow
*window
= NULL
;
319 if(win
&& GTK_WIDGET_REALIZED(win
->GetHandle()))
320 window
= win
->GetHandle()->window
;
328 case wxSYS_FRAMESIZE_X
:
329 case wxSYS_FRAMESIZE_Y
:
332 wxTopLevelWindow
*tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
334 return GetBorderWidth(index
, win
);
337 // Get the frame extents from the windowmanager.
338 // In most cases the top extent is the titlebar, so we use the bottom extent
341 if (wxGetFrameExtents(window
, NULL
, &right
, NULL
, &bottom
))
347 case wxSYS_FRAMESIZE_X
:
348 return right
; // width of right extent
350 return bottom
; // height of bottom extent
356 return -1; // no window specified
360 return gdk_display_get_default_cursor_size(
361 window
? gdk_drawable_get_display(window
)
362 : gdk_display_get_default());
366 gint dclick_distance
;
367 g_object_get(GetSettingsForWindowScreen(window
),
368 "gtk-double-click-distance", &dclick_distance
, NULL
);
370 return dclick_distance
* 2;
372 case wxSYS_DCLICK_MSEC
:
374 g_object_get(GetSettingsForWindowScreen(window
),
375 "gtk-double-click-time", &dclick
, NULL
);
381 g_object_get(GetSettingsForWindowScreen(window
),
382 "gtk-dnd-drag-threshold", &drag_threshold
, NULL
);
384 // The correct thing here would be to double the value
385 // since that is what the API wants. But the values
386 // are much bigger under GNOME than under Windows and
387 // just seem to much in many cases to be useful.
388 // drag_threshold *= 2;
390 return drag_threshold
;
398 return gdk_screen_get_width(gdk_drawable_get_screen(window
));
400 return gdk_screen_width();
404 return gdk_screen_get_height(gdk_drawable_get_screen(window
));
406 return gdk_screen_height();
408 case wxSYS_HSCROLL_Y
:
409 case wxSYS_VSCROLL_X
:
412 case wxSYS_CAPTION_Y
:
414 // No realized window specified, and no implementation for that case yet.
417 wxASSERT_MSG( wxDynamicCast(win
, wxTopLevelWindow
),
418 wxT("Asking for caption height of a non toplevel window") );
420 // Get the height of the top windowmanager border.
421 // This is the titlebar in most cases. The titlebar might be elsewhere, and
422 // we could check which is the thickest wm border to decide on which side the
423 // titlebar is, but this might lead to interesting behaviours in used code.
424 // Reconsider when we have a way to report to the user on which side it is.
427 if (wxGetFrameExtents(window
, NULL
, NULL
, &top
, NULL
))
429 return top
; // top frame extent
433 // Try a default approach without a window pointer, if possible
438 case wxSYS_PENWINDOWS_PRESENT
:
439 // No MS Windows for Pen computing extension available in X11 based gtk+.
443 return -1; // metric is unknown
447 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
451 case wxSYS_CAN_ICONIZE_FRAME
:
454 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: