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>
25 #define wxSYS_COLOUR_SCROLLBAR 0
26 #define wxSYS_COLOUR_BACKGROUND 1
27 #define wxSYS_COLOUR_ACTIVECAPTION 2
28 #define wxSYS_COLOUR_INACTIVECAPTION 3
29 #define wxSYS_COLOUR_MENU 4
30 #define wxSYS_COLOUR_WINDOW 5
31 #define wxSYS_COLOUR_WINDOWFRAME 6
32 #define wxSYS_COLOUR_MENUTEXT 7
33 #define wxSYS_COLOUR_WINDOWTEXT 8
34 #define wxSYS_COLOUR_CAPTIONTEXT 9
35 #define wxSYS_COLOUR_ACTIVEBORDER 10
36 #define wxSYS_COLOUR_INACTIVEBORDER 11
37 #define wxSYS_COLOUR_APPWORKSPACE 12
38 #define wxSYS_COLOUR_HIGHLIGHT 13
39 #define wxSYS_COLOUR_HIGHLIGHTTEXT 14
40 #define wxSYS_COLOUR_BTNFACE 15
41 #define wxSYS_COLOUR_BTNSHADOW 16
42 #define wxSYS_COLOUR_GRAYTEXT 17
43 #define wxSYS_COLOUR_BTNTEXT 18
44 #define wxSYS_COLOUR_INACTIVECAPTIONTEXT 19
45 #define wxSYS_COLOUR_BTNHIGHLIGHT 20
47 #define wxSYS_COLOUR_3DDKSHADOW 21
48 #define wxSYS_COLOUR_3DLIGHT 22
49 #define wxSYS_COLOUR_INFOTEXT 23
50 #define wxSYS_COLOUR_INFOBK 24
52 #define wxSYS_COLOUR_DESKTOP wxSYS_COLOUR_BACKGROUND
53 #define wxSYS_COLOUR_3DFACE wxSYS_COLOUR_BTNFACE
54 #define wxSYS_COLOUR_3DSHADOW wxSYS_COLOUR_BTNSHADOW
55 #define wxSYS_COLOUR_3DHIGHLIGHT wxSYS_COLOUR_BTNHIGHLIGHT
56 #define wxSYS_COLOUR_3DHILIGHT wxSYS_COLOUR_BTNHIGHLIGHT
57 #define wxSYS_COLOUR_BTNHILIGHT wxSYS_COLOUR_BTNHIGHLIGHT
60 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
62 //wxColour *g_systemWinColour = (wxColour *) NULL;
63 wxColour
*g_systemBtnFaceColour
= (wxColour
*) NULL
;
64 wxColour
*g_systemBtnShadowColour
= (wxColour
*) NULL
;
65 wxColour
*g_systemBtnHighlightColour
= (wxColour
*) NULL
;
66 wxColour
*g_systemHighlightColour
= (wxColour
*) NULL
;
67 wxColour
*g_systemHighlightTextColour
= (wxColour
*) NULL
;
68 wxColour
*g_systemListBoxColour
= (wxColour
*) NULL
;
69 wxColour
*g_systemBtnTextColour
= (wxColour
*) NULL
;
71 wxFont
*g_systemFont
= (wxFont
*) NULL
;
73 // ----------------------------------------------------------------------------
74 // wxSystemSettingsModule
75 // ----------------------------------------------------------------------------
77 class wxSystemSettingsModule
: public wxModule
80 bool OnInit() { return TRUE
; }
83 //delete g_systemWinColour;
84 delete g_systemBtnFaceColour
;
85 delete g_systemBtnShadowColour
;
86 delete g_systemBtnHighlightColour
;
87 delete g_systemHighlightColour
;
88 delete g_systemHighlightTextColour
;
89 delete g_systemListBoxColour
;
91 delete g_systemBtnTextColour
;
93 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
96 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
98 // ----------------------------------------------------------------------------
99 // wxSystemSettings implementation
100 // ----------------------------------------------------------------------------
102 // kind of widget to use in GetColourFromGTKWidget
109 // the colour we need
117 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
118 // widget style, return true if we did get them, false to use defaults
119 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
120 wxGtkWidgetType type
= wxGTK_BUTTON
,
121 GtkStateType state
= GTK_STATE_NORMAL
,
122 wxGtkColourType colour
= wxGTK_BG
)
128 wxFAIL_MSG( _T("unexpected GTK widget type") );
132 widget
= gtk_button_new();
136 widget
= gtk_list_new();
139 GtkStyle
*def
= gtk_rc_get_style( widget
);
141 def
= gtk_widget_get_default_style();
150 wxFAIL_MSG( _T("unexpected GTK colour type") );
166 red
= col
[state
].red
;
167 green
= col
[state
].green
;
168 blue
= col
[state
].blue
;
177 gtk_widget_destroy( widget
);
182 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
186 case wxSYS_COLOUR_SCROLLBAR
:
187 case wxSYS_COLOUR_BACKGROUND
:
188 case wxSYS_COLOUR_ACTIVECAPTION
:
189 case wxSYS_COLOUR_INACTIVECAPTION
:
190 case wxSYS_COLOUR_MENU
:
191 case wxSYS_COLOUR_WINDOWFRAME
:
192 case wxSYS_COLOUR_ACTIVEBORDER
:
193 case wxSYS_COLOUR_INACTIVEBORDER
:
194 case wxSYS_COLOUR_BTNFACE
:
195 case wxSYS_COLOUR_3DLIGHT
:
196 if (!g_systemBtnFaceColour
)
198 int red
, green
, blue
;
199 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
206 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
210 return *g_systemBtnFaceColour
;
212 case wxSYS_COLOUR_WINDOW
:
215 case wxSYS_COLOUR_3DDKSHADOW
:
218 case wxSYS_COLOUR_GRAYTEXT
:
219 case wxSYS_COLOUR_BTNSHADOW
:
220 //case wxSYS_COLOUR_3DSHADOW:
221 if (!g_systemBtnShadowColour
)
223 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
224 g_systemBtnShadowColour
=
225 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
226 (unsigned char) (faceColour
.Green() * 0.666),
227 (unsigned char) (faceColour
.Blue() * 0.666));
230 return *g_systemBtnShadowColour
;
232 case wxSYS_COLOUR_3DHIGHLIGHT
:
233 //case wxSYS_COLOUR_BTNHIGHLIGHT:
235 /* I think this should normally be white (JACS 8/2000)
237 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
238 if (!g_systemBtnHighlightColour)
240 g_systemBtnHighlightColour =
241 new wxColour( 0xea60 >> SHIFT,
245 return *g_systemBtnHighlightColour;
248 case wxSYS_COLOUR_HIGHLIGHT
:
249 if (!g_systemHighlightColour
)
251 int red
, green
, blue
;
252 if ( !GetColourFromGTKWidget(red
, green
, blue
,
254 GTK_STATE_SELECTED
) )
261 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
265 return *g_systemHighlightColour
;
267 case wxSYS_COLOUR_LISTBOX
:
268 if (!g_systemListBoxColour
)
270 int red
, green
, blue
;
271 if ( GetColourFromGTKWidget(red
, green
, blue
,
276 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
282 g_systemListBoxColour
= new wxColour(*wxWHITE
);
285 return *g_systemListBoxColour
;
287 case wxSYS_COLOUR_MENUTEXT
:
288 case wxSYS_COLOUR_WINDOWTEXT
:
289 case wxSYS_COLOUR_CAPTIONTEXT
:
290 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
291 case wxSYS_COLOUR_BTNTEXT
:
292 case wxSYS_COLOUR_INFOTEXT
:
293 if (!g_systemBtnTextColour
)
295 int red
, green
, blue
;
296 if ( !GetColourFromGTKWidget(red
, green
, blue
,
306 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
310 return *g_systemBtnTextColour
;
312 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
313 if (!g_systemHighlightTextColour
)
315 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
316 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
317 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
319 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
321 return *g_systemHighlightTextColour
;
323 case wxSYS_COLOUR_INFOBK
:
324 case wxSYS_COLOUR_APPWORKSPACE
:
325 return *wxWHITE
; // ?
331 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
335 case wxSYS_OEM_FIXED_FONT
:
336 case wxSYS_ANSI_FIXED_FONT
:
337 case wxSYS_SYSTEM_FIXED_FONT
:
339 return *wxNORMAL_FONT
;
341 case wxSYS_ANSI_VAR_FONT
:
342 case wxSYS_SYSTEM_FONT
:
343 case wxSYS_DEVICE_DEFAULT_FONT
:
344 case wxSYS_DEFAULT_GUI_FONT
:
348 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
351 return *g_systemFont
;
359 int wxSystemSettingsNative::GetMetric( wxSystemMetric index
)
363 case wxSYS_SCREEN_X
: return gdk_screen_width();
364 case wxSYS_SCREEN_Y
: return gdk_screen_height();
365 case wxSYS_HSCROLL_Y
: return 15;
366 case wxSYS_VSCROLL_X
: return 15;
368 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
373 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
377 case wxSYS_CAN_ICONIZE_FRAME
:
380 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: