6 #include "control-factory.h"
7 #include "GtkMathView.h"
9 static GtkWidget *control;
11 typedef enum{LOAD_STREAM,LOAD_FILE,NONE}FileSelectionOp;
13 struct FileSelectionInfo {
14 BonoboWidget* control;
17 FileSelectionOp Operations;
21 static struct FileSelectionInfo file_selection_info = { NULL, NULL,NONE};
24 file_selection_destroy_cb (GtkWidget *widget,gpointer data)
26 file_selection_info.widget = NULL;
31 load_through_persist_file (const gchar *filename,
32 Bonobo_PersistFile pfile)
35 CORBA_exception_init (&ev);
36 Bonobo_PersistFile_load (pfile, filename, &ev);
37 if (ev._major != CORBA_NO_EXCEPTION)
38 g_warning ("Cannot load.");
39 CORBA_exception_free (&ev);
43 load_through_persist_stream(const gchar *filename,
44 Bonobo_PersistStream pstream)
46 BonoboObject *stream = NULL;
48 CORBA_exception_init (&ev);
51 stream = bonobo_stream_open ("fs", filename,
52 Bonobo_Storage_READ, 0);
57 g_warning ("Couldn't load `%s'\n", filename);
59 Bonobo_Stream corba_stream;
60 corba_stream = bonobo_object_corba_objref (stream);
61 Bonobo_Stream_truncate (corba_stream, 0, &ev);
62 Bonobo_PersistStream_load (pstream, corba_stream, "application/mathml+xml", &ev);
64 Bonobo_Unknown_unref (pstream, &ev);
65 CORBA_Object_release (pstream, &ev);
66 CORBA_exception_free (&ev);
70 file_selection_ok_cb (GtkWidget *widget,
73 CORBA_Object interface;
74 const gchar *interface_name;
77 if (file_selection_info.Operations == LOAD_FILE)
78 interface_name = "IDL:Bonobo/PersistFile:1.0";
79 else if(file_selection_info.Operations == LOAD_STREAM)
80 interface_name = "IDL:Bonobo/PersistStream:1.0";
81 else printf("failed to get operation type\n");
83 CORBA_exception_init (&ev);
84 interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (file_selection_info.control),
86 CORBA_exception_free (&ev);
88 if (interface == CORBA_OBJECT_NIL)
90 g_warning ("The Control does not seem to support `%s'.", interface_name);
95 fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selection_info.widget));
96 switch (file_selection_info.Operations) {
98 load_through_persist_stream (fname, interface);
101 load_through_persist_file (fname, interface);
106 gtk_widget_destroy (file_selection_info.widget);
110 open_dialog (BonoboWindow *app,
111 FileSelectionOp operation)
114 BonoboWidget *control;
116 control = BONOBO_WIDGET (bonobo_window_get_contents (app));
118 if (file_selection_info.widget != NULL) {
119 gdk_window_show (GTK_WIDGET (file_selection_info.widget)->window);
123 if(operation == LOAD_STREAM)
124 widget = gtk_file_selection_new(_("Open Stream...."));
125 if(operation == LOAD_FILE)
126 widget = gtk_file_selection_new (_("Open file..."));
128 gtk_window_set_transient_for (GTK_WINDOW (widget),
131 file_selection_info.widget = widget;
132 file_selection_info.control = control;
133 file_selection_info.Operations = operation;
135 g_signal_connect_object (GTK_FILE_SELECTION (widget)->cancel_button,
136 "clicked", G_CALLBACK (gtk_widget_destroy), widget, G_CONNECT_AFTER);
138 g_signal_connect (GTK_FILE_SELECTION (widget)->ok_button, "clicked", G_CALLBACK (file_selection_ok_cb), NULL);
140 g_signal_connect (file_selection_info.widget, "destroy", G_CALLBACK (file_selection_destroy_cb), NULL);
142 gtk_widget_show (file_selection_info.widget);
145 /* "Open through persist file" dialog. */
147 open_through_persist_file_cb (GtkWidget *widget,
150 open_dialog (BONOBO_WINDOW (data), LOAD_FILE);
154 open_through_persist_stream_cb(GtkWidget *widget,
157 open_dialog(BONOBO_WINDOW(data), LOAD_STREAM);
161 test_view(GtkWidget* widget, gpointer data)
163 CORBA_Object interface;
164 CORBA_Environment ev;
166 CORBA_exception_init (&ev);
167 interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (bonobo_window_get_contents (BONOBO_WINDOW(data)))),
168 "IDL:GNOME/GtkMathView/View:1.0", &ev);
169 CORBA_exception_free (&ev);
171 if (interface == CORBA_OBJECT_NIL)
173 g_warning ("The Control does not seem to support `View'.");
176 CORBA_exception_init (&ev);
177 GNOME_GtkMathView_View_freeze(interface, &ev);
178 CORBA_exception_free (&ev);
180 CORBA_exception_init (&ev);
181 GNOME_GtkMathView_View_thaw(interface, &ev);
182 CORBA_exception_free (&ev);
184 CORBA_exception_init (&ev);
185 Bonobo_Unknown_unref (interface, &ev);
186 CORBA_Object_release (interface, &ev);
187 CORBA_exception_free (&ev);
191 exit_cb (GtkWidget *widget,
194 gtk_widget_destroy (GTK_WIDGET (data));
199 get_size(GtkWidget *widget,
203 BonoboWidget* control;
204 BonoboControlFrame* control_frame;
206 Bonobo_PropertyBag prop_bag;
208 control = BONOBO_WIDGET (bonobo_window_get_contents (BONOBO_WINDOW (data)));
209 control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control));
210 prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL);
212 width = bonobo_pbclient_get_long(prop_bag,"width",NULL);
213 height = bonobo_pbclient_get_long(prop_bag,"height",NULL);
215 printf("Width: %d Height: %d\n",width,height);
217 bonobo_object_release_unref (prop_bag,NULL);
222 get_top(GtkWidget *widget,
226 BonoboWidget* control;
227 BonoboControlFrame* control_frame;
228 Bonobo_PropertyBag prop_bag;
230 control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data)));
231 control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control));
232 prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL);
234 top_x = bonobo_pbclient_get_long(prop_bag,"top-x",NULL);
235 top_y = bonobo_pbclient_get_long(prop_bag,"top-y",NULL);
237 printf("Top X: %d ,Top Y: %d\n",top_x,top_y);
239 bonobo_object_release_unref(prop_bag,NULL);
243 get_font_size(GtkWidget *widget,
247 BonoboWidget* control;
248 BonoboControlFrame* control_frame;
249 Bonobo_PropertyBag prop_bag;
251 control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data)));
252 control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control));
253 prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL);
255 font_size = bonobo_pbclient_get_long(prop_bag,"font-size",NULL);
257 printf("FontSize : %d\n",font_size);
259 bonobo_object_release_unref(prop_bag,NULL);
263 get_verbosity(GtkWidget *widget,
267 BonoboWidget* control;
268 BonoboControlFrame* control_frame;
269 Bonobo_PropertyBag prop_bag;
271 control = BONOBO_WIDGET(bonobo_window_get_contents(BONOBO_WINDOW(data)));
272 control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control));
273 prop_bag = bonobo_control_frame_get_control_property_bag(control_frame,NULL);
275 verbosity = bonobo_pbclient_get_long(prop_bag,"verbosity",NULL);
277 printf("Verbosity: %d\n",verbosity);
279 bonobo_object_release_unref(prop_bag,NULL);
282 static BonoboUIVerb verbs [] = {
283 BONOBO_UI_UNSAFE_VERB ("OpenFile", open_through_persist_file_cb),
284 BONOBO_UI_UNSAFE_VERB ("OpenStream", open_through_persist_stream_cb),
285 BONOBO_UI_UNSAFE_VERB ("TestView", test_view),
286 BONOBO_UI_UNSAFE_VERB ("Size", get_size),
287 BONOBO_UI_UNSAFE_VERB ("Top", get_top),
288 BONOBO_UI_UNSAFE_VERB ("Font Size", get_font_size),
289 BONOBO_UI_UNSAFE_VERB ("Verbosity", get_verbosity),
290 BONOBO_UI_UNSAFE_VERB ("FileExit", exit_cb),
294 /* A dirty, non-translatable hack */
298 " <cmd name=\"FileExit\" _label=\"Exit\" _tip=\"Exit the program\""
299 " pixtype=\"stock\" pixname=\"Exit\" accel=\"*Control*q\"/>"
300 " <cmd name=\"FormatHTML\" _label=\"HTML mode\" type=\"toggle\" _tip=\"HTML Format switch\"/>"
303 " <submenu name=\"File\" _label=\"_File\">"
304 " <menuitem name=\"OpenFile\" verb=\"\" _label=\"Open (PersistFile)\" _tip=\"Open using the PersistFile interface\""
305 " pixtype=\"stock\" pixname=\"Open\"/>"
306 " <menuitem name=\"OpenStream\" verb=\"\" _label=\"_Open Stream (PersistStream)\" _tip=\"Open using the PersistStream interface\""
307 " pixtype=\"stock\" pixname=\"Open Stream\"/>"
309 " <menuitem name=\"TestView\" verb=\"\" _label=\"Test View\" _tip=\"Test the View interface\"/>"
311 " <menuitem name=\"FileExit\" verb=\"\" _label=\"E_xit\"/>"
313 " <placeholder name=\"Component\"/>"
314 " <submenu name=\"PropertyBags\" _label=\"Property_Bag\">"
315 " <menuitem name=\"Size\" verb=\"\" _label=\"Size(PropertyBag)\" _tip=\"Get size\""
316 " pixtype=\"stock\" pixname=\"Get Size\"/>"
318 " <menuitem name=\"Top\" verb=\"\" _label=\"Top(PropertyBag)\" _tip=\"Get Top\""
319 " pixtype=\"stock\" pixname=\"Get Top\"/>"
321 " <menuitem name=\"Font Size\" verb=\"\" _label=\"Font Size(PropertyBag)\" _tip=\"Get FontSize\""
322 " pixtype=\"stock\" pixname=\"Get FontSize\"/>"
324 " <menuitem name=\"Verbosity\" verb=\"\" _label=\"Verbosity(PropertyBag)\" _tip=\"Get Verbosity\""
325 " pixtype=\"stock\" pixname=\"Get Verbosity\"/>"
328 " <dockitem name=\"Toolbar\" behavior=\"exclusive\">"
333 app_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer dummy)
335 gtk_widget_destroy (GTK_WIDGET (widget));
342 container_create (void)
346 BonoboUIComponent *component;
347 BonoboUIContainer *container;
348 CORBA_Environment ev;
351 win = bonobo_window_new ("test-editor",
352 "GtkMathView Control Test");
353 window = GTK_WINDOW (win);
355 container = bonobo_window_get_ui_container (BONOBO_WINDOW (win));
357 g_signal_connect (window, "delete_event", G_CALLBACK (app_delete_cb), NULL);
359 gtk_window_set_default_size (window, 600, 440);
360 gtk_window_set_resizable (window, TRUE);
362 component = bonobo_ui_component_new ("test");
363 bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (component));
365 bonobo_ui_component_set_container (component, BONOBO_OBJREF (container), NULL);
366 bonobo_ui_component_add_verb_list_with_data (component, verbs, win);
367 bonobo_ui_component_set_translate (component, "/", ui, NULL);
369 control = bonobo_widget_new_control (CONTROL_ID, BONOBO_OBJREF (container));
372 g_error ("Cannot get `%s'.", CONTROL_ID);
374 bonobo_window_set_contents (BONOBO_WINDOW (win), control);
376 gtk_widget_show_all (GTK_WIDGET (window));
378 CORBA_exception_init (&ev);
384 load_file (const gchar *fname)
386 CORBA_Object interface;
387 CORBA_Environment ev;
389 printf ("loading: %s\n", fname);
390 CORBA_exception_init (&ev);
391 interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (control)),
392 "IDL:Bonobo/PersistFile:1.0", &ev);
393 CORBA_exception_free (&ev);
394 load_through_persist_file (fname, interface);
400 load_file_stream(const gchar *fname)
402 CORBA_Object interface;
403 CORBA_Environment ev;
405 printf("loading with stream %s\n",fname);
406 CORBA_exception_init(&ev);
407 interface = Bonobo_Unknown_queryInterface(bonobo_widget_get_objref(BONOBO_WIDGET(control)),
408 "IDL:Bonobo/PersistStream:1.0",&ev);
410 CORBA_exception_free(&ev);
411 load_through_persist_stream(fname,interface);
418 install_property_bag_listener (BonoboWidget *control, BonoboWindow *bonobo_win)
420 Bonobo_Listener corba_listener;
421 BonoboListener *listener;
422 BonoboControlFrame *control_frame;
423 CORBA_Environment ev;
424 Bonobo_PropertyBag prop_bag;
426 CORBA_exception_init(&ev);
428 control_frame = bonobo_widget_get_control_frame(BONOBO_WIDGET(control));
430 g_error("can't find control frame\n");
432 prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL);
433 if(prop_bag == CORBA_OBJECT_NIL)
434 g_error("can't connect to property bag\n");
436 //connect a listener to the property bag
437 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn) width_changed,
438 "Bonobo/Property:change:width",NULL,bonobo_win);
440 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)height_changed,
441 "Bonobo/Property:change:height",NULL,bonobo_win);
442 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)top_x_changed,
443 "Bonobo/Property:change:top-x",NULL,bonobo_win);
444 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)top_y_changed,
445 "Bonobo/Property:change:top-y",NULL,bonobo_win);
446 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)font_size_changed,
447 "Bonobo/Property:change:font-size",NULL,bonobo_win);
448 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)anti_aliasing_changed,
449 "Bonobo/Property:change:verbosity",NULL,bonobo_win);
450 bonobo_event_source_client_add_listener(prop_bag, (BonoboListenerCallbackFn)font_manager_changed,
451 "Bonobo/Property:change:font_manager",NULL,bonobo_win);
452 CORBA_exception_free(&ev);
457 main (int argc, char **argv)
459 gnome_program_init("test-editor", VERSION, LIBGNOMEUI_MODULE, argc, argv,
460 GNOME_PROGRAM_STANDARD_PROPERTIES,
461 GNOME_PARAM_HUMAN_READABLE_NAME, _("GtkMathView Test Container"),
466 /* We can't make any CORBA calls unless we're in the main loop. So we
467 delay creating the container here. */
468 gtk_idle_add ((GtkFunction) container_create, NULL);
469 if (argc > 1 && *argv [argc - 1] != '-')
470 gtk_idle_add ((GtkFunction) load_file, argv [argc - 1]);
475 return bonobo_ui_debug_shutdown ();