diff --git a/docs/changes.txt b/docs/changes.txt index 094162c394..6deef2d39b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -226,6 +226,7 @@ wxOSX: - Implement wxTextCtrl::PositionToXY() and XYToPosition(). - Implement wxTextCtrl::ShowPosition(). - Add support for wxTE_NO_VSCROLL style to wxTextCtrl. +- Add support for wxTE_CHARWRAP style to wxTextCtrl. Unix: diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index e0a7cdaa9a..579dbf8ceb 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -124,9 +124,14 @@ public: virtual wxSize GetBestSize() const wxOVERRIDE; + virtual void controlTextDidChange() wxOVERRIDE; + protected: + void DoUpdateTextStyle(); + NSScrollView* m_scrollView; NSTextView* m_textView; + bool m_useCharWrapping; }; class wxNSComboBoxControl : public wxNSTextFieldControl, public wxComboWidgetImpl diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index d7c0cc54cc..96da213db2 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -990,7 +990,7 @@ public: scrollbar instead. @style{wxTE_CHARWRAP} For multiline controls only: wrap the lines too long to be shown - entirely at any position (wxUniv and wxGTK). + entirely at any position (wxUniv, wxGTK, wxOSX). @style{wxTE_WORDWRAP} For multiline controls only: wrap the lines too long to be shown entirely at word boundaries (wxUniv, wxMSW, wxGTK, wxOSX). diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index aed884cdb8..28316d14f6 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -713,6 +713,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s m_scrollView = sv; const bool hasHScroll = (style & wxHSCROLL) != 0; + m_useCharWrapping = (style & wxTE_CHARWRAP) != 0; [m_scrollView setHasVerticalScroller:YES]; [m_scrollView setHasHorizontalScroller:hasHScroll]; @@ -809,6 +810,8 @@ void wxNSTextViewControl::SetStringValue( const wxString &str) // Make sure that any URLs in the new text are highlighted. [m_textView checkTextInDocument:nil]; } + // Some text styles have to be updated manually. + DoUpdateTextStyle(); } } @@ -952,6 +955,29 @@ void wxNSTextViewControl::WriteText(const wxString& str) m_lastKeyDownEvent = nil; [m_textView insertText:wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; m_lastKeyDownEvent = formerEvent; + // Some text styles have to be updated manually. + DoUpdateTextStyle(); +} + +void wxNSTextViewControl::controlTextDidChange() +{ + wxNSTextBase::controlTextDidChange(); + // Some text styles have to be updated manually. + DoUpdateTextStyle(); +} + +void wxNSTextViewControl::DoUpdateTextStyle() +{ + if ( m_useCharWrapping ) + { + // Set line wrapping at any position + // by applying a style to the entire text. + NSTextStorage* storage = [m_textView textStorage]; + NSMutableParagraphStyle* style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + [style setLineBreakMode:NSLineBreakByCharWrapping]; + [storage addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [storage length])]; + [style release]; + } } void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSED(foreground) , long WXUNUSED(windowStyle), bool WXUNUSED(ignoreBlack) )