]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/textctrl.mm
fix positioning bug with window disabler and hidden windows
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
index 6106bedc702ff6c885de5bf3b81ed5278c548fbd..7aa04cf34f564ec7b37789fa72397d0ce57a1c31 100644 (file)
@@ -52,6 +52,8 @@
 @interface NSView(EditableView)
 - (BOOL)isEditable;
 - (void)setEditable:(BOOL)flag;
+- (BOOL)isSelectable;
+- (void)setSelectable:(BOOL)flag;
 @end
 
 class wxMacEditHelper
@@ -60,10 +62,11 @@ public :
     wxMacEditHelper( NSView* textView )
     {
         m_textView = textView;
-        m_formerState = YES;
+        m_formerEditable = YES;
         if ( textView )
         {
-            m_formerState = [textView isEditable];
+            m_formerEditable = [textView isEditable];
+            m_formerSelectable = [textView isSelectable];
             [textView setEditable:YES];
         }
     }
@@ -71,11 +74,15 @@ public :
     ~wxMacEditHelper()
     {
         if ( m_textView )
-            [m_textView setEditable:m_formerState];
+        {
+            [m_textView setEditable:m_formerEditable];
+            [m_textView setSelectable:m_formerSelectable];
+        }
     }
 
 protected :
-    BOOL m_formerState ;
+    BOOL m_formerEditable ;
+    BOOL m_formerSelectable;
     NSView* m_textView;
 } ;
 
@@ -192,6 +199,35 @@ protected :
         impl->controlTextDidChange();
 }
 
+- (void) setEnabled:(BOOL) flag
+{
+    // from Technical Q&A QA1461
+    if (flag) {
+        [self setTextColor: [NSColor controlTextColor]];
+
+    } else {
+        [self setTextColor: [NSColor disabledControlTextColor]];
+    }
+
+    [self setSelectable: flag];
+    [self setEditable: flag];
+}
+
+- (BOOL) isEnabled
+{
+    return [self isEditable];
+}
+
+- (void)textDidEndEditing:(NSNotification *)aNotification
+{
+    wxUnusedVar(aNotification);
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if ( impl )
+    {
+        impl->DoNotifyFocusEvent( false, NULL );
+    }
+}
+
 @end
 
 @implementation wxNSTextField
@@ -684,6 +720,13 @@ void wxNSTextFieldControl::controlAction(WXWidget WXUNUSED(slf),
     }
 }
 
+bool wxNSTextFieldControl::SetHint(const wxString& hint)
+{
+    wxCFStringRef hintstring(hint);
+    [[m_textField cell] setPlaceholderString:hintstring.AsNSString()];
+    return true;
+}
+
 //
 //
 //
@@ -731,6 +774,7 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
 
         c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
     }
+    c->SetNeedsFocusRect( true );
 
     return c;
 }