]>
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> | |
9 | // License: wxWindows license | |
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 | #ifndef WX_PRECOMP | |
28 | #endif // WX_PRECOMP | |
29 | ||
30 | #include <gtk/gtk.h> | |
31 | #include "wx/gtk/win_gtk.h" | |
32 | ||
38c4cb6a VZ |
33 | #include "wx/window.h" |
34 | #include "wx/dc.h" | |
9c7f49f5 VZ |
35 | #include "wx/renderer.h" |
36 | ||
3dd570e5 VZ |
37 | #ifdef __WXGTK20__ |
38 | #include "wx/settings.h" | |
39 | #endif // GTK 2.0 | |
40 | ||
af99040c VZ |
41 | #ifdef __WXGTK20__ |
42 | #define WXUNUSED_IN_GTK1(arg) arg | |
43 | #else | |
44 | #define WXUNUSED_IN_GTK1(arg) | |
45 | #endif | |
46 | ||
9c7f49f5 | 47 | // ---------------------------------------------------------------------------- |
38c4cb6a | 48 | // wxRendererGTK: our wxRendererNative implementation |
9c7f49f5 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | ||
38c4cb6a | 51 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
9c7f49f5 VZ |
52 | { |
53 | public: | |
54 | // draw the header control button (used by wxListCtrl) | |
55 | virtual void DrawHeaderButton(wxWindow *win, | |
56 | wxDC& dc, | |
57 | const wxRect& rect, | |
58 | int flags = 0); | |
59 | ||
60 | #ifdef __WXGTK20__ | |
61 | // draw the expanded/collapsed icon for a tree control item | |
62 | virtual void DrawTreeItemButton(wxWindow *win, | |
63 | wxDC& dc, | |
64 | const wxRect& rect, | |
65 | int flags = 0); | |
66 | #endif // GTK 2.0 | |
67 | ||
d16cf3cd VZ |
68 | virtual void DrawSplitterBorder(wxWindow *win, |
69 | wxDC& dc, | |
af99040c VZ |
70 | const wxRect& rect, |
71 | int flags = 0); | |
95155e75 VZ |
72 | virtual void DrawSplitterSash(wxWindow *win, |
73 | wxDC& dc, | |
74 | const wxSize& size, | |
d16cf3cd | 75 | wxCoord position, |
af99040c VZ |
76 | wxOrientation orient, |
77 | int flags = 0); | |
d16cf3cd | 78 | |
af99040c | 79 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
9c7f49f5 VZ |
80 | }; |
81 | ||
82 | // ============================================================================ | |
83 | // implementation | |
84 | // ============================================================================ | |
85 | ||
86 | /* static */ | |
f0244295 | 87 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
88 | { |
89 | static wxRendererGTK s_rendererGTK; | |
90 | ||
91 | return s_rendererGTK; | |
92 | } | |
93 | ||
d16cf3cd VZ |
94 | // ---------------------------------------------------------------------------- |
95 | // list/tree controls drawing | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
9c7f49f5 VZ |
98 | void |
99 | wxRendererGTK::DrawHeaderButton(wxWindow *win, | |
100 | wxDC& dc, | |
101 | const wxRect& rect, | |
102 | int flags) | |
103 | { | |
9b311923 RR |
104 | |
105 | static GtkWidget *s_button = NULL; | |
106 | static GtkWidget *s_window = NULL; | |
107 | if (s_button == NULL) | |
108 | { | |
109 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
110 | gtk_widget_realize( s_window ); | |
111 | s_button = gtk_button_new(); | |
112 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
113 | gtk_widget_realize( s_button ); | |
114 | } | |
115 | ||
9c7f49f5 VZ |
116 | gtk_paint_box |
117 | ( | |
9b311923 | 118 | s_button->style, |
9c7f49f5 VZ |
119 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
120 | flags & wxCONTROL_DISABLED ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, | |
121 | GTK_SHADOW_OUT, | |
9b311923 RR |
122 | NULL, |
123 | s_button, | |
124 | "button", | |
125 | dc.XLOG2DEV(rect.x) -1, rect.y -1, rect.width +2, rect.height +2 | |
9c7f49f5 VZ |
126 | ); |
127 | } | |
128 | ||
129 | #ifdef __WXGTK20__ | |
130 | ||
131 | // draw a ">" or "v" button | |
132 | // | |
133 | // TODO: isn't there a GTK function to draw it? | |
134 | void | |
9a0b7e33 VS |
135 | wxRendererGTK::DrawTreeItemButton(wxWindow* WXUNUSED(win), |
136 | wxDC& dc, const wxRect& rect, int flags) | |
9c7f49f5 | 137 | { |
3dd570e5 VZ |
138 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT), |
139 | wxSOLID)); | |
9c7f49f5 VZ |
140 | dc.SetPen(*wxBLACK_PEN); |
141 | wxPoint button[3]; | |
142 | ||
143 | const wxCoord xMiddle = rect.x + rect.width/2; | |
144 | const wxCoord yMiddle = rect.y + rect.height/2; | |
145 | ||
146 | if ( flags & wxCONTROL_EXPANDED ) | |
147 | { | |
148 | button[0].x = rect.GetLeft(); | |
149 | button[0].y = yMiddle - 2; | |
150 | button[1].x = rect.GetRight(); | |
151 | button[1].y = yMiddle - 2; | |
152 | button[2].x = xMiddle; | |
153 | button[2].y = yMiddle + 3; | |
154 | } | |
155 | else // collapsed | |
156 | { | |
157 | button[0].y = rect.GetBottom(); | |
158 | button[0].x = xMiddle - 2; | |
159 | button[1].y = rect.GetTop(); | |
160 | button[1].x = xMiddle - 2; | |
161 | button[2].y = yMiddle; | |
162 | button[2].x = xMiddle + 3; | |
163 | } | |
164 | ||
165 | dc.DrawPolygon(3, button); | |
166 | } | |
167 | ||
168 | #endif // GTK 2.0 | |
169 | ||
d16cf3cd VZ |
170 | // ---------------------------------------------------------------------------- |
171 | // splitter sash drawing | |
172 | // ---------------------------------------------------------------------------- | |
173 | ||
af99040c VZ |
174 | // all this should probably be read from the current theme settings somehow? |
175 | #ifdef __WXGTK20__ | |
176 | // the full sash size | |
177 | static const wxCoord SASH_FULL_SIZE = 5; | |
178 | #else // GTK+ 1.x | |
179 | // the full sash width (should be even) | |
35468934 | 180 | static const wxCoord SASH_SIZE = 8; |
af99040c VZ |
181 | |
182 | // margin around the sash | |
35468934 | 183 | static const wxCoord SASH_MARGIN = 2; |
d16cf3cd | 184 | |
af99040c VZ |
185 | // the full sash size |
186 | static const wxCoord SASH_FULL_SIZE = SASH_SIZE + SASH_MARGIN; | |
187 | #endif // GTK+ 2.x/1.x | |
d16cf3cd | 188 | |
af99040c VZ |
189 | wxSplitterRenderParams |
190 | wxRendererGTK::GetSplitterParams(const wxWindow * WXUNUSED(win)) | |
d16cf3cd | 191 | { |
af99040c VZ |
192 | // we don't draw any border, hence 0 for the second field |
193 | return wxSplitterRenderParams | |
194 | ( | |
195 | SASH_FULL_SIZE, | |
196 | 0, | |
197 | #ifdef __WXGTK20__ | |
198 | true // hot sensitive | |
199 | #else // GTK+ 1.x | |
200 | false // not | |
201 | #endif // GTK+ 2.x/1.x | |
202 | ); | |
d16cf3cd VZ |
203 | } |
204 | ||
205 | void | |
206 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
207 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
208 | const wxRect& WXUNUSED(rect), |
209 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
210 | { |
211 | // nothing to do | |
212 | } | |
95155e75 | 213 | |
95155e75 VZ |
214 | void |
215 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
216 | wxDC& dc, | |
217 | const wxSize& size, | |
d16cf3cd | 218 | wxCoord position, |
af99040c VZ |
219 | wxOrientation orient, |
220 | int WXUNUSED_IN_GTK1(flags)) | |
95155e75 VZ |
221 | { |
222 | if ( !win->m_wxwindow->window ) | |
223 | { | |
224 | // VZ: this happens on startup -- why? | |
225 | return; | |
226 | } | |
227 | ||
d16cf3cd VZ |
228 | // are we drawing vertical or horizontal splitter? |
229 | const bool isVert = orient == wxVERTICAL; | |
230 | ||
d16cf3cd | 231 | GdkRectangle rect; |
35468934 | 232 | GdkRectangle erase_rect; |
d16cf3cd VZ |
233 | if ( isVert ) |
234 | { | |
35468934 RR |
235 | int h = win->GetClientSize().GetHeight(); |
236 | ||
d16cf3cd | 237 | rect.x = position; |
35468934 | 238 | rect.y = h/2 - 14/2; |
af99040c | 239 | rect.width = SASH_FULL_SIZE; |
35468934 RR |
240 | rect.height = 14; |
241 | ||
242 | erase_rect.x = position; | |
243 | erase_rect.y = 0; | |
244 | erase_rect.width = SASH_FULL_SIZE; | |
245 | erase_rect.height = h; | |
d16cf3cd VZ |
246 | } |
247 | else // horz | |
248 | { | |
35468934 RR |
249 | int w = win->GetClientSize().GetWidth(); |
250 | ||
251 | rect.x = w/2 - 14/2; | |
d16cf3cd | 252 | rect.y = position; |
af99040c | 253 | rect.height = SASH_FULL_SIZE; |
35468934 RR |
254 | rect.width = 14; |
255 | ||
256 | erase_rect.y = position; | |
257 | erase_rect.x = 0; | |
258 | erase_rect.height = SASH_FULL_SIZE; | |
259 | erase_rect.width = w; | |
d16cf3cd VZ |
260 | } |
261 | ||
35468934 RR |
262 | // we must erase everything first, otherwise the garbage from the old sash |
263 | // is left when dragging it | |
264 | // | |
265 | // TODO: is this the right way to draw themed background? | |
266 | gtk_paint_flat_box | |
267 | ( | |
268 | win->m_wxwindow->style, | |
269 | GTK_PIZZA(win->m_wxwindow)->bin_window, | |
270 | GTK_STATE_NORMAL, | |
271 | GTK_SHADOW_NONE, | |
272 | NULL, | |
273 | win->m_wxwindow, | |
274 | (char *)"base", // const_cast | |
275 | erase_rect.x, | |
276 | erase_rect.y, | |
277 | erase_rect.width, | |
278 | erase_rect.height | |
279 | ); | |
280 | ||
af99040c VZ |
281 | #ifdef __WXGTK20__ |
282 | gtk_paint_handle | |
283 | ( | |
284 | win->m_wxwindow->style, | |
285 | GTK_PIZZA(win->m_wxwindow)->bin_window, | |
286 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, | |
287 | GTK_SHADOW_NONE, | |
288 | NULL /* no clipping */, | |
289 | win->m_wxwindow, | |
290 | "paned", | |
291 | rect.x, | |
292 | rect.y, | |
293 | rect.width, | |
294 | rect.height, | |
35468934 | 295 | !isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c VZ |
296 | ); |
297 | #else // GTK+ 1.x | |
d16cf3cd VZ |
298 | |
299 | // leave some margin before sash itself | |
300 | position += SASH_MARGIN / 2; | |
301 | ||
302 | // and finally draw it using GTK paint functions | |
303 | typedef void (*GtkPaintLineFunc)(GtkStyle *, GdkWindow *, | |
304 | GtkStateType, | |
305 | GdkRectangle *, GtkWidget *, | |
ef9bfb71 | 306 | gchar *, |
ef9bfb71 | 307 | gint, gint, gint); |
d16cf3cd VZ |
308 | |
309 | GtkPaintLineFunc func = isVert ? gtk_paint_vline : gtk_paint_hline; | |
310 | ||
311 | (*func) | |
95155e75 VZ |
312 | ( |
313 | win->m_wxwindow->style, | |
d16cf3cd | 314 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 | 315 | GTK_STATE_NORMAL, |
d16cf3cd | 316 | NULL, |
95155e75 | 317 | win->m_wxwindow, |
d16cf3cd VZ |
318 | (char *)"paned", // const_cast |
319 | 0, isVert ? size.y : size.x, position + SASH_SIZE / 2 - 1 | |
95155e75 VZ |
320 | ); |
321 | ||
322 | gtk_paint_box | |
323 | ( | |
324 | win->m_wxwindow->style, | |
d16cf3cd | 325 | GTK_PIZZA(win->m_wxwindow)->bin_window, |
95155e75 VZ |
326 | GTK_STATE_NORMAL, |
327 | GTK_SHADOW_OUT, | |
d16cf3cd | 328 | (GdkRectangle*) NULL, |
95155e75 VZ |
329 | win->m_wxwindow, |
330 | (char *)"paned", // const_cast | |
d16cf3cd VZ |
331 | isVert ? position : size.x - 2*SASH_SIZE, |
332 | isVert ? size.y - 2*SASH_SIZE : position, | |
333 | SASH_SIZE, SASH_SIZE | |
95155e75 | 334 | ); |
af99040c | 335 | #endif // GTK+ 2.x/1.x |
95155e75 VZ |
336 | } |
337 |