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/cmndata.h"
18 #include "wx/toplevel.h"
21 #include "wx/fontutil.h"
25 bool wxGetFrameExtents(GdkWindow
* window
, int* left
, int* right
, int* top
, int* bottom
);
27 // ----------------------------------------------------------------------------
28 // wxSystemSettings implementation
29 // ----------------------------------------------------------------------------
31 static wxFont gs_fontSystem
;
33 static GtkContainer
* ContainerWidget()
35 static GtkContainer
* s_widget
;
38 s_widget
= GTK_CONTAINER(gtk_fixed_new());
39 GtkWidget
* window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
40 gtk_container_add(GTK_CONTAINER(window
), GTK_WIDGET(s_widget
));
46 static void style_set(GtkWidget
*, GtkStyle
*, void*)
48 gs_fontSystem
= wxNullFont
;
52 static const GtkStyle
* ButtonStyle()
54 static GtkWidget
* s_widget
;
57 s_widget
= gtk_button_new();
58 gtk_container_add(ContainerWidget(), s_widget
);
59 gtk_widget_ensure_style(s_widget
);
60 g_signal_connect(s_widget
, "style_set", G_CALLBACK(style_set
), NULL
);
62 return s_widget
->style
;
65 static const GtkStyle
* ListStyle()
67 static GtkWidget
* s_widget
;
70 s_widget
= gtk_tree_view_new_with_model(
71 GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_INT
)));
72 gtk_container_add(ContainerWidget(), s_widget
);
73 gtk_widget_ensure_style(s_widget
);
75 return s_widget
->style
;
78 static const GtkStyle
* TextCtrlStyle()
80 static GtkWidget
* s_widget
;
83 s_widget
= gtk_text_view_new();
84 gtk_container_add(ContainerWidget(), s_widget
);
85 gtk_widget_ensure_style(s_widget
);
87 return s_widget
->style
;
90 static const GtkStyle
* MenuItemStyle()
92 static GtkWidget
* s_widget
;
95 s_widget
= gtk_menu_item_new();
96 gtk_container_add(ContainerWidget(), s_widget
);
97 gtk_widget_ensure_style(s_widget
);
99 return s_widget
->style
;
102 static const GtkStyle
* MenuBarStyle()
104 static GtkWidget
* s_widget
;
105 if (s_widget
== NULL
)
107 s_widget
= gtk_menu_bar_new();
108 gtk_container_add(ContainerWidget(), s_widget
);
109 gtk_widget_ensure_style(s_widget
);
111 return s_widget
->style
;
114 static const GtkStyle
* ToolTipStyle()
116 static GtkWidget
* s_widget
;
117 if (s_widget
== NULL
)
119 s_widget
= gtk_window_new(GTK_WINDOW_POPUP
);
120 const char* name
= "gtk-tooltip";
121 if (gtk_check_version(2, 11, 0))
122 name
= "gtk-tooltips";
123 gtk_widget_set_name(s_widget
, name
);
124 gtk_widget_ensure_style(s_widget
);
126 return s_widget
->style
;
129 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
134 case wxSYS_COLOUR_SCROLLBAR
:
135 case wxSYS_COLOUR_BACKGROUND
:
136 //case wxSYS_COLOUR_DESKTOP:
137 case wxSYS_COLOUR_INACTIVECAPTION
:
138 case wxSYS_COLOUR_MENU
:
139 case wxSYS_COLOUR_WINDOWFRAME
:
140 case wxSYS_COLOUR_ACTIVEBORDER
:
141 case wxSYS_COLOUR_INACTIVEBORDER
:
142 case wxSYS_COLOUR_BTNFACE
:
143 //case wxSYS_COLOUR_3DFACE:
144 case wxSYS_COLOUR_3DLIGHT
:
145 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_NORMAL
]);
148 case wxSYS_COLOUR_WINDOW
:
149 color
= wxColor(TextCtrlStyle()->base
[GTK_STATE_NORMAL
]);
152 case wxSYS_COLOUR_MENUBAR
:
153 color
= wxColor(MenuBarStyle()->bg
[GTK_STATE_NORMAL
]);
156 case wxSYS_COLOUR_3DDKSHADOW
:
160 case wxSYS_COLOUR_GRAYTEXT
:
161 case wxSYS_COLOUR_BTNSHADOW
:
162 //case wxSYS_COLOUR_3DSHADOW:
164 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
166 wxColour((unsigned char) (faceColour
.Red() * 2 / 3),
167 (unsigned char) (faceColour
.Green() * 2 / 3),
168 (unsigned char) (faceColour
.Blue() * 2 / 3));
172 case wxSYS_COLOUR_BTNHIGHLIGHT
:
173 //case wxSYS_COLOUR_BTNHILIGHT:
174 //case wxSYS_COLOUR_3DHIGHLIGHT:
175 //case wxSYS_COLOUR_3DHILIGHT:
179 case wxSYS_COLOUR_HIGHLIGHT
:
180 color
= wxColor(ButtonStyle()->bg
[GTK_STATE_SELECTED
]);
183 case wxSYS_COLOUR_LISTBOX
:
184 color
= wxColor(ListStyle()->base
[GTK_STATE_NORMAL
]);
187 case wxSYS_COLOUR_MENUTEXT
:
188 case wxSYS_COLOUR_WINDOWTEXT
:
189 case wxSYS_COLOUR_CAPTIONTEXT
:
190 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
191 case wxSYS_COLOUR_BTNTEXT
:
192 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_NORMAL
]);
195 case wxSYS_COLOUR_INFOBK
:
196 color
= wxColor(ToolTipStyle()->bg
[GTK_STATE_NORMAL
]);
199 case wxSYS_COLOUR_INFOTEXT
:
200 color
= wxColor(ToolTipStyle()->fg
[GTK_STATE_NORMAL
]);
203 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
204 color
= wxColor(ButtonStyle()->fg
[GTK_STATE_SELECTED
]);
207 case wxSYS_COLOUR_APPWORKSPACE
:
208 color
= *wxWHITE
; // ?
211 case wxSYS_COLOUR_ACTIVECAPTION
:
212 case wxSYS_COLOUR_MENUHILIGHT
:
213 color
= wxColor(MenuItemStyle()->bg
[GTK_STATE_SELECTED
]);
216 case wxSYS_COLOUR_HOTLIGHT
:
217 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
218 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
223 case wxSYS_COLOUR_MAX
:
225 wxFAIL_MSG( _T("unknown system colour index") );
233 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
238 case wxSYS_OEM_FIXED_FONT
:
239 case wxSYS_ANSI_FIXED_FONT
:
240 case wxSYS_SYSTEM_FIXED_FONT
:
241 font
= *wxNORMAL_FONT
;
244 case wxSYS_ANSI_VAR_FONT
:
245 case wxSYS_SYSTEM_FONT
:
246 case wxSYS_DEVICE_DEFAULT_FONT
:
247 case wxSYS_DEFAULT_GUI_FONT
:
248 if (!gs_fontSystem
.Ok())
250 wxNativeFontInfo info
;
251 info
.description
= ButtonStyle()->font_desc
;
252 gs_fontSystem
= wxFont(info
);
253 info
.description
= NULL
;
255 font
= gs_fontSystem
;
264 // helper: return the GtkSettings either for the screen the current window is
265 // on or for the default screen if window is NULL
266 static GtkSettings
*GetSettingsForWindowScreen(GdkWindow
*window
)
268 return window
? gtk_settings_get_for_screen(gdk_drawable_get_screen(window
))
269 : gtk_settings_get_default();
272 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
, wxWindow
* win
)
274 GdkWindow
*window
= NULL
;
275 if(win
&& GTK_WIDGET_REALIZED(win
->GetHandle()))
276 window
= win
->GetHandle()->window
;
284 case wxSYS_FRAMESIZE_X
:
285 case wxSYS_FRAMESIZE_Y
:
286 // If a window is specified/realized, and it is a toplevel window, we can query from wm.
287 // The returned border thickness is outside the client area in that case.
290 wxTopLevelWindow
*tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
292 return -1; // not a tlw, not sure how to approach
295 // Get the frame extents from the windowmanager.
296 // In most cases the top extent is the titlebar, so we use the bottom extent
299 if (wxGetFrameExtents(window
, NULL
, &right
, NULL
, &bottom
))
305 case wxSYS_FRAMESIZE_X
:
306 return right
; // width of right extent
308 return bottom
; // height of bottom extent
314 return -1; // no window specified
318 return gdk_display_get_default_cursor_size(
319 window
? gdk_drawable_get_display(window
)
320 : gdk_display_get_default());
324 gint dclick_distance
;
325 g_object_get(GetSettingsForWindowScreen(window
),
326 "gtk-double-click-distance", &dclick_distance
, NULL
);
328 return dclick_distance
* 2;
330 case wxSYS_DCLICK_MSEC
:
332 g_object_get(GetSettingsForWindowScreen(window
),
333 "gtk-double-click-time", &dclick
, NULL
);
339 g_object_get(GetSettingsForWindowScreen(window
),
340 "gtk-dnd-drag-threshold", &drag_threshold
, NULL
);
342 // The correct thing here would be to double the value
343 // since that is what the API wants. But the values
344 // are much bigger under GNOME than under Windows and
345 // just seem to much in many cases to be useful.
346 // drag_threshold *= 2;
348 return drag_threshold
;
356 return gdk_screen_get_width(gdk_drawable_get_screen(window
));
358 return gdk_screen_width();
362 return gdk_screen_get_height(gdk_drawable_get_screen(window
));
364 return gdk_screen_height();
366 case wxSYS_HSCROLL_Y
:
367 case wxSYS_VSCROLL_X
:
370 case wxSYS_CAPTION_Y
:
372 // No realized window specified, and no implementation for that case yet.
375 wxASSERT_MSG( wxDynamicCast(win
, wxTopLevelWindow
),
376 wxT("Asking for caption height of a non toplevel window") );
378 // Get the height of the top windowmanager border.
379 // This is the titlebar in most cases. The titlebar might be elsewhere, and
380 // we could check which is the thickest wm border to decide on which side the
381 // titlebar is, but this might lead to interesting behaviours in used code.
382 // Reconsider when we have a way to report to the user on which side it is.
385 if (wxGetFrameExtents(window
, NULL
, NULL
, &top
, NULL
))
387 return top
; // top frame extent
391 // Try a default approach without a window pointer, if possible
396 case wxSYS_PENWINDOWS_PRESENT
:
397 // No MS Windows for Pen computing extension available in X11 based gtk+.
401 return -1; // metric is unknown
405 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
409 case wxSYS_CAN_ICONIZE_FRAME
:
412 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: