xref: /aoo4110/main/sw/source/ui/frmdlg/colmgr.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
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 METHODES ------------------------------------------------------
38 /*------------------------------------------------------------------------
39  Beschreibung:	Spaltenbreite auf aktuelle Breite einstellen
40 ------------------------------------------------------------------------*/
41 
42 
43 
FitToActualSize(SwFmtCol & rCol,sal_uInt16 nWidth)44 void FitToActualSize(SwFmtCol& rCol, sal_uInt16 nWidth)
45 {
46 	const sal_uInt16 nCount = rCol.GetColumns().Count();
47 	for(sal_uInt16 i = 0; i < nCount; ++i)
48 	{
49 		const sal_uInt16 nTmp = rCol.CalcColWidth(i, nWidth);
50 		rCol.GetColumns()[i]->SetWishWidth(nTmp);
51 	}
52 	rCol.SetWishWidth(nWidth);
53 }
54 
55 
56 // PUBLIC METHODES -------------------------------------------------------
57 /*------------------------------------------------------------------------
58  Beschreibung:	Setzen Spaltenanzahl und Gutterwidth
59 ------------------------------------------------------------------------*/
60 
61 
62 
SetCount(sal_uInt16 nCount,sal_uInt16 nGutterWidth)63 void SwColMgr::SetCount(sal_uInt16 nCount, sal_uInt16  nGutterWidth)
64 {
65 	aFmtCol.Init(nCount, nGutterWidth, nWidth);
66 	aFmtCol.SetWishWidth(nWidth);
67 	aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
68 }
69 
70 
71 
GetGutterWidth(sal_uInt16 nPos) const72 sal_uInt16 SwColMgr::GetGutterWidth( sal_uInt16 nPos ) const
73 {
74 	sal_uInt16 nRet;
75 	if(nPos == USHRT_MAX )
76 		nRet = GetCount() > 1 ? aFmtCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
77 	else
78 	{
79 		DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
80 		const SwColumns& rCols = aFmtCol.GetColumns();
81 		nRet = rCols.GetObject(nPos)->GetRight() + rCols.GetObject(nPos + 1)->GetLeft();
82 	}
83 	return nRet;
84 }
85 
86 /*-----------------22.10.96 14.28-------------------
87 
88 --------------------------------------------------*/
89 
90 
SetGutterWidth(sal_uInt16 nGutterWidth,sal_uInt16 nPos)91 void SwColMgr::SetGutterWidth(sal_uInt16 nGutterWidth, sal_uInt16 nPos )
92 {
93 	if(nPos == USHRT_MAX)
94 		aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
95 	else
96 	{
97 		DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
98 		SwColumns& rCols = aFmtCol.GetColumns();
99 		sal_uInt16 nGutterWidth2 = nGutterWidth / 2;
100 		rCols.GetObject(nPos)->SetRight(nGutterWidth2);
101 		rCols.GetObject(nPos + 1)->SetLeft(nGutterWidth2);
102 	}
103 }
104 
105 /*------------------------------------------------------------------------
106  Beschreibung:	Hoehe Trennlinie
107 ------------------------------------------------------------------------*/
108 
109 
110 
GetLineHeightPercent() const111 short SwColMgr::GetLineHeightPercent() const
112 {
113 	return (short)aFmtCol.GetLineHeight();
114 }
115 
116 
117 
SetLineHeightPercent(short nPercent)118 void SwColMgr::SetLineHeightPercent(short nPercent)
119 {
120 	ASSERT(nPercent <= 100, LineHeight darf nur bis 100 % gross  sein);
121 	aFmtCol.SetLineHeight((sal_uInt8)nPercent);
122 }
123 /*------------------------------------------------------------------------
124  Beschreibung:	Spaltenbreite
125 ------------------------------------------------------------------------*/
126 
127 
128 
GetColWidth(sal_uInt16 nIdx) const129 sal_uInt16 SwColMgr::GetColWidth(sal_uInt16 nIdx) const
130 {
131 	ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
132 	return aFmtCol.CalcPrtColWidth(nIdx, nWidth);
133 }
134 
135 
136 
SetColWidth(sal_uInt16 nIdx,sal_uInt16 nWd)137 void SwColMgr::SetColWidth(sal_uInt16 nIdx, sal_uInt16 nWd)
138 {
139 	ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
140 	aFmtCol.GetColumns()[nIdx]->SetWishWidth(nWd);
141 
142 }
143 
144 /*--------------------------------------------------------------------
145 	Beschreibung: 	Groesse neu setzen
146  --------------------------------------------------------------------*/
147 
148 
149 
SetActualWidth(sal_uInt16 nW)150 void SwColMgr::SetActualWidth(sal_uInt16 nW)
151 {
152 	nWidth = nW;
153 	::FitToActualSize(aFmtCol, nW);
154 }
155 
156 /*--------------------------------------------------------------------
157 	Beschreibung: ctor
158  --------------------------------------------------------------------*/
159 
160 
161 
SwColMgr(const SfxItemSet & rSet,sal_uInt16 nActWidth)162 SwColMgr::SwColMgr(const SfxItemSet& rSet, sal_uInt16 nActWidth) :
163 	aFmtCol((const SwFmtCol&)rSet.Get(RES_COL)),
164 	nWidth(nActWidth)
165 {
166 	if(nWidth == USHRT_MAX)
167 	{
168 		nWidth = (sal_uInt16)((const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE)).GetWidth();
169 		if (nWidth < MINLAY)
170 			nWidth = USHRT_MAX;
171 		const SvxLRSpaceItem &rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
172         nWidth = nWidth - (sal_uInt16)rLR.GetLeft();
173         nWidth = nWidth - (sal_uInt16)rLR.GetRight();
174 	}
175 	::FitToActualSize(aFmtCol, nWidth);
176 }
177 
178 
179 
180 
~SwColMgr()181 SwColMgr::~SwColMgr() {}
182 
183 
184 
185 
186 
187 
188