From 1659164a6f06194b40de1eaa72d4035130891227 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2012 23:53:06 +0000 Subject: [PATCH] Implement setting default wxTextCtrl style in wxOSX. Use NSTextView setTypingAttributes to change the attributes used for the new text by default as setting them for the selected region didn't do anything useful under OS X (and did nothing at all when there was no selection). Closes #12839. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72892 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/osx/cocoa/textctrl.mm | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 51e3c84f52..9d864b6497 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -606,6 +606,7 @@ wxOSX/Cocoa: - Implement image support in wxNotebook (Malcolm MacLeod). - Add support for button mnemonics (joostn). +- Implemented wxTextCtrl::SetDefaultStyle(). 2.9.4: (released 2012-07-09) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index e68590a4db..f2482308a1 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -688,10 +688,25 @@ void wxNSTextViewControl::SetStyle(long start, long end, const wxTextAttr& style) { - if (m_textView) { + if ( !m_textView ) + return; + + if ( start == -1 && end == -1 ) + { + NSMutableDictionary* const + attrs = [NSMutableDictionary dictionaryWithCapacity:3]; + if ( style.HasFont() ) + [attrs setValue:style.GetFont().OSXGetNSFont() forKey:NSFontAttributeName]; + if ( style.HasBackgroundColour() ) + [attrs setValue:style.GetBackgroundColour().OSXGetNSColor() forKey:NSBackgroundColorAttributeName]; + if ( style.HasTextColour() ) + [attrs setValue:style.GetTextColour().OSXGetNSColor() forKey:NSForegroundColorAttributeName]; + + [m_textView setTypingAttributes:attrs]; + } + else // Set the attributes just for this range. + { NSRange range = NSMakeRange(start, end-start); - if (start == -1 && end == -1) - range = [m_textView selectedRange]; NSTextStorage* storage = [m_textView textStorage]; if ( style.HasFont() ) @@ -699,7 +714,7 @@ void wxNSTextViewControl::SetStyle(long start, if ( style.HasBackgroundColour() ) [storage addAttribute:NSBackgroundColorAttributeName value:style.GetBackgroundColour().OSXGetNSColor() range:range]; - + if ( style.HasTextColour() ) [storage addAttribute:NSForegroundColorAttributeName value:style.GetTextColour().OSXGetNSColor() range:range]; } -- 2.45.2