1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/renderer.cpp
3 // Purpose: implementation of wxRendererNative for wxGTK
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/renderer.h"
29 #include "wx/window.h"
34 #include "wx/gtk1/win_gtk.h"
35 #include "wx/gtk1/dcclient.h"
37 // RR: After a correction to the orientation of the sash
38 // this doesn't seem to be required anymore and it
39 // seems to confuse some themes so USE_ERASE_RECT=0
40 #define USE_ERASE_RECT 0
42 // ----------------------------------------------------------------------------
43 // wxRendererGTK: our wxRendererNative implementation
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
49 // draw the header control button (used by wxListCtrl)
50 virtual int DrawHeaderButton(wxWindow
*win
,
54 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
55 wxHeaderButtonParams
* params
=NULL
);
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
,
130 wxHeaderSortIconType
WXUNUSED(sortArrow
),
131 wxHeaderButtonParams
* WXUNUSED(params
))
134 GtkWidget
*button
= GetButtonWidget();
139 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
140 // Maybe use code similar as in DrawComboBoxDropButton below?
141 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
142 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
147 dc
.LogicalToDeviceX(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
150 return rect
.width
+ 2;
153 // ----------------------------------------------------------------------------
154 // splitter sash drawing
155 // ----------------------------------------------------------------------------
157 // the full sash width (should be even)
158 static const wxCoord SASH_SIZE
= 8;
160 // margin around the sash
161 static const wxCoord SASH_MARGIN
= 2;
163 static int GetGtkSplitterFullSize()
165 return SASH_SIZE
+ SASH_MARGIN
;
168 wxSplitterRenderParams
169 wxRendererGTK::GetSplitterParams(const wxWindow
*WXUNUSED(win
))
171 // we don't draw any border, hence 0 for the second field
172 return wxSplitterRenderParams
174 GetGtkSplitterFullSize(),
181 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
183 const wxRect
& WXUNUSED(rect
),
190 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
194 wxOrientation orient
,
197 if ( !win
->m_wxwindow
->window
)
199 // window not realized yet
203 wxCoord full_size
= GetGtkSplitterFullSize();
205 // are we drawing vertical or horizontal splitter?
206 const bool isVert
= orient
== wxVERTICAL
;
210 GdkRectangle erase_rect
;
215 int h
= win
->GetClientSize().GetHeight();
219 rect
.width
= full_size
;
223 erase_rect
.x
= position
;
225 erase_rect
.width
= full_size
;
226 erase_rect
.height
= h
;
231 int w
= win
->GetClientSize().GetWidth();
235 rect
.height
= full_size
;
239 erase_rect
.y
= position
;
241 erase_rect
.height
= full_size
;
242 erase_rect
.width
= w
;
247 // we must erase everything first, otherwise the garbage
248 // from the old sash is left when dragging it
251 win
->m_wxwindow
->style
,
252 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
257 (char *)"viewportbin", // const_cast
266 // leave some margin before sash itself
267 position
+= SASH_MARGIN
/ 2;
269 // and finally draw it using GTK paint functions
270 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
272 GdkRectangle
*, GtkWidget
*,
276 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
280 win
->m_wxwindow
->style
,
281 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
285 (char *)"paned", // const_cast
286 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
291 win
->m_wxwindow
->style
,
292 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
297 (char *)"paned", // const_cast
298 isVert
? position
: size
.x
- 2*SASH_SIZE
,
299 isVert
? size
.y
- 2*SASH_SIZE
: position
,
305 wxRendererGTK::DrawDropArrow(wxWindow
*WXUNUSED(win
),
310 GtkWidget
*button
= GetButtonWidget();
312 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
313 // a window for gtk_paint_xxx function, then it won't
314 // work for wxMemoryDC. So that is why we assume wxDC
315 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
316 // are derived from it) and use its m_window.
317 wxWindowDCImpl
* const impl
= wxDynamicCast(dc
.GetImpl(), wxWindowDCImpl
);
318 wxCHECK_RET( impl
, "must have a window DC" );
320 GdkWindow
* gdk_window
= impl
->GetGDKWindow();
322 // draw arrow so that there is even space horizontally
324 int arrowX
= rect
.width
/4 + 1;
325 int arrowWidth
= rect
.width
- (arrowX
*2);
327 // scale arrow's height accoording to the width
328 int arrowHeight
= rect
.width
/3;
329 int arrowY
= (rect
.height
-arrowHeight
)/2 +
330 ((rect
.height
-arrowHeight
) & 1);
334 if ( flags
& wxCONTROL_PRESSED
)
335 state
= GTK_STATE_ACTIVE
;
336 else if ( flags
& wxCONTROL_DISABLED
)
337 state
= GTK_STATE_INSENSITIVE
;
338 else if ( flags
& wxCONTROL_CURRENT
)
339 state
= GTK_STATE_PRELIGHT
;
341 state
= GTK_STATE_NORMAL
;
343 // draw arrow on button
349 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
363 wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
368 GtkWidget
*button
= GetButtonWidget();
370 // for reason why we do this, see DrawDropArrow
371 wxWindowDCImpl
* const impl
= wxDynamicCast(dc
.GetImpl(), wxWindowDCImpl
);
372 wxCHECK_RET( impl
, "must have a window DC" );
374 GdkWindow
* gdk_window
= impl
->GetGDKWindow();
379 if ( flags
& wxCONTROL_PRESSED
)
380 state
= GTK_STATE_ACTIVE
;
381 else if ( flags
& wxCONTROL_DISABLED
)
382 state
= GTK_STATE_INSENSITIVE
;
383 else if ( flags
& wxCONTROL_CURRENT
)
384 state
= GTK_STATE_PRELIGHT
;
386 state
= GTK_STATE_NORMAL
;
393 flags
& wxCONTROL_PRESSED
? GTK_SHADOW_IN
: GTK_SHADOW_OUT
,
397 rect
.x
, rect
.y
, rect
.width
, rect
.height
400 // draw arrow on button
401 DrawDropArrow(win
,dc
,rect
,flags
);