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 extern GdkFont
*GtkGetDefaultGuiFont();
28 #define wxSYS_COLOUR_SCROLLBAR 0
29 #define wxSYS_COLOUR_BACKGROUND 1
30 #define wxSYS_COLOUR_ACTIVECAPTION 2
31 #define wxSYS_COLOUR_INACTIVECAPTION 3
32 #define wxSYS_COLOUR_MENU 4
33 #define wxSYS_COLOUR_WINDOW 5
34 #define wxSYS_COLOUR_WINDOWFRAME 6
35 #define wxSYS_COLOUR_MENUTEXT 7
36 #define wxSYS_COLOUR_WINDOWTEXT 8
37 #define wxSYS_COLOUR_CAPTIONTEXT 9
38 #define wxSYS_COLOUR_ACTIVEBORDER 10
39 #define wxSYS_COLOUR_INACTIVEBORDER 11
40 #define wxSYS_COLOUR_APPWORKSPACE 12
41 #define wxSYS_COLOUR_HIGHLIGHT 13
42 #define wxSYS_COLOUR_HIGHLIGHTTEXT 14
43 #define wxSYS_COLOUR_BTNFACE 15
44 #define wxSYS_COLOUR_BTNSHADOW 16
45 #define wxSYS_COLOUR_GRAYTEXT 17
46 #define wxSYS_COLOUR_BTNTEXT 18
47 #define wxSYS_COLOUR_INACTIVECAPTIONTEXT 19
48 #define wxSYS_COLOUR_BTNHIGHLIGHT 20
50 #define wxSYS_COLOUR_3DDKSHADOW 21
51 #define wxSYS_COLOUR_3DLIGHT 22
52 #define wxSYS_COLOUR_INFOTEXT 23
53 #define wxSYS_COLOUR_INFOBK 24
55 #define wxSYS_COLOUR_DESKTOP wxSYS_COLOUR_BACKGROUND
56 #define wxSYS_COLOUR_3DFACE wxSYS_COLOUR_BTNFACE
57 #define wxSYS_COLOUR_3DSHADOW wxSYS_COLOUR_BTNSHADOW
58 #define wxSYS_COLOUR_3DHIGHLIGHT wxSYS_COLOUR_BTNHIGHLIGHT
59 #define wxSYS_COLOUR_3DHILIGHT wxSYS_COLOUR_BTNHIGHLIGHT
60 #define wxSYS_COLOUR_BTNHILIGHT wxSYS_COLOUR_BTNHIGHLIGHT
63 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
65 //wxColour *g_systemWinColour = (wxColour *) NULL;
66 wxColour
*g_systemBtnFaceColour
= (wxColour
*) NULL
;
67 wxColour
*g_systemBtnShadowColour
= (wxColour
*) NULL
;
68 wxColour
*g_systemBtnHighlightColour
= (wxColour
*) NULL
;
69 wxColour
*g_systemHighlightColour
= (wxColour
*) NULL
;
70 wxColour
*g_systemHighlightTextColour
= (wxColour
*) NULL
;
71 wxColour
*g_systemListBoxColour
= (wxColour
*) NULL
;
72 wxColour
*g_systemBtnTextColour
= (wxColour
*) NULL
;
74 wxFont
*g_systemFont
= (wxFont
*) NULL
;
76 // ----------------------------------------------------------------------------
77 // wxSystemSettingsModule
78 // ----------------------------------------------------------------------------
80 class wxSystemSettingsModule
: public wxModule
83 bool OnInit() { return TRUE
; }
86 //delete g_systemWinColour;
87 delete g_systemBtnFaceColour
;
88 delete g_systemBtnShadowColour
;
89 delete g_systemBtnHighlightColour
;
90 delete g_systemHighlightColour
;
91 delete g_systemHighlightTextColour
;
92 delete g_systemListBoxColour
;
94 delete g_systemBtnTextColour
;
96 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
99 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
101 // ----------------------------------------------------------------------------
102 // wxSystemSettings implementation
103 // ----------------------------------------------------------------------------
105 // kind of widget to use in GetColourFromGTKWidget
112 // the colour we need
120 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
121 // widget style, return true if we did get them, false to use defaults
122 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
123 wxGtkWidgetType type
= wxGTK_BUTTON
,
124 GtkStateType state
= GTK_STATE_NORMAL
,
125 wxGtkColourType colour
= wxGTK_BG
)
131 wxFAIL_MSG( _T("unexpected GTK widget type") );
135 widget
= gtk_button_new();
139 widget
= gtk_list_new();
142 GtkStyle
*def
= gtk_rc_get_style( widget
);
144 def
= gtk_widget_get_default_style();
153 wxFAIL_MSG( _T("unexpected GTK colour type") );
169 red
= col
[state
].red
;
170 green
= col
[state
].green
;
171 blue
= col
[state
].blue
;
180 gtk_widget_destroy( widget
);
185 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
189 case wxSYS_COLOUR_SCROLLBAR
:
190 case wxSYS_COLOUR_BACKGROUND
:
191 case wxSYS_COLOUR_ACTIVECAPTION
:
192 case wxSYS_COLOUR_INACTIVECAPTION
:
193 case wxSYS_COLOUR_MENU
:
194 case wxSYS_COLOUR_WINDOWFRAME
:
195 case wxSYS_COLOUR_ACTIVEBORDER
:
196 case wxSYS_COLOUR_INACTIVEBORDER
:
197 case wxSYS_COLOUR_BTNFACE
:
198 case wxSYS_COLOUR_3DLIGHT
:
199 if (!g_systemBtnFaceColour
)
201 int red
, green
, blue
;
202 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
209 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
213 return *g_systemBtnFaceColour
;
215 case wxSYS_COLOUR_WINDOW
:
218 case wxSYS_COLOUR_3DDKSHADOW
:
221 case wxSYS_COLOUR_GRAYTEXT
:
222 case wxSYS_COLOUR_BTNSHADOW
:
223 //case wxSYS_COLOUR_3DSHADOW:
224 if (!g_systemBtnShadowColour
)
226 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
227 g_systemBtnShadowColour
=
228 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
229 (unsigned char) (faceColour
.Green() * 0.666),
230 (unsigned char) (faceColour
.Blue() * 0.666));
233 return *g_systemBtnShadowColour
;
235 case wxSYS_COLOUR_3DHIGHLIGHT
:
236 //case wxSYS_COLOUR_BTNHIGHLIGHT:
238 /* I think this should normally be white (JACS 8/2000)
240 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
241 if (!g_systemBtnHighlightColour)
243 g_systemBtnHighlightColour =
244 new wxColour( 0xea60 >> SHIFT,
248 return *g_systemBtnHighlightColour;
251 case wxSYS_COLOUR_HIGHLIGHT
:
252 if (!g_systemHighlightColour
)
254 int red
, green
, blue
;
255 if ( !GetColourFromGTKWidget(red
, green
, blue
,
257 GTK_STATE_SELECTED
) )
264 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
268 return *g_systemHighlightColour
;
270 case wxSYS_COLOUR_LISTBOX
:
271 if (!g_systemListBoxColour
)
273 int red
, green
, blue
;
274 if ( GetColourFromGTKWidget(red
, green
, blue
,
279 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
285 g_systemListBoxColour
= new wxColour(*wxWHITE
);
288 return *g_systemListBoxColour
;
290 case wxSYS_COLOUR_MENUTEXT
:
291 case wxSYS_COLOUR_WINDOWTEXT
:
292 case wxSYS_COLOUR_CAPTIONTEXT
:
293 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
294 case wxSYS_COLOUR_BTNTEXT
:
295 case wxSYS_COLOUR_INFOTEXT
:
296 if (!g_systemBtnTextColour
)
298 int red
, green
, blue
;
299 if ( !GetColourFromGTKWidget(red
, green
, blue
,
309 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
313 return *g_systemBtnTextColour
;
315 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
316 if (!g_systemHighlightTextColour
)
318 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
319 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
320 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
322 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
324 return *g_systemHighlightTextColour
;
326 case wxSYS_COLOUR_INFOBK
:
327 case wxSYS_COLOUR_APPWORKSPACE
:
328 return *wxWHITE
; // ?
334 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
338 case wxSYS_OEM_FIXED_FONT
:
339 case wxSYS_ANSI_FIXED_FONT
:
340 case wxSYS_SYSTEM_FIXED_FONT
:
342 return *wxNORMAL_FONT
;
344 case wxSYS_ANSI_VAR_FONT
:
345 case wxSYS_SYSTEM_FONT
:
346 case wxSYS_DEVICE_DEFAULT_FONT
:
347 case wxSYS_DEFAULT_GUI_FONT
:
352 GdkFont
*gdk_font
= GtkGetDefaultGuiFont();
355 GSList
*font_list
= ((GdkFontPrivate
*)gdk_font
)->names
;
356 char *name
= (char*)font_list
->data
;
357 wxString
font_string( name
);
358 wxFontData font_data
;
359 g_systemFont
= new wxFont( font_string
, font_data
);
361 gtk_widget_destroy( widget
);
364 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
367 return *g_systemFont
;
375 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
379 case wxSYS_SCREEN_X
: return gdk_screen_width();
380 case wxSYS_SCREEN_Y
: return gdk_screen_height();
381 case wxSYS_HSCROLL_Y
: return 15;
382 case wxSYS_VSCROLL_X
: return 15;
384 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
389 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
393 case wxSYS_CAN_ICONIZE_FRAME
:
396 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: