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