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