X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..71c5a4d19d8752bd54de0ef27b81cff7a6d4d5c7:/src/osx/carbon/textctrl.cpp diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp index 9397eca99f..57c315012a 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 ); @@ -218,10 +218,14 @@ wxMacWindowClipper::~wxMacWindowClipper() // common parts for implementations based on MLTE -class wxMacMLTEControl : public wxMacTextControl +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 ) ; @@ -358,13 +362,13 @@ private : }; wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, - wxWindowMac* parent, - wxWindowID id, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), const wxString& str, const wxPoint& pos, const wxSize& size, long style, - long extraStyle) + long WXUNUSED(extraStyle)) { bool forceMLTE = false ; @@ -378,7 +382,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, if ( UMAGetSystemVersion() >= 0x1050 ) forceMLTE = false; - wxMacTextControl* peer = NULL; + wxMacControl* peer = NULL; if ( !forceMLTE ) { @@ -466,7 +470,7 @@ static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) -wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacTextControl( wxPeer ) +wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacControl( wxPeer ) { } @@ -474,15 +478,7 @@ wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, const wxSize& size, long style ) - : wxMacTextControl( wxPeer ) -{ - Create( wxPeer, str, pos, size, style ); -} - -bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) + : wxMacControl( wxPeer ) { m_font = wxPeer->GetFont() ; m_windowStyle = style ; @@ -491,23 +487,34 @@ bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, wxString st = str ; wxMacConvertNewlines10To13( &st ) ; wxCFStringRef cf(st , m_font.GetEncoding()) ; - CFStringRef cfr = cf ; m_valueTag = kControlEditTextCFStringTag ; - CreateControl( wxPeer, &bounds, cfr ); + Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; + if ( isPassword ) + { + m_valueTag = kControlEditTextPasswordCFStringTag ; + } + OSStatus err = CreateEditUnicodeTextControl( + MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cf , + isPassword , NULL , &m_controlRef ) ; + verify_noerr( err ); if ( !(m_windowStyle & wxTE_MULTILINE) ) SetData( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; + InstallEventHandlers(); +} + +void wxMacUnicodeTextControl::InstallEventHandlers() +{ ::InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, - NULL); - - return true; + (EventHandlerRef*) &m_macTextCtrlEventHandler); } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() { + ::RemoveEventHandler((EventHandlerRef) m_macTextCtrlEventHandler); } void wxMacUnicodeTextControl::VisibilityChanged(bool shown) @@ -555,19 +562,6 @@ void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) verify_noerr( SetData( 0, m_valueTag , cf ) ) ; } -void wxMacUnicodeTextControl::CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef cfr ) -{ - Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; - if ( isPassword ) - { - m_valueTag = kControlEditTextPasswordCFStringTag ; - } - OSStatus err = CreateEditUnicodeTextControl( - MAC_WXHWND(peer->MacGetTopLevelWindowRef()), bounds , cfr , - isPassword , NULL , &m_controlRef ) ; - verify_noerr( err ); -} - void wxMacUnicodeTextControl::Copy() { SendHICommand( kHICommandCopy ) ; @@ -713,7 +707,7 @@ protected : } ; wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) - : wxMacTextControl( peer ) + : wxMacControl( peer ) { SetNeedsFocusRect( true ) ; } @@ -957,7 +951,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 ) @@ -1069,7 +1063,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 ) @@ -1085,7 +1080,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 ) ; @@ -1124,11 +1120,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 @@ -1137,6 +1142,7 @@ wxTextPos wxMacMLTEControl::GetLastPosition() const actualsize = GetHandleSize( theText ) ; DisposeHandle( theText ) ; } +#endif else { actualsize = 0 ; @@ -1377,8 +1383,10 @@ void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffse #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, + _T("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 @@ -1913,6 +1921,7 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featureSet, &m_controlRef ); verify_noerr( err ); + SetControlReference( m_controlRef , (URefCon) wxPeer ); DoCreate(); @@ -2233,7 +2242,7 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, { HIViewAddSubview( m_scrollView , m_textView ) ; m_controlRef = m_scrollView ; - wxMacControl::MacInstallEventHandler( m_textView, wxPeer ) ; + InstallEventHandler( (WXWidget) m_textView ) ; } else { @@ -2259,9 +2268,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