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"
19 #include "wx/fontutil.h"
22 #include <gdk/gdkprivate.h>
25 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
27 //wxColour *g_systemWinColour = (wxColour *) NULL;
28 wxColour
*g_systemBtnFaceColour
= (wxColour
*) NULL
;
29 wxColour
*g_systemBtnShadowColour
= (wxColour
*) NULL
;
30 wxColour
*g_systemBtnHighlightColour
= (wxColour
*) NULL
;
31 wxColour
*g_systemHighlightColour
= (wxColour
*) NULL
;
32 wxColour
*g_systemHighlightTextColour
= (wxColour
*) NULL
;
33 wxColour
*g_systemListBoxColour
= (wxColour
*) NULL
;
34 wxColour
*g_systemBtnTextColour
= (wxColour
*) NULL
;
36 wxFont
*g_systemFont
= (wxFont
*) NULL
;
38 // ----------------------------------------------------------------------------
39 // wxSystemSettingsModule
40 // ----------------------------------------------------------------------------
42 class wxSystemSettingsModule
: public wxModule
45 bool OnInit() { return TRUE
; }
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
;
56 delete g_systemBtnTextColour
;
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
61 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
63 // ----------------------------------------------------------------------------
64 // wxSystemSettings implementation
65 // ----------------------------------------------------------------------------
67 // kind of widget to use in GetColourFromGTKWidget
82 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
83 // widget style, return true if we did get them, false to use defaults
84 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
85 wxGtkWidgetType type
= wxGTK_BUTTON
,
86 GtkStateType state
= GTK_STATE_NORMAL
,
87 wxGtkColourType colour
= wxGTK_BG
)
93 wxFAIL_MSG( _T("unexpected GTK widget type") );
97 widget
= gtk_button_new();
101 widget
= gtk_list_new();
104 GtkStyle
*def
= gtk_rc_get_style( widget
);
106 def
= gtk_widget_get_default_style();
115 wxFAIL_MSG( _T("unexpected GTK colour type") );
131 red
= col
[state
].red
;
132 green
= col
[state
].green
;
133 blue
= col
[state
].blue
;
142 gtk_widget_destroy( widget
);
147 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
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
)
164 int red
, green
, blue
;
165 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
172 g_systemBtnFaceColour
= new wxColour( red
>> SHIFT
,
176 return *g_systemBtnFaceColour
;
178 case wxSYS_COLOUR_WINDOW
:
181 case wxSYS_COLOUR_3DDKSHADOW
:
184 case wxSYS_COLOUR_GRAYTEXT
:
185 case wxSYS_COLOUR_BTNSHADOW
:
186 //case wxSYS_COLOUR_3DSHADOW:
187 if (!g_systemBtnShadowColour
)
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));
196 return *g_systemBtnShadowColour
;
198 case wxSYS_COLOUR_3DHIGHLIGHT
:
199 //case wxSYS_COLOUR_BTNHIGHLIGHT:
201 /* I think this should normally be white (JACS 8/2000)
203 Hmm, I'm quite sure it shouldn't ... (VZ 20.08.01)
204 if (!g_systemBtnHighlightColour)
206 g_systemBtnHighlightColour =
207 new wxColour( 0xea60 >> SHIFT,
211 return *g_systemBtnHighlightColour;
214 case wxSYS_COLOUR_HIGHLIGHT
:
215 if (!g_systemHighlightColour
)
217 int red
, green
, blue
;
218 if ( !GetColourFromGTKWidget(red
, green
, blue
,
220 GTK_STATE_SELECTED
) )
227 g_systemHighlightColour
= new wxColour( red
>> SHIFT
,
231 return *g_systemHighlightColour
;
233 case wxSYS_COLOUR_LISTBOX
:
234 if (!g_systemListBoxColour
)
236 int red
, green
, blue
;
237 if ( GetColourFromGTKWidget(red
, green
, blue
,
242 g_systemListBoxColour
= new wxColour( red
>> SHIFT
,
248 g_systemListBoxColour
= new wxColour(*wxWHITE
);
251 return *g_systemListBoxColour
;
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
)
261 int red
, green
, blue
;
262 if ( !GetColourFromGTKWidget(red
, green
, blue
,
272 g_systemBtnTextColour
= new wxColour( red
>> SHIFT
,
276 return *g_systemBtnTextColour
;
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);
284 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
285 if (!g_systemHighlightTextColour
)
287 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
288 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
289 g_systemHighlightTextColour
= new wxColour(*wxBLACK
);
291 g_systemHighlightTextColour
= new wxColour(*wxWHITE
);
293 return *g_systemHighlightTextColour
;
295 case wxSYS_COLOUR_APPWORKSPACE
:
296 return *wxWHITE
; // ?
298 case wxSYS_COLOUR_HOTLIGHT
:
299 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
300 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
301 case wxSYS_COLOUR_MENUHILIGHT
:
305 case wxSYS_COLOUR_MAX
:
307 wxFAIL_MSG( _T("unknown system colour index") );
313 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
317 case wxSYS_OEM_FIXED_FONT
:
318 case wxSYS_ANSI_FIXED_FONT
:
319 case wxSYS_SYSTEM_FIXED_FONT
:
321 return *wxNORMAL_FONT
;
323 case wxSYS_ANSI_VAR_FONT
:
324 case wxSYS_SYSTEM_FONT
:
325 case wxSYS_DEVICE_DEFAULT_FONT
:
326 case wxSYS_DEFAULT_GUI_FONT
:
331 GtkWidget
*widget
= gtk_button_new();
332 GtkStyle
*def
= gtk_rc_get_style( widget
);
334 def
= gtk_widget_get_default_style();
337 wxNativeFontInfo info
;
338 info
.description
= def
->font_desc
;
339 g_systemFont
= new wxFont(info
);
343 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
345 gtk_widget_destroy( widget
);
347 g_systemFont
= new wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
350 return *g_systemFont
;
358 int wxSystemSettingsNative::GetMetric( wxSystemMetric 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;
367 // VZ: is there any way to get the cursor size with GDK?
368 case wxSYS_CURSOR_X
: return 16;
369 case wxSYS_CURSOR_Y
: return 16;
370 // MBN: ditto for icons
371 case wxSYS_ICON_X
: return 32;
372 case wxSYS_ICON_Y
: return 32;
374 wxFAIL_MSG( wxT("wxSystemSettings::GetMetric not fully implemented") );
379 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
383 case wxSYS_CAN_ICONIZE_FRAME
:
386 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: