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