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,
106 win->m_wxwindow->style,
107 GTK_PIZZA(win->m_wxwindow)->bin_window,
108 flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
110 (GdkRectangle*) NULL,
112 (char *)"button", // const_cast
113 dc.XLOG2DEV(rect.x) - 1, rect.y - 1, rect.width + 2, rect.height + 2
119 // draw a ">" or "v" button
121 // TODO: isn't there a GTK function to draw it?
123 wxRendererGTK::DrawTreeItemButton(wxWindow* WXUNUSED(win),
124 wxDC& dc, const wxRect& rect, int flags)
126 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT),
128 dc.SetPen(*wxBLACK_PEN);
131 const wxCoord xMiddle = rect.x + rect.width/2;
132 const wxCoord yMiddle = rect.y + rect.height/2;
134 if ( flags & wxCONTROL_EXPANDED )
136 button[0].x = rect.GetLeft();
137 button[0].y = yMiddle - 2;
138 button[1].x = rect.GetRight();
139 button[1].y = yMiddle - 2;
140 button[2].x = xMiddle;
141 button[2].y = yMiddle + 3;
145 button[0].y = rect.GetBottom();
146 button[0].x = xMiddle - 2;
147 button[1].y = rect.GetTop();
148 button[1].x = xMiddle - 2;
149 button[2].y = yMiddle;
150 button[2].x = xMiddle + 3;
153 dc.DrawPolygon(3, button);
158 // ----------------------------------------------------------------------------
159 // splitter sash drawing
160 // ----------------------------------------------------------------------------
162 // all this should probably be read from the current theme settings somehow?
164 // the full sash size
165 static const wxCoord SASH_FULL_SIZE = 5;
167 // the full sash width (should be even)
168 static const wxCoord SASH_SIZE = 10;
170 // margin around the sash
171 static const wxCoord SASH_MARGIN = 5;
173 // the full sash size
174 static const wxCoord SASH_FULL_SIZE = SASH_SIZE + SASH_MARGIN;
175 #endif // GTK+ 2.x/1.x
177 wxSplitterRenderParams
178 wxRendererGTK::GetSplitterParams(const wxWindow * WXUNUSED(win))
180 // we don't draw any border, hence 0 for the second field
181 return wxSplitterRenderParams
186 true // hot sensitive
189 #endif // GTK+ 2.x/1.x
194 wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win),
196 const wxRect& WXUNUSED(rect),
203 wxRendererGTK::DrawSplitterSash(wxWindow *win,
207 wxOrientation orient,
208 int WXUNUSED_IN_GTK1(flags))
210 if ( !win->m_wxwindow->window )
212 // VZ: this happens on startup -- why?
216 // are we drawing vertical or horizontal splitter?
217 const bool isVert = orient == wxVERTICAL;
224 rect.width = SASH_FULL_SIZE;
225 rect.height = size.y;
231 rect.height = SASH_FULL_SIZE;
238 win->m_wxwindow->style,
239 GTK_PIZZA(win->m_wxwindow)->bin_window,
240 flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
242 NULL /* no clipping */,
249 isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL
252 // we must erase everything first, otherwise the garbage from the old sash
253 // is left when dragging it
255 // TODO: is this the right way to draw themed background?
258 win->m_wxwindow->style,
259 GTK_PIZZA(win->m_wxwindow)->bin_window,
264 (char *)"base", // const_cast
269 // leave some margin before sash itself
270 position += SASH_MARGIN / 2;
272 // and finally draw it using GTK paint functions
273 typedef void (*GtkPaintLineFunc)(GtkStyle *, GdkWindow *,
275 GdkRectangle *, GtkWidget *,
279 GtkPaintLineFunc func = isVert ? gtk_paint_vline : gtk_paint_hline;
283 win->m_wxwindow->style,
284 GTK_PIZZA(win->m_wxwindow)->bin_window,
288 (char *)"paned", // const_cast
289 0, isVert ? size.y : size.x, position + SASH_SIZE / 2 - 1
294 win->m_wxwindow->style,
295 GTK_PIZZA(win->m_wxwindow)->bin_window,
298 (GdkRectangle*) NULL,
300 (char *)"paned", // const_cast
301 isVert ? position : size.x - 2*SASH_SIZE,
302 isVert ? size.y - 2*SASH_SIZE : position,
305 #endif // GTK+ 2.x/1.x