Update ooo320-m1
[ooovba.git] / sw / source / ui / table / swtablerep.cxx
blob082004e70ddde74528346644ec0c8168129706aa
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: swtablerep.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"
35 #include <hintids.hxx>
36 #include <tools/list.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svtools/stritem.hxx>
39 #include <svtools/intitem.hxx>
40 #include <svx/htmlmode.hxx>
41 #include <svx/keepitem.hxx>
42 #include <svx/brkitem.hxx>
43 #include <svx/ulspitem.hxx>
44 #include <svx/frmdiritem.hxx>
45 #include <svtools/ctloptions.hxx>
46 #include <swmodule.hxx>
47 #include <fmtornt.hxx>
48 #include <fmtpdsc.hxx>
49 #include <fmtlsplt.hxx>
51 #include <svx/htmlcfg.hxx>
52 #include <fmtrowsplt.hxx>
53 #include <svx/htmlmode.hxx>
55 #ifndef _DOCSH_HXX
56 #include <docsh.hxx>
57 #endif
58 #include <wrtsh.hxx>
59 #ifndef _VIEW_HXX
60 #include <view.hxx>
61 #endif
62 #include <viewopt.hxx>
63 #include <uitool.hxx>
64 #include <frmatr.hxx>
66 #ifndef _TABLEPG_HXX
67 #include <tablepg.hxx>
68 #endif
69 #include <tablemgr.hxx>
70 #include <pagedesc.hxx>
71 #include <poolfmt.hxx>
72 #include <SwStyleNameMapper.hxx>
74 #ifndef _CMDID_H
75 #include <cmdid.h>
76 #endif
77 #ifndef _TABLEDLG_HRC
78 #include <tabledlg.hrc>
79 #endif
80 #ifndef _TABLE_HRC
81 #include <table.hrc>
82 #endif
83 #include "swtablerep.hxx"
85 #ifdef DEBUG_TBLDLG
87 void DbgTColumn(TColumn* pTColumn, USHORT nCount)
89 for(USHORT i = 0; i < nCount; i++)
91 String sMsg(i);
92 sMsg += pTColumn[i].bVisible ? " v " : " h ";
93 sMsg += pTColumn[i].nWidth;
94 DBG_ERROR(sMsg)
97 #endif
100 /*-----------------20.08.96 09.43-------------------
101 --------------------------------------------------*/
102 SwTableRep::SwTableRep( const SwTabCols& rTabCol, BOOL bCplx )
104 nTblWidth(0),
105 nSpace(0),
106 nLeftSpace(0),
107 nRightSpace(0),
108 nAlign(0),
109 nWidthPercent(0),
110 bComplex(bCplx),
111 bLineSelected(FALSE),
112 bWidthChanged(FALSE),
113 bColsChanged(FALSE)
115 nAllCols = nColCount = rTabCol.Count();
116 pTColumns = new TColumn[ nColCount + 1 ];
117 SwTwips nStart = 0,
118 nEnd;
119 for( USHORT i = 0; i < nAllCols; ++i )
121 nEnd = rTabCol[ i ] - rTabCol.GetLeft();
122 pTColumns[ i ].nWidth = nEnd - nStart;
123 pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
124 if(!pTColumns[ i ].bVisible)
125 nColCount --;
126 nStart = nEnd;
128 pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
129 pTColumns[ nAllCols ].bVisible = TRUE;
130 nColCount++;
131 nAllCols++;
134 /*-----------------20.08.96 09.43-------------------
135 --------------------------------------------------*/
136 SwTableRep::~SwTableRep()
138 delete[] pTColumns;
141 /*-----------------20.08.96 13.33-------------------
142 --------------------------------------------------*/
143 BOOL SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
145 long nOldLeft = rTabCols.GetLeft(),
146 nOldRight = rTabCols.GetRight();
148 BOOL bSingleLine = FALSE;
149 USHORT i;
151 for ( i = 0; i < rTabCols.Count(); ++i )
152 if(!pTColumns[i].bVisible)
154 bSingleLine = TRUE;
155 break;
158 #ifdef DEBUG_TBLDLG
159 #define DbgTColumn(pTColumns, nAllCols);
160 #endif
162 SwTwips nPos = 0;
163 SwTwips nLeft = GetLeftSpace();
164 rTabCols.SetLeft(nLeft);
165 if(bSingleLine)
167 // die unsichtbaren Trenner werden aus den alten TabCols genommen
168 // die sichtbaren kommen aus pTColumns
169 TColumn* pOldTColumns = new TColumn[nAllCols + 1];
170 SwTwips nStart = 0,
171 nEnd;
172 for(i = 0; i < nAllCols - 1; i++)
174 nEnd = rTabCols[i] - rTabCols.GetLeft();
175 pOldTColumns[i].nWidth = nEnd - nStart;
176 pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
177 nStart = nEnd;
179 pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
180 pOldTColumns[nAllCols - 1].bVisible = TRUE;
182 #ifdef DEBUG_TBLDLG
183 #define DbgTColumn(pOldTColumns, nAllCols);
184 #endif
186 USHORT nOldPos = 0;
187 USHORT nNewPos = 0;
188 SwTwips nOld = 0;
189 SwTwips nNew = 0;
190 BOOL bOld = FALSE;
191 BOOL bFirst = TRUE;
192 i = 0;
194 while ( i < nAllCols -1 )
196 while((bFirst || bOld ) && nOldPos < nAllCols )
198 nOld += pOldTColumns[nOldPos].nWidth;
199 nOldPos++;
200 if(!pOldTColumns[nOldPos - 1].bVisible)
201 break;
203 while((bFirst || !bOld ) && nNewPos < nAllCols )
205 nNew += pTColumns[nNewPos].nWidth;
206 nNewPos++;
207 if(pOldTColumns[nNewPos - 1].bVisible)
208 break;
210 bFirst = FALSE;
211 // sie muessen sortiert eingefuegt werden
212 bOld = nOld < nNew;
213 nPos = USHORT(bOld ? nOld : nNew);
214 rTabCols[i] = nPos + nLeft;
215 rTabCols.SetHidden( i, bOld );
216 i++;
218 rTabCols.SetRight(nLeft + nTblWidth);
220 delete[] pOldTColumns;
222 else
224 for ( i = 0; i < nAllCols - 1; ++i )
226 nPos += pTColumns[i].nWidth;
227 rTabCols[i] = nPos + rTabCols.GetLeft();
228 rTabCols.SetHidden( i, !pTColumns[i].bVisible );
229 rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
233 // Rundungsfehler abfangen
234 if(Abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3)
235 rTabCols.SetLeft(nOldLeft);
237 if(Abs((long)nOldRight - (long)rTabCols.GetRight()) < 3)
238 rTabCols.SetRight(nOldRight);
240 if(GetRightSpace() >= 0 &&
241 rTabCols.GetRight() > rTabCols.GetRightMax())
242 rTabCols.SetRight(rTabCols.GetRightMax());
243 return bSingleLine;