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
52 // used by DrawHeaderButton and DrawComboBoxDropButton
53 void PrepareButtonDraw();
55 // draw the header control button (used by wxListCtrl)
56 virtual void DrawHeaderButton(wxWindow
*win
,
62 // draw the expanded/collapsed icon for a tree control item
63 virtual void DrawTreeItemButton(wxWindow
*win
,
69 virtual void DrawSplitterBorder(wxWindow
*win
,
73 virtual void DrawSplitterSash(wxWindow
*win
,
80 virtual void DrawComboBoxDropButton(wxWindow
*win
,
85 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
88 // ============================================================================
90 // ============================================================================
93 wxRendererNative
& wxRendererNative::GetDefault()
95 static wxRendererGTK s_rendererGTK
;
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 static GtkWidget
*gs_button
= NULL
;
105 static GtkWidget
*gs_window
= NULL
;
108 wxRendererGTK::PrepareButtonDraw()
110 // prepares gs_button and gs_window which are used when
111 // drawing button based elements.
112 wxASSERT ( !gs_button
);
114 gs_window
= gtk_window_new( GTK_WINDOW_POPUP
);
115 gtk_widget_realize( gs_window
);
116 gs_button
= gtk_button_new();
117 gtk_container_add( GTK_CONTAINER(gs_window
), gs_button
);
118 gtk_widget_realize( gs_button
);
121 // ----------------------------------------------------------------------------
122 // list/tree controls drawing
123 // ----------------------------------------------------------------------------
126 wxRendererGTK::DrawHeaderButton(wxWindow
*win
,
132 if (gs_button
== NULL
)
138 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
139 // Maybe use code similar as in DrawComboBoxDropButton below?
140 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
141 flags
& wxCONTROL_DISABLED
? GTK_STATE_INSENSITIVE
: GTK_STATE_NORMAL
,
146 dc
.XLOG2DEV(rect
.x
) -1, rect
.y
-1, rect
.width
+2, rect
.height
+2
152 // draw a ">" or "v" button
154 // TODO: replace the code below with gtk_paint_expander()
156 wxRendererGTK::DrawTreeItemButton(wxWindow
* win
,
157 wxDC
& dc
, const wxRect
& rect
, int flags
)
161 GtkPizza
*pizza
= GTK_PIZZA( win
->m_wxwindow
);
162 GtkStyle
*style
= win
->m_widget
->style
;
165 y
= dc
.LogicalToDeviceY( y
);
166 x
= dc
.LogicalToDeviceX( x
);
168 // This draws the GTK+ 2.2.4 triangle
172 if ( flags
& wxCONTROL_EXPANDED
)
175 points
[0].y
= y
+ (PM_SIZE
+ 2) / 6;
176 points
[1].x
= points
[0].x
+ (PM_SIZE
+ 2);
177 points
[1].y
= points
[0].y
;
178 points
[2].x
= (points
[0].x
+ (PM_SIZE
+ 2) / 2);
179 points
[2].y
= y
+ 2 * (PM_SIZE
+ 2) / 3;
183 points
[0].x
= x
+ ((PM_SIZE
+ 2) / 6 + 2);
185 points
[1].x
= points
[0].x
;
186 points
[1].y
= points
[0].y
+ (PM_SIZE
+ 2);
187 points
[2].x
= (points
[0].x
+
188 (2 * (PM_SIZE
+ 2) / 3 - 1));
189 points
[2].y
= points
[0].y
+ (PM_SIZE
+ 2) / 2;
192 if ( flags
& wxCONTROL_CURRENT
)
193 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_PRELIGHT
], TRUE
, points
, 3);
195 gdk_draw_polygon( pizza
->bin_window
, style
->base_gc
[GTK_STATE_NORMAL
], TRUE
, points
, 3);
196 gdk_draw_polygon( pizza
->bin_window
, style
->fg_gc
[GTK_STATE_NORMAL
], FALSE
, points
, 3 );
201 // ----------------------------------------------------------------------------
202 // splitter sash drawing
203 // ----------------------------------------------------------------------------
205 // all this should probably be read from the current theme settings somehow?
207 // the full sash size
208 static const wxCoord SASH_FULL_SIZE
= 5;
210 // the full sash width (should be even)
211 static const wxCoord SASH_SIZE
= 8;
213 // margin around the sash
214 static const wxCoord SASH_MARGIN
= 2;
216 // the full sash size
217 static const wxCoord SASH_FULL_SIZE
= SASH_SIZE
+ SASH_MARGIN
;
218 #endif // GTK+ 2.x/1.x
220 wxSplitterRenderParams
221 wxRendererGTK::GetSplitterParams(const wxWindow
* WXUNUSED(win
))
223 // we don't draw any border, hence 0 for the second field
224 return wxSplitterRenderParams
229 true // hot sensitive
232 #endif // GTK+ 2.x/1.x
237 wxRendererGTK::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
239 const wxRect
& WXUNUSED(rect
),
246 wxRendererGTK::DrawSplitterSash(wxWindow
*win
,
250 wxOrientation orient
,
251 int WXUNUSED_IN_GTK1(flags
))
253 if ( !win
->m_wxwindow
->window
)
255 // window not realized yet
259 // are we drawing vertical or horizontal splitter?
260 const bool isVert
= orient
== wxVERTICAL
;
263 GdkRectangle erase_rect
;
266 int h
= win
->GetClientSize().GetHeight();
270 rect
.width
= SASH_FULL_SIZE
;
273 erase_rect
.x
= position
;
275 erase_rect
.width
= SASH_FULL_SIZE
;
276 erase_rect
.height
= h
;
280 int w
= win
->GetClientSize().GetWidth();
284 rect
.height
= SASH_FULL_SIZE
;
287 erase_rect
.y
= position
;
289 erase_rect
.height
= SASH_FULL_SIZE
;
290 erase_rect
.width
= w
;
293 // we must erase everything first, otherwise the garbage from the old sash
294 // is left when dragging it
296 // TODO: is this the right way to draw themed background?
299 win
->m_wxwindow
->style
,
300 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
305 (char *)"base", // const_cast
315 win
->m_wxwindow
->style
,
316 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
317 flags
& wxCONTROL_CURRENT
? GTK_STATE_PRELIGHT
: GTK_STATE_NORMAL
,
319 NULL
/* no clipping */,
326 !isVert
? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL
330 // leave some margin before sash itself
331 position
+= SASH_MARGIN
/ 2;
333 // and finally draw it using GTK paint functions
334 typedef void (*GtkPaintLineFunc
)(GtkStyle
*, GdkWindow
*,
336 GdkRectangle
*, GtkWidget
*,
340 GtkPaintLineFunc func
= isVert
? gtk_paint_vline
: gtk_paint_hline
;
344 win
->m_wxwindow
->style
,
345 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
349 (char *)"paned", // const_cast
350 0, isVert
? size
.y
: size
.x
, position
+ SASH_SIZE
/ 2 - 1
355 win
->m_wxwindow
->style
,
356 GTK_PIZZA(win
->m_wxwindow
)->bin_window
,
359 (GdkRectangle
*) NULL
,
361 (char *)"paned", // const_cast
362 isVert
? position
: size
.x
- 2*SASH_SIZE
,
363 isVert
? size
.y
- 2*SASH_SIZE
: position
,
366 #endif // GTK+ 2.x/1.x
369 void wxRendererGTK::DrawComboBoxDropButton(wxWindow
*win
,
374 if (gs_button
== NULL
)
377 // device context must inherit from wxWindowDC
378 // (so it must be wxClientDC, wxMemoryDC or wxPaintDC)
379 wxWindowDC
& wdc
= (wxWindowDC
&)dc
;
381 // only doing debug-time checking here (it should probably be enough)
382 wxASSERT ( wdc
.IsKindOf(CLASSINFO(wxWindowDC
)) );
384 GtkStateType state
= GTK_STATE_NORMAL
;
385 GtkShadowType shadow
= GTK_SHADOW_OUT
;
387 if ( flags
& wxCONTROL_PRESSED
)
388 shadow
= GTK_SHADOW_IN
;
389 else if ( flags
& wxCONTROL_CURRENT
)
390 state
= GTK_STATE_PRELIGHT
;
391 else if ( flags
& wxCONTROL_DISABLED
)
392 state
= GTK_STATE_INSENSITIVE
;
397 //GTK_PIZZA(wdc->m_window)->bin_window,
404 dc
.XLOG2DEV(rect
.x
), rect
.y
, rect
.width
, rect
.height
407 // draw arrow on button
409 int arr_wid
= rect
.width
/2;
410 int arr_hei
= rect
.height
/2;
411 arr_wid
+= arr_wid
& 1;
412 arr_hei
+= arr_hei
& 1;
417 //GTK_PIZZA(wdc->m_window)->bin_window,
426 dc
.XLOG2DEV(rect
.x
) + (rect
.width
/2-arr_wid
/2) + 1,
427 rect
.y
+ (rect
.height
/2-arr_hei
/2) + 1,