X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e181c7a2c32193fc8138cc32ed07984eadd4a21..cd95f7e65c4e1ee61a5d90eb13687ff468cb13ad:/src/osx/carbon/textctrl.cpp diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp index 2a280a7526..267680fca8 100644 --- a/src/osx/carbon/textctrl.cpp +++ b/src/osx/carbon/textctrl.cpp @@ -144,7 +144,7 @@ void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( con class WXDLLEXPORT wxMacPortSaver { - DECLARE_NO_COPY_CLASS(wxMacPortSaver) + wxDECLARE_NO_COPY_CLASS(wxMacPortSaver); public: wxMacPortSaver( GrafPtr port ); @@ -160,7 +160,7 @@ private : class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver { - DECLARE_NO_COPY_CLASS(wxMacWindowClipper) + wxDECLARE_NO_COPY_CLASS(wxMacWindowClipper); public: wxMacWindowClipper( const wxWindow* win ); @@ -223,6 +223,10 @@ class wxMacMLTEControl : public wxMacControl, public wxTextWidgetImpl public : wxMacMLTEControl( wxTextCtrl *peer ) ; ~wxMacMLTEControl() {} + + virtual bool CanFocus() const + { return true; } + virtual wxString GetStringValue() const ; virtual void SetStringValue( const wxString &str ) ; @@ -230,7 +234,7 @@ public : void AdjustCreationAttributes( const wxColour& background, bool visible ) ; - virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ; + virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle, bool ignoreBlack ) ; virtual void SetBackgroundColour(const wxColour& col ); virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; virtual void Copy() ; @@ -238,7 +242,7 @@ public : virtual void Paste() ; virtual bool CanPaste() const ; virtual void SetEditable( bool editable ) ; - virtual wxTextPos GetLastPosition() const ; + 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 ; @@ -290,7 +294,7 @@ public : const wxSize& size, long style ) ; virtual ~wxMacMLTEHIViewControl() ; - virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; + virtual bool SetFocus() ; virtual bool HasFocus() const ; virtual void SetBackgroundColour(const wxColour& col ) ; @@ -328,7 +332,7 @@ public : return true; } - virtual void Move(int x, int y, int width, int height); + virtual void Move(int x, int y, int width, int height); protected : OSStatus DoCreate(); @@ -357,14 +361,14 @@ private : SInt32 m_lastVerticalValue ; }; -wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, - wxWindowMac* parent, - wxWindowID id, +wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), const wxString& str, - const wxPoint& pos, + const wxPoint& pos, const wxSize& size, - long style, - long extraStyle) + long style, + long WXUNUSED(extraStyle)) { bool forceMLTE = false ; @@ -466,7 +470,9 @@ static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) -wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacControl( wxPeer ) +wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) + : wxMacControl( wxPeer ), + wxTextWidgetImpl( wxPeer ) { } @@ -474,7 +480,8 @@ wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, const wxSize& size, long style ) - : wxMacControl( wxPeer ) + : wxMacControl( wxPeer ), + wxTextWidgetImpl( wxPeer ) { m_font = wxPeer->GetFont() ; m_windowStyle = style ; @@ -505,11 +512,12 @@ void wxMacUnicodeTextControl::InstallEventHandlers() { ::InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, - NULL); + (EventHandlerRef*) &m_macTextCtrlEventHandler); } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() { + ::RemoveEventHandler((EventHandlerRef) m_macTextCtrlEventHandler); } void wxMacUnicodeTextControl::VisibilityChanged(bool shown) @@ -702,7 +710,8 @@ protected : } ; wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) - : wxMacControl( peer ) + : wxMacControl( peer ), + wxTextWidgetImpl( peer ) { SetNeedsFocusRect( true ) ; } @@ -730,23 +739,18 @@ wxString wxMacMLTEControl::GetStringValue() const { 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 ; wxMBConvUTF16 converter ; size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; - wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); + wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Unable to count the number of characters in this string!") ); ptr = new wxChar[noChars + 1] ; noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; - wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); + wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Conversion of string failed!") ); ptr[noChars] = 0 ; HUnlock( theText ) ; -#endif ptr[actualSize] = 0 ; result = wxString( ptr ) ; @@ -755,7 +759,7 @@ wxString wxMacMLTEControl::GetStringValue() const DisposeHandle( theText ) ; } -#else +#else // !wxUSE_UNICODE Handle theText ; err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); @@ -776,7 +780,7 @@ wxString wxMacMLTEControl::GetStringValue() const DisposeHandle( theText ) ; } -#endif +#endif // wxUSE_UNICODE/!wxUSE_UNICODE } #if '\n' == 10 @@ -888,7 +892,7 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, } ; err = TXNSetTypeAttributes( - m_txn, sizeof(typeAttr) / sizeof(TXNTypeAttributes), + m_txn, WXSIZEOF(typeAttr), typeAttr, kTXNStartOffset, kTXNEndOffset ); verify_noerr( err ); @@ -946,7 +950,7 @@ void wxMacMLTEControl::SetBackgroundColour(const wxColour& col ) static inline int wxConvertToTXN(int x) { - return wx_static_cast(int, x / 254.0 * 72 + 0.5); + return static_cast(x / 254.0 * 72 + 0.5); } void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) @@ -1058,7 +1062,8 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo if ( typeAttrCount > 0 ) { verify_noerr( TXNSetTypeAttributes( m_txn , typeAttrCount, typeAttr, from , to ) ); - relayout = true; + if (from != to) + relayout = true; } if ( tabs != NULL ) @@ -1074,7 +1079,8 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo void wxMacMLTEControl::SetFont(const wxFont & font, const wxColour& foreground, - long WXUNUSED(windowStyle)) + long WXUNUSED(windowStyle), + bool WXUNUSED(ignoreBlack)) { wxMacEditHelper help( m_txn ) ; TXNSetAttribute( wxTextAttr( foreground, wxNullColour, font ), kTXNStartOffset, kTXNEndOffset ) ; @@ -1113,11 +1119,20 @@ void wxMacMLTEControl::SetEditable(bool editable) TXNSetTXNObjectControls( m_txn, false, WXSIZEOF(tag), tag, data ) ; } -wxTextPos wxMacMLTEControl::GetLastPosition() const +long wxMacMLTEControl::GetLastPosition() const { wxTextPos actualsize = 0 ; Handle theText ; +#if wxUSE_UNICODE + OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNUnicodeTextData ); + // all done + if ( err == noErr ) + { + actualsize = GetHandleSize( theText )/sizeof(UniChar); + DisposeHandle( theText ) ; + } +#else OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); // all done @@ -1126,6 +1141,7 @@ wxTextPos wxMacMLTEControl::GetLastPosition() const actualsize = GetHandleSize( theText ) ; DisposeHandle( theText ) ; } +#endif else { actualsize = 0 ; @@ -1354,27 +1370,24 @@ void wxMacMLTEControl::ShowPosition( long pos ) // there will be an error returned for classic MLTE implementation when the control is // invisible, but HITextView works correctly, so we don't assert that one - // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); + // wxASSERT_MSG( theErr == noErr, wxT("TXNScroll returned an error!") ); } void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) { #if wxUSE_UNICODE -#if SIZEOF_WCHAR_T == 2 - size_t len = st.length() ; - TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end ); -#else wxMBConvUTF16 converter ; ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; - UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ; - converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ; + wxASSERT_MSG( byteBufferLen != wxCONV_FAILED, + wxT("Conversion to UTF-16 unexpectedly failed") ); + UniChar *unibuf = (UniChar*)malloc( byteBufferLen + 2 ) ; // 2 for NUL in UTF-16 + converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen + 2 ) ; TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; free( unibuf ) ; -#endif -#else +#else // !wxUSE_UNICODE wxCharBuffer text = st.mb_str( wxConvLocal ) ; TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; -#endif +#endif // wxUSE_UNICODE/!wxUSE_UNICODE } wxString wxMacMLTEControl::GetLineText(long lineNo) const @@ -1713,7 +1726,7 @@ void wxMacMLTEClassicControl::MacUpdatePosition() } } -void wxMacMLTEClassicControl::Move(int x, int y, int width, int height) +void wxMacMLTEClassicControl::Move(int x, int y, int width, int height) { wxMacControl::Move(x,y,width,height) ; MacUpdatePosition() ; @@ -1902,6 +1915,7 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featureSet, &m_controlRef ); verify_noerr( err ); + SetControlReference( m_controlRef , (URefCon) wxPeer ); DoCreate(); @@ -2222,7 +2236,7 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, { HIViewAddSubview( m_scrollView , m_textView ) ; m_controlRef = m_scrollView ; - wxMacControl::MacInstallEventHandler( m_textView, wxPeer ) ; + InstallEventHandler( (WXWidget) m_textView ) ; } else { @@ -2248,9 +2262,9 @@ wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() { } -OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) +bool wxMacMLTEHIViewControl::SetFocus() { - return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, focusPart ) ; + return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, kControlFocusNextPart ) == noErr ; } bool wxMacMLTEHIViewControl::HasFocus() const