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
* win
,
136 wxDC
& dc
, const wxRect
& rect
, int flags
)
142 GtkPizza
*pizza
= GTK_PIZZA( win
->m_wxwindow
);
143 GtkStyle
*style
= win
->m_widget
->style
;
148 // This draws the GTK+ 2.2.4 triangle
152 if ( flags
& wxCONTROL_EXPANDED
)
155 points
[0].y
= y
+ (PM_SIZE
+ 2) / 6;
156 points
[1].x
= points
[0].x
+ (PM_SIZE
+ 2);
157 points
[1].y
= points
[0].y
;
158 points
[2].x
= (points
[0].x
+ (PM_SIZE
+ 2) / 2);
159 points
[2].y
= y
+ 2 * (PM_SIZE
+ 2) / 3;
163 points
[0].x
= x
+ ((PM_SIZE
+ 2) / 6 + 2);
165 points
[1].x
= points
[0].x
;
166 points
[1].y
= points
[0].y
+ (PM_SIZE
+ 2);
167 points
[2].x
= (points
[0].x
+
168 (2 * (PM_SIZE
+ 2) / 3 - 1));
169 points
[2].y
= points
[0].y
+ (PM_SIZE
+ 2) / 2;
172 if ( flags
& wxCONTROL_CURRENT
)
173 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_PRELIGHT
], TRUE
, points
, 3);
175 gdk_draw_polygon( pizza
->bin_window
, style
->base_gc
[GTK_STATE_NORMAL
], TRUE
, points
, 3);
176 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
, points
, 3 );
178 // this draws the GTK+ 2.2.3 tree item square
179 gdk_draw_rectangle( pizza
->bin_window
,
180 style
->base_gc
[GTK_STATE_NORMAL
], TRUE
,
181 x
, y
, PM_SIZE
, PM_SIZE
);
182 gdk_draw_rectangle( pizza
->bin_window
,
183 style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
,
184 x
, y
, PM_SIZE
, PM_SIZE
);
186 gdk_draw_line( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
],
187 x
+ 2, y
+ PM_SIZE
/ 2, x
+ PM_SIZE
- 2, y
+ PM_SIZE
/ 2);
189 if ( flags
& wxCONTROL_EXPANDED
)
191 gdk_draw_line( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
],
192 x
+ PM_SIZE
/ 2, y
+ 2,
193 x
+ PM_SIZE
/ 2, y
+ PM_SIZE
- 2);
199 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
201 dc
.SetPen(*wxBLACK_PEN
);
204 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
205 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
207 if ( flags
& wxCONTROL_EXPANDED
)
209 button
[0].x
= rect
.GetLeft();
210 button
[0].y
= yMiddle
- 2;
211 button
[1].x
= rect
.GetRight();
212 button
[1].y
= yMiddle
- 2;
213 button
[2].x
= xMiddle
;
214 button
[2].y
= yMiddle
+ 3;
218 button
[0].y
= rect
.GetBottom();
219 button
[0].x
= xMiddle
- 2;
220 button
[1].y
= rect
.GetTop();
221 button
[1].x
= xMiddle
- 2;
222 button
[2].y
= yMiddle
;
223 button
[2].x
= xMiddle
+ 3;
226 dc
.DrawPolygon(3, button
);
232 // ----------------------------------------------------------------------------
233 // splitter sash drawing
234 // ----------------------------------------------------------------------------
236 // all this should probably be read from the current theme settings somehow?
238 // the full sash size
239 static const wxCoord SASH_FULL_SIZE
= 5;
241 // the full sash width (should be even)
242 static const wxCoord SASH_SIZE
= 8;
244 // margin around the sash
245 static const wxCoord SASH_MARGIN
= 2;
247 // the full sash size
248 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
249 #endif // GTK+ 2.x/1.x
251 wxSplitterRenderParams
252 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
254 // we don't draw any border, hence 0 for the second field
255 return wxSplitterRenderParams
260 true // hot sensitive
263 #endif // GTK+ 2.x/1.x
268 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
270 const wxRect
& WXUNUSED(rect
),
277 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
281 wxOrientation orient
,
282 int WXUNUSED_IN_GTK1(flags
))
284 if ( !win
->m_wxwindow
->window
)
286 // VZ: this happens on startup -- why?
290 // are we drawing vertical or horizontal splitter?
291 const bool isVert
= orient
== wxVERTICAL
;
294 GdkRectangle erase_rect
;
297 int h
= win
->GetClientSize().GetHeight();
301 rect
.width
= SASH_FULL_SIZE
;
304 erase_rect
.x
= position
;
306 erase_rect
.width
= SASH_FULL_SIZE
;
307 erase_rect
.height
= h
;
311 int w
= win
->GetClientSize().GetWidth();
315 rect
.height
= SASH_FULL_SIZE
;
318 erase_rect
.y
= position
;
320 erase_rect
.height
= SASH_FULL_SIZE
;
321 erase_rect
.width
= w
;
324 // we must erase everything first, otherwise the garbage from the old sash
325 // is left when dragging it
327 // TODO: is this the right way to draw themed background?
330 win
->m_wxwindow
->style
,
331 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
336 (char *)"base", // const_cast
346 win
->m_wxwindow
->style
,
347 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
348 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
350 NULL
/* no clipping */,
357 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
361 // leave some margin before sash itself
362 position
+= SASH_MARGIN
/ 2;
364 // and finally draw it using GTK paint functions
365 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
367 GdkRectangle
*, GtkWidget
*,
371 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
375 win
->m_wxwindow
->style
,
376 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
380 (char *)"paned", // const_cast
381 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
386 win
->m_wxwindow
->style
,
387 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
390 (GdkRectangle
*) NULL
,
392 (char *)"paned", // const_cast
393 isVert
? position
: size
.x
- 2*SASH_SIZE
,
394 isVert
? size
.y
- 2*SASH_SIZE
: position
,
397 #endif // GTK+ 2.x/1.x