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 SC_XEESCHER_HXX 25 #define SC_XEESCHER_HXX 26 27 #include <vcl/graph.hxx> 28 #include <filter/msfilter/escherex.hxx> 29 #include "xcl97rec.hxx" 30 #include "xlescher.hxx" 31 32 namespace com { namespace sun { namespace star { 33 namespace script { struct ScriptEventDescriptor; } 34 } } } 35 36 // DFF client anchor ========================================================== 37 38 /** Base class for DFF client anchor atoms used in spreadsheets. */ 39 class XclExpDffAnchorBase : public EscherExClientAnchor_Base, protected XclExpRoot 40 { 41 public: 42 /** Constructs a dummy client anchor. */ 43 explicit XclExpDffAnchorBase( const XclExpRoot& rRoot, sal_uInt16 nFlags = 0 ); 44 45 /** Sets the flags according to the passed SdrObject. */ 46 void SetFlags( const SdrObject& rSdrObj ); 47 /** Sets the anchor position and flags according to the passed SdrObject. */ 48 void SetSdrObject( const SdrObject& rSdrObj ); 49 50 /** Writes the DFF client anchor structure with the current anchor position. */ 51 void WriteDffData( EscherEx& rEscherEx ) const; 52 53 /** Called from SVX DFF converter. 54 @param rRect The object anchor rectangle to be exported (in twips). */ 55 virtual void WriteData( EscherEx& rEscherEx, const Rectangle& rRect ); 56 57 private: 58 virtual void ImplSetFlags( const SdrObject& rSdrObj ); 59 virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit ); 60 61 protected: // for access in derived classes 62 XclObjAnchor maAnchor; /// The client anchor data. 63 sal_uInt16 mnFlags; /// Flags for DFF stream export. 64 }; 65 66 // ---------------------------------------------------------------------------- 67 68 /** Represents the position (anchor) of an object in a Calc sheet. */ 69 class XclExpDffSheetAnchor : public XclExpDffAnchorBase 70 { 71 public: 72 explicit XclExpDffSheetAnchor( const XclExpRoot& rRoot ); 73 74 private: 75 virtual void ImplSetFlags( const SdrObject& rSdrObj ); 76 virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit ); 77 78 private: 79 SCTAB mnScTab; /// Calc sheet index. 80 }; 81 82 // ---------------------------------------------------------------------------- 83 84 /** Represents the position (anchor) of a shape in an embedded draw page. */ 85 class XclExpDffEmbeddedAnchor : public XclExpDffAnchorBase 86 { 87 public: 88 explicit XclExpDffEmbeddedAnchor( const XclExpRoot& rRoot, 89 const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY ); 90 91 private: 92 virtual void ImplSetFlags( const SdrObject& rSdrObj ); 93 virtual void ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit ); 94 95 private: 96 Size maPageSize; 97 sal_Int32 mnScaleX; 98 sal_Int32 mnScaleY; 99 }; 100 101 // ---------------------------------------------------------------------------- 102 103 /** Represents the position (anchor) of a note object. */ 104 class XclExpDffNoteAnchor : public XclExpDffAnchorBase 105 { 106 public: 107 explicit XclExpDffNoteAnchor( const XclExpRoot& rRoot, const Rectangle& rRect ); 108 }; 109 110 // ---------------------------------------------------------------------------- 111 112 /** Represents the position (anchor) of a cell dropdown object. */ 113 class XclExpDffDropDownAnchor : public XclExpDffAnchorBase 114 { 115 public: 116 explicit XclExpDffDropDownAnchor( const XclExpRoot& rRoot, const ScAddress& rScPos ); 117 }; 118 119 // MSODRAWING* records ======================================================== 120 121 /** Base class for records holding DFF stream fragments. */ 122 class XclExpMsoDrawingBase : public XclExpRecord 123 { 124 public: 125 explicit XclExpMsoDrawingBase( XclEscherEx& rEscherEx, sal_uInt16 nRecId ); 126 127 private: 128 virtual void WriteBody( XclExpStream& rStrm ); 129 130 protected: 131 XclEscherEx& mrEscherEx; /// Reference to the DFF converter containing the DFF stream. 132 sal_uInt32 mnFragmentKey; /// The key of the DFF stream fragment to be written by this record. 133 }; 134 135 // ---------------------------------------------------------------------------- 136 137 /** The MSODRAWINGGROUP record contains the DGGCONTAINER with global DFF data 138 such as the picture container. 139 */ 140 class XclExpMsoDrawingGroup : public XclExpMsoDrawingBase 141 { 142 public: 143 explicit XclExpMsoDrawingGroup( XclEscherEx& rEscherEx ); 144 }; 145 146 // ---------------------------------------------------------------------------- 147 148 /** One or more MSODRAWING records contain the DFF stream data for a drawing 149 shape. 150 */ 151 class XclExpMsoDrawing : public XclExpMsoDrawingBase 152 { 153 public: 154 explicit XclExpMsoDrawing( XclEscherEx& rEscherEx ); 155 }; 156 157 // ============================================================================ 158 159 /** Provides export of bitmap data to an IMGDATA record. */ 160 class XclExpImgData : public XclExpRecordBase 161 { 162 public: 163 explicit XclExpImgData( const Graphic& rGraphic, sal_uInt16 nRecId ); 164 165 /** Writes the BITMAP record. */ 166 virtual void Save( XclExpStream& rStrm ); 167 168 private: 169 Graphic maGraphic; /// The VCL graphic. 170 sal_uInt16 mnRecId; /// Record identifier for the IMGDATA record. 171 }; 172 173 // ============================================================================ 174 175 /** Helper class for form controils to manage spreadsheet links . */ 176 class XclExpControlHelper : protected XclExpRoot 177 { 178 public: 179 explicit XclExpControlHelper( const XclExpRoot& rRoot ); 180 virtual ~XclExpControlHelper(); 181 182 protected: 183 /** Tries to get spreadsheet cell link and source range link from the passed shape. */ 184 void ConvertSheetLinks( 185 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ); 186 187 188 /** Returns the Excel token array of the cell link, or 0, if no link present. */ GetCellLinkTokArr() const189 inline const XclTokenArray* GetCellLinkTokArr() const { return mxCellLink.get(); } 190 /** Returns the Excel token array of the source range, or 0, if no link present. */ GetSourceRangeTokArr() const191 inline const XclTokenArray* GetSourceRangeTokArr() const { return mxSrcRange.get(); } 192 /** Returns the number of entries in the source range, or 0, if no source set. */ GetSourceEntryCount() const193 inline sal_uInt16 GetSourceEntryCount() const { return mnEntryCount; } 194 195 /** Writes a formula with special style only valid in OBJ records. */ 196 void WriteFormula( XclExpStream& rStrm, const XclTokenArray& rTokArr ) const; 197 /** Writes a formula subrecord with special style only valid in OBJ records. */ 198 void WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclTokenArray& rTokArr ) const; 199 200 private: 201 XclTokenArrayRef mxCellLink; /// Formula for linked cell. 202 XclTokenArrayRef mxSrcRange; /// Formula for source data range. 203 sal_uInt16 mnEntryCount; /// Number of entries in source range. 204 }; 205 206 // ---------------------------------------------------------------------------- 207 208 //delete for exporting OCX 209 //#if EXC_EXP_OCX_CTRL 210 211 /** Represents an OBJ record for an OCX form control. */ 212 class XclExpOcxControlObj : public XclObj, public XclExpControlHelper 213 { 214 public: 215 explicit XclExpOcxControlObj( 216 XclExpObjectManager& rObjMgr, 217 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape, 218 const Rectangle* pChildAnchor, 219 const String& rClassName, 220 sal_uInt32 nStrmStart, sal_uInt32 nStrmSize ); 221 222 private: 223 virtual void WriteSubRecs( XclExpStream& rStrm ); 224 225 private: 226 String maClassName; /// Class name of the control. 227 sal_uInt32 mnStrmStart; /// Start position in 'Ctls' stream. 228 sal_uInt32 mnStrmSize; /// Size in 'Ctls' stream. 229 }; 230 231 //#else 232 233 /** Represents an OBJ record for an TBX form control. */ 234 class XclExpTbxControlObj : public XclObj, public XclExpControlHelper 235 { 236 public: 237 explicit XclExpTbxControlObj( 238 XclExpObjectManager& rObjMgr, 239 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape, 240 const Rectangle* pChildAnchor ); 241 242 /** Sets the name of a macro attached to this control. 243 @return true = The passed event descriptor was valid, macro name has been found. */ 244 bool SetMacroLink( const ::com::sun::star::script::ScriptEventDescriptor& rEvent ); 245 246 private: 247 virtual void WriteSubRecs( XclExpStream& rStrm ); 248 249 /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */ 250 void WriteMacroSubRec( XclExpStream& rStrm ); 251 /** Writes a subrecord containing a cell link, or nothing, if no link present. */ 252 void WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId ); 253 /** Writes the ftSbs sub structure containing scrollbar data. */ 254 void WriteSbs( XclExpStream& rStrm ); 255 256 private: 257 ScfInt16Vec maMultiSel; /// Indexes of all selected entries in a multi selection. 258 XclTokenArrayRef mxMacroLink; /// Token array containing a link to an attached macro. 259 XclTbxEventType meEventType; /// Type of supported macro event. 260 sal_Int32 mnHeight; /// Height of the control. 261 sal_uInt16 mnState; /// Checked/unchecked state. 262 sal_Int16 mnLineCount; /// Combobox dropdown line count. 263 sal_Int16 mnSelEntry; /// Selected entry in combobox (1-based). 264 sal_uInt16 mnScrollValue; /// Scrollbar: Current value. 265 sal_uInt16 mnScrollMin; /// Scrollbar: Minimum value. 266 sal_uInt16 mnScrollMax; /// Scrollbar: Maximum value. 267 sal_uInt16 mnScrollStep; /// Scrollbar: Single step. 268 sal_uInt16 mnScrollPage; /// Scrollbar: Page step. 269 bool mbFlatButton; /// False = 3D button style; True = Flat button style. 270 bool mbFlatBorder; /// False = 3D border style; True = Flat border style. 271 bool mbMultiSel; /// true = Multi selection in listbox. 272 bool mbScrollHor; /// Scrollbar: true = horizontal. 273 }; 274 275 //#endif 276 277 // ---------------------------------------------------------------------------- 278 279 class XclExpChart; 280 281 /** A chart object. This is the drawing object wrapper for the chart data. */ 282 class XclExpChartObj : public XclObj, protected XclExpRoot 283 { 284 public: 285 explicit XclExpChartObj( 286 XclExpObjectManager& rObjMgr, 287 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape, 288 const Rectangle* pChildAnchor ); 289 virtual ~XclExpChartObj(); 290 291 /** Writes the OBJ record and the entire chart substream. */ 292 virtual void Save( XclExpStream& rStrm ); 293 294 private: 295 typedef ScfRef< XclExpChart > XclExpChartRef; 296 XclExpChartRef mxChart; /// The chart itself (BOF/EOF substream data). 297 }; 298 299 // ============================================================================ 300 301 /** Represents a NOTE record containing the relevant data of a cell note. 302 303 NOTE records differ significantly in various BIFF versions. This class 304 encapsulates all needed actions for each supported BIFF version. 305 BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE 306 records on saving. 307 BIFF8: Creates the Escher object containing the drawing information and the 308 note text. 309 */ 310 class XclExpNote : public XclExpRecord 311 { 312 public: 313 /** Constructs a NOTE record from the passed note object and/or the text. 314 @descr The additional text will be separated from the note text with 315 an empty line. 316 @param rScPos The Calc cell address of the note. 317 @param pScNote The Calc note object. May be 0 to create a note from rAddText only. 318 @param rAddText Additional text appended to the note text. */ 319 explicit XclExpNote( 320 const XclExpRoot& rRoot, 321 const ScAddress& rScPos, 322 const ScPostIt* pScNote, 323 const String& rAddText ); 324 325 /** Writes the NOTE record, if the respective Escher object is present. */ 326 virtual void Save( XclExpStream& rStrm ); 327 328 void WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm ); 329 GetAuthor() const330 const XclExpString& GetAuthor() const { return maAuthor; } 331 private: 332 /** Writes the body of the NOTE record. */ 333 virtual void WriteBody( XclExpStream& rStrm ); 334 335 private: 336 XclExpString maAuthor; /// Name of the author. 337 String maOrigNoteText; /// Original main text of the note. 338 ByteString maNoteText; /// Main text of the note (<=BIFF7). 339 ScAddress maScPos; /// Calc cell address of the note. 340 sal_uInt16 mnObjId; /// Escher object ID (BIFF8). 341 bool mbVisible; /// true = permanently visible. 342 }; 343 344 // ============================================================================ 345 346 class XclExpComments : public XclExpRecord 347 { 348 public: 349 typedef XclExpRecordList< XclExpNote > 350 XclExpNoteList; 351 352 XclExpComments( SCTAB nTab, XclExpNoteList& rNotes ); 353 354 virtual void SaveXml( XclExpXmlStream& rStrm ); 355 356 private: 357 SCTAB mnTab; 358 XclExpNoteList& mrNotes; 359 }; 360 361 // object manager ============================================================= 362 363 class XclExpObjectManager : public XclExpRoot 364 { 365 public: 366 explicit XclExpObjectManager( const XclExpRoot& rRoot ); 367 virtual ~XclExpObjectManager(); 368 369 /** Creates a new DFF client anchor object. Caller takes ownership! May be 370 overwritten in derived classes. */ 371 virtual XclExpDffAnchorBase* CreateDffAnchor() const; 372 373 /** Creates and returns the MSODRAWINGGROUP record containing global DFF 374 data in the DGGCONTAINER. */ 375 ScfRef< XclExpRecordBase > CreateDrawingGroup(); 376 377 /** Initializes the object manager for a new sheet. */ 378 void StartSheet(); 379 380 /** Processes a drawing page and returns the record block containing all 381 related records (MSODRAWING, OBJ, TXO, charts, etc.). */ 382 ScfRef< XclExpRecordBase > ProcessDrawing( SdrPage* pSdrPage ); 383 /** Processes a collection of UNO shapes and returns the record block 384 containing all related records (MSODRAWING, OBJ, TXO, charts, etc.). */ 385 ScfRef< XclExpRecordBase > ProcessDrawing( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes ); 386 387 /** Finalizes the object manager after conversion of all sheets. */ 388 void EndDocument(); 389 GetEscherEx()390 inline XclEscherEx& GetEscherEx() { return *mxEscherEx; } 391 XclExpMsoDrawing* GetMsodrawingPerSheet(); 392 bool HasObj() const; 393 sal_uInt16 AddObj( XclObj* pObjRec ); 394 XclObj* RemoveLastObj(); 395 396 protected: 397 explicit XclExpObjectManager( const XclExpObjectManager& rParent ); 398 399 private: 400 void InitStream( bool bTempFile ); 401 402 private: 403 ScfRef< ::utl::TempFile > mxTempFile; 404 ScfRef< SvStream > mxDffStrm; 405 ScfRef< XclEscherEx > mxEscherEx; 406 ScfRef< XclExpObjList > mxObjList; 407 }; 408 409 // ---------------------------------------------------------------------------- 410 411 class XclExpEmbeddedObjectManager : public XclExpObjectManager 412 { 413 public: 414 explicit XclExpEmbeddedObjectManager( 415 const XclExpObjectManager& rParent, 416 const Size& rPageSize, 417 sal_Int32 nScaleX, sal_Int32 nScaleY ); 418 419 /** Creates a new DFF client anchor object for embedded objects according 420 to the scaling data passed to the constructor. Caller takes ownership! */ 421 virtual XclExpDffAnchorBase* CreateDffAnchor() const; 422 423 private: 424 Size maPageSize; 425 sal_Int32 mnScaleX; 426 sal_Int32 mnScaleY; 427 }; 428 429 // ============================================================================ 430 431 #endif 432 433