1 /* 2 * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org> 3 * Copyright (C) 2010 David King <davidk@openismus.com> 4 * Copyright (C) 2011 Murray Cumming <murrayc@murrayc.com> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 21 #include <string.h> 22 #include <glib/gi18n-lib.h> 23 #include "dummy-perspective.h" 24 25 /* 26 * Main static functions 27 */ 28 static void dummy_perspective_class_init (DummyPerspectiveClass *klass); 29 static void dummy_perspective_init (DummyPerspective *pers); 30 static void dummy_perspective_dispose (GObject *object); 31 32 /* BrowserPerspective interface */ 33 static void dummy_perspective_perspective_init (BrowserPerspectiveIface *iface); 34 static BrowserWindow *dummy_perspective_get_window (BrowserPerspective *perspective); 35 static GtkActionGroup *dummy_perspective_get_actions_group (BrowserPerspective *perspective); 36 static const gchar *dummy_perspective_get_actions_ui (BrowserPerspective *perspective); 37 /* get a pointer to the parents to be able to call their destructor */ 38 static GObjectClass *parent_class = NULL; 39 40 41 GType 42 dummy_perspective_get_type (void) 43 { browser_canvas_util_compute_anchor_shapes(GooCanvasItem * parent,GSList * shapes,BrowserCanvasTable * fk_ent,BrowserCanvasTable * ref_pk_ent,guint nb_anchors,guint ext,gboolean with_handle)44 static GType type = 0; 45 46 if (G_UNLIKELY (type == 0)) { 47 static GMutex registering; 48 static const GTypeInfo info = { 49 sizeof (DummyPerspectiveClass), 50 (GBaseInitFunc) NULL, 51 (GBaseFinalizeFunc) NULL, 52 (GClassInitFunc) dummy_perspective_class_init, 53 NULL, 54 NULL, 55 sizeof (DummyPerspective), 56 0, 57 (GInstanceInitFunc) dummy_perspective_init, 58 0 59 }; 60 61 static GInterfaceInfo perspective_info = { 62 (GInterfaceInitFunc) dummy_perspective_perspective_init, 63 NULL, 64 NULL 65 }; 66 67 g_mutex_lock (®istering); 68 if (type == 0) { 69 type = g_type_register_static (GTK_TYPE_BOX, "DummyPerspective", &info, 0); 70 g_type_add_interface_static (type, BROWSER_PERSPECTIVE_TYPE, &perspective_info); 71 } 72 g_mutex_unlock (®istering); 73 } 74 return type; 75 } 76 77 static void 78 dummy_perspective_class_init (DummyPerspectiveClass * klass) 79 { 80 GObjectClass *object_class = G_OBJECT_CLASS (klass); 81 parent_class = g_type_class_peek_parent (klass); 82 83 object_class->dispose = dummy_perspective_dispose; 84 } 85 86 static void 87 dummy_perspective_perspective_init (BrowserPerspectiveIface *iface) 88 { 89 iface->i_get_window = dummy_perspective_get_window; 90 iface->i_get_actions_group = dummy_perspective_get_actions_group; 91 iface->i_get_actions_ui = dummy_perspective_get_actions_ui; 92 } 93 94 95 static void 96 dummy_perspective_init (DummyPerspective *perspective) 97 { 98 GtkWidget *wid; 99 100 gtk_orientable_set_orientation (GTK_ORIENTABLE (perspective), GTK_ORIENTATION_VERTICAL); 101 102 wid = gtk_label_new (""); 103 gtk_label_set_markup (GTK_LABEL (wid), 104 "<big><b>Dummy perspective</b></big>\n" 105 "Use this as a starting point for your own perspective..."); 106 gtk_box_pack_start (GTK_BOX (perspective), wid, TRUE, TRUE, 0); 107 gtk_widget_show (wid); 108 } 109 110 /** 111 * dummy_perspective_new 112 * 113 * Creates new #BrowserPerspective widget which 114 */ 115 BrowserPerspective * 116 dummy_perspective_new (G_GNUC_UNUSED BrowserWindow *bwin) 117 { 118 BrowserPerspective *bpers; 119 bpers = (BrowserPerspective*) g_object_new (TYPE_DUMMY_PERSPECTIVE, NULL); 120 121 /* if there is a notebook to store pages, use: 122 browser_perspective_declare_notebook (bpers, GTK_NOTEBOOK (perspective->priv->notebook)); 123 */ 124 125 return bpers; 126 } 127 128 129 static void 130 dummy_perspective_dispose (GObject *object) 131 { 132 DummyPerspective *perspective; 133 134 g_return_if_fail (object != NULL); 135 g_return_if_fail (IS_DUMMY_PERSPECTIVE (object)); 136 137 perspective = DUMMY_PERSPECTIVE (object); 138 browser_perspective_declare_notebook ((BrowserPerspective*) perspective, NULL); 139 140 /* parent class */ 141 parent_class->dispose (object); 142 } 143 144 static void 145 dummy_add_cb (G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED BrowserPerspective *bpers) 146 { 147 g_print ("Add something...\n"); 148 } 149 150 static void 151 dummy_list_cb (G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED BrowserPerspective *bpers) 152 { 153 g_print ("List something...\n"); 154 } 155 156 static GtkActionEntry ui_actions[] = { 157 { "DummyMenu", NULL, "_Dummy", NULL, "DummyMenu", NULL }, 158 { "DummyItem1", GTK_STOCK_ADD, "_Dummy Add", NULL, "Add something", 159 G_CALLBACK (dummy_add_cb)}, 160 { "DummyItem2", GTK_STOCK_REMOVE, "_Dummy List", NULL, "List something", 161 G_CALLBACK (dummy_list_cb)}, 162 }; 163 164 static const gchar *ui_actions_info = 165 "<ui>" 166 " <menubar name='MenuBar'>" 167 " <placeholder name='MenuExtension'>" 168 " <menu name='Dummy' action='DummyMenu'>" 169 " <menuitem name='DummyItem1' action= 'DummyItem1'/>" 170 " <menuitem name='DummyItem2' action= 'DummyItem2'/>" 171 " </menu>" 172 " </placeholder>" 173 " </menubar>" 174 " <toolbar name='ToolBar'>" 175 " <separator/>" 176 " <toolitem action='DummyItem1'/>" 177 " <toolitem action='DummyItem2'/>" 178 " </toolbar>" 179 "</ui>"; 180 181 static GtkActionGroup * 182 dummy_perspective_get_actions_group (BrowserPerspective *bpers) 183 { 184 GtkActionGroup *agroup; 185 agroup = gtk_action_group_new ("DummyActions"); 186 gtk_action_group_set_translation_domain (agroup, GETTEXT_PACKAGE); 187 gtk_action_group_add_actions (agroup, ui_actions, G_N_ELEMENTS (ui_actions), bpers); 188 189 return agroup; 190 } 191 192 static const gchar * 193 dummy_perspective_get_actions_ui (G_GNUC_UNUSED BrowserPerspective *bpers) 194 { 195 return ui_actions_info; 196 } 197 198 static BrowserWindow * 199 dummy_perspective_get_window (BrowserPerspective *perspective) 200 { 201 DummyPerspective *bpers; 202 bpers = DUMMY_PERSPECTIVE (perspective); 203 return NULL;/*bpers->priv->bwin;*/ 204 } 205