]>
Commit | Line | Data |
---|---|---|
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" |
9c7f49f5 | 34 | |
3dd570e5 VZ |
35 | #ifdef __WXGTK20__ |
36 | #include "wx/settings.h" | |
37 | #endif // GTK 2.0 | |
38 | ||
af99040c VZ |
39 | #ifdef __WXGTK20__ |
40 | #define WXUNUSED_IN_GTK1(arg) arg | |
41 | #else | |
42 | #define WXUNUSED_IN_GTK1(arg) | |
43 | #endif | |
44 | ||
9c7f49f5 | 45 | // ---------------------------------------------------------------------------- |
38c4cb6a | 46 | // wxRendererGTK: our wxRendererNative implementation |
9c7f49f5 VZ |
47 | // ---------------------------------------------------------------------------- |
48 | ||
38c4cb6a | 49 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
9c7f49f5 VZ |
50 | { |
51 | public: | |
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); | |
e1befae3 | 64 | #endif // GTK+ 2.0 |
9c7f49f5 | 65 | |
d16cf3cd VZ |
66 | virtual void DrawSplitterBorder(wxWindow *win, |
67 | wxDC& dc, | |
af99040c VZ |
68 | const wxRect& rect, |
69 | int flags = 0); | |
95155e75 VZ |
70 | virtual void DrawSplitterSash(wxWindow *win, |
71 | wxDC& dc, | |
72 | const wxSize& size, | |
d16cf3cd | 73 | wxCoord position, |
af99040c VZ |
74 | wxOrientation orient, |
75 | int flags = 0); | |
d16cf3cd | 76 | |
38511687 VZ |
77 | virtual void DrawComboBoxDropButton(wxWindow *win, |
78 | wxDC& dc, | |
79 | const wxRect& rect, | |
80 | int flags = 0); | |
81 | ||
af99040c | 82 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
e1befae3 VZ |
83 | |
84 | private: | |
bc13e772 VZ |
85 | // FIXME: shouldn't we destroy these windows somewhere? |
86 | ||
e1befae3 | 87 | // used by DrawHeaderButton and DrawComboBoxDropButton |
bc13e772 VZ |
88 | static GtkWidget *GetButtonWidget(); |
89 | ||
90 | #ifdef __WXGTK20__ | |
91 | // used by DrawTreeItemButton() | |
92 | static GtkWidget *GetTreeWidget(); | |
93 | #endif // GTK+ 2.0 | |
9c7f49f5 VZ |
94 | }; |
95 | ||
96 | // ============================================================================ | |
97 | // implementation | |
98 | // ============================================================================ | |
99 | ||
100 | /* static */ | |
f0244295 | 101 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
102 | { |
103 | static wxRendererGTK s_rendererGTK; | |
104 | ||
105 | return s_rendererGTK; | |
106 | } | |
107 | ||
a4622f29 | 108 | // ---------------------------------------------------------------------------- |
bc13e772 | 109 | // helper functions |
a4622f29 VZ |
110 | // ---------------------------------------------------------------------------- |
111 | ||
bc13e772 VZ |
112 | GtkWidget * |
113 | wxRendererGTK::GetButtonWidget() | |
114 | { | |
115 | static GtkWidget *s_button = NULL; | |
116 | static GtkWidget *s_window = NULL; | |
a4622f29 | 117 | |
bc13e772 VZ |
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 | ||
132 | GtkWidget * | |
133 | wxRendererGTK::GetTreeWidget() | |
a4622f29 | 134 | { |
bc13e772 VZ |
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; | |
a4622f29 VZ |
148 | } |
149 | ||
bc13e772 VZ |
150 | #endif // GTK+ 2.0 |
151 | ||
d16cf3cd VZ |
152 | // ---------------------------------------------------------------------------- |
153 | // list/tree controls drawing | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
9c7f49f5 VZ |
156 | void |
157 | wxRendererGTK::DrawHeaderButton(wxWindow *win, | |
158 | wxDC& dc, | |
159 | const wxRect& rect, | |
160 | int flags) | |
161 | { | |
9b311923 | 162 | |
bc13e772 | 163 | GtkWidget *button = GetButtonWidget(); |
9b311923 | 164 | |
9c7f49f5 VZ |
165 | gtk_paint_box |
166 | ( | |
bc13e772 | 167 | button->style, |
a4622f29 VZ |
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? | |
9c7f49f5 VZ |
170 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
171 | flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, | |
172 | GTK_SHADOW_OUT, | |
38511687 | 173 | NULL, |
bc13e772 | 174 | button, |
9b311923 RR |
175 | "button", |
176 | dc.XLOG2DEV(rect.x) -1, rect.y -1, rect.width +2, rect.height +2 | |
9c7f49f5 VZ |
177 | ); |
178 | } | |
179 | ||
180 | #ifdef __WXGTK20__ | |
181 | ||
182 | // draw a ">" or "v" button | |
9c7f49f5 | 183 | void |
f8b043e7 | 184 | wxRendererGTK::DrawTreeItemButton(wxWindow* win, |
9a0b7e33 | 185 | wxDC& dc, const wxRect& rect, int flags) |
9c7f49f5 | 186 | { |
bc13e772 | 187 | GtkWidget *tree = GetTreeWidget(); |
f8b043e7 | 188 | |
885dd597 RR |
189 | GtkStateType state; |
190 | if ( flags & wxCONTROL_CURRENT ) | |
191 | state = GTK_STATE_PRELIGHT; | |
192 | else | |
193 | state = GTK_STATE_NORMAL; | |
194 | ||
bc13e772 VZ |
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, | |
885dd597 | 201 | state, |
bc13e772 VZ |
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 | ); | |
9c7f49f5 VZ |
210 | } |
211 | ||
bc13e772 | 212 | #endif // GTK+ 2.0 |
9c7f49f5 | 213 | |
d16cf3cd VZ |
214 | // ---------------------------------------------------------------------------- |
215 | // splitter sash drawing | |
216 | // ---------------------------------------------------------------------------- | |
217 | ||
af99040c VZ |
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) | |
35468934 | 224 | static const wxCoord SASH_SIZE = 8; |
af99040c VZ |
225 | |
226 | // margin around the sash | |
35468934 | 227 | static const wxCoord SASH_MARGIN = 2; |
d16cf3cd | 228 | |
af99040c VZ |
229 | // the full sash size |
230 | static const wxCoord SASH_FULL_SIZE = SASH_SIZE + SASH_MARGIN; | |
231 | #endif // GTK+ 2.x/1.x | |
d16cf3cd | 232 | |
af99040c VZ |
233 | wxSplitterRenderParams |
234 | wxRendererGTK::GetSplitterParams(const wxWindow * WXUNUSED(win)) | |
d16cf3cd | 235 | { |
af99040c VZ |
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 | ); | |
d16cf3cd VZ |
247 | } |
248 | ||
249 | void | |
250 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
251 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
252 | const wxRect& WXUNUSED(rect), |
253 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
254 | { |
255 | // nothing to do | |
256 | } | |
95155e75 | 257 | |
95155e75 VZ |
258 | void |
259 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
260 | wxDC& dc, | |
261 | const wxSize& size, | |
d16cf3cd | 262 | wxCoord position, |
af99040c VZ |
263 | wxOrientation orient, |
264 | int WXUNUSED_IN_GTK1(flags)) | |
95155e75 VZ |
265 | { |
266 | if ( !win->m_wxwindow->window ) | |
267 | { | |
0100b858 | 268 | // window not realized yet |
95155e75 VZ |
269 | return; |
270 | } | |
271 | ||
d16cf3cd VZ |
272 | // are we drawing vertical or horizontal splitter? |
273 | const bool isVert = orient == wxVERTICAL; | |
274 | ||
d16cf3cd | 275 | GdkRectangle rect; |
35468934 | 276 | GdkRectangle erase_rect; |
d16cf3cd VZ |
277 | if ( isVert ) |
278 | { | |
0100b858 | 279 | int h = win->GetClientSize().GetHeight(); |
e1befae3 | 280 | |
d16cf3cd | 281 | rect.x = position; |
0100b858 | 282 | rect.y = 0; |
af99040c | 283 | rect.width = SASH_FULL_SIZE; |
0100b858 | 284 | rect.height = h; |
e1befae3 | 285 | |
35468934 RR |
286 | erase_rect.x = position; |
287 | erase_rect.y = 0; | |
288 | erase_rect.width = SASH_FULL_SIZE; | |
289 | erase_rect.height = h; | |
d16cf3cd VZ |
290 | } |
291 | else // horz | |
292 | { | |
0100b858 | 293 | int w = win->GetClientSize().GetWidth(); |
e1befae3 | 294 | |
0100b858 | 295 | rect.x = 0; |
d16cf3cd | 296 | rect.y = position; |
af99040c | 297 | rect.height = SASH_FULL_SIZE; |
0100b858 | 298 | rect.width = w; |
e1befae3 | 299 | |
35468934 RR |
300 | erase_rect.y = position; |
301 | erase_rect.x = 0; | |
302 | erase_rect.height = SASH_FULL_SIZE; | |
303 | erase_rect.width = w; | |
d16cf3cd VZ |
304 | } |
305 | ||
35468934 RR |
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 | ||
af99040c VZ |
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, | |
6de9d616 | 339 | !isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c VZ |
340 | ); |
341 | #else // GTK+ 1.x | |
d16cf3cd VZ |
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 *, | |
ef9bfb71 | 350 | gchar *, |
ef9bfb71 | 351 | gint, gint, gint); |
d16cf3cd VZ |
352 | |
353 | GtkPaintLineFunc func = isVert ? gtk_paint_vline : gtk_paint_hline; | |
354 | ||
355 | (*func) | |
95155e75 VZ |
356 | ( |
357 | win->m_wxwindow->style, | |
d16cf3cd | 358 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 | 359 | GTK_STATE_NORMAL, |
d16cf3cd | 360 | NULL, |
95155e75 | 361 | win->m_wxwindow, |
d16cf3cd VZ |
362 | (char *)"paned", // const_cast |
363 | 0, isVert ? size.y : size.x, position + SASH_SIZE / 2 - 1 | |
95155e75 VZ |
364 | ); |
365 | ||
366 | gtk_paint_box | |
367 | ( | |
368 | win->m_wxwindow->style, | |
d16cf3cd | 369 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 VZ |
370 | GTK_STATE_NORMAL, |
371 | GTK_SHADOW_OUT, | |
d16cf3cd | 372 | (GdkRectangle*) NULL, |
95155e75 VZ |
373 | win->m_wxwindow, |
374 | (char *)"paned", // const_cast | |
d16cf3cd VZ |
375 | isVert ? position : size.x - 2*SASH_SIZE, |
376 | isVert ? size.y - 2*SASH_SIZE : position, | |
377 | SASH_SIZE, SASH_SIZE | |
95155e75 | 378 | ); |
af99040c | 379 | #endif // GTK+ 2.x/1.x |
95155e75 VZ |
380 | } |
381 | ||
38511687 VZ |
382 | void wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, |
383 | wxDC& dc, | |
384 | const wxRect& rect, | |
385 | int flags) | |
386 | { | |
bc13e772 | 387 | GtkWidget *button = GetButtonWidget(); |
38511687 | 388 | |
a4622f29 VZ |
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 | ||
e1befae3 | 396 | GtkStateType state; |
a4622f29 | 397 | |
e1befae3 | 398 | if ( flags & wxCONTROL_CURRENT ) |
a4622f29 VZ |
399 | state = GTK_STATE_PRELIGHT; |
400 | else if ( flags & wxCONTROL_DISABLED ) | |
401 | state = GTK_STATE_INSENSITIVE; | |
e1befae3 VZ |
402 | else |
403 | state = GTK_STATE_NORMAL; | |
a4622f29 | 404 | |
a4622f29 | 405 | // draw arrow on button |
a4622f29 VZ |
406 | gtk_paint_arrow |
407 | ( | |
bc13e772 | 408 | button->style, |
a4622f29 VZ |
409 | wdc.m_window, |
410 | state, | |
e1befae3 | 411 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 412 | NULL, |
bc13e772 | 413 | button, |
a4622f29 VZ |
414 | "arrow", |
415 | GTK_ARROW_DOWN, | |
a8ac548e | 416 | FALSE, |
e1befae3 | 417 | rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2 |
a4622f29 | 418 | ); |
38511687 VZ |
419 | } |
420 |