1 /*
2 * glade-gtk-text-view.c - GladeWidgetAdaptor for GtkTextView
3 *
4 * Copyright (C) 2013 Tristan Van Berkom
5 *
6 * Authors:
7 * Tristan Van Berkom <tristan.van.berkom@gmail.com>
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23
24 #include <config.h>
25 #include <glib/gi18n-lib.h>
26 #include <gladeui/glade.h>
27
28 #include "glade-text-view-editor.h"
29
30 GladeEditable *
glade_gtk_text_view_create_editable(GladeWidgetAdaptor * adaptor,GladeEditorPageType type)31 glade_gtk_text_view_create_editable (GladeWidgetAdaptor * adaptor,
32 GladeEditorPageType type)
33 {
34 if (type == GLADE_PAGE_GENERAL)
35 {
36 return (GladeEditable *)glade_text_view_editor_new ();
37 }
38
39 return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
40 }
41
42 static gboolean
glade_gtk_text_view_stop_double_click(GtkWidget * widget,GdkEventButton * event,gpointer user_data)43 glade_gtk_text_view_stop_double_click (GtkWidget * widget,
44 GdkEventButton * event,
45 gpointer user_data)
46 {
47 /* Return True if the event is double or triple click */
48 return (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS);
49 }
50
51 void
glade_gtk_text_view_post_create(GladeWidgetAdaptor * adaptor,GObject * object,GladeCreateReason reason)52 glade_gtk_text_view_post_create (GladeWidgetAdaptor * adaptor,
53 GObject * object, GladeCreateReason reason)
54 {
55 /* This makes gtk_text_view_set_buffer() stop complaing */
56 gtk_drag_dest_set (GTK_WIDGET (object), 0, NULL, 0, 0);
57
58 /* Glade hangs when a TextView gets a double click. So we stop them */
59 g_signal_connect (object, "button-press-event",
60 G_CALLBACK (glade_gtk_text_view_stop_double_click), NULL);
61 }
62
63 void
glade_gtk_text_view_set_property(GladeWidgetAdaptor * adaptor,GObject * object,const gchar * property_name,const GValue * value)64 glade_gtk_text_view_set_property (GladeWidgetAdaptor * adaptor,
65 GObject * object,
66 const gchar * property_name,
67 const GValue * value)
68 {
69 if (strcmp (property_name, "buffer") == 0)
70 {
71 if (!g_value_get_object (value))
72 return;
73 }
74
75 GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor,
76 object,
77 property_name, value);
78 }
79