1 /* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView.
2 * Copyright (C) 2003 Luca Padovani <lpadovan@cs.unibo.it>
3 * Pouria Masoudi <pmasoudi@cs.unibo.it>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * For more information, please visit the project's home page
20 * http://helm.cs.unibo.it/gtkmathview-bonobo
21 * or send an email to <lpadovan@cs.unibo.it>
28 #include "control-data.h"
30 GtkMathViewControlData*
31 gtk_math_view_control_data_new(BonoboControl* control, GtkMathView *math_view)
33 GtkMathViewControlData *cd = g_new(GtkMathViewControlData,1);
34 cd->control = control; /* we don't ref the control this is a weak pointer */
35 cd->math_view = math_view;
36 gtk_widget_ref(GTK_WIDGET(math_view));
37 cd->item_factory = NULL;
38 cd->semantic_selection = FALSE;
39 cd->first_selected = NULL;
40 cd->root_selected = NULL;
41 cd->id_ns_uri = gdome_str_mkref("http://www.cs.unibo.it/helm");
42 cd->id_name = gdome_str_mkref("xref");
48 gtk_math_view_control_data_destroy(GtkMathViewControlData* cd)
50 GdomeException exc = 0;
51 cd->control = NULL; /* don't unref the control, see above */
52 gtk_widget_unref(GTK_WIDGET(cd->math_view));
54 if (cd->item_factory != NULL)
56 gtk_object_unref(cd->item_factory);
57 cd->item_factory = NULL;
59 if (cd->first_selected != NULL)
61 gdome_el_unref(cd->first_selected, &exc);
63 cd->first_selected = NULL;
65 if (cd->root_selected != NULL)
67 gdome_el_unref(cd->root_selected, &exc);
69 cd->root_selected = NULL;
71 if (cd->id_ns_uri != NULL)
73 gdome_str_unref(cd->id_ns_uri);
76 if (cd->id_name != NULL)
78 gdome_str_unref(cd->id_name);
85 gtk_math_view_control_data_get_id_ns_uri(GtkMathViewControlData* cd)
87 g_return_val_if_fail(cd != NULL, NULL);
88 return (cd->id_ns_uri != NULL) ? g_strdup(cd->id_ns_uri->str) : NULL;
92 gtk_math_view_control_data_set_id_ns_uri(GtkMathViewControlData* cd, const gchar* ns_uri)
94 g_return_if_fail(cd != NULL);
95 if (cd->id_ns_uri != NULL) gdome_str_unref(cd->id_ns_uri);
96 cd->id_ns_uri = (ns_uri != NULL) ? gdome_str_mkref_dup(ns_uri) : NULL;
100 gtk_math_view_control_data_get_id_name(GtkMathViewControlData* cd)
102 g_return_val_if_fail(cd != NULL, NULL);
103 return (cd->id_name != NULL) ? g_strdup(cd->id_name->str) : NULL;
107 gtk_math_view_control_data_set_id_name(GtkMathViewControlData* cd, const gchar* name)
109 g_return_if_fail(cd != NULL);
110 if (cd->id_name != NULL) gdome_str_unref(cd->id_name);
111 cd->id_name = (name != NULL) ? gdome_str_mkref_dup(name) : NULL;
115 gtk_math_view_control_data_set_root_selected(GtkMathViewControlData* cd, GdomeElement* elem)
117 g_return_if_fail(cd != NULL);
118 GdomeException exc = 0;
120 gtk_math_view_freeze(cd->math_view);
122 if (cd->root_selected != NULL)
124 gtk_math_view_unselect(cd->math_view, cd->root_selected);
125 gdome_el_unref(cd->root_selected, &exc);
129 cd->root_selected = elem;
130 if (cd->root_selected != NULL)
132 gdome_el_ref(cd->root_selected, &exc);
134 gtk_math_view_select(cd->math_view, cd->root_selected);
137 gtk_math_view_thaw(cd->math_view);