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 <hintids.hxx>
21 #include <svl/stritem.hxx>
22 #include <svl/intitem.hxx>
23 #include <editeng/keepitem.hxx>
25 #include <editeng/ulspitem.hxx>
26 #include <editeng/frmdiritem.hxx>
27 #include <svl/ctloptions.hxx>
28 #include <swmodule.hxx>
29 #include <fmtornt.hxx>
30 #include <fmtpdsc.hxx>
31 #include <fmtlsplt.hxx>
32 
33 #include <svtools/htmlcfg.hxx>
34 #include <fmtrowsplt.hxx>
35 #include <sfx2/htmlmode.hxx>
36 
37 #include <docsh.hxx>
38 #include <wrtsh.hxx>
39 #include <view.hxx>
40 #include <viewopt.hxx>
41 #include <uitool.hxx>
42 #include <frmatr.hxx>
43 
44 #include "tablepg.hxx"
45 #include <tablemgr.hxx>
46 #include <pagedesc.hxx>
47 #include <poolfmt.hxx>
48 #include <SwStyleNameMapper.hxx>
49 
50 #include <cmdid.h>
51 #include <swtablerep.hxx>
52 #include <memory>
53 
55  :
56  m_nTableWidth(0),
57  m_nSpace(0),
58  m_nLeftSpace(0),
59  m_nRightSpace(0),
60  m_nAlign(0),
61  m_nWidthPercent(0),
62  m_bLineSelected(false),
63  m_bWidthChanged(false),
64  m_bColsChanged(false)
65 {
66  m_nAllCols = m_nColCount = rTabCol.Count();
67  m_pTColumns.reset( new TColumn[ m_nColCount + 1 ] );
68  SwTwips nStart = 0,
69  nEnd;
70  for( sal_uInt16 i = 0; i < m_nAllCols; ++i )
71  {
72  nEnd = rTabCol[ i ] - rTabCol.GetLeft();
73  m_pTColumns[ i ].nWidth = nEnd - nStart;
74  m_pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
75  if(!m_pTColumns[ i ].bVisible)
76  m_nColCount --;
77  nStart = nEnd;
78  }
79  m_pTColumns[ m_nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
80  m_pTColumns[ m_nAllCols ].bVisible = true;
81  m_nColCount++;
82  m_nAllCols++;
83 }
84 
86 {
87 }
88 
89 bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
90 {
91  long nOldLeft = rTabCols.GetLeft(),
92  nOldRight = rTabCols.GetRight();
93 
94  bool bSingleLine = false;
95 
96  for ( size_t i = 0; i < rTabCols.Count(); ++i )
97  if(!m_pTColumns[i].bVisible)
98  {
99  bSingleLine = true;
100  break;
101  }
102 
103  SwTwips nPos = 0;
104  const SwTwips nLeft = GetLeftSpace();
105  rTabCols.SetLeft(nLeft);
106  if(bSingleLine)
107  {
108  // The invisible separators are taken from the old TabCols,
109  // the visible coming from pTColumns.
110  std::unique_ptr<TColumn[]> pOldTColumns(new TColumn[m_nAllCols + 1]);
111  SwTwips nStart = 0;
112  for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
113  {
114  const SwTwips nEnd = rTabCols[i] - rTabCols.GetLeft();
115  pOldTColumns[i].nWidth = nEnd - nStart;
116  pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
117  nStart = nEnd;
118  }
119  pOldTColumns[m_nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
120  pOldTColumns[m_nAllCols - 1].bVisible = true;
121 
122  sal_uInt16 nOldPos = 0;
123  sal_uInt16 nNewPos = 0;
124  SwTwips nOld = 0;
125  SwTwips nNew = 0;
126  bool bOld = false;
127  bool bFirst = true;
128 
129  for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
130  {
131  while((bFirst || bOld ) && nOldPos < m_nAllCols )
132  {
133  nOld += pOldTColumns[nOldPos].nWidth;
134  nOldPos++;
135  if(!pOldTColumns[nOldPos - 1].bVisible)
136  break;
137  }
138  while((bFirst || !bOld ) && nNewPos < m_nAllCols )
139  {
140  nNew += m_pTColumns[nNewPos].nWidth;
141  nNewPos++;
142  if(pOldTColumns[nNewPos - 1].bVisible)
143  break;
144  }
145  bFirst = false;
146  // They have to be inserted sorted.
147  bOld = nOld < nNew;
148  nPos = bOld ? nOld : nNew;
149  rTabCols[i] = nPos + nLeft;
150  rTabCols.SetHidden( i, bOld );
151  }
152  rTabCols.SetRight(nLeft + m_nTableWidth);
153  }
154  else
155  {
156  for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
157  {
158  nPos += m_pTColumns[i].nWidth;
159  rTabCols[i] = nPos + rTabCols.GetLeft();
160  rTabCols.SetHidden( i, !m_pTColumns[i].bVisible );
161  rTabCols.SetRight(nLeft + m_pTColumns[m_nAllCols - 1].nWidth + nPos);
162  }
163  }
164 
165  // intercept rounding errors
166  if(std::abs(nOldLeft - rTabCols.GetLeft()) < 3)
167  rTabCols.SetLeft(nOldLeft);
168 
169  if(std::abs(nOldRight - rTabCols.GetRight()) < 3)
170  rTabCols.SetRight(nOldRight);
171 
172  if(GetRightSpace() >= 0 &&
173  rTabCols.GetRight() > rTabCols.GetRightMax())
174  rTabCols.SetRight(rTabCols.GetRightMax());
175  return bSingleLine;
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 m_nColCount
Definition: swtablerep.hxx:37
bool bVisible
SwTwips GetLeftSpace() const
Definition: swtablerep.hxx:50
std::unique_ptr< TColumn[]> m_pTColumns
Definition: swtablerep.hxx:30
sal_uInt16 m_nAllCols
Definition: swtablerep.hxx:38
long GetRightMax() const
Definition: tabcol.hxx:79
bool FillTabCols(SwTabCols &rTabCol) const
Definition: swtablerep.cxx:89
long SwTwips
Definition: swtypes.hxx:49
SwTwips GetRightSpace() const
Definition: swtablerep.hxx:53
long GetRight() const
Definition: tabcol.hxx:78
bool IsHidden(size_t nPos) const
Definition: tabcol.hxx:66
int i
void SetLeft(long nNew)
Definition: tabcol.hxx:82
SwTwips m_nTableWidth
Definition: swtablerep.hxx:32
SwTableRep(const SwTabCols &rTabCol)
Definition: swtablerep.cxx:54
void SetHidden(size_t nPos, bool bValue)
Definition: tabcol.hxx:67
void SetRight(long nNew)
Definition: tabcol.hxx:83
sal_uInt16 nPos
long GetLeft() const
Definition: tabcol.hxx:77
size_t Count() const
Definition: tabcol.hxx:64