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_XLROOT_HXX 25 #define SC_XLROOT_HXX 26 27 #include <com/sun/star/beans/NamedValue.hpp> 28 29 #include <i18npool/lang.h> 30 #include <sot/storage.hxx> 31 #include "xlconst.hxx" 32 #include "xltools.hxx" 33 34 namespace comphelper { class IDocPasswordVerifier; } 35 36 // Forward declarations of objects in public use ============================== 37 38 class DateTime; 39 40 struct XclAddress; 41 struct XclRange; 42 class XclRangeList; 43 class XclTokenArray; 44 45 // Global data ================================================================ 46 47 #ifdef DBG_UTIL 48 /** Counts the number of created root objects. */ 49 struct XclDebugObjCounter 50 { 51 sal_Int32 mnObjCnt; XclDebugObjCounterXclDebugObjCounter52 inline explicit XclDebugObjCounter() : mnObjCnt( 0 ) {} 53 ~XclDebugObjCounter(); 54 }; 55 #endif 56 57 // ---------------------------------------------------------------------------- 58 59 class SfxMedium; 60 class ScEditEngineDefaulter; 61 class ScHeaderEditEngine; 62 class EditEngine; 63 class ScExtDocOptions; 64 class XclFontPropSetHelper; 65 class XclChPropSetHelper; 66 class XclTracer; 67 68 struct RootData;//! 69 70 /** Stores global buffers and data needed elsewhere in the Excel filters. */ 71 struct XclRootData 72 #ifdef DBG_UTIL 73 : public XclDebugObjCounter 74 #endif 75 { 76 typedef ScfRef< ScEditEngineDefaulter > ScEEDefaulterRef; 77 typedef ScfRef< ScHeaderEditEngine > ScHeaderEERef; 78 typedef ScfRef< EditEngine > EditEngineRef; 79 typedef ScfRef< XclFontPropSetHelper > XclFontPropSetHlpRef; 80 typedef ScfRef< XclChPropSetHelper > XclChPropSetHlpRef; 81 typedef ScfRef< ScExtDocOptions > ScExtDocOptRef; 82 typedef ScfRef< XclTracer > XclTracerRef; 83 typedef ScfRef< RootData > RootDataRef; 84 85 XclBiff meBiff; /// Current BIFF version. 86 XclOutput meOutput; /// Current Output format. 87 SfxMedium& mrMedium; /// The medium to import from. 88 SotStorageRef mxRootStrg; /// The root OLE storage of imported/exported file. 89 ScDocument& mrDoc; /// The source or destination document. 90 String maDocUrl; /// Document URL of imported/exported file. 91 String maBasePath; /// Base path of imported/exported file (path of maDocUrl). 92 String maUserName; /// Current user name. 93 const String maDefPassword; /// The default password used for stream encryption. 94 rtl_TextEncoding meTextEnc; /// Text encoding to import/export byte strings. 95 LanguageType meSysLang; /// System language. 96 LanguageType meDocLang; /// Document language (import: from file, export: from system). 97 LanguageType meUILang; /// UI language (import: from file, export: from system). 98 sal_Int16 mnDefApiScript; /// Default script type for blank cells (API constant). 99 ScAddress maScMaxPos; /// Highest Calc cell position. 100 ScAddress maXclMaxPos; /// Highest Excel cell position. 101 ScAddress maMaxPos; /// Highest position valid in Calc and Excel. 102 103 ScEEDefaulterRef mxEditEngine; /// Edit engine for rich strings etc. 104 ScHeaderEERef mxHFEditEngine; /// Edit engine for header/footer. 105 EditEngineRef mxDrawEditEng; /// Edit engine for text boxes. 106 107 XclFontPropSetHlpRef mxFontPropSetHlp; /// Property set helper for fonts. 108 XclChPropSetHlpRef mxChPropSetHlp; /// Property set helper for chart filter. 109 110 ScExtDocOptRef mxExtDocOpt; /// Extended document options. 111 XclTracerRef mxTracer; /// Filter tracer. 112 RootDataRef mxRD; /// Old RootData struct. Will be removed. 113 114 double mfScreenPixelX; /// Width of a screen pixel (1/100 mm). 115 double mfScreenPixelY; /// Height of a screen pixel (1/100 mm). 116 long mnCharWidth; /// Width of '0' in default font (twips). 117 SCTAB mnScTab; /// Current Calc sheet index. 118 const bool mbExport; /// false = Import, true = Export. 119 120 explicit XclRootData( XclBiff eBiff, SfxMedium& rMedium, 121 SotStorageRef xRootStrg, ScDocument& rDoc, 122 rtl_TextEncoding eTextEnc, bool bExport ); 123 virtual ~XclRootData(); 124 }; 125 126 // ---------------------------------------------------------------------------- 127 128 class SfxObjectShell; 129 class ScModelObj; 130 class OutputDevice; 131 class SvNumberFormatter; 132 class SdrPage; 133 class ScDocumentPool; 134 class ScStyleSheetPool; 135 class ScRangeName; 136 class ScDBCollection; 137 struct XclFontData; 138 139 /** Access to global data for a filter object (imported or exported document) from other classes. */ 140 class XclRoot 141 { 142 public: 143 explicit XclRoot( XclRootData& rRootData ); 144 XclRoot( const XclRoot& rRoot ); 145 146 virtual ~XclRoot(); 147 148 XclRoot& operator=( const XclRoot& rRoot ); 149 150 /** Returns this root instance - for code readability in derived classes. */ GetRoot() const151 inline const XclRoot& GetRoot() const { return *this; } 152 /** Returns old RootData struct. Deprecated. */ GetOldRoot() const153 inline RootData& GetOldRoot() const { return *mrData.mxRD; } 154 155 /** Returns the current BIFF version of the importer/exporter. */ GetBiff() const156 inline XclBiff GetBiff() const { return mrData.meBiff; } 157 /** Returns the current output format of the importer/exporter. */ GetOutput() const158 inline XclOutput GetOutput() const { return mrData.meOutput; } 159 /** Returns true, if currently a document is imported. */ IsImport() const160 inline bool IsImport() const { return !mrData.mbExport; } 161 /** Returns true, if currently a document is exported. */ IsExport() const162 inline bool IsExport() const { return mrData.mbExport; } 163 /** Returns the text encoding to import/export byte strings. */ GetTextEncoding() const164 inline rtl_TextEncoding GetTextEncoding() const { return mrData.meTextEnc; } 165 /** Returns the system language, i.e. for number formats. */ GetSysLanguage() const166 inline LanguageType GetSysLanguage() const { return mrData.meSysLang; } 167 /** Returns the document language. */ GetDocLanguage() const168 inline LanguageType GetDocLanguage() const { return mrData.meDocLang; } 169 /** Returns the UI language. */ GetUILanguage() const170 inline LanguageType GetUILanguage() const { return mrData.meUILang; } 171 /** Returns the default script type, e.g. for blank cells. */ GetDefApiScript() const172 inline sal_Int16 GetDefApiScript() const { return mrData.mnDefApiScript; } 173 /** Returns the width of the '0' character (default font) for the current printer (twips). */ GetCharWidth() const174 inline long GetCharWidth() const { return mrData.mnCharWidth; } 175 /** Returns the current Calc sheet index. */ IsInGlobals() const176 inline bool IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; } 177 /** Returns the current Calc sheet index. */ GetCurrScTab() const178 inline SCTAB GetCurrScTab() const { return mrData.mnScTab; } 179 180 /** Calculates the width of the passed number of pixels in 1/100 mm. */ 181 sal_Int32 GetHmmFromPixelX( double fPixelX ) const; 182 /** Calculates the height of the passed number of pixels in 1/100 mm. */ 183 sal_Int32 GetHmmFromPixelY( double fPixelY ) const; 184 185 /** Returns the medium to import from. */ GetMedium() const186 inline SfxMedium& GetMedium() const { return mrData.mrMedium; } 187 /** Returns the document URL of the imported/exported file. */ GetDocUrl() const188 inline const String& GetDocUrl() const { return mrData.maDocUrl; } 189 /** Returns the base path of the imported/exported file. */ GetBasePath() const190 inline const String& GetBasePath() const { return mrData.maBasePath; } 191 /** Returns the current user name. */ GetUserName() const192 inline const String& GetUserName() const { return mrData.maUserName; } 193 194 /** Returns the default password used for stream encryption. */ GetDefaultPassword() const195 inline const String& GetDefaultPassword() const { return mrData.maDefPassword; } 196 /** Requests and verifies a password from the medium or the user. */ 197 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > 198 RequestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier ) const; 199 200 /** Returns the OLE2 root storage of the imported/exported file. 201 @return Pointer to root storage or 0, if the file is a simple stream. */ GetRootStorage() const202 inline SotStorageRef GetRootStorage() const { return mrData.mxRootStrg; } 203 /** Returns true, if the document contains a VBA storage. */ 204 bool HasVbaStorage() const; 205 206 /** Tries to open a storage as child of the specified storage for reading or writing. */ 207 SotStorageRef OpenStorage( SotStorageRef xStrg, const String& rStrgName ) const; 208 /** Tries to open a storage as child of the root storage for reading or writing. */ 209 SotStorageRef OpenStorage( const String& rStrgName ) const; 210 /** Tries to open a new stream in the specified storage for reading or writing. */ 211 SotStorageStreamRef OpenStream( SotStorageRef xStrg, const String& rStrmName ) const; 212 /** Tries to open a new stream in the root storage for reading or writing. */ 213 SotStorageStreamRef OpenStream( const String& rStrmName ) const; 214 215 /** Returns the destination document (import) or source document (export). */ GetDoc() const216 inline ScDocument& GetDoc() const { return mrData.mrDoc; } 217 /** Returns pointer to the destination document (import) or source document (export). */ GetDocPtr() const218 inline ScDocument* GetDocPtr() const { return &mrData.mrDoc; } 219 /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */ 220 SfxObjectShell* GetDocShell() const; 221 /** Returns the object model of the Calc document. */ 222 ScModelObj* GetDocModelObj() const; 223 /** Returns pointer to the printer of the Calc document. */ 224 OutputDevice* GetPrinter() const; 225 /** Returns the style sheet pool of the Calc document. */ 226 ScStyleSheetPool& GetStyleSheetPool() const; 227 /** Returns the defined names container of the Calc document. */ 228 ScRangeName& GetNamedRanges() const; 229 /** Returns the database ranges container of the Calc document. */ 230 ScDBCollection& GetDatabaseRanges() const; 231 /** Returns the drawing layer page of the passed sheet, if present. */ 232 SdrPage* GetSdrPage( SCTAB nScTab ) const; 233 234 /** Returns the number formatter of the Calc document. */ 235 SvNumberFormatter& GetFormatter() const; 236 /** Returns the null date of the current number formatter. */ 237 DateTime GetNullDate() const; 238 /** Returns the base year depending on the current null date (1900 or 1904). */ 239 sal_uInt16 GetBaseYear() const; 240 /** Converts a date/time value to a floating-point value. */ 241 double GetDoubleFromDateTime( const DateTime& rDateTime ) const; 242 /** Converts a floating-point value to a date/time value. */ 243 DateTime GetDateTimeFromDouble( double fValue ) const; 244 245 /** Returns the edit engine for import/export of rich strings etc. */ 246 ScEditEngineDefaulter& GetEditEngine() const; 247 /** Returns the edit engine for import/export of headers/footers. */ 248 ScHeaderEditEngine& GetHFEditEngine() const; 249 /** Returns the edit engine for import/export of drawing text boxes. */ 250 EditEngine& GetDrawEditEngine() const; 251 252 /** Returns the property set helper for fonts. */ 253 XclFontPropSetHelper& GetFontPropSetHelper() const; 254 /** Returns the property set helper for the chart filters. */ 255 XclChPropSetHelper& GetChartPropSetHelper() const; 256 257 /** Returns the extended document options. */ 258 ScExtDocOptions& GetExtDocOptions() const; 259 /** Returns the filter tracer. */ 260 XclTracer& GetTracer() const; 261 262 /** Returns the highest possible cell address in a Calc document. */ GetScMaxPos() const263 inline const ScAddress& GetScMaxPos() const { return mrData.maScMaxPos; } 264 /** Returns the highest possible cell address in an Excel document (using current BIFF version). */ GetXclMaxPos() const265 inline const ScAddress& GetXclMaxPos() const { return mrData.maXclMaxPos; } 266 /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */ GetMaxPos() const267 inline const ScAddress& GetMaxPos() const { return mrData.maMaxPos; } 268 269 /** Sets the document language. */ SetDocLanguage(LanguageType eLang)270 inline void SetDocLanguage( LanguageType eLang ) { mrData.meDocLang = eLang; } 271 /** Sets the UI language, i.e. if it has been read from a file. */ SetUILanguage(LanguageType eLang)272 inline void SetUILanguage( LanguageType eLang ) { mrData.meUILang = eLang; } 273 /** Sets the text encoding to import/export byte strings. */ 274 void SetTextEncoding( rtl_TextEncoding eTextEnc ); 275 /** Sets the width of the '0' character (default font) for the current printer (twips). 276 @param rFontData The font used for the '0' character. */ 277 void SetCharWidth( const XclFontData& rFontData ); 278 /** Sets the current Calc sheet index. */ SetCurrScTab(SCTAB nScTab)279 inline void SetCurrScTab( SCTAB nScTab ) { mrData.mnScTab = nScTab; } 280 /** Increases the current Calc sheet index by 1. */ IncCurrScTab()281 inline void IncCurrScTab() { ++mrData.mnScTab; } 282 283 private: 284 XclRootData& mrData; /// Reference to the global data struct. 285 }; 286 287 // ============================================================================ 288 289 #endif 290 291