From 4503c41bd857494a57c247d8abf250cd30d8dc14 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 31 Aug 2017 16:28:42 +0200 Subject: [PATCH] Optimize wxTextCtrl::GetLastPosition() in wxOSX To get the length of the text in the control there is no need to convert NSString to wxString (what is done now by calling to GetStringValue). --- include/wx/osx/cocoa/private/textimpl.h | 2 ++ src/osx/cocoa/textctrl.mm | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 579dbf8ceb..bc60710cd9 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -60,6 +60,7 @@ public : virtual void Paste() wxOVERRIDE ; virtual bool CanPaste() const wxOVERRIDE ; virtual void SetEditable(bool editable) wxOVERRIDE ; + virtual long GetLastPosition() const wxOVERRIDE; virtual void GetSelection( long* from, long* to) const wxOVERRIDE ; virtual void SetSelection( long from , long to ) wxOVERRIDE; virtual bool PositionToXY(long pos, long *x, long *y) const wxOVERRIDE; @@ -103,6 +104,7 @@ public: virtual void Paste() wxOVERRIDE ; virtual bool CanPaste() const wxOVERRIDE ; virtual void SetEditable(bool editable) wxOVERRIDE ; + virtual long GetLastPosition() const wxOVERRIDE; virtual void GetSelection( long* from, long* to) const wxOVERRIDE ; virtual void SetSelection( long from , long to ) wxOVERRIDE; virtual bool PositionToXY(long pos, long *x, long *y) const wxOVERRIDE; diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 9b8f4d11c1..3ca42cbc0c 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -845,6 +845,12 @@ void wxNSTextViewControl::SetEditable(bool editable) [m_textView setEditable: editable]; } +long wxNSTextViewControl::GetLastPosition() const +{ + wxCHECK( m_textView, 0 ); + return [[m_textView string] length]; +} + void wxNSTextViewControl::GetSelection( long* from, long* to) const { if (m_textView) @@ -1221,6 +1227,11 @@ void wxNSTextFieldControl::SetEditable(bool editable) [m_textField setEditable:editable]; } +long wxNSTextFieldControl::GetLastPosition() const +{ + return [[m_textField stringValue] length]; +} + void wxNSTextFieldControl::GetSelection( long* from, long* to) const { NSText* editor = [m_textField currentEditor];