Line data Source code
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 :
20 : #include "hintids.hxx"
21 : #include <editeng/lrspitem.hxx>
22 :
23 : #include "frmmgr.hxx"
24 : #include "frmfmt.hxx"
25 : #include "colmgr.hxx"
26 :
27 : // private methods
28 :
29 : // set column width to current width
30 0 : void FitToActualSize(SwFormatCol& rCol, sal_uInt16 nWidth)
31 : {
32 0 : const sal_uInt16 nCount = rCol.GetColumns().size();
33 0 : for(sal_uInt16 i = 0; i < nCount; ++i)
34 : {
35 0 : const sal_uInt16 nTmp = rCol.CalcColWidth(i, nWidth);
36 0 : rCol.GetColumns()[i].SetWishWidth(nTmp);
37 : }
38 0 : rCol.SetWishWidth(nWidth);
39 0 : }
40 :
41 : // public methods
42 :
43 : // set column quantity and Gutterwidth
44 0 : void SwColMgr::SetCount(sal_uInt16 nCount, sal_uInt16 nGutterWidth)
45 : {
46 0 : aFormatCol.Init(nCount, nGutterWidth, nWidth);
47 0 : aFormatCol.SetWishWidth(nWidth);
48 0 : aFormatCol.SetGutterWidth(nGutterWidth, nWidth);
49 0 : }
50 :
51 0 : sal_uInt16 SwColMgr::GetGutterWidth( sal_uInt16 nPos ) const
52 : {
53 : sal_uInt16 nRet;
54 0 : if(nPos == USHRT_MAX )
55 0 : nRet = GetCount() > 1 ? aFormatCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
56 : else
57 : {
58 : OSL_ENSURE(nPos < GetCount() - 1, "Spalte ueberindiziert" );
59 0 : const SwColumns& rCols = aFormatCol.GetColumns();
60 0 : nRet = rCols[nPos].GetRight() + rCols[nPos + 1].GetLeft();
61 : }
62 0 : return nRet;
63 : }
64 :
65 0 : void SwColMgr::SetGutterWidth(sal_uInt16 nGutterWidth, sal_uInt16 nPos )
66 : {
67 0 : if(nPos == USHRT_MAX)
68 0 : aFormatCol.SetGutterWidth(nGutterWidth, nWidth);
69 : else
70 : {
71 : OSL_ENSURE(nPos < GetCount() - 1, "Spalte ueberindiziert" );
72 0 : SwColumns& rCols = aFormatCol.GetColumns();
73 0 : sal_uInt16 nGutterWidth2 = nGutterWidth / 2;
74 0 : rCols[nPos].SetRight(nGutterWidth2);
75 0 : rCols[nPos + 1].SetLeft(nGutterWidth2);
76 : }
77 0 : }
78 :
79 : // height separation line
80 0 : short SwColMgr::GetLineHeightPercent() const
81 : {
82 0 : return (short)aFormatCol.GetLineHeight();
83 : }
84 0 : void SwColMgr::SetLineHeightPercent(short nPercent)
85 : {
86 : OSL_ENSURE(nPercent <= 100, "line height may be at most 100%");
87 0 : aFormatCol.SetLineHeight((sal_uInt8)nPercent);
88 0 : }
89 :
90 : // column width
91 0 : sal_uInt16 SwColMgr::GetColWidth(sal_uInt16 nIdx) const
92 : {
93 : OSL_ENSURE(nIdx < GetCount(), "Spaltenarray ueberindiziert.");
94 0 : return aFormatCol.CalcPrtColWidth(nIdx, nWidth);
95 : }
96 :
97 0 : void SwColMgr::SetColWidth(sal_uInt16 nIdx, sal_uInt16 nWd)
98 : {
99 : OSL_ENSURE(nIdx < GetCount(), "Spaltenarray ueberindiziert.");
100 0 : aFormatCol.GetColumns()[nIdx].SetWishWidth(nWd);
101 :
102 0 : }
103 :
104 : // newly set size
105 0 : void SwColMgr::SetActualWidth(sal_uInt16 nW)
106 : {
107 0 : nWidth = nW;
108 0 : ::FitToActualSize(aFormatCol, nW);
109 0 : }
110 :
111 : // ctor
112 0 : SwColMgr::SwColMgr(const SfxItemSet& rSet, sal_uInt16 nActWidth) :
113 0 : aFormatCol(static_cast<const SwFormatCol&>(rSet.Get(RES_COL))),
114 0 : nWidth(nActWidth)
115 : {
116 0 : if(nWidth == USHRT_MAX)
117 : {
118 0 : nWidth = (sal_uInt16)static_cast<const SwFormatFrmSize&>(rSet.Get(RES_FRM_SIZE)).GetWidth();
119 0 : if (nWidth < MINLAY)
120 0 : nWidth = USHRT_MAX;
121 0 : const SvxLRSpaceItem &rLR = static_cast<const SvxLRSpaceItem&>(rSet.Get(RES_LR_SPACE));
122 0 : nWidth = nWidth - (sal_uInt16)rLR.GetLeft();
123 0 : nWidth = nWidth - (sal_uInt16)rLR.GetRight();
124 : }
125 0 : ::FitToActualSize(aFormatCol, nWidth);
126 0 : }
127 :
128 0 : SwColMgr::~SwColMgr()
129 : {
130 0 : }
131 :
132 0 : void SwColMgr::SetLineWidthAndColor(::editeng::SvxBorderStyle eStyle, sal_uLong nLWidth, const Color& rCol)
133 : {
134 0 : aFormatCol.SetLineStyle(eStyle);
135 0 : aFormatCol.SetLineWidth(nLWidth);
136 0 : aFormatCol.SetLineColor(rCol);
137 177 : }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|