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