From f75aa5fdb455b324d62b67ec9c51c98b795dbf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Wilmet?= Date: Wed, 12 Jun 2013 13:27:17 +0200 Subject: [PATCH] GtkTextView: add create_buffer virtual method pointer This allows subclasses of GtkTextView that require a corresponding subclass of GtkTextBuffer to automatically do the right thing when constructed with a NULL buffer. An example of this is GtkSourceView which requires a GtkSourceBuffer. https://bugzilla.gnome.org/show_bug.cgi?id=708584 --- gtk/gtktextview.c | 11 ++++++++++- gtk/gtktextview.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 75d0d970f5..e34e2b3309 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -357,6 +357,8 @@ static void gtk_text_view_select_all (GtkWidget *widget, gboolean select); static gboolean get_middle_click_paste (GtkTextView *text_view); +static GtkTextBuffer* gtk_text_view_create_buffer (GtkTextView *text_view); + /* Source side drag signals */ static void gtk_text_view_drag_begin (GtkWidget *widget, GdkDragContext *context); @@ -688,6 +690,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass) klass->copy_clipboard = gtk_text_view_copy_clipboard; klass->paste_clipboard = gtk_text_view_paste_clipboard; klass->toggle_overwrite = gtk_text_view_toggle_overwrite; + klass->create_buffer = gtk_text_view_create_buffer; /* * Properties @@ -1715,13 +1718,19 @@ gtk_text_view_set_buffer (GtkTextView *text_view, gtk_text_view_invalidate (text_view); } +static GtkTextBuffer* +gtk_text_view_create_buffer (GtkTextView *text_view) +{ + return gtk_text_buffer_new (NULL); +} + static GtkTextBuffer* get_buffer (GtkTextView *text_view) { if (text_view->priv->buffer == NULL) { GtkTextBuffer *b; - b = gtk_text_buffer_new (NULL); + b = GTK_TEXT_VIEW_GET_CLASS (text_view)->create_buffer (text_view); gtk_text_view_set_buffer (text_view, b); g_object_unref (b); } diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h index e77c1c472e..4feef3cfe5 100644 --- a/gtk/gtktextview.h +++ b/gtk/gtktextview.h @@ -106,6 +106,8 @@ struct _GtkTextViewClass /* overwrite */ void (* toggle_overwrite) (GtkTextView *text_view); + GtkTextBuffer * (* create_buffer) (GtkTextView *text_view); + /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); @@ -114,7 +116,6 @@ struct _GtkTextViewClass void (*_gtk_reserved5) (void); void (*_gtk_reserved6) (void); void (*_gtk_reserved7) (void); - void (*_gtk_reserved8) (void); }; GDK_AVAILABLE_IN_ALL