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