]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
making removal and re-inserting possible
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: toolbar.cpp
3// Purpose: wxToolBar
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
84969af7 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: The wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "toolbar.h"
14#endif
15
3d1a4878 16#include "wx/wxprec.h"
519cb848
SC
17
18#if wxUSE_TOOLBAR
19
3d1a4878 20#include "wx/wx.h"
e9576ca5 21#include "wx/toolbar.h"
2f1ae414
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
72055702 24#include "wx/bitmap.h"
e9576ca5 25
2f1ae414 26#if !USE_SHARED_LIBRARY
2eb10e2a 27IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
e9576ca5
SC
28
29BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
e044f600 30 EVT_PAINT( wxToolBar::OnPaint )
e9576ca5 31END_EVENT_TABLE()
2f1ae414 32#endif
e9576ca5 33
d497dca4 34#include "wx/mac/uma.h"
bfe9ffbc 35#include "wx/geometry.h"
ee799df7
SC
36
37#ifdef __WXMAC_OSX__
17dfb611
SC
38const short kwxMacToolBarToolDefaultWidth = 16 ;
39const short kwxMacToolBarToolDefaultHeight = 16 ;
ee799df7
SC
40const short kwxMacToolBarTopMargin = 4 ;
41const short kwxMacToolBarLeftMargin = 4 ;
42const short kwxMacToolBorder = 0 ;
abbcdf3f 43const short kwxMacToolSpacing = 6 ;
ee799df7
SC
44#else
45const short kwxMacToolBarToolDefaultWidth = 24 ;
46const short kwxMacToolBarToolDefaultHeight = 22 ;
47const short kwxMacToolBarTopMargin = 2 ;
48const short kwxMacToolBarLeftMargin = 2 ;
49const short kwxMacToolBorder = 4 ;
abbcdf3f 50const short kwxMacToolSpacing = 0 ;
ee799df7
SC
51#endif
52
37e2cb08
SC
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
57class wxToolBarTool : public wxToolBarToolBase
58{
59public:
60 wxToolBarTool(wxToolBar *tbar,
61 int id,
27e2d606
GD
62 const wxString& label,
63 const wxBitmap& bmpNormal,
64 const wxBitmap& bmpDisabled,
65 wxItemKind kind,
37e2cb08 66 wxObject *clientData,
27e2d606 67 const wxString& shortHelp,
bfe9ffbc
SC
68 const wxString& longHelp) ;
69
37e2cb08
SC
70 wxToolBarTool(wxToolBar *tbar, wxControl *control)
71 : wxToolBarToolBase(tbar, control)
72 {
bfe9ffbc 73 Init() ;
37e2cb08 74 }
bfe9ffbc
SC
75
76 ~wxToolBarTool()
77 {
78 if ( m_controlHandle )
79 DisposeControl( m_controlHandle ) ;
80 }
81
facd6764
SC
82 WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; }
83 void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; }
37e2cb08 84
bfe9ffbc
SC
85 void SetSize(const wxSize& size) ;
86 void SetPosition( const wxPoint& position ) ;
a2fe01c9 87
be5fe3aa
SC
88 void ClearControl() { m_control = NULL ; }
89
bfe9ffbc
SC
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 {
abbcdf3f 102 // separator size
bfe9ffbc 103 wxSize sz = GetToolBar()->GetToolSize() ;
5a904a32
SC
104 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
105 sz.y /= 4 ;
106 else
107 sz.x /= 4 ;
bfe9ffbc
SC
108 return sz ;
109 }
110 }
111 wxPoint GetPosition() const
112 {
113 return wxPoint(m_x, m_y);
114 }
a2fe01c9 115 bool DoEnable( bool enable ) ;
73fd9428
SC
116
117 void UpdateToggleImage( bool toggle ) ;
bfe9ffbc
SC
118private :
119 void Init()
120 {
121 m_controlHandle = NULL ;
122 }
facd6764 123 ControlRef m_controlHandle ;
37e2cb08 124
bfe9ffbc
SC
125 wxCoord m_x;
126 wxCoord m_y;
37e2cb08
SC
127};
128
facd6764
SC
129static const EventTypeSpec eventList[] =
130{
131 { kEventClassControl , kEventControlHit } ,
73fd9428
SC
132#ifdef __WXMAC_OSX__
133 { kEventClassControl , kEventControlHitTest } ,
134#endif
facd6764
SC
135} ;
136
137static 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 {
64f553a4
SC
154#ifdef __WXMAC_OSX__
155 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), !tbartool->IsToggled() );
156#else
214b9484 157 ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
64f553a4 158#endif
facd6764
SC
159 }
160 ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
facd6764
SC
161 result = noErr;
162 }
163 break ;
73fd9428
SC
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 = kControlButtonPart ;
174 cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
175 result = noErr ;
176 }
177 break ;
178#endif
facd6764
SC
179 default :
180 break ;
181 }
182 return result ;
183}
184
185pascal 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
200DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
201
37e2cb08
SC
202// ============================================================================
203// implementation
204// ============================================================================
205
206// ----------------------------------------------------------------------------
207// wxToolBarTool
208// ----------------------------------------------------------------------------
209
a2fe01c9
SC
210bool 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}
bfe9ffbc
SC
232void wxToolBarTool::SetSize(const wxSize& size)
233{
234 if ( IsControl() )
235 {
236 GetControl()->SetSize( size ) ;
237 }
238}
239
240void wxToolBarTool::SetPosition(const wxPoint& position)
241{
242 m_x = position.x;
243 m_y = position.y;
244
789ae0cf
SC
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() )
bfe9ffbc 251 {
bfe9ffbc 252 GetToolBar()->MacWindowToRootWindow( &x , &y ) ;
facd6764
SC
253 mac_x += x;
254 mac_y += y;
789ae0cf
SC
255 }
256
257 if ( IsButton() )
258 {
bfe9ffbc
SC
259 Rect contrlRect ;
260 GetControlBounds( m_controlHandle , &contrlRect ) ;
261 int former_mac_x = contrlRect.left ;
262 int former_mac_y = contrlRect.top ;
80e3f464 263 GetToolBar()->GetToolSize() ;
bfe9ffbc
SC
264
265 if ( mac_x != former_mac_x || mac_y != former_mac_y )
266 {
bfe9ffbc 267 UMAMoveControl( m_controlHandle , mac_x , mac_y ) ;
bfe9ffbc
SC
268 }
269 }
270 else if ( IsControl() )
271 {
272 GetControl()->Move( position ) ;
273 }
abbcdf3f
SC
274 else
275 {
276 // separator
277#ifdef __WXMAC_OSX__
abbcdf3f
SC
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 }
bfe9ffbc
SC
289}
290
73fd9428
SC
291void 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
bfe9ffbc
SC
331wxToolBarTool::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{
f4e0be4f 343 Init();
bfe9ffbc
SC
344}
345
2f1ae414 346
37e2cb08 347wxToolBarToolBase *wxToolBar::CreateTool(int id,
27e2d606
GD
348 const wxString& label,
349 const wxBitmap& bmpNormal,
350 const wxBitmap& bmpDisabled,
351 wxItemKind kind,
37e2cb08 352 wxObject *clientData,
27e2d606
GD
353 const wxString& shortHelp,
354 const wxString& longHelp)
37e2cb08 355{
27e2d606
GD
356 return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
357 clientData, shortHelp, longHelp);
37e2cb08
SC
358}
359
360wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
361{
362 return new wxToolBarTool(this, control);
363}
364
37e2cb08 365void wxToolBar::Init()
e9576ca5 366{
e40298d5
JS
367 m_maxWidth = -1;
368 m_maxHeight = -1;
369 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
370 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
e9576ca5
SC
371}
372
373bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
374 long style, const wxString& name)
e40298d5 375{
ee799df7 376
facd6764
SC
377 if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
378 return FALSE ;
e40298d5
JS
379
380 return TRUE;
e9576ca5
SC
381}
382
383wxToolBar::~wxToolBar()
bfe9ffbc 384{
7810c95b
SC
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
e9576ca5
SC
387}
388
37e2cb08 389bool wxToolBar::Realize()
e9576ca5 390{
eb22f2a6 391 if (m_tools.GetCount() == 0)
0b7a8cd3
GD
392 return FALSE;
393
bfe9ffbc
SC
394 int x = m_xMargin + kwxMacToolBarLeftMargin ;
395 int y = m_yMargin + kwxMacToolBarTopMargin ;
0b7a8cd3 396
7c551d95
SC
397 int tw, th;
398 GetSize(& tw, & th);
895f5af7
SC
399
400 int maxWidth = 0 ;
401 int maxHeight = 0 ;
402
bfe9ffbc
SC
403 int maxToolWidth = 0;
404 int maxToolHeight = 0;
405
406 // Find the maximum tool width and height
affd2611 407 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc
SC
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
214b9484 421 bool lastWasRadio = FALSE;
bfe9ffbc 422 node = m_tools.GetFirst();
0b7a8cd3 423 while (node)
7810c95b 424 {
eb22f2a6 425 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
bfe9ffbc 426 wxSize cursize = tool->GetSize() ;
0b7a8cd3 427
214b9484
RD
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 isRadio = TRUE;
440 }
441 else
442 {
443 isRadio = FALSE;
444 }
445 lastWasRadio = isRadio;
446
bfe9ffbc
SC
447 // for the moment we just do a single row/column alignement
448 if ( x + cursize.x > maxWidth )
449 maxWidth = x + cursize.x ;
450 if ( y + cursize.y > maxHeight )
451 maxHeight = y + cursize.y ;
0b7a8cd3 452
73fd9428
SC
453 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
454 {
455 int x1 = x + (maxToolWidth - cursize.x)/2 ;
456 tool->SetPosition( wxPoint( x1 , y ) ) ;
457 }
458 else
459 {
460 int y1 = y + (maxToolHeight - cursize.y)/2 ;
461 tool->SetPosition( wxPoint( x , y1 ) ) ;
462 }
bfe9ffbc
SC
463 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
464 {
465 y += cursize.y ;
abbcdf3f 466 y += kwxMacToolSpacing ;
0b7a8cd3
GD
467 }
468 else
469 {
bfe9ffbc 470 x += cursize.x ;
abbcdf3f 471 x += kwxMacToolSpacing ;
0b7a8cd3 472 }
bfe9ffbc 473
eb22f2a6 474 node = node->GetNext();
7810c95b 475 }
0b7a8cd3
GD
476
477 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 478 {
0b7a8cd3
GD
479 if ( m_maxRows == 0 )
480 {
481 // if not set yet, only one row
482 SetRows(1);
483 }
90d3f91a 484 m_minWidth = maxWidth;
0b7a8cd3 485 maxWidth = tw ;
0b7a8cd3 486 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
90d3f91a 487 m_minHeight = m_maxHeight = maxHeight ;
7810c95b 488 }
0b7a8cd3
GD
489 else
490 {
bfe9ffbc 491 if ( GetToolsCount() > 0 && m_maxRows == 0 )
0b7a8cd3
GD
492 {
493 // if not set yet, have one column
bfe9ffbc 494 SetRows(GetToolsCount());
0b7a8cd3 495 }
90d3f91a 496 m_minHeight = maxHeight;
0b7a8cd3 497 maxHeight = th ;
0b7a8cd3 498 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
90d3f91a 499 m_minWidth = m_maxWidth = maxWidth ;
0b7a8cd3
GD
500 }
501
facd6764 502 SetSize( maxWidth, maxHeight );
9f884528 503 InvalidateBestSize();
0b7a8cd3
GD
504
505 return TRUE;
e9576ca5
SC
506}
507
508void wxToolBar::SetToolBitmapSize(const wxSize& size)
509{
ee799df7 510 m_defaultWidth = size.x+kwxMacToolBorder; m_defaultHeight = size.y+kwxMacToolBorder;
e9576ca5
SC
511}
512
e9576ca5
SC
513// The button size is bigger than the bitmap size
514wxSize wxToolBar::GetToolSize() const
515{
ee799df7 516 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
517}
518
37e2cb08 519void wxToolBar::SetRows(int nRows)
e9576ca5 520{
37e2cb08 521 if ( nRows == m_maxRows )
e9576ca5 522 {
37e2cb08
SC
523 // avoid resizing the frame uselessly
524 return;
e9576ca5 525 }
37e2cb08
SC
526
527 m_maxRows = nRows;
e9576ca5
SC
528}
529
c257d44d
SC
530void wxToolBar::MacSuperChangedPosition()
531{
c257d44d 532 wxWindow::MacSuperChangedPosition() ;
bfe9ffbc 533 Realize() ;
c257d44d
SC
534}
535
37e2cb08 536wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 537{
affd2611 538 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc 539 while (node)
e044f600 540 {
bfe9ffbc
SC
541 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
542 wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
543 if ( r.Contains( wxPoint( x , y ) ) )
e044f600 544 {
bfe9ffbc 545 return tool;
e044f600 546 }
bfe9ffbc
SC
547
548 node = node->GetNext();
e044f600 549 }
37e2cb08
SC
550
551 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
552}
553
2f1ae414
SC
554wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
555{
e044f600
RR
556 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
557 if ( tool )
558 {
559 return tool->GetShortHelp() ;
560 }
427ff662 561 return wxEmptyString ;
2f1ae414
SC
562}
563
37e2cb08 564void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 565{
a2fe01c9 566 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
567}
568
37e2cb08 569void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 570{
e044f600 571 wxToolBarTool *tool = (wxToolBarTool *)t;
bfe9ffbc
SC
572 if ( tool->IsButton() )
573 {
73fd9428 574 tool->UpdateToggleImage( toggle ) ;
bfe9ffbc 575 }
37e2cb08 576}
7c551d95 577
37e2cb08 578bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
be5fe3aa 579 wxToolBarToolBase *toolBase)
37e2cb08 580{
be5fe3aa
SC
581 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase ) ;
582
583 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
584 wxSize toolSize = GetToolSize() ;
585 Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ;
586 ControlRef controlHandle = NULL ;
587
588 switch( tool->GetStyle() )
589 {
590 case wxTOOL_STYLE_SEPARATOR :
591 {
592 wxASSERT( tool->GetControlHandle() == NULL ) ;
593 toolSize.x /= 4 ;
594 toolSize.y /= 4 ;
595 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
596 {
597 toolrect.bottom = toolSize.y ;
598 }
599 else
600 {
601 toolrect.right = toolSize.x ;
602 }
603 #ifdef __WXMAC_OSX__
604 // in flat style we need a visual separator
605 CreateSeparatorControl( window , &toolrect , &controlHandle ) ;
606 tool->SetControlHandle( controlHandle ) ;
607 #endif
608 }
609 break ;
610 case wxTOOL_STYLE_BUTTON :
611 {
612 wxASSERT( tool->GetControlHandle() == NULL ) ;
613 ControlButtonContentInfo info ;
614 wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
615
616 #ifdef __WXMAC_OSX__
617 CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
618 #else
619 SInt16 behaviour = kControlBehaviorOffsetContents ;
620 if ( CanBeToggled() )
621 behaviour += kControlBehaviorToggles ;
622 CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
623 0 , 0 , 0 , &controlHandle ) ;
624 #endif
625
626 wxMacReleaseBitmapButton( &info ) ;
627 /*
628 SetBevelButtonTextPlacement( m_controlHandle , kControlBevelButtonPlaceBelowGraphic ) ;
629 UMASetControlTitle( m_controlHandle , label , wxFont::GetDefaultEncoding() ) ;
630 */
631
632 InstallControlEventHandler( (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
633 GetEventTypeCount(eventList), eventList, tool,NULL);
634
635 tool->SetControlHandle( controlHandle ) ;
636 }
637 break ;
638 case wxTOOL_STYLE_CONTROL :
639 wxASSERT( tool->GetControl() != NULL ) ;
640 // right now there's nothing to do here
641 break ;
642 }
643
644 if ( controlHandle )
645 {
646 ControlRef container = (ControlRef) GetHandle() ;
647 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
648
649 UMAShowControl( controlHandle ) ;
650 ::EmbedControl( controlHandle , container ) ;
651 }
652
653 if ( tool->CanBeToggled() && tool->IsToggled() )
654 {
655 tool->UpdateToggleImage( true ) ;
656 }
657
bfe9ffbc 658 // nothing special to do here - we relayout in Realize() later
37e2cb08 659 tool->Attach(this);
9f884528 660 InvalidateBestSize();
7c551d95 661
37e2cb08
SC
662 return TRUE;
663}
e9576ca5 664
5115c51a 665void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 666{
5115c51a 667 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
668}
669
be5fe3aa 670bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
37e2cb08 671{
be5fe3aa 672 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
affd2611 673 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
674 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
675 {
676 wxToolBarToolBase *tool2 = node->GetData();
677 if ( tool2 == tool )
678 {
679 // let node point to the next node in the list
680 node = node->GetNext();
681
682 break;
683 }
684 }
685
686 wxSize sz = ((wxToolBarTool*)tool)->GetSize() ;
687
688 tool->Detach();
689
488b2c29
SC
690 switch ( tool->GetStyle() )
691 {
692 case wxTOOL_STYLE_CONTROL:
be5fe3aa
SC
693 {
694 tool->GetControl()->Destroy();
695 tool->ClearControl() ;
696 }
488b2c29
SC
697 break;
698
699 case wxTOOL_STYLE_BUTTON:
700 case wxTOOL_STYLE_SEPARATOR:
be5fe3aa 701 if ( tool->GetControlHandle() )
488b2c29 702 {
be5fe3aa
SC
703 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
704 tool->SetControlHandle( (ControlRef) NULL ) ;
488b2c29
SC
705 }
706 break;
707 }
708
bfe9ffbc
SC
709 // and finally reposition all the controls after this one
710
711 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
712 {
713 wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
714 wxPoint pt = tool2->GetPosition() ;
715
716 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
717 {
718 pt.y -= sz.y ;
719 }
720 else
721 {
722 pt.x -= sz.x ;
723 }
724 tool2->SetPosition( pt ) ;
725 }
726
9f884528 727 InvalidateBestSize();
5115c51a 728 return TRUE ;
37e2cb08 729}
2f1ae414
SC
730
731void wxToolBar::OnPaint(wxPaintEvent& event)
732{
e40298d5 733 wxPaintDC dc(this) ;
ddc548ec 734
facd6764
SC
735 int w, h ;
736 GetSize( &w , &h ) ;
ddc548ec
SC
737#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
738 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
739 {
740 if ( UMAGetSystemVersion() >= 0x1030 )
741 {
742 HIThemePlacardDrawInfo info ;
743 memset( &info, 0 , sizeof( info ) ) ;
744 info.version = 0 ;
745 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
746
747 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
748 HIRect rect = CGRectMake( 0 , 0 , w , h ) ;
749 HIThemeDrawPlacard( &rect , & info , cgContext, kHIThemeOrientationNormal) ;
750 }
751 }
752 else
753 {
754 // leave the background as it is (striped or metal)
755 }
756#else
757 wxMacPortSetter helper(&dc) ;
e40298d5 758
1fd1922a 759 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
760 dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ;
761/*
762 if( toolbarrect.left < 0 )
763 toolbarrect.left = 0 ;
764 if ( toolbarrect.top < 0 )
765 toolbarrect.top = 0 ;
766*/
01ffa8f7
SC
767 if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
768 {
769 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
770 }
771 else
772 {
773#if TARGET_API_MAC_OSX
774#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
20b69855
SC
775 if ( UMAGetSystemVersion() >= 0x1030 )
776 {
777 HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
778 dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
779 CGContextRef cgContext ;
780 Rect bounds ;
781 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
782 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
783 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
784 CGContextScaleCTM( cgContext , 1 , -1 ) ;
785f5eaa 785
20b69855
SC
786 {
787 HIThemeBackgroundDrawInfo drawInfo ;
788 drawInfo.version = 0 ;
789 drawInfo.state = kThemeStateActive ;
790 drawInfo.kind = kThemeBackgroundMetal ;
791 HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
792 }
793 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
794 }
795 else
796#endif
01ffa8f7 797 {
20b69855 798 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 799 }
01ffa8f7 800#endif
01ffa8f7
SC
801 }
802#endif
20b69855 803
facd6764 804 event.Skip() ;
2f1ae414 805}
895f5af7 806
519cb848
SC
807#endif // wxUSE_TOOLBAR
808