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