1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/settings.cpp
4 // Author: Robert Roebling
5 // Modified by: Mart Raudsepp (GetMetric)
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #include "wx/settings.h"
16 #include "wx/toplevel.h"
19 #include "wx/fontutil.h"
23 #include <gdk/gdkprivate.h>
26 #include <X11/Xatom.h>
28 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 struct wxSystemObjects
36 wxColour m_colBtnFace
,
43 m_colMenuItemHighlight
,
50 static wxSystemObjects gs_objects
;
52 // ----------------------------------------------------------------------------
53 // wxSystemSettings implementation
54 // ----------------------------------------------------------------------------
56 // kind of widget to use in GetColourFromGTKWidget
72 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
73 // widget style, return true if we did get them, false to use defaults
74 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
75 wxGtkWidgetType type
= wxGTK_BUTTON
,
76 GtkStateType state
= GTK_STATE_NORMAL
,
77 wxGtkColourType colour
= wxGTK_BG
)
83 wxFAIL_MSG( wxT("unexpected GTK widget type") );
87 widget
= gtk_button_new();
91 widget
= gtk_list_new();
95 widget
= gtk_menu_item_new();
98 GtkStyle
*def
= gtk_rc_get_style( widget
);
100 def
= gtk_widget_get_default_style();
109 wxFAIL_MSG( wxT("unexpected GTK colour type") );
125 red
= col
[state
].red
;
126 green
= col
[state
].green
;
127 blue
= col
[state
].blue
;
136 gtk_widget_destroy( widget
);
141 static void GetTooltipColors()
143 GtkTooltips
* tooltips
= gtk_tooltips_new();
144 gtk_tooltips_force_window(tooltips
);
145 gtk_widget_ensure_style(tooltips
->tip_window
);
146 GdkColor c
= tooltips
->tip_window
->style
->bg
[GTK_STATE_NORMAL
];
147 gs_objects
.m_colTooltip
= wxColor(c
.red
>> SHIFT
, c
.green
>> SHIFT
, c
.blue
>> SHIFT
);
148 c
= tooltips
->tip_window
->style
->fg
[GTK_STATE_NORMAL
];
149 gs_objects
.m_colTooltipText
= wxColor(c
.red
>> SHIFT
, c
.green
>> SHIFT
, c
.blue
>> SHIFT
);
150 gtk_object_sink(reinterpret_cast<GtkObject
*>(tooltips
));
153 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
157 case wxSYS_COLOUR_SCROLLBAR
:
158 case wxSYS_COLOUR_BACKGROUND
:
159 case wxSYS_COLOUR_INACTIVECAPTION
:
160 case wxSYS_COLOUR_MENU
:
161 case wxSYS_COLOUR_WINDOWFRAME
:
162 case wxSYS_COLOUR_ACTIVEBORDER
:
163 case wxSYS_COLOUR_INACTIVEBORDER
:
164 case wxSYS_COLOUR_BTNFACE
:
165 case wxSYS_COLOUR_MENUBAR
:
166 case wxSYS_COLOUR_3DLIGHT
:
167 if (!gs_objects
.m_colBtnFace
.IsOk())
169 int red
, green
, blue
;
170 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
177 gs_objects
.m_colBtnFace
= wxColour( red
>> SHIFT
,
181 return gs_objects
.m_colBtnFace
;
183 case wxSYS_COLOUR_WINDOW
:
186 case wxSYS_COLOUR_3DDKSHADOW
:
189 case wxSYS_COLOUR_GRAYTEXT
:
190 case wxSYS_COLOUR_BTNSHADOW
:
191 //case wxSYS_COLOUR_3DSHADOW:
192 if (!gs_objects
.m_colBtnShadow
.IsOk())
194 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
195 gs_objects
.m_colBtnShadow
=
196 wxColour((unsigned char) (faceColour
.Red() * 0.666),
197 (unsigned char) (faceColour
.Green() * 0.666),
198 (unsigned char) (faceColour
.Blue() * 0.666));
201 return gs_objects
.m_colBtnShadow
;
203 case wxSYS_COLOUR_3DHIGHLIGHT
:
204 //case wxSYS_COLOUR_BTNHIGHLIGHT:
207 case wxSYS_COLOUR_HIGHLIGHT
:
208 if (!gs_objects
.m_colHighlight
.IsOk())
210 int red
, green
, blue
;
211 if ( !GetColourFromGTKWidget(red
, green
, blue
,
213 GTK_STATE_SELECTED
) )
220 gs_objects
.m_colHighlight
= wxColour( red
>> SHIFT
,
224 return gs_objects
.m_colHighlight
;
226 case wxSYS_COLOUR_LISTBOX
:
227 if (!gs_objects
.m_colListBox
.IsOk())
229 int red
, green
, blue
;
230 if ( GetColourFromGTKWidget(red
, green
, blue
,
235 gs_objects
.m_colListBox
= wxColour( red
>> SHIFT
,
241 gs_objects
.m_colListBox
= wxColour(*wxWHITE
);
244 return gs_objects
.m_colListBox
;
246 case wxSYS_COLOUR_MENUTEXT
:
247 case wxSYS_COLOUR_WINDOWTEXT
:
248 case wxSYS_COLOUR_CAPTIONTEXT
:
249 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
250 case wxSYS_COLOUR_BTNTEXT
:
251 case wxSYS_COLOUR_LISTBOXTEXT
:
252 if (!gs_objects
.m_colBtnText
.IsOk())
254 int red
, green
, blue
;
255 if ( !GetColourFromGTKWidget(red
, green
, blue
,
265 gs_objects
.m_colBtnText
= wxColour( red
>> SHIFT
,
269 return gs_objects
.m_colBtnText
;
271 case wxSYS_COLOUR_INFOBK
:
272 if (!gs_objects
.m_colTooltip
.IsOk()) {
275 return gs_objects
.m_colTooltip
;
277 case wxSYS_COLOUR_INFOTEXT
:
278 if (!gs_objects
.m_colTooltipText
.IsOk()) {
281 return gs_objects
.m_colTooltipText
;
283 case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
:
284 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
285 if (!gs_objects
.m_colHighlightText
.IsOk())
287 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
288 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
289 gs_objects
.m_colHighlightText
= wxColour(*wxBLACK
);
291 gs_objects
.m_colHighlightText
= wxColour(*wxWHITE
);
293 return gs_objects
.m_colHighlightText
;
295 case wxSYS_COLOUR_APPWORKSPACE
:
296 return *wxWHITE
; // ?
298 case wxSYS_COLOUR_ACTIVECAPTION
:
299 case wxSYS_COLOUR_MENUHILIGHT
:
300 if (!gs_objects
.m_colMenuItemHighlight
.IsOk())
302 int red
, green
, blue
;
303 if ( !GetColourFromGTKWidget(red
, green
, blue
,
313 gs_objects
.m_colMenuItemHighlight
= wxColour( red
>> SHIFT
,
317 return gs_objects
.m_colMenuItemHighlight
;
319 case wxSYS_COLOUR_HOTLIGHT
:
320 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
321 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
325 case wxSYS_COLOUR_MAX
:
327 wxFAIL_MSG( wxT("unknown system colour index") );
333 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
337 case wxSYS_OEM_FIXED_FONT
:
338 case wxSYS_ANSI_FIXED_FONT
:
339 case wxSYS_SYSTEM_FIXED_FONT
:
341 return *wxNORMAL_FONT
;
343 case wxSYS_ANSI_VAR_FONT
:
344 case wxSYS_SYSTEM_FONT
:
345 case wxSYS_DEVICE_DEFAULT_FONT
:
346 case wxSYS_DEFAULT_GUI_FONT
:
348 if (!gs_objects
.m_fontSystem
.IsOk())
350 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
352 return gs_objects
.m_fontSystem
;
361 wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
369 // MBN: ditto for icons
370 case wxSYS_ICON_X
: return 32;
371 case wxSYS_ICON_Y
: return 32;
374 return gdk_screen_width();
377 return gdk_screen_height();
379 case wxSYS_HSCROLL_Y
: return 15;
380 case wxSYS_VSCROLL_X
: return 15;
382 // a gtk1 implementation should be possible too if gtk2 efficiency/convenience functions aren't used
384 case wxSYS_CAPTION_Y
:
386 // No realized window specified, and no implementation for that case yet.
389 // Check if wm supports frame extents - we can't know the caption height if it does not.
390 #if GTK_CHECK_VERSION(2,2,0)
391 if (!gtk_check_version(2,2,0))
393 if (!gdk_x11_screen_supports_net_wm_hint(
394 gdk_drawable_get_screen(window
),
395 gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) )
401 if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false)))
405 wxASSERT_MSG( wxDynamicCast(win
, wxTopLevelWindow
),
406 wxT("Asking for caption height of a non toplevel window") );
408 // Get the height of the top windowmanager border.
409 // This is the titlebar in most cases. The titlebar might be elsewhere, and
410 // we could check which is the thickest wm border to decide on which side the
411 // titlebar is, but this might lead to interesting behaviours in used code.
412 // Reconsider when we have a way to report to the user on which side it is.
418 #if GTK_CHECK_VERSION(2,2,0)
419 if (!gtk_check_version(2,2,0))
422 success
= (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window
)),
423 GDK_WINDOW_XWINDOW(window
),
424 gdk_x11_get_xatom_by_name_for_display (
425 gdk_drawable_get_display(window
),
426 "_NET_FRAME_EXTENTS" ),
427 0, // left, right, top, bottom, CARDINAL[4]/32
428 G_MAXLONG
, // size of long
429 false, // do not delete property
430 XA_CARDINAL
, // 32 bit
431 &type
, &format
, &nitems
, &bytes_after
, &data
437 int caption_height
= -1;
439 if ((type
== XA_CARDINAL
) && (format
== 32) && (nitems
>= 3) && (data
))
442 borders
= (long*)data
;
443 caption_height
= borders
[2]; // top frame extent
449 return caption_height
;
452 // Try a default approach without a window pointer, if possible
458 case wxSYS_PENWINDOWS_PRESENT
:
459 // No MS Windows for Pen computing extension available in X11 based gtk+.
463 return -1; // metric is unknown
467 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
471 case wxSYS_CAN_ICONIZE_FRAME
:
474 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: