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