merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / frmdlg / colmgr.cxx
blobc403174a67f0d583063ff50bfe36de097ab005e9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colmgr.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include "hintids.hxx"
37 #include <svx/lrspitem.hxx>
39 #include "frmmgr.hxx"
40 #include "frmfmt.hxx"
41 #include "colmgr.hxx"
44 // PRIVATE METHODES ------------------------------------------------------
45 /*------------------------------------------------------------------------
46 Beschreibung: Spaltenbreite auf aktuelle Breite einstellen
47 ------------------------------------------------------------------------*/
51 void FitToActualSize(SwFmtCol& rCol, USHORT nWidth)
53 const USHORT nCount = rCol.GetColumns().Count();
54 for(USHORT i = 0; i < nCount; ++i)
56 const USHORT nTmp = rCol.CalcColWidth(i, nWidth);
57 rCol.GetColumns()[i]->SetWishWidth(nTmp);
59 rCol.SetWishWidth(nWidth);
63 // PUBLIC METHODES -------------------------------------------------------
64 /*------------------------------------------------------------------------
65 Beschreibung: Setzen Spaltenanzahl und Gutterwidth
66 ------------------------------------------------------------------------*/
70 void SwColMgr::SetCount(USHORT nCount, USHORT nGutterWidth)
72 aFmtCol.Init(nCount, nGutterWidth, nWidth);
73 aFmtCol.SetWishWidth(nWidth);
74 aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
79 USHORT SwColMgr::GetGutterWidth( USHORT nPos ) const
81 USHORT nRet;
82 if(nPos == USHRT_MAX )
83 nRet = GetCount() > 1 ? aFmtCol.GetGutterWidth() : DEF_GUTTER_WIDTH;
84 else
86 DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
87 const SwColumns& rCols = aFmtCol.GetColumns();
88 nRet = rCols.GetObject(nPos)->GetRight() + rCols.GetObject(nPos + 1)->GetLeft();
90 return nRet;
93 /*-----------------22.10.96 14.28-------------------
95 --------------------------------------------------*/
98 void SwColMgr::SetGutterWidth(USHORT nGutterWidth, USHORT nPos )
100 if(nPos == USHRT_MAX)
101 aFmtCol.SetGutterWidth(nGutterWidth, nWidth);
102 else
104 DBG_ASSERT(nPos < GetCount() - 1, "Spalte ueberindiziert" );
105 SwColumns& rCols = aFmtCol.GetColumns();
106 USHORT nGutterWidth2 = nGutterWidth / 2;
107 rCols.GetObject(nPos)->SetRight(nGutterWidth2);
108 rCols.GetObject(nPos + 1)->SetLeft(nGutterWidth2);
112 /*------------------------------------------------------------------------
113 Beschreibung: Hoehe Trennlinie
114 ------------------------------------------------------------------------*/
118 short SwColMgr::GetLineHeightPercent() const
120 return (short)aFmtCol.GetLineHeight();
125 void SwColMgr::SetLineHeightPercent(short nPercent)
127 ASSERT(nPercent <= 100, LineHeight darf nur bis 100 % gross sein);
128 aFmtCol.SetLineHeight((BYTE)nPercent);
130 /*------------------------------------------------------------------------
131 Beschreibung: Spaltenbreite
132 ------------------------------------------------------------------------*/
136 USHORT SwColMgr::GetColWidth(USHORT nIdx) const
138 ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
139 return aFmtCol.CalcPrtColWidth(nIdx, nWidth);
144 void SwColMgr::SetColWidth(USHORT nIdx, USHORT nWd)
146 ASSERT(nIdx < GetCount(), Spaltenarray ueberindiziert.);
147 aFmtCol.GetColumns()[nIdx]->SetWishWidth(nWd);
151 /*--------------------------------------------------------------------
152 Beschreibung: Groesse neu setzen
153 --------------------------------------------------------------------*/
157 void SwColMgr::SetActualWidth(USHORT nW)
159 nWidth = nW;
160 ::FitToActualSize(aFmtCol, nW);
163 /*--------------------------------------------------------------------
164 Beschreibung: ctor
165 --------------------------------------------------------------------*/
169 SwColMgr::SwColMgr(const SfxItemSet& rSet, USHORT nActWidth) :
170 aFmtCol((const SwFmtCol&)rSet.Get(RES_COL)),
171 nWidth(nActWidth)
173 if(nWidth == USHRT_MAX)
175 nWidth = (USHORT)((const SwFmtFrmSize&)rSet.Get(RES_FRM_SIZE)).GetWidth();
176 if (nWidth < MINLAY)
177 nWidth = USHRT_MAX;
178 const SvxLRSpaceItem &rLR = (const SvxLRSpaceItem&)rSet.Get(RES_LR_SPACE);
179 nWidth = nWidth - (USHORT)rLR.GetLeft();
180 nWidth = nWidth - (USHORT)rLR.GetRight();
182 ::FitToActualSize(aFmtCol, nWidth);
188 SwColMgr::~SwColMgr() {}