From 5ca0d8122ab2ecbce178aa9f21f13270c4ffaca0 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 11 Jul 2004 16:19:18 +0000 Subject: [PATCH] further separating implementation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/private.h | 78 +- include/wx/mac/carbon/textctrl.h | 9 +- include/wx/mac/carbon/window.h | 2 +- src/mac/carbon/bmpbuttn.cpp | 2 +- src/mac/carbon/button.cpp | 9 +- src/mac/carbon/checkbox.cpp | 2 +- src/mac/carbon/checklst.cpp | 21 +- src/mac/carbon/choice.cpp | 2 +- src/mac/carbon/control.cpp | 14 +- src/mac/carbon/gauge.cpp | 2 +- src/mac/carbon/glcanvas.cpp | 4 +- src/mac/carbon/gsocket.c | 1 - src/mac/carbon/listbox.cpp | 42 +- src/mac/carbon/notebmac.cpp | 23 +- src/mac/carbon/radiobox.cpp | 2 +- src/mac/carbon/radiobut.cpp | 8 +- src/mac/carbon/scrolbar.cpp | 26 +- src/mac/carbon/slider.cpp | 14 +- src/mac/carbon/spinbutt.cpp | 10 +- src/mac/carbon/statbox.cpp | 2 +- src/mac/carbon/statlmac.cpp | 2 +- src/mac/carbon/stattext.cpp | 8 +- src/mac/carbon/tabctrl.cpp | 2 +- src/mac/carbon/textctrl.cpp | 3475 +++++++++++++++++------------- src/mac/carbon/tglbtn.cpp | 6 +- src/mac/carbon/toplevel.cpp | 8 +- src/mac/carbon/utils.cpp | 310 +++ src/mac/carbon/window.cpp | 299 ++- 28 files changed, 2554 insertions(+), 1829 deletions(-) diff --git a/include/wx/mac/carbon/private.h b/include/wx/mac/carbon/private.h index a274d0218f..0d84f0ee92 100644 --- a/include/wx/mac/carbon/private.h +++ b/include/wx/mac/carbon/private.h @@ -336,12 +336,20 @@ public : virtual ~wxMacControl() { } - bool Ok() const { return m_controlRef != NULL ; } + virtual void Dispose() ; + + bool Ok() const { return GetControlRef() != NULL ; } + + virtual ControlRef * GetControlRefAddr() { return &m_controlRef; } + virtual ControlRef GetControlRef() const { return m_controlRef ; } + + virtual void SetReference( SInt32 data ) ; + /* void operator= (ControlRef c) { m_controlRef = c ; } operator ControlRef () { return m_controlRef; } operator ControlRef * () { return &m_controlRef; } - + */ // accessing data and values virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ; @@ -363,6 +371,10 @@ public : virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ; virtual void SetRange( SInt32 minimum , SInt32 maximum ) ; + virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; + virtual bool HasFocus() const ; + virtual bool NeedsFocusRect() const ; + // templated helpers Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const @@ -395,7 +407,67 @@ public : virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ) ; virtual void VisibilityChanged( bool shown ) ; virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ; - + virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) ; + void SetActionProc( ControlActionUPP actionProc ) ; + void SetViewSize( SInt32 viewSize ) ; + SInt32 GetViewSize() const ; + + virtual bool IsVisible() const ; + virtual void SetVisibility( bool visible , bool redraw ) ; + virtual bool IsEnabled() const ; + virtual bool IsActive() const ; + virtual void Enable( bool enable ) ; + + // invalidates this control and all children + virtual void InvalidateWithChildren() ; + virtual void SetDrawingEnabled( bool enable ) ; + virtual bool GetNeedsDisplay() const ; + virtual void SetNeedsDisplay( bool needsDisplay , RgnHandle where = NULL ) ; + + virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ; + + virtual void GetRect( Rect *r ) ; + virtual void SetRect( Rect *r ) ; + virtual void GetRectInWindowCoords( Rect *r ) ; + virtual void GetBestRect( Rect *r ) ; + virtual void SetTitle( const wxString &title ) ; + // converts from Toplevel-Content relative to local + static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to ) ; + + virtual void GetFeatures( UInt32 *features ) ; + virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ) ; + virtual OSStatus SetZOrder( bool above , wxMacControl* other ) ; + // to be moved into a databrowser subclass + + virtual OSStatus SetSelectionFlags( DataBrowserSelectionFlags ) ; + virtual OSStatus AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc, + DataBrowserTableViewColumnIndex position ) ; + virtual OSStatus AutoSizeListViewColumns() ; + virtual OSStatus SetHasScrollBars( bool horiz , bool vert ) ; + virtual OSStatus SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) ; + virtual OSStatus SetListViewHeaderBtnHeight(UInt16 height) ; + virtual OSStatus SetCallbacks(const DataBrowserCallbacks * callbacks) ; + virtual OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty, + DataBrowserPropertyID propertyID ) ; + virtual OSStatus AddItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty ) ; + virtual OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty ) ; + virtual OSStatus RevealItem( DataBrowserItemID item, + DataBrowserPropertyID propertyID, + DataBrowserRevealOptions options ) ; + virtual bool IsItemSelected( DataBrowserItemID item ) ; + virtual OSStatus SetSelectedItems(UInt32 numItems, + const DataBrowserItemID * items, + DataBrowserSetOption operation ) ; + + // to be moved into a tab control class + + virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ; protected : ControlRef m_controlRef ; wxFont m_font ; diff --git a/include/wx/mac/carbon/textctrl.h b/include/wx/mac/carbon/textctrl.h index 7bf124a98a..b3bb9905e0 100644 --- a/include/wx/mac/carbon/textctrl.h +++ b/include/wx/mac/carbon/textctrl.h @@ -20,6 +20,8 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr; +class wxMacTextControl ; + // Single-line text item class WXDLLEXPORT wxTextCtrl: public wxTextCtrlBase { @@ -169,6 +171,7 @@ public: virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; virtual void MacControlUserPaneBackgroundProc(void* info) ; + wxMacTextControl* GetPeer() const { return (wxMacTextControl*) m_peer ; } protected: // common part of all ctors void Init(); @@ -180,14 +183,8 @@ protected: // flag is set to true when the user edits the controls contents bool m_dirty; - WXWidget m_scrollView ; - WXWidget m_textView ; - - void* m_macTXN ; unsigned long m_maxLength ; // need to make this public because of the current implementation via callbacks -public : - void* m_macTXNvars ; private : DECLARE_EVENT_TABLE() }; diff --git a/include/wx/mac/carbon/window.h b/include/wx/mac/carbon/window.h index 4dd02468ef..26ec619fdb 100644 --- a/include/wx/mac/carbon/window.h +++ b/include/wx/mac/carbon/window.h @@ -205,7 +205,7 @@ public: { return (m_hScrollBar == sb || m_vScrollBar == sb) ; } wxList& GetSubcontrols() { return m_subControls; } - virtual void MacInstallEventHandler() ; + virtual void MacInstallEventHandler(WXWidget native) ; virtual void MacRedrawControl(); WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; } void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ; diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index a8dc4295c4..2e9f9c6675 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -76,7 +76,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit m_peer = new wxMacControl() ; verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , - kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , *m_peer ) ); + kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 6c3d6f2649..3acf5495cc 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -42,14 +42,14 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_peer = new wxMacControl() ; if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) { - verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , *m_peer ) ); + verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) ); } else { ControlButtonContentInfo info ; info.contentType = kControlNoContent ; verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""), - kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , *m_peer ) ); + kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); } wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; @@ -97,8 +97,7 @@ wxSize wxButton::DoGetBestSize() const } Rect bestsize = { 0 , 0 , 0 , 0 } ; - short baselineoffset ; - ::GetBestControlRect( *m_peer , &bestsize , &baselineoffset ) ; + m_peer->GetBestRect( &bestsize ) ; int wBtn = 0 ; if ( EmptyRect( &bestsize ) ) @@ -107,7 +106,7 @@ wxSize wxButton::DoGetBestSize() const } else { - sz.x = bestsize.right - bestsize.left ; + wBtn = bestsize.right - bestsize.left ; sz.y = bestsize.bottom - bestsize.top ; } diff --git a/src/mac/carbon/checkbox.cpp b/src/mac/carbon/checkbox.cpp index 11ed5fc74f..9c4f5f75d2 100644 --- a/src/mac/carbon/checkbox.cpp +++ b/src/mac/carbon/checkbox.cpp @@ -45,7 +45,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; m_peer = new wxMacControl() ; verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , - CFSTR("") , 0 , false , *m_peer ) ); + CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) ); m_peer->SetMaximum( maxValue ) ; diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index bad85ae455..8ac00dd224 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -233,7 +233,7 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; m_peer = new wxMacControl() ; - verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , *m_peer ) ); + verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , m_peer->GetControlRefAddr() ) ); DataBrowserSelectionFlags options = kDataBrowserDragSelect ; @@ -249,7 +249,7 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, { options += kDataBrowserSelectOnlyOne ; } - verify_noerr(SetDataBrowserSelectionFlags (*m_peer, options ) ); + verify_noerr(m_peer->SetSelectionFlags( options ) ); DataBrowserListViewColumnDesc columnDesc ; columnDesc.headerBtnDesc.titleOffset = 0; @@ -273,7 +273,7 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType; columnDesc.propertyDesc.propertyFlags = kDataBrowserPropertyIsMutable | kDataBrowserTableViewSelectionColumn | kDataBrowserDefaultPropertyFlags; - verify_noerr(::AddDataBrowserListViewColumn(*m_peer, &columnDesc, kDataBrowserListViewAppendColumn) ) ; + verify_noerr( m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ; // text column @@ -289,12 +289,12 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, ; - verify_noerr(::AddDataBrowserListViewColumn(*m_peer, &columnDesc, kDataBrowserListViewAppendColumn) ) ; + verify_noerr( m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ; - verify_noerr(::AutoSizeDataBrowserListViewColumns( *m_peer ) ) ; - verify_noerr(::SetDataBrowserHasScrollBars( *m_peer , false , true ) ) ; - verify_noerr(::SetDataBrowserTableViewHiliteStyle( *m_peer, kDataBrowserTableViewFillHilite ) ) ; - verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( *m_peer , 0 ) ) ; + verify_noerr( m_peer->AutoSizeListViewColumns() ) ; + verify_noerr( m_peer->SetHasScrollBars( false , true ) ) ; + verify_noerr( m_peer->SetTableViewHiliteStyle( kDataBrowserTableViewFillHilite ) ) ; + verify_noerr( m_peer->SetListViewHeaderBtnHeight(0 ) ) ; DataBrowserCallbacks callbacks ; callbacks.version = kDataBrowserLatestCallbacks; @@ -306,7 +306,7 @@ bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, #else NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; #endif - SetDataBrowserCallbacks(*m_peer, &callbacks); + m_peer->SetCallbacks( &callbacks); MacPostControlCreate(pos,size) ; @@ -337,13 +337,12 @@ void wxCheckListBox::Check(size_t item, bool check) wxCHECK_RET( item < m_checks.GetCount(), _T("invalid index in wxCheckListBox::Check") ); - // intermediate var is needed to avoid compiler warning with VC++ bool isChecked = m_checks[item] != 0; if ( check != isChecked ) { m_checks[item] = check; UInt32 id = m_idArray[item] ; - verify_noerr( ::UpdateDataBrowserItems( *m_peer , kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->UpdateItems(kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; } } diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index c0c21a5377..72c34a84a7 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -69,7 +69,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr ( CreatePopupButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - -12345 , false /* no variable width */ , 0 , 0 , 0 , *m_peer ) ); + -12345 , false /* no variable width */ , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); m_macPopUpMenuHandle = NewUniqueMenu() ; diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 39f3a344d2..e7fa4ffe52 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -88,8 +88,6 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) if ( m_peer == NULL || !m_peer->Ok() ) return ; -#if TARGET_CARBON - char charCode ; UInt32 keyCode ; UInt32 modifiers ; @@ -98,16 +96,6 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); - ::HandleControlKey( *m_peer , keyCode , charCode , modifiers ) ; - -#else - EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - - ::HandleControlKey( *m_peer , keycode , keychar , ev->modifiers ) ; -#endif + m_peer->HandleKey( keyCode , charCode , modifiers ) ; } diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp index 9371fb247d..da6aa40dc0 100644 --- a/src/mac/carbon/gauge.cpp +++ b/src/mac/carbon/gauge.cpp @@ -44,7 +44,7 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; m_peer = new wxMacControl() ; verify_noerr ( CreateProgressBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , - GetValue() , 0 , GetRange() , false /* not indeterminate */ , *m_peer ) ); + GetValue() , 0 , GetRange() , false /* not indeterminate */ , m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp index 732de7df9f..facd34a510 100644 --- a/src/mac/carbon/glcanvas.cpp +++ b/src/mac/carbon/glcanvas.cpp @@ -331,7 +331,7 @@ bool wxGLCanvas::Show(bool show) } else { - if ( IsControlVisible( *m_peer ) && !m_macCanvasIsShown ) + if ( m_peer->IsVisible()&& !m_macCanvasIsShown ) { m_macCanvasIsShown = true ; SetViewport() ; @@ -343,7 +343,7 @@ bool wxGLCanvas::Show(bool show) void wxGLCanvas::MacVisibilityChanged() { - if ( !IsControlVisible( *m_peer ) ) + if ( !MacIsReallyShown() ) { if ( m_macCanvasIsShown ) { diff --git a/src/mac/carbon/gsocket.c b/src/mac/carbon/gsocket.c index 073d97c483..07fd19e193 100644 --- a/src/mac/carbon/gsocket.c +++ b/src/mac/carbon/gsocket.c @@ -163,7 +163,6 @@ pascal void OTInetEventHandler(void*s, OTEventCode event, OTResult result, void if ( event == kOTSyncIdleEvent ) { - YieldToAnyThread() ; return ; } diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index 4fe7f3e815..7be9b0d4b1 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -177,7 +177,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; m_peer = new wxMacControl() ; - verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , *m_peer ) ); + verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , m_peer->GetControlRefAddr() ) ); DataBrowserSelectionFlags options = kDataBrowserDragSelect ; if ( style & wxLB_MULTIPLE ) @@ -192,7 +192,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, { options += kDataBrowserSelectOnlyOne ; } - verify_noerr(SetDataBrowserSelectionFlags (*m_peer, options ) ); + verify_noerr(m_peer->SetSelectionFlags( options ) ); DataBrowserListViewColumnDesc columnDesc ; columnDesc.headerBtnDesc.titleOffset = 0; @@ -220,11 +220,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, kDataBrowserTableViewSelectionColumn ; - verify_noerr(::AddDataBrowserListViewColumn(*m_peer, &columnDesc, kDataBrowserListViewAppendColumn) ) ; - verify_noerr(::AutoSizeDataBrowserListViewColumns( *m_peer ) ) ; - verify_noerr(::SetDataBrowserHasScrollBars( *m_peer , false , true ) ) ; - verify_noerr(::SetDataBrowserTableViewHiliteStyle( *m_peer, kDataBrowserTableViewFillHilite ) ) ; - verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( *m_peer , 0 ) ) ; + verify_noerr(m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ; + verify_noerr(m_peer->AutoSizeListViewColumns() ) ; + verify_noerr(m_peer->SetHasScrollBars(false , true ) ) ; + verify_noerr(m_peer->SetTableViewHiliteStyle(kDataBrowserTableViewFillHilite ) ) ; + verify_noerr(m_peer->SetListViewHeaderBtnHeight( 0 ) ) ; DataBrowserCallbacks callbacks ; callbacks.version = kDataBrowserLatestCallbacks; @@ -240,7 +240,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, #else NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; #endif - SetDataBrowserCallbacks(*m_peer, &callbacks); + m_peer->SetCallbacks( &callbacks); MacPostControlCreate(pos,size) ; @@ -256,7 +256,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { - SetControlReference( *m_peer , NULL ) ; + m_peer->SetReference( NULL ) ; FreeData() ; // avoid access during destruction if ( m_macList ) @@ -629,27 +629,27 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n) void wxListBox::MacDelete( int N ) { UInt32 id = m_idArray[N] ; - verify_noerr(::RemoveDataBrowserItems(*m_peer , kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ; m_idArray.RemoveAt( N ) ; } void wxListBox::MacInsert( int n , const wxString& text) { - verify_noerr(::AddDataBrowserItems( *m_peer , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; m_idArray.Insert( m_nextId , n ) ; ++m_nextId ; } void wxListBox::MacAppend( const wxString& text) { - verify_noerr(::AddDataBrowserItems( *m_peer , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->AddItems( kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; m_idArray.Add( m_nextId ) ; ++m_nextId ; } void wxListBox::MacClear() { - verify_noerr(::RemoveDataBrowserItems(*m_peer , kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->RemoveItems( kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ; m_idArray.Empty() ; } @@ -662,26 +662,26 @@ void wxListBox::MacSetSelection( int n , bool select ) if ( n >= 0 ) { UInt32 idOld = m_idArray[n] ; - SetDataBrowserSelectedItems(*m_peer , 1 , & idOld , kDataBrowserItemsRemove ) ; + m_peer->SetSelectedItems( 1 , & idOld , kDataBrowserItemsRemove ) ; } } - if ( ::IsDataBrowserItemSelected( *m_peer , id ) != select ) + if ( m_peer->IsItemSelected( id ) != select ) { - verify_noerr(::SetDataBrowserSelectedItems(*m_peer , 1 , & id , kDataBrowserItemsToggle ) ) ; + verify_noerr(m_peer->SetSelectedItems( 1 , & id , kDataBrowserItemsToggle ) ) ; } MacScrollTo( n ) ; } bool wxListBox::MacIsSelected( int n ) const { - return ::IsDataBrowserItemSelected( *m_peer , m_idArray[n] ) ; + return m_peer->IsItemSelected( m_idArray[n] ) ; } int wxListBox::MacGetSelection() const { for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i ) { - if ( ::IsDataBrowserItemSelected(*m_peer , m_idArray[i] ) ) + if ( m_peer->IsItemSelected( m_idArray[i] ) ) { return i ; } @@ -696,7 +696,7 @@ int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const aSelections.Empty(); for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i ) { - if ( ::IsDataBrowserItemSelected(*m_peer , m_idArray[i] ) ) + if ( m_peer->IsItemSelected( m_idArray[i] ) ) { aSelections.Add( i ) ; no_sel++ ; @@ -709,13 +709,13 @@ void wxListBox::MacSet( int n , const wxString& text ) { // as we don't store the strings we only have to issue a redraw UInt32 id = m_idArray[n] ; - verify_noerr( ::UpdateDataBrowserItems( *m_peer , kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; + verify_noerr( m_peer->UpdateItems( kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; } void wxListBox::MacScrollTo( int n ) { UInt32 id = m_idArray[n] ; - verify_noerr( ::RevealDataBrowserItem(*m_peer , id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ; + verify_noerr( m_peer->RevealItem( id , kTextColumnId , kDataBrowserRevealWithoutSelecting ) ) ; } #if !TARGET_API_MAC_OSX diff --git a/src/mac/carbon/notebmac.cpp b/src/mac/carbon/notebmac.cpp index 182bbb7f10..db806ca7e6 100644 --- a/src/mac/carbon/notebmac.cpp +++ b/src/mac/carbon/notebmac.cpp @@ -127,7 +127,7 @@ bool wxNotebook::Create(wxWindow *parent, m_peer = new wxMacControl() ; verify_noerr ( CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , - tabsize , tabstyle, 0, NULL, *m_peer ) ); + tabsize , tabstyle, 0, NULL, m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; @@ -333,7 +333,7 @@ bool wxNotebook::InsertPage(size_t nPage, { m_nSelection++; // while this still is the same page showing, we need to update the tabs - SetControl32BitValue( *m_peer , m_nSelection + 1 ) ; + m_peer->SetValue( m_nSelection + 1 ) ; } // some page should be selected: either this one or the first one if there @@ -358,7 +358,7 @@ bool wxNotebook::InsertPage(size_t nPage, */ void wxNotebook::MacSetupTabs() { - SetControl32BitMaximum( *m_peer , GetPageCount() ) ; + m_peer->SetMaximum( GetPageCount() ) ; wxNotebookPage *page; ControlTabInfoRec info; @@ -370,10 +370,8 @@ void wxNotebook::MacSetupTabs() info.version = 0; info.iconSuiteID = 0; wxMacStringToPascal( page->GetLabel() , info.name ) ; - - SetControlData( *m_peer, ii+1, kControlTabInfoTag, - sizeof( ControlTabInfoRec) , (char*) &info ) ; - SetTabEnabled( *m_peer , ii+1 , true ) ; + m_peer->SetData( ii+1, kControlTabInfoTag, &info ) ; + m_peer->SetTabEnabled( ii + 1 , true ) ; #if TARGET_CARBON if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) { @@ -402,8 +400,7 @@ void wxNotebook::MacSetupTabs() wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; info.contentType = kControlContentIconRef ; info.u.iconRef = iconRef ; - SetControlData( *m_peer, ii+1,kControlTabImageContentTag, - sizeof( info ), (Ptr)&info ); + m_peer->SetData( ii+1,kControlTabImageContentTag, &info ); wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; if ( UMAGetSystemVersion() < 0x1030 ) { @@ -417,7 +414,7 @@ void wxNotebook::MacSetupTabs() #endif } Rect bounds; - UMAGetControlBoundsInWindowCoords(*m_peer, &bounds); + m_peer->GetRectInWindowCoords( &bounds ) ; InvalWindowRect((WindowRef)MacGetTopLevelWindowRef(), &bounds); } @@ -569,14 +566,14 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) } m_nSelection = nSel; - SetControl32BitValue( *m_peer , m_nSelection + 1 ) ; + m_peer->SetValue( m_nSelection + 1 ) ; } wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { OSStatus status = eventNotHandledErr ; - SInt32 newSel = GetControl32BitValue( *m_peer ) - 1 ; + SInt32 newSel = m_peer->GetValue() - 1 ; if ( newSel != m_nSelection ) { wxNotebookEvent changing(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, @@ -594,7 +591,7 @@ wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTR } else { - SetControl32BitValue( *m_peer , m_nSelection + 1 ) ; + m_peer->SetValue( m_nSelection + 1 ) ; } status = noErr ; } diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp index bae7911630..3695edf6ca 100644 --- a/src/mac/carbon/radiobox.cpp +++ b/src/mac/carbon/radiobox.cpp @@ -140,7 +140,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_peer = new wxMacControl() ; verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , - true /*primary*/ , *m_peer ) ) ; + true /*primary*/ , m_peer->GetControlRefAddr() ) ) ; for (i = 0; i < n; i++) { diff --git a/src/mac/carbon/radiobut.cpp b/src/mac/carbon/radiobut.cpp index 52cc12108a..1a31f44a25 100644 --- a/src/mac/carbon/radiobut.cpp +++ b/src/mac/carbon/radiobut.cpp @@ -41,7 +41,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - 0 , false /* no autotoggle */ , *m_peer ) ); + 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; @@ -75,10 +75,10 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, void wxRadioButton::SetValue(bool val) { wxRadioButton *cycle; - if ( GetControl32BitValue( *m_peer ) == val ) + if ( m_peer->GetValue() == val ) return ; - ::SetControl32BitValue( *m_peer , val ) ; + m_peer->SetValue( val ) ; if (val) { cycle=this->NextInCycle(); @@ -94,7 +94,7 @@ void wxRadioButton::SetValue(bool val) bool wxRadioButton::GetValue() const { - return ::GetControl32BitValue( *m_peer ) ; + return m_peer->GetValue() ; } void wxRadioButton::Command (wxCommandEvent & event) diff --git a/src/mac/carbon/scrolbar.cpp b/src/mac/carbon/scrolbar.cpp index c5a74bc2f4..d6454cf768 100644 --- a/src/mac/carbon/scrolbar.cpp +++ b/src/mac/carbon/scrolbar.cpp @@ -49,7 +49,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr ( CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , - 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , *m_peer ) ); + 0 , 0 , 100 , 1 , true /* liveTracking */ , wxMacLiveScrollbarActionUPP , m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; @@ -63,12 +63,12 @@ wxScrollBar::~wxScrollBar() void wxScrollBar::SetThumbPosition(int viewStart) { - ::SetControl32BitValue( *m_peer , viewStart ) ; + m_peer->SetValue( viewStart ) ; } int wxScrollBar::GetThumbPosition() const { - return ::GetControl32BitValue( *m_peer ) ; + return m_peer->GetValue() ; } void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, @@ -80,10 +80,10 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS int range1 = wxMax((m_objectSize - m_viewSize), 0) ; - SetControl32BitMaximum( *m_peer , range1 ) ; - SetControl32BitMinimum( *m_peer , 0 ) ; - SetControl32BitValue( *m_peer , position ) ; - SetControlViewSize( *m_peer , m_viewSize ) ; + m_peer->SetMaximum( range1 ) ; + m_peer->SetMinimum( 0 ) ; + m_peer->SetValue( position ) ; + m_peer->SetViewSize( m_viewSize ) ; if ( refresh ) MacRedrawControl() ; @@ -98,9 +98,9 @@ void wxScrollBar::Command(wxCommandEvent& event) void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) { - int position = GetControl32BitValue( *m_peer) ; - int minPos = GetControl32BitMinimum( *m_peer) ; - int maxPos = GetControl32BitMaximum( *m_peer) ; + int position = m_peer->GetValue() ; + int minPos = m_peer->GetMinimum() ; + int maxPos = m_peer->GetMaximum() ; wxEventType scrollEvent = wxEVT_NULL; int nScrollInc = 0; @@ -171,9 +171,9 @@ void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) { - int position = GetControl32BitValue( *m_peer) ; - int minPos = GetControl32BitMinimum( *m_peer) ; - int maxPos = GetControl32BitMaximum( *m_peer) ; + int position = m_peer->GetValue() ; + int minPos = m_peer->GetMinimum() ; + int maxPos = m_peer->GetMaximum() ; wxEventType scrollEvent = wxEVT_NULL; int nScrollInc = 0; diff --git a/src/mac/carbon/slider.cpp b/src/mac/carbon/slider.cpp index dc0508f4ea..fb8d6a322a 100644 --- a/src/mac/carbon/slider.cpp +++ b/src/mac/carbon/slider.cpp @@ -87,7 +87,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr ( CreateSliderControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , value , minValue , maxValue , kControlSliderPointsDownOrRight , tickMarks , true /* liveTracking */ , - wxMacLiveScrollbarActionUPP , *m_peer ) ); + wxMacLiveScrollbarActionUPP , m_peer->GetControlRefAddr() ) ); if(style & wxSL_VERTICAL) { @@ -123,7 +123,7 @@ wxSlider::~wxSlider() int wxSlider::GetValue() const { - return GetControl32BitValue( *m_peer) ; + return m_peer->GetValue() ; } void wxSlider::SetValue(int value) @@ -132,7 +132,7 @@ void wxSlider::SetValue(int value) valuestring.Printf( wxT("%d") , value ) ; if ( m_macValueStatic ) m_macValueStatic->SetLabel( valuestring ) ; - SetControl32BitValue( *m_peer , value ) ; + m_peer->SetValue( value ) ; } void wxSlider::SetRange(int minValue, int maxValue) @@ -142,8 +142,8 @@ void wxSlider::SetRange(int minValue, int maxValue) m_rangeMin = minValue; m_rangeMax = maxValue; - SetControl32BitMinimum( *m_peer, m_rangeMin); - SetControl32BitMaximum( *m_peer, m_rangeMax); + m_peer->SetMinimum( m_rangeMin); + m_peer->SetMaximum( m_rangeMax); if(m_macMinimumStatic) { value.Printf(wxT("%d"), m_rangeMin); @@ -237,7 +237,7 @@ void wxSlider::Command (wxCommandEvent & event) void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bool mouseStillDown ) { - SInt16 value = ::GetControl32BitValue( *m_peer ) ; + SInt16 value = m_peer->GetValue() ; SetValue( value ) ; @@ -259,7 +259,7 @@ void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bo wxInt32 wxSlider::MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF mevent ) { - SInt16 value = ::GetControl32BitValue( *m_peer ) ; + SInt16 value = m_peer->GetValue() ; SetValue( value ) ; diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index 526eaacd7b..98272dc92a 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -56,9 +56,9 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c m_peer = new wxMacControl() ; verify_noerr ( CreateLittleArrowsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , 0 , m_min , m_max , 1 , - *m_peer ) ); + m_peer->GetControlRefAddr() ) ); - SetControlAction( *m_peer , wxMacLiveScrollbarActionUPP ) ; + m_peer->SetActionProc( wxMacLiveScrollbarActionUPP ) ; MacPostControlCreate(pos,size) ; return TRUE; @@ -95,8 +95,8 @@ void wxSpinButton::SetRange(int minVal, int maxVal) { m_min = minVal; m_max = maxVal; - SetControl32BitMaximum( *m_peer , maxVal ) ; - SetControl32BitMinimum(*m_peer , minVal ) ; + m_peer->SetMaximum( maxVal ) ; + m_peer->SetMinimum( minVal ) ; } void wxSpinButton::MacHandleValueChanged( int inc ) @@ -139,7 +139,7 @@ void wxSpinButton::MacHandleValueChanged( int inc ) { m_value = oldValue ; } - SetControl32BitValue( *m_peer , m_value ) ; + m_peer->SetValue( m_value ) ; /* always send a thumbtrack event */ if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp index d25be44dab..87ec656d78 100644 --- a/src/mac/carbon/statbox.cpp +++ b/src/mac/carbon/statbox.cpp @@ -45,7 +45,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , - true /*primary*/ , *m_peer ) ) ; + true /*primary*/ , m_peer->GetControlRefAddr() ) ) ; MacPostControlCreate(pos,size) ; diff --git a/src/mac/carbon/statlmac.cpp b/src/mac/carbon/statlmac.cpp index cf9f999fa0..34ca6e86cf 100644 --- a/src/mac/carbon/statlmac.cpp +++ b/src/mac/carbon/statlmac.cpp @@ -57,7 +57,7 @@ bool wxStaticLine::Create( wxWindow *parent, Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; m_peer = new wxMacControl() ; - verify_noerr(CreateSeparatorControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, *m_peer ) ) ; + verify_noerr(CreateSeparatorControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, m_peer->GetControlRefAddr() ) ) ; MacPostControlCreate(pos,size) ; diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp index 024cc6eed7..93998884fd 100644 --- a/src/mac/carbon/stattext.cpp +++ b/src/mac/carbon/stattext.cpp @@ -51,7 +51,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; m_peer = new wxMacControl() ; verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str , - NULL , *m_peer ) ) ; + NULL , m_peer->GetControlRefAddr() ) ) ; MacPostControlCreate(pos,size) ; @@ -61,8 +61,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, wxSize wxStaticText::DoGetBestSize() const { ControlFontStyleRec controlFont ; - Size outSize ; - verify_noerr( GetControlData( *m_peer , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ; + verify_noerr( m_peer->GetData(kControlEntireControl , kControlFontStyleTag , &controlFont ) ) ; Point bounds ; SInt16 baseline ; @@ -89,8 +88,7 @@ void wxStaticText::SetLabel(const wxString& st ) wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; CFStringRef ref = str ; - SetControlData( *m_peer, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ), - &ref ); + verify_noerr( m_peer->SetData(kControlEntireControl , kControlStaticTextCFStringTag, ref ) ) ; if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) { diff --git a/src/mac/carbon/tabctrl.cpp b/src/mac/carbon/tabctrl.cpp index 677dd1ae91..a8b350e713 100644 --- a/src/mac/carbon/tabctrl.cpp +++ b/src/mac/carbon/tabctrl.cpp @@ -58,7 +58,7 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons m_peer = new wxMacControl() ; verify_noerr ( CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , - tabsize , tabstyle, 0, NULL, *m_peer ) ); + tabsize , tabstyle, 0, NULL, m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index b1ae31ebe5..0f5950f8e8 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -17,6 +17,7 @@ #if wxUSE_TEXTCTRL + #ifdef __DARWIN__ #include #include @@ -60,1620 +61,1628 @@ #include #include "wx/mac/uma.h" -#define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL -#if TARGET_API_MAC_OSX - #define wxMAC_USE_MLTE 0 - #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - #define wxMAC_USE_MLTE_HIVIEW 1 - #else - #define wxMAC_USE_MLTE_HIVIEW 0 - #endif -#else - // there is no unicodetextctrl on classic, and hopefully MLTE works better there - #define wxMAC_USE_MLTE 1 - #define wxMAC_USE_MLTE_HIVIEW 0 -#endif - -#if wxMAC_USE_MLTE - -TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) +class wxMacFunctor { - TXNFrameOptions frameOptions = - kTXNDontDrawCaretWhenInactiveMask ; - if ( ! ( wxStyle & wxTE_NOHIDESEL ) ) - frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; - - if ( wxStyle & wxTE_MULTILINE ) +public : + wxMacFunctor(){} + virtual ~wxMacFunctor() {} + virtual void* operator()() = 0 ; + static void* CallBackProc(void *param) { - if ( ! ( wxStyle & wxTE_DONTWRAP ) ) - frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; - else - { - frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; - frameOptions |= kTXNWantHScrollBarMask ; - } - - if ( !(wxStyle & wxTE_NO_VSCROLL ) ) - frameOptions |= kTXNWantVScrollBarMask ; + wxMacFunctor* f = (wxMacFunctor*) param ; + void *result = (*f)() ; + return result ; } - else - frameOptions |= kTXNSingleLineOnlyMask ; - return frameOptions ; -} +} ; -void AdjustAttributesFromWXStyle( TXNObject txn , long wxStyle , bool visible ) +template +class wxMacObjectFunctor1 : public wxMacFunctor { - TXNControlTag iControlTags[3] = { kTXNDoFontSubstitution, kTXNWordWrapStateTag }; - TXNControlData iControlData[3] = { {false}, {kTXNNoAutoWrap} }; - int toptag = 2 ; -#if TARGET_API_MAC_OSX - iControlTags[2] = kTXNVisibilityTag ; - iControlData[2].uValue = visible ; - toptag++ ; -#endif - - if ( wxStyle & wxTE_MULTILINE ) + typedef void (classtype::*function)( param1type p1 ) ; + typedef void (classtype::*ref_function)( const param1type& p1 ) ; +public : + wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) : + wxMacFunctor( ) { - if (wxStyle & wxTE_DONTWRAP) - iControlData[1].uValue = kTXNNoAutoWrap ; - else - iControlData[1].uValue = kTXNAutoWrap ; - + m_object = obj ; + m_function = f ; + m_param1 = p1 ; } - verify_noerr( TXNSetTXNObjectControls( txn, false, toptag, - iControlTags, iControlData )) ; - Str255 fontName ; - SInt16 fontSize ; - Style fontStyle ; - - GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) : + wxMacFunctor( ) + { + m_object = obj ; + m_refFunction = f ; + m_param1 = p1 ; + } - TXNTypeAttributes typeAttr[] = + ~wxMacObjectFunctor1() {} + + virtual void* operator()() { - { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , - { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , - { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , + (m_object->*m_function)(m_param1) ; + return NULL ; + } +private : + classtype* m_object ; + param1type m_param1 ; + union + { + function m_function ; + ref_function m_refFunction ; } ; +} ; - verify_noerr( TXNSetTypeAttributes (txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, - kTXNStartOffset, - kTXNEndOffset) ); +template +void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) +{ + wxMacObjectFunctor1 params(object,function,p1) ; + void *result = + MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; + return result ; +} +template +void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) +{ + wxMacObjectFunctor1 params(object,function,p1) ; + void *result = + MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; + return result ; } -#if !wxMAC_USE_MLTE_HIVIEW +template +void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) +{ + wxMutexGuiLeave() ; + void *result = wxMacMPRemoteCall( object , function , p1 ) ; + wxMutexGuiEnter() ; + return result ; +} -// CS:TODO we still have a problem getting properly at the text events of a control because under Carbon -// the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the -// moment is to avoid setting the true focus on the control, the proper solution at the end would be to have -// an alternate path for carbon key events that routes automatically into the same wx flow of events +template +void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) +{ + wxMutexGuiLeave() ; + void *result = wxMacMPRemoteCall( object , function , p1 ) ; + wxMutexGuiEnter() ; + return result ; +} +// common interface for all implementations +class wxMacTextControl : public wxMacControl +{ +public : + wxMacTextControl() ; + ~wxMacTextControl() ; + + virtual wxString GetStringValue() const = 0 ; + virtual void SetStringValue( const wxString &val ) = 0 ; + virtual void SetStyle(long start, long end, const wxTextAttr& style) ; + virtual void Copy() ; + virtual void Cut() ; + virtual void Paste() ; + virtual bool CanPaste() const ; + virtual void SetEditable(bool editable) ; + virtual long GetLastPosition() const ; + virtual void Replace( long from , long to , const wxString str ) ; + virtual void Remove( long from , long to ) = 0 ; + virtual void SetSelection( long from , long to ) = 0 ; + virtual void GetSelection( long* from, long* to) const = 0 ; + virtual void WriteText(const wxString& str) = 0 ; + + virtual void Clear() ; + virtual bool CanUndo() const; + virtual void Undo() ; + virtual bool CanRedo() const; + virtual void Redo() ; + virtual int GetNumberOfLines() const ; + virtual long XYToPosition(long x, long y) const; + virtual bool PositionToXY(long pos, long *x, long *y) const ; + virtual void ShowPosition( long WXUNUSED(pos) ) ; + virtual int GetLineLength(long lineNo) const ; + virtual wxString GetLineText(long lineNo) const ; +} ; -/* part codes */ +// common parts for implementations based on MLTE -/* kmUPTextPart is the part code we return to indicate the user has clicked - in the text area of our control */ -#define kmUPTextPart 1 +class wxMacMLTEControl : public wxMacTextControl +{ +public : + virtual wxString GetStringValue() const ; + virtual void SetStringValue( const wxString &str) ; + + static int ConvertAttribute( const wxTextAttr& style , TXNTypeAttributes attr[] ) ; + static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; + void AdjustCreationAttributes( const wxColour& background , bool visible ) ; + + virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ; + virtual void SetStyle(long start, long end, const wxTextAttr& style) ; + virtual void Copy() ; + virtual void Cut() ; + virtual void Paste() ; + virtual bool CanPaste() const ; + virtual void SetEditable(bool editable) ; + virtual long GetLastPosition() const ; + virtual void Replace( long from , long to , const wxString str ) ; + virtual void Remove( long from , long to ) ; + virtual void GetSelection( long* from, long* to) const ; + virtual void SetSelection( long from , long to ) ; + + virtual void WriteText(const wxString& str) ; + virtual void Clear() ; + + virtual bool CanUndo() const ; + virtual void Undo() ; + virtual bool CanRedo() const; + virtual void Redo() ; + virtual int GetNumberOfLines() const ; + virtual long XYToPosition(long x, long y) const ; + virtual bool PositionToXY(long pos, long *x, long *y) const ; + virtual void ShowPosition( long pos ) ; + virtual int GetLineLength(long lineNo) const ; + virtual wxString GetLineText(long lineNo) const ; + + void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; + +protected : + TXNObject m_txn ; +} ; +#if TARGET_API_MAC_OSX -/* routines for using existing user pane controls. - These routines are useful for cases where you would like to use an - existing user pane control in, say, a dialog window as a scrolling - text edit field.*/ +// implementation available under OSX + +class wxMacMLTEHIViewControl : public wxMacMLTEControl +{ +public : + wxMacMLTEHIViewControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) ; + virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; + virtual bool HasFocus() const ; + virtual bool NeedsFocusRect() const ; +protected : + HIViewRef m_scrollView ; + HIViewRef m_textView ; +} ; -/* Utility Routines */ +class wxMacUnicodeTextControl : public wxMacTextControl +{ +public : + wxMacUnicodeTextControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) ; + ~wxMacUnicodeTextControl(); + virtual void VisibilityChanged(bool shown); + virtual wxString GetStringValue() const ; + virtual void SetStringValue( const wxString &str) ; + virtual void Copy(); + virtual void Cut(); + virtual void Paste(); + virtual bool CanPaste() const; + virtual void SetEditable(bool editable) ; + virtual void Remove( long from , long to ) ; + virtual void GetSelection( long* from, long* to) const ; + virtual void SetSelection( long from , long to ) ; + virtual void WriteText(const wxString& str) ; +protected : + // contains the tag for the content (is different for password and non-password controls) + OSType m_valueTag ; +} ; -/* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus - routine. In our focus switching routine this part code is understood - as meaning 'the user has clicked in the control and we need to switch - the current focus to ourselves before we can continue'. */ -#define kUserClickedToFocusPart 100 +#else -/* STPTextPaneVars is a structure used for storing the the mUP Control's - internal variables and state information. A handle to this record is - stored in the pane control's reference value field using the - SetControlReference routine. */ +// implementation available under classic -typedef struct { - /* OS records referenced */ - TXNObject fTXNRec; /* the txn record */ - TXNFrameID fTXNFrame; /* the txn frame ID */ - ControlRef fUserPaneRec; /* handle to the user pane control */ - WindowPtr fOwner; /* window containing control */ - GrafPtr fDrawingEnvironment; /* grafport where control is drawn */ - /* flags */ - Boolean fInFocus; /* true while the focus rect is drawn around the control */ - Boolean fIsActive; /* true while the control is drawn in the active state */ - Boolean fTXNObjectActive; /* reflects the activation state of the text edit record */ - Boolean fFocusDrawState; /* true if focus is drawn (default: true) */ - /* calculated locations */ - Rect fRBounds; /* control bounds */ - Rect fRTextArea; /* area where the text is drawn */ - Rect fRFocusOutline; /* rectangle used to draw the focus box */ - Rect fRTextOutline; /* rectangle used to draw the border */ - RgnHandle fRTextOutlineRegion; /* background region for the text, erased before calling TEUpdate */ - /* our focus advance override routine */ - EventHandlerUPP handlerUPP; - EventHandlerRef handlerRef; - bool fNoBorders ; - bool fMultiline ; - bool fVisible ; -} STPTextPaneVars; +class STPTextPaneVars ; -/* mUPOpenControl initializes a user pane control so it will be drawn - and will behave as a scrolling text edit field inside of a window. - This routine performs all of the initialization steps necessary, - except it does not create the user pane control itself. theControl - should refer to a user pane control that you have either created - yourself or extracted from a dialog's control heirarchy using - the GetDialogItemAsControl routine. */ -OSStatus mUPOpenControl(STPTextPaneVars* &handle, ControlRef theControl, long wxStyle); +class wxMacMLTEClassicControl : public wxMacMLTEControl +{ +public : + wxMacMLTEClassicControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) ; + ~wxMacMLTEClassicControl() ; + virtual void VisibilityChanged(bool shown) ; +protected : + OSStatus DoCreate(); +public : + // hack to make public until we have migrated all procs + STPTextPaneVars* m_macTXNvars ; +} ; +#endif +// built-in TextCtrl +#define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL +#if TARGET_API_MAC_OSX + #define wxMAC_USE_MLTE 1 + #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + #define wxMAC_USE_MLTE_HIVIEW 1 + #else + #define wxMAC_USE_MLTE_HIVIEW 0 + #endif +#else + // there is no unicodetextctrl on classic, and hopefully MLTE works better there + #define wxMAC_USE_MLTE 1 + #define wxMAC_USE_MLTE_HIVIEW 0 +#endif -/* Univerals Procedure Pointer variables used by the - mUP Control. These variables are set up - the first time that mUPOpenControl is called. */ -ControlUserPaneDrawUPP gTPDrawProc = NULL; -ControlUserPaneHitTestUPP gTPHitProc = NULL; -ControlUserPaneTrackingUPP gTPTrackProc = NULL; -ControlUserPaneIdleUPP gTPIdleProc = NULL; -ControlUserPaneKeyDownUPP gTPKeyProc = NULL; -ControlUserPaneActivateUPP gTPActivateProc = NULL; -ControlUserPaneFocusUPP gTPFocusProc = NULL; +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) -// one place for calculating all -static void TPCalculateBounds(STPTextPaneVars *varsp, const Rect& bounds) +BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) + EVT_DROP_FILES(wxTextCtrl::OnDropFiles) + EVT_CHAR(wxTextCtrl::OnChar) + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) + EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) + EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) + EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) + EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + + EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) +END_EVENT_TABLE() +#endif + +// Text item +void wxTextCtrl::Init() { - SetRect(&varsp->fRBounds, bounds.left, bounds.top, bounds.right, bounds.bottom); - SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - // eventually make TextOutline inset 1,1 - SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - if ( !varsp->fNoBorders ) - { - SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) , - bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2)); - } - else - { - SetRect(&varsp->fRTextArea, bounds.left , bounds.top , - bounds.right, bounds.bottom); - } + m_editable = true ; + m_dirty = false; + + m_maxLength = TE_UNLIMITED_LENGTH ; } -OSStatus MLTESetObjectVisibility( STPTextPaneVars *varsp, Boolean vis , long wxStyle) +wxTextCtrl::~wxTextCtrl() { - OSStatus err = noErr ; -#if TARGET_API_MAC_OSX - TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; - TXNControlData iControlData[1] = {{ vis }}; - err = ::TXNSetTXNObjectControls( varsp->fTXNRec, false, 1, iControlTags, iControlData ); -#endif - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); - if ( vis && textctrl ) - { - Rect bounds ; - UMAGetControlBoundsInWindowCoords( varsp->fUserPaneRec, &bounds); - TPCalculateBounds( varsp , bounds ) ; - wxMacWindowClipper cl(textctrl) ; - TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, - varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); - TXNShowSelection( varsp->fTXNRec, kTXNShowStart); - } - return err ; } -// make sure we don't miss changes as carbon events are not available for these under classic -static void TPUpdateVisibility(ControlRef theControl) { - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return ; - - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - Rect bounds ; - UMAGetControlBoundsInWindowCoords(theControl, &bounds); - if ( textctrl->MacIsReallyShown() != varsp->fVisible ) - { - // invalidate old position - // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; - varsp->fVisible = textctrl->MacIsReallyShown() ; +bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + m_macIsUserPane = FALSE ; + m_editable = true ; + + // base initialization + + if ( !HasFlag(wxNO_BORDER) ) + { +#if wxMAC_USE_MLTE +#if wxMAC_USE_MLTE_HIVIEW + style |= wxSUNKEN_BORDER ; +#endif +#endif } - if ( !EqualRect( &bounds , &varsp->fRBounds ) ) + else { - // old position - Rect oldBounds = varsp->fRBounds ; - TPCalculateBounds( varsp , bounds ) ; - // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places - if ( varsp->fVisible ) - { - wxMacWindowClipper cl(textctrl) ; - TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, - varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); - } - InvalWindowRect( GetControlOwner( theControl ) , &oldBounds ) ; - InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; } -} + + if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) + return FALSE; -// make correct activations -static void TPActivatePaneText(STPTextPaneVars *varsp, Boolean setActive) { + wxSize mySize = size ; - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); - if (varsp->fTXNObjectActive != setActive && textctrl->MacIsReallyShown() ) + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + + if ( m_windowStyle & wxTE_MULTILINE ) { - varsp->fTXNObjectActive = setActive; - TXNActivate(varsp->fTXNRec, varsp->fTXNFrame, varsp->fTXNObjectActive); - if (varsp->fInFocus) - TXNFocus( varsp->fTXNRec, varsp->fTXNObjectActive); + wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER), + wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") ); + + m_windowStyle |= wxTE_PROCESS_ENTER; + style |= wxTE_PROCESS_ENTER ; } -} +#if wxMAC_USE_MLTE +#if wxMAC_USE_MLTE_HIVIEW + m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; +#else + m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; +#endif +#else // wxMAC_USE_MLTE + m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; +#endif + MacPostControlCreate(pos,size) ; -// update focus outlines -static void TPRedrawFocusOutline(STPTextPaneVars *varsp) { + if ( m_windowStyle & wxTE_READONLY) + { + SetEditable( false ) ; + } + - /* state changed */ - if (varsp->fFocusDrawState != (varsp->fIsActive && varsp->fInFocus)) - { - varsp->fFocusDrawState = (varsp->fIsActive && varsp->fInFocus); - DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState); - } + return TRUE; } -// update TXN focus state -static void TPFocusPaneText(STPTextPaneVars *varsp, Boolean setFocus) { - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); +void wxTextCtrl::MacVisibilityChanged() +{ + GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; +} - if (varsp->fInFocus != setFocus && textctrl->MacIsReallyShown()) { - varsp->fInFocus = setFocus; - TXNFocus( varsp->fTXNRec, varsp->fInFocus); - } +void wxTextCtrl::MacEnabledStateChanged() +{ } -// draw the control -static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart) { - /* set up our globals */ +wxString wxTextCtrl::GetValue() const +{ + return GetPeer()->GetStringValue() ; +} - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) +void wxTextCtrl::GetSelection(long* from, long* to) const +{ + GetPeer()->GetSelection( from , to ) ; +} + +void wxTextCtrl::SetValue(const wxString& str) +{ + // optimize redraws + if ( GetValue() == str ) return ; - TPUpdateVisibility( theControl ) ; - - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - if ( textctrl->MacIsReallyShown() ) - { - wxMacWindowClipper clipper( textctrl ) ; - TXNDraw(varsp->fTXNRec, NULL); - if ( !varsp->fNoBorders ) - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - TPRedrawFocusOutline( varsp ) ; - } + GetPeer()->SetStringValue(str) ; } +void wxTextCtrl::SetMaxLength(unsigned long len) +{ + m_maxLength = len ; +} -/* TPPaneHitTestProc is called when the control manager would - like to determine what part of the control the mouse resides over. - We also call this routine from our tracking proc to determine how - to handle mouse clicks. */ -static pascal ControlPartCode TPPaneHitTestProc(ControlRef theControl, Point where) { - ControlPartCode result; - /* set up our locals and lock down our globals*/ - result = 0; - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return 0 ; - TPUpdateVisibility( theControl ) ; - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - if (textctrl->MacIsReallyShown() ) +bool wxTextCtrl::SetFont( const wxFont& font ) +{ + if ( !wxTextCtrlBase::SetFont( font ) ) + return FALSE ; + + GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; + return true ; +} + +bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) +{ + GetPeer()->SetStyle( start , end , style ) ; + return true ; +} + +bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) +{ + wxTextCtrlBase::SetDefaultStyle( style ) ; + SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; + return TRUE ; +} + +// Clipboard operations +void wxTextCtrl::Copy() +{ + if (CanCopy()) { - if (PtInRect(where, &varsp->fRBounds)) - result = kmUPTextPart; - else - result = 0; + GetPeer()->Copy() ; } - return result; } +void wxTextCtrl::Cut() +{ + if (CanCut()) + { + GetPeer()->Cut() ; + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event.SetString( GetValue() ) ; + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } +} +void wxTextCtrl::Paste() +{ + if (CanPaste()) + { + GetPeer()->Paste() ; + // eventually we should add setting the default style again + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event.SetString( GetValue() ) ; + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } +} -/* TPPaneTrackingProc is called when the mouse is being held down - over our control. This routine handles clicks in the text area - and in the scroll bar. */ -static pascal ControlPartCode TPPaneTrackingProc(ControlRef theControl, Point startPt, ControlActionUPP actionProc) { - - ControlPartCode partCodeResult; - /* make sure we have some variables... */ - partCodeResult = 0; - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return 0; - TPUpdateVisibility( theControl ) ; - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - if (textctrl->MacIsReallyShown() ) - { - /* we don't do any of these functions unless we're in focus */ - if ( ! varsp->fInFocus) { - WindowPtr owner; - owner = GetControlOwner(theControl); - ClearKeyboardFocus(owner); - SetKeyboardFocus(owner, theControl, kUserClickedToFocusPart); - } - /* find the location for the click */ - // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them - if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) - { - int x = 0 , y = 0 ; - textctrl->MacClientToRootWindow( &x , &y ) ; - startPt.h += x ; - startPt.v += y ; - } +bool wxTextCtrl::CanCopy() const +{ + // Can copy if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); +} - switch (TPPaneHitTestProc(theControl, startPt)) - { - - /* handle clicks in the text part */ - case kmUPTextPart: - { - wxMacWindowClipper clipper( textctrl ) ; - - EventRecord rec ; - ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; - TXNClick( varsp->fTXNRec, &rec ); - - } - break; - - } +bool wxTextCtrl::CanCut() const +{ + if ( !IsEditable() ) + { + return false ; } - return partCodeResult; + // Can cut if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); } +bool wxTextCtrl::CanPaste() const +{ + if (!IsEditable()) + return FALSE; -/* TPPaneIdleProc is our user pane idle routine. When our text field - is active and in focus, we use this routine to set the cursor. */ -static pascal void TPPaneIdleProc(ControlRef theControl) { - /* set up locals */ - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return ; - TPUpdateVisibility( theControl ) ; - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - if (textctrl->MacIsReallyShown()) { - /* if we're not active, then we have nothing to say about the cursor */ - if (varsp->fIsActive) { - Rect bounds; - Point mousep; + return GetPeer()->CanPaste() ; +} - wxMacWindowClipper clipper( textctrl ) ; - GetMouse(&mousep); - /* there's a 'focus thing' and an 'unfocused thing' */ - if (varsp->fInFocus) { - /* flash the cursor */ - SetPort(varsp->fDrawingEnvironment); - TXNIdle(varsp->fTXNRec); - /* set the cursor */ - if (PtInRect(mousep, &varsp->fRTextArea)) { - RgnHandle theRgn; - RectRgn((theRgn = NewRgn()), &varsp->fRTextArea); - TXNAdjustCursor(varsp->fTXNRec, theRgn); - DisposeRgn(theRgn); - } - else - { - // SetThemeCursor(kThemeArrowCursor); - } - } else { - /* if it's in our bounds, set the cursor */ - UMAGetControlBoundsInWindowCoords(theControl, &bounds); - if (PtInRect(mousep, &bounds)) - { - // SetThemeCursor(kThemeArrowCursor); - } - } - } +void wxTextCtrl::SetEditable(bool editable) +{ + if ( editable != m_editable ) + { + m_editable = editable ; + GetPeer()->SetEditable( editable ) ; } } +void wxTextCtrl::SetInsertionPoint(long pos) +{ + SetSelection( pos , pos ) ; +} -/* TPPaneKeyDownProc is called whenever a keydown event is directed - at our control. Here, we direct the keydown event to the text - edit record and redraw the scroll bar and text field as appropriate. */ -static pascal ControlPartCode TPPaneKeyDownProc(ControlRef theControl, - SInt16 keyCode, SInt16 charCode, SInt16 modifiers) { +void wxTextCtrl::SetInsertionPointEnd() +{ + long pos = GetLastPosition(); + SetInsertionPoint(pos); +} - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return 0; - TPUpdateVisibility( theControl ) ; +long wxTextCtrl::GetInsertionPoint() const +{ + long begin,end ; + GetSelection( &begin , &end ) ; + return begin ; +} - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - if (varsp->fInFocus) - { - /* turn autoscrolling on and send the key event to text edit */ - wxMacWindowClipper clipper( textctrl ) ; - EventRecord ev ; - memset( &ev , 0 , sizeof( ev ) ) ; - ev.what = keyDown ; - ev.modifiers = modifiers ; - ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; - TXNKeyDown( varsp->fTXNRec, &ev); - } - return kControlEntireControl; +long wxTextCtrl::GetLastPosition() const +{ + return GetPeer()->GetLastPosition( ) ; } +void wxTextCtrl::Replace(long from, long to, const wxString& str) +{ + GetPeer()->Replace( from , to , str) ; +} -/* TPPaneActivateProc is called when the window containing - the user pane control receives activate events. Here, we redraw - the control and it's text as necessary for the activation state. */ -static pascal void TPPaneActivateProc(ControlRef theControl, Boolean activating) { - /* set up locals */ - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - - if ( textctrl == NULL ) - return ; - TPUpdateVisibility( theControl ) ; - - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; +void wxTextCtrl::Remove(long from, long to) +{ + GetPeer()->Remove( from , to ) ; +} - varsp->fIsActive = activating; - wxMacWindowClipper clipper( textctrl ) ; - TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); - /* redraw the frame */ - if ( textctrl->MacIsReallyShown() ) +void wxTextCtrl::SetSelection(long from, long to) +{ + GetPeer()->SetSelection( from , to ) ; +} + +bool wxTextCtrl::LoadFile(const wxString& file) +{ + if ( wxTextCtrlBase::LoadFile(file) ) { - if ( !varsp->fNoBorders ) - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - TPRedrawFocusOutline( varsp ) ; + return TRUE; } + + return FALSE; } +void wxTextCtrl::WriteText(const wxString& str) +{ + // TODO this MPRemoting will be moved into a remoting peer proxy for any command + if ( !wxIsMainThread() ) + { + // unfortunately CW 8 is not able to correctly deduce the template types, so we have + // to instantiate explicitely + wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; + return ; + } + else + { + GetPeer()->WriteText( str ) ; + } +} -/* TPPaneFocusProc is called when every the focus changes to or - from our control. Herein, switch the focus appropriately - according to the parameters and redraw the control as - necessary. */ -static pascal ControlPartCode TPPaneFocusProc(ControlRef theControl, ControlFocusPart action) { - ControlPartCode focusResult; +void wxTextCtrl::AppendText(const wxString& text) +{ + SetInsertionPointEnd(); + WriteText(text); +} - focusResult = kControlFocusNoPart; - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); - if ( textctrl == NULL ) - return 0; - TPUpdateVisibility( theControl ) ; - STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is - tabbing forwards (or shift tabbing backwards) through the items in the dialog, - and kControlFocusNextPart will be received. When the user clicks in our field - and it is not the current focus, then the constant kUserClickedToFocusPart will - be received. The constant kControlFocusNoPart will be received when our control - is the current focus and the user clicks in another control. In your focus routine, - you should respond to these codes as follows: +void wxTextCtrl::Clear() +{ + GetPeer()->Clear() ; +} - kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw - the control and the focus rectangle as necessary. +bool wxTextCtrl::IsModified() const +{ + return m_dirty; +} - kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off - depending on its current state. redraw the control and the focus rectangle - as appropriate for the new focus state. If the focus state is 'off', return the constant - kControlFocusNoPart, otherwise return a non-zero part code. - kUserClickedToFocusPart - is a constant defined for this example. You should - define your own value for handling click-to-focus type events. */ - /* calculate the next highlight state */ - switch (action) { - default: - case kControlFocusNoPart: - TPFocusPaneText(varsp, false); - focusResult = kControlFocusNoPart; - break; - case kUserClickedToFocusPart: - TPFocusPaneText(varsp, true); - focusResult = 1; - break; - case kControlFocusPrevPart: - case kControlFocusNextPart: - TPFocusPaneText(varsp, ( ! varsp->fInFocus)); - focusResult = varsp->fInFocus ? 1 : kControlFocusNoPart; - break; - } - TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); - /* redraw the text fram and focus rectangle to indicate the - new focus state */ - if ( textctrl->MacIsReallyShown() ) - { - wxMacWindowClipper c( textctrl ) ; - if ( !varsp->fNoBorders ) - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - TPRedrawFocusOutline( varsp ) ; - } - return focusResult; +bool wxTextCtrl::IsEditable() const +{ + return IsEnabled() && m_editable ; } +bool wxTextCtrl::AcceptsFocus() const +{ + // we don't want focus if we can't be edited + return /*IsEditable() && */ wxControl::AcceptsFocus(); +} -/* mUPOpenControl initializes a user pane control so it will be drawn - and will behave as a scrolling text edit field inside of a window. - This routine performs all of the initialization steps necessary, - except it does not create the user pane control itself. theControl - should refer to a user pane control that you have either created - yourself or extracted from a dialog's control heirarchy using - the GetDialogItemAsControl routine. */ -OSStatus mUPOpenControl(STPTextPaneVars* &handle, ControlRef theControl, long wxStyle ) +wxSize wxTextCtrl::DoGetBestSize() const { - Rect bounds; - WindowRef theWindow; - STPTextPaneVars *varsp; - OSStatus err = noErr ; + int wText = 100 ; - /* set up our globals */ - if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc); - if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc); - if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc); - if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc); - if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc); - if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc); - if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc); + int hText; - /* allocate our private storage */ - varsp = (STPTextPaneVars *) malloc(sizeof(STPTextPaneVars)); - handle = varsp ; - - /* set the initial settings for our private data */ - varsp->fMultiline = wxStyle & wxTE_MULTILINE ; - varsp->fNoBorders = wxStyle & wxNO_BORDER ; - varsp->fInFocus = false; - varsp->fIsActive = true; - varsp->fTXNObjectActive = false; - varsp->fFocusDrawState = false ; - varsp->fUserPaneRec = theControl; - varsp->fVisible = true ; - - theWindow = varsp->fOwner = GetControlOwner(theControl); - - varsp->fDrawingEnvironment = (GrafPtr) GetWindowPort(theWindow); - - /* set up the user pane procedures */ - SetControlData(theControl, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); - SetControlData(theControl, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); - - /* calculate the rectangles used by the control */ - UMAGetControlBoundsInWindowCoords(theControl, &bounds); - varsp->fRTextOutlineRegion = NewRgn() ; - TPCalculateBounds( varsp , bounds ) ; + switch( m_windowVariant ) + { + case wxWINDOW_VARIANT_NORMAL : + hText = 22 ; + break ; + case wxWINDOW_VARIANT_SMALL : + hText = 19 ; + break ; + case wxWINDOW_VARIANT_MINI : + hText= 15 ; + break ; + default : + hText = 22 ; + break ; + } - /* set up the drawing environment */ - SetPort(varsp->fDrawingEnvironment); +#if !wxMAC_USE_MLTE + // unicode text control is using client size, ie 3 pixels on every side + // TODO make this fit into normal window size concept, probably having + // to reintroduce the margin vars + hText -= 6 ; +#endif - /* create the new edit field */ + if ( m_windowStyle & wxTE_MULTILINE ) + { + hText *= 5 ; + } - TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( wxStyle ) ; + return wxSize(wText, hText); +} - verify_noerr(TXNNewObject(NULL, varsp->fOwner, &varsp->fRTextArea, - frameOptions , - kTXNTextEditStyleFrameType, - kTXNTextensionFile, - kTXNSystemDefaultEncoding, - &varsp->fTXNRec, &varsp->fTXNFrame, (TXNObjectRefcon) varsp)); +// ---------------------------------------------------------------------------- +// Undo/redo +// ---------------------------------------------------------------------------- - AdjustAttributesFromWXStyle( varsp->fTXNRec , wxStyle , varsp->fVisible ) ; - /* perform final activations and setup for our text field. Here, - we assume that the window is going to be the 'active' window. */ - TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); - /* all done */ - return err; +void wxTextCtrl::Undo() +{ + if (CanUndo()) + { + GetPeer()->Undo() ; + } } -#else -struct STPTextPaneVars +void wxTextCtrl::Redo() { -} ; + if (CanRedo()) + { + GetPeer()->Redo() ; + } +} -#endif +bool wxTextCtrl::CanUndo() const +{ + if ( !IsEditable() ) + { + return false ; + } + return GetPeer()->CanUndo() ; +} -static void SetTXNData( STPTextPaneVars *varsp, TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end ) +bool wxTextCtrl::CanRedo() const { -#if wxUSE_UNICODE -#if SIZEOF_WCHAR_T == 2 - size_t len = st.Len() ; - TXNSetData( txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, - start, end); -#else - wxMBConvUTF16BE converter ; - ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; - UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; - converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; - TXNSetData( txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen , - start, end); - free( unibuf ) ; -#endif -#else - wxCharBuffer text = st.mb_str(wxConvLocal) ; - TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) , - start, end); -#endif + if ( !IsEditable() ) + { + return false ; + } + return GetPeer()->CanRedo() ; } +void wxTextCtrl::MarkDirty() +{ + m_dirty = true; +} -#endif +void wxTextCtrl::DiscardEdits() +{ + m_dirty = false; +} -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) - -BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) - EVT_DROP_FILES(wxTextCtrl::OnDropFiles) - EVT_CHAR(wxTextCtrl::OnChar) - EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) - EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) - EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) - EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) - EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) +int wxTextCtrl::GetNumberOfLines() const +{ + return GetPeer()->GetNumberOfLines() ; +} - EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) - EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) - EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) - EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) - EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) -END_EVENT_TABLE() -#endif +long wxTextCtrl::XYToPosition(long x, long y) const +{ + return GetPeer()->XYToPosition( x , y ) ; +} -// Text item -void wxTextCtrl::Init() +bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { - m_macTXN = NULL ; - m_macTXNvars = NULL ; + return GetPeer()->PositionToXY(pos , x , y ) ; +} - m_editable = true ; - m_dirty = false; +void wxTextCtrl::ShowPosition(long pos) +{ + return GetPeer()->ShowPosition(pos) ; +} - m_maxLength = TE_UNLIMITED_LENGTH ; +int wxTextCtrl::GetLineLength(long lineNo) const +{ + return GetPeer()->GetLineLength(lineNo) ; } -wxTextCtrl::~wxTextCtrl() +wxString wxTextCtrl::GetLineText(long lineNo) const { -#if wxMAC_USE_MLTE - SetControlReference(*m_peer, 0) ; -#if !wxMAC_USE_MLTE_HIVIEW - TXNDeleteObject((TXNObject)m_macTXN); -#endif - /* delete our private storage */ - free(m_macTXNvars); - /* zero the control reference */ -#endif + return GetPeer()->GetLineText(lineNo) ; } +/* + * Text item + */ -bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) +void wxTextCtrl::Command(wxCommandEvent & event) { - m_macIsUserPane = FALSE ; - - m_macTXN = NULL ; - m_macTXNvars = NULL ; - m_editable = true ; - - // base initialization - if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) - return FALSE; + SetValue (event.GetString()); + ProcessCommand (event); +} - wxSize mySize = size ; +void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) +{ + // By default, load the first file into the text window. + if (event.GetNumberOfFiles() > 0) + { + LoadFile(event.GetFiles()[0]); + } +} - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; +void wxTextCtrl::OnChar(wxKeyEvent& event) +{ + int key = event.GetKeyCode() ; + bool eat_key = false ; - if ( m_windowStyle & wxTE_MULTILINE ) + if ( key == 'c' && event.MetaDown() ) { - wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER), - wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") ); - - m_windowStyle |= wxTE_PROCESS_ENTER; + if ( CanCopy() ) + Copy() ; + return ; } - wxString st = str ; - wxMacConvertNewlines13To10( &st ) ; -#if wxMAC_USE_MLTE + if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && + !( key == WXK_RETURN && ( (m_windowStyle & wxPROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) +/* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */ + ) { -#if wxMAC_USE_MLTE_HIVIEW - HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ; - HIViewRef scrollView = NULL ; - TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; + // eat it + return ; + } - if ( frameOptions & (kTXNWantVScrollBarMask|kTXNWantHScrollBarMask) ) - { - HIScrollViewCreate(( frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | - ( frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll: 0 ) , &scrollView ) ; - - HIViewSetFrame( scrollView, &hr ); - HIViewSetVisible( scrollView, true ); - } - HIViewRef textView ; - HITextViewCreate( NULL , 0, frameOptions , (ControlRef*) &textView ) ; - m_macTXN = HITextViewGetTXNObject( textView) ; - AdjustAttributesFromWXStyle( (TXNObject) m_macTXN , style , true ) ; - HIViewSetVisible( (ControlRef) textView , true ) ; - if ( scrollView ) - { - HIViewAddSubview( scrollView , textView ) ; - m_peer = scrollView ; - } - else - { - m_peer = textView ; - } -#else - short featurSet; - - featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle - | kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground - | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; - /* create the control */ - m_peer = new wxMacControl() ; - verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, *m_peer ) ); - - wxMacWindowClipper c(this) ; - STPTextPaneVars *varsp ; - mUPOpenControl( varsp, *m_peer, m_windowStyle ); - m_macTXNvars = varsp ; - m_macTXN = varsp->fTXNRec ; -#endif + // assume that any key not processed yet is going to modify the control + m_dirty = true; - if ( style & wxTE_PASSWORD ) - { - UniChar c = 0xA5 ; - verify_noerr(TXNEchoMode( (TXNObject) m_macTXN , c , 0 , true )) ; - } + if ( key == 'v' && event.MetaDown() ) + { + if ( CanPaste() ) + Paste() ; + return ; } - MacPostControlCreate(pos,size) ; - -#if !wxMAC_USE_MLTE_HIVIEW - if ( MacIsReallyShown() ) - MLTESetObjectVisibility( (STPTextPaneVars*) m_macTXNvars, true , GetWindowStyle() ) ; -#endif - + if ( key == 'x' && event.MetaDown() ) { - wxMacWindowClipper clipper( this ) ; -#if !wxMAC_USE_MLTE_HIVIEW - TPUpdateVisibility( *m_peer ) ; -#endif - SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; - - TXNSetSelection( (TXNObject) m_macTXN, 0, 0); - TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); + if ( CanCut() ) + Cut() ; + return ; } - - // in case MLTE is catching events before we get the chance to do so, we'd have to reintroduce the tlw-handler in front : - // parent->MacGetTopLevelWindow()->MacInstallTopLevelWindowEventHandler() ; + switch ( key ) + { + case WXK_RETURN: + if (m_windowStyle & wxPROCESS_ENTER) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + event.SetEventObject( this ); + event.SetString( GetValue() ); + if ( GetEventHandler()->ProcessEvent(event) ) + return; + } + if ( !(m_windowStyle & wxTE_MULTILINE) ) + { + wxWindow *parent = GetParent(); + while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { + parent = parent->GetParent() ; + } + if ( parent && parent->GetDefaultItem() ) + { + wxButton *def = wxDynamicCast(parent->GetDefaultItem(), + wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + return ; + } + } + + // this will make wxWidgets eat the ENTER key so that + // we actually prevent line wrapping in a single line + // text control + eat_key = TRUE; + } - SetBackgroundColour( *wxWHITE ) ; + break; - TXNBackground tback; - tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = MAC_WXCOLORREF( GetBackgroundColour().GetPixel() ); - TXNSetBackground( (TXNObject) m_macTXN , &tback); + case WXK_TAB: + if ( !(m_windowStyle & wxTE_PROCESS_TAB)) + { + int flags = 0; + if (!event.ShiftDown()) + flags |= wxNavigationKeyEvent::IsForward ; + if (event.ControlDown()) + flags |= wxNavigationKeyEvent::WinChange ; + Navigate(flags); + return; + } + else + { + // This is necessary (don't know why) or the tab will not + // be inserted. + WriteText(wxT("\t")); + } + + break; + } -#else - wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; - CFStringRef cfr = cf ; - Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; - m_peer = new wxMacControl() ; - CreateEditUnicodeTextControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , *m_peer ) ; - - if ( !(m_windowStyle & wxTE_MULTILINE) ) + if (!eat_key) { - Boolean singleline = true ; - ::SetControlData( *m_peer, kControlEditTextPart , kControlEditTextSingleLineTag , sizeof( singleline ) , &singleline ) ; + // perform keystroke handling + if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) + CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; + else + { + EventRecord rec ; + if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ) + { + EventRecord *ev = &rec ; + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; + + m_peer->HandleKey( keycode , keychar , ev->modifiers ) ; + } + } } - MacPostControlCreate(pos,size) ; - -#endif - if ( m_windowStyle & wxTE_READONLY) + if ( ( key >= 0x20 && key < WXK_START ) || + key == WXK_RETURN || + key == WXK_DELETE || + key == WXK_BACK) { - SetEditable( false ) ; + wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event1.SetString( GetValue() ) ; + event1.SetEventObject( this ); + wxPostEvent(GetEventHandler(),event1); } - +} - return TRUE; +// ---------------------------------------------------------------------------- +// standard handlers for standard edit menu events +// ---------------------------------------------------------------------------- + +void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); } -void wxTextCtrl::MacVisibilityChanged() +void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) { -#if wxMAC_USE_MLTE -#if !wxMAC_USE_MLTE_HIVIEW - MLTESetObjectVisibility((STPTextPaneVars*) m_macTXNvars , MacIsReallyShown() , GetWindowStyle() ) ; - if ( !MacIsReallyShown() ) - InvalWindowRect( GetControlOwner( *m_peer ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ; -#endif -#else - if ( !(m_windowStyle & wxTE_MULTILINE) && MacIsReallyShown() ) - { - // work around a refresh issue insofar as not always the entire content is shown even if this would be possible - ControlEditTextSelectionRec sel ; - CFStringRef value = NULL ; - Size actualSize = 0 ; - ResType datatag = GetWindowStyle() & wxTE_PASSWORD ? - kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ; + Copy(); +} - verify_noerr( GetControlData( *m_peer , 0, kControlEditTextSelectionTag, - sizeof(ControlEditTextSelectionRec), &sel, &actualSize ) ); - verify_noerr( GetControlData( *m_peer , 0, datatag , sizeof(CFStringRef), &value, &actualSize ) ); - - verify_noerr( SetControlData( *m_peer , 0, datatag, sizeof(CFStringRef), &value ) ); - verify_noerr( SetControlData( *m_peer , 0, kControlEditTextSelectionTag, sizeof(ControlEditTextSelectionRec), &sel ) ); - - CFRelease( value ) ; - } -#endif +void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); } -void wxTextCtrl::MacEnabledStateChanged() +void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) { + Undo(); } +void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} -wxString wxTextCtrl::GetValue() const +void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) { - wxString result ; -#if wxMAC_USE_MLTE - OSStatus err ; - Size actualSize = 0; - { -#if wxUSE_UNICODE - Handle theText ; - err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNUnicodeTextData ); - // all done - if ( err ) - { - actualSize = 0 ; - } - else - { - actualSize = GetHandleSize( theText ) / sizeof( UniChar) ; - if ( actualSize > 0 ) - { - wxChar *ptr = NULL ; -#if SIZEOF_WCHAR_T == 2 - ptr = new wxChar[actualSize + 1 ] ; - wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; - -#else - SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; - HLock( theText ) ; - (((UniChar*)*theText)[actualSize]) = 0 ; - wxMBConvUTF16BE converter ; - size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; - ptr = new wxChar[noChars + 1] ; - - noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ; - ptr[noChars] = 0 ; - HUnlock( theText ) ; -#endif - ptr[actualSize] = 0 ; - result = wxString( ptr ) ; - delete[] ptr ; - } - DisposeHandle( theText ) ; - } -#else - Handle theText ; - err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); - // all done - if ( err ) - { - actualSize = 0 ; - } - else - { - actualSize = GetHandleSize( theText ) ; - if ( actualSize > 0 ) - { - HLock( theText ) ; - result = wxString( *theText , wxConvLocal , actualSize ) ; - HUnlock( theText ) ; - } - DisposeHandle( theText ) ; - } -#endif - } -#else - CFStringRef value = NULL ; - Size actualSize = 0 ; - - verify_noerr( GetControlData( *m_peer , 0, GetWindowStyle() & wxTE_PASSWORD ? - kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag, - sizeof(CFStringRef), &value, &actualSize ) ); - if ( value ) - { - wxMacCFStringHolder cf(value) ; - result = cf.AsString() ; - } -#endif - wxMacConvertNewlines10To13( &result ) ; - return result ; + event.Enable( CanCut() ); } -void wxTextCtrl::GetSelection(long* from, long* to) const -{ -#if wxMAC_USE_MLTE - TXNGetSelection( (TXNObject) m_macTXN , (TXNOffset*) from , (TXNOffset*) to ) ; -#else - ControlEditTextSelectionRec sel ; - Size actualSize ; - verify_noerr( GetControlData( *m_peer , 0, kControlEditTextSelectionTag, - sizeof(ControlEditTextSelectionRec), &sel, &actualSize ) ); - if ( from ) *from = sel.selStart ; - if ( to ) *to = sel.selEnd ; -#endif +void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); } -void wxTextCtrl::SetValue(const wxString& str) +void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) { - // optimize redraws - if ( GetValue() == str ) - return ; - - wxString st = str ; - wxMacConvertNewlines13To10( &st ) ; -#if wxMAC_USE_MLTE - { - wxMacWindowClipper c( this ) ; - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - -#if !wxMAC_USE_MLTE_HIVIEW - // otherwise scrolling might have problems ? - TPUpdateVisibility( ( (STPTextPaneVars *)m_macTXNvars)->fUserPaneRec ) ; -#endif - SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; - TXNSetSelection( (TXNObject) m_macTXN, 0, 0); - TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); - if ( !formerEditable ) - SetEditable(formerEditable) ; - } -#else - wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; - CFStringRef value = cf ; - verify_noerr( SetControlData( *m_peer , 0, GetWindowStyle() & wxTE_PASSWORD ? - kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag, - sizeof(CFStringRef), &value ) ); -#endif + event.Enable( CanPaste() ); } -void wxTextCtrl::SetMaxLength(unsigned long len) +void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) { - m_maxLength = len ; + event.Enable( CanUndo() ); } -bool wxTextCtrl::SetFont( const wxFont& font ) +void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) { - if ( !wxTextCtrlBase::SetFont( font ) ) - return FALSE ; - -#if wxMAC_USE_MLTE - wxMacWindowClipper c( this ) ; - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - - TXNTypeAttributes typeAttr[4] ; - Str255 fontName = "\pMonaco" ; - SInt16 fontSize = 12 ; - Style fontStyle = normal ; - int attrCounter = 0 ; - - wxMacStringToPascal( font.GetFaceName() , fontName ) ; - fontSize = font.MacGetFontSize() ; - fontStyle = font.MacGetFontStyle() ; - - typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; - typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) fontName ; - typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; - typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; - typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; - typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; - typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; - typeAttr[attrCounter+2].data.dataValue = fontStyle ; - attrCounter += 3 ; - /* - typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; - typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) &color ; - color = MAC_WXCOLORREF(GetForegroundColour().GetPixel()) ; - attrCounter += 1 ; - */ - verify_noerr( TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, kTXNStartOffset,kTXNEndOffset) ); - - if ( !formerEditable ) - SetEditable(formerEditable) ; -#endif - return true ; + event.Enable( CanRedo() ); } -bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) +bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) { -#if wxMAC_USE_MLTE - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNTypeAttributes typeAttr[4] ; - Str255 fontName = "\pMonaco" ; - SInt16 fontSize = 12 ; - Style fontStyle = normal ; - RGBColor color ; - int attrCounter = 0 ; - if ( style.HasFont() ) - { - const wxFont &font = style.GetFont() ; - wxMacStringToPascal( font.GetFaceName() , fontName ) ; - fontSize = font.GetPointSize() ; - if ( font.GetUnderlined() ) - fontStyle |= underline ; - if ( font.GetWeight() == wxBOLD ) - fontStyle |= bold ; - if ( font.GetStyle() == wxITALIC ) - fontStyle |= italic ; - - typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; - typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) fontName ; - typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; - typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; - typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; - typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; - typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; - typeAttr[attrCounter+2].data.dataValue = fontStyle ; - attrCounter += 3 ; + return true ; +} - } - if ( style.HasTextColour() ) - { - typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; - typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) &color ; - color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; - attrCounter += 1 ; - } +// user pane implementation - if ( attrCounter > 0 ) - { - verify_noerr( TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, start,end) ); - } - if ( !formerEditable ) - SetEditable(formerEditable) ; -#endif - return TRUE ; +void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) +{ } -bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) +wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) { - wxTextCtrlBase::SetDefaultStyle( style ) ; - SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; - return TRUE ; + return kControlNoPart ; } -// Clipboard operations -void wxTextCtrl::Copy() +wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) { - if (CanCopy()) - { -#if wxMAC_USE_MLTE - ClearCurrentScrap(); - TXNCopy((TXNObject)m_macTXN); - TXNConvertToPublicScrap(); -#else - m_peer->SendHICommand( kHICommandCopy ) ; -#endif - } + return kControlNoPart ; } -void wxTextCtrl::Cut() +void wxTextCtrl::MacControlUserPaneIdleProc() { - if (CanCut()) - { -#if wxMAC_USE_MLTE - ClearCurrentScrap(); - TXNCut((TXNObject)m_macTXN); - TXNConvertToPublicScrap(); -#else - m_peer->SendHICommand( kHICommandCut ) ; -#endif - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - event.SetString( GetValue() ) ; - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } } -void wxTextCtrl::Paste() +wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) { - if (CanPaste()) - { -#if wxMAC_USE_MLTE - TXNConvertFromPublicScrap(); - TXNPaste((TXNObject)m_macTXN); - SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; -#else - m_peer->SendHICommand( kHICommandPaste ) ; -#endif - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - event.SetString( GetValue() ) ; - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } + return kControlNoPart ; } -bool wxTextCtrl::CanCopy() const +void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) { - // Can copy if there's a selection - long from, to; - GetSelection(& from, & to); - return (from != to); } -bool wxTextCtrl::CanCut() const +wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) { - if ( !IsEditable() ) - { - return false ; - } - // Can cut if there's a selection - long from, to; - GetSelection(& from, & to); - return (from != to); + return kControlNoPart ; } -bool wxTextCtrl::CanPaste() const +void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) { - if (!IsEditable()) - return FALSE; +} -#if wxMAC_USE_MLTE - return TXNIsScrapPastable() ; -#else - return true ; -#endif +// ---------------------------------------------------------------------------- +// implementation base class +// ---------------------------------------------------------------------------- + +wxMacTextControl::wxMacTextControl() +{ } -void wxTextCtrl::SetEditable(bool editable) +wxMacTextControl::~wxMacTextControl() { - if ( editable != m_editable ) - { - m_editable = editable ; -#if wxMAC_USE_MLTE - TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; - TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; - TXNSetTXNObjectControls( (TXNObject) m_macTXN , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ; -#else - Boolean value = !editable ; - ::SetControlData( *m_peer, 0, kControlEditTextLockedTag , sizeof( value ) , &value ) ; -#endif - } } -void wxTextCtrl::SetInsertionPoint(long pos) +void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style) { - SetSelection( pos , pos ) ; } -void wxTextCtrl::SetInsertionPointEnd() +void wxMacTextControl::Copy() { - long pos = GetLastPosition(); - SetInsertionPoint(pos); } -long wxTextCtrl::GetInsertionPoint() const +void wxMacTextControl::Cut() { - long begin,end ; - GetSelection( &begin , &end ) ; - return begin ; } -long wxTextCtrl::GetLastPosition() const +void wxMacTextControl::Paste() { - long actualsize = 0 ; -#if wxMAC_USE_MLTE - Handle theText ; - OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); - /* all done */ - if ( err ) - { - actualsize = 0 ; - } - else - { - actualsize = GetHandleSize( theText ) ; - DisposeHandle( theText ) ; - } -#endif - return actualsize ; } -void wxTextCtrl::Replace(long from, long to, const wxString& str) +bool wxMacTextControl::CanPaste() const +{ + return false ; +} + +void wxMacTextControl::SetEditable(bool editable) { -#if wxMAC_USE_MLTE - wxString value = str ; - wxMacConvertNewlines13To10( &value ) ; +} - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; - TXNClear( ((TXNObject) m_macTXN) ) ; - SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; - if ( !formerEditable ) - SetEditable( formerEditable ) ; +long wxMacTextControl::GetLastPosition() const +{ + return GetStringValue().Length() ; +} - Refresh() ; -#endif +void wxMacTextControl::Replace( long from , long to , const wxString str ) +{ } -void wxTextCtrl::Remove(long from, long to) +void wxMacTextControl::Clear() { -#if wxMAC_USE_MLTE - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; - TXNClear( ((TXNObject) m_macTXN) ) ; - if ( !formerEditable ) - SetEditable( formerEditable ) ; - - Refresh() ; -#endif + SetStringValue( wxEmptyString ) ; } -void wxTextCtrl::SetSelection(long from, long to) +bool wxMacTextControl::CanUndo() const { -#if wxMAC_USE_MLTE - /* change the selection */ - if ((from == -1) && (to == -1)) - TXNSelectAll((TXNObject) m_macTXN); - else - TXNSetSelection( (TXNObject) m_macTXN, from, to); - TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); -#else - ControlEditTextSelectionRec sel ; - sel.selStart = from ; - sel.selEnd = to ; - verify_noerr( SetControlData( *m_peer , 0, kControlEditTextSelectionTag, - sizeof(ControlEditTextSelectionRec), &sel ) ); + return false ; +} -#endif +void wxMacTextControl::Undo() { } + +bool wxMacTextControl::CanRedo() const +{ + return false ; +} + +void wxMacTextControl::Redo() +{ } -bool wxTextCtrl::LoadFile(const wxString& file) +long wxMacTextControl::XYToPosition(long x, long y) const { - if ( wxTextCtrlBase::LoadFile(file) ) - { - return TRUE; - } + return 0 ; +} - return FALSE; +bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const +{ + return false ; } -class wxMacFunctor +void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) +{ +} + +int wxMacTextControl::GetNumberOfLines() const { -public : - wxMacFunctor(){} - virtual ~wxMacFunctor() {} - virtual void* operator()() = 0 ; - static void* CallBackProc(void *param) + ItemCount lines = 0 ; + wxString content = GetStringValue() ; + lines = 1; + for (size_t i = 0; i < content.Length() ; i++) { - wxMacFunctor* f = (wxMacFunctor*) param ; - void *result = (*f)() ; - return result ; + if (content[i] == '\r') lines++; } -} ; + return lines ; +} -template -class wxMacObjectFunctor1 : public wxMacFunctor +wxString wxMacTextControl::GetLineText(long lineNo) const { - typedef void (classtype::*function)( param1type p1 ) ; - typedef void (classtype::*ref_function)( const param1type& p1 ) ; -public : - wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) : - wxMacFunctor( ) + // TODO change this if possible to reflect real lines + wxString content = GetStringValue() ; + + // Find line first + int count = 0; + for (size_t i = 0; i < content.Length() ; i++) { - m_object = obj ; - m_function = f ; - m_param1 = p1 ; + if (count == lineNo) + { + // Add chars in line then + wxString tmp; + + for (size_t j = i; j < content.Length(); j++) + { + if (content[j] == '\n') + return tmp; + + tmp += content[j]; + } + + return tmp; + } + if (content[i] == '\n') count++; } + return wxEmptyString ; +} - wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) : - wxMacFunctor( ) +int wxMacTextControl::GetLineLength(long lineNo) const +{ + // TODO change this if possible to reflect real lines + wxString content = GetStringValue() ; + + // Find line first + int count = 0; + for (size_t i = 0; i < content.Length() ; i++) { - m_object = obj ; - m_refFunction = f ; - m_param1 = p1 ; + if (count == lineNo) + { + // Count chars in line then + count = 0; + for (size_t j = i; j < content.Length(); j++) + { + count++; + if (content[j] == '\n') return count; + } + + return count; + } + if (content[i] == '\n') count++; } + return 0 ; +} - ~wxMacObjectFunctor1() {} +// ---------------------------------------------------------------------------- +// standard unicode control implementation +// ---------------------------------------------------------------------------- + +#if TARGET_API_MAC_OSX + +wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) +{ + m_font = wxPeer->GetFont() ; + m_windowStyle = style ; + Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; + wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; + CFStringRef cfr = cf ; + Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; + m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ; + CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , &m_controlRef ) ; - virtual void* operator()() + if ( !(m_windowStyle & wxTE_MULTILINE) ) { - (m_object->*m_function)(m_param1) ; - return NULL ; + SetData( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; } -private : - classtype* m_object ; - param1type m_param1 ; - union - { - function m_function ; - ref_function m_refFunction ; - } ; -} ; +} -template -void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) +wxMacUnicodeTextControl::~wxMacUnicodeTextControl() { - wxMacObjectFunctor1 params(object,function,p1) ; - void *result = - MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; - return result ; } -template -void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) +void wxMacUnicodeTextControl::VisibilityChanged(bool shown) { - wxMacObjectFunctor1 params(object,function,p1) ; - void *result = - MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; - return result ; -} + if ( !(m_windowStyle & wxTE_MULTILINE) && shown ) + { + // work around a refresh issue insofar as not always the entire content is shown even if this would be possible + ControlEditTextSelectionRec sel ; + CFStringRef value = NULL ; -template -void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) + verify_noerr( GetData( 0, kControlEditTextSelectionTag, &sel ) ); + verify_noerr( GetData( 0, m_valueTag , &value ) ); + verify_noerr( SetData( 0, m_valueTag, &value ) ); + verify_noerr( SetData( 0, kControlEditTextSelectionTag, &sel ) ); + + CFRelease( value ) ; + } +} +wxString wxMacUnicodeTextControl::GetStringValue() const { - wxMutexGuiLeave() ; - void *result = wxMacMPRemoteCall( object , function , p1 ) ; - wxMutexGuiEnter() ; + wxString result ; + CFStringRef value = GetData(0,m_valueTag) ; + if ( value ) + { + wxMacCFStringHolder cf(value) ; + result = cf.AsString() ; + } + wxMacConvertNewlines10To13( &result ) ; return result ; } +void wxMacUnicodeTextControl::SetStringValue( const wxString &str) +{ + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; + wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; + verify_noerr( SetData( 0, m_valueTag , cf ) ) ; +} +void wxMacUnicodeTextControl::Copy() +{ + SendHICommand( kHICommandCopy ) ; +} +void wxMacUnicodeTextControl::Cut() +{ + SendHICommand( kHICommandCut ) ; +} +void wxMacUnicodeTextControl::Paste() +{ + SendHICommand( kHICommandPaste ) ; +} +bool wxMacUnicodeTextControl::CanPaste() const +{ + return true ; +} +void wxMacUnicodeTextControl::SetEditable(bool editable) +{ + SetData( 0 , kControlEditTextLockedTag , (Boolean) !editable ) ; +} +void wxMacUnicodeTextControl::Remove( long from , long to ) +{ +} -template -void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) +void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const { - wxMutexGuiLeave() ; - void *result = wxMacMPRemoteCall( object , function , p1 ) ; - wxMutexGuiEnter() ; - return result ; + ControlEditTextSelectionRec sel ; + verify_noerr(GetData( 0, kControlEditTextSelectionTag, &sel ) ) ; + if ( from ) *from = sel.selStart ; + if ( to ) *to = sel.selEnd ; } -void wxTextCtrl::WriteText(const wxString& str) +void wxMacUnicodeTextControl::SetSelection( long from , long to ) { - if ( !wxIsMainThread() ) - { - // unfortunately CW 8 is not able to correctly deduce the template types, so we have - // to instantiate explicitely - wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; - return ; - } - else - { - wxString st = str ; - wxMacConvertNewlines13To10( &st ) ; - #if wxMAC_USE_MLTE - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - { - wxMacWindowStateSaver s( this ) ; - long start , end , dummy ; - GetSelection( &start , &dummy ) ; - SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; - GetSelection( &dummy , &end ) ; - SetStyle( start , end , GetDefaultStyle() ) ; - } - if ( !formerEditable ) - SetEditable( formerEditable ) ; + ControlEditTextSelectionRec sel ; + sel.selStart = from ; + sel.selEnd = to ; + SetData( 0 , kControlEditTextSelectionTag, &sel ) ; +} - MacRedrawControl() ; - #else +void wxMacUnicodeTextControl::WriteText(const wxString& str) +{ + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; CFStringRef value = cf ; - SetControlData( *m_peer , 0, kControlEditTextInsertCFStringRefTag, - sizeof(CFStringRef), &value ); + SetData( 0, kControlEditTextInsertCFStringRefTag, &value ); #else - wxString val = GetValue() ; + wxString val = GetStringValue() ; long start , end ; GetSelection( &start , &end ) ; val.Remove( start , end - start ) ; val.insert( start , str ) ; - SetValue( val ) ; + SetStringValue( val ) ; SetInsertionPoint( start + str.Length() ) ; #endif - #endif - } -} - -void wxTextCtrl::AppendText(const wxString& text) -{ - SetInsertionPointEnd(); - WriteText(text); } -void wxTextCtrl::Clear() -{ -#if wxMAC_USE_MLTE - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNSetSelection( (TXNObject)m_macTXN , kTXNStartOffset , kTXNEndOffset ) ; - TXNClear((TXNObject)m_macTXN); +#endif - if ( !formerEditable ) - SetEditable( formerEditable ) ; +// ---------------------------------------------------------------------------- +// MLTE control implementation (common part) +// ---------------------------------------------------------------------------- - Refresh() ; -#else - SetValue(wxEmptyString) ; +#if TARGET_API_MAC_OSX == 0 +// declaration needed because of one line in the code... +static void TPUpdateVisibility(ControlRef theControl) ; #endif -} -bool wxTextCtrl::IsModified() const -{ - return m_dirty; -} +// if mlte is on read only , no changes at all are allowed, not even from +// procedural API, in order to allow changes via API all the same we must undo +// the readonly status while we are executing, this class helps to do so -bool wxTextCtrl::IsEditable() const +class EditHelper { - return IsEnabled() && m_editable ; -} +public : + EditHelper( TXNObject txn ) + { + TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; + m_txn = txn ; + TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ; + if ( m_data[0].uValue == kTXNReadOnly ) + { + TXNControlData data[] = { { kTXNReadWrite } } ; + TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; + } + } + ~EditHelper() + { + TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; + if ( m_data[0].uValue == kTXNReadOnly ) + { + TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; + } + } + protected : + TXNObject m_txn ; + TXNControlData m_data[1] ; +} ; -bool wxTextCtrl::AcceptsFocus() const +wxString wxMacMLTEControl::GetStringValue() const { - // we don't want focus if we can't be edited - return /*IsEditable() && */ wxControl::AcceptsFocus(); + wxString result ; + OSStatus err ; + Size actualSize = 0; + { +#if wxUSE_UNICODE + Handle theText ; + err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNUnicodeTextData ); + // all done + if ( err ) + { + actualSize = 0 ; + } + else + { + actualSize = GetHandleSize( theText ) / sizeof( UniChar) ; + if ( actualSize > 0 ) + { + wxChar *ptr = NULL ; +#if SIZEOF_WCHAR_T == 2 + ptr = new wxChar[actualSize + 1 ] ; + wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; + +#else + SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; + HLock( theText ) ; + (((UniChar*)*theText)[actualSize]) = 0 ; + wxMBConvUTF16BE converter ; + size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; + ptr = new wxChar[noChars + 1] ; + + noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ; + ptr[noChars] = 0 ; + HUnlock( theText ) ; +#endif + ptr[actualSize] = 0 ; + result = wxString( ptr ) ; + delete[] ptr ; + } + DisposeHandle( theText ) ; + } +#else + Handle theText ; + err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); + // all done + if ( err ) + { + actualSize = 0 ; + } + else + { + actualSize = GetHandleSize( theText ) ; + if ( actualSize > 0 ) + { + HLock( theText ) ; + result = wxString( *theText , wxConvLocal , actualSize ) ; + HUnlock( theText ) ; + } + DisposeHandle( theText ) ; + } +#endif + } + wxMacConvertNewlines10To13( &result ) ; + return result ; } -wxSize wxTextCtrl::DoGetBestSize() const +void wxMacMLTEControl::SetStringValue( const wxString &str) { - int wText = 100 ; + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; + EditHelper help(m_txn) ; - int hText; + // wxMacWindowClipper c( this ) ; +#if !TARGET_API_MAC_OSX + // otherwise scrolling might have problems ? + TPUpdateVisibility( m_controlRef ) ; +#endif + SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; + TXNSetSelection( m_txn, 0, 0); + TXNShowSelection( m_txn, kTXNShowStart); +} - switch( m_windowVariant ) +TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) +{ + TXNFrameOptions frameOptions = + kTXNDontDrawCaretWhenInactiveMask ; + if ( ! ( wxStyle & wxTE_NOHIDESEL ) ) + frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; + + if ( wxStyle & wxTE_MULTILINE ) { - case wxWINDOW_VARIANT_NORMAL : - hText = 22 ; - break ; - case wxWINDOW_VARIANT_SMALL : - hText = 19 ; - break ; - case wxWINDOW_VARIANT_MINI : - hText= 15 ; - break ; - default : - hText = 22 ; - break ; - } + if ( ! ( wxStyle & wxTE_DONTWRAP ) ) + frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; + else + { + frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; + frameOptions |= kTXNWantHScrollBarMask ; + } -#if !wxMAC_USE_MLTE - // unicode text control is using client size, ie 3 pixels on every side - // TODO make this fit into normal window size concept, probably having - // to reintroduce the margin vars - hText -= 6 ; -#endif + if ( !(wxStyle & wxTE_NO_VSCROLL ) ) + frameOptions |= kTXNWantVScrollBarMask ; + } + else + frameOptions |= kTXNSingleLineOnlyMask ; + + if ( wxStyle & wxHSCROLL ) + frameOptions |= kTXNWantHScrollBarMask ; + + return frameOptions ; +} +void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible ) +{ + TXNControlTag iControlTags[3] = { kTXNDoFontSubstitution, kTXNWordWrapStateTag }; + TXNControlData iControlData[3] = { {false}, {kTXNNoAutoWrap} }; + int toptag = 2 ; +#if TARGET_API_MAC_OSX + iControlTags[2] = kTXNVisibilityTag ; + iControlData[2].uValue = visible ; + toptag++ ; +#endif + if ( m_windowStyle & wxTE_MULTILINE ) { - hText *= 5 ; + if (m_windowStyle & wxTE_DONTWRAP) + iControlData[1].uValue = kTXNNoAutoWrap ; + else + iControlData[1].uValue = kTXNAutoWrap ; + } + verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, + iControlTags, iControlData )) ; - return wxSize(wText, hText); -} + // setting the default font -// ---------------------------------------------------------------------------- -// Undo/redo -// ---------------------------------------------------------------------------- + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; -void wxTextCtrl::Undo() -{ - if (CanUndo()) + GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + + TXNTypeAttributes typeAttr[] = { -#if wxMAC_USE_MLTE - TXNUndo((TXNObject)m_macTXN); -#endif + { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , + { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , + { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , + } ; + + verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, + kTXNStartOffset, + kTXNEndOffset) ); + + if ( m_windowStyle & wxTE_PASSWORD ) + { + UniChar c = 0xA5 ; + verify_noerr(TXNEchoMode( m_txn , c , 0 , true )) ; } + + TXNBackground tback; + tback.bgType = kTXNBackgroundTypeRGB; + tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); + TXNSetBackground( m_txn , &tback); } -void wxTextCtrl::Redo() +int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttributes typeAttr[] ) { - if (CanRedo()) + Str255 fontName = "\pMonaco" ; + SInt16 fontSize = 12 ; + Style fontStyle = normal ; + RGBColor color ; + int attrCounter = 0 ; + if ( style.HasFont() ) { -#if wxMAC_USE_MLTE - TXNRedo((TXNObject)m_macTXN); -#endif + const wxFont &font = style.GetFont() ; + wxMacStringToPascal( font.GetFaceName() , fontName ) ; + fontSize = font.GetPointSize() ; + if ( font.GetUnderlined() ) + fontStyle |= underline ; + if ( font.GetWeight() == wxBOLD ) + fontStyle |= bold ; + if ( font.GetStyle() == wxITALIC ) + fontStyle |= italic ; + + typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; + typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) fontName ; + typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; + typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; + typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; + typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; + typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; + typeAttr[attrCounter+2].data.dataValue = fontStyle ; + attrCounter += 3 ; + + } + if ( style.HasTextColour() ) + { + typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; + typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) &color ; + color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; + attrCounter += 1 ; } + return attrCounter ; } -bool wxTextCtrl::CanUndo() const +void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) { - if ( !IsEditable() ) + EditHelper help(m_txn) ; + wxTextAttr style(wxNullColour,wxNullColour,font) ; + TXNTypeAttributes typeAttr[4] ; + int attrCounter = ConvertAttribute( style , typeAttr ) ; + if ( attrCounter > 0 ) { - return false ; + verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, kTXNStartOffset,kTXNEndOffset) ); } -#if wxMAC_USE_MLTE - return TXNCanUndo((TXNObject)m_macTXN,NULL); -#else - return false ; -#endif } - -bool wxTextCtrl::CanRedo() const -{ - if ( !IsEditable() ) +void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style) +{ + EditHelper help(m_txn) ; + TXNTypeAttributes typeAttr[4] ; + int attrCounter = ConvertAttribute( style , typeAttr ) ; + if ( attrCounter > 0 ) { - return false ; + verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, start,end) ); } -#if wxMAC_USE_MLTE - return TXNCanRedo((TXNObject)m_macTXN,NULL); -#else - return false ; -#endif +} + +void wxMacMLTEControl::Copy() +{ + ClearCurrentScrap(); + TXNCopy(m_txn); + TXNConvertToPublicScrap(); } -// Makes modifie or unmodified -void wxTextCtrl::MarkDirty() +void wxMacMLTEControl::Cut() { - m_dirty = true; + ClearCurrentScrap(); + TXNCut(m_txn); + TXNConvertToPublicScrap(); } -void wxTextCtrl::DiscardEdits() +void wxMacMLTEControl::Paste() { - m_dirty = false; + TXNConvertFromPublicScrap(); + TXNPaste(m_txn); } -int wxTextCtrl::GetNumberOfLines() const +bool wxMacMLTEControl::CanPaste() const { - ItemCount lines = 0 ; -#if wxMAC_USE_MLTE - TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; -#else - wxString content = GetValue() ; - lines = 1; - for (size_t i = 0; i < content.Length() ; i++) - { - if (content[i] == '\r') lines++; - } -#endif - return lines ; + return TXNIsScrapPastable() ; } -long wxTextCtrl::XYToPosition(long x, long y) const +void wxMacMLTEControl::SetEditable(bool editable) { -#if wxMAC_USE_MLTE - Point curpt ; - - long lastpos = GetLastPosition() ; - - // TODO find a better implementation : while we can get the - // line metrics of a certain line, we don't get its starting - // position, so it would probably be rather a binary search - // for the start position - long xpos = 0 ; - long ypos = 0 ; - int lastHeight = 0 ; + TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; + TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; + TXNSetTXNObjectControls( m_txn , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ; +} - ItemCount n ; +long wxMacMLTEControl::GetLastPosition() const +{ + long actualsize = 0 ; + + Handle theText ; + OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); + /* all done */ + if ( err ) + { + actualsize = 0 ; + } + else + { + actualsize = GetHandleSize( theText ) ; + DisposeHandle( theText ) ; + } + + return actualsize ; +} + +void wxMacMLTEControl::Replace( long from , long to , const wxString str ) +{ + wxString value = str ; + wxMacConvertNewlines13To10( &value ) ; + + EditHelper help( m_txn ) ; + + TXNSetSelection(m_txn , from , to ) ; + TXNClear( m_txn ) ; + SetTXNData( str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; +} + +void wxMacMLTEControl::Remove( long from , long to ) +{ + EditHelper help( m_txn ) ; + + TXNSetSelection(m_txn , from , to ) ; + TXNClear( m_txn ) ; +} + +void wxMacMLTEControl::GetSelection( long* from, long* to) const +{ + TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ; +} + +void wxMacMLTEControl::SetSelection( long from , long to ) +{ + /* change the selection */ + if ((from == -1) && (to == -1)) + TXNSelectAll(m_txn); + else + TXNSetSelection( m_txn, from, to); + TXNShowSelection( m_txn, kTXNShowStart); +} + +void wxMacMLTEControl::WriteText(const wxString& str) +{ + EditHelper helper( m_txn ) ; + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; + + long start , end , dummy ; + GetSelection( &start , &dummy ) ; + SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; + GetSelection( &dummy , &end ) ; + // TODO SetStyle( start , end , GetDefaultStyle() ) ; +} + +void wxMacMLTEControl::Clear() +{ + EditHelper st(m_txn) ; + TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; + TXNClear(m_txn); +} + +bool wxMacMLTEControl::CanUndo() const +{ + return TXNCanUndo( m_txn , NULL ) ; +} + +void wxMacMLTEControl::Undo() +{ + TXNUndo( m_txn ) ; +} + +bool wxMacMLTEControl::CanRedo() const +{ + return TXNCanRedo( m_txn , NULL ) ; +} + +void wxMacMLTEControl::Redo() +{ + TXNRedo( m_txn ) ; +} + +int wxMacMLTEControl::GetNumberOfLines() const +{ + ItemCount lines = 0 ; + TXNGetLineCount(m_txn, &lines ) ; + return lines ; +} + +long wxMacMLTEControl::XYToPosition(long x, long y) const +{ + Point curpt ; + + long lastpos = GetLastPosition() ; + + // TODO find a better implementation : while we can get the + // line metrics of a certain line, we don't get its starting + // position, so it would probably be rather a binary search + // for the start position + long xpos = 0 ; + long ypos = 0 ; + int lastHeight = 0 ; + + ItemCount n ; for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) { if ( y == ypos && x == xpos ) return n ; - TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); + TXNOffsetToPoint( m_txn , n , &curpt); if ( curpt.v > lastHeight ) { @@ -1685,13 +1694,11 @@ long wxTextCtrl::XYToPosition(long x, long y) const else ++xpos ; } -#endif - return 0; + return 0 ; } -bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const +bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const { -#if wxMAC_USE_MLTE Point curpt ; long lastpos = GetLastPosition() ; @@ -1712,7 +1719,7 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const ItemCount n ; for ( n = 0 ; n <= (ItemCount) pos ; ++n ) { - TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); + TXNOffsetToPoint(m_txn , n , &curpt); if ( curpt.v > lastHeight ) { @@ -1727,43 +1734,64 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const if ( y ) *y = ypos ; if ( x ) *x = xpos ; } -#else - if ( y ) *y = 0 ; - if ( x ) *x = 0 ; -#endif + return FALSE ; } -void wxTextCtrl::ShowPosition(long pos) +void wxMacMLTEControl::ShowPosition( long pos ) { -#if wxMAC_USE_MLTE #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) { Point current ; Point desired ; TXNOffset selstart , selend ; - TXNGetSelection( (TXNObject) m_macTXN , &selstart , &selend) ; - TXNOffsetToPoint( (TXNObject) m_macTXN, selstart , ¤t); - TXNOffsetToPoint( (TXNObject) m_macTXN, pos , &desired); + TXNGetSelection( m_txn , &selstart , &selend) ; + TXNOffsetToPoint( m_txn, selstart , ¤t); + TXNOffsetToPoint( m_txn, pos , &desired); //TODO use HIPoints for 10.3 and above if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress ) { OSErr theErr = noErr; SInt32 dv = desired.v - current.v ; SInt32 dh = desired.h - current.h ; - TXNShowSelection( (TXNObject) m_macTXN , true ) ; - theErr = TXNScroll( (TXNObject) m_macTXN, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); + TXNShowSelection( m_txn , true ) ; + theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); } } #endif +} + +void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) +{ +#if wxUSE_UNICODE +#if SIZEOF_WCHAR_T == 2 + size_t len = st.Len() ; + TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, + start, end); +#else + wxMBConvUTF16BE converter ; + ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; + UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; + converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; + TXNSetData( m_txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen , + start, end); + free( unibuf ) ; #endif +#else + wxCharBuffer text = st.mb_str(wxConvLocal) ; + TXNSetData( m_txn , kTXNTextData, (void*)text.data(), strlen( text ) , + start, end); +#endif } -int wxTextCtrl::GetLineLength(long lineNo) const + +wxString wxMacMLTEControl::GetLineText(long lineNo) const { -#if wxMAC_USE_MLTE + wxString line ; Point curpt ; + wxString content = GetStringValue() ; + if ( lineNo < GetNumberOfLines() ) { // TODO find a better implementation : while we can get the @@ -1776,14 +1804,14 @@ int wxTextCtrl::GetLineLength(long lineNo) const long lastpos = GetLastPosition() ; ItemCount n ; - for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) + for ( n = 0 ; n <= (ItemCount)lastpos ; ++n ) { - TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); + TXNOffsetToPoint( m_txn, n , &curpt); if ( curpt.v > lastHeight ) { if ( ypos == lineNo ) - return xpos ; + return line ; xpos = 0 ; if ( n > 0 ) @@ -1791,42 +1819,19 @@ int wxTextCtrl::GetLineLength(long lineNo) const lastHeight = curpt.v ; } else - ++xpos ; - } - } -#else - // TODO change this if possible to reflect real lines - wxString content = GetValue() ; - - // Find line first - int count = 0; - for (size_t i = 0; i < content.Length() ; i++) - { - if (count == lineNo) - { - // Count chars in line then - count = 0; - for (size_t j = i; j < content.Length(); j++) { - count++; - if (content[j] == '\n') return count; + if ( ypos == lineNo ) + line += content[n] ; + ++xpos ; } - - return count; } - if (content[i] == '\n') count++; } -#endif - return 0; + return line ; } -wxString wxTextCtrl::GetLineText(long lineNo) const +int wxMacMLTEControl::GetLineLength(long lineNo) const { -#if wxMAC_USE_MLTE - wxString line ; Point curpt ; - wxString content = GetValue() ; - if ( lineNo < GetNumberOfLines() ) { // TODO find a better implementation : while we can get the @@ -1839,14 +1844,14 @@ wxString wxTextCtrl::GetLineText(long lineNo) const long lastpos = GetLastPosition() ; ItemCount n ; - for ( n = 0 ; n <= (ItemCount)lastpos ; ++n ) + for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) { - TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); + TXNOffsetToPoint( m_txn , n , &curpt); if ( curpt.v > lastHeight ) { if ( ypos == lineNo ) - return line ; + return xpos ; xpos = 0 ; if ( n > 0 ) @@ -1854,285 +1859,659 @@ wxString wxTextCtrl::GetLineText(long lineNo) const lastHeight = curpt.v ; } else - { - if ( ypos == lineNo ) - line += content[n] ; ++xpos ; - } } } - return line ; -#else - // TODO change this if possible to reflect real lines - wxString content = GetValue() ; + return 0 ; +} - // Find line first - int count = 0; - for (size_t i = 0; i < content.Length() ; i++) - { - if (count == lineNo) - { - // Add chars in line then - wxString tmp; - for (size_t j = i; j < content.Length(); j++) - { - if (content[j] == '\n') - return tmp; +// ---------------------------------------------------------------------------- +// MLTE control implementation (classic part) +// ---------------------------------------------------------------------------- - tmp += content[j]; - } +#if !TARGET_API_MAC_OSX - return tmp; - } - if (content[i] == '\n') count++; - } - return wxEmptyString ; -#endif -} +// CS:TODO we still have a problem getting properly at the text events of a control because under Carbon +// the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the +// moment is to avoid setting the true focus on the control, the proper solution at the end would be to have +// an alternate path for carbon key events that routes automatically into the same wx flow of events -/* - * Text item - */ +/* part codes */ -void wxTextCtrl::Command(wxCommandEvent & event) -{ - SetValue (event.GetString()); - ProcessCommand (event); -} +/* kmUPTextPart is the part code we return to indicate the user has clicked +in the text area of our control */ +#define kmUPTextPart 1 -void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) + +/* routines for using existing user pane controls. +These routines are useful for cases where you would like to use an +existing user pane control in, say, a dialog window as a scrolling +text edit field.*/ + +/* Utility Routines */ + +/* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus +routine. In our focus switching routine this part code is understood +as meaning 'the user has clicked in the control and we need to switch +the current focus to ourselves before we can continue'. */ +#define kUserClickedToFocusPart 100 + +/* STPTextPaneVars is a structure used for storing the the mUP Control's +internal variables and state information. A handle to this record is +stored in the pane control's reference value field using the +SetControlReference routine. */ + +class STPTextPaneVars { +public : + /* OS records referenced */ + TXNObject fTXNRec; /* the txn record */ + TXNFrameID fTXNFrame; /* the txn frame ID */ + ControlRef fUserPaneRec; /* handle to the user pane control */ + WindowPtr fOwner; /* window containing control */ + GrafPtr fDrawingEnvironment; /* grafport where control is drawn */ + /* flags */ + Boolean fInFocus; /* true while the focus rect is drawn around the control */ + Boolean fIsActive; /* true while the control is drawn in the active state */ + Boolean fTXNObjectActive; /* reflects the activation state of the text edit record */ + Boolean fFocusDrawState; /* true if focus is drawn (default: true) */ + /* calculated locations */ + Rect fRBounds; /* control bounds */ + Rect fRTextArea; /* area where the text is drawn */ + Rect fRFocusOutline; /* rectangle used to draw the focus box */ + Rect fRTextOutline; /* rectangle used to draw the border */ + RgnHandle fRTextOutlineRegion; /* background region for the text, erased before calling TEUpdate */ + /* our focus advance override routine */ + EventHandlerUPP handlerUPP; + EventHandlerRef handlerRef; + bool fNoBorders ; + bool fMultiline ; + bool fVisible ; +} ; + +/* Univerals Procedure Pointer variables used by the +mUP Control. These variables are set up +the first time that mUPOpenControl is called. */ +ControlUserPaneDrawUPP gTPDrawProc = NULL; +ControlUserPaneHitTestUPP gTPHitProc = NULL; +ControlUserPaneTrackingUPP gTPTrackProc = NULL; +ControlUserPaneIdleUPP gTPIdleProc = NULL; +ControlUserPaneKeyDownUPP gTPKeyProc = NULL; +ControlUserPaneActivateUPP gTPActivateProc = NULL; +ControlUserPaneFocusUPP gTPFocusProc = NULL; + +// one place for calculating all +static void TPCalculateBounds(STPTextPaneVars *varsp, const Rect& bounds) { - // By default, load the first file into the text window. - if (event.GetNumberOfFiles() > 0) + SetRect(&varsp->fRBounds, bounds.left, bounds.top, bounds.right, bounds.bottom); + SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); + // eventually make TextOutline inset 1,1 + SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); + if ( !varsp->fNoBorders ) { - LoadFile(event.GetFiles()[0]); + SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) , + bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2)); + } + else + { + SetRect(&varsp->fRTextArea, bounds.left , bounds.top , + bounds.right, bounds.bottom); } } -void wxTextCtrl::OnChar(wxKeyEvent& event) +OSStatus MLTESetObjectVisibility( STPTextPaneVars *varsp, Boolean vis , long wxStyle) { - int key = event.GetKeyCode() ; - bool eat_key = false ; - - if ( key == 'c' && event.MetaDown() ) + OSStatus err = noErr ; +#if TARGET_API_MAC_OSX + TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; + TXNControlData iControlData[1] = {{ vis }}; + err = ::TXNSetTXNObjectControls( varsp->fTXNRec, false, 1, iControlTags, iControlData ); +#endif + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); + if ( vis && textctrl ) { - if ( CanCopy() ) - Copy() ; + Rect bounds ; + UMAGetControlBoundsInWindowCoords( varsp->fUserPaneRec, &bounds); + TPCalculateBounds( varsp , bounds ) ; + wxMacWindowClipper cl(textctrl) ; + TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, + varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); + TXNShowSelection( varsp->fTXNRec, kTXNShowStart); + } + return err ; +} + +// make sure we don't miss changes as carbon events are not available for these under classic +static void TPUpdateVisibility(ControlRef theControl) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) return ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + + Rect bounds ; + UMAGetControlBoundsInWindowCoords(theControl, &bounds); + if ( textctrl->MacIsReallyShown() != varsp->fVisible ) + { + // invalidate old position + // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; + varsp->fVisible = textctrl->MacIsReallyShown() ; + } + if ( !EqualRect( &bounds , &varsp->fRBounds ) ) + { + // old position + Rect oldBounds = varsp->fRBounds ; + TPCalculateBounds( varsp , bounds ) ; + // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places + if ( varsp->fVisible ) + { + wxMacWindowClipper cl(textctrl) ; + TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, + varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); + } + InvalWindowRect( GetControlOwner( theControl ) , &oldBounds ) ; + InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; } +} - if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && - !( key == WXK_RETURN && ( (m_windowStyle & wxPROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) -/* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */ - ) +// make correct activations +static void TPActivatePaneText(STPTextPaneVars *varsp, Boolean setActive) { + + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); + if (varsp->fTXNObjectActive != setActive && textctrl->MacIsReallyShown() ) { - // eat it - return ; + varsp->fTXNObjectActive = setActive; + TXNActivate(varsp->fTXNRec, varsp->fTXNFrame, varsp->fTXNObjectActive); + if (varsp->fInFocus) + TXNFocus( varsp->fTXNRec, varsp->fTXNObjectActive); } +} - // assume that any key not processed yet is going to modify the control - m_dirty = true; +// update focus outlines +static void TPRedrawFocusOutline(STPTextPaneVars *varsp) { + + /* state changed */ + if (varsp->fFocusDrawState != (varsp->fIsActive && varsp->fInFocus)) + { + varsp->fFocusDrawState = (varsp->fIsActive && varsp->fInFocus); + DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState); + } +} - if ( key == 'v' && event.MetaDown() ) - { - if ( CanPaste() ) - Paste() ; - return ; +// update TXN focus state +static void TPFocusPaneText(STPTextPaneVars *varsp, Boolean setFocus) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); + + if (varsp->fInFocus != setFocus && textctrl->MacIsReallyShown()) { + varsp->fInFocus = setFocus; + TXNFocus( varsp->fTXNRec, varsp->fInFocus); } - if ( key == 'x' && event.MetaDown() ) - { - if ( CanCut() ) - Cut() ; +} + +// draw the control +static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart) { + /* set up our globals */ + + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) return ; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + if ( textctrl->MacIsReallyShown() ) + { + wxMacWindowClipper clipper( textctrl ) ; + TXNDraw(varsp->fTXNRec, NULL); + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; } - switch ( key ) + +} + + +/* TPPaneHitTestProc is called when the control manager would +like to determine what part of the control the mouse resides over. +We also call this routine from our tracking proc to determine how +to handle mouse clicks. */ +static pascal ControlPartCode TPPaneHitTestProc(ControlRef theControl, Point where) { + ControlPartCode result; + /* set up our locals and lock down our globals*/ + result = 0; + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0 ; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + if (textctrl->MacIsReallyShown() ) { - case WXK_RETURN: - if (m_windowStyle & wxPROCESS_ENTER) - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); - event.SetEventObject( this ); - event.SetString( GetValue() ); - if ( GetEventHandler()->ProcessEvent(event) ) - return; - } - if ( !(m_windowStyle & wxTE_MULTILINE) ) - { - wxWindow *parent = GetParent(); - while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { - parent = parent->GetParent() ; + if (PtInRect(where, &varsp->fRBounds)) + result = kmUPTextPart; + else + result = 0; + } + return result; +} + + + + + +/* TPPaneTrackingProc is called when the mouse is being held down +over our control. This routine handles clicks in the text area +and in the scroll bar. */ +static pascal ControlPartCode TPPaneTrackingProc(ControlRef theControl, Point startPt, ControlActionUPP actionProc) { + + ControlPartCode partCodeResult; + /* make sure we have some variables... */ + partCodeResult = 0; + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + if (textctrl->MacIsReallyShown() ) + { + /* we don't do any of these functions unless we're in focus */ + if ( ! varsp->fInFocus) { + WindowPtr owner; + owner = GetControlOwner(theControl); + ClearKeyboardFocus(owner); + SetKeyboardFocus(owner, theControl, kUserClickedToFocusPart); + } + /* find the location for the click */ + // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them + if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) + { + int x = 0 , y = 0 ; + textctrl->MacClientToRootWindow( &x , &y ) ; + startPt.h += x ; + startPt.v += y ; + } + + switch (TPPaneHitTestProc(theControl, startPt)) + { + + /* handle clicks in the text part */ + case kmUPTextPart: + { + wxMacWindowClipper clipper( textctrl ) ; + + EventRecord rec ; + ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; + TXNClick( varsp->fTXNRec, &rec ); + + } + break; + + } + } + return partCodeResult; +} + + +/* TPPaneIdleProc is our user pane idle routine. When our text field +is active and in focus, we use this routine to set the cursor. */ +static pascal void TPPaneIdleProc(ControlRef theControl) { + /* set up locals */ + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return ; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + if (textctrl->MacIsReallyShown()) { + /* if we're not active, then we have nothing to say about the cursor */ + if (varsp->fIsActive) { + Rect bounds; + Point mousep; + + wxMacWindowClipper clipper( textctrl ) ; + GetMouse(&mousep); + /* there's a 'focus thing' and an 'unfocused thing' */ + if (varsp->fInFocus) { + /* flash the cursor */ + SetPort(varsp->fDrawingEnvironment); + TXNIdle(varsp->fTXNRec); + /* set the cursor */ + if (PtInRect(mousep, &varsp->fRTextArea)) { + RgnHandle theRgn; + RectRgn((theRgn = NewRgn()), &varsp->fRTextArea); + TXNAdjustCursor(varsp->fTXNRec, theRgn); + DisposeRgn(theRgn); } - if ( parent && parent->GetDefaultItem() ) + else { - wxButton *def = wxDynamicCast(parent->GetDefaultItem(), - wxButton); - if ( def && def->IsEnabled() ) - { - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); - event.SetEventObject(def); - def->Command(event); - return ; - } + // SetThemeCursor(kThemeArrowCursor); + } + } else { + /* if it's in our bounds, set the cursor */ + UMAGetControlBoundsInWindowCoords(theControl, &bounds); + if (PtInRect(mousep, &bounds)) + { + // SetThemeCursor(kThemeArrowCursor); } - - // this will make wxWidgets eat the ENTER key so that - // we actually prevent line wrapping in a single line - // text control - eat_key = TRUE; } + } + } +} - break; - case WXK_TAB: - if ( !(m_windowStyle & wxTE_PROCESS_TAB)) - { - int flags = 0; - if (!event.ShiftDown()) - flags |= wxNavigationKeyEvent::IsForward ; - if (event.ControlDown()) - flags |= wxNavigationKeyEvent::WinChange ; - Navigate(flags); - return; - } - else - { - // This is necessary (don't know why) or the tab will not - // be inserted. - WriteText(wxT("\t")); - } - - break; +/* TPPaneKeyDownProc is called whenever a keydown event is directed +at our control. Here, we direct the keydown event to the text +edit record and redraw the scroll bar and text field as appropriate. */ +static pascal ControlPartCode TPPaneKeyDownProc(ControlRef theControl, + SInt16 keyCode, SInt16 charCode, SInt16 modifiers) { + + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + if (varsp->fInFocus) + { + /* turn autoscrolling on and send the key event to text edit */ + wxMacWindowClipper clipper( textctrl ) ; + EventRecord ev ; + memset( &ev , 0 , sizeof( ev ) ) ; + ev.what = keyDown ; + ev.modifiers = modifiers ; + ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; + TXNKeyDown( varsp->fTXNRec, &ev); } + return kControlEntireControl; +} - if (!eat_key) - { - // perform keystroke handling - if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) - CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; - else - { - EventRecord rec ; - if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ) - { - EventRecord *ev = &rec ; - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - ::HandleControlKey( *m_peer , keycode , keychar , ev->modifiers ) ; - } - } - } - if ( ( key >= 0x20 && key < WXK_START ) || - key == WXK_RETURN || - key == WXK_DELETE || - key == WXK_BACK) +/* TPPaneActivateProc is called when the window containing +the user pane control receives activate events. Here, we redraw +the control and it's text as necessary for the activation state. */ +static pascal void TPPaneActivateProc(ControlRef theControl, Boolean activating) { + /* set up locals */ + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + + if ( textctrl == NULL ) + return ; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + + varsp->fIsActive = activating; + wxMacWindowClipper clipper( textctrl ) ; + TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); + /* redraw the frame */ + if ( textctrl->MacIsReallyShown() ) { - wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - event1.SetString( GetValue() ) ; - event1.SetEventObject( this ); - wxPostEvent(GetEventHandler(),event1); + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; } } -// ---------------------------------------------------------------------------- -// standard handlers for standard edit menu events -// ---------------------------------------------------------------------------- -void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) -{ - Cut(); +/* TPPaneFocusProc is called when every the focus changes to or +from our control. Herein, switch the focus appropriately +according to the parameters and redraw the control as +necessary. */ +static pascal ControlPartCode TPPaneFocusProc(ControlRef theControl, ControlFocusPart action) { + ControlPartCode focusResult; + + focusResult = kControlFocusNoPart; + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) ((wxMacMLTEClassicControl*)textctrl->GetPeer())->m_macTXNvars ; + /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is + tabbing forwards (or shift tabbing backwards) through the items in the dialog, + and kControlFocusNextPart will be received. When the user clicks in our field + and it is not the current focus, then the constant kUserClickedToFocusPart will + be received. The constant kControlFocusNoPart will be received when our control + is the current focus and the user clicks in another control. In your focus routine, + you should respond to these codes as follows: + + kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw + the control and the focus rectangle as necessary. + + kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off + depending on its current state. redraw the control and the focus rectangle + as appropriate for the new focus state. If the focus state is 'off', return the constant + kControlFocusNoPart, otherwise return a non-zero part code. + kUserClickedToFocusPart - is a constant defined for this example. You should + define your own value for handling click-to-focus type events. */ + /* calculate the next highlight state */ + switch (action) { + default: + case kControlFocusNoPart: + TPFocusPaneText(varsp, false); + focusResult = kControlFocusNoPart; + break; + case kUserClickedToFocusPart: + TPFocusPaneText(varsp, true); + focusResult = 1; + break; + case kControlFocusPrevPart: + case kControlFocusNextPart: + TPFocusPaneText(varsp, ( ! varsp->fInFocus)); + focusResult = varsp->fInFocus ? 1 : kControlFocusNoPart; + break; + } + TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); + /* redraw the text fram and focus rectangle to indicate the + new focus state */ + if ( textctrl->MacIsReallyShown() ) + { + wxMacWindowClipper c( textctrl ) ; + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; + } + return focusResult; } -void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) +wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) { - Copy(); -} + m_font = wxPeer->GetFont() ; + m_windowStyle = style ; + Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; -void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) -{ - Paste(); -} + wxMacConvertNewlines13To10( &st ) ; -void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) -{ - Undo(); -} + short featurSet; -void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) -{ - Redo(); -} + featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle + | kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground + | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; + /* create the control */ -void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) -{ - event.Enable( CanCut() ); -} + verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) ); + + { +// wxMacWindowClipper c(wxPeer) ; + DoCreate(); + } + + if ( wxPeer->MacIsReallyShown() ) + MLTESetObjectVisibility( (STPTextPaneVars*) m_macTXNvars, true , style ) ; -void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) -{ - event.Enable( CanCopy() ); -} + { + // wxMacWindowClipper clipper( wxPeer ) ; -void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) -{ - event.Enable( CanPaste() ); + TPUpdateVisibility( m_controlRef ) ; + + SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; + + TXNSetSelection( m_txn, 0, 0); + TXNShowSelection( m_txn, kTXNShowStart); + } + + AdjustCreationAttributes( *wxWHITE , true ) ; } -void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) +wxMacMLTEClassicControl::~wxMacMLTEClassicControl() { - event.Enable( CanUndo() ); +// SetControlReference(m_controlRef , 0) ; + TXNDeleteObject(m_txn); + free(m_macTXNvars); } -void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) +void wxMacMLTEClassicControl::VisibilityChanged(bool shown) { - event.Enable( CanRedo() ); + MLTESetObjectVisibility((STPTextPaneVars*) m_macTXNvars , shown , m_windowStyle ) ; + if ( !shown ) + InvalWindowRect( GetControlOwner( m_controlRef ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ; } -bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) +OSStatus wxMacMLTEClassicControl::DoCreate() { - return true ; + Rect bounds; + WindowRef theWindow; + + OSStatus err = noErr ; + + /* set up our globals */ + if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc); + if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(TPPaneHitTestProc); + if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(TPPaneTrackingProc); + if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(TPPaneIdleProc); + if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc); + if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(TPPaneActivateProc); + if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc); + + /* allocate our private storage */ + m_macTXNvars = (STPTextPaneVars *) malloc(sizeof(STPTextPaneVars)); + + /* set the initial settings for our private data */ + m_macTXNvars->fMultiline = m_windowStyle & wxTE_MULTILINE ; + m_macTXNvars->fNoBorders = m_windowStyle & wxNO_BORDER ; + m_macTXNvars->fInFocus = false; + m_macTXNvars->fIsActive = true; + m_macTXNvars->fTXNObjectActive = false; + m_macTXNvars->fFocusDrawState = false ; + m_macTXNvars->fUserPaneRec = m_controlRef ; + m_macTXNvars->fVisible = true ; + + theWindow = m_macTXNvars->fOwner = GetControlOwner(m_controlRef); + + m_macTXNvars->fDrawingEnvironment = (GrafPtr) GetWindowPort(theWindow); + + /* set up the user pane procedures */ + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); + SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); + + /* calculate the rectangles used by the control */ + UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); + m_macTXNvars->fRTextOutlineRegion = NewRgn() ; + TPCalculateBounds( m_macTXNvars , bounds ) ; + + /* set up the drawing environment */ + SetPort(m_macTXNvars->fDrawingEnvironment); + + /* create the new edit field */ + + TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ) ; + + verify_noerr(TXNNewObject(NULL, m_macTXNvars->fOwner, &m_macTXNvars->fRTextArea, + frameOptions , + kTXNTextEditStyleFrameType, + kTXNTextensionFile, + kTXNSystemDefaultEncoding, + &m_macTXNvars->fTXNRec, &m_macTXNvars->fTXNFrame, (TXNObjectRefcon) m_macTXNvars)); + m_txn = m_macTXNvars->fTXNRec ; + + /* perform final activations and setup for our text field. Here, + we assume that the window is going to be the 'active' window. */ + TPActivatePaneText(m_macTXNvars, m_macTXNvars->fIsActive && m_macTXNvars->fInFocus); + /* all done */ + return err; } -// user pane implementation -void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) -{ -} +#endif -wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) -{ - return kControlNoPart ; -} +// ---------------------------------------------------------------------------- +// MLTE control implementation (OSX part) +// ---------------------------------------------------------------------------- -wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) -{ - return kControlNoPart ; -} +#if TARGET_API_MAC_OSX -void wxTextCtrl::MacControlUserPaneIdleProc() +wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) { -} + m_font = wxPeer->GetFont() ; + m_windowStyle = style ; + Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; + wxString st = str ; + wxMacConvertNewlines13To10( &st ) ; + + HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ; -wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) -{ - return kControlNoPart ; + m_scrollView = NULL ; + TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; + if ( frameOptions & (kTXNWantVScrollBarMask|kTXNWantHScrollBarMask) ) + { + HIScrollViewCreate(( frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | + ( frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll: 0 ) , &m_scrollView ) ; + + HIViewSetFrame( m_scrollView, &hr ); + HIViewSetVisible( m_scrollView, true ); + } + + m_textView = NULL ; + HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ; + m_txn = HITextViewGetTXNObject( m_textView) ; + HIViewSetVisible( m_textView , true ) ; + if ( m_scrollView ) + { + HIViewAddSubview( m_scrollView , m_textView ) ; + m_controlRef = m_scrollView ; + wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; + } + else + { + HIViewSetFrame( m_textView, &hr ); + m_controlRef = m_textView ; + } + + + SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; + + TXNSetSelection( m_txn, 0, 0); + TXNShowSelection( m_txn, kTXNShowStart); + + AdjustCreationAttributes( *wxWHITE , true ) ; } -void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) +OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) { + return SetKeyboardFocus( GetControlOwner( m_textView ) , + m_textView , focusPart ) ; } -wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) +bool wxMacMLTEHIViewControl::HasFocus() const { - return kControlNoPart ; + ControlRef control ; + GetKeyboardFocus( GetUserFocusWindow() , &control ) ; + return control == m_textView ; } -void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) +bool wxMacMLTEHIViewControl::NeedsFocusRect() const { + return true ; } #endif - // wxUSE_TEXTCTRL + +#endif // wxUSE_TEXTCTRL diff --git a/src/mac/carbon/tglbtn.cpp b/src/mac/carbon/tglbtn.cpp index 909eeb4d79..db98289a1d 100644 --- a/src/mac/carbon/tglbtn.cpp +++ b/src/mac/carbon/tglbtn.cpp @@ -67,7 +67,7 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, m_peer = new wxMacControl() ; verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , *m_peer ) ); + kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); MacPostControlCreate(pos,size) ; @@ -89,12 +89,12 @@ wxSize wxToggleButton::DoGetBestSize() const void wxToggleButton::SetValue(bool val) { - ::SetControl32BitValue( *m_peer , val ) ; + m_peer->SetValue( val ) ; } bool wxToggleButton::GetValue() const { - return GetControl32BitValue( *m_peer ) ; + return m_peer->GetValue() ; } void wxToggleButton::Command(wxCommandEvent & event) diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index eae3cfaa63..896ede9fdb 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -1002,17 +1002,17 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of // the content view, so we have to retrieve it explicitely HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , - *m_peer ) ; + m_peer->GetControlRefAddr() ) ; if ( !m_peer->Ok() ) { // compatibility mode fallback - GetRootControl( (WindowRef) m_macWindow , *m_peer ) ; + GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; } #else - ::CreateRootControl( (WindowRef)m_macWindow , *m_peer ) ; + ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; #endif // the root control level handleer - MacInstallEventHandler() ; + MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; // the frame window event handler InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 13a54704ed..be4535ea94 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -1435,6 +1435,17 @@ OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType in // Control Access Support // ---------------------------------------------------------------------------- +void wxMacControl::Dispose() +{ + ::DisposeControl( m_controlRef ) ; + m_controlRef = NULL ; +} + +void wxMacControl::SetReference( SInt32 data ) +{ + SetControlReference( m_controlRef , data ) ; +} + OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const { return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ; @@ -1521,6 +1532,24 @@ void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maxi ::SetControl32BitValue( m_controlRef , value ) ; } +OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) +{ + return SetKeyboardFocus( GetControlOwner( m_controlRef ) , + m_controlRef , focusPart ) ; +} + +bool wxMacControl::HasFocus() const +{ + ControlRef control ; + GetKeyboardFocus( GetUserFocusWindow() , &control ) ; + return control == m_controlRef ; +} + +bool wxMacControl::NeedsFocusRect() const +{ + return false ; +} + void wxMacControl::VisibilityChanged(bool shown) { } @@ -1574,5 +1603,286 @@ void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) ::SetControl32BitMaximum( m_controlRef , maximum ) ; } +short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) +{ + return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ; +} + +void wxMacControl::SetActionProc( ControlActionUPP actionProc ) +{ + SetControlAction( m_controlRef , actionProc ) ; +} + +void wxMacControl::SetViewSize( SInt32 viewSize ) +{ + SetControlViewSize(m_controlRef , viewSize ) ; +} + +SInt32 wxMacControl::GetViewSize() const +{ + return GetControlViewSize( m_controlRef ) ; +} + +bool wxMacControl::IsVisible() const +{ + return IsControlVisible( m_controlRef ) ; +} + +void wxMacControl::SetVisibility( bool visible , bool redraw ) +{ + SetControlVisibility( m_controlRef , visible , redraw ) ; +} + +bool wxMacControl::IsEnabled() const +{ +#if TARGET_API_MAC_OSX + return IsControlEnabled( m_controlRef ) ; +#else + return IsControlActive( m_controlRef ) ; +#endif +} + +bool wxMacControl::IsActive() const +{ + return IsControlActive( m_controlRef ) ; +} + +void wxMacControl::Enable( bool enable ) +{ +#if TARGET_API_MAC_OSX + if ( enable ) + EnableControl( m_controlRef ) ; + else + DisableControl( m_controlRef ) ; +#else + if ( enable ) + ActivateControl( m_controlRef ) ; + else + DeactivateControl( m_controlRef ) ; +#endif +} + +void wxMacControl::SetDrawingEnabled( bool enable ) +{ +#if TARGET_API_MAC_OSX + HIViewSetDrawingEnabled( m_controlRef , enable ) ; +#endif +} + +bool wxMacControl::GetNeedsDisplay() const +{ +#if TARGET_API_MAC_OSX + return HIViewGetNeedsDisplay( m_controlRef ) ; +#else + return false ; +#endif +} + +void wxMacControl::SetNeedsDisplay( bool needsDisplay , RgnHandle where ) +{ +#if TARGET_API_MAC_OSX + if ( where != NULL ) + HIViewSetNeedsDisplayInRegion( m_controlRef , where , needsDisplay ) ; + else + HIViewSetNeedsDisplay( m_controlRef , needsDisplay ) ; +#endif +} + +void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) +{ +#if TARGET_API_MAC_OSX + HIPoint hiPoint ; + hiPoint.x = pt->x ; + hiPoint.y = pt->y ; + HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ; + pt->x = hiPoint.x ; + pt->y = hiPoint.y ; +#endif +} + +void wxMacControl::SetRect( Rect *r ) +{ +#if TARGET_API_MAC_OSX + HIRect hir = { r->left , r->top , r->right - r->left , r->bottom - r->top } ; + HIViewSetFrame ( m_controlRef , &hir ) ; +#else + SetControlBounds( m_controlRef , r ) ; +#endif + +} + +void wxMacControl::GetRect( Rect *r ) +{ + GetControlBounds( m_controlRef , r ) ; +} + +void wxMacControl::GetRectInWindowCoords( Rect *r ) +{ + UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ; +} + +void wxMacControl::GetBestRect( Rect *r ) +{ + Rect bestsize = { 0 , 0 , 0 , 0 } ; + short baselineoffset ; + GetBestControlRect( m_controlRef , r , &baselineoffset ) ; +} + +void wxMacControl::SetTitle( const wxString &title ) +{ + UMASetControlTitle( m_controlRef , title , m_font.GetEncoding() ) ; +} + +void wxMacControl::GetFeatures( UInt32 * features ) +{ + GetControlFeatures( m_controlRef , features ) ; +} + +OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) +{ + return GetControlRegion( m_controlRef , partCode , region ) ; +} + +OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) +{ +#if TARGET_API_MAC_OSX + return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, + (other != NULL) ? other->m_controlRef : NULL) ; +#else + return 0 ; +#endif +} + + +#if TARGET_API_MAC_OSX +// SetNeedsDisplay would not invalidate the children +static void InvalidateControlAndChildren( HIViewRef control ) +{ + HIViewSetNeedsDisplay( control , true ) ; + UInt16 childrenCount = 0 ; + OSStatus err = CountSubControls( control , &childrenCount ) ; + if ( err == errControlIsNotEmbedder ) + return ; + wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; + + for ( UInt16 i = childrenCount ; i >=1 ; --i ) + { + HIViewRef child ; + err = GetIndexedSubControl( control , i , & child ) ; + if ( err == errControlIsNotEmbedder ) + return ; + InvalidateControlAndChildren( child ) ; + } +} +#endif + +void wxMacControl::InvalidateWithChildren() +{ +#if TARGET_API_MAC_OSX + InvalidateControlAndChildren( m_controlRef ) ; +#endif +} + +void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy ) +{ +#if TARGET_API_MAC_OSX + HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ; + HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ; +#endif +} + + +// SetNeedsDisplay would not invalidate the children + +// +// Databrowser +// + +OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options ) +{ + return SetDataBrowserSelectionFlags( m_controlRef , options ) ; +} + +OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc, + DataBrowserTableViewColumnIndex position ) +{ + return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ; +} + +OSStatus wxMacControl::AutoSizeListViewColumns() +{ + return AutoSizeDataBrowserListViewColumns(m_controlRef) ; +} + +OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert ) +{ + return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ; +} + +OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) +{ + return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ; +} + +OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height) +{ + return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ; +} + +OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks) +{ + return SetDataBrowserCallbacks( m_controlRef , callbacks ) ; +} + +OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty, + DataBrowserPropertyID propertyID ) +{ + return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ; +} + +bool wxMacControl::IsItemSelected( DataBrowserItemID item ) +{ + return IsDataBrowserItemSelected( m_controlRef , item ) ; +} + +OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty ) +{ + return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; +} + +OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems, + const DataBrowserItemID* items, + DataBrowserPropertyID preSortProperty ) +{ + return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; +} + +OSStatus wxMacControl::RevealItem( DataBrowserItemID item, + DataBrowserPropertyID propertyID, + DataBrowserRevealOptions options ) +{ + return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ; +} + +OSStatus wxMacControl::SetSelectedItems(UInt32 numItems, + const DataBrowserItemID * items, + DataBrowserSetOption operation ) +{ + return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ; +} + +// +// Tab Control +// + +OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) +{ + return ::SetTabEnabled( m_controlRef , tabNo , enable ) ; +} + #endif // wxUSE_GUI diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 8bdcc9b906..ea46601840 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -84,7 +84,8 @@ BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) // TODO EVT_PAINT(wxWindowMac::OnPaint) EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) -// EVT_SET_FOCUS(wxWindowMac::OnSetFocus) + EVT_SET_FOCUS(wxWindowMac::OnSetFocus) + EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) END_EVENT_TABLE() @@ -95,7 +96,7 @@ END_EVENT_TABLE() #define wxMAC_DEBUG_REDRAW 0 #endif -#define wxMAC_USE_THEME_BORDER 0 +#define wxMAC_USE_THEME_BORDER 1 // --------------------------------------------------------------------------- // Carbon Events @@ -209,7 +210,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl thisWindow->GetCaret()->OnKillFocus(); } #endif // wxUSE_CARET - wxFocusEvent event(wxEVT_KILL_FOCUS, thisWindow->GetId()); + wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); thisWindow->GetEventHandler()->ProcessEvent(event) ; } @@ -655,8 +656,9 @@ wxWindowMac::~wxWindowMac() { // in case the callback might be called during destruction wxRemoveMacControlAssociation( this) ; - ::SetControlColorProc( *m_peer , NULL ) ; - ::DisposeControl( *m_peer ) ; + // we currently are not using this hook + // ::SetControlColorProc( *m_peer , NULL ) ; + m_peer->Dispose() ; } if ( g_MacLastWindow == this ) @@ -686,14 +688,14 @@ wxWindowMac::~wxWindowMac() WXWidget wxWindowMac::GetHandle() const { - return (WXWidget) (ControlRef) *m_peer ; + return (WXWidget) m_peer->GetControlRef() ; } -void wxWindowMac::MacInstallEventHandler() +void wxWindowMac::MacInstallEventHandler( WXWidget control ) { - wxAssociateControlWithMacControl( *m_peer , this ) ; - InstallControlEventHandler( *m_peer, GetwxMacWindowEventHandlerUPP(), + wxAssociateControlWithMacControl( (ControlRef) control , this ) ; + InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macControlEventHandler); @@ -731,27 +733,19 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, ; m_peer = new wxMacControl() ; - ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , *m_peer); + ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); MacPostControlCreate(pos,size) ; #if !TARGET_API_MAC_OSX - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneDrawProcTag, - sizeof(gControlUserPaneDrawUPP),(Ptr) &gControlUserPaneDrawUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneHitTestProcTag, - sizeof(gControlUserPaneHitTestUPP),(Ptr) &gControlUserPaneHitTestUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneTrackingProcTag, - sizeof(gControlUserPaneTrackingUPP),(Ptr) &gControlUserPaneTrackingUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneIdleProcTag, - sizeof(gControlUserPaneIdleUPP),(Ptr) &gControlUserPaneIdleUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneKeyDownProcTag, - sizeof(gControlUserPaneKeyDownUPP),(Ptr) &gControlUserPaneKeyDownUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneActivateProcTag, - sizeof(gControlUserPaneActivateUPP),(Ptr) &gControlUserPaneActivateUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneFocusProcTag, - sizeof(gControlUserPaneFocusUPP),(Ptr) &gControlUserPaneFocusUPP); - SetControlData(*m_peer,kControlEntireControl,kControlUserPaneBackgroundProcTag, - sizeof(gControlUserPaneBackgroundUPP),(Ptr) &gControlUserPaneBackgroundUPP); + m_peer->SetData(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ; + m_peer->SetData(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ; #endif } #ifndef __WXUNIVERSAL__ @@ -773,13 +767,13 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) { wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; - ::SetControlReference( *m_peer , (long) this ) ; + m_peer->SetReference( (long) this ) ; - MacInstallEventHandler(); + MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); ControlRef container = (ControlRef) GetParent()->GetHandle() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; - ::EmbedControl( *m_peer , container ) ; + ::EmbedControl( m_peer->GetControlRef() , container ) ; // adjust font, controlsize etc DoSetWindowVariant( m_windowVariant ) ; @@ -789,8 +783,7 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) //if ( m_macIsUserPane ) // SetControlColorProc( *m_peer , wxMacSetupControlBackgroundUPP ) ; #endif - - UMASetControlTitle( *m_peer , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ; + m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; if (!m_macIsUserPane) { @@ -849,7 +842,7 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) wxFAIL_MSG(_T("unexpected window variant")); break ; } - ::SetControlData( *m_peer , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); + m_peer->SetData(kControlEntireControl, kControlSizeTag,&size ) ; wxFont font ; font.MacCreateThemeFont( themeFont ) ; @@ -915,7 +908,7 @@ bool wxWindowMac::MacCanFocus() const // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems // in event handlers... UInt32 features = 0 ; - GetControlFeatures( *m_peer , &features ) ; + m_peer->GetFeatures( & features ) ; return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; } @@ -927,7 +920,7 @@ void wxWindowMac::SetFocus() #if !TARGET_API_MAC_OSX wxWindow* former = FindFocus() ; #endif - OSStatus err = SetKeyboardFocus( (WindowRef) MacGetTopLevelWindowRef() , (ControlRef) GetHandle() , kControlFocusNextPart ) ; + OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only // leave in case of an error if ( err == errCouldntSetFocus ) @@ -1008,7 +1001,7 @@ void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, int& w, int& h) const { Rect bounds ; - GetControlBounds( *m_peer , &bounds ) ; + m_peer->GetRect( &bounds ) ; x = bounds.left ; @@ -1031,6 +1024,8 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, int& x, int& y, int& w, int& h , bool adjustOrigin ) const { + // the desired size, minus the border pixels gives the correct size of the control + x = (int)pos.x; y = (int)pos.y; // todo the default calls may be used as soon as PostCreateControl Is moved here @@ -1039,6 +1034,12 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, #if !TARGET_API_MAC_OSX GetParent()->MacWindowToRootWindow( &x , &y ) ; #endif + + x += MacGetLeftBorderSize() ; + y += MacGetTopBorderSize() ; + w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; + h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; + if ( adjustOrigin ) AdjustForParentClientOrigin( x , y ) ; return true ; @@ -1047,18 +1048,22 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, // Get total size void wxWindowMac::DoGetSize(int *x, int *y) const { -#if TARGET_API_MAC_OSX + // take the size of the control and add the borders that have to be drawn outside int x1 , y1 , w1 ,h1 ; +#if TARGET_API_MAC_OSX MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; - if(x) *x = w1 ; - if(y) *y = h1 ; #else Rect bounds ; - GetControlBounds( *m_peer , &bounds ) ; - if(x) *x = bounds.right - bounds.left ; - if(y) *y = bounds.bottom - bounds.top ; + m_peer->GetRect( &bounds ) ; + w1 = bounds.right - bounds.left ; + h1 = bounds.bottom - bounds.top ; #endif + w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ; + h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ; + + if(x) *x = w1 ; + if(y) *y = h1 ; } void wxWindowMac::DoGetPosition(int *x, int *y) const @@ -1066,6 +1071,8 @@ void wxWindowMac::DoGetPosition(int *x, int *y) const #if TARGET_API_MAC_OSX int x1 , y1 , w1 ,h1 ; MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; + x1 -= MacGetLeftBorderSize() ; + y1 -= MacGetTopBorderSize() ; if ( !IsTopLevel() ) { wxWindow *parent = GetParent(); @@ -1080,11 +1087,13 @@ void wxWindowMac::DoGetPosition(int *x, int *y) const if(y) *y = y1 ; #else Rect bounds ; - GetControlBounds( *m_peer , &bounds ) ; + m_peer->GetRect( &bounds ) ; wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ; int xx = bounds.left ; int yy = bounds.top ; + xx -= MacGetLeftBorderSize() ; + yy -= MacGetTopBorderSize() ; if ( !GetParent()->IsTopLevel() ) { @@ -1169,7 +1178,7 @@ void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const { #if TARGET_API_MAC_OSX - HIPoint pt ; + wxPoint pt ; if ( x ) pt.x = *x ; if ( y ) pt.y = *y ; @@ -1177,7 +1186,11 @@ void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const { wxTopLevelWindowMac* top = MacGetTopLevelWindow(); if (top) - HIViewConvertPoint( &pt , *m_peer , (ControlRef) top->GetHandle() ) ; + { + pt.x -= MacGetLeftBorderSize() ; + pt.y -= MacGetTopBorderSize() ; + wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; + } } if ( x ) *x = (int) pt.x ; @@ -1186,7 +1199,7 @@ void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const if ( !IsTopLevel() ) { Rect bounds ; - GetControlBounds( *m_peer , &bounds ) ; + m_peer->GetRect( &bounds ) ; if(x) *x += bounds.left ; if(y) *y += bounds.top ; } @@ -1206,12 +1219,16 @@ void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const { #if TARGET_API_MAC_OSX - HIPoint pt ; + wxPoint pt ; if ( x ) pt.x = *x ; if ( y ) pt.y = *y ; if ( !IsTopLevel() ) - HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , *m_peer ) ; + { + wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ; + pt.x += MacGetLeftBorderSize() ; + pt.y += MacGetTopBorderSize() ; + } if ( x ) *x = (int) pt.x ; if ( y ) *y = (int) pt.y ; @@ -1219,7 +1236,7 @@ void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const if ( !IsTopLevel() ) { Rect bounds ; - GetControlBounds( *m_peer , &bounds ) ; + m_peer->GetRect( &bounds ) ; if(x) *x -= bounds.left ; if(y) *y -= bounds.top ; } @@ -1240,17 +1257,17 @@ void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , in { RgnHandle rgn = NewRgn() ; Rect content ; - if ( GetControlRegion( *m_peer , kControlContentMetaPart , rgn ) == noErr ) + if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) { GetRegionBounds( rgn , &content ) ; DisposeRgn( rgn ) ; } else { - GetControlBounds( *m_peer , &content ) ; + m_peer->GetRect( &content ) ; } Rect structure ; - GetControlBounds( *m_peer , &structure ) ; + m_peer->GetRect( &structure ) ; #if !TARGET_API_MAC_OSX OffsetRect( &content , -structure.left , -structure.top ) ; #endif @@ -1268,17 +1285,17 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const Rect content ; - if ( GetControlRegion( *m_peer , kControlContentMetaPart , rgn ) == noErr ) + if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) { GetRegionBounds( rgn , &content ) ; DisposeRgn( rgn ) ; } else { - GetControlBounds( *m_peer , &content ) ; + m_peer->GetRect( &content ) ; } Rect structure ; - GetControlBounds( *m_peer , &structure ) ; + m_peer->GetRect( &structure ) ; #if !TARGET_API_MAC_OSX OffsetRect( &content , -structure.left , -structure.top ) ; #endif @@ -1300,18 +1317,18 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const RgnHandle rgn = NewRgn() ; Rect content ; - if ( GetControlRegion( *m_peer , kControlContentMetaPart , rgn ) == noErr ) + if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) { GetRegionBounds( rgn , &content ) ; DisposeRgn( rgn ) ; } else { - GetControlBounds( *m_peer , &content ) ; + m_peer->GetRect( &content ) ; } #if !TARGET_API_MAC_OSX Rect structure ; - GetControlBounds( *m_peer , &structure ) ; + m_peer->GetRect( &structure ) ; OffsetRect( &content , -structure.left , -structure.top ) ; #endif ww = content.right - content.left ; @@ -1479,6 +1496,10 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) DoGetSize( &former_w , &former_h ) ; #else MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ; + former_x -= MacGetLeftBorderSize() ; + former_y -= MacGetTopBorderSize() ; + former_w += MacGetLeftBorderSize() + MacGetRightBorderSize() ; + former_h += MacGetTopBorderSize() + MacGetBottomBorderSize() ; #endif int actualWidth = width; @@ -1511,22 +1532,15 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) { // we don't adjust twice for the origin Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; - bool vis = IsControlVisible( *m_peer ) ; -#if TARGET_API_MAC_OSX + bool vis = m_peer->IsVisible(); + // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! if ( vis ) - SetControlVisibility( *m_peer , false , true ) ; - HIRect hir = { r.left , r.top , r.right - r.left , r.bottom - r.top } ; - HIViewSetFrame ( *m_peer , &hir ) ; + m_peer->SetVisibility( false , true ) ; + m_peer->SetRect( &r ) ; if ( vis ) - SetControlVisibility( *m_peer , true , true ) ; -#else - if ( vis ) - SetControlVisibility( *m_peer , false , true ) ; - SetControlBounds( *m_peer , &r ) ; - if ( vis ) - SetControlVisibility( *m_peer , true , true ) ; -#endif + m_peer->SetVisibility( true , true ) ; + MacRepositionScrollBars() ; if ( doMove ) { @@ -1553,13 +1567,11 @@ wxSize wxWindowMac::DoGetBestSize() const return wxWindowBase::DoGetBestSize() ; Rect bestsize = { 0 , 0 , 0 , 0 } ; - short baselineoffset ; int bestWidth, bestHeight ; - ::GetBestControlRect( *m_peer , &bestsize , &baselineoffset ) ; + m_peer->GetBestRect( &bestsize ) ; if ( EmptyRect( &bestsize ) ) { - baselineoffset = 0; bestsize.left = bestsize.top = 0 ; bestsize.right = 16 ; bestsize.bottom = 16 ; @@ -1583,7 +1595,6 @@ wxSize wxWindowMac::DoGetBestSize() const bestHeight = 13 ; return wxSize(bestWidth, bestHeight); -// return wxWindowBase::DoGetBestSize() ; } @@ -1662,7 +1673,7 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const { RgnHandle rgn = NewRgn() ; Rect content ; - GetControlRegion( *m_peer , kControlContentMetaPart , rgn ) ; + m_peer->GetRegion( kControlContentMetaPart , rgn ) ; GetRegionBounds( rgn , &content ) ; DisposeRgn( rgn ) ; #if !TARGET_API_MAC_OSX @@ -1671,7 +1682,7 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const if (!::EmptyRect( &content ) ) { Rect structure ; - GetControlBounds( *m_peer , &structure ) ; + m_peer->GetRect( &structure ) ; OffsetRect( &content , -structure.left , -structure.top ) ; } #endif @@ -1700,7 +1711,7 @@ void wxWindowMac::SetTitle(const wxString& title) if ( m_peer && m_peer->Ok() ) { - UMASetControlTitle( *m_peer , m_label , m_font.GetEncoding() ) ; + m_peer->SetTitle( m_label ) ; } Refresh() ; } @@ -1718,7 +1729,7 @@ bool wxWindowMac::Show(bool show) // TODO use visibilityChanged Carbon Event for OSX bool former = MacIsReallyShown() ; - SetControlVisibility( *m_peer , show , true ) ; + m_peer->SetVisibility( show , true ) ; if ( former != MacIsReallyShown() ) MacPropagateVisibilityChanged() ; return TRUE; @@ -1731,17 +1742,7 @@ bool wxWindowMac::Enable(bool enable) return FALSE; bool former = MacIsReallyEnabled() ; -#if TARGET_API_MAC_OSX - if ( enable ) - EnableControl( *m_peer ) ; - else - DisableControl( *m_peer ) ; -#else - if ( enable ) - ActivateControl( *m_peer ) ; - else - DeactivateControl( *m_peer ) ; -#endif + m_peer->Enable( enable ) ; if ( former != MacIsReallyEnabled() ) MacPropagateEnabledStateChanged() ; @@ -1824,7 +1825,7 @@ bool wxWindowMac::MacIsReallyShown() { // only under OSX the visibility of the TLW is taken into account #if TARGET_API_MAC_OSX - return IsControlVisible( *m_peer ) ; + return m_peer->IsVisible(); #else wxWindow* win = this ; while( win->IsShown() ) @@ -1843,16 +1844,12 @@ bool wxWindowMac::MacIsReallyShown() bool wxWindowMac::MacIsReallyEnabled() { -#if TARGET_API_MAC_OSX - return IsControlEnabled( *m_peer ) ; -#else - return IsControlActive( *m_peer ) ; -#endif + return m_peer->IsEnabled() ; } bool wxWindowMac::MacIsReallyHilited() { - return IsControlActive( *m_peer ) ; + return m_peer->IsActive(); } void wxWindowMac::MacFlashInvalidAreas() @@ -1907,15 +1904,15 @@ void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) { #if TARGET_API_MAC_OSX if ( rect == NULL ) - HIViewSetNeedsDisplay( *m_peer , true ) ; + m_peer->SetNeedsDisplay( true ) ; else { RgnHandle update = NewRgn() ; SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; wxPoint origin = GetClientAreaOrigin() ; - OffsetRgn( update, origin.x , origin.y ) ; - HIViewSetNeedsDisplayInRegion( *m_peer , update , true ) ; + OffsetRgn( update, origin.x , origin.y ) ; + m_peer->SetNeedsDisplay( true , update) ; } #else /* @@ -1932,16 +1929,16 @@ void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; DisposeRgn(updateRgn) ; */ - if ( IsControlVisible( *m_peer ) ) + if ( m_peer->IsVisible()) { - SetControlVisibility( *m_peer , false , false ) ; - SetControlVisibility( *m_peer , true , true ) ; + m_peer->SetVisibility( false , false ) ; + m_peer->SetVisibility( true , true ) ; } /* if ( MacGetTopLevelWindow() == NULL ) return ; - if ( !IsControlVisible( *m_peer ) ) + if ( !m_peer->IsVisible()) return ; wxPoint client = GetClientAreaOrigin(); @@ -1985,31 +1982,11 @@ void wxWindowMac::Freeze() #if TARGET_API_MAC_OSX if ( !m_frozenness++ ) { - HIViewSetDrawingEnabled( *m_peer , false ) ; + m_peer->SetDrawingEnabled( false ) ; } #endif } -#if TARGET_API_MAC_OSX -static void InvalidateControlAndChildren( HIViewRef control ) -{ - HIViewSetNeedsDisplay( control , true ) ; - UInt16 childrenCount = 0 ; - OSStatus err = CountSubControls( control , &childrenCount ) ; - if ( err == errControlIsNotEmbedder ) - return ; - wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; - - for ( UInt16 i = childrenCount ; i >=1 ; --i ) - { - HIViewRef child ; - err = GetIndexedSubControl( control , i , & child ) ; - if ( err == errControlIsNotEmbedder ) - return ; - InvalidateControlAndChildren( child ) ; - } -} -#endif void wxWindowMac::Thaw() { @@ -2018,9 +1995,8 @@ void wxWindowMac::Thaw() if ( !--m_frozenness ) { - HIViewSetDrawingEnabled( *m_peer , true ) ; - InvalidateControlAndChildren( *m_peer ) ; - // HIViewSetNeedsDisplay( *m_peer , true ) ; + m_peer->SetDrawingEnabled( true ) ; + m_peer->InvalidateWithChildren() ; } #endif } @@ -2028,7 +2004,7 @@ void wxWindowMac::Thaw() void wxWindowMac::MacRedrawControl() { /* - if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) ) + if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible()) { #if TARGET_API_MAC_CARBON Update() ; @@ -2169,18 +2145,14 @@ void wxWindowMac::MacPaintBorders( int left , int top ) int w , h ; GetSize( &w , &h ) ; + Rect rect = { top , left , h + top , w + left } ; if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { #if wxMAC_USE_THEME_BORDER - Rect rect = { top , left , m_height + top , m_width + left } ; SInt32 border = 0 ; - /* - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; InsetRect( &rect , border , border ); - DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; - */ - - DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; #else bool sunken = HasFlag( wxSUNKEN_BORDER ) ; RGBForeColor( &face ); @@ -2287,19 +2259,18 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control // area is scrolled, this does not occur if width and height are 2 pixels less, // TODO write optimal workaround - HIRect scrollrect = CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; + wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width , MacGetTopBorderSize() + height ) ; if ( rect ) { - HIRect scrollarea = CGRectMake( rect->x , rect->y , rect->width , rect->height) ; - scrollrect = CGRectIntersection( scrollrect , scrollarea ) ; + scrollrect.Intersect( *rect ) ; } - if ( HIViewGetNeedsDisplay( *m_peer ) ) + if ( m_peer->GetNeedsDisplay() ) { // becuase HIViewScrollRect does not scroll the already invalidated area we have two options // either immediate redraw or full invalidate #if 1 // is the better overall solution, as it does not slow down scrolling - HIViewSetNeedsDisplay( *m_peer , true ) ; + m_peer->SetNeedsDisplay( true ) ; #else // this would be the preferred version for fast drawing controls if( UMAGetSystemVersion() < 0x1030 ) @@ -2308,7 +2279,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) HIViewRender(*m_peer) ; #endif } - HIViewScrollRect ( *m_peer , &scrollrect , dx ,dy ) ; + m_peer->ScrollRect( scrollrect , dx , dy ) ; #else wxPoint pos; @@ -2321,7 +2292,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) wxClientDC dc(this) ; wxMacPortSetter helper(&dc) ; - GetControlBounds( *m_peer, &scrollrect); + m_peer->GetRect( &scrollrect ) ; scrollrect.top += MacGetTopBorderSize() ; scrollrect.left += MacGetLeftBorderSize() ; scrollrect.bottom = scrollrect.top + height ; @@ -2414,6 +2385,21 @@ void wxWindowMac::OnSetFocus(wxFocusEvent& event) //wxChildFocusEvent eventFocus(this); //(void)GetEventHandler()->ProcessEvent(eventFocus); + if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) + { + wxWindowDC dc(this) ; + wxMacPortSetter helper(&dc) ; + + int w , h ; + GetSize( &w , &h ) ; + Rect rect = { dc.m_macLocalOrigin.y , dc.m_macLocalOrigin.x , h + dc.m_macLocalOrigin.y , w + dc.m_macLocalOrigin.x } ; + + if ( event.GetEventType() == wxEVT_SET_FOCUS ) + DrawThemeFocusRect( &rect , true ) ; + else + DrawThemeFocusRect( &rect , false ) ; + } + event.Skip(); } @@ -2428,17 +2414,13 @@ void wxWindowMac::OnInternalIdle() // Raise the window to the top of the Z order void wxWindowMac::Raise() { -#if TARGET_API_MAC_OSX - HIViewSetZOrder(*m_peer,kHIViewZOrderAbove, NULL) ; -#endif + m_peer->SetZOrder( true , NULL ) ; } // Lower the window to the bottom of the Z order void wxWindowMac::Lower() { -#if TARGET_API_MAC_OSX - HIViewSetZOrder(*m_peer,kHIViewZOrderBelow, NULL) ; -#endif + m_peer->SetZOrder( false , NULL ) ; } @@ -2527,10 +2509,10 @@ void wxWindowMac::Update() status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; } else - HIViewSetNeedsDisplay( *m_peer , true ) ; + m_peer->SetNeedsDisplay( true ) ; } #else - ::Draw1Control( *m_peer ) ; + ::Draw1Control( m_peer->GetControlRef() ) ; #endif } @@ -2550,9 +2532,14 @@ wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) Rect r ; RgnHandle visRgn = NewRgn() ; RgnHandle tempRgn = NewRgn() ; - if ( IsControlVisible( *m_peer ) ) + if ( m_peer->IsVisible()) { - GetControlBounds( *m_peer , &r ) ; + m_peer->GetRect( &r ) ; + r.left -= MacGetLeftBorderSize() ; + r.top -= MacGetTopBorderSize() ; + r.bottom += MacGetBottomBorderSize() ; + r.right += MacGetRightBorderSize() ; + if (! MacGetTopLevelWindow()->MacUsesCompositing() ) { MacRootWindowToWindow( &r.left , & r.top ) ; @@ -2676,7 +2663,7 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) { Rect bounds; - UMAGetControlBoundsInWindowCoords( *m_peer, &bounds ); + m_peer->GetRectInWindowCoords( &bounds ); RgnHandle controlRgn = NewRgn(); RectRgn( controlRgn, &bounds ); //KO: This sets the ownUpdateRgn to the area of this control that is inside @@ -2861,7 +2848,7 @@ long wxWindowMac::MacGetLeftBorderSize( ) const if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) { SInt32 border = 3 ; -#if wxMAC_USE_THEME_BORDER +#if 0 // wxMAC_USE_THEME_BORDER GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; #endif return border ; @@ -2869,8 +2856,8 @@ long wxWindowMac::MacGetLeftBorderSize( ) const else if ( m_windowStyle &wxDOUBLE_BORDER) { SInt32 border = 3 ; -#if wxMAC_USE_THEME_BORDER - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; +#if 0 // wxMAC_USE_THEME_BORDER + GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; #endif return border ; } -- 2.45.2