]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toolbar.cpp
corrected GetCharWidth and implemented MacSuperChangedPosition for toolbars
[wxWidgets.git] / src / mac / carbon / toolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: toolbar.cpp
3 // Purpose: wxToolBar
4 // Author: AUTHOR
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHORy
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "toolbar.h"
13 #endif
14
15 #include "wx/wx.h"
16
17 #if wxUSE_TOOLBAR
18
19 #include "wx/toolbar.h"
20 #include "wx/notebook.h"
21 #include "wx/tabctrl.h"
22
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
25
26 BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
27 EVT_MOUSE_EVENTS( wxToolBar::OnMouse )
28 EVT_PAINT( wxToolBar::OnPaint )
29 END_EVENT_TABLE()
30 #endif
31
32 #include <wx/mac/uma.h>
33
34 // ----------------------------------------------------------------------------
35 // private classes
36 // ----------------------------------------------------------------------------
37
38 class wxToolBarTool : public wxToolBarToolBase
39 {
40 public:
41 wxToolBarTool(wxToolBar *tbar,
42 int id,
43 const wxBitmap& bitmap1,
44 const wxBitmap& bitmap2,
45 bool toggle,
46 wxObject *clientData,
47 const wxString& shortHelpString,
48 const wxString& longHelpString)
49 : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
50 clientData, shortHelpString, longHelpString)
51 {
52 m_nSepCount = 0;
53 m_index = -1 ;
54 }
55
56 wxToolBarTool(wxToolBar *tbar, wxControl *control)
57 : wxToolBarToolBase(tbar, control)
58 {
59 m_nSepCount = 1;
60 m_index = -1 ;
61 }
62
63 // set/get the number of separators which we use to cover the space used by
64 // a control in the toolbar
65 void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
66 size_t GetSeparatorsCount() const { return m_nSepCount; }
67
68 int m_index ;
69 private:
70 size_t m_nSepCount;
71 };
72
73
74 // ============================================================================
75 // implementation
76 // ============================================================================
77
78 // ----------------------------------------------------------------------------
79 // wxToolBarTool
80 // ----------------------------------------------------------------------------
81
82 const short kwxMacToolBarToolDefaultWidth = 24 ;
83 const short kwxMacToolBarToolDefaultHeight = 22 ;
84 const short kwxMacToolBarTopMargin = 2 ;
85 const short kwxMacToolBarLeftMargin = 2 ;
86
87
88 wxToolBarToolBase *wxToolBar::CreateTool(int id,
89 const wxBitmap& bitmap1,
90 const wxBitmap& bitmap2,
91 bool toggle,
92 wxObject *clientData,
93 const wxString& shortHelpString,
94 const wxString& longHelpString)
95 {
96 return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
97 clientData, shortHelpString, longHelpString);
98 }
99
100 wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
101 {
102 return new wxToolBarTool(this, control);
103 }
104
105 void wxToolBar::Init()
106 {
107 m_maxWidth = -1;
108 m_maxHeight = -1;
109 m_defaultWidth = kwxMacToolBarToolDefaultWidth;
110 m_defaultHeight = kwxMacToolBarToolDefaultHeight;
111 }
112
113 bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
114 long style, const wxString& name)
115 {
116
117 int x = pos.x;
118 int y = pos.y;
119 int width = size.x;
120 int height = size.y;
121
122 if (width <= 0)
123 width = 100;
124 if (height <= 0)
125 height = 30;
126 if (x < 0)
127 x = 0;
128 if (y < 0)
129 y = 0;
130
131 SetName(name);
132
133 m_windowStyle = style;
134 parent->AddChild(this);
135
136 m_backgroundColour = parent->GetBackgroundColour() ;
137 m_foregroundColour = parent->GetForegroundColour() ;
138
139 if (id == -1)
140 m_windowId = NewControlId();
141 else
142 m_windowId = id;
143
144 {
145 m_width = size.x ;
146 m_height = size.y ;
147 int x = pos.x ;
148 int y = pos.y ;
149 AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING);
150 m_x = x ;
151 m_y = y ;
152 }
153
154 return TRUE;
155 }
156
157 wxToolBar::~wxToolBar()
158 {
159 // we must refresh the frame size when the toolbar is deleted but the frame
160 // is not - otherwise toolbar leaves a hole in the place it used to occupy
161 }
162
163 PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
164 PicHandle MakePict(GWorldPtr wp, GWorldPtr mask )
165 {
166 CGrafPtr origPort ;
167 GDHandle origDev ;
168
169 PicHandle pict; // this is the Picture we give back
170
171 RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ;
172 RGBColor white = { 0xffff ,0xffff , 0xffff } ;
173 RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
174
175 unsigned char *maskimage = NULL ;
176 Rect portRect ;
177 GetPortBounds( wp , &portRect ) ;
178 int width = portRect.right - portRect.left ;
179 int height = portRect.bottom - portRect.top ;
180
181 LockPixels( GetGWorldPixMap( wp ) ) ;
182 GetGWorld( &origPort , &origDev ) ;
183
184 if ( mask )
185 {
186
187 maskimage = (unsigned char*) malloc( width * height ) ;
188 SetGWorld( mask , NULL ) ;
189 LockPixels( GetGWorldPixMap( mask ) ) ;
190 for ( int y = 0 ; y < height ; ++y )
191 {
192 for( int x = 0 ; x < width ; ++x )
193 {
194 RGBColor col ;
195
196 GetCPixel( x + portRect.left , y + portRect.top , &col ) ;
197 maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks
198 }
199 }
200 UnlockPixels( GetGWorldPixMap( mask ) ) ;
201 }
202
203 SetGWorld( wp , NULL ) ;
204
205 pict = OpenPicture(&portRect); // open a picture, this disables drawing
206 if(!pict)
207 return NULL;
208
209 RGBBackColor( &gray ) ;
210 RGBForeColor( &black ) ;
211 EraseRect(&portRect) ;
212 RGBBackColor( &white ) ;
213
214 if ( maskimage )
215 {
216 for ( int y = 0 ; y < height ; ++y )
217 {
218 for( int x = 0 ; x < width ; ++x )
219 {
220 if ( maskimage[y*width + x] )
221 {
222 RGBColor col ;
223
224 GetCPixel( x + portRect.left , y + portRect.top , &col ) ;
225 SetCPixel( x + portRect.left , y + portRect.top , &col ) ;
226 }
227 }
228 }
229 free( maskimage ) ;
230 maskimage = NULL ;
231 }
232 else
233 {
234 CopyBits(GetPortBitMapForCopyBits(wp), // src PixMap - we copy image over itself -
235 GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs -
236 &portRect, // srcRect - it will be recorded and compressed -
237 &portRect, // dstRect - into the picture that is open -
238 srcCopy,NULL); // copyMode and no clip region
239
240 }
241 ClosePicture(); // We are done recording the picture
242 UnlockPixels( GetGWorldPixMap( wp ) ) ;
243 SetGWorld( origPort , origDev ) ;
244 return pict; // return our groovy pict handle
245 }
246
247 bool wxToolBar::Realize()
248 {
249 if (m_tools.Number() == 0)
250 return FALSE;
251
252 Point localOrigin ;
253 Rect clipRect ;
254 WindowRef window ;
255 wxWindow *win ;
256
257 GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
258
259 Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
260 m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ;
261 ControlFontStyleRec controlstyle ;
262
263 controlstyle.flags = kControlUseFontMask ;
264 controlstyle.font = kControlFontSmallSystemFont ;
265
266 wxNode *node = m_tools.First();
267 int noButtons = 0;
268 int x = 0 ;
269 wxSize toolSize = GetToolSize() ;
270 int tw, th;
271 GetSize(& tw, & th);
272
273 int maxWidth = 0 ;
274 int maxHeight = 0 ;
275
276 while (node)
277 {
278 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
279 wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ;
280
281 if( !tool->IsSeparator() )
282 {
283 Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ;
284 toolrect.right = toolrect.left + toolSize.x ;
285 toolrect.bottom = toolrect.top + toolSize.y ;
286
287 PicHandle icon = NULL ;
288 if ( bmap )
289 {
290 if ( bmap->m_bitmapType == kMacBitmapTypePict )
291 icon = bmap->m_hPict ;
292 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
293 {
294 if ( tool->GetBitmap1().GetMask() )
295 {
296 icon = MakePict( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ) ;
297 }
298 else
299 {
300 icon = MakePict( bmap->m_hBitmap , NULL ) ;
301 }
302 }
303 }
304
305 ControlHandle m_macToolHandle ;
306
307 SInt16 behaviour = kControlBehaviorOffsetContents ;
308 if ( tool->CanBeToggled() )
309 behaviour += kControlBehaviorToggles ;
310
311 if ( icon )
312 {
313 m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 ,
314 behaviour + kControlContentPictHandle , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
315 ControlButtonContentInfo info ;
316
317 info.contentType = kControlContentPictHandle ;
318 info.u.picture = icon ;
319
320 UMASetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
321 }
322 else
323 {
324 m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 ,
325 behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
326 }
327 m_macToolHandles.Add( m_macToolHandle ) ;
328 tool->m_index = m_macToolHandles.Count() -1 ;
329 if ( !tool->IsEnabled() )
330 {
331 UMADeactivateControl( m_macToolHandle ) ;
332 }
333 if ( tool->CanBeToggled() && tool->IsToggled() )
334 {
335 ::SetControlValue( m_macToolHandle , 1 ) ;
336 }
337 UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ;
338 ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
339 wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
340 UMAEmbedControl( m_macToolHandle , container ) ;
341
342 x += (int)toolSize.x;
343 noButtons ++;
344 }
345 else
346 {
347 m_macToolHandles.Add( NULL ) ;
348 x += (int)toolSize.x / 4;
349 }
350 if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth)
351 maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h;
352 if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight)
353 maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ;
354
355 node = node->Next();
356 }
357
358 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
359 {
360 if ( m_maxRows == 0 )
361 {
362 // if not set yet, only one row
363 SetRows(1);
364 }
365 maxWidth = tw ;
366 maxHeight += toolSize.y;
367 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
368 m_maxHeight = maxHeight ;
369 }
370 else
371 {
372 if ( noButtons > 0 && m_maxRows == 0 )
373 {
374 // if not set yet, have one column
375 SetRows(noButtons);
376 }
377 maxHeight = th ;
378 maxWidth += toolSize.x;
379 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
380 m_maxWidth = maxWidth ;
381 }
382
383 SetSize(maxWidth, maxHeight);
384
385 return TRUE;
386 }
387
388 void wxToolBar::SetToolBitmapSize(const wxSize& size)
389 {
390 m_defaultWidth = size.x+2; m_defaultHeight = size.y+2;
391 }
392
393 // The button size is bigger than the bitmap size
394 wxSize wxToolBar::GetToolSize() const
395 {
396 return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);
397 }
398
399 void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
400 {
401 int index = 0 ;
402 for ( index = 0 ; index < m_macToolHandles.Count() ; ++index )
403 {
404 if ( m_macToolHandles[index] == (void*) control )
405 {
406 wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data();
407 if ( tool->CanBeToggled() )
408 {
409 tool->Toggle( GetControlValue( control ) ) ;
410 }
411 OnLeftClick( tool->GetId() , tool -> IsToggled() ) ;
412 break ;
413 }
414 }
415 }
416
417 void wxToolBar::SetRows(int nRows)
418 {
419 if ( nRows == m_maxRows )
420 {
421 // avoid resizing the frame uselessly
422 return;
423 }
424
425 m_maxRows = nRows;
426 }
427
428 void wxToolBar::MacSuperChangedPosition()
429 {
430 if (m_tools.Number() > 0)
431 {
432
433 Point localOrigin ;
434 Rect clipRect ;
435 WindowRef window ;
436 wxWindow *win ;
437
438 GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
439
440 Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
441 m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ;
442 ControlFontStyleRec controlstyle ;
443
444 controlstyle.flags = kControlUseFontMask ;
445 controlstyle.font = kControlFontSmallSystemFont ;
446
447 wxNode *node = m_tools.First();
448 int noButtons = 0;
449 int x = 0 ;
450 wxSize toolSize = GetToolSize() ;
451 int tw, th;
452 GetSize(& tw, & th);
453
454 int maxWidth = 0 ;
455 int maxHeight = 0 ;
456 int toolcount = 0 ;
457 {
458 WindowRef rootwindow = GetMacRootWindow() ;
459 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
460 UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
461 wxMacDrawingHelper focus( wxrootwindow ) ;
462 while (node)
463 {
464 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
465 wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ;
466
467 if( !tool->IsSeparator() )
468 {
469 Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ;
470 toolrect.right = toolrect.left + toolSize.x ;
471 toolrect.bottom = toolrect.top + toolSize.y ;
472
473 ControlHandle m_macToolHandle = (ControlHandle) m_macToolHandles[toolcount++] ;
474
475 {
476 Rect contrlRect ;
477 GetControlBounds( m_macToolHandle , &contrlRect ) ;
478 int former_mac_x = contrlRect.left ;
479 int former_mac_y = contrlRect.top ;
480 int mac_x = toolrect.left ;
481 int mac_y = toolrect.top ;
482
483 if ( mac_x != former_mac_x || mac_y != former_mac_y )
484 {
485 {
486 Rect inval = { former_mac_y , former_mac_x , former_mac_y + toolSize.y , former_mac_x + toolSize.y } ;
487 InvalWindowRect( rootwindow , &inval ) ;
488 }
489 UMAMoveControl( m_macToolHandle , mac_x , mac_y ) ;
490 {
491 Rect inval = { mac_y , mac_x , mac_y + toolSize.y , mac_x + toolSize.y } ;
492 InvalWindowRect( rootwindow , &inval ) ;
493 }
494 }
495 }
496
497 x += (int)toolSize.x;
498 noButtons ++;
499 }
500 else
501 {
502 toolcount++ ;
503 x += (int)toolSize.x / 4;
504 }
505 if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth)
506 maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h;
507 if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight)
508 maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ;
509
510 node = node->Next();
511 }
512 if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
513 {
514 }
515 else
516 {
517 UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
518 }
519 }
520
521 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
522 {
523 if ( m_maxRows == 0 )
524 {
525 // if not set yet, only one row
526 SetRows(1);
527 }
528 maxWidth = tw ;
529 maxHeight += toolSize.y;
530 maxHeight += m_yMargin + kwxMacToolBarTopMargin;
531 m_maxHeight = maxHeight ;
532 }
533 else
534 {
535 if ( noButtons > 0 && m_maxRows == 0 )
536 {
537 // if not set yet, have one column
538 SetRows(noButtons);
539 }
540 maxHeight = th ;
541 maxWidth += toolSize.x;
542 maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
543 m_maxWidth = maxWidth ;
544 }
545
546 SetSize(maxWidth, maxHeight);
547 }
548
549 wxWindow::MacSuperChangedPosition() ;
550 }
551
552 wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
553 {
554 MacClientToRootWindow( &x , &y ) ;
555 Point pt = { y ,x } ;
556
557 int index = 0 ;
558 for ( index = 0 ; index < m_macToolHandles.Count() ; ++index )
559 {
560 if ( m_macToolHandles[index] )
561 {
562 Rect bounds ;
563 GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ;
564 if ( PtInRect( pt , &bounds ) )
565 {
566 return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ;
567 }
568 }
569 }
570
571 return (wxToolBarToolBase *)NULL;
572 }
573
574 wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
575 {
576 wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ;
577 if ( tool )
578 {
579 return tool->GetShortHelp() ;
580 }
581 return "" ;
582 }
583
584 void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
585 {
586 wxToolBarTool *tool = (wxToolBarTool *)t;
587 if ( tool->m_index < 0 )
588 return ;
589
590 ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ;
591
592 if ( enable )
593 UMAActivateControl( control ) ;
594 else
595 UMADeactivateControl( control ) ;
596 }
597
598 void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
599 {
600 wxToolBarTool *tool = (wxToolBarTool *)t;
601 if ( tool->m_index < 0 )
602 return ;
603
604 ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ;
605 ::SetControlValue( control , toggle ) ;
606 }
607
608 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
609 wxToolBarToolBase *tool)
610 {
611 // nothing special to do here - we really create the toolbar buttons in
612 // Realize() later
613 tool->Attach(this);
614
615 return TRUE;
616 }
617
618 void wxToolBar::DoSetToggle(wxToolBarToolBase *t, bool toggle)
619 {
620 wxToolBarTool *tool = (wxToolBarTool *)t;
621 // TODO: set toggle state
622 }
623
624 bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
625 {
626 return TRUE ;
627 }
628
629 void wxToolBar::OnPaint(wxPaintEvent& event)
630 {
631 Point localOrigin ;
632 Rect clipRect ;
633 WindowRef window ;
634 wxWindow *win ;
635
636 GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
637 if ( window && win )
638 {
639 wxMacDrawingHelper help( win ) ;
640 // the mac control manager always assumes to have the origin at 0,0
641 SetOrigin( 0 , 0 ) ;
642
643 bool hasTabBehind = false ;
644 wxWindow* parent = GetParent() ;
645 while ( parent )
646 {
647 if( parent->MacGetWindowData() )
648 {
649 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
650 break ;
651 }
652
653 if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
654 {
655 if ( ((wxControl*)parent)->GetMacControl() )
656 SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ;
657 break ;
658 }
659
660 parent = parent->GetParent() ;
661 }
662
663 Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
664 m_y + localOrigin.v + m_height , m_x + localOrigin.h + m_width } ;
665
666 UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
667 {
668 int index = 0 ;
669 for ( index = 0 ; index < m_macToolHandles.Count() ; ++index )
670 {
671 if ( m_macToolHandles[index] )
672 {
673 UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ;
674 }
675 }
676 }
677 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
678 }
679 }
680
681 void wxToolBar::OnMouse( wxMouseEvent &event )
682 {
683
684 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
685 {
686
687 int x = event.m_x ;
688 int y = event.m_y ;
689
690 MacClientToRootWindow( &x , &y ) ;
691
692 ControlHandle control ;
693 Point localwhere ;
694 GrafPtr port ;
695 SInt16 controlpart ;
696 WindowRef window = GetMacRootWindow() ;
697
698 localwhere.h = x ;
699 localwhere.v = y ;
700
701 short modifiers = 0;
702
703 if ( !event.m_leftDown && !event.m_rightDown )
704 modifiers |= btnState ;
705
706 if ( event.m_shiftDown )
707 modifiers |= shiftKey ;
708
709 if ( event.m_controlDown )
710 modifiers |= controlKey ;
711
712 if ( event.m_altDown )
713 modifiers |= optionKey ;
714
715 if ( event.m_metaDown )
716 modifiers |= cmdKey ;
717
718 controlpart = FindControl( localwhere , window , &control ) ;
719 {
720 if ( control && UMAIsControlActive( control ) )
721 {
722 {
723 if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() )
724 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ;
725 else
726 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
727 wxTheApp->s_lastMouseDown = 0 ;
728 if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) )
729 && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice
730 {
731 MacHandleControlClick( control , controlpart ) ;
732 }
733 }
734 }
735 }
736 }
737 }
738
739 #endif // wxUSE_TOOLBAR
740