1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swtablerep.cxx,v $
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>
62 #include <viewopt.hxx>
67 #include <tablepg.hxx>
69 #include <tablemgr.hxx>
70 #include <pagedesc.hxx>
71 #include <poolfmt.hxx>
72 #include <SwStyleNameMapper.hxx>
78 #include <tabledlg.hrc>
83 #include "swtablerep.hxx"
87 void DbgTColumn(TColumn
* pTColumn
, USHORT nCount
)
89 for(USHORT i
= 0; i
< nCount
; i
++)
92 sMsg
+= pTColumn
[i
].bVisible
? " v " : " h ";
93 sMsg
+= pTColumn
[i
].nWidth
;
100 /*-----------------20.08.96 09.43-------------------
101 --------------------------------------------------*/
102 SwTableRep::SwTableRep( const SwTabCols
& rTabCol
, BOOL bCplx
)
111 bLineSelected(FALSE
),
112 bWidthChanged(FALSE
),
115 nAllCols
= nColCount
= rTabCol
.Count();
116 pTColumns
= new TColumn
[ nColCount
+ 1 ];
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
)
128 pTColumns
[ nAllCols
].nWidth
= rTabCol
.GetRight() - rTabCol
.GetLeft() - nStart
;
129 pTColumns
[ nAllCols
].bVisible
= TRUE
;
134 /*-----------------20.08.96 09.43-------------------
135 --------------------------------------------------*/
136 SwTableRep::~SwTableRep()
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
;
151 for ( i
= 0; i
< rTabCols
.Count(); ++i
)
152 if(!pTColumns
[i
].bVisible
)
159 #define DbgTColumn(pTColumns, nAllCols);
163 SwTwips nLeft
= GetLeftSpace();
164 rTabCols
.SetLeft(nLeft
);
167 // die unsichtbaren Trenner werden aus den alten TabCols genommen
168 // die sichtbaren kommen aus pTColumns
169 TColumn
* pOldTColumns
= new TColumn
[nAllCols
+ 1];
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
);
179 pOldTColumns
[nAllCols
- 1].nWidth
= rTabCols
.GetRight() - rTabCols
.GetLeft() - nStart
;
180 pOldTColumns
[nAllCols
- 1].bVisible
= TRUE
;
183 #define DbgTColumn(pOldTColumns, nAllCols);
194 while ( i
< nAllCols
-1 )
196 while((bFirst
|| bOld
) && nOldPos
< nAllCols
)
198 nOld
+= pOldTColumns
[nOldPos
].nWidth
;
200 if(!pOldTColumns
[nOldPos
- 1].bVisible
)
203 while((bFirst
|| !bOld
) && nNewPos
< nAllCols
)
205 nNew
+= pTColumns
[nNewPos
].nWidth
;
207 if(pOldTColumns
[nNewPos
- 1].bVisible
)
211 // sie muessen sortiert eingefuegt werden
213 nPos
= USHORT(bOld
? nOld
: nNew
);
214 rTabCols
[i
] = nPos
+ nLeft
;
215 rTabCols
.SetHidden( i
, bOld
);
218 rTabCols
.SetRight(nLeft
+ nTblWidth
);
220 delete[] pOldTColumns
;
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());