X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/51abe921b849be69f02c174365c9a7bc8b46bd08..49a91764b57168d9f441578001b3206a7330ee70:/src/mac/carbon/control.cpp diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 037d95784f..f0714b067a 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -13,10 +13,22 @@ #pragma implementation "control.h" #endif +#include "wx/defs.h" + #include "wx/control.h" +#include "wx/panel.h" +#include "wx/app.h" +#include "wx/dc.h" #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) @@ -34,6 +46,7 @@ END_EVENT_TABLE() ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; +pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) { if ( partCode != 0) @@ -48,9 +61,9 @@ pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCod wxControl::wxControl() { - m_macControl = NULL ; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; + m_macControl = NULL ; + m_macHorizontalBorder = 0 ; // additional pixels around the real control + m_macVerticalBorder = 0 ; m_backgroundColour = *wxWHITE; m_foregroundColour = *wxBLACK; #if WXWIN_COMPATIBILITY @@ -59,10 +72,32 @@ wxControl::wxControl() if ( wxMacLiveScrollbarActionUPP == NULL ) { +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) + wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); +#else wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; +#endif } } +bool wxControl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + 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 (rval) { +#if wxUSE_VALIDATORS + SetValidator(validator); +#endif + } + return rval; +} + wxControl::~wxControl() { m_isBeingDeleted = TRUE; @@ -95,14 +130,18 @@ void wxControl::SetLabel(const wxString& title) else label = title ; - strcpy( (char*) maclabel , label ) ; - c2pstr( (char*) maclabel ) ; - +#if TARGET_CARBON + c2pstrcpy( (StringPtr) maclabel , label ) ; +#else + strcpy( (char *) maclabel , label ) ; + c2pstr( (char *) maclabel ) ; +#endif ::SetControlTitle( m_macControl , maclabel ) ; } + Refresh() ; } -wxSize wxControl::DoGetBestSize() +wxSize wxControl::DoGetBestSize() const { return wxSize(20, 20); } @@ -183,22 +222,25 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l 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 ) ; + char c_text[255]; + strcpy( c_text , label ) ; if( wxApp::s_macDefaultEncodingIsPC ) { - wxMacConvertFromPCForControls( (char*) maclabel ) ; + wxMacConvertFromPCForControls( c_text ) ; } - c2pstr( (char*) maclabel ) ; +#if TARGET_CARBON + c2pstrcpy( (StringPtr) maclabel , c_text ) ; +#else + strcpy( (char *) maclabel , c_text ) ; + c2pstr( (char *) maclabel ) ; +#endif } void wxControl::MacPostControlCreate() @@ -209,7 +251,7 @@ void wxControl::MacPostControlCreate() { // no font } - else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) { ControlFontStyleRec controlstyle ; controlstyle.flags = kControlUseFontMask ; @@ -228,8 +270,10 @@ void wxControl::MacPostControlCreate() ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; ::UMAEmbedControl( m_macControl , container ) ; + m_macControlIsShown = true ; MacAdjustControlRect() ; wxAssociateControlWithMacControl( m_macControl , this ) ; + UMAShowControl( m_macControl ) ; } void wxControl::MacAdjustControlRect() @@ -262,14 +306,18 @@ void wxControl::MacAdjustControlRect() { if ( IsKindOf( CLASSINFO( wxButton ) ) ) { - m_width = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; + 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 ; } else - m_width = bestsize.right - bestsize.left + 2 * m_macHorizontalBorder; + m_width = bestsize.right - bestsize.left ; + + m_width += 2 * m_macHorizontalBorder ; } if ( m_height == -1 ) { @@ -283,7 +331,7 @@ void wxControl::MacAdjustControlRect() wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; if ( helper.Ok() ) { - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; } } } @@ -299,8 +347,10 @@ void wxControl::MacSuperChangedPosition() { if ( m_macControl ) { - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int mac_x = m_x ; int mac_y = m_y ; GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; @@ -312,15 +362,15 @@ void wxControl::MacSuperChangedPosition() 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 ) ; - } + { + Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; + InvalWindowRect( rootwindow , &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 } ; + InvalWindowRect( rootwindow , &inval ) ; + } } if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) { @@ -365,27 +415,32 @@ void wxControl::MacSuperEnabled( bool enabled ) } } wxWindow::MacSuperEnabled( enabled ) ; - */ +*/ } void wxControl::MacSuperShown( bool show ) { - /* if ( m_macControl ) { if ( !show ) { - ::UMAHideControl( m_macControl ) ; + if ( m_macControlIsShown ) + { + ::UMAHideControl( m_macControl ) ; + m_macControlIsShown = false ; + } } else { - if ( m_macShown ) + if ( MacIsReallyShown() && !m_macControlIsShown ) + { ::UMAShowControl( m_macControl ) ; + m_macControlIsShown = true ; + } } } wxWindow::MacSuperShown( show ) ; - */ } void wxControl::DoSetSize(int x, int y, @@ -407,8 +462,10 @@ void wxControl::DoSetSize(int x, int y, int former_w = m_width ; int former_h = m_height ; - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -419,9 +476,9 @@ void wxControl::DoSetSize(int x, int y, int actualHeight = height; int actualX = x; int actualY = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualX = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; if (width == -1) actualWidth = currentW ; @@ -432,7 +489,8 @@ void wxControl::DoSetSize(int x, int y, return ; AdjustForParentClientOrigin(actualX, actualY, sizeFlags); - wxMacDrawingHelper focus( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; + WindowRef macrootwindow = GetMacRootWindow() ; + wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; int mac_x = actualX ; int mac_y = actualY ; @@ -440,15 +498,15 @@ void wxControl::DoSetSize(int x, int y, 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 ) ; - } + { + Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; + InvalWindowRect( macrootwindow, &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 } ; + InvalWindowRect(macrootwindow, &inval ) ; + } } if ( actualX != former_x || actualY != former_y ) @@ -458,29 +516,31 @@ void wxControl::DoSetSize(int x, int y, MacRepositionScrollBars() ; // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..) - wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + wxPoint point(m_x, m_y); + wxMoveEvent event(point, m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); } if ( actualWidth != former_w || actualHeight != former_h ) { { Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow, &inval ) ; } m_width = actualWidth ; m_height = actualHeight ; - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow , &inval ) ; } MacRepositionScrollBars() ; - wxSizeEvent event(wxSize(m_width, m_height), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + wxSize size(m_width, m_height); + wxSizeEvent event(size, m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); } if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) { @@ -498,10 +558,22 @@ bool wxControl::Show(bool show) if ( m_macControl ) { - if ( show ) - ::UMAShowControl( m_macControl ) ; + if ( !show ) + { + if ( m_macControlIsShown ) + { + ::UMAHideControl( m_macControl ) ; + m_macControlIsShown = false ; + } + } else - ::UMAHideControl( m_macControl ) ; + { + if ( MacIsReallyShown() && !m_macControlIsShown ) + { + ::UMAShowControl( m_macControl ) ; + m_macControlIsShown = true ; + } + } } return TRUE ; } @@ -513,21 +585,10 @@ bool wxControl::Enable(bool enable) if ( m_macControl ) { - - if ( UMAHasAppearance() ) - { - if ( enable ) - ::ActivateControl( m_macControl ) ; - else - ::DeactivateControl( m_macControl ) ; - } + if ( enable ) + UMAActivateControl( m_macControl ) ; else - { - if ( enable ) - ::HiliteControl( m_macControl , 0 ) ; - else - ::HiliteControl( m_macControl , 255 ) ; - } + UMADeactivateControl( m_macControl ) ; } return TRUE ; } @@ -544,7 +605,7 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect) } } -void wxControl::OnPaint(wxPaintEvent& event) +void wxControl::MacRedrawControl() { if ( m_macControl ) { @@ -555,6 +616,7 @@ void wxControl::OnPaint(wxPaintEvent& event) if ( win ) { wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 SetOrigin( 0 , 0 ) ; bool hasTabBehind = false ; @@ -577,6 +639,48 @@ void wxControl::OnPaint(wxPaintEvent& event) parent = parent->GetParent() ; } + UMADrawControl( m_macControl ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; + } + } + } +} + +void wxControl::OnPaint(wxPaintEvent& event) +{ + if ( m_macControl ) + { + WindowRef window = GetMacRootWindow() ; + if ( window ) + { + wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { + wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 + SetOrigin( 0 , 0 ) ; + + + bool hasTabBehind = false ; + wxWindow* parent = GetParent() ; + while ( parent ) + { + if( parent->MacGetWindowData() ) + { + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + break ; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) + { + if ( ((wxControl*)parent)->m_macControl ) + SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; + break ; + } + + parent = parent->GetParent() ; + } + UMADrawControl( m_macControl ) ; UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; } @@ -618,7 +722,7 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) return ; } - if (event.GetEventType() == wxEVT_LEFT_DOWN ) + if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { int x = event.m_x ; @@ -654,10 +758,12 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) controlpart = FindControl( localwhere , window , &control ) ; { + /* if ( AcceptsFocus() && FindFocus() != this ) { SetFocus() ; } + */ if ( control && UMAIsControlActive( control ) ) { {