554d478f7407df186d726df8ae6c497db0e456d4
[pspp] / src / output / text-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011 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_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     TEXT_ITEM_PAGE_TITLE,       /* TITLE and SUBTITLE commands. */
34     TEXT_ITEM_TITLE,            /* Title. */
35     TEXT_ITEM_SYNTAX,           /* Syntax printback logging. */
36     TEXT_ITEM_LOG,              /* Other logging. */
37   };
38
39 const char *text_item_type_to_string (enum text_item_type);
40
41 /* A text item. */
42 struct text_item
43   {
44     struct output_item output_item;
45     char *text;                 /* The content. */
46     enum text_item_type type;   /* Type. */
47
48     bool bold, italic, underline, markup;
49     char *typeface;
50     int size;
51   };
52
53 struct text_item *text_item_create (enum text_item_type, const char *text);
54 struct text_item *text_item_create_nocopy (enum text_item_type, char *text);
55 struct text_item *text_item_create_format (enum text_item_type,
56                                            const char *format, ...)
57   PRINTF_FORMAT (2, 3);
58
59 enum text_item_type text_item_get_type (const struct text_item *);
60 const char *text_item_get_text (const struct text_item *);
61
62 struct table_item *text_item_to_table_item (struct text_item *);
63 \f
64 /* This boilerplate for text_item, a subclass of output_item, was
65    autogenerated by mk-class-boilerplate. */
66
67 #include <assert.h>
68 #include "libpspp/cast.h"
69
70 extern const struct output_item_class text_item_class;
71
72 /* Returns true if SUPER is a text_item, otherwise false. */
73 static inline bool
74 is_text_item (const struct output_item *super)
75 {
76   return super->class == &text_item_class;
77 }
78
79 /* Returns SUPER converted to text_item.  SUPER must be a text_item, as
80    reported by is_text_item. */
81 static inline struct text_item *
82 to_text_item (const struct output_item *super)
83 {
84   assert (is_text_item (super));
85   return UP_CAST (super, struct text_item, output_item);
86 }
87
88 /* Returns INSTANCE converted to output_item. */
89 static inline struct output_item *
90 text_item_super (const struct text_item *instance)
91 {
92   return CONST_CAST (struct output_item *, &instance->output_item);
93 }
94
95 /* Increments INSTANCE's reference count and returns INSTANCE. */
96 static inline struct text_item *
97 text_item_ref (const struct text_item *instance)
98 {
99   return to_text_item (output_item_ref (&instance->output_item));
100 }
101
102 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
103    the reference count is now zero. */
104 static inline void
105 text_item_unref (struct text_item *instance)
106 {
107   output_item_unref (&instance->output_item);
108 }
109
110 /* Returns true if INSTANCE's reference count is greater than 1,
111    false otherwise. */
112 static inline bool
113 text_item_is_shared (const struct text_item *instance)
114 {
115   return output_item_is_shared (&instance->output_item);
116 }
117
118 void text_item_submit (struct text_item *);
119 \f
120 #endif /* output/text-item.h */