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_DOCSHELL_HXX 25 #define SC_DOCSHELL_HXX 26 27 28 #include <sfx2/objsh.hxx> 29 30 #include <sfx2/docfac.hxx> 31 #include <sfx2/sfxmodelfactory.hxx> 32 #include <sfx2/viewsh.hxx> 33 34 #include "scdllapi.h" 35 #include "scdll.hxx" 36 #include "document.hxx" 37 #include "shellids.hxx" 38 #include "refreshtimer.hxx" 39 40 #include <hash_map> 41 42 class ScEditEngineDefaulter; 43 class FontList; 44 class SfxStyleSheetBasePool; 45 class SfxStyleSheetHint; 46 struct ChartSelectionInfo; 47 class INetURLObject; 48 49 class ScPaintItem; 50 class ScViewData; 51 class ScDocFunc; 52 class ScDrawLayer; 53 class ScTabViewShell; 54 class ScSbxDocHelper; 55 class ScAutoStyleList; 56 class ScRange; 57 class ScMarkData; 58 class ScPaintLockData; 59 class ScJobSetup; 60 class ScChangeAction; 61 class VirtualDevice; 62 class ScImportOptions; 63 class ScDocShellModificator; 64 class ScOptSolverSave; 65 class ScSheetSaveData; 66 67 namespace sfx2 { class FileDialogHelper; } 68 struct DocShell_Impl; 69 70 typedef ::std::hash_map< sal_uLong, sal_uLong > ScChangeActionMergeMap; 71 72 //================================================================== 73 74 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF }; 75 76 // Extra-Flags fuer Repaint 77 #define SC_PF_LINES 1 78 #define SC_PF_TESTMERGE 2 79 #define SC_PF_WHOLEROWS 4 80 81 class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener 82 { 83 static const sal_Char __FAR_DATA pStarCalcDoc[]; 84 static const sal_Char __FAR_DATA pStyleName[]; 85 86 ScDocument aDocument; 87 88 String aDdeTextFmt; 89 String aConvFilterName; //@ #BugId 54198 90 91 double nPrtToScreenFactor; 92 //! FontList* pFontList; 93 DocShell_Impl* pImpl; 94 ScDocFunc* pDocFunc; 95 96 //SfxObjectCreateMode eShellMode; 97 98 sal_Bool bIsInplace; // wird von der View gesetzt 99 sal_Bool bHeaderOn; 100 sal_Bool bFooterOn; 101 sal_Bool bNoInformLost; 102 sal_Bool bIsEmpty; 103 sal_Bool bIsInUndo; 104 sal_Bool bDocumentModifiedPending; 105 sal_uInt16 nDocumentLock; 106 sal_Int16 nCanUpdate; // stores the UpdateDocMode from loading a document till update links 107 sal_Bool bUpdateEnabled; 108 109 ScDBData* pOldAutoDBRange; 110 111 ScSbxDocHelper* pDocHelper; 112 113 ScAutoStyleList* pAutoStyleList; 114 ScPaintLockData* pPaintLockData; 115 ScJobSetup* pOldJobSetup; 116 ScOptSolverSave* pSolverSaveData; 117 ScSheetSaveData* pSheetSaveData; 118 119 ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading) 120 121 SC_DLLPRIVATE void InitItems(); 122 SC_DLLPRIVATE void DoEnterHandler(); 123 SC_DLLPRIVATE void InitOptions(bool bForLoading); 124 SC_DLLPRIVATE void ResetDrawObjectShell(); 125 126 // SUNWS needs a forward declared friend, otherwise types and members 127 // of the outer class are not accessible. 128 class PrepareSaveGuard; 129 friend class ScDocShell::PrepareSaveGuard; 130 /** Do things that need to be done before saving to our own format and 131 necessary clean ups in dtor. */ 132 class PrepareSaveGuard 133 { 134 public: 135 explicit PrepareSaveGuard( ScDocShell & rDocShell ); 136 ~PrepareSaveGuard(); 137 private: 138 ScDocShell & mrDocShell; 139 }; 140 141 SC_DLLPRIVATE sal_Bool LoadXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); 142 SC_DLLPRIVATE sal_Bool SaveXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); 143 SC_DLLPRIVATE SCTAB GetSaveTab(); 144 145 SC_DLLPRIVATE sal_uLong DBaseImport( const String& rFullFileName, CharSet eCharSet, 146 sal_Bool bSimpleColWidth[MAXCOLCOUNT] ); 147 SC_DLLPRIVATE sal_uLong DBaseExport( const String& rFullFileName, CharSet eCharSet, 148 sal_Bool& bHasMemo ); 149 150 SC_DLLPRIVATE static sal_Bool MoveFile( const INetURLObject& rSource, const INetURLObject& rDest ); 151 SC_DLLPRIVATE static sal_Bool KillFile( const INetURLObject& rURL ); 152 SC_DLLPRIVATE static sal_Bool IsDocument( const INetURLObject& rURL ); 153 154 SC_DLLPRIVATE void LockPaint_Impl(sal_Bool bDoc); 155 SC_DLLPRIVATE void UnlockPaint_Impl(sal_Bool bDoc); 156 SC_DLLPRIVATE void LockDocument_Impl(sal_uInt16 nNew); 157 SC_DLLPRIVATE void UnlockDocument_Impl(sal_uInt16 nNew); 158 159 SC_DLLPRIVATE void EnableSharedSettings( bool bEnable ); 160 SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument(); 161 162 SC_DLLPRIVATE void UseSheetSaveEntries(); 163 164 protected: 165 166 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 167 168 public: 169 TYPEINFO(); 170 171 SFX_DECL_INTERFACE(SCID_DOC_SHELL) 172 SFX_DECL_OBJECTFACTORY(); 173 174 ScDocShell( const ScDocShell& rDocShell ); 175 ScDocShell( const sal_uInt64 i_nSfxCreationFlags = SFXMODEL_EMBEDDED_OBJECT ); 176 ~ScDocShell(); 177 178 using SotObject::GetInterface; 179 using SfxShell::Activate; // with sal_Bool bMDI 180 using SfxShell::Deactivate; // with sal_Bool bMDI 181 using SfxObjectShell::Print; // print styles 182 183 virtual void Activate(); 184 virtual void Deactivate(); 185 186 virtual ::svl::IUndoManager* 187 GetUndoManager(); 188 189 virtual void FillClass( SvGlobalName * pClassName, 190 sal_uInt32 * pFormat, 191 String * pAppName, 192 String * pFullTypeName, 193 String * pShortTypeName, 194 sal_Int32 nFileFormat, 195 sal_Bool bTemplate = sal_False ) const; 196 197 virtual sal_Bool InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); 198 virtual sal_Bool Load( SfxMedium& rMedium ); 199 virtual sal_Bool LoadFrom( SfxMedium& rMedium ); 200 virtual sal_Bool ConvertFrom( SfxMedium &rMedium ); 201 virtual sal_Bool Save(); 202 virtual sal_Bool SaveAs( SfxMedium& rMedium ); 203 virtual sal_Bool ConvertTo( SfxMedium &rMedium ); 204 virtual sal_uInt16 PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = sal_False ); 205 virtual void PrepareReload(); 206 virtual sal_Bool IsInformationLost(); 207 virtual void LoadStyles( SfxObjectShell &rSource ); 208 virtual sal_Bool Insert( SfxObjectShell &rSource, 209 sal_uInt16 nSourceIdx1, sal_uInt16 nSourceIdx2, sal_uInt16 nSourceIdx3, 210 sal_uInt16 &nIdx1, sal_uInt16 &nIdx2, sal_uInt16 &nIdx3, sal_uInt16 &rIdxDeleted ); 211 212 virtual sal_Bool SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); // SfxInPlaceObject 213 virtual sal_Bool DoSaveCompleted( SfxMedium * pNewStor); // SfxObjectShell 214 virtual sal_Bool QuerySlotExecutable( sal_uInt16 nSlotId ); 215 216 virtual void Draw( OutputDevice *, const JobSetup & rSetup, 217 sal_uInt16 nAspect = ASPECT_CONTENT ); 218 219 virtual void SetVisArea( const Rectangle & rVisArea ); 220 221 using SfxObjectShell::GetVisArea; 222 virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const; 223 224 virtual Printer* GetDocumentPrinter(); 225 226 virtual void SetModified( sal_Bool = sal_True ); 227 228 void SetVisAreaOrSize( const Rectangle& rVisArea, sal_Bool bModifyStart ); 229 230 virtual SfxDocumentInfoDialog* CreateDocumentInfoDialog( Window *pParent, 231 const SfxItemSet &rSet ); 232 233 void GetDocStat( ScDocStat& rDocStat ); 234 235 ScDocument* GetDocument() { return &aDocument; } 236 ScDocFunc& GetDocFunc() { return *pDocFunc; } 237 238 SfxPrinter* GetPrinter( sal_Bool bCreateIfNotExist = sal_True ); 239 sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL ); 240 241 void UpdateFontList(); 242 243 String CreateObjectName( const String& rPrefix ); 244 245 ScDrawLayer* MakeDrawLayer(); 246 247 void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt ); 248 249 void GetSbxState( SfxItemSet &rSet ); 250 void GetDrawObjState( SfxItemSet &rSet ); 251 252 void Execute( SfxRequest& rReq ); 253 void GetState( SfxItemSet &rSet ); 254 void ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab ); 255 void GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab ); 256 257 void CompareDocument( ScDocument& rOtherDoc ); 258 void MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false ); 259 bool MergeSharedDocument( ScDocShell* pSharedDocShell ); 260 261 ScChangeAction* GetChangeAction( const ScAddress& rPos ); 262 void SetChangeComment( ScChangeAction* pAction, const String& rComment ); 263 void ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pParent,sal_Bool bPrevNext=sal_True ); 264 /// Protect/unprotect ChangeTrack and return <TRUE/> if 265 /// protection was successfully changed. 266 /// If bJustQueryIfProtected==sal_True protection is not 267 /// changed and <TRUE/> is returned if not protected or 268 /// password was entered correctly. 269 sal_Bool ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected = sal_False ); 270 271 void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages ); 272 sal_Bool AdjustPrintZoom( const ScRange& rRange ); 273 274 void LoadStylesArgs( ScDocShell& rSource, sal_Bool bReplace, sal_Bool bCellStyles, sal_Bool bPageStyles ); 275 276 void PageStyleModified( const String& rStyleName, sal_Bool bApi ); 277 278 void NotifyStyle( const SfxStyleSheetHint& rHint ); 279 void DoAutoStyle( const ScRange& rRange, const String& rStyle ); 280 281 Window* GetActiveDialogParent(); 282 void ErrorMessage( sal_uInt16 nGlobStrId ); 283 sal_Bool IsEditable() const; 284 285 sal_Bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab ); 286 void UpdateAllRowHeights( const ScMarkData* pTabMark = NULL ); 287 void UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false ); 288 289 void RefreshPivotTables( const ScRange& rSource ); 290 void DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True ); 291 void UseScenario( SCTAB nTab, const String& rName, sal_Bool bRecord = sal_True ); 292 SCTAB MakeScenario( SCTAB nTab, const String& rName, const String& rComment, 293 const Color& rColor, sal_uInt16 nFlags, 294 ScMarkData& rMark, sal_Bool bRecord = sal_True ); 295 void ModifyScenario( SCTAB nTab, const String& rName, const String& rComment, 296 const Color& rColor, sal_uInt16 nFlags ); 297 sal_Bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord ); 298 299 void DoRecalc( sal_Bool bApi ); 300 void DoHardRecalc( sal_Bool bApi ); 301 302 void UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = sal_False); 303 sal_Bool IsOle(); 304 305 void DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 ); 306 ScDBData* GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel ); 307 ScDBData* GetOldAutoDBRange(); // has to be deleted by caller! 308 void CancelAutoDBRange(); // called when dialog is cancelled 309 310 void UpdateLinks(); // Link-Eintraege aktuallisieren 311 sal_Bool ReloadTabLinks(); // Links ausfuehren (Inhalt aktualisieren) 312 313 void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos ); 314 315 void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, 316 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart, 317 sal_uInt16 nExtFlags = 0 ); 318 void PostPaint( const ScRange& rRange, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 ); 319 320 void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab ); 321 void PostPaintCell( const ScAddress& rPos ); 322 void PostPaintGridAll(); 323 void PostPaintExtras(); 324 325 bool IsPaintLocked() const { return pPaintLockData != NULL; } 326 327 void PostDataChanged(); 328 329 void UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, 330 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab ); 331 void UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange ); 332 333 void SetDocumentModified( sal_Bool bIsModified = sal_True ); 334 void SetDrawModified( sal_Bool bIsModified = sal_True ); 335 336 void LockPaint(); 337 void UnlockPaint(); 338 sal_uInt16 GetLockCount() const; 339 void SetLockCount(sal_uInt16 nNew); 340 341 void LockDocument(); 342 void UnlockDocument(); 343 344 DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* ); 345 346 virtual SfxStyleSheetBasePool* GetStyleSheetPool(); 347 348 void SetInplace( sal_Bool bInplace ); 349 sal_Bool IsEmpty() const; 350 void SetEmpty(sal_Bool bSet); 351 352 sal_Bool IsInUndo() const { return bIsInUndo; } 353 void SetInUndo(sal_Bool bSet); 354 355 void CalcOutputFactor(); 356 double GetOutputFactor() const; 357 void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet, 358 SCTAB nCurTab, 359 sal_Bool& rbHeader, 360 sal_Bool& rbFooter ); 361 362 virtual long DdeGetData( const String& rItem, const String& rMimeType, 363 ::com::sun::star::uno::Any & rValue ); 364 virtual long DdeSetData( const String& rItem, const String& rMimeType, 365 const ::com::sun::star::uno::Any & rValue ); 366 virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const String& rItem ); 367 368 const String& GetDdeTextFmt() const { return aDdeTextFmt; } 369 370 SfxBindings* GetViewBindings(); 371 372 ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True ); 373 ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; } 374 375 void SetDocumentModifiedPending( sal_Bool bVal ) 376 { bDocumentModifiedPending = bVal; } 377 sal_Bool IsDocumentModifiedPending() const 378 { return bDocumentModifiedPending; } 379 380 sal_Bool IsUpdateEnabled() const 381 { return bUpdateEnabled; } 382 void SetUpdateEnabled(sal_Bool bValue) 383 { bUpdateEnabled = bValue; } 384 385 OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice... 386 387 static ScViewData* GetViewData(); 388 static SCTAB GetCurTab(); 389 390 static ScDocShell* GetShellByNum( sal_uInt16 nDocNo ); 391 static String GetOwnFilterName(); 392 static String GetHtmlFilterName(); 393 static String GetWebQueryFilterName(); 394 static String GetAsciiFilterName(); 395 static String GetLotusFilterName(); 396 static String GetDBaseFilterName(); 397 static String GetDifFilterName(); 398 static sal_Bool HasAutomaticTableName( const String& rFilter ); 399 400 DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* ); 401 402 void BeforeXMLLoading(); 403 void AfterXMLLoading(sal_Bool bRet); 404 405 virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates ); 406 407 const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null 408 void SetSolverSaveData( const ScOptSolverSave& rData ); 409 //<!--Added by PengYunQuan for Validity Cell Range Picker 410 sal_Bool AcceptStateUpdate() const; 411 //-->Added by PengYunQuan for Validity Cell Range Picker 412 ScSheetSaveData* GetSheetSaveData(); 413 414 // passwword protection for Calc (derived from SfxObjectShell) 415 // see also: FID_CHG_RECORD, SID_CHG_PROTECT 416 virtual bool IsChangeRecording() const; 417 virtual bool HasChangeRecordProtection() const; 418 virtual void SetChangeRecording( bool bActivate ); 419 virtual bool SetProtectionPassword( const String &rPassword ); 420 virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ); 421 }; 422 423 424 void UpdateAcceptChangesDialog(); 425 426 427 SO2_DECL_REF(ScDocShell) 428 SO2_IMPL_REF(ScDocShell) 429 430 431 // Vor Modifizierungen des Dokuments anlegen und danach zerstoeren. 432 // Merkt sich im Ctor AutoCalcShellDisabled und IdleDisabled, schaltet sie ab 433 // und stellt sie im Dtor wieder her, AutoCalcShellDisabled ggbf. auch vor 434 // einem ScDocShell SetDocumentModified. 435 // SetDocumentModified hierdran aufrufen statt an der ScDocShell. 436 // Im Dtor wird wenn ScDocShell bDocumentModifiedPending gesetzt ist und 437 // bAutoCalcShellDisabled nicht gesetzt ist ein SetDocumentModified gerufen. 438 class SC_DLLPUBLIC ScDocShellModificator 439 { 440 ScDocShell& rDocShell; 441 ScRefreshTimerProtector aProtector; 442 sal_Bool bAutoCalcShellDisabled; 443 sal_Bool bIdleDisabled; 444 445 // not implemented 446 ScDocShellModificator( const ScDocShellModificator& ); 447 ScDocShellModificator& operator=( const ScDocShellModificator& ); 448 449 public: 450 ScDocShellModificator( ScDocShell& ); 451 ~ScDocShellModificator(); 452 void SetDocumentModified(); 453 }; 454 455 456 457 #endif 458 459 460