+// ------------------------
+wxList *wxWinMacControlList = NULL;
+wxControl *wxFindControlFromMacControl(ControlHandle inControl )
+{
+ wxNode *node = wxWinMacControlList->Find((long)inControl);
+ if (!node)
+ return NULL;
+ return (wxControl *)node->Data();
+}
+
+void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
+{
+ // adding NULL WindowRef is (first) surely a result of an error and
+ // (secondly) breaks menu command processing
+ wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" );
+
+ if ( !wxWinMacControlList->Find((long)inControl) )
+ wxWinMacControlList->Append((long)inControl, control);
+}
+
+void wxRemoveMacControlAssociation(wxControl *control)
+{
+ wxWinMacControlList->DeleteObject(control);
+}
+
+void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
+ const wxPoint& pos,
+ const wxSize& size, long style,
+ const wxValidator& validator,
+ const wxString& name , Rect *outBounds , StringPtr maclabel )
+{
+ m_label = label ;
+ SetName(name);
+ if ( &validator )
+ SetValidator(validator);
+
+ m_windowStyle = style;
+ parent->AddChild((wxButton *)this);
+
+ m_backgroundColour = parent->GetBackgroundColour() ;
+ m_foregroundColour = parent->GetForegroundColour() ;
+
+ if (id == -1)
+ m_windowId = NewControlId();
+ else
+ m_windowId = id;
+
+ m_width = size.x ;
+ m_height = size.y ;
+ int x = pos.x ;
+ int y = pos.y ;
+ AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING);
+ m_x = x ;
+ m_y = y ;
+
+
+ Point localOrigin ;
+ Rect clipRect ;
+
+ parent->MacClientToRootWindow( &x , &y ) ;
+ outBounds->top = y + m_macVerticalBorder ;
+ outBounds->left = x + m_macHorizontalBorder ;
+ outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder;
+ outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ;
+
+ strcpy( (char*) maclabel , label ) ;
+ if( wxApp::s_macDefaultEncodingIsPC )
+ {
+ wxMacConvertFromPCForControls( (char*) maclabel ) ;
+ }
+
+ c2pstr( (char*) maclabel ) ;
+}
+
+void wxControl::MacPostControlCreate()
+{
+ wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+
+ if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
+ {
+ // no font
+ }
+ else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
+ {
+ ControlFontStyleRec controlstyle ;
+ controlstyle.flags = kControlUseFontMask ;
+ controlstyle.font = kControlFontSmallBoldSystemFont ;
+
+ ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
+ }
+ else
+ {
+ ControlFontStyleRec controlstyle ;
+ controlstyle.flags = kControlUseFontMask ;
+ controlstyle.font = kControlFontSmallSystemFont ;
+
+ ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
+ }
+ ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+ wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
+ ::UMAEmbedControl( m_macControl , container ) ;
+ MacAdjustControlRect() ;
+ wxAssociateControlWithMacControl( m_macControl , this ) ;
+}
+
+void wxControl::MacAdjustControlRect()
+{
+ wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
+ if ( m_width == -1 || m_height == -1 )
+ {
+ Rect bestsize = { 0 , 0 , 0 , 0 } ;
+ short baselineoffset ;
+
+ UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
+
+ if ( EmptyRect( &bestsize ) )
+ {
+ baselineoffset = 0;
+ bestsize.left = bestsize.top = 0 ;
+ bestsize.right = 16 ;
+ bestsize.bottom = 16 ;
+ if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
+ {
+ bestsize.bottom = 16 ;
+ }
+ else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
+ {
+ bestsize.bottom = 24 ;
+ }
+ }
+
+ if ( m_width == -1 )
+ {
+ if ( IsKindOf( CLASSINFO( wxButton ) ) )
+ {
+ m_width = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder;
+ }
+ else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
+ {
+ m_width = m_label.Length() * 8 ;
+ }
+ else
+ m_width = bestsize.right - bestsize.left + 2 * m_macHorizontalBorder;
+ }
+ if ( m_height == -1 )
+ {
+ m_height = bestsize.bottom - bestsize.top ;
+ if ( m_height < 10 )
+ m_height = 13 ;
+
+ m_height += 2 * m_macVerticalBorder;
+ }
+
+ wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
+ if ( helper.Ok() )
+ {
+ UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
+ }
+ }
+}
+ControlHandle wxControl::MacGetContainerForEmbedding()
+{
+ if ( m_macControl )
+ return m_macControl ;
+
+ return wxWindow::MacGetContainerForEmbedding() ;
+}
+
+void wxControl::MacSuperChangedPosition()
+{
+ if ( m_macControl )
+ {
+ int former_mac_x = (**m_macControl).contrlRect.left ;
+ int former_mac_y = (**m_macControl).contrlRect.top ;
+ int mac_x = m_x ;
+ int mac_y = m_y ;
+ GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
+
+ WindowRef rootwindow = GetMacRootWindow() ;
+ wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
+ UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
+ wxMacDrawingHelper focus( wxrootwindow ) ;
+
+ if ( mac_x != former_mac_x || mac_y != former_mac_y )
+ {
+ {
+ Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
+ InvalRect( &inval ) ;
+ }
+ UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
+ {
+ Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
+ InvalRect( &inval ) ;
+ }
+ }
+ if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
+ {
+ }
+ else
+ {
+ UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
+ }
+ }
+
+ wxWindow::MacSuperChangedPosition() ;
+}
+
+void wxControl::MacSuperEnabled( bool enabled )