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
,
42 m_colMenuItemHighlight
;
47 static wxSystemObjects gs_objects
;
49 // ----------------------------------------------------------------------------
50 // wxSystemSettings implementation
51 // ----------------------------------------------------------------------------
53 // kind of widget to use in GetColourFromGTKWidget
69 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
70 // widget style, return true if we did get them, false to use defaults
71 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
72 wxGtkWidgetType type
= wxGTK_BUTTON
,
73 GtkStateType state
= GTK_STATE_NORMAL
,
74 wxGtkColourType colour
= wxGTK_BG
)
80 wxFAIL_MSG( _T("unexpected GTK widget type") );
84 widget
= gtk_button_new();
88 widget
= gtk_list_new();
91 widget
= gtk_menu_item_new();
94 GtkStyle
*def
= gtk_rc_get_style( widget
);
96 def
= gtk_widget_get_default_style();
105 wxFAIL_MSG( _T("unexpected GTK colour type") );
121 red
= col
[state
].red
;
122 green
= col
[state
].green
;
123 blue
= col
[state
].blue
;
132 gtk_widget_destroy( widget
);
137 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
141 case wxSYS_COLOUR_SCROLLBAR
:
142 case wxSYS_COLOUR_BACKGROUND
:
143 case wxSYS_COLOUR_INACTIVECAPTION
:
144 case wxSYS_COLOUR_MENU
:
145 case wxSYS_COLOUR_WINDOWFRAME
:
146 case wxSYS_COLOUR_ACTIVEBORDER
:
147 case wxSYS_COLOUR_INACTIVEBORDER
:
148 case wxSYS_COLOUR_BTNFACE
:
149 case wxSYS_COLOUR_MENUBAR
:
150 case wxSYS_COLOUR_3DLIGHT
:
151 if (!gs_objects
.m_colBtnFace
.Ok())
153 int red
, green
, blue
;
154 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
161 gs_objects
.m_colBtnFace
= wxColour( red
>> SHIFT
,
165 return gs_objects
.m_colBtnFace
;
167 case wxSYS_COLOUR_WINDOW
:
170 case wxSYS_COLOUR_3DDKSHADOW
:
173 case wxSYS_COLOUR_GRAYTEXT
:
174 case wxSYS_COLOUR_BTNSHADOW
:
175 //case wxSYS_COLOUR_3DSHADOW:
176 if (!gs_objects
.m_colBtnShadow
.Ok())
178 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
179 gs_objects
.m_colBtnShadow
=
180 wxColour((unsigned char) (faceColour
.Red() * 0.666),
181 (unsigned char) (faceColour
.Green() * 0.666),
182 (unsigned char) (faceColour
.Blue() * 0.666));
185 return gs_objects
.m_colBtnShadow
;
187 case wxSYS_COLOUR_3DHIGHLIGHT
:
188 //case wxSYS_COLOUR_BTNHIGHLIGHT:
191 case wxSYS_COLOUR_HIGHLIGHT
:
192 if (!gs_objects
.m_colHighlight
.Ok())
194 int red
, green
, blue
;
195 if ( !GetColourFromGTKWidget(red
, green
, blue
,
197 GTK_STATE_SELECTED
) )
204 gs_objects
.m_colHighlight
= wxColour( red
>> SHIFT
,
208 return gs_objects
.m_colHighlight
;
210 case wxSYS_COLOUR_LISTBOX
:
211 if (!gs_objects
.m_colListBox
.Ok())
213 int red
, green
, blue
;
214 if ( GetColourFromGTKWidget(red
, green
, blue
,
219 gs_objects
.m_colListBox
= wxColour( red
>> SHIFT
,
225 gs_objects
.m_colListBox
= wxColour(*wxWHITE
);
228 return gs_objects
.m_colListBox
;
230 case wxSYS_COLOUR_MENUTEXT
:
231 case wxSYS_COLOUR_WINDOWTEXT
:
232 case wxSYS_COLOUR_CAPTIONTEXT
:
233 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
234 case wxSYS_COLOUR_BTNTEXT
:
235 case wxSYS_COLOUR_INFOTEXT
:
236 if (!gs_objects
.m_colBtnText
.Ok())
238 int red
, green
, blue
;
239 if ( !GetColourFromGTKWidget(red
, green
, blue
,
249 gs_objects
.m_colBtnText
= wxColour( red
>> SHIFT
,
253 return gs_objects
.m_colBtnText
;
255 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
256 // tooltip windows - Robert, please change this code to use the
257 // real GTK tooltips when/if you can (TODO)
258 case wxSYS_COLOUR_INFOBK
:
259 return wxColour(255, 255, 225);
261 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
262 if (!gs_objects
.m_colHighlightText
.Ok())
264 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
265 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
266 gs_objects
.m_colHighlightText
= wxColour(*wxBLACK
);
268 gs_objects
.m_colHighlightText
= wxColour(*wxWHITE
);
270 return gs_objects
.m_colHighlightText
;
272 case wxSYS_COLOUR_APPWORKSPACE
:
273 return *wxWHITE
; // ?
275 case wxSYS_COLOUR_ACTIVECAPTION
:
276 case wxSYS_COLOUR_MENUHILIGHT
:
277 if (!gs_objects
.m_colMenuItemHighlight
.Ok())
279 int red
, green
, blue
;
280 if ( !GetColourFromGTKWidget(red
, green
, blue
,
290 gs_objects
.m_colMenuItemHighlight
= wxColour( red
>> SHIFT
,
294 return gs_objects
.m_colMenuItemHighlight
;
296 case wxSYS_COLOUR_HOTLIGHT
:
297 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
298 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
302 case wxSYS_COLOUR_MAX
:
304 wxFAIL_MSG( _T("unknown system colour index") );
310 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
314 case wxSYS_OEM_FIXED_FONT
:
315 case wxSYS_ANSI_FIXED_FONT
:
316 case wxSYS_SYSTEM_FIXED_FONT
:
318 return *wxNORMAL_FONT
;
320 case wxSYS_ANSI_VAR_FONT
:
321 case wxSYS_SYSTEM_FONT
:
322 case wxSYS_DEVICE_DEFAULT_FONT
:
323 case wxSYS_DEFAULT_GUI_FONT
:
325 if (!gs_objects
.m_fontSystem
.Ok())
328 GtkWidget
*widget
= gtk_button_new();
329 GtkStyle
*def
= gtk_rc_get_style( widget
);
330 if ( !def
|| !def
->font_desc
)
331 def
= gtk_widget_get_default_style();
332 if ( def
&& def
->font_desc
)
334 wxNativeFontInfo info
;
336 pango_font_description_copy(def
->font_desc
);
337 gs_objects
.m_fontSystem
= wxFont(info
);
341 GtkSettings
*settings
= gtk_settings_get_default();
342 gchar
*font_name
= NULL
;
343 g_object_get ( settings
,
348 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
350 gs_objects
.m_fontSystem
= wxFont(wxString::FromAscii(font_name
));
353 gtk_widget_destroy( widget
);
355 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
358 return gs_objects
.m_fontSystem
;
366 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
370 case wxSYS_SCREEN_X
: return gdk_screen_width();
371 case wxSYS_SCREEN_Y
: return gdk_screen_height();
372 case wxSYS_HSCROLL_Y
: return 15;
373 case wxSYS_VSCROLL_X
: return 15;
375 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 4, 0)
378 gint dclick_distance
;
379 g_object_get(gtk_settings_get_default(), "gtk-double-click-distance", &dclick_distance
, NULL
);
380 return dclick_distance
* 2;
383 #if defined(__WXGTK20__)
387 g_object_get(gtk_settings_get_default(), "gtk-dnd-drag-threshold", &drag_threshold
, NULL
);
388 return drag_threshold
* 2;
391 // VZ: is there any way to get the cursor size with GDK?
392 // Mart Raudsepp: Yes, there is a way to get the default cursor size for a display ever since GDK 2.4
393 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 4, 0)
396 return gdk_display_get_default_cursor_size(gdk_display_get_default());
398 case wxSYS_CURSOR_X
: return 16;
399 case wxSYS_CURSOR_Y
: return 16;
401 // MBN: ditto for icons
402 case wxSYS_ICON_X
: return 32;
403 case wxSYS_ICON_Y
: return 32;
405 return -1; // metric is unknown
409 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
413 case wxSYS_CAN_ICONIZE_FRAME
:
416 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: