1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <hintids.hxx> 33 #include <tools/list.hxx> 34 #include <vcl/msgbox.hxx> 35 #include <svl/stritem.hxx> 36 #include <svl/intitem.hxx> 37 #include <svx/htmlmode.hxx> 38 #include <editeng/keepitem.hxx> 39 #include <editeng/brkitem.hxx> 40 #include <editeng/ulspitem.hxx> 41 #include <editeng/frmdiritem.hxx> 42 #include <svl/ctloptions.hxx> 43 #include <swmodule.hxx> 44 #include <fmtornt.hxx> 45 #include <fmtpdsc.hxx> 46 #include <fmtlsplt.hxx> 47 48 #include <svtools/htmlcfg.hxx> 49 #include <fmtrowsplt.hxx> 50 #include <svx/htmlmode.hxx> 51 52 #ifndef _DOCSH_HXX 53 #include <docsh.hxx> 54 #endif 55 #include <wrtsh.hxx> 56 #ifndef _VIEW_HXX 57 #include <view.hxx> 58 #endif 59 #include <viewopt.hxx> 60 #include <uitool.hxx> 61 #include <frmatr.hxx> 62 63 #ifndef _TABLEPG_HXX 64 #include <tablepg.hxx> 65 #endif 66 #include <tablemgr.hxx> 67 #include <pagedesc.hxx> 68 #include <poolfmt.hxx> 69 #include <SwStyleNameMapper.hxx> 70 71 #ifndef _CMDID_H 72 #include <cmdid.h> 73 #endif 74 #ifndef _TABLEDLG_HRC 75 #include <tabledlg.hrc> 76 #endif 77 #ifndef _TABLE_HRC 78 #include <table.hrc> 79 #endif 80 #include "swtablerep.hxx" 81 82 #ifdef DEBUG_TBLDLG 83 84 void DbgTColumn(TColumn* pTColumn, sal_uInt16 nCount) 85 { 86 for(sal_uInt16 i = 0; i < nCount; i++) 87 { 88 String sMsg(i); 89 sMsg += pTColumn[i].bVisible ? " v " : " h "; 90 sMsg += pTColumn[i].nWidth; 91 DBG_ERROR(sMsg) 92 } 93 } 94 #endif 95 96 97 /*-----------------20.08.96 09.43------------------- 98 --------------------------------------------------*/ 99 SwTableRep::SwTableRep( const SwTabCols& rTabCol, sal_Bool bCplx ) 100 : 101 nTblWidth(0), 102 nSpace(0), 103 nLeftSpace(0), 104 nRightSpace(0), 105 nAlign(0), 106 nWidthPercent(0), 107 bComplex(bCplx), 108 bLineSelected(sal_False), 109 bWidthChanged(sal_False), 110 bColsChanged(sal_False) 111 { 112 nAllCols = nColCount = rTabCol.Count(); 113 pTColumns = new TColumn[ nColCount + 1 ]; 114 SwTwips nStart = 0, 115 nEnd; 116 for( sal_uInt16 i = 0; i < nAllCols; ++i ) 117 { 118 nEnd = rTabCol[ i ] - rTabCol.GetLeft(); 119 pTColumns[ i ].nWidth = nEnd - nStart; 120 pTColumns[ i ].bVisible = !rTabCol.IsHidden(i); 121 if(!pTColumns[ i ].bVisible) 122 nColCount --; 123 nStart = nEnd; 124 } 125 pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart; 126 pTColumns[ nAllCols ].bVisible = sal_True; 127 nColCount++; 128 nAllCols++; 129 } 130 131 /*-----------------20.08.96 09.43------------------- 132 --------------------------------------------------*/ 133 SwTableRep::~SwTableRep() 134 { 135 delete[] pTColumns; 136 } 137 138 /*-----------------20.08.96 13.33------------------- 139 --------------------------------------------------*/ 140 sal_Bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const 141 { 142 long nOldLeft = rTabCols.GetLeft(), 143 nOldRight = rTabCols.GetRight(); 144 145 sal_Bool bSingleLine = sal_False; 146 sal_uInt16 i; 147 148 for ( i = 0; i < rTabCols.Count(); ++i ) 149 if(!pTColumns[i].bVisible) 150 { 151 bSingleLine = sal_True; 152 break; 153 } 154 155 #ifdef DEBUG_TBLDLG 156 #define DbgTColumn(pTColumns, nAllCols); 157 #endif 158 159 SwTwips nPos = 0; 160 SwTwips nLeft = GetLeftSpace(); 161 rTabCols.SetLeft(nLeft); 162 if(bSingleLine) 163 { 164 // die unsichtbaren Trenner werden aus den alten TabCols genommen 165 // die sichtbaren kommen aus pTColumns 166 TColumn* pOldTColumns = new TColumn[nAllCols + 1]; 167 SwTwips nStart = 0, 168 nEnd; 169 for(i = 0; i < nAllCols - 1; i++) 170 { 171 nEnd = rTabCols[i] - rTabCols.GetLeft(); 172 pOldTColumns[i].nWidth = nEnd - nStart; 173 pOldTColumns[i].bVisible = !rTabCols.IsHidden(i); 174 nStart = nEnd; 175 } 176 pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart; 177 pOldTColumns[nAllCols - 1].bVisible = sal_True; 178 179 #ifdef DEBUG_TBLDLG 180 #define DbgTColumn(pOldTColumns, nAllCols); 181 #endif 182 183 sal_uInt16 nOldPos = 0; 184 sal_uInt16 nNewPos = 0; 185 SwTwips nOld = 0; 186 SwTwips nNew = 0; 187 sal_Bool bOld = sal_False; 188 sal_Bool bFirst = sal_True; 189 i = 0; 190 191 while ( i < nAllCols -1 ) 192 { 193 while((bFirst || bOld ) && nOldPos < nAllCols ) 194 { 195 nOld += pOldTColumns[nOldPos].nWidth; 196 nOldPos++; 197 if(!pOldTColumns[nOldPos - 1].bVisible) 198 break; 199 } 200 while((bFirst || !bOld ) && nNewPos < nAllCols ) 201 { 202 nNew += pTColumns[nNewPos].nWidth; 203 nNewPos++; 204 if(pOldTColumns[nNewPos - 1].bVisible) 205 break; 206 } 207 bFirst = sal_False; 208 // sie muessen sortiert eingefuegt werden 209 bOld = nOld < nNew; 210 nPos = sal_uInt16(bOld ? nOld : nNew); 211 rTabCols[i] = nPos + nLeft; 212 rTabCols.SetHidden( i, bOld ); 213 i++; 214 } 215 rTabCols.SetRight(nLeft + nTblWidth); 216 217 delete[] pOldTColumns; 218 } 219 else 220 { 221 for ( i = 0; i < nAllCols - 1; ++i ) 222 { 223 nPos += pTColumns[i].nWidth; 224 rTabCols[i] = nPos + rTabCols.GetLeft(); 225 rTabCols.SetHidden( i, !pTColumns[i].bVisible ); 226 rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos); 227 } 228 } 229 230 // Rundungsfehler abfangen 231 if(Abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3) 232 rTabCols.SetLeft(nOldLeft); 233 234 if(Abs((long)nOldRight - (long)rTabCols.GetRight()) < 3) 235 rTabCols.SetRight(nOldRight); 236 237 if(GetRightSpace() >= 0 && 238 rTabCols.GetRight() > rTabCols.GetRightMax()) 239 rTabCols.SetRight(rTabCols.GetRightMax()); 240 return bSingleLine; 241 } 242