summaryrefslogtreecommitdiffstats
path: root/sw/inc/fmtclds.hxx
blob: d2b34192b48d8e06ca86eb3f841473052b7e7c32 (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
/* -*- 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_SW_INC_FMTCLDS_HXX
#define INCLUDED_SW_INC_FMTCLDS_HXX

#include <editeng/borderline.hxx>
#include <tools/color.hxx>
#include <tools/solar.h>
#include <svl/poolitem.hxx>
#include "swdllapi.h"
#include "hintids.hxx"
#include "format.hxx"

#include <vector>

/// ColumnDescriptor
class SwColumn
{
    sal_uInt16 m_nWish;   /**< Desired width, borders included.
                         It is inversely proportional to the ratio of
                         desired width environment / current width column. */
    sal_uInt16 m_nLeft;   ///< Left border.
    sal_uInt16 m_nRight;  ///< Right border.

public:
    SwColumn();

    bool operator==( const SwColumn & ) const;

    void SetWishWidth( sal_uInt16 nNew ) { m_nWish  = nNew; }
    void SetLeft ( sal_uInt16  nNew ) { m_nLeft  = nNew; }
    void SetRight( sal_uInt16  nNew ) { m_nRight = nNew; }

    sal_uInt16 GetWishWidth() const { return m_nWish;  }
    sal_uInt16 GetLeft () const { return m_nLeft; }
    sal_uInt16 GetRight() const { return m_nRight; }

    void dumpAsXml(xmlTextWriterPtr pWriter) const;
};

typedef std::vector<SwColumn> SwColumns;

enum SwColLineAdj
{
    COLADJ_NONE,
    COLADJ_TOP,
    COLADJ_CENTER,
    COLADJ_BOTTOM
};

/// This pool item subclass can appear in the item set of an SwPageDesc, and contains settings
/// visible on the UI via Format -> Page Style -> Columns tab.
/// It can also appear in the item set of an SwSectionFormat, and then contains settings visible on
/// the UI via Format -> Sections -> Options -> Columns tab.
class SW_DLLPUBLIC SwFormatCol final : public SfxPoolItem
{
    SvxBorderLineStyle m_eLineStyle;     ///< style of the separator line
    sal_uLong   m_nLineWidth;                 ///< Width of the separator line.
    Color   m_aLineColor;                     ///< Color of the separator line.

    sal_uInt16   m_nLineHeight;               /**< Percentile height of lines.
                                          (Based on height of columns including UL). */

    SwColLineAdj m_eAdj;                      ///< Line will be adjusted top, centered or bottom.

    SwColumns   m_aColumns;                   ///< Information concerning the columns.
    sal_uInt16  m_nWidth;                     ///< Total desired width of all columns.
    sal_Int16   m_aWidthAdjustValue;

    bool m_bOrtho;            /**< Only if this flag is set, the setting of GutterWidth will
                             be accompanied by a "visual rearrangement".
                             The flag must be reset if widths of columns or borders are changed.
                             When it is set (again) the visual arrangement is recalculated.
                             The flag is initially set. */

    SAL_DLLPRIVATE void Calc( sal_uInt16 nGutterWidth, sal_uInt16 nAct );

public:
    SwFormatCol();
    SwFormatCol( const SwFormatCol& );
    virtual ~SwFormatCol() override;
    //#i120133#
    sal_Int16 GetAdjustValue() const { return m_aWidthAdjustValue; }
    void SetAdjustValue( sal_Int16 n ) { m_aWidthAdjustValue = n; }

    SwFormatCol& operator=( const SwFormatCol& );

    /// "pure virtual methods" of SfxPoolItem
    virtual bool            operator==( const SfxPoolItem& ) const override;
    virtual SwFormatCol*    Clone( SfxItemPool* pPool = nullptr ) const override;
    virtual bool GetPresentation( SfxItemPresentation ePres,
                                  MapUnit eCoreMetric,
                                  MapUnit ePresMetric,
                                  OUString &rText,
                                  const IntlWrapper& rIntl ) 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;

    const SwColumns &GetColumns() const { return m_aColumns; }
          SwColumns &GetColumns()       { return m_aColumns; }
    sal_uInt16           GetNumCols() const { return m_aColumns.size(); }

    SvxBorderLineStyle     GetLineStyle() const  { return m_eLineStyle;}
    sal_uLong           GetLineWidth() const  { return m_nLineWidth;}
    const Color&    GetLineColor() const { return m_aLineColor;}

    SwColLineAdj     GetLineAdj() const { return m_eAdj; }
    bool             IsOrtho()    const { return m_bOrtho; }
    sal_uInt16           GetWishWidth() const { return m_nWidth; }
    sal_uInt8            GetLineHeight()const { return m_nLineHeight; }

    /** @return USHRT_MAX if ambiguous.
     @return smallest width if bMin is true. */
    sal_uInt16 GetGutterWidth( bool bMin = false ) const;

    void SetLineStyle(SvxBorderLineStyle eStyle)        { m_eLineStyle = eStyle;}
    void SetLineWidth(sal_uLong nLWidth)        { m_nLineWidth = nLWidth;}
    void SetLineColor(const Color& rCol )   { m_aLineColor = rCol;}
    void SetLineHeight( sal_uInt8 nNew )     { m_nLineHeight = nNew; }
    void SetLineAdj( SwColLineAdj eNew ){ m_eAdj = eNew; }
    void SetWishWidth( sal_uInt16 nNew )    { m_nWidth = nNew; }

    /** This function allows to (repeatedly) initialize the columns.
     The Ortho flag is set automatically. */
    void Init( sal_uInt16 nNumCols, sal_uInt16 nGutterWidth, sal_uInt16 nAct );

    /** Adjusts borders for columns in aColumns.
     If flag m_bOrtho is set, columns are visually re-arranged.
     If the flag is not set, columns widths are not changed and
     borders are adjusted. */
    void SetGutterWidth( sal_uInt16 nNew, sal_uInt16 nAct );

    /** This too re-arranges columns automatically if flag is set.
     Only in this case the second parameter is needed and evaluated. */
    void SetOrtho( bool bNew, sal_uInt16 nGutterWidth, sal_uInt16 nAct );

    /// For the reader
    void SetOrtho_( bool bNew ) { m_bOrtho = bNew; }

    /** Calculates current width of column nCol.
     The ratio of desired width of this column to return value is
     proportional to ratio of total desired value to nAct. */
    sal_uInt16 CalcColWidth( sal_uInt16 nCol, sal_uInt16 nAct ) const;

    /** As above except that it @return the width of PrtArea -
     that corresponds to what constitutes the column for the user. */
    sal_uInt16 CalcPrtColWidth( sal_uInt16 nCol, sal_uInt16 nAct ) const;

    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
};

inline const SwFormatCol &SwAttrSet::GetCol(bool bInP) const
    { return Get( RES_COL,bInP); }

inline const SwFormatCol &SwFormat::GetCol(bool bInP) const
    { return m_aSet.GetCol(bInP); }

#endif

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