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
This commit is contained in:
Kevin Ollivier
2009-11-26 23:11:27 +00:00
parent b9cf2753b4
commit 9ab7ff537d
4 changed files with 28 additions and 1 deletions

View File

@@ -62,6 +62,7 @@ public:
virtual void SetStyle(long start, long end, const wxTextAttr& style); virtual void SetStyle(long start, long end, const wxTextAttr& style);
virtual void CheckSpelling(bool check); virtual void CheckSpelling(bool check);
virtual wxSize GetBestSize() const;
protected: protected:
NSScrollView* m_scrollView; NSScrollView* m_scrollView;

View File

@@ -586,6 +586,8 @@ public :
virtual int GetLineLength(long lineNo) const ; virtual int GetLineLength(long lineNo) const ;
virtual wxString GetLineText(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ;
virtual void CheckSpelling(bool WXUNUSED(check)) { } virtual void CheckSpelling(bool WXUNUSED(check)) { }
virtual wxSize GetBestSize() const { return wxDefaultSize; }
}; };
// //

View File

@@ -514,6 +514,18 @@ void wxNSTextViewControl::CheckSpelling(bool check)
[m_textView setContinuousSpellCheckingEnabled: 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::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w) wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)

View File

@@ -190,7 +190,8 @@ bool wxTextCtrl::SetFont( const wxFont& font )
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
{ {
GetTextPeer()->SetStyle( start , end , style ) ; if (GetTextPeer())
GetTextPeer()->SetStyle( start , end , style ) ;
return true ; return true ;
} }
@@ -337,6 +338,13 @@ bool wxTextCtrl::AcceptsFocus() const
wxSize wxTextCtrl::DoGetBestSize() const wxSize wxTextCtrl::DoGetBestSize() const
{ {
if (GetTextPeer())
{
wxSize size = GetTextPeer()->GetBestSize();
if (size.x > 0 && size.y > 0)
return size;
}
int wText, hText; int wText, hText;
// these are the numbers from the HIG: // these are the numbers from the HIG:
@@ -826,7 +834,11 @@ int wxTextWidgetImpl::GetNumberOfLines() const
for (size_t i = 0; i < content.length() ; i++) for (size_t i = 0; i < content.length() ; i++)
{ {
#if wxOSX_USE_COCOA
if (content[i] == '\n')
#else
if (content[i] == '\r') if (content[i] == '\r')
#endif
lines++; lines++;
} }