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