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