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