Commit c92e7484 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Use constant expression to make factors easier to understand. Constify.

2000-09-27  Morten Welinder  <terra@diku.dk>

	* src/print-info.c: Use constant expression to make factors easier
 	to understand.  Constify.  Have the compiler check UNIT_LAST.
	(print_info_new): Compute margins from unit lengths instead of
 	storing "magic" numbers.



2000-09-27  Morten Welinder  <terra@diku.dk>

	* dialog-printer-setup.c (add_unit): Avoid double translation of
 	the unit name.
	(do_convert): Don't corrupt the values.  Someone needs to check
 	that what we do to the gtk_adjustment -- here and elsewhere -- is
 	right.
parent e7bb7032
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
......@@ -2,6 +2,8 @@
* src/print-info.c: Use constant expression to make factors easier
to understand. Constify. Have the compiler check UNIT_LAST.
(print_info_new): Compute margins from unit lengths instead of
storing "magic" numbers.
2000-09-27 Morten Welinder <terra@diku.dk>
......@@ -16,7 +18,7 @@
* src/number-match.c (format_match_init) : Call the currency_date init
routine from here. It must be done BEFORE the regexps are generated.
(format_match_finish) : Shut the currency_date routines down from here.
for symetry.
for symmetry.
2000-09-25 Morten Welinder <terra@diku.dk>
......
2000-09-27 Morten Welinder <terra@diku.dk>
* dialog-printer-setup.c (add_unit): Avoid double translation of
the unit name.
(do_convert): Don't corrupt the values. Someone needs to check
that what we do to the gtk_adjustment -- here and elsewhere -- is
right.
2000-09-24 <michael@thomas.home>
* dialog-graph-guru.c (cb_graph_guru_clicked): update to item container.
......
......@@ -76,7 +76,7 @@ typedef struct {
} margins;
GList *conversion_listeners;
const GnomePaper *paper;
const GnomePaper *current_paper;
......@@ -131,7 +131,7 @@ spin_button_set_bound (GtkSpinButton *spin, double space_to_grow,
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 1); /* Ditto */
space_to_grow = unit_convert (space_to_grow, space_unit, spin_unit);
if (space_to_grow + EPSILON < 0) {
double shrink = MIN (-space_to_grow, adjustment->value);
......@@ -144,7 +144,7 @@ spin_button_set_bound (GtkSpinButton *spin, double space_to_grow,
adjustment->upper = adjustment->value + space_to_grow;
gtk_adjustment_changed (adjustment);
}
return unit_convert (space_to_grow, spin_unit, space_unit);
}
......@@ -210,7 +210,7 @@ static void set_horizontal_bounds (dialog_print_info_t *dpi,
printable_width,
unit,
dpi->margins.left.unit);
if (margin_fixed != MARGIN_RIGHT)
printable_width
= spin_button_set_bound (dpi->margins.right.spin,
......@@ -229,7 +229,7 @@ static void set_horizontal_bounds (dialog_print_info_t *dpi,
* If margin_fixed is one of those margins, it kept unchanged. This is to
* avoid the possibility of an endless loop.
*/
static void set_vertical_bounds (dialog_print_info_t *dpi,
static void set_vertical_bounds (dialog_print_info_t *dpi,
MarginOrientation margin_fixed,
UnitName unit)
{
......@@ -241,21 +241,21 @@ static void set_vertical_bounds (dialog_print_info_t *dpi,
printable_height,
unit,
dpi->margins.top.unit);
if (margin_fixed != MARGIN_BOTTOM)
printable_height
= spin_button_set_bound (dpi->margins.bottom.spin,
printable_height,
unit,
dpi->margins.bottom.unit);
if (margin_fixed != MARGIN_HEADER)
if (margin_fixed != MARGIN_HEADER)
printable_height
= spin_button_set_bound (dpi->margins.header.spin,
printable_height,
unit,
dpi->margins.header.unit);
if (margin_fixed != MARGIN_FOOTER)
printable_height
= spin_button_set_bound (dpi->margins.footer.spin,
......@@ -398,7 +398,7 @@ create_margin (dialog_print_info_t *dpi,
uinfo->bound_y1 = y1;
uinfo->bound_x2 = x2;
uinfo->bound_y2 = y2;
draw_margin (uinfo, dpi);
}
......@@ -546,11 +546,14 @@ spin_button_adapt_to_unit (GtkSpinButton *spin, UnitName new_unit)
static void
do_convert (UnitInfo *target, UnitName new_unit)
{
double new_value;
if (target->unit == new_unit)
return;
new_value = unit_convert (target->value, target->unit, new_unit);
spin_button_adapt_to_unit (target->spin, new_unit);
target->value = unit_convert (target->value, target->unit, new_unit);
target->adj->value = target->value = new_value;
target->unit = new_unit;
gtk_spin_button_set_value (target->spin, target->value);
......@@ -599,7 +602,7 @@ add_unit (GtkWidget *menu, int i, dialog_print_info_t *dpi,
{
GtkWidget *item;
item = gtk_menu_item_new_with_label (_(unit_name_get_short_name (i)));
item = gtk_menu_item_new_with_label (unit_name_get_short_name (i));
gtk_widget_show (item);
gtk_menu_append (GTK_MENU (menu), item);
......@@ -608,14 +611,14 @@ add_unit (GtkWidget *menu, int i, dialog_print_info_t *dpi,
gtk_signal_connect (
GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (listeners_convert), (gpointer) convert);
}
static void
unit_changed (GtkSpinButton *spin_button, UnitInfo_cbdata *data)
{
data->target->value = data->target->adj->value;
switch (data->target->orientation) {
case MARGIN_LEFT:
case MARGIN_RIGHT:
......@@ -628,7 +631,7 @@ unit_changed (GtkSpinButton *spin_button, UnitInfo_cbdata *data)
data->target->orientation,
data->target->unit);
}
/* Adjust the display to the current values */
draw_margin (data->target, data->dpi);
}
......@@ -659,7 +662,7 @@ unit_editor_configure (UnitInfo *target, dialog_print_info_t *dpi,
{
GtkSpinButton *spin;
UnitInfo_cbdata *cbdata;
spin = GTK_SPIN_BUTTON (glade_xml_get_widget (dpi->gui, spin_name));
target->unit = unit;
......@@ -712,12 +715,12 @@ do_setup_margin (dialog_print_info_t *dpi)
GtkBox *container;
PrintMargins *pm;
UnitName displayed_unit;
g_return_if_fail (dpi && dpi->pi);
pm = &dpi->pi->margins;
displayed_unit = pm->top.desired_display;
dpi->preview.canvas = gnome_canvas_new ();
gnome_canvas_set_scroll_region (
GNOME_CANVAS (dpi->preview.canvas),
......@@ -735,7 +738,7 @@ do_setup_margin (dialog_print_info_t *dpi)
add_unit (menu, UNIT_MILLIMETER, dpi, convert_to_mm);
add_unit (menu, UNIT_CENTIMETER, dpi, convert_to_cm);
add_unit (menu, UNIT_INCH, dpi, convert_to_in);
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu),
displayed_unit);
......@@ -1042,7 +1045,7 @@ do_setup_page_info (dialog_print_info_t *dpi)
comments_combo = GTK_COMBO (glade_xml_get_widget (dpi->gui,
"comments-combo"));
gnumeric_combo_enters (GTK_WINDOW (dpi->dialog), comments_combo);
if (dpi->pi->repeat_top.use){
char *s;
......@@ -1119,13 +1122,13 @@ do_setup_page (dialog_print_info_t *dpi)
GTK_SPIN_BUTTON (scale_percent_spin), pi->scaling.percentage);
gnome_dialog_editable_enters (GNOME_DIALOG (dpi->dialog),
GTK_EDITABLE (scale_percent_spin));
scale_width_spin = glade_xml_get_widget (gui, "scale-width-spin");
gtk_spin_button_set_value (
GTK_SPIN_BUTTON (scale_width_spin), pi->scaling.dim.cols);
gnome_dialog_editable_enters (GNOME_DIALOG (dpi->dialog),
GTK_EDITABLE (scale_width_spin));
scale_height_spin = glade_xml_get_widget (gui, "scale-height-spin");
gtk_spin_button_set_value (
GTK_SPIN_BUTTON (scale_height_spin), pi->scaling.dim.rows);
......@@ -1225,7 +1228,7 @@ do_setup_main_dialog (dialog_print_info_t *dpi)
#else
{
GtkWidget *w;
w = glade_xml_get_widget (dpi->gui, "print");
gtk_signal_connect (GTK_OBJECT (w), "clicked",
GTK_SIGNAL_FUNC (do_print_cb), dpi);
......@@ -1240,8 +1243,8 @@ do_setup_main_dialog (dialog_print_info_t *dpi)
w = glade_xml_get_widget (dpi->gui, "options");
gtk_widget_hide (w);
}
#endif
}
......@@ -1337,7 +1340,7 @@ do_fetch_margins (dialog_print_info_t *dpi)
m->header.points += m->top.points;
m->footer.points += m->bottom.points;
t = GTK_TOGGLE_BUTTON (glade_xml_get_widget (dpi->gui, "center-horizontal"));
dpi->pi->center_horizontally = t->active;
......@@ -1361,7 +1364,7 @@ do_fetch_page_info (dialog_print_info_t *dpi)
GtkToggleButton *t;
Value *top_range, *left_range;
GtkEntry *entry_top, *entry_left;
t = GTK_TOGGLE_BUTTON (glade_xml_get_widget (dpi->gui, "check-print-divisions"));
dpi->pi->print_line_divisions = t->active;
......
......@@ -38,7 +38,7 @@ print_hf_new (const char *left_side_format,
PrintHF *format;
format = g_new0 (PrintHF, 1);
if (left_side_format)
format->left_format = g_strdup (left_side_format);
......@@ -56,28 +56,28 @@ print_hf_same (const PrintHF *a, const PrintHF *b)
{
if (strcmp (b->left_format, a->left_format))
return FALSE;
if (strcmp (b->middle_format, a->middle_format))
if (strcmp (b->middle_format, a->middle_format))
return FALSE;
if (strcmp (b->right_format, a->right_format))
return FALSE;
return TRUE;
}
PrintHF *
print_hf_register (PrintHF *hf)
{
GList *l;
PrintHF *newi;
g_return_val_if_fail (hf != NULL, NULL);
for (l = hf_formats; l; l = l->next)
if (print_hf_same (hf, l->data))
return l->data;
newi = print_hf_copy (hf);
hf_formats = g_list_append (hf_formats, newi);
......@@ -116,7 +116,7 @@ print_info_free (PrintInformation *pi)
print_hf_free (pi->header);
print_hf_free (pi->footer);
g_free (pi);
}
......@@ -139,7 +139,7 @@ load_margin (const char *str, PrintUnit *p, char *def)
char *pts_units = g_strconcat (str, "_units=centimeter", NULL);
char *pts = g_strconcat (str, "=", def, NULL);
char *s;
p->points = gnome_config_get_float (pts);
s = gnome_config_get_string (pts_units);
p->desired_display = unit_name_to_unit (s);
......@@ -174,7 +174,7 @@ load_range (const char *name)
{
static Value *v;
char *str;
str = gnome_config_get_string (name);
if (!str)
return NULL;
......@@ -227,9 +227,6 @@ load_formats (void)
gnome_config_pop_prefix ();
}
#define CENTIMETER_IN_POINTS "28.346457"
#define HALF_CENTIMETER_IN_POINTS "14.1732285"
/**
* print_info_new:
*
......@@ -241,11 +238,11 @@ print_info_new (void)
PrintInformation *pi;
Value *cellrange;
char *s;
pi = g_new0 (PrintInformation, 1);
gnome_config_push_prefix ("/Gnumeric/Print/");
/* Orientation */
if (gnome_config_get_bool ("vertical_print=false"))
pi->orientation = PRINT_ORIENT_VERTICAL;
......@@ -262,12 +259,16 @@ print_info_new (void)
pi->scaling.dim.rows = gnome_config_get_int ("scale_height=1");
/* Margins */
load_margin ("margin_top", &pi->margins.top, CENTIMETER_IN_POINTS);
load_margin ("margin_bottom", &pi->margins.bottom, CENTIMETER_IN_POINTS);
load_margin ("margin_left", &pi->margins.left, CENTIMETER_IN_POINTS);
load_margin ("margin_right", &pi->margins.right, CENTIMETER_IN_POINTS);
load_margin ("margin_header", &pi->margins.header, HALF_CENTIMETER_IN_POINTS);
load_margin ("margin_footer", &pi->margins.footer, HALF_CENTIMETER_IN_POINTS);
s = g_strdup_printf ("%.13g", unit_convert (1.0, UNIT_CENTIMETER, UNIT_POINTS));
load_margin ("margin_top", &pi->margins.top, s);
load_margin ("margin_bottom", &pi->margins.bottom, s);
load_margin ("margin_left", &pi->margins.left, s);
load_margin ("margin_right", &pi->margins.right, s);
g_free (s);
s = g_strdup_printf ("%.13g", unit_convert (0.5, UNIT_CENTIMETER, UNIT_POINTS));
load_margin ("margin_header", &pi->margins.header, s);
load_margin ("margin_footer", &pi->margins.footer, s);
g_free (s);
pi->header = load_hf ("header", "", _("&[TAB]"), "");
pi->footer = load_hf ("footer", "", _("Page &[PAGE]"), "");
......@@ -318,7 +319,7 @@ static void
save_margin (const char *prefix, PrintUnit *p)
{
char *x = g_strconcat (prefix, "_units", NULL);
gnome_config_set_float (prefix, p->points);
gnome_config_set_string (x, unit_name_get_name (p->desired_display));
g_free (x);
......@@ -347,7 +348,7 @@ save_hf (const char *type, const char *a, const char *b, const char *c)
gnome_config_set_string (code_a, a);
gnome_config_set_string (code_b, b);
gnome_config_set_string (code_c, c);
g_free (code_a);
g_free (code_b);
g_free (code_c);
......@@ -362,7 +363,7 @@ save_formats (void)
{
int format_count, i;
GList *l;
gnome_config_push_prefix ("/Gnumeric/Headers_and_Footers/");
format_count = g_list_length (hf_formats);
......@@ -423,7 +424,7 @@ print_info_save (PrintInformation *pi)
gnome_config_pop_prefix ();
save_formats ();
gnome_config_sync ();
}
......@@ -475,7 +476,7 @@ unit_convert (double value, UnitName source, UnitName target)
return (units [source].factor * value) / units [target].factor;
}
UnitName
unit_name_to_unit (const char *s)
{
......@@ -515,10 +516,10 @@ render_value_with_format (GString *target, const char *number_format, HFRenderIn
{
StyleFormat *format;
char *text;
/* TODO : Check this assumption. Is it a localized format ?? */
format = style_format_new_XL (number_format, FALSE);
text = format_value (format, info->date_time, NULL, NULL);
/* Just in case someone tries to format it as text */
......@@ -538,7 +539,7 @@ render_date (GString *target, HFRenderInfo *info, const char *args)
date_format = args;
else
date_format = "dd-mmm-yyyy";
render_value_with_format (target, date_format, info);
}
......@@ -575,7 +576,7 @@ render_opcode (GString *target, const char *opcode, HFRenderInfo *info, HFRender
{
char *args;
int i;
for (i = 0; render_ops [i].name; i++){
if (render_type == HF_RENDER_TO_ENGLISH){
if (g_strcasecmp (_(render_ops [i].name), opcode) == 0){
......@@ -599,12 +600,12 @@ render_opcode (GString *target, const char *opcode, HFRenderInfo *info, HFRender
*args = 0;
args++;
}
if ((g_strcasecmp (render_ops [i].name, opcode) == 0) ||
(g_strcasecmp (_(render_ops [i].name), opcode) == 0)){
(*render_ops [i].render)(target, info, args);
}
}
}
......@@ -614,9 +615,9 @@ hf_format_render (const char *format, HFRenderInfo *info, HFRenderType render_ty
GString *result;
const char *p;
char *str;
g_return_val_if_fail (format != NULL, NULL);
result = g_string_new ("");
for (p = format; *p; p++){
if (*p == '&' && *(p+1) == '['){
......@@ -642,10 +643,10 @@ hf_format_render (const char *format, HFRenderInfo *info, HFRenderType render_ty
str = result->str;
g_string_free (result, FALSE);
return str;
}
HFRenderInfo *
hf_render_info_new (void)
{
......@@ -693,7 +694,7 @@ print_info_copy (PrintInformation *src_pi)
PrintInformation *dst_pi;
dst_pi = print_info_new();
dst_pi->orientation = src_pi->orientation;
/* Print Scaling */
......
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