1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/settings.cpp
4 // Author: Robert Roebling
5 // Modified by: Mart Raudsepp (GetMetric)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/settings.h"
17 #include "wx/cmndata.h"
18 #include "wx/toplevel.h"
21 #include "wx/fontutil.h"
25 #include <gdk/gdkprivate.h>
28 #include <X11/Xatom.h>
30 #define SHIFT (8*(sizeof(short int)-sizeof(char)))
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 struct wxSystemObjects
38 wxColour m_colBtnFace
,
45 m_colMenuItemHighlight
,
52 static wxSystemObjects gs_objects
;
54 // ----------------------------------------------------------------------------
55 // wxSystemSettings implementation
56 // ----------------------------------------------------------------------------
58 // kind of widget to use in GetColourFromGTKWidget
74 // wxSystemSettings::GetColour() helper: get the colours from a GTK+
75 // widget style, return true if we did get them, false to use defaults
76 static bool GetColourFromGTKWidget(int& red
, int& green
, int& blue
,
77 wxGtkWidgetType type
= wxGTK_BUTTON
,
78 GtkStateType state
= GTK_STATE_NORMAL
,
79 wxGtkColourType colour
= wxGTK_BG
)
85 wxFAIL_MSG( wxT("unexpected GTK widget type") );
89 widget
= gtk_button_new();
93 widget
= gtk_list_new();
97 widget
= gtk_menu_item_new();
100 GtkStyle
*def
= gtk_rc_get_style( widget
);
102 def
= gtk_widget_get_default_style();
111 wxFAIL_MSG( wxT("unexpected GTK colour type") );
127 red
= col
[state
].red
;
128 green
= col
[state
].green
;
129 blue
= col
[state
].blue
;
138 gtk_widget_destroy( widget
);
143 static void GetTooltipColors()
145 GtkTooltips
* tooltips
= gtk_tooltips_new();
146 gtk_tooltips_force_window(tooltips
);
147 gtk_widget_ensure_style(tooltips
->tip_window
);
148 GdkColor c
= tooltips
->tip_window
->style
->bg
[GTK_STATE_NORMAL
];
149 gs_objects
.m_colTooltip
= wxColor(c
.red
>> SHIFT
, c
.green
>> SHIFT
, c
.blue
>> SHIFT
);
150 c
= tooltips
->tip_window
->style
->fg
[GTK_STATE_NORMAL
];
151 gs_objects
.m_colTooltipText
= wxColor(c
.red
>> SHIFT
, c
.green
>> SHIFT
, c
.blue
>> SHIFT
);
152 gtk_object_sink(reinterpret_cast<GtkObject
*>(tooltips
));
155 wxColour
wxSystemSettingsNative::GetColour( wxSystemColour index
)
159 case wxSYS_COLOUR_SCROLLBAR
:
160 case wxSYS_COLOUR_BACKGROUND
:
161 case wxSYS_COLOUR_INACTIVECAPTION
:
162 case wxSYS_COLOUR_MENU
:
163 case wxSYS_COLOUR_WINDOWFRAME
:
164 case wxSYS_COLOUR_ACTIVEBORDER
:
165 case wxSYS_COLOUR_INACTIVEBORDER
:
166 case wxSYS_COLOUR_BTNFACE
:
167 case wxSYS_COLOUR_MENUBAR
:
168 case wxSYS_COLOUR_3DLIGHT
:
169 if (!gs_objects
.m_colBtnFace
.Ok())
171 int red
, green
, blue
;
172 if ( !GetColourFromGTKWidget(red
, green
, blue
) )
179 gs_objects
.m_colBtnFace
= wxColour( red
>> SHIFT
,
183 return gs_objects
.m_colBtnFace
;
185 case wxSYS_COLOUR_WINDOW
:
188 case wxSYS_COLOUR_3DDKSHADOW
:
191 case wxSYS_COLOUR_GRAYTEXT
:
192 case wxSYS_COLOUR_BTNSHADOW
:
193 //case wxSYS_COLOUR_3DSHADOW:
194 if (!gs_objects
.m_colBtnShadow
.Ok())
196 wxColour
faceColour(GetColour(wxSYS_COLOUR_3DFACE
));
197 gs_objects
.m_colBtnShadow
=
198 wxColour((unsigned char) (faceColour
.Red() * 0.666),
199 (unsigned char) (faceColour
.Green() * 0.666),
200 (unsigned char) (faceColour
.Blue() * 0.666));
203 return gs_objects
.m_colBtnShadow
;
205 case wxSYS_COLOUR_3DHIGHLIGHT
:
206 //case wxSYS_COLOUR_BTNHIGHLIGHT:
209 case wxSYS_COLOUR_HIGHLIGHT
:
210 if (!gs_objects
.m_colHighlight
.Ok())
212 int red
, green
, blue
;
213 if ( !GetColourFromGTKWidget(red
, green
, blue
,
215 GTK_STATE_SELECTED
) )
222 gs_objects
.m_colHighlight
= wxColour( red
>> SHIFT
,
226 return gs_objects
.m_colHighlight
;
228 case wxSYS_COLOUR_LISTBOX
:
229 if (!gs_objects
.m_colListBox
.Ok())
231 int red
, green
, blue
;
232 if ( GetColourFromGTKWidget(red
, green
, blue
,
237 gs_objects
.m_colListBox
= wxColour( red
>> SHIFT
,
243 gs_objects
.m_colListBox
= wxColour(*wxWHITE
);
246 return gs_objects
.m_colListBox
;
248 case wxSYS_COLOUR_MENUTEXT
:
249 case wxSYS_COLOUR_WINDOWTEXT
:
250 case wxSYS_COLOUR_CAPTIONTEXT
:
251 case wxSYS_COLOUR_INACTIVECAPTIONTEXT
:
252 case wxSYS_COLOUR_BTNTEXT
:
253 case wxSYS_COLOUR_LISTBOXTEXT
:
254 if (!gs_objects
.m_colBtnText
.Ok())
256 int red
, green
, blue
;
257 if ( !GetColourFromGTKWidget(red
, green
, blue
,
267 gs_objects
.m_colBtnText
= wxColour( red
>> SHIFT
,
271 return gs_objects
.m_colBtnText
;
273 case wxSYS_COLOUR_INFOBK
:
274 if (!gs_objects
.m_colTooltip
.Ok()) {
277 return gs_objects
.m_colTooltip
;
279 case wxSYS_COLOUR_INFOTEXT
:
280 if (!gs_objects
.m_colTooltipText
.Ok()) {
283 return gs_objects
.m_colTooltipText
;
285 case wxSYS_COLOUR_HIGHLIGHTTEXT
:
286 if (!gs_objects
.m_colHighlightText
.Ok())
288 wxColour hclr
= GetColour(wxSYS_COLOUR_HIGHLIGHT
);
289 if (hclr
.Red() > 200 && hclr
.Green() > 200 && hclr
.Blue() > 200)
290 gs_objects
.m_colHighlightText
= wxColour(*wxBLACK
);
292 gs_objects
.m_colHighlightText
= wxColour(*wxWHITE
);
294 return gs_objects
.m_colHighlightText
;
296 case wxSYS_COLOUR_APPWORKSPACE
:
297 return *wxWHITE
; // ?
299 case wxSYS_COLOUR_ACTIVECAPTION
:
300 case wxSYS_COLOUR_MENUHILIGHT
:
301 if (!gs_objects
.m_colMenuItemHighlight
.Ok())
303 int red
, green
, blue
;
304 if ( !GetColourFromGTKWidget(red
, green
, blue
,
314 gs_objects
.m_colMenuItemHighlight
= wxColour( red
>> SHIFT
,
318 return gs_objects
.m_colMenuItemHighlight
;
320 case wxSYS_COLOUR_HOTLIGHT
:
321 case wxSYS_COLOUR_GRADIENTACTIVECAPTION
:
322 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION
:
326 case wxSYS_COLOUR_MAX
:
328 wxFAIL_MSG( wxT("unknown system colour index") );
334 wxFont
wxSystemSettingsNative::GetFont( wxSystemFont index
)
338 case wxSYS_OEM_FIXED_FONT
:
339 case wxSYS_ANSI_FIXED_FONT
:
340 case wxSYS_SYSTEM_FIXED_FONT
:
342 return *wxNORMAL_FONT
;
344 case wxSYS_ANSI_VAR_FONT
:
345 case wxSYS_SYSTEM_FONT
:
346 case wxSYS_DEVICE_DEFAULT_FONT
:
347 case wxSYS_DEFAULT_GUI_FONT
:
349 if (!gs_objects
.m_fontSystem
.Ok())
351 gs_objects
.m_fontSystem
= wxFont( 12, wxSWISS
, wxNORMAL
, wxNORMAL
);
353 return gs_objects
.m_fontSystem
;
362 wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
370 // MBN: ditto for icons
371 case wxSYS_ICON_X
: return 32;
372 case wxSYS_ICON_Y
: return 32;
375 return gdk_screen_width();
378 return gdk_screen_height();
380 case wxSYS_HSCROLL_Y
: return 15;
381 case wxSYS_VSCROLL_X
: return 15;
383 // a gtk1 implementation should be possible too if gtk2 efficiency/convenience functions aren't used
385 case wxSYS_CAPTION_Y
:
387 // No realized window specified, and no implementation for that case yet.
390 // Check if wm supports frame extents - we can't know the caption height if it does not.
391 #if GTK_CHECK_VERSION(2,2,0)
392 if (!gtk_check_version(2,2,0))
394 if (!gdk_x11_screen_supports_net_wm_hint(
395 gdk_drawable_get_screen(window
),
396 gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) )
402 if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false)))
406 wxASSERT_MSG( wxDynamicCast(win
, wxTopLevelWindow
),
407 wxT("Asking for caption height of a non toplevel window") );
409 // Get the height of the top windowmanager border.
410 // This is the titlebar in most cases. The titlebar might be elsewhere, and
411 // we could check which is the thickest wm border to decide on which side the
412 // titlebar is, but this might lead to interesting behaviours in used code.
413 // Reconsider when we have a way to report to the user on which side it is.
419 #if GTK_CHECK_VERSION(2,2,0)
420 if (!gtk_check_version(2,2,0))
423 success
= (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(window
)),
424 GDK_WINDOW_XWINDOW(window
),
425 gdk_x11_get_xatom_by_name_for_display (
426 gdk_drawable_get_display(window
),
427 "_NET_FRAME_EXTENTS" ),
428 0, // left, right, top, bottom, CARDINAL[4]/32
429 G_MAXLONG
, // size of long
430 false, // do not delete property
431 XA_CARDINAL
, // 32 bit
432 &type
, &format
, &nitems
, &bytes_after
, &data
438 int caption_height
= -1;
440 if ((type
== XA_CARDINAL
) && (format
== 32) && (nitems
>= 3) && (data
))
443 borders
= (long*)data
;
444 caption_height
= borders
[2]; // top frame extent
450 return caption_height
;
453 // Try a default approach without a window pointer, if possible
459 case wxSYS_PENWINDOWS_PRESENT
:
460 // No MS Windows for Pen computing extension available in X11 based gtk+.
464 return -1; // metric is unknown
468 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
472 case wxSYS_CAN_ICONIZE_FRAME
:
475 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: