AbiWord SDK

From AbiWiki

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
-
<!--Modify this as appropriate, especially if it''s not an FAQ-->
 
-
<!--Aside: using H2 and H3 is a trick for old TWikis to keep headings out of the [[ToC|ToC]]-->
 
-
<!--Delete this line and those above, and anything else that is not needed when you create the page, leave the [[ToC|ToC]] commented out if you don''t use it-->
 
-
 
<H2>[[AbiWordSDK|AbiWordSDK]]</H2>  
<H2>[[AbiWordSDK|AbiWordSDK]]</H2>  
Line 37: Line 33:
<H4> The Makefile </H4>
<H4> The Makefile </H4>
-
<verbatim>
+
<pre>
test-widget: test-widget.c
test-widget: test-widget.c
-
  gcc -g -O0 -Wall -o test-widget `pkg-config --cflags --libs abiword-2.5` test-widget.c
+
  gcc -o test-widget `pkg-config --cflags --libs abiword-2.7` test-widget.c
clean:
clean:
  rm -f test-widget *~
  rm -f test-widget *~
-
</verbatim>
+
</pre>
-
<H4> The Example code, test-widget.c </H4> 
+
-
<verbatim>
+
<H4> The Example code, test-widget.c</H4> 
 +
<pre>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 56: Line 52:
gpointer user_data)
gpointer user_data)
{
{
-
g_print ("Boolean signal ''d\n", (char *)user_data, value);
+
    g_print ("Boolean signal ''d\n", (char *)user_data, value);
}
}
Line 63: Line 59:
gpointer user_data)
gpointer user_data)
{
{
-
g_print ("String signal ''s\n", (char *)user_data, value);
+
    g_print ("String signal ''s\n", (char *)user_data, value);
}
}
Line 70: Line 66:
gpointer user_data)
gpointer user_data)
{
{
-
g_print ("Double signal ''f\n", (char *)user_data, value);
+
    g_print ("Double signal ''f\n", (char *)user_data, value);
}
}
int main(int argc, char ** argv)
int main(int argc, char ** argv)
{
{
-
[[GtkWidget|GtkWidget]] * window;
+
    GtkWidget * window;
-
[[GtkWidget|GtkWidget]] * abi;
+
    GtkWidget * abi;
-
gtk_init (&argc, &argv);
+
    gtk_init (&argc, &argv);
-
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
gtk_widget_set_usize(GTK_WIDGET(window),640,480);
+
    gtk_widget_set_usize(GTK_WIDGET(window),640,480);
-
/* Initialize libabiword */
+
    /* Initialize libabiword */
 +
    libabiword_init(argc, (const char **)argv);
-
libabiword_init(argc, (const char **)argv);
+
    /* Construct our widget! */
-
abi = abi_widget_new ();
+
    abi = abi_widget_new ();
-
gtk_container_add (GTK_CONTAINER (window), abi);
+
    gtk_container_add (GTK_CONTAINER (window), abi);
-
gtk_widget_show_all (window);
+
    gtk_widget_show_all (window);
-
g_signal_connect (G_OBJECT (abi), "bold", G_CALLBACK (boolean_signal), "bold");
+
    g_signal_connect (G_OBJECT (abi), "bold", G_CALLBACK (boolean_signal), "bold");
-
g_signal_connect (G_OBJECT (abi), "italic", G_CALLBACK (boolean_signal), "italic");
+
    g_signal_connect (G_OBJECT (abi), "italic", G_CALLBACK (boolean_signal), "italic");
-
g_signal_connect (G_OBJECT (abi), "underline", G_CALLBACK (boolean_signal), "underline");
+
    g_signal_connect (G_OBJECT (abi), "underline", G_CALLBACK (boolean_signal), "underline");
-
g_signal_connect (G_OBJECT (abi), "can-undo", G_CALLBACK (boolean_signal), "can-undo");
+
    g_signal_connect (G_OBJECT (abi), "can-undo", G_CALLBACK (boolean_signal), "can-undo");
-
g_signal_connect (G_OBJECT (abi), "can-redo", G_CALLBACK (boolean_signal), "can-redo");
+
    g_signal_connect (G_OBJECT (abi), "can-redo", G_CALLBACK (boolean_signal), "can-redo");
-
g_signal_connect (G_OBJECT (abi), "font-size", G_CALLBACK (double_signal), "font-size");
+
    g_signal_connect (G_OBJECT (abi), "font-size", G_CALLBACK (double_signal), "font-size");
-
g_signal_connect (G_OBJECT (abi), "font-family", G_CALLBACK (string_signal), "font-family");
+
    g_signal_connect (G_OBJECT (abi), "font-family", G_CALLBACK (string_signal), "font-family");
-
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+
    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
-
if(argv[1])
+
    if (argv[1])
-
abi_widget_load_file (ABI_WIDGET (abi), argv[1]);
+
        abi_widget_load_file (ABI_WIDGET (abi), argv[1]);
-
else
+
-
abi_widget_load_file (ABI_WIDGET (abi), "");
+
 +
    gtk_main ();
-
gtk_main ();
+
    /* Close libabiword */
-
 
+
    libabiword_shutdown ();
-
/* Close libabiword */
+
    return 0;
-
 
+
-
libabiword_shutdown ();
+
-
return 0;
+
}
}
-
</verbatim>
+
</pre>
-
 
