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