Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <hintids.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <svl/intitem.hxx>
25 : #include <editeng/keepitem.hxx>
26 : #include <editeng/formatbreakitem.hxx>
27 : #include <editeng/ulspitem.hxx>
28 : #include <editeng/frmdiritem.hxx>
29 : #include <svl/ctloptions.hxx>
30 : #include <swmodule.hxx>
31 : #include <fmtornt.hxx>
32 : #include <fmtpdsc.hxx>
33 : #include <fmtlsplt.hxx>
34 :
35 : #include <svtools/htmlcfg.hxx>
36 : #include <fmtrowsplt.hxx>
37 : #include <sfx2/htmlmode.hxx>
38 :
39 : #include <docsh.hxx>
40 : #include <wrtsh.hxx>
41 : #include <view.hxx>
42 : #include <viewopt.hxx>
43 : #include <uitool.hxx>
44 : #include <frmatr.hxx>
45 :
46 : #include <tablepg.hxx>
47 : #include <tablemgr.hxx>
48 : #include <pagedesc.hxx>
49 : #include <poolfmt.hxx>
50 : #include <SwStyleNameMapper.hxx>
51 :
52 : #include <cmdid.h>
53 : #include <table.hrc>
54 : #include "swtablerep.hxx"
55 :
56 :
57 0 : SwTableRep::SwTableRep( const SwTabCols& rTabCol )
58 : :
59 : nTblWidth(0),
60 : nSpace(0),
61 : nLeftSpace(0),
62 : nRightSpace(0),
63 : nAlign(0),
64 : nWidthPercent(0),
65 : bLineSelected(sal_False),
66 : bWidthChanged(sal_False),
67 0 : bColsChanged(sal_False)
68 : {
69 0 : nAllCols = nColCount = rTabCol.Count();
70 0 : pTColumns = new TColumn[ nColCount + 1 ];
71 0 : SwTwips nStart = 0,
72 : nEnd;
73 0 : for( sal_uInt16 i = 0; i < nAllCols; ++i )
74 : {
75 0 : nEnd = rTabCol[ i ] - rTabCol.GetLeft();
76 0 : pTColumns[ i ].nWidth = nEnd - nStart;
77 0 : pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
78 0 : if(!pTColumns[ i ].bVisible)
79 0 : nColCount --;
80 0 : nStart = nEnd;
81 : }
82 0 : pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
83 0 : pTColumns[ nAllCols ].bVisible = sal_True;
84 0 : nColCount++;
85 0 : nAllCols++;
86 0 : }
87 :
88 0 : SwTableRep::~SwTableRep()
89 : {
90 0 : delete[] pTColumns;
91 0 : }
92 :
93 0 : sal_Bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
94 : {
95 0 : long nOldLeft = rTabCols.GetLeft(),
96 0 : nOldRight = rTabCols.GetRight();
97 :
98 0 : sal_Bool bSingleLine = sal_False;
99 : sal_uInt16 i;
100 :
101 0 : for ( i = 0; i < rTabCols.Count(); ++i )
102 0 : if(!pTColumns[i].bVisible)
103 : {
104 0 : bSingleLine = sal_True;
105 0 : break;
106 : }
107 :
108 0 : SwTwips nPos = 0;
109 0 : SwTwips nLeft = GetLeftSpace();
110 0 : rTabCols.SetLeft(nLeft);
111 0 : if(bSingleLine)
112 : {
113 : // The invisible separators are taken from the old TabCols,
114 : // the visible coming from pTColumns.
115 0 : TColumn* pOldTColumns = new TColumn[nAllCols + 1];
116 0 : SwTwips nStart = 0,
117 : nEnd;
118 0 : for(i = 0; i < nAllCols - 1; i++)
119 : {
120 0 : nEnd = rTabCols[i] - rTabCols.GetLeft();
121 0 : pOldTColumns[i].nWidth = nEnd - nStart;
122 0 : pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
123 0 : nStart = nEnd;
124 : }
125 0 : pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
126 0 : pOldTColumns[nAllCols - 1].bVisible = sal_True;
127 :
128 0 : sal_uInt16 nOldPos = 0;
129 0 : sal_uInt16 nNewPos = 0;
130 0 : SwTwips nOld = 0;
131 0 : SwTwips nNew = 0;
132 0 : sal_Bool bOld = sal_False;
133 0 : bool bFirst = true;
134 0 : i = 0;
135 :
136 0 : while ( i < nAllCols -1 )
137 : {
138 0 : while((bFirst || bOld ) && nOldPos < nAllCols )
139 : {
140 0 : nOld += pOldTColumns[nOldPos].nWidth;
141 0 : nOldPos++;
142 0 : if(!pOldTColumns[nOldPos - 1].bVisible)
143 0 : break;
144 : }
145 0 : while((bFirst || !bOld ) && nNewPos < nAllCols )
146 : {
147 0 : nNew += pTColumns[nNewPos].nWidth;
148 0 : nNewPos++;
149 0 : if(pOldTColumns[nNewPos - 1].bVisible)
150 0 : break;
151 : }
152 0 : bFirst = false;
153 : // They have to be inserted sorted.
154 0 : bOld = nOld < nNew;
155 0 : nPos = sal_uInt16(bOld ? nOld : nNew);
156 0 : rTabCols[i] = nPos + nLeft;
157 0 : rTabCols.SetHidden( i, bOld );
158 0 : i++;
159 : }
160 0 : rTabCols.SetRight(nLeft + nTblWidth);
161 :
162 0 : delete[] pOldTColumns;
163 : }
164 : else
165 : {
166 0 : for ( i = 0; i < nAllCols - 1; ++i )
167 : {
168 0 : nPos += pTColumns[i].nWidth;
169 0 : rTabCols[i] = nPos + rTabCols.GetLeft();
170 0 : rTabCols.SetHidden( i, !pTColumns[i].bVisible );
171 0 : rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
172 : }
173 : }
174 :
175 : // intercept rounding errors
176 0 : if(std::abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3)
177 0 : rTabCols.SetLeft(nOldLeft);
178 :
179 0 : if(std::abs((long)nOldRight - (long)rTabCols.GetRight()) < 3)
180 0 : rTabCols.SetRight(nOldRight);
181 :
182 0 : if(GetRightSpace() >= 0 &&
183 0 : rTabCols.GetRight() > rTabCols.GetRightMax())
184 0 : rTabCols.SetRight(rTabCols.GetRightMax());
185 0 : return bSingleLine;
186 99 : }
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|