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 //wxColour *g_systemWinColour = (wxColour *) NULL;
31 wxColour
*g_systemBtnFaceColour
= (wxColour
*) NULL
;
32 wxColour
*g_systemBtnShadowColour
= (wxColour
*) NULL
;
33 wxColour
*g_systemBtnHighlightColour
= (wxColour
*) NULL
;
34 wxColour
*g_systemHighlightColour
= (wxColour
*) NULL
;
35 wxColour
*g_systemHighlightTextColour
= (wxColour
*) NULL
;
36 wxColour
*g_systemListBoxColour
= (wxColour
*) NULL
;
37 wxColour
*g_systemBtnTextColour
= (wxColour
*) NULL
;
39 wxFont
*g_systemFont
= (wxFont
*) NULL
;
41 // ----------------------------------------------------------------------------
42 // wxSystemSettingsModule
43 // ----------------------------------------------------------------------------
45 class wxSystemSettingsModule
: public wxModule
48 bool OnInit() { return TRUE
; }
51 //delete g_systemWinColour;
52 delete g_systemBtnFaceColour
;
53 delete g_systemBtnShadowColour
;
54 delete g_systemBtnHighlightColour
;
55 delete g_systemHighlightColour
;
56 delete g_systemHighlightTextColour
;
57 delete g_systemListBoxColour
;
59 delete g_systemBtnTextColour
;
61 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
64 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
66 // ----------------------------------------------------------------------------
67 // wxSystemSettings implementation
68 // ----------------------------------------------------------------------------
70 // kind of widget to use in GetColourFromGTKWidget
85 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
86 // widget style, return true if we did get them, false to use defaults
87 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
88 wxGtkWidgetType type
= wxGTK_BUTTON
,
89 GtkStateType state
= GTK_STATE_NORMAL
,
90 wxGtkColourType colour
= wxGTK_BG
)
96 wxFAIL_MSG( _T("unexpected GTK widget type") );
100 widget
= gtk_button_new();
104 widget
= gtk_list_new();
107 GtkStyle
*def
= gtk_rc_get_style( widget
);
109 def
= gtk_widget_get_default_style();
118 wxFAIL_MSG( _T("unexpected GTK colour type") );
134 red
= col
[state
].red
;
135 green
= col
[state
].green
;
136 blue
= col
[state
].blue
;
145 gtk_widget_destroy( widget
);
150 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
154 case wxSYS_COLOUR_SCROLLBAR
:
155 case wxSYS_COLOUR_BACKGROUND
:
156 case wxSYS_COLOUR_ACTIVECAPTION
:
157 case wxSYS_COLOUR_INACTIVECAPTION
:
158 case wxSYS_COLOUR_MENU
:
159 case wxSYS_COLOUR_WINDOWFRAME
:
160 case wxSYS_COLOUR_ACTIVEBORDER
:
161 case wxSYS_COLOUR_INACTIVEBORDER
:
162 case wxSYS_COLOUR_BTNFACE
:
163 case wxSYS_COLOUR_MENUBAR
:
164 case wxSYS_COLOUR_3DLIGHT
:
165 if (!g_systemBtnFaceColour
)
167 int red
, green
, blue
;
168 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
175 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
179 return *g_systemBtnFaceColour
;
181 case wxSYS_COLOUR_WINDOW
:
184 case wxSYS_COLOUR_3DDKSHADOW
:
187 case wxSYS_COLOUR_GRAYTEXT
:
188 case wxSYS_COLOUR_BTNSHADOW
:
189 //case wxSYS_COLOUR_3DSHADOW:
190 if (!g_systemBtnShadowColour
)
192 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
193 g_systemBtnShadowColour
=
194 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
195 (unsigned char) (faceColour
.Green() * 0.666),
196 (unsigned char) (faceColour
.Blue() * 0.666));
199 return *g_systemBtnShadowColour
;
201 case wxSYS_COLOUR_3DHIGHLIGHT
:
202 //case wxSYS_COLOUR_BTNHIGHLIGHT:
204 /* I think this should normally be white (JACS 8/2000)
206 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
207 if (!g_systemBtnHighlightColour)
209 g_systemBtnHighlightColour =
210 new wxColour( 0xea60 >> SHIFT,
214 return *g_systemBtnHighlightColour;
217 case wxSYS_COLOUR_HIGHLIGHT
:
218 if (!g_systemHighlightColour
)
220 int red
, green
, blue
;
221 if ( !GetColourFromGTKWidget(red
, green
, blue
,
223 GTK_STATE_SELECTED
) )
230 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
234 return *g_systemHighlightColour
;
236 case wxSYS_COLOUR_LISTBOX
:
237 if (!g_systemListBoxColour
)
239 int red
, green
, blue
;
240 if ( GetColourFromGTKWidget(red
, green
, blue
,
245 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
251 g_systemListBoxColour
= new wxColour(*wxWHITE
);
254 return *g_systemListBoxColour
;
256 case wxSYS_COLOUR_MENUTEXT
:
257 case wxSYS_COLOUR_WINDOWTEXT
:
258 case wxSYS_COLOUR_CAPTIONTEXT
:
259 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
260 case wxSYS_COLOUR_BTNTEXT
:
261 case wxSYS_COLOUR_INFOTEXT
:
262 if (!g_systemBtnTextColour
)
264 int red
, green
, blue
;
265 if ( !GetColourFromGTKWidget(red
, green
, blue
,
275 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
279 return *g_systemBtnTextColour
;
281 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
282 // tooltip windows - Robert, please change this code to use the
283 // real GTK tooltips when/if you can (TODO)
284 case wxSYS_COLOUR_INFOBK
:
285 return wxColour(255, 255, 225);
287 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
288 if (!g_systemHighlightTextColour
)
290 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
291 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
292 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
294 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
296 return *g_systemHighlightTextColour
;
298 case wxSYS_COLOUR_APPWORKSPACE
:
299 return *wxWHITE
; // ?
301 case wxSYS_COLOUR_HOTLIGHT
:
302 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
303 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
304 case wxSYS_COLOUR_MENUHILIGHT
:
308 case wxSYS_COLOUR_MAX
:
310 wxFAIL_MSG( _T("unknown system colour index") );
316 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
320 case wxSYS_OEM_FIXED_FONT
:
321 case wxSYS_ANSI_FIXED_FONT
:
322 case wxSYS_SYSTEM_FIXED_FONT
:
324 return *wxNORMAL_FONT
;
326 case wxSYS_ANSI_VAR_FONT
:
327 case wxSYS_SYSTEM_FONT
:
328 case wxSYS_DEVICE_DEFAULT_FONT
:
329 case wxSYS_DEFAULT_GUI_FONT
:
334 GtkWidget
*widget
= gtk_button_new();
335 GtkStyle
*def
= gtk_rc_get_style( widget
);
336 if ( !def
|| !def
->font_desc
)
337 def
= gtk_widget_get_default_style();
338 if ( def
&& def
->font_desc
)
340 wxNativeFontInfo info
;
341 info
.description
= def
->font_desc
;
342 g_systemFont
= new wxFont(info
);
346 const gchar
*font_name
=
347 _gtk_rc_context_get_default_font_name(gtk_settings_get_default());
348 g_systemFont
= new wxFont(wxString::FromAscii(font_name
));
350 gtk_widget_destroy( widget
);
352 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
355 return *g_systemFont
;
363 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
367 case wxSYS_SCREEN_X
: return gdk_screen_width();
368 case wxSYS_SCREEN_Y
: return gdk_screen_height();
369 case wxSYS_HSCROLL_Y
: return 15;
370 case wxSYS_VSCROLL_X
: return 15;
372 // VZ: is there any way to get the cursor size with GDK?
373 case wxSYS_CURSOR_X
: return 16;
374 case wxSYS_CURSOR_Y
: return 16;
375 // MBN: ditto for icons
376 case wxSYS_ICON_X
: return 32;
377 case wxSYS_ICON_Y
: return 32;
379 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
384 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
388 case wxSYS_CAN_ICONIZE_FRAME
:
391 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: