9 #include "control-factory.h"
11 static GtkWidget *control;
13 struct FileSelectionInfo {
14 BonoboWidget* control;
18 static struct FileSelectionInfo file_selection_info = { NULL, NULL };
21 load_through_persist_file (const gchar *filename,
22 Bonobo_PersistFile pfile)
25 CORBA_exception_init (&ev);
26 Bonobo_PersistFile_load (pfile, filename, &ev);
27 if (ev._major != CORBA_NO_EXCEPTION)
28 g_warning ("Cannot load.");
29 CORBA_exception_free (&ev);
33 file_selection_ok_cb (GtkWidget *widget,
36 CORBA_Object interface;
37 const gchar *interface_name;
40 interface_name = "IDL:Bonobo/PersistFile:1.0";
42 CORBA_exception_init (&ev);
43 interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (file_selection_info.control),
45 CORBA_exception_free (&ev);
47 if (interface == CORBA_OBJECT_NIL)
49 g_warning ("The Control does not seem to support `%s'.", interface_name);
53 const gchar *fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selection_info.widget));
54 load_through_persist_file (fname, interface);
57 gtk_widget_destroy (file_selection_info.widget);
61 file_selection_destroy_cb (GtkWidget *widget,
64 file_selection_info.widget = NULL;
68 open_dialog (BonoboWindow *app)
71 BonoboWidget *control;
73 control = BONOBO_WIDGET (bonobo_window_get_contents (app));
75 if (file_selection_info.widget != NULL) {
76 gdk_window_show (GTK_WIDGET (file_selection_info.widget)->window);
80 widget = gtk_file_selection_new (_("Open file..."));
82 gtk_window_set_transient_for (GTK_WINDOW (widget),
85 file_selection_info.widget = widget;
86 file_selection_info.control = control;
88 g_signal_connect_object (GTK_FILE_SELECTION (widget)->cancel_button,
89 "clicked", G_CALLBACK (gtk_widget_destroy), widget, G_CONNECT_AFTER);
90 g_signal_connect (GTK_FILE_SELECTION (widget)->ok_button, "clicked", G_CALLBACK (file_selection_ok_cb), NULL);
91 g_signal_connect (file_selection_info.widget, "destroy", G_CALLBACK (file_selection_destroy_cb), NULL);
93 gtk_widget_show (file_selection_info.widget);
96 /* "Open through persist file" dialog. */
98 open_through_persist_file_cb (GtkWidget *widget,
101 open_dialog (BONOBO_WINDOW (data));
105 exit_cb (GtkWidget *widget,
108 gtk_widget_destroy (GTK_WIDGET (data));
112 static BonoboUIVerb verbs [] = {
113 BONOBO_UI_UNSAFE_VERB ("OpenFile", open_through_persist_file_cb),
114 BONOBO_UI_UNSAFE_VERB ("FileExit", exit_cb),
119 /* A dirty, non-translatable hack */
123 " <cmd name=\"FileExit\" _label=\"Exit\" _tip=\"Exit the program\""
124 " pixtype=\"stock\" pixname=\"Exit\" accel=\"*Control*q\"/>"
125 " <cmd name=\"FormatHTML\" _label=\"HTML mode\" type=\"toggle\" _tip=\"HTML Format switch\"/>"
128 " <submenu name=\"File\" _label=\"_File\">"
129 " <menuitem name=\"OpenFile\" verb=\"\" _label=\"Open (PersistFile)\" _tip=\"Open using the PersistFile interface\""
130 " pixtype=\"stock\" pixname=\"Open\"/>"
131 " <menuitem name=\"SaveFile\" verb=\"\" _label=\"Save (PersistFile)\" _tip=\"Save using the PersistFile interface\""
132 " pixtype=\"stock\" pixname=\"Save\"/>"
134 " <menuitem name=\"OpenStream\" verb=\"\" _label=\"_Open (PersistStream)\" _tip=\"Open using the PersistStream interface\""
135 " pixtype=\"stock\" pixname=\"Open\"/>"
136 " <menuitem name=\"SaveStream\" verb=\"\" _label=\"_Save (PersistStream)\" _tip=\"Save using the PersistStream interface\""
137 " pixtype=\"stock\" pixname=\"Save\"/>"
138 " <menuitem name=\"SavePlainStream\" verb=\"\" _label=\"Save _plain(PersistStream)\" _tip=\"Save using the PersistStream interface\""
139 " pixtype=\"stock\" pixname=\"Save\"/>"
141 " <menuitem name=\"ViewHTMLSource\" verb=\"\" _label=\"View HTML Source\" _tip=\"View the html source of the current document\"/>"
142 " <menuitem name=\"ViewHTMLSourceHTML\" verb=\"\" _label=\"View HTML Output\" _tip=\"View the html source of the current document as html\"/>"
143 " <menuitem name=\"ViewPlainSource\" verb=\"\" _label=\"View PLAIN Source\" _tip=\"View the plain text source of the current document\"/>"
145 " <menuitem name=\"FileExit\" verb=\"\" _label=\"E_xit\"/>"
147 " <placeholder name=\"Component\"/>"
148 " <submenu name=\"Format\" _label=\"For_mat\">"
149 " <menuitem name=\"FormatHTML\" verb=\"\"/>"
151 " <placeholder name=\"FormatParagraph\"/>"
154 " <dockitem name=\"Toolbar\" behavior=\"exclusive\">"
159 app_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer dummy)
161 gtk_widget_destroy (GTK_WIDGET (widget));
168 container_create (void)
172 BonoboUIComponent *component;
173 BonoboUIContainer *container;
174 CORBA_Environment ev;
176 win = bonobo_window_new ("test-editor",
177 "GtkMathView Control Test");
178 window = GTK_WINDOW (win);
180 container = bonobo_window_get_ui_container (BONOBO_WINDOW (win));
182 g_signal_connect (window, "delete_event", G_CALLBACK (app_delete_cb), NULL);
184 gtk_window_set_default_size (window, 600, 440);
185 gtk_window_set_resizable (window, TRUE);
187 component = bonobo_ui_component_new ("test");
188 bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (component));
190 bonobo_ui_component_set_container (component, BONOBO_OBJREF (container), NULL);
191 bonobo_ui_component_add_verb_list_with_data (component, verbs, win);
192 bonobo_ui_component_set_translate (component, "/", ui, NULL);
194 control = bonobo_widget_new_control (CONTROL_ID, BONOBO_OBJREF (container));
197 g_error ("Cannot get `%s'.", CONTROL_ID);
199 bonobo_window_set_contents (BONOBO_WINDOW (win), control);
201 gtk_widget_show_all (GTK_WIDGET (window));
203 CORBA_exception_init (&ev);
209 load_file (const gchar *fname)
211 CORBA_Object interface;
212 CORBA_Environment ev;
214 printf ("loading: %s\n", fname);
215 CORBA_exception_init (&ev);
216 interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (control)),
217 "IDL:Bonobo/PersistFile:1.0", &ev);
218 CORBA_exception_free (&ev);
219 load_through_persist_file (fname, interface);
225 main (int argc, char **argv)
227 gnome_program_init("test-editor", VERSION, LIBGNOMEUI_MODULE, argc, argv,
228 GNOME_PROGRAM_STANDARD_PROPERTIES,
229 GNOME_PARAM_HUMAN_READABLE_NAME, _("GtkMathView Test Container"),
234 /* We can't make any CORBA calls unless we're in the main loop. So we
235 delay creating the container here. */
236 gtk_idle_add ((GtkFunction) container_create, NULL);
237 if (argc > 1 && *argv [argc - 1] != '-')
238 gtk_idle_add ((GtkFunction) load_file, argv [argc - 1]);
243 return bonobo_ui_debug_shutdown ();