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 #include <hintids.hxx>
29 #include <tools/list.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <svl/stritem.hxx>
32 #include <svl/intitem.hxx>
33 #include <svx/htmlmode.hxx>
34 #include <editeng/keepitem.hxx>
35 #include <editeng/brkitem.hxx>
36 #include <editeng/ulspitem.hxx>
37 #include <editeng/frmdiritem.hxx>
38 #include <svl/ctloptions.hxx>
39 #include <swmodule.hxx>
40 #include <fmtornt.hxx>
41 #include <fmtpdsc.hxx>
42 #include <fmtlsplt.hxx>
43
44 #include <svtools/htmlcfg.hxx>
45 #include <fmtrowsplt.hxx>
46 #include <svx/htmlmode.hxx>
47
48 #ifndef _DOCSH_HXX
49 #include <docsh.hxx>
50 #endif
51 #include <wrtsh.hxx>
52 #ifndef _VIEW_HXX
53 #include <view.hxx>
54 #endif
55 #include <viewopt.hxx>
56 #include <uitool.hxx>
57 #include <frmatr.hxx>
58
59 #ifndef _TABLEPG_HXX
60 #include <tablepg.hxx>
61 #endif
62 #include <tablemgr.hxx>
63 #include <pagedesc.hxx>
64 #include <poolfmt.hxx>
65 #include <SwStyleNameMapper.hxx>
66
67 #ifndef _CMDID_H
68 #include <cmdid.h>
69 #endif
70 #ifndef _TABLEDLG_HRC
71 #include <tabledlg.hrc>
72 #endif
73 #ifndef _TABLE_HRC
74 #include <table.hrc>
75 #endif
76 #include "swtablerep.hxx"
77
78 #ifdef DEBUG_TBLDLG
79
DbgTColumn(TColumn * pTColumn,sal_uInt16 nCount)80 void DbgTColumn(TColumn* pTColumn, sal_uInt16 nCount)
81 {
82 for(sal_uInt16 i = 0; i < nCount; i++)
83 {
84 String sMsg(i);
85 sMsg += pTColumn[i].bVisible ? " v " : " h ";
86 sMsg += pTColumn[i].nWidth;
87 DBG_ERROR(sMsg)
88 }
89 }
90 #endif
91
92
93 /*-----------------20.08.96 09.43-------------------
94 --------------------------------------------------*/
SwTableRep(const SwTabCols & rTabCol,sal_Bool bCplx)95 SwTableRep::SwTableRep( const SwTabCols& rTabCol, sal_Bool bCplx )
96 :
97 nTblWidth(0),
98 nSpace(0),
99 nLeftSpace(0),
100 nRightSpace(0),
101 nAlign(0),
102 nWidthPercent(0),
103 bComplex(bCplx),
104 bLineSelected(sal_False),
105 bWidthChanged(sal_False),
106 bColsChanged(sal_False)
107 {
108 nAllCols = nColCount = rTabCol.Count();
109 pTColumns = new TColumn[ nColCount + 1 ];
110 SwTwips nStart = 0,
111 nEnd;
112 for( sal_uInt16 i = 0; i < nAllCols; ++i )
113 {
114 nEnd = rTabCol[ i ] - rTabCol.GetLeft();
115 pTColumns[ i ].nWidth = nEnd - nStart;
116 pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
117 if(!pTColumns[ i ].bVisible)
118 nColCount --;
119 nStart = nEnd;
120 }
121 pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
122 pTColumns[ nAllCols ].bVisible = sal_True;
123 nColCount++;
124 nAllCols++;
125 }
126
127 /*-----------------20.08.96 09.43-------------------
128 --------------------------------------------------*/
~SwTableRep()129 SwTableRep::~SwTableRep()
130 {
131 delete[] pTColumns;
132 }
133
134 /*-----------------20.08.96 13.33-------------------
135 --------------------------------------------------*/
FillTabCols(SwTabCols & rTabCols) const136 sal_Bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
137 {
138 long nOldLeft = rTabCols.GetLeft(),
139 nOldRight = rTabCols.GetRight();
140
141 sal_Bool bSingleLine = sal_False;
142 sal_uInt16 i;
143
144 for ( i = 0; i < rTabCols.Count(); ++i )
145 if(!pTColumns[i].bVisible)
146 {
147 bSingleLine = sal_True;
148 break;
149 }
150
151 #ifdef DEBUG_TBLDLG
152 #define DbgTColumn(pTColumns, nAllCols);
153 #endif
154
155 SwTwips nPos = 0;
156 SwTwips nLeft = GetLeftSpace();
157 rTabCols.SetLeft(nLeft);
158 if(bSingleLine)
159 {
160 // die unsichtbaren Trenner werden aus den alten TabCols genommen
161 // die sichtbaren kommen aus pTColumns
162 TColumn* pOldTColumns = new TColumn[nAllCols + 1];
163 SwTwips nStart = 0,
164 nEnd;
165 for(i = 0; i < nAllCols - 1; i++)
166 {
167 nEnd = rTabCols[i] - rTabCols.GetLeft();
168 pOldTColumns[i].nWidth = nEnd - nStart;
169 pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
170 nStart = nEnd;
171 }
172 pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
173 pOldTColumns[nAllCols - 1].bVisible = sal_True;
174
175 #ifdef DEBUG_TBLDLG
176 #define DbgTColumn(pOldTColumns, nAllCols);
177 #endif
178
179 sal_uInt16 nOldPos = 0;
180 sal_uInt16 nNewPos = 0;
181 SwTwips nOld = 0;
182 SwTwips nNew = 0;
183 sal_Bool bOld = sal_False;
184 sal_Bool bFirst = sal_True;
185 i = 0;
186
187 while ( i < nAllCols -1 )
188 {
189 while((bFirst || bOld ) && nOldPos < nAllCols )
190 {
191 nOld += pOldTColumns[nOldPos].nWidth;
192 nOldPos++;
193 if(!pOldTColumns[nOldPos - 1].bVisible)
194 break;
195 }
196 while((bFirst || !bOld ) && nNewPos < nAllCols )
197 {
198 nNew += pTColumns[nNewPos].nWidth;
199 nNewPos++;
200 if(pOldTColumns[nNewPos - 1].bVisible)
201 break;
202 }
203 bFirst = sal_False;
204 // sie muessen sortiert eingefuegt werden
205 bOld = nOld < nNew;
206 nPos = sal_uInt16(bOld ? nOld : nNew);
207 rTabCols[i] = nPos + nLeft;
208 rTabCols.SetHidden( i, bOld );
209 i++;
210 }
211 rTabCols.SetRight(nLeft + nTblWidth);
212
213 delete[] pOldTColumns;
214 }
215 else
216 {
217 for ( i = 0; i < nAllCols - 1; ++i )
218 {
219 nPos += pTColumns[i].nWidth;
220 rTabCols[i] = nPos + rTabCols.GetLeft();
221 rTabCols.SetHidden( i, !pTColumns[i].bVisible );
222 rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
223 }
224 }
225
226 // Rundungsfehler abfangen
227 if(Abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3)
228 rTabCols.SetLeft(nOldLeft);
229
230 if(Abs((long)nOldRight - (long)rTabCols.GetRight()) < 3)
231 rTabCols.SetRight(nOldRight);
232
233 if(GetRightSpace() >= 0 &&
234 rTabCols.GetRight() > rTabCols.GetRightMax())
235 rTabCols.SetRight(rTabCols.GetRightMax());
236 return bSingleLine;
237 }
238