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();
189 // VZ: I don't know how to get the size of the expander so as to centre it
190 // in the given rectangle, +2/3 below is just what looks good here...
194 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
199 dc
.LogicalToDeviceX(rect
.x
) + 2,
200 dc
.LogicalToDeviceY(rect
.y
) + 3,
201 flags
& wxCONTROL_EXPANDED
? GTK_EXPANDER_EXPANDED
202 : GTK_EXPANDER_COLLAPSED
208 // ----------------------------------------------------------------------------
209 // splitter sash drawing
210 // ----------------------------------------------------------------------------
212 // all this should probably be read from the current theme settings somehow?
214 // the full sash size
215 static const wxCoord SASH_FULL_SIZE
= 5;
217 // the full sash width (should be even)
218 static const wxCoord SASH_SIZE
= 8;
220 // margin around the sash
221 static const wxCoord SASH_MARGIN
= 2;
223 // the full sash size
224 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
225 #endif // GTK+ 2.x/1.x
227 wxSplitterRenderParams
228 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
230 // we don't draw any border, hence 0 for the second field
231 return wxSplitterRenderParams
236 true // hot sensitive
239 #endif // GTK+ 2.x/1.x
244 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
246 const wxRect
& WXUNUSED(rect
),
253 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
257 wxOrientation orient
,
258 int WXUNUSED_IN_GTK1(flags
))
260 if ( !win
->m_wxwindow
->window
)
262 // window not realized yet
266 // are we drawing vertical or horizontal splitter?
267 const bool isVert
= orient
== wxVERTICAL
;
270 GdkRectangle erase_rect
;
273 int h
= win
->GetClientSize().GetHeight();
277 rect
.width
= SASH_FULL_SIZE
;
280 erase_rect
.x
= position
;
282 erase_rect
.width
= SASH_FULL_SIZE
;
283 erase_rect
.height
= h
;
287 int w
= win
->GetClientSize().GetWidth();
291 rect
.height
= SASH_FULL_SIZE
;
294 erase_rect
.y
= position
;
296 erase_rect
.height
= SASH_FULL_SIZE
;
297 erase_rect
.width
= w
;
300 // we must erase everything first, otherwise the garbage from the old sash
301 // is left when dragging it
303 // TODO: is this the right way to draw themed background?
306 win
->m_wxwindow
->style
,
307 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
312 (char *)"base", // const_cast
322 win
->m_wxwindow
->style
,
323 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
324 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
326 NULL
/* no clipping */,
333 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
337 // leave some margin before sash itself
338 position
+= SASH_MARGIN
/ 2;
340 // and finally draw it using GTK paint functions
341 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
343 GdkRectangle
*, GtkWidget
*,
347 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
351 win
->m_wxwindow
->style
,
352 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
356 (char *)"paned", // const_cast
357 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
362 win
->m_wxwindow
->style
,
363 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
366 (GdkRectangle
*) NULL
,
368 (char *)"paned", // const_cast
369 isVert
? position
: size
.x
- 2*SASH_SIZE
,
370 isVert
? size
.y
- 2*SASH_SIZE
: position
,
373 #endif // GTK+ 2.x/1.x
376 void wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
381 GtkWidget
*button
= GetButtonWidget();
383 // device context must inherit from wxWindowDC
384 // (so it must be wxClientDC, wxMemoryDC or wxPaintDC)
385 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
387 // only doing debug-time checking here (it should probably be enough)
388 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
392 if ( flags
& wxCONTROL_CURRENT
)
393 state
= GTK_STATE_PRELIGHT
;
394 else if ( flags
& wxCONTROL_DISABLED
)
395 state
= GTK_STATE_INSENSITIVE
;
397 state
= GTK_STATE_NORMAL
;
399 // draw arrow on button
405 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
411 rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2, rect
.height
- 2