]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/settings.cpp
Applied Patch 664399: wxButton default size should not be adjusted
[wxWidgets.git] / src / gtk / settings.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: gtk/settings.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "settings.h"
13#endif
14
15#include "wx/settings.h"
16#include "wx/debug.h"
17#include "wx/module.h"
18#include "wx/cmndata.h"
19#include "wx/fontutil.h"
20
21#include <gdk/gdk.h>
22#include <gdk/gdkprivate.h>
23#include <gtk/gtk.h>
24
25#define SHIFT (8*(sizeof(short int)-sizeof(char)))
26
27//wxColour *g_systemWinColour = (wxColour *) NULL;
28wxColour *g_systemBtnFaceColour = (wxColour *) NULL;
29wxColour *g_systemBtnShadowColour = (wxColour *) NULL;
30wxColour *g_systemBtnHighlightColour = (wxColour *) NULL;
31wxColour *g_systemHighlightColour = (wxColour *) NULL;
32wxColour *g_systemHighlightTextColour = (wxColour *) NULL;
33wxColour *g_systemListBoxColour = (wxColour *) NULL;
34wxColour *g_systemBtnTextColour = (wxColour *) NULL;
35
36wxFont *g_systemFont = (wxFont *) NULL;
37
38// ----------------------------------------------------------------------------
39// wxSystemSettingsModule
40// ----------------------------------------------------------------------------
41
42class wxSystemSettingsModule : public wxModule
43{
44public:
45 bool OnInit() { return TRUE; }
46 void OnExit()
47 {
48 //delete g_systemWinColour;
49 delete g_systemBtnFaceColour;
50 delete g_systemBtnShadowColour;
51 delete g_systemBtnHighlightColour;
52 delete g_systemHighlightColour;
53 delete g_systemHighlightTextColour;
54 delete g_systemListBoxColour;
55 delete g_systemFont;
56 delete g_systemBtnTextColour;
57 }
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
59};
60
61IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
62
63// ----------------------------------------------------------------------------
64// wxSystemSettings implementation
65// ----------------------------------------------------------------------------
66
67// kind of widget to use in GetColourFromGTKWidget
68enum wxGtkWidgetType
69{
70 wxGTK_BUTTON,
71 wxGTK_LIST
72};
73
74// the colour we need
75enum wxGtkColourType
76{
77 wxGTK_FG,
78 wxGTK_BG,
79 wxGTK_BASE
80};
81
82// wxSystemSettings::GetColour() helper: get the colours from a GTK+
83// widget style, return true if we did get them, false to use defaults
84static bool GetColourFromGTKWidget(int& red, int& green, int& blue,
85 wxGtkWidgetType type = wxGTK_BUTTON,
86 GtkStateType state = GTK_STATE_NORMAL,
87 wxGtkColourType colour = wxGTK_BG)
88{
89 GtkWidget *widget;
90 switch ( type )
91 {
92 default:
93 wxFAIL_MSG( _T("unexpected GTK widget type") );
94 // fall through
95
96 case wxGTK_BUTTON:
97 widget = gtk_button_new();
98 break;
99
100 case wxGTK_LIST:
101 widget = gtk_list_new();
102 }
103
104 GtkStyle *def = gtk_rc_get_style( widget );
105 if ( !def )
106 def = gtk_widget_get_default_style();
107
108 bool ok;
109 if ( def )
110 {
111 GdkColor *col;
112 switch ( colour )
113 {
114 default:
115 wxFAIL_MSG( _T("unexpected GTK colour type") );
116 // fall through
117
118 case wxGTK_FG:
119 col = def->fg;
120 break;
121
122 case wxGTK_BG:
123 col = def->bg;
124 break;
125
126 case wxGTK_BASE:
127 col = def->base;
128 break;
129 }
130
131 red = col[state].red;
132 green = col[state].green;
133 blue = col[state].blue;
134
135 ok = TRUE;
136 }
137 else
138 {
139 ok = FALSE;
140 }
141
142 gtk_widget_destroy( widget );
143
144 return ok;
145}
146
147wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
148{
149 switch (index)
150 {
151 case wxSYS_COLOUR_SCROLLBAR:
152 case wxSYS_COLOUR_BACKGROUND:
153 case wxSYS_COLOUR_ACTIVECAPTION:
154 case wxSYS_COLOUR_INACTIVECAPTION:
155 case wxSYS_COLOUR_MENU:
156 case wxSYS_COLOUR_WINDOWFRAME:
157 case wxSYS_COLOUR_ACTIVEBORDER:
158 case wxSYS_COLOUR_INACTIVEBORDER:
159 case wxSYS_COLOUR_BTNFACE:
160 case wxSYS_COLOUR_MENUBAR:
161 case wxSYS_COLOUR_3DLIGHT:
162 if (!g_systemBtnFaceColour)
163 {
164 int red, green, blue;
165 if ( !GetColourFromGTKWidget(red, green, blue) )
166 {
167 red =
168 green = 0;
169 blue = 0x9c40;
170 }
171
172 g_systemBtnFaceColour = new wxColour( red >> SHIFT,
173 green >> SHIFT,
174 blue >> SHIFT );
175 }
176 return *g_systemBtnFaceColour;
177
178 case wxSYS_COLOUR_WINDOW:
179 return *wxWHITE;
180
181 case wxSYS_COLOUR_3DDKSHADOW:
182 return *wxBLACK;
183
184 case wxSYS_COLOUR_GRAYTEXT:
185 case wxSYS_COLOUR_BTNSHADOW:
186 //case wxSYS_COLOUR_3DSHADOW:
187 if (!g_systemBtnShadowColour)
188 {
189 wxColour faceColour(GetColour(wxSYS_COLOUR_3DFACE));
190 g_systemBtnShadowColour =
191 new wxColour((unsigned char) (faceColour.Red() * 0.666),
192 (unsigned char) (faceColour.Green() * 0.666),
193 (unsigned char) (faceColour.Blue() * 0.666));
194 }
195
196 return *g_systemBtnShadowColour;
197
198 case wxSYS_COLOUR_3DHIGHLIGHT:
199 //case wxSYS_COLOUR_BTNHIGHLIGHT:
200 return * wxWHITE;
201/* I think this should normally be white (JACS 8/2000)
202
203 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
204 if (!g_systemBtnHighlightColour)
205 {
206 g_systemBtnHighlightColour =
207 new wxColour( 0xea60 >> SHIFT,
208 0xea60 >> SHIFT,
209 0xea60 >> SHIFT );
210 }
211 return *g_systemBtnHighlightColour;
212*/
213
214 case wxSYS_COLOUR_HIGHLIGHT:
215 if (!g_systemHighlightColour)
216 {
217 int red, green, blue;
218 if ( !GetColourFromGTKWidget(red, green, blue,
219 wxGTK_BUTTON,
220 GTK_STATE_SELECTED) )
221 {
222 red =
223 green = 0;
224 blue = 0x9c40;
225 }
226
227 g_systemHighlightColour = new wxColour( red >> SHIFT,
228 green >> SHIFT,
229 blue >> SHIFT );
230 }
231 return *g_systemHighlightColour;
232
233 case wxSYS_COLOUR_LISTBOX:
234 if (!g_systemListBoxColour)
235 {
236 int red, green, blue;
237 if ( GetColourFromGTKWidget(red, green, blue,
238 wxGTK_LIST,
239 GTK_STATE_NORMAL,
240 wxGTK_BASE) )
241 {
242 g_systemListBoxColour = new wxColour( red >> SHIFT,
243 green >> SHIFT,
244 blue >> SHIFT );
245 }
246 else
247 {
248 g_systemListBoxColour = new wxColour(*wxWHITE);
249 }
250 }
251 return *g_systemListBoxColour;
252
253 case wxSYS_COLOUR_MENUTEXT:
254 case wxSYS_COLOUR_WINDOWTEXT:
255 case wxSYS_COLOUR_CAPTIONTEXT:
256 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
257 case wxSYS_COLOUR_BTNTEXT:
258 case wxSYS_COLOUR_INFOTEXT:
259 if (!g_systemBtnTextColour)
260 {
261 int red, green, blue;
262 if ( !GetColourFromGTKWidget(red, green, blue,
263 wxGTK_BUTTON,
264 GTK_STATE_NORMAL,
265 wxGTK_FG) )
266 {
267 red =
268 green =
269 blue = 0;
270 }
271
272 g_systemBtnTextColour = new wxColour( red >> SHIFT,
273 green >> SHIFT,
274 blue >> SHIFT );
275 }
276 return *g_systemBtnTextColour;
277
278 // this (as well as wxSYS_COLOUR_INFOTEXT above) is used for
279 // tooltip windows - Robert, please change this code to use the
280 // real GTK tooltips when/if you can (TODO)
281 case wxSYS_COLOUR_INFOBK:
282 return wxColour(255, 255, 225);
283
284 case wxSYS_COLOUR_HIGHLIGHTTEXT:
285 if (!g_systemHighlightTextColour)
286 {
287 wxColour hclr = GetColour(wxSYS_COLOUR_HIGHLIGHT);
288 if (hclr.Red() > 200 && hclr.Green() > 200 && hclr.Blue() > 200)
289 g_systemHighlightTextColour = new wxColour(*wxBLACK);
290 else
291 g_systemHighlightTextColour = new wxColour(*wxWHITE);
292 }
293 return *g_systemHighlightTextColour;
294
295 case wxSYS_COLOUR_APPWORKSPACE:
296 return *wxWHITE; // ?
297
298 case wxSYS_COLOUR_HOTLIGHT:
299 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
300 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
301 case wxSYS_COLOUR_MENUHILIGHT:
302 // TODO
303 return *wxBLACK;
304
305 case wxSYS_COLOUR_MAX:
306 default:
307 wxFAIL_MSG( _T("unknown system colour index") );
308 }
309
310 return *wxWHITE;
311}
312
313wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
314{
315 switch (index)
316 {
317 case wxSYS_OEM_FIXED_FONT:
318 case wxSYS_ANSI_FIXED_FONT:
319 case wxSYS_SYSTEM_FIXED_FONT:
320 {
321 return *wxNORMAL_FONT;
322 }
323 case wxSYS_ANSI_VAR_FONT:
324 case wxSYS_SYSTEM_FONT:
325 case wxSYS_DEVICE_DEFAULT_FONT:
326 case wxSYS_DEFAULT_GUI_FONT:
327 {
328 if (!g_systemFont)
329 {
330#ifdef __WXGTK20__
331 const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ());
332 g_systemFont = new wxFont( wxString::FromAscii( font_name ) );
333#else
334 g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
335#endif
336 }
337 return *g_systemFont;
338 }
339
340 default:
341 return wxNullFont;
342 }
343}
344
345int wxSystemSettingsNative::GetMetric( wxSystemMetric index )
346{
347 switch (index)
348 {
349 case wxSYS_SCREEN_X: return gdk_screen_width();
350 case wxSYS_SCREEN_Y: return gdk_screen_height();
351 case wxSYS_HSCROLL_Y: return 15;
352 case wxSYS_VSCROLL_X: return 15;
353
354 // VZ: is there any way to get the cursor size with GDK?
355 case wxSYS_CURSOR_X: return 16;
356 case wxSYS_CURSOR_Y: return 16;
357 // MBN: ditto for icons
358 case wxSYS_ICON_X: return 32;
359 case wxSYS_ICON_Y: return 32;
360 default:
361 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
362 return 0;
363 }
364}
365
366bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
367{
368 switch (index)
369 {
370 case wxSYS_CAN_ICONIZE_FRAME:
371 return FALSE;
372 break;
373 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
374 return TRUE;
375 break;
376 default:
377 return FALSE;
378 }
379}