1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SW_INC_FMTCLDS_HXX
20 #define INCLUDED_SW_INC_FMTCLDS_HXX
21 
22 #include <editeng/borderline.hxx>
23 #include <tools/color.hxx>
24 #include <tools/solar.h>
25 #include <svl/poolitem.hxx>
26 #include "swdllapi.h"
27 #include "hintids.hxx"
28 #include "format.hxx"
29 
30 #include <vector>
31 
32 /// ColumnDescriptor
33 class SwColumn
34 {
35     sal_uInt16 m_nWish;   /**< Desired width, borders included.
36                          It is inversely proportional to the ratio of
37                          desired width environment / current width column. */
38     sal_uInt16 m_nLeft;   ///< Left border.
39     sal_uInt16 m_nRight;  ///< Right border.
40 
41 public:
42     SwColumn();
43 
44     bool operator==( const SwColumn & ) const;
45 
SetWishWidth(sal_uInt16 nNew)46     void SetWishWidth( sal_uInt16 nNew ) { m_nWish  = nNew; }
SetLeft(sal_uInt16 nNew)47     void SetLeft ( sal_uInt16  nNew ) { m_nLeft  = nNew; }
SetRight(sal_uInt16 nNew)48     void SetRight( sal_uInt16  nNew ) { m_nRight = nNew; }
49 
GetWishWidth() const50     sal_uInt16 GetWishWidth() const { return m_nWish;  }
GetLeft() const51     sal_uInt16 GetLeft () const { return m_nLeft; }
GetRight() const52     sal_uInt16 GetRight() const { return m_nRight; }
53 
54     void dumpAsXml(xmlTextWriterPtr pWriter) const;
55 };
56 
57 typedef std::vector<SwColumn> SwColumns;
58 
59 enum SwColLineAdj
60 {
61     COLADJ_NONE,
62     COLADJ_TOP,
63     COLADJ_CENTER,
64     COLADJ_BOTTOM
65 };
66 
67 class SW_DLLPUBLIC SwFormatCol : public SfxPoolItem
68 {
69     SvxBorderLineStyle m_eLineStyle;     ///< style of the separator line
70     sal_uLong   m_nLineWidth;                 ///< Width of the separator line.
71     Color   m_aLineColor;                     ///< Color of the separator line.
72 
73     sal_uInt16   m_nLineHeight;               /**< Percentile height of lines.
74                                           (Based on height of columns including UL). */
75 
76     SwColLineAdj m_eAdj;                      ///< Line will be adjusted top, centered or bottom.
77 
78     SwColumns   m_aColumns;                   ///< Information concerning the columns.
79     sal_uInt16  m_nWidth;                     ///< Total desired width of all columns.
80     sal_Int16   m_aWidthAdjustValue;
81 
82     bool m_bOrtho;            /**< Only if this flag is set, the setting of GutterWidth will
83                              be accompanied by a "visual rearrangement".
84                              The flag must be reset if widths of columns or borders are changed.
85                              When it is set (again) the visual arrangement is recalculated.
86                              The flag is initially set. */
87 
88     SAL_DLLPRIVATE void Calc( sal_uInt16 nGutterWidth, sal_uInt16 nAct );
89 
90 public:
91     SwFormatCol();
92     SwFormatCol( const SwFormatCol& );
93     virtual ~SwFormatCol() override;
94     //#i120133#
GetAdjustValue() const95     sal_Int16 GetAdjustValue() const { return m_aWidthAdjustValue; }
SetAdjustValue(sal_Int16 n)96     void SetAdjustValue( sal_Int16 n ) { m_aWidthAdjustValue = n; }
97 
98     SwFormatCol& operator=( const SwFormatCol& );
99 
100     /// "pure virtual methods" of SfxPoolItem
101     virtual bool            operator==( const SfxPoolItem& ) const override;
102     virtual SfxPoolItem*    Clone( SfxItemPool* pPool = nullptr ) const override;
103     virtual bool GetPresentation( SfxItemPresentation ePres,
104                                   MapUnit eCoreMetric,
105                                   MapUnit ePresMetric,
106                                   OUString &rText,
107                                   const IntlWrapper& rIntl ) const override;
108 
109     virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
110     virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
111 
GetColumns() const112     const SwColumns &GetColumns() const { return m_aColumns; }
GetColumns()113           SwColumns &GetColumns()       { return m_aColumns; }
GetNumCols() const114     sal_uInt16           GetNumCols() const { return m_aColumns.size(); }
115 
GetLineStyle() const116     SvxBorderLineStyle     GetLineStyle() const  { return m_eLineStyle;}
GetLineWidth() const117     sal_uLong           GetLineWidth() const  { return m_nLineWidth;}
GetLineColor() const118     const Color&    GetLineColor() const { return m_aLineColor;}
119 
GetLineAdj() const120     SwColLineAdj     GetLineAdj() const { return m_eAdj; }
IsOrtho() const121     bool             IsOrtho()    const { return m_bOrtho; }
GetWishWidth() const122     sal_uInt16           GetWishWidth() const { return m_nWidth; }
GetLineHeight() const123     sal_uInt8            GetLineHeight()const { return m_nLineHeight; }
124 
125     /** @return USHRT_MAX if ambiguous.
126      @return smallest width if bMin is true. */
127     sal_uInt16 GetGutterWidth( bool bMin = false ) const;
128 
SetLineStyle(SvxBorderLineStyle eStyle)129     void SetLineStyle(SvxBorderLineStyle eStyle)        { m_eLineStyle = eStyle;}
SetLineWidth(sal_uLong nLWidth)130     void SetLineWidth(sal_uLong nLWidth)        { m_nLineWidth = nLWidth;}
SetLineColor(const Color & rCol)131     void SetLineColor(const Color& rCol )   { m_aLineColor = rCol;}
SetLineHeight(sal_uInt8 nNew)132     void SetLineHeight( sal_uInt8 nNew )     { m_nLineHeight = nNew; }
SetLineAdj(SwColLineAdj eNew)133     void SetLineAdj( SwColLineAdj eNew ){ m_eAdj = eNew; }
SetWishWidth(sal_uInt16 nNew)134     void SetWishWidth( sal_uInt16 nNew )    { m_nWidth = nNew; }
135 
136     /** This function allows to (repeatedly) initialize the columns.
137      The Ortho flag is set automatically. */
138     void Init( sal_uInt16 nNumCols, sal_uInt16 nGutterWidth, sal_uInt16 nAct );
139 
140     /** Adjusts borders for columns in aColumns.
141      If flag m_bOrtho is set, columns are visually re-arranged.
142      If the flag is not set, columns widths are not changed and
143      borders are adjusted. */
144     void SetGutterWidth( sal_uInt16 nNew, sal_uInt16 nAct );
145 
146     /** This too re-arranges columns automatically if flag is set.
147      Only in this case the second parameter is needed and evaluated. */
148     void SetOrtho( bool bNew, sal_uInt16 nGutterWidth, sal_uInt16 nAct );
149 
150     /// For the reader
SetOrtho_(bool bNew)151     void SetOrtho_( bool bNew ) { m_bOrtho = bNew; }
152 
153     /** Calculates current width of column nCol.
154      The ratio of desired width of this column to return value is
155      proportional to ratio of total desired value to nAct. */
156     sal_uInt16 CalcColWidth( sal_uInt16 nCol, sal_uInt16 nAct ) const;
157 
158     /** As above except that it @return the width of PrtArea -
159      that corresponds to what constitutes the column for the user. */
160     sal_uInt16 CalcPrtColWidth( sal_uInt16 nCol, sal_uInt16 nAct ) const;
161 
162     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
163 };
164 
GetCol(bool bInP) const165 inline const SwFormatCol &SwAttrSet::GetCol(bool bInP) const
166     { return Get( RES_COL,bInP); }
167 
GetCol(bool bInP) const168 inline const SwFormatCol &SwFormat::GetCol(bool bInP) const
169     { return m_aSet.GetCol(bInP); }
170 
171 #endif
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
174