]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/textctrl.cpp
use WXDLLIMPEXP_ADV on the base class too
[wxWidgets.git] / src / gtk / textctrl.cpp
index a16a86876f9cedcb79dfee0c984bae52c9cfdeba..8a2cd7bffe1eeaf6de5f5d0938684722a08df863 100644 (file)
@@ -16,7 +16,6 @@
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/utils.h"
-    #include "wx/panel.h"
     #include "wx/settings.h"
     #include "wx/math.h"
 #endif
@@ -29,7 +28,6 @@
 #include <ctype.h>
 
 #include "wx/gtk/private.h"
-#include <gdk/gdkkeysyms.h>
 
 // ----------------------------------------------------------------------------
 // helpers
@@ -54,7 +52,8 @@ static void wxGtkOnRemoveTag(GtkTextBuffer *buffer,
 }
 
 extern "C" {
-static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer,
+static void wxGtkTextApplyTagsFromAttr(GtkWidget *text,
+                                       GtkTextBuffer *text_buffer,
                                        const wxTextAttr& attr,
                                        GtkTextIter *start,
                                        GtkTextIter *end)
@@ -157,6 +156,109 @@ static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer,
                                               "justification", align, NULL );
         gtk_text_buffer_apply_tag( text_buffer, tag, &para_start, &para_end );
     }
+
+    if (attr.HasLeftIndent())
+    {
+        // Indentation attribute
+
+        // Clear old indentation tags
+        GtkTextIter para_start, para_end = *end;
+        gtk_text_buffer_get_iter_at_line( text_buffer,
+                                          &para_start,
+                                          gtk_text_iter_get_line(start) );
+        gtk_text_iter_forward_line(&para_end);
+
+        remove_handler_id = g_signal_connect (text_buffer, "remove_tag",
+                                              G_CALLBACK(wxGtkOnRemoveTag),
+                                              gpointer("WXINDENT"));
+        gtk_text_buffer_remove_all_tags( text_buffer, &para_start, &para_end );
+        g_signal_handler_disconnect (text_buffer, remove_handler_id);
+
+        // Convert indent from 1/10th of a mm into pixels
+        float factor;
+#if GTK_CHECK_VERSION(2,2,0)
+        if (!gtk_check_version(2,2,0))
+            factor = (float)gdk_screen_get_width(gtk_widget_get_screen(text)) /
+                      gdk_screen_get_width_mm(gtk_widget_get_screen(text)) / 10;
+        else
+#endif
+            factor = (float)gdk_screen_width() / gdk_screen_width_mm() / 10;
+
+        const int indent = (int)(factor * attr.GetLeftIndent());
+        const int subIndent = (int)(factor * attr.GetLeftSubIndent());
+
+        gint gindent;
+        gint gsubindent;
+
+        if (subIndent >= 0)
+        {
+            gindent = indent;
+            gsubindent = -subIndent;
+        }
+        else
+        {
+            gindent = -subIndent;
+            gsubindent = indent;
+        }
+
+        g_snprintf(buf, sizeof(buf), "WXINDENT %d %d", gindent, gsubindent);
+        tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
+                                        buf );
+        if (!tag)
+            tag = gtk_text_buffer_create_tag( text_buffer, buf,
+                                              "left-margin", gindent, "indent", gsubindent, NULL );
+        gtk_text_buffer_apply_tag (text_buffer, tag, &para_start, &para_end);
+    }
+
+    if (attr.HasTabs())
+    {
+        // Set tab stops
+
+        // Clear old tabs
+        GtkTextIter para_start, para_end = *end;
+        gtk_text_buffer_get_iter_at_line( text_buffer,
+                                          &para_start,
+                                          gtk_text_iter_get_line(start) );
+        gtk_text_iter_forward_line(&para_end);
+
+        remove_handler_id = g_signal_connect (text_buffer, "remove_tag",
+                                              G_CALLBACK(wxGtkOnRemoveTag),
+                                              gpointer("WXTABS"));
+        gtk_text_buffer_remove_all_tags( text_buffer, &para_start, &para_end );
+        g_signal_handler_disconnect (text_buffer, remove_handler_id);
+
+        const wxArrayInt& tabs = attr.GetTabs();
+
+        wxString tagname = _T("WXTABS");
+        g_snprintf(buf, sizeof(buf), "WXTABS");
+        for (size_t i = 0; i < tabs.GetCount(); i++)
+            tagname += wxString::Format(_T(" %d"), tabs[i]);
+
+        const wxWX2MBbuf buf = tagname.mb_str(wxConvUTF8);
+
+        tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
+                                        buf );
+        if (!tag)
+        {
+            // Factor to convert from 1/10th of a mm into pixels
+            float factor;
+#if GTK_CHECK_VERSION(2,2,0)
+            if (!gtk_check_version(2,2,0))
+                factor = (float)gdk_screen_get_width(gtk_widget_get_screen(text)) /
+                          gdk_screen_get_width_mm(gtk_widget_get_screen(text)) / 10;
+            else
+#endif
+                factor = (float)gdk_screen_width() / gdk_screen_width_mm() / 10;
+
+            PangoTabArray* tabArray = pango_tab_array_new(tabs.GetCount(), TRUE);
+            for (size_t i = 0; i < tabs.GetCount(); i++)
+                pango_tab_array_set_tab(tabArray, i, PANGO_TAB_LEFT, (gint)(tabs[i] * factor));
+            tag = gtk_text_buffer_create_tag( text_buffer, buf,
+                                              "tabs", tabArray, NULL );
+            pango_tab_array_free(tabArray);
+        }
+        gtk_text_buffer_apply_tag (text_buffer, tag, &para_start, &para_end);
+    }
 }
 }
 
@@ -177,7 +279,7 @@ static void wxGtkTextInsert(GtkWidget *text,
 
     gtk_text_buffer_get_iter_at_offset (text_buffer, &start, start_offset);
 
-    wxGtkTextApplyTagsFromAttr(text_buffer, attr, &start, &iter);
+    wxGtkTextApplyTagsFromAttr(text, text_buffer, attr, &start, &iter);
 }
 }
 
@@ -448,9 +550,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
     if ( win->MarkDirtyOnChange() )
         win->MarkDirty();
 
-    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
-    event.SetEventObject( win );
-    win->GetEventHandler()->ProcessEvent( event );
+    win->SendTextUpdatedEvent();
 }
 }
 
@@ -867,6 +967,12 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags )
         gtk_entry_set_text( GTK_ENTRY(m_text), buffer );
     }
 
+    // if, for whatever reason, the callback wasn't called the expected number
+    // of times, still reset the flags to the default values
+    m_dontMarkDirty = false;
+    m_countUpdatesToIgnore = 0;
+
+
     // GRG, Jun/2000: Changed this after a lot of discussion in
     //   the lists. wxWidgets 2.2 will have a set of flags to
     //   customize this behaviour.
@@ -1653,7 +1759,7 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
         // colours for the others
         wxTextAttr attr = wxTextAttr::Combine(style, m_defaultStyle, this);
 
-        wxGtkTextApplyTagsFromAttr( m_buffer, attr, &starti, &endi );
+        wxGtkTextApplyTagsFromAttr( m_widget, m_buffer, attr, &starti, &endi );
 
         return true;
     }
@@ -1744,7 +1850,10 @@ void wxTextCtrl::Freeze()
                               G_CALLBACK (gtk_text_exposed_callback), this);
             gtk_widget_set_sensitive(m_widget, false);
             g_object_ref(m_buffer);
-            gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), gtk_text_buffer_new(NULL));
+            GtkTextBuffer* buf_new = gtk_text_buffer_new(NULL);
+            gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), buf_new);
+            // gtk_text_view_set_buffer adds its own reference
+            g_object_unref(buf_new);
         }
     }
 }