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>
27 #include <gtkmathview.h>
30 #include "persist-file.h"
31 #include "control-factory.h"
33 static BonoboObjectClass *gtk_math_view_persist_file_parent_class;
35 static void load_implementation(PortableServer_Servant servant,const gchar *path,
36 CORBA_Environment *ev);
38 static void save_implementation(PortableServer_Servant servant,const gchar *path,
39 CORBA_Environment *ev);
41 static void finalize(GObject *object)
43 GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object);
47 g_object_unref(file->math_view);
48 file->math_view = NULL;
51 G_OBJECT_CLASS(gtk_math_view_persist_file_parent_class)->finalize (object);
54 static Bonobo_Persist_ContentTypeList *
55 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
57 return bonobo_persist_generate_content_types(3, "application/mathml+xml", "text/mathml", "text/plain");
61 gtk_math_view_persist_file_class_init(GtkMathViewPersistFileClass *klass)
63 GObjectClass *object_class = G_OBJECT_CLASS(klass);
64 BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
65 POA_Bonobo_PersistFile__epv *epv = &klass->epv;
67 gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
69 epv->load = load_implementation;
70 epv->save = save_implementation;
72 object_class->finalize = finalize;
73 persist_class->get_content_types = get_content_types;
77 gtk_math_view_persist_file_get_type(void)
79 static GType type = 0;
85 sizeof(GtkMathViewPersistFileClass),
87 (GBaseFinalizeFunc) NULL,
88 (GClassInitFunc) gtk_math_view_persist_file_class_init,
89 NULL, /* class finalize */
90 NULL, /* class_data */
91 sizeof(GtkMathViewPersistFile),
93 (GInstanceInitFunc) NULL
96 type = bonobo_type_unique(BONOBO_TYPE_PERSIST,
97 POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
98 G_STRUCT_OFFSET(GtkMathViewPersistFileClass, epv),
99 &info,"GtkMathViewPresistFile");
106 gtk_math_view_persist_file_new(GtkMathView *math_view)
110 file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
111 bonobo_persist_construct(BONOBO_PERSIST(file),CONTROL_FACTORY_ID);
113 g_object_ref(math_view);
114 GTK_MATH_VIEW_PERSIST_FILE(file)->math_view = math_view;
120 load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
123 GtkMathViewPersistFile* file = GTK_MATH_VIEW_PERSIST_FILE(bonobo_object_from_servant(servant));
124 //fd = open(path, O_RDONLY);
126 result = gtk_math_view_load_uri(file->math_view,path);
128 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
130 bonobo_object_unref(BONOBO_OBJECT(file));
134 save_implementation(PortableServer_Servant servant,
136 CORBA_Environment *ev)
138 bonobo_exception_set(ev,"save_exception");
139 bonobo_exception_add_handler_str("save_exception",
140 "Save option is not valid");