]> git.saurik.com Git - wxWidgets.git/blob - src/univ/toolbar.cpp
Missing #includes to allow wx/mac/carbon/tooltip.h be included first by user.
[wxWidgets.git] / src / univ / toolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/toolbar.cpp
3 // Purpose: implementation of wxToolBar for wxUniversal
4 // Author: Robert Roebling, Vadim Zeitlin (universalization)
5 // Modified by:
6 // Created: 20.02.02
7 // Id: $Id$
8 // Copyright: (c) 2001 Robert Roebling,
9 // (c) 2002 SciTech Software, Inc. (www.scitechsoft.com)
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // ============================================================================
14 // declarations
15 // ============================================================================
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #if wxUSE_TOOLBAR
29
30 #include "wx/toolbar.h"
31
32 #ifndef WX_PRECOMP
33 #include "wx/utils.h"
34 #include "wx/app.h"
35 #include "wx/log.h"
36 #include "wx/frame.h"
37 #endif
38
39 #include "wx/univ/renderer.h"
40
41 #include "wx/image.h"
42
43 // ----------------------------------------------------------------------------
44 // constants
45 // ----------------------------------------------------------------------------
46
47 // value meaning that m_widthSeparator is not initialized
48 static const wxCoord INVALID_WIDTH = wxDefaultCoord;
49
50 // ----------------------------------------------------------------------------
51 // wxToolBarTool: our implementation of wxToolBarToolBase
52 // ----------------------------------------------------------------------------
53
54 class WXDLLEXPORT wxToolBarTool : public wxToolBarToolBase
55 {
56 public:
57 wxToolBarTool(wxToolBar *tbar,
58 int id,
59 const wxString& label,
60 const wxBitmap& bmpNormal,
61 const wxBitmap& bmpDisabled,
62 wxItemKind kind,
63 wxObject *clientData,
64 const wxString& shortHelp,
65 const wxString& longHelp)
66 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
67 clientData, shortHelp, longHelp)
68 {
69 // no position yet
70 m_x =
71 m_y = wxDefaultCoord;
72 m_width =
73 m_height = 0;
74
75 // not pressed yet
76 m_isInverted = false;
77
78 // mouse not here yet
79 m_underMouse = false;
80 }
81
82 wxToolBarTool(wxToolBar *tbar, wxControl *control)
83 : wxToolBarToolBase(tbar, control)
84 {
85 // no position yet
86 m_x =
87 m_y = wxDefaultCoord;
88 m_width =
89 m_height = 0;
90
91 // not pressed yet
92 m_isInverted = false;
93
94 // mouse not here yet
95 m_underMouse = false;
96 }
97
98 // is this tool pressed, even temporarily? (this is different from being
99 // permanently toggled which is what IsToggled() returns)
100 bool IsPressed() const
101 { return CanBeToggled() ? IsToggled() != m_isInverted : m_isInverted; }
102
103 // are we temporarily pressed/unpressed?
104 bool IsInverted() const { return m_isInverted; }
105
106 // press the tool temporarily by inverting its toggle state
107 void Invert() { m_isInverted = !m_isInverted; }
108
109 // Set underMouse
110 void SetUnderMouse( bool under = true ) { m_underMouse = under; }
111 bool IsUnderMouse() { return m_underMouse; }
112
113 public:
114 // the tool position (for controls)
115 wxCoord m_x;
116 wxCoord m_y;
117 wxCoord m_width;
118 wxCoord m_height;
119
120 private:
121 // true if the tool is pressed
122 bool m_isInverted;
123
124 // true if the tool is under the mouse
125 bool m_underMouse;
126 };
127
128 // ============================================================================
129 // wxToolBar implementation
130 // ============================================================================
131
132 IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
133
134 // ----------------------------------------------------------------------------
135 // wxToolBar creation
136 // ----------------------------------------------------------------------------
137
138 void wxToolBar::Init()
139 {
140 // no tools yet
141 m_needsLayout = false;
142
143 // unknown widths for the tools and separators
144 m_widthSeparator = INVALID_WIDTH;
145
146 m_maxWidth =
147 m_maxHeight = 0;
148
149 wxRenderer *renderer = GetRenderer();
150
151 SetToolBitmapSize(renderer->GetToolBarButtonSize(&m_widthSeparator));
152 SetMargins(renderer->GetToolBarMargin());
153 }
154
155 bool wxToolBar::Create(wxWindow *parent,
156 wxWindowID id,
157 const wxPoint& pos,
158 const wxSize& size,
159 long style,
160 const wxString& name)
161 {
162 if ( !wxToolBarBase::Create(parent, id, pos, size, style,
163 wxDefaultValidator, name) )
164 {
165 return false;
166 }
167
168 CreateInputHandler(wxINP_HANDLER_TOOLBAR);
169
170 SetBestSize(size);
171
172 return true;
173 }
174
175 wxToolBar::~wxToolBar()
176 {
177 // Make sure the toolbar is removed from the parent.
178 SetSize(0,0);
179 }
180
181 void wxToolBar::SetMargins(int x, int y)
182 {
183 // This required for similar visual effects under
184 // native platforms and wxUniv.
185 wxToolBarBase::SetMargins( x + 3, y + 3 );
186 }
187
188 // ----------------------------------------------------------------------------
189 // wxToolBar tool-related methods
190 // ----------------------------------------------------------------------------
191
192 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
193 {
194 // check the "other" direction first: it must be inside the toolbar or we
195 // don't risk finding anything
196 if ( IsVertical() )
197 {
198 if ( x < 0 || x > m_maxWidth )
199 return NULL;
200
201 // we always use x, even for a vertical toolbar, this makes the code
202 // below simpler
203 x = y;
204 }
205 else // horizontal
206 {
207 if ( y < 0 || y > m_maxHeight )
208 return NULL;
209 }
210
211 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
212 node;
213 node = node->GetNext() )
214 {
215 wxToolBarToolBase *tool = node->GetData();
216 wxRect rectTool = GetToolRect(tool);
217
218 wxCoord startTool, endTool;
219 GetRectLimits(rectTool, &startTool, &endTool);
220
221 if ( x >= startTool && x <= endTool )
222 {
223 // don't return the separators from here, they don't accept any
224 // input anyhow
225 return tool->IsSeparator() ? NULL : tool;
226 }
227 }
228
229 return NULL;
230 }
231
232 void wxToolBar::SetToolShortHelp(int id, const wxString& help)
233 {
234 wxToolBarToolBase *tool = FindById(id);
235
236 wxCHECK_RET( tool, _T("SetToolShortHelp: no such tool") );
237
238 tool->SetShortHelp(help);
239 }
240
241 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
242 wxToolBarToolBase * WXUNUSED(tool))
243 {
244 // recalculate the toolbar geometry before redrawing it the next time
245 m_needsLayout = true;
246
247 // and ensure that we indeed are going to redraw
248 Refresh();
249
250 return true;
251 }
252
253 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos),
254 wxToolBarToolBase * WXUNUSED(tool))
255 {
256 // as above
257 m_needsLayout = true;
258
259 Refresh();
260
261 return true;
262 }
263
264 void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
265 {
266 // created disabled-state bitmap on demand
267 if ( !enable && !tool->GetDisabledBitmap().Ok() )
268 {
269 wxImage image( tool->GetNormalBitmap().ConvertToImage() );
270
271 // TODO: don't hardcode 180
272 unsigned char bg_red = 180;
273 unsigned char bg_green = 180;
274 unsigned char bg_blue = 180;
275
276 unsigned char mask_red = image.GetMaskRed();
277 unsigned char mask_green = image.GetMaskGreen();
278 unsigned char mask_blue = image.GetMaskBlue();
279
280 bool has_mask = image.HasMask();
281
282 int x,y;
283 for (y = 0; y < image.GetHeight(); y++)
284 {
285 for (x = 0; x < image.GetWidth(); x++)
286 {
287 unsigned char red = image.GetRed(x,y);
288 unsigned char green = image.GetGreen(x,y);
289 unsigned char blue = image.GetBlue(x,y);
290 if (!has_mask || red != mask_red || green != mask_green || blue != mask_blue)
291 {
292 red = (unsigned char)((((wxInt32) red - bg_red) >> 1) + bg_red);
293 green = (unsigned char)((((wxInt32) green - bg_green) >> 1) + bg_green);
294 blue = (unsigned char)((((wxInt32) blue - bg_blue) >> 1) + bg_blue);
295 image.SetRGB( x, y, red, green, blue );
296 }
297 }
298 }
299
300 for (y = 0; y < image.GetHeight(); y++)
301 {
302 for (x = y % 2; x < image.GetWidth(); x += 2)
303 {
304 unsigned char red = image.GetRed(x,y);
305 unsigned char green = image.GetGreen(x,y);
306 unsigned char blue = image.GetBlue(x,y);
307 if (!has_mask || red != mask_red || green != mask_green || blue != mask_blue)
308 {
309 red = (unsigned char)((((wxInt32) red - bg_red) >> 1) + bg_red);
310 green = (unsigned char)((((wxInt32) green - bg_green) >> 1) + bg_green);
311 blue = (unsigned char)((((wxInt32) blue - bg_blue) >> 1) + bg_blue);
312 image.SetRGB( x, y, red, green, blue );
313 }
314 }
315 }
316
317 tool->SetDisabledBitmap(image);
318 }
319
320 RefreshTool(tool);
321 }
322
323 void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool WXUNUSED(toggle))
324 {
325 // note that if we're called the tool did change state (the base class
326 // checks for it), so it's not necessary to check for this again here
327 RefreshTool(tool);
328 }
329
330 void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool WXUNUSED(toggle))
331 {
332 RefreshTool(tool);
333 }
334
335 wxToolBarToolBase *wxToolBar::CreateTool(int id,
336 const wxString& label,
337 const wxBitmap& bmpNormal,
338 const wxBitmap& bmpDisabled,
339 wxItemKind kind,
340 wxObject *clientData,
341 const wxString& shortHelp,
342 const wxString& longHelp)
343 {
344 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
345 clientData, shortHelp, longHelp);
346 }
347
348 wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
349 {
350 return new wxToolBarTool(this, control);
351 }
352
353 // ----------------------------------------------------------------------------
354 // wxToolBar geometry
355 // ----------------------------------------------------------------------------
356
357 wxRect wxToolBar::GetToolRect(wxToolBarToolBase *toolBase) const
358 {
359 const wxToolBarTool *tool = (wxToolBarTool *)toolBase;
360
361 wxRect rect;
362
363 wxCHECK_MSG( tool, rect, _T("GetToolRect: NULL tool") );
364
365 // ensure that we always have the valid tool position
366 if ( m_needsLayout )
367 {
368 wxConstCast(this, wxToolBar)->DoLayout();
369 }
370
371 rect.x = tool->m_x - m_xMargin;
372 rect.y = tool->m_y - m_yMargin;
373
374 if ( IsVertical() )
375 {
376 if (tool->IsButton())
377 {
378 rect.width = m_defaultWidth;
379 rect.height = m_defaultHeight;
380 }
381 else if (tool->IsSeparator())
382 {
383 rect.width = m_defaultWidth;
384 rect.height = m_widthSeparator;
385 }
386 else // control
387 {
388 rect.width = tool->m_width;
389 rect.height = tool->m_height;
390 }
391 }
392 else // horizontal
393 {
394 if (tool->IsButton())
395 {
396 rect.width = m_defaultWidth;
397 rect.height = m_defaultHeight;
398 }
399 else if (tool->IsSeparator())
400 {
401 rect.width = m_widthSeparator;
402 rect.height = m_defaultHeight;
403 }
404 else // control
405 {
406 rect.width = tool->m_width;
407 rect.height = tool->m_height;
408 }
409 }
410
411 rect.width += 2*m_xMargin;
412 rect.height += 2*m_yMargin;
413
414 return rect;
415 }
416
417 bool wxToolBar::Realize()
418 {
419 if ( !wxToolBarBase::Realize() )
420 return false;
421
422 m_needsLayout = true;
423 DoLayout();
424
425 SetBestSize(wxDefaultSize);
426
427 return true;
428 }
429
430 void wxToolBar::DoLayout()
431 {
432 wxASSERT_MSG( m_needsLayout, _T("why are we called?") );
433
434 m_needsLayout = false;
435
436 wxCoord x = m_xMargin,
437 y = m_yMargin;
438
439 const wxCoord widthTool = IsVertical() ? m_defaultHeight : m_defaultWidth;
440 wxCoord margin = IsVertical() ? m_xMargin : m_yMargin;
441 wxCoord *pCur = IsVertical() ? &y : &x;
442
443 // calculate the positions of all elements
444 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
445 node;
446 node = node->GetNext() )
447 {
448 wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
449
450 tool->m_x = x;
451 tool->m_y = y;
452
453 // TODO ugly number fiddling
454 if (tool->IsButton())
455 {
456 *pCur += widthTool;
457 }
458 else if (tool->IsSeparator())
459 {
460 *pCur += m_widthSeparator;
461 }
462 else if (!IsVertical()) // horizontal control
463 {
464 wxControl *control = tool->GetControl();
465 wxSize size = control->GetSize();
466 tool->m_y += (m_defaultHeight - size.y)/2;
467 tool->m_width = size.x;
468 tool->m_height = size.y;
469
470 *pCur += tool->m_width;
471 }
472 *pCur += margin;
473 }
474
475 // calculate the total toolbar size
476 wxCoord xMin = m_defaultWidth + 2*m_xMargin,
477 yMin = m_defaultHeight + 2*m_yMargin;
478
479 m_maxWidth = x < xMin ? xMin : x;
480 m_maxHeight = y < yMin ? yMin : y;
481 }
482
483 wxSize wxToolBar::DoGetBestClientSize() const
484 {
485 return wxSize(m_maxWidth, m_maxHeight);
486 }
487
488 void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
489 {
490 int old_width, old_height;
491 GetSize(&old_width, &old_height);
492
493 wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
494
495 // Correct width and height if needed.
496 if ( width == wxDefaultCoord || height == wxDefaultCoord )
497 {
498 int tmp_width, tmp_height;
499 GetSize(&tmp_width, &tmp_height);
500
501 if ( width == wxDefaultCoord )
502 width = tmp_width;
503 if ( height == wxDefaultCoord )
504 height = tmp_height;
505 }
506
507 // We must refresh the frame size when the toolbar changes size
508 // otherwise the toolbar can be shown incorrectly
509 if ( old_width != width || old_height != height )
510 {
511 // But before we send the size event check it
512 // we have a frame that is not being deleted.
513 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
514 if ( frame && !frame->IsBeingDeleted() )
515 {
516 frame->SendSizeEvent();
517 }
518 }
519 }
520
521 // ----------------------------------------------------------------------------
522 // wxToolBar drawing
523 // ----------------------------------------------------------------------------
524
525 void wxToolBar::RefreshTool(wxToolBarToolBase *tool)
526 {
527 RefreshRect(GetToolRect(tool));
528 }
529
530 void wxToolBar::GetRectLimits(const wxRect& rect,
531 wxCoord *start,
532 wxCoord *end) const
533 {
534 wxCHECK_RET( start && end, _T("NULL pointer in GetRectLimits") );
535
536 if ( IsVertical() )
537 {
538 *start = rect.GetTop();
539 *end = rect.GetBottom();
540 }
541 else // horizontal
542 {
543 *start = rect.GetLeft();
544 *end = rect.GetRight();
545 }
546 }
547
548 void wxToolBar::DoDraw(wxControlRenderer *renderer)
549 {
550 // prepare the variables used below
551 wxDC& dc = renderer->GetDC();
552 wxRenderer *rend = renderer->GetRenderer();
553 // dc.SetFont(GetFont()); -- uncomment when we support labels
554
555 // draw the border separating us from the menubar (if there is no menubar
556 // we probably shouldn't draw it?)
557 if ( !IsVertical() )
558 {
559 rend->DrawHorizontalLine(dc, 0, 0, GetClientSize().x);
560 }
561
562 // get the update rect and its limits depending on the orientation
563 wxRect rectUpdate = GetUpdateClientRect();
564 wxCoord start, end;
565 GetRectLimits(rectUpdate, &start, &end);
566
567 // and redraw all the tools intersecting it
568 for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
569 node;
570 node = node->GetNext() )
571 {
572 wxToolBarTool *tool = (wxToolBarTool*) node->GetData();
573 wxRect rectTool = GetToolRect(tool);
574 wxCoord startTool, endTool;
575 GetRectLimits(rectTool, &startTool, &endTool);
576
577 if ( endTool < start )
578 {
579 // we're still to the left of the area to redraw
580 continue;
581 }
582
583 if ( startTool > end )
584 {
585 // we're beyond the area to redraw, nothing left to do
586 break;
587 }
588
589 if (tool->IsSeparator() && !HasFlag(wxTB_FLAT))
590 {
591 // Draw separators only in flat mode
592 continue;
593 }
594
595 // deal with the flags
596 int flags = 0;
597
598 if ( tool->IsEnabled() )
599 {
600 // The toolbars without wxTB_FLAT don't react to the mouse hovering
601 if ( !HasFlag(wxTB_FLAT) || tool->IsUnderMouse() )
602 flags |= wxCONTROL_CURRENT;
603 }
604 else // disabled tool
605 {
606 flags |= wxCONTROL_DISABLED;
607 }
608
609 //if ( tool == m_toolCaptured )
610 // flags |= wxCONTROL_FOCUSED;
611
612 if ( tool->IsPressed() )
613 flags = wxCONTROL_PRESSED;
614
615 wxString label;
616 wxBitmap bitmap;
617 if ( !tool->IsSeparator() )
618 {
619 // label = tool->GetLabel();
620 bitmap = tool->GetBitmap();
621 }
622 //else: leave both the label and the bitmap invalid to draw a separator
623
624 if ( !tool->IsControl() )
625 {
626 rend->DrawToolBarButton(dc, label, bitmap, rectTool, flags, tool->GetStyle());
627 }
628 else // control
629 {
630 wxControl *control = tool->GetControl();
631 control->Move(tool->m_x, tool->m_y);
632 }
633 }
634 }
635
636 // ----------------------------------------------------------------------------
637 // wxToolBar actions
638 // ----------------------------------------------------------------------------
639
640 bool wxToolBar::PerformAction(const wxControlAction& action,
641 long numArg,
642 const wxString& strArg)
643 {
644 wxToolBarTool *tool = (wxToolBarTool*) FindById(numArg);
645 if (!tool)
646 return false;
647
648 if ( action == wxACTION_TOOLBAR_TOGGLE )
649 {
650 PerformAction( wxACTION_BUTTON_RELEASE, numArg );
651
652 PerformAction( wxACTION_BUTTON_CLICK, numArg );
653
654 // Write by Danny Raynor to change state again.
655 // Check button still pressed or not
656 if( tool->IsInverted() )
657 {
658 PerformAction( wxACTION_TOOLBAR_RELEASE, numArg );
659 }
660
661 // Set mouse leave toolbar button range (If still in the range,
662 // toolbar button would get focus again
663 PerformAction( wxACTION_TOOLBAR_LEAVE, numArg );
664 }
665 else if ( action == wxACTION_TOOLBAR_PRESS )
666 {
667 wxLogTrace(_T("toolbar"), _T("Button '%s' pressed."), tool->GetShortHelp().c_str());
668
669 tool->Invert();
670
671 RefreshTool( tool );
672 }
673 else if ( action == wxACTION_TOOLBAR_RELEASE )
674 {
675 wxLogTrace(_T("toolbar"), _T("Button '%s' released."), tool->GetShortHelp().c_str());
676
677 wxASSERT_MSG( tool->IsInverted(), _T("release unpressed button?") );
678
679 tool->Invert();
680
681 RefreshTool( tool );
682 }
683 else if ( action == wxACTION_TOOLBAR_CLICK )
684 {
685 bool isToggled;
686 if ( tool->CanBeToggled() )
687 {
688 tool->Toggle();
689
690 RefreshTool( tool );
691
692 isToggled = tool->IsToggled();
693 }
694 else // simple non-checkable tool
695 {
696 isToggled = false;
697 }
698 OnLeftClick( tool->GetId(), isToggled );
699 }
700 else if ( action == wxACTION_TOOLBAR_ENTER )
701 {
702 wxCHECK_MSG( tool, false, _T("no tool to enter?") );
703
704 if ( HasFlag(wxTB_FLAT) && tool->IsEnabled() )
705 {
706 tool->SetUnderMouse( true );
707
708 if ( !tool->IsToggled() )
709 RefreshTool( tool );
710 }
711 }
712 else if ( action == wxACTION_TOOLBAR_LEAVE )
713 {
714 wxCHECK_MSG( tool, false, _T("no tool to leave?") );
715
716 if ( HasFlag(wxTB_FLAT) && tool->IsEnabled() )
717 {
718 tool->SetUnderMouse( false );
719
720 if ( !tool->IsToggled() )
721 RefreshTool( tool );
722 }
723 }
724 else
725 return wxControl::PerformAction(action, numArg, strArg);
726
727 return true;
728 }
729
730 // ============================================================================
731 // wxStdToolbarInputHandler implementation
732 // ============================================================================
733
734 wxStdToolbarInputHandler::wxStdToolbarInputHandler(wxInputHandler *handler)
735 : wxStdInputHandler(handler)
736 {
737 m_winCapture = NULL;
738 m_toolCapture = NULL;
739 m_toolLast = NULL;
740 }
741
742 bool wxStdToolbarInputHandler::HandleKey(wxInputConsumer *consumer,
743 const wxKeyEvent& event,
744 bool pressed)
745 {
746 // TODO: when we have a current button we should allow the arrow
747 // keys to move it
748 return wxStdInputHandler::HandleKey(consumer, event, pressed);
749 }
750
751 bool wxStdToolbarInputHandler::HandleMouse(wxInputConsumer *consumer,
752 const wxMouseEvent& event)
753 {
754 wxToolBar *tbar = wxStaticCast(consumer->GetInputWindow(), wxToolBar);
755 wxToolBarToolBase *tool = tbar->FindToolForPosition(event.GetX(), event.GetY());
756
757 if ( event.Button(1) )
758 {
759
760 if ( event.LeftDown() || event.LeftDClick() )
761 {
762 if ( !tool || !tool->IsEnabled() )
763 return true;
764
765 m_winCapture = tbar;
766 m_winCapture->CaptureMouse();
767
768 m_toolCapture = tool;
769
770 consumer->PerformAction( wxACTION_BUTTON_PRESS, tool->GetId() );
771
772 return true;
773 }
774 else if ( event.LeftUp() )
775 {
776 if ( m_winCapture )
777 {
778 m_winCapture->ReleaseMouse();
779 m_winCapture = NULL;
780 }
781
782 if (m_toolCapture)
783 {
784 if ( tool == m_toolCapture )
785 consumer->PerformAction( wxACTION_BUTTON_TOGGLE, m_toolCapture->GetId() );
786 else
787 consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
788 }
789
790 m_toolCapture = NULL;
791
792 return true;
793 }
794 //else: don't do anything special about the double click
795 }
796
797 return wxStdInputHandler::HandleMouse(consumer, event);
798 }
799
800 bool wxStdToolbarInputHandler::HandleMouseMove(wxInputConsumer *consumer,
801 const wxMouseEvent& event)
802 {
803 if ( !wxStdInputHandler::HandleMouseMove(consumer, event) )
804 {
805 wxToolBar *tbar = wxStaticCast(consumer->GetInputWindow(), wxToolBar);
806
807 wxToolBarTool *tool;
808 if ( event.Leaving() )
809 {
810 // We cannot possibly be over a tool when
811 // leaving the toolbar
812 tool = NULL;
813 }
814 else
815 {
816 tool = (wxToolBarTool*) tbar->FindToolForPosition( event.GetX(), event.GetY() );
817 }
818
819 if (m_toolCapture)
820 {
821 // During capture we only care of the captured tool
822 if (tool && (tool != m_toolCapture))
823 tool = NULL;
824
825 if (tool == m_toolLast)
826 return true;
827
828 if (tool)
829 consumer->PerformAction( wxACTION_BUTTON_PRESS, m_toolCapture->GetId() );
830 else
831 consumer->PerformAction( wxACTION_BUTTON_RELEASE, m_toolCapture->GetId() );
832
833 m_toolLast = tool;
834 }
835 else
836 {
837 if (tool == m_toolLast)
838 return true;
839
840 if (m_toolLast)
841 {
842 // Leave old tool if any
843 consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolLast->GetId() );
844 }
845
846 if (tool)
847 {
848 // Enter new tool if any
849 consumer->PerformAction( wxACTION_TOOLBAR_ENTER, tool->GetId() );
850 }
851
852 m_toolLast = tool;
853 }
854
855 return true;
856 }
857
858 return false;
859 }
860
861 bool wxStdToolbarInputHandler::HandleFocus(wxInputConsumer *consumer,
862 const wxFocusEvent& WXUNUSED(event))
863 {
864 if ( m_toolCapture )
865 {
866 // We shouldn't be left with a highlighted button
867 consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
868 }
869
870 return true;
871 }
872
873 bool wxStdToolbarInputHandler::HandleActivation(wxInputConsumer *consumer,
874 bool activated)
875 {
876 if (m_toolCapture && !activated)
877 {
878 // We shouldn't be left with a highlighted button
879 consumer->PerformAction( wxACTION_TOOLBAR_LEAVE, m_toolCapture->GetId() );
880 }
881
882 return true;
883 }
884
885 #endif // wxUSE_TOOLBAR