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