Commit 043d57b0 authored by JP Rosevear's avatar JP Rosevear Committed by JP Rosevear

Small sort improvement, initial persistent attribute support (workbooks

2000-03-22  JP Rosevear  <jpr@arcavia.com>

	Small sort improvement, initial persistent attribute support
	(workbooks only).

	* src/xml-io.c (xml_arg_set): Set an arg value based on type and
	contents in the xml tree.
	(xml_arg_get): Get a string representing an arg's value.
	(xml_write_attributes): Create the list of attributes.
	(xml_free_arg_list): Function to free the args in a GList.
	(xml_read_attributes): Read the attributes back in from the
	xml tree.
	(xml_workbook_read): Read the workbook attributes in and set them.
	(xml_workbook_write): Write out the workbook attributes.

	* src/workbook.c (workbook_class_init): Add three args, the h & v
	scrollbars and the notebook tab.  Override parent set_arg and
	get_arg functions.
	(workbook_set_arg): New function to handle arg setting.
	(workbook_get_arg): New function to handle getting args.
	(workbook_set_attributev): Set a whole list of args for the
	object.
	(workbook_get_attributev): Return an array of args for the
	workbook.

	* src/workbook.c (sort_cmd): Sort all the columns in order so
	that ties are broken nicely (pointed out by meeks)
parent 10e9a53e
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
2000-03-22 JP Rosevear <jpr@arcavia.com>
* src/xml-io.c (xml_arg_set): Set an arg value based on type and
contents in the xml tree.
(xml_arg_get): Get a string representing an arg's value.
(xml_write_attributes): Create the list of attributes.
(xml_free_arg_list): Function to free the args in a GList.
(xml_read_attributes): Read the attributes back in from the
xml tree.
(xml_workbook_read): Read the workbook attributes in and set them.
(xml_workbook_write): Write out the workbook attributes.
* src/workbook.c (workbook_class_init): Add three args, the h & v
scrollbars and the notebook tab. Override parent set_arg and get_arg
functions.
(workbook_set_arg): New function to handle arg setting.
(workbook_get_arg): New function to handle getting args.
(workbook_set_attributev): Set a whole list of args for the object.
(workbook_get_attributev): Return an array of args for the workbook.
* src/workbook.c (sort_cmd): Sort all the columns in order so
that ties are broken nicely (pointed out by meeks)
2000-03-22 Jody Goldberg <jgoldberg@home.com>
* src/plugin.c (plugin_load) : Typo.
......
......@@ -57,6 +57,8 @@ struct _Workbook {
#else
GtkObject gtk_object;
#endif
/* Attribute list */
GList *attributes;
/* { Start view specific elements */
GtkWidget *toplevel;
......@@ -144,6 +146,9 @@ Workbook *workbook_new (void);
Workbook *workbook_core_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
void workbook_set_attributev (Workbook *wb, GList *list);
GtkArg *workbook_get_attributev (Workbook *wb, guint *n_args);
gboolean workbook_set_filename (Workbook *, const char *);
Workbook *workbook_try_read (CommandContext *context,
const char *filename);
......
......@@ -47,6 +47,11 @@
#include "workbook-private.h"
/* Persistent attribute ids */
#define ARG_VIEW_HSCROLLBAR 1
#define ARG_VIEW_VSCROLLBAR 2
#define ARG_VIEW_TABS 3
/* The locations within the main table in the workbook */
#define WB_EA_LINE 0
#define WB_EA_SHEETS 1
......@@ -71,6 +76,8 @@ static gint workbook_signals [LAST_SIGNAL] = {
0, /* SHEET_CHANGED, CELL_CHANGED */
};
static void workbook_set_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void workbook_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void workbook_set_focus (GtkWindow *window, GtkWidget *focus, Workbook *wb);
static int workbook_can_close (Workbook *wb);
......@@ -1047,7 +1054,8 @@ sort_cmd (Workbook *wb, int asc)
Sheet *sheet;
Range *sel;
SortClause *clause;
int numclause, i;
g_return_if_fail (wb != NULL);
g_return_if_fail (wb->current_sheet != NULL);
......@@ -1060,15 +1068,18 @@ sort_cmd (Workbook *wb, int asc)
return;
range_clip_to_finite (sel, sheet);
clause = g_new0 (SortClause, 1);
clause->offset = 0;
clause->asc = asc;
clause->cs = FALSE;
clause->val = FALSE;
numclause = sel->end.col - sel->start.col + 1;
clause = g_new0 (SortClause, numclause);
for (i=0; i < numclause; i++) {
clause[i].offset = i;
clause[i].asc = asc;
clause[i].cs = FALSE;
clause[i].val = FALSE;
}
cmd_sort ( workbook_command_context_gui (wb),
sheet, sel, clause, 1, TRUE);
sheet, sel, clause, numclause, TRUE);
}
static void
......@@ -2148,6 +2159,19 @@ workbook_class_init (GtkObjectClass *object_class)
{
workbook_parent_class = gtk_type_class (WORKBOOK_PARENT_CLASS_TYPE);
object_class->set_arg = workbook_set_arg;
object_class->get_arg = workbook_get_arg;
gtk_object_add_arg_type ("Workbook::show_horizontal_scrollbar",
GTK_TYPE_BOOL, GTK_ARG_READWRITE,
ARG_VIEW_HSCROLLBAR);
gtk_object_add_arg_type ("Workbook::show_vertical_scrollbar",
GTK_TYPE_BOOL, GTK_ARG_READWRITE,
ARG_VIEW_VSCROLLBAR);
gtk_object_add_arg_type ("Workbook::show_notebook_tabs",
GTK_TYPE_BOOL, GTK_ARG_READWRITE,
ARG_VIEW_TABS);
workbook_signals [SHEET_CHANGED] =
gtk_signal_new (
"sheet_changed",
......@@ -2465,6 +2489,76 @@ workbook_new (void)
return wb;
}
static void
workbook_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
Workbook *wb;
wb = WORKBOOK (object);
switch (arg_id) {
case ARG_VIEW_HSCROLLBAR:
wb->show_horizontal_scrollbar = GTK_VALUE_BOOL (*arg);
workbook_view_pref_visibility (wb);
case ARG_VIEW_VSCROLLBAR:
wb->show_vertical_scrollbar = GTK_VALUE_BOOL (*arg);
workbook_view_pref_visibility (wb);
case ARG_VIEW_TABS:
wb->show_notebook_tabs = GTK_VALUE_BOOL (*arg);
workbook_view_pref_visibility (wb);
}
}
static void
workbook_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
Workbook *wb;
wb = WORKBOOK (object);
switch (arg_id) {
case ARG_VIEW_HSCROLLBAR:
GTK_VALUE_BOOL (*arg) = wb->show_horizontal_scrollbar;
case ARG_VIEW_VSCROLLBAR:
GTK_VALUE_BOOL (*arg) = wb->show_vertical_scrollbar;
case ARG_VIEW_TABS:
GTK_VALUE_BOOL (*arg) = wb->show_notebook_tabs;
}
}
void
workbook_set_attributev (Workbook *wb, GList *list)
{
GtkArg *arg;
gint length, i;
length = g_list_length(list);
for (i=0; i<length; i++) {
arg = (GtkArg *) (g_list_nth_data (list, i));
gtk_object_arg_set (GTK_OBJECT(wb), arg, NULL);
}
}
GtkArg *
workbook_get_attributev (Workbook *wb, guint *n_args)
{
GtkArg *args;
guint num;
args = gtk_object_query_args (WORKBOOK_TYPE, NULL, &num);
gtk_object_getv (GTK_OBJECT(wb), num, args);
*n_args = num;
return args;
}
/**
* workbook_rename_sheet:
* @wb: the workbook where the sheet is
......
......@@ -57,6 +57,8 @@ struct _Workbook {
#else
GtkObject gtk_object;
#endif
/* Attribute list */
GList *attributes;
/* { Start view specific elements */
GtkWidget *toplevel;
......@@ -144,6 +146,9 @@ Workbook *workbook_new (void);
Workbook *workbook_core_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
void workbook_set_attributev (Workbook *wb, GList *list);
GtkArg *workbook_get_attributev (Workbook *wb, guint *n_args);
gboolean workbook_set_filename (Workbook *, const char *);
Workbook *workbook_try_read (CommandContext *context,
const char *filename);
......
......@@ -47,6 +47,34 @@ typedef struct {
* Internal stuff: xml helper functions.
*/
static void
xml_arg_set (GtkArg *arg, gchar *string)
{
switch (arg->type) {
case GTK_TYPE_BOOL:
if (!strcmp (string, "TRUE"))
GTK_VALUE_BOOL (*arg) = TRUE;
else
GTK_VALUE_BOOL (*arg) = FALSE;
}
}
static char *
xml_arg_get (GtkArg *arg)
{
switch (arg->type) {
case GTK_TYPE_BOOL:
if (GTK_VALUE_BOOL (*arg))
return g_strdup ("TRUE");
else
return g_strdup ("FALSE");
}
return NULL;
}
/*
* Get a value for a node either carried as an attibute or as
* the content of a child.
......@@ -1049,6 +1077,112 @@ xml_get_print_hf (xmlNodePtr node, PrintHF *const hf)
}
}
static xmlNodePtr
xml_write_attributes (parse_xml_context_t *ctxt, guint n_args, GtkArg *args)
{
xmlNodePtr cur;
gint i;
cur = xmlNewDocNode (ctxt->doc, ctxt->ns, "Attributes", NULL);
for (i=0; i < n_args; args++, i++) {
xmlNodePtr tmp;
xmlChar *tstr;
gchar *str;
tmp = xmlNewDocNode (ctxt->doc, ctxt->ns, "Attribute", NULL);
tstr = xmlEncodeEntitiesReentrant (ctxt->doc, args->name);
xmlNewChild (tmp, ctxt->ns, "name", tstr);
if (tstr) {
xmlFree (tstr);
}
xmlNewChild (tmp, ctxt->ns, "type", tstr);
xml_set_value_int (tmp, "type", args->type);
str = xml_arg_get (args);
tstr = xmlEncodeEntitiesReentrant (ctxt->doc, str);
xmlNewChild (tmp, ctxt->ns, "value", tstr);
if (tstr) {
xmlFree (tstr);
}
g_free (str);
xmlAddChild (cur, tmp);
}
return cur;
}
static void
xml_free_arg_list (GList *list)
{
while (list) {
if (list->data) {
g_free (list->data);
}
list = list->next;
}
}
static void
xml_read_attributes (parse_xml_context_t *ctxt, xmlNodePtr tree, GList **list)
{
xmlNodePtr child;
GtkArg *arg;
g_return_if_fail (ctxt != NULL);
g_return_if_fail (tree != NULL);
g_return_if_fail (ctxt->wb != NULL);
child = tree->childs;
while (child) {
char *name = NULL;
int type = 0;
char *value = NULL;
if (child->name && !strcmp (child->name, "Attribute")) {
xmlNodePtr bits;
bits = child->childs;
while (bits) {
if (!strcmp (bits->name, "name")) {
name = xmlNodeGetContent (bits);
}
if (!strcmp (bits->name, "type")) {
xml_get_value_int (child,
"type", &type);
}
if (!strcmp (bits->name, "value")) {
value = xmlNodeGetContent (bits);
}
bits = bits->next;
}
if (name && type && value) {
arg = gtk_arg_new (type);
arg->name = g_strdup (name);
xml_arg_set ( arg, value);
*list = g_list_prepend (*list, arg);
}
}
if (name){
xmlFree (name);
name = NULL;
}
if (value){
xmlFree (value);
value = NULL;
}
child = child->next;
}
}
static xmlNodePtr
xml_write_print_info (parse_xml_context_t *ctxt, PrintInformation *pi)
{
......@@ -2443,6 +2577,8 @@ xml_workbook_write (parse_xml_context_t *ctxt, Workbook *wb)
xmlNodePtr cur;
xmlNsPtr gmr;
xmlNodePtr child;
GtkArg *args;
guint n_args;
GList *sheets, *sheets0;
char *oldlocale;
......@@ -2461,6 +2597,11 @@ xml_workbook_write (parse_xml_context_t *ctxt, Workbook *wb)
oldlocale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C");
args = workbook_get_attributev (wb, &n_args);
child = xml_write_attributes (ctxt, n_args, args);
if (child)
xmlAddChild (cur, child);
child = xml_write_summary (ctxt, wb->summary_info);
if (child)
xmlAddChild (cur, child);
......@@ -2543,7 +2684,8 @@ xml_workbook_read (Workbook *wb, parse_xml_context_t *ctxt, xmlNodePtr tree)
Sheet *sheet;
xmlNodePtr child, c;
char *oldlocale;
GList *list = NULL;
if (strcmp (tree->name, "Workbook")){
fprintf (stderr,
"xml_workbook_read: invalid element type %s, 'Workbook' expected`\n",
......@@ -2605,6 +2747,14 @@ xml_workbook_read (Workbook *wb, parse_xml_context_t *ctxt, xmlNodePtr tree)
c = c->next;
}
child = xml_search_child (tree, "Attributes");
if (child) {
xml_read_attributes (ctxt, child, &list);
workbook_set_attributev (ctxt->wb, list);
xml_free_arg_list (list);
g_list_free (list);
}
child = xml_search_child (tree, "UIData");
if (child) {
int tmp = 0;
......@@ -2797,7 +2947,7 @@ gnumeric_xml_read_workbook (CommandContext *context, Workbook *wb,
xml_workbook_read (wb, &ctxt, res->root);
workbook_set_filename (wb, (char *) filename);
workbook_recalc_all (wb);
xmlFreeDoc (res);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment