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"
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 void wxSystemSettings::Done()
78 // delete g_systemWinColour;
79 delete g_systemBtnFaceColour
;
80 delete g_systemBtnShadowColour
;
81 delete g_systemBtnHighlightColour
;
82 delete g_systemHighlightColour
;
83 delete g_systemHighlightTextColour
;
84 delete g_systemListBoxColour
;
86 delete g_systemBtnTextColour
;
89 // kind of widget to use in GetColourFromGTKWidget
104 // wxSystemSettings::GetSystemColour() helper: get the colours from a GTK+
105 // widget style, return true if we did get them, false to use defaults
106 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
107 wxGtkWidgetType type
= wxGTK_BUTTON
,
108 GtkStateType state
= GTK_STATE_NORMAL
,
109 wxGtkColourType colour
= wxGTK_BG
)
115 wxFAIL_MSG( _T("unexpected GTK widget type") );
119 widget
= gtk_button_new();
123 widget
= gtk_list_new();
126 GtkStyle
*def
= gtk_rc_get_style( widget
);
128 def
= gtk_widget_get_default_style();
137 wxFAIL_MSG( _T("unexpected GTK colour type") );
153 red
= col
[state
].red
;
154 green
= col
[state
].green
;
155 blue
= col
[state
].blue
;
164 gtk_widget_destroy( widget
);
169 wxColour
wxSystemSettings::GetSystemColour( int index
)
173 case wxSYS_COLOUR_SCROLLBAR
:
174 case wxSYS_COLOUR_BACKGROUND
:
175 case wxSYS_COLOUR_ACTIVECAPTION
:
176 case wxSYS_COLOUR_INACTIVECAPTION
:
177 case wxSYS_COLOUR_MENU
:
178 case wxSYS_COLOUR_WINDOWFRAME
:
179 case wxSYS_COLOUR_ACTIVEBORDER
:
180 case wxSYS_COLOUR_INACTIVEBORDER
:
181 case wxSYS_COLOUR_BTNFACE
:
182 case wxSYS_COLOUR_3DLIGHT
:
183 if (!g_systemBtnFaceColour
)
185 int red
, green
, blue
;
186 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
193 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
197 return *g_systemBtnFaceColour
;
199 case wxSYS_COLOUR_WINDOW
:
202 case wxSYS_COLOUR_3DDKSHADOW
:
205 case wxSYS_COLOUR_GRAYTEXT
:
206 case wxSYS_COLOUR_BTNSHADOW
:
207 //case wxSYS_COLOUR_3DSHADOW:
208 if (!g_systemBtnShadowColour
)
210 wxColour
faceColour(GetSystemColour(wxSYS_COLOUR_3DFACE
));
211 g_systemBtnShadowColour
=
212 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
213 (unsigned char) (faceColour
.Green() * 0.666),
214 (unsigned char) (faceColour
.Blue() * 0.666));
217 return *g_systemBtnShadowColour
;
219 case wxSYS_COLOUR_3DHIGHLIGHT
:
220 //case wxSYS_COLOUR_BTNHIGHLIGHT:
222 /* I think this should normally be white (JACS 8/2000)
224 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
225 if (!g_systemBtnHighlightColour)
227 g_systemBtnHighlightColour =
228 new wxColour( 0xea60 >> SHIFT,
232 return *g_systemBtnHighlightColour;
235 case wxSYS_COLOUR_HIGHLIGHT
:
236 if (!g_systemHighlightColour
)
238 int red
, green
, blue
;
239 if ( !GetColourFromGTKWidget(red
, green
, blue
,
241 GTK_STATE_SELECTED
) )
248 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
252 return *g_systemHighlightColour
;
254 case wxSYS_COLOUR_LISTBOX
:
255 if (!g_systemListBoxColour
)
257 int red
, green
, blue
;
258 if ( GetColourFromGTKWidget(red
, green
, blue
,
263 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
269 g_systemListBoxColour
= new wxColour(*wxWHITE
);
272 return *g_systemListBoxColour
;
274 case wxSYS_COLOUR_MENUTEXT
:
275 case wxSYS_COLOUR_WINDOWTEXT
:
276 case wxSYS_COLOUR_CAPTIONTEXT
:
277 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
278 case wxSYS_COLOUR_BTNTEXT
:
279 case wxSYS_COLOUR_INFOTEXT
:
280 if (!g_systemBtnTextColour
)
282 int red
, green
, blue
;
283 if ( !GetColourFromGTKWidget(red
, green
, blue
,
293 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
297 return *g_systemBtnTextColour
;
299 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
300 if (!g_systemHighlightTextColour
)
302 wxColour hclr
= GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
303 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
304 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
306 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
308 return *g_systemHighlightTextColour
;
310 case wxSYS_COLOUR_INFOBK
:
311 case wxSYS_COLOUR_APPWORKSPACE
:
312 return *wxWHITE
; // ?
318 wxFont
wxSystemSettings::GetSystemFont( int index
)
322 case wxSYS_OEM_FIXED_FONT
:
323 case wxSYS_ANSI_FIXED_FONT
:
324 case wxSYS_SYSTEM_FIXED_FONT
:
326 return *wxNORMAL_FONT
;
328 case wxSYS_ANSI_VAR_FONT
:
329 case wxSYS_SYSTEM_FONT
:
330 case wxSYS_DEVICE_DEFAULT_FONT
:
331 case wxSYS_DEFAULT_GUI_FONT
:
336 GdkFont
*gdk_font
= GtkGetDefaultGuiFont();
339 GSList
*font_list
= ((GdkFontPrivate
*)gdk_font
)->names
;
340 char *name
= (char*)font_list
->data
;
341 wxString
font_string( name
);
342 wxFontData font_data
;
343 g_systemFont
= new wxFont( font_string
, font_data
);
345 gtk_widget_destroy( widget
);
348 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
351 return *g_systemFont
;
358 int wxSystemSettings::GetSystemMetric( int index
)
362 case wxSYS_SCREEN_X
: return gdk_screen_width();
363 case wxSYS_SCREEN_Y
: return gdk_screen_height();
364 case wxSYS_HSCROLL_Y
: return 15;
365 case wxSYS_VSCROLL_X
: return 15;
368 wxCHECK_MSG( index
, 0, wxT("wxSystemSettings::GetSystemMetric not fully implemented") );