]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
fixed (harmless) unused variable warning in release build
[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"
72055702 21#include "wx/bitmap.h"
e56d2520 22#include "wx/toolbar.h"
e9576ca5 23
2eb10e2a 24IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
e9576ca5
SC
25
26BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
f3a65c3e 27 EVT_PAINT( wxToolBar::OnPaint )
e9576ca5 28END_EVENT_TABLE()
e9576ca5 29
d497dca4 30#include "wx/mac/uma.h"
bfe9ffbc 31#include "wx/geometry.h"
ee799df7
SC
32
33#ifdef __WXMAC_OSX__
17dfb611
SC
34const short kwxMacToolBarToolDefaultWidth = 16 ;
35const short kwxMacToolBarToolDefaultHeight = 16 ;
e56d2520
SC
36const short kwxMacToolBarTopMargin = 4 ; // 1 ; // used to be 4
37const short kwxMacToolBarLeftMargin = 4 ; //1 ; // used to be 4
38const short kwxMacToolBorder = 0 ; // used to be 0
39const short kwxMacToolSpacing = 6 ; // 2 ; // used to be 6
ee799df7
SC
40#else
41const short kwxMacToolBarToolDefaultWidth = 24 ;
42const short kwxMacToolBarToolDefaultHeight = 22 ;
43const short kwxMacToolBarTopMargin = 2 ;
44const short kwxMacToolBarLeftMargin = 2 ;
45const short kwxMacToolBorder = 4 ;
abbcdf3f 46const short kwxMacToolSpacing = 0 ;
ee799df7
SC
47#endif
48
e56d2520
SC
49#pragma mark -
50#pragma mark Tool Implementation
51
52
37e2cb08
SC
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
e56d2520
SC
57// We have a dual implementation for each tool, ControlRef and HIToolbarItemRef
58
37e2cb08
SC
59class wxToolBarTool : public wxToolBarToolBase
60{
61public:
62 wxToolBarTool(wxToolBar *tbar,
63 int id,
27e2d606
GD
64 const wxString& label,
65 const wxBitmap& bmpNormal,
66 const wxBitmap& bmpDisabled,
67 wxItemKind kind,
37e2cb08 68 wxObject *clientData,
27e2d606 69 const wxString& shortHelp,
bfe9ffbc 70 const wxString& longHelp) ;
f3a65c3e 71
37e2cb08
SC
72 wxToolBarTool(wxToolBar *tbar, wxControl *control)
73 : wxToolBarToolBase(tbar, control)
74 {
bfe9ffbc 75 Init() ;
e56d2520
SC
76 if (control != NULL)
77 SetControlHandle( (ControlRef) control->GetHandle() ) ;
37e2cb08 78 }
f3a65c3e 79
bfe9ffbc
SC
80 ~wxToolBarTool()
81 {
e56d2520 82 ClearControl() ;
bfe9ffbc
SC
83 if ( m_controlHandle )
84 DisposeControl( m_controlHandle ) ;
e56d2520
SC
85#if wxMAC_USE_NATIVE_TOOLBAR
86 if ( m_toolbarItemRef )
87 CFRelease( m_toolbarItemRef ) ;
88#endif
bfe9ffbc 89 }
f3a65c3e
VZ
90
91 WXWidget GetControlHandle()
92 {
93 return (WXWidget) m_controlHandle ;
e56d2520 94 }
f3a65c3e
VZ
95
96 void SetControlHandle( ControlRef handle )
97 {
98 m_controlHandle = handle ;
e56d2520 99 }
37e2cb08 100
bfe9ffbc 101 void SetPosition( const wxPoint& position ) ;
f3a65c3e
VZ
102
103 void ClearControl()
104 {
105 m_control = NULL ;
e56d2520 106#if wxMAC_USE_NATIVE_TOOLBAR
f3a65c3e
VZ
107 m_toolbarItemRef = NULL ;
108#endif
e56d2520 109 }
f3a65c3e 110
bfe9ffbc
SC
111 wxSize GetSize() const
112 {
113 if ( IsControl() )
114 {
115 return GetControl()->GetSize() ;
116 }
117 else if ( IsButton() )
118 {
119 return GetToolBar()->GetToolSize() ;
120 }
121 else
122 {
abbcdf3f 123 // separator size
bfe9ffbc 124 wxSize sz = GetToolBar()->GetToolSize() ;
5a904a32
SC
125 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
126 sz.y /= 4 ;
127 else
128 sz.x /= 4 ;
bfe9ffbc
SC
129 return sz ;
130 }
131 }
132 wxPoint GetPosition() const
133 {
134 return wxPoint(m_x, m_y);
f3a65c3e 135 }
a2fe01c9 136 bool DoEnable( bool enable ) ;
f3a65c3e 137
73fd9428 138 void UpdateToggleImage( bool toggle ) ;
f3a65c3e
VZ
139
140#if wxMAC_USE_NATIVE_TOOLBAR
141 void SetToolbarItemRef( HIToolbarItemRef ref )
142 {
e56d2520
SC
143 if ( m_controlHandle )
144 HideControl( m_controlHandle ) ;
145 if ( m_toolbarItemRef )
146 CFRelease( m_toolbarItemRef ) ;
f3a65c3e 147 m_toolbarItemRef = ref ;
e56d2520
SC
148 if ( m_toolbarItemRef )
149 {
150 HIToolbarItemSetHelpText(
151 m_toolbarItemRef, wxMacCFStringHolder( GetShortHelp() , GetToolBar()->GetFont().GetEncoding() ) ,
152 wxMacCFStringHolder( GetLongHelp() , GetToolBar()->GetFont().GetEncoding() ) ) ;
153 }
154 }
f3a65c3e
VZ
155 HIToolbarItemRef GetToolbarItemRef() const
156 {
157 return m_toolbarItemRef ;
e56d2520
SC
158 }
159#endif
5d0bf05a 160
bfe9ffbc 161private :
f3a65c3e 162 void Init()
bfe9ffbc
SC
163 {
164 m_controlHandle = NULL ;
e56d2520
SC
165#if wxMAC_USE_NATIVE_TOOLBAR
166 m_toolbarItemRef = NULL ;
167#endif
bfe9ffbc 168 }
facd6764 169 ControlRef m_controlHandle ;
e56d2520
SC
170#if wxMAC_USE_NATIVE_TOOLBAR
171 HIToolbarItemRef m_toolbarItemRef ;
172#endif
bfe9ffbc
SC
173 wxCoord m_x;
174 wxCoord m_y;
37e2cb08
SC
175};
176
facd6764
SC
177static const EventTypeSpec eventList[] =
178{
179 { kEventClassControl , kEventControlHit } ,
73fd9428
SC
180#ifdef __WXMAC_OSX__
181 { kEventClassControl , kEventControlHitTest } ,
182#endif
facd6764
SC
183} ;
184
185static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
186{
187 OSStatus result = eventNotHandledErr ;
188
189 wxMacCarbonEvent cEvent( event ) ;
f3a65c3e 190
facd6764
SC
191 ControlRef controlRef ;
192
193 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
194
195 switch( GetEventKind( event ) )
196 {
197 case kEventControlHit :
198 {
199 wxToolBarTool* tbartool = (wxToolBarTool*)data ;
e56d2520
SC
200 wxToolBar *tbar = tbartool != NULL ? ( wxToolBar * ) ( tbartool->GetToolBar() ) : NULL ;
201 if ((tbartool != NULL) && tbartool->CanBeToggled() )
facd6764 202 {
e56d2520 203 bool shouldToggle;
64f553a4 204#ifdef __WXMAC_OSX__
e56d2520 205 shouldToggle = !tbartool->IsToggled();
64f553a4 206#else
e56d2520 207 shouldToggle = ( GetControl32BitValue((ControlRef) tbartool->GetControlHandle()) != 0 );
64f553a4 208#endif
e56d2520 209 tbar->ToggleTool( tbartool->GetId(), shouldToggle );
facd6764 210 }
e56d2520
SC
211 if (tbartool != NULL)
212 tbar->OnLeftClick( tbartool->GetId(), tbartool->IsToggled() );
f3a65c3e 213 result = noErr;
facd6764
SC
214 }
215 break ;
5d0bf05a 216
73fd9428
SC
217#ifdef __WXMAC_OSX__
218 case kEventControlHitTest :
219 {
220 HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
221 HIRect rect ;
222 HIViewGetBounds( controlRef , &rect ) ;
f3a65c3e 223
73fd9428
SC
224 ControlPartCode pc = kControlNoPart ;
225 if ( CGRectContainsPoint( rect , pt ) )
d60f41f2 226 pc = kControlIconPart ;
73fd9428
SC
227 cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
228 result = noErr ;
229 }
230 break ;
231#endif
5d0bf05a 232
facd6764
SC
233 default :
234 break ;
235 }
236 return result ;
237}
238
0aeeec99 239static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
facd6764
SC
240{
241 OSStatus result = eventNotHandledErr ;
242
243 switch ( GetEventClass( event ) )
244 {
245 case kEventClassControl :
246 result = wxMacToolBarToolControlEventHandler( handler, event, data ) ;
247 break ;
5d0bf05a 248
facd6764
SC
249 default :
250 break ;
251 }
252 return result ;
253}
254
255DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
256
e56d2520
SC
257#if wxMAC_USE_NATIVE_TOOLBAR
258
259//
260// native toolbar
261//
262
263static const EventTypeSpec toolBarEventList[] =
264{
265 { kEventClassToolbarItem , kEventToolbarItemPerformAction } ,
266} ;
267
268static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
269{
270 OSStatus result = eventNotHandledErr ;
f3a65c3e 271
e56d2520
SC
272 switch( GetEventKind( event ) )
273 {
274 case kEventToolbarItemPerformAction :
275 {
276 wxToolBarTool* tbartool = (wxToolBarTool*) data ;
277 if ( tbartool != NULL )
278 {
279 int toolID = tbartool->GetId();
280 wxToolBar *tbar = ( wxToolBar * ) ( tbartool->GetToolBar() );
281 if ( tbartool->CanBeToggled() )
282 {
283 tbar->ToggleTool(toolID, !tbartool->IsToggled() );
284 }
285 tbar->OnLeftClick( toolID , tbartool -> IsToggled() ) ;
f3a65c3e 286 result = noErr;
e56d2520
SC
287 }
288 }
289 break ;
5d0bf05a 290
e56d2520
SC
291 default :
292 break ;
293 }
294 return result ;
295}
296
297static pascal OSStatus wxMacToolBarEventHandler( EventHandlerCallRef handler, EventRef event, void *data )
298{
299 OSStatus result = eventNotHandledErr ;
300 switch( GetEventClass( event ) )
301 {
302 case kEventClassToolbarItem :
303 result = wxMacToolBarCommandEventHandler( handler, event, data ) ;
304 break ;
5d0bf05a 305
e56d2520
SC
306 default :
307 break ;
308 }
309 return result ;
310}
311
312DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler )
313
314#endif
315
37e2cb08
SC
316// ============================================================================
317// implementation
318// ============================================================================
319
320// ----------------------------------------------------------------------------
321// wxToolBarTool
322// ----------------------------------------------------------------------------
323
a2fe01c9
SC
324bool wxToolBarTool::DoEnable(bool enable)
325{
326 if ( IsControl() )
327 {
328 GetControl()->Enable( enable ) ;
329 }
330 else if ( IsButton() )
331 {
f3a65c3e 332#if wxMAC_USE_NATIVE_TOOLBAR
e56d2520
SC
333 if ( m_toolbarItemRef )
334 HIToolbarItemSetEnabled( m_toolbarItemRef , enable ) ;
335#endif
336
337 if ( m_controlHandle )
338 {
a2fe01c9 339#if TARGET_API_MAC_OSX
e56d2520
SC
340 if ( enable )
341 EnableControl( m_controlHandle ) ;
342 else
343 DisableControl( m_controlHandle ) ;
a2fe01c9 344#else
e56d2520
SC
345 if ( enable )
346 ActivateControl( m_controlHandle ) ;
347 else
348 DeactivateControl( m_controlHandle ) ;
a2fe01c9 349#endif
e56d2520 350 }
a2fe01c9
SC
351 }
352 return true ;
353}
bfe9ffbc
SC
354
355void wxToolBarTool::SetPosition(const wxPoint& position)
356{
357 m_x = position.x;
358 m_y = position.y;
359
789ae0cf
SC
360 int x , y ;
361 x = y = 0 ;
362 int mac_x = position.x ;
363 int mac_y = position.y ;
364
365 if ( ! GetToolBar()->MacGetTopLevelWindow()->MacUsesCompositing() )
bfe9ffbc 366 {
bfe9ffbc 367 GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
facd6764
SC
368 mac_x += x;
369 mac_y += y;
789ae0cf
SC
370 }
371
372 if ( IsButton() )
373 {
f3a65c3e
VZ
374 Rect contrlRect ;
375 GetControlBounds( m_controlHandle , &contrlRect ) ;
bfe9ffbc
SC
376 int former_mac_x = contrlRect.left ;
377 int former_mac_y = contrlRect.top ;
80e3f464 378 GetToolBar()->GetToolSize() ;
f3a65c3e 379
bfe9ffbc
SC
380 if ( mac_x != former_mac_x || mac_y != former_mac_y )
381 {
bfe9ffbc 382 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
bfe9ffbc
SC
383 }
384 }
385 else if ( IsControl() )
386 {
387 GetControl()->Move( position ) ;
388 }
abbcdf3f
SC
389 else
390 {
f3a65c3e 391 // separator
abbcdf3f 392#ifdef __WXMAC_OSX__
f3a65c3e
VZ
393 Rect contrlRect ;
394 GetControlBounds( m_controlHandle , &contrlRect ) ;
abbcdf3f
SC
395 int former_mac_x = contrlRect.left ;
396 int former_mac_y = contrlRect.top ;
f3a65c3e 397
abbcdf3f
SC
398 if ( mac_x != former_mac_x || mac_y != former_mac_y )
399 {
400 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
401 }
402#endif
403 }
bfe9ffbc
SC
404}
405
f3a65c3e 406void wxToolBarTool::UpdateToggleImage( bool toggle )
73fd9428 407{
f3a65c3e 408#if wxMAC_USE_NATIVE_TOOLBAR
e56d2520
SC
409
410#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
411#define kHIToolbarItemSelected (1 << 7)
412#endif
413
414 // FIXME: this should be a OSX v10.4 runtime check
415 if (m_toolbarItemRef != NULL)
416 {
417 OptionBits addAttrs, removeAttrs;
418 OSStatus result;
419
420 if (toggle)
421 {
422 addAttrs = kHIToolbarItemSelected;
423 removeAttrs = kHIToolbarItemNoAttributes;
424 }
425 else
426 {
427 addAttrs = kHIToolbarItemNoAttributes;
428 removeAttrs = kHIToolbarItemSelected;
429 }
430
431 result = HIToolbarItemChangeAttributes( m_toolbarItemRef, addAttrs, removeAttrs );
432 }
433#endif
5d0bf05a 434
73fd9428
SC
435#ifdef __WXMAC_OSX__
436 if ( toggle )
437 {
438 int w = m_bmpNormal.GetWidth() ;
439 int h = m_bmpNormal.GetHeight() ;
440 wxBitmap bmp( w , h ) ;
441 wxMemoryDC dc ;
442 dc.SelectObject( bmp ) ;
443 dc.SetPen( wxNullPen ) ;
444 dc.SetBackground( *wxWHITE ) ;
445 dc.DrawRectangle( 0 , 0 , w , h ) ;
446 dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ;
447 dc.SelectObject( wxNullBitmap ) ;
448 ControlButtonContentInfo info ;
449 wxMacCreateBitmapButton( &info , bmp ) ;
450 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
451 (Ptr)&info );
452 wxMacReleaseBitmapButton( &info ) ;
453 }
454 else
455 {
456 ControlButtonContentInfo info ;
457 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
458 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
459 (Ptr)&info );
460 wxMacReleaseBitmapButton( &info ) ;
461 }
462
463 IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
464 SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
465 (Ptr)&transform );
466 HIViewSetNeedsDisplay( m_controlHandle , true ) ;
467
468#else
469 ::SetControl32BitValue( m_controlHandle , toggle ) ;
470#endif
471}
472
bfe9ffbc
SC
473wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
474 int id,
475 const wxString& label,
476 const wxBitmap& bmpNormal,
477 const wxBitmap& bmpDisabled,
478 wxItemKind kind,
479 wxObject *clientData,
480 const wxString& shortHelp,
481 const wxString& longHelp)
482 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
483 clientData, shortHelp, longHelp)
484{
f4e0be4f 485 Init();
bfe9ffbc
SC
486}
487
e56d2520
SC
488#pragma mark -
489#pragma mark Toolbar Implementation
2f1ae414 490
37e2cb08 491wxToolBarToolBase *wxToolBar::CreateTool(int id,
27e2d606
GD
492 const wxString& label,
493 const wxBitmap& bmpNormal,
494 const wxBitmap& bmpDisabled,
495 wxItemKind kind,
37e2cb08 496 wxObject *clientData,
27e2d606
GD
497 const wxString& shortHelp,
498 const wxString& longHelp)
37e2cb08 499{
27e2d606
GD
500 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
501 clientData, shortHelp, longHelp);
37e2cb08
SC
502}
503
504wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
505{
506 return new wxToolBarTool(this, control);
507}
508
37e2cb08 509void wxToolBar::Init()
e9576ca5 510{
e40298d5
JS
511 m_maxWidth = -1;
512 m_maxHeight = -1;
513 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
514 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
e56d2520
SC
515#if wxMAC_USE_NATIVE_TOOLBAR
516 m_macHIToolbarRef = NULL ;
517 m_macUsesNativeToolbar = false ;
518#endif
e9576ca5
SC
519}
520
e56d2520
SC
521// also for the toolbar we have the dual implementation:
522// only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
523//
e9576ca5
SC
524bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
525 long style, const wxString& name)
5d0bf05a 526{
facd6764 527 if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
3803c372 528 return false ;
e56d2520
SC
529
530 OSStatus err = 0;
531
532#if wxMAC_USE_NATIVE_TOOLBAR
533 wxString labelStr;
534 labelStr.Format(wxT("%xd"), (int)this);
535 err = HIToolbarCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding() ) , 0 ,
536 (HIToolbarRef*) &m_macHIToolbarRef );
537
538 if (m_macHIToolbarRef != NULL)
f3a65c3e 539 {
e56d2520
SC
540 HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault ;
541 HIToolbarDisplaySize displaySize = kHIToolbarDisplaySizeSmall ;
542
543 if ( style & wxTB_NOICONS )
544 mode = kHIToolbarDisplayModeLabelOnly ;
545 else if ( style & wxTB_TEXT )
546 mode = kHIToolbarDisplayModeIconAndLabel ;
547 else
548 mode = kHIToolbarDisplayModeIconOnly ;
549
e56d2520
SC
550 HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef , mode ) ;
551 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef , displaySize ) ;
552 }
553#endif
554
555 return (err == 0);
e9576ca5
SC
556}
557
558wxToolBar::~wxToolBar()
f3a65c3e 559{
e56d2520
SC
560#if wxMAC_USE_NATIVE_TOOLBAR
561 if ( m_macHIToolbarRef )
562 {
563 // if this is the installed toolbar, then deinstall it
564 if (m_macUsesNativeToolbar)
565 MacInstallNativeToolbar( false );
566
567 CFRelease( (HIToolbarRef) m_macHIToolbarRef );
568 m_macHIToolbarRef = NULL;
569 }
570#endif
571}
572
e56d2520
SC
573bool wxToolBar::Show( bool show )
574{
f3a65c3e 575 bool bResult;
e56d2520 576 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
f3a65c3e 577
e56d2520
SC
578 bResult = (tlw != NULL);
579 if (bResult)
580 {
581#if wxMAC_USE_NATIVE_TOOLBAR
f3a65c3e 582 bool ownToolbarInstalled = false;
e56d2520
SC
583 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
584 if (ownToolbarInstalled)
585 {
586 bResult = (HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ) != show);
587 ShowHideWindowToolbar( tlw, show, false );
588 }
589 else
590#endif
591 bResult = wxToolBarBase::Show( show );
592 }
f3a65c3e 593
e56d2520
SC
594 return bResult;
595}
596
597bool wxToolBar::IsShown() const
598{
599 bool bResult;
600
601#if wxMAC_USE_NATIVE_TOOLBAR
602 bool ownToolbarInstalled ;
603 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
604 if (ownToolbarInstalled)
605 bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef );
606 else
607#endif
608 bResult = wxToolBarBase::IsShown();
f3a65c3e 609
e56d2520
SC
610 return bResult;
611}
612
e56d2520
SC
613void wxToolBar::DoGetSize( int *width, int *height ) const
614{
615#if wxMAC_USE_NATIVE_TOOLBAR
616 Rect boundsR;
617 bool ownToolbarInstalled;
f3a65c3e 618
e56d2520
SC
619 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
620 if ( ownToolbarInstalled )
621 {
622 // TODO is this really a control ?
623 GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR );
624 if ( width != NULL )
625 *width = boundsR.right - boundsR.left;
626 if ( height != NULL )
627 *height = boundsR.bottom - boundsR.top;
628 }
629 else
630#endif
631 wxToolBarBase::DoGetSize( width, height );
e9576ca5
SC
632}
633
f3a65c3e 634void wxToolBar::SetWindowStyleFlag( long style )
e56d2520
SC
635{
636 wxToolBarBase::SetWindowStyleFlag( style );
637#if wxMAC_USE_NATIVE_TOOLBAR
638 if (m_macHIToolbarRef != NULL)
639 {
640 HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
641
642 if ( style & wxTB_NOICONS )
643 mode = kHIToolbarDisplayModeLabelOnly;
644 else if ( style & wxTB_TEXT )
645 mode = kHIToolbarDisplayModeIconAndLabel;
646 else
647 mode = kHIToolbarDisplayModeIconOnly;
f3a65c3e 648
e56d2520
SC
649 HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
650 }
651#endif
652}
653
654#if wxMAC_USE_NATIVE_TOOLBAR
655bool wxToolBar::MacWantsNativeToolbar()
656{
657 return m_macUsesNativeToolbar;
658}
659
660bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const
661{
662 bool bResultV = false;
663
664 if (ownToolbarInstalled != NULL)
665 *ownToolbarInstalled = false;
666
667 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
668 if (tlw != NULL)
669 {
670 HIToolbarRef curToolbarRef = NULL;
671 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
672 bResultV = ((err == 0) && (curToolbarRef != NULL));
673 if (bResultV && (ownToolbarInstalled != NULL))
674 *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
675 }
676
677 return bResultV;
678}
679
f3a65c3e 680bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
e56d2520
SC
681{
682 bool bResult = false;
683
684 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
685 if (tlw == NULL)
686 return bResult;
687
688 if (usesNative && (m_macHIToolbarRef == NULL))
689 return bResult;
f3a65c3e 690
e56d2520
SC
691 if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
692 return bResult;
f3a65c3e 693
e56d2520
SC
694 // check the existing toolbar
695 HIToolbarRef curToolbarRef = NULL;
696 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
697 if (err != 0)
698 curToolbarRef = NULL;
699
700 m_macUsesNativeToolbar = usesNative;
701
702 if (m_macUsesNativeToolbar)
703 {
704 // only install toolbar if there isn't one installed already
705 if (curToolbarRef == NULL)
706 {
707 bResult = true;
708
709 SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef );
710 ShowHideWindowToolbar( tlw, true, false );
711 ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
712 SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
f3a65c3e 713
e56d2520
SC
714 // FIXME: which is best, which is necessary?
715 //
716 // m_peer->SetVisibility( false, true );
717 //
718 //
719 Rect r = { 0 , 0 , 0 , 0 };
720 //
721 //
722 m_peer->SetRect( &r );
723 //
724 // FIXME: which is best, which is necessary?
725 //
726 SetSize( wxSIZE_AUTO_WIDTH, 0 );
727 //
728 m_peer->SetVisibility( false, true );
729 wxToolBarBase::Show( false );
730 }
731 }
732 else
733 {
734 // only deinstall toolbar if this is the installed one
735 if (m_macHIToolbarRef == curToolbarRef)
736 {
737 bResult = true;
738
739 ShowHideWindowToolbar( tlw, false, false );
740 ChangeWindowAttributes( tlw, 0 , kWindowToolbarButtonAttribute );
741 SetWindowToolbar( tlw, NULL );
f3a65c3e 742
e56d2520
SC
743 // FIXME: which is best, which is necessary?
744 m_peer->SetVisibility( true, true );
f3a65c3e 745
e56d2520
SC
746 //
747 // wxToolBarBase::Show( true );
748 //
749 }
750 }
751
752 if (bResult)
753 InvalidateBestSize();
754
755// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
756 return bResult;
757}
758#endif
759
37e2cb08 760bool wxToolBar::Realize()
e9576ca5 761{
eb22f2a6 762 if (m_tools.GetCount() == 0)
3803c372 763 return false;
0b7a8cd3 764
e56d2520
SC
765 int x = m_xMargin + kwxMacToolBarLeftMargin;
766 int y = m_yMargin + kwxMacToolBarTopMargin;
f3a65c3e 767
7c551d95 768 int tw, th;
e56d2520 769 GetSize( &tw, &th );
f3a65c3e 770
e56d2520
SC
771 int maxWidth = 0;
772 int maxHeight = 0;
f3a65c3e 773
bfe9ffbc
SC
774 int maxToolWidth = 0;
775 int maxToolHeight = 0;
f3a65c3e 776
e56d2520
SC
777 // find the maximum tool width and height
778 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
779 while ( node != NULL )
bfe9ffbc 780 {
e56d2520 781 wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
f3a65c3e 782
e56d2520
SC
783 if ( tool != NULL )
784 {
785 wxSize sz = tool->GetSize();
f3a65c3e 786
e56d2520
SC
787 if ( sz.x > maxToolWidth )
788 maxToolWidth = sz.x;
789 if ( sz.y > maxToolHeight )
790 maxToolHeight = sz.y;
791 }
f3a65c3e 792
bfe9ffbc
SC
793 node = node->GetNext();
794 }
f3a65c3e 795
e56d2520
SC
796 bool lastIsRadio = false;
797 bool curIsRadio = false;
798 bool setChoiceInGroup = false;
f3a65c3e 799
bfe9ffbc 800 node = m_tools.GetFirst();
e56d2520 801 while ( node != NULL )
7810c95b 802 {
e56d2520 803 wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
f3a65c3e 804
e56d2520 805 if ( tool == NULL )
214b9484 806 {
e56d2520
SC
807 node = node->GetNext();
808 continue;
214b9484 809 }
f3a65c3e 810
e56d2520
SC
811 // set tool position
812 // for the moment just perform a single row/column alignment
813 wxSize cursize = tool->GetSize();
bfe9ffbc 814 if ( x + cursize.x > maxWidth )
e56d2520 815 maxWidth = x + cursize.x;
bfe9ffbc 816 if ( y + cursize.y > maxHeight )
e56d2520 817 maxHeight = y + cursize.y;
f3a65c3e 818
73fd9428
SC
819 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
820 {
e56d2520
SC
821 int x1 = x + ( maxToolWidth - cursize.x ) / 2;
822 tool->SetPosition( wxPoint(x1, y) );
73fd9428
SC
823 }
824 else
825 {
e56d2520
SC
826 int y1 = y + ( maxToolHeight - cursize.y ) / 2;
827 tool->SetPosition( wxPoint(x, y1) );
828 }
f3a65c3e 829
e56d2520 830 // update the item positioning state
bfe9ffbc 831 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520
SC
832 y += cursize.y + kwxMacToolSpacing;
833 else
834 x += cursize.x + kwxMacToolSpacing;
f3a65c3e 835
e56d2520
SC
836#if wxMAC_USE_NATIVE_TOOLBAR
837 // install in native HIToolbar
838 if ( m_macHIToolbarRef != NULL )
bfe9ffbc 839 {
e56d2520
SC
840 HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
841 if ( hiItemRef != NULL )
842 {
843 OSStatus result = HIToolbarAppendItem( (HIToolbarRef) m_macHIToolbarRef, hiItemRef );
844 if ( result == 0 )
845 {
846 InstallEventHandler( HIObjectGetEventTarget(hiItemRef), GetwxMacToolBarEventHandlerUPP(),
847 GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
848 }
849 }
850 }
851#endif
f3a65c3e 852
e56d2520
SC
853 // update radio button (and group) state
854 lastIsRadio = curIsRadio;
855 curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) );
f3a65c3e 856
e56d2520
SC
857 if ( !curIsRadio )
858 {
859 if ( tool->IsToggled() )
860 DoToggleTool( tool, true );
f3a65c3e 861
e56d2520 862 setChoiceInGroup = false;
0b7a8cd3
GD
863 }
864 else
865 {
e56d2520
SC
866 if ( !lastIsRadio )
867 {
868 if ( tool->Toggle(true) )
869 {
870 DoToggleTool( tool, true );
871 setChoiceInGroup = true;
872 }
873 }
874 else if ( tool->IsToggled() )
875 {
876 if ( tool->IsToggled() )
877 DoToggleTool( tool, true );
f3a65c3e 878
e56d2520
SC
879 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
880 while ( nodePrev != NULL )
881 {
882 wxToolBarToolBase *toggleTool = nodePrev->GetData();
883 if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) )
884 break;
f3a65c3e 885
e56d2520
SC
886 if ( toggleTool->Toggle(false) )
887 DoToggleTool( toggleTool, false );
f3a65c3e 888
e56d2520
SC
889 nodePrev = nodePrev->GetPrevious();
890 }
891 }
0b7a8cd3 892 }
f3a65c3e 893
eb22f2a6 894 node = node->GetNext();
7810c95b 895 }
f3a65c3e 896
0b7a8cd3 897 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 898 {
e56d2520
SC
899 // if not set yet, only one row
900 if ( m_maxRows <= 0 )
901 SetRows( 1 );
f3a65c3e 902
90d3f91a 903 m_minWidth = maxWidth;
e56d2520 904 maxWidth = tw;
0b7a8cd3 905 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
e56d2520 906 m_minHeight = m_maxHeight = maxHeight;
7810c95b 907 }
0b7a8cd3
GD
908 else
909 {
e56d2520
SC
910 // if not set yet, have one column
911 if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
912 SetRows( GetToolsCount() );
f3a65c3e 913
90d3f91a 914 m_minHeight = maxHeight;
e56d2520 915 maxHeight = th;
0b7a8cd3 916 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
e56d2520 917 m_minWidth = m_maxWidth = maxWidth;
0b7a8cd3 918 }
e56d2520 919
f3a65c3e 920#if 0
e56d2520
SC
921 // FIXME: should this be OSX-only?
922 {
923 bool wantNativeToolbar, ownToolbarInstalled;
924
925 // attempt to install the native toolbar
926 wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0);
927 MacInstallNativeToolbar( wantNativeToolbar );
928 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
929 if (!ownToolbarInstalled)
930 {
931 SetSize( maxWidth, maxHeight );
932 InvalidateBestSize();
933 }
934 }
f3a65c3e 935#else
facd6764 936 SetSize( maxWidth, maxHeight );
9f884528 937 InvalidateBestSize();
e56d2520 938#endif
3803c372 939 return true;
e9576ca5
SC
940}
941
942void wxToolBar::SetToolBitmapSize(const wxSize& size)
943{
e56d2520
SC
944 m_defaultWidth = size.x + kwxMacToolBorder;
945 m_defaultHeight = size.y + kwxMacToolBorder;
f3a65c3e 946
e56d2520
SC
947#if wxMAC_USE_NATIVE_TOOLBAR
948 if (m_macHIToolbarRef != NULL)
949 {
950 int maxs = wxMax( size.x, size.y );
328f4fee
SC
951 HIToolbarDisplaySize sizeSpec ;
952 if ( maxs > 32 )
328f4fee 953 sizeSpec = kHIToolbarDisplaySizeNormal ;
00a7bd85
SC
954 else if ( maxs > 24 )
955 sizeSpec = kHIToolbarDisplaySizeDefault ;
328f4fee
SC
956 else
957 sizeSpec = kHIToolbarDisplaySizeSmall ;
f3a65c3e 958
e56d2520
SC
959 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
960 }
961#endif
e9576ca5
SC
962}
963
e9576ca5
SC
964// The button size is bigger than the bitmap size
965wxSize wxToolBar::GetToolSize() const
966{
ee799df7 967 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
968}
969
37e2cb08 970void wxToolBar::SetRows(int nRows)
e9576ca5 971{
e56d2520
SC
972 // avoid resizing the frame uselessly
973 if ( nRows != m_maxRows )
e9576ca5 974 {
e56d2520 975 m_maxRows = nRows;
e9576ca5
SC
976 }
977}
978
f3a65c3e 979void wxToolBar::MacSuperChangedPosition()
c257d44d 980{
e56d2520
SC
981 wxWindow::MacSuperChangedPosition();
982#if wxMAC_USE_NATIVE_TOOLBAR
983 if (! m_macUsesNativeToolbar )
984#endif
985 {
986 Realize();
987 }
c257d44d
SC
988}
989
37e2cb08 990wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 991{
affd2611 992 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
e56d2520 993 while ( node != NULL )
e044f600 994 {
bfe9ffbc 995 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
e56d2520
SC
996
997 if (tool != NULL)
e044f600 998 {
e56d2520
SC
999 wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
1000 if ( r.Contains( wxPoint( x, y ) ) )
1001 return tool;
e044f600 1002 }
bfe9ffbc
SC
1003
1004 node = node->GetNext();
e044f600 1005 }
37e2cb08
SC
1006
1007 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
1008}
1009
2f1ae414
SC
1010wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
1011{
e044f600 1012 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
e56d2520 1013 if ( tool != NULL )
e044f600 1014 return tool->GetShortHelp() ;
e56d2520 1015
427ff662 1016 return wxEmptyString ;
2f1ae414
SC
1017}
1018
37e2cb08 1019void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 1020{
e56d2520
SC
1021 if ( t != NULL )
1022 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
1023}
1024
37e2cb08 1025void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 1026{
e044f600 1027 wxToolBarTool *tool = (wxToolBarTool *)t;
e56d2520
SC
1028 if ( ( tool != NULL ) && tool->IsButton() )
1029 tool->UpdateToggleImage( toggle );
37e2cb08 1030}
7c551d95 1031
37e2cb08 1032bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
be5fe3aa 1033 wxToolBarToolBase *toolBase)
37e2cb08 1034{
e56d2520
SC
1035 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase );
1036 if (tool == NULL)
1037 return false;
1038
1039 WindowRef window = (WindowRef) MacGetTopLevelWindowRef();
1040 wxSize toolSize = GetToolSize();
1041 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x };
1042 ControlRef controlHandle = NULL;
1043 OSStatus err = 0;
be5fe3aa 1044
e56d2520 1045 switch (tool->GetStyle())
be5fe3aa
SC
1046 {
1047 case wxTOOL_STYLE_SEPARATOR :
1048 {
e56d2520
SC
1049 wxASSERT( tool->GetControlHandle() == NULL );
1050 toolSize.x /= 4;
1051 toolSize.y /= 4;
be5fe3aa 1052 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520 1053 toolrect.bottom = toolSize.y;
be5fe3aa 1054 else
e56d2520
SC
1055 toolrect.right = toolSize.x;
1056
be5fe3aa
SC
1057 #ifdef __WXMAC_OSX__
1058 // in flat style we need a visual separator
e56d2520
SC
1059 #if wxMAC_USE_NATIVE_TOOLBAR
1060 HIToolbarItemRef item;
1061 err = HIToolbarItemCreate( kHIToolbarSeparatorIdentifier, kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates, &item );
1062 if (err == noErr)
1063 tool->SetToolbarItemRef( item );
1064 #endif
1065 CreateSeparatorControl( window, &toolrect, &controlHandle );
1066 tool->SetControlHandle( controlHandle );
be5fe3aa
SC
1067 #endif
1068 }
e56d2520
SC
1069 break;
1070
be5fe3aa
SC
1071 case wxTOOL_STYLE_BUTTON :
1072 {
1073 wxASSERT( tool->GetControlHandle() == NULL ) ;
1074 ControlButtonContentInfo info ;
1075 wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
f3a65c3e 1076
e56d2520
SC
1077 if ( UMAGetSystemVersion() >= 0x1000)
1078 CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
1079 else
1080 {
1081 SInt16 behaviour = kControlBehaviorOffsetContents ;
1082 if ( tool->CanBeToggled() )
1083 behaviour += kControlBehaviorToggles ;
f3a65c3e 1084 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
e56d2520 1085 0 , 0 , 0 , &controlHandle ) ;
f3a65c3e 1086 }
e56d2520
SC
1087
1088#if wxMAC_USE_NATIVE_TOOLBAR
1089 HIToolbarItemRef item ;
1090 wxString labelStr;
1091 labelStr.Format(wxT("%xd"), (int)tool);
1092 err = HIToolbarItemCreate(
1093 wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1094 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
1095 if (err == noErr)
1096 {
1097 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1098 HIToolbarItemSetIconRef( item, info.u.iconRef );
1099 HIToolbarItemSetCommandID( item, tool->GetId() );
1100 tool->SetToolbarItemRef( item );
1101 }
1102#endif
1103
be5fe3aa
SC
1104 wxMacReleaseBitmapButton( &info ) ;
1105 /*
1106 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
1107 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
1108 */
f3a65c3e 1109
be5fe3aa 1110 InstallControlEventHandler( (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
e56d2520 1111 GetEventTypeCount(eventList), eventList, tool, NULL );
be5fe3aa 1112
e56d2520 1113 tool->SetControlHandle( controlHandle );
be5fe3aa 1114 }
e56d2520
SC
1115 break;
1116
be5fe3aa 1117 case wxTOOL_STYLE_CONTROL :
e56d2520
SC
1118 wxASSERT( tool->GetControl() != NULL );
1119#if 0 // wxMAC_USE_NATIVE_TOOLBAR
1120 // FIXME: doesn't work yet...
1121 {
1122 HIToolbarItemRef item;
1123 wxString labelStr;
1124 labelStr.Format( wxT("%xd"), (int) tool );
1125 result = HIToolbarItemCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1126 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates,
1127 &item );
1128 if ( result == 0 )
1129 {
1130 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1131 HIToolbarItemSetCommandID( item, tool->GetId() );
1132 tool->SetToolbarItemRef( item );
f3a65c3e 1133
e56d2520
SC
1134 controlHandle = ( ControlRef ) tool->GetControlHandle();
1135 wxASSERT_MSG( controlHandle != NULL, wxT("NULL tool control") );
f3a65c3e 1136
e56d2520
SC
1137 // FIXME: is this necessary ??
1138 ::GetControlBounds( controlHandle, &toolrect );
1139 UMAMoveControl( controlHandle, -toolrect.left, -toolrect.top );
f3a65c3e 1140
e56d2520
SC
1141 // FIXME: is this necessary ??
1142 InstallControlEventHandler( controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
1143 GetEventTypeCount(eventList), eventList, tool, NULL );
1144 }
1145 }
f3a65c3e 1146
e56d2520
SC
1147#else
1148 // FIXME: right now there's nothing to do here
1149#endif
1150 break;
1151
1152 default :
1153 break;
be5fe3aa 1154 }
f3a65c3e 1155
e56d2520 1156 if ( err == 0 )
be5fe3aa 1157 {
e56d2520
SC
1158 if ( controlHandle )
1159 {
1160 ControlRef container = (ControlRef) GetHandle();
1161 wxASSERT_MSG( container != NULL, wxT("No valid mac container control") );
be5fe3aa 1162
e56d2520
SC
1163 UMAShowControl( controlHandle );
1164 ::EmbedControl( controlHandle, container );
1165 }
1166
1167 if ( tool->CanBeToggled() && tool->IsToggled() )
1168 tool->UpdateToggleImage( true );
be5fe3aa 1169
e56d2520
SC
1170 // nothing special to do here - we relayout in Realize() later
1171 tool->Attach(this);
1172 InvalidateBestSize();
1173 }
1174 else
be5fe3aa 1175 {
e56d2520
SC
1176 wxString errMsg;
1177 errMsg.Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long) err );
1178 wxASSERT_MSG( false, errMsg.c_str() );
be5fe3aa 1179 }
f3a65c3e 1180
e56d2520 1181 return( err == 0 );
37e2cb08 1182}
e9576ca5 1183
5115c51a 1184void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 1185{
5115c51a 1186 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
1187}
1188
be5fe3aa 1189bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
37e2cb08 1190{
be5fe3aa 1191 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
affd2611 1192 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
1193 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1194 {
1195 wxToolBarToolBase *tool2 = node->GetData();
1196 if ( tool2 == tool )
1197 {
1198 // let node point to the next node in the list
1199 node = node->GetNext();
1200
1201 break;
1202 }
1203 }
1204
1205 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
1206
1207 tool->Detach();
1208
488b2c29
SC
1209 switch ( tool->GetStyle() )
1210 {
1211 case wxTOOL_STYLE_CONTROL:
be5fe3aa
SC
1212 {
1213 tool->GetControl()->Destroy();
e56d2520 1214 tool->ClearControl() ;
be5fe3aa 1215 }
488b2c29
SC
1216 break;
1217
1218 case wxTOOL_STYLE_BUTTON:
1219 case wxTOOL_STYLE_SEPARATOR:
be5fe3aa 1220 if ( tool->GetControlHandle() )
488b2c29 1221 {
be5fe3aa 1222 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
e56d2520
SC
1223#if wxMAC_USE_NATIVE_TOOLBAR
1224 if ( tool->GetToolbarItemRef() )
1225 CFRelease( tool->GetToolbarItemRef() ) ;
1226#endif
1227 tool->ClearControl() ;
488b2c29
SC
1228 }
1229 break;
e56d2520
SC
1230
1231 default:
1232 break;
488b2c29
SC
1233 }
1234
bfe9ffbc 1235 // and finally reposition all the controls after this one
f3a65c3e 1236
bfe9ffbc
SC
1237 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
1238 {
1239 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
1240 wxPoint pt = tool2->GetPosition() ;
1241
1242 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
bfe9ffbc 1243 pt.y -= sz.y ;
bfe9ffbc 1244 else
bfe9ffbc 1245 pt.x -= sz.x ;
e56d2520 1246
bfe9ffbc
SC
1247 tool2->SetPosition( pt ) ;
1248 }
f3a65c3e 1249
9f884528 1250 InvalidateBestSize();
3803c372 1251 return true ;
37e2cb08 1252}
2f1ae414
SC
1253
1254void wxToolBar::OnPaint(wxPaintEvent& event)
1255{
e56d2520
SC
1256#if wxMAC_USE_NATIVE_TOOLBAR
1257 if ( m_macUsesNativeToolbar )
1258 {
1259 event.Skip(true) ;
1260 return ;
1261 }
1262#endif
f3a65c3e 1263
e40298d5 1264 wxPaintDC dc(this) ;
ddc548ec 1265
facd6764
SC
1266 int w, h ;
1267 GetSize( &w , &h ) ;
ddc548ec
SC
1268#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1269 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
1270 {
1271 if ( UMAGetSystemVersion() >= 0x1030 )
1272 {
1273 HIThemePlacardDrawInfo info ;
1274 memset( &info, 0 , sizeof( info ) ) ;
1275 info.version = 0 ;
1276 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
f3a65c3e 1277
ddc548ec
SC
1278 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
1279 HIRect rect = CGRectMake( 0 , 0 , w , h ) ;
1280 HIThemeDrawPlacard( &rect , & info , cgContext, kHIThemeOrientationNormal) ;
1281 }
1282 }
1283 else
1284 {
1285 // leave the background as it is (striped or metal)
1286 }
1287#else
1288 wxMacPortSetter helper(&dc) ;
f3a65c3e
VZ
1289
1290 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
1291 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
1292/*
1293 if( toolbarrect.left < 0 )
1294 toolbarrect.left = 0 ;
1295 if ( toolbarrect.top < 0 )
1296 toolbarrect.top = 0 ;
1297*/
01ffa8f7
SC
1298 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
1299 {
1300 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1301 }
1302 else
1303 {
1304#if TARGET_API_MAC_OSX
1305#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
20b69855
SC
1306 if ( UMAGetSystemVersion() >= 0x1030 )
1307 {
f3a65c3e 1308 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
20b69855
SC
1309 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
1310 CGContextRef cgContext ;
1311 Rect bounds ;
1312 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
1313 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1314 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
1315 CGContextScaleCTM( cgContext , 1 , -1 ) ;
785f5eaa 1316
20b69855
SC
1317 {
1318 HIThemeBackgroundDrawInfo drawInfo ;
1319 drawInfo.version = 0 ;
1320 drawInfo.state = kThemeStateActive ;
1321 drawInfo.kind = kThemeBackgroundMetal ;
1322 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
1323 }
e56d2520 1324
20b69855
SC
1325 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1326 }
1327 else
1328#endif
01ffa8f7 1329 {
20b69855 1330 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 1331 }
01ffa8f7 1332#endif
01ffa8f7
SC
1333 }
1334#endif
20b69855 1335
facd6764 1336 event.Skip() ;
2f1ae414 1337}
895f5af7 1338
519cb848
SC
1339#endif // wxUSE_TOOLBAR
1340