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