]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
scaling for 24x24 and 64x64 sizes
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: toolbar.cpp
3// Purpose: wxToolBar
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
84969af7 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: The wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "toolbar.h"
14#endif
15
3d1a4878 16#include "wx/wxprec.h"
519cb848
SC
17
18#if wxUSE_TOOLBAR
19
3d1a4878 20#include "wx/wx.h"
e9576ca5 21#include "wx/toolbar.h"
2f1ae414
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
72055702 24#include "wx/bitmap.h"
e9576ca5 25
2f1ae414 26#if !USE_SHARED_LIBRARY
2eb10e2a 27IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
e9576ca5
SC
28
29BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
e044f600 30 EVT_PAINT( wxToolBar::OnPaint )
e9576ca5 31END_EVENT_TABLE()
2f1ae414 32#endif
e9576ca5 33
d497dca4 34#include "wx/mac/uma.h"
bfe9ffbc 35#include "wx/geometry.h"
ee799df7
SC
36
37#ifdef __WXMAC_OSX__
abbcdf3f
SC
38const short kwxMacToolBarToolDefaultWidth = 24 ;
39const short kwxMacToolBarToolDefaultHeight = 24 ;
ee799df7
SC
40const short kwxMacToolBarTopMargin = 4 ;
41const short kwxMacToolBarLeftMargin = 4 ;
42const short kwxMacToolBorder = 0 ;
abbcdf3f 43const short kwxMacToolSpacing = 6 ;
ee799df7
SC
44#else
45const short kwxMacToolBarToolDefaultWidth = 24 ;
46const short kwxMacToolBarToolDefaultHeight = 22 ;
47const short kwxMacToolBarTopMargin = 2 ;
48const short kwxMacToolBarLeftMargin = 2 ;
49const short kwxMacToolBorder = 4 ;
abbcdf3f 50const short kwxMacToolSpacing = 0 ;
ee799df7
SC
51#endif
52
37e2cb08
SC
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
57class wxToolBarTool : public wxToolBarToolBase
58{
59public:
60 wxToolBarTool(wxToolBar *tbar,
61 int id,
27e2d606
GD
62 const wxString& label,
63 const wxBitmap& bmpNormal,
64 const wxBitmap& bmpDisabled,
65 wxItemKind kind,
37e2cb08 66 wxObject *clientData,
27e2d606 67 const wxString& shortHelp,
bfe9ffbc
SC
68 const wxString& longHelp) ;
69
37e2cb08
SC
70 wxToolBarTool(wxToolBar *tbar, wxControl *control)
71 : wxToolBarToolBase(tbar, control)
72 {
bfe9ffbc 73 Init() ;
37e2cb08 74 }
bfe9ffbc
SC
75
76 ~wxToolBarTool()
77 {
78 if ( m_controlHandle )
79 DisposeControl( m_controlHandle ) ;
80 }
81
facd6764
SC
82 WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; }
83 void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; }
37e2cb08 84
bfe9ffbc
SC
85 void SetSize(const wxSize& size) ;
86 void SetPosition( const wxPoint& position ) ;
a2fe01c9 87
bfe9ffbc
SC
88 wxSize GetSize() const
89 {
90 if ( IsControl() )
91 {
92 return GetControl()->GetSize() ;
93 }
94 else if ( IsButton() )
95 {
96 return GetToolBar()->GetToolSize() ;
97 }
98 else
99 {
abbcdf3f 100 // separator size
bfe9ffbc 101 wxSize sz = GetToolBar()->GetToolSize() ;
5a904a32
SC
102 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
103 sz.y /= 4 ;
104 else
105 sz.x /= 4 ;
bfe9ffbc
SC
106 return sz ;
107 }
108 }
109 wxPoint GetPosition() const
110 {
111 return wxPoint(m_x, m_y);
112 }
a2fe01c9 113 bool DoEnable( bool enable ) ;
73fd9428
SC
114
115 void UpdateToggleImage( bool toggle ) ;
bfe9ffbc
SC
116private :
117 void Init()
118 {
119 m_controlHandle = NULL ;
120 }
facd6764 121 ControlRef m_controlHandle ;
37e2cb08 122
bfe9ffbc
SC
123 wxCoord m_x;
124 wxCoord m_y;
37e2cb08
SC
125};
126
facd6764
SC
127static const EventTypeSpec eventList[] =
128{
129 { kEventClassControl , kEventControlHit } ,
73fd9428
SC
130#ifdef __WXMAC_OSX__
131 { kEventClassControl , kEventControlHitTest } ,
132#endif
facd6764
SC
133} ;
134
135static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
136{
137 OSStatus result = eventNotHandledErr ;
138
139 wxMacCarbonEvent cEvent( event ) ;
140
141 ControlRef controlRef ;
142
143 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
144
145 switch( GetEventKind( event ) )
146 {
147 case kEventControlHit :
148 {
149 wxToolBarTool* tbartool = (wxToolBarTool*)data ;
150 if ( tbartool->CanBeToggled() )
151 {
64f553a4
SC
152#ifdef __WXMAC_OSX__
153 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), !tbartool->IsToggled() );
154#else
214b9484 155 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
64f553a4 156#endif
facd6764
SC
157 }
158 ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
facd6764
SC
159 result = noErr;
160 }
161 break ;
73fd9428
SC
162#ifdef __WXMAC_OSX__
163 case kEventControlHitTest :
164 {
165 HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
166 HIRect rect ;
167 HIViewGetBounds( controlRef , &rect ) ;
168
169 ControlPartCode pc = kControlNoPart ;
170 if ( CGRectContainsPoint( rect , pt ) )
171 pc = kControlButtonPart ;
172 cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
173 result = noErr ;
174 }
175 break ;
176#endif
facd6764
SC
177 default :
178 break ;
179 }
180 return result ;
181}
182
183pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
184{
185 OSStatus result = eventNotHandledErr ;
186
187 switch ( GetEventClass( event ) )
188 {
189 case kEventClassControl :
190 result = wxMacToolBarToolControlEventHandler( handler, event, data ) ;
191 break ;
192 default :
193 break ;
194 }
195 return result ;
196}
197
198DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
199
37e2cb08
SC
200// ============================================================================
201// implementation
202// ============================================================================
203
204// ----------------------------------------------------------------------------
205// wxToolBarTool
206// ----------------------------------------------------------------------------
207
a2fe01c9
SC
208bool wxToolBarTool::DoEnable(bool enable)
209{
210 if ( IsControl() )
211 {
212 GetControl()->Enable( enable ) ;
213 }
214 else if ( IsButton() )
215 {
216#if TARGET_API_MAC_OSX
217 if ( enable )
218 EnableControl( m_controlHandle ) ;
219 else
220 DisableControl( m_controlHandle ) ;
221#else
222 if ( enable )
223 ActivateControl( m_controlHandle ) ;
224 else
225 DeactivateControl( m_controlHandle ) ;
226#endif
227 }
228 return true ;
229}
bfe9ffbc
SC
230void wxToolBarTool::SetSize(const wxSize& size)
231{
232 if ( IsControl() )
233 {
234 GetControl()->SetSize( size ) ;
235 }
236}
237
238void wxToolBarTool::SetPosition(const wxPoint& position)
239{
240 m_x = position.x;
241 m_y = position.y;
242
243 if ( IsButton() )
244 {
245 int x , y ;
246 x = y = 0 ;
facd6764
SC
247 int mac_x = position.x ;
248 int mac_y = position.y ;
ee799df7 249#ifdef __WXMAC_OSX__
73fd9428 250 // already correctly set up
ee799df7 251#else
facd6764 252 WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetTopLevelWindowRef() ;
bfe9ffbc 253 GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
facd6764
SC
254 mac_x += x;
255 mac_y += y;
256#endif
bfe9ffbc
SC
257 Rect contrlRect ;
258 GetControlBounds( m_controlHandle , &contrlRect ) ;
259 int former_mac_x = contrlRect.left ;
260 int former_mac_y = contrlRect.top ;
80e3f464 261 GetToolBar()->GetToolSize() ;
bfe9ffbc
SC
262
263 if ( mac_x != former_mac_x || mac_y != former_mac_y )
264 {
bfe9ffbc 265 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
bfe9ffbc
SC
266 }
267 }
268 else if ( IsControl() )
269 {
270 GetControl()->Move( position ) ;
271 }
abbcdf3f
SC
272 else
273 {
274 // separator
275#ifdef __WXMAC_OSX__
276 int x , y ;
277 x = y = 0 ;
278 int mac_x = position.x ;
279 int mac_y = position.y ;
280
281 Rect contrlRect ;
282 GetControlBounds( m_controlHandle , &contrlRect ) ;
283 int former_mac_x = contrlRect.left ;
284 int former_mac_y = contrlRect.top ;
285
286 if ( mac_x != former_mac_x || mac_y != former_mac_y )
287 {
288 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
289 }
290#endif
291 }
bfe9ffbc
SC
292}
293
73fd9428
SC
294void wxToolBarTool::UpdateToggleImage( bool toggle )
295{
296#ifdef __WXMAC_OSX__
297 if ( toggle )
298 {
299 int w = m_bmpNormal.GetWidth() ;
300 int h = m_bmpNormal.GetHeight() ;
301 wxBitmap bmp( w , h ) ;
302 wxMemoryDC dc ;
303 dc.SelectObject( bmp ) ;
304 dc.SetPen( wxNullPen ) ;
305 dc.SetBackground( *wxWHITE ) ;
306 dc.DrawRectangle( 0 , 0 , w , h ) ;
307 dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ;
308 dc.SelectObject( wxNullBitmap ) ;
309 ControlButtonContentInfo info ;
310 wxMacCreateBitmapButton( &info , bmp ) ;
311 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
312 (Ptr)&info );
313 wxMacReleaseBitmapButton( &info ) ;
314 }
315 else
316 {
317 ControlButtonContentInfo info ;
318 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
319 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
320 (Ptr)&info );
321 wxMacReleaseBitmapButton( &info ) ;
322 }
323
324 IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
325 SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
326 (Ptr)&transform );
327 HIViewSetNeedsDisplay( m_controlHandle , true ) ;
328
329#else
330 ::SetControl32BitValue( m_controlHandle , toggle ) ;
331#endif
332}
333
bfe9ffbc
SC
334wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
335 int id,
336 const wxString& label,
337 const wxBitmap& bmpNormal,
338 const wxBitmap& bmpDisabled,
339 wxItemKind kind,
340 wxObject *clientData,
341 const wxString& shortHelp,
342 const wxString& longHelp)
343 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
344 clientData, shortHelp, longHelp)
345{
f4e0be4f
RR
346 Init();
347
facd6764 348 WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ;
bfe9ffbc
SC
349 wxSize toolSize = tbar->GetToolSize() ;
350 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
abbcdf3f
SC
351
352 if ( id == wxID_SEPARATOR )
ee799df7 353 {
abbcdf3f
SC
354 toolSize.x /= 4 ;
355 toolSize.y /= 4 ;
356 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
357 {
358 toolrect.bottom = toolSize.y ;
359 }
360 else
361 {
362 toolrect.right = toolSize.x ;
363 }
364#ifdef __WXMAC_OSX__
365 // in flat style we need a visual separator
366 CreateSeparatorControl( window , &toolrect , &m_controlHandle ) ;
367#endif
ee799df7 368 }
abbcdf3f
SC
369 else
370 {
371 ControlButtonContentInfo info ;
372 wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ;
373
374#ifdef __WXMAC_OSX__
abbcdf3f 375 CreateIconControl( window , &toolrect , &info , false , &m_controlHandle ) ;
ee799df7 376#else
abbcdf3f
SC
377 SInt16 behaviour = kControlBehaviorOffsetContents ;
378 if ( CanBeToggled() )
379 behaviour += kControlBehaviorToggles ;
380 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
381 0 , 0 , 0 , &m_controlHandle ) ;
ee799df7 382#endif
abbcdf3f
SC
383
384 wxMacReleaseBitmapButton( &info ) ;
385 /*
386 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
387 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
388 */
4c37f124 389
abbcdf3f
SC
390 InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
391 GetEventTypeCount(eventList), eventList, this,NULL);
4c37f124 392
abbcdf3f 393 }
facd6764 394 ControlRef container = (ControlRef) tbar->GetHandle() ;
bfe9ffbc 395 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
abbcdf3f
SC
396 if ( m_controlHandle )
397 {
398 UMAShowControl( m_controlHandle ) ;
399 ::EmbedControl( m_controlHandle , container ) ;
400 }
73fd9428
SC
401 if ( CanBeToggled() && IsToggled() )
402 {
403 UpdateToggleImage( true ) ;
404 }
bfe9ffbc
SC
405}
406
2f1ae414 407
37e2cb08 408wxToolBarToolBase *wxToolBar::CreateTool(int id,
27e2d606
GD
409 const wxString& label,
410 const wxBitmap& bmpNormal,
411 const wxBitmap& bmpDisabled,
412 wxItemKind kind,
37e2cb08 413 wxObject *clientData,
27e2d606
GD
414 const wxString& shortHelp,
415 const wxString& longHelp)
37e2cb08 416{
27e2d606
GD
417 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
418 clientData, shortHelp, longHelp);
37e2cb08
SC
419}
420
421wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
422{
423 return new wxToolBarTool(this, control);
424}
425
37e2cb08 426void wxToolBar::Init()
e9576ca5 427{
e40298d5
JS
428 m_maxWidth = -1;
429 m_maxHeight = -1;
430 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
431 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
e9576ca5
SC
432}
433
434bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
435 long style, const wxString& name)
e40298d5 436{
ee799df7 437
facd6764
SC
438 if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
439 return FALSE ;
e40298d5
JS
440
441 return TRUE;
e9576ca5
SC
442}
443
444wxToolBar::~wxToolBar()
bfe9ffbc 445{
7810c95b
SC
446 // we must refresh the frame size when the toolbar is deleted but the frame
447 // is not - otherwise toolbar leaves a hole in the place it used to occupy
e9576ca5
SC
448}
449
37e2cb08 450bool wxToolBar::Realize()
e9576ca5 451{
eb22f2a6 452 if (m_tools.GetCount() == 0)
0b7a8cd3
GD
453 return FALSE;
454
bfe9ffbc
SC
455 int x = m_xMargin + kwxMacToolBarLeftMargin ;
456 int y = m_yMargin + kwxMacToolBarTopMargin ;
0b7a8cd3 457
7c551d95
SC
458 int tw, th;
459 GetSize(& tw, & th);
895f5af7
SC
460
461 int maxWidth = 0 ;
462 int maxHeight = 0 ;
463
bfe9ffbc
SC
464 int maxToolWidth = 0;
465 int maxToolHeight = 0;
466
467 // Find the maximum tool width and height
affd2611 468 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc
SC
469 while ( node )
470 {
471 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
472 wxSize sz = tool->GetSize() ;
473
474 if ( sz.x > maxToolWidth )
475 maxToolWidth = sz.x ;
476 if (sz.y> maxToolHeight)
477 maxToolHeight = sz.y;
478
479 node = node->GetNext();
480 }
481
214b9484 482 bool lastWasRadio = FALSE;
bfe9ffbc 483 node = m_tools.GetFirst();
0b7a8cd3 484 while (node)
7810c95b 485 {
eb22f2a6 486 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
bfe9ffbc 487 wxSize cursize = tool->GetSize() ;
0b7a8cd3 488
214b9484
RD
489 bool isRadio = FALSE;
490
491 if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO )
492 {
493 if ( !lastWasRadio )
494 {
495 if (tool->Toggle(true))
496 {
497 DoToggleTool(tool, true);
498 }
499 }
500 isRadio = TRUE;
501 }
502 else
503 {
504 isRadio = FALSE;
505 }
506 lastWasRadio = isRadio;
507
bfe9ffbc
SC
508 // for the moment we just do a single row/column alignement
509 if ( x + cursize.x > maxWidth )
510 maxWidth = x + cursize.x ;
511 if ( y + cursize.y > maxHeight )
512 maxHeight = y + cursize.y ;
0b7a8cd3 513
73fd9428
SC
514 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
515 {
516 int x1 = x + (maxToolWidth - cursize.x)/2 ;
517 tool->SetPosition( wxPoint( x1 , y ) ) ;
518 }
519 else
520 {
521 int y1 = y + (maxToolHeight - cursize.y)/2 ;
522 tool->SetPosition( wxPoint( x , y1 ) ) ;
523 }
bfe9ffbc
SC
524 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
525 {
526 y += cursize.y ;
abbcdf3f 527 y += kwxMacToolSpacing ;
0b7a8cd3
GD
528 }
529 else
530 {
bfe9ffbc 531 x += cursize.x ;
abbcdf3f 532 x += kwxMacToolSpacing ;
0b7a8cd3 533 }
bfe9ffbc 534
eb22f2a6 535 node = node->GetNext();
7810c95b 536 }
0b7a8cd3
GD
537
538 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 539 {
0b7a8cd3
GD
540 if ( m_maxRows == 0 )
541 {
542 // if not set yet, only one row
543 SetRows(1);
544 }
90d3f91a 545 m_minWidth = maxWidth;
0b7a8cd3 546 maxWidth = tw ;
0b7a8cd3 547 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
90d3f91a 548 m_minHeight = m_maxHeight = maxHeight ;
7810c95b 549 }
0b7a8cd3
GD
550 else
551 {
bfe9ffbc 552 if ( GetToolsCount() > 0 && m_maxRows == 0 )
0b7a8cd3
GD
553 {
554 // if not set yet, have one column
bfe9ffbc 555 SetRows(GetToolsCount());
0b7a8cd3 556 }
90d3f91a 557 m_minHeight = maxHeight;
0b7a8cd3 558 maxHeight = th ;
0b7a8cd3 559 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
90d3f91a 560 m_minWidth = m_maxWidth = maxWidth ;
0b7a8cd3
GD
561 }
562
facd6764 563 SetSize( maxWidth, maxHeight );
9f884528 564 InvalidateBestSize();
0b7a8cd3
GD
565
566 return TRUE;
e9576ca5
SC
567}
568
569void wxToolBar::SetToolBitmapSize(const wxSize& size)
570{
ee799df7 571 m_defaultWidth = size.x+kwxMacToolBorder; m_defaultHeight = size.y+kwxMacToolBorder;
e9576ca5
SC
572}
573
e9576ca5
SC
574// The button size is bigger than the bitmap size
575wxSize wxToolBar::GetToolSize() const
576{
ee799df7 577 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
578}
579
37e2cb08 580void wxToolBar::SetRows(int nRows)
e9576ca5 581{
37e2cb08 582 if ( nRows == m_maxRows )
e9576ca5 583 {
37e2cb08
SC
584 // avoid resizing the frame uselessly
585 return;
e9576ca5 586 }
37e2cb08
SC
587
588 m_maxRows = nRows;
e9576ca5
SC
589}
590
c257d44d
SC
591void wxToolBar::MacSuperChangedPosition()
592{
c257d44d 593 wxWindow::MacSuperChangedPosition() ;
bfe9ffbc 594 Realize() ;
c257d44d
SC
595}
596
37e2cb08 597wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 598{
affd2611 599 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc 600 while (node)
e044f600 601 {
bfe9ffbc
SC
602 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
603 wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
604 if ( r.Contains( wxPoint( x , y ) ) )
e044f600 605 {
bfe9ffbc 606 return tool;
e044f600 607 }
bfe9ffbc
SC
608
609 node = node->GetNext();
e044f600 610 }
37e2cb08
SC
611
612 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
613}
614
2f1ae414
SC
615wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
616{
e044f600
RR
617 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
618 if ( tool )
619 {
620 return tool->GetShortHelp() ;
621 }
427ff662 622 return wxEmptyString ;
2f1ae414
SC
623}
624
37e2cb08 625void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 626{
a2fe01c9 627 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
628}
629
37e2cb08 630void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 631{
e044f600 632 wxToolBarTool *tool = (wxToolBarTool *)t;
bfe9ffbc
SC
633 if ( tool->IsButton() )
634 {
73fd9428 635 tool->UpdateToggleImage( toggle ) ;
bfe9ffbc 636 }
37e2cb08 637}
7c551d95 638
37e2cb08
SC
639bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
640 wxToolBarToolBase *tool)
641{
bfe9ffbc 642 // nothing special to do here - we relayout in Realize() later
37e2cb08 643 tool->Attach(this);
9f884528 644 InvalidateBestSize();
7c551d95 645
37e2cb08
SC
646 return TRUE;
647}
e9576ca5 648
5115c51a 649void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 650{
5115c51a 651 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
652}
653
bfe9ffbc 654bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
37e2cb08 655{
affd2611 656 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
657 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
658 {
659 wxToolBarToolBase *tool2 = node->GetData();
660 if ( tool2 == tool )
661 {
662 // let node point to the next node in the list
663 node = node->GetNext();
664
665 break;
666 }
667 }
668
669 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
670
671 tool->Detach();
672
673 // and finally reposition all the controls after this one
674
675 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
676 {
677 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
678 wxPoint pt = tool2->GetPosition() ;
679
680 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
681 {
682 pt.y -= sz.y ;
683 }
684 else
685 {
686 pt.x -= sz.x ;
687 }
688 tool2->SetPosition( pt ) ;
689 }
690
9f884528 691 InvalidateBestSize();
5115c51a 692 return TRUE ;
37e2cb08 693}
2f1ae414
SC
694
695void wxToolBar::OnPaint(wxPaintEvent& event)
696{
e40298d5 697 wxPaintDC dc(this) ;
20b69855 698#if wxMAC_USE_CORE_GRAPHICS
ee799df7 699 // leave the background as it is (striped or metal)
20b69855 700#else
e40298d5 701 wxMacPortSetter helper(&dc) ;
facd6764
SC
702 int w, h ;
703 GetSize( &w , &h ) ;
e40298d5 704
1fd1922a 705 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
706 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
707/*
708 if( toolbarrect.left < 0 )
709 toolbarrect.left = 0 ;
710 if ( toolbarrect.top < 0 )
711 toolbarrect.top = 0 ;
712*/
01ffa8f7
SC
713 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
714 {
715 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
716 }
717 else
718 {
719#if TARGET_API_MAC_OSX
720#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
20b69855
SC
721 if ( UMAGetSystemVersion() >= 0x1030 )
722 {
723 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
724 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
725 CGContextRef cgContext ;
726 Rect bounds ;
727 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
728 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
729 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
730 CGContextScaleCTM( cgContext , 1 , -1 ) ;
785f5eaa 731
20b69855
SC
732 {
733 HIThemeBackgroundDrawInfo drawInfo ;
734 drawInfo.version = 0 ;
735 drawInfo.state = kThemeStateActive ;
736 drawInfo.kind = kThemeBackgroundMetal ;
737 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
738 }
739 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
740 }
741 else
742#endif
01ffa8f7 743 {
20b69855 744 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 745 }
01ffa8f7 746#endif
01ffa8f7
SC
747 }
748#endif
20b69855 749
facd6764 750 event.Skip() ;
2f1ae414 751}
895f5af7 752
519cb848
SC
753#endif // wxUSE_TOOLBAR
754