1 /////////////////////////////////////////////////////////////////////////////
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
96 // wxSystemSettings::GetSystemColour() helper: get the colours from a GTK+
97 // widget style, return true if we did get them, false to use defaults
98 static bool GetColourFromGTKWidget(GtkWidgetType type
, GtkStateType state
,
99 int& red
, int& green
, int& blue
)
101 GtkWidget
*widget
= type
== GTK_BUTTON
? gtk_button_new() : gtk_list_new();
102 GtkStyle
*def
= gtk_rc_get_style( widget
);
104 def
= gtk_widget_get_default_style();
109 red
= def
->bg
[state
].red
;
110 green
= def
->bg
[state
].green
;
111 blue
= def
->bg
[state
].blue
;
120 gtk_widget_destroy( widget
);
125 wxColour
wxSystemSettings::GetSystemColour( int index
)
129 case wxSYS_COLOUR_SCROLLBAR
:
130 case wxSYS_COLOUR_BACKGROUND
:
131 case wxSYS_COLOUR_ACTIVECAPTION
:
132 case wxSYS_COLOUR_INACTIVECAPTION
:
133 case wxSYS_COLOUR_MENU
:
134 case wxSYS_COLOUR_WINDOWFRAME
:
135 case wxSYS_COLOUR_ACTIVEBORDER
:
136 case wxSYS_COLOUR_INACTIVEBORDER
:
137 case wxSYS_COLOUR_BTNFACE
:
138 case wxSYS_COLOUR_3DLIGHT
:
139 if (!g_systemBtnFaceColour
)
141 int red
, green
, blue
;
142 if ( !GetColourFromGTKWidget(GTK_BUTTON
, GTK_STATE_NORMAL
,
150 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
154 return *g_systemBtnFaceColour
;
156 case wxSYS_COLOUR_WINDOW
:
159 case wxSYS_COLOUR_3DDKSHADOW
:
162 case wxSYS_COLOUR_GRAYTEXT
:
163 case wxSYS_COLOUR_BTNSHADOW
:
164 //case wxSYS_COLOUR_3DSHADOW:
165 if (!g_systemBtnShadowColour
)
167 wxColour
faceColour(GetSystemColour(wxSYS_COLOUR_3DFACE
));
168 g_systemBtnShadowColour
=
169 new wxColour((unsigned char) (faceColour
.Red() * 0.666),
170 (unsigned char) (faceColour
.Green() * 0.666),
171 (unsigned char) (faceColour
.Blue() * 0.666));
174 return *g_systemBtnShadowColour
;
176 case wxSYS_COLOUR_3DHIGHLIGHT
:
177 //case wxSYS_COLOUR_BTNHIGHLIGHT:
179 /* I think this should normally be white (JACS 8/2000)
181 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
182 if (!g_systemBtnHighlightColour)
184 g_systemBtnHighlightColour =
185 new wxColour( 0xea60 >> SHIFT,
189 return *g_systemBtnHighlightColour;
192 case wxSYS_COLOUR_HIGHLIGHT
:
193 if (!g_systemHighlightColour
)
195 int red
, green
, blue
;
196 if ( !GetColourFromGTKWidget(GTK_BUTTON
, GTK_STATE_SELECTED
,
204 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
208 return *g_systemHighlightColour
;
210 case wxSYS_COLOUR_LISTBOX
:
211 if (!g_systemListBoxColour
)
213 int red
, green
, blue
;
214 if ( GetColourFromGTKWidget(GTK_LIST
, GTK_STATE_NORMAL
,
217 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
223 g_systemListBoxColour
= new wxColour(*wxWHITE
);
226 return *g_systemListBoxColour
;
228 case wxSYS_COLOUR_MENUTEXT
:
229 case wxSYS_COLOUR_WINDOWTEXT
:
230 case wxSYS_COLOUR_CAPTIONTEXT
:
231 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
232 case wxSYS_COLOUR_BTNTEXT
:
233 case wxSYS_COLOUR_INFOTEXT
:
234 if (!g_systemBtnTextColour
)
236 GtkWidget
*widget
= gtk_button_new();
237 GtkStyle
*def
= gtk_rc_get_style( widget
);
239 def
= gtk_widget_get_default_style();
242 int red
= def
->fg
[GTK_STATE_NORMAL
].red
;
243 int green
= def
->fg
[GTK_STATE_NORMAL
].green
;
244 int blue
= def
->fg
[GTK_STATE_NORMAL
].blue
;
245 g_systemBtnTextColour
=
246 new wxColour( red
>> SHIFT
,
252 g_systemBtnTextColour
=
253 new wxColour(0, 0, 0);
255 gtk_widget_destroy( widget
);
257 return *g_systemBtnTextColour
;
259 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
260 if (!g_systemHighlightTextColour
)
262 wxColour hclr
= GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
263 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
264 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
266 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
268 return *g_systemHighlightTextColour
;
270 case wxSYS_COLOUR_INFOBK
:
271 case wxSYS_COLOUR_APPWORKSPACE
:
272 return *wxWHITE
; // ?
278 wxFont
wxSystemSettings::GetSystemFont( int index
)
282 case wxSYS_OEM_FIXED_FONT
:
283 case wxSYS_ANSI_FIXED_FONT
:
284 case wxSYS_SYSTEM_FIXED_FONT
:
286 return *wxNORMAL_FONT
;
288 case wxSYS_ANSI_VAR_FONT
:
289 case wxSYS_SYSTEM_FONT
:
290 case wxSYS_DEVICE_DEFAULT_FONT
:
291 case wxSYS_DEFAULT_GUI_FONT
:
296 GdkFont
*gdk_font
= GtkGetDefaultGuiFont();
299 GSList
*font_list
= ((GdkFontPrivate
*)gdk_font
)->names
;
300 char *name
= (char*)font_list
->data
;
301 wxString
font_string( name
);
302 wxFontData font_data
;
303 g_systemFont
= new wxFont( font_string
, font_data
);
305 gtk_widget_destroy( widget
);
308 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
311 return *g_systemFont
;
318 int wxSystemSettings::GetSystemMetric( int index
)
322 case wxSYS_SCREEN_X
: return gdk_screen_width();
323 case wxSYS_SCREEN_Y
: return gdk_screen_height();
324 case wxSYS_HSCROLL_Y
: return 15;
325 case wxSYS_VSCROLL_X
: return 15;
328 wxCHECK_MSG( index
, 0, wxT("wxSystemSettings::GetSystemMetric not fully implemented") );