Commit fc3936ee authored by Jean Bréfort's avatar Jean Bréfort Committed by Jean Bréfort

add component directory. add a goffice component. ditto. ditto. ditto. add

2006-05-12  Jean Brefort  <jean.brefort@normalesup.org>

	* Makefile.am: add component directory.
	* component/Gnumeric-embed.xml.in: add a goffice component.
	* component/Makefile.am: ditto.
	* component/gnumeric.c: ditto.
	* component/plugin.xml.in: ditto.
	* configure.in: add support for the component.
	* src/gnm-plugin.c: make GnmPluginLoaderModule public.
	* src/gnm-so-filled.c: (gnm_so_filled_draw_cairo),
	(gnm_so_filled_class_init): render using cairo.
	* src/sheet-object-impl.h: add a draw_cairo method.
	* src/sheet-object.c: (sheet_object_draw_cairo): implement the
	new functionality.
	* src/sheet-object.h: ditto.
	* src/wbc-gtk.c: (wbc_gtk_init): add support for customized ui.
parent 56933cc5
2006-05-12 Jean Brefort <jean.brefort@normalesup.org>
* Makefile.am: add component directory.
* component/Gnumeric-embed.xml.in: add a goffice component.
* component/Makefile.am: ditto.
* component/gnumeric.c: ditto.
* component/plugin.xml.in: ditto.
* configure.in: add support for the component.
* src/gnm-plugin.c: make GnmPluginLoaderModule public.
* src/gnm-so-filled.c: (gnm_so_filled_draw_cairo),
(gnm_so_filled_class_init): render using cairo.
* src/sheet-object-impl.h: add a draw_cairo method.
* src/sheet-object.c: (sheet_object_draw_cairo): implement the
new functionality.
* src/sheet-object.h: ditto.
* src/wbc-gtk.c: (wbc_gtk_init): add support for customized ui.
2006-05-11 Christian Neumair <chris@gnome-de.org>
* src/Makefile.am:
......
SUBDIRS = . po po-functions src plugins icons templates doc schemas
SUBDIRS = . po po-functions src plugins icons templates doc schemas component
if WITH_WIN32
SUBDIRS += tools
endif
......
<?xml version="1.0" encoding="UTF-8"?>
<ui>
<menubar>
<menu name="File" action="MenuFile">
<!-- <menuitem action="FileNew"/>
<menuitem action="FileOpen"/>
<separator name="file-sep1"/>-->
<menuitem action="FileSaveEmbed"/>
<!-- <menuitem action="FileSaveAs"/>
<separator name="file-sep2"/>
<menuitem action="FilePageSetup"/>
<menuitem action="FilePrintPreview"/>
<menuitem action="FilePrint"/>
<separator name="file-sep3"/>
<menuitem action="FileSend"/>
<menuitem action="FileMetaData"/>
<menuitem action="FilePreferences"/>
<separator name="file-sep4"/>
<placeholder name="FileHistory" />
<separator name="file-sep5"/>-->
<menuitem action="FileClose"/>
<!-- <menuitem action="FileQuit"/>-->
</menu>
<menu name="Edit" action="MenuEdit">
<menuitem action="Undo"/>
<menuitem action="Redo"/>
<separator name="edit-sep1"/>
<menuitem action="EditCut"/>
<menuitem action="EditCopy"/>
<menuitem action="EditPaste"/>
<menuitem action="EditPasteSpecial"/>
<!--TODO menuitem action="EditPasteLink" -->
<separator name="edit-sep2"/>
<menu name="Fill" action="MenuEditFill">
<menuitem action="EditFillAutofill"/>
<menuitem action="ToolsMerge"/>
<menuitem action="ToolsTabulate"/>
<menuitem action="EditFillSeries"/>
<menuitem action="RandomGenerator"/>
</menu>
<menu name="Clear" action="MenuEditClear">
<menuitem action="EditClearAll"/>
<menuitem action="EditClearFormats"/>
<menuitem action="EditClearComments"/>
<menuitem action="EditClearContent"/>
</menu>
<menu name="Delete" action="MenuEditDelete">
<menuitem action="EditDeleteColumns"/>
<menuitem action="EditDeleteRows"/>
<menuitem action="EditDeleteCells"/>
</menu>
<separator name="edit-sep3"/>
<menuitem action="EditFind"/>
<menuitem action="EditReplace"/>
<menuitem action="EditGoto"/>
<separator name="edit-sep4"/>
<menu name="EditSheet" action="MenuEditSheet">
<menuitem action="SheetReorder"/>
<separator/>
<menuitem action="InsertSheet"/>
<menuitem action="InsertSheetAtEnd"/>
<menuitem action="EditDuplicateSheet"/>
<menuitem action="SheetRemove"/>
<menuitem action="SheetChangeName"/>
</menu>
<menu name="Select" action="MenuEditSelect">
<menuitem action="EditSelectAll"/>
<menuitem action="EditSelectColumn"/>
<menuitem action="EditSelectRow"/>
<menuitem action="EditSelectArray"/>
<menuitem action="EditSelectDepends"/>
<menuitem action="EditSelectInputs"/>
</menu>
<menuitem action="EditRecalc"/>
<placeholder name="ops"/>
</menu>
<menu name="View" action="MenuView">
<menuitem action="ViewNew"/>
<menuitem action="ViewFreezeThawPanes"/>
<menu name="Windows" action="MenuViewWindows">
</menu>
<separator/>
<menu name="Toolbars" action="MenuViewToolbars">
</menu>
<menuitem action="ViewStatusbar"/>
<menuitem action="ViewFullScreen"/>
<menuitem action="ViewZoom"/>
</menu>
<menu name="Insert" action="MenuInsert">
<menuitem action="InsertCells"/>
<menuitem action="InsertColumns"/>
<menuitem action="InsertRows"/>
<menuitem action="SheetInsert"/>
<separator/>
<menuitem action="ChartGuru"/>
<!-- These don't work yet for Gnome 2
<menuitem action="InsertComponent" />
<menuitem action="InsertShapedComponent" />
<separator/>
-->
<menuitem action="InsertImage"/>
<menuitem action="InsertFormula"/>
<menu name="Names" action="MenuInsertNames">
<menuitem action="EditNames"/>
</menu>
<menuitem action="InsertComment"/>
<menuitem action="InsertHyperlink"/>
<menu name="Special" action="MenuInsertSpecial">
<menuitem action="InsertCurrentDate"/>
<menuitem action="InsertCurrentTime"/>
<menuitem action="InsertCurrentDateTime"/>
</menu>
</menu>
<menu name="Format" action="MenuFormat">
<menuitem action="FormatCells"/>
<menu name="FormatColumn" action="MenuFormatColumn">
<menuitem action="ColumnSize"/>
<menuitem action="ColumnAutoSize"/>
<menuitem action="ColumnHide"/>
<menuitem action="ColumnUnhide"/>
<menuitem action="ColumnDefaultSize"/>
</menu>
<menu name="FormatRow" action="MenuFormatRow">
<menuitem action="RowSize"/>
<menuitem action="RowAutoSize"/>
<menuitem action="RowHide"/>
<menuitem action="RowUnhide"/>
<menuitem action="RowDefaultSize"/>
</menu>
<menu name="FormatSheets" action="MenuFormatSheet">
<menuitem action="SheetReorder"/>
<menuitem action="SheetChangeName"/>
<separator/>
<menuitem action="SheetDisplayFormulas"/>
<menuitem action="SheetUseR1C1"/>
<menuitem action="SheetHideZeros"/>
<menuitem action="SheetHideGridlines"/>
<menuitem action="SheetHideColHeader"/>
<menuitem action="SheetHideRowHeader"/>
</menu>
<menuitem action="FormatWorkbook"/>
<menuitem action="FilePreferences"/>
<menuitem action="FormatAuto"/>
</menu>
<menu name="Tools" action="MenuTools">
<menuitem action="ToolsPlugins"/>
<separator name="tools-sep1"/>
<menuitem action="ToolsAutoCorrect"/>
<menuitem action="ToolsAutoSave"/>
<separator name="tools-sep2"/>
<menuitem action="ToolsGoalSeek"/>
<menuitem action="ToolsSolver"/>
<menu name="Scenarios" action="MenuToolsScenarios">
<menuitem action="ToolsScenarios"/>
<menuitem action="ToolsScenarioAdd"/>
</menu>
<menuitem action="ToolsSimulation"/>
<separator/>
<menu name="ToolStatisticalAnalysis" action="MenuToolStatisticalAnalysis">
<menu name="ANOVA" action="MenuANOVA">
<menuitem action="ToolsANOVAoneFactor"/>
<menuitem action="ToolsANOVAtwoFactor"/>
</menu>
<menuitem action="ToolsCorrelation"/>
<menuitem action="ToolsCovariance"/>
<menuitem action="ToolsDescStatistics"/>
<menu name="ToolForecast" action="MenuToolForecast">
<menuitem action="ToolsExpSmoothing"/>
<menuitem action="ToolsAverage"/>
</menu>
<menuitem action="ToolsFourier"/>
<menuitem action="ToolsHistogram"/>
<menuitem action="ToolsRanking"/>
<menuitem action="ToolsRegression"/>
<menuitem action="ToolsSampling"/>
<menu name="ToolTTest" action="MenuToolTTest">
<menuitem action="ToolTTestPaired"/>
<menuitem action="ToolTTestEqualVar"/>
<menuitem action="ToolTTestUnequalVar"/>
<menuitem action="ToolZTest"/>
</menu>
<menuitem action="ToolsFTest"/>
</menu>
</menu>
<menu name="Data" action="MenuData">
<menuitem action="DataSort"/>
<menu name="Filter" action="MenuFilter">
<menuitem action="DataAutoFilter"/>
<menuitem action="DataFilterShowAll"/>
<menuitem action="DataFilterAdvancedfilter"/>
</menu>
<menuitem action="DataValidate"/>
<separator/>
<menuitem action="DataTextToColumns"/>
<menuitem action="DataConsolidate"/>
<menu name="Outline" action="MenuOutline">
<menuitem action="DataOutlineHideDetail"/>
<menuitem action="DataOutlineShowDetail"/>
<menuitem action="DataOutlineGroup"/>
<menuitem action="DataOutlineUngroup"/>
<separator/>
<menuitem action="SheetDisplayOutlines"/>
<menuitem action="SheetOutlineBelow"/>
<menuitem action="SheetOutlineRight"/>
</menu>
<!--
<menuitem action="PivotTable" />
-->
<menu name="ExternalData" action="MenuExternalData">
<menuitem action="DataImportText"/>
</menu>
</menu>
<menu name="Help" action="MenuHelp">
<menuitem action="HelpDocs"/>
<menuitem action="HelpWeb"/>
<menuitem action="HelpIRC"/>
<menuitem action="HelpBug"/>
<separator/>
<menuitem action="HelpAbout"/>
</menu>
</menubar>
<toolbar _name="StandardToolbar">
<!-- <toolitem action="FileNew"/>
<toolitem action="FileOpen"/> -->
<toolitem action="FileSaveEmbed"/>
<separator name="std-sep1"/>
<!-- <toolitem action="FilePrint"/>
<toolitem action="FilePrintPreview"/>
<separator name="std-sep2"/> -->
<toolitem action="EditCut"/>
<toolitem action="EditCopy"/>
<toolitem action="EditPaste"/>
<separator name="std-sep3"/>
<toolitem action="Undo"/>
<toolitem action="Redo"/>
<separator name="std-sep4"/>
<toolitem action="InsertHyperlink"/>
<toolitem action="AutoSum"/>
<toolitem action="InsertFormula"/>
<toolitem action="SortAscending"/>
<toolitem action="SortDescending"/>
<separator name="std-sep5"/>
<toolitem action="ChartGuru" />
<toolitem action="Zoom"/>
<toolitem action="Direction"/>
</toolbar>
<toolbar _name="FormatToolbar">
<toolitem action="FontName"/>
<toolitem action="FontSize"/>
<toolitem action="FontBold"/>
<toolitem action="FontItalic"/>
<toolitem action="FontUnderline"/>
<separator name="fmt-sep1"/>
<toolitem action="AlignLeft"/>
<toolitem action="AlignCenter"/>
<toolitem action="AlignRight"/>
<toolitem action="CenterAcrossSelection"/>
<toolitem action="FormatMergeCells"/>
<toolitem action="FormatUnmergeCells"/>
<separator name="fmt-sep2"/>
<toolitem action="FormatAsAccounting"/>
<toolitem action="FormatAsPercentage"/>
<toolitem action="FormatWithThousands"/>
<toolitem action="FormatIncreasePrecision"/>
<toolitem action="FormatDecreasePrecision"/>
<separator name="fmt-sep3"/>
<toolitem action="FormatDecreaseIndent"/>
<toolitem action="FormatIncreaseIndent"/>
<separator name="fmt-sep4"/>
<toolitem action="BorderSelector"/>
<toolitem action="ColorBack"/>
<toolitem action="ColorFore"/>
</toolbar>
<toolbar _name="ObjectToolbar">
<toolitem action="CreateLabel"/>
<toolitem action="CreateFrame"/>
<!-- Not useful until we have scripts
<toolitem action="CreateButton"/> -->
<!-- think about how to handle groups
<toolitem action="CreateRadioButton"/> -->
<toolitem action="CreateCheckbox"/>
<toolitem action="CreateScrollbar"/>
<toolitem action="CreateSpinButton"/>
<toolitem action="CreateSlider"/>
<toolitem action="CreateList"/>
<toolitem action="CreateCombo"/>
<toolitem action="CreateLine"/>
<toolitem action="CreateArrow"/>
<toolitem action="CreateRectangle"/>
<toolitem action="CreateEllipse"/>
</toolbar>
<accelerator name="CopyRight" action="CopyRight"/>
<accelerator name="CopyDown" action="CopyDown"/>
<accelerator name="FontBold" action="FontBold"/>
<accelerator name="FontItalic" action="FontItalic"/>
<accelerator name="FontUnderline" action="FontUnderline"/>
<accelerator name="FontDoubleUnderline" action="FontDoubleUnderline"/>
<accelerator name="FontSuperscript" action="FontSuperscript"/>
<accelerator name="FontSubscript" action="FontSubscript"/>
<accelerator name="FontStrikeThrough" action="FontStrikeThrough"/>
<accelerator name="FormatAsNumber" action="FormatAsNumber"/>
<accelerator name="FormatAsCurrency" action="FormatAsCurrency"/>
<accelerator name="FormatAsGeneral" action="FormatAsGeneral"/>
<accelerator name="FormatAsPercentage" action="FormatAsPercentage"/>
<accelerator name="FormatAsScientific" action="FormatAsScientific"/>
<accelerator name="FormatAsDate" action="FormatAsDate"/>
<accelerator name="FormatAsTime" action="FormatAsTime"/>
<accelerator name="FormatAddBorders" action="FormatAddBorders"/>
<accelerator name="FormatClearBorders" action="FormatClearBorders"/>
<accelerator name="Repeat" action="Repeat"/>
</ui>
goffice_gnumeric_LTLIBRARIES = gnumeric.la
goffice_gnumericdir = $(GOFFICE_PLUGINS_DIR)/gnumeric
gnumeric_la_LDFLAGS = -module -avoid-version -no-undefined
gnumeric_la_LIBADD = \
$(top_builddir)/src/libspreadsheet.la \
@GNUMERIC_LIBS@
xml_DATA = $(xml_in_files:.xml.in=.xml)
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_builddir)/src \
-DGNOMELOCALEDIR=\"$(datadir)/locale\" @GNUMERIC_CFLAGS@
gnumeric_la_SOURCES = \
gnumeric.c
xml_in_files = plugin.xml.in
xmldir = $(goffice_gnumericdir)
@INTLTOOL_XML_RULE@
gtkactiondir=$(gnumeric_datadir)
gtkaction_DATA = Gnumeric-embed.xml
Gnumeric-embed.xml: Gnumeric-embed.xml.in
sed -e 's/ _name *=/ name=/' <$< >$@
EXTRA_DIST = $(xml_in_files) Gnumeric-embed.xml.in
DISTCLEANFILES = $(xml_in_files:.xml.in=.xml) Gnumeric-embed.xml
/*
* 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 <cairo/cairo.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>
#include <rendered-value.h>
#include <workbook-view.h>
#include <workbook-control-gui-priv.h>
#include <workbook.h>
#include <sheet.h>
#include <sheet-object.h>
#include <command-context.h>
#include <command-context-stderr.h>
#include <cairo.h>
#include <pango/pangocairo.h>
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);
enum {
COMPONENT_PROP_0,
COMPONENT_PROP_START_ROW,
COMPONENT_PROP_END_ROW,
COMPONENT_PROP_START_COL,
COMPONENT_PROP_END_COL,
COMPONENT_PROP_SHEET,
};
typedef struct
{
GOComponent parent;
WorkbookView *wv;
WorkbookControlGUI *edited;
int sheet, col_start, col_end, row_start, row_end;
int width, height;
} GOGnmComponent;
/* Red and blue are inverted in a pixbuf compared to cairo */
static void
pixbuf_to_cairo (unsigned char *p, int width, int height, int rowstride)
{
int i,j;
unsigned char a;
guint t;
#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
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);
Sheet *sheet;
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);
sheet = workbook_sheet_by_index (wb_view_get_workbook (gognm->wv), gognm->sheet);
gognm->width = sheet_col_get_distance_pts (
sheet, gognm->col_start, gognm->col_end + 1);
component->width = gognm->width / 72.;
component->descent = 0.;
gognm->height = sheet_row_get_distance_pts (
sheet, gognm->row_start, gognm->row_end + 1);
component->ascent = gognm->height / 72.;
}
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_set_source_rgb (cairo, UINT_RGBA_R(fore_color), UINT_RGBA_G(fore_color), UINT_RGBA_B(fore_color));
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);
cairo_set_source_rgb (cairo, UINT_RGBA_B(fore_color), UINT_RGBA_G(fore_color), UINT_RGBA_R(fore_color));
if (rv->rotation) {
RenderedRotatedValue *rrv = (RenderedRotatedValue *)rv;
PangoContext *context = pango_layout_get_context (rv->layout);
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);
}
}
}
static void
go_gnm_component_draw (GOComponent *component, int width_pixels, int height_pixels)
{
GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
int col, row;
cairo_surface_t* surface ;
cairo_t *cairo;
GnmCell *cell;
Sheet *sheet;
double xoffset = 0., yoffset;
GSList *l;
SheetObject *so;
SheetObjectAnchor const *anchor;
gdk_pixbuf_fill (component->pixbuf, 0);
if (gognm->wv == NULL)
return;
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);
sheet = workbook_sheet_by_index (wb_view_get_workbook (gognm->wv), gognm->sheet);
for (col = gognm->col_start; col <= gognm->col_end; col++) {
yoffset = 0.;
for (row = gognm->row_start; row <= gognm->row_end; row++) {
cell = sheet_cell_get (sheet, col, row);
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);
}
yoffset += sheet_row_get_distance_pts (sheet, row, row + 1);
}
xoffset += sheet_col_get_distance_pts (sheet, col, col + 1);
}
/* Now render objects */
l = sheet->sheet_objects;
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 */
xoffset = sheet_col_get_distance_pts (sheet, gognm->col_start,
anchor->cell_bound.start.col);
yoffset = sheet_row_get_distance_pts (sheet, gognm->row_start,
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);
pixbuf_to_cairo (gdk_pixbuf_get_pixels (component->pixbuf),
width_pixels, height_pixels,
gdk_pixbuf_get_rowstride (component->pixbuf));
}
static void
go_gnm_component_print (GOComponent *component, GnomePrintContext *gpc,
double width, double height)
{
GOGnmComponent *gognm = GO_GNM_COMPONENT (component);
}
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"),
G_CALLBACK (cb_gognm_save) }
};
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);
}