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