xref: /trunk/main/sw/source/ui/frmdlg/colmgr.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 #include "hintids.hxx"
34 #include <editeng/lrspitem.hxx>
35 
36 #include "frmmgr.hxx"
37 #include "frmfmt.hxx"
38 #include "colmgr.hxx"
39 
40 
41 // PRIVATE METHODES ------------------------------------------------------
42 /*------------------------------------------------------------------------
43  Beschreibung:  Spaltenbreite auf aktuelle Breite einstellen
44 ------------------------------------------------------------------------*/
45 
46 
47 
48 void FitToActualSize(SwFmtCol& rCol, sal_uInt16 nWidth)
49 {
50     const sal_uInt16 nCount = rCol.GetColumns().Count();
51     for(sal_uInt16 i = 0; i < nCount; ++i)
52     {
53         const sal_uInt16 nTmp = rCol.CalcColWidth(i, nWidth);
54         rCol.GetColumns()[i]->SetWishWidth(nTmp);
55     }
56     rCol.SetWishWidth(nWidth);
57 }
58 
59 
60 // PUBLIC METHODES -------------------------------------------------------
61 /*------------------------------------------------------------------------
62  Beschreibung:  Setzen Spaltenanzahl und Gutterwidth
63 ------------------------------------------------------------------------*/
64 
65 
66 
67 void SwColMgr::SetCount(sal_uInt16 nCount, sal_uInt16  nGutterWidth)
68 {
69     aFmtCol.Init(nCount, nGutterWidth, nWidth);
70     aFmtCol.SetWishWidth(nWidth);
71     aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
72 }
73 
74 
75 
76 sal_uInt16 SwColMgr::GetGutterWidth( sal_uInt16 nPos ) const
77 {
78     sal_uInt16 nRet;
79     if(nPos == USHRT_MAX )
80         nRet = GetCount() > 1 ? aFmtCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
81     else
82     {
83         DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
84         const SwColumns& rCols = aFmtCol.GetColumns();
85         nRet = rCols.GetObject(nPos)->GetRight() + rCols.GetObject(nPos + 1)->GetLeft();
86     }
87     return nRet;
88 }
89 
90 /*-----------------22.10.96 14.28-------------------
91 
92 --------------------------------------------------*/
93 
94 
95 void SwColMgr::SetGutterWidth(sal_uInt16 nGutterWidth, sal_uInt16 nPos )
96 {
97     if(nPos == USHRT_MAX)
98         aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
99     else
100     {
101         DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
102         SwColumns& rCols = aFmtCol.GetColumns();
103         sal_uInt16 nGutterWidth2 = nGutterWidth / 2;
104         rCols.GetObject(nPos)->SetRight(nGutterWidth2);
105         rCols.GetObject(nPos + 1)->SetLeft(nGutterWidth2);
106     }
107 }
108 
109 /*------------------------------------------------------------------------
110  Beschreibung:  Hoehe Trennlinie
111 ------------------------------------------------------------------------*/
112 
113 
114 
115 short SwColMgr::GetLineHeightPercent() const
116 {
117     return (short)aFmtCol.GetLineHeight();
118 }
119 
120 
121 
122 void SwColMgr::SetLineHeightPercent(short nPercent)
123 {
124     ASSERT(nPercent <= 100, LineHeight darf nur bis 100 % gross  sein);
125     aFmtCol.SetLineHeight((sal_uInt8)nPercent);
126 }
127 /*------------------------------------------------------------------------
128  Beschreibung:  Spaltenbreite
129 ------------------------------------------------------------------------*/
130 
131 
132 
133 sal_uInt16 SwColMgr::GetColWidth(sal_uInt16 nIdx) const
134 {
135     ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
136     return aFmtCol.CalcPrtColWidth(nIdx, nWidth);
137 }
138 
139 
140 
141 void SwColMgr::SetColWidth(sal_uInt16 nIdx, sal_uInt16 nWd)
142 {
143     ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
144     aFmtCol.GetColumns()[nIdx]->SetWishWidth(nWd);
145 
146 }
147 
148 /*--------------------------------------------------------------------
149     Beschreibung:   Groesse neu setzen
150  --------------------------------------------------------------------*/
151 
152 
153 
154 void SwColMgr::SetActualWidth(sal_uInt16 nW)
155 {
156     nWidth = nW;
157     ::FitToActualSize(aFmtCol, nW);
158 }
159 
160 /*--------------------------------------------------------------------
161     Beschreibung: ctor
162  --------------------------------------------------------------------*/
163 
164 
165 
166 SwColMgr::SwColMgr(const SfxItemSet& rSet, sal_uInt16 nActWidth) :
167     aFmtCol((const SwFmtCol&)rSet.Get(RES_COL)),
168     nWidth(nActWidth)
169 {
170     if(nWidth == USHRT_MAX)
171     {
172         nWidth = (sal_uInt16)((const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE)).GetWidth();
173         if (nWidth < MINLAY)
174             nWidth = USHRT_MAX;
175         const SvxLRSpaceItem &rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
176         nWidth = nWidth - (sal_uInt16)rLR.GetLeft();
177         nWidth = nWidth - (sal_uInt16)rLR.GetRight();
178     }
179     ::FitToActualSize(aFmtCol, nWidth);
180 }
181 
182 
183 
184 
185 SwColMgr::~SwColMgr() {}
186 
187 
188 
189 
190 
191 
192