Add support for wxTE_CHARWRAP to wxTextCtrl
Apparently various text wrapping modes are not supported natively by NSTextView (apart from word wrapping which is used by default) and non-default wrapping has to be implemented in the custom code. To wrap lines at any character, NSLineBreakByCharWrapping style should be applied at any text change to the entire text stored in NSTextStorage associated with NSTextView. This is done in DoUpdateTextStyle() method which is called from controlTextDidChange() when text is modified by the user, or SetStringValue() and WriteText() when text is set programmatically.
This commit is contained in:
@@ -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:
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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).
|
||||
|
@@ -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) )
|
||||
|
Reference in New Issue
Block a user