+
-
<!--
+
-
<H3>Contents</H3>
+
-
-->
 
-
==== Contributors
 
-
====
 
-
* Main.[[MartinSevior|MartinSevior]] - 04 Jan 2007
 
[[Category:To Convert]]
[[Category:To Convert]]

Revision as of 15:20, 4 November 2007

Contents

AbiWordSDK

AbiWord can be compiled to create a stand alone library, headers and package configuration file. These are built if you place the following into the AbiWord ./configure script.

./configure --prefix=/Path/To/Install --enable-libabiword

This will create the following files

  • /Path/To/Install/bin/abiword-2.7
  • /Path/To/Install/include/abiword-2.7/libabiword.h
  • /Path/To/Install/lib/pkgconfig/abiword-2.7.pc
  • /Path/To/Install/lib/libabiword-2.7.so

The most easily accessible way to use this library is to use the GtkWidget, AbiWidget.

In addition tere are a large variety of [[[AbiWordSignals|AbiWordSignals]] Gtk signals] emitted by the widget that reflect the current document and th elocation of the insersion caret within the document. You can hook up callbacks to these signals to implement useful features (like buttons that reflect the current state of the document at the caret).

Simple Example program

The following example assumes that you set your PKG_CONFIG_PATH evironment variable to discover abiword-2.5.pc. The code was written by Dom Lachowicz.

The main thing you have to do to enable the widget to be visible is to call the method:

abi_widget_load_file (AbiWidget * abi, char * filename)

even if the filename is an empty string.

By default, PyAbiWord starts using the "Normal View".

The code below also shows some of the signals emitted by the widget as the user navigates through the document. You can use these signals to determine the state of the document at the current insertion point.

A complete listing of all the methods and signals currently implemented will be made eventually. In the meantime look at the abiwidget.h header file available [[[AbiWidgetHeader|AbiWidgetHeader]] here].

The Makefile

test-widget: test-widget.c
		  gcc -o test-widget `pkg-config --cflags --libs abiword-2.7` test-widget.c

clean:
		  rm -f test-widget *~

The Example code, test-widget.c

#include <stdio.h>
#include <stdlib.h>
#include <libabiword.h>
#include <abiwidget.h>

static void boolean_signal ([[AbiWidget|AbiWidget]] * widget,
									 gboolean value,
									 gpointer user_data)
{
    g_print ("Boolean signal ''d\n", (char *)user_data, value);
}

static void string_signal ([[AbiWidget|AbiWidget]] * widget,
									const char * value,
									gpointer user_data)
{
    g_print ("String signal ''s\n", (char *)user_data, value);
}

static void double_signal ([[AbiWidget|AbiWidget]] * widget,
									double value,
									gpointer user_data)
{
    g_print ("Double signal ''f\n", (char *)user_data, value);
}

int main(int argc, char ** argv)
{
    GtkWidget * window;
    GtkWidget * abi;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(GTK_WIDGET(window),640,480);

    /* Initialize libabiword */
    libabiword_init(argc, (const char **)argv);

    /* Construct our widget! */
    abi = abi_widget_new ();
    gtk_container_add (GTK_CONTAINER (window), abi);
    gtk_widget_show_all (window);

    g_signal_connect (G_OBJECT (abi), "bold", G_CALLBACK (boolean_signal), "bold");
    g_signal_connect (G_OBJECT (abi), "italic", G_CALLBACK (boolean_signal), "italic");
    g_signal_connect (G_OBJECT (abi), "underline", G_CALLBACK (boolean_signal), "underline");
    g_signal_connect (G_OBJECT (abi), "can-undo", G_CALLBACK (boolean_signal), "can-undo");
    g_signal_connect (G_OBJECT (abi), "can-redo", G_CALLBACK (boolean_signal), "can-redo");
    g_signal_connect (G_OBJECT (abi), "font-size", G_CALLBACK (double_signal), "font-size");
    g_signal_connect (G_OBJECT (abi), "font-family", G_CALLBACK (string_signal), "font-family");

    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);

    if (argv[1])
        abi_widget_load_file (ABI_WIDGET (abi), argv[1]);

    gtk_main ();

    /* Close libabiword */
    libabiword_shutdown ();
    return 0;
}
Personal tools