1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/renderer.cpp
3 // Purpose: implementation of wxRendererNative for wxGTK
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/renderer.h"
29 #include "wx/gtk/win_gtk.h"
31 #include "wx/window.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
36 // RR: After a correction to the orientation of the sash
37 // this doesn't seem to be required anymore and it
38 // seems to confuse some themes so USE_ERASE_RECT=0
39 #define USE_ERASE_RECT 0
41 // ----------------------------------------------------------------------------
42 // wxRendererGTK: our wxRendererNative implementation
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
48 // draw the header control button (used by wxListCtrl)
49 virtual void DrawHeaderButton(wxWindow
*win
,
54 // draw the expanded/collapsed icon for a tree control item
55 virtual void DrawTreeItemButton(wxWindow
*win
,
60 virtual void DrawSplitterBorder(wxWindow
*win
,
64 virtual void DrawSplitterSash(wxWindow
*win
,
71 virtual void DrawComboBoxDropButton(wxWindow
*win
,
76 virtual void DrawDropArrow(wxWindow
*win
,
81 virtual void DrawCheckButton(wxWindow
*win
,
86 virtual void DrawPushButton(wxWindow
*win
,
91 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
94 // FIXME: shouldn't we destroy these windows somewhere?
96 // used by DrawHeaderButton and DrawPushButton
97 static GtkWidget
*GetButtonWidget();
99 // used by DrawTreeItemButton()
100 static GtkWidget
*GetTreeWidget();
102 // used by DrawCheckButton()
103 static GtkWidget
*GetCheckButtonWidget();
106 // ============================================================================
108 // ============================================================================
111 wxRendererNative
& wxRendererNative::GetDefault()
113 static wxRendererGTK s_rendererGTK
;
115 return s_rendererGTK
;
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
123 wxRendererGTK::GetButtonWidget()
125 static GtkWidget
*s_button
= NULL
;
126 static GtkWidget
*s_window
= NULL
;
130 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
131 gtk_widget_realize( s_window
);
132 s_button
= gtk_button_new();
133 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
134 gtk_widget_realize( s_button
);
141 wxRendererGTK::GetCheckButtonWidget()
143 static GtkWidget
*s_button
= NULL
;
144 static GtkWidget
*s_window
= NULL
;
148 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
149 gtk_widget_realize( s_window
);
150 s_button
= gtk_check_button_new();
151 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
152 gtk_widget_realize( s_button
);
159 wxRendererGTK::GetTreeWidget()
161 static GtkWidget
*s_tree
= NULL
;
162 static GtkWidget
*s_window
= NULL
;
166 s_tree
= gtk_tree_view_new();
167 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
168 gtk_widget_realize( s_window
);
169 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
170 gtk_widget_realize( s_tree
);
176 // ----------------------------------------------------------------------------
177 // list/tree controls drawing
178 // ----------------------------------------------------------------------------
181 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
187 GtkWidget
*button
= GetButtonWidget();
192 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
193 // Maybe use code similar as in DrawPushButton below?
194 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
195 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
200 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
204 // draw a ">" or "v" button
206 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
207 wxDC
& dc
, const wxRect
& rect
, int flags
)
209 GtkWidget
*tree
= GetTreeWidget();
212 if ( flags
& wxCONTROL_CURRENT
)
213 state
= GTK_STATE_PRELIGHT
;
215 state
= GTK_STATE_NORMAL
;
217 // VZ: I don't know how to get the size of the expander so as to centre it
218 // in the given rectangle, +2/3 below is just what looks good here...
222 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
227 dc
.LogicalToDeviceX(rect
.x
) + 2,
228 dc
.LogicalToDeviceY(rect
.y
) + 3,
229 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
230 : GTK_EXPANDER_COLLAPSED
235 // ----------------------------------------------------------------------------
236 // splitter sash drawing
237 // ----------------------------------------------------------------------------
239 static int GetGtkSplitterFullSize()
241 static GtkWidget
*s_paned
= NULL
;
243 s_paned
= gtk_vpaned_new();
246 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
251 wxSplitterRenderParams
252 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
254 // we don't draw any border, hence 0 for the second field
255 return wxSplitterRenderParams
257 GetGtkSplitterFullSize(),
259 true // hot sensitive
264 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
266 const wxRect
& WXUNUSED(rect
),
273 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
277 wxOrientation orient
,
280 if ( !win
->m_wxwindow
->window
)
282 // window not realized yet
286 wxCoord full_size
= GetGtkSplitterFullSize();
288 // are we drawing vertical or horizontal splitter?
289 const bool isVert
= orient
== wxVERTICAL
;
293 GdkRectangle erase_rect
;
298 int h
= win
->GetClientSize().GetHeight();
302 rect
.width
= full_size
;
306 erase_rect
.x
= position
;
308 erase_rect
.width
= full_size
;
309 erase_rect
.height
= h
;
314 int w
= win
->GetClientSize().GetWidth();
318 rect
.height
= full_size
;
322 erase_rect
.y
= position
;
324 erase_rect
.height
= full_size
;
325 erase_rect
.width
= w
;
330 // we must erase everything first, otherwise the garbage
331 // from the old sash is left when dragging it
334 win
->m_wxwindow
->style
,
335 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
340 (char *)"viewportbin", // const_cast
350 win
->m_wxwindow
->style
,
351 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
352 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
354 NULL
/* no clipping */,
361 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
366 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
371 GtkWidget
*button
= GetButtonWidget();
373 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
374 // a window for gtk_paint_xxx function, then it won't
375 // work for wxMemoryDC. So that is why we assume wxDC
376 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
377 // are derived from it) and use its m_window.
378 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
380 // only doing debug-time checking here (it should
381 // probably be enough)
382 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
384 // draw arrow so that there is even space horizontally
386 int arrowX
= rect
.width
/4 + 1;
387 int arrowWidth
= rect
.width
- (arrowX
*2);
389 // scale arrow's height accoording to the width
390 int arrowHeight
= rect
.width
/3;
391 int arrowY
= (rect
.height
-arrowHeight
)/2 +
392 ((rect
.height
-arrowHeight
) & 1);
396 if ( flags
& wxCONTROL_PRESSED
)
397 state
= GTK_STATE_ACTIVE
;
398 else if ( flags
& wxCONTROL_DISABLED
)
399 state
= GTK_STATE_INSENSITIVE
;
400 else if ( flags
& wxCONTROL_CURRENT
)
401 state
= GTK_STATE_PRELIGHT
;
403 state
= GTK_STATE_NORMAL
;
405 // draw arrow on button
411 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
425 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
430 DrawPushButton(win
,dc
,rect
,flags
);
431 DrawDropArrow(win
,dc
,rect
);
435 wxRendererGTK::DrawCheckButton(wxWindow
*win
,
440 GtkWidget
*button
= GetCheckButtonWidget();
442 // for reason why we do this, see DrawDropArrow
443 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
444 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
448 if ( flags
& wxCONTROL_PRESSED
)
449 state
= GTK_STATE_ACTIVE
;
450 else if ( flags
& wxCONTROL_DISABLED
)
451 state
= GTK_STATE_INSENSITIVE
;
452 else if ( flags
& wxCONTROL_CURRENT
)
453 state
= GTK_STATE_PRELIGHT
;
455 state
= GTK_STATE_NORMAL
;
462 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
466 rect
.x
, rect
.y
, 13, 13
471 wxRendererGTK::DrawPushButton(wxWindow
*win
,
476 GtkWidget
*button
= GetButtonWidget();
478 // for reason why we do this, see DrawDropArrow
479 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
480 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
485 if ( flags
& wxCONTROL_PRESSED
)
486 state
= GTK_STATE_ACTIVE
;
487 else if ( flags
& wxCONTROL_DISABLED
)
488 state
= GTK_STATE_INSENSITIVE
;
489 else if ( flags
& wxCONTROL_CURRENT
)
490 state
= GTK_STATE_PRELIGHT
;
492 state
= GTK_STATE_NORMAL
;
499 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
503 rect
.x
, rect
.y
, rect
.width
, rect
.height