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 // RR: After a correction to the orientation of the sash
46 // this doesn't seem to be required anymore and it
47 // seems to confuse some themes so USE_ERASE_RECT=0
48 #define USE_ERASE_RECT 0
50 // ----------------------------------------------------------------------------
51 // wxRendererGTK: our wxRendererNative implementation
52 // ----------------------------------------------------------------------------
54 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
57 // draw the header control button (used by wxListCtrl)
58 virtual void DrawHeaderButton(wxWindow
*win
,
64 // draw the expanded/collapsed icon for a tree control item
65 virtual void DrawTreeItemButton(wxWindow
*win
,
71 virtual void DrawSplitterBorder(wxWindow
*win
,
75 virtual void DrawSplitterSash(wxWindow
*win
,
82 virtual void DrawComboBoxDropButton(wxWindow
*win
,
87 virtual void DrawDropArrow(wxWindow
*win
,
92 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
95 // FIXME: shouldn't we destroy these windows somewhere?
97 // used by DrawHeaderButton and DrawComboBoxDropButton
98 static GtkWidget
*GetButtonWidget();
101 // used by DrawTreeItemButton()
102 static GtkWidget
*GetTreeWidget();
106 // ============================================================================
108 // ============================================================================
111 wxRendererNative
& wxRendererNative::GetDefault()
113 static wxRendererGTK s_rendererGTK
;
115 return s_rendererGTK
;
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
123 wxRendererGTK::GetButtonWidget()
125 static GtkWidget
*s_button
= NULL
;
126 static GtkWidget
*s_window
= NULL
;
130 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
131 gtk_widget_realize( s_window
);
132 s_button
= gtk_button_new();
133 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
134 gtk_widget_realize( s_button
);
143 wxRendererGTK::GetTreeWidget()
145 static GtkWidget
*s_tree
= NULL
;
146 static GtkWidget
*s_window
= NULL
;
150 s_tree
= gtk_tree_view_new();
151 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
152 gtk_widget_realize( s_window
);
153 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
154 gtk_widget_realize( s_tree
);
162 // ----------------------------------------------------------------------------
163 // list/tree controls drawing
164 // ----------------------------------------------------------------------------
167 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
173 GtkWidget
*button
= GetButtonWidget();
178 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
179 // Maybe use code similar as in DrawComboBoxDropButton below?
180 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
181 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
186 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
192 // draw a ">" or "v" button
194 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
195 wxDC
& dc
, const wxRect
& rect
, int flags
)
197 GtkWidget
*tree
= GetTreeWidget();
200 if ( flags
& wxCONTROL_CURRENT
)
201 state
= GTK_STATE_PRELIGHT
;
203 state
= GTK_STATE_NORMAL
;
205 // VZ: I don't know how to get the size of the expander so as to centre it
206 // in the given rectangle, +2/3 below is just what looks good here...
210 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
215 dc
.LogicalToDeviceX(rect
.x
) + 2,
216 dc
.LogicalToDeviceY(rect
.y
) + 3,
217 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
218 : GTK_EXPANDER_COLLAPSED
224 // ----------------------------------------------------------------------------
225 // splitter sash drawing
226 // ----------------------------------------------------------------------------
229 // the full sash width (should be even)
230 static const wxCoord SASH_SIZE
= 8;
232 // margin around the sash
233 static const wxCoord SASH_MARGIN
= 2;
234 #endif // GTK+ 2.x/1.x
236 static int GetGtkSplitterFullSize()
239 static GtkWidget
*s_paned
= NULL
;
241 s_paned
= gtk_vpaned_new();
244 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
248 return SASH_SIZE
+ SASH_MARGIN
;
252 wxSplitterRenderParams
253 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
255 // we don't draw any border, hence 0 for the second field
256 return wxSplitterRenderParams
258 GetGtkSplitterFullSize(),
261 true // hot sensitive
264 #endif // GTK+ 2.x/1.x
269 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
271 const wxRect
& WXUNUSED(rect
),
278 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
282 wxOrientation orient
,
283 int WXUNUSED_IN_GTK1(flags
))
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
356 win
->m_wxwindow
->style
,
357 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
358 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
360 NULL
/* no clipping */,
367 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
371 // leave some margin before sash itself
372 position
+= SASH_MARGIN
/ 2;
374 // and finally draw it using GTK paint functions
375 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
377 GdkRectangle
*, GtkWidget
*,
381 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
385 win
->m_wxwindow
->style
,
386 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
390 (char *)"paned", // const_cast
391 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
396 win
->m_wxwindow
->style
,
397 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
400 (GdkRectangle
*) NULL
,
402 (char *)"paned", // const_cast
403 isVert
? position
: size
.x
- 2*SASH_SIZE
,
404 isVert
? size
.y
- 2*SASH_SIZE
: position
,
407 #endif // GTK+ 2.x/1.x
411 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
416 GtkWidget
*button
= GetButtonWidget();
418 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
419 // a window for gtk_paint_xxx function, then it won't
420 // work for wxMemoryDC. So that is why we assume wxDC
421 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
422 // are derived from it) and use its m_window.
423 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
425 // only doing debug-time checking here (it should
426 // probably be enough)
427 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
429 // draw arrow so that there is even space horizontally
431 int arrowX
= rect
.width
/4 + 1;
432 int arrowWidth
= rect
.width
- (arrowX
*2);
434 // scale arrow's height accoording to the width
435 int arrowHeight
= rect
.width
/3;
436 int arrowY
= (rect
.height
-arrowHeight
)/2 +
437 ((rect
.height
-arrowHeight
) & 1);
441 if ( flags
& wxCONTROL_PRESSED
)
442 state
= GTK_STATE_ACTIVE
;
443 else if ( flags
& wxCONTROL_DISABLED
)
444 state
= GTK_STATE_INSENSITIVE
;
445 else if ( flags
& wxCONTROL_CURRENT
)
446 state
= GTK_STATE_PRELIGHT
;
448 state
= GTK_STATE_NORMAL
;
450 // draw arrow on button
456 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
470 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
475 GtkWidget
*button
= GetButtonWidget();
477 // for reason why we do this, see DrawDropArrow
478 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
479 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
484 if ( flags
& wxCONTROL_PRESSED
)
485 state
= GTK_STATE_ACTIVE
;
486 else if ( flags
& wxCONTROL_DISABLED
)
487 state
= GTK_STATE_INSENSITIVE
;
488 else if ( flags
& wxCONTROL_CURRENT
)
489 state
= GTK_STATE_PRELIGHT
;
491 state
= GTK_STATE_NORMAL
;
498 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
502 rect
.x
, rect
.y
, rect
.width
, rect
.height
505 // draw arrow on button
506 DrawDropArrow(win
,dc
,rect
,flags
);