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 license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/gtk/win_gtk.h"
33 #include "wx/window.h"
35 #include "wx/renderer.h"
38 #include "wx/settings.h"
42 #define WXUNUSED_IN_GTK1(arg) arg
44 #define WXUNUSED_IN_GTK1(arg)
47 // ----------------------------------------------------------------------------
48 // wxRendererGTK: our wxRendererNative implementation
49 // ----------------------------------------------------------------------------
51 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
54 // draw the header control button (used by wxListCtrl)
55 virtual void DrawHeaderButton(wxWindow
*win
,
61 // draw the expanded/collapsed icon for a tree control item
62 virtual void DrawTreeItemButton(wxWindow
*win
,
68 virtual void DrawSplitterBorder(wxWindow
*win
,
72 virtual void DrawSplitterSash(wxWindow
*win
,
79 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
82 // ============================================================================
84 // ============================================================================
87 wxRendererNative
& wxRendererNative::GetDefault()
89 static wxRendererGTK s_rendererGTK
;
94 // ----------------------------------------------------------------------------
95 // list/tree controls drawing
96 // ----------------------------------------------------------------------------
99 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
105 static GtkWidget
*s_button
= NULL
;
106 static GtkWidget
*s_window
= NULL
;
107 if (s_button
== NULL
)
109 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
110 gtk_widget_realize( s_window
);
111 s_button
= gtk_button_new();
112 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
113 gtk_widget_realize( s_button
);
119 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
120 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
125 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
131 // draw a ">" or "v" button
133 // TODO: isn't there a GTK function to draw it?
135 wxRendererGTK::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
136 wxDC
& dc
, const wxRect
& rect
, int flags
)
138 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
140 dc
.SetPen(*wxBLACK_PEN
);
143 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
144 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
146 if ( flags
& wxCONTROL_EXPANDED
)
148 button
[0].x
= rect
.GetLeft();
149 button
[0].y
= yMiddle
- 2;
150 button
[1].x
= rect
.GetRight();
151 button
[1].y
= yMiddle
- 2;
152 button
[2].x
= xMiddle
;
153 button
[2].y
= yMiddle
+ 3;
157 button
[0].y
= rect
.GetBottom();
158 button
[0].x
= xMiddle
- 2;
159 button
[1].y
= rect
.GetTop();
160 button
[1].x
= xMiddle
- 2;
161 button
[2].y
= yMiddle
;
162 button
[2].x
= xMiddle
+ 3;
165 dc
.DrawPolygon(3, button
);
170 // ----------------------------------------------------------------------------
171 // splitter sash drawing
172 // ----------------------------------------------------------------------------
174 // all this should probably be read from the current theme settings somehow?
176 // the full sash size
177 static const wxCoord SASH_FULL_SIZE
= 5;
179 // the full sash width (should be even)
180 static const wxCoord SASH_SIZE
= 8;
182 // margin around the sash
183 static const wxCoord SASH_MARGIN
= 2;
185 // the full sash size
186 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
187 #endif // GTK+ 2.x/1.x
189 wxSplitterRenderParams
190 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
192 // we don't draw any border, hence 0 for the second field
193 return wxSplitterRenderParams
198 true // hot sensitive
201 #endif // GTK+ 2.x/1.x
206 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
208 const wxRect
& WXUNUSED(rect
),
215 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
219 wxOrientation orient
,
220 int WXUNUSED_IN_GTK1(flags
))
222 if ( !win
->m_wxwindow
->window
)
224 // VZ: this happens on startup -- why?
228 // are we drawing vertical or horizontal splitter?
229 const bool isVert
= orient
== wxVERTICAL
;
232 GdkRectangle erase_rect
;
235 int h
= win
->GetClientSize().GetHeight();
239 rect
.width
= SASH_FULL_SIZE
;
242 erase_rect
.x
= position
;
244 erase_rect
.width
= SASH_FULL_SIZE
;
245 erase_rect
.height
= h
;
249 int w
= win
->GetClientSize().GetWidth();
253 rect
.height
= SASH_FULL_SIZE
;
256 erase_rect
.y
= position
;
258 erase_rect
.height
= SASH_FULL_SIZE
;
259 erase_rect
.width
= w
;
262 // we must erase everything first, otherwise the garbage from the old sash
263 // is left when dragging it
265 // TODO: is this the right way to draw themed background?
268 win
->m_wxwindow
->style
,
269 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
274 (char *)"base", // const_cast
284 win
->m_wxwindow
->style
,
285 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
286 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
288 NULL
/* no clipping */,
295 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
299 // leave some margin before sash itself
300 position
+= SASH_MARGIN
/ 2;
302 // and finally draw it using GTK paint functions
303 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
305 GdkRectangle
*, GtkWidget
*,
309 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
313 win
->m_wxwindow
->style
,
314 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
318 (char *)"paned", // const_cast
319 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
324 win
->m_wxwindow
->style
,
325 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
328 (GdkRectangle
*) NULL
,
330 (char *)"paned", // const_cast
331 isVert
? position
: size
.x
- 2*SASH_SIZE
,
332 isVert
? size
.y
- 2*SASH_SIZE
: position
,
335 #endif // GTK+ 2.x/1.x