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 void DrawComboBoxDropButton(wxWindow
*win
,
81 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
84 // ============================================================================
86 // ============================================================================
89 wxRendererNative
& wxRendererNative::GetDefault()
91 static wxRendererGTK s_rendererGTK
;
96 // ----------------------------------------------------------------------------
97 // list/tree controls drawing
98 // ----------------------------------------------------------------------------
101 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
107 static GtkWidget
*s_button
= NULL
;
108 static GtkWidget
*s_window
= NULL
;
109 if (s_button
== NULL
)
111 s_window
= gtk_window_new( GTK_WINDOW_POPUP
);
112 gtk_widget_realize( s_window
);
113 s_button
= gtk_button_new();
114 gtk_container_add( GTK_CONTAINER(s_window
), s_button
);
115 gtk_widget_realize( s_button
);
121 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
122 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
127 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
133 // draw a ">" or "v" button
135 // TODO: replace the code below with gtk_paint_expander()
137 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
138 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
);
149 // This draws the GTK+ 2.2.4 triangle
153 if ( flags
& wxCONTROL_EXPANDED
)
156 points
[0].y
= y
+ (PM_SIZE
+ 2) / 6;
157 points
[1].x
= points
[0].x
+ (PM_SIZE
+ 2);
158 points
[1].y
= points
[0].y
;
159 points
[2].x
= (points
[0].x
+ (PM_SIZE
+ 2) / 2);
160 points
[2].y
= y
+ 2 * (PM_SIZE
+ 2) / 3;
164 points
[0].x
= x
+ ((PM_SIZE
+ 2) / 6 + 2);
166 points
[1].x
= points
[0].x
;
167 points
[1].y
= points
[0].y
+ (PM_SIZE
+ 2);
168 points
[2].x
= (points
[0].x
+
169 (2 * (PM_SIZE
+ 2) / 3 - 1));
170 points
[2].y
= points
[0].y
+ (PM_SIZE
+ 2) / 2;
173 if ( flags
& wxCONTROL_CURRENT
)
174 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_PRELIGHT
], TRUE
, points
, 3);
176 gdk_draw_polygon( pizza
->bin_window
, style
->base_gc
[GTK_STATE_NORMAL
], TRUE
, points
, 3);
177 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
, points
, 3 );
182 // ----------------------------------------------------------------------------
183 // splitter sash drawing
184 // ----------------------------------------------------------------------------
186 // all this should probably be read from the current theme settings somehow?
188 // the full sash size
189 static const wxCoord SASH_FULL_SIZE
= 5;
191 // the full sash width (should be even)
192 static const wxCoord SASH_SIZE
= 8;
194 // margin around the sash
195 static const wxCoord SASH_MARGIN
= 2;
197 // the full sash size
198 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
199 #endif // GTK+ 2.x/1.x
201 wxSplitterRenderParams
202 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
204 // we don't draw any border, hence 0 for the second field
205 return wxSplitterRenderParams
210 true // hot sensitive
213 #endif // GTK+ 2.x/1.x
218 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
220 const wxRect
& WXUNUSED(rect
),
227 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
231 wxOrientation orient
,
232 int WXUNUSED_IN_GTK1(flags
))
234 if ( !win
->m_wxwindow
->window
)
236 // window not realized yet
240 // are we drawing vertical or horizontal splitter?
241 const bool isVert
= orient
== wxVERTICAL
;
244 GdkRectangle erase_rect
;
247 int h
= win
->GetClientSize().GetHeight();
251 rect
.width
= SASH_FULL_SIZE
;
254 erase_rect
.x
= position
;
256 erase_rect
.width
= SASH_FULL_SIZE
;
257 erase_rect
.height
= h
;
261 int w
= win
->GetClientSize().GetWidth();
265 rect
.height
= SASH_FULL_SIZE
;
268 erase_rect
.y
= position
;
270 erase_rect
.height
= SASH_FULL_SIZE
;
271 erase_rect
.width
= w
;
274 // we must erase everything first, otherwise the garbage from the old sash
275 // is left when dragging it
277 // TODO: is this the right way to draw themed background?
280 win
->m_wxwindow
->style
,
281 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
286 (char *)"base", // const_cast
296 win
->m_wxwindow
->style
,
297 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
298 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
300 NULL
/* no clipping */,
307 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
311 // leave some margin before sash itself
312 position
+= SASH_MARGIN
/ 2;
314 // and finally draw it using GTK paint functions
315 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
317 GdkRectangle
*, GtkWidget
*,
321 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
325 win
->m_wxwindow
->style
,
326 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
330 (char *)"paned", // const_cast
331 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
336 win
->m_wxwindow
->style
,
337 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
340 (GdkRectangle
*) NULL
,
342 (char *)"paned", // const_cast
343 isVert
? position
: size
.x
- 2*SASH_SIZE
,
344 isVert
? size
.y
- 2*SASH_SIZE
: position
,
347 #endif // GTK+ 2.x/1.x
350 void wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
355 dc
.SetBrush(wxBrush(win
->GetBackgroundColour()));
356 dc
.SetPen(wxPen(win
->GetBackgroundColour()));
357 dc
.DrawRectangle(rect
);
359 int x
= (rect
.GetWidth()-9) / 2;
360 int y
= (rect
.GetHeight()-10) / 2;
372 dc
.SetBrush(wxBrush(win
->GetForegroundColour()));
373 dc
.SetPen(wxPen(win
->GetForegroundColour()));
374 dc
.DrawLine(x
, y
, x
+9, y
);
375 dc
.DrawPolygon(WXSIZEOF(pt
), pt
, rect
.x
, rect
.y
);