Commit 86a1dc8b authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Miguel de Icaza

Remove stf plugin from here. And from here.

2000-02-18  Miguel de Icaza  <miguel@gnu.org>

	* configure.in (EXTRA_GNOME_CFLAGS): Remove stf plugin from here.
	* plugins/Makefile.am (SUBDIRS): And from here.

	* src/stf.c (stf_open_and_read): Use malloc instead of g_malloc0
	because g_malloc aborts execution if the buffer is too large
	(which it might likely be).
	(stf_read_workbook): Release using free, not g_free here.
	(stf_read_workbook): Fix sheet object memory leak.
	(stf_init): Kill old and unused code.
parent 617208cd
2000-02-18 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Remove stf plugin from here.
* plugins/Makefile.am (SUBDIRS): And from here.
* src/stf.c (stf_open_and_read): Use malloc instead of g_malloc0
because g_malloc aborts execution if the buffer is too large
(which it might likely be).
(stf_read_workbook): Release using free, not g_free here.
(stf_read_workbook): Fix sheet object memory leak.
(stf_init): Kill old and unused code.
2000-02-18 Michael Meeks <michael@helixcode.com>
* src/workbook.c (workbook_new): setup view history.
......
2000-02-18 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Remove stf plugin from here.
* plugins/Makefile.am (SUBDIRS): And from here.
* src/stf.c (stf_open_and_read): Use malloc instead of g_malloc0
because g_malloc aborts execution if the buffer is too large
(which it might likely be).
(stf_read_workbook): Release using free, not g_free here.
(stf_read_workbook): Fix sheet object memory leak.
(stf_init): Kill old and unused code.
2000-02-18 Michael Meeks <michael@helixcode.com>
* src/workbook.c (workbook_new): setup view history.
......
......@@ -330,7 +330,6 @@ plugins/xbase/Makefile
plugins/html/Makefile
plugins/dif/Makefile
plugins/plan-perfect/Makefile
plugins/ff-stf/Makefile
intl/Makefile
po/Makefile.in
macros/Makefile
......
......@@ -24,4 +24,4 @@ else
GB_DIR =
endif
SUBDIRS = sample excel lotus-123 oleo sc sylk ff-csv text xbase html dif ff-stf $(PYTHON) $(GUILE_DIR) $(GB_DIR)
SUBDIRS = sample excel lotus-123 oleo sc sylk ff-csv text xbase html dif $(PYTHON) $(GUILE_DIR) $(GB_DIR)
......@@ -172,6 +172,10 @@ GNUMERIC_BASE_SOURCES = \
sort.h \
str.c \
str.h \
stf.c \
stf.h \
stf-parse.c \
stf-parse.h \
style.c \
style.h \
summary.c \
......
......@@ -20,6 +20,9 @@
#include "workbook-view.h"
#include "ranges.h"
#include "dialog-stf.h"
#include "stf-parse.h"
/*
* Callback information.
*
......@@ -189,92 +192,90 @@ do_clipboard_paste_cell_region (CommandContext *context,
cell_queue_recalc_list (deps, TRUE);
}
static GList *
new_node (GList *list, char const *data, char const *p, int col, int row)
static CellRegion *
x_selection_to_cell_region (char const * data, int len)
{
CellCopy *c_copy;
DialogStfResult_t *dialogresult;
CellRegion *cr = NULL;
CellRegion *crerr;
crerr = g_new (CellRegion, 1);
crerr->list = NULL;
crerr->cols = -1;
crerr->rows = 0;
crerr->styles = NULL;
/* End of FIXME */
if (!stf_parse_convert_to_unix (data)) {
g_free ( (char*) data);
g_warning (_("Error while trying to pre-convert clipboard data"));
return crerr;
}
/* Eliminate spaces */
while (*data == ' ' && *data)
data++;
if (!stf_parse_is_valid_data (data)) {
c_copy = g_new (CellCopy, 1);
c_copy->type = CELL_COPY_TYPE_TEXT;
c_copy->col_offset = col;
c_copy->row_offset = row;
c_copy->u.text = g_strndup (data, p-data);
g_free ( (char*) data);
g_warning (_("This data on the clipboard does not seem to be valid text"));
return crerr;
}
return g_list_prepend (list, c_copy);
}
dialogresult = dialog_stf (NULL, "clipboard", data);
/**
* x_selection_to_cell_region:
* @data: points to an array of chars are received.
* @len: The length of the @data buffer as received.
*
* Creates a CellRegion based on the X selection
*
* We use \t, ; and "," as cell separators
* \n is a line separator
*/
static CellRegion *
x_selection_to_cell_region (char const * data, int len)
{
CellRegion *cr;
int cols = 1, cur_col = 0;
int rows = 0;
GList *list = NULL;
char const *p = data;
gboolean not_comma_decimal, not_semicolon_decimal;
/* Points to the locale information for number display */
static struct lconv *lc = NULL;
if (!lc)
lc = localeconv ();
g_return_val_if_fail (lc != NULL, NULL);
/* Do not use something as a seperator if it is a decimal point.
* This is not perfect. There is no way to handle thousands seperators
*/
not_comma_decimal = NULL == strchr (lc->decimal_point, ',');
not_semicolon_decimal = NULL == strchr (lc->decimal_point, ';');
for (;--len >= 0; p++){
if (*p == '\t' || *p == '\n' ||
(*p == ',' && not_comma_decimal) ||
(*p == ';' && not_semicolon_decimal)) {
if (p != data)
list = new_node (list, data, p, cur_col, rows);
cur_col++;
if (cur_col > cols)
cols = cur_col;
if (*p == '\n'){
if (p [1])
rows++;
cur_col = 0;
}
if (dialogresult != NULL) {
GSList *iterator;
int col, rowcount;
cr = stf_parse_region (dialogresult->parseoptions, dialogresult->newstart);
if (cr == NULL) {
data = p+1;
g_free ( (char*) data);
g_warning (_("Parse error while trying to parse data into cellregion"));
return crerr;
}
}
/* Handle the remainings */
if (p != data) {
list = new_node (list, data, p, cur_col, rows);
cur_col++;
if (cur_col > cols)
cols = cur_col;
}
iterator = dialogresult->formats;
col = 0;
rowcount = stf_parse_get_rowcount (dialogresult->parseoptions, dialogresult->newstart);
while (iterator) {
StyleRegion *region = g_new (StyleRegion, 1);
MStyle *style = mstyle_new ();
Range range;
mstyle_set_format (style, iterator->data);
range.start.col = col;
range.start.row = 0;
range.end.col = col;
range.end.row = rowcount;
region->style = style;
region->range = range;
/* FIXME : I Wonder who actually frees these StyleRegions, I am not
* sure if this is done automatically... (I think it should though)
* my observation is that neither sheet_paste_selection nor sheet_style_attach_list
* frees these structs...
* IS THIS A MEMORY LEAK?
*/
cr->styles = g_list_prepend (cr->styles, region);
iterator = g_slist_next (iterator);
col++;
}
/* Return the CellRegion */
cr = g_new (CellRegion, 1);
cr->list = list;
cr->cols = cols ? cols : 1;
cr->rows = rows + 1;
cr->styles = NULL;
dialog_stf_result_free (dialogresult);
}
else {
return crerr;
}
g_free (crerr);
return cr;
}
......@@ -290,6 +291,10 @@ sheet_paste_selection (CommandContext *context, Sheet *sheet,
int paste_height, paste_width;
int end_col, end_row;
/* If 'cols' is set to -1 then there is _nothing_ to paste */
if (content->cols == -1)
return;
/* Compute the bigger bounding box (selection u clipboard-region) */
if (ss->user.end.col - ss->user.start.col + 1 > content->cols)
paste_width = ss->user.end.col - ss->user.start.col + 1;
......
......@@ -37,6 +37,14 @@ libdialogs_a_SOURCES = \
dialog-printer-setup.c \
dialog-simple-input.c \
dialog-solver.c \
dialog-stf.c \
dialog-stf.h \
dialog-stf-main-page.c \
dialog-stf-csv-page.c \
dialog-stf-fixed-page.c \
dialog-stf-format-page.c \
dialog-stf-preview.c \
dialog-stf-preview.h \
dialog-summary.c \
dialog-zoom.c \
utils-dialog.c \
......@@ -69,6 +77,7 @@ glade_DATA = \
delete-cells.glade \
cell-format.glade \
cell-sort.glade \
dialog-stf.glade \
plugin-manager.glade
glade_msgs = \
......@@ -94,6 +103,7 @@ glade_msgs = \
dialog-zoom.glade.h \
cell-format.glade.h \
cell-sort.glade.h \
dialog-stf.glade.h \
plugin-manager.glade.h
EXTRA_DIST = $(glade_DATA) $(glade_msgs)
......
/*
* dialog-stf.c : Controls the widget on the CSV (Comma Separated Value) page of the druid
*
* Almer. S. Tigelaar <almer1@dds.nl>
*
*/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include "dialog-stf.h"
/*************************************************************************************************
* MISC UTILITY FUNCTIONS
*************************************************************************************************/
/*************************************************************************************************
* SIGNAL HANDLERS
*************************************************************************************************/
/**
* csv_page_global_change
* @widget : the widget which emmited the signal
* @data : mother struct
*
* This will update the preview based on the state of
* the widgets on the csv page
*
* returns : nothing
**/
static void
csv_page_global_change (GtkWidget *widget, DruidPageData_t *data)
{
CsvInfo_t *info = data->csv_info;
StfParseOptions_t *parseoptions = info->csv_run_parseoptions;
GSList *list;
char *textfieldtext;
gboolean customvalid = FALSE;
stf_parse_options_before_modification (parseoptions);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_custom))) {
char *csvcustomtext = gtk_editable_get_chars (GTK_EDITABLE (info->csv_customseparator), 0, -1);
if (strcmp (csvcustomtext, "") != 0) {
stf_parse_options_csv_set_customfieldseparator (parseoptions, csvcustomtext[0]);
customvalid = TRUE;
}
}
stf_parse_options_csv_set_separators (parseoptions,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_tab)),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_colon)),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_comma)),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_space)),
customvalid);
textfieldtext = gtk_editable_get_chars (GTK_EDITABLE (info->csv_textfield), 0, -1);
stf_parse_options_csv_set_stringindicator (parseoptions, textfieldtext[0]);
stf_parse_options_csv_set_duplicates (parseoptions,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->csv_duplicates)));
/* Check if we actually changed something and invalidate the cache if necessary */
if (stf_parse_options_after_modification (parseoptions)) {
int i;
data->colcount = stf_parse_get_colcount (parseoptions, data->cur);
stf_cache_options_invalidate (info->csv_run_cacheoptions);
stf_preview_colwidths_clear (info->csv_run_renderdata);
for (i = 0; i < data->colcount + 1; i++)
stf_preview_colwidths_add (info->csv_run_renderdata, stf_parse_get_colwidth (parseoptions, data->cur, i));
}
/* actually do the parsing and rendering */
stf_cache_options_set_range (info->csv_run_cacheoptions,
info->csv_run_renderdata->startrow - 1,
(info->csv_run_renderdata->startrow - 1) + info->csv_run_displayrows);
list = stf_parse_general_cached (parseoptions,
info->csv_run_cacheoptions);
stf_preview_render (info->csv_run_renderdata,
list,
info->csv_run_displayrows,
data->colcount);
}
/**
* csv_page_scroll_value_changed
* @adjustment : The gtkadjustment that emitted the signal
* @data : a mother struct
*
* This signal responds to changes in the scrollbar and
* will force a redraw of the preview
*
* returns : nothing
**/
static void
csv_page_scroll_value_changed (GtkAdjustment *adjustment, DruidPageData_t *data)
{
CsvInfo_t *info = data->csv_info;
stf_preview_set_startrow (info->csv_run_renderdata, adjustment->value);
csv_page_global_change (NULL, data);
}
/**
* csv_page_custom_toggled
* @button : the Checkbutton that emmited the signal
* @data : a mother struct
*
* This will nicely activate the @data->csv_info->csv_customseparator widget
* so the user can enter text into it.
* It will also gray out this widget if the @button is not selected.
*
* returns : nothing
**/
static void
csv_page_custom_toggled (GtkCheckButton *button, DruidPageData_t *data)
{
CsvInfo_t *info = data->csv_info;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
gtk_widget_set_sensitive (GTK_WIDGET (info->csv_customseparator), TRUE);
gtk_widget_grab_focus (GTK_WIDGET (info->csv_customseparator));
gtk_editable_select_region (GTK_EDITABLE (info->csv_customseparator), 0, -1);
}
else {
gtk_widget_set_sensitive (GTK_WIDGET (info->csv_customseparator), FALSE);
gtk_editable_select_region (GTK_EDITABLE (info->csv_customseparator), 0, 0); /* If we don't use this the selection will remain blue */
}
csv_page_global_change (NULL, data);
}
/*************************************************************************************************
* CSV EXPORTED FUNCTIONS
*************************************************************************************************/
/**
* csv_page_prepare
* @page : The druidpage that emmitted the signal
* @druid : The gnomedruid that houses @page
* @data : mother struct
*
* Will prepare the csv page
*
* returns : nothing
**/
void
csv_page_prepare (GnomeDruidPage *page, GnomeDruid *druid, DruidPageData_t *pagedata)
{
CsvInfo_t *info = pagedata->csv_info;
if (pagedata->cur != info->csv_run_cacheoptions->data || pagedata->importlines != info->csv_run_parseoptions->parselines) {
stf_parse_options_set_lines_to_parse (info->csv_run_parseoptions, pagedata->importlines);
stf_cache_options_set_data (info->csv_run_cacheoptions, info->csv_run_parseoptions, pagedata->cur);
}
stf_cache_options_invalidate (info->csv_run_cacheoptions);
pagedata->colcount = stf_parse_get_colcount (info->csv_run_parseoptions, pagedata->cur);
GTK_RANGE (info->csv_scroll)->adjustment->upper = stf_parse_get_rowcount (info->csv_run_parseoptions, pagedata->cur) + 1;
gtk_adjustment_changed (GTK_RANGE (info->csv_scroll)->adjustment);
stf_preview_set_startrow (info->csv_run_renderdata, GTK_RANGE (info->csv_scroll)->adjustment->value);
/* Calling this routine will also automatically call global change which updates the preview too */
csv_page_custom_toggled (info->csv_custom, pagedata);
/* Calling this routine will also automatically call global change which updates the preview too */
csv_page_custom_toggled (info->csv_custom, pagedata);
}
/**
* csv_page_cleanup
* @pagedata : mother struct
*
* Will cleanup csv page run-time data
*
* returns : nothing
**/
void
csv_page_cleanup (DruidPageData_t *pagedata)
{
CsvInfo_t *info = pagedata->csv_info;
stf_cache_options_free (info->csv_run_cacheoptions);
info->csv_run_cacheoptions = NULL;
if (info->csv_run_parseoptions) {
stf_parse_options_free (info->csv_run_parseoptions);
info->csv_run_parseoptions = NULL;
}
stf_preview_free (info->csv_run_renderdata);
info->csv_run_renderdata = NULL;
}
/**
* csv_page_init
* @gui : The glade gui of the dialog
* @pagedata : pagedata mother struct passed to signal handlers etc.
*
* This routine prepares/initializes all widgets on the CSV Page of the
* Druid.
*
* returns : nothing
**/
void
csv_page_init (GladeXML *gui, DruidPageData_t *pagedata)
{
CsvInfo_t *info;
g_return_if_fail (gui != NULL);
g_return_if_fail (pagedata != NULL);
g_return_if_fail (pagedata->csv_info != NULL);
info = pagedata->csv_info;
/* Create/get object and fill information struct */
info->csv_tab = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_tab"));
info->csv_colon = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_colon"));
info->csv_comma = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_comma"));
info->csv_space = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_space"));
info->csv_custom = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_custom"));
info->csv_customseparator = GTK_ENTRY (glade_xml_get_widget (gui, "csv_customseparator"));
info->csv_duplicates = GTK_CHECK_BUTTON (glade_xml_get_widget (gui, "csv_duplicates"));
info->csv_textindicator = GTK_COMBO (glade_xml_get_widget (gui, "csv_textindicator"));
info->csv_textfield = GTK_ENTRY (glade_xml_get_widget (gui, "csv_textfield"));
info->csv_canvas = GNOME_CANVAS (glade_xml_get_widget (gui, "csv_canvas"));
info->csv_scroll = GTK_VSCROLLBAR (glade_xml_get_widget (gui, "csv_scroll"));
/* Set properties */
info->csv_run_renderdata = stf_preview_new (info->csv_canvas, FALSE);
info->csv_run_parseoptions = stf_parse_options_new ();
info->csv_run_cacheoptions = stf_cache_options_new ();
info->csv_run_displayrows = stf_preview_get_displayed_rowcount (info->csv_run_renderdata);
stf_parse_options_set_type (info->csv_run_parseoptions, PARSE_TYPE_CSV);
stf_cache_options_set_data (info->csv_run_cacheoptions, info->csv_run_parseoptions, pagedata->cur);
/* Connect signals */
gtk_signal_connect (GTK_OBJECT (info->csv_tab),
"toggled",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_colon),
"toggled",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_comma),
"toggled",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_space),
"toggled",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_custom),
"toggled",
GTK_SIGNAL_FUNC (csv_page_custom_toggled),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_customseparator),
"changed",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_duplicates),
"toggled",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (info->csv_textfield),
"changed",
GTK_SIGNAL_FUNC (csv_page_global_change),
pagedata);
gtk_signal_connect (GTK_OBJECT (GTK_RANGE (info->csv_scroll)->adjustment),
"value_changed",
GTK_SIGNAL_FUNC (csv_page_scroll_value_changed),
pagedata);
}
/*
* dialog-stf.c : Controls the widgets on the fixed page of the dialog (fixed-width page that is)
*
* Almer. S. Tigelaar <almer1@dds.nl>
*
*/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include <stdlib.h>
#include "dialog-stf.h"
/*************************************************************************************************
* MISC UTILITY FUNCTIONS
*************************************************************************************************/
/**
* fixed_page_update_preview
* @pagedata : mother struct
*
* Will simply update the preview
*
* returns : nothing
**/
static void
fixed_page_update_preview (DruidPageData_t *pagedata)
{
FixedInfo_t *info = pagedata->fixed_info;
StfParseOptions_t *parseoptions = pagedata->fixed_info->fixed_run_parseoptions;
GSList *list;
char *t[2];
int i, temp;
stf_parse_options_before_modification (parseoptions);
stf_parse_options_fixed_splitpositions_clear (parseoptions);
for (i = 0; i < info->fixed_collist->rows; i++) {
gtk_clist_get_text (info->fixed_collist, i, 1, t);
temp = atoi (t[0]);
stf_parse_options_fixed_splitpositions_add (parseoptions, temp);
}
if (stf_parse_options_after_modification (parseoptions)) {
stf_cache_options_invalidate (info->fixed_run_cacheoptions);
pagedata->colcount = stf_parse_get_colcount (parseoptions, pagedata->cur);
stf_preview_colwidths_clear (info->fixed_run_renderdata);
for (i = 0; i < pagedata->colcount + 1; i++)
stf_preview_colwidths_add (info->fixed_run_renderdata, stf_parse_get_colwidth (parseoptions, pagedata->cur, i));
}
stf_cache_options_set_range (info->fixed_run_cacheoptions,
info->fixed_run_renderdata->startrow - 1,
(info->fixed_run_renderdata->startrow - 1) + info->fixed_run_displayrows);
list = stf_parse_general_cached (parseoptions,
info->fixed_run_cacheoptions);
stf_preview_render (info->fixed_run_renderdata,
list,
info->fixed_run_displayrows,
pagedata->colcount);
}
/*************************************************************************************************
* SIGNAL HANDLERS
*************************************************************************************************/
/**
* fixed_page_scroll_value_changed
* @adjustment : The gtkadjustment that emitted the signal
* @data : a mother struct
*
* This signal responds to changes in the scrollbar and
* will force a redraw of the preview
*
* returns : nothing
**/
static void
fixed_page_scroll_value_changed (GtkAdjustment *adjustment, DruidPageData_t *data)
{
FixedInfo_t *info = data->fixed_info;
stf_preview_set_startrow (info->fixed_run_renderdata, adjustment->value);
fixed_page_update_preview (data);
}
static gboolean
fixed_page_canvas_motion_notify_event (GnomeCanvas *canvas, GdkEventMotion *event, DruidPageData_t *data)
{
FixedInfo_t *info = data->fixed_info;
GdkCursor *cursor;
double worldx, worldy;
int column;
gnome_canvas_window_to_world (canvas, event->x, event->y, &worldx, &worldy);
column = stf_preview_get_column_border_at_x (info->fixed_run_renderdata, worldx);
if (column != -1 || info->fixed_run_mousedown) {
cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
gdk_window_set_cursor (canvas->layout.bin_window, cursor);
gdk_cursor_destroy (cursor);
/* This is were the actual resizing is done, now we simply wait till
* the user moves the mouse "width in pixels of a char" pixels
* after that we reset the x_position and adjust the column end and
* wait till the same thing happens again
*/
if (info->fixed_run_mousedown) {
char *t[1];
double diff;
int min, max;
int colend, chars;
diff = worldx - info->fixed_run_xorigin;
chars = diff / info->fixed_run_renderdata->charwidth;
if (chars != 0) {
info->fixed_run_xorigin = worldx;
gtk_clist_get_text (info->fixed_collist, info->fixed_run_column, 1, t);
colend = atoi (t[0]);
if (info->fixed_run_column > 0) {
gtk_clist_get_text (info->fixed_collist, info->fixed_run_column - 1, 1, t);
min = atoi (t[0]) + 1;
} else
min = 1;
if (info->fixed_run_column < info->fixed_collist->rows - 2) {
gtk_clist_get_text (info->fixed_collist, info->fixed_run_column + 1, 1, t);
max = atoi (t[0]) - 1;
} else {
GtkAdjustment *spinadjust = gtk_spin_button_get_adjustment (info->fixed_colend);
max = spinadjust->upper;
}
colend += chars;
if (colend < min)
colend = min;
if (colend > max)
colend = max;
gtk_clist_select_row (info->fixed_collist, info->fixed_run_column, 0);
gtk_spin_button_set_value (info->fixed_colend, colend);
fixed_page_update_preview (data);
}