]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
fix MSVC warnings about possibly uninitialized variables; some reindentation
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index b5c896241eaf590a0caee82d4954eb8fd45db5fb..a9898bf349644d93fa78c0873b17fdd2607d49fd 100644 (file)
 
 @implementation wxNSTextField
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
++ (void)initialize
 {
-    impl = theImplementation;
-}
-
-- (wxWidgetImpl*) implementation
-{
-    return impl;
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
-- (BOOL) isFlipped
+- (id)initWithFrame:(NSRect)frame
 {
-    return YES;
+    [super initWithFrame:frame];
+    [self setDelegate: self];
+    [self setTarget: self];
+//    [self setAction: @selector(enterAction:)];
+    return self;
 }
 
 // use our common calls
 {
     [self setStringValue: title];
 }
+/*
+- (void)controlTextDidChange:(NSNotification *)aNotification
+{
+    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 );
+        }
+    }
+}
 
+- (void)controlTextDidEndEditing:(NSNotification *)aNotification
+{
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer ) {
+            wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetWindow( wxpeer );
+            wxpeer->HandleWindowEvent( event );
+        }
+    }
+}
+
+- (void) enterAction: (id) sender
+{
+    if ( impl )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) {
+            wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
+            event.SetEventObject( wxpeer );
+            event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
+            wxpeer->HandleWindowEvent( event );
+        }
+    }
+}
+*/
 @end
 
 wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
@@ -110,6 +156,7 @@ bool wxNSTextFieldControl::CanPaste() const
 
 void wxNSTextFieldControl::SetEditable(bool editable) 
 {
+    [(wxNSTextField*) m_osxView setEditable:editable];
 }
 
 void wxNSTextFieldControl::GetSelection( long* from, long* to) const 
@@ -136,11 +183,8 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
-    [sv addSubview:v];
     
     if ( style & wxNO_BORDER )
     {
@@ -153,7 +197,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
     //[v setDrawsBackground:NO];
     
     wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }