Re: GnuCash page on GO site

[email protected]
Newsgroups gmane.editors.abiword.devel,gmane.comp.gnome.apps.gnucash.devel,gmane.comp.gnome.office.general
Message-ID <[email protected]>
>> > I'll post some example code of how to use the control shortly.
>>
>> Please post it on the approporiate abi website, so that google finds it.
>> One of the harder aspects to bonobo is that there haven't been many
>> good examples of how to use some of these controls. I've seen a
>> gnumeric bonobo for years, but have always scratched my head
>> "gee, now what? how do I use this thing?"
>
> Please forward that code to me as well Martin. I want to create a
> Manual/HowTo section on abisource.com, and this seems a good start...
>

OK. Here it is. This is the README inside the gzipped directory.

This little demo shows how to embed a AbiWord Bonobo control into a GTK
program.

You'll need AbiWord > 2.0 and the GNOME_AbiWord_Control_2_0.server IDL
file placed in /usr/lib/bonobo/servers

Recent Linux distros like fedora-1 should this for you or you can can just
grab a 2.0.3 GNOME rpm and "embeddable" rpm and install them.

The program loads simple document with a nice little table called
AbiTableTest.abw at line 240 in the test-abi2Container.c.

You'll need to change the full path name of "/home/msevior/abiBonoboDemo"
to where-ever you place this directory.

If you know how to fix this to use a relative path to where the directory
is placed, please send me a patch :-)

To build type "make"
The clean up type "make clean"

To play, load in the document (or one of your own  via the "load-file"
command)
Click in the window and start typing. Try changing th column widths, and
heights like you normally would.

Resize the app and watch AbiWord zoom to fit inside the new window.

Then type "undo" in the command line and watch your changes get undone.
Type "redo" see them come back. Type something missspelled and see it get
underlined with squiggles.

Have fun and think of the possiblities for your app :-)

Martin Sevior

> Marc
>
> _______________________________________________
> gnome-office-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/gnome-office-list
>
abiBonoboDemo.tar.gz (application/gzip, 6.7 KB) - not displayed
test-abi2Container.c (application/octet-stream, 6.9 KB)
/*
 *  test-abi2Ccontainer.c
 *  container for the AbiWord Bonobo Control
 */

/*
** Copyright (C) 2000 Dirk-Jan C. Binnema <[email protected]>
** Copyright (C) 2004 Martin Sevior <[email protected]>
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/


#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 AbiControl;

/*
 * 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(AbiControl,CORBA_OBJECT_NIL);
	bonobo_main_quit();
}

static gboolean s_entry_activated(GtkWidget * wAbiEntry, gpointer p)
{
	gchar *command;
	gchar ** ptr;
	gchar s_command[100];
	gint n;
	command = (gchar *) gtk_entry_get_text (GTK_ENTRY (wAbiEntry));
	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,
					    "AbiWidget--load-file",
					    (gchar *) ptr[1], &ev);
		}
	}
	else if(strcmp(ptr[0],"cursoron") == 0)
	{
		bonobo_pbclient_set_boolean(prop_bag,
				    "AbiWidget--cursoron", TRUE, &ev);
	}
	else if(n=1)
	{
		strcpy(s_command,"AbiWidget--");
		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 (void)
{
	GtkWidget *box, *control, *button;
	GtkWidget * frame1;
	GtkWidget * hseparator1;
	BonoboUIContainer *uic;
	GtkWidget * hboxEntry;
	GtkWidget * AbiCommandLabel;
	GtkWidget * wAbiEntry;
	/*
     *  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 ("AbiWord_control",
					"A container for AbiWord");
	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));
	
	/* Get our remote control */

	AbiControl = bonobo_get_object ("OAFIID:GNOME_AbiWord_Control",
					"Bonobo/Control", &ev);
	if (BONOBO_EX (&ev) || (AbiControl == CORBA_OBJECT_NIL))
	{
	  g_error("Can't get the Abi Control \n");
	}


	/* get a widget, containing the control */

	control = bonobo_widget_new_control_from_objref(AbiControl,
							BONOBO_OBJREF (uic));
	if (!control) 
	{
		g_error ("Can't create control\n");
	}
	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");
	}
	/* 
	 * now, get a ref to the property bag
	 */
	prop_bag =Bonobo_Control_getProperties(AbiControl, &ev);
	if (prop_bag == CORBA_OBJECT_NIL)
	{
	  /*		g_error ("can't connect to property bag\n"); */
	  printf("Can't connect to property bag \n");
	}
	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 ("AbiControl");
	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 AbiWidget 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);

	AbiCommandLabel = gtk_label_new("AbiWidget Command: ");
	gtk_widget_show(AbiCommandLabel);
	gtk_box_pack_start (GTK_BOX (hboxEntry), AbiCommandLabel, TRUE, TRUE, 0);
	
	wAbiEntry = gtk_entry_new();
	gtk_widget_show(wAbiEntry);
	gtk_box_pack_start (GTK_BOX (hboxEntry), wAbiEntry, TRUE, TRUE, 0);
	g_signal_connect(G_OBJECT(wAbiEntry),
					   "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,
					    "AbiWidget--load-file",
					    "/home/msevior/abiBonoboDemo/AbiTableTest.abw", &ev);
	}
	return FALSE; /* putting TRUE here is a bad idea. I warned you. */
}




int 
main (int argc, char** argv)
{
	
	gnome_init("AbiWord-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"));


	/*
	 * We can't make any CORBA calls unless we're in the main
	 * loop.  So we delay creating the container here.
	 */
	create_app();
	//	gtk_idle_add ((GtkFunction) create_app, NULL);
	bonobo_main ();

	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.