1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/settings.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "settings.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
18 #include "wx/settings.h"
20 #include "wx/cmndata.h"
21 #include "wx/fontutil.h"
24 #include <gdk/gdkprivate.h>
27 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 struct wxSystemObjects
35 wxColour m_colBtnFace
,
46 static wxSystemObjects gs_objects
;
48 // ----------------------------------------------------------------------------
49 // wxSystemSettings implementation
50 // ----------------------------------------------------------------------------
52 // kind of widget to use in GetColourFromGTKWidget
67 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
68 // widget style, return true if we did get them, false to use defaults
69 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
70 wxGtkWidgetType type
= wxGTK_BUTTON
,
71 GtkStateType state
= GTK_STATE_NORMAL
,
72 wxGtkColourType colour
= wxGTK_BG
)
78 wxFAIL_MSG( _T("unexpected GTK widget type") );
82 widget
= gtk_button_new();
86 widget
= gtk_list_new();
89 GtkStyle
*def
= gtk_rc_get_style( widget
);
91 def
= gtk_widget_get_default_style();
100 wxFAIL_MSG( _T("unexpected GTK colour type") );
116 red
= col
[state
].red
;
117 green
= col
[state
].green
;
118 blue
= col
[state
].blue
;
127 gtk_widget_destroy( widget
);
132 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
136 case wxSYS_COLOUR_SCROLLBAR
:
137 case wxSYS_COLOUR_BACKGROUND
:
138 case wxSYS_COLOUR_ACTIVECAPTION
:
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_MENUBAR
:
146 case wxSYS_COLOUR_3DLIGHT
:
147 if (!gs_objects
.m_colBtnFace
.Ok())
149 int red
, green
, blue
;
150 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
157 gs_objects
.m_colBtnFace
= wxColour( red
>> SHIFT
,
161 return gs_objects
.m_colBtnFace
;
163 case wxSYS_COLOUR_WINDOW
:
166 case wxSYS_COLOUR_3DDKSHADOW
:
169 case wxSYS_COLOUR_GRAYTEXT
:
170 case wxSYS_COLOUR_BTNSHADOW
:
171 //case wxSYS_COLOUR_3DSHADOW:
172 if (!gs_objects
.m_colBtnShadow
.Ok())
174 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
175 gs_objects
.m_colBtnShadow
=
176 wxColour((unsigned char) (faceColour
.Red() * 0.666),
177 (unsigned char) (faceColour
.Green() * 0.666),
178 (unsigned char) (faceColour
.Blue() * 0.666));
181 return gs_objects
.m_colBtnShadow
;
183 case wxSYS_COLOUR_3DHIGHLIGHT
:
184 //case wxSYS_COLOUR_BTNHIGHLIGHT:
187 case wxSYS_COLOUR_HIGHLIGHT
:
188 if (!gs_objects
.m_colHighlight
.Ok())
190 int red
, green
, blue
;
191 if ( !GetColourFromGTKWidget(red
, green
, blue
,
193 GTK_STATE_SELECTED
) )
200 gs_objects
.m_colHighlight
= wxColour( red
>> SHIFT
,
204 return gs_objects
.m_colHighlight
;
206 case wxSYS_COLOUR_LISTBOX
:
207 if (!gs_objects
.m_colListBox
.Ok())
209 int red
, green
, blue
;
210 if ( GetColourFromGTKWidget(red
, green
, blue
,
215 gs_objects
.m_colListBox
= wxColour( red
>> SHIFT
,
221 gs_objects
.m_colListBox
= wxColour(*wxWHITE
);
224 return gs_objects
.m_colListBox
;
226 case wxSYS_COLOUR_MENUTEXT
:
227 case wxSYS_COLOUR_WINDOWTEXT
:
228 case wxSYS_COLOUR_CAPTIONTEXT
:
229 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
230 case wxSYS_COLOUR_BTNTEXT
:
231 case wxSYS_COLOUR_INFOTEXT
:
232 if (!gs_objects
.m_colBtnText
.Ok())
234 int red
, green
, blue
;
235 if ( !GetColourFromGTKWidget(red
, green
, blue
,
245 gs_objects
.m_colBtnText
= wxColour( red
>> SHIFT
,
249 return gs_objects
.m_colBtnText
;
251 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
252 // tooltip windows - Robert, please change this code to use the
253 // real GTK tooltips when/if you can (TODO)
254 case wxSYS_COLOUR_INFOBK
:
255 return wxColour(255, 255, 225);
257 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
258 if (!gs_objects
.m_colHighlightText
.Ok())
260 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
261 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
262 gs_objects
.m_colHighlightText
= wxColour(*wxBLACK
);
264 gs_objects
.m_colHighlightText
= wxColour(*wxWHITE
);
266 return gs_objects
.m_colHighlightText
;
268 case wxSYS_COLOUR_APPWORKSPACE
:
269 return *wxWHITE
; // ?
271 case wxSYS_COLOUR_HOTLIGHT
:
272 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
273 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
274 case wxSYS_COLOUR_MENUHILIGHT
:
278 case wxSYS_COLOUR_MAX
:
280 wxFAIL_MSG( _T("unknown system colour index") );
286 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
290 case wxSYS_OEM_FIXED_FONT
:
291 case wxSYS_ANSI_FIXED_FONT
:
292 case wxSYS_SYSTEM_FIXED_FONT
:
294 return *wxNORMAL_FONT
;
296 case wxSYS_ANSI_VAR_FONT
:
297 case wxSYS_SYSTEM_FONT
:
298 case wxSYS_DEVICE_DEFAULT_FONT
:
299 case wxSYS_DEFAULT_GUI_FONT
:
301 if (!gs_objects
.m_fontSystem
.Ok())
304 GtkWidget
*widget
= gtk_button_new();
305 GtkStyle
*def
= gtk_rc_get_style( widget
);
306 if ( !def
|| !def
->font_desc
)
307 def
= gtk_widget_get_default_style();
308 if ( def
&& def
->font_desc
)
310 wxNativeFontInfo info
;
312 pango_font_description_copy(def
->font_desc
);
313 gs_objects
.m_fontSystem
= wxFont(info
);
317 GtkSettings
*settings
= gtk_settings_get_default();
318 gchar
*font_name
= NULL
;
319 g_object_get ( settings
,
324 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
326 gs_objects
.m_fontSystem
= wxFont(wxString::FromAscii(font_name
));
329 gtk_widget_destroy( widget
);
331 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
334 return gs_objects
.m_fontSystem
;
342 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
346 case wxSYS_SCREEN_X
: return gdk_screen_width();
347 case wxSYS_SCREEN_Y
: return gdk_screen_height();
348 case wxSYS_HSCROLL_Y
: return 15;
349 case wxSYS_VSCROLL_X
: return 15;
351 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 4, 0)
354 gint dclick_distance
;
355 g_object_get(gtk_settings_get_default(), "gtk-double-click-distance", &dclick_distance
, NULL
);
356 return dclick_distance
* 2;
359 #if defined(__WXGTK20__)
363 g_object_get(gtk_settings_get_default(), "gtk-dnd-drag-threshold", &drag_threshold
, NULL
);
364 return drag_threshold
* 2;
367 // VZ: is there any way to get the cursor size with GDK?
368 // Mart Raudsepp: Yes, there is a way to get the default cursor size for a display ever since GDK 2.4
369 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 4, 0)
372 return gdk_display_get_default_cursor_size(gdk_display_get_default());
374 case wxSYS_CURSOR_X
: return 16;
375 case wxSYS_CURSOR_Y
: return 16;
377 // MBN: ditto for icons
378 case wxSYS_ICON_X
: return 32;
379 case wxSYS_ICON_Y
: return 32;
381 return -1; // metric is unknown
385 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
389 case wxSYS_CAN_ICONIZE_FRAME
:
392 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: