gnumeric.c 18.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/* 
 * Gnumeric GOffice component
 * gnumeric.c
 *
 * Copyright (C) 2006
 *
 * Developed by Jean Bréfort <jean.brefort@normalesup.org>
 *
 * 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 <gnumeric-config.h>
#include <gnumeric.h>
#include <libgnumeric.h>
#include <gnumeric-gconf.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtkactiongroup.h>
#include <gtk/gtkstock.h>
#include <goffice/app/io-context.h>
#include <goffice/component/goffice-component.h>
#include <goffice/component/go-component.h>
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-color.h>
#include <gsf/gsf-impl-utils.h>
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-output-memory.h>
#include <goffice/app/go-cmd-context.h>
#include <goffice/app/module-plugin-defs.h>
#include <application.h>
#include <cell.h>
#include <cell-draw.h>
#include <colrow.h>
46
#include <print-cell.h>
47 48 49 50
#include <rendered-value.h>
#include <workbook-view.h>
#include <workbook-control-gui-priv.h>
#include <workbook.h>
51
#include <selection.h>
52
#include <sheet.h>
53
#include <sheet-object-impl.h>
54
#include <print-cell.h>
55 56 57
#include <sheet-object.h>
#include <command-context.h>
#include <command-context-stderr.h>
58 59 60 61
#ifdef GOFFICE_WITH_CAIRO
#	include <cairo.h>
#	include <pango/pangocairo.h>
#endif
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

GOPluginModuleDepend const go_plugin_depends [] = {
    { "goffice", GOFFICE_API_VERSION }
};
GOPluginModuleHeader const go_plugin_header =
	{ GOFFICE_MODULE_PLUGIN_MAGIC_NUMBER, G_N_ELEMENTS (go_plugin_depends) };

G_MODULE_EXPORT void go_plugin_init (GOPlugin *plugin, GOCmdContext *cc);
G_MODULE_EXPORT void go_plugin_shutdown (GOPlugin *plugin, GOCmdContext *cc);

typedef struct
{
	GOComponent parent;

	WorkbookView *wv;
	WorkbookControlGUI *edited;
78 79
	Sheet *sheet;
	int col_start, col_end, row_start, row_end;
80 81 82 83 84
	int width, height;
} GOGnmComponent;

/* Red and blue are inverted in a pixbuf compared to cairo */
static void
85
cairo_to_pixbuf (unsigned char *p, int width, int height, int rowstride)
86 87 88 89 90
{
	int i,j;
	unsigned char a;
	guint t;
	
91
#define MULT(d,c,a,t) G_STMT_START { t = (a)? c * 255 / a: 0; d = t;} G_STMT_END
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	
	for (i = 0; i < height; i++) {
		for (j = 0; j < width; j++) {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
			MULT(a,    p[2], p[3], t);
			MULT(p[1], p[1], p[3], t);
			MULT(p[2], p[0], p[3], t);
			p[0] = a;
#else	  
			a = p[3];
			MULT(p[3], p[2], a, t);
			MULT(p[2], p[1], a, t);
			MULT(p[1], p[0], a, t);
			p[0] = a;
#endif
			p += 4;
		}
		p += rowstride - width * 4;
	}
#undef MULT
}

typedef GOComponentClass GOGnmComponentClass;

#define GO_GNM_COMPONENT_TYPE	(go_gnm_component_get_type ())
#define GO_GNM_COMPONENT(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GO_GNM_COMPONENT_TYPE, GOGnmComponent))
#define GO_IS_GNM_COMPONENT(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GO_GNM_COMPONENT_TYPE))

GType go_gnm_component_get_type (void);

static GObjectClass *gognm_parent_klass;

static gboolean
go_gnm_component_get_data (GOComponent *component, gpointer *data, int *length,
									void (**clearfunc) (gpointer), gpointer *user_data)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
	if (gognm->edited) {
		GOCmdContext *cc = go_component_get_command_context ();
		IOContext *io_context = gnumeric_io_context_new (cc);
		GsfOutput *output = gsf_output_memory_new ();
		WorkbookView *wbv = wb_control_view (WORKBOOK_CONTROL (gognm->edited));
		Workbook *wb = wb_control_get_workbook (WORKBOOK_CONTROL (gognm->edited));
		GOFileSaver *gfs = workbook_get_file_saver (wb);
		if (gfs == NULL)
			gfs = go_file_saver_get_default ();
		wbv_save_to_output (wbv, gfs, output, io_context);
		*data = (gpointer) gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (output));
		*length = gsf_output_size (output);
		*clearfunc = g_object_unref;
		*user_data = output;
		return TRUE;
	}
	return FALSE;
}

static void
go_gnm_component_set_data (GOComponent *component)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
152 153
	SheetView *sv;
	GnmRange const *range;
154 155 156 157 158 159 160
	GOCmdContext *cc = go_component_get_command_context ();
	IOContext *io_context = gnumeric_io_context_new (cc);
	GsfInput *input = gsf_input_memory_new (component->data, component->length, FALSE);

	g_object_set (G_OBJECT (io_context), "exec-main-loop", FALSE, NULL);
 	gognm->wv = wb_view_new_from_input (input, NULL, io_context, NULL);
	g_object_unref (io_context);
161 162 163 164 165 166 167
	gognm->sheet = wb_view_cur_sheet (gognm->wv);
	sv = sheet_get_view (gognm->sheet, gognm->wv);
	range = selection_first_range (sv, NULL, NULL);
	gognm->col_start = range->start.col;
	gognm->row_start = range->start.row;
	gognm->col_end = range->end.col;
	gognm->row_end = range->end.row;
168
	gognm->width = sheet_col_get_distance_pts (
169
		gognm->sheet, gognm->col_start, gognm->col_end + 1);
170 171 172
	component->width = gognm->width / 72.;
	component->descent = 0.;
	gognm->height = sheet_row_get_distance_pts (
173
		gognm->sheet, gognm->row_start, gognm->row_end + 1);
174 175 176
	component->ascent = gognm->height  / 72.;
}

177
#ifdef GOFFICE_WITH_CAIRO
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
static void
cell_render (cairo_t *cairo, GnmCell *cell)
{
	GOColor fore_color;
	int x, y;
	RenderedValue *rv = cell->rendered_value;
	ColRowInfo const * const ci = cell->col_info;
	ColRowInfo const * const ri = cell->row_info;

	int width  = ci->size_pixels - (ci->margin_b + ci->margin_a + 1);
	int height = ri->size_pixels - (ri->margin_b + ri->margin_a + 1);
	int h_center = -1;
	int x1 = 1 + ci->margin_a;
	int y1 = 1 + ri->margin_a;

	if (!rv) {
		cell_render_value (cell, FALSE);
		rv = cell->rendered_value;
	}

	if (cell_calc_layout (cell, rv, +1,
			width * PANGO_SCALE,
			height * PANGO_SCALE,
			h_center == -1 ? -1 : (h_center * PANGO_SCALE),
			&fore_color, &x, &y)) {
		cairo_new_path (cairo);
		cairo_move_to (cairo, x1, y1);
		cairo_line_to (cairo, x1 + width, y1);
		cairo_line_to (cairo, x1 + width, y1 + height);
		cairo_line_to (cairo, x1, y1 + height);
		cairo_close_path (cairo);
		cairo_clip (cairo);

211
		cairo_set_source_rgb (cairo, UINT_RGBA_R(fore_color), UINT_RGBA_G(fore_color),  UINT_RGBA_B(fore_color));
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
		if (rv->rotation) {
			RenderedRotatedValue *rrv = (RenderedRotatedValue *)rv;
			struct RenderedRotatedValueInfo const *li = rrv->lines;
			GSList *lines;
			cairo_matrix_t m;
			m.xx = rrv->rotmat.xx;
			m.xy = rrv->rotmat.xy;
			m.yx = rrv->rotmat.yx;
			m.yy = rrv->rotmat.yy;
			m.x0 = rrv->rotmat.x0;
			m.y0 = rrv->rotmat.y0;

			for (lines = pango_layout_get_lines (rv->layout);
					lines;
					lines = lines->next, li++) {
				cairo_save (cairo);
				cairo_move_to (cairo, PANGO_PIXELS (x + li->dx), PANGO_PIXELS (y + li->dy));
				cairo_transform (cairo, &m);
				pango_cairo_show_layout_line (cairo, lines->data);
				cairo_restore (cairo);
			}
		} else {
			cairo_move_to (cairo, x / PANGO_SCALE, y / PANGO_SCALE);
			pango_cairo_show_layout (cairo, rv->layout);
		}
	}
}
239
#endif
240 241 242 243

static void
go_gnm_component_draw (GOComponent *component, int width_pixels, int height_pixels)
{
244
#ifdef GOFFICE_WITH_CAIRO
245 246 247 248 249 250 251 252 253
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
	int col, row;
	cairo_surface_t* surface ;
	cairo_t *cairo;
	GnmCell *cell;
	double xoffset = 0., yoffset;
	GSList *l;
	SheetObject *so;
	SheetObjectAnchor const *anchor;
254
	ColRowInfo const *ri;
255 256 257 258

	gdk_pixbuf_fill (component->pixbuf, 0);
	if (gognm->wv == NULL)
		return;
259 260
	if (gognm->sheet == NULL)
		return;
261 262 263 264 265 266 267 268
	surface = cairo_image_surface_create_for_data (
              				gdk_pixbuf_get_pixels (component->pixbuf),
							CAIRO_FORMAT_ARGB32,
							width_pixels, height_pixels, 
               				gdk_pixbuf_get_rowstride (component->pixbuf));
	cairo = cairo_create (surface);
	cairo_scale (cairo, ((double) width_pixels) / gognm->width, ((double) height_pixels) / gognm->height);
	for (col = gognm->col_start; col <= gognm->col_end; col++) {
269 270 271
		ri = sheet_col_get_info (gognm->sheet, col);
		if (!ri->visible)
			continue;
272 273
		yoffset = 0.;
		for (row = gognm->row_start; row <= gognm->row_end; row++) {
274 275 276 277
			ri = sheet_row_get_info (gognm->sheet, row);
			if (!ri->visible)
				continue;
			cell = sheet_cell_get (gognm->sheet, col, row);
278 279 280 281 282 283 284 285 286
			if (cell) {
				cairo_save (cairo);
				cairo_translate (cairo, xoffset, yoffset);
				cairo_scale (cairo,
					72. / gnm_app_display_dpi_get (TRUE),
					72. / gnm_app_display_dpi_get (FALSE));
				cell_render (cairo, cell);
				cairo_restore (cairo);
			}
287
			yoffset += sheet_row_get_distance_pts (gognm->sheet, row, row + 1);
288
		}
289
		xoffset += sheet_col_get_distance_pts (gognm->sheet, col, col + 1);
290 291
	}
	/* Now render objects */
292
	l = gognm->sheet->sheet_objects;
293 294 295 296 297 298 299 300 301
	while (l) {
		so = SHEET_OBJECT (l->data);
		anchor = sheet_object_get_anchor (so);
		/* test if the object overlaps the exposed range */
		if ((anchor->cell_bound.start.col <= gognm->col_end) &&
			(anchor->cell_bound.end.col >= gognm->col_start) &&
			(anchor->cell_bound.start.row <= gognm->row_end) &&
			(anchor->cell_bound.end.row >= gognm->row_start)) {
			/* translate the origin to start cell of object */
302
			xoffset = sheet_col_get_distance_pts (gognm->sheet, gognm->col_start,
303
				anchor->cell_bound.start.col);
304
			yoffset = sheet_row_get_distance_pts (gognm->sheet, gognm->row_start,
305 306 307 308 309 310 311 312 313 314
				anchor->cell_bound.start.row);
			cairo_save (cairo);
			cairo_translate (cairo, xoffset, yoffset);
			sheet_object_draw_cairo (so, (gpointer) cairo);
			cairo_restore (cairo);
		}
		l = l->next;
	}
	cairo_destroy (cairo);
	cairo_surface_destroy (surface);
315
	cairo_to_pixbuf (gdk_pixbuf_get_pixels (component->pixbuf), 
316 317
					width_pixels, height_pixels, 
					gdk_pixbuf_get_rowstride (component->pixbuf));
318
#endif
319 320 321 322 323 324 325
}

static void
go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
												double width, double height)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
Jean Bréfort's avatar
Jean Bréfort committed
326
	GnmRange range;
327 328 329 330
	GSList *l;
	SheetObject *so;
	SheetObjectAnchor const *anchor;
	if (gognm->sheet == NULL)
Jean Bréfort's avatar
Jean Bréfort committed
331 332 333 334 335
		return;
	range.start.row = gognm->row_start;
	range.start.col = gognm->col_start;
	range.end.row = gognm->row_end;
	range.end.col = gognm->col_end;
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	print_cell_range (gpc, gognm->sheet, &range, 0., height, TRUE);
	/* Now print objects */
	l = gognm->sheet->sheet_objects;
	gnome_print_gsave (gpc);
	gnome_print_translate (gpc, 0., height);
	while (l) {
		so = SHEET_OBJECT (l->data);
		anchor = sheet_object_get_anchor (so);
		/* test if the object overlaps the exposed range */
		if ((anchor->cell_bound.start.col <= gognm->col_end) &&
			(anchor->cell_bound.end.col >= gognm->col_start) &&
			(anchor->cell_bound.start.row <= gognm->row_end) &&
			(anchor->cell_bound.end.row >= gognm->row_start)) {
			double xoffset = 0., yoffset, x = 0., y = 0., cell_width, cell_height;
			/* translate the origin to start cell of object */
			xoffset = sheet_col_get_distance_pts (gognm->sheet, gognm->col_start,
				anchor->cell_bound.start.col);
			yoffset = sheet_row_get_distance_pts (gognm->sheet, gognm->row_start,
				anchor->cell_bound.start.row);
			width = sheet_col_get_distance_pts (so->sheet,
						anchor->cell_bound.start.col,
						anchor->cell_bound.end.col + 1);
			height = sheet_row_get_distance_pts (so->sheet,
						anchor->cell_bound.start.row,
						anchor->cell_bound.end.row + 1);
			cell_width = sheet_col_get_distance_pts (so->sheet,
						anchor->cell_bound.start.col,
						anchor->cell_bound.start.col + 1);
			cell_height = sheet_row_get_distance_pts (so->sheet,
						anchor->cell_bound.start.row,
						anchor->cell_bound.start.row + 1);
			switch (anchor->type[0]) {
			case SO_ANCHOR_UNKNOWN:
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
				x = cell_width * anchor->offset[0];
				break;
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
				x = cell_width * (1. - anchor->offset[0]);
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_START:
				x = anchor->offset[0];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_END:
				x = cell_width - anchor->offset[0];
				break;
			default:
				break;
			}
			width -= x;	
			switch (anchor->type[1]) {
			case SO_ANCHOR_UNKNOWN:
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
				y = cell_height * anchor->offset[1];
				break;
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
				y = cell_height * (1 - anchor->offset[1]);
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_START:
				y = anchor->offset[1];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_END:
				y = cell_height - anchor->offset[1];
				break;
			default:
				break;
			}	
			height -= y;
			cell_width = sheet_col_get_distance_pts (so->sheet,
						anchor->cell_bound.end.col,
						anchor->cell_bound.end.col + 1);
			cell_height = sheet_row_get_distance_pts (so->sheet,
						anchor->cell_bound.end.row,
						anchor->cell_bound.end.row + 1);
			switch (anchor->type[2]) {
			case SO_ANCHOR_UNKNOWN:
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
				width -= cell_width * (1. - anchor->offset[2]);
				break;
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
				width -= cell_width * anchor->offset[2];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_START:
				width -= cell_width - anchor->offset[2];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_END:
				width -= anchor->offset[2];
				break;
			case SO_ANCHOR_PTS_ABSOLUTE:
				width = anchor->offset[2];
				break;
			default:
				break;
			}		
			switch (anchor->type[3]) {
			case SO_ANCHOR_UNKNOWN:
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
				height -= cell_height * (1 - anchor->offset[3]);
				break;
			case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
				height -= cell_height * anchor->offset[3];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_START:
				height -= cell_height - anchor->offset[3];
				break;
			case SO_ANCHOR_PTS_FROM_COLROW_END:
				height -= anchor->offset[3];
				break;
			case SO_ANCHOR_PTS_ABSOLUTE:
				height = anchor->offset[3];
				break;
			default:
				break;
			}
			gnome_print_gsave (gpc);
			gnome_print_translate (gpc, xoffset + x, - yoffset - y);
			sheet_object_print (so, gpc, width, height);
			gnome_print_grestore (gpc);
		}
		l = l->next;
	}
	gnome_print_grestore (gpc);
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
}

static void
cb_gognm_save (GtkAction *a, WorkbookControlGUI *wbcg)
{
	GOComponent *component = GO_COMPONENT (g_object_get_data (G_OBJECT (wbcg), "component"));
	go_component_emit_changed (component);
}

extern char const *uifilename;
extern GtkActionEntry const *extra_actions;
extern int nb_extra_actions;
static GtkActionEntry const actions[] = {
/* File */
	{ "FileSaveEmbed", GTK_STOCK_SAVE, NULL,
		NULL, N_("Save the embedded workbook"),
473
		G_CALLBACK (cb_gognm_save) },
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
};

static void
editor_destroyed_cb (GOGnmComponent *gognm)
{
	gognm->edited = NULL;
}

