]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/renderer.cpp
Eliminate a warning
[wxWidgets.git] / src / gtk1 / renderer.cpp
CommitLineData
9c7f49f5 1///////////////////////////////////////////////////////////////////////////////
cdccdfab 2// Name: src/gtk1/renderer.cpp
38c4cb6a 3// Purpose: implementation of wxRendererNative for wxGTK
9c7f49f5
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 20.07.2003
7// RCS-ID: $Id$
8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
65571936 9// License: wxWindows licence
9c7f49f5
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
e1bf3ad3 27#include "wx/renderer.h"
cdccdfab
WS
28
29#ifndef WX_PRECOMP
30 #include "wx/window.h"
da80ae71 31 #include "wx/dc.h"
cdccdfab
WS
32#endif
33
9c7f49f5 34#include <gtk/gtk.h>
3cbab641 35#include "wx/gtk1/win_gtk.h"
10d30222 36#include "wx/gtk1/dcclient.h"
9c7f49f5 37
91af0895
WS
38// RR: After a correction to the orientation of the sash
39// this doesn't seem to be required anymore and it
40// seems to confuse some themes so USE_ERASE_RECT=0
41#define USE_ERASE_RECT 0
42
9c7f49f5 43// ----------------------------------------------------------------------------
38c4cb6a 44// wxRendererGTK: our wxRendererNative implementation
9c7f49f5
VZ
45// ----------------------------------------------------------------------------
46
38c4cb6a 47class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative
9c7f49f5
VZ
48{
49public:
50 // draw the header control button (used by wxListCtrl)
51 virtual void DrawHeaderButton(wxWindow *win,
52 wxDC& dc,
53 const wxRect& rect,
54 int flags = 0);
55
d16cf3cd
VZ
56 virtual void DrawSplitterBorder(wxWindow *win,
57 wxDC& dc,
af99040c
VZ
58 const wxRect& rect,
59 int flags = 0);
95155e75
VZ
60 virtual void DrawSplitterSash(wxWindow *win,
61 wxDC& dc,
62 const wxSize& size,
d16cf3cd 63 wxCoord position,
af99040c
VZ
64 wxOrientation orient,
65 int flags = 0);
d16cf3cd 66
38511687
VZ
67 virtual void DrawComboBoxDropButton(wxWindow *win,
68 wxDC& dc,
69 const wxRect& rect,
70 int flags = 0);
71
4c85ab75
VZ
72 virtual void DrawDropArrow(wxWindow *win,
73 wxDC& dc,
74 const wxRect& rect,
75 int flags = 0);
76
af99040c 77 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
e1befae3
VZ
78
79private:
bc13e772
VZ
80 // FIXME: shouldn't we destroy these windows somewhere?
81
e1befae3 82 // used by DrawHeaderButton and DrawComboBoxDropButton
bc13e772 83 static GtkWidget *GetButtonWidget();
9c7f49f5
VZ
84};
85
86// ============================================================================
87// implementation
88// ============================================================================
89
90/* static */
f0244295 91wxRendererNative& wxRendererNative::GetDefault()
9c7f49f5
VZ
92{
93 static wxRendererGTK s_rendererGTK;
94
95 return s_rendererGTK;
96}
97
a4622f29 98// ----------------------------------------------------------------------------
bc13e772 99// helper functions
a4622f29
VZ
100// ----------------------------------------------------------------------------
101
bc13e772
VZ
102GtkWidget *
103wxRendererGTK::GetButtonWidget()
104{
105 static GtkWidget *s_button = NULL;
106 static GtkWidget *s_window = NULL;
a4622f29 107
bc13e772
VZ
108 if ( !s_button )
109 {
110 s_window = gtk_window_new( GTK_WINDOW_POPUP );
111 gtk_widget_realize( s_window );
112 s_button = gtk_button_new();
113 gtk_container_add( GTK_CONTAINER(s_window), s_button );
114 gtk_widget_realize( s_button );
115 }
116
117 return s_button;
118}
119
d16cf3cd
VZ
120// ----------------------------------------------------------------------------
121// list/tree controls drawing
122// ----------------------------------------------------------------------------
123
9c7f49f5
VZ
124void
125wxRendererGTK::DrawHeaderButton(wxWindow *win,
126 wxDC& dc,
127 const wxRect& rect,
128 int flags)
129{
9b311923 130
bc13e772 131 GtkWidget *button = GetButtonWidget();
9b311923 132
9c7f49f5
VZ
133 gtk_paint_box
134 (
bc13e772 135 button->style,
a4622f29
VZ
136 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
137 // Maybe use code similar as in DrawComboBoxDropButton below?
9c7f49f5
VZ
138 GTK_PIZZA(win->m_wxwindow)->bin_window,
139 flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
140 GTK_SHADOW_OUT,
38511687 141 NULL,
bc13e772 142 button,
9b311923 143 "button",
10d30222 144 dc.LogicalToDeviceX(rect.x) -1, rect.y -1, rect.width +2, rect.height +2
9c7f49f5
VZ
145 );
146}
147
d16cf3cd
VZ
148// ----------------------------------------------------------------------------
149// splitter sash drawing
150// ----------------------------------------------------------------------------
151
3cbab641
MR
152// the full sash width (should be even)
153static const wxCoord SASH_SIZE = 8;
af99040c 154
3cbab641
MR
155// margin around the sash
156static const wxCoord SASH_MARGIN = 2;
d16cf3cd 157
38418827
RR
158static int GetGtkSplitterFullSize()
159{
38418827 160 return SASH_SIZE + SASH_MARGIN;
38418827
RR
161}
162
af99040c 163wxSplitterRenderParams
38418827 164wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win))
d16cf3cd 165{
af99040c
VZ
166 // we don't draw any border, hence 0 for the second field
167 return wxSplitterRenderParams
168 (
38418827 169 GetGtkSplitterFullSize(),
af99040c 170 0,
af99040c 171 false // not
af99040c 172 );
d16cf3cd
VZ
173}
174
175void
176wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win),
177 wxDC& WXUNUSED(dc),
af99040c
VZ
178 const wxRect& WXUNUSED(rect),
179 int WXUNUSED(flags))
d16cf3cd
VZ
180{
181 // nothing to do
182}
95155e75 183
95155e75
VZ
184void
185wxRendererGTK::DrawSplitterSash(wxWindow *win,
89954433 186 wxDC& WXUNUSED(dc),
95155e75 187 const wxSize& size,
d16cf3cd 188 wxCoord position,
af99040c 189 wxOrientation orient,
3cbab641 190 int WXUNUSED(flags))
95155e75
VZ
191{
192 if ( !win->m_wxwindow->window )
193 {
0100b858 194 // window not realized yet
95155e75
VZ
195 return;
196 }
91af0895 197
38418827 198 wxCoord full_size = GetGtkSplitterFullSize();
95155e75 199
d16cf3cd
VZ
200 // are we drawing vertical or horizontal splitter?
201 const bool isVert = orient == wxVERTICAL;
202
d16cf3cd 203 GdkRectangle rect;
91af0895 204#if USE_ERASE_RECT
35468934 205 GdkRectangle erase_rect;
91af0895
WS
206#endif
207
d16cf3cd
VZ
208 if ( isVert )
209 {
0100b858 210 int h = win->GetClientSize().GetHeight();
e1befae3 211
d16cf3cd 212 rect.x = position;
0100b858 213 rect.y = 0;
38418827 214 rect.width = full_size;
0100b858 215 rect.height = h;
e1befae3 216
91af0895 217#if USE_ERASE_RECT
35468934
RR
218 erase_rect.x = position;
219 erase_rect.y = 0;
38418827 220 erase_rect.width = full_size;
35468934 221 erase_rect.height = h;
91af0895 222#endif
d16cf3cd
VZ
223 }
224 else // horz
225 {
0100b858 226 int w = win->GetClientSize().GetWidth();
e1befae3 227
0100b858 228 rect.x = 0;
d16cf3cd 229 rect.y = position;
38418827 230 rect.height = full_size;
0100b858 231 rect.width = w;
e1befae3 232
91af0895 233#if USE_ERASE_RECT
35468934
RR
234 erase_rect.y = position;
235 erase_rect.x = 0;
38418827 236 erase_rect.height = full_size;
35468934 237 erase_rect.width = w;
91af0895 238#endif
d16cf3cd
VZ
239 }
240
91af0895 241#if USE_ERASE_RECT
ab5ea030
RR
242 // we must erase everything first, otherwise the garbage
243 // from the old sash is left when dragging it
35468934
RR
244 gtk_paint_flat_box
245 (
246 win->m_wxwindow->style,
247 GTK_PIZZA(win->m_wxwindow)->bin_window,
248 GTK_STATE_NORMAL,
249 GTK_SHADOW_NONE,
250 NULL,
251 win->m_wxwindow,
ab5ea030 252 (char *)"viewportbin", // const_cast
35468934
RR
253 erase_rect.x,
254 erase_rect.y,
255 erase_rect.width,
256 erase_rect.height
257 );
ab5ea030 258#endif
35468934 259
d16cf3cd
VZ
260
261 // leave some margin before sash itself
262 position += SASH_MARGIN / 2;
263
264 // and finally draw it using GTK paint functions
265 typedef void (*GtkPaintLineFunc)(GtkStyle *, GdkWindow *,
266 GtkStateType,
267 GdkRectangle *, GtkWidget *,
ef9bfb71 268 gchar *,
ef9bfb71 269 gint, gint, gint);
d16cf3cd
VZ
270
271 GtkPaintLineFunc func = isVert ? gtk_paint_vline : gtk_paint_hline;
272
273 (*func)
95155e75
VZ
274 (
275 win->m_wxwindow->style,
d16cf3cd 276 GTK_PIZZA(win->m_wxwindow)->bin_window,
95155e75 277 GTK_STATE_NORMAL,
d16cf3cd 278 NULL,
95155e75 279 win->m_wxwindow,
d16cf3cd
VZ
280 (char *)"paned", // const_cast
281 0, isVert ? size.y : size.x, position + SASH_SIZE / 2 - 1
95155e75
VZ
282 );
283
284 gtk_paint_box
285 (
286 win->m_wxwindow->style,
d16cf3cd 287 GTK_PIZZA(win->m_wxwindow)->bin_window,
95155e75
VZ
288 GTK_STATE_NORMAL,
289 GTK_SHADOW_OUT,
d16cf3cd 290 (GdkRectangle*) NULL,
95155e75
VZ
291 win->m_wxwindow,
292 (char *)"paned", // const_cast
d16cf3cd
VZ
293 isVert ? position : size.x - 2*SASH_SIZE,
294 isVert ? size.y - 2*SASH_SIZE : position,
295 SASH_SIZE, SASH_SIZE
95155e75
VZ
296 );
297}
298
4c85ab75 299void
89954433 300wxRendererGTK::DrawDropArrow(wxWindow *WXUNUSED(win),
4c85ab75
VZ
301 wxDC& dc,
302 const wxRect& rect,
303 int flags)
38511687 304{
bc13e772 305 GtkWidget *button = GetButtonWidget();
38511687 306
4c85ab75
VZ
307 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
308 // a window for gtk_paint_xxx function, then it won't
309 // work for wxMemoryDC. So that is why we assume wxDC
310 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
311 // are derived from it) and use its m_window.
10d30222
VZ
312 wxWindowDCImpl * const impl = wxDynamicCast(dc.GetImpl(), wxWindowDCImpl);
313 wxCHECK_RET( impl, "must have a window DC" );
314
315 GdkWindow* gdk_window = impl->GetGDKWindow();
a4622f29 316
4c85ab75
VZ
317 // draw arrow so that there is even space horizontally
318 // on both sides
319 int arrowX = rect.width/4 + 1;
320 int arrowWidth = rect.width - (arrowX*2);
321
322 // scale arrow's height accoording to the width
323 int arrowHeight = rect.width/3;
324 int arrowY = (rect.height-arrowHeight)/2 +
325 ((rect.height-arrowHeight) & 1);
326
e1befae3 327 GtkStateType state;
a4622f29 328
3203621a
JS
329 if ( flags & wxCONTROL_PRESSED )
330 state = GTK_STATE_ACTIVE;
a4622f29
VZ
331 else if ( flags & wxCONTROL_DISABLED )
332 state = GTK_STATE_INSENSITIVE;
3203621a
JS
333 else if ( flags & wxCONTROL_CURRENT )
334 state = GTK_STATE_PRELIGHT;
e1befae3
VZ
335 else
336 state = GTK_STATE_NORMAL;
a4622f29 337
a4622f29 338 // draw arrow on button
a4622f29
VZ
339 gtk_paint_arrow
340 (
bc13e772 341 button->style,
2e992e06 342 gdk_window,
a4622f29 343 state,
e1befae3 344 flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
a4622f29 345 NULL,
bc13e772 346 button,
a4622f29
VZ
347 "arrow",
348 GTK_ARROW_DOWN,
a8ac548e 349 FALSE,
4c85ab75
VZ
350 rect.x + arrowX,
351 rect.y + arrowY,
352 arrowWidth,
353 arrowHeight
a4622f29 354 );
38511687
VZ
355}
356
4c85ab75
VZ
357void
358wxRendererGTK::DrawComboBoxDropButton(wxWindow *win,
359 wxDC& dc,
360 const wxRect& rect,
361 int flags)
362{
363 GtkWidget *button = GetButtonWidget();
364
365 // for reason why we do this, see DrawDropArrow
10d30222
VZ
366 wxWindowDCImpl * const impl = wxDynamicCast(dc.GetImpl(), wxWindowDCImpl);
367 wxCHECK_RET( impl, "must have a window DC" );
368
369 GdkWindow* gdk_window = impl->GetGDKWindow();
4c85ab75
VZ
370
371 // draw button
372 GtkStateType state;
373
3203621a
JS
374 if ( flags & wxCONTROL_PRESSED )
375 state = GTK_STATE_ACTIVE;
4c85ab75
VZ
376 else if ( flags & wxCONTROL_DISABLED )
377 state = GTK_STATE_INSENSITIVE;
3203621a
JS
378 else if ( flags & wxCONTROL_CURRENT )
379 state = GTK_STATE_PRELIGHT;
4c85ab75
VZ
380 else
381 state = GTK_STATE_NORMAL;
382
383 gtk_paint_box
384 (
385 button->style,
2e992e06 386 gdk_window,
4c85ab75
VZ
387 state,
388 flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
389 NULL,
390 button,
391 "button",
392 rect.x, rect.y, rect.width, rect.height
393 );
394
395 // draw arrow on button
396 DrawDropArrow(win,dc,rect,flags);
397
398}