]>
Commit | Line | Data |
---|---|---|
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" |
ed4b0fdc | 32 | #include "wx/dcclient.h" |
cdccdfab WS |
33 | #endif |
34 | ||
9c7f49f5 | 35 | #include <gtk/gtk.h> |
3cbab641 | 36 | #include "wx/gtk1/win_gtk.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 | 47 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
9c7f49f5 VZ |
48 | { |
49 | public: | |
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 | |
79 | private: | |
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 | 91 | wxRendererNative& 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 |
102 | GtkWidget * |
103 | wxRendererGTK::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 |
124 | void |
125 | wxRendererGTK::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 RR |
143 | "button", |
144 | dc.XLOG2DEV(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) |
153 | static const wxCoord SASH_SIZE = 8; | |
af99040c | 154 | |
3cbab641 MR |
155 | // margin around the sash |
156 | static const wxCoord SASH_MARGIN = 2; | |
d16cf3cd | 157 | |
38418827 RR |
158 | static int GetGtkSplitterFullSize() |
159 | { | |
38418827 | 160 | return SASH_SIZE + SASH_MARGIN; |
38418827 RR |
161 | } |
162 | ||
af99040c | 163 | wxSplitterRenderParams |
38418827 | 164 | wxRendererGTK::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 | ||
175 | void | |
176 | wxRendererGTK::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 |
184 | void |
185 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
186 | wxDC& dc, | |
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 VZ |
299 | void |
300 | wxRendererGTK::DrawDropArrow(wxWindow *win, | |
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. | |
a4622f29 VZ |
312 | wxWindowDC& wdc = (wxWindowDC&)dc; |
313 | ||
4c85ab75 VZ |
314 | // only doing debug-time checking here (it should |
315 | // probably be enough) | |
a4622f29 VZ |
316 | wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) ); |
317 | ||
4c85ab75 VZ |
318 | // draw arrow so that there is even space horizontally |
319 | // on both sides | |
320 | int arrowX = rect.width/4 + 1; | |
321 | int arrowWidth = rect.width - (arrowX*2); | |
322 | ||
323 | // scale arrow's height accoording to the width | |
324 | int arrowHeight = rect.width/3; | |
325 | int arrowY = (rect.height-arrowHeight)/2 + | |
326 | ((rect.height-arrowHeight) & 1); | |
327 | ||
e1befae3 | 328 | GtkStateType state; |
a4622f29 | 329 | |
3203621a JS |
330 | if ( flags & wxCONTROL_PRESSED ) |
331 | state = GTK_STATE_ACTIVE; | |
a4622f29 VZ |
332 | else if ( flags & wxCONTROL_DISABLED ) |
333 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
334 | else if ( flags & wxCONTROL_CURRENT ) |
335 | state = GTK_STATE_PRELIGHT; | |
e1befae3 VZ |
336 | else |
337 | state = GTK_STATE_NORMAL; | |
a4622f29 | 338 | |
a4622f29 | 339 | // draw arrow on button |
a4622f29 VZ |
340 | gtk_paint_arrow |
341 | ( | |
bc13e772 | 342 | button->style, |
a4622f29 VZ |
343 | wdc.m_window, |
344 | state, | |
e1befae3 | 345 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 346 | NULL, |
bc13e772 | 347 | button, |
a4622f29 VZ |
348 | "arrow", |
349 | GTK_ARROW_DOWN, | |
a8ac548e | 350 | FALSE, |
4c85ab75 VZ |
351 | rect.x + arrowX, |
352 | rect.y + arrowY, | |
353 | arrowWidth, | |
354 | arrowHeight | |
a4622f29 | 355 | ); |
38511687 VZ |
356 | } |
357 | ||
4c85ab75 VZ |
358 | void |
359 | wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, | |
360 | wxDC& dc, | |
361 | const wxRect& rect, | |
362 | int flags) | |
363 | { | |
364 | GtkWidget *button = GetButtonWidget(); | |
365 | ||
366 | // for reason why we do this, see DrawDropArrow | |
367 | wxWindowDC& wdc = (wxWindowDC&)dc; | |
368 | wxASSERT ( wdc.IsKindOf(CLASSINFO(wxWindowDC)) ); | |
369 | ||
370 | // draw button | |
371 | GtkStateType state; | |
372 | ||
3203621a JS |
373 | if ( flags & wxCONTROL_PRESSED ) |
374 | state = GTK_STATE_ACTIVE; | |
4c85ab75 VZ |
375 | else if ( flags & wxCONTROL_DISABLED ) |
376 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
377 | else if ( flags & wxCONTROL_CURRENT ) |
378 | state = GTK_STATE_PRELIGHT; | |
4c85ab75 VZ |
379 | else |
380 | state = GTK_STATE_NORMAL; | |
381 | ||
382 | gtk_paint_box | |
383 | ( | |
384 | button->style, | |
385 | wdc.m_window, | |
386 | state, | |
387 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, | |
388 | NULL, | |
389 | button, | |
390 | "button", | |
391 | rect.x, rect.y, rect.width, rect.height | |
392 | ); | |
393 | ||
394 | // draw arrow on button | |
395 | DrawDropArrow(win,dc,rect,flags); | |
396 | ||
397 | } |