]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
fixing class
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index 96a35ede643805f6e833cd771ced56e71b464f90..b1364c509c5ae9ef478dff011c9788f04c4423c2 100644 (file)
@@ -119,7 +119,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
 
 - (id)init 
 {
 
 - (id)init 
 {
-    [super init];
+    self = [super init];
     maxLength = 0;
     return self;
 }
     maxLength = 0;
     return self;
 }
@@ -186,6 +186,39 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
     }
 }
 
     }
 }
 
+- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
+{
+    wxUnusedVar(textView);
+    
+    BOOL handled = NO;
+    
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( control );
+    if ( impl  )
+    {
+        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        if ( wxpeer )
+        {
+            if (commandSelector == @selector(insertNewline:))
+            {
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(wxpeer), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
+                {
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+                    if ( def && def->IsEnabled() )
+                    {
+                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+                        event.SetEventObject(def);
+                        def->Command(event);
+                        handled = YES;
+                    }
+                }
+            }
+        }
+    }
+    
+    return handled;
+}
+
 @end
 
 @interface wxNSTextScrollView : NSScrollView
 @end
 
 @interface wxNSTextScrollView : NSScrollView
@@ -834,7 +867,12 @@ void wxNSTextFieldControl::WriteText(const wxString& str)
     if ( editor )
     {
         wxMacEditHelper helper(m_textField);
     if ( editor )
     {
         wxMacEditHelper helper(m_textField);
+        BOOL hasUndo = [editor respondsToSelector:@selector(setAllowsUndo:)];
+        if ( hasUndo )
+            [editor setAllowsUndo:NO];
         [editor insertText:wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
         [editor insertText:wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
+        if ( hasUndo )
+            [editor setAllowsUndo:YES];
     }
     else
     {
     }
     else
     {
@@ -890,6 +928,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         wxNSTextScrollView* v = nil;
         v = [[wxNSTextScrollView alloc] initWithFrame:r];
         c = new wxNSTextViewControl( wxpeer, v );
         wxNSTextScrollView* v = nil;
         v = [[wxNSTextScrollView alloc] initWithFrame:r];
         c = new wxNSTextViewControl( wxpeer, v );
+        c->SetNeedsFocusRect( true );
     }
     else
     {
     }
     else
     {
@@ -899,24 +938,39 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
         else
             v = [[wxNSTextField alloc] initWithFrame:r];
 
         else
             v = [[wxNSTextField alloc] initWithFrame:r];
 
-        if ( style & wxNO_BORDER )
+        if ( style & wxTE_RIGHT)
         {
         {
-            // FIXME: How can we remove the native control's border?
-            // setBordered is separate from the text ctrl's border.
+            [v setAlignment:NSRightTextAlignment];
         }
         }
-        
+        else if ( style & wxTE_CENTRE)
+        {
+            [v setAlignment:NSCenterTextAlignment];
+        }
+                
         NSTextFieldCell* cell = [v cell];
         [cell setScrollable:YES];
         // TODO: Remove if we definitely are sure, it's not needed
         // as setting scrolling to yes, should turn off any wrapping
         // [cell setLineBreakMode:NSLineBreakByClipping]; 
 
         NSTextFieldCell* cell = [v cell];
         [cell setScrollable:YES];
         // TODO: Remove if we definitely are sure, it's not needed
         // as setting scrolling to yes, should turn off any wrapping
         // [cell setLineBreakMode:NSLineBreakByClipping]; 
 
-        [v setBezeled:NO];
-        [v setBordered:NO];
-
         c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
         c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
+        
+        if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) )
+        {
+            // under 10.7 the textcontrol can draw its own focus
+            // even if no border is shown, on previous systems
+            // we have to emulate this
+            [v setBezeled:NO];
+            [v setBordered:NO];
+            if ( UMAGetSystemVersion() < 0x1070 )
+                c->SetNeedsFocusRect( true );
+        }
+        else
+        {
+            // use native border
+            c->SetNeedsFrame(false);
+        }
     }
     }
-    c->SetNeedsFocusRect( true );
 
     return c;
 }
 
     return c;
 }