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