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 // ----------------------------------------------------------------------------
39 // wxRendererGTK: our wxRendererNative implementation
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
45 // draw the header control button (used by wxListCtrl)
46 virtual void DrawHeaderButton(wxWindow
*win
,
51 // draw the expanded/collapsed icon for a tree control item
52 virtual void DrawTreeItemButton(wxWindow
*win
,
57 virtual void DrawSplitterBorder(wxWindow
*win
,
61 virtual void DrawSplitterSash(wxWindow
*win
,
68 virtual void DrawComboBoxDropButton(wxWindow
*win
,
73 virtual void DrawDropArrow(wxWindow
*win
,
78 virtual void DrawCheckBox(wxWindow
*win
,
83 virtual void DrawPushButton(wxWindow
*win
,
88 virtual void DrawItemSelectionRect(wxWindow
*win
,
93 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
96 // FIXME: shouldn't we destroy these windows somewhere?
98 // used by DrawHeaderButton and DrawPushButton
99 static GtkWidget
*GetButtonWidget();
101 // used by DrawTreeItemButton()
102 static GtkWidget
*GetTreeWidget();
104 // used by DrawCheckBox()
105 static GtkWidget
*GetCheckButtonWidget();
108 // ============================================================================
110 // ============================================================================
113 wxRendererNative
& wxRendererNative::GetDefault()
115 static wxRendererGTK s_rendererGTK
;
117 return s_rendererGTK
;
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
125 wxRendererGTK::GetButtonWidget()
127 static GtkWidget
*s_button
= NULL
;
128 static GtkWidget
*s_window
= NULL
;
132 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
133 gtk_widget_realize( s_window
);
134 s_button
= gtk_button_new();
135 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
136 gtk_widget_realize( s_button
);
143 wxRendererGTK::GetCheckButtonWidget()
145 static GtkWidget
*s_button
= NULL
;
146 static GtkWidget
*s_window
= NULL
;
150 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
151 gtk_widget_realize( s_window
);
152 s_button
= gtk_check_button_new();
153 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
154 gtk_widget_realize( s_button
);
161 wxRendererGTK::GetTreeWidget()
163 static GtkWidget
*s_tree
= NULL
;
164 static GtkWidget
*s_window
= NULL
;
168 s_tree
= gtk_tree_view_new();
169 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
170 gtk_widget_realize( s_window
);
171 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
172 gtk_widget_realize( s_tree
);
178 // ----------------------------------------------------------------------------
179 // list/tree controls drawing
180 // ----------------------------------------------------------------------------
183 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
189 GtkWidget
*button
= GetButtonWidget();
194 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
195 // Maybe use code similar as in DrawPushButton below?
196 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
197 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
202 dc
.LogicalToDeviceX(rect
.x
), rect
.y
, rect
.width
, rect
.height
206 // draw a ">" or "v" button
208 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
209 wxDC
& dc
, const wxRect
& rect
, int flags
)
211 GtkWidget
*tree
= GetTreeWidget();
214 if ( flags
& wxCONTROL_CURRENT
)
215 state
= GTK_STATE_PRELIGHT
;
217 state
= GTK_STATE_NORMAL
;
220 if (win
->GetLayoutDirection() == wxLayout_RightToLeft
)
223 // VZ: I don't know how to get the size of the expander so as to centre it
224 // in the given rectangle, +2/3 below is just what looks good here...
228 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
233 dc
.LogicalToDeviceX(rect
.x
) + 2 - x_diff
,
234 dc
.LogicalToDeviceY(rect
.y
) + 3,
235 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
236 : GTK_EXPANDER_COLLAPSED
241 // ----------------------------------------------------------------------------
242 // splitter sash drawing
243 // ----------------------------------------------------------------------------
245 static int GetGtkSplitterFullSize()
247 static GtkWidget
*s_paned
= NULL
;
249 s_paned
= gtk_vpaned_new();
252 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
257 wxSplitterRenderParams
258 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
260 // we don't draw any border, hence 0 for the second field
261 return wxSplitterRenderParams
263 GetGtkSplitterFullSize(),
265 true // hot sensitive
270 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
272 const wxRect
& WXUNUSED(rect
),
279 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
283 wxOrientation orient
,
286 if ( !win
->m_wxwindow
->window
)
288 // window not realized yet
292 wxCoord full_size
= GetGtkSplitterFullSize();
294 // are we drawing vertical or horizontal splitter?
295 const bool isVert
= orient
== wxVERTICAL
;
301 int h
= win
->GetClientSize().GetHeight();
305 rect
.width
= full_size
;
310 int w
= win
->GetClientSize().GetWidth();
314 rect
.height
= full_size
;
319 if (win
->GetLayoutDirection() == wxLayout_RightToLeft
)
324 win
->m_wxwindow
->style
,
325 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
326 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
328 NULL
/* no clipping */,
331 dc
.LogicalToDeviceX(rect
.x
) - x_diff
,
332 dc
.LogicalToDeviceY(rect
.y
),
335 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
340 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
345 GtkWidget
*button
= GetButtonWidget();
347 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
348 // a window for gtk_paint_xxx function, then it won't
349 // work for wxMemoryDC. So that is why we assume wxDC
350 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
351 // are derived from it) and use its m_window.
352 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
354 // only doing debug-time checking here (it should
355 // probably be enough)
356 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
358 // draw arrow so that there is even space horizontally
360 int arrowX
= rect
.width
/4 + 1;
361 int arrowWidth
= rect
.width
- (arrowX
*2);
363 // scale arrow's height accoording to the width
364 int arrowHeight
= rect
.width
/3;
365 int arrowY
= (rect
.height
-arrowHeight
)/2 +
366 ((rect
.height
-arrowHeight
) & 1);
370 if ( flags
& wxCONTROL_PRESSED
)
371 state
= GTK_STATE_ACTIVE
;
372 else if ( flags
& wxCONTROL_DISABLED
)
373 state
= GTK_STATE_INSENSITIVE
;
374 else if ( flags
& wxCONTROL_CURRENT
)
375 state
= GTK_STATE_PRELIGHT
;
377 state
= GTK_STATE_NORMAL
;
379 // draw arrow on button
385 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
399 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
404 DrawPushButton(win
,dc
,rect
,flags
);
405 DrawDropArrow(win
,dc
,rect
);
409 wxRendererGTK::DrawCheckBox(wxWindow
*win
,
414 GtkWidget
*button
= GetCheckButtonWidget();
416 // for reason why we do this, see DrawDropArrow
417 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
418 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
422 if ( flags
& wxCONTROL_PRESSED
)
423 state
= GTK_STATE_ACTIVE
;
424 else if ( flags
& wxCONTROL_DISABLED
)
425 state
= GTK_STATE_INSENSITIVE
;
426 else if ( flags
& wxCONTROL_CURRENT
)
427 state
= GTK_STATE_PRELIGHT
;
429 state
= GTK_STATE_NORMAL
;
436 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
440 dc
.LogicalToDeviceX(rect
.x
)+2,
441 dc
.LogicalToDeviceY(rect
.y
)+3,
447 wxRendererGTK::DrawPushButton(wxWindow
*win
,
452 GtkWidget
*button
= GetButtonWidget();
454 // for reason why we do this, see DrawDropArrow
455 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
456 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
461 if ( flags
& wxCONTROL_PRESSED
)
462 state
= GTK_STATE_ACTIVE
;
463 else if ( flags
& wxCONTROL_DISABLED
)
464 state
= GTK_STATE_INSENSITIVE
;
465 else if ( flags
& wxCONTROL_CURRENT
)
466 state
= GTK_STATE_PRELIGHT
;
468 state
= GTK_STATE_NORMAL
;
475 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
479 rect
.x
, rect
.y
, rect
.width
, rect
.height
484 wxRendererGTK::DrawItemSelectionRect(wxWindow
*win
,
490 if (flags
& wxCONTROL_SELECTED
)
492 if (flags
& wxCONTROL_FOCUSED
)
493 state
= GTK_STATE_SELECTED
;
495 state
= GTK_STATE_INSENSITIVE
;
497 gtk_paint_flat_box( win
->m_wxwindow
->style
,
498 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
504 dc
.LogicalToDeviceX(rect
.x
),
505 dc
.LogicalToDeviceY(rect
.y
),
510 if (flags
& wxCONTROL_CURRENT
)
512 dc
.SetPen( *wxBLACK_PEN
);
513 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
514 dc
.DrawRectangle( rect
);