summaryrefslogtreecommitdiff
path: root/include/orcus/spreadsheet/import_interface_styles.hpp
blob: 0ae6032390e4899685a4777567ab5d1d6024945a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <cstdlib>

#include "types.hpp"
#include "../types.hpp"
#include "../env.hpp"

// NB: This header must not depend on ixion, as it needs to be usable for
// those clients that provide their own formula engine.  Other headers in
// the orcus::spreadsheet namespace may depend on ixion.

namespace orcus { namespace spreadsheet { namespace iface {

class import_font_style;
class import_fill_style;
class import_border_style;
class import_cell_protection;
class import_number_format;

/**
 * Interface for styles. Note that because the default style must have an
 * index of 0 in each style category, the caller must commit the default
 * styles first before importing and setting other, non-default styles. The
 * indices of the styles are assigned sequentially starting with 0 and upward
 * in each style category.  Font, fill, border, cell protection etc are
 * considered categories in this context.
 *
 * The term 'xf' here stands for cell format.
 *
 * In contrast to xf formatting, dxf (differential formats) format only stores
 * the format information that is different from the base format data.
 */
class ORCUS_DLLPUBLIC import_styles
{
public:
    virtual ~import_styles();

    /**
     * Return a pointer to the interface instance for importing font style
     * attributes. Note that the import_styles implementer <i>must</i> return a
     * non-null pointer.
     *
     * @return pointer to the interface instance for importing font style
     *         attributes.
     */
    virtual import_font_style* get_font_style() = 0;

    /**
     * Return a pointer to the interface instance for importing fill style
     * attributes. Note that the import_styles implementer <i>must</i> return a
     * non-null pointer.
     *
     * @return pointer to the interface instance for importing fill style
     *         attributes.
     */
    virtual import_fill_style* get_fill_style() = 0;

    /**
     * Return a pointer to the interface instance for importing border style
     * attributes. Note that the import_styles implementer <i>must</i> return a
     * non-null pointer.
     *
     * @return pointer to the interface instance for importing border style
     *         attributes.
     */
    virtual import_border_style* get_border_style() = 0;

    /**
     * Return a pointer to the interface instance for importing cell protection
     * attributes. Note that the import_styles implementer <i>must</i> return a
     * non-null pointer.
     *
     * @return pointer to the interface instance for importing cell protection
     *         attributes.
     */
    virtual import_cell_protection* get_cell_protection() = 0;

    /**
     * Return a pointer to the interface instance for importing number format
     * attributes. Note that the import_styles implementer <i>must</i> return a
     * non-null pointer.
     *
     * @return pointer to the interface instance for importing number format
     *         attributes.
     */
    virtual import_number_format* get_number_format() = 0;

    /**
     * Set the total number of font styles. This may be called before importing
     * any of the font styles. This will give the implementer a chance to
     * allocate storage.  Note that it may not always be called.
     *
     * @param n number of font styles.
     */
    virtual void set_font_count(size_t n) = 0;

    /**
     * Set the total number of fill styles. This may be called before importing
     * any of the fill styles. This will give the implementer a chance to
     * allocate storage.  Note that it may not always be called.
     *
     * @param n number of fill styles.
     */
    virtual void set_fill_count(size_t n) = 0;

    /**
     * Set the total number of border styles. This may be called before
     * importing any of the border styles. This will give the implementer a
     * chance to allocate storage.  Note that it may not always be called.
     *
     * @param n number of border styles.
     */
    virtual void set_border_count(size_t n) = 0;

    /**
     * Set the total number of number format styles. This may be called before
     * importing any of the number format styles. This will give the implementer
     * a chance to allocate storage.  Note that it may not always be called.
     *
     * @param n number of number format styles.
     */
    virtual void set_number_format_count(size_t n) = 0;

    // Cell format and cell style format, and differential cell format records.
    // All of these records share the same data structure for their entries. A
    // cell in a worksheet references an entry in the cell format record
    // directly by the index, and the entry in the cell format record references
    // a cell style format in the cell style format record by the index.

    virtual void set_xf_count(xf_category_t cat, size_t n) = 0;

    virtual void set_xf_font(size_t index) = 0;
    virtual void set_xf_fill(size_t index) = 0;
    virtual void set_xf_border(size_t index) = 0;
    virtual void set_xf_protection(size_t index) = 0;
    virtual void set_xf_number_format(size_t index) = 0;

    /**
     * Set the index into the cell style record to specify a named cell style it
     * uses as its basis.
     *
     * @param index index into the cell style record it uses as its basis.
     */
    virtual void set_xf_style_xf(size_t index) = 0;
    virtual void set_xf_apply_alignment(bool b) = 0;
    virtual void set_xf_horizontal_alignment(hor_alignment_t align) = 0;
    virtual void set_xf_vertical_alignment(ver_alignment_t align) = 0;

    virtual size_t commit_cell_xf() = 0;
    virtual size_t commit_cell_style_xf() = 0;
    virtual size_t commit_dxf() = 0;

    // named cell style. It references the actual cell format data via xf index
    // into the cell style format record.

    virtual void set_cell_style_count(size_t n) = 0;
    virtual void set_cell_style_name(std::string_view s) = 0;

    /**
     * Set the index into the cell style record.  The named cell style uses the
     * entry specified by this index as its format.
     *
     * @param index index into the cell style record.
     */
    virtual void set_cell_style_xf(size_t index) = 0;

    /**
     * Set the index into the built-in style record.
     *
     * @note This is Excel-specific, and unclear whether it's useful outside of
     * Excel's implementation.  Built-in styles are not stored in file.
     *
     * @param index index into the built-in cell style record.
     */
    virtual void set_cell_style_builtin(size_t index) = 0;

    /**
     * Set the name of the parent cell style it uses as its basis.
     *
     * @note ODF uses this but Excel does not use this value.
     *
     * @param s name of the parent cell style.
     */
    virtual void set_cell_style_parent_name(std::string_view s) = 0;
    virtual size_t commit_cell_style() = 0;
};

class ORCUS_DLLPUBLIC import_font_style
{
public:
    virtual ~import_font_style();

    virtual void set_bold(bool b) = 0;
    virtual void set_italic(bool b) = 0;
    virtual void set_name(std::string_view s) = 0;
    virtual void set_size(double point) = 0;
    virtual void set_underline(underline_t e) = 0;
    virtual void set_underline_width(underline_width_t e) = 0;
    virtual void set_underline_mode(underline_mode_t e) = 0;
    virtual void set_underline_type(underline_type_t e) = 0;
    virtual void set_underline_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue) = 0;
    virtual void set_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue) = 0;
    virtual void set_strikethrough_style(strikethrough_style_t s) = 0;
    virtual void set_strikethrough_type(strikethrough_type_t s) = 0;
    virtual void set_strikethrough_width(strikethrough_width_t s) = 0;
    virtual void set_strikethrough_text(strikethrough_text_t s) = 0;
    virtual size_t commit() = 0;
};

class ORCUS_DLLPUBLIC import_fill_style
{
public:
    virtual ~import_fill_style();

    /**
     * Set the type of fill pattern.
     *
     * @param fp fill pattern type.
     */
    virtual void set_pattern_type(fill_pattern_t fp) = 0;

    /**
     * Set the foreground color of a fill.  <i>Note that for a solid fill
     * type, the foreground color will be used.</i>
     *
     * @param alpha alpha component ranging from 0 (fully transparent) to 255
     *              (fully opaque).
     * @param red red component ranging from 0 to 255.
     * @param green green component ranging from 0 to 255.
     * @param blue blue component ranging from 0 to 255.
     */
    virtual void set_fg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue) = 0;

    /**
     * Set the background color of a fill.  <i>Note that this color will
     * be ignored for a solid fill type.</i>
     *
     * @param alpha alpha component ranging from 0 (fully transparent) to 255
     *              (fully opaque).
     * @param red red component ranging from 0 to 255.
     * @param green green component ranging from 0 to 255.
     * @param blue blue component ranging from 0 to 255.
     */
    virtual void set_bg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue) = 0;

    /**
     * Commit the fill style currently in the buffer.
     *
     * @return the ID of the committed fill style, to be passed on to the
     *         set_xf_fill() method as its argument.
     */
    virtual size_t commit() = 0;
};

class ORCUS_DLLPUBLIC import_border_style
{
public:
    virtual ~import_border_style();

    virtual void set_style(border_direction_t dir, border_style_t style) = 0;
    virtual void set_color(
        border_direction_t dir, color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue) = 0;
    virtual void set_width(border_direction_t dir, double width, orcus::length_unit_t unit) = 0;
    virtual size_t commit() = 0;
};

class ORCUS_DLLPUBLIC import_cell_protection
{
public:
    virtual ~import_cell_protection();

    virtual void set_hidden(bool b) = 0;
    virtual void set_locked(bool b) = 0;
    virtual void set_print_content(bool b) = 0;
    virtual void set_formula_hidden(bool b) = 0;
    virtual size_t commit() = 0;
};

class ORCUS_DLLPUBLIC import_number_format
{
public:
    virtual ~import_number_format();

    virtual void set_identifier(std::size_t id) = 0;
    virtual void set_code(std::string_view s) = 0;
    virtual size_t commit() = 0;
};

}}}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */