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"
36 #include "wx/settings.h"
40 #define WXUNUSED_IN_GTK1(arg) arg
42 #define WXUNUSED_IN_GTK1(arg)
45 // ----------------------------------------------------------------------------
46 // wxRendererGTK: our wxRendererNative implementation
47 // ----------------------------------------------------------------------------
49 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
52 // draw the header control button (used by wxListCtrl)
53 virtual void DrawHeaderButton(wxWindow
*win
,
59 // draw the expanded/collapsed icon for a tree control item
60 virtual void DrawTreeItemButton(wxWindow
*win
,
66 virtual void DrawSplitterBorder(wxWindow
*win
,
70 virtual void DrawSplitterSash(wxWindow
*win
,
77 virtual void DrawComboBoxDropButton(wxWindow
*win
,
82 virtual void DrawDropArrow(wxWindow
*win
,
87 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
90 // FIXME: shouldn't we destroy these windows somewhere?
92 // used by DrawHeaderButton and DrawComboBoxDropButton
93 static GtkWidget
*GetButtonWidget();
96 // used by DrawTreeItemButton()
97 static GtkWidget
*GetTreeWidget();
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
);
138 wxRendererGTK::GetTreeWidget()
140 static GtkWidget
*s_tree
= NULL
;
141 static GtkWidget
*s_window
= NULL
;
145 s_tree
= gtk_tree_view_new();
146 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
147 gtk_widget_realize( s_window
);
148 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
149 gtk_widget_realize( s_tree
);
157 // ----------------------------------------------------------------------------
158 // list/tree controls drawing
159 // ----------------------------------------------------------------------------
162 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
168 GtkWidget
*button
= GetButtonWidget();
173 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
174 // Maybe use code similar as in DrawComboBoxDropButton below?
175 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
176 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
181 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
187 // draw a ">" or "v" button
189 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
190 wxDC
& dc
, const wxRect
& rect
, int flags
)
192 GtkWidget
*tree
= GetTreeWidget();
195 if ( flags
& wxCONTROL_CURRENT
)
196 state
= GTK_STATE_PRELIGHT
;
198 state
= GTK_STATE_NORMAL
;
200 // VZ: I don't know how to get the size of the expander so as to centre it
201 // in the given rectangle, +2/3 below is just what looks good here...
205 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
210 dc
.LogicalToDeviceX(rect
.x
) + 2,
211 dc
.LogicalToDeviceY(rect
.y
) + 3,
212 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
213 : GTK_EXPANDER_COLLAPSED
219 // ----------------------------------------------------------------------------
220 // splitter sash drawing
221 // ----------------------------------------------------------------------------
224 // the full sash width (should be even)
225 static const wxCoord SASH_SIZE
= 8;
227 // margin around the sash
228 static const wxCoord SASH_MARGIN
= 2;
229 #endif // GTK+ 2.x/1.x
231 static int GetGtkSplitterFullSize()
234 static GtkWidget
*s_paned
= NULL
;
236 s_paned
= gtk_vpaned_new();
239 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
243 return SASH_SIZE
+ SASH_MARGIN
;
247 wxSplitterRenderParams
248 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
250 // we don't draw any border, hence 0 for the second field
251 return wxSplitterRenderParams
253 GetGtkSplitterFullSize(),
256 true // hot sensitive
259 #endif // GTK+ 2.x/1.x
264 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
266 const wxRect
& WXUNUSED(rect
),
273 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
277 wxOrientation orient
,
278 int WXUNUSED_IN_GTK1(flags
))
280 if ( !win
->m_wxwindow
->window
)
282 // window not realized yet
286 wxCoord full_size
= GetGtkSplitterFullSize();
288 // are we drawing vertical or horizontal splitter?
289 const bool isVert
= orient
== wxVERTICAL
;
292 GdkRectangle erase_rect
;
295 int h
= win
->GetClientSize().GetHeight();
299 rect
.width
= full_size
;
302 erase_rect
.x
= position
;
304 erase_rect
.width
= full_size
;
305 erase_rect
.height
= h
;
309 int w
= win
->GetClientSize().GetWidth();
313 rect
.height
= full_size
;
316 erase_rect
.y
= position
;
318 erase_rect
.height
= full_size
;
319 erase_rect
.width
= w
;
323 // RR: After a correction to the orientation of the sash
324 // this doesn't seem to be required anymore and it
325 // seems to confuse some themes
327 // we must erase everything first, otherwise the garbage
328 // from the old sash is left when dragging it
331 win
->m_wxwindow
->style
,
332 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
337 (char *)"viewportbin", // const_cast
348 win
->m_wxwindow
->style
,
349 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
350 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
352 NULL
/* no clipping */,
359 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
363 // leave some margin before sash itself
364 position
+= SASH_MARGIN
/ 2;
366 // and finally draw it using GTK paint functions
367 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
369 GdkRectangle
*, GtkWidget
*,
373 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
377 win
->m_wxwindow
->style
,
378 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
382 (char *)"paned", // const_cast
383 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
388 win
->m_wxwindow
->style
,
389 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
392 (GdkRectangle
*) NULL
,
394 (char *)"paned", // const_cast
395 isVert
? position
: size
.x
- 2*SASH_SIZE
,
396 isVert
? size
.y
- 2*SASH_SIZE
: position
,
399 #endif // GTK+ 2.x/1.x
403 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
408 GtkWidget
*button
= GetButtonWidget();
410 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
411 // a window for gtk_paint_xxx function, then it won't
412 // work for wxMemoryDC. So that is why we assume wxDC
413 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
414 // are derived from it) and use its m_window.
415 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
417 // only doing debug-time checking here (it should
418 // probably be enough)
419 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
421 // draw arrow so that there is even space horizontally
423 int arrowX
= rect
.width
/4 + 1;
424 int arrowWidth
= rect
.width
- (arrowX
*2);
426 // scale arrow's height accoording to the width
427 int arrowHeight
= rect
.width
/3;
428 int arrowY
= (rect
.height
-arrowHeight
)/2 +
429 ((rect
.height
-arrowHeight
) & 1);
433 if ( flags
& wxCONTROL_PRESSED
)
434 state
= GTK_STATE_ACTIVE
;
435 else if ( flags
& wxCONTROL_DISABLED
)
436 state
= GTK_STATE_INSENSITIVE
;
437 else if ( flags
& wxCONTROL_CURRENT
)
438 state
= GTK_STATE_PRELIGHT
;
440 state
= GTK_STATE_NORMAL
;
442 // draw arrow on button
448 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
462 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
467 GtkWidget
*button
= GetButtonWidget();
469 // for reason why we do this, see DrawDropArrow
470 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
471 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
476 if ( flags
& wxCONTROL_PRESSED
)
477 state
= GTK_STATE_ACTIVE
;
478 else if ( flags
& wxCONTROL_DISABLED
)
479 state
= GTK_STATE_INSENSITIVE
;
480 else if ( flags
& wxCONTROL_CURRENT
)
481 state
= GTK_STATE_PRELIGHT
;
483 state
= GTK_STATE_NORMAL
;
490 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
494 rect
.x
, rect
.y
, rect
.width
, rect
.height
497 // draw arrow on button
498 DrawDropArrow(win
,dc
,rect
,flags
);