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 licence
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
;
146 y
= dc
.LogicalToDeviceY( y
);
147 x
= dc
.LogicalToDeviceX( x
);
150 // This draws the GTK+ 2.2.4 triangle
154 if ( flags
& wxCONTROL_EXPANDED
)
157 points
[0].y
= y
+ (PM_SIZE
+ 2) / 6;
158 points
[1].x
= points
[0].x
+ (PM_SIZE
+ 2);
159 points
[1].y
= points
[0].y
;
160 points
[2].x
= (points
[0].x
+ (PM_SIZE
+ 2) / 2);
161 points
[2].y
= y
+ 2 * (PM_SIZE
+ 2) / 3;
165 points
[0].x
= x
+ ((PM_SIZE
+ 2) / 6 + 2);
167 points
[1].x
= points
[0].x
;
168 points
[1].y
= points
[0].y
+ (PM_SIZE
+ 2);
169 points
[2].x
= (points
[0].x
+
170 (2 * (PM_SIZE
+ 2) / 3 - 1));
171 points
[2].y
= points
[0].y
+ (PM_SIZE
+ 2) / 2;
174 if ( flags
& wxCONTROL_CURRENT
)
175 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_PRELIGHT
], TRUE
, points
, 3);
177 gdk_draw_polygon( pizza
->bin_window
, style
->base_gc
[GTK_STATE_NORMAL
], TRUE
, points
, 3);
178 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
, points
, 3 );
180 // this draws the GTK+ 2.2.3 tree item square
181 gdk_draw_rectangle( pizza
->bin_window
,
182 style
->base_gc
[GTK_STATE_NORMAL
], TRUE
,
183 x
, y
, PM_SIZE
, PM_SIZE
);
184 gdk_draw_rectangle( pizza
->bin_window
,
185 style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
,
186 x
, y
, PM_SIZE
, PM_SIZE
);
188 gdk_draw_line( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
],
189 x
+ 2, y
+ PM_SIZE
/ 2, x
+ PM_SIZE
- 2, y
+ PM_SIZE
/ 2);
191 if ( flags
& wxCONTROL_EXPANDED
)
193 gdk_draw_line( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
],
194 x
+ PM_SIZE
/ 2, y
+ 2,
195 x
+ PM_SIZE
/ 2, y
+ PM_SIZE
- 2);
201 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
),
203 dc
.SetPen(*wxBLACK_PEN
);
206 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
207 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
209 if ( flags
& wxCONTROL_EXPANDED
)
211 button
[0].x
= rect
.GetLeft();
212 button
[0].y
= yMiddle
- 2;
213 button
[1].x
= rect
.GetRight();
214 button
[1].y
= yMiddle
- 2;
215 button
[2].x
= xMiddle
;
216 button
[2].y
= yMiddle
+ 3;
220 button
[0].y
= rect
.GetBottom();
221 button
[0].x
= xMiddle
- 2;
222 button
[1].y
= rect
.GetTop();
223 button
[1].x
= xMiddle
- 2;
224 button
[2].y
= yMiddle
;
225 button
[2].x
= xMiddle
+ 3;
228 dc
.DrawPolygon(3, button
);
234 // ----------------------------------------------------------------------------
235 // splitter sash drawing
236 // ----------------------------------------------------------------------------
238 // all this should probably be read from the current theme settings somehow?
240 // the full sash size
241 static const wxCoord SASH_FULL_SIZE
= 5;
243 // the full sash width (should be even)
244 static const wxCoord SASH_SIZE
= 8;
246 // margin around the sash
247 static const wxCoord SASH_MARGIN
= 2;
249 // the full sash size
250 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
251 #endif // GTK+ 2.x/1.x
253 wxSplitterRenderParams
254 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
256 // we don't draw any border, hence 0 for the second field
257 return wxSplitterRenderParams
262 true // hot sensitive
265 #endif // GTK+ 2.x/1.x
270 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
272 const wxRect
& WXUNUSED(rect
),
279 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
283 wxOrientation orient
,
284 int WXUNUSED_IN_GTK1(flags
))
286 if ( !win
->m_wxwindow
->window
)
288 // VZ: this happens on startup -- why?
292 // are we drawing vertical or horizontal splitter?
293 const bool isVert
= orient
== wxVERTICAL
;
296 GdkRectangle erase_rect
;
299 int h
= win
->GetClientSize().GetHeight();
303 rect
.width
= SASH_FULL_SIZE
;
306 erase_rect
.x
= position
;
308 erase_rect
.width
= SASH_FULL_SIZE
;
309 erase_rect
.height
= h
;
313 int w
= win
->GetClientSize().GetWidth();
317 rect
.height
= SASH_FULL_SIZE
;
320 erase_rect
.y
= position
;
322 erase_rect
.height
= SASH_FULL_SIZE
;
323 erase_rect
.width
= w
;
326 // we must erase everything first, otherwise the garbage from the old sash
327 // is left when dragging it
329 // TODO: is this the right way to draw themed background?
332 win
->m_wxwindow
->style
,
333 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
338 (char *)"base", // const_cast
348 win
->m_wxwindow
->style
,
349 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
350 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
352 NULL
/* no clipping */,
359 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
363 // leave some margin before sash itself
364 position
+= SASH_MARGIN
/ 2;
366 // and finally draw it using GTK paint functions
367 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
369 GdkRectangle
*, GtkWidget
*,
373 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
377 win
->m_wxwindow
->style
,
378 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
382 (char *)"paned", // const_cast
383 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
388 win
->m_wxwindow
->style
,
389 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
392 (GdkRectangle
*) NULL
,
394 (char *)"paned", // const_cast
395 isVert
? position
: size
.x
- 2*SASH_SIZE
,
396 isVert
? size
.y
- 2*SASH_SIZE
: position
,
399 #endif // GTK+ 2.x/1.x