X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..f164c52bc761d08cbfe5b733198e9d21afc3c221:/src/mac/classic/control.cpp diff --git a/src/mac/classic/control.cpp b/src/mac/classic/control.cpp index 473bdec9fd..d5c0ca1880 100644 --- a/src/mac/classic/control.cpp +++ b/src/mac/classic/control.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: control.cpp +// Name: src/mac/classic/control.cpp // Purpose: wxControl class // Author: Stefan Csomor // Modified by: @@ -9,36 +9,38 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "control.h" -#endif +#include "wx/wxprec.h" -#include "wx/defs.h" +#ifdef __BORLANDC__ + #pragma hdrstop +#endif #include "wx/control.h" -#include "wx/panel.h" -#include "wx/app.h" -#include "wx/dc.h" -#include "wx/dcclient.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/panel.h" + #include "wx/dc.h" + #include "wx/dcclient.h" + #include "wx/button.h" + #include "wx/dialog.h" + #include "wx/scrolbar.h" + #include "wx/stattext.h" + #include "wx/statbox.h" + #include "wx/radiobox.h" + #include "wx/sizer.h" +#endif // WX_PRECOMP + #include "wx/notebook.h" #include "wx/tabctrl.h" -#include "wx/radiobox.h" #include "wx/spinbutt.h" -#include "wx/scrolbar.h" -#include "wx/button.h" -#include "wx/dialog.h" -#include "wx/statbox.h" -#include "wx/sizer.h" -#include "wx/stattext.h" - -#if !USE_SHARED_LIBRARY + IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) BEGIN_EVENT_TABLE(wxControl, wxWindow) - EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) - EVT_PAINT( wxControl::OnPaint ) + EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) + EVT_PAINT( wxControl::OnPaint ) END_EVENT_TABLE() -#endif #include "wx/mac/uma.h" #include "wx/mac/private.h" @@ -78,7 +80,7 @@ pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCod wxControl* wx = (wxControl*) GetControlReference( control ) ; if ( wx ) { - wx->MacHandleControlClick( control , partCode , true /* stillDown */ ) ; + wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; } } } @@ -88,7 +90,7 @@ ControlDefUPP wxMacControlActionUPP = NULL ; pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param) { - + wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ; if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) { @@ -138,7 +140,7 @@ pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessa } return status ; } - + wxControl::wxControl() { m_macControl = NULL ; @@ -167,7 +169,7 @@ bool wxControl::Create(wxWindow *parent, wxWindowID id, m_macControl = NULL ; m_macHorizontalBorder = 0 ; // additional pixels around the real control m_macVerticalBorder = 0 ; - + bool rval = wxWindow::Create(parent, id, pos, size, style, name); if ( parent ) { @@ -184,15 +186,15 @@ bool wxControl::Create(wxWindow *parent, wxWindowID id, wxControl::~wxControl() { - m_isBeingDeleted = TRUE; + m_isBeingDeleted = true; wxRemoveMacControlAssociation( this ) ; // If we delete an item, we should initialize the parent panel, // because it could now be invalid. - wxWindow *parent = GetParent() ; - if ( parent ) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw ) { - if (parent->GetDefaultItem() == (wxButton*) this) - parent->SetDefaultItem(NULL); + if ( tlw->GetDefaultItem() == (wxButton*) this) + tlw->SetDefaultItem(NULL); } if ( (ControlHandle) m_macControl ) { @@ -205,11 +207,11 @@ wxControl::~wxControl() void wxControl::SetLabel(const wxString& title) { - m_label = wxStripMenuCodes(title) ; + m_label = GetLabelText(title) ; if ( m_macControl ) { - UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ; + UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ; } Refresh() ; } @@ -218,7 +220,7 @@ wxSize wxControl::DoGetBestSize() const { if ( (ControlHandle) m_macControl == NULL ) return wxWindow::DoGetBestSize() ; - + Rect bestsize = { 0 , 0 , 0 , 0 } ; short baselineoffset ; int bestWidth, bestHeight ; @@ -236,12 +238,12 @@ wxSize wxControl::DoGetBestSize() const } else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) { - bestsize.bottom = 24 ; + bestsize.bottom = 24 ; } } bestWidth = bestsize.right - bestsize.left ; - + bestWidth += 2 * m_macHorizontalBorder ; bestHeight = bestsize.bottom - bestsize.top ; @@ -250,7 +252,7 @@ wxSize wxControl::DoGetBestSize() const bestHeight += 2 * m_macVerticalBorder; - + return wxSize(bestWidth, bestHeight); } @@ -288,11 +290,11 @@ void wxRemoveMacControlAssociation(wxControl *control) wxWinMacControlList->DeleteObject(control); } -void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , +void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, - const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) + const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) { m_label = label ; @@ -301,20 +303,20 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l m_height = size.y ; m_x = pos.x ; m_y = pos.y ; - + ((Rect*)outBounds)->top = -10; ((Rect*)outBounds)->left = -10; ((Rect*)outBounds)->bottom = 0; ((Rect*)outBounds)->right = 0; - wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ; + wxMacStringToPascal( GetLabelText(label) , maclabel ) ; } void wxControl::MacPostControlCreate() { wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; DoSetWindowVariant( m_windowVariant ) ; - /* + /* if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) { // no font @@ -324,19 +326,19 @@ void wxControl::MacPostControlCreate() ControlFontStyleRec controlstyle ; controlstyle.flags = kControlUseFontMask ; controlstyle.font = kControlFontSmallBoldSystemFont ; - + ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; } else { ControlFontStyleRec controlstyle ; controlstyle.flags = kControlUseFontMask ; - + if (IsKindOf( CLASSINFO( wxButton ) ) ) controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ; else controlstyle.font = kControlFontSmallSystemFont ; - + ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; } */ @@ -378,43 +380,43 @@ void wxControl::MacPostControlCreate() #endif #endif SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ; - + // Adjust the controls size and position wxPoint pos(m_x, m_y); wxSize best_size( DoGetBestSize() ); wxSize new_size( m_width, m_height ); - + m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control - + if (new_size.x == -1) { new_size.x = best_size.x; } if (new_size.y == -1) { new_size.y = best_size.y; } - + SetSize(pos.x, pos.y, new_size.x, new_size.y); - + #if wxUSE_UNICODE - UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ; + UMASetControlTitle( (ControlHandle) m_macControl , GetLabelText(m_label) , m_font.GetEncoding() ) ; #endif if ( m_macControlIsShown ) UMAShowControl( (ControlHandle) m_macControl ) ; - + SetCursor( *wxSTANDARD_CURSOR ) ; - + Refresh() ; } -void wxControl::MacAdjustControlRect() +void wxControl::MacAdjustControlRect() { wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; if ( m_width == -1 || m_height == -1 ) { Rect bestsize = { 0 , 0 , 0 , 0 } ; short baselineoffset ; - + ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; if ( EmptyRect( &bestsize ) ) @@ -429,7 +431,7 @@ void wxControl::MacAdjustControlRect() } else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) { - bestsize.bottom = 24 ; + bestsize.bottom = 24 ; } } @@ -437,17 +439,17 @@ void wxControl::MacAdjustControlRect() { if ( IsKindOf( CLASSINFO( wxButton ) ) ) { - m_width = m_label.Length() * 8 + 12 ; + m_width = m_label.length() * 8 + 12 ; if ( m_width < 70 ) m_width = 70 ; } else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) { - m_width = m_label.Length() * 8 ; + m_width = m_label.length() * 8 ; } else m_width = bestsize.right - bestsize.left ; - + m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ; } if ( m_height == -1 ) @@ -458,11 +460,11 @@ void wxControl::MacAdjustControlRect() m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ; } - MacUpdateDimensions() ; + MacUpdateDimensions() ; } } -WXWidget wxControl::MacGetContainerForEmbedding() +WXWidget wxControl::MacGetContainerForEmbedding() { if ( m_macControl ) return m_macControl ; @@ -470,29 +472,29 @@ WXWidget wxControl::MacGetContainerForEmbedding() return wxWindow::MacGetContainerForEmbedding() ; } -void wxControl::MacUpdateDimensions() +void wxControl::MacUpdateDimensions() { // actually in the current systems this should never be possible, but later reparenting // may become a reality - + if ( (ControlHandle) m_macControl == NULL ) return ; - + if ( GetParent() == NULL ) return ; - + WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; if ( rootwindow == NULL ) return ; - - Rect oldBounds ; - GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; - + + Rect oldBounds ; + GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; + int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ; int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ; int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ; int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ; - + GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ; bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ; bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ; @@ -510,19 +512,19 @@ void wxControl::MacUpdateDimensions() } } -void wxControl::MacSuperChangedPosition() +void wxControl::MacSuperChangedPosition() { MacUpdateDimensions() ; wxWindow::MacSuperChangedPosition() ; } -void wxControl::MacSuperEnabled( bool enabled ) +void wxControl::MacSuperEnabled( bool enabled ) { - Refresh(FALSE) ; + Refresh(false) ; wxWindow::MacSuperEnabled( enabled ) ; } -void wxControl::MacSuperShown( bool show ) +void wxControl::MacSuperShown( bool show ) { if ( (ControlHandle) m_macControl ) { @@ -543,7 +545,7 @@ void wxControl::MacSuperShown( bool show ) } } } - + wxWindow::MacSuperShown( show ) ; } @@ -572,11 +574,11 @@ void wxControl::DoSetSize(int x, int y, return ; } -bool wxControl::Show(bool show) +bool wxControl::Show(bool show) { if ( !wxWindow::Show( show ) ) - return FALSE ; - + return false ; + if ( (ControlHandle) m_macControl ) { if ( !show ) @@ -596,13 +598,13 @@ bool wxControl::Show(bool show) } } } - return TRUE ; + return true ; } -bool wxControl::Enable(bool enable) +bool wxControl::Enable(bool enable) { if ( !wxWindow::Enable(enable) ) - return FALSE; + return false; if ( (ControlHandle) m_macControl ) { @@ -611,7 +613,7 @@ bool wxControl::Enable(bool enable) else UMADeactivateControl( (ControlHandle) m_macControl ) ; } - return TRUE ; + return true ; } void wxControl::Refresh(bool eraseBack, const wxRect *rect) @@ -648,18 +650,18 @@ void wxControl::OnPaint(wxPaintEvent& event) } void wxControl::OnEraseBackground(wxEraseEvent& event) { - wxWindow::OnEraseBackground( event ) ; + wxWindow::OnEraseBackground( event ) ; } -void wxControl::OnKeyDown( wxKeyEvent &event ) +void wxControl::OnKeyDown( wxKeyEvent &event ) { if ( (ControlHandle) m_macControl == NULL ) return ; - + #if TARGET_CARBON char charCode ; - UInt32 keyCode ; + UInt32 keyCode ; UInt32 modifiers ; GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); @@ -667,7 +669,7 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ; - + #else EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; short keycode ; @@ -679,43 +681,43 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) #endif } -void wxControl::OnMouseEvent( wxMouseEvent &event ) +void wxControl::OnMouseEvent( wxMouseEvent &event ) { if ( (ControlHandle) m_macControl == NULL ) { event.Skip() ; return ; } - + if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { - + int x = event.m_x ; int y = event.m_y ; - + MacClientToRootWindow( &x , &y ) ; - + ControlHandle control ; Point localwhere ; SInt16 controlpart ; - + localwhere.h = x ; localwhere.v = y ; - + short modifiers = 0; - + if ( !event.m_leftDown && !event.m_rightDown ) modifiers |= btnState ; - + if ( event.m_shiftDown ) modifiers |= shiftKey ; - + if ( event.m_controlDown ) modifiers |= controlKey ; - + if ( event.m_altDown ) modifiers |= optionKey ; - + if ( event.m_metaDown ) modifiers |= cmdKey ; { @@ -725,9 +727,9 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) { controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; wxTheApp->s_lastMouseDown = 0 ; - if ( control && controlpart != kControlNoPart ) + if ( control && controlpart != kControlNoPart ) { - MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ; + MacHandleControlClick( (WXWidget) control , controlpart , false /* mouse not down anymore */ ) ; } } } @@ -735,19 +737,19 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) } else { - event.Skip() ; + event.Skip() ; } } bool wxControl::MacCanFocus() const { - if ( (ControlHandle) m_macControl == NULL ) - return true ; + if ( (ControlHandle) m_macControl == NULL ) + return true ; else - return false ; + return false ; } -void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) +void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) { wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; } @@ -758,57 +760,57 @@ void wxControl::DoSetWindowVariant( wxWindowVariant variant ) { wxWindow::SetWindowVariant( variant ) ; return ; - + } - m_windowVariant = variant ; + m_windowVariant = variant ; - ControlSize size ; - ControlFontStyleRec fontStyle; - fontStyle.flags = kControlUseFontMask ; + ControlSize size ; + ControlFontStyleRec fontStyle; + fontStyle.flags = kControlUseFontMask ; // we will get that from the settings later - // and make this NORMAL later, but first + // and make this NORMAL later, but first // we have a few calculations that we must fix - if ( variant == wxWINDOW_VARIANT_DEFAULT ) + if ( variant == wxWINDOW_VARIANT_NORMAL ) { if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) variant = wxWINDOW_VARIANT_NORMAL ; else variant = wxWINDOW_VARIANT_SMALL ; } - + switch ( variant ) { case wxWINDOW_VARIANT_NORMAL : - size = kControlSizeNormal; - fontStyle.font = kControlFontBigSystemFont; + size = kControlSizeNormal; + fontStyle.font = kControlFontBigSystemFont; break ; case wxWINDOW_VARIANT_SMALL : - size = kControlSizeSmall; - fontStyle.font = kControlFontSmallSystemFont; + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; break ; case wxWINDOW_VARIANT_MINI : if (UMAGetSystemVersion() >= 0x1030 ) { - size = 3 ; // not always defined in the header - fontStyle.font = -5 ; // not always defined in the header + size = 3 ; // not always defined in the header + fontStyle.font = -5 ; // not always defined in the header } else { - size = kControlSizeSmall; - fontStyle.font = kControlFontSmallSystemFont; + size = kControlSizeSmall; + fontStyle.font = kControlFontSmallSystemFont; } break; break ; case wxWINDOW_VARIANT_LARGE : - size = kControlSizeLarge; - fontStyle.font = kControlFontBigSystemFont; + size = kControlSizeLarge; + fontStyle.font = kControlFontBigSystemFont; break ; default: wxFAIL_MSG(_T("unexpected window variant")); break ; } - ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); - ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle ); + ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); + ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle ); }