Add CheckSpelling support for OS X Cocoa, make sure NSTextView-based wxTextCtrls emit EVT_TEXT, and a fix for GetStyle when position == length.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62724 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -301,10 +301,12 @@ protected :
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface wxNSTextView : NSTextView
|
@interface wxNSTextView : NSTextView <NSTextViewDelegate>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)textDidChange:(NSNotification *)aNotification;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface wxNSMenu : NSMenu
|
@interface wxNSMenu : NSMenu
|
||||||
|
@@ -61,6 +61,8 @@ public:
|
|||||||
virtual bool GetStyle(long position, wxTextAttr& style);
|
virtual bool GetStyle(long position, wxTextAttr& style);
|
||||||
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);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NSScrollView* m_scrollView;
|
NSScrollView* m_scrollView;
|
||||||
NSTextView* m_textView;
|
NSTextView* m_textView;
|
||||||
|
@@ -192,6 +192,21 @@ protected :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)textDidChange:(NSNotification *)aNotification
|
||||||
|
{
|
||||||
|
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( [aNotification object] );
|
||||||
|
if ( impl )
|
||||||
|
{
|
||||||
|
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
|
||||||
|
if ( wxpeer ) {
|
||||||
|
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
|
||||||
|
event.SetEventObject( wxpeer );
|
||||||
|
event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
|
||||||
|
wxpeer->HandleWindowEvent( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation wxNSTextField
|
@implementation wxNSTextField
|
||||||
@@ -319,7 +334,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxW
|
|||||||
|
|
||||||
[m_scrollView setDocumentView: tv];
|
[m_scrollView setDocumentView: tv];
|
||||||
|
|
||||||
[tv setDelegate: w];
|
[tv setDelegate: tv];
|
||||||
|
|
||||||
InstallEventHandler(tv);
|
InstallEventHandler(tv);
|
||||||
}
|
}
|
||||||
@@ -431,15 +446,36 @@ void wxNSTextViewControl::SetFont( const wxFont & font , const wxColour& WXUNUSE
|
|||||||
|
|
||||||
bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
|
bool wxNSTextViewControl::GetStyle(long position, wxTextAttr& style)
|
||||||
{
|
{
|
||||||
if (m_textView && position >=0 && position < [[m_textView string] length]) {
|
if (m_textView && position >=0)
|
||||||
|
{
|
||||||
|
NSFont* font = NULL;
|
||||||
|
NSColor* bgcolor = NULL;
|
||||||
|
NSColor* fgcolor = NULL;
|
||||||
|
// NOTE: It appears that other platforms accept GetStyle with the position == length
|
||||||
|
// but that NSTextStorage does not accept length as a valid position.
|
||||||
|
// Therefore we return the default control style in that case.
|
||||||
|
if (position < [[m_textView string] length])
|
||||||
|
{
|
||||||
NSTextStorage* storage = [m_textView textStorage];
|
NSTextStorage* storage = [m_textView textStorage];
|
||||||
NSFont* font = [storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL];
|
font = [[storage attribute:NSFontAttributeName atIndex:position effectiveRange:NULL] autorelease];
|
||||||
|
bgcolor = [[storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
|
||||||
|
fgcolor = [[storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL] autorelease];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSDictionary* attrs = [m_textView typingAttributes];
|
||||||
|
font = [[attrs objectForKey:NSFontAttributeName] autorelease];
|
||||||
|
bgcolor = [[attrs objectForKey:NSBackgroundColorAttributeName] autorelease];
|
||||||
|
fgcolor = [[attrs objectForKey:NSForegroundColorAttributeName] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
if (font)
|
if (font)
|
||||||
style.SetFont(wxFont(font));
|
style.SetFont(wxFont(font));
|
||||||
NSColor* bgcolor = [storage attribute:NSBackgroundColorAttributeName atIndex:position effectiveRange:NULL];
|
|
||||||
if (bgcolor)
|
if (bgcolor)
|
||||||
style.SetBackgroundColour(wxColour(bgcolor));
|
style.SetBackgroundColour(wxColour(bgcolor));
|
||||||
NSColor* fgcolor = [storage attribute:NSForegroundColorAttributeName atIndex:position effectiveRange:NULL];
|
|
||||||
|
if (fgcolor)
|
||||||
style.SetTextColour(wxColour(fgcolor));
|
style.SetTextColour(wxColour(fgcolor));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -453,22 +489,31 @@ void wxNSTextViewControl::SetStyle(long start,
|
|||||||
{
|
{
|
||||||
if (m_textView) {
|
if (m_textView) {
|
||||||
NSRange range = NSMakeRange(start, end-start);
|
NSRange range = NSMakeRange(start, end-start);
|
||||||
|
if (start == -1 && end == -1)
|
||||||
|
range = [m_textView selectedRange];
|
||||||
|
|
||||||
NSTextStorage* storage = [m_textView textStorage];
|
NSTextStorage* storage = [m_textView textStorage];
|
||||||
|
|
||||||
wxFont font = style.GetFont();
|
wxFont font = style.GetFont();
|
||||||
if (font.IsOk())
|
if (style.HasFont() && font.IsOk())
|
||||||
[storage addAttribute:NSFontAttributeName value:style.GetFont().OSXGetNSFont() range:range];
|
[storage addAttribute:NSFontAttributeName value:font.OSXGetNSFont() range:range];
|
||||||
|
|
||||||
wxColour bgcolor = style.GetBackgroundColour();
|
wxColour bgcolor = style.GetBackgroundColour();
|
||||||
if (bgcolor.IsOk())
|
if (style.HasBackgroundColour() && bgcolor.IsOk())
|
||||||
[storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
|
[storage addAttribute:NSBackgroundColorAttributeName value:bgcolor.OSXGetNSColor() range:range];
|
||||||
|
|
||||||
wxColour fgcolor = style.GetTextColour();
|
wxColour fgcolor = style.GetTextColour();
|
||||||
if (fgcolor.IsOk())
|
if (style.HasTextColour() && fgcolor.IsOk())
|
||||||
[storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
|
[storage addAttribute:NSForegroundColorAttributeName value:fgcolor.OSXGetNSColor() range:range];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxNSTextViewControl::CheckSpelling(bool check)
|
||||||
|
{
|
||||||
|
if (m_textView)
|
||||||
|
[m_textView setContinuousSpellCheckingEnabled: check];
|
||||||
|
}
|
||||||
|
|
||||||
// wxNSTextFieldControl
|
// wxNSTextFieldControl
|
||||||
|
|
||||||
wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
|
wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
|
||||||
|
Reference in New Issue
Block a user