]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toolbar.cpp
cleanup - reformatting
[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 insertAll = true;
891
892 // if this is the first tool that gets newly inserted or repositioned
893 // first remove all 'old' tools from here to the right, because of this
894 // all following tools will have to be reinserted (insertAll). i = 100 because there's
895 // no way to determine how many there are in a toolbar, so just a high number :-(
896 for ( CFIndex i = 100 ; i >= currentPosition ; --i )
897 {
898 err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, i );
899 }
900
901 if (err != noErr)
902 {
903 wxString errMsg = wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err );
904 wxASSERT_MSG( 0, errMsg.c_str() );
905 }
906 }
907
908 err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef, currentPosition );
909 if (err != noErr)
910 {
911 wxString errMsg = wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err );
912 wxASSERT_MSG( 0, errMsg.c_str() );
913 }
914
915 tool->SetIndex( currentPosition );
916 }
917
918 currentPosition++;
919 }
920 }
921 #endif
922
923 // update radio button (and group) state
924 lastIsRadio = curIsRadio;
925 curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) );
926
927 if ( !curIsRadio )
928 {
929 if ( tool->IsToggled() )
930 DoToggleTool( tool, true );
931
932 setChoiceInGroup = false;
933 }
934 else
935 {
936 if ( !lastIsRadio )
937 {
938 if ( tool->Toggle( true ) )
939 {
940 DoToggleTool( tool, true );
941 setChoiceInGroup = true;
942 }
943 }
944 else if ( tool->IsToggled() )
945 {
946 if ( tool->IsToggled() )
947 DoToggleTool( tool, true );
948
949 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
950 while ( nodePrev != NULL )
951 {
952 wxToolBarToolBase *toggleTool = nodePrev->GetData();
953 if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) )
954 break;
955
956 if ( toggleTool->Toggle( false ) )
957 DoToggleTool( toggleTool, false );
958
959 nodePrev = nodePrev->GetPrevious();
960 }
961 }
962 }
963
964 node = node->GetNext();
965 }
966
967 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
968 {
969 // if not set yet, only one row
970 if ( m_maxRows <= 0 )
971 SetRows( 1 );
972
973 m_minWidth = maxWidth;
974 maxWidth = tw;
975 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
976 m_minHeight = m_maxHeight = maxHeight;
977 }
978 else
979 {
980 // if not set yet, have one column
981 if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
982 SetRows( GetToolsCount() );
983
984 m_minHeight = maxHeight;
985 maxHeight = th;
986 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
987 m_minWidth = m_maxWidth = maxWidth;
988 }
989
990 #if 0
991 // FIXME: should this be OSX-only?
992 {
993 bool wantNativeToolbar, ownToolbarInstalled;
994
995 // attempt to install the native toolbar
996 wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0);
997 MacInstallNativeToolbar( wantNativeToolbar );
998 (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
999 if (!ownToolbarInstalled)
1000 {
1001 SetSize( maxWidth, maxHeight );
1002 InvalidateBestSize();
1003 }
1004 }
1005 #else
1006 SetSize( maxWidth, maxHeight );
1007 InvalidateBestSize();
1008 #endif
1009
1010 SetBestFittingSize();
1011
1012 return true;
1013 }
1014
1015 void wxToolBar::SetToolBitmapSize(const wxSize& size)
1016 {
1017 m_defaultWidth = size.x + kwxMacToolBorder;
1018 m_defaultHeight = size.y + kwxMacToolBorder;
1019
1020 #if wxMAC_USE_NATIVE_TOOLBAR
1021 if (m_macHIToolbarRef != NULL)
1022 {
1023 int maxs = wxMax( size.x, size.y );
1024 HIToolbarDisplaySize sizeSpec ;
1025 if ( maxs > 32 )
1026 sizeSpec = kHIToolbarDisplaySizeNormal ;
1027 else if ( maxs > 24 )
1028 sizeSpec = kHIToolbarDisplaySizeDefault ;
1029 else
1030 sizeSpec = kHIToolbarDisplaySizeSmall ;
1031
1032 HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
1033 }
1034 #endif
1035 }
1036
1037 // The button size is bigger than the bitmap size
1038 wxSize wxToolBar::GetToolSize() const
1039 {
1040 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
1041 }
1042
1043 void wxToolBar::SetRows(int nRows)
1044 {
1045 // avoid resizing the frame uselessly
1046 if ( nRows != m_maxRows )
1047 m_maxRows = nRows;
1048 }
1049
1050 void wxToolBar::MacSuperChangedPosition()
1051 {
1052 wxWindow::MacSuperChangedPosition();
1053
1054 #if wxMAC_USE_NATIVE_TOOLBAR
1055 if (! m_macUsesNativeToolbar )
1056 Realize();
1057 #else
1058 Realize();
1059 #endif
1060 }
1061
1062 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
1063 {
1064 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1065 while ( node != NULL )
1066 {
1067 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
1068
1069 if (tool != NULL)
1070 {
1071 wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
1072 if ( r.Contains( wxPoint( x, y ) ) )
1073 return tool;
1074 }
1075
1076 node = node->GetNext();
1077 }
1078
1079 return (wxToolBarToolBase *)NULL;
1080 }
1081
1082 wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
1083 {
1084 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
1085 if ( tool != NULL )
1086 return tool->GetShortHelp() ;
1087
1088 return wxEmptyString ;
1089 }
1090
1091 void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
1092 {
1093 if ( t != NULL )
1094 ((wxToolBarTool*)t)->DoEnable( enable ) ;
1095 }
1096
1097 void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
1098 {
1099 wxToolBarTool *tool = (wxToolBarTool *)t;
1100 if ( ( tool != NULL ) && tool->IsButton() )
1101 tool->UpdateToggleImage( toggle );
1102 }
1103
1104 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
1105 wxToolBarToolBase *toolBase)
1106 {
1107 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase );
1108 if (tool == NULL)
1109 return false;
1110
1111 WindowRef window = (WindowRef) MacGetTopLevelWindowRef();
1112 wxSize toolSize = GetToolSize();
1113 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x };
1114 ControlRef controlHandle = NULL;
1115 OSStatus err = 0;
1116
1117 switch (tool->GetStyle())
1118 {
1119 case wxTOOL_STYLE_SEPARATOR :
1120 {
1121 wxASSERT( tool->GetControlHandle() == NULL );
1122 toolSize.x /= 4;
1123 toolSize.y /= 4;
1124 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
1125 toolrect.bottom = toolSize.y;
1126 else
1127 toolrect.right = toolSize.x;
1128
1129 #ifdef __WXMAC_OSX__
1130 // in flat style we need a visual separator
1131 #if wxMAC_USE_NATIVE_TOOLBAR
1132 HIToolbarItemRef item;
1133 err = HIToolbarItemCreate(
1134 kHIToolbarSeparatorIdentifier,
1135 kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
1136 &item );
1137 if (err == noErr)
1138 tool->SetToolbarItemRef( item );
1139 #endif
1140
1141 CreateSeparatorControl( window, &toolrect, &controlHandle );
1142 tool->SetControlHandle( controlHandle );
1143 #endif
1144 }
1145 break;
1146
1147 case wxTOOL_STYLE_BUTTON :
1148 {
1149 wxASSERT( tool->GetControlHandle() == NULL ) ;
1150 ControlButtonContentInfo info ;
1151 wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
1152
1153 if ( UMAGetSystemVersion() >= 0x1000)
1154 CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
1155 else
1156 {
1157 SInt16 behaviour = kControlBehaviorOffsetContents ;
1158 if ( tool->CanBeToggled() )
1159 behaviour |= kControlBehaviorToggles ;
1160 CreateBevelButtonControl( window ,
1161 &toolrect , CFSTR("") , kControlBevelButtonNormalBevel ,
1162 behaviour , &info , 0 , 0 , 0 , &controlHandle ) ;
1163 }
1164
1165 #if wxMAC_USE_NATIVE_TOOLBAR
1166 HIToolbarItemRef item ;
1167 wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
1168 err = HIToolbarItemCreate(
1169 wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1170 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
1171 if (err == noErr)
1172 {
1173 InstallEventHandler( HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
1174 GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
1175 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1176 HIToolbarItemSetIconRef( item, info.u.iconRef );
1177 HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
1178 tool->SetToolbarItemRef( item );
1179 }
1180 #endif
1181
1182 wxMacReleaseBitmapButton( &info ) ;
1183 #if 0
1184 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
1185 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
1186 #endif
1187
1188 InstallControlEventHandler( (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
1189 GetEventTypeCount(eventList), eventList, tool, NULL );
1190
1191 tool->SetControlHandle( controlHandle );
1192 }
1193 break;
1194
1195 case wxTOOL_STYLE_CONTROL :
1196 wxASSERT( tool->GetControl() != NULL );
1197 #if 0 // wxMAC_USE_NATIVE_TOOLBAR
1198 // FIXME: doesn't work yet...
1199 {
1200 HIToolbarItemRef item;
1201 wxString labelStr = wxString::Format( wxT("%xd"), (int) tool );
1202 result = HIToolbarItemCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
1203 kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates,
1204 &item );
1205 if ( result == 0 )
1206 {
1207 HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
1208 HIToolbarItemSetCommandID( item, tool->GetId() );
1209 tool->SetToolbarItemRef( item );
1210
1211 controlHandle = ( ControlRef ) tool->GetControlHandle();
1212 wxASSERT_MSG( controlHandle != NULL, wxT("NULL tool control") );
1213
1214 // FIXME: is this necessary ??
1215 ::GetControlBounds( controlHandle, &toolrect );
1216 UMAMoveControl( controlHandle, -toolrect.left, -toolrect.top );
1217
1218 // FIXME: is this necessary ??
1219 InstallControlEventHandler( controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
1220 GetEventTypeCount(eventList), eventList, tool, NULL );
1221 }
1222 }
1223
1224 #else
1225 // FIXME: right now there's nothing to do here
1226 #endif
1227 break;
1228
1229 default :
1230 break;
1231 }
1232
1233 if ( err == noErr )
1234 {
1235 if ( controlHandle )
1236 {
1237 ControlRef container = (ControlRef) GetHandle();
1238 wxASSERT_MSG( container != NULL, wxT("No valid mac container control") );
1239
1240 UMAShowControl( controlHandle );
1241 ::EmbedControl( controlHandle, container );
1242 }
1243
1244 if ( tool->CanBeToggled() && tool->IsToggled() )
1245 tool->UpdateToggleImage( true );
1246
1247 // nothing special to do here - we relayout in Realize() later
1248 tool->Attach(this);
1249 InvalidateBestSize();
1250 }
1251 else
1252 {
1253 wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long) err );
1254 wxASSERT_MSG( false, errMsg.c_str() );
1255 }
1256
1257 return (err == noErr);
1258 }
1259
1260 void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
1261 {
1262 wxFAIL_MSG( _T("not implemented") );
1263 }
1264
1265 bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
1266 {
1267 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
1268 wxToolBarToolsList::compatibility_iterator node;
1269 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
1270 {
1271 wxToolBarToolBase *tool2 = node->GetData();
1272 if ( tool2 == tool )
1273 {
1274 // let node point to the next node in the list
1275 node = node->GetNext();
1276
1277 break;
1278 }
1279 }
1280
1281 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
1282
1283 tool->Detach();
1284
1285 #if wxMAC_USE_NATIVE_TOOLBAR
1286 CFIndex removeIndex = tool->GetIndex();
1287 #endif
1288
1289 switch ( tool->GetStyle() )
1290 {
1291 case wxTOOL_STYLE_CONTROL:
1292 {
1293 tool->GetControl()->Destroy();
1294 tool->ClearControl() ;
1295 }
1296 break;
1297
1298 case wxTOOL_STYLE_BUTTON:
1299 case wxTOOL_STYLE_SEPARATOR:
1300 if ( tool->GetControlHandle() )
1301 {
1302 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
1303
1304 #if wxMAC_USE_NATIVE_TOOLBAR
1305 if ( removeIndex != -1 && m_macHIToolbarRef )
1306 {
1307 HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef , removeIndex ) ;
1308 tool->SetIndex( -1 ) ;
1309 }
1310 #endif
1311
1312 tool->ClearControl() ;
1313 }
1314 break;
1315
1316 default:
1317 break;
1318 }
1319
1320 // and finally reposition all the controls after this one
1321
1322 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
1323 {
1324 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
1325 wxPoint pt = tool2->GetPosition() ;
1326
1327 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
1328 pt.y -= sz.y ;
1329 else
1330 pt.x -= sz.x ;
1331
1332 tool2->SetPosition( pt ) ;
1333
1334 #if wxMAC_USE_NATIVE_TOOLBAR
1335 if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
1336 tool2->SetIndex( tool2->GetIndex() - 1 ) ;
1337 #endif
1338 }
1339
1340 InvalidateBestSize();
1341
1342 return true ;
1343 }
1344
1345 void wxToolBar::OnPaint(wxPaintEvent& event)
1346 {
1347 #if wxMAC_USE_NATIVE_TOOLBAR
1348 if ( m_macUsesNativeToolbar )
1349 {
1350 event.Skip(true);
1351 return;
1352 }
1353 #endif
1354
1355 wxPaintDC dc(this) ;
1356
1357 int w, h ;
1358 GetSize( &w , &h ) ;
1359
1360 bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance();
1361 bool minimumUmaAvailable = (UMAGetSystemVersion() >= 0x1030);
1362
1363 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1364 if ( !drawMetalTheme && minimumUmaAvailable )
1365 {
1366 HIThemePlacardDrawInfo info;
1367 memset( &info, 0, sizeof(info) );
1368 info.version = 0;
1369 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive;
1370
1371 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef();
1372 HIRect rect = CGRectMake( 0, 0, w, h );
1373 HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal );
1374 }
1375 else
1376 {
1377 // leave the background as it is (striped or metal)
1378 }
1379
1380 #else
1381
1382 const bool drawBorder = true;
1383
1384 if (drawBorder)
1385 {
1386 wxMacPortSetter helper(&dc) ;
1387
1388 if ( !drawMetalTheme || !minimumUmaAvailable )
1389 {
1390 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
1391 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
1392
1393 #if 0
1394 if ( toolbarrect.left < 0 )
1395 toolbarrect.left = 0 ;
1396 if ( toolbarrect.top < 0 )
1397 toolbarrect.top = 0 ;
1398 #endif
1399
1400 UMADrawThemePlacard( &toolbarrect, IsEnabled() ? kThemeStateActive : kThemeStateInactive );
1401 }
1402 else
1403 {
1404 #if TARGET_API_MAC_OSX
1405 HIRect hiToolbarrect = CGRectMake(
1406 dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
1407 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
1408 CGContextRef cgContext ;
1409 Rect bounds ;
1410
1411 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
1412 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1413
1414 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
1415 CGContextScaleCTM( cgContext , 1 , -1 ) ;
1416
1417 HIThemeBackgroundDrawInfo drawInfo ;
1418 drawInfo.version = 0 ;
1419 drawInfo.state = kThemeStateActive ;
1420 drawInfo.kind = kThemeBackgroundMetal ;
1421 HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal );
1422
1423 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
1424 #endif
1425 }
1426 }
1427 #endif
1428
1429 event.Skip();
1430 }
1431
1432 #endif // wxUSE_TOOLBAR
1433