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 // ----------------------------------------------------------------------------
218 // all this should probably be read from the current theme settings somehow?
220 // the full sash size
221 static const wxCoord SASH_FULL_SIZE
= 5;
223 // the full sash width (should be even)
224 static const wxCoord SASH_SIZE
= 8;
226 // margin around the sash
227 static const wxCoord SASH_MARGIN
= 2;
229 // the full sash size
230 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
231 #endif // GTK+ 2.x/1.x
233 wxSplitterRenderParams
234 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
236 // we don't draw any border, hence 0 for the second field
237 return wxSplitterRenderParams
242 true // hot sensitive
245 #endif // GTK+ 2.x/1.x
250 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
252 const wxRect
& WXUNUSED(rect
),
259 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
263 wxOrientation orient
,
264 int WXUNUSED_IN_GTK1(flags
))
266 if ( !win
->m_wxwindow
->window
)
268 // window not realized yet
272 // are we drawing vertical or horizontal splitter?
273 const bool isVert
= orient
== wxVERTICAL
;
276 GdkRectangle erase_rect
;
279 int h
= win
->GetClientSize().GetHeight();
283 rect
.width
= SASH_FULL_SIZE
;
286 erase_rect
.x
= position
;
288 erase_rect
.width
= SASH_FULL_SIZE
;
289 erase_rect
.height
= h
;
293 int w
= win
->GetClientSize().GetWidth();
297 rect
.height
= SASH_FULL_SIZE
;
300 erase_rect
.y
= position
;
302 erase_rect
.height
= SASH_FULL_SIZE
;
303 erase_rect
.width
= w
;
306 // we must erase everything first, otherwise the garbage from the old sash
307 // is left when dragging it
309 // TODO: is this the right way to draw themed background?
312 win
->m_wxwindow
->style
,
313 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
318 (char *)"base", // const_cast
328 win
->m_wxwindow
->style
,
329 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
330 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
332 NULL
/* no clipping */,
339 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
343 // leave some margin before sash itself
344 position
+= SASH_MARGIN
/ 2;
346 // and finally draw it using GTK paint functions
347 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
349 GdkRectangle
*, GtkWidget
*,
353 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
357 win
->m_wxwindow
->style
,
358 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
362 (char *)"paned", // const_cast
363 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
368 win
->m_wxwindow
->style
,
369 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
372 (GdkRectangle
*) NULL
,
374 (char *)"paned", // const_cast
375 isVert
? position
: size
.x
- 2*SASH_SIZE
,
376 isVert
? size
.y
- 2*SASH_SIZE
: position
,
379 #endif // GTK+ 2.x/1.x
382 void wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
387 GtkWidget
*button
= GetButtonWidget();
389 // device context must inherit from wxWindowDC
390 // (so it must be wxClientDC, wxMemoryDC or wxPaintDC)
391 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
393 // only doing debug-time checking here (it should probably be enough)
394 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
398 if ( flags
& wxCONTROL_CURRENT
)
399 state
= GTK_STATE_PRELIGHT
;
400 else if ( flags
& wxCONTROL_DISABLED
)
401 state
= GTK_STATE_INSENSITIVE
;
403 state
= GTK_STATE_NORMAL
;
405 // draw arrow on button
411 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
417 rect
.x
+ 1, rect
.y
+ 1, rect
.width
- 2, rect
.height
- 2