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/module.h"
21 #include "wx/cmndata.h"
22 #include "wx/fontutil.h"
25 #include <gdk/gdkprivate.h>
28 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
30 // ----------------------------------------------------------------------------
31 // wxSystemSettingsModule
32 // ----------------------------------------------------------------------------
34 class wxSystemSettingsModule
: public wxModule
37 virtual bool OnInit() { ms_instance
= this; return TRUE
; }
38 virtual void OnExit() { ms_instance
= NULL
; }
40 static wxSystemSettingsModule
*ms_instance
;
42 wxColour m_colBtnFace
,
53 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
56 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
58 wxSystemSettingsModule
*wxSystemSettingsModule::ms_instance
= NULL
;
60 // ----------------------------------------------------------------------------
61 // wxSystemSettings implementation
62 // ----------------------------------------------------------------------------
64 // kind of widget to use in GetColourFromGTKWidget
79 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
80 // widget style, return true if we did get them, false to use defaults
81 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
82 wxGtkWidgetType type
= wxGTK_BUTTON
,
83 GtkStateType state
= GTK_STATE_NORMAL
,
84 wxGtkColourType colour
= wxGTK_BG
)
90 wxFAIL_MSG( _T("unexpected GTK widget type") );
94 widget
= gtk_button_new();
98 widget
= gtk_list_new();
101 GtkStyle
*def
= gtk_rc_get_style( widget
);
103 def
= gtk_widget_get_default_style();
112 wxFAIL_MSG( _T("unexpected GTK colour type") );
128 red
= col
[state
].red
;
129 green
= col
[state
].green
;
130 blue
= col
[state
].blue
;
139 gtk_widget_destroy( widget
);
144 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
148 case wxSYS_COLOUR_SCROLLBAR
:
149 case wxSYS_COLOUR_BACKGROUND
:
150 case wxSYS_COLOUR_ACTIVECAPTION
:
151 case wxSYS_COLOUR_INACTIVECAPTION
:
152 case wxSYS_COLOUR_MENU
:
153 case wxSYS_COLOUR_WINDOWFRAME
:
154 case wxSYS_COLOUR_ACTIVEBORDER
:
155 case wxSYS_COLOUR_INACTIVEBORDER
:
156 case wxSYS_COLOUR_BTNFACE
:
157 case wxSYS_COLOUR_MENUBAR
:
158 case wxSYS_COLOUR_3DLIGHT
:
159 if (!wxSystemSettingsModule::ms_instance
->m_colBtnFace
.Ok())
161 int red
, green
, blue
;
162 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
169 wxSystemSettingsModule::ms_instance
->m_colBtnFace
= wxColour( red
>> SHIFT
,
173 return wxSystemSettingsModule::ms_instance
->m_colBtnFace
;
175 case wxSYS_COLOUR_WINDOW
:
178 case wxSYS_COLOUR_3DDKSHADOW
:
181 case wxSYS_COLOUR_GRAYTEXT
:
182 case wxSYS_COLOUR_BTNSHADOW
:
183 //case wxSYS_COLOUR_3DSHADOW:
184 if (!wxSystemSettingsModule::ms_instance
->m_colBtnShadow
.Ok())
186 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
187 wxSystemSettingsModule::ms_instance
->m_colBtnShadow
=
188 wxColour((unsigned char) (faceColour
.Red() * 0.666),
189 (unsigned char) (faceColour
.Green() * 0.666),
190 (unsigned char) (faceColour
.Blue() * 0.666));
193 return wxSystemSettingsModule::ms_instance
->m_colBtnShadow
;
195 case wxSYS_COLOUR_3DHIGHLIGHT
:
196 //case wxSYS_COLOUR_BTNHIGHLIGHT:
199 case wxSYS_COLOUR_HIGHLIGHT
:
200 if (!wxSystemSettingsModule::ms_instance
->m_colHighlight
.Ok())
202 int red
, green
, blue
;
203 if ( !GetColourFromGTKWidget(red
, green
, blue
,
205 GTK_STATE_SELECTED
) )
212 wxSystemSettingsModule::ms_instance
->m_colHighlight
= wxColour( red
>> SHIFT
,
216 return wxSystemSettingsModule::ms_instance
->m_colHighlight
;
218 case wxSYS_COLOUR_LISTBOX
:
219 if (!wxSystemSettingsModule::ms_instance
->m_colListBox
.Ok())
221 int red
, green
, blue
;
222 if ( GetColourFromGTKWidget(red
, green
, blue
,
227 wxSystemSettingsModule::ms_instance
->m_colListBox
= wxColour( red
>> SHIFT
,
233 wxSystemSettingsModule::ms_instance
->m_colListBox
= wxColour(*wxWHITE
);
236 return wxSystemSettingsModule::ms_instance
->m_colListBox
;
238 case wxSYS_COLOUR_MENUTEXT
:
239 case wxSYS_COLOUR_WINDOWTEXT
:
240 case wxSYS_COLOUR_CAPTIONTEXT
:
241 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
242 case wxSYS_COLOUR_BTNTEXT
:
243 case wxSYS_COLOUR_INFOTEXT
:
244 if (!wxSystemSettingsModule::ms_instance
->m_colBtnText
.Ok())
246 int red
, green
, blue
;
247 if ( !GetColourFromGTKWidget(red
, green
, blue
,
257 wxSystemSettingsModule::ms_instance
->m_colBtnText
= wxColour( red
>> SHIFT
,
261 return wxSystemSettingsModule::ms_instance
->m_colBtnText
;
263 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
264 // tooltip windows - Robert, please change this code to use the
265 // real GTK tooltips when/if you can (TODO)
266 case wxSYS_COLOUR_INFOBK
:
267 return wxColour(255, 255, 225);
269 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
270 if (!wxSystemSettingsModule::ms_instance
->m_colHighlightText
.Ok())
272 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
273 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
274 wxSystemSettingsModule::ms_instance
->m_colHighlightText
= wxColour(*wxBLACK
);
276 wxSystemSettingsModule::ms_instance
->m_colHighlightText
= wxColour(*wxWHITE
);
278 return wxSystemSettingsModule::ms_instance
->m_colHighlightText
;
280 case wxSYS_COLOUR_APPWORKSPACE
:
281 return *wxWHITE
; // ?
283 case wxSYS_COLOUR_HOTLIGHT
:
284 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
285 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
286 case wxSYS_COLOUR_MENUHILIGHT
:
290 case wxSYS_COLOUR_MAX
:
292 wxFAIL_MSG( _T("unknown system colour index") );
298 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
302 case wxSYS_OEM_FIXED_FONT
:
303 case wxSYS_ANSI_FIXED_FONT
:
304 case wxSYS_SYSTEM_FIXED_FONT
:
306 return *wxNORMAL_FONT
;
308 case wxSYS_ANSI_VAR_FONT
:
309 case wxSYS_SYSTEM_FONT
:
310 case wxSYS_DEVICE_DEFAULT_FONT
:
311 case wxSYS_DEFAULT_GUI_FONT
:
313 if (!wxSystemSettingsModule::ms_instance
->m_fontSystem
.Ok())
316 GtkWidget
*widget
= gtk_button_new();
317 GtkStyle
*def
= gtk_rc_get_style( widget
);
318 if ( !def
|| !def
->font_desc
)
319 def
= gtk_widget_get_default_style();
320 if ( def
&& def
->font_desc
)
322 wxNativeFontInfo info
;
323 info
.description
= def
->font_desc
;
324 wxSystemSettingsModule::ms_instance
->m_fontSystem
= wxFont(info
);
328 const gchar
*font_name
=
329 _gtk_rc_context_get_default_font_name(gtk_settings_get_default());
330 wxSystemSettingsModule::ms_instance
->m_fontSystem
= wxFont(wxString::FromAscii(font_name
));
332 gtk_widget_destroy( widget
);
334 wxSystemSettingsModule::ms_instance
->m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
337 return wxSystemSettingsModule::ms_instance
->m_fontSystem
;
345 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
349 case wxSYS_SCREEN_X
: return gdk_screen_width();
350 case wxSYS_SCREEN_Y
: return gdk_screen_height();
351 case wxSYS_HSCROLL_Y
: return 15;
352 case wxSYS_VSCROLL_X
: return 15;
354 // VZ: is there any way to get the cursor size with GDK?
355 case wxSYS_CURSOR_X
: return 16;
356 case wxSYS_CURSOR_Y
: return 16;
357 // MBN: ditto for icons
358 case wxSYS_ICON_X
: return 32;
359 case wxSYS_ICON_Y
: return 32;
361 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
366 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
370 case wxSYS_CAN_ICONIZE_FRAME
:
373 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: