3cfeb28b73e9e5ed08fdd8a33d1cefbec0f27a24
[pspp] / src / output / text-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011 Free Sonftware 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_TEXT_ITEM_H
18 #define OUTPUT_TEXT_ITEM_H 1
19
20 /* Text items.
21
22    A text item is a subclass of an output item (see
23    output/output-item.h).
24
25    A text item is just a text string. */
26
27 #include <stdbool.h>
28 #include "libpspp/compiler.h"
29 #include "output/output-item.h"
30
31 enum text_item_type
32   {
33     /* Each PSPP command is bracketed between a pair of these text items.  The
34        text item's string is the full name of the command.  The syntax text
35        items associated with the command, as well as all output produced
36        directly by the command, are contained within the pair.  There is no
37        nesting. */
38     TEXT_ITEM_COMMAND_OPEN,     /* Command starting. */
39     TEXT_ITEM_COMMAND_CLOSE,    /* Command completed. */
40
41     /* Headings. */
42     TEXT_ITEM_TITLE,            /* TITLE command. */
43     TEXT_ITEM_SUBTITLE,         /* SUBTITLE command. */
44     TEXT_ITEM_SUBHEAD,          /* Heading within a command's output.*/
45
46     /* Syntax. */
47     TEXT_ITEM_SYNTAX,           /* A single line of PSPP syntax. */
48     TEXT_ITEM_COMMENT,          /* COMMENT command. */
49     TEXT_ITEM_ECHO,             /* ECHO command. */
50
51     /* Ordinary text. */
52     TEXT_ITEM_PARAGRAPH,        /* Normal paragraph of text. */
53     TEXT_ITEM_MONOSPACE,        /* Paragraph of monospaced text. */
54
55     /* Spacing.  Some output drivers that are not based on lines and pages
56        (e.g. CSV, HTML) may ignore these. */
57     TEXT_ITEM_BLANK_LINE,       /* Blank line. */
58     TEXT_ITEM_EJECT_PAGE        /* Eject page. */
59   };
60
61 /* A text item. */
62 struct text_item
63   {
64     struct output_item output_item;
65     char *text;                 /* The content. */
66     enum text_item_type type;   /* Type. */
67     char *font;
68     int font_size;
69     bool bold, italic, underline;
70   };
71
72 struct text_item *text_item_create (enum text_item_type, const char *text);
73 struct text_item *text_item_create_nocopy (enum text_item_type, char *text);
74 struct text_item *text_item_create_format (enum text_item_type,
75                                            const char *format, ...)
76   PRINTF_FORMAT (2, 3);
77
78 enum text_item_type text_item_get_type (const struct text_item *);
79 const char *text_item_get_text (const struct text_item *);
80 \f
81 /* This boilerplate for text_item, a subclass of output_item, was
82    autogenerated by mk-class-boilerplate. */
83
84 #include <assert.h>
85 #include "libpspp/cast.h"
86
87 extern const struct output_item_class text_item_class;
88
89 /* Returns true if SUPER is a text_item, otherwise false. */
90 static inline bool
91 is_text_item (const struct output_item *super)
92 {
93   return super->class == &text_item_class;
94 }
95
96 /* Returns SUPER converted to text_item.  SUPER must be a text_item, as
97    reported by is_text_item. */
98 static inline struct text_item *
99 to_text_item (const struct output_item *super)
100 {
101   assert (is_text_item (super));
102   return UP_CAST (super, struct text_item, output_item);
103 }
104
105 /* Returns INSTANCE converted to output_item. */
106 static inline struct output_item *
107 text_item_super (const struct text_item *instance)
108 {
109   return CONST_CAST (struct output_item *, &instance->output_item);
110 }
111
112 /* Increments INSTANCE's reference count and returns INSTANCE. */
113 static inline struct text_item *
114 text_item_ref (const struct text_item *instance)
115 {
116   return to_text_item (output_item_ref (&instance->output_item));
117 }
118
119 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
120    the reference count is now zero. */
121 static inline void
122 text_item_unref (struct text_item *instance)
123 {
124   output_item_unref (&instance->output_item);
125 }
126
127 /* Returns true if INSTANCE's reference count is greater than 1,
128    false otherwise. */
129 static inline bool
130 text_item_is_shared (const struct text_item *instance)
131 {
132   return output_item_is_shared (&instance->output_item);
133 }
134
135 void text_item_submit (struct text_item *);
136 \f
137 #endif /* output/text-item.h */