gnumeric component
- From: Kutloisiso Mona <kmona cs uct ac za>
- To: gnome-components-list gnome org
- Subject: gnumeric component
- Date: Sun, 25 Sep 2005 12:26:01 +0200
Hi Again
I have managed to embed a gnumeric component into a gtk application. Is
the component only a viewer, I am unable to edit. Has the component been
implemented as a viewer only. Here is the code I am using: I dont
#include <bonobo.h>
#include <glib.h>
#include <gnome.h>
static Bonobo_PropertyBag prop_bag = CORBA_OBJECT_NIL;
static GtkWidget *bonobo_win;
static CORBA_Environment ev;
static BonoboControlFrame *control_frame;
static Bonobo_Control gnumericControl;
/*
* close the app, but clean up things first
*/
static void on_destroy (GtkWidget *app, BonoboUIContainer *uic)
{
if (uic)
bonobo_object_unref (BONOBO_OBJECT (uic));
if (prop_bag != CORBA_OBJECT_NIL)
bonobo_object_release_unref (prop_bag, CORBA_OBJECT_NIL);
bonobo_control_frame_control_deactivate(control_frame);
bonobo_object_release_unref(gnumericControl,CORBA_OBJECT_NIL);
bonobo_main_quit();
}
static gboolean s_entry_activated(GtkWidget * wgnumericEntry, gpointer p)
{
gchar *command;
gchar ** ptr;
gchar s_command[100];
gint n;
command = (gchar *) gtk_entry_get_text (GTK_ENTRY (wgnumericEntry));
printf("command is %s \n",command);
ptr = g_strsplit(command," ",100);
n = 0;
while(ptr[n] != NULL)
{
n++;
}
if(n > 1)
{
if(strcmp(ptr[0],"load-file") == 0)
{
bonobo_pbclient_set_string(prop_bag,
"gnumericWidget--load-file",
(gchar *) ptr[1], &ev);
}
}
else if(strcmp(ptr[0],"cursoron") == 0)
{
bonobo_pbclient_set_boolean(prop_bag,
"gnumericWidget--cursoron", TRUE, &ev);
}
else if(n=1)
{
strcpy(s_command,"gnumericWidget--");
strcat(s_command,command);
printf("command sent is %s \n",s_command);
bonobo_pbclient_set_boolean(prop_bag,
s_command,
TRUE, &ev);
}
#if 0
// else
// {
// bonobo_property_bag_client_set_value_string (prop_bag,
//
"AbiWidget::invoke_noargs",(gchar *) command,NULL);
// }
#endif
g_strfreev (ptr);
return FALSE;
}
/*
* Create the container frame, the control, the property bag and the
* surrounding GTK nicities.
*/
static guint create_app (char *gnumeric_file)
{
GtkWidget *box, *control, *button;
GtkWidget * frame1;
GtkWidget * hseparator1;
BonoboUIContainer *uic;
GtkWidget * hboxEntry;
GtkWidget * gnumericCommandLabel;
GtkWidget * wGnumericEntry;
GtkWidget* gmoniker;
/*
* Now acquire a property bag.
* The property bag is associated with the control frame, so get a
* control frame first
*/
CORBA_exception_init (&ev);
/* Create a bonobo application (window) */
bonobo_win = bonobo_window_new ("gnumeric_control",
"A container for Gnumeric");
gtk_widget_set_usize (GTK_WIDGET(bonobo_win), 600, 600);
/* Connect a ui container to the application */
uic = bonobo_window_get_ui_container (BONOBO_WINDOW (bonobo_win));
//uic = bonobo_ui_container_new ();
//bonobo_ui_container_set_win (uic, BONOBO_WINDOW(bonobo_win));
/* Get our remote control */
//gnumericControl = bonobo_get_object ("OAFIID:GNOME_Gnumeric_Workbook",
//
// "Bonobo/Control", &ev);
control = bonobo_widget_new_control (
"file:/home/kmona/test.gnumeric", BONOBO_OBJREF(uic));
if (BONOBO_EX (&ev) || (control == CORBA_OBJECT_NIL))
{
g_error("Can't get the Gnumeric Control\n");
return FALSE;
}
/* Get a widget, containing the control */
//control = bonobo_widget_new_control_from_objref(gnumericControl,
// BONOBO_OBJREF (uic));
if (!control)
{
g_error ("Can't create control\n");
return FALSE;
}
gtk_widget_show(control);
control_frame = bonobo_widget_get_control_frame
(BONOBO_WIDGET(control));
if (!control_frame)
{
g_error ("Can't find control frame\n");
return FALSE;
}
prop_bag = bonobo_control_frame_get_control_property_bag
(control_frame, NULL);
if (prop_bag != CORBA_OBJECT_NIL) {
/* Set editable property */
bonobo_pbclient_set_boolean(prop_bag, "bonobo:editable",
TRUE, NULL);
//DEBUGM("viewer: set editable to false\n");
}
/* Now, get a ref to the property bag */
//prop_bag =Bonobo_Control_getProperties(gnumericControl, &ev);
/*prop_bag = bonobo_control_frame_get_control_property_bag
(control_frame, &ev);
if (prop_bag == CORBA_OBJECT_NIL)
{
//g_error ("Can't connect to property bag\n");
//return FALSE;
}*/
//GList * keyValues = bonobo_pbclient_get_keys (prop_bag, &ev);
/*GList * curVal = g_list_first(keyValues);
int i = 0;
while(curVal)
{
printf("Key %d value %s \n",i,curVal->data);
curVal = g_list_next(curVal);
i++;
}*/
/* Build the gtk support structure. */
box = gtk_vbox_new (FALSE, 0);
gtk_widget_show(box);
bonobo_window_set_contents (BONOBO_WINDOW(bonobo_win), box);
frame1 = gtk_frame_new ("GnumericControl");
gtk_widget_show (frame1);
gtk_box_pack_start (GTK_BOX (box), frame1, TRUE, TRUE, 0);
gtk_frame_set_label_align (GTK_FRAME (frame1), 0.04, 0.5);
gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_ETCHED_OUT);
hseparator1 = gtk_hseparator_new ();
gtk_widget_show (hseparator1);
gtk_box_pack_start (GTK_BOX (box), hseparator1, FALSE, FALSE, 0);
/* Add the gnumeric Widget to our app */
gtk_container_add (GTK_CONTAINER (frame1), control);
/* Create an entry so we can play with the widget. */
hboxEntry = gtk_hbox_new(FALSE,0);
gtk_widget_show(hboxEntry);
gtk_box_pack_start (GTK_BOX (box), hboxEntry, FALSE, FALSE, 0);
gnumericCommandLabel = gtk_label_new("GnumericWidget Command: ");
gtk_widget_show(gnumericCommandLabel);
gtk_box_pack_start (GTK_BOX (hboxEntry), gnumericCommandLabel, TRUE,
TRUE, 0);
wGnumericEntry = gtk_entry_new();
gtk_widget_show(wGnumericEntry);
gtk_box_pack_start (GTK_BOX (hboxEntry), wGnumericEntry, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(wGnumericEntry),
"activate",
G_CALLBACK(s_entry_activated),
(gpointer) NULL);
/* Create a "close" button and add it to the app */
button = gtk_button_new_with_label ("close");
gtk_box_pack_start(GTK_BOX (box), button, FALSE,FALSE,0);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(on_destroy), NULL);
/* Create a 'destroy' handler, so we can clean things up */
g_signal_connect (G_OBJECT(bonobo_win), "destroy",
G_CALLBACK(on_destroy), uic);
/* OK Boris let her rip!!! */
gtk_widget_show_all (GTK_WIDGET(bonobo_win));
/* Load a file in the control */
if(prop_bag != CORBA_OBJECT_NIL)
{
/*bonobo_pbclient_set_string(prop_bag,
"GnumericWidget--load-file",
abw_file, &ev);*/
}
return TRUE;
}
int
main (int argc, char** argv)
{
gnome_init("Gnumeric-test-container", "0.0",
argc, argv);
if (!bonobo_init (NULL, NULL))
g_error ("could not initialize Bonobo");
if(gnome_vfs_init () == FALSE)
g_error (_("Could not initialize GnomeVFS!\n"));
/*if (argc != 2)
{
printf("Usage: test-gnumericContainer <file.abw>\n");
return 1;
}*/
/*
* We can't make any CORBA calls unless we're in the main
* loop. So we delay creating the container here.
*/
if (!create_app(argv[1]))
return 1; /* Emergency bailout */
bonobo_main ();
return 0;
}
Kutloisiso
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]