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