]>
Commit | Line | Data |
---|---|---|
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 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
e9576ca5 SC |
28 | |
29 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) | |
e044f600 | 30 | EVT_PAINT( wxToolBar::OnPaint ) |
e9576ca5 | 31 | END_EVENT_TABLE() |
2f1ae414 | 32 | #endif |
e9576ca5 | 33 | |
d497dca4 | 34 | #include "wx/mac/uma.h" |
bfe9ffbc | 35 | #include "wx/geometry.h" |
37e2cb08 SC |
36 | // ---------------------------------------------------------------------------- |
37 | // private classes | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | class wxToolBarTool : public wxToolBarToolBase | |
41 | { | |
42 | public: | |
43 | wxToolBarTool(wxToolBar *tbar, | |
44 | int id, | |
27e2d606 GD |
45 | const wxString& label, |
46 | const wxBitmap& bmpNormal, | |
47 | const wxBitmap& bmpDisabled, | |
48 | wxItemKind kind, | |
37e2cb08 | 49 | wxObject *clientData, |
27e2d606 | 50 | const wxString& shortHelp, |
bfe9ffbc SC |
51 | const wxString& longHelp) ; |
52 | ||
37e2cb08 SC |
53 | wxToolBarTool(wxToolBar *tbar, wxControl *control) |
54 | : wxToolBarToolBase(tbar, control) | |
55 | { | |
bfe9ffbc | 56 | Init() ; |
37e2cb08 | 57 | } |
bfe9ffbc SC |
58 | |
59 | ~wxToolBarTool() | |
60 | { | |
61 | if ( m_controlHandle ) | |
62 | DisposeControl( m_controlHandle ) ; | |
63 | } | |
64 | ||
facd6764 SC |
65 | WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; } |
66 | void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; } | |
37e2cb08 | 67 | |
bfe9ffbc SC |
68 | void SetSize(const wxSize& size) ; |
69 | void SetPosition( const wxPoint& position ) ; | |
a2fe01c9 | 70 | |
bfe9ffbc SC |
71 | wxSize GetSize() const |
72 | { | |
73 | if ( IsControl() ) | |
74 | { | |
75 | return GetControl()->GetSize() ; | |
76 | } | |
77 | else if ( IsButton() ) | |
78 | { | |
79 | return GetToolBar()->GetToolSize() ; | |
80 | } | |
81 | else | |
82 | { | |
83 | wxSize sz = GetToolBar()->GetToolSize() ; | |
84 | sz.x /= 4 ; | |
85 | sz.y /= 4 ; | |
86 | return sz ; | |
87 | } | |
88 | } | |
89 | wxPoint GetPosition() const | |
90 | { | |
91 | return wxPoint(m_x, m_y); | |
92 | } | |
a2fe01c9 | 93 | bool DoEnable( bool enable ) ; |
bfe9ffbc SC |
94 | private : |
95 | void Init() | |
96 | { | |
97 | m_controlHandle = NULL ; | |
98 | } | |
facd6764 | 99 | ControlRef m_controlHandle ; |
37e2cb08 | 100 | |
bfe9ffbc SC |
101 | wxCoord m_x; |
102 | wxCoord m_y; | |
37e2cb08 SC |
103 | }; |
104 | ||
facd6764 SC |
105 | static const EventTypeSpec eventList[] = |
106 | { | |
107 | { kEventClassControl , kEventControlHit } , | |
108 | } ; | |
109 | ||
110 | static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
111 | { | |
112 | OSStatus result = eventNotHandledErr ; | |
113 | ||
114 | wxMacCarbonEvent cEvent( event ) ; | |
115 | ||
116 | ControlRef controlRef ; | |
117 | ||
118 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
119 | ||
120 | switch( GetEventKind( event ) ) | |
121 | { | |
122 | case kEventControlHit : | |
123 | { | |
124 | wxToolBarTool* tbartool = (wxToolBarTool*)data ; | |
125 | if ( tbartool->CanBeToggled() ) | |
126 | { | |
214b9484 | 127 | ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle())); |
facd6764 SC |
128 | } |
129 | ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ; | |
facd6764 SC |
130 | result = noErr; |
131 | } | |
132 | break ; | |
133 | default : | |
134 | break ; | |
135 | } | |
136 | return result ; | |
137 | } | |
138 | ||
139 | pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
140 | { | |
141 | OSStatus result = eventNotHandledErr ; | |
142 | ||
143 | switch ( GetEventClass( event ) ) | |
144 | { | |
145 | case kEventClassControl : | |
146 | result = wxMacToolBarToolControlEventHandler( handler, event, data ) ; | |
147 | break ; | |
148 | default : | |
149 | break ; | |
150 | } | |
151 | return result ; | |
152 | } | |
153 | ||
154 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler ) | |
155 | ||
37e2cb08 SC |
156 | // ============================================================================ |
157 | // implementation | |
158 | // ============================================================================ | |
159 | ||
160 | // ---------------------------------------------------------------------------- | |
161 | // wxToolBarTool | |
162 | // ---------------------------------------------------------------------------- | |
163 | ||
a2fe01c9 SC |
164 | bool wxToolBarTool::DoEnable(bool enable) |
165 | { | |
166 | if ( IsControl() ) | |
167 | { | |
168 | GetControl()->Enable( enable ) ; | |
169 | } | |
170 | else if ( IsButton() ) | |
171 | { | |
172 | #if TARGET_API_MAC_OSX | |
173 | if ( enable ) | |
174 | EnableControl( m_controlHandle ) ; | |
175 | else | |
176 | DisableControl( m_controlHandle ) ; | |
177 | #else | |
178 | if ( enable ) | |
179 | ActivateControl( m_controlHandle ) ; | |
180 | else | |
181 | DeactivateControl( m_controlHandle ) ; | |
182 | #endif | |
183 | } | |
184 | return true ; | |
185 | } | |
bfe9ffbc SC |
186 | void wxToolBarTool::SetSize(const wxSize& size) |
187 | { | |
188 | if ( IsControl() ) | |
189 | { | |
190 | GetControl()->SetSize( size ) ; | |
191 | } | |
192 | } | |
193 | ||
194 | void wxToolBarTool::SetPosition(const wxPoint& position) | |
195 | { | |
196 | m_x = position.x; | |
197 | m_y = position.y; | |
198 | ||
199 | if ( IsButton() ) | |
200 | { | |
201 | int x , y ; | |
202 | x = y = 0 ; | |
facd6764 SC |
203 | int mac_x = position.x ; |
204 | int mac_y = position.y ; | |
205 | #if !TARGET_API_MAC_OSX | |
206 | WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetTopLevelWindowRef() ; | |
bfe9ffbc | 207 | GetToolBar()->MacWindowToRootWindow( &x , &y ) ; |
facd6764 SC |
208 | mac_x += x; |
209 | mac_y += y; | |
210 | #endif | |
bfe9ffbc SC |
211 | Rect contrlRect ; |
212 | GetControlBounds( m_controlHandle , &contrlRect ) ; | |
213 | int former_mac_x = contrlRect.left ; | |
214 | int former_mac_y = contrlRect.top ; | |
80e3f464 | 215 | GetToolBar()->GetToolSize() ; |
bfe9ffbc SC |
216 | |
217 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
218 | { | |
bfe9ffbc | 219 | UMAMoveControl( m_controlHandle , mac_x , mac_y ) ; |
bfe9ffbc SC |
220 | } |
221 | } | |
222 | else if ( IsControl() ) | |
223 | { | |
224 | GetControl()->Move( position ) ; | |
225 | } | |
226 | } | |
227 | ||
895f5af7 SC |
228 | const short kwxMacToolBarToolDefaultWidth = 24 ; |
229 | const short kwxMacToolBarToolDefaultHeight = 22 ; | |
230 | const short kwxMacToolBarTopMargin = 2 ; | |
231 | const short kwxMacToolBarLeftMargin = 2 ; | |
232 | ||
bfe9ffbc SC |
233 | wxToolBarTool::wxToolBarTool(wxToolBar *tbar, |
234 | int id, | |
235 | const wxString& label, | |
236 | const wxBitmap& bmpNormal, | |
237 | const wxBitmap& bmpDisabled, | |
238 | wxItemKind kind, | |
239 | wxObject *clientData, | |
240 | const wxString& shortHelp, | |
241 | const wxString& longHelp) | |
242 | : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind, | |
243 | clientData, shortHelp, longHelp) | |
244 | { | |
f4e0be4f RR |
245 | Init(); |
246 | ||
247 | if (id == wxID_SEPARATOR) return; | |
bfe9ffbc | 248 | |
facd6764 | 249 | WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ; |
bfe9ffbc SC |
250 | wxSize toolSize = tbar->GetToolSize() ; |
251 | Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ; | |
252 | ||
253 | ControlButtonContentInfo info ; | |
254 | wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ; | |
255 | ||
256 | SInt16 behaviour = kControlBehaviorOffsetContents ; | |
257 | if ( CanBeToggled() ) | |
258 | behaviour += kControlBehaviorToggles ; | |
bfe9ffbc | 259 | |
4c37f124 SC |
260 | CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info , |
261 | 0 , 0 , 0 , &m_controlHandle ) ; | |
262 | ||
20b69855 SC |
263 | wxMacReleaseBitmapButton( &info ) ; |
264 | ||
facd6764 SC |
265 | InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(), |
266 | GetEventTypeCount(eventList), eventList, this,NULL); | |
4c37f124 | 267 | |
bfe9ffbc | 268 | UMAShowControl( m_controlHandle ) ; |
4c37f124 | 269 | |
bfe9ffbc | 270 | if ( CanBeToggled() && IsToggled() ) |
bfe9ffbc | 271 | ::SetControl32BitValue( m_controlHandle , 1 ) ; |
bfe9ffbc | 272 | else |
bfe9ffbc | 273 | ::SetControl32BitValue( m_controlHandle , 0 ) ; |
bfe9ffbc | 274 | |
facd6764 | 275 | ControlRef container = (ControlRef) tbar->GetHandle() ; |
bfe9ffbc SC |
276 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; |
277 | ::EmbedControl( m_controlHandle , container ) ; | |
278 | } | |
279 | ||
2f1ae414 | 280 | |
37e2cb08 | 281 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
27e2d606 GD |
282 | const wxString& label, |
283 | const wxBitmap& bmpNormal, | |
284 | const wxBitmap& bmpDisabled, | |
285 | wxItemKind kind, | |
37e2cb08 | 286 | wxObject *clientData, |
27e2d606 GD |
287 | const wxString& shortHelp, |
288 | const wxString& longHelp) | |
37e2cb08 | 289 | { |
27e2d606 GD |
290 | return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind, |
291 | clientData, shortHelp, longHelp); | |
37e2cb08 SC |
292 | } |
293 | ||
294 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) | |
295 | { | |
296 | return new wxToolBarTool(this, control); | |
297 | } | |
298 | ||
37e2cb08 | 299 | void wxToolBar::Init() |
e9576ca5 | 300 | { |
e40298d5 JS |
301 | m_maxWidth = -1; |
302 | m_maxHeight = -1; | |
303 | m_defaultWidth = kwxMacToolBarToolDefaultWidth; | |
304 | m_defaultHeight = kwxMacToolBarToolDefaultHeight; | |
e9576ca5 SC |
305 | } |
306 | ||
307 | bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
308 | long style, const wxString& name) | |
e40298d5 | 309 | { |
facd6764 SC |
310 | if ( !wxToolBarBase::Create( parent , id , pos , size , style ) ) |
311 | return FALSE ; | |
e40298d5 JS |
312 | |
313 | return TRUE; | |
e9576ca5 SC |
314 | } |
315 | ||
316 | wxToolBar::~wxToolBar() | |
bfe9ffbc | 317 | { |
7810c95b SC |
318 | // we must refresh the frame size when the toolbar is deleted but the frame |
319 | // is not - otherwise toolbar leaves a hole in the place it used to occupy | |
e9576ca5 SC |
320 | } |
321 | ||
37e2cb08 | 322 | bool wxToolBar::Realize() |
e9576ca5 | 323 | { |
eb22f2a6 | 324 | if (m_tools.GetCount() == 0) |
0b7a8cd3 GD |
325 | return FALSE; |
326 | ||
bfe9ffbc SC |
327 | int x = m_xMargin + kwxMacToolBarLeftMargin ; |
328 | int y = m_yMargin + kwxMacToolBarTopMargin ; | |
0b7a8cd3 | 329 | |
7c551d95 SC |
330 | int tw, th; |
331 | GetSize(& tw, & th); | |
895f5af7 SC |
332 | |
333 | int maxWidth = 0 ; | |
334 | int maxHeight = 0 ; | |
335 | ||
bfe9ffbc SC |
336 | int maxToolWidth = 0; |
337 | int maxToolHeight = 0; | |
338 | ||
339 | // Find the maximum tool width and height | |
affd2611 | 340 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
bfe9ffbc SC |
341 | while ( node ) |
342 | { | |
343 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
344 | wxSize sz = tool->GetSize() ; | |
345 | ||
346 | if ( sz.x > maxToolWidth ) | |
347 | maxToolWidth = sz.x ; | |
348 | if (sz.y> maxToolHeight) | |
349 | maxToolHeight = sz.y; | |
350 | ||
351 | node = node->GetNext(); | |
352 | } | |
353 | ||
214b9484 | 354 | bool lastWasRadio = FALSE; |
bfe9ffbc | 355 | node = m_tools.GetFirst(); |
0b7a8cd3 | 356 | while (node) |
7810c95b | 357 | { |
eb22f2a6 | 358 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); |
bfe9ffbc | 359 | wxSize cursize = tool->GetSize() ; |
0b7a8cd3 | 360 | |
214b9484 RD |
361 | bool isRadio = FALSE; |
362 | ||
363 | if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO ) | |
364 | { | |
365 | if ( !lastWasRadio ) | |
366 | { | |
367 | if (tool->Toggle(true)) | |
368 | { | |
369 | DoToggleTool(tool, true); | |
370 | } | |
371 | } | |
372 | isRadio = TRUE; | |
373 | } | |
374 | else | |
375 | { | |
376 | isRadio = FALSE; | |
377 | } | |
378 | lastWasRadio = isRadio; | |
379 | ||
bfe9ffbc SC |
380 | // for the moment we just do a single row/column alignement |
381 | if ( x + cursize.x > maxWidth ) | |
382 | maxWidth = x + cursize.x ; | |
383 | if ( y + cursize.y > maxHeight ) | |
384 | maxHeight = y + cursize.y ; | |
0b7a8cd3 | 385 | |
bfe9ffbc SC |
386 | tool->SetPosition( wxPoint( x , y ) ) ; |
387 | ||
388 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) | |
389 | { | |
390 | y += cursize.y ; | |
0b7a8cd3 GD |
391 | } |
392 | else | |
393 | { | |
bfe9ffbc | 394 | x += cursize.x ; |
0b7a8cd3 | 395 | } |
bfe9ffbc | 396 | |
eb22f2a6 | 397 | node = node->GetNext(); |
7810c95b | 398 | } |
0b7a8cd3 GD |
399 | |
400 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
7810c95b | 401 | { |
0b7a8cd3 GD |
402 | if ( m_maxRows == 0 ) |
403 | { | |
404 | // if not set yet, only one row | |
405 | SetRows(1); | |
406 | } | |
90d3f91a | 407 | m_minWidth = maxWidth; |
0b7a8cd3 | 408 | maxWidth = tw ; |
0b7a8cd3 | 409 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; |
90d3f91a | 410 | m_minHeight = m_maxHeight = maxHeight ; |
7810c95b | 411 | } |
0b7a8cd3 GD |
412 | else |
413 | { | |
bfe9ffbc | 414 | if ( GetToolsCount() > 0 && m_maxRows == 0 ) |
0b7a8cd3 GD |
415 | { |
416 | // if not set yet, have one column | |
bfe9ffbc | 417 | SetRows(GetToolsCount()); |
0b7a8cd3 | 418 | } |
90d3f91a | 419 | m_minHeight = maxHeight; |
0b7a8cd3 | 420 | maxHeight = th ; |
0b7a8cd3 | 421 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; |
90d3f91a | 422 | m_minWidth = m_maxWidth = maxWidth ; |
0b7a8cd3 GD |
423 | } |
424 | ||
facd6764 | 425 | SetSize( maxWidth, maxHeight ); |
9f884528 | 426 | InvalidateBestSize(); |
0b7a8cd3 GD |
427 | |
428 | return TRUE; | |
e9576ca5 SC |
429 | } |
430 | ||
431 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
432 | { | |
9aad97fd | 433 | m_defaultWidth = size.x+4; m_defaultHeight = size.y+4; |
e9576ca5 SC |
434 | } |
435 | ||
e9576ca5 SC |
436 | // The button size is bigger than the bitmap size |
437 | wxSize wxToolBar::GetToolSize() const | |
438 | { | |
2f1ae414 | 439 | return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); |
e9576ca5 SC |
440 | } |
441 | ||
37e2cb08 | 442 | void wxToolBar::SetRows(int nRows) |
e9576ca5 | 443 | { |
37e2cb08 | 444 | if ( nRows == m_maxRows ) |
e9576ca5 | 445 | { |
37e2cb08 SC |
446 | // avoid resizing the frame uselessly |
447 | return; | |
e9576ca5 | 448 | } |
37e2cb08 SC |
449 | |
450 | m_maxRows = nRows; | |
e9576ca5 SC |
451 | } |
452 | ||
c257d44d SC |
453 | void wxToolBar::MacSuperChangedPosition() |
454 | { | |
c257d44d | 455 | wxWindow::MacSuperChangedPosition() ; |
bfe9ffbc | 456 | Realize() ; |
c257d44d SC |
457 | } |
458 | ||
37e2cb08 | 459 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
e9576ca5 | 460 | { |
affd2611 | 461 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
bfe9ffbc | 462 | while (node) |
e044f600 | 463 | { |
bfe9ffbc SC |
464 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ; |
465 | wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ; | |
466 | if ( r.Contains( wxPoint( x , y ) ) ) | |
e044f600 | 467 | { |
bfe9ffbc | 468 | return tool; |
e044f600 | 469 | } |
bfe9ffbc SC |
470 | |
471 | node = node->GetNext(); | |
e044f600 | 472 | } |
37e2cb08 SC |
473 | |
474 | return (wxToolBarToolBase *)NULL; | |
e9576ca5 SC |
475 | } |
476 | ||
2f1ae414 SC |
477 | wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) |
478 | { | |
e044f600 RR |
479 | wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; |
480 | if ( tool ) | |
481 | { | |
482 | return tool->GetShortHelp() ; | |
483 | } | |
427ff662 | 484 | return wxEmptyString ; |
2f1ae414 SC |
485 | } |
486 | ||
37e2cb08 | 487 | void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) |
e9576ca5 | 488 | { |
a2fe01c9 | 489 | ((wxToolBarTool*)t)->DoEnable( enable ) ; |
e9576ca5 SC |
490 | } |
491 | ||
37e2cb08 | 492 | void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) |
e9576ca5 | 493 | { |
e044f600 | 494 | wxToolBarTool *tool = (wxToolBarTool *)t; |
bfe9ffbc SC |
495 | if ( tool->IsButton() ) |
496 | { | |
facd6764 | 497 | ::SetControl32BitValue( (ControlRef) tool->GetControlHandle() , toggle ) ; |
bfe9ffbc | 498 | } |
37e2cb08 | 499 | } |
7c551d95 | 500 | |
37e2cb08 SC |
501 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), |
502 | wxToolBarToolBase *tool) | |
503 | { | |
bfe9ffbc | 504 | // nothing special to do here - we relayout in Realize() later |
37e2cb08 | 505 | tool->Attach(this); |
9f884528 | 506 | InvalidateBestSize(); |
7c551d95 | 507 | |
37e2cb08 SC |
508 | return TRUE; |
509 | } | |
e9576ca5 | 510 | |
5115c51a | 511 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
37e2cb08 | 512 | { |
5115c51a | 513 | wxFAIL_MSG( _T("not implemented") ); |
e9576ca5 SC |
514 | } |
515 | ||
bfe9ffbc | 516 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
37e2cb08 | 517 | { |
affd2611 | 518 | wxToolBarToolsList::compatibility_iterator node; |
bfe9ffbc SC |
519 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
520 | { | |
521 | wxToolBarToolBase *tool2 = node->GetData(); | |
522 | if ( tool2 == tool ) | |
523 | { | |
524 | // let node point to the next node in the list | |
525 | node = node->GetNext(); | |
526 | ||
527 | break; | |
528 | } | |
529 | } | |
530 | ||
531 | wxSize sz = ((wxToolBarTool*)tool)->GetSize() ; | |
532 | ||
533 | tool->Detach(); | |
534 | ||
535 | // and finally reposition all the controls after this one | |
536 | ||
537 | for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) | |
538 | { | |
539 | wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); | |
540 | wxPoint pt = tool2->GetPosition() ; | |
541 | ||
542 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) | |
543 | { | |
544 | pt.y -= sz.y ; | |
545 | } | |
546 | else | |
547 | { | |
548 | pt.x -= sz.x ; | |
549 | } | |
550 | tool2->SetPosition( pt ) ; | |
551 | } | |
552 | ||
9f884528 | 553 | InvalidateBestSize(); |
5115c51a | 554 | return TRUE ; |
37e2cb08 | 555 | } |
2f1ae414 SC |
556 | |
557 | void wxToolBar::OnPaint(wxPaintEvent& event) | |
558 | { | |
e40298d5 | 559 | wxPaintDC dc(this) ; |
20b69855 SC |
560 | #if wxMAC_USE_CORE_GRAPHICS |
561 | #else | |
e40298d5 | 562 | wxMacPortSetter helper(&dc) ; |
facd6764 SC |
563 | int w, h ; |
564 | GetSize( &w , &h ) ; | |
e40298d5 | 565 | |
1fd1922a | 566 | Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , |
facd6764 SC |
567 | dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ; |
568 | /* | |
569 | if( toolbarrect.left < 0 ) | |
570 | toolbarrect.left = 0 ; | |
571 | if ( toolbarrect.top < 0 ) | |
572 | toolbarrect.top = 0 ; | |
573 | */ | |
01ffa8f7 SC |
574 | if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() ) |
575 | { | |
576 | UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
577 | } | |
578 | else | |
579 | { | |
580 | #if TARGET_API_MAC_OSX | |
581 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
20b69855 SC |
582 | if ( UMAGetSystemVersion() >= 0x1030 ) |
583 | { | |
584 | HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , | |
585 | dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) ); | |
586 | CGContextRef cgContext ; | |
587 | Rect bounds ; | |
588 | GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ; | |
589 | QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
590 | CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; | |
591 | CGContextScaleCTM( cgContext , 1 , -1 ) ; | |
785f5eaa | 592 | |
20b69855 SC |
593 | { |
594 | HIThemeBackgroundDrawInfo drawInfo ; | |
595 | drawInfo.version = 0 ; | |
596 | drawInfo.state = kThemeStateActive ; | |
597 | drawInfo.kind = kThemeBackgroundMetal ; | |
598 | HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ; | |
599 | } | |
600 | QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
601 | } | |
602 | else | |
603 | #endif | |
01ffa8f7 | 604 | { |
20b69855 | 605 | UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
01ffa8f7 | 606 | } |
01ffa8f7 | 607 | #endif |
01ffa8f7 SC |
608 | } |
609 | #endif | |
20b69855 | 610 | |
facd6764 | 611 | event.Skip() ; |
2f1ae414 | 612 | } |
895f5af7 | 613 | |
519cb848 SC |
614 | #endif // wxUSE_TOOLBAR |
615 |