]>
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 | |
bc13e772 VZ |
189 | // VZ: I don't know how to get the size of the expander so as to centre it |
190 | // in the given rectangle, +2/3 below is just what looks good here... | |
191 | gtk_paint_expander | |
192 | ( | |
193 | tree->style, | |
194 | GTK_PIZZA(win->m_wxwindow)->bin_window, | |
195 | GTK_STATE_NORMAL, | |
196 | NULL, | |
197 | tree, | |
198 | "treeview", | |
199 | dc.LogicalToDeviceX(rect.x) + 2, | |
200 | dc.LogicalToDeviceY(rect.y) + 3, | |
201 | flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED | |
202 | : GTK_EXPANDER_COLLAPSED | |
203 | ); | |
9c7f49f5 VZ |
204 | } |
205 | ||
bc13e772 | 206 | #endif // GTK+ 2.0 |
9c7f49f5 | 207 | |
d16cf3cd VZ |
208 | // ---------------------------------------------------------------------------- |
209 | // splitter sash drawing | |
210 | // ---------------------------------------------------------------------------- | |
211 | ||
af99040c VZ |
212 | // all this should probably be read from the current theme settings somehow? |
213 | #ifdef __WXGTK20__ | |
214 | // the full sash size | |
215 | static const wxCoord SASH_FULL_SIZE = 5; | |
216 | #else // GTK+ 1.x | |
217 | // the full sash width (should be even) | |
35468934 | 218 | static const wxCoord SASH_SIZE = 8; |
af99040c VZ |
219 | |
220 | // margin around the sash | |
35468934 | 221 | static const wxCoord SASH_MARGIN = 2; |
d16cf3cd | 222 | |
af99040c VZ |
223 | // the full sash size |
224 | static const wxCoord SASH_FULL_SIZE = SASH_SIZE + SASH_MARGIN; | |
225 | #endif // GTK+ 2.x/1.x | |
d16cf3cd | 226 | |
af99040c VZ |
227 | wxSplitterRenderParams |
228 | wxRendererGTK::GetSplitterParams(const wxWindow * WXUNUSED(win)) | |
d16cf3cd | 229 | { |
af99040c VZ |
230 | // we don't draw any border, hence 0 for the second field |
231 | return wxSplitterRenderParams | |
232 | ( | |
233 | SASH_FULL_SIZE, | |
234 | 0, | |
235 | #ifdef __WXGTK20__ | |
236 | true // hot sensitive | |
237 | #else // GTK+ 1.x | |
238 | false // not | |
239 | #endif // GTK+ 2.x/1.x | |
240 | ); | |
d16cf3cd VZ |
241 | } |
242 | ||
243 | void | |
244 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
245 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
246 | const wxRect& WXUNUSED(rect), |
247 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
248 | { |
249 | // nothing to do | |
250 | } | |
95155e75 | 251 | |
95155e75 VZ |
252 | void |
253 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
254 | wxDC& dc, | |
255 | const wxSize& size, | |
d16cf3cd | 256 | wxCoord position, |
af99040c VZ |
257 | wxOrientation orient, |
258 | int WXUNUSED_IN_GTK1(flags)) | |
95155e75 VZ |
259 | { |
260 | if ( !win->m_wxwindow->window ) | |
261 | { | |
0100b858 | 262 | // window not realized yet |
95155e75 VZ |
263 | return; |
264 | } | |
265 | ||
d16cf3cd VZ |
266 | // are we drawing vertical or horizontal splitter? |
267 | const bool isVert = orient == wxVERTICAL; | |
268 | ||
d16cf3cd | 269 | GdkRectangle rect; |
35468934 | 270 | GdkRectangle erase_rect; |
d16cf3cd VZ |
271 | if ( isVert ) |
272 | { | |
0100b858 | 273 | int h = win->GetClientSize().GetHeight(); |
e1befae3 | 274 | |
d16cf3cd | 275 | rect.x = position; |
0100b858 | 276 | rect.y = 0; |
af99040c | 277 | rect.width = SASH_FULL_SIZE; |
0100b858 | 278 | rect.height = h; |
e1befae3 | 279 | |
35468934 RR |
280 | erase_rect.x = position; |
281 | erase_rect.y = 0; | |
282 | erase_rect.width = SASH_FULL_SIZE; | |
283 | erase_rect.height = h; | |
d16cf3cd VZ |
284 | } |
285 | else // horz | |
286 | { | |
0100b858 | 287 | int w = win->GetClientSize().GetWidth(); |
e1befae3 | 288 | |
0100b858 | 289 | rect.x = 0; |
d16cf3cd | 290 | rect.y = position; |
af99040c | 291 | rect.height = SASH_FULL_SIZE; |
0100b858 | 292 | rect.width = w; |
e1befae3 | 293 | |
35468934 RR |
294 | erase_rect.y = position; |
295 | erase_rect.x = 0; | |
296 | erase_rect.height = SASH_FULL_SIZE; | |
297 | erase_rect.width = w; | |
d16cf3cd VZ |
298 | } |
299 | ||
35468934 RR |
300 | // we must erase everything first, otherwise the garbage from the old sash |
301 | // is left when dragging it | |
302 | // | |
303 | // TODO: is this the right way to draw themed background? | |
304 | gtk_paint_flat_box | |
305 | ( | |
306 | win->m_wxwindow->style, | |
307 | GTK_PIZZA(win->m_wxwindow)->bin_window, | |
308 | GTK_STATE_NORMAL, | |
309 | GTK_SHADOW_NONE, | |
310 | NULL, | |
311 | win->m_wxwindow, | |
312 | (char *)"base", // const_cast | |
313 | erase_rect.x, | |
314 | erase_rect.y, | |
315 | erase_rect.width, | |
316 | erase_rect.height | |
317 | ); | |
318 | ||
af99040c VZ |
319 | #ifdef __WXGTK20__ |
320 | gtk_paint_handle | |
321 | ( | |
322 | win->m_wxwindow->style, | |
323 | GTK_PIZZA(win->m_wxwindow)->bin_window, | |
324 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, | |
325 | GTK_SHADOW_NONE, | |
326 | NULL /* no clipping */, | |
327 | win->m_wxwindow, | |
328 | "paned", | |
329 | rect.x, | |
330 | rect.y, | |
331 | rect.width, | |
332 | rect.height, | |
6de9d616 | 333 | !isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c VZ |
334 | ); |
335 | #else // GTK+ 1.x | |
d16cf3cd VZ |
336 | |
337 | // leave some margin before sash itself | |
338 | position += SASH_MARGIN / 2; | |
339 | ||
340 | // and finally draw it using GTK paint functions | |
341 | typedef void (*GtkPaintLineFunc)(GtkStyle *, GdkWindow *, | |
342 | GtkStateType, | |
343 | GdkRectangle *, GtkWidget *, | |
ef9bfb71 | 344 | gchar *, |
ef9bfb71 | 345 | gint, gint, gint); |
d16cf3cd VZ |
346 | |
347 | GtkPaintLineFunc func = isVert ? gtk_paint_vline : gtk_paint_hline; | |
348 | ||
349 | (*func) | |
95155e75 VZ |
350 | ( |
351 | win->m_wxwindow->style, | |
d16cf3cd | 352 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 | 353 | GTK_STATE_NORMAL, |
d16cf3cd | 354 | NULL, |
95155e75 | 355 | win->m_wxwindow, |
d16cf3cd VZ |
356 | (char *)"paned", // const_cast |
357 | 0, isVert ? size.y : size.x, position + SASH_SIZE / 2 - 1 | |
95155e75 VZ |
358 | ); |
359 | ||
360 | gtk_paint_box | |
361 | ( | |
362 | win->m_wxwindow->style, | |
d16cf3cd | 363 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 VZ |
364 | GTK_STATE_NORMAL, |
365 | GTK_SHADOW_OUT, | |
d16cf3cd | 366 | (GdkRectangle*) NULL, |
95155e75 VZ |
367 | win->m_wxwindow, |
368 | (char *)"paned", // const_cast | |
d16cf3cd VZ |
369 | isVert ? position : size.x - 2*SASH_SIZE, |
370 | isVert ? size.y - 2*SASH_SIZE : position, | |
371 | SASH_SIZE, SASH_SIZE | |
95155e75 | 372 | ); |
af99040c | 373 | #endif // GTK+ 2.x/1.x |
95155e75 VZ |
374 | } |
375 | ||
38511687 VZ |
376 | void wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, |
377 | wxDC& dc, | |
378 | const wxRect& rect, | |
379 | int flags) | |
380 | { | |
bc13e772 | 381 | GtkWidget *button = GetButtonWidget(); |
38511687 | 382 | |
a4622f29 VZ |
383 | // device context must inherit from wxWindowDC |
384 | // (so it must be wxClientDC, wxMemoryDC or wxPaintDC) | |
385 | wxWindowDC& wdc = (wxWindowDC&)dc; | |
386 | ||
387 | // only doing debug-time checking here (it should probably be enough) | |
388 | wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) ); | |
389 | ||
e1befae3 | 390 | GtkStateType state; |
a4622f29 | 391 | |
e1befae3 | 392 | if ( flags & wxCONTROL_CURRENT ) |
a4622f29 VZ |
393 | state = GTK_STATE_PRELIGHT; |
394 | else if ( flags & wxCONTROL_DISABLED ) | |
395 | state = GTK_STATE_INSENSITIVE; | |
e1befae3 VZ |
396 | else |
397 | state = GTK_STATE_NORMAL; | |
a4622f29 | 398 | |
a4622f29 | 399 | // draw arrow on button |
a4622f29 VZ |
400 | gtk_paint_arrow |
401 | ( | |
bc13e772 | 402 | button->style, |
a4622f29 VZ |
403 | wdc.m_window, |
404 | state, | |
e1befae3 | 405 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 406 | NULL, |
bc13e772 | 407 | button, |
a4622f29 VZ |
408 | "arrow", |
409 | GTK_ARROW_DOWN, | |
a8ac548e | 410 | FALSE, |
e1befae3 | 411 | rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2 |
a4622f29 | 412 | ); |
38511687 VZ |
413 | } |
414 |