LibreOffice Module sw (master) 1
swtablerep.cxx
Go to the documentation of this file.
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#include <tabcol.hxx>
21
22#include <swtablerep.hxx>
23#include <memory>
24
26 :
27 m_nTableWidth(0),
28 m_nSpace(0),
29 m_nLeftSpace(0),
30 m_nRightSpace(0),
31 m_nAlign(0),
32 m_nWidthPercent(0),
33 m_bLineSelected(false),
34 m_bWidthChanged(false),
35 m_bColsChanged(false)
36{
37 m_nAllCols = m_nColCount = rTabCol.Count();
38 m_aTColumns.resize(m_nColCount + 1);
39 SwTwips nStart = 0,
40 nEnd;
41 for( sal_uInt16 i = 0; i < m_nAllCols; ++i )
42 {
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)
47 m_nColCount --;
48 nStart = nEnd;
49 }
50 m_aTColumns[ m_nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
51 m_aTColumns[ m_nAllCols ].bVisible = true;
53 m_nAllCols++;
54}
55
57{
58}
59
60bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
61{
62 tools::Long nOldLeft = rTabCols.GetLeft(),
63 nOldRight = rTabCols.GetRight();
64
65 bool bSingleLine = false;
66
67 for ( size_t i = 0; i < rTabCols.Count(); ++i )
69 {
70 bSingleLine = true;
71 break;
72 }
73
74 SwTwips nPos = 0;
75 const SwTwips nLeft = GetLeftSpace();
76 rTabCols.SetLeft(nLeft);
77 if(bSingleLine)
78 {
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]);
82 SwTwips nStart = 0;
83 for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
84 {
85 const SwTwips nEnd = rTabCols[i] - rTabCols.GetLeft();
86 pOldTColumns[i].nWidth = nEnd - nStart;
87 pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
88 nStart = nEnd;
89 }
90 pOldTColumns[m_nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
91 pOldTColumns[m_nAllCols - 1].bVisible = true;
92
93 sal_uInt16 nOldPos = 0;
94 sal_uInt16 nNewPos = 0;
95 SwTwips nOld = 0;
96 SwTwips nNew = 0;
97 bool bOld = false;
98 bool bFirst = true;
99
100 for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
101 {
102 while((bFirst || bOld ) && nOldPos < m_nAllCols )
103 {
104 nOld += pOldTColumns[nOldPos].nWidth;
105 nOldPos++;
106 if(!pOldTColumns[nOldPos - 1].bVisible)
107 break;
108 }
109 while((bFirst || !bOld ) && nNewPos < m_nAllCols )
110 {
111 nNew += m_aTColumns[nNewPos].nWidth;
112 nNewPos++;
113 if(pOldTColumns[nNewPos - 1].bVisible)
114 break;
115 }
116 bFirst = false;
117 // They have to be inserted sorted.
118 bOld = nOld < nNew;
119 nPos = bOld ? nOld : nNew;
120 rTabCols[i] = nPos + nLeft;
121 rTabCols.SetHidden( i, bOld );
122 }
123 rTabCols.SetRight(nLeft + m_nTableWidth);
124 }
125 else
126 {
127 for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
128 {
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);
133 }
134 }
135
136 // intercept rounding errors
137 if(std::abs(nOldLeft - rTabCols.GetLeft()) < 3)
138 rTabCols.SetLeft(nOldLeft);
139
140 if(std::abs(nOldRight - rTabCols.GetRight()) < 3)
141 rTabCols.SetRight(nOldRight);
142
143 if(GetRightSpace() >= 0 &&
144 rTabCols.GetRight() > rTabCols.GetRightMax())
145 rTabCols.SetRight(rTabCols.GetRightMax());
146 return bSingleLine;
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetRight(tools::Long nNew)
Definition: tabcol.hxx:84
size_t Count() const
Definition: tabcol.hxx:65
tools::Long GetLeft() const
Definition: tabcol.hxx:78
void SetLeft(tools::Long nNew)
Definition: tabcol.hxx:83
tools::Long GetRight() const
Definition: tabcol.hxx:79
tools::Long GetRightMax() const
Definition: tabcol.hxx:80
void SetHidden(size_t nPos, bool bValue)
Definition: tabcol.hxx:68
bool IsHidden(size_t nPos) const
Definition: tabcol.hxx:67
SwTwips GetLeftSpace() const
Definition: swtablerep.hxx:60
SwTwips m_nTableWidth
Definition: swtablerep.hxx:37
SwTwips GetRightSpace() const
Definition: swtablerep.hxx:63
bool FillTabCols(SwTabCols &rTabCol) const
Definition: swtablerep.cxx:60
std::vector< TColumn > m_aTColumns
Definition: swtablerep.hxx:35
sal_uInt16 m_nAllCols
Definition: swtablerep.hxx:43
sal_uInt16 m_nColCount
Definition: swtablerep.hxx:42
SwTableRep(const SwTabCols &rTabCol)
Definition: swtablerep.cxx:25
sal_uInt16 nPos
int i
long Long
SwNodeOffset abs(const SwNodeOffset &a)
Definition: nodeoffset.hxx:34
tools::Long SwTwips
Definition: swtypes.hxx:51
bool bVisible