summaryrefslogtreecommitdiff
path: root/include/editeng/lrspitem.hxx
blob: 998ea71fbb84d77fe1a62f00a50e4ddf283add8f (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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_EDITENG_LRSPITEM_HXX
#define INCLUDED_EDITENG_LRSPITEM_HXX

#include <svl/poolitem.hxx>
#include <editeng/editengdllapi.h>


// class SvxLRSpaceItem --------------------------------------------------

/*  [Description]

    Left/Right margin and first line indent

    SvxLRSpaceItem offers two interfaces to get the left margin and first line
    indent.
    - The Get* methods return the member in the way the layout used to expect:
      with a negative first line indent, the left margin shifts to the left.
    - The SetText*,GetText* methods assume that the left margin represents
      the 0 coordinate for the first line indent:

    UI         UI       LAYOUT   UI/TEXT      UI/TEXT    (Where?)
SetTextLeft SetTextFirst GetLeft GetTextLeft  GetTextFirst  (What?)
    500       -500        0        500         -500      (How much?)
    500         0        500       500           0
    500       +500       500       500         +500
    700       -500       200       700         -500
*/

class SvxFirstLineIndentItem;

/// GetLeft() - for everything that's not applied to a paragraph
class EDITENG_DLLPUBLIC SvxLeftMarginItem final : public SfxPoolItem
{
private:
    /// left margin: nothing special
    tools::Long m_nLeftMargin = 0;
    sal_uInt16 m_nPropLeftMargin = 100;

public:
    // The "layout interface":
    void SetLeft(const tools::Long nL, const sal_uInt16 nProp = 100);

    // Query/direct setting of the absolute values
    tools::Long GetLeft() const { return m_nLeftMargin; }

    sal_uInt16 GetPropLeft() const { return m_nPropLeftMargin; }

    explicit SvxLeftMarginItem(const sal_uInt16 nId);
    SvxLeftMarginItem(const tools::Long nLeft, const sal_uInt16 nId);
    SvxLeftMarginItem(SvxLeftMarginItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxLeftMarginItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

/// GetTextLeft() - for everything that's applied to a paragraph
class EDITENG_DLLPUBLIC SvxTextLeftMarginItem final : public SfxPoolItem
{
private:
    friend class SvxFirstLineIndentItem;
    /// left margin including negative first-line indent
    tools::Long m_nTextLeftMargin = 0;
    sal_uInt16 m_nPropLeftMargin = 100;

public:
    //TODO: need this?
    //void SetLeft(SvxFirstLineIndentItem const& rFirstLine, const tools::Long nL, const sal_uInt16 nProp = 100);
    /// get left margin without negative first-line indent
    tools::Long GetLeft(SvxFirstLineIndentItem const& rFirstLine) const;
    sal_uInt16 GetPropLeft() const { return m_nPropLeftMargin; }

    void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp = 100);
    tools::Long GetTextLeft() const;

    explicit SvxTextLeftMarginItem(const sal_uInt16 nId);
    SvxTextLeftMarginItem(const tools::Long nLeft, const sal_uInt16 nId);
    SvxTextLeftMarginItem(SvxTextLeftMarginItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxTextLeftMarginItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

/// first line indent that may be applied to paragraphs
class EDITENG_DLLPUBLIC SvxFirstLineIndentItem final : public SfxPoolItem
{
private:
    /// First-line indent always relative to GetTextLeft()
    short m_nFirstLineOffset = 0;
    sal_uInt16 m_nPropFirstLineOffset = 100;
    /// Automatic calculation of the first line indent
    bool m_bAutoFirst = false;

public:
    bool IsAutoFirst()  const { return m_bAutoFirst; }
    void SetAutoFirst(const bool bNew) { m_bAutoFirst = bNew; }

    void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp = 100);
    short GetTextFirstLineOffset() const { return m_nFirstLineOffset; }
    void SetPropTextFirstLineOffset(const sal_uInt16 nProp)
                    { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nPropFirstLineOffset = nProp; }
    sal_uInt16 GetPropTextFirstLineOffset() const
                    { return m_nPropFirstLineOffset; }
    void SetTextFirstLineOffsetValue(const short nValue)
                    { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nFirstLineOffset = nValue; }

    explicit SvxFirstLineIndentItem(const sal_uInt16 nId);
    SvxFirstLineIndentItem(const short nOffset, const sal_uInt16 nId);
    SvxFirstLineIndentItem(SvxFirstLineIndentItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxFirstLineIndentItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

class EDITENG_DLLPUBLIC SvxRightMarginItem final : public SfxPoolItem
{
private:
    /// right margin: nothing special
    tools::Long m_nRightMargin = 0;
    sal_uInt16 m_nPropRightMargin = 100;

public:
    // The "layout interface":
    void SetRight(const tools::Long nR, const sal_uInt16 nProp = 100);

    // Query/direct setting of the absolute values
    tools::Long GetRight() const { return m_nRightMargin;}

    sal_uInt16 GetPropRight() const { return m_nPropRightMargin; }

    explicit SvxRightMarginItem(const sal_uInt16 nId);
    SvxRightMarginItem(const tools::Long nRight, const sal_uInt16 nId);
    SvxRightMarginItem(SvxRightMarginItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxRightMarginItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

/// gutter margin - for page styles
class EDITENG_DLLPUBLIC SvxGutterLeftMarginItem final : public SfxPoolItem
{
private:
    /// The amount of extra space added to the left margin.
    tools::Long m_nGutterMargin = 0;

public:
    void SetGutterMargin(const tools::Long nGutterMargin) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nGutterMargin = nGutterMargin; }
    tools::Long GetGutterMargin() const { return m_nGutterMargin; }

    explicit SvxGutterLeftMarginItem(const sal_uInt16 nId);
    SvxGutterLeftMarginItem(SvxGutterLeftMarginItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxGutterLeftMarginItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

/// gutter margin - for page styles
class EDITENG_DLLPUBLIC SvxGutterRightMarginItem final : public SfxPoolItem
{
private:
    /// The amount of extra space added to the right margin, on mirrored pages.
    tools::Long m_nRightGutterMargin = 0;

public:
    tools::Long GetRightGutterMargin() const { return m_nRightGutterMargin; }

    explicit SvxGutterRightMarginItem(const sal_uInt16 nId);
    SvxGutterRightMarginItem(SvxGutterRightMarginItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool operator==(const SfxPoolItem&) const override;

    virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override;
    virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;

    virtual bool GetPresentation(SfxItemPresentation ePres,
                                 MapUnit eCoreMetric,
                                 MapUnit ePresMetric,
                                 OUString &rText, const IntlWrapper&) const override;

    virtual SvxGutterRightMarginItem* Clone(SfxItemPool *pPool = nullptr) const override;
    virtual void ScaleMetrics(tools::Long nMult, tools::Long nDiv) override;
    virtual bool HasMetrics() const override;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

class EDITENG_DLLPUBLIC SvxLRSpaceItem final : public SfxPoolItem
{
    /// First-line indent always relative to GetTextLeft()
    short   nFirstLineOffset;
    tools::Long    nLeftMargin;        // nLeft or the negative first-line indent
    tools::Long    nRightMargin;       // The unproblematic right edge
    /// The amount of extra space added to the left margin.
    tools::Long    m_nGutterMargin;
    /// The amount of extra space added to the right margin, on mirrored pages.
    tools::Long    m_nRightGutterMargin;

    sal_uInt16  nPropFirstLineOffset, nPropLeftMargin, nPropRightMargin;
    bool        bAutoFirst;    // Automatic calculation of the first line indent
    bool        bExplicitZeroMarginValRight;
    bool        bExplicitZeroMarginValLeft;

public:

    static SfxPoolItem* CreateDefault();

    explicit SvxLRSpaceItem( const sal_uInt16 nId  );
    SvxLRSpaceItem( const tools::Long nLeft, const tools::Long nRight,
                    const short nOfset /*= 0*/,
                    const sal_uInt16 nId  );
    SvxLRSpaceItem(SvxLRSpaceItem const &) = default; // SfxPoolItem copy function dichotomy

    // "pure virtual Methods" from SfxPoolItem
    virtual bool isHashable() const override;
    virtual size_t hashCode() const override;
    virtual bool            operator==( const SfxPoolItem& ) const override;

    virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
    virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;

    virtual bool GetPresentation( SfxItemPresentation ePres,
                                  MapUnit eCoreMetric,
                                  MapUnit ePresMetric,
                                  OUString &rText, const IntlWrapper& ) const override;

    virtual SvxLRSpaceItem*      Clone( SfxItemPool *pPool = nullptr ) const override;
    virtual void                 ScaleMetrics( tools::Long nMult, tools::Long nDiv ) override;
    virtual bool                 HasMetrics() const override;

    // The "layout interface":
    void   SetLeft (const tools::Long nL, const sal_uInt16 nProp = 100);
    void   SetRight(const tools::Long nR, const sal_uInt16 nProp = 100);

    // Query/direct setting of the absolute values
    tools::Long GetLeft()  const { return nLeftMargin; }
    tools::Long GetRight() const { return nRightMargin;}
    void SetLeftValue( const tools::Long nL ) { ASSERT_CHANGE_REFCOUNTED_ITEM; assert(nFirstLineOffset == 0); nLeftMargin = nL; }
    void SetRightValue( const tools::Long nR ) { ASSERT_CHANGE_REFCOUNTED_ITEM; nRightMargin = nR; }
    bool IsAutoFirst()  const { return bAutoFirst; }
    void SetAutoFirst( const bool bNew ) { ASSERT_CHANGE_REFCOUNTED_ITEM; bAutoFirst = bNew; }

    bool IsExplicitZeroMarginValRight()  const { return bExplicitZeroMarginValRight; }
    bool IsExplicitZeroMarginValLeft()  const { return bExplicitZeroMarginValLeft; }
    void SetExplicitZeroMarginValRight( const bool eR ) { ASSERT_CHANGE_REFCOUNTED_ITEM; bExplicitZeroMarginValRight = eR; }
    void SetExplicitZeroMarginValLeft( const bool eL ) { ASSERT_CHANGE_REFCOUNTED_ITEM; bExplicitZeroMarginValLeft = eL; }
    sal_uInt16 GetPropLeft()  const { return nPropLeftMargin; }
    sal_uInt16 GetPropRight() const { return nPropRightMargin;}

    // The UI/text interface:
    void SetTextLeft(const tools::Long nL, const sal_uInt16 nProp = 100);
    tools::Long GetTextLeft() const;

    void SetTextFirstLineOffset(const short nF, const sal_uInt16 nProp = 100);
    short  GetTextFirstLineOffset() const { return nFirstLineOffset; }
    void SetPropTextFirstLineOffset( const sal_uInt16 nProp )
                    { ASSERT_CHANGE_REFCOUNTED_ITEM; nPropFirstLineOffset = nProp; }
    sal_uInt16 GetPropTextFirstLineOffset() const
                    { return nPropFirstLineOffset; }
    void SetTextFirstLineOffsetValue( const short nValue )
                    { ASSERT_CHANGE_REFCOUNTED_ITEM; nFirstLineOffset = nValue; }
    void SetGutterMargin(const tools::Long nGutterMargin) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nGutterMargin = nGutterMargin; }
    tools::Long GetGutterMargin() const { return m_nGutterMargin; }
    void SetRightGutterMargin(const tools::Long nRightGutterMargin) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nRightGutterMargin = nRightGutterMargin; }
    tools::Long GetRightGutterMargin() const { return m_nRightGutterMargin; }

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
    virtual boost::property_tree::ptree dumpAsJSON() const override;
};

#endif

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