1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <swtablerep.hxx>
25 SwTableRep::SwTableRep( const SwTabCols
& rTabCol
)
33 m_bLineSelected(false),
34 m_bWidthChanged(false),
37 m_nAllCols
= m_nColCount
= rTabCol
.Count();
38 m_aTColumns
.resize(m_nColCount
+ 1);
41 for( sal_uInt16 i
= 0; i
< m_nAllCols
; ++i
)
43 nEnd
= rTabCol
[ i
] - rTabCol
.GetLeft();
44 m_aTColumns
[ i
].nWidth
= nEnd
- nStart
;
45 m_aTColumns
[ i
].bVisible
= !rTabCol
.IsHidden(i
);
46 if(!m_aTColumns
[ i
].bVisible
)
50 m_aTColumns
[ m_nAllCols
].nWidth
= rTabCol
.GetRight() - rTabCol
.GetLeft() - nStart
;
51 m_aTColumns
[ m_nAllCols
].bVisible
= true;
56 SwTableRep::~SwTableRep()
60 bool SwTableRep::FillTabCols( SwTabCols
& rTabCols
) const
62 tools::Long nOldLeft
= rTabCols
.GetLeft(),
63 nOldRight
= rTabCols
.GetRight();
65 bool bSingleLine
= false;
67 for ( size_t i
= 0; i
< rTabCols
.Count(); ++i
)
68 if(!m_aTColumns
[i
].bVisible
)
75 const SwTwips nLeft
= GetLeftSpace();
76 rTabCols
.SetLeft(nLeft
);
79 // The invisible separators are taken from the old TabCols,
80 // the visible coming from pTColumns.
81 std::unique_ptr
<TColumn
[]> pOldTColumns(new TColumn
[m_nAllCols
+ 1]);
83 for ( sal_uInt16 i
= 0; i
< m_nAllCols
- 1; ++i
)
85 const SwTwips nEnd
= rTabCols
[i
] - rTabCols
.GetLeft();
86 pOldTColumns
[i
].nWidth
= nEnd
- nStart
;
87 pOldTColumns
[i
].bVisible
= !rTabCols
.IsHidden(i
);
90 pOldTColumns
[m_nAllCols
- 1].nWidth
= rTabCols
.GetRight() - rTabCols
.GetLeft() - nStart
;
91 pOldTColumns
[m_nAllCols
- 1].bVisible
= true;
93 sal_uInt16 nOldPos
= 0;
94 sal_uInt16 nNewPos
= 0;
100 for ( sal_uInt16 i
= 0; i
< m_nAllCols
- 1; ++i
)
102 while((bFirst
|| bOld
) && nOldPos
< m_nAllCols
)
104 nOld
+= pOldTColumns
[nOldPos
].nWidth
;
106 if(!pOldTColumns
[nOldPos
- 1].bVisible
)
109 while((bFirst
|| !bOld
) && nNewPos
< m_nAllCols
)
111 nNew
+= m_aTColumns
[nNewPos
].nWidth
;
113 if(pOldTColumns
[nNewPos
- 1].bVisible
)
117 // They have to be inserted sorted.
119 nPos
= bOld
? nOld
: nNew
;
120 rTabCols
[i
] = nPos
+ nLeft
;
121 rTabCols
.SetHidden( i
, bOld
);
123 rTabCols
.SetRight(nLeft
+ m_nTableWidth
);
127 for ( sal_uInt16 i
= 0; i
< m_nAllCols
- 1; ++i
)
129 nPos
+= m_aTColumns
[i
].nWidth
;
130 rTabCols
[i
] = nPos
+ rTabCols
.GetLeft();
131 rTabCols
.SetHidden( i
, !m_aTColumns
[i
].bVisible
);
132 rTabCols
.SetRight(nLeft
+ m_aTColumns
[m_nAllCols
- 1].nWidth
+ nPos
);
136 // intercept rounding errors
137 if(std::abs(nOldLeft
- rTabCols
.GetLeft()) < 3)
138 rTabCols
.SetLeft(nOldLeft
);
140 if(std::abs(nOldRight
- rTabCols
.GetRight()) < 3)
141 rTabCols
.SetRight(nOldRight
);
143 if(GetRightSpace() >= 0 &&
144 rTabCols
.GetRight() > rTabCols
.GetRightMax())
145 rTabCols
.SetRight(rTabCols
.GetRightMax());
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */