]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: toolbar.cpp | |
3 | // Purpose: wxToolBar | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
2f1ae414 | 8 | // Copyright: (c) AUTHORy |
e9576ca5 SC |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "toolbar.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/wx.h" | |
519cb848 SC |
16 | |
17 | #if wxUSE_TOOLBAR | |
18 | ||
e9576ca5 | 19 | #include "wx/toolbar.h" |
2f1ae414 SC |
20 | #include "wx/notebook.h" |
21 | #include "wx/tabctrl.h" | |
72055702 | 22 | #include "wx/bitmap.h" |
e9576ca5 | 23 | |
2f1ae414 | 24 | #if !USE_SHARED_LIBRARY |
12ed316d | 25 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) |
e9576ca5 SC |
26 | |
27 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) | |
e044f600 RR |
28 | EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) |
29 | EVT_PAINT( wxToolBar::OnPaint ) | |
e9576ca5 | 30 | END_EVENT_TABLE() |
2f1ae414 | 31 | #endif |
e9576ca5 | 32 | |
d497dca4 | 33 | #include "wx/mac/uma.h" |
519cb848 | 34 | |
37e2cb08 SC |
35 | // ---------------------------------------------------------------------------- |
36 | // private classes | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | class wxToolBarTool : public wxToolBarToolBase | |
40 | { | |
41 | public: | |
42 | wxToolBarTool(wxToolBar *tbar, | |
43 | int id, | |
27e2d606 GD |
44 | const wxString& label, |
45 | const wxBitmap& bmpNormal, | |
46 | const wxBitmap& bmpDisabled, | |
47 | wxItemKind kind, | |
37e2cb08 | 48 | wxObject *clientData, |
27e2d606 GD |
49 | const wxString& shortHelp, |
50 | const wxString& longHelp) | |
51 | : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind, | |
52 | clientData, shortHelp, longHelp) | |
37e2cb08 SC |
53 | { |
54 | m_nSepCount = 0; | |
2f1ae414 | 55 | m_index = -1 ; |
37e2cb08 SC |
56 | } |
57 | ||
58 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
59 | : wxToolBarToolBase(tbar, control) | |
60 | { | |
61 | m_nSepCount = 1; | |
2f1ae414 | 62 | m_index = -1 ; |
37e2cb08 SC |
63 | } |
64 | ||
65 | // set/get the number of separators which we use to cover the space used by | |
66 | // a control in the toolbar | |
67 | void SetSeparatorsCount(size_t count) { m_nSepCount = count; } | |
68 | size_t GetSeparatorsCount() const { return m_nSepCount; } | |
69 | ||
e044f600 | 70 | int m_index ; |
37e2cb08 SC |
71 | private: |
72 | size_t m_nSepCount; | |
73 | }; | |
74 | ||
75 | ||
76 | // ============================================================================ | |
77 | // implementation | |
78 | // ============================================================================ | |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // wxToolBarTool | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
895f5af7 SC |
84 | const short kwxMacToolBarToolDefaultWidth = 24 ; |
85 | const short kwxMacToolBarToolDefaultHeight = 22 ; | |
86 | const short kwxMacToolBarTopMargin = 2 ; | |
87 | const short kwxMacToolBarLeftMargin = 2 ; | |
88 | ||
2f1ae414 | 89 | |
37e2cb08 | 90 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
27e2d606 GD |
91 | const wxString& label, |
92 | const wxBitmap& bmpNormal, | |
93 | const wxBitmap& bmpDisabled, | |
94 | wxItemKind kind, | |
37e2cb08 | 95 | wxObject *clientData, |
27e2d606 GD |
96 | const wxString& shortHelp, |
97 | const wxString& longHelp) | |
37e2cb08 | 98 | { |
27e2d606 GD |
99 | return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind, |
100 | clientData, shortHelp, longHelp); | |
37e2cb08 SC |
101 | } |
102 | ||
103 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) | |
104 | { | |
105 | return new wxToolBarTool(this, control); | |
106 | } | |
107 | ||
37e2cb08 | 108 | void wxToolBar::Init() |
e9576ca5 SC |
109 | { |
110 | m_maxWidth = -1; | |
111 | m_maxHeight = -1; | |
895f5af7 SC |
112 | m_defaultWidth = kwxMacToolBarToolDefaultWidth; |
113 | m_defaultHeight = kwxMacToolBarToolDefaultHeight; | |
e9576ca5 SC |
114 | } |
115 | ||
116 | bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
117 | long style, const wxString& name) | |
118 | { | |
e9576ca5 | 119 | |
519cb848 SC |
120 | int x = pos.x; |
121 | int y = pos.y; | |
122 | int width = size.x; | |
123 | int height = size.y; | |
e9576ca5 | 124 | |
519cb848 SC |
125 | if (width <= 0) |
126 | width = 100; | |
127 | if (height <= 0) | |
128 | height = 30; | |
129 | if (x < 0) | |
130 | x = 0; | |
131 | if (y < 0) | |
132 | y = 0; | |
e9576ca5 | 133 | |
895f5af7 SC |
134 | SetName(name); |
135 | ||
136 | m_windowStyle = style; | |
137 | parent->AddChild(this); | |
138 | ||
139 | m_backgroundColour = parent->GetBackgroundColour() ; | |
140 | m_foregroundColour = parent->GetForegroundColour() ; | |
141 | ||
142 | if (id == -1) | |
143 | m_windowId = NewControlId(); | |
144 | else | |
145 | m_windowId = id; | |
146 | ||
147 | { | |
e044f600 RR |
148 | m_width = size.x ; |
149 | m_height = size.y ; | |
150 | int x = pos.x ; | |
151 | int y = pos.y ; | |
152 | AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING); | |
153 | m_x = x ; | |
154 | m_y = y ; | |
895f5af7 | 155 | } |
a90c95aa RR |
156 | |
157 | return TRUE; | |
e9576ca5 SC |
158 | } |
159 | ||
160 | wxToolBar::~wxToolBar() | |
161 | { | |
7810c95b SC |
162 | // we must refresh the frame size when the toolbar is deleted but the frame |
163 | // is not - otherwise toolbar leaves a hole in the place it used to occupy | |
e9576ca5 SC |
164 | } |
165 | ||
37e2cb08 | 166 | bool wxToolBar::Realize() |
e9576ca5 | 167 | { |
0b7a8cd3 GD |
168 | if (m_tools.Number() == 0) |
169 | return FALSE; | |
170 | ||
171 | Point localOrigin ; | |
d84afea9 | 172 | // Rect clipRect ; |
76a5e5d2 | 173 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
d84afea9 | 174 | // wxWindow *win ; |
0b7a8cd3 | 175 | |
de043984 SC |
176 | int lx , ly ; |
177 | lx = ly = 0 ; | |
178 | MacWindowToRootWindow( &lx , &ly ) ; | |
179 | localOrigin.v = ly ; | |
180 | localOrigin.h = lx ; | |
181 | ||
182 | // GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; | |
0b7a8cd3 | 183 | |
de043984 SC |
184 | Rect toolbarrect = { localOrigin.v ,localOrigin.h , |
185 | m_height + localOrigin.v , m_width + localOrigin.h} ; | |
0b7a8cd3 GD |
186 | ControlFontStyleRec controlstyle ; |
187 | ||
188 | controlstyle.flags = kControlUseFontMask ; | |
189 | controlstyle.font = kControlFontSmallSystemFont ; | |
190 | ||
191 | wxNode *node = m_tools.First(); | |
192 | int noButtons = 0; | |
193 | int x = 0 ; | |
194 | int y = 0 ; | |
195 | wxSize toolSize = GetToolSize() ; | |
7c551d95 SC |
196 | int tw, th; |
197 | GetSize(& tw, & th); | |
895f5af7 SC |
198 | |
199 | int maxWidth = 0 ; | |
200 | int maxHeight = 0 ; | |
201 | ||
0b7a8cd3 | 202 | while (node) |
7810c95b | 203 | { |
0b7a8cd3 | 204 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); |
0b7a8cd3 GD |
205 | |
206 | if( !tool->IsSeparator() ) | |
207 | { | |
208 | Rect toolrect = { toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin, | |
209 | toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
210 | toolrect.right = toolrect.left + toolSize.x ; | |
211 | toolrect.bottom = toolrect.top + toolSize.y ; | |
212 | ||
213 | ControlButtonContentInfo info ; | |
1b21409b | 214 | wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() ) ; |
0b7a8cd3 GD |
215 | ControlHandle m_macToolHandle ; |
216 | ||
217 | SInt16 behaviour = kControlBehaviorOffsetContents ; | |
218 | if ( tool->CanBeToggled() ) | |
219 | behaviour += kControlBehaviorToggles ; | |
220 | ||
be295828 | 221 | if ( info.contentType != kControlNoContent ) |
0b7a8cd3 GD |
222 | { |
223 | m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , | |
224 | behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
225 | ||
226 | ::SetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
227 | } | |
228 | else | |
229 | { | |
230 | m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , | |
231 | behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
232 | } | |
233 | UMAShowControl( m_macToolHandle ) ; | |
234 | m_macToolHandles.Add( m_macToolHandle ) ; | |
235 | tool->m_index = m_macToolHandles.Count() -1 ; | |
236 | if ( !tool->IsEnabled() ) | |
237 | { | |
238 | UMADeactivateControl( m_macToolHandle ) ; | |
239 | } | |
240 | if ( tool->CanBeToggled() && tool->IsToggled() ) | |
241 | { | |
467e3168 | 242 | ::SetControl32BitValue( m_macToolHandle , 1 ) ; |
0b7a8cd3 GD |
243 | } |
244 | else | |
245 | { | |
467e3168 | 246 | ::SetControl32BitValue( m_macToolHandle , 0 ) ; |
0b7a8cd3 GD |
247 | } |
248 | /* | |
249 | ::SetControlFontStyle( m_macToolHandle , &controlstyle ) ; | |
250 | */ | |
76a5e5d2 | 251 | ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; |
0b7a8cd3 GD |
252 | wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; |
253 | ::EmbedControl( m_macToolHandle , container ) ; | |
254 | ||
1fd1922a | 255 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) |
0b7a8cd3 | 256 | { |
1fd1922a | 257 | y += (int)toolSize.y; |
0b7a8cd3 GD |
258 | } |
259 | else | |
260 | { | |
1fd1922a | 261 | x += (int)toolSize.x; |
0b7a8cd3 GD |
262 | } |
263 | noButtons ++; | |
264 | } | |
265 | else | |
266 | { | |
267 | m_macToolHandles.Add( NULL ) ; | |
1fd1922a RR |
268 | |
269 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) | |
0b7a8cd3 | 270 | { |
1fd1922a | 271 | y += (int)toolSize.y / 4; |
0b7a8cd3 GD |
272 | } |
273 | else | |
274 | { | |
1fd1922a | 275 | x += (int)toolSize.x / 4; |
0b7a8cd3 GD |
276 | } |
277 | } | |
278 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin - m_x - localOrigin.h > maxWidth) { | |
279 | maxWidth = toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin - m_x - localOrigin.h; | |
280 | } | |
281 | if (toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) { | |
282 | maxHeight = toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v ; | |
283 | } | |
284 | node = node->Next(); | |
7810c95b | 285 | } |
0b7a8cd3 GD |
286 | |
287 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
7810c95b | 288 | { |
0b7a8cd3 GD |
289 | if ( m_maxRows == 0 ) |
290 | { | |
291 | // if not set yet, only one row | |
292 | SetRows(1); | |
293 | } | |
294 | maxWidth = tw ; | |
295 | maxHeight += toolSize.y; | |
296 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; | |
297 | m_maxHeight = maxHeight ; | |
7810c95b | 298 | } |
0b7a8cd3 GD |
299 | else |
300 | { | |
301 | if ( noButtons > 0 && m_maxRows == 0 ) | |
302 | { | |
303 | // if not set yet, have one column | |
304 | SetRows(noButtons); | |
305 | } | |
306 | maxHeight = th ; | |
307 | maxWidth += toolSize.x; | |
308 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; | |
309 | m_maxWidth = maxWidth ; | |
310 | } | |
311 | ||
312 | SetSize(maxWidth, maxHeight); | |
313 | ||
314 | return TRUE; | |
e9576ca5 SC |
315 | } |
316 | ||
317 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
318 | { | |
9aad97fd | 319 | m_defaultWidth = size.x+4; m_defaultHeight = size.y+4; |
e9576ca5 SC |
320 | } |
321 | ||
e9576ca5 SC |
322 | // The button size is bigger than the bitmap size |
323 | wxSize wxToolBar::GetToolSize() const | |
324 | { | |
2f1ae414 | 325 | return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); |
e9576ca5 SC |
326 | } |
327 | ||
76a5e5d2 | 328 | void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) |
519cb848 | 329 | { |
7af79c94 | 330 | size_t index = 0 ; |
e044f600 RR |
331 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
332 | { | |
333 | if ( m_macToolHandles[index] == (void*) control ) | |
334 | { | |
335 | wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data(); | |
336 | if ( tool->CanBeToggled() ) | |
337 | { | |
467e3168 | 338 | tool->Toggle( GetControl32BitValue( (ControlHandle) control ) ) ; |
e044f600 RR |
339 | } |
340 | OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; | |
341 | break ; | |
342 | } | |
343 | } | |
519cb848 SC |
344 | } |
345 | ||
37e2cb08 | 346 | void wxToolBar::SetRows(int nRows) |
e9576ca5 | 347 | { |
37e2cb08 | 348 | if ( nRows == m_maxRows ) |
e9576ca5 | 349 | { |
37e2cb08 SC |
350 | // avoid resizing the frame uselessly |
351 | return; | |
e9576ca5 | 352 | } |
37e2cb08 SC |
353 | |
354 | m_maxRows = nRows; | |
e9576ca5 SC |
355 | } |
356 | ||
c257d44d SC |
357 | void wxToolBar::MacSuperChangedPosition() |
358 | { | |
359 | if (m_tools.Number() > 0) | |
360 | { | |
361 | ||
e044f600 | 362 | Point localOrigin ; |
d84afea9 GD |
363 | // Rect clipRect ; |
364 | // WindowRef window ; | |
365 | // wxWindow *win ; | |
de043984 SC |
366 | int lx , ly ; |
367 | lx = ly = 0 ; | |
368 | MacWindowToRootWindow( &lx , &ly ) ; | |
369 | localOrigin.v = ly ; | |
370 | localOrigin.h = lx ; | |
e044f600 | 371 | |
de043984 | 372 | // GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; |
e044f600 | 373 | |
de043984 SC |
374 | Rect toolbarrect = { localOrigin.v ,localOrigin.h , |
375 | m_height + localOrigin.v , m_width + localOrigin.h} ; | |
e044f600 RR |
376 | ControlFontStyleRec controlstyle ; |
377 | ||
378 | controlstyle.flags = kControlUseFontMask ; | |
379 | controlstyle.font = kControlFontSmallSystemFont ; | |
380 | ||
381 | wxNode *node = m_tools.First(); | |
382 | int noButtons = 0; | |
383 | int x = 0 ; | |
384 | wxSize toolSize = GetToolSize() ; | |
c257d44d SC |
385 | int tw, th; |
386 | GetSize(& tw, & th); | |
387 | ||
388 | int maxWidth = 0 ; | |
389 | int maxHeight = 0 ; | |
390 | int toolcount = 0 ; | |
391 | { | |
76a5e5d2 | 392 | WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; |
1fd1922a RR |
393 | while (node) |
394 | { | |
395 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
1fd1922a RR |
396 | |
397 | if( !tool->IsSeparator() ) | |
398 | { | |
399 | Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
400 | toolrect.right = toolrect.left + toolSize.x ; | |
401 | toolrect.bottom = toolrect.top + toolSize.y ; | |
402 | ||
403 | ControlHandle m_macToolHandle = (ControlHandle) m_macToolHandles[toolcount++] ; | |
404 | ||
405 | { | |
406 | Rect contrlRect ; | |
407 | GetControlBounds( m_macToolHandle , &contrlRect ) ; | |
408 | int former_mac_x = contrlRect.left ; | |
409 | int former_mac_y = contrlRect.top ; | |
410 | int mac_x = toolrect.left ; | |
411 | int mac_y = toolrect.top ; | |
412 | ||
413 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
414 | { | |
415 | { | |
416 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + toolSize.y , former_mac_x + toolSize.y } ; | |
417 | InvalWindowRect( rootwindow , &inval ) ; | |
418 | } | |
419 | UMAMoveControl( m_macToolHandle , mac_x , mac_y ) ; | |
420 | { | |
421 | Rect inval = { mac_y , mac_x , mac_y + toolSize.y , mac_x + toolSize.y } ; | |
422 | InvalWindowRect( rootwindow , &inval ) ; | |
423 | } | |
424 | } | |
425 | } | |
426 | ||
427 | x += (int)toolSize.x; | |
428 | noButtons ++; | |
429 | } | |
430 | else | |
431 | { | |
c257d44d | 432 | toolcount++ ; |
e044f600 RR |
433 | x += (int)toolSize.x / 4; |
434 | } | |
435 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth) | |
436 | maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h; | |
437 | if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) | |
438 | maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ; | |
439 | ||
440 | node = node->Next(); | |
441 | } | |
c257d44d SC |
442 | } |
443 | ||
444 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
445 | { | |
446 | if ( m_maxRows == 0 ) | |
447 | { | |
448 | // if not set yet, only one row | |
449 | SetRows(1); | |
450 | } | |
e044f600 | 451 | maxWidth = tw ; |
c257d44d | 452 | maxHeight += toolSize.y; |
e044f600 RR |
453 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; |
454 | m_maxHeight = maxHeight ; | |
c257d44d SC |
455 | } |
456 | else | |
457 | { | |
458 | if ( noButtons > 0 && m_maxRows == 0 ) | |
459 | { | |
460 | // if not set yet, have one column | |
461 | SetRows(noButtons); | |
462 | } | |
463 | maxHeight = th ; | |
464 | maxWidth += toolSize.x; | |
e044f600 RR |
465 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; |
466 | m_maxWidth = maxWidth ; | |
c257d44d SC |
467 | } |
468 | ||
469 | SetSize(maxWidth, maxHeight); | |
470 | } | |
471 | ||
472 | wxWindow::MacSuperChangedPosition() ; | |
473 | } | |
474 | ||
37e2cb08 | 475 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
e9576ca5 | 476 | { |
37e2cb08 | 477 | MacClientToRootWindow( &x , &y ) ; |
2f1ae414 | 478 | Point pt = { y ,x } ; |
37e2cb08 | 479 | |
7af79c94 | 480 | size_t index = 0 ; |
e044f600 RR |
481 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
482 | { | |
483 | if ( m_macToolHandles[index] ) | |
484 | { | |
485 | Rect bounds ; | |
486 | GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ; | |
487 | if ( PtInRect( pt , &bounds ) ) | |
488 | { | |
489 | return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; | |
490 | } | |
491 | } | |
492 | } | |
37e2cb08 SC |
493 | |
494 | return (wxToolBarToolBase *)NULL; | |
e9576ca5 SC |
495 | } |
496 | ||
2f1ae414 SC |
497 | wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) |
498 | { | |
e044f600 RR |
499 | wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; |
500 | if ( tool ) | |
501 | { | |
502 | return tool->GetShortHelp() ; | |
503 | } | |
504 | return "" ; | |
2f1ae414 SC |
505 | } |
506 | ||
37e2cb08 | 507 | void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) |
e9576ca5 | 508 | { |
e044f600 RR |
509 | if (!IsShown()) |
510 | return ; | |
511 | ||
512 | wxToolBarTool *tool = (wxToolBarTool *)t; | |
513 | if ( tool->m_index < 0 ) | |
514 | return ; | |
515 | ||
516 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; | |
517 | ||
518 | if ( enable ) | |
519 | UMAActivateControl( control ) ; | |
520 | else | |
521 | UMADeactivateControl( control ) ; | |
e9576ca5 SC |
522 | } |
523 | ||
37e2cb08 | 524 | void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) |
e9576ca5 | 525 | { |
e044f600 RR |
526 | if (!IsShown()) |
527 | return ; | |
528 | ||
529 | wxToolBarTool *tool = (wxToolBarTool *)t; | |
530 | if ( tool->m_index < 0 ) | |
531 | return ; | |
8208e181 | 532 | |
e044f600 | 533 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; |
467e3168 | 534 | ::SetControl32BitValue( control , toggle ) ; |
37e2cb08 | 535 | } |
7c551d95 | 536 | |
37e2cb08 SC |
537 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), |
538 | wxToolBarToolBase *tool) | |
539 | { | |
540 | // nothing special to do here - we really create the toolbar buttons in | |
541 | // Realize() later | |
542 | tool->Attach(this); | |
7c551d95 | 543 | |
37e2cb08 SC |
544 | return TRUE; |
545 | } | |
e9576ca5 | 546 | |
5115c51a | 547 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
37e2cb08 | 548 | { |
5115c51a | 549 | wxFAIL_MSG( _T("not implemented") ); |
e9576ca5 SC |
550 | } |
551 | ||
5115c51a | 552 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *WXUNUSED(tool)) |
37e2cb08 | 553 | { |
5115c51a SC |
554 | wxFAIL_MSG( _T("not implemented") ); |
555 | return TRUE ; | |
37e2cb08 | 556 | } |
2f1ae414 SC |
557 | |
558 | void wxToolBar::OnPaint(wxPaintEvent& event) | |
559 | { | |
de043984 SC |
560 | wxPaintDC dc(this) ; |
561 | wxMacPortSetter helper(&dc) ; | |
562 | ||
1fd1922a RR |
563 | Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , |
564 | dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ; | |
565 | UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
566 | { | |
7af79c94 | 567 | size_t index = 0 ; |
1fd1922a RR |
568 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
569 | { | |
570 | if ( m_macToolHandles[index] ) | |
571 | { | |
572 | UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ; | |
573 | } | |
574 | } | |
575 | } | |
2f1ae414 | 576 | } |
895f5af7 | 577 | |
2f1ae414 SC |
578 | void wxToolBar::OnMouse( wxMouseEvent &event ) |
579 | { | |
1fd1922a RR |
580 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) |
581 | { | |
582 | ||
583 | int x = event.m_x ; | |
584 | int y = event.m_y ; | |
585 | ||
586 | MacClientToRootWindow( &x , &y ) ; | |
587 | ||
588 | ControlHandle control ; | |
589 | Point localwhere ; | |
590 | SInt16 controlpart ; | |
591 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
592 | ||
593 | localwhere.h = x ; | |
594 | localwhere.v = y ; | |
595 | ||
596 | short modifiers = 0; | |
597 | ||
598 | if ( !event.m_leftDown && !event.m_rightDown ) | |
599 | modifiers |= btnState ; | |
600 | ||
601 | if ( event.m_shiftDown ) | |
602 | modifiers |= shiftKey ; | |
603 | ||
604 | if ( event.m_controlDown ) | |
605 | modifiers |= controlKey ; | |
606 | ||
607 | if ( event.m_altDown ) | |
608 | modifiers |= optionKey ; | |
609 | ||
610 | if ( event.m_metaDown ) | |
611 | modifiers |= cmdKey ; | |
612 | ||
613 | controlpart = ::FindControl( localwhere , window , &control ) ; | |
614 | { | |
615 | if ( control && ::IsControlActive( control ) ) | |
616 | { | |
617 | { | |
618 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
619 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
620 | else | |
621 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
622 | wxTheApp->s_lastMouseDown = 0 ; | |
623 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
624 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
625 | { | |
626 | MacHandleControlClick( control , controlpart ) ; | |
627 | } | |
628 | } | |
629 | } | |
630 | } | |
631 | } | |
2f1ae414 SC |
632 | } |
633 | ||
519cb848 SC |
634 | #endif // wxUSE_TOOLBAR |
635 |