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 wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
85 // FIXME: shouldn't we destroy these windows somewhere?
87 // used by DrawHeaderButton and DrawComboBoxDropButton
88 static GtkWidget
*GetButtonWidget();
91 // used by DrawTreeItemButton()
92 static GtkWidget
*GetTreeWidget();
96 // ============================================================================
98 // ============================================================================
101 wxRendererNative
& wxRendererNative::GetDefault()
103 static wxRendererGTK s_rendererGTK
;
105 return s_rendererGTK
;
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
113 wxRendererGTK::GetButtonWidget()
115 static GtkWidget
*s_button
= NULL
;
116 static GtkWidget
*s_window
= NULL
;
120 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
121 gtk_widget_realize( s_window
);
122 s_button
= gtk_button_new();
123 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
124 gtk_widget_realize( s_button
);
133 wxRendererGTK::GetTreeWidget()
135 static GtkWidget
*s_tree
= NULL
;
136 static GtkWidget
*s_window
= NULL
;
140 s_tree
= gtk_tree_view_new();
141 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
142 gtk_widget_realize( s_window
);
143 gtk_container_add( GTK_CONTAINER(s_window
), s_tree
);
144 gtk_widget_realize( s_tree
);
152 // ----------------------------------------------------------------------------
153 // list/tree controls drawing
154 // ----------------------------------------------------------------------------
157 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
163 GtkWidget
*button
= GetButtonWidget();
168 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
169 // Maybe use code similar as in DrawComboBoxDropButton below?
170 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
171 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
176 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
182 // draw a ">" or "v" button
184 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
185 wxDC
& dc
, const wxRect
& rect
, int flags
)
187 GtkWidget
*tree
= GetTreeWidget();
190 if ( flags
& wxCONTROL_CURRENT
)
191 state
= GTK_STATE_PRELIGHT
;
193 state
= GTK_STATE_NORMAL
;
195 // VZ: I don't know how to get the size of the expander so as to centre it
196 // in the given rectangle, +2/3 below is just what looks good here...
200 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
205 dc
.LogicalToDeviceX(rect
.x
) + 2,
206 dc
.LogicalToDeviceY(rect
.y
) + 3,
207 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
208 : GTK_EXPANDER_COLLAPSED
214 // ----------------------------------------------------------------------------
215 // splitter sash drawing
216 // ----------------------------------------------------------------------------
219 // the full sash width (should be even)
220 static const wxCoord SASH_SIZE
= 8;
222 // margin around the sash
223 static const wxCoord SASH_MARGIN
= 2;
224 #endif // GTK+ 2.x/1.x
226 static int GetGtkSplitterFullSize()
229 static GtkWidget
*s_paned
= NULL
;
231 s_paned
= gtk_vpaned_new();
234 gtk_widget_style_get (s_paned
, "handle_size", &handle_size
, NULL
);
238 return SASH_SIZE
+ SASH_MARGIN
;
242 wxSplitterRenderParams
243 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
245 // we don't draw any border, hence 0 for the second field
246 return wxSplitterRenderParams
248 GetGtkSplitterFullSize(),
251 true // hot sensitive
254 #endif // GTK+ 2.x/1.x
259 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
261 const wxRect
& WXUNUSED(rect
),
268 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
272 wxOrientation orient
,
273 int WXUNUSED_IN_GTK1(flags
))
275 if ( !win
->m_wxwindow
->window
)
277 // window not realized yet
281 wxCoord full_size
= GetGtkSplitterFullSize();
283 // are we drawing vertical or horizontal splitter?
284 const bool isVert
= orient
== wxVERTICAL
;
287 GdkRectangle erase_rect
;
290 int h
= win
->GetClientSize().GetHeight();
294 rect
.width
= full_size
;
297 erase_rect
.x
= position
;
299 erase_rect
.width
= full_size
;
300 erase_rect
.height
= h
;
304 int w
= win
->GetClientSize().GetWidth();
308 rect
.height
= full_size
;
311 erase_rect
.y
= position
;
313 erase_rect
.height
= full_size
;
314 erase_rect
.width
= w
;
318 // RR: After a correction to the orientation of the sash
319 // this doesn't seem to be required anymore and it
320 // seems to confuse some themes
322 // we must erase everything first, otherwise the garbage
323 // from the old sash is left when dragging it
326 win
->m_wxwindow
->style
,
327 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
332 (char *)"viewportbin", // const_cast
343 win
->m_wxwindow
->style
,
344 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
345 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
347 NULL
/* no clipping */,
354 isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
358 // leave some margin before sash itself
359 position
+= SASH_MARGIN
/ 2;
361 // and finally draw it using GTK paint functions
362 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
364 GdkRectangle
*, GtkWidget
*,
368 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
372 win
->m_wxwindow
->style
,
373 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
377 (char *)"paned", // const_cast
378 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
383 win
->m_wxwindow
->style
,
384 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
387 (GdkRectangle
*) NULL
,
389 (char *)"paned", // const_cast
390 isVert
? position
: size
.x
- 2*SASH_SIZE
,
391 isVert
? size
.y
- 2*SASH_SIZE
: position
,
394 #endif // GTK+ 2.x/1.x
397 void wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
402 GtkWidget
*button
= GetButtonWidget();
404 // device context must inherit from wxWindowDC
405 // (so it must be wxClientDC, wxMemoryDC or wxPaintDC)
406 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
408 // only doing debug-time checking here (it should probably be enough)
409 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
413 if ( flags
& wxCONTROL_CURRENT
)
414 state
= GTK_STATE_PRELIGHT
;
415 else if ( flags
& wxCONTROL_DISABLED
)
416 state
= GTK_STATE_INSENSITIVE
;
418 state
= GTK_STATE_NORMAL
;
420 // draw arrow on button
426 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
432 rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2, rect
.height
- 2