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