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