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