]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3b6a1179 | 2 | // Name: src/mac/carbon/toolbar.cpp |
e9576ca5 | 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 |
991f71dc | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #include "wx/wxprec.h" |
519cb848 SC |
13 | |
14 | #if wxUSE_TOOLBAR | |
15 | ||
e56d2520 | 16 | #include "wx/toolbar.h" |
e9576ca5 | 17 | |
4e3e485b WS |
18 | #ifndef WX_PRECOMP |
19 | #include "wx/wx.h" | |
20 | #endif | |
21 | ||
d497dca4 | 22 | #include "wx/mac/uma.h" |
bfe9ffbc | 23 | #include "wx/geometry.h" |
ee799df7 | 24 | |
991f71dc | 25 | |
ee799df7 | 26 | #ifdef __WXMAC_OSX__ |
3b6a1179 DS |
27 | const short kwxMacToolBarToolDefaultWidth = 16; |
28 | const short kwxMacToolBarToolDefaultHeight = 16; | |
29 | const short kwxMacToolBarTopMargin = 4; | |
30 | const short kwxMacToolBarLeftMargin = 4; | |
31 | const short kwxMacToolBorder = 0; | |
32 | const short kwxMacToolSpacing = 6; | |
ee799df7 | 33 | #else |
3b6a1179 DS |
34 | const short kwxMacToolBarToolDefaultWidth = 24; |
35 | const short kwxMacToolBarToolDefaultHeight = 22; | |
36 | const short kwxMacToolBarTopMargin = 2; | |
37 | const short kwxMacToolBarLeftMargin = 2; | |
38 | const short kwxMacToolBorder = 4; | |
39 | const short kwxMacToolSpacing = 0; | |
ee799df7 SC |
40 | #endif |
41 | ||
991f71dc DS |
42 | |
43 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) | |
44 | ||
45 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) | |
46 | EVT_PAINT( wxToolBar::OnPaint ) | |
47 | END_EVENT_TABLE() | |
48 | ||
49 | ||
e56d2520 SC |
50 | #pragma mark - |
51 | #pragma mark Tool Implementation | |
52 | ||
53 | ||
37e2cb08 SC |
54 | // ---------------------------------------------------------------------------- |
55 | // private classes | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
e56d2520 SC |
58 | // We have a dual implementation for each tool, ControlRef and HIToolbarItemRef |
59 | ||
37e2cb08 SC |
60 | class wxToolBarTool : public wxToolBarToolBase |
61 | { | |
62 | public: | |
3025abca DS |
63 | wxToolBarTool( |
64 | wxToolBar *tbar, | |
65 | int id, | |
66 | const wxString& label, | |
67 | const wxBitmap& bmpNormal, | |
68 | const wxBitmap& bmpDisabled, | |
69 | wxItemKind kind, | |
70 | wxObject *clientData, | |
71 | const wxString& shortHelp, | |
72 | const wxString& longHelp ); | |
f3a65c3e | 73 | |
37e2cb08 SC |
74 | wxToolBarTool(wxToolBar *tbar, wxControl *control) |
75 | : wxToolBarToolBase(tbar, control) | |
76 | { | |
3b6a1179 | 77 | Init(); |
e56d2520 | 78 | if (control != NULL) |
3b6a1179 | 79 | SetControlHandle( (ControlRef) control->GetHandle() ); |
37e2cb08 | 80 | } |
f3a65c3e | 81 | |
bfe9ffbc SC |
82 | ~wxToolBarTool() |
83 | { | |
3b6a1179 | 84 | ClearControl(); |
991f71dc | 85 | |
e56d2520 SC |
86 | #if wxMAC_USE_NATIVE_TOOLBAR |
87 | if ( m_toolbarItemRef ) | |
3b6a1179 | 88 | CFRelease( m_toolbarItemRef ); |
e56d2520 | 89 | #endif |
bfe9ffbc | 90 | } |
f3a65c3e VZ |
91 | |
92 | WXWidget GetControlHandle() | |
93 | { | |
3b6a1179 | 94 | return (WXWidget) m_controlHandle; |
e56d2520 | 95 | } |
f3a65c3e VZ |
96 | |
97 | void SetControlHandle( ControlRef handle ) | |
98 | { | |
3b6a1179 | 99 | m_controlHandle = handle; |
e56d2520 | 100 | } |
37e2cb08 | 101 | |
3b6a1179 | 102 | void SetPosition( const wxPoint& position ); |
f3a65c3e VZ |
103 | |
104 | void ClearControl() | |
105 | { | |
3b6a1179 | 106 | m_control = NULL; |
8c07d8b3 SC |
107 | if ( m_controlHandle ) |
108 | { | |
109 | DisposeControl( m_controlHandle ); | |
110 | m_controlHandle = NULL ; | |
111 | } | |
991f71dc | 112 | |
e56d2520 | 113 | #if wxMAC_USE_NATIVE_TOOLBAR |
3b6a1179 | 114 | m_toolbarItemRef = NULL; |
f3a65c3e | 115 | #endif |
e56d2520 | 116 | } |
f3a65c3e | 117 | |
bfe9ffbc SC |
118 | wxSize GetSize() const |
119 | { | |
3025abca DS |
120 | wxSize curSize; |
121 | ||
bfe9ffbc SC |
122 | if ( IsControl() ) |
123 | { | |
3025abca | 124 | curSize = GetControl()->GetSize(); |
bfe9ffbc SC |
125 | } |
126 | else if ( IsButton() ) | |
127 | { | |
3025abca | 128 | curSize = GetToolBar()->GetToolSize(); |
bfe9ffbc SC |
129 | } |
130 | else | |
131 | { | |
abbcdf3f | 132 | // separator size |
3025abca | 133 | curSize = GetToolBar()->GetToolSize(); |
5a904a32 | 134 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
3025abca | 135 | curSize.y /= 4; |
5a904a32 | 136 | else |
3025abca | 137 | curSize.x /= 4; |
bfe9ffbc | 138 | } |
3025abca DS |
139 | |
140 | return curSize; | |
bfe9ffbc | 141 | } |
991f71dc | 142 | |
bfe9ffbc SC |
143 | wxPoint GetPosition() const |
144 | { | |
3b6a1179 | 145 | return wxPoint( m_x, m_y ); |
f3a65c3e | 146 | } |
991f71dc | 147 | |
3b6a1179 | 148 | bool DoEnable( bool enable ); |
f3a65c3e | 149 | |
3b6a1179 | 150 | void UpdateToggleImage( bool toggle ); |
f3a65c3e VZ |
151 | |
152 | #if wxMAC_USE_NATIVE_TOOLBAR | |
153 | void SetToolbarItemRef( HIToolbarItemRef ref ) | |
154 | { | |
e56d2520 | 155 | if ( m_controlHandle ) |
3b6a1179 | 156 | HideControl( m_controlHandle ); |
e56d2520 | 157 | if ( m_toolbarItemRef ) |
3b6a1179 | 158 | CFRelease( m_toolbarItemRef ); |
991f71dc | 159 | |
3b6a1179 | 160 | m_toolbarItemRef = ref; |
e56d2520 SC |
161 | if ( m_toolbarItemRef ) |
162 | { | |
163 | HIToolbarItemSetHelpText( | |
991f71dc | 164 | m_toolbarItemRef, |
3b6a1179 DS |
165 | wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ), |
166 | wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) ); | |
e56d2520 SC |
167 | } |
168 | } | |
991f71dc | 169 | |
f3a65c3e VZ |
170 | HIToolbarItemRef GetToolbarItemRef() const |
171 | { | |
3b6a1179 | 172 | return m_toolbarItemRef; |
e56d2520 | 173 | } |
df7998fc VZ |
174 | |
175 | void SetIndex( CFIndex idx ) | |
2c1dbc95 | 176 | { |
3b6a1179 | 177 | m_index = idx; |
2c1dbc95 SC |
178 | } |
179 | ||
df7998fc | 180 | CFIndex GetIndex() const |
2c1dbc95 | 181 | { |
3b6a1179 | 182 | return m_index; |
2c1dbc95 | 183 | } |
e56d2520 | 184 | #endif |
5d0bf05a | 185 | |
3b6a1179 | 186 | private: |
f3a65c3e | 187 | void Init() |
bfe9ffbc | 188 | { |
3b6a1179 | 189 | m_controlHandle = NULL; |
991f71dc | 190 | |
e56d2520 | 191 | #if wxMAC_USE_NATIVE_TOOLBAR |
3b6a1179 DS |
192 | m_toolbarItemRef = NULL; |
193 | m_index = -1; | |
e56d2520 | 194 | #endif |
bfe9ffbc | 195 | } |
991f71dc | 196 | |
3b6a1179 | 197 | ControlRef m_controlHandle; |
991f71dc DS |
198 | wxCoord m_x; |
199 | wxCoord m_y; | |
200 | ||
e56d2520 | 201 | #if wxMAC_USE_NATIVE_TOOLBAR |
3b6a1179 | 202 | HIToolbarItemRef m_toolbarItemRef; |
2c1dbc95 | 203 | // position in its toolbar, -1 means not inserted |
3b6a1179 | 204 | CFIndex m_index; |
e56d2520 | 205 | #endif |
37e2cb08 SC |
206 | }; |
207 | ||
facd6764 SC |
208 | static const EventTypeSpec eventList[] = |
209 | { | |
3b6a1179 | 210 | { kEventClassControl, kEventControlHit }, |
73fd9428 | 211 | #ifdef __WXMAC_OSX__ |
3b6a1179 | 212 | { kEventClassControl, kEventControlHitTest }, |
73fd9428 | 213 | #endif |
3b6a1179 | 214 | }; |
facd6764 | 215 | |
3b6a1179 | 216 | static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler, EventRef event, void *data ) |
facd6764 | 217 | { |
3b6a1179 DS |
218 | OSStatus result = eventNotHandledErr; |
219 | ControlRef controlRef; | |
220 | wxMacCarbonEvent cEvent( event ); | |
facd6764 | 221 | |
3b6a1179 | 222 | cEvent.GetParameter( kEventParamDirectObject, &controlRef ); |
facd6764 | 223 | |
991f71dc | 224 | switch ( GetEventKind( event ) ) |
facd6764 | 225 | { |
3b6a1179 | 226 | case kEventControlHit: |
facd6764 | 227 | { |
3b6a1179 DS |
228 | wxToolBarTool *tbartool = (wxToolBarTool*)data; |
229 | wxToolBar *tbar = tbartool != NULL ? (wxToolBar*) (tbartool->GetToolBar()) : NULL; | |
991f71dc | 230 | if ((tbartool != NULL) && tbartool->CanBeToggled()) |
facd6764 | 231 | { |
e56d2520 | 232 | bool shouldToggle; |
991f71dc | 233 | |
64f553a4 | 234 | #ifdef __WXMAC_OSX__ |
e56d2520 | 235 | shouldToggle = !tbartool->IsToggled(); |
64f553a4 | 236 | #else |
3025abca | 237 | shouldToggle = (GetControl32BitValue( (ControlRef)(tbartool->GetControlHandle()) ) != 0); |
64f553a4 | 238 | #endif |
991f71dc | 239 | |
e56d2520 | 240 | tbar->ToggleTool( tbartool->GetId(), shouldToggle ); |
facd6764 | 241 | } |
991f71dc | 242 | |
e56d2520 SC |
243 | if (tbartool != NULL) |
244 | tbar->OnLeftClick( tbartool->GetId(), tbartool->IsToggled() ); | |
f3a65c3e | 245 | result = noErr; |
facd6764 | 246 | } |
3b6a1179 | 247 | break; |
5d0bf05a | 248 | |
73fd9428 | 249 | #ifdef __WXMAC_OSX__ |
3b6a1179 | 250 | case kEventControlHitTest: |
73fd9428 | 251 | { |
3b6a1179 DS |
252 | HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation); |
253 | HIRect rect; | |
254 | HIViewGetBounds( controlRef, &rect ); | |
255 | ||
256 | ControlPartCode pc = kControlNoPart; | |
257 | if ( CGRectContainsPoint( rect, pt ) ) | |
258 | pc = kControlIconPart; | |
259 | cEvent.SetParameter( kEventParamControlPart, typeControlPartCode, pc ); | |
260 | result = noErr; | |
73fd9428 | 261 | } |
3b6a1179 | 262 | break; |
73fd9428 | 263 | #endif |
5d0bf05a | 264 | |
3b6a1179 DS |
265 | default: |
266 | break; | |
facd6764 | 267 | } |
991f71dc | 268 | |
3b6a1179 | 269 | return result; |
facd6764 SC |
270 | } |
271 | ||
3b6a1179 | 272 | static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler, EventRef event, void *data ) |
facd6764 | 273 | { |
3b6a1179 | 274 | OSStatus result = eventNotHandledErr; |
facd6764 SC |
275 | |
276 | switch ( GetEventClass( event ) ) | |
277 | { | |
3b6a1179 DS |
278 | case kEventClassControl: |
279 | result = wxMacToolBarToolControlEventHandler( handler, event, data ); | |
280 | break; | |
5d0bf05a | 281 | |
3b6a1179 DS |
282 | default: |
283 | break; | |
facd6764 | 284 | } |
991f71dc | 285 | |
3b6a1179 | 286 | return result; |
facd6764 SC |
287 | } |
288 | ||
289 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler ) | |
290 | ||
e56d2520 SC |
291 | #if wxMAC_USE_NATIVE_TOOLBAR |
292 | ||
e56d2520 SC |
293 | static const EventTypeSpec toolBarEventList[] = |
294 | { | |
3b6a1179 DS |
295 | { kEventClassToolbarItem, kEventToolbarItemPerformAction }, |
296 | }; | |
e56d2520 | 297 | |
3b6a1179 | 298 | static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler, EventRef event, void *data ) |
e56d2520 | 299 | { |
3b6a1179 | 300 | OSStatus result = eventNotHandledErr; |
f3a65c3e | 301 | |
991f71dc | 302 | switch ( GetEventKind( event ) ) |
e56d2520 | 303 | { |
3b6a1179 | 304 | case kEventToolbarItemPerformAction: |
e56d2520 | 305 | { |
3b6a1179 | 306 | wxToolBarTool* tbartool = (wxToolBarTool*) data; |
e56d2520 SC |
307 | if ( tbartool != NULL ) |
308 | { | |
991f71dc DS |
309 | wxToolBar *tbar = (wxToolBar*)(tbartool->GetToolBar()); |
310 | int toolID = tbartool->GetId(); | |
311 | ||
e56d2520 SC |
312 | if ( tbartool->CanBeToggled() ) |
313 | { | |
3025abca | 314 | if ( tbar != NULL ) |
2c1dbc95 | 315 | tbar->ToggleTool(toolID, !tbartool->IsToggled() ); |
e56d2520 | 316 | } |
991f71dc | 317 | |
3025abca | 318 | if ( tbar != NULL ) |
3b6a1179 | 319 | tbar->OnLeftClick( toolID, tbartool->IsToggled() ); |
f3a65c3e | 320 | result = noErr; |
e56d2520 SC |
321 | } |
322 | } | |
3b6a1179 | 323 | break; |
5d0bf05a | 324 | |
3b6a1179 DS |
325 | default: |
326 | break; | |
e56d2520 | 327 | } |
991f71dc | 328 | |
3b6a1179 | 329 | return result; |
e56d2520 SC |
330 | } |
331 | ||
332 | static pascal OSStatus wxMacToolBarEventHandler( EventHandlerCallRef handler, EventRef event, void *data ) | |
333 | { | |
3b6a1179 | 334 | OSStatus result = eventNotHandledErr; |
991f71dc DS |
335 | |
336 | switch ( GetEventClass( event ) ) | |
e56d2520 | 337 | { |
3b6a1179 DS |
338 | case kEventClassToolbarItem: |
339 | result = wxMacToolBarCommandEventHandler( handler, event, data ); | |
340 | break; | |
5d0bf05a | 341 | |
3b6a1179 DS |
342 | default: |
343 | break; | |
e56d2520 | 344 | } |
991f71dc | 345 | |
3b6a1179 | 346 | return result; |
e56d2520 SC |
347 | } |
348 | ||
349 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler ) | |
350 | ||
351 | #endif | |
352 | ||
3b6a1179 | 353 | bool wxToolBarTool::DoEnable( bool enable ) |
a2fe01c9 SC |
354 | { |
355 | if ( IsControl() ) | |
356 | { | |
3b6a1179 | 357 | GetControl()->Enable( enable ); |
a2fe01c9 SC |
358 | } |
359 | else if ( IsButton() ) | |
360 | { | |
f3a65c3e | 361 | #if wxMAC_USE_NATIVE_TOOLBAR |
3025abca | 362 | if ( m_toolbarItemRef != NULL ) |
3b6a1179 | 363 | HIToolbarItemSetEnabled( m_toolbarItemRef, enable ); |
e56d2520 SC |
364 | #endif |
365 | ||
3025abca | 366 | if ( m_controlHandle != NULL ) |
e56d2520 | 367 | { |
a2fe01c9 | 368 | #if TARGET_API_MAC_OSX |
e56d2520 | 369 | if ( enable ) |
3b6a1179 | 370 | EnableControl( m_controlHandle ); |
e56d2520 | 371 | else |
3b6a1179 | 372 | DisableControl( m_controlHandle ); |
a2fe01c9 | 373 | #else |
e56d2520 | 374 | if ( enable ) |
3b6a1179 | 375 | ActivateControl( m_controlHandle ); |
e56d2520 | 376 | else |
3b6a1179 | 377 | DeactivateControl( m_controlHandle ); |
a2fe01c9 | 378 | #endif |
e56d2520 | 379 | } |
a2fe01c9 | 380 | } |
991f71dc | 381 | |
3b6a1179 | 382 | return true; |
a2fe01c9 | 383 | } |
bfe9ffbc | 384 | |
3b6a1179 | 385 | void wxToolBarTool::SetPosition( const wxPoint& position ) |
bfe9ffbc SC |
386 | { |
387 | m_x = position.x; | |
388 | m_y = position.y; | |
389 | ||
3b6a1179 DS |
390 | int x, y; |
391 | x = y = 0; | |
392 | int mac_x = position.x; | |
393 | int mac_y = position.y; | |
789ae0cf | 394 | |
789ae0cf SC |
395 | if ( IsButton() ) |
396 | { | |
3b6a1179 DS |
397 | Rect contrlRect; |
398 | GetControlBounds( m_controlHandle, &contrlRect ); | |
399 | int former_mac_x = contrlRect.left; | |
400 | int former_mac_y = contrlRect.top; | |
401 | GetToolBar()->GetToolSize(); | |
f3a65c3e | 402 | |
bfe9ffbc SC |
403 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) |
404 | { | |
3b6a1179 | 405 | UMAMoveControl( m_controlHandle, mac_x, mac_y ); |
bfe9ffbc SC |
406 | } |
407 | } | |
408 | else if ( IsControl() ) | |
409 | { | |
3b6a1179 | 410 | GetControl()->Move( position ); |
bfe9ffbc | 411 | } |
abbcdf3f SC |
412 | else |
413 | { | |
f3a65c3e | 414 | // separator |
abbcdf3f | 415 | #ifdef __WXMAC_OSX__ |
3b6a1179 DS |
416 | Rect contrlRect; |
417 | GetControlBounds( m_controlHandle, &contrlRect ); | |
418 | int former_mac_x = contrlRect.left; | |
419 | int former_mac_y = contrlRect.top; | |
f3a65c3e | 420 | |
abbcdf3f | 421 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) |
3b6a1179 | 422 | UMAMoveControl( m_controlHandle, mac_x, mac_y ); |
abbcdf3f SC |
423 | #endif |
424 | } | |
bfe9ffbc SC |
425 | } |
426 | ||
f3a65c3e | 427 | void wxToolBarTool::UpdateToggleImage( bool toggle ) |
73fd9428 | 428 | { |
f3a65c3e | 429 | #if wxMAC_USE_NATIVE_TOOLBAR |
e56d2520 SC |
430 | |
431 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4 | |
3025abca | 432 | #define kHIToolbarItemSelected (1 << 7) |
e56d2520 SC |
433 | #endif |
434 | ||
435 | // FIXME: this should be a OSX v10.4 runtime check | |
436 | if (m_toolbarItemRef != NULL) | |
437 | { | |
438 | OptionBits addAttrs, removeAttrs; | |
439 | OSStatus result; | |
440 | ||
441 | if (toggle) | |
442 | { | |
443 | addAttrs = kHIToolbarItemSelected; | |
444 | removeAttrs = kHIToolbarItemNoAttributes; | |
445 | } | |
446 | else | |
447 | { | |
448 | addAttrs = kHIToolbarItemNoAttributes; | |
449 | removeAttrs = kHIToolbarItemSelected; | |
450 | } | |
451 | ||
452 | result = HIToolbarItemChangeAttributes( m_toolbarItemRef, addAttrs, removeAttrs ); | |
453 | } | |
454 | #endif | |
5d0bf05a | 455 | |
73fd9428 SC |
456 | #ifdef __WXMAC_OSX__ |
457 | if ( toggle ) | |
458 | { | |
3b6a1179 DS |
459 | int w = m_bmpNormal.GetWidth(); |
460 | int h = m_bmpNormal.GetHeight(); | |
461 | wxBitmap bmp( w, h ); | |
462 | wxMemoryDC dc; | |
463 | ||
464 | dc.SelectObject( bmp ); | |
465 | dc.SetPen( wxNullPen ); | |
466 | dc.SetBackground( *wxWHITE ); | |
467 | dc.DrawRectangle( 0, 0, w, h ); | |
468 | dc.DrawBitmap( m_bmpNormal, 0, 0, true ); | |
469 | dc.SelectObject( wxNullBitmap ); | |
470 | ControlButtonContentInfo info; | |
471 | wxMacCreateBitmapButton( &info, bmp ); | |
991f71dc | 472 | SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); |
3b6a1179 | 473 | wxMacReleaseBitmapButton( &info ); |
73fd9428 SC |
474 | } |
475 | else | |
476 | { | |
3b6a1179 DS |
477 | ControlButtonContentInfo info; |
478 | wxMacCreateBitmapButton( &info, m_bmpNormal ); | |
3025abca | 479 | SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info ); |
3b6a1179 | 480 | wxMacReleaseBitmapButton( &info ); |
73fd9428 SC |
481 | } |
482 | ||
3b6a1179 DS |
483 | IconTransformType transform = toggle ? kTransformSelected : kTransformNone; |
484 | SetControlData( | |
485 | m_controlHandle, 0, kControlIconTransformTag, | |
3025abca | 486 | sizeof(transform), (Ptr)&transform ); |
3b6a1179 | 487 | HIViewSetNeedsDisplay( m_controlHandle, true ); |
73fd9428 SC |
488 | |
489 | #else | |
3b6a1179 | 490 | ::SetControl32BitValue( m_controlHandle, toggle ); |
73fd9428 SC |
491 | #endif |
492 | } | |
493 | ||
3b6a1179 DS |
494 | wxToolBarTool::wxToolBarTool( |
495 | wxToolBar *tbar, | |
496 | int id, | |
497 | const wxString& label, | |
498 | const wxBitmap& bmpNormal, | |
499 | const wxBitmap& bmpDisabled, | |
500 | wxItemKind kind, | |
501 | wxObject *clientData, | |
502 | const wxString& shortHelp, | |
503 | const wxString& longHelp ) | |
504 | : | |
505 | wxToolBarToolBase( | |
506 | tbar, id, label, bmpNormal, bmpDisabled, kind, | |
507 | clientData, shortHelp, longHelp ) | |
bfe9ffbc | 508 | { |
f4e0be4f | 509 | Init(); |
bfe9ffbc SC |
510 | } |
511 | ||
e56d2520 SC |
512 | #pragma mark - |
513 | #pragma mark Toolbar Implementation | |
2f1ae414 | 514 | |
3b6a1179 DS |
515 | wxToolBarToolBase *wxToolBar::CreateTool( |
516 | int id, | |
517 | const wxString& label, | |
518 | const wxBitmap& bmpNormal, | |
519 | const wxBitmap& bmpDisabled, | |
520 | wxItemKind kind, | |
521 | wxObject *clientData, | |
522 | const wxString& shortHelp, | |
523 | const wxString& longHelp ) | |
37e2cb08 | 524 | { |
3b6a1179 DS |
525 | return new wxToolBarTool( |
526 | this, id, label, bmpNormal, bmpDisabled, kind, | |
527 | clientData, shortHelp, longHelp ); | |
37e2cb08 SC |
528 | } |
529 | ||
3b6a1179 | 530 | wxToolBarToolBase * wxToolBar::CreateTool( wxControl *control ) |
37e2cb08 | 531 | { |
3025abca | 532 | return new wxToolBarTool( this, control ); |
37e2cb08 SC |
533 | } |
534 | ||
37e2cb08 | 535 | void wxToolBar::Init() |
e9576ca5 | 536 | { |
e40298d5 JS |
537 | m_maxWidth = -1; |
538 | m_maxHeight = -1; | |
539 | m_defaultWidth = kwxMacToolBarToolDefaultWidth; | |
540 | m_defaultHeight = kwxMacToolBarToolDefaultHeight; | |
991f71dc | 541 | |
e56d2520 | 542 | #if wxMAC_USE_NATIVE_TOOLBAR |
3b6a1179 DS |
543 | m_macHIToolbarRef = NULL; |
544 | m_macUsesNativeToolbar = false; | |
e56d2520 | 545 | #endif |
e9576ca5 SC |
546 | } |
547 | ||
e56d2520 SC |
548 | // also for the toolbar we have the dual implementation: |
549 | // only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar | |
550 | // | |
3b6a1179 DS |
551 | bool wxToolBar::Create( |
552 | wxWindow *parent, | |
991f71dc DS |
553 | wxWindowID id, |
554 | const wxPoint& pos, | |
555 | const wxSize& size, | |
556 | long style, | |
3b6a1179 | 557 | const wxString& name ) |
5d0bf05a | 558 | { |
3b6a1179 DS |
559 | if ( !wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) |
560 | return false; | |
e56d2520 | 561 | |
991f71dc | 562 | OSStatus err = noErr; |
e56d2520 SC |
563 | |
564 | #if wxMAC_USE_NATIVE_TOOLBAR | |
3b6a1179 DS |
565 | wxString labelStr = wxString::Format( wxT("%xd"), (int)this ); |
566 | err = HIToolbarCreate( | |
567 | wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ), 0, | |
568 | (HIToolbarRef*) &m_macHIToolbarRef ); | |
e56d2520 SC |
569 | |
570 | if (m_macHIToolbarRef != NULL) | |
f3a65c3e | 571 | { |
3b6a1179 DS |
572 | HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; |
573 | HIToolbarDisplaySize displaySize = kHIToolbarDisplaySizeSmall; | |
e56d2520 SC |
574 | |
575 | if ( style & wxTB_NOICONS ) | |
3b6a1179 | 576 | mode = kHIToolbarDisplayModeLabelOnly; |
e56d2520 | 577 | else if ( style & wxTB_TEXT ) |
3b6a1179 | 578 | mode = kHIToolbarDisplayModeIconAndLabel; |
e56d2520 | 579 | else |
3b6a1179 | 580 | mode = kHIToolbarDisplayModeIconOnly; |
e56d2520 | 581 | |
3b6a1179 DS |
582 | HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); |
583 | HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize ); | |
e56d2520 SC |
584 | } |
585 | #endif | |
586 | ||
991f71dc | 587 | return (err == noErr); |
e9576ca5 SC |
588 | } |
589 | ||
590 | wxToolBar::~wxToolBar() | |
f3a65c3e | 591 | { |
e56d2520 | 592 | #if wxMAC_USE_NATIVE_TOOLBAR |
3025abca | 593 | if (m_macHIToolbarRef != NULL) |
e56d2520 SC |
594 | { |
595 | // if this is the installed toolbar, then deinstall it | |
596 | if (m_macUsesNativeToolbar) | |
597 | MacInstallNativeToolbar( false ); | |
598 | ||
3025abca | 599 | CFRelease( (HIToolbarRef)m_macHIToolbarRef ); |
e56d2520 SC |
600 | m_macHIToolbarRef = NULL; |
601 | } | |
602 | #endif | |
603 | } | |
604 | ||
e56d2520 SC |
605 | bool wxToolBar::Show( bool show ) |
606 | { | |
e56d2520 | 607 | WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); |
3025abca | 608 | bool bResult = (tlw != NULL); |
f3a65c3e | 609 | |
e56d2520 SC |
610 | if (bResult) |
611 | { | |
612 | #if wxMAC_USE_NATIVE_TOOLBAR | |
f3a65c3e | 613 | bool ownToolbarInstalled = false; |
e56d2520 SC |
614 | MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); |
615 | if (ownToolbarInstalled) | |
616 | { | |
3025abca | 617 | bResult = (IsWindowToolbarVisible( tlw ) != show); |
a749a99f SC |
618 | if ( bResult ) |
619 | ShowHideWindowToolbar( tlw, show, false ); | |
e56d2520 SC |
620 | } |
621 | else | |
e56d2520 | 622 | bResult = wxToolBarBase::Show( show ); |
3025abca DS |
623 | #else |
624 | ||
625 | bResult = wxToolBarBase::Show( show ); | |
626 | #endif | |
e56d2520 | 627 | } |
f3a65c3e | 628 | |
e56d2520 SC |
629 | return bResult; |
630 | } | |
631 | ||
632 | bool wxToolBar::IsShown() const | |
633 | { | |
634 | bool bResult; | |
635 | ||
636 | #if wxMAC_USE_NATIVE_TOOLBAR | |
3b6a1179 | 637 | bool ownToolbarInstalled; |
3025abca | 638 | |
e56d2520 SC |
639 | MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); |
640 | if (ownToolbarInstalled) | |
a749a99f SC |
641 | { |
642 | WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); | |
3b6a1179 | 643 | bResult = IsWindowToolbarVisible( tlw ); |
a749a99f | 644 | } |
e56d2520 | 645 | else |
e56d2520 | 646 | bResult = wxToolBarBase::IsShown(); |
3025abca DS |
647 | #else |
648 | ||
649 | bResult = wxToolBarBase::IsShown(); | |
650 | #endif | |
f3a65c3e | 651 | |
e56d2520 SC |
652 | return bResult; |
653 | } | |
654 | ||
e56d2520 SC |
655 | void wxToolBar::DoGetSize( int *width, int *height ) const |
656 | { | |
657 | #if wxMAC_USE_NATIVE_TOOLBAR | |
658 | Rect boundsR; | |
659 | bool ownToolbarInstalled; | |
f3a65c3e | 660 | |
e56d2520 SC |
661 | MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); |
662 | if ( ownToolbarInstalled ) | |
663 | { | |
991f71dc | 664 | // TODO: is this really a control ? |
e56d2520 SC |
665 | GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR ); |
666 | if ( width != NULL ) | |
667 | *width = boundsR.right - boundsR.left; | |
668 | if ( height != NULL ) | |
669 | *height = boundsR.bottom - boundsR.top; | |
670 | } | |
671 | else | |
e56d2520 | 672 | wxToolBarBase::DoGetSize( width, height ); |
3025abca DS |
673 | |
674 | #else | |
675 | wxToolBarBase::DoGetSize( width, height ); | |
676 | #endif | |
e9576ca5 SC |
677 | } |
678 | ||
b13095df SC |
679 | wxSize wxToolBar::DoGetBestSize() const |
680 | { | |
3b6a1179 | 681 | int width, height; |
991f71dc | 682 | |
3b6a1179 | 683 | DoGetSize( &width, &height ); |
991f71dc | 684 | |
3b6a1179 | 685 | return wxSize( width, height ); |
b13095df SC |
686 | } |
687 | ||
f3a65c3e | 688 | void wxToolBar::SetWindowStyleFlag( long style ) |
e56d2520 SC |
689 | { |
690 | wxToolBarBase::SetWindowStyleFlag( style ); | |
991f71dc | 691 | |
e56d2520 SC |
692 | #if wxMAC_USE_NATIVE_TOOLBAR |
693 | if (m_macHIToolbarRef != NULL) | |
694 | { | |
695 | HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; | |
696 | ||
697 | if ( style & wxTB_NOICONS ) | |
698 | mode = kHIToolbarDisplayModeLabelOnly; | |
699 | else if ( style & wxTB_TEXT ) | |
700 | mode = kHIToolbarDisplayModeIconAndLabel; | |
701 | else | |
702 | mode = kHIToolbarDisplayModeIconOnly; | |
f3a65c3e | 703 | |
e56d2520 SC |
704 | HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); |
705 | } | |
706 | #endif | |
707 | } | |
708 | ||
709 | #if wxMAC_USE_NATIVE_TOOLBAR | |
710 | bool wxToolBar::MacWantsNativeToolbar() | |
711 | { | |
712 | return m_macUsesNativeToolbar; | |
713 | } | |
714 | ||
715 | bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const | |
716 | { | |
717 | bool bResultV = false; | |
718 | ||
719 | if (ownToolbarInstalled != NULL) | |
720 | *ownToolbarInstalled = false; | |
721 | ||
722 | WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); | |
723 | if (tlw != NULL) | |
724 | { | |
725 | HIToolbarRef curToolbarRef = NULL; | |
726 | OSStatus err = GetWindowToolbar( tlw, &curToolbarRef ); | |
3025abca | 727 | bResultV = ((err == noErr) && (curToolbarRef != NULL)); |
e56d2520 SC |
728 | if (bResultV && (ownToolbarInstalled != NULL)) |
729 | *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef); | |
730 | } | |
731 | ||
732 | return bResultV; | |
733 | } | |
734 | ||
f3a65c3e | 735 | bool wxToolBar::MacInstallNativeToolbar(bool usesNative) |
e56d2520 | 736 | { |
df7998fc | 737 | bool bResult = false; |
e56d2520 | 738 | |
e56d2520 SC |
739 | if (usesNative && (m_macHIToolbarRef == NULL)) |
740 | return bResult; | |
f3a65c3e | 741 | |
e56d2520 SC |
742 | if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0)) |
743 | return bResult; | |
f3a65c3e | 744 | |
3025abca DS |
745 | WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); |
746 | if (tlw == NULL) | |
747 | return bResult; | |
748 | ||
e56d2520 SC |
749 | // check the existing toolbar |
750 | HIToolbarRef curToolbarRef = NULL; | |
751 | OSStatus err = GetWindowToolbar( tlw, &curToolbarRef ); | |
991f71dc | 752 | if (err != noErr) |
e56d2520 SC |
753 | curToolbarRef = NULL; |
754 | ||
755 | m_macUsesNativeToolbar = usesNative; | |
756 | ||
757 | if (m_macUsesNativeToolbar) | |
758 | { | |
759 | // only install toolbar if there isn't one installed already | |
760 | if (curToolbarRef == NULL) | |
761 | { | |
762 | bResult = true; | |
763 | ||
764 | SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef ); | |
765 | ShowHideWindowToolbar( tlw, true, false ); | |
766 | ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 ); | |
767 | SetAutomaticControlDragTrackingEnabledForWindow( tlw, true ); | |
f3a65c3e | 768 | |
3b6a1179 | 769 | Rect r = { 0, 0, 0, 0 }; |
e56d2520 | 770 | m_peer->SetRect( &r ); |
e56d2520 | 771 | SetSize( wxSIZE_AUTO_WIDTH, 0 ); |
e56d2520 SC |
772 | m_peer->SetVisibility( false, true ); |
773 | wxToolBarBase::Show( false ); | |
774 | } | |
775 | } | |
776 | else | |
777 | { | |
778 | // only deinstall toolbar if this is the installed one | |
779 | if (m_macHIToolbarRef == curToolbarRef) | |
780 | { | |
781 | bResult = true; | |
782 | ||
783 | ShowHideWindowToolbar( tlw, false, false ); | |
3b6a1179 | 784 | ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute ); |
e56d2520 | 785 | SetWindowToolbar( tlw, NULL ); |
f3a65c3e | 786 | |
e56d2520 | 787 | m_peer->SetVisibility( true, true ); |
e56d2520 SC |
788 | } |
789 | } | |
790 | ||
791 | if (bResult) | |
792 | InvalidateBestSize(); | |
793 | ||
794 | // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") ); | |
795 | return bResult; | |
796 | } | |
797 | #endif | |
798 | ||
37e2cb08 | 799 | bool wxToolBar::Realize() |
e9576ca5 | 800 | { |
eb22f2a6 | 801 | if (m_tools.GetCount() == 0) |
3803c372 | 802 | return false; |
0b7a8cd3 | 803 | |
e56d2520 SC |
804 | int maxWidth = 0; |
805 | int maxHeight = 0; | |
f3a65c3e | 806 | |
bfe9ffbc SC |
807 | int maxToolWidth = 0; |
808 | int maxToolHeight = 0; | |
f3a65c3e | 809 | |
991f71dc DS |
810 | int x = m_xMargin + kwxMacToolBarLeftMargin; |
811 | int y = m_yMargin + kwxMacToolBarTopMargin; | |
812 | ||
813 | int tw, th; | |
814 | GetSize( &tw, &th ); | |
815 | ||
e56d2520 | 816 | // find the maximum tool width and height |
3025abca DS |
817 | wxToolBarTool *tool; |
818 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); | |
e56d2520 | 819 | while ( node != NULL ) |
bfe9ffbc | 820 | { |
3025abca | 821 | tool = (wxToolBarTool *) node->GetData(); |
e56d2520 SC |
822 | if ( tool != NULL ) |
823 | { | |
824 | wxSize sz = tool->GetSize(); | |
f3a65c3e | 825 | |
e56d2520 SC |
826 | if ( sz.x > maxToolWidth ) |
827 | maxToolWidth = sz.x; | |
828 | if ( sz.y > maxToolHeight ) | |
829 | maxToolHeight = sz.y; | |
830 | } | |
f3a65c3e | 831 | |
bfe9ffbc SC |
832 | node = node->GetNext(); |
833 | } | |
f3a65c3e | 834 | |
991f71dc DS |
835 | bool lastIsRadio = false; |
836 | bool curIsRadio = false; | |
837 | bool setChoiceInGroup = false; | |
df7998fc VZ |
838 | |
839 | #if wxMAC_USE_NATIVE_TOOLBAR | |
3b6a1179 DS |
840 | CFIndex currentPosition = 0; |
841 | bool insertAll = false; | |
991f71dc | 842 | #endif |
df7998fc | 843 | |
991f71dc | 844 | node = m_tools.GetFirst(); |
e56d2520 | 845 | while ( node != NULL ) |
7810c95b | 846 | { |
3025abca | 847 | tool = (wxToolBarTool*) node->GetData(); |
e56d2520 | 848 | if ( tool == NULL ) |
214b9484 | 849 | { |
e56d2520 SC |
850 | node = node->GetNext(); |
851 | continue; | |
214b9484 | 852 | } |
f3a65c3e | 853 | |
991f71dc | 854 | // set tool position: |
e56d2520 SC |
855 | // for the moment just perform a single row/column alignment |
856 | wxSize cursize = tool->GetSize(); | |
bfe9ffbc | 857 | if ( x + cursize.x > maxWidth ) |
e56d2520 | 858 | maxWidth = x + cursize.x; |
bfe9ffbc | 859 | if ( y + cursize.y > maxHeight ) |
e56d2520 | 860 | maxHeight = y + cursize.y; |
f3a65c3e | 861 | |
73fd9428 SC |
862 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) |
863 | { | |
e56d2520 SC |
864 | int x1 = x + ( maxToolWidth - cursize.x ) / 2; |
865 | tool->SetPosition( wxPoint(x1, y) ); | |
73fd9428 SC |
866 | } |
867 | else | |
868 | { | |
e56d2520 SC |
869 | int y1 = y + ( maxToolHeight - cursize.y ) / 2; |
870 | tool->SetPosition( wxPoint(x, y1) ); | |
871 | } | |
f3a65c3e | 872 | |
e56d2520 | 873 | // update the item positioning state |
bfe9ffbc | 874 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) |
e56d2520 SC |
875 | y += cursize.y + kwxMacToolSpacing; |
876 | else | |
877 | x += cursize.x + kwxMacToolSpacing; | |
f3a65c3e | 878 | |
e56d2520 SC |
879 | #if wxMAC_USE_NATIVE_TOOLBAR |
880 | // install in native HIToolbar | |
881 | if ( m_macHIToolbarRef != NULL ) | |
bfe9ffbc | 882 | { |
e56d2520 SC |
883 | HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef(); |
884 | if ( hiItemRef != NULL ) | |
885 | { | |
991f71dc | 886 | if ( insertAll || (tool->GetIndex() != currentPosition) ) |
e56d2520 | 887 | { |
dcae64c2 | 888 | OSStatus err = noErr; |
8138cfec SC |
889 | if ( !insertAll ) |
890 | { | |
dcae64c2 DS |
891 | insertAll = true; |
892 | ||
8138cfec SC |
893 | // if this is the first tool that gets newly inserted or repositioned |
894 | // first remove all 'old' tools from here to the right, because of this | |
895 | // all following tools will have to be reinserted (insertAll). i = 100 because there's | |
896 | // no way to determine how many there are in a toolbar, so just a high number :-( | |
3b6a1179 | 897 | for ( CFIndex i = 100; i >= currentPosition; --i ) |
8138cfec | 898 | { |
dcae64c2 | 899 | err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, i ); |
8138cfec | 900 | } |
991f71dc | 901 | |
dcae64c2 DS |
902 | if (err != noErr) |
903 | { | |
904 | wxString errMsg = wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err ); | |
4362c705 | 905 | wxFAIL_MSG( errMsg.c_str() ); |
dcae64c2 DS |
906 | } |
907 | } | |
991f71dc | 908 | |
dcae64c2 DS |
909 | err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef, currentPosition ); |
910 | if (err != noErr) | |
911 | { | |
912 | wxString errMsg = wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err ); | |
4362c705 | 913 | wxFAIL_MSG( errMsg.c_str() ); |
dcae64c2 | 914 | } |
3b6a1179 | 915 | |
dcae64c2 | 916 | tool->SetIndex( currentPosition ); |
e56d2520 | 917 | } |
991f71dc | 918 | |
dcae64c2 | 919 | currentPosition++; |
e56d2520 SC |
920 | } |
921 | } | |
dcae64c2 | 922 | #endif |
f3a65c3e | 923 | |
e56d2520 SC |
924 | // update radio button (and group) state |
925 | lastIsRadio = curIsRadio; | |
926 | curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) ); | |
f3a65c3e | 927 | |
e56d2520 SC |
928 | if ( !curIsRadio ) |
929 | { | |
930 | if ( tool->IsToggled() ) | |
931 | DoToggleTool( tool, true ); | |
f3a65c3e | 932 | |
e56d2520 | 933 | setChoiceInGroup = false; |
0b7a8cd3 GD |
934 | } |
935 | else | |
936 | { | |
e56d2520 SC |
937 | if ( !lastIsRadio ) |
938 | { | |
dcae64c2 | 939 | if ( tool->Toggle( true ) ) |
e56d2520 SC |
940 | { |
941 | DoToggleTool( tool, true ); | |
942 | setChoiceInGroup = true; | |
943 | } | |
944 | } | |
945 | else if ( tool->IsToggled() ) | |
946 | { | |
947 | if ( tool->IsToggled() ) | |
948 | DoToggleTool( tool, true ); | |
f3a65c3e | 949 | |
e56d2520 SC |
950 | wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious(); |
951 | while ( nodePrev != NULL ) | |
952 | { | |
953 | wxToolBarToolBase *toggleTool = nodePrev->GetData(); | |
954 | if ( (toggleTool == NULL) || !toggleTool->IsButton() || (toggleTool->GetKind() != wxITEM_RADIO) ) | |
955 | break; | |
f3a65c3e | 956 | |
dcae64c2 | 957 | if ( toggleTool->Toggle( false ) ) |
e56d2520 | 958 | DoToggleTool( toggleTool, false ); |
f3a65c3e | 959 | |
e56d2520 SC |
960 | nodePrev = nodePrev->GetPrevious(); |
961 | } | |
962 | } | |
0b7a8cd3 | 963 | } |
f3a65c3e | 964 | |
eb22f2a6 | 965 | node = node->GetNext(); |
7810c95b | 966 | } |
f3a65c3e | 967 | |
0b7a8cd3 | 968 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) |
7810c95b | 969 | { |
e56d2520 SC |
970 | // if not set yet, only one row |
971 | if ( m_maxRows <= 0 ) | |
972 | SetRows( 1 ); | |
f3a65c3e | 973 | |
90d3f91a | 974 | m_minWidth = maxWidth; |
e56d2520 | 975 | maxWidth = tw; |
0b7a8cd3 | 976 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; |
e56d2520 | 977 | m_minHeight = m_maxHeight = maxHeight; |
7810c95b | 978 | } |
0b7a8cd3 GD |
979 | else |
980 | { | |
e56d2520 SC |
981 | // if not set yet, have one column |
982 | if ( (GetToolsCount() > 0) && (m_maxRows <= 0) ) | |
983 | SetRows( GetToolsCount() ); | |
f3a65c3e | 984 | |
90d3f91a | 985 | m_minHeight = maxHeight; |
e56d2520 | 986 | maxHeight = th; |
0b7a8cd3 | 987 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; |
e56d2520 | 988 | m_minWidth = m_maxWidth = maxWidth; |
0b7a8cd3 | 989 | } |
e56d2520 | 990 | |
f3a65c3e | 991 | #if 0 |
e56d2520 SC |
992 | // FIXME: should this be OSX-only? |
993 | { | |
994 | bool wantNativeToolbar, ownToolbarInstalled; | |
995 | ||
996 | // attempt to install the native toolbar | |
997 | wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0); | |
998 | MacInstallNativeToolbar( wantNativeToolbar ); | |
999 | (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); | |
1000 | if (!ownToolbarInstalled) | |
1001 | { | |
1002 | SetSize( maxWidth, maxHeight ); | |
1003 | InvalidateBestSize(); | |
1004 | } | |
1005 | } | |
f3a65c3e | 1006 | #else |
facd6764 | 1007 | SetSize( maxWidth, maxHeight ); |
9f884528 | 1008 | InvalidateBestSize(); |
e56d2520 | 1009 | #endif |
2c1dbc95 SC |
1010 | |
1011 | SetBestFittingSize(); | |
1012 | ||
3803c372 | 1013 | return true; |
e9576ca5 SC |
1014 | } |
1015 | ||
1016 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
1017 | { | |
e56d2520 SC |
1018 | m_defaultWidth = size.x + kwxMacToolBorder; |
1019 | m_defaultHeight = size.y + kwxMacToolBorder; | |
f3a65c3e | 1020 | |
e56d2520 SC |
1021 | #if wxMAC_USE_NATIVE_TOOLBAR |
1022 | if (m_macHIToolbarRef != NULL) | |
1023 | { | |
1024 | int maxs = wxMax( size.x, size.y ); | |
3b6a1179 | 1025 | HIToolbarDisplaySize sizeSpec; |
328f4fee | 1026 | if ( maxs > 32 ) |
3b6a1179 | 1027 | sizeSpec = kHIToolbarDisplaySizeNormal; |
00a7bd85 | 1028 | else if ( maxs > 24 ) |
3b6a1179 | 1029 | sizeSpec = kHIToolbarDisplaySizeDefault; |
328f4fee | 1030 | else |
3b6a1179 | 1031 | sizeSpec = kHIToolbarDisplaySizeSmall; |
f3a65c3e | 1032 | |
e56d2520 SC |
1033 | HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec ); |
1034 | } | |
1035 | #endif | |
e9576ca5 SC |
1036 | } |
1037 | ||
e9576ca5 SC |
1038 | // The button size is bigger than the bitmap size |
1039 | wxSize wxToolBar::GetToolSize() const | |
1040 | { | |
ee799df7 | 1041 | return wxSize(m_defaultWidth + kwxMacToolBorder, m_defaultHeight + kwxMacToolBorder); |
e9576ca5 SC |
1042 | } |
1043 | ||
37e2cb08 | 1044 | void wxToolBar::SetRows(int nRows) |
e9576ca5 | 1045 | { |
e56d2520 SC |
1046 | // avoid resizing the frame uselessly |
1047 | if ( nRows != m_maxRows ) | |
e56d2520 | 1048 | m_maxRows = nRows; |
e9576ca5 SC |
1049 | } |
1050 | ||
f3a65c3e | 1051 | void wxToolBar::MacSuperChangedPosition() |
c257d44d | 1052 | { |
e56d2520 | 1053 | wxWindow::MacSuperChangedPosition(); |
991f71dc | 1054 | |
e56d2520 SC |
1055 | #if wxMAC_USE_NATIVE_TOOLBAR |
1056 | if (! m_macUsesNativeToolbar ) | |
e56d2520 | 1057 | Realize(); |
991f71dc | 1058 | #else |
3025abca | 1059 | |
991f71dc DS |
1060 | Realize(); |
1061 | #endif | |
c257d44d SC |
1062 | } |
1063 | ||
37e2cb08 | 1064 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
e9576ca5 | 1065 | { |
3025abca | 1066 | wxToolBarTool *tool; |
affd2611 | 1067 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
e56d2520 | 1068 | while ( node != NULL ) |
e044f600 | 1069 | { |
3025abca | 1070 | tool = (wxToolBarTool *)node->GetData(); |
e56d2520 | 1071 | if (tool != NULL) |
e044f600 | 1072 | { |
e56d2520 SC |
1073 | wxRect2DInt r( tool->GetPosition(), tool->GetSize() ); |
1074 | if ( r.Contains( wxPoint( x, y ) ) ) | |
1075 | return tool; | |
e044f600 | 1076 | } |
bfe9ffbc SC |
1077 | |
1078 | node = node->GetNext(); | |
e044f600 | 1079 | } |
37e2cb08 | 1080 | |
3025abca | 1081 | return (wxToolBarToolBase*)NULL; |
e9576ca5 SC |
1082 | } |
1083 | ||
2f1ae414 SC |
1084 | wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) |
1085 | { | |
3b6a1179 | 1086 | wxToolBarToolBase *tool = FindToolForPosition( pt.x, pt.y ); |
e56d2520 | 1087 | if ( tool != NULL ) |
3b6a1179 | 1088 | return tool->GetShortHelp(); |
e56d2520 | 1089 | |
3b6a1179 | 1090 | return wxEmptyString; |
2f1ae414 SC |
1091 | } |
1092 | ||
37e2cb08 | 1093 | void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) |
e9576ca5 | 1094 | { |
e56d2520 | 1095 | if ( t != NULL ) |
3b6a1179 | 1096 | ((wxToolBarTool*)t)->DoEnable( enable ); |
e9576ca5 SC |
1097 | } |
1098 | ||
37e2cb08 | 1099 | void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) |
e9576ca5 | 1100 | { |
e044f600 | 1101 | wxToolBarTool *tool = (wxToolBarTool *)t; |
e56d2520 SC |
1102 | if ( ( tool != NULL ) && tool->IsButton() ) |
1103 | tool->UpdateToggleImage( toggle ); | |
37e2cb08 | 1104 | } |
7c551d95 | 1105 | |
3b6a1179 | 1106 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) |
37e2cb08 | 1107 | { |
3b6a1179 | 1108 | wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase ); |
e56d2520 SC |
1109 | if (tool == NULL) |
1110 | return false; | |
1111 | ||
1112 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef(); | |
1113 | wxSize toolSize = GetToolSize(); | |
3b6a1179 | 1114 | Rect toolrect = { 0, 0, toolSize.y, toolSize.x }; |
e56d2520 SC |
1115 | ControlRef controlHandle = NULL; |
1116 | OSStatus err = 0; | |
be5fe3aa | 1117 | |
e56d2520 | 1118 | switch (tool->GetStyle()) |
be5fe3aa | 1119 | { |
3b6a1179 | 1120 | case wxTOOL_STYLE_SEPARATOR: |
be5fe3aa | 1121 | { |
e56d2520 SC |
1122 | wxASSERT( tool->GetControlHandle() == NULL ); |
1123 | toolSize.x /= 4; | |
1124 | toolSize.y /= 4; | |
be5fe3aa | 1125 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) |
e56d2520 | 1126 | toolrect.bottom = toolSize.y; |
be5fe3aa | 1127 | else |
e56d2520 SC |
1128 | toolrect.right = toolSize.x; |
1129 | ||
991f71dc | 1130 | #ifdef __WXMAC_OSX__ |
be5fe3aa | 1131 | // in flat style we need a visual separator |
991f71dc | 1132 | #if wxMAC_USE_NATIVE_TOOLBAR |
e56d2520 | 1133 | HIToolbarItemRef item; |
991f71dc DS |
1134 | err = HIToolbarItemCreate( |
1135 | kHIToolbarSeparatorIdentifier, | |
1136 | kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates, | |
1137 | &item ); | |
e56d2520 SC |
1138 | if (err == noErr) |
1139 | tool->SetToolbarItemRef( item ); | |
991f71dc DS |
1140 | #endif |
1141 | ||
e56d2520 SC |
1142 | CreateSeparatorControl( window, &toolrect, &controlHandle ); |
1143 | tool->SetControlHandle( controlHandle ); | |
991f71dc | 1144 | #endif |
be5fe3aa | 1145 | } |
e56d2520 SC |
1146 | break; |
1147 | ||
3b6a1179 | 1148 | case wxTOOL_STYLE_BUTTON: |
be5fe3aa | 1149 | { |
3b6a1179 DS |
1150 | wxASSERT( tool->GetControlHandle() == NULL ); |
1151 | ControlButtonContentInfo info; | |
1152 | wxMacCreateBitmapButton( &info, tool->GetNormalBitmap(), kControlContentIconRef ); | |
f3a65c3e | 1153 | |
df7998fc | 1154 | if ( UMAGetSystemVersion() >= 0x1000) |
3b6a1179 DS |
1155 | { |
1156 | CreateIconControl( window, &toolrect, &info, false, &controlHandle ); | |
1157 | } | |
df7998fc VZ |
1158 | else |
1159 | { | |
3b6a1179 | 1160 | SInt16 behaviour = kControlBehaviorOffsetContents; |
df7998fc | 1161 | if ( tool->CanBeToggled() ) |
3b6a1179 DS |
1162 | behaviour |= kControlBehaviorToggles; |
1163 | err = CreateBevelButtonControl( window, | |
1164 | &toolrect, CFSTR(""), kControlBevelButtonNormalBevel, | |
1165 | behaviour, &info, 0, 0, 0, &controlHandle ); | |
df7998fc | 1166 | } |
e56d2520 SC |
1167 | |
1168 | #if wxMAC_USE_NATIVE_TOOLBAR | |
3b6a1179 | 1169 | HIToolbarItemRef item; |
30962327 | 1170 | wxString labelStr = wxString::Format(wxT("%xd"), (int)tool); |
e56d2520 SC |
1171 | err = HIToolbarItemCreate( |
1172 | wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()), | |
1173 | kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item ); | |
1174 | if (err == noErr) | |
1175 | { | |
3025abca DS |
1176 | InstallEventHandler( |
1177 | HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(), | |
1178 | GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL ); | |
e56d2520 SC |
1179 | HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) ); |
1180 | HIToolbarItemSetIconRef( item, info.u.iconRef ); | |
2c1dbc95 | 1181 | HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction ); |
e56d2520 SC |
1182 | tool->SetToolbarItemRef( item ); |
1183 | } | |
991f71dc | 1184 | #endif |
e56d2520 | 1185 | |
3b6a1179 | 1186 | wxMacReleaseBitmapButton( &info ); |
3025abca | 1187 | |
991f71dc | 1188 | #if 0 |
3b6a1179 DS |
1189 | SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic ); |
1190 | UMASetControlTitle( m_controlHandle, label, wxFont::GetDefaultEncoding() ); | |
991f71dc | 1191 | #endif |
f3a65c3e | 1192 | |
3b6a1179 DS |
1193 | InstallControlEventHandler( |
1194 | (ControlRef) controlHandle, GetwxMacToolBarToolEventHandlerUPP(), | |
e56d2520 | 1195 | GetEventTypeCount(eventList), eventList, tool, NULL ); |
be5fe3aa | 1196 | |
e56d2520 | 1197 | tool->SetControlHandle( controlHandle ); |
be5fe3aa | 1198 | } |
e56d2520 SC |
1199 | break; |
1200 | ||
3b6a1179 | 1201 | case wxTOOL_STYLE_CONTROL: |
e56d2520 | 1202 | wxASSERT( tool->GetControl() != NULL ); |
3b6a1179 | 1203 | |
e56d2520 SC |
1204 | #if 0 // wxMAC_USE_NATIVE_TOOLBAR |
1205 | // FIXME: doesn't work yet... | |
1206 | { | |
1207 | HIToolbarItemRef item; | |
3b6a1179 DS |
1208 | wxString labelStr = wxString::Format( wxT("%xd"), (int)tool ); |
1209 | result = HIToolbarItemCreate( | |
1210 | wxMacCFStringHolder( labelStr, wxFont::GetDefaultEncoding() ), | |
1211 | kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, | |
1212 | &item ); | |
1213 | if ( result == noErr ) | |
e56d2520 | 1214 | { |
3b6a1179 | 1215 | HIToolbarItemSetLabel( item, wxMacCFStringHolder( tool->GetLabel(), m_font.GetEncoding() ) ); |
e56d2520 SC |
1216 | HIToolbarItemSetCommandID( item, tool->GetId() ); |
1217 | tool->SetToolbarItemRef( item ); | |
f3a65c3e | 1218 | |
e56d2520 SC |
1219 | controlHandle = ( ControlRef ) tool->GetControlHandle(); |
1220 | wxASSERT_MSG( controlHandle != NULL, wxT("NULL tool control") ); | |
f3a65c3e | 1221 | |
e56d2520 SC |
1222 | // FIXME: is this necessary ?? |
1223 | ::GetControlBounds( controlHandle, &toolrect ); | |
1224 | UMAMoveControl( controlHandle, -toolrect.left, -toolrect.top ); | |
f3a65c3e | 1225 | |
e56d2520 | 1226 | // FIXME: is this necessary ?? |
3b6a1179 DS |
1227 | InstallControlEventHandler( |
1228 | controlHandle, GetwxMacToolBarToolEventHandlerUPP(), | |
1229 | GetEventTypeCount(eventList), eventList, tool, NULL ); | |
e56d2520 SC |
1230 | } |
1231 | } | |
f3a65c3e | 1232 | |
e56d2520 SC |
1233 | #else |
1234 | // FIXME: right now there's nothing to do here | |
1235 | #endif | |
1236 | break; | |
1237 | ||
3b6a1179 | 1238 | default: |
e56d2520 | 1239 | break; |
be5fe3aa | 1240 | } |
f3a65c3e | 1241 | |
991f71dc | 1242 | if ( err == noErr ) |
be5fe3aa | 1243 | { |
e56d2520 SC |
1244 | if ( controlHandle ) |
1245 | { | |
1246 | ControlRef container = (ControlRef) GetHandle(); | |
3b6a1179 | 1247 | wxASSERT_MSG( container != NULL, wxT("No valid Mac container control") ); |
be5fe3aa | 1248 | |
e56d2520 SC |
1249 | UMAShowControl( controlHandle ); |
1250 | ::EmbedControl( controlHandle, container ); | |
1251 | } | |
1252 | ||
1253 | if ( tool->CanBeToggled() && tool->IsToggled() ) | |
1254 | tool->UpdateToggleImage( true ); | |
be5fe3aa | 1255 | |
e56d2520 | 1256 | // nothing special to do here - we relayout in Realize() later |
3b6a1179 | 1257 | tool->Attach( this ); |
e56d2520 SC |
1258 | InvalidateBestSize(); |
1259 | } | |
1260 | else | |
be5fe3aa | 1261 | { |
3b6a1179 | 1262 | wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err ); |
4362c705 | 1263 | wxFAIL_MSG( errMsg.c_str() ); |
be5fe3aa | 1264 | } |
f3a65c3e | 1265 | |
991f71dc | 1266 | return (err == noErr); |
37e2cb08 | 1267 | } |
e9576ca5 | 1268 | |
5115c51a | 1269 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
37e2cb08 | 1270 | { |
3b6a1179 | 1271 | wxFAIL_MSG( wxT("not implemented") ); |
e9576ca5 SC |
1272 | } |
1273 | ||
be5fe3aa | 1274 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) |
37e2cb08 | 1275 | { |
3b6a1179 | 1276 | wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase ); |
affd2611 | 1277 | wxToolBarToolsList::compatibility_iterator node; |
bfe9ffbc SC |
1278 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
1279 | { | |
1280 | wxToolBarToolBase *tool2 = node->GetData(); | |
1281 | if ( tool2 == tool ) | |
1282 | { | |
1283 | // let node point to the next node in the list | |
1284 | node = node->GetNext(); | |
1285 | ||
1286 | break; | |
1287 | } | |
1288 | } | |
1289 | ||
3b6a1179 | 1290 | wxSize sz = ((wxToolBarTool*)tool)->GetSize(); |
bfe9ffbc SC |
1291 | |
1292 | tool->Detach(); | |
df7998fc VZ |
1293 | |
1294 | #if wxMAC_USE_NATIVE_TOOLBAR | |
1295 | CFIndex removeIndex = tool->GetIndex(); | |
dcae64c2 | 1296 | #endif |
bfe9ffbc | 1297 | |
488b2c29 SC |
1298 | switch ( tool->GetStyle() ) |
1299 | { | |
1300 | case wxTOOL_STYLE_CONTROL: | |
be5fe3aa SC |
1301 | { |
1302 | tool->GetControl()->Destroy(); | |
3b6a1179 | 1303 | tool->ClearControl(); |
be5fe3aa | 1304 | } |
488b2c29 SC |
1305 | break; |
1306 | ||
1307 | case wxTOOL_STYLE_BUTTON: | |
1308 | case wxTOOL_STYLE_SEPARATOR: | |
be5fe3aa | 1309 | if ( tool->GetControlHandle() ) |
488b2c29 | 1310 | { |
e56d2520 | 1311 | #if wxMAC_USE_NATIVE_TOOLBAR |
df7998fc | 1312 | if ( removeIndex != -1 && m_macHIToolbarRef ) |
2c1dbc95 | 1313 | { |
3b6a1179 DS |
1314 | HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex ); |
1315 | tool->SetIndex( -1 ); | |
2c1dbc95 | 1316 | } |
991f71dc DS |
1317 | #endif |
1318 | ||
3b6a1179 | 1319 | tool->ClearControl(); |
488b2c29 SC |
1320 | } |
1321 | break; | |
e56d2520 SC |
1322 | |
1323 | default: | |
1324 | break; | |
488b2c29 SC |
1325 | } |
1326 | ||
bfe9ffbc | 1327 | // and finally reposition all the controls after this one |
f3a65c3e | 1328 | |
3b6a1179 | 1329 | for ( /* node -> first after deleted */; node; node = node->GetNext() ) |
bfe9ffbc SC |
1330 | { |
1331 | wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); | |
3b6a1179 | 1332 | wxPoint pt = tool2->GetPosition(); |
bfe9ffbc SC |
1333 | |
1334 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) | |
3b6a1179 | 1335 | pt.y -= sz.y; |
bfe9ffbc | 1336 | else |
3b6a1179 | 1337 | pt.x -= sz.x; |
e56d2520 | 1338 | |
3b6a1179 | 1339 | tool2->SetPosition( pt ); |
df7998fc | 1340 | |
2c1dbc95 SC |
1341 | #if wxMAC_USE_NATIVE_TOOLBAR |
1342 | if ( removeIndex != -1 && tool2->GetIndex() > removeIndex ) | |
3b6a1179 | 1343 | tool2->SetIndex( tool2->GetIndex() - 1 ); |
2c1dbc95 | 1344 | #endif |
bfe9ffbc | 1345 | } |
f3a65c3e | 1346 | |
9f884528 | 1347 | InvalidateBestSize(); |
991f71dc | 1348 | |
3b6a1179 | 1349 | return true; |
37e2cb08 | 1350 | } |
2f1ae414 SC |
1351 | |
1352 | void wxToolBar::OnPaint(wxPaintEvent& event) | |
1353 | { | |
e56d2520 SC |
1354 | #if wxMAC_USE_NATIVE_TOOLBAR |
1355 | if ( m_macUsesNativeToolbar ) | |
1356 | { | |
dcae64c2 DS |
1357 | event.Skip(true); |
1358 | return; | |
e56d2520 SC |
1359 | } |
1360 | #endif | |
f3a65c3e | 1361 | |
3b6a1179 | 1362 | wxPaintDC dc(this); |
ddc548ec | 1363 | |
3b6a1179 DS |
1364 | int w, h; |
1365 | GetSize( &w, &h ); | |
991f71dc | 1366 | |
dcae64c2 DS |
1367 | bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance(); |
1368 | bool minimumUmaAvailable = (UMAGetSystemVersion() >= 0x1030); | |
1369 | ||
ddc548ec | 1370 | #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
dcae64c2 | 1371 | if ( !drawMetalTheme && minimumUmaAvailable ) |
ddc548ec | 1372 | { |
dcae64c2 DS |
1373 | HIThemePlacardDrawInfo info; |
1374 | memset( &info, 0, sizeof(info) ); | |
1375 | info.version = 0; | |
1376 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive; | |
1377 | ||
1378 | CGContextRef cgContext = (CGContextRef) MacGetCGContextRef(); | |
1379 | HIRect rect = CGRectMake( 0, 0, w, h ); | |
1380 | HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal ); | |
ddc548ec SC |
1381 | } |
1382 | else | |
1383 | { | |
1384 | // leave the background as it is (striped or metal) | |
1385 | } | |
991f71dc | 1386 | |
ddc548ec | 1387 | #else |
dcae64c2 DS |
1388 | |
1389 | const bool drawBorder = true; | |
1390 | ||
1391 | if (drawBorder) | |
01ffa8f7 | 1392 | { |
3b6a1179 | 1393 | wxMacPortSetter helper( &dc ); |
dcae64c2 DS |
1394 | |
1395 | if ( !drawMetalTheme || !minimumUmaAvailable ) | |
20b69855 | 1396 | { |
3b6a1179 DS |
1397 | Rect toolbarrect = { dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0), |
1398 | dc.YLOG2DEVMAC(h), dc.XLOG2DEVMAC(w) }; | |
dcae64c2 DS |
1399 | |
1400 | #if 0 | |
1401 | if ( toolbarrect.left < 0 ) | |
3b6a1179 | 1402 | toolbarrect.left = 0; |
dcae64c2 | 1403 | if ( toolbarrect.top < 0 ) |
3b6a1179 | 1404 | toolbarrect.top = 0; |
dcae64c2 DS |
1405 | #endif |
1406 | ||
1407 | UMADrawThemePlacard( &toolbarrect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ); | |
1408 | } | |
1409 | else | |
1410 | { | |
1411 | #if TARGET_API_MAC_OSX | |
991f71dc | 1412 | HIRect hiToolbarrect = CGRectMake( |
3b6a1179 DS |
1413 | dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0), |
1414 | dc.YLOG2DEVREL(h), dc.XLOG2DEVREL(w) ); | |
1415 | CGContextRef cgContext; | |
1416 | Rect bounds; | |
dcae64c2 | 1417 | |
3b6a1179 DS |
1418 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); |
1419 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
dcae64c2 | 1420 | |
3b6a1179 DS |
1421 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); |
1422 | CGContextScaleCTM( cgContext, 1, -1 ); | |
785f5eaa | 1423 | |
3b6a1179 DS |
1424 | HIThemeBackgroundDrawInfo drawInfo; |
1425 | drawInfo.version = 0; | |
1426 | drawInfo.state = kThemeStateActive; | |
1427 | drawInfo.kind = kThemeBackgroundMetal; | |
dcae64c2 | 1428 | HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal ); |
e56d2520 | 1429 | |
3b6a1179 | 1430 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); |
20b69855 | 1431 | #endif |
01ffa8f7 | 1432 | } |
01ffa8f7 SC |
1433 | } |
1434 | #endif | |
20b69855 | 1435 | |
dcae64c2 | 1436 | event.Skip(); |
2f1ae414 | 1437 | } |
895f5af7 | 1438 | |
519cb848 | 1439 | #endif // wxUSE_TOOLBAR |