]> git.saurik.com Git - wxWidgets.git/commitdiff
adding support for focus events to multiline textctrl
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 25 Mar 2009 13:12:55 +0000 (13:12 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 25 Mar 2009 13:12:55 +0000 (13:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/textctrl.mm

index e4f99f7040d95407016f43a8d1f397214edc9881..ca728cf9db4df97fcd8b3a84ae21b579b41ea2c1 100644 (file)
 
 @end
 
-@interface wxNSTextView : NSScrollView
+@interface wxNSTextScrollView : NSScrollView
 {
 }
+@end
+
+@interface wxNSTextView : NSTextView
+{
+    wxNSTextScrollView* scrollView;
+}
+
+- (void)setScrollView: (wxNSTextScrollView *) sv;
+- (wxNSTextScrollView*) scrollView;
 
 @end
 
-@implementation wxNSTextView
+@implementation wxNSTextScrollView
 
 + (void)initialize
 {
     
     return NO;
 }
+
+- (void)textDidEndEditing:(NSNotification *)aNotification
+{
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if ( impl )
+    {
+        impl->DoNotifyFocusEvent( false, NULL );
+    }
+}
+@end
+
+@implementation wxNSTextView
+
+- (BOOL) becomeFirstResponder
+{
+    BOOL val = [super becomeFirstResponder];
+    
+    if ( val )
+    {
+        wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( scrollView );
+        if (impl )
+            impl->DoNotifyFocusEvent( true, NULL );
+
+    }
+    return val;
+}
+
+- (void)setScrollView: (wxNSTextScrollView *) sv
+{
+    scrollView = sv;
+}
+
+- (wxNSTextScrollView*) scrollView
+{
+    return scrollView;
+}
+
 @end
 
 @implementation wxNSTextField
@@ -235,22 +282,25 @@ typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl
 
 wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 {
-    m_scrollView = (NSScrollView*) w;
+    wxNSTextScrollView* sv = (wxNSTextScrollView*) w;
+    m_scrollView = sv;
     
     [m_scrollView setHasVerticalScroller:YES];
     [m_scrollView setHasHorizontalScroller:NO];
     [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
     NSSize contentSize = [m_scrollView contentSize];
     
-    m_textView = [[NSTextView alloc] initWithFrame: NSMakeRect(0, 0,
+    wxNSTextView* tv = [[wxNSTextView alloc] initWithFrame: NSMakeRect(0, 0,
             contentSize.width, contentSize.height)];
-    [m_textView setVerticallyResizable:YES];
-    [m_textView setHorizontallyResizable:NO];
-    [m_textView setAutoresizingMask:NSViewWidthSizable];
+    m_textView = tv;
+    [tv setVerticallyResizable:YES];
+    [tv setHorizontallyResizable:NO];
+    [tv setAutoresizingMask:NSViewWidthSizable];
     
-    [m_scrollView setDocumentView: m_textView];
+    [m_scrollView setDocumentView: tv];
 
-    [m_textView setDelegate: w];
+    [tv setDelegate: w];
+    [tv setScrollView:sv];
 }
 
 wxNSTextViewControl::~wxNSTextViewControl()
@@ -447,8 +497,8 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
     
     if ( style & wxTE_MULTILINE || style & wxTE_RICH || style & wxTE_RICH2 )
     {
-        wxNSTextView* v = nil;
-        v = [[wxNSTextView alloc] initWithFrame:r];
+        wxNSTextScrollView* v = nil;
+        v = [[wxNSTextScrollView alloc] initWithFrame:r];
         c = new wxNSTextViewControl( wxpeer, v );
         static_cast<wxNSTextViewControl*>(c)->SetStringValue(str);
     }