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/gtk1/win_gtk.h"
31 #include "wx/window.h"
33 #include "wx/dcclient.h"
35 // RR: After a correction to the orientation of the sash
36 // this doesn't seem to be required anymore and it
37 // seems to confuse some themes so USE_ERASE_RECT=0
38 #define USE_ERASE_RECT 0
40 // ----------------------------------------------------------------------------
41 // wxRendererGTK: our wxRendererNative implementation
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
47 // draw the header control button (used by wxListCtrl)
48 virtual void DrawHeaderButton(wxWindow
*win
,
53 virtual void DrawSplitterBorder(wxWindow
*win
,
57 virtual void DrawSplitterSash(wxWindow
*win
,
64 virtual void DrawComboBoxDropButton(wxWindow
*win
,
69 virtual void DrawDropArrow(wxWindow
*win
,
74 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
77 // FIXME: shouldn't we destroy these windows somewhere?
79 // used by DrawHeaderButton and DrawComboBoxDropButton
80 static GtkWidget
*GetButtonWidget();
83 // ============================================================================
85 // ============================================================================
88 wxRendererNative
& wxRendererNative::GetDefault()
90 static wxRendererGTK s_rendererGTK
;
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
100 wxRendererGTK::GetButtonWidget()
102 static GtkWidget
*s_button
= NULL
;
103 static GtkWidget
*s_window
= NULL
;
107 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
108 gtk_widget_realize( s_window
);
109 s_button
= gtk_button_new();
110 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
111 gtk_widget_realize( s_button
);
117 // ----------------------------------------------------------------------------
118 // list/tree controls drawing
119 // ----------------------------------------------------------------------------
122 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
128 GtkWidget
*button
= GetButtonWidget();
133 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
134 // Maybe use code similar as in DrawComboBoxDropButton below?
135 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
136 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
141 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
145 // ----------------------------------------------------------------------------
146 // splitter sash drawing
147 // ----------------------------------------------------------------------------
149 // the full sash width (should be even)
150 static const wxCoord SASH_SIZE
= 8;
152 // margin around the sash
153 static const wxCoord SASH_MARGIN
= 2;
155 static int GetGtkSplitterFullSize()
157 return SASH_SIZE
+ SASH_MARGIN
;
160 wxSplitterRenderParams
161 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
163 // we don't draw any border, hence 0 for the second field
164 return wxSplitterRenderParams
166 GetGtkSplitterFullSize(),
173 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
175 const wxRect
& WXUNUSED(rect
),
182 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
186 wxOrientation orient
,
189 if ( !win
->m_wxwindow
->window
)
191 // window not realized yet
195 wxCoord full_size
= GetGtkSplitterFullSize();
197 // are we drawing vertical or horizontal splitter?
198 const bool isVert
= orient
== wxVERTICAL
;
202 GdkRectangle erase_rect
;
207 int h
= win
->GetClientSize().GetHeight();
211 rect
.width
= full_size
;
215 erase_rect
.x
= position
;
217 erase_rect
.width
= full_size
;
218 erase_rect
.height
= h
;
223 int w
= win
->GetClientSize().GetWidth();
227 rect
.height
= full_size
;
231 erase_rect
.y
= position
;
233 erase_rect
.height
= full_size
;
234 erase_rect
.width
= w
;
239 // we must erase everything first, otherwise the garbage
240 // from the old sash is left when dragging it
243 win
->m_wxwindow
->style
,
244 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
249 (char *)"viewportbin", // const_cast
258 // leave some margin before sash itself
259 position
+= SASH_MARGIN
/ 2;
261 // and finally draw it using GTK paint functions
262 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
264 GdkRectangle
*, GtkWidget
*,
268 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
272 win
->m_wxwindow
->style
,
273 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
277 (char *)"paned", // const_cast
278 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
283 win
->m_wxwindow
->style
,
284 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
287 (GdkRectangle
*) NULL
,
289 (char *)"paned", // const_cast
290 isVert
? position
: size
.x
- 2*SASH_SIZE
,
291 isVert
? size
.y
- 2*SASH_SIZE
: position
,
297 wxRendererGTK::DrawDropArrow(wxWindow
*win
,
302 GtkWidget
*button
= GetButtonWidget();
304 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
305 // a window for gtk_paint_xxx function, then it won't
306 // work for wxMemoryDC. So that is why we assume wxDC
307 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
308 // are derived from it) and use its m_window.
309 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
311 // only doing debug-time checking here (it should
312 // probably be enough)
313 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
315 // draw arrow so that there is even space horizontally
317 int arrowX
= rect
.width
/4 + 1;
318 int arrowWidth
= rect
.width
- (arrowX
*2);
320 // scale arrow's height accoording to the width
321 int arrowHeight
= rect
.width
/3;
322 int arrowY
= (rect
.height
-arrowHeight
)/2 +
323 ((rect
.height
-arrowHeight
) & 1);
327 if ( flags
& wxCONTROL_PRESSED
)
328 state
= GTK_STATE_ACTIVE
;
329 else if ( flags
& wxCONTROL_DISABLED
)
330 state
= GTK_STATE_INSENSITIVE
;
331 else if ( flags
& wxCONTROL_CURRENT
)
332 state
= GTK_STATE_PRELIGHT
;
334 state
= GTK_STATE_NORMAL
;
336 // draw arrow on button
342 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
356 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
361 GtkWidget
*button
= GetButtonWidget();
363 // for reason why we do this, see DrawDropArrow
364 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
365 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
370 if ( flags
& wxCONTROL_PRESSED
)
371 state
= GTK_STATE_ACTIVE
;
372 else if ( flags
& wxCONTROL_DISABLED
)
373 state
= GTK_STATE_INSENSITIVE
;
374 else if ( flags
& wxCONTROL_CURRENT
)
375 state
= GTK_STATE_PRELIGHT
;
377 state
= GTK_STATE_NORMAL
;
384 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
388 rect
.x
, rect
.y
, rect
.width
, rect
.height
391 // draw arrow on button
392 DrawDropArrow(win
,dc
,rect
,flags
);