1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxControl class 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "control.h" 
  18 #include "wx/control.h" 
  22 #include "wx/dcclient.h" 
  23 #include "wx/notebook.h" 
  24 #include "wx/tabctrl.h" 
  25 #include "wx/radiobox.h" 
  26 #include "wx/spinbutt.h" 
  27 #include "wx/scrolbar.h" 
  28 #include "wx/button.h" 
  29 #include "wx/dialog.h" 
  30 #include "wx/statbox.h" 
  32 #include "wx/stattext.h" 
  34 #if !USE_SHARED_LIBRARY 
  35 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
) 
  37 BEGIN_EVENT_TABLE(wxControl
, wxWindow
) 
  38     EVT_MOUSE_EVENTS( wxControl::OnMouseEvent 
)  
  39 //    EVT_CHAR( wxControl::OnKeyDown )  
  40     EVT_PAINT( wxControl::OnPaint 
)  
  44 #include "wx/mac/uma.h" 
  45 #include "wx/mac/private.h" 
  50 #if PRAGMA_STRUCT_ALIGN 
  51     #pragma options align=mac68k 
  52 #elif PRAGMA_STRUCT_PACKPUSH 
  54 #elif PRAGMA_STRUCT_PACK 
  59  unsigned short instruction
; 
  61 } cdefRec
, *cdefPtr
, **cdefHandle
; 
  63 #if PRAGMA_STRUCT_ALIGN 
  64     #pragma options align=reset 
  65 #elif PRAGMA_STRUCT_PACKPUSH 
  67 #elif PRAGMA_STRUCT_PACK 
  71 ControlActionUPP wxMacLiveScrollbarActionUPP 
= NULL 
; 
  72 wxControl 
*wxFindControlFromMacControl(ControlHandle inControl 
) ; 
  74 pascal void wxMacLiveScrollbarActionProc( ControlHandle control 
, ControlPartCode partCode 
) ; 
  75 pascal void wxMacLiveScrollbarActionProc( ControlHandle control 
, ControlPartCode partCode 
) 
  79         wxControl
*  wx 
= (wxControl
*) GetControlReference( control 
) ; 
  82             wx
->MacHandleControlClick( control 
, partCode 
) ; 
  87 ControlColorUPP wxMacSetupControlBackgroundUPP 
= NULL 
; 
  88 ControlDefUPP wxMacControlActionUPP 
= NULL 
; 
  90 pascal SInt32  
wxMacControlDefintion(SInt16 varCode
, ControlRef theControl
, ControlDefProcMessage message
, SInt32 param
) 
  93         wxControl
*  wx 
= (wxControl
*) wxFindControlFromMacControl( theControl 
) ; 
  94         if ( wx 
!= NULL 
&& wx
->IsKindOf( CLASSINFO( wxControl 
) ) ) 
  96             if( message 
== drawCntl 
) 
  98                 wxMacWindowClipper 
clip( wx 
) ; 
  99                 return InvokeControlDefUPP( varCode 
, theControl 
, message 
, param 
, (ControlDefUPP
) wx
->MacGetControlAction() ) ; 
 102                 return InvokeControlDefUPP( varCode 
, theControl 
, message 
, param 
, (ControlDefUPP
) wx
->MacGetControlAction() ) ; 
 107 pascal OSStatus 
wxMacSetupControlBackground( ControlRef iControl 
, SInt16 iMessage 
, SInt16 iDepth 
, Boolean iIsColor 
) 
 109         OSStatus status 
= noErr 
; 
 112                 case kControlMsgSetUpBackground 
: 
 114                         wxControl
*  wx 
= (wxControl
*) GetControlReference( iControl 
) ; 
 115                         if ( wx 
!= NULL 
&& wx
->IsKindOf( CLASSINFO( wxControl 
) ) ) 
 117                                 wxDC::MacSetupBackgroundForCurrentPort( wx
->MacGetBackgroundBrush() ) ; 
 118         //                              SetThemeBackground( iDepth , iIsColor ) ; 
 133 wxControl::wxControl() 
 135     m_macControl 
= NULL 
; 
 136     m_macControlAction 
= NULL 
; 
 137     m_macHorizontalBorder 
= 0 ; // additional pixels around the real control 
 138     m_macVerticalBorder 
= 0 ; 
 139     m_backgroundColour 
= *wxWHITE
; 
 140     m_foregroundColour 
