output-item: Make command name part of every output_item.
[pspp] / src / output / page-setup-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011, 2018 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_PAGE_SETUP_ITEM_H
18 #define OUTPUT_PAGE_SETUP_ITEM_H 1
19
20 /* Page setup items.
21
22    A page setup item configures the paper size, margins, header and footer,
23    and other attributes used for printing. */
24
25 #include <stdbool.h>
26 #include "output/output-item.h"
27 #include "table.h"
28
29 enum page_orientation
30   {
31     PAGE_PORTRAIT,
32     PAGE_LANDSCAPE
33   };
34
35 enum page_chart_size
36   {
37     PAGE_CHART_AS_IS,
38     PAGE_CHART_FULL_HEIGHT,
39     PAGE_CHART_HALF_HEIGHT,
40     PAGE_CHART_QUARTER_HEIGHT,
41   };
42
43 struct page_paragraph
44   {
45     char *markup;
46     enum table_halign halign;
47   };
48
49 bool page_paragraph_equals (const struct page_paragraph *,
50                             const struct page_paragraph *);
51
52 struct page_heading
53   {
54     struct page_paragraph *paragraphs;
55     size_t n;
56   };
57
58 void page_heading_copy (struct page_heading *, const struct page_heading *);
59 void page_heading_uninit (struct page_heading *);
60 bool page_heading_equals (const struct page_heading *,
61                           const struct page_heading *);
62
63 struct page_setup
64   {
65     int initial_page_number;
66     double paper[TABLE_N_AXES];         /* Paper size in inches. */
67     double margins[TABLE_N_AXES][2];    /* In inches. */
68     enum page_orientation orientation;
69     double object_spacing;      /* Space between objects, in inches. */
70     enum page_chart_size chart_size;
71     struct page_heading headings[2]; /* Header and footer. */
72     char *file_name;
73   };
74
75 #define PAGE_SETUP_INITIALIZER                                          \
76     {                                                                   \
77         .initial_page_number = 1,                                       \
78         .paper = { [TABLE_HORZ] = 8.5, [TABLE_VERT] = 11.0 },           \
79         .margins = { { 0.5, 0.5 }, { 0.5, 0.5 } },                      \
80         .orientation = PAGE_PORTRAIT,                                   \
81         .object_spacing = 12.0 / 72.0,                                  \
82         .chart_size = PAGE_CHART_AS_IS,                                 \
83     }
84
85 struct page_setup *page_setup_clone (const struct page_setup *);
86 void page_setup_destroy (struct page_setup *);
87
88 /* A page setup item. */
89 struct page_setup_item
90   {
91     struct output_item output_item;
92     struct page_setup *page_setup;
93   };
94
95 struct page_setup_item *page_setup_item_create (const struct page_setup *);
96 \f
97 /* This boilerplate for page_setup_item, a subclass of output_item, was
98    autogenerated by mk-class-boilerplate. */
99
100 #include <assert.h>
101 #include "libpspp/cast.h"
102
103 extern const struct output_item_class page_setup_item_class;
104
105 /* Returns true if SUPER is a page_setup_item, otherwise false. */
106 static inline bool
107 is_page_setup_item (const struct output_item *super)
108 {
109   return super->class == &page_setup_item_class;
110 }
111
112 /* Returns SUPER converted to page_setup_item.  SUPER must be a page_setup_item, as
113    reported by is_page_setup_item. */
114 static inline struct page_setup_item *
115 to_page_setup_item (const struct output_item *super)
116 {
117   assert (is_page_setup_item (super));
118   return UP_CAST (super, struct page_setup_item, output_item);
119 }
120
121 /* Returns INSTANCE converted to output_item. */
122 static inline struct output_item *
123 page_setup_item_super (const struct page_setup_item *instance)
124 {
125   return CONST_CAST (struct output_item *, &instance->output_item);
126 }
127
128 /* Increments INSTANCE's reference count and returns INSTANCE. */
129 static inline struct page_setup_item *
130 page_setup_item_ref (const struct page_setup_item *instance)
131 {
132   return to_page_setup_item (output_item_ref (&instance->output_item));
133 }
134
135 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
136    the reference count is now zero. */
137 static inline void
138 page_setup_item_unref (struct page_setup_item *instance)
139 {
140   output_item_unref (&instance->output_item);
141 }
142
143 /* Returns true if INSTANCE's reference count is greater than 1,
144    false otherwise. */
145 static inline bool
146 page_setup_item_is_shared (const struct page_setup_item *instance)
147 {
148   return output_item_is_shared (&instance->output_item);
149 }
150
151 void page_setup_item_submit (struct page_setup_item *);
152 \f
153 #endif /* output/page-setup-item.h */