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 void DrawItemSelectionRect(wxWindow
*win
,
96 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
99 // FIXME: shouldn't we destroy these windows somewhere?
101 // used by DrawHeaderButton and DrawPushButton
102 static GtkWidget
*GetButtonWidget();
104 // used by DrawTreeItemButton()
105 static GtkWidget
*GetTreeWidget();
107 // used by DrawCheckButton()
108 static GtkWidget
*GetCheckButtonWidget();
111 // ============================================================================
113 // ============================================================================
116 wxRendererNative
& wxRendererNative::GetDefault()
118 static wxRendererGTK s_rendererGTK
;
120 return s_rendererGTK
;
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
128 wxRendererGTK::GetButtonWidget()
130 static GtkWidget
*s_button
= NULL
;
131 static GtkWidget
*s_window
= NULL
;
135 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
136 gtk_widget_realize( s_window
);
137 s_button
= gtk_button_new();
138 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
139 gtk_widget_realize( s_button
);
146 wxRendererGTK::GetCheckButtonWidget()
148 static GtkWidget
*s_button
= NULL
;
149 static GtkWidget
*s_window
= NULL
;
153 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
154 gtk_widget_realize( s_window
);
155 s_button
= gtk_check_button_new();
156 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
157 gtk_widget_realize( s_button
);
164 wxRendererGTK::GetTreeWidget()
166 static GtkWidget
*s_tree
= NULL
;
167 static GtkWidget
*s_window
= NULL
;
171 s_tree
= gtk_tree_view_new();
172 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
173 gtk_widget_realize( s_window
);
174 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
175 gtk_widget_realize( s_tree
);
181 // ----------------------------------------------------------------------------
182 // list/tree controls drawing
183 // ----------------------------------------------------------------------------
186 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
192 GtkWidget
*button
= GetButtonWidget();
197 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
198 // Maybe use code similar as in DrawPushButton below?
199 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
200 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
205 dc
.XLOG2DEV(rect
.x
), rect
.y
, rect
.width
, rect
.height
209 // draw a ">" or "v" button
211 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
212 wxDC
& dc
, const wxRect
& rect
, int flags
)
214 GtkWidget
*tree
= GetTreeWidget();
217 if ( flags
& wxCONTROL_CURRENT
)
218 state
= GTK_STATE_PRELIGHT
;
220 state
= GTK_STATE_NORMAL
;
222 // VZ: I don't know how to get the size of the expander so as to centre it
223 // in the given rectangle, +2/3 below is just what looks good here...
227 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
232 dc
.LogicalToDeviceX(rect
.x
) + 2,
233 dc
.LogicalToDeviceY(rect
.y
) + 3,
234 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
235 : GTK_EXPANDER_COLLAPSED
240 // ----------------------------------------------------------------------------
241 // splitter sash drawing
242 // ----------------------------------------------------------------------------
244 static int GetGtkSplitterFullSize()
246 static GtkWidget
*s_paned
= NULL
;
248 s_paned
= gtk_vpaned_new();
251 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
256 wxSplitterRenderParams
257 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
259 // we don't draw any border, hence 0 for the second field
260 return wxSplitterRenderParams
262 GetGtkSplitterFullSize(),
264 true // hot sensitive
269 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
271 const wxRect
& WXUNUSED(rect
),
278 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
282 wxOrientation orient
,
285 if ( !win
->m_wxwindow
->window
)
287 // window not realized yet
291 wxCoord full_size
= GetGtkSplitterFullSize();
293 // are we drawing vertical or horizontal splitter?
294 const bool isVert
= orient
== wxVERTICAL
;
298 GdkRectangle erase_rect
;
303 int h
= win
->GetClientSize().GetHeight();
307 rect
.width
= full_size
;
311 erase_rect
.x
= position
;
313 erase_rect
.width
= full_size
;
314 erase_rect
.height
= h
;
319 int w
= win
->GetClientSize().GetWidth();
323 rect
.height
= full_size
;
327 erase_rect
.y
= position
;
329 erase_rect
.height
= full_size
;
330 erase_rect
.width
= w
;
335 // we must erase everything first, otherwise the garbage
336 // from the old sash is left when dragging it
339 win
->m_wxwindow
->style
,
340 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
345 (char *)"viewportbin", // const_cast
355 win
->m_wxwindow
->style
,
356 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
357 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
359 NULL
/* no clipping */,
366 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
371 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
376 GtkWidget
*button
= GetButtonWidget();
378 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
379 // a window for gtk_paint_xxx function, then it won't
380 // work for wxMemoryDC. So that is why we assume wxDC
381 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
382 // are derived from it) and use its m_window.
383 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
385 // only doing debug-time checking here (it should
386 // probably be enough)
387 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
389 // draw arrow so that there is even space horizontally
391 int arrowX
= rect
.width
/4 + 1;
392 int arrowWidth
= rect
.width
- (arrowX
*2);
394 // scale arrow's height accoording to the width
395 int arrowHeight
= rect
.width
/3;
396 int arrowY
= (rect
.height
-arrowHeight
)/2 +
397 ((rect
.height
-arrowHeight
) & 1);
401 if ( flags
& wxCONTROL_PRESSED
)
402 state
= GTK_STATE_ACTIVE
;
403 else if ( flags
& wxCONTROL_DISABLED
)
404 state
= GTK_STATE_INSENSITIVE
;
405 else if ( flags
& wxCONTROL_CURRENT
)
406 state
= GTK_STATE_PRELIGHT
;
408 state
= GTK_STATE_NORMAL
;
410 // draw arrow on button
416 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
430 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
435 DrawPushButton(win
,dc
,rect
,flags
);
436 DrawDropArrow(win
,dc
,rect
);
440 wxRendererGTK::DrawCheckButton(wxWindow
*win
,
445 GtkWidget
*button
= GetCheckButtonWidget();
447 // for reason why we do this, see DrawDropArrow
448 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
449 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
453 if ( flags
& wxCONTROL_PRESSED
)
454 state
= GTK_STATE_ACTIVE
;
455 else if ( flags
& wxCONTROL_DISABLED
)
456 state
= GTK_STATE_INSENSITIVE
;
457 else if ( flags
& wxCONTROL_CURRENT
)
458 state
= GTK_STATE_PRELIGHT
;
460 state
= GTK_STATE_NORMAL
;
467 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
471 dc
.LogicalToDeviceX(rect
.x
)+2,
472 dc
.LogicalToDeviceY(rect
.y
)+3,
478 wxRendererGTK::DrawPushButton(wxWindow
*win
,
483 GtkWidget
*button
= GetButtonWidget();
485 // for reason why we do this, see DrawDropArrow
486 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
487 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
492 if ( flags
& wxCONTROL_PRESSED
)
493 state
= GTK_STATE_ACTIVE
;
494 else if ( flags
& wxCONTROL_DISABLED
)
495 state
= GTK_STATE_INSENSITIVE
;
496 else if ( flags
& wxCONTROL_CURRENT
)
497 state
= GTK_STATE_PRELIGHT
;
499 state
= GTK_STATE_NORMAL
;
506 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
510 rect
.x
, rect
.y
, rect
.width
, rect
.height
515 wxRendererGTK::DrawItemSelectionRect(wxWindow
*win
,
520 // for reason why we do this, see DrawDropArrow
521 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
522 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
525 if (flags
& wxCONTROL_SELECTED
)
527 if (flags
& wxCONTROL_FOCUSED
)
528 state
= GTK_STATE_SELECTED
;
530 state
= GTK_STATE_INSENSITIVE
;
532 gtk_paint_flat_box( win
->m_wxwindow
->style
,
533 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
539 dc
.LogicalToDeviceX(rect
.x
),
540 dc
.LogicalToDeviceY(rect
.y
),
545 if (flags
& wxCONTROL_CURRENT
)
547 dc
.SetPen( *wxBLACK_PEN
);
548 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
549 dc
.DrawRectangle( rect
);