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
This commit is contained in:
Sébastien Wilmet 2013-06-12 13:27:17 +02:00
parent cb867d88bb
commit f75aa5fdb4
2 changed files with 12 additions and 2 deletions

View File

@ -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);
}

View File

@ -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