]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | ||
3 | // Name: src/aui/dockart.cpp | |
4 | // Purpose: wxaui: wx advanced user interface - docking window manager | |
5 | // Author: Benjamin I. Williams | |
6 | // Modified by: | |
7 | // Created: 2005-05-17 | |
8 | // RCS-ID: $Id: dockart.cpp 48848 2007-09-21 10:19:53Z SC $ | |
9 | // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved | |
10 | // Licence: wxWindows Library Licence, Version 3.1 | |
11 | /////////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // ============================================================================ | |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #if wxUSE_AUI | |
28 | ||
29 | #include "wx/statline.h" | |
30 | #include "wx/dcbuffer.h" | |
31 | #include "wx/sizer.h" | |
32 | #include "wx/image.h" | |
33 | #include "wx/settings.h" | |
34 | #include "wx/menu.h" | |
35 | ||
36 | #include "wx/aui/auibar.h" | |
37 | #include "wx/aui/framemanager.h" | |
38 | ||
39 | #ifdef __WXMAC__ | |
40 | #include "wx/osx/private.h" | |
41 | // for themeing support | |
42 | #include <Carbon/Carbon.h> | |
43 | #endif | |
44 | ||
45 | #include "wx/arrimpl.cpp" | |
46 | WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray) | |
47 | ||
48 | ||
49 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN) | |
50 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK) | |
51 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK) | |
52 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK) | |
53 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG) | |
54 | ||
55 | ||
56 | IMPLEMENT_CLASS(wxAuiToolBar, wxControl) | |
57 | IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent, wxEvent) | |
58 | ||
59 | ||
60 | // missing wxITEM_* items | |
61 | enum | |
62 | { | |
63 | wxITEM_CONTROL = wxITEM_MAX, | |
64 | wxITEM_LABEL, | |
65 | wxITEM_SPACER | |
66 | }; | |
67 | ||
68 | const int BUTTON_DROPDOWN_WIDTH = 10; | |
69 | ||
70 | ||
71 | wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, | |
72 | const wxColour& color); | |
73 | ||
74 | unsigned char wxAuiBlendColour(unsigned char fg, unsigned char bg, double alpha); | |
75 | wxColor wxAuiStepColour(const wxColor& c, int percent); | |
76 | ||
77 | static wxBitmap MakeDisabledBitmap(wxBitmap& bmp) | |
78 | { | |
79 | wxImage image = bmp.ConvertToImage(); | |
80 | ||
81 | int mr, mg, mb; | |
82 | mr = image.GetMaskRed(); | |
83 | mg = image.GetMaskGreen(); | |
84 | mb = image.GetMaskBlue(); | |
85 | ||
86 | unsigned char* data = image.GetData(); | |
87 | int width = image.GetWidth(); | |
88 | int height = image.GetHeight(); | |
89 | bool has_mask = image.HasMask(); | |
90 | ||
91 | for (int y = height-1; y >= 0; --y) | |
92 | { | |
93 | for (int x = width-1; x >= 0; --x) | |
94 | { | |
95 | data = image.GetData() + (y*(width*3))+(x*3); | |
96 | unsigned char* r = data; | |
97 | unsigned char* g = data+1; | |
98 | unsigned char* b = data+2; | |
99 | ||
100 | if (has_mask && *r == mr && *g == mg && *b == mb) | |
101 | continue; | |
102 | ||
103 | *r = wxAuiBlendColour(*r, 255, 0.4); | |
104 | *g = wxAuiBlendColour(*g, 255, 0.4); | |
105 | *b = wxAuiBlendColour(*b, 255, 0.4); | |
106 | } | |
107 | } | |
108 | ||
109 | return wxBitmap(image); | |
110 | } | |
111 | ||
112 | static wxColor GetBaseColor() | |
113 | { | |
114 | ||
115 | #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON | |
116 | wxColor base_colour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); | |
117 | #else | |
118 | wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
119 | #endif | |
120 | ||
121 | // the base_colour is too pale to use as our base colour, | |
122 | // so darken it a bit -- | |
123 | if ((255-base_colour.Red()) + | |
124 | (255-base_colour.Green()) + | |
125 | (255-base_colour.Blue()) < 60) | |
126 | { | |
127 | base_colour = wxAuiStepColour(base_colour, 92); | |
128 | } | |
129 | ||
130 | return base_colour; | |
131 | } | |
132 | ||
133 | ||
134 | ||
135 | class ToolbarCommandCapture : public wxEvtHandler | |
136 | { | |
137 | public: | |
138 | ||
139 | ToolbarCommandCapture() { m_last_id = 0; } | |
140 | int GetCommandId() const { return m_last_id; } | |
141 | ||
142 | bool ProcessEvent(wxEvent& evt) | |
143 | { | |
144 | if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED) | |
145 | { | |
146 | m_last_id = evt.GetId(); | |
147 | return true; | |
148 | } | |
149 | ||
150 | if (GetNextHandler()) | |
151 | return GetNextHandler()->ProcessEvent(evt); | |
152 | ||
153 | return false; | |
154 | } | |
155 | ||
156 | private: | |
157 | int m_last_id; | |
158 | }; | |
159 | ||
160 | ||
161 | ||
162 | static const unsigned char | |
163 | DISABLED_TEXT_GREY_HUE = wxAuiBlendColour(0, 255, 0.4); | |
164 | const wxColour DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE, | |
165 | DISABLED_TEXT_GREY_HUE, | |
166 | DISABLED_TEXT_GREY_HUE); | |
167 | ||
168 | wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt() | |
169 | { | |
170 | m_base_colour = GetBaseColor(); | |
171 | ||
172 | m_flags = 0; | |
173 | m_text_orientation = wxAUI_TBTOOL_TEXT_BOTTOM; | |
174 | m_highlight_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); | |
175 | ||
176 | m_separator_size = 7; | |
177 | m_gripper_size = 7; | |
178 | m_overflow_size = 16; | |
179 | ||
180 | wxColor darker1_colour = wxAuiStepColour(m_base_colour, 85); | |
181 | wxColor darker2_colour = wxAuiStepColour(m_base_colour, 75); | |
182 | wxColor darker3_colour = wxAuiStepColour(m_base_colour, 60); | |
183 | wxColor darker4_colour = wxAuiStepColour(m_base_colour, 50); | |
184 | wxColor darker5_colour = wxAuiStepColour(m_base_colour, 40); | |
185 | ||
186 | m_gripper_pen1 = wxPen(darker5_colour); | |
187 | m_gripper_pen2 = wxPen(darker3_colour); | |
188 | m_gripper_pen3 = *wxWHITE_PEN; | |
189 | ||
190 | static unsigned char button_dropdown_bits[] = { 0xe0, 0xf1, 0xfb }; | |
191 | static unsigned char overflow_bits[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 }; | |
192 | ||
193 | m_button_dropdown_bmp = wxAuiBitmapFromBits(button_dropdown_bits, 5, 3, | |
194 | *wxBLACK); | |
195 | m_disabled_button_dropdown_bmp = wxAuiBitmapFromBits( | |
196 | button_dropdown_bits, 5, 3, | |
197 | wxColor(128,128,128)); | |
198 | m_overflow_bmp = wxAuiBitmapFromBits(overflow_bits, 7, 6, *wxBLACK); | |
199 | m_disabled_overflow_bmp = wxAuiBitmapFromBits(overflow_bits, 7, 6, wxColor(128,128,128)); | |
200 | ||
201 | m_font = *wxNORMAL_FONT; | |
202 | } | |
203 | ||
204 | wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt() | |
205 | { | |
206 | m_font = *wxNORMAL_FONT; | |
207 | } | |
208 | ||
209 | ||
210 | wxAuiToolBarArt* wxAuiDefaultToolBarArt::Clone() | |
211 | { | |
212 | return static_cast<wxAuiToolBarArt*>(new wxAuiDefaultToolBarArt); | |
213 | } | |
214 | ||
215 | void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags) | |
216 | { | |
217 | m_flags = flags; | |
218 | } | |
219 | ||
220 | void wxAuiDefaultToolBarArt::SetFont(const wxFont& font) | |
221 | { | |
222 | m_font = font; | |
223 | } | |
224 | ||
225 | void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation) | |
226 | { | |
227 | m_text_orientation = orientation; | |
228 | } | |
229 | ||
230 | void wxAuiDefaultToolBarArt::DrawBackground( | |
231 | wxDC& dc, | |
232 | wxWindow* WXUNUSED(wnd), | |
233 | const wxRect& _rect) | |
234 | { | |
235 | wxRect rect = _rect; | |
236 | rect.height++; | |
237 | wxColour start_colour = wxAuiStepColour(m_base_colour, 150); | |
238 | wxColour end_colour = wxAuiStepColour(m_base_colour, 90); | |
239 | dc.GradientFillLinear(rect, start_colour, end_colour, wxSOUTH); | |
240 | } | |
241 | ||
242 | void wxAuiDefaultToolBarArt::DrawLabel( | |
243 | wxDC& dc, | |
244 | wxWindow* WXUNUSED(wnd), | |
245 | const wxAuiToolBarItem& item, | |
246 | const wxRect& rect) | |
247 | { | |
248 | dc.SetFont(m_font); | |
249 | dc.SetTextForeground(*wxBLACK); | |
250 | ||
251 | // we only care about the text height here since the text | |
252 | // will get cropped based on the width of the item | |
253 | int text_width = 0, text_height = 0; | |
254 | dc.GetTextExtent(wxT("ABCDHgj"), &text_width, &text_height); | |
255 | ||
256 | // set the clipping region | |
257 | wxRect clip_rect = rect; | |
258 | clip_rect.width -= 1; | |
259 | dc.SetClippingRegion(clip_rect); | |
260 | ||
261 | int text_x, text_y; | |
262 | text_x = rect.x + 1; | |
263 | text_y = rect.y + (rect.height-text_height)/2; | |
264 | dc.DrawText(item.GetLabel(), text_x, text_y); | |
265 | dc.DestroyClippingRegion(); | |
266 | } | |
267 | ||
268 | ||
269 | void wxAuiDefaultToolBarArt::DrawButton( | |
270 | wxDC& dc, | |
271 | wxWindow* WXUNUSED(wnd), | |
272 | const wxAuiToolBarItem& item, | |
273 | const wxRect& rect) | |
274 | { | |
275 | int text_width = 0, text_height = 0; | |
276 | ||
277 | if (m_flags & wxAUI_TB_TEXT) | |
278 | { | |
279 | dc.SetFont(m_font); | |
280 | ||
281 | int tx, ty; | |
282 | ||
283 | dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height); | |
284 | text_width = 0; | |
285 | dc.GetTextExtent(item.GetLabel(), &text_width, &ty); | |
286 | } | |
287 | ||
288 | int bmp_x = 0, bmp_y = 0; | |
289 | int text_x = 0, text_y = 0; | |
290 | ||
291 | if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM) | |
292 | { | |
293 | bmp_x = rect.x + | |
294 | (rect.width/2) - | |
295 | (item.GetBitmap().GetWidth()/2); | |
296 | ||
297 | bmp_y = rect.y + | |
298 | ((rect.height-text_height)/2) - | |
299 | (item.GetBitmap().GetHeight()/2); | |
300 | ||
301 | text_x = rect.x + (rect.width/2) - (text_width/2) + 1; | |
302 | text_y = rect.y + rect.height - text_height - 1; | |
303 | } | |
304 | else if (m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT) | |
305 | { | |
306 | bmp_x = rect.x + 3; | |
307 | ||
308 | bmp_y = rect.y + | |
309 | (rect.height/2) - | |
310 | (item.GetBitmap().GetHeight()/2); | |
311 | ||
312 | text_x = bmp_x + 3 + item.GetBitmap().GetWidth(); | |
313 | text_y = rect.y + | |
314 | (rect.height/2) - | |
315 | (text_height/2); | |
316 | } | |
317 | ||
318 | ||
319 | if (!(item.GetState() & wxAUI_BUTTON_STATE_DISABLED)) | |
320 | { | |
321 | if (item.GetState() & wxAUI_BUTTON_STATE_PRESSED) | |
322 | { | |
323 | dc.SetPen(wxPen(m_highlight_colour)); | |
324 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 150))); | |
325 | dc.DrawRectangle(rect); | |
326 | } | |
327 | else if ((item.GetState() & wxAUI_BUTTON_STATE_HOVER) || item.IsSticky()) | |
328 | { | |
329 | dc.SetPen(wxPen(m_highlight_colour)); | |
330 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170))); | |
331 | ||
332 | // draw an even lighter background for checked item hovers (since | |
333 | // the hover background is the same color as the check background) | |
334 | if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED) | |
335 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 180))); | |
336 | ||
337 | dc.DrawRectangle(rect); | |
338 | } | |
339 | else if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED) | |
340 | { | |
341 | // it's important to put this code in an else statment after the | |
342 | // hover, otherwise hovers won't draw properly for checked items | |
343 | dc.SetPen(wxPen(m_highlight_colour)); | |
344 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170))); | |
345 | dc.DrawRectangle(rect); | |
346 | } | |
347 | } | |
348 | ||
349 | wxBitmap bmp; | |
350 | if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) | |
351 | bmp = item.GetDisabledBitmap(); | |
352 | else | |
353 | bmp = item.GetBitmap(); | |
354 | ||
355 | if (!bmp.IsOk()) | |
356 | return; | |
357 | ||
358 | dc.DrawBitmap(bmp, bmp_x, bmp_y, true); | |
359 | ||
360 | // set the item's text color based on if it is disabled | |
361 | dc.SetTextForeground(*wxBLACK); | |
362 | if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) | |
363 | dc.SetTextForeground(DISABLED_TEXT_COLOR); | |
364 | ||
365 | if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) | |
366 | { | |
367 | dc.DrawText(item.GetLabel(), text_x, text_y); | |
368 | } | |
369 | } | |
370 | ||
371 | ||
372 | void wxAuiDefaultToolBarArt::DrawDropDownButton( | |
373 | wxDC& dc, | |
374 | wxWindow* WXUNUSED(wnd), | |
375 | const wxAuiToolBarItem& item, | |
376 | const wxRect& rect) | |
377 | { | |
378 | int text_width = 0, text_height = 0, text_x = 0, text_y = 0; | |
379 | int bmp_x = 0, bmp_y = 0, dropbmp_x = 0, dropbmp_y = 0; | |
380 | ||
381 | wxRect button_rect = wxRect(rect.x, | |
382 | rect.y, | |
383 | rect.width-BUTTON_DROPDOWN_WIDTH, | |
384 | rect.height); | |
385 | wxRect dropdown_rect = wxRect(rect.x+rect.width-BUTTON_DROPDOWN_WIDTH-1, | |
386 | rect.y, | |
387 | BUTTON_DROPDOWN_WIDTH+1, | |
388 | rect.height); | |
389 | ||
390 | if (m_flags & wxAUI_TB_TEXT) | |
391 | { | |
392 | dc.SetFont(m_font); | |
393 | ||
394 | int tx, ty; | |
395 | if (m_flags & wxAUI_TB_TEXT) | |
396 | { | |
397 | dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height); | |
398 | text_width = 0; | |
399 | } | |
400 | ||
401 | dc.GetTextExtent(item.GetLabel(), &text_width, &ty); | |
402 | } | |
403 | ||
404 | ||
405 | ||
406 | dropbmp_x = dropdown_rect.x + | |
407 | (dropdown_rect.width/2) - | |
408 | (m_button_dropdown_bmp.GetWidth()/2); | |
409 | dropbmp_y = dropdown_rect.y + | |
410 | (dropdown_rect.height/2) - | |
411 | (m_button_dropdown_bmp.GetHeight()/2); | |
412 | ||
413 | ||
414 | if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM) | |
415 | { | |
416 | bmp_x = button_rect.x + | |
417 | (button_rect.width/2) - | |
418 | (item.GetBitmap().GetWidth()/2); | |
419 | bmp_y = button_rect.y + | |
420 | ((button_rect.height-text_height)/2) - | |
421 | (item.GetBitmap().GetHeight()/2); | |
422 | ||
423 | text_x = rect.x + (rect.width/2) - (text_width/2) + 1; | |
424 | text_y = rect.y + rect.height - text_height - 1; | |
425 | } | |
426 | else if (m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT) | |
427 | { | |
428 | bmp_x = rect.x + 3; | |
429 | ||
430 | bmp_y = rect.y + | |
431 | (rect.height/2) - | |
432 | (item.GetBitmap().GetHeight()/2); | |
433 | ||
434 | text_x = bmp_x + 3 + item.GetBitmap().GetWidth(); | |
435 | text_y = rect.y + | |
436 | (rect.height/2) - | |
437 | (text_height/2); | |
438 | } | |
439 | ||
440 | ||
441 | if (item.GetState() & wxAUI_BUTTON_STATE_PRESSED) | |
442 | { | |
443 | dc.SetPen(wxPen(m_highlight_colour)); | |
444 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 140))); | |
445 | dc.DrawRectangle(button_rect); | |
446 | dc.DrawRectangle(dropdown_rect); | |
447 | } | |
448 | else if (item.GetState() & wxAUI_BUTTON_STATE_HOVER || | |
449 | item.IsSticky()) | |
450 | { | |
451 | dc.SetPen(wxPen(m_highlight_colour)); | |
452 | dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170))); | |
453 | dc.DrawRectangle(button_rect); | |
454 | dc.DrawRectangle(dropdown_rect); | |
455 | } | |
456 | ||
457 | wxBitmap bmp; | |
458 | wxBitmap dropbmp; | |
459 | if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) | |
460 | { | |
461 | bmp = item.GetDisabledBitmap(); | |
462 | dropbmp = m_disabled_button_dropdown_bmp; | |
463 | } | |
464 | else | |
465 | { | |
466 | bmp = item.GetBitmap(); | |
467 | dropbmp = m_button_dropdown_bmp; | |
468 | } | |
469 | ||
470 | if (!bmp.IsOk()) | |
471 | return; | |
472 | ||
473 | dc.DrawBitmap(bmp, bmp_x, bmp_y, true); | |
474 | dc.DrawBitmap(dropbmp, dropbmp_x, dropbmp_y, true); | |
475 | ||
476 | // set the item's text color based on if it is disabled | |
477 | dc.SetTextForeground(*wxBLACK); | |
478 | if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) | |
479 | dc.SetTextForeground(DISABLED_TEXT_COLOR); | |
480 | ||
481 | if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) | |
482 | { | |
483 | dc.DrawText(item.GetLabel(), text_x, text_y); | |
484 | } | |
485 | } | |
486 | ||
487 | void wxAuiDefaultToolBarArt::DrawControlLabel( | |
488 | wxDC& dc, | |
489 | wxWindow* WXUNUSED(wnd), | |
490 | const wxAuiToolBarItem& item, | |
491 | const wxRect& rect) | |
492 | { | |
493 | if (!(m_flags & wxAUI_TB_TEXT)) | |
494 | return; | |
495 | ||
496 | if (m_text_orientation != wxAUI_TBTOOL_TEXT_BOTTOM) | |
497 | return; | |
498 | ||
499 | int text_x = 0, text_y = 0; | |
500 | int text_width = 0, text_height = 0; | |
501 | ||
502 | dc.SetFont(m_font); | |
503 | ||
504 | int tx, ty; | |
505 | if (m_flags & wxAUI_TB_TEXT) | |
506 | { | |
507 | dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height); | |
508 | text_width = 0; | |
509 | } | |
510 | ||
511 | dc.GetTextExtent(item.GetLabel(), &text_width, &ty); | |
512 | ||
513 | // don't draw the label if it is wider than the item width | |
514 | if (text_width > rect.width) | |
515 | return; | |
516 | ||
517 | // set the label's text color | |
518 | dc.SetTextForeground(*wxBLACK); | |
519 | ||
520 | text_x = rect.x + (rect.width/2) - (text_width/2) + 1; | |
521 | text_y = rect.y + rect.height - text_height - 1; | |
522 | ||
523 | if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) | |
524 | { | |
525 | dc.DrawText(item.GetLabel(), text_x, text_y); | |
526 | } | |
527 | } | |
528 | ||
529 | wxSize wxAuiDefaultToolBarArt::GetLabelSize( | |
530 | wxDC& dc, | |
531 | wxWindow* WXUNUSED(wnd), | |
532 | const wxAuiToolBarItem& item) | |
533 | { | |
534 | dc.SetFont(m_font); | |
535 | ||
536 | // get label's height | |
537 | int width = 0, height = 0; | |
538 | dc.GetTextExtent(wxT("ABCDHgj"), &width, &height); | |
539 | ||
540 | // get item's width | |
541 | width = item.GetMinSize().GetWidth(); | |
542 | ||
543 | return wxSize(width, height); | |
544 | } | |
545 | ||
546 | wxSize wxAuiDefaultToolBarArt::GetToolSize( | |
547 | wxDC& dc, | |
548 | wxWindow* WXUNUSED(wnd), | |
549 | const wxAuiToolBarItem& item) | |
550 | { | |
551 | if (!item.GetBitmap().IsOk() && !(m_flags & wxAUI_TB_TEXT)) | |
552 | return wxSize(16,16); | |
553 | ||
554 | int width = item.GetBitmap().GetWidth(); | |
555 | int height = item.GetBitmap().GetHeight(); | |
556 | ||
557 | if (m_flags & wxAUI_TB_TEXT) | |
558 | { | |
559 | dc.SetFont(m_font); | |
560 | int tx, ty; | |
561 | ||
562 | if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM) | |
563 | { | |
564 | dc.GetTextExtent(wxT("ABCDHgj"), &tx, &ty); | |
565 | height += ty; | |
566 | ||
567 | if ( !item.GetLabel().empty() ) | |
568 | { | |
569 | dc.GetTextExtent(item.GetLabel(), &tx, &ty); | |
570 | width = wxMax(width, tx+6); | |
571 | } | |
572 | } | |
573 | else if ( m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT && | |
574 | !item.GetLabel().empty() ) | |
575 | { | |
576 | width += 3; // space between left border and bitmap | |
577 | width += 3; // space between bitmap and text | |
578 | ||
579 | if ( !item.GetLabel().empty() ) | |
580 | { | |
581 | dc.GetTextExtent(item.GetLabel(), &tx, &ty); | |
582 | width += tx; | |
583 | height = wxMax(height, ty); | |
584 | } | |
585 | } | |
586 | } | |
587 | ||
588 | // if the tool has a dropdown button, add it to the width | |
589 | if (item.HasDropDown()) | |
590 | width += (BUTTON_DROPDOWN_WIDTH+4); | |
591 | ||
592 | return wxSize(width, height); | |
593 | } | |
594 | ||
595 | void wxAuiDefaultToolBarArt::DrawSeparator( | |
596 | wxDC& dc, | |
597 | wxWindow* WXUNUSED(wnd), | |
598 | const wxRect& _rect) | |
599 | { | |
600 | bool horizontal = true; | |
601 | if (m_flags & wxAUI_TB_VERTICAL) | |
602 | horizontal = false; | |
603 | ||
604 | wxRect rect = _rect; | |
605 | ||
606 | if (horizontal) | |
607 | { | |
608 | rect.x += (rect.width/2); | |
609 | rect.width = 1; | |
610 | int new_height = (rect.height*3)/4; | |
611 | rect.y += (rect.height/2) - (new_height/2); | |
612 | rect.height = new_height; | |
613 | } | |
614 | else | |
615 | { | |
616 | rect.y += (rect.height/2); | |
617 | rect.height = 1; | |
618 | int new_width = (rect.width*3)/4; | |
619 | rect.x += (rect.width/2) - (new_width/2); | |
620 | rect.width = new_width; | |
621 | } | |
622 | ||
623 | wxColour start_colour = wxAuiStepColour(m_base_colour, 80); | |
624 | wxColour end_colour = wxAuiStepColour(m_base_colour, 80); | |
625 | dc.GradientFillLinear(rect, start_colour, end_colour, horizontal ? wxSOUTH : wxEAST); | |
626 | } | |
627 | ||
628 | void wxAuiDefaultToolBarArt::DrawGripper(wxDC& dc, | |
629 | wxWindow* WXUNUSED(wnd), | |
630 | const wxRect& rect) | |
631 | { | |
632 | int i = 0; | |
633 | while (1) | |
634 | { | |
635 | int x, y; | |
636 | ||
637 | if (m_flags & wxAUI_TB_VERTICAL) | |
638 | { | |
639 | x = rect.x + (i*4) + 5; | |
640 | y = rect.y + 3; | |
641 | if (x > rect.GetWidth()-5) | |
642 | break; | |
643 | } | |
644 | else | |
645 | { | |
646 | x = rect.x + 3; | |
647 | y = rect.y + (i*4) + 5; | |
648 | if (y > rect.GetHeight()-5) | |
649 | break; | |
650 | } | |
651 | ||
652 | dc.SetPen(m_gripper_pen1); | |
653 | dc.DrawPoint(x, y); | |
654 | dc.SetPen(m_gripper_pen2); | |
655 | dc.DrawPoint(x, y+1); | |
656 | dc.DrawPoint(x+1, y); | |
657 | dc.SetPen(m_gripper_pen3); | |
658 | dc.DrawPoint(x+2, y+1); | |
659 | dc.DrawPoint(x+2, y+2); | |
660 | dc.DrawPoint(x+1, y+2); | |
661 | ||
662 | i++; | |
663 | } | |
664 | ||
665 | } | |
666 | ||
667 | void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC& dc, | |
668 | wxWindow* wnd, | |
669 | const wxRect& rect, | |
670 | int state) | |
671 | { | |
672 | if (state & wxAUI_BUTTON_STATE_HOVER || | |
673 | state & wxAUI_BUTTON_STATE_PRESSED) | |
674 | { | |
675 | wxRect cli_rect = wnd->GetClientRect(); | |
676 | wxColor light_gray_bg = wxAuiStepColour(m_highlight_colour, 170); | |
677 | ||
678 | if (m_flags & wxAUI_TB_VERTICAL) | |
679 | { | |
680 | dc.SetPen(wxPen(m_highlight_colour)); | |
681 | dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y); | |
682 | dc.SetPen(wxPen(light_gray_bg)); | |
683 | dc.SetBrush(wxBrush(light_gray_bg)); | |
684 | dc.DrawRectangle(rect.x, rect.y+1, rect.width, rect.height); | |
685 | } | |
686 | else | |
687 | { | |
688 | dc.SetPen(wxPen(m_highlight_colour)); | |
689 | dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height); | |
690 | dc.SetPen(wxPen(light_gray_bg)); | |
691 | dc.SetBrush(wxBrush(light_gray_bg)); | |
692 | dc.DrawRectangle(rect.x+1, rect.y, rect.width, rect.height); | |
693 | } | |
694 | } | |
695 | ||
696 | int x = rect.x+1+(rect.width-m_overflow_bmp.GetWidth())/2; | |
697 | int y = rect.y+1+(rect.height-m_overflow_bmp.GetHeight())/2; | |
698 | dc.DrawBitmap(m_overflow_bmp, x, y, true); | |
699 | } | |
700 | ||
701 | int wxAuiDefaultToolBarArt::GetElementSize(int element_id) | |
702 | { | |
703 | switch (element_id) | |
704 | { | |
705 | case wxAUI_TBART_SEPARATOR_SIZE: return m_separator_size; | |
706 | case wxAUI_TBART_GRIPPER_SIZE: return m_gripper_size; | |
707 | case wxAUI_TBART_OVERFLOW_SIZE: return m_overflow_size; | |
708 | default: return 0; | |
709 | } | |
710 | } | |
711 | ||
712 | void wxAuiDefaultToolBarArt::SetElementSize(int element_id, int size) | |
713 | { | |
714 | switch (element_id) | |
715 | { | |
716 | case wxAUI_TBART_SEPARATOR_SIZE: m_separator_size = size; | |
717 | case wxAUI_TBART_GRIPPER_SIZE: m_gripper_size = size; | |
718 | case wxAUI_TBART_OVERFLOW_SIZE: m_overflow_size = size; | |
719 | } | |
720 | } | |
721 | ||
722 | int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow* wnd, | |
723 | const wxAuiToolBarItemArray& items) | |
724 | { | |
725 | wxMenu menuPopup; | |
726 | ||
727 | size_t items_added = 0; | |
728 | ||
729 | size_t i, count = items.GetCount(); | |
730 | for (i = 0; i < count; ++i) | |
731 | { | |
732 | wxAuiToolBarItem& item = items.Item(i); | |
733 | ||
734 | if (item.GetKind() == wxITEM_NORMAL) | |
735 | { | |
736 | wxString text = item.GetShortHelp(); | |
737 | if (text.empty()) | |
738 | text = item.GetLabel(); | |
739 | ||
740 | if (text.empty()) | |
741 | text = wxT(" "); | |
742 | ||
743 | wxMenuItem* m = new wxMenuItem(&menuPopup, item.GetId(), text, item.GetShortHelp()); | |
744 | ||
745 | m->SetBitmap(item.GetBitmap()); | |
746 | menuPopup.Append(m); | |
747 | items_added++; | |
748 | } | |
749 | else if (item.GetKind() == wxITEM_SEPARATOR) | |
750 | { | |
751 | if (items_added > 0) | |
752 | menuPopup.AppendSeparator(); | |
753 | } | |
754 | } | |
755 | ||
756 | // find out where to put the popup menu of window items | |
757 | wxPoint pt = ::wxGetMousePosition(); | |
758 | pt = wnd->ScreenToClient(pt); | |
759 | ||
760 | // find out the screen coordinate at the bottom of the tab ctrl | |
761 | wxRect cli_rect = wnd->GetClientRect(); | |
762 | pt.y = cli_rect.y + cli_rect.height; | |
763 | ||
764 | ToolbarCommandCapture* cc = new ToolbarCommandCapture; | |
765 | wnd->PushEventHandler(cc); | |
766 | wnd->PopupMenu(&menuPopup, pt); | |
767 | int command = cc->GetCommandId(); | |
768 | wnd->PopEventHandler(true); | |
769 | ||
770 | return command; | |
771 | } | |
772 | ||
773 | ||
774 | ||
775 | ||
776 | BEGIN_EVENT_TABLE(wxAuiToolBar, wxControl) | |
777 | EVT_SIZE(wxAuiToolBar::OnSize) | |
778 | EVT_IDLE(wxAuiToolBar::OnIdle) | |
779 | EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground) | |
780 | EVT_PAINT(wxAuiToolBar::OnPaint) | |
781 | EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown) | |
782 | EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown) | |
783 | EVT_LEFT_UP(wxAuiToolBar::OnLeftUp) | |
784 | EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown) | |
785 | EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown) | |
786 | EVT_RIGHT_UP(wxAuiToolBar::OnRightUp) | |
787 | EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown) | |
788 | EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown) | |
789 | EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp) | |
790 | EVT_MOTION(wxAuiToolBar::OnMotion) | |
791 | EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow) | |
792 | EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor) | |
793 | END_EVENT_TABLE() | |
794 | ||
795 | ||
796 | wxAuiToolBar::wxAuiToolBar(wxWindow* parent, | |
797 | wxWindowID id, | |
798 | const wxPoint& position, | |
799 | const wxSize& size, | |
800 | long style) | |
801 | : wxControl(parent, | |
802 | id, | |
803 | position, | |
804 | size, | |
805 | style | wxBORDER_NONE) | |
806 | { | |
807 | m_sizer = new wxBoxSizer(wxHORIZONTAL); | |
808 | m_button_width = -1; | |
809 | m_button_height = -1; | |
810 | m_sizer_element_count = 0; | |
811 | m_action_pos = wxPoint(-1,-1); | |
812 | m_action_item = NULL; | |
813 | m_tip_item = NULL; | |
814 | m_art = new wxAuiDefaultToolBarArt; | |
815 | m_tool_packing = 2; | |
816 | m_tool_border_padding = 3; | |
817 | m_tool_text_orientation = wxAUI_TBTOOL_TEXT_BOTTOM; | |
818 | m_gripper_sizer_item = NULL; | |
819 | m_overflow_sizer_item = NULL; | |
820 | m_dragging = false; | |
821 | m_style = style; | |
822 | m_gripper_visible = (m_style & wxAUI_TB_GRIPPER) ? true : false; | |
823 | m_overflow_visible = (m_style & wxAUI_TB_OVERFLOW) ? true : false; | |
824 | m_overflow_state = 0; | |
825 | SetMargins(5, 5, 2, 2); | |
826 | SetFont(*wxNORMAL_FONT); | |
827 | m_art->SetFlags((unsigned int)m_style); | |
828 | SetExtraStyle(wxWS_EX_PROCESS_IDLE); | |
829 | if (style & wxAUI_TB_HORZ_LAYOUT) | |
830 | SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT); | |
831 | } | |
832 | ||
833 | ||
834 | wxAuiToolBar::~wxAuiToolBar() | |
835 | { | |
836 | delete m_art; | |
837 | delete m_sizer; | |
838 | } | |
839 | ||
840 | void wxAuiToolBar::SetWindowStyleFlag(long style) | |
841 | { | |
842 | wxControl::SetWindowStyleFlag(style); | |
843 | ||
844 | m_style = style; | |
845 | ||
846 | if (m_art) | |
847 | { | |
848 | m_art->SetFlags((unsigned int)m_style); | |
849 | } | |
850 | ||
851 | if (m_style & wxAUI_TB_GRIPPER) | |
852 | m_gripper_visible = true; | |
853 | else | |
854 | m_gripper_visible = false; | |
855 | ||
856 | ||
857 | if (m_style & wxAUI_TB_OVERFLOW) | |
858 | m_overflow_visible = true; | |
859 | else | |
860 | m_overflow_visible = false; | |
861 | ||
862 | if (style & wxAUI_TB_HORZ_LAYOUT) | |
863 | SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT); | |
864 | else | |
865 | SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM); | |
866 | } | |
867 | ||
868 | ||
869 | void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt* art) | |
870 | { | |
871 | delete m_art; | |
872 | ||
873 | m_art = art; | |
874 | ||
875 | if (m_art) | |
876 | { | |
877 | m_art->SetFlags((unsigned int)m_style); | |
878 | m_art->SetTextOrientation(m_tool_text_orientation); | |
879 | } | |
880 | } | |
881 | ||
882 | wxAuiToolBarArt* wxAuiToolBar::GetArtProvider() const | |
883 | { | |
884 | return m_art; | |
885 | } | |
886 | ||
887 | ||
888 | ||
889 | ||
890 | void wxAuiToolBar::AddTool(int tool_id, | |
891 | const wxString& label, | |
892 | const wxBitmap& bitmap, | |
893 | const wxString& short_help_string, | |
894 | wxItemKind kind) | |
895 | { | |
896 | AddTool(tool_id, | |
897 | label, | |
898 | bitmap, | |
899 | wxNullBitmap, | |
900 | kind, | |
901 | short_help_string, | |
902 | wxEmptyString, | |
903 | NULL); | |
904 | } | |
905 | ||
906 | ||
907 | void wxAuiToolBar::AddTool(int tool_id, | |
908 | const wxString& label, | |
909 | const wxBitmap& bitmap, | |
910 | const wxBitmap& disabled_bitmap, | |
911 | wxItemKind kind, | |
912 | const wxString& short_help_string, | |
913 | const wxString& long_help_string, | |
914 | wxObject* WXUNUSED(client_data)) | |
915 | { | |
916 | wxAuiToolBarItem item; | |
917 | item.window = NULL; | |
918 | item.label = label; | |
919 | item.bitmap = bitmap; | |
920 | item.disabled_bitmap = disabled_bitmap; | |
921 | item.short_help = short_help_string; | |
922 | item.long_help = long_help_string; | |
923 | item.active = true; | |
924 | item.dropdown = false; | |
925 | item.spacer_pixels = 0; | |
926 | item.id = tool_id; | |
927 | item.state = 0; | |
928 | item.proportion = 0; | |
929 | item.kind = kind; | |
930 | item.sizer_item = NULL; | |
931 | item.min_size = wxDefaultSize; | |
932 | item.user_data = 0; | |
933 | item.sticky = false; | |
934 | ||
935 | if (!item.disabled_bitmap.IsOk()) | |
936 | { | |
937 | // no disabled bitmap specified, we need to make one | |
938 | if (item.bitmap.IsOk()) | |
939 | { | |
940 | //wxImage img = item.bitmap.ConvertToImage(); | |
941 | //wxImage grey_version = img.ConvertToGreyscale(); | |
942 | //item.disabled_bitmap = wxBitmap(grey_version); | |
943 | item.disabled_bitmap = MakeDisabledBitmap(item.bitmap); | |
944 | } | |
945 | } | |
946 | ||
947 | m_items.Add(item); | |
948 | } | |
949 | ||
950 | void wxAuiToolBar::AddControl(wxControl* control, | |
951 | const wxString& label) | |
952 | { | |
953 | wxAuiToolBarItem item; | |
954 | item.window = (wxWindow*)control; | |
955 | item.label = label; | |
956 | item.bitmap = wxNullBitmap; | |
957 | item.disabled_bitmap = wxNullBitmap; | |
958 | item.active = true; | |
959 | item.dropdown = false; | |
960 | item.spacer_pixels = 0; | |
961 | item.id = control->GetId(); | |
962 | item.state = 0; | |
963 | item.proportion = 0; | |
964 | item.kind = wxITEM_CONTROL; | |
965 | item.sizer_item = NULL; | |
966 | item.min_size = control->GetEffectiveMinSize(); | |
967 | item.user_data = 0; | |
968 | item.sticky = false; | |
969 | ||
970 | m_items.Add(item); | |
971 | } | |
972 | ||
973 | void wxAuiToolBar::AddLabel(int tool_id, | |
974 | const wxString& label, | |
975 | const int width) | |
976 | { | |
977 | wxSize min_size = wxDefaultSize; | |
978 | if (width != -1) | |
979 | min_size.x = width; | |
980 | ||
981 | wxAuiToolBarItem item; | |
982 | item.window = NULL; | |
983 | item.label = label; | |
984 | item.bitmap = wxNullBitmap; | |
985 | item.disabled_bitmap = wxNullBitmap; | |
986 | item.active = true; | |
987 | item.dropdown = false; | |
988 | item.spacer_pixels = 0; | |
989 | item.id = tool_id; | |
990 | item.state = 0; | |
991 | item.proportion = 0; | |
992 | item.kind = wxITEM_LABEL; | |
993 | item.sizer_item = NULL; | |
994 | item.min_size = min_size; | |
995 | item.user_data = 0; | |
996 | item.sticky = false; | |
997 | ||
998 | m_items.Add(item); | |
999 | } | |
1000 | ||
1001 | void wxAuiToolBar::AddSeparator() | |
1002 | { | |
1003 | wxAuiToolBarItem item; | |
1004 | item.window = NULL; | |
1005 | item.label = wxEmptyString; | |
1006 | item.bitmap = wxNullBitmap; | |
1007 | item.disabled_bitmap = wxNullBitmap; | |
1008 | item.active = true; | |
1009 | item.dropdown = false; | |
1010 | item.id = -1; | |
1011 | item.state = 0; | |
1012 | item.proportion = 0; | |
1013 | item.kind = wxITEM_SEPARATOR; | |
1014 | item.sizer_item = NULL; | |
1015 | item.min_size = wxDefaultSize; | |
1016 | item.user_data = 0; | |
1017 | item.sticky = false; | |
1018 | ||
1019 | m_items.Add(item); | |
1020 | } | |
1021 | ||
1022 | void wxAuiToolBar::AddSpacer(int pixels) | |
1023 | { | |
1024 | wxAuiToolBarItem item; | |
1025 | item.window = NULL; | |
1026 | item.label = wxEmptyString; | |
1027 | item.bitmap = wxNullBitmap; | |
1028 | item.disabled_bitmap = wxNullBitmap; | |
1029 | item.active = true; | |
1030 | item.dropdown = false; | |
1031 | item.spacer_pixels = pixels; | |
1032 | item.id = -1; | |
1033 | item.state = 0; | |
1034 | item.proportion = 0; | |
1035 | item.kind = wxITEM_SPACER; | |
1036 | item.sizer_item = NULL; | |
1037 | item.min_size = wxDefaultSize; | |
1038 | item.user_data = 0; | |
1039 | item.sticky = false; | |
1040 | ||
1041 | m_items.Add(item); | |
1042 | } | |
1043 | ||
1044 | void wxAuiToolBar::AddStretchSpacer(int proportion) | |
1045 | { | |
1046 | wxAuiToolBarItem item; | |
1047 | item.window = NULL; | |
1048 | item.label = wxEmptyString; | |
1049 | item.bitmap = wxNullBitmap; | |
1050 | item.disabled_bitmap = wxNullBitmap; | |
1051 | item.active = true; | |
1052 | item.dropdown = false; | |
1053 | item.spacer_pixels = 0; | |
1054 | item.id = -1; | |
1055 | item.state = 0; | |
1056 | item.proportion = proportion; | |
1057 | item.kind = wxITEM_SPACER; | |
1058 | item.sizer_item = NULL; | |
1059 | item.min_size = wxDefaultSize; | |
1060 | item.user_data = 0; | |
1061 | item.sticky = false; | |
1062 | ||
1063 | m_items.Add(item); | |
1064 | } | |
1065 | ||
1066 | void wxAuiToolBar::Clear() | |
1067 | { | |
1068 | m_items.Clear(); | |
1069 | m_sizer_element_count = 0; | |
1070 | } | |
1071 | ||
1072 | bool wxAuiToolBar::DeleteTool(int tool_id) | |
1073 | { | |
1074 | int idx = GetToolIndex(tool_id); | |
1075 | if (idx >= 0 && idx < (int)m_items.GetCount()) | |
1076 | { | |
1077 | m_items.RemoveAt(idx); | |
1078 | Realize(); | |
1079 | return true; | |
1080 | } | |
1081 | ||
1082 | return false; | |
1083 | } | |
1084 | ||
1085 | bool wxAuiToolBar::DeleteByIndex(int idx) | |
1086 | { | |
1087 | if (idx >= 0 && idx < (int)m_items.GetCount()) | |
1088 | { | |
1089 | m_items.RemoveAt(idx); | |
1090 | Realize(); | |
1091 | return true; | |
1092 | } | |
1093 | ||
1094 | return false; | |
1095 | } | |
1096 | ||
1097 | ||
1098 | wxControl* wxAuiToolBar::FindControl(int id) | |
1099 | { | |
1100 | wxWindow* wnd = FindWindow(id); | |
1101 | return (wxControl*)wnd; | |
1102 | } | |
1103 | ||
1104 | wxAuiToolBarItem* wxAuiToolBar::FindTool(int tool_id) const | |
1105 | { | |
1106 | size_t i, count; | |
1107 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1108 | { | |
1109 | wxAuiToolBarItem& item = m_items.Item(i); | |
1110 | if (item.id == tool_id) | |
1111 | return &item; | |
1112 | } | |
1113 | ||
1114 | return NULL; | |
1115 | } | |
1116 | ||
1117 | wxAuiToolBarItem* wxAuiToolBar::FindToolByPosition(wxCoord x, wxCoord y) const | |
1118 | { | |
1119 | size_t i, count; | |
1120 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1121 | { | |
1122 | wxAuiToolBarItem& item = m_items.Item(i); | |
1123 | ||
1124 | if (!item.sizer_item) | |
1125 | continue; | |
1126 | ||
1127 | wxRect rect = item.sizer_item->GetRect(); | |
1128 | if (rect.Contains(x,y)) | |
1129 | { | |
1130 | // if the item doesn't fit on the toolbar, return NULL | |
1131 | if (!GetToolFitsByIndex(i)) | |
1132 | return NULL; | |
1133 | ||
1134 | return &item; | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | return NULL; | |
1139 | } | |
1140 | ||
1141 | wxAuiToolBarItem* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x, wxCoord y) const | |
1142 | { | |
1143 | size_t i, count; | |
1144 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1145 | { | |
1146 | wxAuiToolBarItem& item = m_items.Item(i); | |
1147 | ||
1148 | if (!item.sizer_item) | |
1149 | continue; | |
1150 | ||
1151 | wxRect rect = item.sizer_item->GetRect(); | |
1152 | ||
1153 | // apply tool packing | |
1154 | if (i+1 < count) | |
1155 | rect.width += m_tool_packing; | |
1156 | ||
1157 | if (rect.Contains(x,y)) | |
1158 | { | |
1159 | // if the item doesn't fit on the toolbar, return NULL | |
1160 | if (!GetToolFitsByIndex(i)) | |
1161 | return NULL; | |
1162 | ||
1163 | return &item; | |
1164 | } | |
1165 | } | |
1166 | ||
1167 | return NULL; | |
1168 | } | |
1169 | ||
1170 | wxAuiToolBarItem* wxAuiToolBar::FindToolByIndex(int idx) const | |
1171 | { | |
1172 | if (idx < 0) | |
1173 | return NULL; | |
1174 | ||
1175 | if (idx >= (int)m_items.size()) | |
1176 | return NULL; | |
1177 | ||
1178 | return &(m_items[idx]); | |
1179 | } | |
1180 | ||
1181 | void wxAuiToolBar::SetToolBitmapSize(const wxSize& WXUNUSED(size)) | |
1182 | { | |
1183 | // TODO: wxToolBar compatibility | |
1184 | } | |
1185 | ||
1186 | wxSize wxAuiToolBar::GetToolBitmapSize() const | |
1187 | { | |
1188 | // TODO: wxToolBar compatibility | |
1189 | return wxSize(16,15); | |
1190 | } | |
1191 | ||
1192 | void wxAuiToolBar::SetToolProportion(int tool_id, int proportion) | |
1193 | { | |
1194 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1195 | if (!item) | |
1196 | return; | |
1197 | ||
1198 | item->proportion = proportion; | |
1199 | } | |
1200 | ||
1201 | int wxAuiToolBar::GetToolProportion(int tool_id) const | |
1202 | { | |
1203 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1204 | if (!item) | |
1205 | return 0; | |
1206 | ||
1207 | return item->proportion; | |
1208 | } | |
1209 | ||
1210 | void wxAuiToolBar::SetToolSeparation(int separation) | |
1211 | { | |
1212 | if (m_art) | |
1213 | m_art->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE, separation); | |
1214 | } | |
1215 | ||
1216 | int wxAuiToolBar::GetToolSeparation() const | |
1217 | { | |
1218 | if (m_art) | |
1219 | return m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE); | |
1220 | else | |
1221 | return 5; | |
1222 | } | |
1223 | ||
1224 | ||
1225 | void wxAuiToolBar::SetToolDropDown(int tool_id, bool dropdown) | |
1226 | { | |
1227 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1228 | if (!item) | |
1229 | return; | |
1230 | ||
1231 | item->dropdown = dropdown; | |
1232 | } | |
1233 | ||
1234 | bool wxAuiToolBar::GetToolDropDown(int tool_id) const | |
1235 | { | |
1236 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1237 | if (!item) | |
1238 | return 0; | |
1239 | ||
1240 | return item->dropdown; | |
1241 | } | |
1242 | ||
1243 | void wxAuiToolBar::SetToolSticky(int tool_id, bool sticky) | |
1244 | { | |
1245 | // ignore separators | |
1246 | if (tool_id == -1) | |
1247 | return; | |
1248 | ||
1249 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1250 | if (!item) | |
1251 | return; | |
1252 | ||
1253 | if (item->sticky == sticky) | |
1254 | return; | |
1255 | ||
1256 | item->sticky = sticky; | |
1257 | ||
1258 | Refresh(false); | |
1259 | Update(); | |
1260 | } | |
1261 | ||
1262 | bool wxAuiToolBar::GetToolSticky(int tool_id) const | |
1263 | { | |
1264 | wxAuiToolBarItem* item = FindTool(tool_id); | |
1265 | if (!item) | |
1266 | return 0; | |
1267 | ||
1268 | return item->sticky; | |
1269 | } | |
1270 | ||
1271 | ||
1272 | ||
1273 | ||
1274 | void wxAuiToolBar::SetToolBorderPadding(int padding) | |
1275 | { | |
1276 | m_tool_border_padding = padding; | |
1277 | } | |
1278 | ||
1279 | int wxAuiToolBar::GetToolBorderPadding() const | |
1280 | { | |
1281 | return m_tool_border_padding; | |
1282 | } | |
1283 | ||
1284 | void wxAuiToolBar::SetToolTextOrientation(int orientation) | |
1285 | { | |
1286 | m_tool_text_orientation = orientation; | |
1287 | ||
1288 | if (m_art) | |
1289 | { | |
1290 | m_art->SetTextOrientation(orientation); | |
1291 | } | |
1292 | } | |
1293 | ||
1294 | int wxAuiToolBar::GetToolTextOrientation() const | |
1295 | { | |
1296 | return m_tool_text_orientation; | |
1297 | } | |
1298 | ||
1299 | void wxAuiToolBar::SetToolPacking(int packing) | |
1300 | { | |
1301 | m_tool_packing = packing; | |
1302 | } | |
1303 | ||
1304 | int wxAuiToolBar::GetToolPacking() const | |
1305 | { | |
1306 | return m_tool_packing; | |
1307 | } | |
1308 | ||
1309 | ||
1310 | void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation)) | |
1311 | { | |
1312 | } | |
1313 | ||
1314 | void wxAuiToolBar::SetMargins(int left, int right, int top, int bottom) | |
1315 | { | |
1316 | if (left != -1) | |
1317 | m_left_padding = left; | |
1318 | if (right != -1) | |
1319 | m_right_padding = right; | |
1320 | if (top != -1) | |
1321 | m_top_padding = top; | |
1322 | if (bottom != -1) | |
1323 | m_bottom_padding = bottom; | |
1324 | } | |
1325 | ||
1326 | bool wxAuiToolBar::GetGripperVisible() const | |
1327 | { | |
1328 | return m_gripper_visible; | |
1329 | } | |
1330 | ||
1331 | void wxAuiToolBar::SetGripperVisible(bool visible) | |
1332 | { | |
1333 | m_gripper_visible = visible; | |
1334 | if (visible) | |
1335 | m_style |= wxAUI_TB_GRIPPER; | |
1336 | Realize(); | |
1337 | Refresh(false); | |
1338 | } | |
1339 | ||
1340 | ||
1341 | bool wxAuiToolBar::GetOverflowVisible() const | |
1342 | { | |
1343 | return m_overflow_visible; | |
1344 | } | |
1345 | ||
1346 | void wxAuiToolBar::SetOverflowVisible(bool visible) | |
1347 | { | |
1348 | m_overflow_visible = visible; | |
1349 | if (visible) | |
1350 | m_style |= wxAUI_TB_OVERFLOW; | |
1351 | Refresh(false); | |
1352 | } | |
1353 | ||
1354 | bool wxAuiToolBar::SetFont(const wxFont& font) | |
1355 | { | |
1356 | bool res = wxWindow::SetFont(font); | |
1357 | ||
1358 | if (m_art) | |
1359 | { | |
1360 | m_art->SetFont(font); | |
1361 | } | |
1362 | ||
1363 | return res; | |
1364 | } | |
1365 | ||
1366 | ||
1367 | void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem* pitem) | |
1368 | { | |
1369 | wxAuiToolBarItem* former_hover = NULL; | |
1370 | ||
1371 | size_t i, count; | |
1372 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1373 | { | |
1374 | wxAuiToolBarItem& item = m_items.Item(i); | |
1375 | if (item.state & wxAUI_BUTTON_STATE_HOVER) | |
1376 | former_hover = &item; | |
1377 | item.state &= ~wxAUI_BUTTON_STATE_HOVER; | |
1378 | } | |
1379 | ||
1380 | if (pitem) | |
1381 | { | |
1382 | pitem->state |= wxAUI_BUTTON_STATE_HOVER; | |
1383 | } | |
1384 | ||
1385 | if (former_hover != pitem) | |
1386 | { | |
1387 | Refresh(false); | |
1388 | Update(); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem* pitem) | |
1393 | { | |
1394 | wxAuiToolBarItem* former_item = NULL; | |
1395 | ||
1396 | size_t i, count; | |
1397 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1398 | { | |
1399 | wxAuiToolBarItem& item = m_items.Item(i); | |
1400 | if (item.state & wxAUI_BUTTON_STATE_PRESSED) | |
1401 | former_item = &item; | |
1402 | item.state &= ~wxAUI_BUTTON_STATE_PRESSED; | |
1403 | } | |
1404 | ||
1405 | if (pitem) | |
1406 | { | |
1407 | pitem->state &= ~wxAUI_BUTTON_STATE_HOVER; | |
1408 | pitem->state |= wxAUI_BUTTON_STATE_PRESSED; | |
1409 | } | |
1410 | ||
1411 | if (former_item != pitem) | |
1412 | { | |
1413 | Refresh(false); | |
1414 | Update(); | |
1415 | } | |
1416 | } | |
1417 | ||
1418 | void wxAuiToolBar::RefreshOverflowState() | |
1419 | { | |
1420 | if (!m_overflow_sizer_item) | |
1421 | { | |
1422 | m_overflow_state = 0; | |
1423 | return; | |
1424 | } | |
1425 | ||
1426 | int overflow_state = 0; | |
1427 | ||
1428 | wxRect overflow_rect = GetOverflowRect(); | |
1429 | ||
1430 | ||
1431 | // find out the mouse's current position | |
1432 | wxPoint pt = ::wxGetMousePosition(); | |
1433 | pt = this->ScreenToClient(pt); | |
1434 | ||
1435 | // find out if the mouse cursor is inside the dropdown rectangle | |
1436 | if (overflow_rect.Contains(pt.x, pt.y)) | |
1437 | { | |
1438 | if (::wxGetMouseState().LeftDown()) | |
1439 | overflow_state = wxAUI_BUTTON_STATE_PRESSED; | |
1440 | else | |
1441 | overflow_state = wxAUI_BUTTON_STATE_HOVER; | |
1442 | } | |
1443 | ||
1444 | if (overflow_state != m_overflow_state) | |
1445 | { | |
1446 | m_overflow_state = overflow_state; | |
1447 | Refresh(false); | |
1448 | Update(); | |
1449 | } | |
1450 | ||
1451 | m_overflow_state = overflow_state; | |
1452 | } | |
1453 | ||
1454 | void wxAuiToolBar::ToggleTool(int tool_id, bool state) | |
1455 | { | |
1456 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1457 | ||
1458 | if (tool) | |
1459 | { | |
1460 | if (tool->kind != wxITEM_CHECK) | |
1461 | return; | |
1462 | ||
1463 | if (state == true) | |
1464 | tool->state |= wxAUI_BUTTON_STATE_CHECKED; | |
1465 | else | |
1466 | tool->state &= ~wxAUI_BUTTON_STATE_CHECKED; | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | bool wxAuiToolBar::GetToolToggled(int tool_id) const | |
1471 | { | |
1472 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1473 | ||
1474 | if (tool) | |
1475 | { | |
1476 | if (tool->kind != wxITEM_CHECK) | |
1477 | return false; | |
1478 | ||
1479 | return (tool->state & wxAUI_BUTTON_STATE_CHECKED) ? true : false; | |
1480 | } | |
1481 | ||
1482 | return false; | |
1483 | } | |
1484 | ||
1485 | void wxAuiToolBar::EnableTool(int tool_id, bool state) | |
1486 | { | |
1487 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1488 | ||
1489 | if (tool) | |
1490 | { | |
1491 | if (state == true) | |
1492 | tool->state &= ~wxAUI_BUTTON_STATE_DISABLED; | |
1493 | else | |
1494 | tool->state |= wxAUI_BUTTON_STATE_DISABLED; | |
1495 | } | |
1496 | } | |
1497 | ||
1498 | bool wxAuiToolBar::GetToolEnabled(int tool_id) const | |
1499 | { | |
1500 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1501 | ||
1502 | if (tool) | |
1503 | return (tool->state & wxAUI_BUTTON_STATE_DISABLED) ? false : true; | |
1504 | ||
1505 | return false; | |
1506 | } | |
1507 | ||
1508 | wxString wxAuiToolBar::GetToolLabel(int tool_id) const | |
1509 | { | |
1510 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1511 | wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array")); | |
1512 | if (!tool) | |
1513 | return wxEmptyString; | |
1514 | ||
1515 | return tool->label; | |
1516 | } | |
1517 | ||
1518 | void wxAuiToolBar::SetToolLabel(int tool_id, const wxString& label) | |
1519 | { | |
1520 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1521 | if (tool) | |
1522 | { | |
1523 | tool->label = label; | |
1524 | } | |
1525 | } | |
1526 | ||
1527 | wxBitmap wxAuiToolBar::GetToolBitmap(int tool_id) const | |
1528 | { | |
1529 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1530 | wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array")); | |
1531 | if (!tool) | |
1532 | return wxNullBitmap; | |
1533 | ||
1534 | return tool->bitmap; | |
1535 | } | |
1536 | ||
1537 | void wxAuiToolBar::SetToolBitmap(int tool_id, const wxBitmap& bitmap) | |
1538 | { | |
1539 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1540 | if (tool) | |
1541 | { | |
1542 | tool->bitmap = bitmap; | |
1543 | } | |
1544 | } | |
1545 | ||
1546 | wxString wxAuiToolBar::GetToolShortHelp(int tool_id) const | |
1547 | { | |
1548 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1549 | wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array")); | |
1550 | if (!tool) | |
1551 | return wxEmptyString; | |
1552 | ||
1553 | return tool->short_help; | |
1554 | } | |
1555 | ||
1556 | void wxAuiToolBar::SetToolShortHelp(int tool_id, const wxString& help_string) | |
1557 | { | |
1558 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1559 | if (tool) | |
1560 | { | |
1561 | tool->short_help = help_string; | |
1562 | } | |
1563 | } | |
1564 | ||
1565 | wxString wxAuiToolBar::GetToolLongHelp(int tool_id) const | |
1566 | { | |
1567 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1568 | wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array")); | |
1569 | if (!tool) | |
1570 | return wxEmptyString; | |
1571 | ||
1572 | return tool->long_help; | |
1573 | } | |
1574 | ||
1575 | void wxAuiToolBar::SetToolLongHelp(int tool_id, const wxString& help_string) | |
1576 | { | |
1577 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1578 | if (tool) | |
1579 | { | |
1580 | tool->long_help = help_string; | |
1581 | } | |
1582 | } | |
1583 | ||
1584 | void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray& prepend, | |
1585 | const wxAuiToolBarItemArray& append) | |
1586 | { | |
1587 | m_custom_overflow_prepend = prepend; | |
1588 | m_custom_overflow_append = append; | |
1589 | } | |
1590 | ||
1591 | ||
1592 | size_t wxAuiToolBar::GetToolCount() const | |
1593 | { | |
1594 | return m_items.size(); | |
1595 | } | |
1596 | ||
1597 | int wxAuiToolBar::GetToolIndex(int tool_id) const | |
1598 | { | |
1599 | // this will prevent us from returning the index of the | |
1600 | // first separator in the toolbar since its id is equal to -1 | |
1601 | if (tool_id == -1) | |
1602 | return wxNOT_FOUND; | |
1603 | ||
1604 | size_t i, count = m_items.GetCount(); | |
1605 | for (i = 0; i < count; ++i) | |
1606 | { | |
1607 | wxAuiToolBarItem& item = m_items.Item(i); | |
1608 | if (item.id == tool_id) | |
1609 | return i; | |
1610 | } | |
1611 | ||
1612 | return wxNOT_FOUND; | |
1613 | } | |
1614 | ||
1615 | bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx) const | |
1616 | { | |
1617 | if (tool_idx < 0 || tool_idx >= (int)m_items.GetCount()) | |
1618 | return false; | |
1619 | ||
1620 | if (!m_items[tool_idx].sizer_item) | |
1621 | return false; | |
1622 | ||
1623 | int cli_w, cli_h; | |
1624 | GetClientSize(&cli_w, &cli_h); | |
1625 | ||
1626 | wxRect rect = m_items[tool_idx].sizer_item->GetRect(); | |
1627 | ||
1628 | if (m_style & wxAUI_TB_VERTICAL) | |
1629 | { | |
1630 | // take the dropdown size into account | |
1631 | if (m_overflow_visible) | |
1632 | cli_h -= m_overflow_sizer_item->GetSize().y; | |
1633 | ||
1634 | if (rect.y+rect.height < cli_h) | |
1635 | return true; | |
1636 | } | |
1637 | else | |
1638 | { | |
1639 | // take the dropdown size into account | |
1640 | if (m_overflow_visible) | |
1641 | cli_w -= m_overflow_sizer_item->GetSize().x; | |
1642 | ||
1643 | if (rect.x+rect.width < cli_w) | |
1644 | return true; | |
1645 | } | |
1646 | ||
1647 | return false; | |
1648 | } | |
1649 | ||
1650 | ||
1651 | bool wxAuiToolBar::GetToolFits(int tool_id) const | |
1652 | { | |
1653 | return GetToolFitsByIndex(GetToolIndex(tool_id)); | |
1654 | } | |
1655 | ||
1656 | wxRect wxAuiToolBar::GetToolRect(int tool_id) const | |
1657 | { | |
1658 | wxAuiToolBarItem* tool = FindTool(tool_id); | |
1659 | if (tool && tool->sizer_item) | |
1660 | { | |
1661 | return tool->sizer_item->GetRect(); | |
1662 | } | |
1663 | ||
1664 | return wxRect(); | |
1665 | } | |
1666 | ||
1667 | bool wxAuiToolBar::GetToolBarFits() const | |
1668 | { | |
1669 | if (m_items.GetCount() == 0) | |
1670 | { | |
1671 | // empty toolbar always 'fits' | |
1672 | return true; | |
1673 | } | |
1674 | ||
1675 | // entire toolbar content fits if the last tool fits | |
1676 | return GetToolFitsByIndex(m_items.GetCount() - 1); | |
1677 | } | |
1678 | ||
1679 | bool wxAuiToolBar::Realize() | |
1680 | { | |
1681 | wxClientDC dc(this); | |
1682 | if (!dc.IsOk()) | |
1683 | return false; | |
1684 | ||
1685 | bool horizontal = true; | |
1686 | if (m_style & wxAUI_TB_VERTICAL) | |
1687 | horizontal = false; | |
1688 | ||
1689 | ||
1690 | // create the new sizer to add toolbar elements to | |
1691 | wxBoxSizer* sizer = new wxBoxSizer(horizontal ? wxHORIZONTAL : wxVERTICAL); | |
1692 | ||
1693 | // add gripper area | |
1694 | int separator_size = m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE); | |
1695 | int gripper_size = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE); | |
1696 | if (gripper_size > 0 && m_gripper_visible) | |
1697 | { | |
1698 | if (horizontal) | |
1699 | m_gripper_sizer_item = sizer->Add(gripper_size, 1, 0, wxEXPAND); | |
1700 | else | |
1701 | m_gripper_sizer_item = sizer->Add(1, gripper_size, 0, wxEXPAND); | |
1702 | } | |
1703 | else | |
1704 | { | |
1705 | m_gripper_sizer_item = NULL; | |
1706 | } | |
1707 | ||
1708 | // add "left" padding | |
1709 | if (m_left_padding > 0) | |
1710 | { | |
1711 | if (horizontal) | |
1712 | sizer->Add(m_left_padding, 1); | |
1713 | else | |
1714 | sizer->Add(1, m_left_padding); | |
1715 | } | |
1716 | ||
1717 | size_t i, count; | |
1718 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1719 | { | |
1720 | wxAuiToolBarItem& item = m_items.Item(i); | |
1721 | wxSizerItem* sizer_item = NULL; | |
1722 | ||
1723 | switch (item.kind) | |
1724 | { | |
1725 | case wxITEM_LABEL: | |
1726 | { | |
1727 | wxSize size = m_art->GetLabelSize(dc, this, item); | |
1728 | sizer_item = sizer->Add(size.x + (m_tool_border_padding*2), | |
1729 | size.y + (m_tool_border_padding*2), | |
1730 | item.proportion, | |
1731 | wxALIGN_CENTER); | |
1732 | if (i+1 < count) | |
1733 | { | |
1734 | sizer->AddSpacer(m_tool_packing); | |
1735 | } | |
1736 | ||
1737 | break; | |
1738 | } | |
1739 | ||
1740 | case wxITEM_CHECK: | |
1741 | case wxITEM_NORMAL: | |
1742 | { | |
1743 | wxSize size = m_art->GetToolSize(dc, this, item); | |
1744 | sizer_item = sizer->Add(size.x + (m_tool_border_padding*2), | |
1745 | size.y + (m_tool_border_padding*2), | |
1746 | 0, | |
1747 | wxALIGN_CENTER); | |
1748 | // add tool packing | |
1749 | if (i+1 < count) | |
1750 | { | |
1751 | sizer->AddSpacer(m_tool_packing); | |
1752 | } | |
1753 | ||
1754 | break; | |
1755 | } | |
1756 | ||
1757 | case wxITEM_SEPARATOR: | |
1758 | { | |
1759 | if (horizontal) | |
1760 | sizer_item = sizer->Add(separator_size, 1, 0, wxEXPAND); | |
1761 | else | |
1762 | sizer_item = sizer->Add(1, separator_size, 0, wxEXPAND); | |
1763 | ||
1764 | // add tool packing | |
1765 | if (i+1 < count) | |
1766 | { | |
1767 | sizer->AddSpacer(m_tool_packing); | |
1768 | } | |
1769 | ||
1770 | break; | |
1771 | } | |
1772 | ||
1773 | case wxITEM_SPACER: | |
1774 | if (item.proportion > 0) | |
1775 | sizer_item = sizer->AddStretchSpacer(item.proportion); | |
1776 | else | |
1777 | sizer_item = sizer->Add(item.spacer_pixels, 1); | |
1778 | break; | |
1779 | ||
1780 | case wxITEM_CONTROL: | |
1781 | { | |
1782 | //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND); | |
1783 | wxSizerItem* ctrl_sizer_item; | |
1784 | ||
1785 | wxBoxSizer* vert_sizer = new wxBoxSizer(wxVERTICAL); | |
1786 | vert_sizer->AddStretchSpacer(1); | |
1787 | ctrl_sizer_item = vert_sizer->Add(item.window, 0, wxEXPAND); | |
1788 | vert_sizer->AddStretchSpacer(1); | |
1789 | if ( (m_style & wxAUI_TB_TEXT) && | |
1790 | m_tool_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM && | |
1791 | !item.GetLabel().empty() ) | |
1792 | { | |
1793 | wxSize s = GetLabelSize(item.GetLabel()); | |
1794 | vert_sizer->Add(1, s.y); | |
1795 | } | |
1796 | ||
1797 | ||
1798 | sizer_item = sizer->Add(vert_sizer, item.proportion, wxEXPAND); | |
1799 | ||
1800 | wxSize min_size = item.min_size; | |
1801 | ||
1802 | ||
1803 | // proportional items will disappear from the toolbar if | |
1804 | // their min width is not set to something really small | |
1805 | if (item.proportion != 0) | |
1806 | { | |
1807 | min_size.x = 1; | |
1808 | } | |
1809 | ||
1810 | if (min_size.IsFullySpecified()) | |
1811 | { | |
1812 | sizer_item->SetMinSize(min_size); | |
1813 | ctrl_sizer_item->SetMinSize(min_size); | |
1814 | } | |
1815 | ||
1816 | // add tool packing | |
1817 | if (i+1 < count) | |
1818 | { | |
1819 | sizer->AddSpacer(m_tool_packing); | |
1820 | } | |
1821 | } | |
1822 | } | |
1823 | ||
1824 | item.sizer_item = sizer_item; | |
1825 | } | |
1826 | ||
1827 | // add "right" padding | |
1828 | if (m_right_padding > 0) | |
1829 | { | |
1830 | if (horizontal) | |
1831 | sizer->Add(m_right_padding, 1); | |
1832 | else | |
1833 | sizer->Add(1, m_right_padding); | |
1834 | } | |
1835 | ||
1836 | // add drop down area | |
1837 | m_overflow_sizer_item = NULL; | |
1838 | ||
1839 | if (m_style & wxAUI_TB_OVERFLOW) | |
1840 | { | |
1841 | int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); | |
1842 | if (overflow_size > 0 && m_overflow_visible) | |
1843 | { | |
1844 | if (horizontal) | |
1845 | m_overflow_sizer_item = sizer->Add(overflow_size, 1, 0, wxEXPAND); | |
1846 | else | |
1847 | m_overflow_sizer_item = sizer->Add(1, overflow_size, 0, wxEXPAND); | |
1848 | } | |
1849 | else | |
1850 | { | |
1851 | m_overflow_sizer_item = NULL; | |
1852 | } | |
1853 | } | |
1854 | ||
1855 | ||
1856 | // the outside sizer helps us apply the "top" and "bottom" padding | |
1857 | wxBoxSizer* outside_sizer = new wxBoxSizer(horizontal ? wxVERTICAL : wxHORIZONTAL); | |
1858 | ||
1859 | // add "top" padding | |
1860 | if (m_top_padding > 0) | |
1861 | { | |
1862 | if (horizontal) | |
1863 | outside_sizer->Add(1, m_top_padding); | |
1864 | else | |
1865 | outside_sizer->Add(m_top_padding, 1); | |
1866 | } | |
1867 | ||
1868 | // add the sizer that contains all of the toolbar elements | |
1869 | outside_sizer->Add(sizer, 1, wxEXPAND); | |
1870 | ||
1871 | // add "bottom" padding | |
1872 | if (m_bottom_padding > 0) | |
1873 | { | |
1874 | if (horizontal) | |
1875 | outside_sizer->Add(1, m_bottom_padding); | |
1876 | else | |
1877 | outside_sizer->Add(m_bottom_padding, 1); | |
1878 | } | |
1879 | ||
1880 | delete m_sizer; // remove old sizer | |
1881 | m_sizer = outside_sizer; | |
1882 | ||
1883 | // calculate the rock-bottom minimum size | |
1884 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1885 | { | |
1886 | wxAuiToolBarItem& item = m_items.Item(i); | |
1887 | if (item.sizer_item && item.proportion > 0 && item.min_size.IsFullySpecified()) | |
1888 | item.sizer_item->SetMinSize(0,0); | |
1889 | } | |
1890 | ||
1891 | m_absolute_min_size = m_sizer->GetMinSize(); | |
1892 | ||
1893 | // reset the min sizes to what they were | |
1894 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1895 | { | |
1896 | wxAuiToolBarItem& item = m_items.Item(i); | |
1897 | if (item.sizer_item && item.proportion > 0 && item.min_size.IsFullySpecified()) | |
1898 | item.sizer_item->SetMinSize(item.min_size); | |
1899 | } | |
1900 | ||
1901 | // set control size | |
1902 | wxSize size = m_sizer->GetMinSize(); | |
1903 | m_minWidth = size.x; | |
1904 | m_minHeight = size.y; | |
1905 | ||
1906 | if ((m_style & wxAUI_TB_NO_AUTORESIZE) == 0) | |
1907 | { | |
1908 | wxSize cur_size = GetClientSize(); | |
1909 | wxSize new_size = GetMinSize(); | |
1910 | if (new_size != cur_size) | |
1911 | { | |
1912 | SetClientSize(new_size); | |
1913 | } | |
1914 | else | |
1915 | { | |
1916 | m_sizer->SetDimension(0, 0, cur_size.x, cur_size.y); | |
1917 | } | |
1918 | } | |
1919 | else | |
1920 | { | |
1921 | wxSize cur_size = GetClientSize(); | |
1922 | m_sizer->SetDimension(0, 0, cur_size.x, cur_size.y); | |
1923 | } | |
1924 | ||
1925 | Refresh(false); | |
1926 | return true; | |
1927 | } | |
1928 | ||
1929 | int wxAuiToolBar::GetOverflowState() const | |
1930 | { | |
1931 | return m_overflow_state; | |
1932 | } | |
1933 | ||
1934 | wxRect wxAuiToolBar::GetOverflowRect() const | |
1935 | { | |
1936 | wxRect cli_rect(wxPoint(0,0), GetClientSize()); | |
1937 | wxRect overflow_rect = m_overflow_sizer_item->GetRect(); | |
1938 | int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); | |
1939 | ||
1940 | if (m_style & wxAUI_TB_VERTICAL) | |
1941 | { | |
1942 | overflow_rect.y = cli_rect.height - overflow_size; | |
1943 | overflow_rect.x = 0; | |
1944 | overflow_rect.width = cli_rect.width; | |
1945 | overflow_rect.height = overflow_size; | |
1946 | } | |
1947 | else | |
1948 | { | |
1949 | overflow_rect.x = cli_rect.width - overflow_size; | |
1950 | overflow_rect.y = 0; | |
1951 | overflow_rect.width = overflow_size; | |
1952 | overflow_rect.height = cli_rect.height; | |
1953 | } | |
1954 | ||
1955 | return overflow_rect; | |
1956 | } | |
1957 | ||
1958 | wxSize wxAuiToolBar::GetLabelSize(const wxString& label) | |
1959 | { | |
1960 | wxClientDC dc(this); | |
1961 | ||
1962 | int tx, ty; | |
1963 | int text_width = 0, text_height = 0; | |
1964 | ||
1965 | dc.SetFont(m_font); | |
1966 | ||
1967 | // get the text height | |
1968 | dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height); | |
1969 | ||
1970 | // get the text width | |
1971 | dc.GetTextExtent(label, &text_width, &ty); | |
1972 | ||
1973 | return wxSize(text_width, text_height); | |
1974 | } | |
1975 | ||
1976 | ||
1977 | void wxAuiToolBar::DoIdleUpdate() | |
1978 | { | |
1979 | wxEvtHandler* handler = GetEventHandler(); | |
1980 | ||
1981 | bool need_refresh = false; | |
1982 | ||
1983 | size_t i, count; | |
1984 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
1985 | { | |
1986 | wxAuiToolBarItem& item = m_items.Item(i); | |
1987 | ||
1988 | if (item.id == -1) | |
1989 | continue; | |
1990 | ||
1991 | wxUpdateUIEvent evt(item.id); | |
1992 | evt.SetEventObject(this); | |
1993 | ||
1994 | if (handler->ProcessEvent(evt)) | |
1995 | { | |
1996 | if (evt.GetSetEnabled()) | |
1997 | { | |
1998 | bool is_enabled; | |
1999 | if (item.window) | |
2000 | is_enabled = item.window->IsEnabled(); | |
2001 | else | |
2002 | is_enabled = (item.state & wxAUI_BUTTON_STATE_DISABLED) ? false : true; | |
2003 | ||
2004 | bool new_enabled = evt.GetEnabled(); | |
2005 | if (new_enabled != is_enabled) | |
2006 | { | |
2007 | if (item.window) | |
2008 | { | |
2009 | item.window->Enable(new_enabled); | |
2010 | } | |
2011 | else | |
2012 | { | |
2013 | if (new_enabled) | |
2014 | item.state &= ~wxAUI_BUTTON_STATE_DISABLED; | |
2015 | else | |
2016 | item.state |= wxAUI_BUTTON_STATE_DISABLED; | |
2017 | } | |
2018 | need_refresh = true; | |
2019 | } | |
2020 | } | |
2021 | ||
2022 | if (evt.GetSetChecked()) | |
2023 | { | |
2024 | // make sure we aren't checking an item that can't be | |
2025 | if (item.kind != wxITEM_CHECK && item.kind != wxITEM_RADIO) | |
2026 | continue; | |
2027 | ||
2028 | bool is_checked = (item.state & wxAUI_BUTTON_STATE_CHECKED) ? true : false; | |
2029 | bool new_checked = evt.GetChecked(); | |
2030 | ||
2031 | if (new_checked != is_checked) | |
2032 | { | |
2033 | if (new_checked) | |
2034 | item.state |= wxAUI_BUTTON_STATE_CHECKED; | |
2035 | else | |
2036 | item.state &= ~wxAUI_BUTTON_STATE_CHECKED; | |
2037 | ||
2038 | need_refresh = true; | |
2039 | } | |
2040 | } | |
2041 | ||
2042 | } | |
2043 | } | |
2044 | ||
2045 | ||
2046 | if (need_refresh) | |
2047 | { | |
2048 | Refresh(false); | |
2049 | } | |
2050 | } | |
2051 | ||
2052 | ||
2053 | void wxAuiToolBar::OnSize(wxSizeEvent& WXUNUSED(evt)) | |
2054 | { | |
2055 | int x, y; | |
2056 | GetClientSize(&x, &y); | |
2057 | ||
2058 | if (x > y) | |
2059 | SetOrientation(wxHORIZONTAL); | |
2060 | else | |
2061 | SetOrientation(wxVERTICAL); | |
2062 | ||
2063 | if (((x >= y) && m_absolute_min_size.x > x) || | |
2064 | ((y > x) && m_absolute_min_size.y > y)) | |
2065 | { | |
2066 | // hide all flexible items | |
2067 | size_t i, count; | |
2068 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
2069 | { | |
2070 | wxAuiToolBarItem& item = m_items.Item(i); | |
2071 | if (item.sizer_item && item.proportion > 0 && item.sizer_item->IsShown()) | |
2072 | { | |
2073 | item.sizer_item->Show(false); | |
2074 | item.sizer_item->SetProportion(0); | |
2075 | } | |
2076 | } | |
2077 | } | |
2078 | else | |
2079 | { | |
2080 | // show all flexible items | |
2081 | size_t i, count; | |
2082 | for (i = 0, count = m_items.GetCount(); i < count; ++i) | |
2083 | { | |
2084 | wxAuiToolBarItem& item = m_items.Item(i); | |
2085 | if (item.sizer_item && item.proportion > 0 && !item.sizer_item->IsShown()) | |
2086 | { | |
2087 | item.sizer_item->Show(true); | |
2088 | item.sizer_item->SetProportion(item.proportion); | |
2089 | } | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | m_sizer->SetDimension(0, 0, x, y); | |
2094 | ||
2095 | Refresh(false); | |
2096 | Update(); | |
2097 | } | |
2098 | ||
2099 | ||
2100 | ||
2101 | void wxAuiToolBar::DoSetSize(int x, | |
2102 | int y, | |
2103 | int width, | |
2104 | int height, | |
2105 | int sizeFlags) | |
2106 | { | |
2107 | wxSize parent_size = GetParent()->GetClientSize(); | |
2108 | if (x + width > parent_size.x) | |
2109 | width = wxMax(0, parent_size.x - x); | |
2110 | if (y + height > parent_size.y) | |
2111 | height = wxMax(0, parent_size.y - y); | |
2112 | ||
2113 | wxWindow::DoSetSize(x, y, width, height, sizeFlags); | |
2114 | } | |
2115 | ||
2116 | ||
2117 | void wxAuiToolBar::OnIdle(wxIdleEvent& evt) | |
2118 | { | |
2119 | DoIdleUpdate(); | |
2120 | evt.Skip(); | |
2121 | } | |
2122 | ||
2123 | void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) | |
2124 | { | |
2125 | wxBufferedPaintDC dc(this); | |
2126 | wxRect cli_rect(wxPoint(0,0), GetClientSize()); | |
2127 | ||
2128 | ||
2129 | bool horizontal = true; | |
2130 | if (m_style & wxAUI_TB_VERTICAL) | |
2131 | horizontal = false; | |
2132 | ||
2133 | ||
2134 | m_art->DrawBackground(dc, this, cli_rect); | |
2135 | ||
2136 | int gripper_size = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE); | |
2137 | int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); | |
2138 | ||
2139 | // paint the gripper | |
2140 | if (gripper_size > 0 && m_gripper_sizer_item) | |
2141 | { | |
2142 | wxRect gripper_rect = m_gripper_sizer_item->GetRect(); | |
2143 | if (horizontal) | |
2144 | gripper_rect.width = gripper_size; | |
2145 | else | |
2146 | gripper_rect.height = gripper_size; | |
2147 | m_art->DrawGripper(dc, this, gripper_rect); | |
2148 | } | |
2149 | ||
2150 | // calculated how far we can draw items | |
2151 | int last_extent; | |
2152 | if (horizontal) | |
2153 | last_extent = cli_rect.width; | |
2154 | else | |
2155 | last_extent = cli_rect.height; | |
2156 | if (m_overflow_visible) | |
2157 | last_extent -= dropdown_size; | |
2158 | ||
2159 | // paint each individual tool | |
2160 | size_t i, count = m_items.GetCount(); | |
2161 | for (i = 0; i < count; ++i) | |
2162 | { | |
2163 | wxAuiToolBarItem& item = m_items.Item(i); | |
2164 | ||
2165 | if (!item.sizer_item) | |
2166 | continue; | |
2167 | ||
2168 | wxRect item_rect = item.sizer_item->GetRect(); | |
2169 | ||
2170 | ||
2171 | if ((horizontal && item_rect.x + item_rect.width >= last_extent) || | |
2172 | (!horizontal && item_rect.y + item_rect.height >= last_extent)) | |
2173 | { | |
2174 | break; | |
2175 | } | |
2176 | ||
2177 | if (item.kind == wxITEM_SEPARATOR) | |
2178 | { | |
2179 | // draw a separator | |
2180 | m_art->DrawSeparator(dc, this, item_rect); | |
2181 | } | |
2182 | else if (item.kind == wxITEM_LABEL) | |
2183 | { | |
2184 | // draw a text label only | |
2185 | m_art->DrawLabel(dc, this, item, item_rect); | |
2186 | } | |
2187 | else if (item.kind == wxITEM_NORMAL) | |
2188 | { | |
2189 | // draw a regular button or dropdown button | |
2190 | if (!item.dropdown) | |
2191 | m_art->DrawButton(dc, this, item, item_rect); | |
2192 | else | |
2193 | m_art->DrawDropDownButton(dc, this, item, item_rect); | |
2194 | } | |
2195 | else if (item.kind == wxITEM_CHECK) | |
2196 | { | |
2197 | // draw a toggle button | |
2198 | m_art->DrawButton(dc, this, item, item_rect); | |
2199 | } | |
2200 | else if (item.kind == wxITEM_CONTROL) | |
2201 | { | |
2202 | // draw the control's label | |
2203 | m_art->DrawControlLabel(dc, this, item, item_rect); | |
2204 | } | |
2205 | ||
2206 | // fire a signal to see if the item wants to be custom-rendered | |
2207 | OnCustomRender(dc, item, item_rect); | |
2208 | } | |
2209 | ||
2210 | // paint the overflow button | |
2211 | if (dropdown_size > 0 && m_overflow_sizer_item) | |
2212 | { | |
2213 | wxRect dropdown_rect = GetOverflowRect(); | |
2214 | m_art->DrawOverflowButton(dc, this, dropdown_rect, m_overflow_state); | |
2215 | } | |
2216 | } | |
2217 | ||
2218 | void wxAuiToolBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) | |
2219 | { | |
2220 | // empty | |
2221 | } | |
2222 | ||
2223 | void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) | |
2224 | { | |
2225 | wxRect cli_rect(wxPoint(0,0), GetClientSize()); | |
2226 | ||
2227 | if (m_gripper_sizer_item) | |
2228 | { | |
2229 | wxRect gripper_rect = m_gripper_sizer_item->GetRect(); | |
2230 | if (gripper_rect.Contains(evt.GetX(), evt.GetY())) | |
2231 | { | |
2232 | // find aui manager | |
2233 | wxAuiManager* manager = wxAuiManager::GetManager(this); | |
2234 | if (!manager) | |
2235 | return; | |
2236 | ||
2237 | int x_drag_offset = evt.GetX() - gripper_rect.GetX(); | |
2238 | int y_drag_offset = evt.GetY() - gripper_rect.GetY(); | |
2239 | ||
2240 | // gripper was clicked | |
2241 | manager->StartPaneDrag(this, wxPoint(x_drag_offset, y_drag_offset)); | |
2242 | return; | |
2243 | } | |
2244 | } | |
2245 | ||
2246 | if (m_overflow_sizer_item) | |
2247 | { | |
2248 | wxRect overflow_rect = GetOverflowRect(); | |
2249 | ||
2250 | if (m_art && | |
2251 | m_overflow_visible && | |
2252 | overflow_rect.Contains(evt.m_x, evt.m_y)) | |
2253 | { | |
2254 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, -1); | |
2255 | e.SetEventObject(this); | |
2256 | e.SetToolId(-1); | |
2257 | e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY())); | |
2258 | bool processed = ProcessEvent(e); | |
2259 | ||
2260 | if (processed) | |
2261 | { | |
2262 | DoIdleUpdate(); | |
2263 | } | |
2264 | else | |
2265 | { | |
2266 | size_t i, count; | |
2267 | wxAuiToolBarItemArray overflow_items; | |
2268 | ||
2269 | ||
2270 | // add custom overflow prepend items, if any | |
2271 | count = m_custom_overflow_prepend.GetCount(); | |
2272 | for (i = 0; i < count; ++i) | |
2273 | overflow_items.Add(m_custom_overflow_prepend[i]); | |
2274 | ||
2275 | // only show items that don't fit in the dropdown | |
2276 | count = m_items.GetCount(); | |
2277 | for (i = 0; i < count; ++i) | |
2278 | { | |
2279 | if (!GetToolFitsByIndex(i)) | |
2280 | overflow_items.Add(m_items[i]); | |
2281 | } | |
2282 | ||
2283 | // add custom overflow append items, if any | |
2284 | count = m_custom_overflow_append.GetCount(); | |
2285 | for (i = 0; i < count; ++i) | |
2286 | overflow_items.Add(m_custom_overflow_append[i]); | |
2287 | ||
2288 | int res = m_art->ShowDropDown(this, overflow_items); | |
2289 | m_overflow_state = 0; | |
2290 | Refresh(false); | |
2291 | if (res != -1) | |
2292 | { | |
2293 | wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res); | |
2294 | e.SetEventObject(this); | |
2295 | GetParent()->ProcessEvent(e); | |
2296 | } | |
2297 | } | |
2298 | ||
2299 | return; | |
2300 | } | |
2301 | } | |
2302 | ||
2303 | m_dragging = false; | |
2304 | m_action_pos = wxPoint(evt.GetX(), evt.GetY()); | |
2305 | m_action_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2306 | ||
2307 | if (m_action_item) | |
2308 | { | |
2309 | if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED) | |
2310 | { | |
2311 | m_action_pos = wxPoint(-1,-1); | |
2312 | m_action_item = NULL; | |
2313 | return; | |
2314 | } | |
2315 | ||
2316 | SetPressedItem(m_action_item); | |
2317 | ||
2318 | // fire the tool dropdown event | |
2319 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, m_action_item->id); | |
2320 | e.SetEventObject(this); | |
2321 | e.SetToolId(m_action_item->id); | |
2322 | e.SetDropDownClicked(false); | |
2323 | ||
2324 | int mouse_x = evt.GetX(); | |
2325 | wxRect rect = m_action_item->sizer_item->GetRect(); | |
2326 | ||
2327 | if (m_action_item->dropdown && | |
2328 | mouse_x >= (rect.x+rect.width-BUTTON_DROPDOWN_WIDTH-1) && | |
2329 | mouse_x < (rect.x+rect.width)) | |
2330 | { | |
2331 | e.SetDropDownClicked(true); | |
2332 | } | |
2333 | ||
2334 | e.SetClickPoint(evt.GetPosition()); | |
2335 | e.SetItemRect(rect); | |
2336 | ProcessEvent(e); | |
2337 | DoIdleUpdate(); | |
2338 | } | |
2339 | } | |
2340 | ||
2341 | void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt) | |
2342 | { | |
2343 | SetPressedItem(NULL); | |
2344 | ||
2345 | wxAuiToolBarItem* hit_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2346 | if (hit_item && !(hit_item->state & wxAUI_BUTTON_STATE_DISABLED)) | |
2347 | { | |
2348 | SetHoverItem(hit_item); | |
2349 | } | |
2350 | ||
2351 | ||
2352 | if (m_dragging) | |
2353 | { | |
2354 | // reset drag and drop member variables | |
2355 | m_dragging = false; | |
2356 | m_action_pos = wxPoint(-1,-1); | |
2357 | m_action_item = NULL; | |
2358 | return; | |
2359 | } | |
2360 | else | |
2361 | { | |
2362 | wxAuiToolBarItem* hit_item; | |
2363 | hit_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2364 | ||
2365 | if (m_action_item && hit_item == m_action_item) | |
2366 | { | |
2367 | UnsetToolTip(); | |
2368 | ||
2369 | if (hit_item->kind == wxITEM_CHECK) | |
2370 | { | |
2371 | bool toggle = false; | |
2372 | ||
2373 | if (m_action_item->state & wxAUI_BUTTON_STATE_CHECKED) | |
2374 | toggle = false; | |
2375 | else | |
2376 | toggle = true; | |
2377 | ||
2378 | ToggleTool(m_action_item->id, toggle); | |
2379 | ||
2380 | wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); | |
2381 | e.SetEventObject(this); | |
2382 | ProcessEvent(e); | |
2383 | DoIdleUpdate(); | |
2384 | } | |
2385 | else | |
2386 | { | |
2387 | wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); | |
2388 | e.SetEventObject(this); | |
2389 | ProcessEvent(e); | |
2390 | DoIdleUpdate(); | |
2391 | } | |
2392 | } | |
2393 | } | |
2394 | ||
2395 | // reset drag and drop member variables | |
2396 | m_dragging = false; | |
2397 | m_action_pos = wxPoint(-1,-1); | |
2398 | m_action_item = NULL; | |
2399 | } | |
2400 | ||
2401 | void wxAuiToolBar::OnRightDown(wxMouseEvent& evt) | |
2402 | { | |
2403 | wxRect cli_rect(wxPoint(0,0), GetClientSize()); | |
2404 | ||
2405 | if (m_gripper_sizer_item) | |
2406 | { | |
2407 | wxRect gripper_rect = m_gripper_sizer_item->GetRect(); | |
2408 | if (gripper_rect.Contains(evt.GetX(), evt.GetY())) | |
2409 | return; | |
2410 | } | |
2411 | ||
2412 | if (m_overflow_sizer_item) | |
2413 | { | |
2414 | int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); | |
2415 | if (dropdown_size > 0 && | |
2416 | evt.m_x > cli_rect.width - dropdown_size && | |
2417 | evt.m_y >= 0 && | |
2418 | evt.m_y < cli_rect.height && | |
2419 | m_art) | |
2420 | { | |
2421 | return; | |
2422 | } | |
2423 | } | |
2424 | ||
2425 | m_action_pos = wxPoint(evt.GetX(), evt.GetY()); | |
2426 | m_action_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2427 | ||
2428 | if (m_action_item) | |
2429 | { | |
2430 | if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED) | |
2431 | { | |
2432 | m_action_pos = wxPoint(-1,-1); | |
2433 | m_action_item = NULL; | |
2434 | return; | |
2435 | } | |
2436 | } | |
2437 | } | |
2438 | ||
2439 | void wxAuiToolBar::OnRightUp(wxMouseEvent& evt) | |
2440 | { | |
2441 | wxAuiToolBarItem* hit_item; | |
2442 | hit_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2443 | ||
2444 | if (m_action_item && hit_item == m_action_item) | |
2445 | { | |
2446 | if (hit_item->kind == wxITEM_NORMAL) | |
2447 | { | |
2448 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, m_action_item->id); | |
2449 | e.SetEventObject(this); | |
2450 | e.SetToolId(m_action_item->id); | |
2451 | e.SetClickPoint(m_action_pos); | |
2452 | ProcessEvent(e); | |
2453 | DoIdleUpdate(); | |
2454 | } | |
2455 | } | |
2456 | else | |
2457 | { | |
2458 | // right-clicked on the invalid area of the toolbar | |
2459 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, -1); | |
2460 | e.SetEventObject(this); | |
2461 | e.SetToolId(-1); | |
2462 | e.SetClickPoint(m_action_pos); | |
2463 | ProcessEvent(e); | |
2464 | DoIdleUpdate(); | |
2465 | } | |
2466 | ||
2467 | // reset member variables | |
2468 | m_action_pos = wxPoint(-1,-1); | |
2469 | m_action_item = NULL; | |
2470 | } | |
2471 | ||
2472 | void wxAuiToolBar::OnMiddleDown(wxMouseEvent& evt) | |
2473 | { | |
2474 | wxRect cli_rect(wxPoint(0,0), GetClientSize()); | |
2475 | ||
2476 | if (m_gripper_sizer_item) | |
2477 | { | |
2478 | wxRect gripper_rect = m_gripper_sizer_item->GetRect(); | |
2479 | if (gripper_rect.Contains(evt.GetX(), evt.GetY())) | |
2480 | return; | |
2481 | } | |
2482 | ||
2483 | if (m_overflow_sizer_item) | |
2484 | { | |
2485 | int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE); | |
2486 | if (dropdown_size > 0 && | |
2487 | evt.m_x > cli_rect.width - dropdown_size && | |
2488 | evt.m_y >= 0 && | |
2489 | evt.m_y < cli_rect.height && | |
2490 | m_art) | |
2491 | { | |
2492 | return; | |
2493 | } | |
2494 | } | |
2495 | ||
2496 | m_action_pos = wxPoint(evt.GetX(), evt.GetY()); | |
2497 | m_action_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2498 | ||
2499 | if (m_action_item) | |
2500 | { | |
2501 | if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED) | |
2502 | { | |
2503 | m_action_pos = wxPoint(-1,-1); | |
2504 | m_action_item = NULL; | |
2505 | return; | |
2506 | } | |
2507 | } | |
2508 | } | |
2509 | ||
2510 | void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt) | |
2511 | { | |
2512 | wxAuiToolBarItem* hit_item; | |
2513 | hit_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2514 | ||
2515 | if (m_action_item && hit_item == m_action_item) | |
2516 | { | |
2517 | if (hit_item->kind == wxITEM_NORMAL) | |
2518 | { | |
2519 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, m_action_item->id); | |
2520 | e.SetEventObject(this); | |
2521 | e.SetToolId(m_action_item->id); | |
2522 | e.SetClickPoint(m_action_pos); | |
2523 | ProcessEvent(e); | |
2524 | DoIdleUpdate(); | |
2525 | } | |
2526 | } | |
2527 | ||
2528 | // reset member variables | |
2529 | m_action_pos = wxPoint(-1,-1); | |
2530 | m_action_item = NULL; | |
2531 | } | |
2532 | ||
2533 | void wxAuiToolBar::OnMotion(wxMouseEvent& evt) | |
2534 | { | |
2535 | // start a drag event | |
2536 | if (!m_dragging && | |
2537 | m_action_item != NULL && | |
2538 | m_action_pos != wxPoint(-1,-1) && | |
2539 | abs(evt.m_x - m_action_pos.x) + abs(evt.m_y - m_action_pos.y) > 5) | |
2540 | { | |
2541 | UnsetToolTip(); | |
2542 | ||
2543 | m_dragging = true; | |
2544 | ||
2545 | wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId()); | |
2546 | e.SetEventObject(this); | |
2547 | e.SetToolId(m_action_item->id); | |
2548 | ProcessEvent(e); | |
2549 | DoIdleUpdate(); | |
2550 | return; | |
2551 | } | |
2552 | ||
2553 | wxAuiToolBarItem* hit_item = FindToolByPosition(evt.GetX(), evt.GetY()); | |
2554 | if (hit_item) | |
2555 | { | |
2556 | if (!(hit_item->state & wxAUI_BUTTON_STATE_DISABLED)) | |
2557 | SetHoverItem(hit_item); | |
2558 | else | |
2559 | SetHoverItem(NULL); | |
2560 | } | |
2561 | else | |
2562 | { | |
2563 | // no hit item, remove any hit item | |
2564 | SetHoverItem(hit_item); | |
2565 | } | |
2566 | ||
2567 | // figure out tooltips | |
2568 | wxAuiToolBarItem* packing_hit_item; | |
2569 | packing_hit_item = FindToolByPositionWithPacking(evt.GetX(), evt.GetY()); | |
2570 | if (packing_hit_item) | |
2571 | { | |
2572 | if (packing_hit_item != m_tip_item) | |
2573 | { | |
2574 | m_tip_item = packing_hit_item; | |
2575 | ||
2576 | if ( !packing_hit_item->short_help.empty() ) | |
2577 | SetToolTip(packing_hit_item->short_help); | |
2578 | else | |
2579 | UnsetToolTip(); | |
2580 | } | |
2581 | } | |
2582 | else | |
2583 | { | |
2584 | UnsetToolTip(); | |
2585 | m_tip_item = NULL; | |
2586 | } | |
2587 | ||
2588 | // if we've pressed down an item and we're hovering | |
2589 | // over it, make sure it's state is set to pressed | |
2590 | if (m_action_item) | |
2591 | { | |
2592 | if (m_action_item == hit_item) | |
2593 | SetPressedItem(m_action_item); | |
2594 | else | |
2595 | SetPressedItem(NULL); | |
2596 | } | |
2597 | ||
2598 | // figure out the dropdown button state (are we hovering or pressing it?) | |
2599 | RefreshOverflowState(); | |
2600 | } | |
2601 | ||
2602 | void wxAuiToolBar::OnLeaveWindow(wxMouseEvent& WXUNUSED(evt)) | |
2603 | { | |
2604 | RefreshOverflowState(); | |
2605 | SetHoverItem(NULL); | |
2606 | SetPressedItem(NULL); | |
2607 | ||
2608 | m_tip_item = NULL; | |
2609 | } | |
2610 | ||
2611 | ||
2612 | void wxAuiToolBar::OnSetCursor(wxSetCursorEvent& evt) | |
2613 | { | |
2614 | wxCursor cursor = wxNullCursor; | |
2615 | ||
2616 | if (m_gripper_sizer_item) | |
2617 | { | |
2618 | wxRect gripper_rect = m_gripper_sizer_item->GetRect(); | |
2619 | if (gripper_rect.Contains(evt.GetX(), evt.GetY())) | |
2620 | { | |
2621 | cursor = wxCursor(wxCURSOR_SIZING); | |
2622 | } | |
2623 | } | |
2624 | ||
2625 | evt.SetCursor(cursor); | |
2626 | } | |
2627 | ||
2628 | ||
2629 | #endif // wxUSE_AUI | |
2630 |