]> git.saurik.com Git - wxWidgets.git/blame - src/aui/auibar.cpp
Don't use a cached best size if the window has a sizer
[wxWidgets.git] / src / aui / auibar.cpp
CommitLineData
1154f91b
BW
1///////////////////////////////////////////////////////////////////////////////
2
3// Name: src/aui/dockart.cpp
4// Purpose: wxaui: wx advanced user interface - docking window manager
5// Author: Benjamin I. Williams
6// Modified by:
7// Created: 2005-05-17
054f177b 8// RCS-ID: $Id$
1154f91b
BW
9// Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
10// Licence: wxWindows Library Licence, Version 3.1
11///////////////////////////////////////////////////////////////////////////////
12
13// ============================================================================
14// declarations
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_AUI
28
29#include "wx/statline.h"
30#include "wx/dcbuffer.h"
31#include "wx/sizer.h"
32#include "wx/image.h"
33#include "wx/settings.h"
34#include "wx/menu.h"
35
36#include "wx/aui/auibar.h"
37#include "wx/aui/framemanager.h"
38
eecf97a5
VZ
39#ifdef __WXMAC__
40#include "wx/osx/private.h"
c21febdb
SC
41// for themeing support
42#include <Carbon/Carbon.h>
1154f91b
BW
43#endif
44
45#include "wx/arrimpl.cpp"
46WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray)
47
48
3c778901
VZ
49wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEvent )
50wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, wxAuiToolBarEvent )
51wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEvent )
52wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, wxAuiToolBarEvent )
53wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEvent )
1154f91b
BW
54
55
56IMPLEMENT_CLASS(wxAuiToolBar, wxControl)
57IMPLEMENT_DYNAMIC_CLASS(wxAuiToolBarEvent, wxEvent)
58
59
60// missing wxITEM_* items
61enum
62{
63 wxITEM_CONTROL = wxITEM_MAX,
64 wxITEM_LABEL,
65 wxITEM_SPACER
66};
67
68const int BUTTON_DROPDOWN_WIDTH = 10;
69
70
71wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
72 const wxColour& color);
73
eecf97a5 74unsigned char wxAuiBlendColour(unsigned char fg, unsigned char bg, double alpha);
1154f91b
BW
75wxColor wxAuiStepColour(const wxColor& c, int percent);
76
77static wxBitmap MakeDisabledBitmap(wxBitmap& bmp)
78{
79 wxImage image = bmp.ConvertToImage();
eecf97a5 80
1154f91b
BW
81 int mr, mg, mb;
82 mr = image.GetMaskRed();
83 mg = image.GetMaskGreen();
84 mb = image.GetMaskBlue();
85
86 unsigned char* data = image.GetData();
87 int width = image.GetWidth();
88 int height = image.GetHeight();
89 bool has_mask = image.HasMask();
90
91 for (int y = height-1; y >= 0; --y)
92 {
93 for (int x = width-1; x >= 0; --x)
94 {
95 data = image.GetData() + (y*(width*3))+(x*3);
96 unsigned char* r = data;
97 unsigned char* g = data+1;
98 unsigned char* b = data+2;
99
100 if (has_mask && *r == mr && *g == mg && *b == mb)
101 continue;
102
eecf97a5
VZ
103 *r = wxAuiBlendColour(*r, 255, 0.4);
104 *g = wxAuiBlendColour(*g, 255, 0.4);
105 *b = wxAuiBlendColour(*b, 255, 0.4);
1154f91b
BW
106 }
107 }
108
109 return wxBitmap(image);
110}
111
112static wxColor GetBaseColor()
113{
114
eecf97a5
VZ
115#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
116 wxColor base_colour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground));
1154f91b 117#else
93dcd337 118 wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
1154f91b
BW
119#endif
120
121 // the base_colour is too pale to use as our base colour,
122 // so darken it a bit --
93dcd337
BW
123 if ((255-base_colour.Red()) +
124 (255-base_colour.Green()) +
125 (255-base_colour.Blue()) < 60)
1154f91b 126 {
93dcd337 127 base_colour = wxAuiStepColour(base_colour, 92);
1154f91b
BW
128 }
129
93dcd337 130 return base_colour;
1154f91b
BW
131}
132
133
134
135class ToolbarCommandCapture : public wxEvtHandler
136{
137public:
138
139 ToolbarCommandCapture() { m_last_id = 0; }
140 int GetCommandId() const { return m_last_id; }
141
142 bool ProcessEvent(wxEvent& evt)
143 {
144 if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED)
145 {
146 m_last_id = evt.GetId();
147 return true;
148 }
149
150 if (GetNextHandler())
151 return GetNextHandler()->ProcessEvent(evt);
152
153 return false;
154 }
155
156private:
157 int m_last_id;
158};
159
160
161
eecf97a5
VZ
162static const unsigned char
163 DISABLED_TEXT_GREY_HUE = wxAuiBlendColour(0, 255, 0.4);
164const wxColour DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE,
165 DISABLED_TEXT_GREY_HUE,
166 DISABLED_TEXT_GREY_HUE);
1154f91b
BW
167
168wxAuiDefaultToolBarArt::wxAuiDefaultToolBarArt()
169{
170 m_base_colour = GetBaseColor();
171
172 m_flags = 0;
173 m_text_orientation = wxAUI_TBTOOL_TEXT_BOTTOM;
174 m_highlight_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
eecf97a5 175
1154f91b
BW
176 m_separator_size = 7;
177 m_gripper_size = 7;
178 m_overflow_size = 16;
179
180 wxColor darker1_colour = wxAuiStepColour(m_base_colour, 85);
181 wxColor darker2_colour = wxAuiStepColour(m_base_colour, 75);
182 wxColor darker3_colour = wxAuiStepColour(m_base_colour, 60);
183 wxColor darker4_colour = wxAuiStepColour(m_base_colour, 50);
184 wxColor darker5_colour = wxAuiStepColour(m_base_colour, 40);
185
186 m_gripper_pen1 = wxPen(darker5_colour);
187 m_gripper_pen2 = wxPen(darker3_colour);
188 m_gripper_pen3 = *wxWHITE_PEN;
eecf97a5 189
1154f91b
BW
190 static unsigned char button_dropdown_bits[] = { 0xe0, 0xf1, 0xfb };
191 static unsigned char overflow_bits[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
eecf97a5 192
1154f91b
BW
193 m_button_dropdown_bmp = wxAuiBitmapFromBits(button_dropdown_bits, 5, 3,
194 *wxBLACK);
195 m_disabled_button_dropdown_bmp = wxAuiBitmapFromBits(
196 button_dropdown_bits, 5, 3,
197 wxColor(128,128,128));
198 m_overflow_bmp = wxAuiBitmapFromBits(overflow_bits, 7, 6, *wxBLACK);
199 m_disabled_overflow_bmp = wxAuiBitmapFromBits(overflow_bits, 7, 6, wxColor(128,128,128));
200
201 m_font = *wxNORMAL_FONT;
202}
203
204wxAuiDefaultToolBarArt::~wxAuiDefaultToolBarArt()
205{
206 m_font = *wxNORMAL_FONT;
207}
208
209
210wxAuiToolBarArt* wxAuiDefaultToolBarArt::Clone()
211{
212 return static_cast<wxAuiToolBarArt*>(new wxAuiDefaultToolBarArt);
213}
214
215void wxAuiDefaultToolBarArt::SetFlags(unsigned int flags)
216{
217 m_flags = flags;
218}
219
220void wxAuiDefaultToolBarArt::SetFont(const wxFont& font)
221{
222 m_font = font;
223}
224
225void wxAuiDefaultToolBarArt::SetTextOrientation(int orientation)
226{
227 m_text_orientation = orientation;
228}
229
230void wxAuiDefaultToolBarArt::DrawBackground(
231 wxDC& dc,
232 wxWindow* WXUNUSED(wnd),
233 const wxRect& _rect)
234{
235 wxRect rect = _rect;
236 rect.height++;
237 wxColour start_colour = wxAuiStepColour(m_base_colour, 150);
238 wxColour end_colour = wxAuiStepColour(m_base_colour, 90);
239 dc.GradientFillLinear(rect, start_colour, end_colour, wxSOUTH);
240}
241
242void wxAuiDefaultToolBarArt::DrawLabel(
243 wxDC& dc,
244 wxWindow* WXUNUSED(wnd),
245 const wxAuiToolBarItem& item,
246 const wxRect& rect)
247{
248 dc.SetFont(m_font);
249 dc.SetTextForeground(*wxBLACK);
250
251 // we only care about the text height here since the text
252 // will get cropped based on the width of the item
253 int text_width = 0, text_height = 0;
254 dc.GetTextExtent(wxT("ABCDHgj"), &text_width, &text_height);
255
256 // set the clipping region
257 wxRect clip_rect = rect;
258 clip_rect.width -= 1;
259 dc.SetClippingRegion(clip_rect);
260
261 int text_x, text_y;
262 text_x = rect.x + 1;
263 text_y = rect.y + (rect.height-text_height)/2;
e42f2c16 264 dc.DrawText(item.GetLabel(), text_x, text_y);
1154f91b
BW
265 dc.DestroyClippingRegion();
266}
267
268
269void wxAuiDefaultToolBarArt::DrawButton(
270 wxDC& dc,
271 wxWindow* WXUNUSED(wnd),
272 const wxAuiToolBarItem& item,
273 const wxRect& rect)
274{
275 int text_width = 0, text_height = 0;
eecf97a5 276
1154f91b
BW
277 if (m_flags & wxAUI_TB_TEXT)
278 {
279 dc.SetFont(m_font);
eecf97a5 280
1154f91b
BW
281 int tx, ty;
282
283 dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height);
284 text_width = 0;
e42f2c16 285 dc.GetTextExtent(item.GetLabel(), &text_width, &ty);
1154f91b
BW
286 }
287
288 int bmp_x = 0, bmp_y = 0;
289 int text_x = 0, text_y = 0;
eecf97a5 290
1154f91b
BW
291 if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM)
292 {
293 bmp_x = rect.x +
294 (rect.width/2) -
e42f2c16 295 (item.GetBitmap().GetWidth()/2);
eecf97a5 296
1154f91b
BW
297 bmp_y = rect.y +
298 ((rect.height-text_height)/2) -
e42f2c16 299 (item.GetBitmap().GetHeight()/2);
eecf97a5 300
1154f91b
BW
301 text_x = rect.x + (rect.width/2) - (text_width/2) + 1;
302 text_y = rect.y + rect.height - text_height - 1;
303 }
8b385bf8 304 else if (m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT)
1154f91b
BW
305 {
306 bmp_x = rect.x + 3;
eecf97a5 307
1154f91b
BW
308 bmp_y = rect.y +
309 (rect.height/2) -
e42f2c16 310 (item.GetBitmap().GetHeight()/2);
eecf97a5 311
e42f2c16 312 text_x = bmp_x + 3 + item.GetBitmap().GetWidth();
1154f91b
BW
313 text_y = rect.y +
314 (rect.height/2) -
315 (text_height/2);
316 }
317
318
e42f2c16 319 if (!(item.GetState() & wxAUI_BUTTON_STATE_DISABLED))
1154f91b 320 {
e42f2c16 321 if (item.GetState() & wxAUI_BUTTON_STATE_PRESSED)
1154f91b
BW
322 {
323 dc.SetPen(wxPen(m_highlight_colour));
324 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 150)));
325 dc.DrawRectangle(rect);
326 }
e42f2c16 327 else if ((item.GetState() & wxAUI_BUTTON_STATE_HOVER) || item.IsSticky())
1154f91b
BW
328 {
329 dc.SetPen(wxPen(m_highlight_colour));
330 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170)));
eecf97a5 331
1154f91b
BW
332 // draw an even lighter background for checked item hovers (since
333 // the hover background is the same color as the check background)
e42f2c16 334 if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED)
1154f91b 335 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 180)));
eecf97a5 336
1154f91b
BW
337 dc.DrawRectangle(rect);
338 }
e42f2c16 339 else if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED)
1154f91b
BW
340 {
341 // it's important to put this code in an else statment after the
342 // hover, otherwise hovers won't draw properly for checked items
343 dc.SetPen(wxPen(m_highlight_colour));
344 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170)));
345 dc.DrawRectangle(rect);
346 }
347 }
348
349 wxBitmap bmp;
e42f2c16
BW
350 if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
351 bmp = item.GetDisabledBitmap();
8b385bf8 352 else
e42f2c16 353 bmp = item.GetBitmap();
eecf97a5 354
1154f91b
BW
355 if (!bmp.IsOk())
356 return;
eecf97a5 357
1154f91b
BW
358 dc.DrawBitmap(bmp, bmp_x, bmp_y, true);
359
360 // set the item's text color based on if it is disabled
361 dc.SetTextForeground(*wxBLACK);
e42f2c16 362 if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
1154f91b 363 dc.SetTextForeground(DISABLED_TEXT_COLOR);
eecf97a5 364
e42f2c16 365 if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
1154f91b 366 {
e42f2c16 367 dc.DrawText(item.GetLabel(), text_x, text_y);
1154f91b
BW
368 }
369}
370
371
372void wxAuiDefaultToolBarArt::DrawDropDownButton(
373 wxDC& dc,
374 wxWindow* WXUNUSED(wnd),
375 const wxAuiToolBarItem& item,
376 const wxRect& rect)
377{
378 int text_width = 0, text_height = 0, text_x = 0, text_y = 0;
379 int bmp_x = 0, bmp_y = 0, dropbmp_x = 0, dropbmp_y = 0;
eecf97a5 380
1154f91b
BW
381 wxRect button_rect = wxRect(rect.x,
382 rect.y,
383 rect.width-BUTTON_DROPDOWN_WIDTH,
384 rect.height);
385 wxRect dropdown_rect = wxRect(rect.x+rect.width-BUTTON_DROPDOWN_WIDTH-1,
386 rect.y,
387 BUTTON_DROPDOWN_WIDTH+1,
388 rect.height);
eecf97a5 389
1154f91b
BW
390 if (m_flags & wxAUI_TB_TEXT)
391 {
392 dc.SetFont(m_font);
eecf97a5 393
1154f91b
BW
394 int tx, ty;
395 if (m_flags & wxAUI_TB_TEXT)
396 {
397 dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height);
398 text_width = 0;
eecf97a5
VZ
399 }
400
e42f2c16 401 dc.GetTextExtent(item.GetLabel(), &text_width, &ty);
1154f91b
BW
402 }
403
404
eecf97a5 405
1154f91b
BW
406 dropbmp_x = dropdown_rect.x +
407 (dropdown_rect.width/2) -
408 (m_button_dropdown_bmp.GetWidth()/2);
409 dropbmp_y = dropdown_rect.y +
410 (dropdown_rect.height/2) -
411 (m_button_dropdown_bmp.GetHeight()/2);
eecf97a5
VZ
412
413
1154f91b
BW
414 if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM)
415 {
416 bmp_x = button_rect.x +
417 (button_rect.width/2) -
e42f2c16 418 (item.GetBitmap().GetWidth()/2);
1154f91b
BW
419 bmp_y = button_rect.y +
420 ((button_rect.height-text_height)/2) -
e42f2c16 421 (item.GetBitmap().GetHeight()/2);
eecf97a5 422
1154f91b
BW
423 text_x = rect.x + (rect.width/2) - (text_width/2) + 1;
424 text_y = rect.y + rect.height - text_height - 1;
425 }
8b385bf8 426 else if (m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT)
1154f91b
BW
427 {
428 bmp_x = rect.x + 3;
eecf97a5 429
1154f91b
BW
430 bmp_y = rect.y +
431 (rect.height/2) -
e42f2c16 432 (item.GetBitmap().GetHeight()/2);
eecf97a5 433
e42f2c16 434 text_x = bmp_x + 3 + item.GetBitmap().GetWidth();
1154f91b
BW
435 text_y = rect.y +
436 (rect.height/2) -
437 (text_height/2);
438 }
eecf97a5
VZ
439
440
e42f2c16 441 if (item.GetState() & wxAUI_BUTTON_STATE_PRESSED)
1154f91b
BW
442 {
443 dc.SetPen(wxPen(m_highlight_colour));
444 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 140)));
445 dc.DrawRectangle(button_rect);
446 dc.DrawRectangle(dropdown_rect);
447 }
e42f2c16
BW
448 else if (item.GetState() & wxAUI_BUTTON_STATE_HOVER ||
449 item.IsSticky())
1154f91b
BW
450 {
451 dc.SetPen(wxPen(m_highlight_colour));
452 dc.SetBrush(wxBrush(wxAuiStepColour(m_highlight_colour, 170)));
453 dc.DrawRectangle(button_rect);
454 dc.DrawRectangle(dropdown_rect);
455 }
456
457 wxBitmap bmp;
458 wxBitmap dropbmp;
e42f2c16 459 if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
1154f91b 460 {
e42f2c16 461 bmp = item.GetDisabledBitmap();
1154f91b
BW
462 dropbmp = m_disabled_button_dropdown_bmp;
463 }
8b385bf8 464 else
1154f91b 465 {
e42f2c16 466 bmp = item.GetBitmap();
1154f91b
BW
467 dropbmp = m_button_dropdown_bmp;
468 }
eecf97a5 469
1154f91b
BW
470 if (!bmp.IsOk())
471 return;
eecf97a5 472
1154f91b
BW
473 dc.DrawBitmap(bmp, bmp_x, bmp_y, true);
474 dc.DrawBitmap(dropbmp, dropbmp_x, dropbmp_y, true);
475
476 // set the item's text color based on if it is disabled
477 dc.SetTextForeground(*wxBLACK);
e42f2c16 478 if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
1154f91b 479 dc.SetTextForeground(DISABLED_TEXT_COLOR);
eecf97a5 480
e42f2c16 481 if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
1154f91b 482 {
e42f2c16 483 dc.DrawText(item.GetLabel(), text_x, text_y);
1154f91b
BW
484 }
485}
486
487void wxAuiDefaultToolBarArt::DrawControlLabel(
488 wxDC& dc,
489 wxWindow* WXUNUSED(wnd),
490 const wxAuiToolBarItem& item,
491 const wxRect& rect)
492{
493 if (!(m_flags & wxAUI_TB_TEXT))
494 return;
495
496 if (m_text_orientation != wxAUI_TBTOOL_TEXT_BOTTOM)
497 return;
eecf97a5 498
1154f91b
BW
499 int text_x = 0, text_y = 0;
500 int text_width = 0, text_height = 0;
501
502 dc.SetFont(m_font);
eecf97a5 503
1154f91b
BW
504 int tx, ty;
505 if (m_flags & wxAUI_TB_TEXT)
506 {
507 dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height);
508 text_width = 0;
eecf97a5
VZ
509 }
510
e42f2c16 511 dc.GetTextExtent(item.GetLabel(), &text_width, &ty);
eecf97a5 512
1154f91b
BW
513 // don't draw the label if it is wider than the item width
514 if (text_width > rect.width)
515 return;
eecf97a5 516
1154f91b
BW
517 // set the label's text color
518 dc.SetTextForeground(*wxBLACK);
eecf97a5 519
1154f91b
BW
520 text_x = rect.x + (rect.width/2) - (text_width/2) + 1;
521 text_y = rect.y + rect.height - text_height - 1;
eecf97a5 522
e42f2c16 523 if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
1154f91b 524 {
e42f2c16 525 dc.DrawText(item.GetLabel(), text_x, text_y);
1154f91b
BW
526 }
527}
528
529wxSize wxAuiDefaultToolBarArt::GetLabelSize(
530 wxDC& dc,
531 wxWindow* WXUNUSED(wnd),
532 const wxAuiToolBarItem& item)
533{
534 dc.SetFont(m_font);
535
536 // get label's height
537 int width = 0, height = 0;
538 dc.GetTextExtent(wxT("ABCDHgj"), &width, &height);
539
540 // get item's width
e42f2c16 541 width = item.GetMinSize().GetWidth();
eecf97a5 542
1154f91b
BW
543 return wxSize(width, height);
544}
545
546wxSize wxAuiDefaultToolBarArt::GetToolSize(
547 wxDC& dc,
548 wxWindow* WXUNUSED(wnd),
549 const wxAuiToolBarItem& item)
550{
e42f2c16 551 if (!item.GetBitmap().IsOk() && !(m_flags & wxAUI_TB_TEXT))
1154f91b 552 return wxSize(16,16);
eecf97a5 553
e42f2c16
BW
554 int width = item.GetBitmap().GetWidth();
555 int height = item.GetBitmap().GetHeight();
eecf97a5 556
1154f91b
BW
557 if (m_flags & wxAUI_TB_TEXT)
558 {
559 dc.SetFont(m_font);
560 int tx, ty;
eecf97a5 561
1154f91b
BW
562 if (m_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM)
563 {
564 dc.GetTextExtent(wxT("ABCDHgj"), &tx, &ty);
565 height += ty;
eecf97a5 566
e42f2c16 567 if ( !item.GetLabel().empty() )
1154f91b 568 {
e42f2c16 569 dc.GetTextExtent(item.GetLabel(), &tx, &ty);
1154f91b
BW
570 width = wxMax(width, tx+6);
571 }
572 }
8b385bf8 573 else if ( m_text_orientation == wxAUI_TBTOOL_TEXT_RIGHT &&
e42f2c16 574 !item.GetLabel().empty() )
1154f91b
BW
575 {
576 width += 3; // space between left border and bitmap
577 width += 3; // space between bitmap and text
eecf97a5 578
e42f2c16 579 if ( !item.GetLabel().empty() )
1154f91b 580 {
e42f2c16 581 dc.GetTextExtent(item.GetLabel(), &tx, &ty);
1154f91b
BW
582 width += tx;
583 height = wxMax(height, ty);
584 }
585 }
eecf97a5 586 }
1154f91b
BW
587
588 // if the tool has a dropdown button, add it to the width
e42f2c16 589 if (item.HasDropDown())
1154f91b 590 width += (BUTTON_DROPDOWN_WIDTH+4);
eecf97a5 591
1154f91b
BW
592 return wxSize(width, height);
593}
594
595void wxAuiDefaultToolBarArt::DrawSeparator(
596 wxDC& dc,
597 wxWindow* WXUNUSED(wnd),
598 const wxRect& _rect)
599{
600 bool horizontal = true;
601 if (m_flags & wxAUI_TB_VERTICAL)
602 horizontal = false;
eecf97a5 603
1154f91b 604 wxRect rect = _rect;
eecf97a5 605
1154f91b
BW
606 if (horizontal)
607 {
608 rect.x += (rect.width/2);
609 rect.width = 1;
610 int new_height = (rect.height*3)/4;
611 rect.y += (rect.height/2) - (new_height/2);
612 rect.height = new_height;
613 }
8b385bf8 614 else
1154f91b
BW
615 {
616 rect.y += (rect.height/2);
617 rect.height = 1;
618 int new_width = (rect.width*3)/4;
619 rect.x += (rect.width/2) - (new_width/2);
620 rect.width = new_width;
621 }
eecf97a5 622
1154f91b
BW
623 wxColour start_colour = wxAuiStepColour(m_base_colour, 80);
624 wxColour end_colour = wxAuiStepColour(m_base_colour, 80);
625 dc.GradientFillLinear(rect, start_colour, end_colour, horizontal ? wxSOUTH : wxEAST);
626}
eecf97a5 627
1154f91b
BW
628void wxAuiDefaultToolBarArt::DrawGripper(wxDC& dc,
629 wxWindow* WXUNUSED(wnd),
630 const wxRect& rect)
631{
632 int i = 0;
633 while (1)
634 {
635 int x, y;
eecf97a5 636
1154f91b
BW
637 if (m_flags & wxAUI_TB_VERTICAL)
638 {
639 x = rect.x + (i*4) + 5;
640 y = rect.y + 3;
641 if (x > rect.GetWidth()-5)
642 break;
643 }
8b385bf8 644 else
1154f91b
BW
645 {
646 x = rect.x + 3;
647 y = rect.y + (i*4) + 5;
648 if (y > rect.GetHeight()-5)
649 break;
650 }
eecf97a5 651
1154f91b
BW
652 dc.SetPen(m_gripper_pen1);
653 dc.DrawPoint(x, y);
654 dc.SetPen(m_gripper_pen2);
655 dc.DrawPoint(x, y+1);
656 dc.DrawPoint(x+1, y);
657 dc.SetPen(m_gripper_pen3);
658 dc.DrawPoint(x+2, y+1);
659 dc.DrawPoint(x+2, y+2);
660 dc.DrawPoint(x+1, y+2);
661
662 i++;
663 }
664
665}
eecf97a5 666
1154f91b
BW
667void wxAuiDefaultToolBarArt::DrawOverflowButton(wxDC& dc,
668 wxWindow* wnd,
669 const wxRect& rect,
670 int state)
671{
672 if (state & wxAUI_BUTTON_STATE_HOVER ||
673 state & wxAUI_BUTTON_STATE_PRESSED)
674 {
675 wxRect cli_rect = wnd->GetClientRect();
676 wxColor light_gray_bg = wxAuiStepColour(m_highlight_colour, 170);
eecf97a5 677
1154f91b
BW
678 if (m_flags & wxAUI_TB_VERTICAL)
679 {
680 dc.SetPen(wxPen(m_highlight_colour));
681 dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
682 dc.SetPen(wxPen(light_gray_bg));
683 dc.SetBrush(wxBrush(light_gray_bg));
684 dc.DrawRectangle(rect.x, rect.y+1, rect.width, rect.height);
685 }
686 else
687 {
688 dc.SetPen(wxPen(m_highlight_colour));
689 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height);
690 dc.SetPen(wxPen(light_gray_bg));
691 dc.SetBrush(wxBrush(light_gray_bg));
692 dc.DrawRectangle(rect.x+1, rect.y, rect.width, rect.height);
693 }
694 }
695
696 int x = rect.x+1+(rect.width-m_overflow_bmp.GetWidth())/2;
697 int y = rect.y+1+(rect.height-m_overflow_bmp.GetHeight())/2;
698 dc.DrawBitmap(m_overflow_bmp, x, y, true);
699}
700
701int wxAuiDefaultToolBarArt::GetElementSize(int element_id)
702{
703 switch (element_id)
704 {
705 case wxAUI_TBART_SEPARATOR_SIZE: return m_separator_size;
706 case wxAUI_TBART_GRIPPER_SIZE: return m_gripper_size;
707 case wxAUI_TBART_OVERFLOW_SIZE: return m_overflow_size;
708 default: return 0;
709 }
710}
711
712void wxAuiDefaultToolBarArt::SetElementSize(int element_id, int size)
713{
714 switch (element_id)
715 {
716 case wxAUI_TBART_SEPARATOR_SIZE: m_separator_size = size;
717 case wxAUI_TBART_GRIPPER_SIZE: m_gripper_size = size;
718 case wxAUI_TBART_OVERFLOW_SIZE: m_overflow_size = size;
719 }
720}
721
722int wxAuiDefaultToolBarArt::ShowDropDown(wxWindow* wnd,
723 const wxAuiToolBarItemArray& items)
724{
725 wxMenu menuPopup;
726
727 size_t items_added = 0;
eecf97a5 728
1154f91b
BW
729 size_t i, count = items.GetCount();
730 for (i = 0; i < count; ++i)
731 {
732 wxAuiToolBarItem& item = items.Item(i);
eecf97a5 733
e42f2c16 734 if (item.GetKind() == wxITEM_NORMAL)
1154f91b 735 {
e42f2c16 736 wxString text = item.GetShortHelp();
1154f91b 737 if (text.empty())
e42f2c16 738 text = item.GetLabel();
eecf97a5 739
1154f91b
BW
740 if (text.empty())
741 text = wxT(" ");
eecf97a5 742
e42f2c16 743 wxMenuItem* m = new wxMenuItem(&menuPopup, item.GetId(), text, item.GetShortHelp());
1154f91b 744
e42f2c16 745 m->SetBitmap(item.GetBitmap());
1154f91b
BW
746 menuPopup.Append(m);
747 items_added++;
748 }
e42f2c16 749 else if (item.GetKind() == wxITEM_SEPARATOR)
1154f91b
BW
750 {
751 if (items_added > 0)
752 menuPopup.AppendSeparator();
753 }
754 }
755
756 // find out where to put the popup menu of window items
757 wxPoint pt = ::wxGetMousePosition();
758 pt = wnd->ScreenToClient(pt);
759
760 // find out the screen coordinate at the bottom of the tab ctrl
761 wxRect cli_rect = wnd->GetClientRect();
762 pt.y = cli_rect.y + cli_rect.height;
763
764 ToolbarCommandCapture* cc = new ToolbarCommandCapture;
765 wnd->PushEventHandler(cc);
766 wnd->PopupMenu(&menuPopup, pt);
767 int command = cc->GetCommandId();
768 wnd->PopEventHandler(true);
769
770 return command;
771}
772
773
774
775
776BEGIN_EVENT_TABLE(wxAuiToolBar, wxControl)
777 EVT_SIZE(wxAuiToolBar::OnSize)
778 EVT_IDLE(wxAuiToolBar::OnIdle)
779 EVT_ERASE_BACKGROUND(wxAuiToolBar::OnEraseBackground)
780 EVT_PAINT(wxAuiToolBar::OnPaint)
781 EVT_LEFT_DOWN(wxAuiToolBar::OnLeftDown)
782 EVT_LEFT_DCLICK(wxAuiToolBar::OnLeftDown)
783 EVT_LEFT_UP(wxAuiToolBar::OnLeftUp)
784 EVT_RIGHT_DOWN(wxAuiToolBar::OnRightDown)
785 EVT_RIGHT_DCLICK(wxAuiToolBar::OnRightDown)
786 EVT_RIGHT_UP(wxAuiToolBar::OnRightUp)
787 EVT_MIDDLE_DOWN(wxAuiToolBar::OnMiddleDown)
788 EVT_MIDDLE_DCLICK(wxAuiToolBar::OnMiddleDown)
789 EVT_MIDDLE_UP(wxAuiToolBar::OnMiddleUp)
790 EVT_MOTION(wxAuiToolBar::OnMotion)
791 EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow)
792 EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor)
793END_EVENT_TABLE()
794
795
796wxAuiToolBar::wxAuiToolBar(wxWindow* parent,
797 wxWindowID id,
798 const wxPoint& position,
799 const wxSize& size,
800 long style)
801 : wxControl(parent,
802 id,
803 position,
804 size,
805 style | wxBORDER_NONE)
806{
807 m_sizer = new wxBoxSizer(wxHORIZONTAL);
808 m_button_width = -1;
809 m_button_height = -1;
810 m_sizer_element_count = 0;
811 m_action_pos = wxPoint(-1,-1);
812 m_action_item = NULL;
813 m_tip_item = NULL;
814 m_art = new wxAuiDefaultToolBarArt;
815 m_tool_packing = 2;
816 m_tool_border_padding = 3;
817 m_tool_text_orientation = wxAUI_TBTOOL_TEXT_BOTTOM;
818 m_gripper_sizer_item = NULL;
819 m_overflow_sizer_item = NULL;
820 m_dragging = false;
821 m_style = style;
822 m_gripper_visible = (m_style & wxAUI_TB_GRIPPER) ? true : false;
823 m_overflow_visible = (m_style & wxAUI_TB_OVERFLOW) ? true : false;
824 m_overflow_state = 0;
825 SetMargins(5, 5, 2, 2);
826 SetFont(*wxNORMAL_FONT);
827 m_art->SetFlags((unsigned int)m_style);
828 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
9578058d 829 if (style & wxAUI_TB_HORZ_LAYOUT)
1154f91b
BW
830 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT);
831}
832
833
834wxAuiToolBar::~wxAuiToolBar()
835{
836 delete m_art;
837 delete m_sizer;
838}
839
840void wxAuiToolBar::SetWindowStyleFlag(long style)
841{
842 wxControl::SetWindowStyleFlag(style);
843
844 m_style = style;
eecf97a5 845
1154f91b
BW
846 if (m_art)
847 {
848 m_art->SetFlags((unsigned int)m_style);
849 }
eecf97a5 850
1154f91b
BW
851 if (m_style & wxAUI_TB_GRIPPER)
852 m_gripper_visible = true;
8b385bf8 853 else
1154f91b
BW
854 m_gripper_visible = false;
855
856
857 if (m_style & wxAUI_TB_OVERFLOW)
858 m_overflow_visible = true;
8b385bf8 859 else
1154f91b 860 m_overflow_visible = false;
eecf97a5 861
9578058d 862 if (style & wxAUI_TB_HORZ_LAYOUT)
1154f91b 863 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_RIGHT);
8b385bf8 864 else
1154f91b
BW
865 SetToolTextOrientation(wxAUI_TBTOOL_TEXT_BOTTOM);
866}
867
868
869void wxAuiToolBar::SetArtProvider(wxAuiToolBarArt* art)
870{
871 delete m_art;
eecf97a5 872
1154f91b 873 m_art = art;
eecf97a5 874
1154f91b
BW
875 if (m_art)
876 {
877 m_art->SetFlags((unsigned int)m_style);
878 m_art->SetTextOrientation(m_tool_text_orientation);
879 }
880}
881
882wxAuiToolBarArt* wxAuiToolBar::GetArtProvider() const
883{
884 return m_art;
885}
886
887
888
889
7bce8439 890wxAuiToolBarItem* wxAuiToolBar::AddTool(int tool_id,
1154f91b
BW
891 const wxString& label,
892 const wxBitmap& bitmap,
893 const wxString& short_help_string,
894 wxItemKind kind)
895{
7bce8439 896 return AddTool(tool_id,
1154f91b
BW
897 label,
898 bitmap,
899 wxNullBitmap,
900 kind,
901 short_help_string,
902 wxEmptyString,
903 NULL);
904}
905
906
7bce8439 907wxAuiToolBarItem* wxAuiToolBar::AddTool(int tool_id,
1154f91b
BW
908 const wxString& label,
909 const wxBitmap& bitmap,
910 const wxBitmap& disabled_bitmap,
911 wxItemKind kind,
9e10f5d4
VZ
912 const wxString& short_help_string,
913 const wxString& long_help_string,
1154f91b
BW
914 wxObject* WXUNUSED(client_data))
915{
916 wxAuiToolBarItem item;
917 item.window = NULL;
918 item.label = label;
919 item.bitmap = bitmap;
920 item.disabled_bitmap = disabled_bitmap;
9e10f5d4
VZ
921 item.short_help = short_help_string;
922 item.long_help = long_help_string;
1154f91b
BW
923 item.active = true;
924 item.dropdown = false;
e42f2c16 925 item.spacer_pixels = 0;
1154f91b
BW
926 item.id = tool_id;
927 item.state = 0;
928 item.proportion = 0;
929 item.kind = kind;
930 item.sizer_item = NULL;
931 item.min_size = wxDefaultSize;
932 item.user_data = 0;
933 item.sticky = false;
eecf97a5 934
1154f91b
BW
935 if (!item.disabled_bitmap.IsOk())
936 {
937 // no disabled bitmap specified, we need to make one
938 if (item.bitmap.IsOk())
939 {
940 //wxImage img = item.bitmap.ConvertToImage();
941 //wxImage grey_version = img.ConvertToGreyscale();
942 //item.disabled_bitmap = wxBitmap(grey_version);
943 item.disabled_bitmap = MakeDisabledBitmap(item.bitmap);
944 }
945 }
1154f91b 946 m_items.Add(item);
7bce8439 947 return &m_items.Last();
1154f91b
BW
948}
949
7bce8439 950wxAuiToolBarItem* wxAuiToolBar::AddControl(wxControl* control,
1154f91b
BW
951 const wxString& label)
952{
953 wxAuiToolBarItem item;
954 item.window = (wxWindow*)control;
955 item.label = label;
956 item.bitmap = wxNullBitmap;
957 item.disabled_bitmap = wxNullBitmap;
958 item.active = true;
959 item.dropdown = false;
e42f2c16 960 item.spacer_pixels = 0;
1154f91b
BW
961 item.id = control->GetId();
962 item.state = 0;
963 item.proportion = 0;
964 item.kind = wxITEM_CONTROL;
965 item.sizer_item = NULL;
966 item.min_size = control->GetEffectiveMinSize();
967 item.user_data = 0;
968 item.sticky = false;
969
970 m_items.Add(item);
7bce8439 971 return &m_items.Last();
1154f91b
BW
972}
973
7bce8439 974wxAuiToolBarItem* wxAuiToolBar::AddLabel(int tool_id,
1154f91b
BW
975 const wxString& label,
976 const int width)
977{
978 wxSize min_size = wxDefaultSize;
979 if (width != -1)
980 min_size.x = width;
eecf97a5 981
1154f91b
BW
982 wxAuiToolBarItem item;
983 item.window = NULL;
984 item.label = label;
985 item.bitmap = wxNullBitmap;
986 item.disabled_bitmap = wxNullBitmap;
987 item.active = true;
988 item.dropdown = false;
e42f2c16 989 item.spacer_pixels = 0;
1154f91b
BW
990 item.id = tool_id;
991 item.state = 0;
992 item.proportion = 0;
993 item.kind = wxITEM_LABEL;
994 item.sizer_item = NULL;
995 item.min_size = min_size;
996 item.user_data = 0;
997 item.sticky = false;
998
999 m_items.Add(item);
7bce8439 1000 return &m_items.Last();
1154f91b
BW
1001}
1002
7bce8439 1003wxAuiToolBarItem* wxAuiToolBar::AddSeparator()
1154f91b
BW
1004{
1005 wxAuiToolBarItem item;
1006 item.window = NULL;
1007 item.label = wxEmptyString;
1008 item.bitmap = wxNullBitmap;
1009 item.disabled_bitmap = wxNullBitmap;
1010 item.active = true;
1011 item.dropdown = false;
1012 item.id = -1;
1013 item.state = 0;
1014 item.proportion = 0;
1015 item.kind = wxITEM_SEPARATOR;
1016 item.sizer_item = NULL;
1017 item.min_size = wxDefaultSize;
1018 item.user_data = 0;
1019 item.sticky = false;
1020
1021 m_items.Add(item);
7bce8439 1022 return &m_items.Last();
1154f91b
BW
1023}
1024
7bce8439 1025wxAuiToolBarItem* wxAuiToolBar::AddSpacer(int pixels)
1154f91b
BW
1026{
1027 wxAuiToolBarItem item;
1028 item.window = NULL;
1029 item.label = wxEmptyString;
1030 item.bitmap = wxNullBitmap;
1031 item.disabled_bitmap = wxNullBitmap;
1032 item.active = true;
1033 item.dropdown = false;
e42f2c16 1034 item.spacer_pixels = pixels;
1154f91b
BW
1035 item.id = -1;
1036 item.state = 0;
1037 item.proportion = 0;
1038 item.kind = wxITEM_SPACER;
1039 item.sizer_item = NULL;
1040 item.min_size = wxDefaultSize;
1041 item.user_data = 0;
1042 item.sticky = false;
1043
1044 m_items.Add(item);
7bce8439 1045 return &m_items.Last();
1154f91b
BW
1046}
1047
7bce8439 1048wxAuiToolBarItem* wxAuiToolBar::AddStretchSpacer(int proportion)
1154f91b
BW
1049{
1050 wxAuiToolBarItem item;
1051 item.window = NULL;
1052 item.label = wxEmptyString;
1053 item.bitmap = wxNullBitmap;
1054 item.disabled_bitmap = wxNullBitmap;
1055 item.active = true;
1056 item.dropdown = false;
e42f2c16 1057 item.spacer_pixels = 0;
1154f91b
BW
1058 item.id = -1;
1059 item.state = 0;
1060 item.proportion = proportion;
1061 item.kind = wxITEM_SPACER;
1062 item.sizer_item = NULL;
1063 item.min_size = wxDefaultSize;
1064 item.user_data = 0;
1065 item.sticky = false;
1066
1067 m_items.Add(item);
7bce8439 1068 return &m_items.Last();
1154f91b
BW
1069}
1070
1071void wxAuiToolBar::Clear()
1072{
1073 m_items.Clear();
1074 m_sizer_element_count = 0;
1075}
1076
1077bool wxAuiToolBar::DeleteTool(int tool_id)
1078{
1079 int idx = GetToolIndex(tool_id);
1080 if (idx >= 0 && idx < (int)m_items.GetCount())
1081 {
1082 m_items.RemoveAt(idx);
1083 Realize();
1084 return true;
1085 }
eecf97a5 1086
1154f91b
BW
1087 return false;
1088}
1089
1090bool wxAuiToolBar::DeleteByIndex(int idx)
1091{
1092 if (idx >= 0 && idx < (int)m_items.GetCount())
1093 {
1094 m_items.RemoveAt(idx);
1095 Realize();
1096 return true;
1097 }
eecf97a5 1098
1154f91b
BW
1099 return false;
1100}
1101
1102
1103wxControl* wxAuiToolBar::FindControl(int id)
1104{
1105 wxWindow* wnd = FindWindow(id);
1106 return (wxControl*)wnd;
1107}
1108
1109wxAuiToolBarItem* wxAuiToolBar::FindTool(int tool_id) const
1110{
1111 size_t i, count;
1112 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1113 {
1114 wxAuiToolBarItem& item = m_items.Item(i);
1115 if (item.id == tool_id)
1116 return &item;
1117 }
eecf97a5 1118
1154f91b
BW
1119 return NULL;
1120}
1121
1122wxAuiToolBarItem* wxAuiToolBar::FindToolByPosition(wxCoord x, wxCoord y) const
1123{
1124 size_t i, count;
1125 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1126 {
1127 wxAuiToolBarItem& item = m_items.Item(i);
eecf97a5 1128
1154f91b
BW
1129 if (!item.sizer_item)
1130 continue;
eecf97a5 1131
1154f91b
BW
1132 wxRect rect = item.sizer_item->GetRect();
1133 if (rect.Contains(x,y))
1134 {
1135 // if the item doesn't fit on the toolbar, return NULL
1136 if (!GetToolFitsByIndex(i))
1137 return NULL;
eecf97a5 1138
1154f91b
BW
1139 return &item;
1140 }
1141 }
eecf97a5 1142
1154f91b
BW
1143 return NULL;
1144}
1145
1146wxAuiToolBarItem* wxAuiToolBar::FindToolByPositionWithPacking(wxCoord x, wxCoord y) const
1147{
1148 size_t i, count;
1149 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1150 {
1151 wxAuiToolBarItem& item = m_items.Item(i);
eecf97a5 1152
1154f91b
BW
1153 if (!item.sizer_item)
1154 continue;
eecf97a5 1155
1154f91b 1156 wxRect rect = item.sizer_item->GetRect();
eecf97a5 1157
1154f91b
BW
1158 // apply tool packing
1159 if (i+1 < count)
1160 rect.width += m_tool_packing;
eecf97a5 1161
1154f91b
BW
1162 if (rect.Contains(x,y))
1163 {
1164 // if the item doesn't fit on the toolbar, return NULL
1165 if (!GetToolFitsByIndex(i))
1166 return NULL;
eecf97a5 1167
1154f91b
BW
1168 return &item;
1169 }
1170 }
eecf97a5 1171
1154f91b
BW
1172 return NULL;
1173}
1174
1175wxAuiToolBarItem* wxAuiToolBar::FindToolByIndex(int idx) const
1176{
1177 if (idx < 0)
1178 return NULL;
eecf97a5 1179
1154f91b
BW
1180 if (idx >= (int)m_items.size())
1181 return NULL;
eecf97a5 1182
1154f91b
BW
1183 return &(m_items[idx]);
1184}
1185
1186void wxAuiToolBar::SetToolBitmapSize(const wxSize& WXUNUSED(size))
1187{
1188 // TODO: wxToolBar compatibility
1189}
1190
1191wxSize wxAuiToolBar::GetToolBitmapSize() const
1192{
1193 // TODO: wxToolBar compatibility
1194 return wxSize(16,15);
1195}
eecf97a5 1196
1154f91b
BW
1197void wxAuiToolBar::SetToolProportion(int tool_id, int proportion)
1198{
1199 wxAuiToolBarItem* item = FindTool(tool_id);
1200 if (!item)
1201 return;
eecf97a5 1202
1154f91b
BW
1203 item->proportion = proportion;
1204}
1205
1206int wxAuiToolBar::GetToolProportion(int tool_id) const
1207{
1208 wxAuiToolBarItem* item = FindTool(tool_id);
1209 if (!item)
1210 return 0;
eecf97a5 1211
1154f91b
BW
1212 return item->proportion;
1213}
1214
1215void wxAuiToolBar::SetToolSeparation(int separation)
1216{
1217 if (m_art)
1218 m_art->SetElementSize(wxAUI_TBART_SEPARATOR_SIZE, separation);
1219}
1220
1221int wxAuiToolBar::GetToolSeparation() const
1222{
1223 if (m_art)
1224 return m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE);
8b385bf8 1225 else
1154f91b
BW
1226 return 5;
1227}
eecf97a5 1228
1154f91b
BW
1229
1230void wxAuiToolBar::SetToolDropDown(int tool_id, bool dropdown)
1231{
eecf97a5 1232 wxAuiToolBarItem* item = FindTool(tool_id);
1154f91b
BW
1233 if (!item)
1234 return;
1235
1236 item->dropdown = dropdown;
1237}
1238
1239bool wxAuiToolBar::GetToolDropDown(int tool_id) const
1240{
1241 wxAuiToolBarItem* item = FindTool(tool_id);
1242 if (!item)
1243 return 0;
eecf97a5 1244
1154f91b
BW
1245 return item->dropdown;
1246}
1247
1248void wxAuiToolBar::SetToolSticky(int tool_id, bool sticky)
1249{
1250 // ignore separators
1251 if (tool_id == -1)
1252 return;
eecf97a5
VZ
1253
1254 wxAuiToolBarItem* item = FindTool(tool_id);
1154f91b
BW
1255 if (!item)
1256 return;
eecf97a5 1257
1154f91b
BW
1258 if (item->sticky == sticky)
1259 return;
eecf97a5 1260
1154f91b 1261 item->sticky = sticky;
eecf97a5 1262
1154f91b
BW
1263 Refresh(false);
1264 Update();
1265}
1266
1267bool wxAuiToolBar::GetToolSticky(int tool_id) const
1268{
1269 wxAuiToolBarItem* item = FindTool(tool_id);
1270 if (!item)
1271 return 0;
eecf97a5 1272
1154f91b
BW
1273 return item->sticky;
1274}
1275
1276
1277
1278
1279void wxAuiToolBar::SetToolBorderPadding(int padding)
1280{
1281 m_tool_border_padding = padding;
1282}
1283
1284int wxAuiToolBar::GetToolBorderPadding() const
1285{
1286 return m_tool_border_padding;
1287}
1288
1289void wxAuiToolBar::SetToolTextOrientation(int orientation)
1290{
1291 m_tool_text_orientation = orientation;
1292
1293 if (m_art)
1294 {
1295 m_art->SetTextOrientation(orientation);
1296 }
1297}
1298
1299int wxAuiToolBar::GetToolTextOrientation() const
1300{
1301 return m_tool_text_orientation;
1302}
1303
1304void wxAuiToolBar::SetToolPacking(int packing)
1305{
1306 m_tool_packing = packing;
1307}
1308
1309int wxAuiToolBar::GetToolPacking() const
1310{
1311 return m_tool_packing;
1312}
1313
1314
1315void wxAuiToolBar::SetOrientation(int WXUNUSED(orientation))
1316{
1317}
1318
1319void wxAuiToolBar::SetMargins(int left, int right, int top, int bottom)
1320{
1321 if (left != -1)
1322 m_left_padding = left;
1323 if (right != -1)
1324 m_right_padding = right;
1325 if (top != -1)
1326 m_top_padding = top;
1327 if (bottom != -1)
1328 m_bottom_padding = bottom;
1329}
1330
1331bool wxAuiToolBar::GetGripperVisible() const
1332{
1333 return m_gripper_visible;
1334}
1335
1336void wxAuiToolBar::SetGripperVisible(bool visible)
1337{
1338 m_gripper_visible = visible;
1339 if (visible)
1340 m_style |= wxAUI_TB_GRIPPER;
1341 Realize();
1342 Refresh(false);
1343}
1344
1345
1346bool wxAuiToolBar::GetOverflowVisible() const
1347{
1348 return m_overflow_visible;
1349}
1350
1351void wxAuiToolBar::SetOverflowVisible(bool visible)
1352{
1353 m_overflow_visible = visible;
1354 if (visible)
1355 m_style |= wxAUI_TB_OVERFLOW;
1356 Refresh(false);
1357}
1358
1359bool wxAuiToolBar::SetFont(const wxFont& font)
1360{
1361 bool res = wxWindow::SetFont(font);
eecf97a5 1362
1154f91b
BW
1363 if (m_art)
1364 {
1365 m_art->SetFont(font);
1366 }
eecf97a5 1367
1154f91b
BW
1368 return res;
1369}
1370
1371
1372void wxAuiToolBar::SetHoverItem(wxAuiToolBarItem* pitem)
1373{
1374 wxAuiToolBarItem* former_hover = NULL;
eecf97a5 1375
1154f91b
BW
1376 size_t i, count;
1377 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1378 {
1379 wxAuiToolBarItem& item = m_items.Item(i);
1380 if (item.state & wxAUI_BUTTON_STATE_HOVER)
1381 former_hover = &item;
1382 item.state &= ~wxAUI_BUTTON_STATE_HOVER;
1383 }
eecf97a5 1384
1154f91b
BW
1385 if (pitem)
1386 {
1387 pitem->state |= wxAUI_BUTTON_STATE_HOVER;
1388 }
eecf97a5 1389
1154f91b
BW
1390 if (former_hover != pitem)
1391 {
1392 Refresh(false);
1393 Update();
1394 }
1395}
1396
1397void wxAuiToolBar::SetPressedItem(wxAuiToolBarItem* pitem)
1398{
1399 wxAuiToolBarItem* former_item = NULL;
eecf97a5 1400
1154f91b
BW
1401 size_t i, count;
1402 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1403 {
1404 wxAuiToolBarItem& item = m_items.Item(i);
1405 if (item.state & wxAUI_BUTTON_STATE_PRESSED)
1406 former_item = &item;
1407 item.state &= ~wxAUI_BUTTON_STATE_PRESSED;
1408 }
eecf97a5 1409
1154f91b
BW
1410 if (pitem)
1411 {
1412 pitem->state &= ~wxAUI_BUTTON_STATE_HOVER;
1413 pitem->state |= wxAUI_BUTTON_STATE_PRESSED;
1414 }
eecf97a5 1415
1154f91b
BW
1416 if (former_item != pitem)
1417 {
1418 Refresh(false);
1419 Update();
1420 }
1421}
1422
1423void wxAuiToolBar::RefreshOverflowState()
1424{
1425 if (!m_overflow_sizer_item)
1426 {
1427 m_overflow_state = 0;
1428 return;
1429 }
eecf97a5 1430
1154f91b 1431 int overflow_state = 0;
eecf97a5 1432
1154f91b
BW
1433 wxRect overflow_rect = GetOverflowRect();
1434
eecf97a5 1435
1154f91b
BW
1436 // find out the mouse's current position
1437 wxPoint pt = ::wxGetMousePosition();
1438 pt = this->ScreenToClient(pt);
eecf97a5 1439
1154f91b
BW
1440 // find out if the mouse cursor is inside the dropdown rectangle
1441 if (overflow_rect.Contains(pt.x, pt.y))
1442 {
1443 if (::wxGetMouseState().LeftDown())
1444 overflow_state = wxAUI_BUTTON_STATE_PRESSED;
8b385bf8 1445 else
1154f91b
BW
1446 overflow_state = wxAUI_BUTTON_STATE_HOVER;
1447 }
eecf97a5 1448
1154f91b
BW
1449 if (overflow_state != m_overflow_state)
1450 {
1451 m_overflow_state = overflow_state;
1452 Refresh(false);
1453 Update();
1454 }
eecf97a5 1455
1154f91b
BW
1456 m_overflow_state = overflow_state;
1457}
1458
1459void wxAuiToolBar::ToggleTool(int tool_id, bool state)
1460{
1461 wxAuiToolBarItem* tool = FindTool(tool_id);
eecf97a5 1462
1154f91b
BW
1463 if (tool)
1464 {
1465 if (tool->kind != wxITEM_CHECK)
1466 return;
eecf97a5 1467
1154f91b
BW
1468 if (state == true)
1469 tool->state |= wxAUI_BUTTON_STATE_CHECKED;
8b385bf8 1470 else
1154f91b
BW
1471 tool->state &= ~wxAUI_BUTTON_STATE_CHECKED;
1472 }
1473}
1474
1475bool wxAuiToolBar::GetToolToggled(int tool_id) const
1476{
1477 wxAuiToolBarItem* tool = FindTool(tool_id);
eecf97a5 1478
1154f91b
BW
1479 if (tool)
1480 {
1481 if (tool->kind != wxITEM_CHECK)
1482 return false;
eecf97a5 1483
1154f91b
BW
1484 return (tool->state & wxAUI_BUTTON_STATE_CHECKED) ? true : false;
1485 }
eecf97a5 1486
1154f91b
BW
1487 return false;
1488}
1489
1490void wxAuiToolBar::EnableTool(int tool_id, bool state)
1491{
1492 wxAuiToolBarItem* tool = FindTool(tool_id);
eecf97a5 1493
1154f91b
BW
1494 if (tool)
1495 {
1496 if (state == true)
1497 tool->state &= ~wxAUI_BUTTON_STATE_DISABLED;
8b385bf8 1498 else
1154f91b
BW
1499 tool->state |= wxAUI_BUTTON_STATE_DISABLED;
1500 }
1501}
1502
1503bool wxAuiToolBar::GetToolEnabled(int tool_id) const
1504{
1505 wxAuiToolBarItem* tool = FindTool(tool_id);
eecf97a5 1506
1154f91b
BW
1507 if (tool)
1508 return (tool->state & wxAUI_BUTTON_STATE_DISABLED) ? false : true;
eecf97a5 1509
1154f91b
BW
1510 return false;
1511}
1512
1513wxString wxAuiToolBar::GetToolLabel(int tool_id) const
1514{
1515 wxAuiToolBarItem* tool = FindTool(tool_id);
1516 wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array"));
1517 if (!tool)
1518 return wxEmptyString;
eecf97a5 1519
1154f91b
BW
1520 return tool->label;
1521}
1522
1523void wxAuiToolBar::SetToolLabel(int tool_id, const wxString& label)
1524{
1525 wxAuiToolBarItem* tool = FindTool(tool_id);
1526 if (tool)
1527 {
1528 tool->label = label;
1529 }
1530}
1531
1532wxBitmap wxAuiToolBar::GetToolBitmap(int tool_id) const
1533{
1534 wxAuiToolBarItem* tool = FindTool(tool_id);
1535 wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array"));
1536 if (!tool)
1537 return wxNullBitmap;
eecf97a5 1538
1154f91b
BW
1539 return tool->bitmap;
1540}
1541
1542void wxAuiToolBar::SetToolBitmap(int tool_id, const wxBitmap& bitmap)
1543{
1544 wxAuiToolBarItem* tool = FindTool(tool_id);
1545 if (tool)
1546 {
1547 tool->bitmap = bitmap;
1548 }
1549}
1550
1551wxString wxAuiToolBar::GetToolShortHelp(int tool_id) const
1552{
1553 wxAuiToolBarItem* tool = FindTool(tool_id);
1554 wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array"));
1555 if (!tool)
1556 return wxEmptyString;
eecf97a5 1557
1154f91b
BW
1558 return tool->short_help;
1559}
1560
1561void wxAuiToolBar::SetToolShortHelp(int tool_id, const wxString& help_string)
1562{
1563 wxAuiToolBarItem* tool = FindTool(tool_id);
1564 if (tool)
1565 {
1566 tool->short_help = help_string;
1567 }
1568}
1569
1570wxString wxAuiToolBar::GetToolLongHelp(int tool_id) const
1571{
1572 wxAuiToolBarItem* tool = FindTool(tool_id);
1573 wxASSERT_MSG(tool, wxT("can't find tool in toolbar item array"));
1574 if (!tool)
1575 return wxEmptyString;
eecf97a5 1576
1154f91b
BW
1577 return tool->long_help;
1578}
1579
1580void wxAuiToolBar::SetToolLongHelp(int tool_id, const wxString& help_string)
1581{
1582 wxAuiToolBarItem* tool = FindTool(tool_id);
1583 if (tool)
1584 {
1585 tool->long_help = help_string;
1586 }
1587}
1588
1589void wxAuiToolBar::SetCustomOverflowItems(const wxAuiToolBarItemArray& prepend,
1590 const wxAuiToolBarItemArray& append)
1591{
1592 m_custom_overflow_prepend = prepend;
1593 m_custom_overflow_append = append;
1594}
1595
1596
1597size_t wxAuiToolBar::GetToolCount() const
1598{
1599 return m_items.size();
1600}
1601
1602int wxAuiToolBar::GetToolIndex(int tool_id) const
1603{
1604 // this will prevent us from returning the index of the
1605 // first separator in the toolbar since its id is equal to -1
1606 if (tool_id == -1)
1607 return wxNOT_FOUND;
eecf97a5 1608
1154f91b
BW
1609 size_t i, count = m_items.GetCount();
1610 for (i = 0; i < count; ++i)
1611 {
1612 wxAuiToolBarItem& item = m_items.Item(i);
1613 if (item.id == tool_id)
1614 return i;
1615 }
eecf97a5 1616
1154f91b
BW
1617 return wxNOT_FOUND;
1618}
1619
1620bool wxAuiToolBar::GetToolFitsByIndex(int tool_idx) const
1621{
1622 if (tool_idx < 0 || tool_idx >= (int)m_items.GetCount())
1623 return false;
eecf97a5 1624
1154f91b
BW
1625 if (!m_items[tool_idx].sizer_item)
1626 return false;
eecf97a5 1627
1154f91b
BW
1628 int cli_w, cli_h;
1629 GetClientSize(&cli_w, &cli_h);
eecf97a5 1630
1154f91b 1631 wxRect rect = m_items[tool_idx].sizer_item->GetRect();
eecf97a5 1632
1154f91b
BW
1633 if (m_style & wxAUI_TB_VERTICAL)
1634 {
1635 // take the dropdown size into account
1636 if (m_overflow_visible)
1637 cli_h -= m_overflow_sizer_item->GetSize().y;
eecf97a5 1638
1154f91b
BW
1639 if (rect.y+rect.height < cli_h)
1640 return true;
1641 }
8b385bf8 1642 else
1154f91b
BW
1643 {
1644 // take the dropdown size into account
1645 if (m_overflow_visible)
1646 cli_w -= m_overflow_sizer_item->GetSize().x;
eecf97a5 1647
1154f91b
BW
1648 if (rect.x+rect.width < cli_w)
1649 return true;
1650 }
1651
1652 return false;
1653}
1654
1655
1656bool wxAuiToolBar::GetToolFits(int tool_id) const
1657{
1658 return GetToolFitsByIndex(GetToolIndex(tool_id));
1659}
1660
1661wxRect wxAuiToolBar::GetToolRect(int tool_id) const
1662{
1663 wxAuiToolBarItem* tool = FindTool(tool_id);
1664 if (tool && tool->sizer_item)
1665 {
1666 return tool->sizer_item->GetRect();
1667 }
eecf97a5 1668
1154f91b
BW
1669 return wxRect();
1670}
1671
1672bool wxAuiToolBar::GetToolBarFits() const
1673{
1674 if (m_items.GetCount() == 0)
1675 {
1676 // empty toolbar always 'fits'
1677 return true;
1678 }
eecf97a5 1679
1154f91b
BW
1680 // entire toolbar content fits if the last tool fits
1681 return GetToolFitsByIndex(m_items.GetCount() - 1);
1682}
1683
1684bool wxAuiToolBar::Realize()
1685{
1686 wxClientDC dc(this);
1687 if (!dc.IsOk())
1688 return false;
1689
1690 bool horizontal = true;
1691 if (m_style & wxAUI_TB_VERTICAL)
1692 horizontal = false;
eecf97a5
VZ
1693
1694
1154f91b
BW
1695 // create the new sizer to add toolbar elements to
1696 wxBoxSizer* sizer = new wxBoxSizer(horizontal ? wxHORIZONTAL : wxVERTICAL);
eecf97a5 1697
1154f91b
BW
1698 // add gripper area
1699 int separator_size = m_art->GetElementSize(wxAUI_TBART_SEPARATOR_SIZE);
1700 int gripper_size = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE);
1701 if (gripper_size > 0 && m_gripper_visible)
1702 {
1703 if (horizontal)
1704 m_gripper_sizer_item = sizer->Add(gripper_size, 1, 0, wxEXPAND);
8b385bf8 1705 else
1154f91b
BW
1706 m_gripper_sizer_item = sizer->Add(1, gripper_size, 0, wxEXPAND);
1707 }
8b385bf8 1708 else
1154f91b
BW
1709 {
1710 m_gripper_sizer_item = NULL;
1711 }
eecf97a5 1712
1154f91b
BW
1713 // add "left" padding
1714 if (m_left_padding > 0)
1715 {
1716 if (horizontal)
1717 sizer->Add(m_left_padding, 1);
8b385bf8 1718 else
1154f91b
BW
1719 sizer->Add(1, m_left_padding);
1720 }
eecf97a5 1721
1154f91b
BW
1722 size_t i, count;
1723 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1724 {
1725 wxAuiToolBarItem& item = m_items.Item(i);
1726 wxSizerItem* sizer_item = NULL;
eecf97a5 1727
1154f91b 1728 switch (item.kind)
eecf97a5 1729 {
1154f91b
BW
1730 case wxITEM_LABEL:
1731 {
1732 wxSize size = m_art->GetLabelSize(dc, this, item);
1733 sizer_item = sizer->Add(size.x + (m_tool_border_padding*2),
1734 size.y + (m_tool_border_padding*2),
1735 item.proportion,
1736 wxALIGN_CENTER);
1737 if (i+1 < count)
1738 {
1739 sizer->AddSpacer(m_tool_packing);
1740 }
eecf97a5 1741
1154f91b
BW
1742 break;
1743 }
eecf97a5 1744
1154f91b
BW
1745 case wxITEM_CHECK:
1746 case wxITEM_NORMAL:
1747 {
1748 wxSize size = m_art->GetToolSize(dc, this, item);
1749 sizer_item = sizer->Add(size.x + (m_tool_border_padding*2),
1750 size.y + (m_tool_border_padding*2),
1751 0,
1752 wxALIGN_CENTER);
1753 // add tool packing
1754 if (i+1 < count)
1755 {
1756 sizer->AddSpacer(m_tool_packing);
1757 }
eecf97a5 1758
1154f91b
BW
1759 break;
1760 }
eecf97a5 1761
1154f91b
BW
1762 case wxITEM_SEPARATOR:
1763 {
1764 if (horizontal)
1765 sizer_item = sizer->Add(separator_size, 1, 0, wxEXPAND);
8b385bf8 1766 else
1154f91b
BW
1767 sizer_item = sizer->Add(1, separator_size, 0, wxEXPAND);
1768
1769 // add tool packing
1770 if (i+1 < count)
1771 {
1772 sizer->AddSpacer(m_tool_packing);
1773 }
eecf97a5 1774
1154f91b
BW
1775 break;
1776 }
eecf97a5 1777
1154f91b
BW
1778 case wxITEM_SPACER:
1779 if (item.proportion > 0)
1780 sizer_item = sizer->AddStretchSpacer(item.proportion);
8b385bf8 1781 else
e42f2c16 1782 sizer_item = sizer->Add(item.spacer_pixels, 1);
1154f91b 1783 break;
eecf97a5 1784
1154f91b
BW
1785 case wxITEM_CONTROL:
1786 {
1787 //sizer_item = sizer->Add(item.window, item.proportion, wxEXPAND);
1788 wxSizerItem* ctrl_sizer_item;
eecf97a5 1789
1154f91b
BW
1790 wxBoxSizer* vert_sizer = new wxBoxSizer(wxVERTICAL);
1791 vert_sizer->AddStretchSpacer(1);
1792 ctrl_sizer_item = vert_sizer->Add(item.window, 0, wxEXPAND);
1793 vert_sizer->AddStretchSpacer(1);
23511cdb
BW
1794 if ( (m_style & wxAUI_TB_TEXT) &&
1795 m_tool_text_orientation == wxAUI_TBTOOL_TEXT_BOTTOM &&
1796 !item.GetLabel().empty() )
1154f91b 1797 {
e42f2c16 1798 wxSize s = GetLabelSize(item.GetLabel());
1154f91b
BW
1799 vert_sizer->Add(1, s.y);
1800 }
eecf97a5
VZ
1801
1802
1154f91b 1803 sizer_item = sizer->Add(vert_sizer, item.proportion, wxEXPAND);
eecf97a5 1804
1154f91b 1805 wxSize min_size = item.min_size;
eecf97a5 1806
1154f91b
BW
1807
1808 // proportional items will disappear from the toolbar if
1809 // their min width is not set to something really small
1810 if (item.proportion != 0)
1811 {
1812 min_size.x = 1;
1813 }
eecf97a5 1814
1154f91b
BW
1815 if (min_size.IsFullySpecified())
1816 {
eecf97a5 1817 sizer_item->SetMinSize(min_size);
1154f91b
BW
1818 ctrl_sizer_item->SetMinSize(min_size);
1819 }
1820
1821 // add tool packing
1822 if (i+1 < count)
1823 {
1824 sizer->AddSpacer(m_tool_packing);
1825 }
1826 }
1827 }
eecf97a5 1828
1154f91b
BW
1829 item.sizer_item = sizer_item;
1830 }
1831
1832 // add "right" padding
1833 if (m_right_padding > 0)
1834 {
1835 if (horizontal)
1836 sizer->Add(m_right_padding, 1);
8b385bf8 1837 else
1154f91b
BW
1838 sizer->Add(1, m_right_padding);
1839 }
eecf97a5 1840
1154f91b
BW
1841 // add drop down area
1842 m_overflow_sizer_item = NULL;
eecf97a5 1843
1154f91b
BW
1844 if (m_style & wxAUI_TB_OVERFLOW)
1845 {
1846 int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
1847 if (overflow_size > 0 && m_overflow_visible)
1848 {
1849 if (horizontal)
1850 m_overflow_sizer_item = sizer->Add(overflow_size, 1, 0, wxEXPAND);
8b385bf8 1851 else
1154f91b
BW
1852 m_overflow_sizer_item = sizer->Add(1, overflow_size, 0, wxEXPAND);
1853 }
8b385bf8 1854 else
1154f91b
BW
1855 {
1856 m_overflow_sizer_item = NULL;
1857 }
1858 }
eecf97a5 1859
1154f91b
BW
1860
1861 // the outside sizer helps us apply the "top" and "bottom" padding
1862 wxBoxSizer* outside_sizer = new wxBoxSizer(horizontal ? wxVERTICAL : wxHORIZONTAL);
eecf97a5 1863
1154f91b
BW
1864 // add "top" padding
1865 if (m_top_padding > 0)
1866 {
1867 if (horizontal)
1868 outside_sizer->Add(1, m_top_padding);
8b385bf8 1869 else
1154f91b
BW
1870 outside_sizer->Add(m_top_padding, 1);
1871 }
1872
1873 // add the sizer that contains all of the toolbar elements
1874 outside_sizer->Add(sizer, 1, wxEXPAND);
eecf97a5 1875
1154f91b
BW
1876 // add "bottom" padding
1877 if (m_bottom_padding > 0)
1878 {
1879 if (horizontal)
1880 outside_sizer->Add(1, m_bottom_padding);
8b385bf8 1881 else
1154f91b
BW
1882 outside_sizer->Add(m_bottom_padding, 1);
1883 }
eecf97a5 1884
1154f91b
BW
1885 delete m_sizer; // remove old sizer
1886 m_sizer = outside_sizer;
eecf97a5 1887
1154f91b
BW
1888 // calculate the rock-bottom minimum size
1889 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1890 {
1891 wxAuiToolBarItem& item = m_items.Item(i);
1892 if (item.sizer_item && item.proportion > 0 && item.min_size.IsFullySpecified())
1893 item.sizer_item->SetMinSize(0,0);
1894 }
eecf97a5 1895
1154f91b 1896 m_absolute_min_size = m_sizer->GetMinSize();
eecf97a5 1897
1154f91b
BW
1898 // reset the min sizes to what they were
1899 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1900 {
1901 wxAuiToolBarItem& item = m_items.Item(i);
1902 if (item.sizer_item && item.proportion > 0 && item.min_size.IsFullySpecified())
1903 item.sizer_item->SetMinSize(item.min_size);
eecf97a5 1904 }
1154f91b
BW
1905
1906 // set control size
1907 wxSize size = m_sizer->GetMinSize();
1908 m_minWidth = size.x;
1909 m_minHeight = size.y;
eecf97a5 1910
1154f91b
BW
1911 if ((m_style & wxAUI_TB_NO_AUTORESIZE) == 0)
1912 {
1913 wxSize cur_size = GetClientSize();
1914 wxSize new_size = GetMinSize();
1915 if (new_size != cur_size)
1916 {
1917 SetClientSize(new_size);
1918 }
8b385bf8 1919 else
1154f91b
BW
1920 {
1921 m_sizer->SetDimension(0, 0, cur_size.x, cur_size.y);
1922 }
eecf97a5 1923 }
8b385bf8 1924 else
1154f91b
BW
1925 {
1926 wxSize cur_size = GetClientSize();
1927 m_sizer->SetDimension(0, 0, cur_size.x, cur_size.y);
1928 }
eecf97a5 1929
1154f91b
BW
1930 Refresh(false);
1931 return true;
1932}
1933
1934int wxAuiToolBar::GetOverflowState() const
1935{
1936 return m_overflow_state;
1937}
1938
1939wxRect wxAuiToolBar::GetOverflowRect() const
eecf97a5 1940{
1154f91b
BW
1941 wxRect cli_rect(wxPoint(0,0), GetClientSize());
1942 wxRect overflow_rect = m_overflow_sizer_item->GetRect();
1943 int overflow_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
1944
1945 if (m_style & wxAUI_TB_VERTICAL)
1946 {
1947 overflow_rect.y = cli_rect.height - overflow_size;
1948 overflow_rect.x = 0;
1949 overflow_rect.width = cli_rect.width;
1950 overflow_rect.height = overflow_size;
1951 }
8b385bf8 1952 else
1154f91b
BW
1953 {
1954 overflow_rect.x = cli_rect.width - overflow_size;
1955 overflow_rect.y = 0;
1956 overflow_rect.width = overflow_size;
1957 overflow_rect.height = cli_rect.height;
1958 }
eecf97a5 1959
1154f91b
BW
1960 return overflow_rect;
1961}
1962
1963wxSize wxAuiToolBar::GetLabelSize(const wxString& label)
1964{
1965 wxClientDC dc(this);
eecf97a5 1966
1154f91b
BW
1967 int tx, ty;
1968 int text_width = 0, text_height = 0;
1969
1970 dc.SetFont(m_font);
eecf97a5 1971
1154f91b
BW
1972 // get the text height
1973 dc.GetTextExtent(wxT("ABCDHgj"), &tx, &text_height);
1974
1975 // get the text width
1976 dc.GetTextExtent(label, &text_width, &ty);
1977
1978 return wxSize(text_width, text_height);
1979}
1980
1981
1982void wxAuiToolBar::DoIdleUpdate()
1983{
1984 wxEvtHandler* handler = GetEventHandler();
1985
1986 bool need_refresh = false;
1987
1988 size_t i, count;
1989 for (i = 0, count = m_items.GetCount(); i < count; ++i)
1990 {
1991 wxAuiToolBarItem& item = m_items.Item(i);
eecf97a5 1992
1154f91b
BW
1993 if (item.id == -1)
1994 continue;
eecf97a5 1995
1154f91b
BW
1996 wxUpdateUIEvent evt(item.id);
1997 evt.SetEventObject(this);
1998
1999 if (handler->ProcessEvent(evt))
2000 {
2001 if (evt.GetSetEnabled())
2002 {
2003 bool is_enabled;
2004 if (item.window)
2005 is_enabled = item.window->IsEnabled();
8b385bf8 2006 else
1154f91b 2007 is_enabled = (item.state & wxAUI_BUTTON_STATE_DISABLED) ? false : true;
eecf97a5 2008
1154f91b
BW
2009 bool new_enabled = evt.GetEnabled();
2010 if (new_enabled != is_enabled)
2011 {
2012 if (item.window)
2013 {
2014 item.window->Enable(new_enabled);
2015 }
8b385bf8 2016 else
1154f91b
BW
2017 {
2018 if (new_enabled)
2019 item.state &= ~wxAUI_BUTTON_STATE_DISABLED;
8b385bf8 2020 else
1154f91b
BW
2021 item.state |= wxAUI_BUTTON_STATE_DISABLED;
2022 }
2023 need_refresh = true;
2024 }
2025 }
eecf97a5 2026
1154f91b
BW
2027 if (evt.GetSetChecked())
2028 {
2029 // make sure we aren't checking an item that can't be
2030 if (item.kind != wxITEM_CHECK && item.kind != wxITEM_RADIO)
2031 continue;
2032
2033 bool is_checked = (item.state & wxAUI_BUTTON_STATE_CHECKED) ? true : false;
2034 bool new_checked = evt.GetChecked();
2035
2036 if (new_checked != is_checked)
2037 {
2038 if (new_checked)
2039 item.state |= wxAUI_BUTTON_STATE_CHECKED;
8b385bf8 2040 else
1154f91b 2041 item.state &= ~wxAUI_BUTTON_STATE_CHECKED;
eecf97a5 2042
1154f91b
BW
2043 need_refresh = true;
2044 }
2045 }
2046
2047 }
2048 }
eecf97a5 2049
1154f91b
BW
2050
2051 if (need_refresh)
2052 {
2053 Refresh(false);
2054 }
2055}
2056
2057
2058void wxAuiToolBar::OnSize(wxSizeEvent& WXUNUSED(evt))
2059{
2060 int x, y;
2061 GetClientSize(&x, &y);
2062
2063 if (x > y)
2064 SetOrientation(wxHORIZONTAL);
8b385bf8 2065 else
1154f91b
BW
2066 SetOrientation(wxVERTICAL);
2067
2068 if (((x >= y) && m_absolute_min_size.x > x) ||
2069 ((y > x) && m_absolute_min_size.y > y))
2070 {
2071 // hide all flexible items
2072 size_t i, count;
2073 for (i = 0, count = m_items.GetCount(); i < count; ++i)
2074 {
2075 wxAuiToolBarItem& item = m_items.Item(i);
2076 if (item.sizer_item && item.proportion > 0 && item.sizer_item->IsShown())
2077 {
2078 item.sizer_item->Show(false);
2079 item.sizer_item->SetProportion(0);
2080 }
2081 }
2082 }
8b385bf8 2083 else
1154f91b
BW
2084 {
2085 // show all flexible items
2086 size_t i, count;
2087 for (i = 0, count = m_items.GetCount(); i < count; ++i)
2088 {
2089 wxAuiToolBarItem& item = m_items.Item(i);
2090 if (item.sizer_item && item.proportion > 0 && !item.sizer_item->IsShown())
2091 {
2092 item.sizer_item->Show(true);
2093 item.sizer_item->SetProportion(item.proportion);
2094 }
2095 }
2096 }
2097
2098 m_sizer->SetDimension(0, 0, x, y);
2099
2100 Refresh(false);
2101 Update();
2102}
2103
2104
2105
2106void wxAuiToolBar::DoSetSize(int x,
2107 int y,
2108 int width,
2109 int height,
2110 int sizeFlags)
2111{
2112 wxSize parent_size = GetParent()->GetClientSize();
2113 if (x + width > parent_size.x)
2114 width = wxMax(0, parent_size.x - x);
2115 if (y + height > parent_size.y)
2116 height = wxMax(0, parent_size.y - y);
2117
2118 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
2119}
2120
2121
2122void wxAuiToolBar::OnIdle(wxIdleEvent& evt)
2123{
2124 DoIdleUpdate();
2125 evt.Skip();
2126}
2127
2128void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
2129{
2130 wxBufferedPaintDC dc(this);
2131 wxRect cli_rect(wxPoint(0,0), GetClientSize());
eecf97a5
VZ
2132
2133
1154f91b
BW
2134 bool horizontal = true;
2135 if (m_style & wxAUI_TB_VERTICAL)
2136 horizontal = false;
2137
2138
2139 m_art->DrawBackground(dc, this, cli_rect);
eecf97a5 2140
1154f91b
BW
2141 int gripper_size = m_art->GetElementSize(wxAUI_TBART_GRIPPER_SIZE);
2142 int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
eecf97a5 2143
1154f91b
BW
2144 // paint the gripper
2145 if (gripper_size > 0 && m_gripper_sizer_item)
2146 {
2147 wxRect gripper_rect = m_gripper_sizer_item->GetRect();
2148 if (horizontal)
2149 gripper_rect.width = gripper_size;
8b385bf8 2150 else
1154f91b
BW
2151 gripper_rect.height = gripper_size;
2152 m_art->DrawGripper(dc, this, gripper_rect);
2153 }
eecf97a5 2154
1154f91b
BW
2155 // calculated how far we can draw items
2156 int last_extent;
2157 if (horizontal)
2158 last_extent = cli_rect.width;
8b385bf8 2159 else
1154f91b
BW
2160 last_extent = cli_rect.height;
2161 if (m_overflow_visible)
2162 last_extent -= dropdown_size;
eecf97a5 2163
1154f91b
BW
2164 // paint each individual tool
2165 size_t i, count = m_items.GetCount();
2166 for (i = 0; i < count; ++i)
2167 {
2168 wxAuiToolBarItem& item = m_items.Item(i);
eecf97a5 2169
1154f91b
BW
2170 if (!item.sizer_item)
2171 continue;
eecf97a5 2172
1154f91b 2173 wxRect item_rect = item.sizer_item->GetRect();
eecf97a5
VZ
2174
2175
1154f91b
BW
2176 if ((horizontal && item_rect.x + item_rect.width >= last_extent) ||
2177 (!horizontal && item_rect.y + item_rect.height >= last_extent))
2178 {
2179 break;
2180 }
eecf97a5 2181
1154f91b
BW
2182 if (item.kind == wxITEM_SEPARATOR)
2183 {
2184 // draw a separator
2185 m_art->DrawSeparator(dc, this, item_rect);
2186 }
8b385bf8 2187 else if (item.kind == wxITEM_LABEL)
1154f91b
BW
2188 {
2189 // draw a text label only
2190 m_art->DrawLabel(dc, this, item, item_rect);
2191 }
8b385bf8 2192 else if (item.kind == wxITEM_NORMAL)
1154f91b
BW
2193 {
2194 // draw a regular button or dropdown button
2195 if (!item.dropdown)
2196 m_art->DrawButton(dc, this, item, item_rect);
8b385bf8 2197 else
1154f91b
BW
2198 m_art->DrawDropDownButton(dc, this, item, item_rect);
2199 }
8b385bf8 2200 else if (item.kind == wxITEM_CHECK)
1154f91b
BW
2201 {
2202 // draw a toggle button
2203 m_art->DrawButton(dc, this, item, item_rect);
2204 }
8b385bf8 2205 else if (item.kind == wxITEM_CONTROL)
1154f91b
BW
2206 {
2207 // draw the control's label
2208 m_art->DrawControlLabel(dc, this, item, item_rect);
2209 }
2210
2211 // fire a signal to see if the item wants to be custom-rendered
2212 OnCustomRender(dc, item, item_rect);
2213 }
eecf97a5 2214
1154f91b
BW
2215 // paint the overflow button
2216 if (dropdown_size > 0 && m_overflow_sizer_item)
2217 {
2218 wxRect dropdown_rect = GetOverflowRect();
2219 m_art->DrawOverflowButton(dc, this, dropdown_rect, m_overflow_state);
2220 }
2221}
2222
2223void wxAuiToolBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
2224{
2225 // empty
2226}
2227
2228void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
2229{
2230 wxRect cli_rect(wxPoint(0,0), GetClientSize());
eecf97a5 2231
1154f91b
BW
2232 if (m_gripper_sizer_item)
2233 {
2234 wxRect gripper_rect = m_gripper_sizer_item->GetRect();
2235 if (gripper_rect.Contains(evt.GetX(), evt.GetY()))
2236 {
2237 // find aui manager
2238 wxAuiManager* manager = wxAuiManager::GetManager(this);
2239 if (!manager)
2240 return;
eecf97a5 2241
1154f91b
BW
2242 int x_drag_offset = evt.GetX() - gripper_rect.GetX();
2243 int y_drag_offset = evt.GetY() - gripper_rect.GetY();
eecf97a5 2244
1154f91b
BW
2245 // gripper was clicked
2246 manager->StartPaneDrag(this, wxPoint(x_drag_offset, y_drag_offset));
2247 return;
2248 }
2249 }
eecf97a5 2250
1154f91b
BW
2251 if (m_overflow_sizer_item)
2252 {
2253 wxRect overflow_rect = GetOverflowRect();
eecf97a5
VZ
2254
2255 if (m_art &&
1154f91b
BW
2256 m_overflow_visible &&
2257 overflow_rect.Contains(evt.m_x, evt.m_y))
2258 {
2259 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, -1);
2260 e.SetEventObject(this);
2261 e.SetToolId(-1);
2262 e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY()));
004867db 2263 bool processed = GetEventHandler()->ProcessEvent(e);
eecf97a5 2264
1154f91b
BW
2265 if (processed)
2266 {
2267 DoIdleUpdate();
2268 }
8b385bf8 2269 else
1154f91b
BW
2270 {
2271 size_t i, count;
2272 wxAuiToolBarItemArray overflow_items;
eecf97a5 2273
1154f91b
BW
2274
2275 // add custom overflow prepend items, if any
2276 count = m_custom_overflow_prepend.GetCount();
2277 for (i = 0; i < count; ++i)
eecf97a5
VZ
2278 overflow_items.Add(m_custom_overflow_prepend[i]);
2279
1154f91b
BW
2280 // only show items that don't fit in the dropdown
2281 count = m_items.GetCount();
2282 for (i = 0; i < count; ++i)
2283 {
2284 if (!GetToolFitsByIndex(i))
2285 overflow_items.Add(m_items[i]);
2286 }
2287
2288 // add custom overflow append items, if any
2289 count = m_custom_overflow_append.GetCount();
2290 for (i = 0; i < count; ++i)
2291 overflow_items.Add(m_custom_overflow_append[i]);
eecf97a5 2292
1154f91b
BW
2293 int res = m_art->ShowDropDown(this, overflow_items);
2294 m_overflow_state = 0;
2295 Refresh(false);
2296 if (res != -1)
2297 {
2298 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res);
2299 e.SetEventObject(this);
004867db 2300 GetParent()->GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2301 }
2302 }
eecf97a5 2303
1154f91b
BW
2304 return;
2305 }
2306 }
eecf97a5 2307
1154f91b
BW
2308 m_dragging = false;
2309 m_action_pos = wxPoint(evt.GetX(), evt.GetY());
2310 m_action_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2311
1154f91b
BW
2312 if (m_action_item)
2313 {
2314 if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED)
2315 {
2316 m_action_pos = wxPoint(-1,-1);
2317 m_action_item = NULL;
2318 return;
2319 }
eecf97a5 2320
1154f91b 2321 SetPressedItem(m_action_item);
eecf97a5 2322
1154f91b
BW
2323 // fire the tool dropdown event
2324 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, m_action_item->id);
2325 e.SetEventObject(this);
2326 e.SetToolId(m_action_item->id);
2327 e.SetDropDownClicked(false);
eecf97a5 2328
1154f91b
BW
2329 int mouse_x = evt.GetX();
2330 wxRect rect = m_action_item->sizer_item->GetRect();
eecf97a5 2331
1154f91b
BW
2332 if (m_action_item->dropdown &&
2333 mouse_x >= (rect.x+rect.width-BUTTON_DROPDOWN_WIDTH-1) &&
2334 mouse_x < (rect.x+rect.width))
2335 {
2336 e.SetDropDownClicked(true);
2337 }
eecf97a5 2338
1154f91b
BW
2339 e.SetClickPoint(evt.GetPosition());
2340 e.SetItemRect(rect);
004867db 2341 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2342 DoIdleUpdate();
2343 }
2344}
2345
2346void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt)
2347{
2348 SetPressedItem(NULL);
2349
2350 wxAuiToolBarItem* hit_item = FindToolByPosition(evt.GetX(), evt.GetY());
2351 if (hit_item && !(hit_item->state & wxAUI_BUTTON_STATE_DISABLED))
2352 {
2353 SetHoverItem(hit_item);
2354 }
2355
2356
2357 if (m_dragging)
2358 {
2359 // reset drag and drop member variables
2360 m_dragging = false;
2361 m_action_pos = wxPoint(-1,-1);
2362 m_action_item = NULL;
2363 return;
2364 }
8b385bf8 2365 else
1154f91b
BW
2366 {
2367 wxAuiToolBarItem* hit_item;
2368 hit_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2369
1154f91b
BW
2370 if (m_action_item && hit_item == m_action_item)
2371 {
8b385bf8 2372 UnsetToolTip();
eecf97a5 2373
1154f91b
BW
2374 if (hit_item->kind == wxITEM_CHECK)
2375 {
2376 bool toggle = false;
eecf97a5 2377
1154f91b
BW
2378 if (m_action_item->state & wxAUI_BUTTON_STATE_CHECKED)
2379 toggle = false;
8b385bf8 2380 else
1154f91b 2381 toggle = true;
eecf97a5 2382
1154f91b 2383 ToggleTool(m_action_item->id, toggle);
eecf97a5 2384
1154f91b
BW
2385 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
2386 e.SetEventObject(this);
004867db 2387 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2388 DoIdleUpdate();
2389 }
8b385bf8 2390 else
1154f91b
BW
2391 {
2392 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
2393 e.SetEventObject(this);
004867db 2394 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2395 DoIdleUpdate();
2396 }
2397 }
2398 }
2399
2400 // reset drag and drop member variables
2401 m_dragging = false;
2402 m_action_pos = wxPoint(-1,-1);
2403 m_action_item = NULL;
2404}
2405
2406void wxAuiToolBar::OnRightDown(wxMouseEvent& evt)
2407{
2408 wxRect cli_rect(wxPoint(0,0), GetClientSize());
eecf97a5 2409
1154f91b
BW
2410 if (m_gripper_sizer_item)
2411 {
2412 wxRect gripper_rect = m_gripper_sizer_item->GetRect();
2413 if (gripper_rect.Contains(evt.GetX(), evt.GetY()))
2414 return;
2415 }
eecf97a5 2416
1154f91b
BW
2417 if (m_overflow_sizer_item)
2418 {
2419 int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
2420 if (dropdown_size > 0 &&
2421 evt.m_x > cli_rect.width - dropdown_size &&
2422 evt.m_y >= 0 &&
2423 evt.m_y < cli_rect.height &&
2424 m_art)
2425 {
2426 return;
2427 }
2428 }
eecf97a5 2429
1154f91b
BW
2430 m_action_pos = wxPoint(evt.GetX(), evt.GetY());
2431 m_action_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2432
1154f91b
BW
2433 if (m_action_item)
2434 {
2435 if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED)
2436 {
2437 m_action_pos = wxPoint(-1,-1);
2438 m_action_item = NULL;
2439 return;
2440 }
2441 }
2442}
2443
2444void wxAuiToolBar::OnRightUp(wxMouseEvent& evt)
2445{
2446 wxAuiToolBarItem* hit_item;
2447 hit_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2448
1154f91b
BW
2449 if (m_action_item && hit_item == m_action_item)
2450 {
2451 if (hit_item->kind == wxITEM_NORMAL)
2452 {
2453 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, m_action_item->id);
2454 e.SetEventObject(this);
2455 e.SetToolId(m_action_item->id);
2456 e.SetClickPoint(m_action_pos);
004867db 2457 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2458 DoIdleUpdate();
2459 }
2460 }
8b385bf8 2461 else
1154f91b
BW
2462 {
2463 // right-clicked on the invalid area of the toolbar
2464 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, -1);
2465 e.SetEventObject(this);
2466 e.SetToolId(-1);
2467 e.SetClickPoint(m_action_pos);
004867db 2468 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2469 DoIdleUpdate();
2470 }
2471
2472 // reset member variables
2473 m_action_pos = wxPoint(-1,-1);
2474 m_action_item = NULL;
2475}
2476
2477void wxAuiToolBar::OnMiddleDown(wxMouseEvent& evt)
2478{
2479 wxRect cli_rect(wxPoint(0,0), GetClientSize());
eecf97a5 2480
1154f91b
BW
2481 if (m_gripper_sizer_item)
2482 {
2483 wxRect gripper_rect = m_gripper_sizer_item->GetRect();
2484 if (gripper_rect.Contains(evt.GetX(), evt.GetY()))
2485 return;
2486 }
eecf97a5 2487
1154f91b
BW
2488 if (m_overflow_sizer_item)
2489 {
2490 int dropdown_size = m_art->GetElementSize(wxAUI_TBART_OVERFLOW_SIZE);
2491 if (dropdown_size > 0 &&
2492 evt.m_x > cli_rect.width - dropdown_size &&
2493 evt.m_y >= 0 &&
2494 evt.m_y < cli_rect.height &&
2495 m_art)
2496 {
2497 return;
2498 }
2499 }
eecf97a5 2500
1154f91b
BW
2501 m_action_pos = wxPoint(evt.GetX(), evt.GetY());
2502 m_action_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2503
1154f91b
BW
2504 if (m_action_item)
2505 {
2506 if (m_action_item->state & wxAUI_BUTTON_STATE_DISABLED)
2507 {
2508 m_action_pos = wxPoint(-1,-1);
2509 m_action_item = NULL;
2510 return;
2511 }
2512 }
2513}
2514
2515void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt)
2516{
2517 wxAuiToolBarItem* hit_item;
2518 hit_item = FindToolByPosition(evt.GetX(), evt.GetY());
eecf97a5 2519
1154f91b
BW
2520 if (m_action_item && hit_item == m_action_item)
2521 {
2522 if (hit_item->kind == wxITEM_NORMAL)
2523 {
2524 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, m_action_item->id);
2525 e.SetEventObject(this);
2526 e.SetToolId(m_action_item->id);
2527 e.SetClickPoint(m_action_pos);
004867db 2528 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2529 DoIdleUpdate();
2530 }
2531 }
2532
2533 // reset member variables
2534 m_action_pos = wxPoint(-1,-1);
2535 m_action_item = NULL;
2536}
2537
2538void wxAuiToolBar::OnMotion(wxMouseEvent& evt)
2539{
2540 // start a drag event
2541 if (!m_dragging &&
2542 m_action_item != NULL &&
2543 m_action_pos != wxPoint(-1,-1) &&
2544 abs(evt.m_x - m_action_pos.x) + abs(evt.m_y - m_action_pos.y) > 5)
2545 {
8b385bf8 2546 UnsetToolTip();
eecf97a5 2547
1154f91b 2548 m_dragging = true;
eecf97a5 2549
1154f91b
BW
2550 wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId());
2551 e.SetEventObject(this);
2552 e.SetToolId(m_action_item->id);
004867db 2553 GetEventHandler()->ProcessEvent(e);
1154f91b
BW
2554 DoIdleUpdate();
2555 return;
2556 }
2557
2558 wxAuiToolBarItem* hit_item = FindToolByPosition(evt.GetX(), evt.GetY());
2559 if (hit_item)
2560 {
2561 if (!(hit_item->state & wxAUI_BUTTON_STATE_DISABLED))
2562 SetHoverItem(hit_item);
8b385bf8 2563 else
1154f91b
BW
2564 SetHoverItem(NULL);
2565 }
8b385bf8 2566 else
1154f91b
BW
2567 {
2568 // no hit item, remove any hit item
2569 SetHoverItem(hit_item);
2570 }
eecf97a5 2571
1154f91b
BW
2572 // figure out tooltips
2573 wxAuiToolBarItem* packing_hit_item;
2574 packing_hit_item = FindToolByPositionWithPacking(evt.GetX(), evt.GetY());
2575 if (packing_hit_item)
2576 {
2577 if (packing_hit_item != m_tip_item)
2578 {
2579 m_tip_item = packing_hit_item;
eecf97a5 2580
8b385bf8 2581 if ( !packing_hit_item->short_help.empty() )
1154f91b 2582 SetToolTip(packing_hit_item->short_help);
8b385bf8
VZ
2583 else
2584 UnsetToolTip();
1154f91b
BW
2585 }
2586 }
8b385bf8 2587 else
1154f91b 2588 {
8b385bf8 2589 UnsetToolTip();
1154f91b
BW
2590 m_tip_item = NULL;
2591 }
eecf97a5 2592
1154f91b
BW
2593 // if we've pressed down an item and we're hovering
2594 // over it, make sure it's state is set to pressed
2595 if (m_action_item)
2596 {
2597 if (m_action_item == hit_item)
2598 SetPressedItem(m_action_item);
8b385bf8 2599 else
1154f91b
BW
2600 SetPressedItem(NULL);
2601 }
eecf97a5 2602
1154f91b
BW
2603 // figure out the dropdown button state (are we hovering or pressing it?)
2604 RefreshOverflowState();
2605}
2606
2607void wxAuiToolBar::OnLeaveWindow(wxMouseEvent& WXUNUSED(evt))
2608{
2609 RefreshOverflowState();
2610 SetHoverItem(NULL);
2611 SetPressedItem(NULL);
eecf97a5 2612
1154f91b
BW
2613 m_tip_item = NULL;
2614}
2615
2616
2617void wxAuiToolBar::OnSetCursor(wxSetCursorEvent& evt)
2618{
2619 wxCursor cursor = wxNullCursor;
eecf97a5 2620
1154f91b
BW
2621 if (m_gripper_sizer_item)
2622 {
2623 wxRect gripper_rect = m_gripper_sizer_item->GetRect();
2624 if (gripper_rect.Contains(evt.GetX(), evt.GetY()))
2625 {
2626 cursor = wxCursor(wxCURSOR_SIZING);
2627 }
2628 }
eecf97a5 2629
1154f91b
BW
2630 evt.SetCursor(cursor);
2631}
2632
2633
2634#endif // wxUSE_AUI
2635