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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_TBLRWCL_HXX 20 #define INCLUDED_SW_SOURCE_CORE_INC_TBLRWCL_HXX 21 22 #include <cstddef> 23 #include <memory> 24 #include <vector> 25 26 #include <swtypes.hxx> 27 #include <swtable.hxx> 28 29 namespace editeng { class SvxBorderLine; } 30 31 class SwDoc; 32 class SwTableNode; 33 class SwTableBoxFormat; 34 class SwHistory; 35 class SwContentNode; 36 class SfxPoolItem; 37 class SwShareBoxFormats; 38 class SwFormatFrameSize; 39 40 void sw_LineSetHeadCondColl( const SwTableLine* pLine ); 41 42 #ifdef DBG_UTIL 43 void CheckBoxWidth( const SwTableLine& rLine, SwTwips nSize ); 44 #endif 45 46 void InsTableBox( SwDoc& rDoc, SwTableNode* pTableNd, 47 SwTableLine* pLine, SwTableBoxFormat* pBoxFrameFormat, 48 SwTableBox* pBox, sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 ); 49 50 void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* pUndo, 51 bool bCalcNewSize, const bool bCorrBorder, 52 SwShareBoxFormats* pShareFormats = nullptr ); 53 54 /** 55 * Class for SplitTable 56 * Collects the uppermost or lowermost Lines of a Box from a Line in an array. 57 * We also store their positions. 58 * 59 * @see implementation in ndtbl.cxx 60 */ 61 class SwCollectTableLineBoxes 62 { 63 std::vector<sal_uInt16> m_aPositionArr; 64 std::vector<SwTableBox*> m_Boxes; 65 SwHistory* m_pHistory; 66 SplitTable_HeadlineOption m_nMode; 67 sal_uInt16 m_nWidth; 68 bool m_bGetFromTop : 1; 69 bool m_bGetValues : 1; 70 71 public: SwCollectTableLineBoxes(bool bTop,SplitTable_HeadlineOption nMd=SplitTable_HeadlineOption::NONE,SwHistory * pHist=nullptr)72 SwCollectTableLineBoxes( bool bTop, SplitTable_HeadlineOption nMd = SplitTable_HeadlineOption::NONE, SwHistory* pHist=nullptr ) 73 : 74 m_pHistory( pHist ), m_nMode( nMd ), m_nWidth( 0 ), 75 m_bGetFromTop( bTop ), m_bGetValues( true ) 76 77 {} 78 79 void AddBox( const SwTableBox& rBox ); 80 const SwTableBox* GetBoxOfPos( const SwTableBox& rBox ); 81 void AddToUndoHistory( const SwContentNode& rNd ); 82 Count() const83 size_t Count() const { return m_Boxes.size(); } GetBox(std::size_t nPos,sal_uInt16 * pWidth=nullptr) const84 const SwTableBox& GetBox( std::size_t nPos, sal_uInt16* pWidth = nullptr ) const 85 { 86 // We need the EndPos of the column here! 87 if( pWidth ) 88 *pWidth = (nPos+1 == m_aPositionArr.size()) ? m_nWidth 89 : m_aPositionArr[ nPos+1 ]; 90 return *m_Boxes[ nPos ]; 91 } 92 IsGetFromTop() const93 bool IsGetFromTop() const { return m_bGetFromTop; } IsGetValues() const94 bool IsGetValues() const { return m_bGetValues; } 95 GetMode() const96 SplitTable_HeadlineOption GetMode() const { return m_nMode; } SetValues(bool bFlag)97 void SetValues( bool bFlag ) { m_bGetValues = false; m_nWidth = 0; 98 m_bGetFromTop = bFlag; } 99 bool Resize( sal_uInt16 nOffset, sal_uInt16 nWidth ); 100 }; 101 102 void sw_Box_CollectBox( const SwTableBox* pBox, SwCollectTableLineBoxes* pSplPara ); 103 bool sw_Line_CollectBox( const SwTableLine*& rpLine, void* pPara ); 104 105 void sw_BoxSetSplitBoxFormats( SwTableBox* pBox, SwCollectTableLineBoxes* pSplPara ); 106 107 /** 108 * This structure is needed by Undo to restore row span attributes 109 * when a table has been split into two tables 110 */ 111 struct SwSaveRowSpan 112 { 113 sal_uInt16 mnSplitLine; // the line number where the table has been split 114 std::vector< tools::Long > mnRowSpans; // the row span attributes in this line 115 SwSaveRowSpan( SwTableBoxes& rBoxes, sal_uInt16 nSplitLn ); 116 }; 117 118 struct SwGCLineBorder 119 { 120 const SwTableLines* pLines; 121 SwShareBoxFormats* pShareFormats; 122 sal_uInt16 nLinePos; 123 SwGCLineBorderSwGCLineBorder124 SwGCLineBorder( const SwTable& rTable ) 125 : pLines( &rTable.GetTabLines() ), pShareFormats(nullptr), nLinePos( 0 ) {} 126 SwGCLineBorderSwGCLineBorder127 SwGCLineBorder( const SwTableBox& rBox ) 128 : pLines( &rBox.GetTabLines() ), pShareFormats(nullptr), nLinePos( 0 ) {} IsLastLineSwGCLineBorder129 bool IsLastLine() const { return nLinePos + 1 >= o3tl::narrowing<sal_uInt16>(pLines->size()); } 130 }; 131 132 class SwGCBorder_BoxBrd 133 { 134 const editeng::SvxBorderLine* m_pBorderLine; 135 bool m_bAnyBorderFind; 136 public: SwGCBorder_BoxBrd()137 SwGCBorder_BoxBrd() : m_pBorderLine( nullptr ), m_bAnyBorderFind( false ) {} 138 SetBorder(const editeng::SvxBorderLine & rBorderLine)139 void SetBorder( const editeng::SvxBorderLine& rBorderLine ) 140 { m_pBorderLine = &rBorderLine; m_bAnyBorderFind = false; } 141 142 /** 143 * Check whether the left Border is the same as the set one 144 * @returns false if no Border was set 145 */ 146 bool CheckLeftBorderOfFormat( const SwFrameFormat& rFormat ); 147 IsAnyBorderFound() const148 bool IsAnyBorderFound() const { return m_bAnyBorderFind; } 149 }; 150 151 void sw_GC_Line_Border( const SwTableLine* pLine, SwGCLineBorder* pGCPara ); 152 153 class SwShareBoxFormat 154 { 155 const SwFrameFormat* m_pOldFormat; 156 std::vector<SwFrameFormat*> m_aNewFormats; 157 158 public: SwShareBoxFormat(const SwFrameFormat & rFormat)159 SwShareBoxFormat( const SwFrameFormat& rFormat ) 160 : m_pOldFormat( &rFormat ) 161 {} 162 GetOldFormat() const163 const SwFrameFormat& GetOldFormat() const { return *m_pOldFormat; } 164 165 SwFrameFormat* GetFormat( tools::Long nWidth ) const; 166 SwFrameFormat* GetFormat( const SfxPoolItem& rItem ) const; 167 void AddFormat( SwFrameFormat& rFormat ); 168 /// @returns true, if we can delete 169 bool RemoveFormat( const SwFrameFormat& rFormat ); 170 }; 171 172 class SwShareBoxFormats 173 { 174 std::vector<std::unique_ptr<SwShareBoxFormat>> m_ShareArr; 175 176 bool Seek_Entry( const SwFrameFormat& rFormat, sal_uInt16* pPos ) const; 177 178 void ChangeFrameFormat( SwTableBox* pBox, SwTableLine* pLn, SwFrameFormat& rFormat ); 179 180 public: SwShareBoxFormats()181 SwShareBoxFormats() {} 182 ~SwShareBoxFormats(); 183 184 SwFrameFormat* GetFormat( const SwFrameFormat& rFormat, tools::Long nWidth ) const; 185 SwFrameFormat* GetFormat( const SwFrameFormat& rFormat, const SfxPoolItem& ) const; 186 187 void AddFormat( const SwFrameFormat& rOld, SwFrameFormat& rNew ); 188 189 void SetSize( SwTableBox& rBox, const SwFormatFrameSize& rSz ); 190 void SetAttr( SwTableBox& rBox, const SfxPoolItem& rItem ); 191 void SetAttr( SwTableLine& rLine, const SfxPoolItem& rItem ); 192 193 void RemoveFormat( const SwFrameFormat& rFormat ); 194 }; 195 196 #endif 197 198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 199