]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/renderer.cpp
fix for non precomp
[wxWidgets.git] / src / gtk / renderer.cpp
CommitLineData
9c7f49f5
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: gtk/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"
9c7f49f5
VZ
28#include <gtk/gtk.h>
29#include "wx/gtk/win_gtk.h"
30
38c4cb6a
VZ
31#include "wx/window.h"
32#include "wx/dc.h"
31059a74 33#include "wx/dcclient.h"
68567a96 34#include "wx/settings.h"
af99040c 35
91af0895
WS
36// RR: After a correction to the orientation of the sash
37// this doesn't seem to be required anymore and it
38// seems to confuse some themes so USE_ERASE_RECT=0
39#define USE_ERASE_RECT 0
40
9c7f49f5 41// ----------------------------------------------------------------------------
38c4cb6a 42// wxRendererGTK: our wxRendererNative implementation
9c7f49f5
VZ
43// ----------------------------------------------------------------------------
44
38c4cb6a 45class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative
9c7f49f5
VZ
46{
47public:
48 // draw the header control button (used by wxListCtrl)
49 virtual void DrawHeaderButton(wxWindow *win,
50 wxDC& dc,
51 const wxRect& rect,
52 int flags = 0);
53
9c7f49f5
VZ
54 // draw the expanded/collapsed icon for a tree control item
55 virtual void DrawTreeItemButton(wxWindow *win,
56 wxDC& dc,
57 const wxRect& rect,
58 int flags = 0);
9c7f49f5 59
d16cf3cd
VZ
60 virtual void DrawSplitterBorder(wxWindow *win,
61 wxDC& dc,
af99040c
VZ
62 const wxRect& rect,
63 int flags = 0);
95155e75
VZ
64 virtual void DrawSplitterSash(wxWindow *win,
65 wxDC& dc,
66 const wxSize& size,
d16cf3cd 67 wxCoord position,
af99040c
VZ
68 wxOrientation orient,
69 int flags = 0);
d16cf3cd 70
38511687
VZ
71 virtual void DrawComboBoxDropButton(wxWindow *win,
72 wxDC& dc,
73 const wxRect& rect,
74 int flags = 0);
75
4c85ab75
VZ
76 virtual void DrawDropArrow(wxWindow *win,
77 wxDC& dc,
78 const wxRect& rect,
79 int flags = 0);
80
af99040c 81 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
e1befae3
VZ
82
83private:
bc13e772
VZ
84 // FIXME: shouldn't we destroy these windows somewhere?
85
e1befae3 86 // used by DrawHeaderButton and DrawComboBoxDropButton
bc13e772
VZ
87 static GtkWidget *GetButtonWidget();
88
bc13e772
VZ
89 // used by DrawTreeItemButton()
90 static GtkWidget *GetTreeWidget();
9c7f49f5
VZ
91};
92
93// ============================================================================
94// implementation
95// ============================================================================
96
97/* static */
f0244295 98wxRendererNative& wxRendererNative::GetDefault()
9c7f49f5
VZ
99{
100 static wxRendererGTK s_rendererGTK;
101
102 return s_rendererGTK;
103}
104
a4622f29 105// ----------------------------------------------------------------------------
bc13e772 106// helper functions
a4622f29
VZ
107// ----------------------------------------------------------------------------
108
bc13e772
VZ
109GtkWidget *
110wxRendererGTK::GetButtonWidget()
111{
112 static GtkWidget *s_button = NULL;
113 static GtkWidget *s_window = NULL;
a4622f29 114
bc13e772
VZ
115 if ( !s_button )
116 {
117 s_window = gtk_window_new( GTK_WINDOW_POPUP );
118 gtk_widget_realize( s_window );
119 s_button = gtk_button_new();
120 gtk_container_add( GTK_CONTAINER(s_window), s_button );
121 gtk_widget_realize( s_button );
122 }
123
124 return s_button;
125}
126
bc13e772
VZ
127GtkWidget *
128wxRendererGTK::GetTreeWidget()
a4622f29 129{
bc13e772
VZ
130 static GtkWidget *s_tree = NULL;
131 static GtkWidget *s_window = NULL;
132
133 if ( !s_tree )
134 {
135 s_tree = gtk_tree_view_new();
136 s_window = gtk_window_new( GTK_WINDOW_POPUP );
137 gtk_widget_realize( s_window );
138 gtk_container_add( GTK_CONTAINER(s_window), s_tree );
139 gtk_widget_realize( s_tree );
140 }
141
142 return s_tree;
a4622f29
VZ
143}
144
d16cf3cd
VZ
145// ----------------------------------------------------------------------------
146// list/tree controls drawing
147// ----------------------------------------------------------------------------
148
9c7f49f5
VZ
149void
150wxRendererGTK::DrawHeaderButton(wxWindow *win,
151 wxDC& dc,
152 const wxRect& rect,
153 int flags)
154{
9b311923 155
bc13e772 156 GtkWidget *button = GetButtonWidget();
9b311923 157
9c7f49f5
VZ
158 gtk_paint_box
159 (
bc13e772 160 button->style,
a4622f29
VZ
161 // FIXME: I suppose GTK_PIZZA(win->m_wxwindow)->bin_window doesn't work with wxMemoryDC.
162 // Maybe use code similar as in DrawComboBoxDropButton below?
9c7f49f5
VZ
163 GTK_PIZZA(win->m_wxwindow)->bin_window,
164 flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL,
165 GTK_SHADOW_OUT,
38511687 166 NULL,
bc13e772 167 button,
9b311923
RR
168 "button",
169 dc.XLOG2DEV(rect.x) -1, rect.y -1, rect.width +2, rect.height +2
9c7f49f5
VZ
170 );
171}
172
9c7f49f5 173// draw a ">" or "v" button
9c7f49f5 174void
f8b043e7 175wxRendererGTK::DrawTreeItemButton(wxWindow* win,
9a0b7e33 176 wxDC& dc, const wxRect& rect, int flags)
9c7f49f5 177{
bc13e772 178 GtkWidget *tree = GetTreeWidget();
f8b043e7 179
885dd597
RR
180 GtkStateType state;
181 if ( flags & wxCONTROL_CURRENT )
182 state = GTK_STATE_PRELIGHT;
183 else
184 state = GTK_STATE_NORMAL;
91af0895 185
bc13e772
VZ
186 // VZ: I don't know how to get the size of the expander so as to centre it
187 // in the given rectangle, +2/3 below is just what looks good here...
188 gtk_paint_expander
189 (
190 tree->style,
191 GTK_PIZZA(win->m_wxwindow)->bin_window,
885dd597 192 state,
bc13e772
VZ
193 NULL,
194 tree,
195 "treeview",
196 dc.LogicalToDeviceX(rect.x) + 2,
197 dc.LogicalToDeviceY(rect.y) + 3,
198 flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED
199 : GTK_EXPANDER_COLLAPSED
200 );
9c7f49f5
VZ
201}
202
9c7f49f5 203
d16cf3cd
VZ
204// ----------------------------------------------------------------------------
205// splitter sash drawing
206// ----------------------------------------------------------------------------
207
38418827
RR
208static int GetGtkSplitterFullSize()
209{
38418827
RR
210 static GtkWidget *s_paned = NULL;
211 if (s_paned == NULL)
212 s_paned = gtk_vpaned_new();
213
214 gint handle_size;
215 gtk_widget_style_get (s_paned, "handle_size", &handle_size, NULL);
91af0895 216
38418827 217 return handle_size;
38418827
RR
218}
219
af99040c 220wxSplitterRenderParams
38418827 221wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win))
d16cf3cd 222{
af99040c
VZ
223 // we don't draw any border, hence 0 for the second field
224 return wxSplitterRenderParams
225 (
38418827 226 GetGtkSplitterFullSize(),
af99040c 227 0,
af99040c 228 true // hot sensitive
af99040c 229 );
d16cf3cd
VZ
230}
231
232void
233wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win),
234 wxDC& WXUNUSED(dc),
af99040c
VZ
235 const wxRect& WXUNUSED(rect),
236 int WXUNUSED(flags))
d16cf3cd
VZ
237{
238 // nothing to do
239}
95155e75 240
95155e75
VZ
241void
242wxRendererGTK::DrawSplitterSash(wxWindow *win,
243 wxDC& dc,
244 const wxSize& size,
d16cf3cd 245 wxCoord position,
af99040c 246 wxOrientation orient,
68567a96 247 int flags)
95155e75
VZ
248{
249 if ( !win->m_wxwindow->window )
250 {
0100b858 251 // window not realized yet
95155e75
VZ
252 return;
253 }
91af0895 254
38418827 255 wxCoord full_size = GetGtkSplitterFullSize();
95155e75 256
d16cf3cd
VZ
257 // are we drawing vertical or horizontal splitter?
258 const bool isVert = orient == wxVERTICAL;
259
d16cf3cd 260 GdkRectangle rect;
91af0895 261#if USE_ERASE_RECT
35468934 262 GdkRectangle erase_rect;
91af0895
WS
263#endif
264
d16cf3cd
VZ
265 if ( isVert )
266 {
0100b858 267 int h = win->GetClientSize().GetHeight();
e1befae3 268
d16cf3cd 269 rect.x = position;
0100b858 270 rect.y = 0;
38418827 271 rect.width = full_size;
0100b858 272 rect.height = h;
e1befae3 273
91af0895 274#if USE_ERASE_RECT
35468934
RR
275 erase_rect.x = position;
276 erase_rect.y = 0;
38418827 277 erase_rect.width = full_size;
35468934 278 erase_rect.height = h;
91af0895 279#endif
d16cf3cd
VZ
280 }
281 else // horz
282 {
0100b858 283 int w = win->GetClientSize().GetWidth();
e1befae3 284
0100b858 285 rect.x = 0;
d16cf3cd 286 rect.y = position;
38418827 287 rect.height = full_size;
0100b858 288 rect.width = w;
e1befae3 289
91af0895 290#if USE_ERASE_RECT
35468934
RR
291 erase_rect.y = position;
292 erase_rect.x = 0;
38418827 293 erase_rect.height = full_size;
35468934 294 erase_rect.width = w;
91af0895 295#endif
d16cf3cd
VZ
296 }
297
91af0895 298#if USE_ERASE_RECT
ab5ea030
RR
299 // we must erase everything first, otherwise the garbage
300 // from the old sash is left when dragging it
35468934
RR
301 gtk_paint_flat_box
302 (
303 win->m_wxwindow->style,
304 GTK_PIZZA(win->m_wxwindow)->bin_window,
305 GTK_STATE_NORMAL,
306 GTK_SHADOW_NONE,
307 NULL,
308 win->m_wxwindow,
ab5ea030 309 (char *)"viewportbin", // const_cast
35468934
RR
310 erase_rect.x,
311 erase_rect.y,
312 erase_rect.width,
313 erase_rect.height
314 );
ab5ea030 315#endif
35468934 316
af99040c
VZ
317 gtk_paint_handle
318 (
319 win->m_wxwindow->style,
320 GTK_PIZZA(win->m_wxwindow)->bin_window,
321 flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
322 GTK_SHADOW_NONE,
323 NULL /* no clipping */,
324 win->m_wxwindow,
325 "paned",
326 rect.x,
327 rect.y,
328 rect.width,
329 rect.height,
38418827 330 isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL
af99040c 331 );
95155e75
VZ
332}
333
4c85ab75
VZ
334void
335wxRendererGTK::DrawDropArrow(wxWindow *win,
336 wxDC& dc,
337 const wxRect& rect,
338 int flags)
38511687 339{
bc13e772 340 GtkWidget *button = GetButtonWidget();
38511687 341
4c85ab75
VZ
342 // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as
343 // a window for gtk_paint_xxx function, then it won't
344 // work for wxMemoryDC. So that is why we assume wxDC
345 // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC
346 // are derived from it) and use its m_window.
a4622f29
VZ
347 wxWindowDC& wdc = (wxWindowDC&)dc;
348
4c85ab75
VZ
349 // only doing debug-time checking here (it should
350 // probably be enough)
a4622f29
VZ
351 wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) );
352
4c85ab75
VZ
353 // draw arrow so that there is even space horizontally
354 // on both sides
355 int arrowX = rect.width/4 + 1;
356 int arrowWidth = rect.width - (arrowX*2);
357
358 // scale arrow's height accoording to the width
359 int arrowHeight = rect.width/3;
360 int arrowY = (rect.height-arrowHeight)/2 +
361 ((rect.height-arrowHeight) & 1);
362
e1befae3 363 GtkStateType state;
a4622f29 364
3203621a
JS
365 if ( flags & wxCONTROL_PRESSED )
366 state = GTK_STATE_ACTIVE;
a4622f29
VZ
367 else if ( flags & wxCONTROL_DISABLED )
368 state = GTK_STATE_INSENSITIVE;
3203621a
JS
369 else if ( flags & wxCONTROL_CURRENT )
370 state = GTK_STATE_PRELIGHT;
e1befae3
VZ
371 else
372 state = GTK_STATE_NORMAL;
a4622f29 373
a4622f29 374 // draw arrow on button
a4622f29
VZ
375 gtk_paint_arrow
376 (
bc13e772 377 button->style,
a4622f29
VZ
378 wdc.m_window,
379 state,
e1befae3 380 flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
a4622f29 381 NULL,
bc13e772 382 button,
a4622f29
VZ
383 "arrow",
384 GTK_ARROW_DOWN,
a8ac548e 385 FALSE,
4c85ab75
VZ
386 rect.x + arrowX,
387 rect.y + arrowY,
388 arrowWidth,
389 arrowHeight
a4622f29 390 );
38511687
VZ
391}
392
4c85ab75
VZ
393void
394wxRendererGTK::DrawComboBoxDropButton(wxWindow *win,
395 wxDC& dc,
396 const wxRect& rect,
397 int flags)
398{
399 GtkWidget *button = GetButtonWidget();
400
401 // for reason why we do this, see DrawDropArrow
402 wxWindowDC& wdc = (wxWindowDC&)dc;
403 wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) );
404
405 // draw button
406 GtkStateType state;
407
3203621a
JS
408 if ( flags & wxCONTROL_PRESSED )
409 state = GTK_STATE_ACTIVE;
4c85ab75
VZ
410 else if ( flags & wxCONTROL_DISABLED )
411 state = GTK_STATE_INSENSITIVE;
3203621a
JS
412 else if ( flags & wxCONTROL_CURRENT )
413 state = GTK_STATE_PRELIGHT;
4c85ab75
VZ
414 else
415 state = GTK_STATE_NORMAL;
416
417 gtk_paint_box
418 (
419 button->style,
420 wdc.m_window,
421 state,
422 flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
423 NULL,
424 button,
425 "button",
426 rect.x, rect.y, rect.width, rect.height
427 );
428
429 // draw arrow on button
430 DrawDropArrow(win,dc,rect,flags);
431
432}
433