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"
27 #include "wx/renderer.h"
29 #include "wx/gtk/win_gtk.h"
31 #include "wx/window.h"
35 #include "wx/settings.h"
39 #define WXUNUSED_IN_GTK1(arg) arg
41 #define WXUNUSED_IN_GTK1(arg)
44 // ----------------------------------------------------------------------------
45 // wxRendererGTK: our wxRendererNative implementation
46 // ----------------------------------------------------------------------------
48 class WXDLLEXPORT wxRendererGTK
: public wxDelegateRendererNative
51 // draw the header control button (used by wxListCtrl)
52 virtual void DrawHeaderButton(wxWindow
*win
,
58 // draw the expanded/collapsed icon for a tree control item
59 virtual void DrawTreeItemButton(wxWindow
*win
,
65 virtual void DrawSplitterBorder(wxWindow
*win
,
69 virtual void DrawSplitterSash(wxWindow
*win
,
76 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
79 // ============================================================================
81 // ============================================================================
84 wxRendererNative
& wxRendererNative::GetDefault()
86 static wxRendererGTK s_rendererGTK
;
91 // ----------------------------------------------------------------------------
92 // list/tree controls drawing
93 // ----------------------------------------------------------------------------
96 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
102 static GtkWidget
*s_button
= NULL
;
103 static GtkWidget
*s_window
= NULL
;
104 if (s_button
== NULL
)
106 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
107 gtk_widget_realize( s_window
);
108 s_button
= gtk_button_new();
109 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
110 gtk_widget_realize( s_button
);
116 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
117 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
122 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
128 // draw a ">" or "v" button
130 // TODO: replace the code below with gtk_paint_expander()
132 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
133 wxDC
& dc
, const wxRect
& rect
, int flags
)
137 GtkPizza
*pizza
= GTK_PIZZA( win
->m_wxwindow
);
138 GtkStyle
*style
= win
->m_widget
->style
;
141 y
= dc
.LogicalToDeviceY( y
);
142 x
= dc
.LogicalToDeviceX( x
);
144 // This draws the GTK+ 2.2.4 triangle
148 if ( flags
& wxCONTROL_EXPANDED
)
151 points
[0].y
= y
+ (PM_SIZE
+ 2) / 6;
152 points
[1].x
= points
[0].x
+ (PM_SIZE
+ 2);
153 points
[1].y
= points
[0].y
;
154 points
[2].x
= (points
[0].x
+ (PM_SIZE
+ 2) / 2);
155 points
[2].y
= y
+ 2 * (PM_SIZE
+ 2) / 3;
159 points
[0].x
= x
+ ((PM_SIZE
+ 2) / 6 + 2);
161 points
[1].x
= points
[0].x
;
162 points
[1].y
= points
[0].y
+ (PM_SIZE
+ 2);
163 points
[2].x
= (points
[0].x
+
164 (2 * (PM_SIZE
+ 2) / 3 - 1));
165 points
[2].y
= points
[0].y
+ (PM_SIZE
+ 2) / 2;
168 if ( flags
& wxCONTROL_CURRENT
)
169 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_PRELIGHT
], TRUE
, points
, 3);
171 gdk_draw_polygon( pizza
->bin_window
, style
->base_gc
[GTK_STATE_NORMAL
], TRUE
, points
, 3);
172 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
, points
, 3 );
177 // ----------------------------------------------------------------------------
178 // splitter sash drawing
179 // ----------------------------------------------------------------------------
181 // all this should probably be read from the current theme settings somehow?
183 // the full sash size
184 static const wxCoord SASH_FULL_SIZE
= 5;
186 // the full sash width (should be even)
187 static const wxCoord SASH_SIZE
= 8;
189 // margin around the sash
190 static const wxCoord SASH_MARGIN
= 2;
192 // the full sash size
193 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
194 #endif // GTK+ 2.x/1.x
196 wxSplitterRenderParams
197 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
199 // we don't draw any border, hence 0 for the second field
200 return wxSplitterRenderParams
205 true // hot sensitive
208 #endif // GTK+ 2.x/1.x
213 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
215 const wxRect
& WXUNUSED(rect
),
222 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
226 wxOrientation orient
,
227 int WXUNUSED_IN_GTK1(flags
))
229 if ( !win
->m_wxwindow
->window
)
231 // window not realized yet
235 // are we drawing vertical or horizontal splitter?
236 const bool isVert
= orient
== wxVERTICAL
;
239 GdkRectangle erase_rect
;
242 int h
= win
->GetClientSize().GetHeight();
246 rect
.width
= SASH_FULL_SIZE
;
249 erase_rect
.x
= position
;
251 erase_rect
.width
= SASH_FULL_SIZE
;
252 erase_rect
.height
= h
;
256 int w
= win
->GetClientSize().GetWidth();
260 rect
.height
= SASH_FULL_SIZE
;
263 erase_rect
.y
= position
;
265 erase_rect
.height
= SASH_FULL_SIZE
;
266 erase_rect
.width
= w
;
269 // we must erase everything first, otherwise the garbage from the old sash
270 // is left when dragging it
272 // TODO: is this the right way to draw themed background?
275 win
->m_wxwindow
->style
,
276 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
281 (char *)"base", // const_cast
291 win
->m_wxwindow
->style
,
292 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
293 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
295 NULL
/* no clipping */,
302 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
306 // leave some margin before sash itself
307 position
+= SASH_MARGIN
/ 2;
309 // and finally draw it using GTK paint functions
310 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
312 GdkRectangle
*, GtkWidget
*,
316 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
320 win
->m_wxwindow
->style
,
321 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
325 (char *)"paned", // const_cast
326 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
331 win
->m_wxwindow
->style
,
332 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
335 (GdkRectangle
*) NULL
,
337 (char *)"paned", // const_cast
338 isVert
? position
: size
.x
- 2*SASH_SIZE
,
339 isVert
? size
.y
- 2*SASH_SIZE
: position
,
342 #endif // GTK+ 2.x/1.x