]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/textctrl.cpp
fix for discrepancies between wxNotebookEvent and wxNotebook GetSelection() results
[wxWidgets.git] / src / gtk / textctrl.cpp
index ee8855a367b89d9ab58c46b6e83dcfeea1639df5..2ed849a9955165105b75675240ec595f3eb19226 100644 (file)
@@ -327,10 +327,6 @@ bool wxTextCtrl::Create( wxWindow *parent,
     if (multi_line)
         gtk_widget_show(m_text);
 
-    /* we want to be notified about text changes */
-    gtk_signal_connect( GTK_OBJECT(m_text), "changed",
-      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
-
     if (multi_line)
     {
         gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
@@ -393,7 +389,13 @@ bool wxTextCtrl::Create( wxWindow *parent,
             gtk_text_set_editable( GTK_TEXT(m_text), 1 );
     }
 
-    SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) );
+    /* we want to be notified about text changes */
+    gtk_signal_connect( GTK_OBJECT(m_text), "changed",
+      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
+
+    /* we don't set a valid background colour, because the window
+       manager should use a default one */
+    m_backgroundColour = wxColour();
     SetForegroundColour( parent->GetForegroundColour() );
 
     m_cursor = wxCursor( wxCURSOR_IBEAM );
@@ -524,14 +526,14 @@ void wxTextCtrl::AppendText( const wxString &text )
     if (m_windowStyle & wxTE_MULTILINE)
     {
         bool hasSpecialAttributes = m_font.Ok() ||
-                                    m_foregroundColour.Ok() ||
-                                    m_backgroundColour.Ok();
+                                   m_foregroundColour.Ok();
         if ( hasSpecialAttributes )
         {
              gtk_text_insert( GTK_TEXT(m_text),
                               m_font.GetInternalFont(),
                               m_foregroundColour.GetColor(),
-                              m_backgroundColour.GetColor(),
+                              m_backgroundColour.Ok() ?
+                                m_backgroundColour.GetColor(): NULL,
                               text.mbc_str(), text.length());
 
         }
@@ -754,6 +756,7 @@ bool wxTextCtrl::Enable( bool enable )
     if (m_windowStyle & wxTE_MULTILINE)
     {
         gtk_text_set_editable( GTK_TEXT(m_text), enable );
+        OnParentEnable(enable);
     }
     else
     {
@@ -763,6 +766,26 @@ bool wxTextCtrl::Enable( bool enable )
     return TRUE;
 }
 
+// wxGTK-specific: called recursively by Enable,
+// to give widgets an oppprtunity to correct their colours after they
+// have been changed by Enable
+void wxTextCtrl::OnParentEnable( bool enable )
+{
+    // If we have a custom background colour, we use this colour in both
+    // disabled and enabled mode, or we end up with a different colour under the
+    // text.
+    wxColour oldColour = GetBackgroundColour();
+    if (oldColour.Ok())
+    {
+        // Need to set twice or it'll optimize the useful stuff out
+        if (oldColour == * wxWHITE)
+            SetBackgroundColour(*wxBLACK);
+        else
+            SetBackgroundColour(*wxWHITE);
+        SetBackgroundColour(oldColour);
+    }
+}
+
 void wxTextCtrl::DiscardEdits()
 {
     m_modified = FALSE;
@@ -916,20 +939,34 @@ bool wxTextCtrl::CanRedo() const
 
 // If the return values from and to are the same, there is no
 // selection.
-void wxTextCtrl::GetSelection(long* from, long* to) const
+void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
 {
     wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
 
-    if (!(GTK_EDITABLE(m_text)->has_selection))
+    long from, to;
+    if ( !(GTK_EDITABLE(m_text)->has_selection) )
     {
-        long i = GetInsertionPoint();
-        if (from) *from = i;
-        if (to)   *to = i;
-        return;
+        from =
+        to = GetInsertionPoint();
+    }
+    else // got selection
+    {
+        from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
+        to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+
+        if ( from > to )
+        {
+            // exchange them to be compatible with wxMSW
+            long tmp = from;
+            from = to;
+            to = tmp;
+        }
     }
 
-    if (from) *from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
-    if (to)   *to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+    if ( fromOut )
+        *fromOut = from;
+    if ( toOut )
+        *toOut = to;
 }
 
 bool wxTextCtrl::IsEditable() const