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