X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72e430cd9754a68932bf907d282120f91cb0a040..2cf3a6d7bef6f20bea35062dd3d4dbf0aec9efb5:/src/mac/classic/textctrl.cpp diff --git a/src/mac/classic/textctrl.cpp b/src/mac/classic/textctrl.cpp index 93123e9740..cae116ab43 100644 --- a/src/mac/classic/textctrl.cpp +++ b/src/mac/classic/textctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: textctrl.cpp +// Name: src/mac/classic/textctrl.cpp // Purpose: wxTextCtrl // Author: Stefan Csomor // Modified by: @@ -9,23 +9,33 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "textctrl.h" -#endif +#include "wx/wxprec.h" -#include "wx/defs.h" +#ifdef __BORLANDC__ + #pragma hdrstop +#endif #if wxUSE_TEXTCTRL +#include "wx/textctrl.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/dc.h" + #include "wx/button.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/toplevel.h" +#endif + #ifdef __DARWIN__ - #include - #include + #include + #include #else - #include + #include #endif -#include "wx/msgdlg.h" - #if wxUSE_STD_IOSTREAM #if wxUSE_IOSTREAMH #include @@ -34,21 +44,14 @@ #endif #endif -#include "wx/app.h" -#include "wx/dc.h" -#include "wx/button.h" -#include "wx/toplevel.h" -#include "wx/textctrl.h" #include "wx/notebook.h" #include "wx/tabctrl.h" -#include "wx/settings.h" #include "wx/filefn.h" -#include "wx/utils.h" #if defined(__BORLANDC__) && !defined(__WIN32__) - #include + #include #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) - #include + #include #endif #ifndef __DARWIN__ @@ -225,7 +228,7 @@ static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart else TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 30000 , varsp->fRTextArea.left + 30000 , varsp->fRTextArea.bottom + 30000 , varsp->fRTextArea.right + 30000 , varsp->fTXNFrame); - + } if ( IsControlVisible( theControl ) ) @@ -238,7 +241,7 @@ static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart /* restore the drawing environment */ /* draw the text frame and focus frame (if necessary) */ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - if ((**tpvars).fIsActive && varsp->fInFocus) + if ((**tpvars).fIsActive && varsp->fInFocus) DrawThemeFocusRect(&varsp->fRFocusOutline, true); /* release our globals */ HSetState((Handle) tpvars, state); @@ -420,7 +423,7 @@ static pascal void TPPaneActivateProc(ControlHandle theControl, Boolean activati if ( IsControlVisible( theControl ) ) { DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - if (varsp->fInFocus) + if (varsp->fInFocus) DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive); } HSetState((Handle) tpvars, state); @@ -483,8 +486,8 @@ static pascal ControlPartCode TPPaneFocusProc(ControlHandle theControl, ControlF if ( IsControlVisible( theControl ) ) { /* save the drawing state */ - SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; + SetPort((**tpvars).fDrawingEnvironment); + wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive && varsp->fInFocus); } @@ -637,10 +640,9 @@ OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle ) -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) -BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) +BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) @@ -655,29 +657,28 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) END_EVENT_TABLE() -#endif static void SetTXNData( TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end ) { #if wxUSE_UNICODE #if SIZEOF_WCHAR_T == 2 - size_t len = st.Len() ; + size_t len = st.length() ; 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 ) ; + 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 ) ; + free( unibuf ) ; #endif #else - wxCharBuffer text = st.mb_str(wxConvLocal) ; + wxCharBuffer text = st.mb_str(wxConvLocal) ; TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) , start, end); -#endif +#endif } // Text item @@ -728,7 +729,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, // base initialization if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) - return FALSE; + return false; wxSize mySize = size ; if ( m_macUsesTXN ) @@ -767,7 +768,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, if ( m_windowStyle & wxTE_READONLY) { - m_editable = FALSE ; + m_editable = false ; } wxString st = str ; @@ -796,7 +797,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, if ( !m_macUsesTXN ) { - wxCharBuffer text = st.mb_str(wxConvLocal) ; + wxCharBuffer text = st.mb_str(wxConvLocal) ; ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ; } else @@ -813,7 +814,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); } - return TRUE; + return true; } wxString wxTextCtrl::GetValue() const @@ -826,12 +827,12 @@ wxString wxTextCtrl::GetValue() const err = ::GetControlDataSize((ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, &actualSize ) ; - if ( err ) - return wxEmptyString ; + if ( err ) + return wxEmptyString ; - if ( actualSize > 0 ) - { - wxCharBuffer buf(actualSize) ; + if ( actualSize > 0 ) + { + wxCharBuffer buf(actualSize) ; ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, actualSize , buf.data() , &actualSize ) ; @@ -854,13 +855,13 @@ wxString wxTextCtrl::GetValue() const if ( actualSize > 0 ) { wxChar *ptr = result.GetWriteBuf(actualSize*sizeof(wxChar)) ; -#if SIZEOF_WCHAR_T == 2 +#if SIZEOF_WCHAR_T == 2 wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; #else - wxMBConvUTF16BE converter ; - HLock( theText ) ; - converter.MB2WC( ptr , (const char*)*theText , actualSize ) ; - HUnlock( theText ) ; + wxMBConvUTF16BE converter ; + HLock( theText ) ; + converter.MB2WC( ptr , (const char*)*theText , actualSize ) ; + HUnlock( theText ) ; #endif ptr[actualSize] = 0 ; result.UngetWriteBuf( actualSize *sizeof(wxChar) ) ; @@ -911,7 +912,7 @@ void wxTextCtrl::SetValue(const wxString& str) wxMacConvertNewlines13To10( &st ) ; if ( !m_macUsesTXN ) { - wxCharBuffer text = st.mb_str(wxConvLocal) ; + wxCharBuffer text = st.mb_str(wxConvLocal) ; ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ; } else @@ -990,14 +991,14 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) if ( !formerEditable ) SetEditable(formerEditable) ; } - return TRUE ; + return true ; } bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) { wxTextCtrlBase::SetDefaultStyle( style ) ; SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; - return TRUE ; + return true ; } // Clipboard operations @@ -1089,7 +1090,7 @@ bool wxTextCtrl::CanCut() const bool wxTextCtrl::CanPaste() const { if (!IsEditable()) - return FALSE; + return false; #if TARGET_CARBON OSStatus err = noErr; @@ -1105,20 +1106,20 @@ bool wxTextCtrl::CanPaste() const { if (( err = GetScrapFlavorSize( scrapRef, 'TEXT', &byteCount )) == noErr) { - return TRUE ; + return true ; } } } - return FALSE; + return false; #else long offset ; if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) { - return TRUE ; + return true ; } #endif - return FALSE ; + return false ; } void wxTextCtrl::SetEditable(bool editable) @@ -1149,7 +1150,7 @@ void wxTextCtrl::SetInsertionPoint(long pos) void wxTextCtrl::SetInsertionPointEnd() { - long pos = GetLastPosition(); + wxTextPos pos = GetLastPosition(); SetInsertionPoint(pos); } @@ -1160,7 +1161,7 @@ long wxTextCtrl::GetInsertionPoint() const return begin ; } -long wxTextCtrl::GetLastPosition() const +wxTextPos wxTextCtrl::GetLastPosition() const { if ( !m_macUsesTXN ) { @@ -1198,7 +1199,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& str) ::SetControlData((ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; TESetSelect( from , to , ((TEHandle) m_macTE) ) ; TEDelete( ((TEHandle) m_macTE) ) ; - TEInsert( value , value.Length() , ((TEHandle) m_macTE) ) ; + TEInsert( value , value.length() , ((TEHandle) m_macTE) ) ; } else { @@ -1245,14 +1246,14 @@ void wxTextCtrl::SetSelection(long from, long to) ControlEditTextSelectionRec selection ; if ((from == -1) && (to == -1)) { - selection.selStart = 0 ; - selection.selEnd = 32767 ; - } + selection.selStart = 0 ; + selection.selEnd = 32767 ; + } else { - selection.selStart = from ; - selection.selEnd = to ; - } + selection.selStart = from ; + selection.selEnd = to ; + } TESetSelect( selection.selStart , selection.selEnd , ((TEHandle) m_macTE) ) ; ::SetControlData((ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; @@ -1267,9 +1268,9 @@ void wxTextCtrl::SetSelection(long from, long to) SetPort((**tpvars).fDrawingEnvironment); /* change the selection */ if ((from == -1) && (to == -1)) - TXNSelectAll((TXNObject) m_macTXN); + TXNSelectAll((TXNObject) m_macTXN); else - TXNSetSelection( (**tpvars).fTXNRec, from, to); + TXNSetSelection( (**tpvars).fTXNRec, from, to); TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); } } @@ -1278,10 +1279,10 @@ bool wxTextCtrl::LoadFile(const wxString& file) { if ( wxTextCtrlBase::LoadFile(file) ) { - return TRUE; + return true; } - return FALSE; + return false; } void wxTextCtrl::WriteText(const wxString& str) @@ -1290,7 +1291,7 @@ void wxTextCtrl::WriteText(const wxString& str) wxMacConvertNewlines13To10( &st ) ; if ( !m_macUsesTXN ) { - wxCharBuffer text = st.mb_str(wxConvLocal) ; + wxCharBuffer text = st.mb_str(wxConvLocal) ; TEInsert( text , strlen(text) , ((TEHandle) m_macTE) ) ; } else @@ -1386,9 +1387,9 @@ void wxTextCtrl::Undo() { if (CanUndo()) { - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { - TXNUndo((TXNObject)m_macTXN); + TXNUndo((TXNObject)m_macTXN); } } } @@ -1397,37 +1398,37 @@ void wxTextCtrl::Redo() { if (CanRedo()) { - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { - TXNRedo((TXNObject)m_macTXN); + TXNRedo((TXNObject)m_macTXN); } } } bool wxTextCtrl::CanUndo() const { - if ( !IsEditable() ) + if ( !IsEditable() ) { - return false ; + return false ; } - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { - return TXNCanUndo((TXNObject)m_macTXN,NULL); + return TXNCanUndo((TXNObject)m_macTXN,NULL); } - return FALSE ; + return false ; } bool wxTextCtrl::CanRedo() const { - if ( !IsEditable() ) + if ( !IsEditable() ) { - return false ; + return false ; } - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { - return TXNCanRedo((TXNObject)m_macTXN,NULL); + return TXNCanRedo((TXNObject)m_macTXN,NULL); } - return FALSE ; + return false ; } // Makes modifie or unmodified @@ -1443,18 +1444,18 @@ void wxTextCtrl::DiscardEdits() int wxTextCtrl::GetNumberOfLines() const { - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { ItemCount lines ; TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; return lines ; } else - { + { wxString content = GetValue() ; int count = 1; - for (size_t i = 0; i < content.Length() ; i++) + for (size_t i = 0; i < content.length() ; i++) { if (content[i] == '\r') count++; } @@ -1470,13 +1471,13 @@ long wxTextCtrl::XYToPosition(long x, long y) const bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { - return FALSE ; + return false ; } void wxTextCtrl::ShowPosition(long pos) { #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) - if ( m_macUsesTXN ) + if ( m_macUsesTXN ) { Point current ; Point desired ; @@ -1491,7 +1492,7 @@ void wxTextCtrl::ShowPosition(long pos) 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 ); + theErr = TXNScroll( (TXNObject) m_macTXN, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh ); wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); } } @@ -1505,13 +1506,13 @@ int wxTextCtrl::GetLineLength(long lineNo) const // Find line first int count = 0; - for (size_t i = 0; i < content.Length() ; i++) + 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++) + for (size_t j = i; j < content.length(); j++) { count++; if (content[j] == '\n') return count; @@ -1531,14 +1532,14 @@ wxString wxTextCtrl::GetLineText(long lineNo) const // Find line first int count = 0; - for (size_t i = 0; i < content.Length() ; i++) + 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++) + for (size_t j = i; j < content.length(); j++) { if (content[j] == '\n') return tmp; @@ -1585,8 +1586,8 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) } 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 */ + !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) +/* && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END */ ) { // eat it @@ -1611,7 +1612,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) switch ( key ) { case WXK_RETURN: - if (m_windowStyle & wxPROCESS_ENTER) + if (m_windowStyle & wxTE_PROCESS_ENTER) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); @@ -1641,7 +1642,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // this will make wxWidgets eat the ENTER key so that // we actually prevent line wrapping in a single line // text control - eat_key = TRUE; + eat_key = true; } break; @@ -1672,7 +1673,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) #if TARGET_CARBON if ( m_macUsesTXN && wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; - else + else { EventRecord rec ; if ( wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) )