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 // Licence: 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"
35 #include "wx/gtk1/win_gtk.h"
36 #include "wx/gtk1/dcclient.h"
38 // RR: After a correction to the orientation of the sash
39 // this doesn't seem to be required anymore and it
40 // seems to confuse some themes so USE_ERASE_RECT=0
41 #define USE_ERASE_RECT 0
43 // ----------------------------------------------------------------------------
44 // wxRendererGTK: our wxRendererNative implementation
45 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
50 // draw the header control button (used by wxListCtrl)
51 virtual int DrawHeaderButton(wxWindow
*win
,
55 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
56 wxHeaderButtonParams
* params
=NULL
);
58 virtual void DrawSplitterBorder(wxWindow
*win
,
62 virtual void DrawSplitterSash(wxWindow
*win
,
69 virtual void DrawComboBoxDropButton(wxWindow
*win
,
74 virtual void DrawDropArrow(wxWindow
*win
,
79 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
82 // FIXME: shouldn't we destroy these windows somewhere?
84 // used by DrawHeaderButton and DrawComboBoxDropButton
85 static GtkWidget
*GetButtonWidget();
88 // ============================================================================
90 // ============================================================================
93 wxRendererNative
& wxRendererNative::GetDefault()
95 static wxRendererGTK s_rendererGTK
;
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
105 wxRendererGTK::GetButtonWidget()
107 static GtkWidget
*s_button
= NULL
;
108 static GtkWidget
*s_window
= NULL
;
112 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
113 gtk_widget_realize( s_window
);
114 s_button
= gtk_button_new();
115 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
116 gtk_widget_realize( s_button
);
122 // ----------------------------------------------------------------------------
123 // list/tree controls drawing
124 // ----------------------------------------------------------------------------
127 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
131 wxHeaderSortIconType
WXUNUSED(sortArrow
),
132 wxHeaderButtonParams
* WXUNUSED(params
))
135 GtkWidget
*button
= GetButtonWidget();
140 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
141 // Maybe use code similar as in DrawComboBoxDropButton below?
142 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
143 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
148 dc
.LogicalToDeviceX(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
151 return rect
.width
+ 2;
154 // ----------------------------------------------------------------------------
155 // splitter sash drawing
156 // ----------------------------------------------------------------------------
158 // the full sash width (should be even)
159 static const wxCoord SASH_SIZE
= 8;
161 // margin around the sash
162 static const wxCoord SASH_MARGIN
= 2;
164 static int GetGtkSplitterFullSize()
166 return SASH_SIZE
+ SASH_MARGIN
;
169 wxSplitterRenderParams
170 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
172 // we don't draw any border, hence 0 for the second field
173 return wxSplitterRenderParams
175 GetGtkSplitterFullSize(),
182 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
184 const wxRect
& WXUNUSED(rect
),
191 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
195 wxOrientation orient
,
198 if ( !win
->m_wxwindow
->window
)
200 // window not realized yet
204 wxCoord full_size
= GetGtkSplitterFullSize();
206 // are we drawing vertical or horizontal splitter?
207 const bool isVert
= orient
== wxVERTICAL
;
211 GdkRectangle erase_rect
;
216 int h
= win
->GetClientSize().GetHeight();
220 rect
.width
= full_size
;
224 erase_rect
.x
= position
;
226 erase_rect
.width
= full_size
;
227 erase_rect
.height
= h
;
232 int w
= win
->GetClientSize().GetWidth();
236 rect
.height
= full_size
;
240 erase_rect
.y
= position
;
242 erase_rect
.height
= full_size
;
243 erase_rect
.width
= w
;
248 // we must erase everything first, otherwise the garbage
249 // from the old sash is left when dragging it
252 win
->m_wxwindow
->style
,
253 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
258 (char *)"viewportbin", // const_cast
267 // leave some margin before sash itself
268 position
+= SASH_MARGIN
/ 2;
270 // and finally draw it using GTK paint functions
271 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
273 GdkRectangle
*, GtkWidget
*,
277 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
281 win
->m_wxwindow
->style
,
282 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
286 (char *)"paned", // const_cast
287 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
292 win
->m_wxwindow
->style
,
293 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
298 (char *)"paned", // const_cast
299 isVert
? position
: size
.x
- 2*SASH_SIZE
,
300 isVert
? size
.y
- 2*SASH_SIZE
: position
,
306 wxRendererGTK::DrawDropArrow(wxWindow
*WXUNUSED(win
),
311 GtkWidget
*button
= GetButtonWidget();
313 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
314 // a window for gtk_paint_xxx function, then it won't
315 // work for wxMemoryDC. So that is why we assume wxDC
316 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
317 // are derived from it) and use its m_window.
318 wxWindowDCImpl
* const impl
= wxDynamicCast(dc
.GetImpl(), wxWindowDCImpl
);
319 wxCHECK_RET( impl
, "must have a window DC" );
321 GdkWindow
* gdk_window
= impl
->GetGDKWindow();
323 // draw arrow so that there is even space horizontally
325 int arrowX
= rect
.width
/4 + 1;
326 int arrowWidth
= rect
.width
- (arrowX
*2);
328 // scale arrow's height accoording to the width
329 int arrowHeight
= rect
.width
/3;
330 int arrowY
= (rect
.height
-arrowHeight
)/2 +
331 ((rect
.height
-arrowHeight
) & 1);
335 if ( flags
& wxCONTROL_PRESSED
)
336 state
= GTK_STATE_ACTIVE
;
337 else if ( flags
& wxCONTROL_DISABLED
)
338 state
= GTK_STATE_INSENSITIVE
;
339 else if ( flags
& wxCONTROL_CURRENT
)
340 state
= GTK_STATE_PRELIGHT
;
342 state
= GTK_STATE_NORMAL
;
344 // draw arrow on button
350 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
364 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
369 GtkWidget
*button
= GetButtonWidget();
371 // for reason why we do this, see DrawDropArrow
372 wxWindowDCImpl
* const impl
= wxDynamicCast(dc
.GetImpl(), wxWindowDCImpl
);
373 wxCHECK_RET( impl
, "must have a window DC" );
375 GdkWindow
* gdk_window
= impl
->GetGDKWindow();
380 if ( flags
& wxCONTROL_PRESSED
)
381 state
= GTK_STATE_ACTIVE
;
382 else if ( flags
& wxCONTROL_DISABLED
)
383 state
= GTK_STATE_INSENSITIVE
;
384 else if ( flags
& wxCONTROL_CURRENT
)
385 state
= GTK_STATE_PRELIGHT
;
387 state
= GTK_STATE_NORMAL
;
394 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
398 rect
.x
, rect
.y
, rect
.width
, rect
.height
401 // draw arrow on button
402 DrawDropArrow(win
,dc
,rect
,flags
);