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 wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
89 // FIXME: shouldn't we destroy these windows somewhere?
91 // used by DrawHeaderButton and DrawComboBoxDropButton
92 static GtkWidget
*GetButtonWidget();
94 // used by DrawTreeItemButton()
95 static GtkWidget
*GetTreeWidget();
97 // used by DrawCheckButton()
98 static GtkWidget
*GetCheckButtonWidget();
101 // ============================================================================
103 // ============================================================================
106 wxRendererNative
& wxRendererNative::GetDefault()
108 static wxRendererGTK s_rendererGTK
;
110 return s_rendererGTK
;
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
118 wxRendererGTK::GetButtonWidget()
120 static GtkWidget
*s_button
= NULL
;
121 static GtkWidget
*s_window
= NULL
;
125 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
126 gtk_widget_realize( s_window
);
127 s_button
= gtk_button_new();
128 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
129 gtk_widget_realize( s_button
);
136 wxRendererGTK::GetCheckButtonWidget()
138 static GtkWidget
*s_button
= NULL
;
139 static GtkWidget
*s_window
= NULL
;
143 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
144 gtk_widget_realize( s_window
);
145 s_button
= gtk_check_button_new();
146 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
147 gtk_widget_realize( s_button
);
154 wxRendererGTK::GetTreeWidget()
156 static GtkWidget
*s_tree
= NULL
;
157 static GtkWidget
*s_window
= NULL
;
161 s_tree
= gtk_tree_view_new();
162 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
163 gtk_widget_realize( s_window
);
164 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
165 gtk_widget_realize( s_tree
);
171 // ----------------------------------------------------------------------------
172 // list/tree controls drawing
173 // ----------------------------------------------------------------------------
176 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
182 GtkWidget
*button
= GetButtonWidget();
187 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
188 // Maybe use code similar as in DrawComboBoxDropButton below?
189 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
190 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
195 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
199 // draw a ">" or "v" button
201 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
202 wxDC
& dc
, const wxRect
& rect
, int flags
)
204 GtkWidget
*tree
= GetTreeWidget();
207 if ( flags
& wxCONTROL_CURRENT
)
208 state
= GTK_STATE_PRELIGHT
;
210 state
= GTK_STATE_NORMAL
;
212 // VZ: I don't know how to get the size of the expander so as to centre it
213 // in the given rectangle, +2/3 below is just what looks good here...
217 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
222 dc
.LogicalToDeviceX(rect
.x
) + 2,
223 dc
.LogicalToDeviceY(rect
.y
) + 3,
224 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
225 : GTK_EXPANDER_COLLAPSED
230 // ----------------------------------------------------------------------------
231 // splitter sash drawing
232 // ----------------------------------------------------------------------------
234 static int GetGtkSplitterFullSize()
236 static GtkWidget
*s_paned
= NULL
;
238 s_paned
= gtk_vpaned_new();
241 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
246 wxSplitterRenderParams
247 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
249 // we don't draw any border, hence 0 for the second field
250 return wxSplitterRenderParams
252 GetGtkSplitterFullSize(),
254 true // hot sensitive
259 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
261 const wxRect
& WXUNUSED(rect
),
268 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
272 wxOrientation orient
,
275 if ( !win
->m_wxwindow
->window
)
277 // window not realized yet
281 wxCoord full_size
= GetGtkSplitterFullSize();
283 // are we drawing vertical or horizontal splitter?
284 const bool isVert
= orient
== wxVERTICAL
;
288 GdkRectangle erase_rect
;
293 int h
= win
->GetClientSize().GetHeight();
297 rect
.width
= full_size
;
301 erase_rect
.x
= position
;
303 erase_rect
.width
= full_size
;
304 erase_rect
.height
= h
;
309 int w
= win
->GetClientSize().GetWidth();
313 rect
.height
= full_size
;
317 erase_rect
.y
= position
;
319 erase_rect
.height
= full_size
;
320 erase_rect
.width
= w
;
325 // we must erase everything first, otherwise the garbage
326 // from the old sash is left when dragging it
329 win
->m_wxwindow
->style
,
330 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
335 (char *)"viewportbin", // const_cast
345 win
->m_wxwindow
->style
,
346 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
347 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
349 NULL
/* no clipping */,
356 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
361 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
366 GtkWidget
*button
= GetButtonWidget();
368 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
369 // a window for gtk_paint_xxx function, then it won't
370 // work for wxMemoryDC. So that is why we assume wxDC
371 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
372 // are derived from it) and use its m_window.
373 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
375 // only doing debug-time checking here (it should
376 // probably be enough)
377 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
379 // draw arrow so that there is even space horizontally
381 int arrowX
= rect
.width
/4 + 1;
382 int arrowWidth
= rect
.width
- (arrowX
*2);
384 // scale arrow's height accoording to the width
385 int arrowHeight
= rect
.width
/3;
386 int arrowY
= (rect
.height
-arrowHeight
)/2 +
387 ((rect
.height
-arrowHeight
) & 1);
391 if ( flags
& wxCONTROL_PRESSED
)
392 state
= GTK_STATE_ACTIVE
;
393 else if ( flags
& wxCONTROL_DISABLED
)
394 state
= GTK_STATE_INSENSITIVE
;
395 else if ( flags
& wxCONTROL_CURRENT
)
396 state
= GTK_STATE_PRELIGHT
;
398 state
= GTK_STATE_NORMAL
;
400 // draw arrow on button
406 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
420 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
425 GtkWidget
*button
= GetButtonWidget();
427 // for reason why we do this, see DrawDropArrow
428 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
429 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
434 if ( flags
& wxCONTROL_PRESSED
)
435 state
= GTK_STATE_ACTIVE
;
436 else if ( flags
& wxCONTROL_DISABLED
)
437 state
= GTK_STATE_INSENSITIVE
;
438 else if ( flags
& wxCONTROL_CURRENT
)
439 state
= GTK_STATE_PRELIGHT
;
441 state
= GTK_STATE_NORMAL
;
448 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
452 rect
.x
, rect
.y
, rect
.width
, rect
.height
455 // draw arrow on button
456 DrawDropArrow(win
,dc
,rect
,flags
);
461 wxRendererGTK::DrawCheckButton(wxWindow
*win
,
466 GtkWidget
*button
= GetCheckButtonWidget();
468 // for reason why we do this, see DrawDropArrow
469 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
470 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
474 if ( flags
& wxCONTROL_PRESSED
)
475 state
= GTK_STATE_ACTIVE
;
476 else if ( flags
& wxCONTROL_DISABLED
)
477 state
= GTK_STATE_INSENSITIVE
;
478 else if ( flags
& wxCONTROL_CURRENT
)
479 state
= GTK_STATE_PRELIGHT
;
481 state
= GTK_STATE_NORMAL
;
488 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
492 rect
.x
, rect
.y
, 13, 13