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