From 9ab7ff537d1ead0f0b07c14841474203c7fa59ba Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Thu, 26 Nov 2009 23:11:27 +0000 Subject: [PATCH] Allow OS X Cocoa (or any OS X port) to override GetBestSize and provide a native OS X Cocoa impl. Also, fix the line ending check under OS X Cocoa, and a sanity check for SetStyle. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private/textimpl.h | 1 + include/wx/osx/core/private.h | 2 ++ src/osx/cocoa/textctrl.mm | 12 ++++++++++++ src/osx/textctrl_osx.cpp | 14 +++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 5d7f07bceb..51bf090d2a 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -62,6 +62,7 @@ public: virtual void SetStyle(long start, long end, const wxTextAttr& style); virtual void CheckSpelling(bool check); + virtual wxSize GetBestSize() const; protected: NSScrollView* m_scrollView; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 47c9179bf3..5cb0e3688a 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -586,6 +586,8 @@ public : virtual int GetLineLength(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ; virtual void CheckSpelling(bool WXUNUSED(check)) { } + + virtual wxSize GetBestSize() const { return wxDefaultSize; } }; // diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 63a2515307..9dbb445eed 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -514,6 +514,18 @@ void wxNSTextViewControl::CheckSpelling(bool check) [m_textView setContinuousSpellCheckingEnabled: check]; } +wxSize wxNSTextViewControl::GetBestSize() const +{ + if (m_textView && [m_textView layoutManager]) + { + NSRect rect = [[m_textView layoutManager] usedRectForTextContainer: [m_textView textContainer]]; + wxSize size = wxSize(rect.size.width, rect.size.height); + size.x += [m_textView textContainerInset].width; + size.y += [m_textView textContainerInset].height; + return size; + } +} + // wxNSTextFieldControl wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w) diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 6edd282e97..ae3328808a 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -190,7 +190,8 @@ bool wxTextCtrl::SetFont( const wxFont& font ) bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - GetTextPeer()->SetStyle( start , end , style ) ; + if (GetTextPeer()) + GetTextPeer()->SetStyle( start , end , style ) ; return true ; } @@ -337,6 +338,13 @@ bool wxTextCtrl::AcceptsFocus() const wxSize wxTextCtrl::DoGetBestSize() const { + if (GetTextPeer()) + { + wxSize size = GetTextPeer()->GetBestSize(); + if (size.x > 0 && size.y > 0) + return size; + } + int wText, hText; // these are the numbers from the HIG: @@ -826,7 +834,11 @@ int wxTextWidgetImpl::GetNumberOfLines() const for (size_t i = 0; i < content.length() ; i++) { +#if wxOSX_USE_COCOA + if (content[i] == '\n') +#else if (content[i] == '\r') +#endif lines++; } -- 2.49.0