1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/settings.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "settings.h"
15 #include "wx/settings.h"
17 #include "wx/module.h"
18 #include "wx/cmndata.h"
21 #include <gdk/gdkprivate.h>
24 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
26 //wxColour *g_systemWinColour = (wxColour *) NULL;
27 wxColour
*g_systemBtnFaceColour
= (wxColour
*) NULL
;
28 wxColour
*g_systemBtnShadowColour
= (wxColour
*) NULL
;
29 wxColour
*g_systemBtnHighlightColour
= (wxColour
*) NULL
;
30 wxColour
*g_systemHighlightColour
= (wxColour
*) NULL
;
31 wxColour
*g_systemHighlightTextColour
= (wxColour
*) NULL
;
32 wxColour
*g_systemListBoxColour
= (wxColour
*) NULL
;
33 wxColour
*g_systemBtnTextColour
= (wxColour
*) NULL
;
35 wxFont
*g_systemFont
= (wxFont
*) NULL
;
37 // ----------------------------------------------------------------------------
38 // wxSystemSettingsModule
39 // ----------------------------------------------------------------------------
41 class wxSystemSettingsModule
: public wxModule
44 bool OnInit() { return TRUE
; }
47 //delete g_systemWinColour;
48 delete g_systemBtnFaceColour
;
49 delete g_systemBtnShadowColour
;
50 delete g_systemBtnHighlightColour
;
51 delete g_systemHighlightColour
;
52 delete g_systemHighlightTextColour
;
53 delete g_systemListBoxColour
;
55 delete g_systemBtnTextColour
;
57 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
60 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
62 // ----------------------------------------------------------------------------
63 // wxSystemSettings implementation
64 // ----------------------------------------------------------------------------
66 // kind of widget to use in GetColourFromGTKWidget
81 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
82 // widget style, return true if we did get them, false to use defaults
83 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
84 wxGtkWidgetType type
= wxGTK_BUTTON
,
85 GtkStateType state
= GTK_STATE_NORMAL
,
86 wxGtkColourType colour
= wxGTK_BG
)
92 wxFAIL_MSG( _T("unexpected GTK widget type") );
96 widget
= gtk_button_new();
100 widget
= gtk_list_new();
103 GtkStyle
*def
= gtk_rc_get_style( widget
);
105 def
= gtk_widget_get_default_style();
114 wxFAIL_MSG( _T("unexpected GTK colour type") );
130 red
= col
[state
].red
;
131 green
= col
[state
].green
;
132 blue
= col
[state
].blue
;
141 gtk_widget_destroy( widget
);
146 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
150 case wxSYS_COLOUR_SCROLLBAR
:
151 case wxSYS_COLOUR_BACKGROUND
:
152 case wxSYS_COLOUR_ACTIVECAPTION
:
153 case wxSYS_COLOUR_INACTIVECAPTION
:
154 case wxSYS_COLOUR_MENU
:
155 case wxSYS_COLOUR_WINDOWFRAME
:
156 case wxSYS_COLOUR_ACTIVEBORDER
:
157 case wxSYS_COLOUR_INACTIVEBORDER
:
158 case wxSYS_COLOUR_BTNFACE
:
159 case wxSYS_COLOUR_3DLIGHT
:
160 if (!g_systemBtnFaceColour
)
162 int red
, green
, blue
;
163 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
170 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
174 return *g_systemBtnFaceColour
;
176 case wxSYS_COLOUR_WINDOW
:
179 case wxSYS_COLOUR_3DDKSHADOW
:
182 case wxSYS_COLOUR_GRAYTEXT
:
183 case wxSYS_COLOUR_BTNSHADOW
:
184 //case wxSYS_COLOUR_3DSHADOW:
185 if (!g_systemBtnShadowColour
)
187 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
188 g_systemBtnShadowColour
=
189 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
190 (unsigned char) (faceColour
.Green() * 0.666),
191 (unsigned char) (faceColour
.Blue() * 0.666));
194 return *g_systemBtnShadowColour
;
196 case wxSYS_COLOUR_3DHIGHLIGHT
:
197 //case wxSYS_COLOUR_BTNHIGHLIGHT:
199 /* I think this should normally be white (JACS 8/2000)
201 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
202 if (!g_systemBtnHighlightColour)
204 g_systemBtnHighlightColour =
205 new wxColour( 0xea60 >> SHIFT,
209 return *g_systemBtnHighlightColour;
212 case wxSYS_COLOUR_HIGHLIGHT
:
213 if (!g_systemHighlightColour
)
215 int red
, green
, blue
;
216 if ( !GetColourFromGTKWidget(red
, green
, blue
,
218 GTK_STATE_SELECTED
) )
225 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
229 return *g_systemHighlightColour
;
231 case wxSYS_COLOUR_LISTBOX
:
232 if (!g_systemListBoxColour
)
234 int red
, green
, blue
;
235 if ( GetColourFromGTKWidget(red
, green
, blue
,
240 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
246 g_systemListBoxColour
= new wxColour(*wxWHITE
);
249 return *g_systemListBoxColour
;
251 case wxSYS_COLOUR_MENUTEXT
:
252 case wxSYS_COLOUR_WINDOWTEXT
:
253 case wxSYS_COLOUR_CAPTIONTEXT
:
254 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
255 case wxSYS_COLOUR_BTNTEXT
:
256 case wxSYS_COLOUR_INFOTEXT
:
257 if (!g_systemBtnTextColour
)
259 int red
, green
, blue
;
260 if ( !GetColourFromGTKWidget(red
, green
, blue
,
270 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
274 return *g_systemBtnTextColour
;
276 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
277 // tooltip windows - Robert, please change this code to use the
278 // real GTK tooltips when/if you can (TODO)
279 case wxSYS_COLOUR_INFOBK
:
280 return wxColour(255, 255, 225);
282 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
283 if (!g_systemHighlightTextColour
)
285 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
286 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
287 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
289 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
291 return *g_systemHighlightTextColour
;
293 case wxSYS_COLOUR_APPWORKSPACE
:
294 return *wxWHITE
; // ?
300 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
304 case wxSYS_OEM_FIXED_FONT
:
305 case wxSYS_ANSI_FIXED_FONT
:
306 case wxSYS_SYSTEM_FIXED_FONT
:
308 return *wxNORMAL_FONT
;
310 case wxSYS_ANSI_VAR_FONT
:
311 case wxSYS_SYSTEM_FONT
:
312 case wxSYS_DEVICE_DEFAULT_FONT
:
313 case wxSYS_DEFAULT_GUI_FONT
:
317 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
320 return *g_systemFont
;
328 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
332 case wxSYS_SCREEN_X
: return gdk_screen_width();
333 case wxSYS_SCREEN_Y
: return gdk_screen_height();
334 case wxSYS_HSCROLL_Y
: return 15;
335 case wxSYS_VSCROLL_X
: return 15;
337 // VZ: is there any way to get the cursor size with GDK?
338 case wxSYS_CURSOR_X
: return 16;
339 case wxSYS_CURSOR_Y
: return 16;
342 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
347 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
351 case wxSYS_CAN_ICONIZE_FRAME
:
354 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: