1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SVX_SVDOTABLE_HXX 25 #define _SVX_SVDOTABLE_HXX 26 27 #include <com/sun/star/text/WritingMode.hpp> 28 #include <com/sun/star/container/XIndexAccess.hpp> 29 #include <com/sun/star/table/XTable.hpp> 30 #include <rtl/ref.hxx> 31 #include "svdotext.hxx" 32 #include "svx/svxdllapi.h" 33 34 //------------------------------------------------------------------------ 35 36 class SvStream; 37 class SfxStyleSheet; 38 39 namespace sdr { namespace contact { 40 class ViewContactOfTableObj; 41 }} 42 43 namespace sdr { namespace table { 44 45 class TableLayouter; 46 struct ImplTableShadowPaintInfo; 47 48 #ifndef CellRef 49 class Cell; 50 typedef rtl::Reference< Cell > CellRef; 51 #endif 52 53 //------------------------------------------------------------------------ 54 // SdrTableHitKind 55 //------------------------------------------------------------------------ 56 57 enum TableHitKind 58 { 59 SDRTABLEHIT_NONE, 60 SDRTABLEHIT_CELL, 61 SDRTABLEHIT_CELLTEXTAREA, 62 SDRTABLEHIT_HORIZONTAL_BORDER, 63 SDRTABLEHIT_VERTICAL_BORDER 64 }; 65 66 //------------------------------------------------------------------------ 67 68 struct CellPos 69 { 70 sal_Int32 mnCol; 71 sal_Int32 mnRow; 72 CellPossdr::table::CellPos73 CellPos() : mnCol( 0 ), mnRow( 0 ) {} CellPossdr::table::CellPos74 CellPos( sal_Int32 nCol, sal_Int32 nRow ) { mnCol = nCol; mnRow = nRow; } 75 operator ==sdr::table::CellPos76 bool operator==( const CellPos& r ) const { return (r.mnCol == mnCol) && (r.mnRow == mnRow); } operator !=sdr::table::CellPos77 bool operator!=( const CellPos& r ) const { return (r.mnCol != mnCol) || (r.mnRow != mnRow); } 78 }; 79 80 //------------------------------------------------------------------------ 81 // TableStyleSettings 82 //------------------------------------------------------------------------ 83 84 struct SVX_DLLPUBLIC TableStyleSettings 85 { 86 bool mbUseFirstRow; 87 bool mbUseLastRow; 88 bool mbUseFirstColumn; 89 bool mbUseLastColumn; 90 bool mbUseRowBanding; 91 bool mbUseColumnBanding; 92 93 TableStyleSettings(); 94 TableStyleSettings( const TableStyleSettings& rStyle ); 95 TableStyleSettings& operator=(const TableStyleSettings& rStyle); 96 97 bool operator==( const TableStyleSettings& r ) const; 98 }; 99 100 //------------------------------------------------------------------------ 101 // SdrTableObj 102 //------------------------------------------------------------------------ 103 104 class SdrTableObjImpl; 105 106 class SVX_DLLPUBLIC SdrTableObj : public ::SdrTextObj 107 { 108 friend class Cell; 109 friend class SdrTableObjImpl; 110 friend class SdrTableModifyGuard; 111 112 public: 113 SdrTableObj(SdrModel* _pModel); 114 SdrTableObj(SdrModel* _pModel, const ::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows); 115 virtual ~SdrTableObj(); 116 117 TYPEINFO(); 118 119 // table stuff 120 121 SdrTableObj* CloneRange( const CellPos& rStartPos, const CellPos& rEndPos ); 122 void DistributeColumns( sal_Int32 nFirstColumn, sal_Int32 nLastColumn ); 123 void DistributeRows( sal_Int32 nFirstRow, sal_Int32 nLastRow ); 124 125 com::sun::star::uno::Reference< com::sun::star::table::XTable > getTable() const; 126 127 bool isValid( const sdr::table::CellPos& rPos ) const; 128 CellPos getFirstCell() const; 129 CellPos getLastCell() const; 130 CellPos getLeftCell( const CellPos& rPos, bool bEdgeTravel ) const; 131 CellPos getRightCell( const CellPos& rPos, bool bEdgeTravel ) const; 132 CellPos getUpCell( const CellPos& rPos, bool bEdgeTravel ) const; 133 CellPos getDownCell( const CellPos& rPos, bool bEdgeTravel ) const; 134 CellPos getPreviousCell( const CellPos& rPos, bool bEdgeTravel ) const; 135 CellPos getNextCell( const CellPos& rPos, bool bEdgeTravel ) const; 136 CellPos getPreviousRow( const CellPos& rPos, bool bEdgeTravel ) const; 137 CellPos getNextRow( const CellPos& rPos, bool bEdgeTravel ) const; 138 139 void createCell( ::sdr::table::CellRef& xCell ); 140 141 const ::sdr::table::TableStyleSettings& getTableStyleSettings() const; 142 void setTableStyleSettings( const ::sdr::table::TableStyleSettings& rStyle ); 143 144 TableHitKind CheckTableHit( const Point& rPos, sal_Int32& rnX, sal_Int32& rnY, int nTol ) const; 145 146 void uno_lock(); 147 void uno_unlock(); 148 149 /** the active table has the focus or is currently edited */ 150 const ::sdr::table::CellRef& getActiveCell() const; 151 152 void setActiveCell( const sdr::table::CellPos& rPos ); 153 void getActiveCellPos( sdr::table::CellPos& rPos ) const; 154 155 sal_Int32 getRowCount() const; 156 sal_Int32 getColumnCount() const; 157 158 void getCellBounds( const sdr::table::CellPos& rPos, ::Rectangle& rCellRect ); 159 160 const SfxItemSet& GetActiveCellItemSet() const; 161 162 void InsertRows( sal_Int32 nIndex, sal_Int32 nCount = 1 ); 163 void InsertColumns( sal_Int32 nIndex, sal_Int32 nCount = 1 ); 164 void DeleteRows( sal_Int32 nIndex, sal_Int32 nCount = 1 ); 165 void DeleteColumns( sal_Int32 nIndex, sal_Int32 nCount = 1 ); 166 167 void setTableStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& xAutoFormatStyle ); 168 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& getTableStyle() const; 169 170 // text stuff 171 172 /** returns the currently active text. */ 173 virtual SdrText* getActiveText() const; 174 175 /** returns the nth available text. */ 176 virtual SdrText* getText( sal_Int32 nIndex ) const; 177 178 /** returns the number of texts available for this object. */ 179 virtual sal_Int32 getTextCount() const; 180 181 /** changes the current active text */ 182 virtual void setActiveText( sal_Int32 nIndex ); 183 184 /** returns the index of the text that contains the given point or -1 */ 185 virtual sal_Int32 CheckTextHit(const Point& rPnt) const; 186 187 // #121917# 188 virtual bool HasText() const; 189 IsTextEditActive() const190 sal_Bool IsTextEditActive() const { return (pEdtOutl != 0L); } 191 bool IsTextEditActive( const sdr::table::CellPos& rPos ); 192 193 /** returns true only if we are in edit mode and the user actually changed anything */ 194 virtual bool IsRealyEdited() const; 195 196 void FitFrameToTextSize(); 197 198 SdrOutliner* GetCellTextEditOutliner( const sdr::table::CellPos& rPos ) const; 199 200 // Gleichzeitig wird der Text in den Outliner gesetzt (ggf. 201 // der des EditOutliners) und die PaperSize gesetzt. 202 virtual void TakeTextRect( const sdr::table::CellPos& rPos, SdrOutliner& rOutliner, ::Rectangle& rTextRect, FASTBOOL bNoEditText=sal_False, ::Rectangle* pAnchorRect=NULL, sal_Bool bLineWidth=sal_True ) const; 203 virtual void TakeTextRect( SdrOutliner& rOutliner, Rectangle& rTextRect, FASTBOOL bNoEditText=sal_False, Rectangle* pAnchorRect=NULL, sal_Bool bLineWidth=sal_True ) const; 204 virtual void TakeTextAnchorRect(const sdr::table::CellPos& rPos, ::Rectangle& rAnchorRect ) const; 205 virtual void TakeTextAnchorRect(::Rectangle& rAnchorRect) const; 206 207 virtual FASTBOOL IsAutoGrowHeight() const; 208 long GetMinTextFrameHeight() const; 209 long GetMaxTextFrameHeight() const; 210 virtual FASTBOOL IsAutoGrowWidth() const; 211 long GetMinTextFrameWidth() const; 212 long GetMaxTextFrameWidth() const; 213 214 virtual FASTBOOL IsFontwork() const; 215 216 virtual void SetPage(SdrPage* pNewPage); 217 virtual void SetModel(SdrModel* pNewModel); 218 virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const; 219 virtual sal_uInt16 GetObjIdentifier() const; 220 virtual void SetChanged(); 221 222 virtual FASTBOOL AdjustTextFrameWidthAndHeight(Rectangle& rR, FASTBOOL bHgt=sal_True, FASTBOOL bWdt=sal_True) const; 223 virtual FASTBOOL AdjustTextFrameWidthAndHeight(FASTBOOL bHgt=sal_True, FASTBOOL bWdt=sal_True); 224 virtual void TakeObjNameSingul(String& rName) const; 225 virtual void TakeObjNamePlural(String& rName) const; 226 virtual void operator=(const SdrObject& rObj); 227 virtual basegfx::B2DPolyPolygon TakeXorPoly() const; 228 virtual basegfx::B2DPolyPolygon TakeContour() const; 229 virtual void RecalcSnapRect(); 230 virtual const Rectangle& GetSnapRect() const; 231 virtual void NbcSetSnapRect(const Rectangle& rRect); 232 233 virtual const Rectangle& GetLogicRect() const; 234 virtual void NbcSetLogicRect(const Rectangle& rRect); 235 virtual void AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly = false ); 236 237 virtual sal_uInt32 GetSnapPointCount() const; 238 virtual Point GetSnapPoint(sal_uInt32 i) const; 239 240 virtual sal_uInt32 GetHdlCount() const; 241 virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const; 242 virtual void AddToHdlList(SdrHdlList& rHdlList) const; 243 244 // special drag methods 245 virtual bool hasSpecialDrag() const; 246 virtual bool beginSpecialDrag(SdrDragStat& rDrag) const; 247 virtual bool applySpecialDrag(SdrDragStat& rDrag); 248 virtual String getSpecialDragComment(const SdrDragStat& rDrag) const; 249 virtual basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat& rDrag) const; 250 251 virtual FASTBOOL BegCreate(SdrDragStat& rStat); 252 virtual FASTBOOL MovCreate(SdrDragStat& rStat); 253 virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd); 254 virtual FASTBOOL BckCreate(SdrDragStat& rStat); 255 virtual void BrkCreate(SdrDragStat& rStat); 256 virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat& rDrag) const; 257 virtual Pointer GetCreatePointer() const; 258 259 virtual void NbcMove(const Size& rSiz); 260 virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact); 261 262 virtual sal_Bool BegTextEdit(SdrOutliner& rOutl); 263 virtual void EndTextEdit(SdrOutliner& rOutl); 264 virtual void TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const; 265 virtual void TakeTextEditArea(const sdr::table::CellPos& rPos, Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const; 266 virtual sal_uInt16 GetOutlinerViewAnchorMode() const; 267 268 virtual void NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject); 269 270 virtual OutlinerParaObject* GetOutlinerParaObject() const; 271 virtual OutlinerParaObject* GetEditOutlinerParaObject() const; 272 273 virtual void NbcReformatText(); 274 virtual void ReformatText(); 275 SetTextEditOutliner(SdrOutliner * pOutl)276 void SetTextEditOutliner(SdrOutliner* pOutl) { pEdtOutl=pOutl; } 277 278 virtual sal_Bool IsVerticalWriting() const; 279 virtual void SetVerticalWriting(sal_Bool bVertical); 280 281 com::sun::star::text::WritingMode GetWritingMode() const; 282 283 virtual void onEditOutlinerStatusEvent( EditStatus* pEditStatus ); 284 285 //////////////////////////////////////////////////////////////////////////////////////////////////// 286 // 287 // transformation interface for StarOfficeAPI. This implements support for 288 // homogen 3x3 matrices containing the transformation of the SdrObject. At the 289 // moment it contains a shearX, rotation and translation, but for setting all linear 290 // transforms like Scale, ShearX, ShearY, Rotate and Translate are supported. 291 // 292 //////////////////////////////////////////////////////////////////////////////////////////////////// 293 // gets base transformation and rectangle of object. If it's an SdrPathObj it fills the PolyPolygon 294 // with the base geometry and returns TRUE. Otherwise it returns FALSE. 295 virtual sal_Bool TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& rPolyPolygon) const; 296 297 // sets the base geometry of the object using infos contained in the homogen 3x3 matrix. 298 // If it's an SdrPathObj it will use the provided geometry information. The Polygon has 299 // to use (0,0) as upper left and will be scaled to the given size in the matrix. 300 virtual void TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& rPolyPolygon); 301 302 // #103836# iterates over the paragraphs of a given SdrObject and removes all 303 // hard set character attributes with the which ids contained in the 304 // given vector 305 // virtual void RemoveOutlinerCharacterAttribs( const std::vector<sal_uInt16>& rCharWhichIds ); 306 307 /** hack for clipboard with calc and writer, export and import table content as rtf table */ 308 static void ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); 309 static void ImportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); 310 311 private: 312 void init( sal_Int32 nColumns, sal_Int32 nRows ); 313 314 protected: 315 virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties(); 316 virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact(); 317 318 virtual SdrObjGeoData* NewGeoData() const; 319 virtual void SaveGeoData(SdrObjGeoData& rGeo) const; 320 virtual void RestGeoData(const SdrObjGeoData& rGeo); 321 322 private: 323 SdrOutliner* GetCellTextEditOutliner( const ::sdr::table::Cell& rCell ) const; 324 325 private: 326 // for the ViewContactOfTableObj to build the primitive representation, it is necessary to access the 327 // TableLayouter for position and attribute informations 328 friend class sdr::contact::ViewContactOfTableObj; 329 const TableLayouter& getTableLayouter() const; 330 331 Rectangle maLogicRect; 332 private: 333 SdrTableObjImpl* mpImpl; 334 }; 335 336 //////////////////////////////////////////////////////////////////////////////////////////////////// 337 338 } } 339 340 #endif 341