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