]>
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(); |
7af79c94 | 205 | // wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetNormalBitmap().GetRefData()) ; |
0b7a8cd3 GD |
206 | |
207 | if( !tool->IsSeparator() ) | |
208 | { | |
209 | Rect toolrect = { toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin, | |
210 | toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
211 | toolrect.right = toolrect.left + toolSize.x ; | |
212 | toolrect.bottom = toolrect.top + toolSize.y ; | |
213 | ||
214 | ControlButtonContentInfo info ; | |
1b21409b | 215 | wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() ) ; |
0b7a8cd3 GD |
216 | ControlHandle m_macToolHandle ; |
217 | ||
218 | SInt16 behaviour = kControlBehaviorOffsetContents ; | |
219 | if ( tool->CanBeToggled() ) | |
220 | behaviour += kControlBehaviorToggles ; | |
221 | ||
be295828 | 222 | if ( info.contentType != kControlNoContent ) |
0b7a8cd3 GD |
223 | { |
224 | m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , | |
225 | behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
226 | ||
227 | ::SetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
228 | } | |
229 | else | |
230 | { | |
231 | m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , | |
232 | behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
233 | } | |
234 | UMAShowControl( m_macToolHandle ) ; | |
235 | m_macToolHandles.Add( m_macToolHandle ) ; | |
236 | tool->m_index = m_macToolHandles.Count() -1 ; | |
237 | if ( !tool->IsEnabled() ) | |
238 | { | |
239 | UMADeactivateControl( m_macToolHandle ) ; | |
240 | } | |
241 | if ( tool->CanBeToggled() && tool->IsToggled() ) | |
242 | { | |
467e3168 | 243 | ::SetControl32BitValue( m_macToolHandle , 1 ) ; |
0b7a8cd3 GD |
244 | } |
245 | else | |
246 | { | |
467e3168 | 247 | ::SetControl32BitValue( m_macToolHandle , 0 ) ; |
0b7a8cd3 GD |
248 | } |
249 | /* | |
250 | ::SetControlFontStyle( m_macToolHandle , &controlstyle ) ; | |
251 | */ | |
76a5e5d2 | 252 | ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; |
0b7a8cd3 GD |
253 | wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; |
254 | ::EmbedControl( m_macToolHandle , container ) ; | |
255 | ||
1fd1922a | 256 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) |
0b7a8cd3 | 257 | { |
1fd1922a | 258 | y += (int)toolSize.y; |
0b7a8cd3 GD |
259 | } |
260 | else | |
261 | { | |
1fd1922a | 262 | x += (int)toolSize.x; |
0b7a8cd3 GD |
263 | } |
264 | noButtons ++; | |
265 | } | |
266 | else | |
267 | { | |
268 | m_macToolHandles.Add( NULL ) ; | |
1fd1922a RR |
269 | |
270 | if ( GetWindowStyleFlag() & wxTB_VERTICAL ) | |
0b7a8cd3 | 271 | { |
1fd1922a | 272 | y += (int)toolSize.y / 4; |
0b7a8cd3 GD |
273 | } |
274 | else | |
275 | { | |
1fd1922a | 276 | x += (int)toolSize.x / 4; |
0b7a8cd3 GD |
277 | } |
278 | } | |
279 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin - m_x - localOrigin.h > maxWidth) { | |
280 | maxWidth = toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin - m_x - localOrigin.h; | |
281 | } | |
282 | if (toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) { | |
283 | maxHeight = toolbarrect.top + y + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v ; | |
284 | } | |
285 | node = node->Next(); | |
7810c95b | 286 | } |
0b7a8cd3 GD |
287 | |
288 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
7810c95b | 289 | { |
0b7a8cd3 GD |
290 | if ( m_maxRows == 0 ) |
291 | { | |
292 | // if not set yet, only one row | |
293 | SetRows(1); | |
294 | } | |
295 | maxWidth = tw ; | |
296 | maxHeight += toolSize.y; | |
297 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; | |
298 | m_maxHeight = maxHeight ; | |
7810c95b | 299 | } |
0b7a8cd3 GD |
300 | else |
301 | { | |
302 | if ( noButtons > 0 && m_maxRows == 0 ) | |
303 | { | |
304 | // if not set yet, have one column | |
305 | SetRows(noButtons); | |
306 | } | |
307 | maxHeight = th ; | |
308 | maxWidth += toolSize.x; | |
309 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; | |
310 | m_maxWidth = maxWidth ; | |
311 | } | |
312 | ||
313 | SetSize(maxWidth, maxHeight); | |
314 | ||
315 | return TRUE; | |
e9576ca5 SC |
316 | } |
317 | ||
318 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
319 | { | |
9aad97fd | 320 | m_defaultWidth = size.x+4; m_defaultHeight = size.y+4; |
e9576ca5 SC |
321 | } |
322 | ||
e9576ca5 SC |
323 | // The button size is bigger than the bitmap size |
324 | wxSize wxToolBar::GetToolSize() const | |
325 | { | |
2f1ae414 | 326 | return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); |
e9576ca5 SC |
327 | } |
328 | ||
76a5e5d2 | 329 | void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) |
519cb848 | 330 | { |
7af79c94 | 331 | size_t index = 0 ; |
e044f600 RR |
332 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
333 | { | |
334 | if ( m_macToolHandles[index] == (void*) control ) | |
335 | { | |
336 | wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data(); | |
337 | if ( tool->CanBeToggled() ) | |
338 | { | |
467e3168 | 339 | tool->Toggle( GetControl32BitValue( (ControlHandle) control ) ) ; |
e044f600 RR |
340 | } |
341 | OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; | |
342 | break ; | |
343 | } | |
344 | } | |
519cb848 SC |
345 | } |
346 | ||
37e2cb08 | 347 | void wxToolBar::SetRows(int nRows) |
e9576ca5 | 348 | { |
37e2cb08 | 349 | if ( nRows == m_maxRows ) |
e9576ca5 | 350 | { |
37e2cb08 SC |
351 | // avoid resizing the frame uselessly |
352 | return; | |
e9576ca5 | 353 | } |
37e2cb08 SC |
354 | |
355 | m_maxRows = nRows; | |
e9576ca5 SC |
356 | } |
357 | ||
c257d44d SC |
358 | void wxToolBar::MacSuperChangedPosition() |
359 | { | |
360 | if (m_tools.Number() > 0) | |
361 | { | |
362 | ||
e044f600 | 363 | Point localOrigin ; |
d84afea9 GD |
364 | // Rect clipRect ; |
365 | // WindowRef window ; | |
366 | // wxWindow *win ; | |
de043984 SC |
367 | int lx , ly ; |
368 | lx = ly = 0 ; | |
369 | MacWindowToRootWindow( &lx , &ly ) ; | |
370 | localOrigin.v = ly ; | |
371 | localOrigin.h = lx ; | |
e044f600 | 372 | |
de043984 | 373 | // GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; |
e044f600 | 374 | |
de043984 SC |
375 | Rect toolbarrect = { localOrigin.v ,localOrigin.h , |
376 | m_height + localOrigin.v , m_width + localOrigin.h} ; | |
e044f600 RR |
377 | ControlFontStyleRec controlstyle ; |
378 | ||
379 | controlstyle.flags = kControlUseFontMask ; | |
380 | controlstyle.font = kControlFontSmallSystemFont ; | |
381 | ||
382 | wxNode *node = m_tools.First(); | |
383 | int noButtons = 0; | |
384 | int x = 0 ; | |
385 | wxSize toolSize = GetToolSize() ; | |
c257d44d SC |
386 | int tw, th; |
387 | GetSize(& tw, & th); | |
388 | ||
389 | int maxWidth = 0 ; | |
390 | int maxHeight = 0 ; | |
391 | int toolcount = 0 ; | |
392 | { | |
76a5e5d2 | 393 | WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; |
1fd1922a RR |
394 | while (node) |
395 | { | |
396 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
7af79c94 | 397 | // wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetNormalBitmap().GetRefData()) ; |
1fd1922a RR |
398 | |
399 | if( !tool->IsSeparator() ) | |
400 | { | |
401 | Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
402 | toolrect.right = toolrect.left + toolSize.x ; | |
403 | toolrect.bottom = toolrect.top + toolSize.y ; | |
404 | ||
405 | ControlHandle m_macToolHandle = (ControlHandle) m_macToolHandles[toolcount++] ; | |
406 | ||
407 | { | |
408 | Rect contrlRect ; | |
409 | GetControlBounds( m_macToolHandle , &contrlRect ) ; | |
410 | int former_mac_x = contrlRect.left ; | |
411 | int former_mac_y = contrlRect.top ; | |
412 | int mac_x = toolrect.left ; | |
413 | int mac_y = toolrect.top ; | |
414 | ||
415 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
416 | { | |
417 | { | |
418 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + toolSize.y , former_mac_x + toolSize.y } ; | |
419 | InvalWindowRect( rootwindow , &inval ) ; | |
420 | } | |
421 | UMAMoveControl( m_macToolHandle , mac_x , mac_y ) ; | |
422 | { | |
423 | Rect inval = { mac_y , mac_x , mac_y + toolSize.y , mac_x + toolSize.y } ; | |
424 | InvalWindowRect( rootwindow , &inval ) ; | |
425 | } | |
426 | } | |
427 | } | |
428 | ||
429 | x += (int)toolSize.x; | |
430 | noButtons ++; | |
431 | } | |
432 | else | |
433 | { | |
c257d44d | 434 | toolcount++ ; |
e044f600 RR |
435 | x += (int)toolSize.x / 4; |
436 | } | |
437 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth) | |
438 | maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h; | |
439 | if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) | |
440 | maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ; | |
441 | ||
442 | node = node->Next(); | |
443 | } | |
c257d44d SC |
444 | } |
445 | ||
446 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
447 | { | |
448 | if ( m_maxRows == 0 ) | |
449 | { | |
450 | // if not set yet, only one row | |
451 | SetRows(1); | |
452 | } | |
e044f600 | 453 | maxWidth = tw ; |
c257d44d | 454 | maxHeight += toolSize.y; |
e044f600 RR |
455 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; |
456 | m_maxHeight = maxHeight ; | |
c257d44d SC |
457 | } |
458 | else | |
459 | { | |
460 | if ( noButtons > 0 && m_maxRows == 0 ) | |
461 | { | |
462 | // if not set yet, have one column | |
463 | SetRows(noButtons); | |
464 | } | |
465 | maxHeight = th ; | |
466 | maxWidth += toolSize.x; | |
e044f600 RR |
467 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; |
468 | m_maxWidth = maxWidth ; | |
c257d44d SC |
469 | } |
470 | ||
471 | SetSize(maxWidth, maxHeight); | |
472 | } | |
473 | ||
474 | wxWindow::MacSuperChangedPosition() ; | |
475 | } | |
476 | ||
37e2cb08 | 477 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
e9576ca5 | 478 | { |
37e2cb08 | 479 | MacClientToRootWindow( &x , &y ) ; |
2f1ae414 | 480 | Point pt = { y ,x } ; |
37e2cb08 | 481 | |
7af79c94 | 482 | size_t index = 0 ; |
e044f600 RR |
483 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
484 | { | |
485 | if ( m_macToolHandles[index] ) | |
486 | { | |
487 | Rect bounds ; | |
488 | GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ; | |
489 | if ( PtInRect( pt , &bounds ) ) | |
490 | { | |
491 | return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; | |
492 | } | |
493 | } | |
494 | } | |
37e2cb08 SC |
495 | |
496 | return (wxToolBarToolBase *)NULL; | |
e9576ca5 SC |
497 | } |
498 | ||
2f1ae414 SC |
499 | wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) |
500 | { | |
e044f600 RR |
501 | wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; |
502 | if ( tool ) | |
503 | { | |
504 | return tool->GetShortHelp() ; | |
505 | } | |
506 | return "" ; | |
2f1ae414 SC |
507 | } |
508 | ||
37e2cb08 | 509 | void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) |
e9576ca5 | 510 | { |
e044f600 RR |
511 | if (!IsShown()) |
512 | return ; | |
513 | ||
514 | wxToolBarTool *tool = (wxToolBarTool *)t; | |
515 | if ( tool->m_index < 0 ) | |
516 | return ; | |
517 | ||
518 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; | |
519 | ||
520 | if ( enable ) | |
521 | UMAActivateControl( control ) ; | |
522 | else | |
523 | UMADeactivateControl( control ) ; | |
e9576ca5 SC |
524 | } |
525 | ||
37e2cb08 | 526 | void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) |
e9576ca5 | 527 | { |
e044f600 RR |
528 | if (!IsShown()) |
529 | return ; | |
530 | ||
531 | wxToolBarTool *tool = (wxToolBarTool *)t; | |
532 | if ( tool->m_index < 0 ) | |
533 | return ; | |
8208e181 | 534 | |
e044f600 | 535 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; |
467e3168 | 536 | ::SetControl32BitValue( control , toggle ) ; |
37e2cb08 | 537 | } |
7c551d95 | 538 | |
37e2cb08 SC |
539 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), |
540 | wxToolBarToolBase *tool) | |
541 | { | |
542 | // nothing special to do here - we really create the toolbar buttons in | |
543 | // Realize() later | |
544 | tool->Attach(this); | |
7c551d95 | 545 | |
37e2cb08 SC |
546 | return TRUE; |
547 | } | |
e9576ca5 | 548 | |
5115c51a | 549 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
37e2cb08 | 550 | { |
5115c51a | 551 | wxFAIL_MSG( _T("not implemented") ); |
e9576ca5 SC |
552 | } |
553 | ||
5115c51a | 554 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *WXUNUSED(tool)) |
37e2cb08 | 555 | { |
5115c51a SC |
556 | wxFAIL_MSG( _T("not implemented") ); |
557 | return TRUE ; | |
37e2cb08 | 558 | } |
2f1ae414 SC |
559 | |
560 | void wxToolBar::OnPaint(wxPaintEvent& event) | |
561 | { | |
de043984 SC |
562 | wxPaintDC dc(this) ; |
563 | wxMacPortSetter helper(&dc) ; | |
564 | ||
1fd1922a RR |
565 | Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , |
566 | dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ; | |
567 | UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
568 | { | |
7af79c94 | 569 | size_t index = 0 ; |
1fd1922a RR |
570 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) |
571 | { | |
572 | if ( m_macToolHandles[index] ) | |
573 | { | |
574 | UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ; | |
575 | } | |
576 | } | |
577 | } | |
2f1ae414 | 578 | } |
895f5af7 | 579 | |
2f1ae414 SC |
580 | void wxToolBar::OnMouse( wxMouseEvent &event ) |
581 | { | |
1fd1922a RR |
582 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) |
583 | { | |
584 | ||
585 | int x = event.m_x ; | |
586 | int y = event.m_y ; | |
587 | ||
588 | MacClientToRootWindow( &x , &y ) ; | |
589 | ||
590 | ControlHandle control ; | |
591 | Point localwhere ; | |
592 | SInt16 controlpart ; | |
593 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
594 | ||
595 | localwhere.h = x ; | |
596 | localwhere.v = y ; | |
597 | ||
598 | short modifiers = 0; | |
599 | ||
600 | if ( !event.m_leftDown && !event.m_rightDown ) | |
601 | modifiers |= btnState ; | |
602 | ||
603 | if ( event.m_shiftDown ) | |
604 | modifiers |= shiftKey ; | |
605 | ||
606 | if ( event.m_controlDown ) | |
607 | modifiers |= controlKey ; | |
608 | ||
609 | if ( event.m_altDown ) | |
610 | modifiers |= optionKey ; | |
611 | ||
612 | if ( event.m_metaDown ) | |
613 | modifiers |= cmdKey ; | |
614 | ||
615 | controlpart = ::FindControl( localwhere , window , &control ) ; | |
616 | { | |
617 | if ( control && ::IsControlActive( control ) ) | |
618 | { | |
619 | { | |
620 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
621 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
622 | else | |
623 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
624 | wxTheApp->s_lastMouseDown = 0 ; | |
625 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
626 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
627 | { | |
628 | MacHandleControlClick( control , controlpart ) ; | |
629 | } | |
630 | } | |
631 | } | |
632 | } | |
633 | } | |
2f1ae414 SC |
634 | } |
635 | ||
519cb848 SC |
636 | #endif // wxUSE_TOOLBAR |
637 |