= *wxBLACK
; 
 141 #if WXWIN_COMPATIBILITY 
 143 #endif // WXWIN_COMPATIBILITY 
 145     if ( wxMacLiveScrollbarActionUPP 
== NULL 
) 
 147 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) 
 148         wxMacLiveScrollbarActionUPP 
= NewControlActionUPP( wxMacLiveScrollbarActionProc 
); 
 150         wxMacLiveScrollbarActionUPP 
= NewControlActionProc( wxMacLiveScrollbarActionProc 
) ; 
 155 bool wxControl::Create(wxWindow 
*parent
, wxWindowID id
, 
 157                        const wxSize
& size
, long style
, 
 158                        const wxValidator
& validator
, 
 159                        const wxString
& name
) 
 161     m_macControl 
= NULL 
; 
 162     m_macHorizontalBorder 
= 0 ; // additional pixels around the real control 
 163     m_macVerticalBorder 
= 0 ; 
 165     bool rval 
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
); 
 168         m_backgroundColour 
= parent
->GetBackgroundColour() ; 
 169         m_foregroundColour 
= parent
->GetForegroundColour() ; 
 173         SetValidator(validator
); 
 179 wxControl::~wxControl() 
 181     m_isBeingDeleted 
= TRUE
; 
 182     wxRemoveMacControlAssociation( this ) ; 
 183     // If we delete an item, we should initialize the parent panel, 
 184     // because it could now be invalid. 
 185     wxWindow 
*parent 
= GetParent() ; 
 188         if (parent
->GetDefaultItem() == (wxButton
*) this) 
 189             parent
->SetDefaultItem(NULL
); 
 191     if ( (ControlHandle
) m_macControl 
) 
 193         ::DisposeControl( (ControlHandle
) m_macControl 
) ; 
 194         m_macControl 
= NULL 
; 
 198 void wxControl::SetLabel(const wxString
& title
) 
 200     m_label 
= wxStripMenuCodes(title
) ; 
 202     if ( (ControlHandle
) m_macControl 
) 
 207         if( wxApp::s_macDefaultEncodingIsPC 
) 
 208             label 
= wxMacMakeMacStringFromPC( m_label 
) ; 
 213         c2pstrcpy( (StringPtr
) maclabel 
, label 
) ; 
 215         strcpy( (char *) maclabel 
, label 
) ; 
 216         c2pstr( (char *) maclabel 
) ; 
 218         ::SetControlTitle( (ControlHandle
) m_macControl 
, maclabel 
) ; 
 223 wxSize 
wxControl::DoGetBestSize() const 
 225     Rect    bestsize 
= { 0 , 0 , 0 , 0 } ; 
 226     short   baselineoffset 
; 
 227     int bestWidth
, bestHeight 
; 
 228     ::GetBestControlRect( (ControlHandle
) m_macControl 
, &bestsize 
, &baselineoffset 
) ; 
 230     if ( EmptyRect( &bestsize 
) ) 
 233         bestsize
.left 
= bestsize
.top 
= 0 ; 
 234         bestsize
.right 
= 16 ; 
 235         bestsize
.bottom 
= 16 ; 
 236         if ( IsKindOf( CLASSINFO( wxScrollBar 
) ) ) 
 238             bestsize
.bottom 
= 16 ; 
 240         else if ( IsKindOf( CLASSINFO( wxSpinButton 
) ) ) 
 242             bestsize
.bottom 
= 24 ;  
 246     if ( IsKindOf( CLASSINFO( wxButton 
) ) ) 
 248         bestWidth 
= m_label
.Length() * 8 + 12 ; 
 249         if ( bestWidth 
< 70 ) 
 252     else if ( IsKindOf( CLASSINFO( wxStaticText 
) ) ) 
 254         bestWidth 
= m_label
.Length() * 8 ; 
 257         bestWidth 
= bestsize
.right 
- bestsize
.left 
; 
 259     bestWidth 
+= 2 * m_macHorizontalBorder 
; 
 261     bestHeight 
= bestsize
.bottom 
- bestsize
.top 
; 
 262     if ( bestHeight 
< 10 ) 
 265     bestHeight 
+= 2 * m_macVerticalBorder
; 
 268     return wxSize(bestWidth
, bestHeight
); 
 271 bool wxControl::ProcessCommand (wxCommandEvent 
& event
) 
 274   // 1) A callback function (to become obsolete) 
 275   // 2) OnCommand, starting at this window and working up parent hierarchy 
 276   // 3) OnCommand then calls ProcessEvent to search the event tables. 
 277 #if WXWIN_COMPATIBILITY 
 280         (void)(*m_callback
)(this, event
); 
 285 #endif // WXWIN_COMPATIBILITY 
 287       return GetEventHandler()->ProcessEvent(event
); 
 291 // ------------------------ 
 292 wxList 
