]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
correcting condition: only interfere in the non-native case
[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)
e044f600 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
SC
70 const wxString& longHelp) ;
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 }
bfe9ffbc
SC
79
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
SC
89 }
90
e56d2520
SC
91 WXWidget GetControlHandle()
92 {
93 return (WXWidget) m_controlHandle ;
94 }
95
96 void SetControlHandle( ControlRef handle )
97 {
98 m_controlHandle = handle ;
99 }
37e2cb08 100
bfe9ffbc 101 void SetPosition( const wxPoint& position ) ;
a2fe01c9 102
e56d2520
SC
103 void ClearControl()
104 {
105 m_control = NULL ;
106#if wxMAC_USE_NATIVE_TOOLBAR
5d0bf05a 107 m_toolbarItemRef = NULL ;
e56d2520
SC
108#endif
109 }
be5fe3aa 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);
135 }
a2fe01c9 136 bool DoEnable( bool enable ) ;
73fd9428
SC
137
138 void UpdateToggleImage( bool toggle ) ;
e56d2520
SC
139
140#if wxMAC_USE_NATIVE_TOOLBAR
141 void SetToolbarItemRef( HIToolbarItemRef ref )
142 {
143 if ( m_controlHandle )
144 HideControl( m_controlHandle ) ;
145 if ( m_toolbarItemRef )
146 CFRelease( m_toolbarItemRef ) ;
147 m_toolbarItemRef = ref ;
148 if ( m_toolbarItemRef )
149 {
150 HIToolbarItemSetHelpText(
151 m_toolbarItemRef, wxMacCFStringHolder( GetShortHelp() , GetToolBar()->GetFont().GetEncoding() ) ,
152 wxMacCFStringHolder( GetLongHelp() , GetToolBar()->GetFont().GetEncoding() ) ) ;
153 }
154 }
155 HIToolbarItemRef GetToolbarItemRef() const
156 {
157 return m_toolbarItemRef ;
158 }
159#endif
5d0bf05a 160
bfe9ffbc
SC
161private :
162 void Init()
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 ) ;
190
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() );
facd6764
SC
213 result = noErr;
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 ) ;
223
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 ;
271
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() ) ;
286 result = noErr;
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 {
e56d2520
SC
332#if wxMAC_USE_NATIVE_TOOLBAR
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 {
bfe9ffbc
SC
374 Rect contrlRect ;
375 GetControlBounds( m_controlHandle , &contrlRect ) ;
376 int former_mac_x = contrlRect.left ;
377 int former_mac_y = contrlRect.top ;
80e3f464 378 GetToolBar()->GetToolSize() ;
bfe9ffbc
SC
379
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 {
391 // separator
392#ifdef __WXMAC_OSX__
abbcdf3f
SC
393 Rect contrlRect ;
394 GetControlBounds( m_controlHandle , &contrlRect ) ;
395 int former_mac_x = contrlRect.left ;
396 int former_mac_y = contrlRect.top ;
397
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
73fd9428
SC
406void wxToolBarTool::UpdateToggleImage( bool toggle )
407{
e56d2520
SC
408#if wxMAC_USE_NATIVE_TOOLBAR
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)
539 {
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()
bfe9ffbc 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{
575 bool bResult, ownToolbarInstalled = false;
576 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
577
578 bResult = (tlw != NULL);
579 if (bResult)
580 {
581#if wxMAC_USE_NATIVE_TOOLBAR
582 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
583 if (ownToolbarInstalled)
584 {
585 bResult = (HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ) != show);
586 ShowHideWindowToolbar( tlw, show, false );
587 }
588 else
589#endif
590 bResult = wxToolBarBase::Show( show );
591 }
592
593 return bResult;
594}
595
596bool wxToolBar::IsShown() const
597{
598 bool bResult;
599
600#if wxMAC_USE_NATIVE_TOOLBAR
601 bool ownToolbarInstalled ;
602 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
603 if (ownToolbarInstalled)
604 bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef );
605 else
606#endif
607 bResult = wxToolBarBase::IsShown();
608
609 return bResult;
610}
611
e56d2520
SC
612void wxToolBar::DoGetSize( int *width, int *height ) const
613{
614#if wxMAC_USE_NATIVE_TOOLBAR
615 Rect boundsR;
616 bool ownToolbarInstalled;
617
618 MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
619 if ( ownToolbarInstalled )
620 {
621 // TODO is this really a control ?
622 GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR );
623 if ( width != NULL )
624 *width = boundsR.right - boundsR.left;
625 if ( height != NULL )
626 *height = boundsR.bottom - boundsR.top;
627 }
628 else
629#endif
630 wxToolBarBase::DoGetSize( width, height );
e9576ca5
SC
631}
632
e56d2520
SC
633void wxToolBar::SetWindowStyleFlag( long style )
634{
635 wxToolBarBase::SetWindowStyleFlag( style );
636#if wxMAC_USE_NATIVE_TOOLBAR
637 if (m_macHIToolbarRef != NULL)
638 {
639 HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
640
641 if ( style & wxTB_NOICONS )
642 mode = kHIToolbarDisplayModeLabelOnly;
643 else if ( style & wxTB_TEXT )
644 mode = kHIToolbarDisplayModeIconAndLabel;
645 else
646 mode = kHIToolbarDisplayModeIconOnly;
647
648 HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
649 }
650#endif
651}
652
653#if wxMAC_USE_NATIVE_TOOLBAR
654bool wxToolBar::MacWantsNativeToolbar()
655{
656 return m_macUsesNativeToolbar;
657}
658
659bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const
660{
661 bool bResultV = false;
662
663 if (ownToolbarInstalled != NULL)
664 *ownToolbarInstalled = false;
665
666 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
667 if (tlw != NULL)
668 {
669 HIToolbarRef curToolbarRef = NULL;
670 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
671 bResultV = ((err == 0) && (curToolbarRef != NULL));
672 if (bResultV && (ownToolbarInstalled != NULL))
673 *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
674 }
675
676 return bResultV;
677}
678
679bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
680{
681 bool bResult = false;
682
683 WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
684 if (tlw == NULL)
685 return bResult;
686
687 if (usesNative && (m_macHIToolbarRef == NULL))
688 return bResult;
689
690 if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
691 return bResult;
692
693 // check the existing toolbar
694 HIToolbarRef curToolbarRef = NULL;
695 OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
696 if (err != 0)
697 curToolbarRef = NULL;
698
699 m_macUsesNativeToolbar = usesNative;
700
701 if (m_macUsesNativeToolbar)
702 {
703 // only install toolbar if there isn't one installed already
704 if (curToolbarRef == NULL)
705 {
706 bResult = true;
707
708 SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef );
709 ShowHideWindowToolbar( tlw, true, false );
710 ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
711 SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
712
713 // FIXME: which is best, which is necessary?
714 //
715 // m_peer->SetVisibility( false, true );
716 //
717 //
718 Rect r = { 0 , 0 , 0 , 0 };
719 //
720 //
721 m_peer->SetRect( &r );
722 //
723 // FIXME: which is best, which is necessary?
724 //
725 SetSize( wxSIZE_AUTO_WIDTH, 0 );
726 //
727 m_peer->SetVisibility( false, true );
728 wxToolBarBase::Show( false );
729 }
730 }
731 else
732 {
733 // only deinstall toolbar if this is the installed one
734 if (m_macHIToolbarRef == curToolbarRef)
735 {
736 bResult = true;
737
738 ShowHideWindowToolbar( tlw, false, false );
739 ChangeWindowAttributes( tlw, 0 , kWindowToolbarButtonAttribute );
740 SetWindowToolbar( tlw, NULL );
741
742 // FIXME: which is best, which is necessary?
743 m_peer->SetVisibility( true, true );
744
745 //
746 // wxToolBarBase::Show( true );
747 //
748 }
749 }
750
751 if (bResult)
752 InvalidateBestSize();
753
754// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
755 return bResult;
756}
757#endif
758
37e2cb08 759bool wxToolBar::Realize()
e9576ca5 760{
eb22f2a6 761 if (m_tools.GetCount() == 0)
3803c372 762 return false;
0b7a8cd3 763
e56d2520
SC
764 int x = m_xMargin + kwxMacToolBarLeftMargin;
765 int y = m_yMargin + kwxMacToolBarTopMargin;
766
7c551d95 767 int tw, th;
e56d2520 768 GetSize( &tw, &th );
895f5af7 769
e56d2520
SC
770 int maxWidth = 0;
771 int maxHeight = 0;
895f5af7 772
bfe9ffbc
SC
773 int maxToolWidth = 0;
774 int maxToolHeight = 0;
e56d2520
SC
775
776 // find the maximum tool width and height
777 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
778 while ( node != NULL )
bfe9ffbc 779 {
e56d2520
SC
780 wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
781
782 if ( tool != NULL )
783 {
784 wxSize sz = tool->GetSize();
785
786 if ( sz.x > maxToolWidth )
787 maxToolWidth = sz.x;
788 if ( sz.y > maxToolHeight )
789 maxToolHeight = sz.y;
790 }
791
bfe9ffbc
SC
792 node = node->GetNext();
793 }
e56d2520
SC
794
795 bool lastIsRadio = false;
796 bool curIsRadio = false;
797 bool setChoiceInGroup = false;
798
bfe9ffbc 799 node = m_tools.GetFirst();
e56d2520 800 while ( node != NULL )
7810c95b 801 {
e56d2520 802 wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
0b7a8cd3 803
e56d2520 804 if ( tool == NULL )
214b9484 805 {
e56d2520
SC
806 node = node->GetNext();
807 continue;
214b9484 808 }
e56d2520
SC
809
810 // set tool position
811 // for the moment just perform a single row/column alignment
812 wxSize cursize = tool->GetSize();
bfe9ffbc 813 if ( x + cursize.x > maxWidth )
e56d2520 814 maxWidth = x + cursize.x;
bfe9ffbc 815 if ( y + cursize.y > maxHeight )
e56d2520
SC
816 maxHeight = y + cursize.y;
817
73fd9428
SC
818 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
819 {
e56d2520
SC
820 int x1 = x + ( maxToolWidth - cursize.x ) / 2;
821 tool->SetPosition( wxPoint(x1, y) );
73fd9428
SC
822 }
823 else
824 {
e56d2520
SC
825 int y1 = y + ( maxToolHeight - cursize.y ) / 2;
826 tool->SetPosition( wxPoint(x, y1) );
827 }
828
829 // update the item positioning state
bfe9ffbc 830 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520
SC
831 y += cursize.y + kwxMacToolSpacing;
832 else
833 x += cursize.x + kwxMacToolSpacing;
834
835#if wxMAC_USE_NATIVE_TOOLBAR
836 // install in native HIToolbar
837 if ( m_macHIToolbarRef != NULL )
bfe9ffbc 838 {
e56d2520
SC
839 HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
840 if ( hiItemRef != NULL )
841 {
842 OSStatus result = HIToolbarAppendItem( (HIToolbarRef) m_macHIToolbarRef, hiItemRef );
843 if ( result == 0 )
844 {
845 InstallEventHandler( HIObjectGetEventTarget(hiItemRef), GetwxMacToolBarEventHandlerUPP(),
846 GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
847 }
848 }
849 }
850#endif
851
852 // update radio button (and group) state
853 lastIsRadio = curIsRadio;
854 curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) );
855
856 if ( !curIsRadio )
857 {
858 if ( tool->IsToggled() )
859 DoToggleTool( tool, true );
860
861 setChoiceInGroup = false;
0b7a8cd3
GD
862 }
863 else
864 {
e56d2520
SC
865 if ( !lastIsRadio )
866 {
867 if ( tool->Toggle(true) )
868 {
869 DoToggleTool( tool, true );
870 setChoiceInGroup = true;
871 }
872 }
873 else if ( tool->IsToggled() )
874 {
875 if ( tool->IsToggled() )
876 DoToggleTool( tool, true );
877
878 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
879 while ( nodePrev != NULL )
880 {
881 wxToolBarToolBase *toggleTool = nodePrev->GetData();
882 if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) )
883 break;
884
885 if ( toggleTool->Toggle(false) )
886 DoToggleTool( toggleTool, false );
887
888 nodePrev = nodePrev->GetPrevious();
889 }
890 }
0b7a8cd3 891 }
e56d2520 892
eb22f2a6 893 node = node->GetNext();
7810c95b 894 }
0b7a8cd3
GD
895
896 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 897 {
e56d2520
SC
898 // if not set yet, only one row
899 if ( m_maxRows <= 0 )
900 SetRows( 1 );
901
90d3f91a 902 m_minWidth = maxWidth;
e56d2520 903 maxWidth = tw;
0b7a8cd3 904 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
e56d2520 905 m_minHeight = m_maxHeight = maxHeight;
7810c95b 906 }
0b7a8cd3
GD
907 else
908 {
e56d2520
SC
909 // if not set yet, have one column
910 if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
911 SetRows( GetToolsCount() );
912
90d3f91a 913 m_minHeight = maxHeight;
e56d2520 914 maxHeight = th;
0b7a8cd3 915 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
e56d2520 916 m_minWidth = m_maxWidth = maxWidth;
0b7a8cd3 917 }
e56d2520
SC
918
919#if 0
920 // FIXME: should this be OSX-only?
921 {
922 bool wantNativeToolbar, ownToolbarInstalled;
923
924 // attempt to install the native toolbar
925 wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0);
926 MacInstallNativeToolbar( wantNativeToolbar );
927 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
928 if (!ownToolbarInstalled)
929 {
930 SetSize( maxWidth, maxHeight );
931 InvalidateBestSize();
932 }
933 }
934#else
facd6764 935 SetSize( maxWidth, maxHeight );
9f884528 936 InvalidateBestSize();
e56d2520 937#endif
3803c372 938 return true;
e9576ca5
SC
939}
940
941void wxToolBar::SetToolBitmapSize(const wxSize& size)
942{
e56d2520
SC
943 m_defaultWidth = size.x + kwxMacToolBorder;
944 m_defaultHeight = size.y + kwxMacToolBorder;
945
946#if wxMAC_USE_NATIVE_TOOLBAR
947 if (m_macHIToolbarRef != NULL)
948 {
949 int maxs = wxMax( size.x, size.y );
328f4fee
SC
950 HIToolbarDisplaySize sizeSpec ;
951 if ( maxs > 32 )
328f4fee 952 sizeSpec = kHIToolbarDisplaySizeNormal ;
00a7bd85
SC
953 else if ( maxs > 24 )
954 sizeSpec = kHIToolbarDisplaySizeDefault ;
328f4fee
SC
955 else
956 sizeSpec = kHIToolbarDisplaySizeSmall ;
957
e56d2520
SC
958 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
959 }
960#endif
e9576ca5
SC
961}
962
e9576ca5
SC
963// The button size is bigger than the bitmap size
964wxSize wxToolBar::GetToolSize() const
965{
ee799df7 966 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
967}
968
37e2cb08 969void wxToolBar::SetRows(int nRows)
e9576ca5 970{
e56d2520
SC
971 // avoid resizing the frame uselessly
972 if ( nRows != m_maxRows )
e9576ca5 973 {
e56d2520 974 m_maxRows = nRows;
e9576ca5
SC
975 }
976}
977
c257d44d
SC
978void wxToolBar::MacSuperChangedPosition()
979{
e56d2520
SC
980 wxWindow::MacSuperChangedPosition();
981#if wxMAC_USE_NATIVE_TOOLBAR
982 if (! m_macUsesNativeToolbar )
983#endif
984 {
985 Realize();
986 }
c257d44d
SC
987}
988
37e2cb08 989wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 990{
affd2611 991 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
e56d2520 992 while ( node != NULL )
e044f600 993 {
bfe9ffbc 994 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
e56d2520
SC
995
996 if (tool != NULL)
e044f600 997 {
e56d2520
SC
998 wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
999 if ( r.Contains( wxPoint( x, y ) ) )
1000 return tool;
e044f600 1001 }
bfe9ffbc
SC
1002
1003 node = node->GetNext();
e044f600 1004 }
37e2cb08
SC
1005
1006 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
1007}
1008
2f1ae414
SC
1009wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
1010{
e044f600 1011 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
e56d2520 1012 if ( tool != NULL )
e044f600 1013 return tool->GetShortHelp() ;
e56d2520 1014
427ff662 1015 return wxEmptyString ;
2f1ae414
SC
1016}
1017
37e2cb08 1018void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 1019{
e56d2520
SC
1020 if ( t != NULL )
1021 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
1022}
1023
37e2cb08 1024void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 1025{
e044f600 1026 wxToolBarTool *tool = (wxToolBarTool *)t;
e56d2520
SC
1027 if ( ( tool != NULL ) && tool->IsButton() )
1028 tool->UpdateToggleImage( toggle );
37e2cb08 1029}
7c551d95 1030
37e2cb08 1031bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
be5fe3aa 1032 wxToolBarToolBase *toolBase)
37e2cb08 1033{
e56d2520
SC
1034 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase );
1035 if (tool == NULL)
1036 return false;
1037
1038 WindowRef window = (WindowRef) MacGetTopLevelWindowRef();
1039 wxSize toolSize = GetToolSize();
1040 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x };
1041 ControlRef controlHandle = NULL;
1042 OSStatus err = 0;
be5fe3aa 1043
e56d2520 1044 switch (tool->GetStyle())
be5fe3aa
SC
1045 {
1046 case wxTOOL_STYLE_SEPARATOR :
1047 {
e56d2520
SC
1048 wxASSERT( tool->GetControlHandle() == NULL );
1049 toolSize.x /= 4;
1050 toolSize.y /= 4;
be5fe3aa 1051 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
e56d2520 1052 toolrect.bottom = toolSize.y;
be5fe3aa 1053 else
e56d2520
SC
1054 toolrect.right = toolSize.x;
1055
be5fe3aa
SC
1056 #ifdef __WXMAC_OSX__
1057 // in flat style we need a visual separator
e56d2520
SC
1058 #if wxMAC_USE_NATIVE_TOOLBAR
1059 HIToolbarItemRef item;
1060 err = HIToolbarItemCreate( kHIToolbarSeparatorIdentifier, kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates, &item );
1061 if (err == noErr)
1062 tool->SetToolbarItemRef( item );
1063 #endif
1064 CreateSeparatorControl( window, &toolrect, &controlHandle );
1065 tool->SetControlHandle( controlHandle );
be5fe3aa
SC
1066 #endif
1067 }
e56d2520
SC
1068 break;
1069
be5fe3aa
SC
1070 case wxTOOL_STYLE_BUTTON :
1071 {
1072 wxASSERT( tool->GetControlHandle() == NULL ) ;
1073 ControlButtonContentInfo info ;
1074 wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
1075
e56d2520
SC
1076 if ( UMAGetSystemVersion() >= 0x1000)
1077 CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
1078 else
1079 {
1080 SInt16 behaviour = kControlBehaviorOffsetContents ;
1081 if ( tool->CanBeToggled() )
1082 behaviour += kControlBehaviorToggles ;
1083 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
1084 0 , 0 , 0 , &controlHandle ) ;
1085 }
1086
1087#if wxMAC_USE_NATIVE_TOOLBAR
1088 HIToolbarItemRef item ;
1089 wxString labelStr;
1090 labelStr.Format(wxT("%xd"), (int)tool);
1091 err = HIToolbarItemCreate(
1092 wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1093 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
1094 if (err == noErr)
1095 {
1096 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1097 HIToolbarItemSetIconRef( item, info.u.iconRef );
1098 HIToolbarItemSetCommandID( item, tool->GetId() );
1099 tool->SetToolbarItemRef( item );
1100 }
1101#endif
1102
be5fe3aa
SC
1103 wxMacReleaseBitmapButton( &info ) ;
1104 /*
1105 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
1106 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
1107 */
1108
1109 InstallControlEventHandler( (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
e56d2520 1110 GetEventTypeCount(eventList), eventList, tool, NULL );
be5fe3aa 1111
e56d2520 1112 tool->SetControlHandle( controlHandle );
be5fe3aa 1113 }
e56d2520
SC
1114 break;
1115
be5fe3aa 1116 case wxTOOL_STYLE_CONTROL :
e56d2520
SC
1117 wxASSERT( tool->GetControl() != NULL );
1118#if 0 // wxMAC_USE_NATIVE_TOOLBAR
1119 // FIXME: doesn't work yet...
1120 {
1121 HIToolbarItemRef item;
1122 wxString labelStr;
1123 labelStr.Format( wxT("%xd"), (int) tool );
1124 result = HIToolbarItemCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1125 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates,
1126 &item );
1127 if ( result == 0 )
1128 {
1129 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1130 HIToolbarItemSetCommandID( item, tool->GetId() );
1131 tool->SetToolbarItemRef( item );
1132
1133 controlHandle = ( ControlRef ) tool->GetControlHandle();
1134 wxASSERT_MSG( controlHandle != NULL, wxT("NULL tool control") );
1135
1136 // FIXME: is this necessary ??
1137 ::GetControlBounds( controlHandle, &toolrect );
1138 UMAMoveControl( controlHandle, -toolrect.left, -toolrect.top );
1139
1140 // FIXME: is this necessary ??
1141 InstallControlEventHandler( controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
1142 GetEventTypeCount(eventList), eventList, tool, NULL );
1143 }
1144 }
1145
1146#else
1147 // FIXME: right now there's nothing to do here
1148#endif
1149 break;
1150
1151 default :
1152 break;
be5fe3aa
SC
1153 }
1154
e56d2520 1155 if ( err == 0 )
be5fe3aa 1156 {
e56d2520
SC
1157 if ( controlHandle )
1158 {
1159 ControlRef container = (ControlRef) GetHandle();
1160 wxASSERT_MSG( container != NULL, wxT("No valid mac container control") );
be5fe3aa 1161
e56d2520
SC
1162 UMAShowControl( controlHandle );
1163 ::EmbedControl( controlHandle, container );
1164 }
1165
1166 if ( tool->CanBeToggled() && tool->IsToggled() )
1167 tool->UpdateToggleImage( true );
be5fe3aa 1168
e56d2520
SC
1169 // nothing special to do here - we relayout in Realize() later
1170 tool->Attach(this);
1171 InvalidateBestSize();
1172 }
1173 else
be5fe3aa 1174 {
e56d2520
SC
1175 wxString errMsg;
1176 errMsg.Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long) err );
1177 wxASSERT_MSG( false, errMsg.c_str() );
be5fe3aa 1178 }
e56d2520
SC
1179
1180 return( err == 0 );
37e2cb08 1181}
e9576ca5 1182
5115c51a 1183void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 1184{
5115c51a 1185 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
1186}
1187
be5fe3aa 1188bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
37e2cb08 1189{
be5fe3aa 1190 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
affd2611 1191 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
1192 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1193 {
1194 wxToolBarToolBase *tool2 = node->GetData();
1195 if ( tool2 == tool )
1196 {
1197 // let node point to the next node in the list
1198 node = node->GetNext();
1199
1200 break;
1201 }
1202 }
1203
1204 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
1205
1206 tool->Detach();
1207
488b2c29
SC
1208 switch ( tool->GetStyle() )
1209 {
1210 case wxTOOL_STYLE_CONTROL:
be5fe3aa
SC
1211 {
1212 tool->GetControl()->Destroy();
e56d2520 1213 tool->ClearControl() ;
be5fe3aa 1214 }
488b2c29
SC
1215 break;
1216
1217 case wxTOOL_STYLE_BUTTON:
1218 case wxTOOL_STYLE_SEPARATOR:
be5fe3aa 1219 if ( tool->GetControlHandle() )
488b2c29 1220 {
be5fe3aa 1221 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
e56d2520
SC
1222#if wxMAC_USE_NATIVE_TOOLBAR
1223 if ( tool->GetToolbarItemRef() )
1224 CFRelease( tool->GetToolbarItemRef() ) ;
1225#endif
1226 tool->ClearControl() ;
488b2c29
SC
1227 }
1228 break;
e56d2520
SC
1229
1230 default:
1231 break;
488b2c29
SC
1232 }
1233
bfe9ffbc
SC
1234 // and finally reposition all the controls after this one
1235
1236 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
1237 {
1238 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
1239 wxPoint pt = tool2->GetPosition() ;
1240
1241 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
bfe9ffbc 1242 pt.y -= sz.y ;
bfe9ffbc 1243 else
bfe9ffbc 1244 pt.x -= sz.x ;
e56d2520 1245
bfe9ffbc
SC
1246 tool2->SetPosition( pt ) ;
1247 }
1248
9f884528 1249 InvalidateBestSize();
3803c372 1250 return true ;
37e2cb08 1251}
2f1ae414
SC
1252
1253void wxToolBar::OnPaint(wxPaintEvent& event)
1254{
e56d2520
SC
1255#if wxMAC_USE_NATIVE_TOOLBAR
1256 if ( m_macUsesNativeToolbar )
1257 {
1258 event.Skip(true) ;
1259 return ;
1260 }
1261#endif
1262
e40298d5 1263 wxPaintDC dc(this) ;
ddc548ec 1264
facd6764
SC
1265 int w, h ;
1266 GetSize( &w , &h ) ;
ddc548ec
SC
1267#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1268 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
1269 {
1270 if ( UMAGetSystemVersion() >= 0x1030 )
1271 {
1272 HIThemePlacardDrawInfo info ;
1273 memset( &info, 0 , sizeof( info ) ) ;
1274 info.version = 0 ;
1275 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1276
1277 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
1278 HIRect rect = CGRectMake( 0 , 0 , w , h ) ;
1279 HIThemeDrawPlacard( &rect , & info , cgContext, kHIThemeOrientationNormal) ;
1280 }
1281 }
1282 else
1283 {
1284 // leave the background as it is (striped or metal)
1285 }
1286#else
1287 wxMacPortSetter helper(&dc) ;
e40298d5 1288
1fd1922a 1289 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
1290 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
1291/*
1292 if( toolbarrect.left < 0 )
1293 toolbarrect.left = 0 ;
1294 if ( toolbarrect.top < 0 )
1295 toolbarrect.top = 0 ;
1296*/
01ffa8f7
SC
1297 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
1298 {
1299 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1300 }
1301 else
1302 {
1303#if TARGET_API_MAC_OSX
1304#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
20b69855
SC
1305 if ( UMAGetSystemVersion() >= 0x1030 )
1306 {
1307 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
1308 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
1309 CGContextRef cgContext ;
1310 Rect bounds ;
1311 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
1312 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1313 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
1314 CGContextScaleCTM( cgContext , 1 , -1 ) ;
785f5eaa 1315
20b69855
SC
1316 {
1317 HIThemeBackgroundDrawInfo drawInfo ;
1318 drawInfo.version = 0 ;
1319 drawInfo.state = kThemeStateActive ;
1320 drawInfo.kind = kThemeBackgroundMetal ;
1321 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
1322 }
e56d2520 1323
20b69855
SC
1324 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1325 }
1326 else
1327#endif
01ffa8f7 1328 {
20b69855 1329 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 1330 }
01ffa8f7 1331#endif
01ffa8f7
SC
1332 }
1333#endif
20b69855 1334
facd6764 1335 event.Skip() ;
2f1ae414 1336}
895f5af7 1337
519cb848
SC
1338#endif // wxUSE_TOOLBAR
1339