]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/toolbar.cpp
otherwise we always fall back to blitting, even if we can provide better results
[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 ) )
d60f41f2 173 pc = kControlIconPart ;
73fd9428
SC
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
0aeeec99 185static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
facd6764
SC
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 }
8f2ee25d
SC
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 }
214b9484
RD
454 isRadio = TRUE;
455 }
456 else
457 {
458 isRadio = FALSE;
459 }
460 lastWasRadio = isRadio;
461
bfe9ffbc
SC
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 ;
0b7a8cd3 467
73fd9428
SC
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 }
bfe9ffbc
SC
478 if ( GetWindowStyleFlag() & wxTB_VERTICAL )
479 {
480 y += cursize.y ;
abbcdf3f 481 y += kwxMacToolSpacing ;
0b7a8cd3
GD
482 }
483 else
484 {
bfe9ffbc 485 x += cursize.x ;
abbcdf3f 486 x += kwxMacToolSpacing ;
0b7a8cd3 487 }
bfe9ffbc 488
eb22f2a6 489 node = node->GetNext();
7810c95b 490 }
0b7a8cd3
GD
491
492 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
7810c95b 493 {
0b7a8cd3
GD
494 if ( m_maxRows == 0 )
495 {
496 // if not set yet, only one row
497 SetRows(1);
498 }
90d3f91a 499 m_minWidth = maxWidth;
0b7a8cd3 500 maxWidth = tw ;
0b7a8cd3 501 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
90d3f91a 502 m_minHeight = m_maxHeight = maxHeight ;
7810c95b 503 }
0b7a8cd3
GD
504 else
505 {
bfe9ffbc 506 if ( GetToolsCount() > 0 && m_maxRows == 0 )
0b7a8cd3
GD
507 {
508 // if not set yet, have one column
bfe9ffbc 509 SetRows(GetToolsCount());
0b7a8cd3 510 }
90d3f91a 511 m_minHeight = maxHeight;
0b7a8cd3 512 maxHeight = th ;
0b7a8cd3 513 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
90d3f91a 514 m_minWidth = m_maxWidth = maxWidth ;
0b7a8cd3
GD
515 }
516
facd6764 517 SetSize( maxWidth, maxHeight );
9f884528 518 InvalidateBestSize();
0b7a8cd3
GD
519
520 return TRUE;
e9576ca5
SC
521}
522
523void wxToolBar::SetToolBitmapSize(const wxSize& size)
524{
ee799df7 525 m_defaultWidth = size.x+kwxMacToolBorder; m_defaultHeight = size.y+kwxMacToolBorder;
e9576ca5
SC
526}
527
e9576ca5
SC
528// The button size is bigger than the bitmap size
529wxSize wxToolBar::GetToolSize() const
530{
ee799df7 531 return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder);
e9576ca5
SC
532}
533
37e2cb08 534void wxToolBar::SetRows(int nRows)
e9576ca5 535{
37e2cb08 536 if ( nRows == m_maxRows )
e9576ca5 537 {
37e2cb08
SC
538 // avoid resizing the frame uselessly
539 return;
e9576ca5 540 }
37e2cb08
SC
541
542 m_maxRows = nRows;
e9576ca5
SC
543}
544
c257d44d
SC
545void wxToolBar::MacSuperChangedPosition()
546{
c257d44d 547 wxWindow::MacSuperChangedPosition() ;
bfe9ffbc 548 Realize() ;
c257d44d
SC
549}
550
37e2cb08 551wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
e9576ca5 552{
affd2611 553 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
bfe9ffbc 554 while (node)
e044f600 555 {
bfe9ffbc
SC
556 wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
557 wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ;
558 if ( r.Contains( wxPoint( x , y ) ) )
e044f600 559 {
bfe9ffbc 560 return tool;
e044f600 561 }
bfe9ffbc
SC
562
563 node = node->GetNext();
e044f600 564 }
37e2cb08
SC
565
566 return (wxToolBarToolBase *)NULL;
e9576ca5
SC
567}
568
2f1ae414
SC
569wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
570{
e044f600
RR
571 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
572 if ( tool )
573 {
574 return tool->GetShortHelp() ;
575 }
427ff662 576 return wxEmptyString ;
2f1ae414
SC
577}
578
37e2cb08 579void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
e9576ca5 580{
a2fe01c9 581 ((wxToolBarTool*)t)->DoEnable( enable ) ;
e9576ca5
SC
582}
583
37e2cb08 584void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
e9576ca5 585{
e044f600 586 wxToolBarTool *tool = (wxToolBarTool *)t;
bfe9ffbc
SC
587 if ( tool->IsButton() )
588 {
73fd9428 589 tool->UpdateToggleImage( toggle ) ;
bfe9ffbc 590 }
37e2cb08 591}
7c551d95 592
37e2cb08 593bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
be5fe3aa 594 wxToolBarToolBase *toolBase)
37e2cb08 595{
be5fe3aa
SC
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 ;
61c747cd 635 if ( tool->CanBeToggled() )
be5fe3aa
SC
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
bfe9ffbc 673 // nothing special to do here - we relayout in Realize() later
37e2cb08 674 tool->Attach(this);
9f884528 675 InvalidateBestSize();
7c551d95 676
37e2cb08
SC
677 return TRUE;
678}
e9576ca5 679
5115c51a 680void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
37e2cb08 681{
5115c51a 682 wxFAIL_MSG( _T("not implemented") );
e9576ca5
SC
683}
684
be5fe3aa 685bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
37e2cb08 686{
be5fe3aa 687 wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolbase ) ;
affd2611 688 wxToolBarToolsList::compatibility_iterator node;
bfe9ffbc
SC
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
488b2c29
SC
705 switch ( tool->GetStyle() )
706 {
707 case wxTOOL_STYLE_CONTROL:
be5fe3aa
SC
708 {
709 tool->GetControl()->Destroy();
710 tool->ClearControl() ;
711 }
488b2c29
SC
712 break;
713
714 case wxTOOL_STYLE_BUTTON:
715 case wxTOOL_STYLE_SEPARATOR:
be5fe3aa 716 if ( tool->GetControlHandle() )
488b2c29 717 {
be5fe3aa
SC
718 DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
719 tool->SetControlHandle( (ControlRef) NULL ) ;
488b2c29
SC
720 }
721 break;
722 }
723
bfe9ffbc
SC
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
9f884528 742 InvalidateBestSize();
5115c51a 743 return TRUE ;
37e2cb08 744}
2f1ae414
SC
745
746void wxToolBar::OnPaint(wxPaintEvent& event)
747{
e40298d5 748 wxPaintDC dc(this) ;
ddc548ec 749
facd6764
SC
750 int w, h ;
751 GetSize( &w , &h ) ;
ddc548ec
SC
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) ;
e40298d5 773
1fd1922a 774 Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
facd6764
SC
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*/
01ffa8f7
SC
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
20b69855
SC
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 ) ;
785f5eaa 800
20b69855
SC
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
01ffa8f7 812 {
20b69855 813 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
01ffa8f7 814 }
01ffa8f7 815#endif
01ffa8f7
SC
816 }
817#endif
20b69855 818
facd6764 819 event.Skip() ;
2f1ae414 820}
895f5af7 821
519cb848
SC
822#endif // wxUSE_TOOLBAR
823