static gboolean
go_gnm_component_edit (GOComponent *component)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
	WorkbookView *wv;
	if (gognm->edited) {
		gdk_window_raise (gognm->edited->toplevel->window);
		return TRUE;
	}
	if (!gognm->wv) {
		component->ascent = 0.;
		component->descent = 0.;
		component->width = 0.;
		wv = workbook_view_new (workbook_new_with_sheets (1));
	} else {
		GOCmdContext *cc = go_component_get_command_context ();
		IOContext *io_context = gnumeric_io_context_new (cc);
		GsfInput *input = gsf_input_memory_new (component->data, component->length, FALSE);
	
		g_object_set (G_OBJECT (io_context), "exec-main-loop", FALSE, NULL);
		wv = wb_view_new_from_input (input, NULL, io_context, NULL);
		g_object_unref (io_context);
	}
	uifilename =  "Gnumeric-embed.xml";
	extra_actions = actions;
	nb_extra_actions = G_N_ELEMENTS (actions);
	gognm->edited = WORKBOOK_CONTROL_GUI (workbook_control_gui_new (wv, NULL, NULL));
	g_object_set_data (G_OBJECT (gognm->edited), "component", gognm);
	g_signal_connect_swapped (gognm->edited->toplevel, "destroy",
					G_CALLBACK (editor_destroyed_cb), gognm);
	return TRUE;
}

static void
go_gnm_component_finalize (GObject *obj)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (obj);
	if (gognm->wv != NULL) {
		g_object_unref (gognm->wv);
		gognm->wv = NULL;
	}
	if (gognm->edited != NULL) {
		g_object_unref (wb_control_view (WORKBOOK_CONTROL (gognm->edited)));
		gognm->edited = NULL;
	}
	G_OBJECT_CLASS (gognm_parent_klass)->finalize (obj);
}

static void
go_gnm_component_init (GOComponent *component)
{
	GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
	component->resizable = FALSE;
	component->editable = TRUE;
	component->needs_window = FALSE;
537 538
	gognm->row_start = gognm->col_start = 0;
	gognm->sheet = NULL;
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	gognm->row_end = 9;
	gognm->col_end = 4;
}

static void
go_gnm_component_class_init (GOComponentClass *klass)
{
	GObjectClass *obj_klass = (GObjectClass *) klass;
	obj_klass->finalize = go_gnm_component_finalize;

	gognm_parent_klass = (GObjectClass*) g_type_class_peek_parent (klass);

	klass->get_data = go_gnm_component_get_data;
	klass->set_data = go_gnm_component_set_data;
	klass->draw = go_gnm_component_draw;
	klass->print = go_gnm_component_print;
	klass->edit = go_gnm_component_edit;
}

GSF_DYNAMIC_CLASS (GOGnmComponent, go_gnm_component,
	go_gnm_component_class_init, go_gnm_component_init,
	GO_COMPONENT_TYPE)

/*************************************************************************************/
extern GType gnm_plugin_loader_module_get_type (void);

G_MODULE_EXPORT void
go_plugin_init (GOPlugin *plugin, GOCmdContext *cc)
{
	GTypeModule *module;
	char const *env_var;
	GSList *dir_list;
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
#ifdef ENABLE_NLS
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif
	module = go_plugin_get_type_module (plugin);
	go_gnm_component_register_type (module);
	gnm_common_init (FALSE);
	dir_list = go_slist_create (
		g_build_filename (gnm_sys_lib_dir (), PLUGIN_SUBDIR, NULL),
		(gnm_usr_dir () == NULL ? NULL :
			g_build_filename (gnm_usr_dir (), PLUGIN_SUBDIR, NULL)),
		NULL);
	dir_list = g_slist_concat (dir_list,
		go_string_slist_copy (gnm_app_prefs->plugin_extra_dirs));

	env_var = g_getenv ("GNUMERIC_PLUGIN_PATH");
	if (env_var != NULL)
		GO_SLIST_CONCAT (dir_list, go_strsplit_to_slist (env_var, G_SEARCHPATH_SEPARATOR));

590
/* WHERE IS THIS DEFINED */
591 592 593 594 595 596 597 598 599 600 601
	go_plugins_add (go_component_get_command_context (),
		gnm_app_prefs->plugin_file_states,
		gnm_app_prefs->active_plugins,
		dir_list,
		gnm_plugin_loader_module_get_type ());
}

G_MODULE_EXPORT void
go_plugin_shutdown (GOPlugin *plugin, GOCmdContext *cc)
{
}