*wxWinMacControlList 
= NULL
; 
 293 wxControl 
*wxFindControlFromMacControl(ControlHandle inControl 
) 
 295     wxNode 
*node 
= wxWinMacControlList
->Find((long)inControl
); 
 298     return (wxControl 
*)node
->Data(); 
 301 void wxAssociateControlWithMacControl(ControlHandle inControl
, wxControl 
*control
) 
 303     // adding NULL WindowRef is (first) surely a result of an error and 
 304     // (secondly) breaks menu command processing 
 305     wxCHECK_RET( inControl 
!= (ControlHandle
) NULL
, "attempt to add a NULL WindowRef to window list" ); 
 307     if ( !wxWinMacControlList
->Find((long)inControl
) ) 
 308         wxWinMacControlList
->Append((long)inControl
, control
); 
 311 void wxRemoveMacControlAssociation(wxControl 
*control
) 
 313     wxWinMacControlList
->DeleteObject(control
); 
 316 void wxControl::MacPreControlCreate( wxWindow 
*parent
, wxWindowID id
, wxString label 
,  
 318              const wxSize
& size
, long style
, 
 319              const wxValidator
& validator
, 
 320              const wxString
& name 
, WXRECTPTR outBounds 
, unsigned char* maclabel 
)  
 325     SetValidator(validator
); 
 327   m_windowStyle 
= style
; 
 328   parent
->AddChild(this); 
 330   m_backgroundColour 
= parent
->GetBackgroundColour() ; 
 331   m_foregroundColour 
= parent
->GetForegroundColour() ; 
 334       m_windowId 
= NewControlId(); 
 338    // These sizes will be adjusted in MacPostControlCreate 
 345     ((Rect
*)outBounds
)->top 
= -10; 
 346     ((Rect
*)outBounds
)->left 
= -10; 
 347     ((Rect
*)outBounds
)->bottom 
= 0; 
 348     ((Rect
*)outBounds
)->right 
= 0; 
 351     strcpy( c_text 
, label 
) ; 
 352     if( wxApp::s_macDefaultEncodingIsPC 
) 
 354         wxMacConvertFromPCForControls( c_text 
) ; 
 358     c2pstrcpy( (StringPtr
) maclabel 
, c_text 
) ; 
 360     strcpy( (char *) maclabel 
, c_text 
) ; 
 361     c2pstr( (char *) maclabel 
) ; 
 365 void wxControl::MacPostControlCreate() 
 367     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, "No valid mac control" ) ; 
 369     if ( IsKindOf( CLASSINFO( wxScrollBar 
) ) ) 
 373     else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox 
) ) || IsKindOf( CLASSINFO( wxRadioBox 
) ) || IsKindOf( CLASSINFO( wxButton 
) ) ) ) 
 375         ControlFontStyleRec     controlstyle 
; 
 376         controlstyle
.flags 
= kControlUseFontMask 
; 
 377         controlstyle
.font 
= kControlFontSmallBoldSystemFont 
; 
 379         ::SetControlFontStyle( (ControlHandle
) m_macControl 
, &controlstyle 
) ; 
 383         ControlFontStyleRec     controlstyle 
; 
 384         controlstyle
.flags 
= kControlUseFontMask 
; 
 385         controlstyle
.font 
= kControlFontSmallSystemFont 
; 
 387         ::SetControlFontStyle( (ControlHandle
) m_macControl 
, &controlstyle 
) ; 
 389     ControlHandle container 
= (ControlHandle
) GetParent()->MacGetContainerForEmbedding() ; 
 390     wxASSERT_MSG( container 
!= NULL 
, wxT("No valid mac container control") ) ; 
 391     ::EmbedControl( (ControlHandle
) m_macControl 
, container 
) ; 
 392     m_macControlIsShown  
= true ; 
 394     wxAssociateControlWithMacControl( (ControlHandle
) m_macControl 
, this ) ; 
 395         if ( wxMacSetupControlBackgroundUPP 
== NULL 
) 
 397                 wxMacSetupControlBackgroundUPP 
= NewControlColorUPP( wxMacSetupControlBackground 
) ; 
 399         if ( wxMacControlActionUPP 
== NULL 
) 
 401             wxMacControlActionUPP 
