return true;
}
\f
-/* Renders a single output_item to an output device in one of two ways:
-
- - 'print == true': Broken across multiple pages if necessary.
-
- - 'print == false': In a single region that the user may scroll around if
- needed.
-
- Normally 'output_item' corresponds to a single rendering. There is a
- special case when 'print == true' and 'output_item' is a table_item with
- multiple layers and 'item->pt->table_look->print_all_layers == true'. In
- that case, each layer is rendered separately from the FSM's internal point
- of view; from the client's point of view, it is all one operation.
-*/
struct xr_fsm
{
struct xr_fsm_style *style;
struct output_item *item;
- bool print;
/* Table items only. */
- size_t *layer_indexes;
struct render_params rp;
struct render_pager *p;
cairo_t *cairo; /* XXX should this be here?! */
#define CHART_WIDTH 500
#define CHART_HEIGHT 375
-static struct xr_fsm *
+struct xr_fsm *
xr_fsm_create (const struct output_item *item_,
- const struct xr_fsm_style *style, cairo_t *cr,
- bool print)
+ const struct xr_fsm_style *style, cairo_t *cr)
{
if (is_page_setup_item (item_)
|| is_group_open_item (item_)
|| is_chart_item (item)
|| is_page_eject_item (item));
- size_t *layer_indexes = NULL;
- if (is_table_item (item))
- {
- layer_indexes = pivot_table_next_layer (table_item->pt, NULL, print);
- if (!layer_indexes)
- return NULL;
- }
-
static const struct render_ops xrr_render_ops = {
.measure_cell_width = xrr_measure_cell_width,
.measure_cell_height = xrr_measure_cell_height,
[RENDER_LINE_DOUBLE] = 2 * LW + LS,
};
- size_t *layer_indexes = NULL;
- if (is_table_item (item)
- pivot_table_next_display_layer (
-
struct xr_fsm *fsm = xmalloc (sizeof *fsm);
*fsm = (struct xr_fsm) {
.style = xr_fsm_style_ref (style),
.item = item,
- .print = print,
- .layer_indexes = layer_indexes,
.rp = {
.ops = &xrr_render_ops,
.aux = fsm,
}
};
+ if (is_table_item (item))
+ {
+ fsm->cairo = cr;
+ fsm->p = render_pager_create (&fsm->rp, to_table_item (item));
+ fsm->cairo = NULL;
+ }
+
for (int i = 0; i < XR_N_FONTS; i++)
{
PangoContext *context = pango_cairo_create_context (cr);
g_object_unref (G_OBJECT (layout));
}
- if (is_table_item (item))
- {
- struct table_item *table_item = to_table_item (item);
-
- fsm->cairo = cr;
- fsm->p = render_pager_create (&fsm->rp, table_item);
- fsm->cairo = NULL;
- }
-
return fsm;
}
bool xr_fsm_style_equals (const struct xr_fsm_style *,
const struct xr_fsm_style *);
-/* Interface used for rendering output items in a single on-screen region. */
-struct xr_fsm *xr_fsm_create_for_scrolling (const struct output_item *,
- const struct xr_fsm_style *,
- cairo_t *);
+struct xr_fsm *xr_fsm_create (const struct output_item *,
+ const struct xr_fsm_style *,
+ cairo_t *);
+void xr_fsm_destroy (struct xr_fsm *);
+
void xr_fsm_measure (struct xr_fsm *, cairo_t *, int *w, int *h);
void xr_fsm_draw_all (struct xr_fsm *, cairo_t *);
void xr_fsm_draw_region (struct xr_fsm *, cairo_t *,
int x, int y, int w, int h);
-/* Interface used for rendering output items to a series of printed pages. */
-struct xr_fsm *xr_fsm_create_for_printing (const struct output_item *,
- const struct xr_fsm_style *,
- cairo_t *);
-void xr_fsm_destroy (struct xr_fsm *);
int xr_fsm_draw_slice (struct xr_fsm *, cairo_t *, int space);
bool xr_fsm_is_empty (const struct xr_fsm *);
}
}
- p->fsm = xr_fsm_create_for_printing (p->item, p->fsm_style, p->cr);
+ p->fsm = xr_fsm_create (p->item, p->fsm_style, p->cr);
if (!p->fsm)
{
output_item_unref (p->item);
#include <stdlib.h>
-#include "output/pivot-output.h"
+#include "output/pivot-table.h"
#include "data/settings.h"
#include "libpspp/assertion.h"
#include "libpspp/pool.h"
+#include "output/table.h"
#include "output/page-eject-item.h"
-#include "output/pivot-table.h"
#include "output/table-item.h"
-#include "output/table-provider.h"
-#include "output/table.h"
#include "output/text-item.h"
+#include "output/table-provider.h"
#include "gl/minmax.h"
#include "gl/xalloc.h"
}
}
-<<<<<<< HEAD
static struct table_item_text *
pivot_value_to_table_item_text (const struct pivot_value *value,
const struct table_area_style *area,
return text;
}
-=======
->>>>>>> 8b935a7c95 (work toward getting rid of struct table in table_item)
static int
get_table_rule (const struct table_border_style *styles,
enum pivot_border style_idx)
}
}
-struct table *
-pivot_table_to_table (const struct pivot_table *pt,
- const size_t *layer_indexes)
+static void
+pivot_table_submit_layer (const struct pivot_table *pt,
+ const size_t *layer_indexes)
{
const size_t *pindexes[PIVOT_N_AXES]
= { [PIVOT_AXIS_LAYER] = layer_indexes };
free (column_enumeration);
free (row_enumeration);
+ struct table_item *ti = table_item_create (table, NULL, NULL, pt->notes);
+
+ if (pt->title)
+ {
+ struct table_item_text *title = pivot_value_to_table_item_text (
+ pt->title, &pt->look->areas[PIVOT_AREA_TITLE], footnotes,
+ pt->show_values, pt->show_variables);
+ table_item_set_title (ti, title);
+ table_item_text_destroy (title);
+ }
+
+ const struct pivot_axis *layer_axis = &pt->axes[PIVOT_AXIS_LAYER];
+ struct table_item_layers *layers = NULL;
+ for (size_t i = 0; i < layer_axis->n_dimensions; i++)
+ {
+ const struct pivot_dimension *d = layer_axis->dimensions[i];
+ if (d->n_leaves)
+ {
+ if (!layers)
+ {
+ layers = xzalloc (sizeof *layers);
+ layers->style = table_area_style_override (
+ NULL, &pt->look->areas[PIVOT_AREA_LAYERS], NULL, NULL, false);
+ layers->layers = xnmalloc (layer_axis->n_dimensions,
+ sizeof *layers->layers);
+ }
+
+ const struct pivot_value *name
+ = d->data_leaves[layer_indexes[i]]->name;
+ struct table_item_layer *layer = &layers->layers[layers->n_layers++];
+ struct string s = DS_EMPTY_INITIALIZER;
+ pivot_value_format_body (name, pt->show_values, pt->show_variables,
+ &s);
+ layer->content = ds_steal_cstr (&s);
+ layer->n_footnotes = 0;
+ layer->footnotes = xnmalloc (name->n_footnotes,
+ sizeof *layer->footnotes);
+ for (size_t i = 0; i < name->n_footnotes; i++)
+ {
+ struct footnote *f = footnotes[name->footnotes[i]->idx];
+ if (f)
+ layer->footnotes[layer->n_footnotes++] = f;
+ }
+ }
+ }
+ if (layers)
+ {
+ table_item_set_layers (ti, layers);
+ table_item_layers_destroy (layers);
+ }
+
+ if (pt->caption && pt->show_caption)
+ {
+ struct table_item_text *caption = pivot_value_to_table_item_text (
+ pt->caption, &pt->look->areas[PIVOT_AREA_CAPTION], footnotes,
+ pt->show_values, pt->show_variables);
+ table_item_set_caption (ti, caption);
+ table_item_text_destroy (caption);
+ }
+
free (footnotes);
+ ti->pt = pivot_table_ref (pt);
- return table;
+ table_item_submit (ti);
}
void
pivot_table_submit (struct pivot_table *pt)
{
- table_item_submit (table_item_create (pt));
+ pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, pt));
+
+ int old_decimal = settings_get_decimal_char (FMT_COMMA);
+ if (pt->decimal == '.' || pt->decimal == ',')
+ settings_set_decimal_char (pt->decimal);
+
+ if (pt->look->print_all_layers)
+ {
+ size_t *layer_indexes;
+
+ PIVOT_AXIS_FOR_EACH (layer_indexes, &pt->axes[PIVOT_AXIS_LAYER])
+ {
+ if (pt->look->paginate_layers)
+ page_eject_item_submit (page_eject_item_create ());
+ pivot_table_submit_layer (pt, layer_indexes);
+ }
+ }
+ else
+ pivot_table_submit_layer (pt, pt->current_layer);
+
+ settings_set_decimal_char (old_decimal);
+
+ pivot_table_unref (pt);
}
+++ /dev/null
-/* PSPP - a program for statistical analysis.
- Copyright (C) 2020 Free Software Foundation, Inc.
-
- 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 3 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, see <http://www.gnu.org/licenses/>. */
-
-#ifndef OUTPUT_PIVOT_OUTPUT_H
-#define OUTPUT_PIVOT_OUTPUT_H 1
-
-#include <stddef.h>
-
-struct pivot_table;
-
-struct table *pivot_table_to_table (const struct pivot_table *,
- const size_t *layer_indexes);
-
-#endif /* output/pivot-output.h */
if (axis->dimensions[i]->n_leaves == 0)
return NULL;
- size_t size = axis->n_dimensions * sizeof *indexes;
- return xzalloc (MAX (size, 1));
+ return xcalloc (axis->n_dimensions, sizeof *indexes);
}
for (size_t i = 0; i < axis->n_dimensions; i++)
return hmap_is_empty (&table->cells);
}
-size_t *
-pivot_table_next_display_layer (const struct pivot_table *pt, size_t *indexes,
- bool print)
-{
- const struct pivot_axis *layer_axis = &pt->axes[PIVOT_AXIS_LAYER];
- if (print && pt->look->print_all_layers)
- return pivot_axis_iterator_next (indexes, layer_axis);
- else if (!indexes)
- {
- size_t size = layer_axis->n_dimensions * sizeof *pt->current_layer;
- return xmemdup (pt->current_layer, MAX (size, 1));
- }
- else
- {
- free (indexes);
- return NULL;
- }
-}
-
static unsigned int
pivot_cell_hash_indexes (const size_t *indexes, size_t n_idx)
{
bool show_grid_lines;
bool show_title;
bool show_caption;
- size_t *current_layer; /* axes[PIVOT_AXIS_LAYER].n_dimensions elements. */
+ size_t *current_layer; /* axis[PIVOT_AXIS_LAYER].n_dimensions elements. */
enum settings_value_show show_values;
enum settings_value_show show_variables;
struct fmt_spec weight_format;
/* Output. */
void pivot_table_submit (struct pivot_table *);
-/* Layers. */
-#define PIVOT_TABLE_FOR_EACH_DISPLAY_LAYER(INDEXES, PT, PRINT) \
- for ((INDEXES) = NULL; \
- ((INDEXES) = pivot_table_next_display_layer (PT, INDEXES, PRINT)); )
-size_t *pivot_table_next_display_layer (const struct pivot_table *,
- size_t *indexes, bool print);
-
/* Data cells. */
void pivot_table_put (struct pivot_table *, const size_t *dindexes, size_t n,
struct pivot_value *);
char *structure_member;
enum spv_item_type type;
- char *label; /* Localized label. */
- char *command_id; /* Non-localized unique command identifier. */
+ char *label;
+ char *command_id; /* Unique command identifier. */
/* Whether the item is visible.
For SPV_ITEM_HEADING, false indicates that the item is collapsed.
#include "gettext.h"
#define _(msgid) gettext (msgid)
-/* Initializes ITEM as a table item for rendering PT. Takes ownership of
- PT. */
-struct table_item *
-table_item_create (struct pivot_table *pt)
+struct table_item_text *
+table_item_text_create (const char *content)
+{
+ if (!content)
+ return NULL;
+
+ struct table_item_text *text = xmalloc (sizeof *text);
+ *text = (struct table_item_text) { .content = xstrdup (content) };
+ return text;
+}
+
+struct table_item_text *
+table_item_text_clone (const struct table_item_text *old)
+{
+ if (!old)
+ return NULL;
+
+ struct table_item_text *new = xmalloc (sizeof *new);
+ *new = (struct table_item_text) {
+ .content = xstrdup (old->content),
+ .footnotes = xmemdup (old->footnotes,
+ old->n_footnotes * sizeof *old->footnotes),
+ .n_footnotes = old->n_footnotes,
+ .style = table_area_style_clone (NULL, old->style),
+ };
+ return new;
+}
+
+void
+table_item_text_destroy (struct table_item_text *text)
+{
+ if (text)
+ {
+ free (text->content);
+ free (text->footnotes);
+ table_area_style_free (text->style);
+ free (text);
+ }
+}
+
+void
+table_item_layer_copy (struct table_item_layer *dst,
+ const struct table_item_layer *src)
+{
+ dst->content = xstrdup (src->content);
+ dst->footnotes = xmemdup (src->footnotes,
+ src->n_footnotes * sizeof *src->footnotes);
+ dst->n_footnotes = src->n_footnotes;
+}
+
+void
+table_item_layer_uninit (struct table_item_layer *layer)
+{
+ if (layer)
+ {
+ free (layer->content);
+ free (layer->footnotes);
+ }
+}
+
+struct table_item_layers *
+table_item_layers_clone (const struct table_item_layers *old)
{
- pivot_table_assign_label_depth (pt);
+ if (!old)
+ return NULL;
+ struct table_item_layers *new = xmalloc (sizeof *new);
+ *new = (struct table_item_layers) {
+ .layers = xnmalloc (old->n_layers, sizeof *new->layers),
+ .n_layers = old->n_layers,
+ .style = table_area_style_clone (NULL, old->style),
+ };
+ for (size_t i = 0; i < new->n_layers; i++)
+ table_item_layer_copy (&new->layers[i], &old->layers[i]);
+ return new;
+}
+
+void
+table_item_layers_destroy (struct table_item_layers *layers)
+{
+ if (layers)
+ {
+ for (size_t i = 0; i < layers->n_layers; i++)
+ table_item_layer_uninit (&layers->layers[i]);
+ free (layers->layers);
+ table_area_style_free (layers->style);
+ free (layers);
+ }
+}
+
+/* Initializes ITEM as a table item for rendering TABLE. The new table item
+ initially has the specified TITLE, CAPTION, and NOTES, which may each be
+ NULL. The caller retains ownership of TITLE, CAPTION, and NOTES. */
+struct table_item *
+table_item_create (struct table *table, const char *title, const char *caption,
+ const char *notes)
+{
struct table_item *item = xmalloc (sizeof *item);
*item = (struct table_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&table_item_class),
- .pt = pt,
+ .table = table,
+ .title = table_item_text_create (title),
+ .caption = table_item_text_create (caption),
+ .notes = notes ? xstrdup (notes) : NULL,
};
return item;
}
+/* Returns the table contained by TABLE_ITEM. The caller must not modify or
+ unref the returned table. */
+const struct table *
+table_item_get_table (const struct table_item *table_item)
+{
+ return table_item->table;
+}
+
+/* Returns ITEM's title, which is a null pointer if no title has been
+ set. */
+const struct table_item_text *
+table_item_get_title (const struct table_item *item)
+{
+ return item->title;
+}
+
+/* Sets ITEM's title to TITLE, replacing any previous title. Specify NULL for
+ TITLE to clear any title from ITEM. The caller retains ownership of TITLE.
+
+ This function may only be used on a table_item that is unshared. */
+void
+table_item_set_title (struct table_item *item,
+ const struct table_item_text *title)
+{
+ assert (!table_item_is_shared (item));
+ table_item_text_destroy (item->title);
+ item->title = table_item_text_clone (title);
+}
+
+/* Returns ITEM's layers, which will be a null pointer if no layers have been
+ set. */
+const struct table_item_layers *
+table_item_get_layers (const struct table_item *item)
+{
+ return item->layers;
+}
+
+/* Sets ITEM's layers to LAYERS, replacing any previous layers. Specify NULL
+ for LAYERS to clear any layers from ITEM. The caller retains ownership of
+ LAYERS.
+
+ This function may only be used on a table_item that is unshared. */
+void
+table_item_set_layers (struct table_item *item,
+ const struct table_item_layers *layers)
+{
+ assert (!table_item_is_shared (item));
+ table_item_layers_destroy (item->layers);
+ item->layers = table_item_layers_clone (layers);
+}
+
+/* Returns ITEM's caption, which is a null pointer if no caption has been
+ set. */
+const struct table_item_text *
+table_item_get_caption (const struct table_item *item)
+{
+ return item->caption;
+}
+
+/* Sets ITEM's caption to CAPTION, replacing any previous caption. Specify
+ NULL for CAPTION to clear any caption from ITEM. The caller retains
+ ownership of CAPTION.
+
+ This function may only be used on a table_item that is unshared. */
+void
+table_item_set_caption (struct table_item *item,
+ const struct table_item_text *caption)
+{
+ assert (!table_item_is_shared (item));
+ table_item_text_destroy (item->caption);
+ item->caption = table_item_text_clone (caption);
+}
+
+/* Returns ITEM's notes, which is a null pointer if ITEM has no notes. */
+const char *
+table_item_get_notes (const struct table_item *item)
+{
+ return item->notes;
+}
+
+/* Sets ITEM's notes to NOTES, replacing any previous notes. Specify NULL for
+ NOTES to clear any notes from ITEM. The caller retains ownership of
+ NOTES.
+
+ This function may only be used on a table_item that is unshared.*/
+void
+table_item_set_notes (struct table_item *item, const char *notes)
+{
+ assert (!table_item_is_shared (item));
+ free (item->notes);
+ item->notes = notes ? xstrdup (notes) : NULL;
+}
+
/* Submits TABLE_ITEM to the configured output drivers, and transfers ownership
to the output subsystem. */
void
static const char *
table_item_get_label (const struct output_item *output_item)
{
- struct table_item *item = to_table_item (output_item);
-
- if (!item->cached_label)
- {
- if (!item->pt->title)
- return _("Table");
-
- item->cached_label = pivot_value_to_string (item->pt->title,
- SETTINGS_VALUE_SHOW_DEFAULT,
- SETTINGS_VALUE_SHOW_DEFAULT);
- }
- return item->cached_label;
+ const struct table_item *item = to_table_item (output_item);
+ return (item->title && item->title->content
+ ? item->title->content
+ : _("Table"));
}
static void
table_item_destroy (struct output_item *output_item)
{
struct table_item *item = to_table_item (output_item);
+ table_item_text_destroy (item->title);
+ table_item_text_destroy (item->caption);
+ table_item_layers_destroy (item->layers);
+ free (item->notes);
pivot_table_unref (item->pt);
- free (item->cached_label);
+ table_unref (item->table);
free (item);
}
#include "output/output-item.h"
#include "output/table.h"
+/* Title or caption in a table item. */
+struct table_item_text
+ {
+ char *content;
+ const struct footnote **footnotes;
+ size_t n_footnotes;
+ struct table_area_style *style;
+ };
+
+struct table_item_text *table_item_text_create (const char *);
+struct table_item_text *table_item_text_clone (const struct table_item_text *);
+void table_item_text_destroy (struct table_item_text *);
+
+struct table_item_layer
+ {
+ char *content;
+ const struct footnote **footnotes;
+ size_t n_footnotes;
+ };
+
+void table_item_layer_copy (struct table_item_layer *,
+ const struct table_item_layer *);
+void table_item_layer_uninit (struct table_item_layer *);
+
+struct table_item_layers
+ {
+ struct table_item_layer *layers;
+ size_t n_layers;
+ struct table_area_style *style;
+ };
+
+struct table_item_layers *table_item_layers_clone (
+ const struct table_item_layers *);
+void table_item_layers_destroy (struct table_item_layers *);
+
/* A table item.
The members of struct table_item should not be accessed directly. Use one
struct table_item
{
struct output_item output_item; /* Superclass. */
- struct pivot_table *pt; /* The table to be rendered. */
-
- char *cached_label;
+ struct table *table; /* The table to be rendered. */
+ struct table_item_text *title; /* Null if there is no title. */
+ struct table_item_text *caption; /* Null if there is no caption. */
+ struct table_item_layers *layers; /* Null if there is no layer info. */
+ char *notes; /* Shown as tooltip. */
+ struct pivot_table *pt;
};
-struct table_item *table_item_create (struct pivot_table *);
+struct table_item *table_item_create (struct table *, const char *title,
+ const char *caption, const char *notes);
+
+const struct table *table_item_get_table (const struct table_item *);
+
+const struct table_item_text *table_item_get_title (const struct table_item *);
+void table_item_set_title (struct table_item *,
+ const struct table_item_text *);
+
+const struct table_item_layers *table_item_get_layers (
+ const struct table_item *);
+void table_item_set_layers (struct table_item *,
+ const struct table_item_layers *);
+
+const struct table_item_text *table_item_get_caption (
+ const struct table_item *);
+void table_item_set_caption (struct table_item *,
+ const struct table_item_text *);
+
+const char *table_item_get_notes (const struct table_item *);
+void table_item_set_notes (struct table_item *, const char *notes);
\f
/* This boilerplate for table_item, a subclass of output_item, was
autogenerated by mk-class-boilerplate. */
if (is_group_open_item (item->item))
continue;
- r = xr_fsm_create_for_scrolling (item->item, view->style, cr);
+ r = xr_fsm_create (item->item, view->style, cr);
if (r == NULL)
{
g_warn_if_reached ();
if (view->y > 0)
view->y += view->object_spacing;
- struct xr_fsm *r = xr_fsm_create_for_scrolling (item, view->style, cr);
+ struct xr_fsm *r = xr_fsm_create (item, view->style, cr);
if (r == NULL)
{
gdk_window_end_draw_frame (win, ctx);