BonoboPrint

Name

BonoboPrint -- A print interface all embeddables should implement

Synopsis



typedef     BonoboPrint;
typedef     BonoboPrintClass;
GtkType     bonobo_print_get_type           (void);
BonoboPrint* bonobo_print_construct         (BonoboPrint *p,
                                             BonoboPrintRenderFn *render,
                                             gpointer user_data);
BonoboPrint* bonobo_print_new               (BonoboPrintRenderFn *render,
                                             gpointer user_data);

Description

This interfaces is implemented by an embeddable ( compound document item ). It exposes a simple render method that allows its child to print itself. The component renders itself ( or a sub-window of itself ) with the specified dimensions to the provided GnomePrintContext.

In addition to proxying the render request, the context also converts the scribbled on context to a meta file, and returns a stream to the callee such that the information can be transfered to the caller. A nice wrapper interface is available in BonoboPrintClient that makes this very simple to use.

First of course, the interface has to be constructed add associated with the BonoboEmbeddable 's BonoboObject using the bonobo_object_add_interface method.

Example 1. Aggregating a new BonoboPrint interface

HelloBonoboEmbeddable *
hello_bonobo_embeddable_construct (HelloBonoboEmbeddable *embeddable)
{
	BonoboPrint         *print;

	g_return_val_if_fail (HELLO_BONOBO_IS_EMBEDDABLE (embeddable), NULL);

	bonobo_embeddable_construct (BONOBO_EMBEDDABLE (embeddable),
				     hello_bonobo_view_factory, NULL);

	/* Register the Bonobo::Print interface */
	print = bonobo_print_new (hello_object_print, embeddable);
	if (!print) {
		bonobo_object_unref (BONOBO_OBJECT (embeddable));
		return NULL;
	}

	bonobo_object_add_interface (BONOBO_OBJECT (embeddable),
				     BONOBO_OBJECT (print));
	return embeddable;
}
    

Having aggregated the print interface to the embeddable, and passed in the 'embeddable' itself as the user_data, we can then implement the BonoboPrintRenderFn method and make the interface actually useful, in this case we extract the text from the embeddable->text pointer, and print 'Value:' with the text under it, and some miscellaneous lines:

Example 2. A simple print function

void
hello_object_print (GnomePrintContext         *ctx,
		    double                     width,
		    double                     height,
		    const Bonobo_PrintScissor *scissor,
		    gpointer                   user_data)
{
	HelloBonoboEmbeddable *embeddable = user_data;
	GnomeFont             *font;
	double                 w, w2, h;
	const char            *str, *descr;

	str = embeddable->text ? embeddable->text : "No text";
	descr = "Value:";

	gnome_print_setlinewidth (ctx, 2);
	font = gnome_font_new ("Helvetica", 12.0);
	g_return_if_fail (font != NULL);
	gnome_print_setrgbcolor (ctx, 0.0, 0.0, 0.0);
	gnome_print_setfont (ctx, font);

	w  = gnome_font_get_width_string (font, descr);
	w2 = gnome_font_get_width_string (font, str);
	h  = gnome_font_get_ascender (font) +
	     gnome_font_get_descender (font);

	gnome_print_moveto (ctx, (width / 2) - (w / 2), (height / 2) + h * 2);
	gnome_print_show (ctx, descr);
	gnome_print_moveto (ctx, (width / 2) - (w2 / 2), height / 2 - h);
	gnome_print_show (ctx, str);

	gtk_object_unref (GTK_OBJECT (font));
}
    

In the above example the Scissor context is not used. In many applications it will not, however the scissor context specifies how the printed item will be cropped inside the container application, this allows the component to adjust its printed output to best fit this situation if neccessary.

Details

BonoboPrint

typedef struct {
        BonoboXObject        object;

	BonoboPrintRenderFn *render;
	gpointer             user_data;
} BonoboPrint;


BonoboPrintClass

typedef struct {
	BonoboXObjectClass   parent;

	POA_Bonobo_Print__epv epv;

	BonoboPrintRenderFn *render;
} BonoboPrintClass;


bonobo_print_get_type ()

GtkType     bonobo_print_get_type           (void);

Returns : the GtkType for a BonoboPrint object.


bonobo_print_construct ()

BonoboPrint* bonobo_print_construct         (BonoboPrint *p,
                                             BonoboPrintRenderFn *render,
                                             gpointer user_data);

Construct p setting its render and user_data pointers

p : the print object
render : the render method
user_data : the render method's user data
Returns : a constructed BonoboPrint object


bonobo_print_new ()

BonoboPrint* bonobo_print_new               (BonoboPrintRenderFn *render,
                                             gpointer user_data);

Create a new bonobo-print implementing BonoboObject interface.

This interface is called to ask a component to render itself to a print context with the specified width and height, and scissoring data.

render : the render function
user_data : the render's user data function
Returns : a new BonoboPrint interface