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