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
;
219 // VZ: I don't know how to get the size of the expander so as to centre it
220 // in the given rectangle, +2/3 below is just what looks good here...
224 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
229 dc
.LogicalToDeviceX(rect
.x
) + 2,
230 dc
.LogicalToDeviceY(rect
.y
) + 3,
231 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
232 : GTK_EXPANDER_COLLAPSED
237 // ----------------------------------------------------------------------------
238 // splitter sash drawing
239 // ----------------------------------------------------------------------------
241 static int GetGtkSplitterFullSize()
243 static GtkWidget
*s_paned
= NULL
;
245 s_paned
= gtk_vpaned_new();
248 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
253 wxSplitterRenderParams
254 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
256 // we don't draw any border, hence 0 for the second field
257 return wxSplitterRenderParams
259 GetGtkSplitterFullSize(),
261 true // hot sensitive
266 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
268 const wxRect
& WXUNUSED(rect
),
275 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
279 wxOrientation orient
,
282 if ( !win
->m_wxwindow
->window
)
284 // window not realized yet
288 wxCoord full_size
= GetGtkSplitterFullSize();
290 // are we drawing vertical or horizontal splitter?
291 const bool isVert
= orient
== wxVERTICAL
;
297 int h
= win
->GetClientSize().GetHeight();
301 rect
.width
= full_size
;
306 int w
= win
->GetClientSize().GetWidth();
310 rect
.height
= full_size
;
315 if (win
->GetLayoutDirection() == wxLayout_RightToLeft
)
320 win
->m_wxwindow
->style
,
321 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
322 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
324 NULL
/* no clipping */,
327 dc
.LogicalToDeviceX(rect
.x
) - x_diff
,
328 dc
.LogicalToDeviceY(rect
.y
),
331 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
336 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
341 GtkWidget
*button
= GetButtonWidget();
343 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
344 // a window for gtk_paint_xxx function, then it won't
345 // work for wxMemoryDC. So that is why we assume wxDC
346 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
347 // are derived from it) and use its m_window.
348 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
350 // only doing debug-time checking here (it should
351 // probably be enough)
352 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
354 // draw arrow so that there is even space horizontally
356 int arrowX
= rect
.width
/4 + 1;
357 int arrowWidth
= rect
.width
- (arrowX
*2);
359 // scale arrow's height accoording to the width
360 int arrowHeight
= rect
.width
/3;
361 int arrowY
= (rect
.height
-arrowHeight
)/2 +
362 ((rect
.height
-arrowHeight
) & 1);
366 if ( flags
& wxCONTROL_PRESSED
)
367 state
= GTK_STATE_ACTIVE
;
368 else if ( flags
& wxCONTROL_DISABLED
)
369 state
= GTK_STATE_INSENSITIVE
;
370 else if ( flags
& wxCONTROL_CURRENT
)
371 state
= GTK_STATE_PRELIGHT
;
373 state
= GTK_STATE_NORMAL
;
375 // draw arrow on button
381 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
395 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
400 DrawPushButton(win
,dc
,rect
,flags
);
401 DrawDropArrow(win
,dc
,rect
);
405 wxRendererGTK::DrawCheckBox(wxWindow
*win
,
410 GtkWidget
*button
= GetCheckButtonWidget();
412 // for reason why we do this, see DrawDropArrow
413 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
414 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
418 if ( flags
& wxCONTROL_PRESSED
)
419 state
= GTK_STATE_ACTIVE
;
420 else if ( flags
& wxCONTROL_DISABLED
)
421 state
= GTK_STATE_INSENSITIVE
;
422 else if ( flags
& wxCONTROL_CURRENT
)
423 state
= GTK_STATE_PRELIGHT
;
425 state
= GTK_STATE_NORMAL
;
432 flags
& wxCONTROL_CHECKED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
436 dc
.LogicalToDeviceX(rect
.x
)+2,
437 dc
.LogicalToDeviceY(rect
.y
)+3,
443 wxRendererGTK::DrawPushButton(wxWindow
*win
,
448 GtkWidget
*button
= GetButtonWidget();
450 // for reason why we do this, see DrawDropArrow
451 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
452 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
457 if ( flags
& wxCONTROL_PRESSED
)
458 state
= GTK_STATE_ACTIVE
;
459 else if ( flags
& wxCONTROL_DISABLED
)
460 state
= GTK_STATE_INSENSITIVE
;
461 else if ( flags
& wxCONTROL_CURRENT
)
462 state
= GTK_STATE_PRELIGHT
;
464 state
= GTK_STATE_NORMAL
;
471 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
475 rect
.x
, rect
.y
, rect
.width
, rect
.height
480 wxRendererGTK::DrawItemSelectionRect(wxWindow
*win
,
486 if (flags
& wxCONTROL_SELECTED
)
488 if (flags
& wxCONTROL_FOCUSED
)
489 state
= GTK_STATE_SELECTED
;
491 state
= GTK_STATE_INSENSITIVE
;
493 gtk_paint_flat_box( win
->m_wxwindow
->style
,
494 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
500 dc
.LogicalToDeviceX(rect
.x
),
501 dc
.LogicalToDeviceY(rect
.y
),
506 if (flags
& wxCONTROL_CURRENT
)
508 dc
.SetPen( *wxBLACK_PEN
);
509 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
510 dc
.DrawRectangle( rect
);