= NewControlDefUPP( wxMacControlDefintion 
) ; 
 405     only working under classic carbon 
 406     m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; 
 407     (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ; 
 410     m_macControlAction 
= *(**(ControlHandle
)m_macControl
).contrlDefProc 
; 
 413     cdef 
= (cdefHandle
) NewHandle( sizeof(cdefRec
) ) ; 
 414     if (  (**(ControlHandle
)m_macControl
).contrlDefProc 
!= NULL 
) 
 416       (**cdef
).instruction 
= 0x4EF9;  /* JMP instruction */ 
 417       (**cdef
).function 
= (void(*)()) wxMacControlActionUPP
; 
 418       (**(ControlHandle
)m_macControl
).contrlDefProc 
= (Handle
) cdef 
; 
 421         SetControlColorProc( (ControlHandle
) m_macControl 
, wxMacSetupControlBackgroundUPP 
) ; 
 423      // Adjust the controls size and position 
 424      wxPoint 
pos(m_x
, m_y
); 
 425      wxSize 
best_size( DoGetBestSize() ); 
 426      wxSize 
new_size( m_width
, m_height 
); 
 428      m_x 
= m_y 
= m_width 
= m_height 
= -1;  // Forces SetSize to move/size the control 
 430      if (new_size
.x 
== -1) { 
 431         new_size
.x 
= best_size
.x
; 
 433      if (new_size
.y 
== -1) { 
 434          new_size
.y 
= best_size
.y
; 
 437      SetSize(pos
.x
, pos
.y
, new_size
.x
, new_size
.y
); 
 439      UMAShowControl( (ControlHandle
) m_macControl 
) ; 
 443 void wxControl::MacAdjustControlRect()  
 445     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
 446     if ( m_width 
== -1 || m_height 
== -1 ) 
 448         Rect    bestsize 
= { 0 , 0 , 0 , 0 } ; 
 449         short   baselineoffset 
; 
 451         ::GetBestControlRect( (ControlHandle
) m_macControl 
, &bestsize 
, &baselineoffset 
) ; 
 453         if ( EmptyRect( &bestsize 
) ) 
 456             bestsize
.left 
= bestsize
.top 
= 0 ; 
 457             bestsize
.right 
= 16 ; 
 458             bestsize
.bottom 
= 16 ; 
 459             if ( IsKindOf( CLASSINFO( wxScrollBar 
) ) ) 
 461                 bestsize
.bottom 
= 16 ; 
 463             else if ( IsKindOf( CLASSINFO( wxSpinButton 
) ) ) 
 465                 bestsize
.bottom 
= 24 ;  
 471             if ( IsKindOf( CLASSINFO( wxButton 
) ) ) 
 473                 m_width 
= m_label
.Length() * 8 + 12 ; 
 477             else if ( IsKindOf( CLASSINFO( wxStaticText 
) ) ) 
 479                 m_width 
= m_label
.Length() * 8 ; 
 482                 m_width 
= bestsize
.right 
- bestsize
.left 
; 
 484             m_width 
+= 2 * m_macHorizontalBorder 
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ; 
 486         if ( m_height 
== -1 ) 
 488             m_height 
= bestsize
.bottom 
- bestsize
.top 
; 
 492             m_height 
+= 2 * m_macVerticalBorder 
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ; 
 494                 MacUpdateDimensions() ;       
 495 //        UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height -  2 * m_macVerticalBorder ) ; 
 499 WXWidget 
wxControl::MacGetContainerForEmbedding()  
 502         return m_macControl 
; 
 504     return wxWindow::MacGetContainerForEmbedding() ; 
 507 void wxControl::MacUpdateDimensions()  
 509         // actually in the current systems this should never be possible, but later reparenting 
 510         // may become a reality 
 512         if ( (ControlHandle
) m_macControl 
== NULL 
) 
 515         if ( GetParent() == NULL 
) 
 518     WindowRef rootwindow 
= (WindowRef
) MacGetRootWindow() ; 
 519     if ( rootwindow 
== NULL 
) 
 523     GetControlBounds( (ControlHandle
) m_macControl 
, &oldBounds 
) ;  
 525     int new_x 
= m_x 
+ MacGetLeftBorderSize() + m_macHorizontalBorder 
; 
 526     int new_y 
= m_y 
+ MacGetTopBorderSize() + m_macVerticalBorder 
; 
 527     int new_width 
= m_width 
- MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder 
; 
 528     int new_height 
= m_height 
- MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder 
; 
 530     GetParent()->MacWindowToRootWindow( & new_x 
, & new_y 
) ; 
 531     bool doMove 
= new_x 
!= oldBounds
.left 
|| new_y 
!= oldBounds
.top 
; 
 532     bool doResize 
=  ( oldBounds
.right 
- oldBounds
.left 
) != new_width 
|| (oldBounds
.bottom 
- oldBounds
.top 
) != new_height 
; 
 533         if ( doMove 
|| doResize 
) 
 535                 InvalWindowRect( rootwindow
, &oldBounds 
) ; 
 538                         UMAMoveControl( (ControlHandle
) m_macControl 
, new_x 
, new_y 
) ; 
 542                         UMASizeControl( (ControlHandle
) m_macControl 
, new_width 
, new_height 
) ; 
 547 void wxControl::MacSuperChangedPosition()  
 549         MacUpdateDimensions() ; 
 550     wxWindow::MacSuperChangedPosition() ; 
 553 void wxControl::MacSuperEnabled( bool enabled 
)  
 556     wxWindow::MacSuperEnabled( enabled 
) ; 
 559 void  wxControl::MacSuperShown( bool show 
)  
 561     if ( (ControlHandle
) m_macControl 
) 
 565             if ( m_macControlIsShown 
) 
 567                 ::UMAHideControl( (ControlHandle
) m_macControl 
) ; 
 568                 m_macControlIsShown 
= false ; 
 573             if ( MacIsReallyShown() && !m_macControlIsShown 
) 
 575                 ::UMAShowControl( (ControlHandle
) m_macControl 
) ; 
 576                 m_macControlIsShown 
= true ; 
 581     wxWindow::MacSuperShown( show 
) ; 
 584 void  wxControl::DoSetSize(int x
, int y
, 
 585             int width
, int height
, 
 588     wxWindow::DoSetSize( x 
, y 
,width 
, height 
,sizeFlags 
) ; 
 592     if ( (ControlHandle) m_macControl == NULL ) 
 594         wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; 
 599      int new_x, new_y, new_width, new_height; 
 605      new_height = m_height; 
 607      if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) 
 616          if (x != -1)      new_x      = x; 
 617          if (y != -1)      new_y      = y; 
 618          if (width != -1)  new_width  = width; 
 619          if (height != -1) new_height = height; 
 622      if(sizeFlags & wxSIZE_AUTO) 
 624          wxSize size = GetBestSize(); 
 625          if (sizeFlags & wxSIZE_AUTO_WIDTH) 
 627              if (width == -1)   new_width = size.x; 
 629          if (sizeFlags & wxSIZE_AUTO_HEIGHT) 
 631              if (height == -1)   new_height = size.y; 
 634      AdjustForParentClientOrigin(new_x, new_y, sizeFlags); 
 639          GetParent()->MacWindowToRootWindow(&mac_x, &mac_y); 
 641      GetControlBounds( (ControlHandle) m_macControl, &oldbounds); 
 642      oldbounds.right = oldbounds.left + m_width; 
 643      oldbounds.bottom = oldbounds.top + m_height; 
 646      bool doResize = false; 
 648      if ( mac_x != (oldbounds.left - m_macHorizontalBorder) || 
 649           mac_y != (oldbounds.top - m_macVerticalBorder) ) 
 653      if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder || 
 654           new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder) 
 659      if ( doMove || doResize ) 
 663          // Ensure resize is within constraints 
 664          if ((m_minWidth != -1) && (new_width < m_minWidth)) { 
 665              new_width = m_minWidth; 
 667          if ((m_minHeight != -1) && (new_height < m_minHeight)) { 
 668              new_height = m_minHeight; 
 670          if ((m_maxWidth != -1) && (new_width > m_maxWidth)) { 
 671              new_width = m_maxWidth; 
 673          if ((m_maxHeight != -1) && (new_height > m_maxHeight)) { 
 674              new_height = m_maxHeight; 
 682              UMAMoveControl( (ControlHandle) m_macControl, 
 683                             mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder); 
 685              wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); 
 686              event.SetEventObject(this); 
 687              GetEventHandler()->ProcessEvent(event) ; 
 692              m_height = new_height; 
 694              UMASizeControl( (ControlHandle) m_macControl, 
 695                              m_width - 2 * m_macHorizontalBorder, 
 696                              m_height -  2 * m_macVerticalBorder ) ; 
 699              wxSizeEvent event(wxSize(m_width, m_height), m_windowId); 
 700              event.SetEventObject(this); 
 701              GetEventHandler()->ProcessEvent(event); 
 709 bool  wxControl::Show(bool show
)  
 711     if ( !wxWindow::Show( show 
) ) 
 714     if ( (ControlHandle
) m_macControl 
) 
 718             if ( m_macControlIsShown 
) 
 720                 ::UMAHideControl( (ControlHandle
) m_macControl 
) ; 
 721                 m_macControlIsShown 
= false ; 
 726             if ( MacIsReallyShown() && !m_macControlIsShown 
) 
 728                 ::UMAShowControl( (ControlHandle
) m_macControl 
) ; 
 729                 m_macControlIsShown 
= true ; 
 736 bool  wxControl::Enable(bool enable
)  
 738     if ( !wxWindow::Enable(enable
) ) 
 741     if ( (ControlHandle
) m_macControl 
) 
 744             UMAActivateControl( (ControlHandle
) m_macControl 
) ; 
 746             UMADeactivateControl( (ControlHandle
) m_macControl 
) ; 
 751 void wxControl::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 753     wxWindow::Refresh( eraseBack 
, rect 
) ; 
 756 void wxControl::MacRedrawControl() 
 758     if ( (ControlHandle
) m_macControl 
&& MacGetRootWindow() && m_macControlIsShown 
) 
 760         wxClientDC 
dc(this) ; 
 761         wxMacPortSetter 
helper(&dc
) ; 
 762         wxMacWindowClipper 
clipper(this) ; 
 763         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; 
 764         UMADrawControl( (ControlHandle
) m_macControl 
) ; 
 768 void wxControl::OnPaint(wxPaintEvent
& event
) 
 770     if ( (ControlHandle
) m_macControl 
) 
 773         wxMacPortSetter 
helper(&dc
) ; 
 774         wxMacWindowClipper 
clipper(this) ; 
 775         wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; 
 776         UMADrawControl( (ControlHandle
) m_macControl 
) ; 
 783 void wxControl::OnEraseBackground(wxEraseEvent
& event
) 
 785     wxWindow::OnEraseBackground( event 
) ;  
 789 void  wxControl::OnKeyDown( wxKeyEvent 
&event 
)  
 791     if ( (ControlHandle
) m_macControl 
== NULL 
) 
 794     EventRecord 
*ev 
= (EventRecord
*) wxTheApp
->MacGetCurrentEvent() ; 
 797     keychar 
= short(ev
->message 
& charCodeMask
); 
 798     keycode 
= short(ev
->message 
& keyCodeMask
) >> 8 ; 
 800     ::HandleControlKey( (ControlHandle
) m_macControl 
, keycode 
, keychar 
, ev
->modifiers 
) ; 
 803 void  wxControl::OnMouseEvent( wxMouseEvent 
&event 
)  
 805     if ( (ControlHandle
) m_macControl 
== NULL 
) 
 811     if (event
.GetEventType() == wxEVT_LEFT_DOWN 
|| event
.GetEventType() == wxEVT_LEFT_DCLICK 
) 
 817         MacClientToRootWindow( &x 
, &y 
) ; 
 819         ControlHandle   control 
; 
 828         if ( !event
.m_leftDown 
&& !event
.m_rightDown 
) 
 829             modifiers  
|= btnState 
; 
 831         if ( event
.m_shiftDown 
) 
 832             modifiers 
|= shiftKey 
; 
 834         if ( event
.m_controlDown 
) 
 835             modifiers 
|= controlKey 
; 
 837         if ( event
.m_altDown 
) 
 838             modifiers 
|= optionKey 
; 
 840         if ( event
.m_metaDown 
) 
 841             modifiers 
|= cmdKey 
; 
 843             control 
= (ControlHandle
) m_macControl 
; 
 844             if ( control 
&& ::IsControlActive( control 
) ) 
 847                     controlpart 
= ::HandleControlClick( control 
, localwhere 
, modifiers 
, (ControlActionUPP
) -1 ) ; 
 848                     wxTheApp
->s_lastMouseDown 
= 0 ; 
 849                     if ( control 
&& controlpart 
!= kControlNoPart 
&&  
 850                         ! IsKindOf( CLASSINFO( wxScrollBar 
) )  
 851                     ) // otherwise we will get the event twice for scrollbar 
 853                         MacHandleControlClick( control 
, controlpart 
) ; 
 861 bool wxControl::MacCanFocus() const 
 863         { if ( (ControlHandle
) m_macControl 
== NULL 
)  
 870 void wxControl::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
)  
 872     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, "No valid mac control" ) ;