1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
30 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/settings.h"
36 #include "wx/gtk/win_gtk.h"
38 // RR: After a correction to the orientation of the sash
39 // this doesn't seem to be required anymore and it
40 // seems to confuse some themes so USE_ERASE_RECT=0
41 #define USE_ERASE_RECT 0
43 // ----------------------------------------------------------------------------
44 // wxRendererGTK: our wxRendererNative implementation
45 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
50 // draw the header control button (used by wxListCtrl)
51 virtual void DrawHeaderButton(wxWindow
*win
,
56 // draw the expanded/collapsed icon for a tree control item
57 virtual void DrawTreeItemButton(wxWindow
*win
,
62 virtual void DrawSplitterBorder(wxWindow
*win
,
66 virtual void DrawSplitterSash(wxWindow
*win
,
73 virtual void DrawComboBoxDropButton(wxWindow
*win
,
78 virtual void DrawDropArrow(wxWindow
*win
,
83 virtual void DrawCheckBox(wxWindow
*win
,
88 virtual void DrawPushButton(wxWindow
*win
,
93 virtual void DrawItemSelectionRect(wxWindow
*win
,
98 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
101 // FIXME: shouldn't we destroy these windows somewhere?
103 // used by DrawHeaderButton and DrawPushButton
104 static GtkWidget
*GetButtonWidget();
106 // used by DrawTreeItemButton()
107 static GtkWidget
*GetTreeWidget();
109 // used by DrawCheckBox()
110 static GtkWidget
*GetCheckButtonWidget();
113 // ============================================================================
115 // ============================================================================
118 wxRendererNative
& wxRendererNative::GetDefault()
120 static wxRendererGTK s_rendererGTK
;
122 return s_rendererGTK
;
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
130 wxRendererGTK::GetButtonWidget()
132 static GtkWidget
*s_button
= NULL
;
133 static GtkWidget
*s_window
= NULL
;
137 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
138 gtk_widget_realize( s_window
);
139 s_button
= gtk_button_new();
140 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
141 gtk_widget_realize( s_button
);
148 wxRendererGTK::GetCheckButtonWidget()
150 static GtkWidget
*s_button
= NULL
;
151 static GtkWidget
*s_window
= NULL
;
155 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
156 gtk_widget_realize( s_window
);
157 s_button
= gtk_check_button_new();
158 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
159 gtk_widget_realize( s_button
);
166 wxRendererGTK::GetTreeWidget()
168 static GtkWidget
*s_tree
= NULL
;
169 static GtkWidget
*s_window
= NULL
;
173 s_tree
= gtk_tree_view_new();
174 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
175 gtk_widget_realize( s_window
);
176 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
177 gtk_widget_realize( s_tree
);
183 // ----------------------------------------------------------------------------
184 // list/tree controls drawing
185 // ----------------------------------------------------------------------------
188 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
194 GtkWidget
*button
= GetButtonWidget();
199 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
200 // Maybe use code similar as in DrawPushButton below?
201 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
202 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
207 dc
.LogicalToDeviceX(rect
.x
), rect
.y
, rect
.width
, rect
.height
211 // draw a ">" or "v" button
213 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
214 wxDC
& dc
, const wxRect
& rect
, int flags
)
216 GtkWidget
*tree
= GetTreeWidget();
219 if ( flags
& wxCONTROL_CURRENT
)
220 state
= GTK_STATE_PRELIGHT
;
222 state
= GTK_STATE_NORMAL
;
224 // VZ: I don't know how to get the size of the expander so as to centre it
225 // in the given rectangle, +2/3 below is just what looks good here...
229 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
234 dc
.LogicalToDeviceX(rect
.x
) + 2,
235 dc
.LogicalToDeviceY(rect
.y
) + 3,
236 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
237 : GTK_EXPANDER_COLLAPSED
242 // ----------------------------------------------------------------------------
243 // splitter sash drawing
244 // ----------------------------------------------------------------------------
246 static int GetGtkSplitterFullSize()
248 static GtkWidget
*s_paned
= NULL
;
250 s_paned
= gtk_vpaned_new();
253 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
258 wxSplitterRenderParams
259 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
261 // we don't draw any border, hence 0 for the second field
262 return wxSplitterRenderParams
264 GetGtkSplitterFullSize(),
266 true // hot sensitive
271 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
273 const wxRect
& WXUNUSED(rect
),
280 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
284 wxOrientation orient
,
287 if ( !win
->m_wxwindow
->window
)
289 // window not realized yet
293 wxCoord full_size
= GetGtkSplitterFullSize();
295 // are we drawing vertical or horizontal splitter?
296 const bool isVert
= orient
== wxVERTICAL
;
300 GdkRectangle erase_rect
;
305 int h
= win
->GetClientSize().GetHeight();
309 rect
.width
= full_size
;
313 erase_rect
.x
= position
;
315 erase_rect
.width
= full_size
;
316 erase_rect
.height
= h
;
321 int w
= win
->GetClientSize().GetWidth();
325 rect
.height
= full_size
;
329 erase_rect
.y
= position
;
331 erase_rect
.height
= full_size
;
332 erase_rect
.width
= w
;
337 // we must erase everything first, otherwise the garbage
338 // from the old sash is left when dragging it
341 win
->m_wxwindow
->style
,
342 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
347 (char *)"viewportbin", // const_cast
357 win
->m_wxwindow
->style
,
358 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
359 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
361 NULL
/* no clipping */,
368 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
373 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
378 GtkWidget
*button
= GetButtonWidget();
380 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
381 // a window for gtk_paint_xxx function, then it won't
382 // work for wxMemoryDC. So that is why we assume wxDC
383 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
384 // are derived from it) and use its m_window.
385 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
387 // only doing debug-time checking here (it should
388 // probably be enough)
389 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
391 // draw arrow so that there is even space horizontally
393 int arrowX
= rect
.width
/4 + 1;
394 int arrowWidth
= rect
.width
- (arrowX
*2);
396 // scale arrow's height accoording to the width
397 int arrowHeight
= rect
.width
/3;
398 int arrowY
= (rect
.height
-arrowHeight
)/2 +
399 ((rect
.height
-arrowHeight
) & 1);
403 if ( flags
& wxCONTROL_PRESSED
)
404 state
= GTK_STATE_ACTIVE
;
405 else if ( flags
& wxCONTROL_DISABLED
)
406 state
= GTK_STATE_INSENSITIVE
;
407 else if ( flags
& wxCONTROL_CURRENT
)
408 state
= GTK_STATE_PRELIGHT
;
410 state
= GTK_STATE_NORMAL
;
412 // draw arrow on button
418 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
432 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
437 DrawPushButton(win
,dc
,rect
,flags
);
438 DrawDropArrow(win
,dc
,rect
);
442 wxRendererGTK::DrawCheckBox(wxWindow
*win
,
447 GtkWidget
*button
= GetCheckButtonWidget();
449 // for reason why we do this, see DrawDropArrow
450 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
451 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
455 if ( flags
& wxCONTROL_PRESSED
)
456 state
= GTK_STATE_ACTIVE
;
457 else if ( flags
& wxCONTROL_DISABLED
)
458 state
= GTK_STATE_INSENSITIVE
;
459 else if ( flags
& wxCONTROL_CURRENT
)
460 state
= GTK_STATE_PRELIGHT
;
462 state
= GTK_STATE_NORMAL
;
469 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
473 dc
.LogicalToDeviceX(rect
.x
)+2,
474 dc
.LogicalToDeviceY(rect
.y
)+3,
480 wxRendererGTK::DrawPushButton(wxWindow
*win
,
485 GtkWidget
*button
= GetButtonWidget();
487 // for reason why we do this, see DrawDropArrow
488 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
489 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
494 if ( flags
& wxCONTROL_PRESSED
)
495 state
= GTK_STATE_ACTIVE
;
496 else if ( flags
& wxCONTROL_DISABLED
)
497 state
= GTK_STATE_INSENSITIVE
;
498 else if ( flags
& wxCONTROL_CURRENT
)
499 state
= GTK_STATE_PRELIGHT
;
501 state
= GTK_STATE_NORMAL
;
508 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
512 rect
.x
, rect
.y
, rect
.width
, rect
.height
517 wxRendererGTK::DrawItemSelectionRect(wxWindow
*win
,
523 if (flags
& wxCONTROL_SELECTED
)
525 if (flags
& wxCONTROL_FOCUSED
)
526 state
= GTK_STATE_SELECTED
;
528 state
= GTK_STATE_INSENSITIVE
;
530 gtk_paint_flat_box( win
->m_wxwindow
->style
,
531 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
537 dc
.LogicalToDeviceX(rect
.x
),
538 dc
.LogicalToDeviceY(rect
.y
),
543 if (flags
& wxCONTROL_CURRENT
)
545 dc
.SetPen( *wxBLACK_PEN
);
546 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
547 dc
.DrawRectangle( rect
);