]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/toolbar.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
... / ...
CommitLineData
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/toolbar.h"
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
24#include "wx/bitmap.h"
25
26IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
27
28BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
29 EVT_PAINT( wxToolBar::OnPaint )
30END_EVENT_TABLE()
31
32#include "wx/mac/uma.h"
33#include "wx/geometry.h"
34
35#ifdef __WXMAC_OSX__
36const short kwxMacToolBarToolDefaultWidth = 16 ;
37const short kwxMacToolBarToolDefaultHeight = 16 ;
38const short kwxMacToolBarTopMargin = 4 ;
39const short kwxMacToolBarLeftMargin = 4 ;
40const short kwxMacToolBorder = 0 ;
41const short kwxMacToolSpacing = 6 ;
42#else
43const short kwxMacToolBarToolDefaultWidth = 24 ;
44const short kwxMacToolBarToolDefaultHeight = 22 ;
45const short kwxMacToolBarTopMargin = 2 ;
46const short kwxMacToolBarLeftMargin = 2 ;
47const short kwxMacToolBorder = 4 ;
48const short kwxMacToolSpacing = 0 ;
49#endif
50
51// ----------------------------------------------------------------------------
52// private classes
53// ----------------------------------------------------------------------------
54
55class wxToolBarTool : public wxToolBarToolBase
56{
57public:
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 }
73
74 ~wxToolBarTool()
75 {
76 if ( m_controlHandle )
77 DisposeControl( m_controlHandle ) ;
78 }
79
80 WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; }
81 void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; }
82
83 void SetSize(const wxSize& size) ;
84 void SetPosition( const wxPoint& position ) ;
85
86 void ClearControl() { m_control = NULL ; }
87
88 wxSize GetSize() const
89 {
90 if ( IsControl() )
91 {
92 return GetControl()->GetSize() ;
93 }
94 else if ( IsButton() )
95 {
96 return GetToolBar()->GetToolSize() ;
97 }
98 else
99 {
100 // separator size
101 wxSize sz = GetToolBar()->GetToolSize() ;
102 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
103 sz.y /= 4 ;
104 else
105 sz.x /= 4 ;
106 return sz ;
107 }
108 }
109 wxPoint GetPosition() const
110 {
111 return wxPoint(m_x, m_y);
112 }
113 bool DoEnable( bool enable ) ;
114
115 void UpdateToggleImage( bool toggle ) ;
116private :
117 void Init()
118 {
119 m_controlHandle = NULL ;
120 }
121 ControlRef m_controlHandle ;
122
123 wxCoord m_x;
124 wxCoord m_y;
125};
126
127static const EventTypeSpec eventList[] =
128{
129 { kEventClassControl , kEventControlHit } ,
130#ifdef __WXMAC_OSX__
131 { kEventClassControl , kEventControlHitTest } ,
132#endif
133} ;
134
135static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
136{
137 OSStatus result = eventNotHandledErr ;
138
139 wxMacCarbonEvent cEvent( event ) ;
140
141 ControlRef controlRef ;
142
143 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
144
145 switch( GetEventKind( event ) )
146 {
147 case kEventControlHit :
148 {
149 wxToolBarTool* tbartool = (wxToolBarTool*)data ;
150 if ( tbartool->CanBeToggled() )
151 {
152#ifdef __WXMAC_OSX__
153 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), !tbartool->IsToggled() );
154#else
155 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
156#endif
157 }
158 ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
159 result = noErr;
160 }
161 break ;
162#ifdef __WXMAC_OSX__
163 case kEventControlHitTest :
164 {
165 HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
166 HIRect rect ;
167 HIViewGetBounds( controlRef , &rect ) ;
168
169 ControlPartCode pc = kControlNoPart ;
170 if ( CGRectContainsPoint( rect , pt ) )
171 pc = kControlIconPart ;
172 cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
173 result = noErr ;
174 }
175 break ;
176#endif
177 default :
178 break ;
179 }
180 return result ;
181}
182
183static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
184{
185 OSStatus result = eventNotHandledErr ;
186
187 switch ( GetEventClass( event ) )
188 {
189 case kEventClassControl :
190 result = wxMacToolBarToolControlEventHandler( handler, event, data ) ;
191 break ;
192 default :
193 break ;
194 }
195 return result ;
196}
197
198DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
199
200// ============================================================================
201// implementation
202// ============================================================================
203
204// ----------------------------------------------------------------------------
205// wxToolBarTool
206// ----------------------------------------------------------------------------
207
208bool wxToolBarTool::DoEnable(bool enable)
209{
210 if ( IsControl() )
211 {
212 GetControl()->Enable( enable ) ;
213 }
214 else if ( IsButton() )
215 {
216#if TARGET_API_MAC_OSX
217 if ( enable )
218 EnableControl( m_controlHandle ) ;
219 else
220 DisableControl( m_controlHandle ) ;
221#else
222 if ( enable )
223 ActivateControl( m_controlHandle ) ;
224 else
225 DeactivateControl( m_controlHandle ) ;
226#endif
227 }
228 return true ;
229}
230void wxToolBarTool::SetSize(const wxSize& size)
231{
232 if ( IsControl() )
233 {
234 GetControl()->SetSize( size ) ;
235 }
236}
237
238void wxToolBarTool::SetPosition(const wxPoint& position)
239{
240 m_x = position.x;
241 m_y = position.y;
242
243 int x , y ;
244 x = y = 0 ;
245 int mac_x = position.x ;
246 int mac_y = position.y ;
247
248 if ( ! GetToolBar()->MacGetTopLevelWindow()->MacUsesCompositing() )
249 {
250 GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
251 mac_x += x;
252 mac_y += y;
253 }
254
255 if ( IsButton() )
256 {
257 Rect contrlRect ;
258 GetControlBounds( m_controlHandle , &contrlRect ) ;
259 int former_mac_x = contrlRect.left ;
260 int former_mac_y = contrlRect.top ;
261 GetToolBar()->GetToolSize() ;
262
263 if ( mac_x != former_mac_x || mac_y != former_mac_y )
264 {
265 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
266 }
267 }
268 else if ( IsControl() )
269 {
270 GetControl()->Move( position ) ;
271 }
272 else
273 {
274 // separator
275#ifdef __WXMAC_OSX__
276 Rect contrlRect ;
277 GetControlBounds( m_controlHandle , &contrlRect ) ;
278 int former_mac_x = contrlRect.left ;
279 int former_mac_y = contrlRect.top ;
280
281 if ( mac_x != former_mac_x || mac_y != former_mac_y )
282 {
283 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
284 }
285#endif
286 }
287}
288
289void wxToolBarTool::UpdateToggleImage( bool toggle )
290{
291#ifdef __WXMAC_OSX__
292 if ( toggle )
293 {
294 int w = m_bmpNormal.GetWidth() ;
295 int h = m_bmpNormal.GetHeight() ;
296 wxBitmap bmp( w , h ) ;
297 wxMemoryDC dc ;
298 dc.SelectObject( bmp ) ;
299 dc.SetPen( wxNullPen ) ;
300 dc.SetBackground( *wxWHITE ) ;
301 dc.DrawRectangle( 0 , 0 , w , h ) ;
302 dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ;
303 dc.SelectObject( wxNullBitmap ) ;
304 ControlButtonContentInfo info ;
305 wxMacCreateBitmapButton( &info , bmp ) ;
306 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
307 (Ptr)&info );
308 wxMacReleaseBitmapButton( &info ) ;
309 }
310 else
311 {
312 ControlButtonContentInfo info ;
313 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
314 SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
315 (Ptr)&info );
316 wxMacReleaseBitmapButton( &info ) ;
317 }
318
319 IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
320 SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
321 (Ptr)&transform );
322 HIViewSetNeedsDisplay( m_controlHandle , true ) ;
323
324#else
325 ::SetControl32BitValue( m_controlHandle , toggle ) ;
326#endif
327}
328
329wxToolBarTool::wxToolBarTool(wxToolBar *tbar,
330 int id,
331 const wxString& label,
332 const wxBitmap& bmpNormal,
333 const wxBitmap& bmpDisabled,
334 wxItemKind kind,
335 wxObject *clientData,
336 const wxString& shortHelp,
337 const wxString& longHelp)
338 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,
339 clientData, shortHelp, longHelp)
340{
341 Init();
342}
343
344
345wxToolBarToolBase *wxToolBar::CreateTool(int id,
346 const wxString& label,
347 const wxBitmap& bmpNormal,
348 const wxBitmap& bmpDisabled,
349 wxItemKind kind,
350 wxObject *clientData,
351 const wxString& shortHelp,
352 const wxString& longHelp)
353{
354 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
355 clientData, shortHelp, longHelp);
356}
357
358wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
359{
360 return new wxToolBarTool(this, control);
361}
362
363void wxToolBar::Init()
364{
365 m_maxWidth = -1;
366 m_maxHeight = -1;
367 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
368 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
369}
370
371bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
372 long style, const wxString& name)
373{
374
375 if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
376 return FALSE ;
377
378 return TRUE;
379}
380
381wxToolBar::~wxToolBar()
382{
383 // we must refresh the frame size when the toolbar is deleted but the frame
384 // is not - otherwise toolbar leaves a hole in the place it used to occupy
385}
386
387bool wxToolBar::Realize()
388{
389 if (m_tools.GetCount() == 0)
390 return FALSE;
391
392 int x = m_xMargin + kwxMacToolBarLeftMargin ;
393 int y = m_yMargin + kwxMacToolBarTopMargin ;
394
395 int tw, th;
396 GetSize(& tw, & th);
397
398 int maxWidth = 0 ;
399 int maxHeight = 0 ;
400
401 int maxToolWidth = 0;
402 int maxToolHeight = 0;
403
404 // Find the maximum tool width and height
405 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
406 while ( node )
407 {
408 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
409 wxSize sz = tool->GetSize() ;
410
411 if ( sz.x > maxToolWidth )
412 maxToolWidth = sz.x ;
413 if (sz.y> maxToolHeight)
414 maxToolHeight = sz.y;
415
416 node = node->GetNext();
417 }
418
419 bool lastWasRadio = FALSE;
420 node = m_tools.GetFirst();
421 while (node)
422 {
423 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
424 wxSize cursize = tool->GetSize() ;
425
426 bool isRadio = FALSE;
427
428 if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO )
429 {
430 if ( !lastWasRadio )
431 {
432 if (tool->Toggle(true))
433 {
434 DoToggleTool(tool, true);
435 }
436 }
437 else if (tool->IsToggled())
438 {
439 wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious();
440 while ( nodePrev )
441 {
442 wxToolBarToolBase *tool = nodePrev->GetData();
443 if ( !tool->IsButton() || (tool->GetKind() != wxITEM_RADIO) )
444 break;
445 if ( tool->Toggle(false) )
446 {
447 DoToggleTool(tool, false);
448 }
449 nodePrev = nodePrev->GetPrevious();
450 }
451 }
452 isRadio = TRUE;
453 }
454 else
455 {
456 isRadio = FALSE;
457 }
458 lastWasRadio = isRadio;
459
460 // for the moment we just do a single row/column alignement
461 if ( x + cursize.x > maxWidth )
462 maxWidth = x + cursize.x ;
463 if ( y + cursize.y > maxHeight )
464 maxHeight = y + cursize.y ;
465
466 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
467 {
468 int x1 = x + (maxToolWidth - cursize.x)/2 ;
469 tool->SetPosition( wxPoint( x1 , y ) ) ;
470 }
471 else
472 {
473 int y1 = y + (maxToolHeight - cursize.y)/2 ;
474 tool->SetPosition( wxPoint( x , y1 ) ) ;
475 }
476 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
477 {
478 y += cursize.y ;
479 y += kwxMacToolSpacing ;
480 }
481 else
482 {
483 x += cursize.x ;
484 x += kwxMacToolSpacing ;
485 }
486
487 node = node->GetNext();
488 }
489
490 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
491 {
492 if ( m_maxRows == 0 )
493 {
494 // if not set yet, only one row
495 SetRows(1);
496 }
497 m_minWidth = maxWidth;
498 maxWidth = tw ;
499 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
500 m_minHeight = m_maxHeight = maxHeight ;
501 }
502 else
503 {
504 if ( GetToolsCount() > 0 && m_maxRows == 0 )
505 {
506 // if not set yet, have one column
507 SetRows(GetToolsCount());
508 }
509 m_minHeight = maxHeight;
510 maxHeight = th ;
511 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
512 m_minWidth = m_maxWidth = maxWidth ;
513 }
514
515 SetSize( maxWidth, maxHeight );
516 InvalidateBestSize();
517
518 return TRUE;
519}
520
521void wxToolBar::SetToolBitmapSize(const wxSize& size)
522{
523 m_defaultWidth = size.x+kwxMacToolBorder; m_defaultHeight = size.y+kwxMacToolBorder;
524}
525
526// The button size is bigger than the bitmap size
527wxSize wxToolBar::GetToolSize() const
528{
529 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
530}
531
532void wxToolBar::SetRows(int nRows)
533{
534 if ( nRows == m_maxRows )
535 {
536 // avoid resizing the frame uselessly
537 return;
538 }
539
540 m_maxRows = nRows;
541}
542
543void wxToolBar::MacSuperChangedPosition()
544{
545 wxWindow::MacSuperChangedPosition() ;
546 Realize() ;
547}
548
549wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
550{
551 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
552 while (node)
553 {
554 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
555 wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
556 if ( r.Contains( wxPoint( x , y ) ) )
557 {
558 return tool;
559 }
560
561 node = node->GetNext();
562 }
563
564 return (wxToolBarToolBase *)NULL;
565}
566
567wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
568{
569 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
570 if ( tool )
571 {
572 return tool->GetShortHelp() ;
573 }
574 return wxEmptyString ;
575}
576
577void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
578{
579 ((wxToolBarTool*)t)->DoEnable( enable ) ;
580}
581
582void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
583{
584 wxToolBarTool *tool = (wxToolBarTool *)t;
585 if ( tool->IsButton() )
586 {
587 tool->UpdateToggleImage( toggle ) ;
588 }
589}
590
591bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
592 wxToolBarToolBase *toolBase)
593{
594 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase ) ;
595
596 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
597 wxSize toolSize = GetToolSize() ;
598 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
599 ControlRef controlHandle = NULL ;
600
601 switch( tool->GetStyle() )
602 {
603 case wxTOOL_STYLE_SEPARATOR :
604 {
605 wxASSERT( tool->GetControlHandle() == NULL ) ;
606 toolSize.x /= 4 ;
607 toolSize.y /= 4 ;
608 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
609 {
610 toolrect.bottom = toolSize.y ;
611 }
612 else
613 {
614 toolrect.right = toolSize.x ;
615 }
616 #ifdef __WXMAC_OSX__
617 // in flat style we need a visual separator
618 CreateSeparatorControl( window , &toolrect , &controlHandle ) ;
619 tool->SetControlHandle( controlHandle ) ;
620 #endif
621 }
622 break ;
623 case wxTOOL_STYLE_BUTTON :
624 {
625 wxASSERT( tool->GetControlHandle() == NULL ) ;
626 ControlButtonContentInfo info ;
627 wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
628
629 #ifdef __WXMAC_OSX__
630 CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
631 #else
632 SInt16 behaviour = kControlBehaviorOffsetContents ;
633 if ( tool->CanBeToggled() )
634 behaviour += kControlBehaviorToggles ;
635 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
636 0 , 0 , 0 , &controlHandle ) ;
637 #endif
638
639 wxMacReleaseBitmapButton( &info ) ;
640 /*
641 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
642 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
643 */
644
645 InstallControlEventHandler( (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
646 GetEventTypeCount(eventList), eventList, tool,NULL);
647
648 tool->SetControlHandle( controlHandle ) ;
649 }
650 break ;
651 case wxTOOL_STYLE_CONTROL :
652 wxASSERT( tool->GetControl() != NULL ) ;
653 // right now there's nothing to do here
654 break ;
655 }
656
657 if ( controlHandle )
658 {
659 ControlRef container = (ControlRef) GetHandle() ;
660 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
661
662 UMAShowControl( controlHandle ) ;
663 ::EmbedControl( controlHandle , container ) ;
664 }
665
666 if ( tool->CanBeToggled() && tool->IsToggled() )
667 {
668 tool->UpdateToggleImage( true ) ;
669 }
670
671 // nothing special to do here - we relayout in Realize() later
672 tool->Attach(this);
673 InvalidateBestSize();
674
675 return TRUE;
676}
677
678void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
679{
680 wxFAIL_MSG( _T("not implemented") );
681}
682
683bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
684{
685 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
686 wxToolBarToolsList::compatibility_iterator node;
687 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
688 {
689 wxToolBarToolBase *tool2 = node->GetData();
690 if ( tool2 == tool )
691 {
692 // let node point to the next node in the list
693 node = node->GetNext();
694
695 break;
696 }
697 }
698
699 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
700
701 tool->Detach();
702
703 switch ( tool->GetStyle() )
704 {
705 case wxTOOL_STYLE_CONTROL:
706 {
707 tool->GetControl()->Destroy();
708 tool->ClearControl() ;
709 }
710 break;
711
712 case wxTOOL_STYLE_BUTTON:
713 case wxTOOL_STYLE_SEPARATOR:
714 if ( tool->GetControlHandle() )
715 {
716 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
717 tool->SetControlHandle( (ControlRef) NULL ) ;
718 }
719 break;
720 }
721
722 // and finally reposition all the controls after this one
723
724 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
725 {
726 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
727 wxPoint pt = tool2->GetPosition() ;
728
729 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
730 {
731 pt.y -= sz.y ;
732 }
733 else
734 {
735 pt.x -= sz.x ;
736 }
737 tool2->SetPosition( pt ) ;
738 }
739
740 InvalidateBestSize();
741 return TRUE ;
742}
743
744void wxToolBar::OnPaint(wxPaintEvent& event)
745{
746 wxPaintDC dc(this) ;
747
748 int w, h ;
749 GetSize( &w , &h ) ;
750#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
751 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
752 {
753 if ( UMAGetSystemVersion() >= 0x1030 )
754 {
755 HIThemePlacardDrawInfo info ;
756 memset( &info, 0 , sizeof( info ) ) ;
757 info.version = 0 ;
758 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
759
760 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
761 HIRect rect = CGRectMake( 0 , 0 , w , h ) ;
762 HIThemeDrawPlacard( &rect , & info , cgContext, kHIThemeOrientationNormal) ;
763 }
764 }
765 else
766 {
767 // leave the background as it is (striped or metal)
768 }
769#else
770 wxMacPortSetter helper(&dc) ;
771
772 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
773 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
774/*
775 if( toolbarrect.left < 0 )
776 toolbarrect.left = 0 ;
777 if ( toolbarrect.top < 0 )
778 toolbarrect.top = 0 ;
779*/
780 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
781 {
782 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
783 }
784 else
785 {
786#if TARGET_API_MAC_OSX
787#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
788 if ( UMAGetSystemVersion() >= 0x1030 )
789 {
790 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
791 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
792 CGContextRef cgContext ;
793 Rect bounds ;
794 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
795 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
796 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
797 CGContextScaleCTM( cgContext , 1 , -1 ) ;
798
799 {
800 HIThemeBackgroundDrawInfo drawInfo ;
801 drawInfo.version = 0 ;
802 drawInfo.state = kThemeStateActive ;
803 drawInfo.kind = kThemeBackgroundMetal ;
804 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
805 }
806 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
807 }
808 else
809#endif
810 {
811 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
812 }
813#endif
814 }
815#endif
816
817 event.Skip() ;
818}
819
820#endif // wxUSE_TOOLBAR
821