1bfb63689b28cd94f6cce1c14b7c8fa570456e03
[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     /* Headings. */
34     TEXT_ITEM_PAGE_TITLE,       /* TITLE and SUBTITLE commands. */
35     TEXT_ITEM_SUBHEAD,          /* Heading within a command's output.*/
36
37     /* Syntax. */
38     TEXT_ITEM_SYNTAX,           /* A single line of PSPP syntax. */
39     TEXT_ITEM_COMMENT,          /* COMMENT command. */
40     TEXT_ITEM_ECHO,             /* ECHO command. */
41
42     /* Ordinary text. */
43     TEXT_ITEM_PARAGRAPH,        /* Normal paragraph of text. */
44     TEXT_ITEM_MONOSPACE,        /* Paragraph of monospaced text. */
45
46     /* Spacing.  Some output drivers that are not based on lines and pages
47        (e.g. CSV, HTML) may ignore these. */
48     TEXT_ITEM_BLANK_LINE,       /* Blank line. */
49     TEXT_ITEM_EJECT_PAGE        /* Eject page. */
50   };
51
52 /* A text item. */
53 struct text_item
54   {
55     struct output_item output_item;
56     char *text;                 /* The content. */
57     enum text_item_type type;   /* Type. */
58     char *font;
59     int font_size;
60     bool bold, italic, underline;
61   };
62
63 struct text_item *text_item_create (enum text_item_type, const char *text);
64 struct text_item *text_item_create_nocopy (enum text_item_type, char *text);
65 struct text_item *text_item_create_format (enum text_item_type,
66                                            const char *format, ...)
67   PRINTF_FORMAT (2, 3);
68
69 enum text_item_type text_item_get_type (const struct text_item *);
70 const char *text_item_get_text (const struct text_item *);
71 \f
72 /* This boilerplate for text_item, a subclass of output_item, was
73    autogenerated by mk-class-boilerplate. */
74
75 #include <assert.h>
76 #include "libpspp/cast.h"
77
78 extern const struct output_item_class text_item_class;
79
80 /* Returns true if SUPER is a text_item, otherwise false. */
81 static inline bool
82 is_text_item (const struct output_item *super)
83 {
84   return super->class == &text_item_class;
85 }
86
87 /* Returns SUPER converted to text_item.  SUPER must be a text_item, as
88    reported by is_text_item. */
89 static inline struct text_item *
90 to_text_item (const struct output_item *super)
91 {
92   assert (is_text_item (super));
93   return UP_CAST (super, struct text_item, output_item);
94 }
95
96 /* Returns INSTANCE converted to output_item. */
97 static inline struct output_item *
98 text_item_super (const struct text_item *instance)
99 {
100   return CONST_CAST (struct output_item *, &instance->output_item);
101 }
102
103 /* Increments INSTANCE's reference count and returns INSTANCE. */
104 static inline struct text_item *
105 text_item_ref (const struct text_item *instance)
106 {
107   return to_text_item (output_item_ref (&instance->output_item));
108 }
109
110 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
111    the reference count is now zero. */
112 static inline void
113 text_item_unref (struct text_item *instance)
114 {
115   output_item_unref (&instance->output_item);
116 }
117
118 /* Returns true if INSTANCE's reference count is greater than 1,
119    false otherwise. */
120 static inline bool
121 text_item_is_shared (const struct text_item *instance)
122 {
123   return output_item_is_shared (&instance->output_item);
124 }
125
126 void text_item_submit (struct text_item *);
127 \f
128 #endif /* output/text-item.h */