1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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"
30 #include "wx/window.h"
34 #include "wx/gtk1/win_gtk.h"
37 #include "wx/dcclient.h"
39 // RR: After a correction to the orientation of the sash
40 // this doesn't seem to be required anymore and it
41 // seems to confuse some themes so USE_ERASE_RECT=0
42 #define USE_ERASE_RECT 0
44 // ----------------------------------------------------------------------------
45 // wxRendererGTK: our wxRendererNative implementation
46 // ----------------------------------------------------------------------------
48 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
51 // draw the header control button (used by wxListCtrl)
52 virtual void DrawHeaderButton(wxWindow
*win
,
57 virtual void DrawSplitterBorder(wxWindow
*win
,
61 virtual void DrawSplitterSash(wxWindow
*win
,
68 virtual void DrawComboBoxDropButton(wxWindow
*win
,
73 virtual void DrawDropArrow(wxWindow
*win
,
78 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
81 // FIXME: shouldn't we destroy these windows somewhere?
83 // used by DrawHeaderButton and DrawComboBoxDropButton
84 static GtkWidget
*GetButtonWidget();
87 // ============================================================================
89 // ============================================================================
92 wxRendererNative
& wxRendererNative::GetDefault()
94 static wxRendererGTK s_rendererGTK
;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
104 wxRendererGTK::GetButtonWidget()
106 static GtkWidget
*s_button
= NULL
;
107 static GtkWidget
*s_window
= NULL
;
111 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
112 gtk_widget_realize( s_window
);
113 s_button
= gtk_button_new();
114 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
115 gtk_widget_realize( s_button
);
121 // ----------------------------------------------------------------------------
122 // list/tree controls drawing
123 // ----------------------------------------------------------------------------
126 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
132 GtkWidget
*button
= GetButtonWidget();
137 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
138 // Maybe use code similar as in DrawComboBoxDropButton below?
139 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
140 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
145 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
149 // ----------------------------------------------------------------------------
150 // splitter sash drawing
151 // ----------------------------------------------------------------------------
153 // the full sash width (should be even)
154 static const wxCoord SASH_SIZE
= 8;
156 // margin around the sash
157 static const wxCoord SASH_MARGIN
= 2;
159 static int GetGtkSplitterFullSize()
161 return SASH_SIZE
+ SASH_MARGIN
;
164 wxSplitterRenderParams
165 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
167 // we don't draw any border, hence 0 for the second field
168 return wxSplitterRenderParams
170 GetGtkSplitterFullSize(),
177 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
179 const wxRect
& WXUNUSED(rect
),
186 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
190 wxOrientation orient
,
193 if ( !win
->m_wxwindow
->window
)
195 // window not realized yet
199 wxCoord full_size
= GetGtkSplitterFullSize();
201 // are we drawing vertical or horizontal splitter?
202 const bool isVert
= orient
== wxVERTICAL
;
206 GdkRectangle erase_rect
;
211 int h
= win
->GetClientSize().GetHeight();
215 rect
.width
= full_size
;
219 erase_rect
.x
= position
;
221 erase_rect
.width
= full_size
;
222 erase_rect
.height
= h
;
227 int w
= win
->GetClientSize().GetWidth();
231 rect
.height
= full_size
;
235 erase_rect
.y
= position
;
237 erase_rect
.height
= full_size
;
238 erase_rect
.width
= w
;
243 // we must erase everything first, otherwise the garbage
244 // from the old sash is left when dragging it
247 win
->m_wxwindow
->style
,
248 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
253 (char *)"viewportbin", // const_cast
262 // leave some margin before sash itself
263 position
+= SASH_MARGIN
/ 2;
265 // and finally draw it using GTK paint functions
266 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
268 GdkRectangle
*, GtkWidget
*,
272 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
276 win
->m_wxwindow
->style
,
277 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
281 (char *)"paned", // const_cast
282 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
287 win
->m_wxwindow
->style
,
288 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
291 (GdkRectangle
*) NULL
,
293 (char *)"paned", // const_cast
294 isVert
? position
: size
.x
- 2*SASH_SIZE
,
295 isVert
? size
.y
- 2*SASH_SIZE
: position
,
301 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
306 GtkWidget
*button
= GetButtonWidget();
308 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
309 // a window for gtk_paint_xxx function, then it won't
310 // work for wxMemoryDC. So that is why we assume wxDC
311 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
312 // are derived from it) and use its m_window.
313 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
315 // only doing debug-time checking here (it should
316 // probably be enough)
317 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
319 // draw arrow so that there is even space horizontally
321 int arrowX
= rect
.width
/4 + 1;
322 int arrowWidth
= rect
.width
- (arrowX
*2);
324 // scale arrow's height accoording to the width
325 int arrowHeight
= rect
.width
/3;
326 int arrowY
= (rect
.height
-arrowHeight
)/2 +
327 ((rect
.height
-arrowHeight
) & 1);
331 if ( flags
& wxCONTROL_PRESSED
)
332 state
= GTK_STATE_ACTIVE
;
333 else if ( flags
& wxCONTROL_DISABLED
)
334 state
= GTK_STATE_INSENSITIVE
;
335 else if ( flags
& wxCONTROL_CURRENT
)
336 state
= GTK_STATE_PRELIGHT
;
338 state
= GTK_STATE_NORMAL
;
340 // draw arrow on button
346 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
360 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
365 GtkWidget
*button
= GetButtonWidget();
367 // for reason why we do this, see DrawDropArrow
368 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
369 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
374 if ( flags
& wxCONTROL_PRESSED
)
375 state
= GTK_STATE_ACTIVE
;
376 else if ( flags
& wxCONTROL_DISABLED
)
377 state
= GTK_STATE_INSENSITIVE
;
378 else if ( flags
& wxCONTROL_CURRENT
)
379 state
= GTK_STATE_PRELIGHT
;
381 state
= GTK_STATE_NORMAL
;
388 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
392 rect
.x
, rect
.y
, rect
.width
, rect
.height
395 // draw arrow on button
396 DrawDropArrow(win
,dc
,rect
,flags
);