Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "hintids.hxx"
30 : : #include <editeng/lrspitem.hxx>
31 : :
32 : : #include "frmmgr.hxx"
33 : : #include "frmfmt.hxx"
34 : : #include "colmgr.hxx"
35 : :
36 : :
37 : : // private methods
38 : : /*------------------------------------------------------------------------
39 : : Description: set column width to current width
40 : : ------------------------------------------------------------------------*/
41 : 0 : void FitToActualSize(SwFmtCol& rCol, sal_uInt16 nWidth)
42 : : {
43 : 0 : const sal_uInt16 nCount = rCol.GetColumns().size();
44 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nCount; ++i)
45 : : {
46 : 0 : const sal_uInt16 nTmp = rCol.CalcColWidth(i, nWidth);
47 : 0 : rCol.GetColumns()[i].SetWishWidth(nTmp);
48 : : }
49 : 0 : rCol.SetWishWidth(nWidth);
50 : 0 : }
51 : :
52 : : // public methods
53 : : /*------------------------------------------------------------------------
54 : : Description: set column quantity and Gutterwidth
55 : : ------------------------------------------------------------------------*/
56 : 0 : void SwColMgr::SetCount(sal_uInt16 nCount, sal_uInt16 nGutterWidth)
57 : : {
58 : 0 : aFmtCol.Init(nCount, nGutterWidth, nWidth);
59 : 0 : aFmtCol.SetWishWidth(nWidth);
60 : 0 : aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
61 : 0 : }
62 : :
63 : 0 : sal_uInt16 SwColMgr::GetGutterWidth( sal_uInt16 nPos ) const
64 : : {
65 : : sal_uInt16 nRet;
66 [ # # ]: 0 : if(nPos == USHRT_MAX )
67 [ # # ]: 0 : nRet = GetCount() > 1 ? aFmtCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
68 : : else
69 : : {
70 : : OSL_ENSURE(nPos < GetCount() - 1, "Spalte ueberindiziert" );
71 : 0 : const SwColumns& rCols = aFmtCol.GetColumns();
72 : 0 : nRet = rCols[nPos].GetRight() + rCols[nPos + 1].GetLeft();
73 : : }
74 : 0 : return nRet;
75 : : }
76 : :
77 : 0 : void SwColMgr::SetGutterWidth(sal_uInt16 nGutterWidth, sal_uInt16 nPos )
78 : : {
79 [ # # ]: 0 : if(nPos == USHRT_MAX)
80 : 0 : aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
81 : : else
82 : : {
83 : : OSL_ENSURE(nPos < GetCount() - 1, "Spalte ueberindiziert" );
84 : 0 : SwColumns& rCols = aFmtCol.GetColumns();
85 : 0 : sal_uInt16 nGutterWidth2 = nGutterWidth / 2;
86 : 0 : rCols[nPos].SetRight(nGutterWidth2);
87 : 0 : rCols[nPos + 1].SetLeft(nGutterWidth2);
88 : : }
89 : 0 : }
90 : :
91 : : /*------------------------------------------------------------------------
92 : : Description: height seperation line
93 : : ------------------------------------------------------------------------*/
94 : 0 : short SwColMgr::GetLineHeightPercent() const
95 : : {
96 : 0 : return (short)aFmtCol.GetLineHeight();
97 : : }
98 : :
99 : 0 : void SwColMgr::SetLineHeightPercent(short nPercent)
100 : : {
101 : : OSL_ENSURE(nPercent <= 100, "line height may be at most 100 %");
102 : 0 : aFmtCol.SetLineHeight((sal_uInt8)nPercent);
103 : 0 : }
104 : :
105 : : /*------------------------------------------------------------------------
106 : : Description: column width
107 : : ------------------------------------------------------------------------*/
108 : 0 : sal_uInt16 SwColMgr::GetColWidth(sal_uInt16 nIdx) const
109 : : {
110 : : OSL_ENSURE(nIdx < GetCount(), "Spaltenarray ueberindiziert.");
111 : 0 : return aFmtCol.CalcPrtColWidth(nIdx, nWidth);
112 : : }
113 : :
114 : 0 : void SwColMgr::SetColWidth(sal_uInt16 nIdx, sal_uInt16 nWd)
115 : : {
116 : : OSL_ENSURE(nIdx < GetCount(), "Spaltenarray ueberindiziert.");
117 : 0 : aFmtCol.GetColumns()[nIdx].SetWishWidth(nWd);
118 : :
119 : 0 : }
120 : :
121 : : /*--------------------------------------------------------------------
122 : : Description: newly set size
123 : : --------------------------------------------------------------------*/
124 : 0 : void SwColMgr::SetActualWidth(sal_uInt16 nW)
125 : : {
126 : 0 : nWidth = nW;
127 : 0 : ::FitToActualSize(aFmtCol, nW);
128 : 0 : }
129 : :
130 : : /*--------------------------------------------------------------------
131 : : Description: ctor
132 : : --------------------------------------------------------------------*/
133 : 0 : SwColMgr::SwColMgr(const SfxItemSet& rSet, sal_uInt16 nActWidth) :
134 : 0 : aFmtCol((const SwFmtCol&)rSet.Get(RES_COL)),
135 : 0 : nWidth(nActWidth)
136 : : {
137 [ # # ]: 0 : if(nWidth == USHRT_MAX)
138 : : {
139 [ # # ]: 0 : nWidth = (sal_uInt16)((const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE)).GetWidth();
140 [ # # ]: 0 : if (nWidth < MINLAY)
141 : 0 : nWidth = USHRT_MAX;
142 [ # # ]: 0 : const SvxLRSpaceItem &rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
143 : 0 : nWidth = nWidth - (sal_uInt16)rLR.GetLeft();
144 : 0 : nWidth = nWidth - (sal_uInt16)rLR.GetRight();
145 : : }
146 [ # # ]: 0 : ::FitToActualSize(aFmtCol, nWidth);
147 : 0 : }
148 : :
149 : 0 : SwColMgr::~SwColMgr()
150 : : {
151 : 0 : }
152 : :
153 : 0 : void SwColMgr::SetLineWidthAndColor(::editeng::SvxBorderStyle eStyle, sal_uLong nLWidth, const Color& rCol)
154 : : {
155 : 0 : aFmtCol.SetLineStyle(eStyle);
156 : 0 : aFmtCol.SetLineWidth(nLWidth);
157 : 0 : aFmtCol.SetLineColor(rCol);
158 : 0 : }
159 : :
160 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|