Commit e0f71b51 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Use some code from expr.c to simplify binary/unary output and to add

2001-02-16  Jody Goldberg <jgoldberg@home.com>

	* ms-formula-write.c (write_node) : Use some code from expr.c
	  to simplify binary/unary output and to add parens when necessary.

	* ms-excel-write.c (write_formula) : Start at paren level 0.
	(write_names) : ditto.

2001-02-16  Jody Goldberg <jgoldberg@home.com>

	* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
	  begin support for indenting.
	* src/workbook-format-toolbar.c : ditto.

2001-02-16  Jody Goldberg <jgoldberg@home.com>

	* configure.in : post release version bump

2001-02-15  Jody Goldberg <jgoldberg@home.com>

	* s/fit_in_cell/wrap_text/
	rename this in preparation for supporting shrink_to_fit
parent 238ec777
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
begin support for indenting.
* src/workbook-format-toolbar.c : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* configure.in : post release version bump
2001-02-15 Jody Goldberg <jgoldberg@home.com>
* s/fit_in_cell/wrap_text/
rename this in preparation for supporting shrink_to_fit
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
Gnumeric 0.63
Jody:
* Fix parenthesis for XL export.
* Enable right/left indent.
--------------------------------------------------------------------------
Gnumeric 0.62
Chema:
......
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
begin support for indenting.
* src/workbook-format-toolbar.c : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* configure.in : post release version bump
2001-02-15 Jody Goldberg <jgoldberg@home.com>
* s/fit_in_cell/wrap_text/
rename this in preparation for supporting shrink_to_fit
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
begin support for indenting.
* src/workbook-format-toolbar.c : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* configure.in : post release version bump
2001-02-15 Jody Goldberg <jgoldberg@home.com>
* s/fit_in_cell/wrap_text/
rename this in preparation for supporting shrink_to_fit
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
begin support for indenting.
* src/workbook-format-toolbar.c : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* configure.in : post release version bump
2001-02-15 Jody Goldberg <jgoldberg@home.com>
* s/fit_in_cell/wrap_text/
rename this in preparation for supporting shrink_to_fit
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-cell-format.c (fmt_dialog_init_align_page) :
begin support for indenting.
* src/workbook-format-toolbar.c : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* configure.in : post release version bump
2001-02-15 Jody Goldberg <jgoldberg@home.com>
* s/fit_in_cell/wrap_text/
rename this in preparation for supporting shrink_to_fit
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
AC_INIT(src/gnumeric.h)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gnumeric,0.62)
AM_INIT_AUTOMAKE(gnumeric,0.63)
AM_MAINTAINER_MODE
AM_ACLOCAL_INCLUDE(macros)
AM_PROG_XML_I18N_TOOLS
......
......@@ -527,7 +527,7 @@ applix_parse_style (ApplixReadState *state, char **buffer)
sep +=3;
break;
}
mstyle_set_fit_in_cell (style, TRUE);
mstyle_set_wrap_text (style, TRUE);
sep +=2;
break;
}
......
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* ms-formula-write.c (write_node) : Use some code from expr.c
to simplify binary/unary output and to add parens when necessary.
* ms-excel-write.c (write_formula) : Start at paren level 0.
(write_names) : ditto.
2001-02-16 Jody Goldberg <jgoldberg@home.com>
* Release 0.62
......
......@@ -1207,10 +1207,10 @@ ms_excel_get_style_from_xf (ExcelSheet *sheet, guint16 xfidx)
mstyle_set_format (mstyle, xf->style_format);
/* Alignment */
mstyle_set_align_v (mstyle, xf->valign);
mstyle_set_align_h (mstyle, xf->halign);
mstyle_set_fit_in_cell (mstyle, xf->wrap);
mstyle_set_indent (mstyle, xf->indent);
mstyle_set_align_v (mstyle, xf->valign);
mstyle_set_align_h (mstyle, xf->halign);
mstyle_set_wrap_text (mstyle, xf->wrap);
mstyle_set_indent (mstyle, xf->indent);
/* mstyle_set_orientation (mstyle, ); */
/* Font */
......
......@@ -1919,7 +1919,7 @@ build_xf_data (ExcelWorkbook *wb, BiffXFData *xfd, MStyle *st)
xfd->halign = mstyle_get_align_h (st);
xfd->valign = mstyle_get_align_v (st);
xfd->wrap = mstyle_get_fit_in_cell (st);
xfd->wrap = mstyle_get_wrap_text (st);
xfd->orientation = mstyle_get_orientation (st);
/* Borders */
......@@ -2208,7 +2208,7 @@ write_names (BiffPut *bp, ExcelWorkbook *wb)
ms_biff_put_var_seekto (bp, 14 + name_len);
len = ms_excel_write_formula (bp, sheet,
expr_name->t.expr_tree,
0, 0);
0, 0, 0);
g_assert (len <= 0xffff);
ms_biff_put_var_seekto (bp, 4);
MS_OLE_SET_GUINT16 (data, len);
......@@ -2448,7 +2448,7 @@ write_formula (BiffPut *bp, ExcelSheet *sheet, const Cell *cell, gint16 xf)
MS_OLE_SET_GUINT16 (data + 20, 0x0);
ms_biff_put_var_write (bp, data, 22);
len = ms_excel_write_formula (bp, sheet, cell->base.expression,
col, row);
col, row, 0);
g_assert (len <= 0xffff);
ms_biff_put_var_seekto (bp, 20);
MS_OLE_SET_GUINT16 (lendat, len);
......
......@@ -39,7 +39,7 @@ extern int ms_excel_formula_debug;
typedef struct _PolishData PolishData;
typedef struct _FormulaCacheEntry FormulaCacheEntry;
static void write_node (PolishData *pd, ExprTree *tree);
static void write_node (PolishData *pd, ExprTree *tree, int paren_level);
/* FIXME: Leaks like a leaky bucket */
......@@ -154,7 +154,7 @@ get_formula_index (ExcelSheet *sheet, const gchar *name)
* and builds a database of things to write out later.
**/
void
ms_formula_build_pre_data (ExcelSheet *sheet, ExprTree *tree)
ms_formula_build_pre_data (ExcelSheet *sheet, ExprTree const *tree)
{
g_return_if_fail (tree != NULL);
g_return_if_fail (sheet != NULL);
......@@ -479,7 +479,7 @@ write_funcall (PolishData *pd, FormulaCacheEntry *fce, ExprTree *tree)
}
while (args) {
write_node (pd, args->data);
write_node (pd, args->data, 0);
args = g_list_next (args);
num_args++;
}
......@@ -510,72 +510,53 @@ write_funcall (PolishData *pd, FormulaCacheEntry *fce, ExprTree *tree)
* Recursion is just so fun.
**/
static void
write_node (PolishData *pd, ExprTree *tree)
write_node (PolishData *pd, ExprTree *tree, int paren_level)
{
static const struct {
guint8 xl_op;
int prec; /* Precedences -- should match parser.y */
int assoc_left, assoc_right; /* 0: no, 1: yes. */
} operations [] = {
{ FORMULA_PTG_EQUAL, 1, 1, 0 },
{ FORMULA_PTG_GT, 1, 1, 0 },
{ FORMULA_PTG_LT, 1, 1, 0 },
{ FORMULA_PTG_GTE, 1, 1, 0 },
{ FORMULA_PTG_LTE, 1, 1, 0 },
{ FORMULA_PTG_NOT_EQUAL, 1, 1, 0 },
{ FORMULA_PTG_ADD, 3, 1, 0 },
{ FORMULA_PTG_SUB, 3, 1, 0 },
{ FORMULA_PTG_MULT, 4, 1, 0 },
{ FORMULA_PTG_DIV, 4, 1, 0 },
{ FORMULA_PTG_EXP, 6, 0, 1 },
{ FORMULA_PTG_CONCAT, 2, 1, 0 },
{ 0, 0, 0, 0 }, /* Funcall */
{ 0, 0, 0, 0 }, /* Name */
{ 0, 0, 0, 0 }, /* Constant */
{ 0, 0, 0, 0 }, /* Var */
{ FORMULA_PTG_U_PLUS, 5, 0, 0 }, /* Unary - */
{ FORMULA_PTG_U_MINUS, 5, 0, 0 }, /* Unary + */
{ FORMULA_PTG_PERCENT, 5, 0, 0 }, /* Percentage (NOT MODULO) */
{ 0, 0, 0, 0 } /* Array */
};
int op;
g_return_if_fail (pd);
g_return_if_fail (tree);
switch (tree->any.oper) {
case OPER_EQUAL:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_EQUAL);
break;
case OPER_GT:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_GT);
break;
case OPER_LT:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_LT);
break;
case OPER_GTE:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_GTE);
break;
case OPER_LTE:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_LTE);
break;
case OPER_NOT_EQUAL:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_NOT_EQUAL);
break;
case OPER_ADD:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_ADD);
break;
case OPER_SUB:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_SUB);
break;
case OPER_MULT:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_MULT);
break;
case OPER_DIV:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_DIV);
break;
case OPER_EXP:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_EXP);
break;
case OPER_CONCAT:
write_node (pd, tree->binary.value_a);
write_node (pd, tree->binary.value_b);
push_guint8 (pd, FORMULA_PTG_CONCAT);
op = tree->any.oper;
switch (op) {
case OPER_ANY_BINARY: {
int const prec = operations[op].prec;
write_node (pd, tree->binary.value_a,
prec - operations[op].assoc_left);
write_node (pd, tree->binary.value_b,
prec - operations[op].assoc_right);
push_guint8 (pd, operations[op].xl_op);
if (prec <= paren_level)
push_guint8 (pd, FORMULA_PTG_PAREN);
break;
}
case OPER_FUNCALL:
{
FormulaCacheEntry *fce;
......@@ -694,43 +675,37 @@ write_node (PolishData *pd, ExprTree *tree)
}
break;
}
case OPER_UNARY_PLUS:
write_node (pd, tree->unary.value);
push_guint8 (pd, FORMULA_PTG_U_PLUS);
break;
case OPER_UNARY_NEG:
write_node (pd, tree->unary.value);
push_guint8 (pd, FORMULA_PTG_U_MINUS);
break;
case OPER_ANY_UNARY: {
int const prec = operations[op].prec;
case OPER_PERCENT:
write_node (pd, tree->unary.value);
push_guint8 (pd, FORMULA_PTG_PERCENT);
write_node (pd, tree->unary.value, operations[op].prec);
push_guint8 (pd, operations[op].xl_op);
if (prec <= paren_level)
push_guint8 (pd, FORMULA_PTG_PAREN);
break;
}
case OPER_VAR:
write_ref (pd, &tree->var.ref);
break;
case OPER_NAME:
{
guint8 data[14];
guint16 idx;
for (idx = 0; idx <14; idx++) data[idx] = 0;
for (idx = 0; idx < pd->sheet->wb->names->len; idx++) {
if (!strcmp(tree->name.name->name->str,
g_ptr_array_index (pd->sheet->wb->names, idx))) {
MS_OLE_SET_GUINT8 (data + 0, FORMULA_PTG_NAME);
MS_OLE_SET_GUINT16 (data + 1, idx + 1);
ms_biff_put_var_write (pd->bp, data, 15);
return;
}
}
}
{
guint8 data[14];
guint16 idx;
for (idx = 0; idx <14; idx++) data[idx] = 0;
for (idx = 0; idx < pd->sheet->wb->names->len; idx++)
if (!strcmp(tree->name.name->name->str,
g_ptr_array_index (pd->sheet->wb->names, idx))) {
MS_OLE_SET_GUINT8 (data + 0, FORMULA_PTG_NAME);
MS_OLE_SET_GUINT16 (data + 1, idx + 1);
ms_biff_put_var_write (pd->bp, data, 15);
return;
}
break;
}
case OPER_ARRAY:
default:
......@@ -785,7 +760,7 @@ write_arrays (PolishData *pd)
guint32
ms_excel_write_formula (BiffPut *bp, ExcelSheet *sheet, ExprTree *expr,
int fn_col, int fn_row)
int fn_col, int fn_row, int paren_level)
{
PolishData *pd;
MsOlePos start;
......@@ -804,7 +779,7 @@ ms_excel_write_formula (BiffPut *bp, ExcelSheet *sheet, ExprTree *expr,
pd->ver = sheet->wb->ver;
start = bp->length;
write_node (pd, expr);
write_node (pd, expr, 0);
len = bp->length - start;
if (pd->arrays) {
......
......@@ -15,17 +15,17 @@
#include "ms-biff.h"
#include "formula-types.h"
extern guint32 ms_excel_write_formula (BiffPut *bp, ExcelSheet *sheet,
ExprTree *expr,
int fn_col, int fn_row);
guint32 ms_excel_write_formula (BiffPut *bp, ExcelSheet *sheet,
ExprTree *expr,
int fn_col, int fn_row, int paren_level);
typedef enum { EXCEL_NAME, EXCEL_EXTERNNAME } formula_write_t;
extern void ms_formula_build_pre_data (ExcelSheet *sheet, ExprTree *tree);
extern void ms_formula_write_pre_data (BiffPut *bp, ExcelSheet *sheet,
formula_write_t which,
MsBiffVersion ver);
void ms_formula_build_pre_data (ExcelSheet *sheet, ExprTree const *tree);
void ms_formula_write_pre_data (BiffPut *bp, ExcelSheet *sheet,
formula_write_t which,
MsBiffVersion ver);
extern void ms_formula_cache_init (ExcelSheet *sheet);
extern void ms_formula_cache_shutdown (ExcelSheet *sheet);
void ms_formula_cache_init (ExcelSheet *sheet);
void ms_formula_cache_shutdown (ExcelSheet *sheet);
#endif
#endif /* GNUMERIC_MS_FORMULA_W_H */
......@@ -699,10 +699,15 @@ xml2ParseStyleRegionStyle (XML2ParseState *state, CHAR const **attrs)
mstyle_set_align_h (state->style, val);
else if (xml2ParseAttrInt (attrs, "VAlign", &val))
mstyle_set_align_v (state->style, val);
/* Pre version V6 */
else if (xml2ParseAttrInt (attrs, "Fit", &val))
mstyle_set_fit_in_cell (state->style, val);
mstyle_set_wrap_text (state->style, val);
else if (xml2ParseAttrInt (attrs, "WrapText", &val))
mstyle_set_wrap_text (state->style, val);
else if (xml2ParseAttrInt (attrs, "Orient", &val))
mstyle_set_fit_in_cell (state->style, val);
mstyle_set_orientation (state->style, val);
else if (xml2ParseAttrInt (attrs, "Shade", &val))
mstyle_set_pattern (state->style, val);
else if (xml2ParseAttrColour (attrs, "Fore", &colour))
......
......@@ -699,10 +699,15 @@ xml2ParseStyleRegionStyle (XML2ParseState *state, CHAR const **attrs)
mstyle_set_align_h (state->style, val);
else if (xml2ParseAttrInt (attrs, "VAlign", &val))
mstyle_set_align_v (state->style, val);
/* Pre version V6 */
else if (xml2ParseAttrInt (attrs, "Fit", &val))
mstyle_set_fit_in_cell (state->style, val);
mstyle_set_wrap_text (state->style, val);
else if (xml2ParseAttrInt (attrs, "WrapText", &val))
mstyle_set_wrap_text (state->style, val);
else if (xml2ParseAttrInt (attrs, "Orient", &val))
mstyle_set_fit_in_cell (state->style, val);
mstyle_set_orientation (state->style, val);
else if (xml2ParseAttrInt (attrs, "Shade", &val))
mstyle_set_pattern (state->style, val);
else if (xml2ParseAttrColour (attrs, "Fore", &colour))
......
......@@ -657,10 +657,22 @@
<separator/>
<control name="BorderSelector" _tip="Borders" />
<toolitem name="IncreaseIndent"
pixtype="stock" pixname="Text Indent"
_label="Increase Indent"
_tip="Aligns the contents to the left and increases the indent"
verb="FormatIncreaseIndent"/>
<control name="BackgroundColor" _tip="Background" />
<toolitem name="DecreasePrecision"
pixtype="stock" pixname="Text Unindent"
_label="Decrease Indent"
_tip="Aligns the contents to the left and decreases the indent"
verb="FormatDecreaseIndent"/>
<separator/>
<control name="BorderSelector" _tip="Borders" />
<control name="BackgroundColor" _tip="Background" />
<control name="ForegroundColor" _tip="Foreground" />
</dockitem>
......
......@@ -229,7 +229,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
align != HALIGN_CENTER_ACROSS_SELECTION) ||
align == HALIGN_JUSTIFY ||
align == HALIGN_FILL ||
mstyle_get_fit_in_cell (mstyle) ||
mstyle_get_wrap_text (mstyle) ||
mstyle_get_align_v (mstyle) == VALIGN_JUSTIFY) {
*col1 = *col2 = cell->pos.col;
return;
......
......@@ -655,7 +655,7 @@ static void
Sheet_cell_set_alignment (PortableServer_Servant servant,
const CORBA_long col, const CORBA_long row,
const CORBA_long halign, const CORBA_long valign,
const CORBA_long orientation, const CORBA_boolean auto_return,
const CORBA_long orientation, const CORBA_boolean wrap_text,
CORBA_Environment *ev)
{
int v, h;
......@@ -721,6 +721,7 @@ Sheet_cell_set_alignment (PortableServer_Servant servant,
mstyle_set_align_v (mstyle, v);
mstyle_set_align_h (mstyle, h);
mstyle_set_wrap_text (mstyle, (gboolean) wrap_text);
sheet_style_attach_single (sheet_from_servant (servant),
col, row, mstyle);
}
......@@ -729,7 +730,7 @@ static void
Sheet_cell_get_alignment (PortableServer_Servant servant,
const CORBA_long col, const CORBA_long row,
CORBA_long * halign, CORBA_long * valign,
CORBA_long * orientation, CORBA_boolean * auto_return,
CORBA_long * orientation, CORBA_boolean *wrap_text,
CORBA_Environment *ev)
{
MStyle *mstyle;
......@@ -790,7 +791,7 @@ Sheet_cell_get_alignment (PortableServer_Servant servant,
break;
}
*orientation = mstyle_get_orientation (mstyle);
*auto_return = mstyle_get_fit_in_cell (mstyle);
*wrap_text = mstyle_get_wrap_text (mstyle);
}
static void
......@@ -1086,7 +1087,7 @@ Sheet_range_set_alignment (PortableServer_Servant servant,
CORBA_long halign,
CORBA_long valign,
CORBA_long orientation,
CORBA_boolean auto_return,
CORBA_boolean wrap_text,
CORBA_Environment *ev)
{
Sheet *sheet = sheet_from_servant (servant);
......@@ -1099,7 +1100,7 @@ Sheet_range_set_alignment (PortableServer_Servant servant,
mstyle_set_align_h (mstyle, halign);
mstyle_set_align_v (mstyle, valign);
mstyle_set_orientation (mstyle, orientation);
mstyle_set_fit_in_cell (mstyle, (gboolean) auto_return);
mstyle_set_wrap_text (mstyle, (gboolean) wrap_text);
ranges_set_style (sheet, ranges, mstyle);
range_list_destroy (ranges);
......
......@@ -822,8 +822,7 @@
<widget>
<class>GtkLabel</class>
<name>label50</name>
<sensitive>False</sensitive>
<name>halign_indent_label</name>
<label>_Indent</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
......@@ -842,7 +841,7 @@
<class>GtkAlignment</class>
<name>alignment49</name>
<sensitive>False</sensitive>
<xalign>7.45058e-09</xalign>
<xalign>0</xalign>
<yalign>0.5</yalign>
<xscale>0.0400004</xscale>
<yscale>0</yscale>
......@@ -858,11 +857,11 @@
<can_focus>True</can_focus>
<climb_rate>1</climb_rate>
<digits>0</digits>
<numeric>False</numeric>
<update_policy>GTK_UPDATE_ALWAYS</update_policy>
<numeric>True</numeric>
<update_policy>GTK_UPDATE_IF_VALID</update_policy>
<snap>False</snap>
<wrap>False</wrap>
<value>1</value>
<value>0</value>
<lower>0</lower>
<upper>20</upper>
<step>1</step>
......@@ -1025,7 +1024,6 @@
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
</widget>
......
......@@ -113,6 +113,9 @@ typedef struct _FormatState
} format;
struct {
GtkCheckButton *wrap;
GtkSpinButton *indent_button;