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