]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/control-data.c
* added popup menu, implemented some functions
[helm.git] / helm / gtkmathview-bonobo / src / control-data.c
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>
4  * 
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.
9  * 
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.
14  * 
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
18  *
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>
22  */
23
24 #include <config.h>
25
26 #include <gdome.h>
27
28 #include "control-data.h"
29
30 GtkMathViewControlData*
31 gtk_math_view_control_data_new(GtkMathView *math_view)
32 {
33   GtkMathViewControlData *cd = g_new(GtkMathViewControlData,1);
34   cd->math_view = math_view;
35   gtk_widget_ref(GTK_WIDGET(math_view));
36   cd->item_factory = NULL;
37   cd->semantic_selection = FALSE;
38   cd->first_selected = NULL;
39   cd->root_selected = NULL;
40   cd->id_ns_uri = gdome_str_mkref("http://www.cs.unibo.it/helm");
41   cd->id_name = gdome_str_mkref("xref");
42   cd->x = cd->y = 0;
43   return cd;
44 }
45
46 void
47 gtk_math_view_control_data_destroy(GtkMathViewControlData* cd)
48 {
49   GdomeException exc = 0;
50   gtk_widget_unref(GTK_WIDGET(cd->math_view));
51   cd->math_view = NULL;
52   if (cd->item_factory != NULL)
53     {
54       gtk_object_unref(cd->item_factory);
55       cd->item_factory = NULL;
56     }
57   if (cd->first_selected != NULL)
58     {
59       gdome_el_unref(cd->first_selected, &exc);
60       g_assert(exc == 0);
61       cd->first_selected = NULL;
62     }
63   if (cd->root_selected != NULL)
64     {
65       gdome_el_unref(cd->root_selected, &exc);
66       g_assert(exc == 0);
67       cd->root_selected = NULL;
68     }
69   if (cd->id_ns_uri != NULL)
70     {
71       gdome_str_unref(cd->id_ns_uri);
72       cd->id_ns_uri = NULL;
73     }
74   if (cd->id_name != NULL)
75     {
76       gdome_str_unref(cd->id_name);
77       cd->id_name = NULL;
78     }
79   g_free(cd);
80 }
81
82 gchar*
83 gtk_math_view_control_data_get_id_ns_uri(GtkMathViewControlData* cd)
84 {
85   g_return_val_if_fail(cd != NULL, NULL);
86   return (cd->id_ns_uri != NULL) ? g_strdup(cd->id_ns_uri->str) : NULL;
87 }
88                                          
89 void
90 gtk_math_view_control_data_set_id_ns_uri(GtkMathViewControlData* cd, const gchar* ns_uri)
91 {
92   g_return_if_fail(cd != NULL);
93   if (cd->id_ns_uri != NULL) gdome_str_unref(cd->id_ns_uri);
94   cd->id_ns_uri = (ns_uri != NULL) ? gdome_str_mkref_dup(ns_uri) : NULL;
95 }
96
97 gchar*
98 gtk_math_view_control_data_get_id_name(GtkMathViewControlData* cd)
99 {
100   g_return_val_if_fail(cd != NULL, NULL);
101   return (cd->id_name != NULL) ? g_strdup(cd->id_name->str) : NULL;
102 }
103                                          
104 void
105 gtk_math_view_control_data_set_id_name(GtkMathViewControlData* cd, const gchar* name)
106 {
107   g_return_if_fail(cd != NULL);
108   if (cd->id_name != NULL) gdome_str_unref(cd->id_name);
109   cd->id_name = (name != NULL) ? gdome_str_mkref_dup(name) : NULL;
110 }
111
112 void
113 gtk_math_view_control_data_set_root_selected(GtkMathViewControlData* cd, GdomeElement* elem)
114 {
115   g_return_if_fail(cd != NULL);
116   GdomeException exc = 0;
117
118   gtk_math_view_freeze(cd->math_view);
119
120   if (cd->root_selected != NULL)
121     {
122       gtk_math_view_unselect(cd->math_view, cd->root_selected);
123       gdome_el_unref(cd->root_selected, &exc);
124       g_assert(exc == 0);
125     }
126
127   cd->root_selected = elem;
128   if (cd->root_selected != NULL)
129     {
130       gdome_el_ref(cd->root_selected, &exc);
131       g_assert(exc == 0);
132       gtk_math_view_select(cd->math_view, cd->root_selected);
133     }
134
135   gtk_math_view_thaw(cd->math_view);
136 }