LCOV - code coverage report
Current view: top level - sfx2/source/doc - objcont.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 264 0.4 %
Date: 2014-04-14 Functions: 2 28 7.1 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : 
      21             : #include <com/sun/star/uno/Reference.hxx>
      22             : 
      23             : #include <com/sun/star/document/DocumentProperties.hpp>
      24             : #include <com/sun/star/document/XDocumentProperties.hpp>
      25             : #include <com/sun/star/document/UpdateDocMode.hpp>
      26             : #include <com/sun/star/frame/XLayoutManager.hpp>
      27             : #include <com/sun/star/embed/ElementModes.hpp>
      28             : #include <vcl/msgbox.hxx>
      29             : #include <svl/style.hxx>
      30             : #include <vcl/wrkwin.hxx>
      31             : 
      32             : #include <svl/stritem.hxx>
      33             : #include <svl/intitem.hxx>
      34             : #include <svl/rectitem.hxx>
      35             : #include <svl/eitem.hxx>
      36             : #include <svl/urihelper.hxx>
      37             : #include <svl/ctloptions.hxx>
      38             : #include <comphelper/storagehelper.hxx>
      39             : #include <comphelper/processfactory.hxx>
      40             : #include <unotools/securityoptions.hxx>
      41             : #include <svtools/sfxecode.hxx>
      42             : #include <svtools/ehdl.hxx>
      43             : #include <tools/datetime.hxx>
      44             : #include <rtl/uri.hxx>
      45             : #include <math.h>
      46             : 
      47             : #include <unotools/saveopt.hxx>
      48             : #include <unotools/useroptions.hxx>
      49             : #include <unotools/localfilehelper.hxx>
      50             : #include <vcl/virdev.hxx>
      51             : #include <vcl/oldprintadaptor.hxx>
      52             : #include <vcl/settings.hxx>
      53             : 
      54             : #include <sfx2/app.hxx>
      55             : #include <sfx2/sfxresid.hxx>
      56             : #include "appdata.hxx"
      57             : #include <sfx2/dinfdlg.hxx>
      58             : #include <sfx2/fcontnr.hxx>
      59             : #include <sfx2/docfac.hxx>
      60             : #include <sfx2/viewsh.hxx>
      61             : #include <sfx2/objsh.hxx>
      62             : #include "objshimp.hxx"
      63             : #include <sfx2/evntconf.hxx>
      64             : #include <sfx2/sfxhelp.hxx>
      65             : #include <sfx2/dispatch.hxx>
      66             : #include <sfx2/printer.hxx>
      67             : #include <basic/basmgr.hxx>
      68             : #include <svtools/svtools.hrc>
      69             : #include <sfx2/viewfrm.hxx>
      70             : #include <sfx2/doctempl.hxx>
      71             : #include "doc.hrc"
      72             : #include <sfx2/sfxbasemodel.hxx>
      73             : #include <sfx2/docfile.hxx>
      74             : #include <sfx2/request.hxx>
      75             : #include "openflag.hxx"
      76             : #include "querytemplate.hxx"
      77             : #include <boost/scoped_array.hpp>
      78             : 
      79             : using namespace ::com::sun::star;
      80             : using namespace ::com::sun::star::uno;
      81             : 
      82             : 
      83             : 
      84             : static
      85           0 : bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight)
      86             : {
      87           0 :     if ( i_rLeft.Year != i_rRight.Year )
      88           0 :         return i_rLeft.Year > i_rRight.Year;
      89             : 
      90           0 :     if ( i_rLeft.Month != i_rRight.Month )
      91           0 :         return i_rLeft.Month > i_rRight.Month;
      92             : 
      93           0 :     if ( i_rLeft.Day != i_rRight.Day )
      94           0 :         return i_rLeft.Day > i_rRight.Day;
      95             : 
      96           0 :     if ( i_rLeft.Hours != i_rRight.Hours )
      97           0 :         return i_rLeft.Hours > i_rRight.Hours;
      98             : 
      99           0 :     if ( i_rLeft.Minutes != i_rRight.Minutes )
     100           0 :         return i_rLeft.Minutes > i_rRight.Minutes;
     101             : 
     102           0 :     if ( i_rLeft.Seconds != i_rRight.Seconds )
     103           0 :         return i_rLeft.Seconds > i_rRight.Seconds;
     104             : 
     105           0 :     if ( i_rLeft.NanoSeconds != i_rRight.NanoSeconds )
     106           0 :         return i_rLeft.NanoSeconds > i_rRight.NanoSeconds;
     107             : 
     108           0 :     return false;
     109             : }
     110             : 
     111             : ::boost::shared_ptr<GDIMetaFile>
     112           0 : SfxObjectShell::GetPreviewMetaFile( bool bFullContent ) const
     113             : {
     114           0 :     return CreatePreviewMetaFile_Impl( bFullContent );
     115             : }
     116             : 
     117             : ::boost::shared_ptr<GDIMetaFile>
     118           0 : SfxObjectShell::CreatePreviewMetaFile_Impl( bool bFullContent ) const
     119             : {
     120             :     // DoDraw can only be called when no printing is done, otherwise
     121             :     // the printer may be turned off
     122           0 :     SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
     123           0 :     if ( pFrame && pFrame->GetViewShell() &&
     124           0 :          pFrame->GetViewShell()->GetPrinter() &&
     125           0 :          pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
     126           0 :          return ::boost::shared_ptr<GDIMetaFile>();
     127             : 
     128           0 :     ::boost::shared_ptr<GDIMetaFile> pFile(new GDIMetaFile);
     129             : 
     130           0 :     VirtualDevice aDevice;
     131           0 :     aDevice.EnableOutput( false );
     132             : 
     133           0 :     MapMode aMode( ((SfxObjectShell*)this)->GetMapUnit() );
     134           0 :     aDevice.SetMapMode( aMode );
     135           0 :     pFile->SetPrefMapMode( aMode );
     136             : 
     137           0 :     Size aTmpSize;
     138             :     sal_Int8 nAspect;
     139           0 :     if ( bFullContent )
     140             :     {
     141           0 :         nAspect = ASPECT_CONTENT;
     142           0 :         aTmpSize = GetVisArea( nAspect ).GetSize();
     143             :     }
     144             :     else
     145             :     {
     146           0 :         nAspect = ASPECT_THUMBNAIL;
     147           0 :         aTmpSize = ((SfxObjectShell*)this)->GetFirstPageSize();
     148             :     }
     149             : 
     150           0 :     pFile->SetPrefSize( aTmpSize );
     151             :     DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
     152             :                 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
     153             : 
     154           0 :     pFile->Record( &aDevice );
     155             : 
     156             :     LanguageType eLang;
     157           0 :     SvtCTLOptions aCTLOptions;
     158           0 :     if ( SvtCTLOptions::NUMERALS_HINDI == aCTLOptions.GetCTLTextNumerals() )
     159           0 :         eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
     160           0 :     else if ( SvtCTLOptions::NUMERALS_ARABIC == aCTLOptions.GetCTLTextNumerals() )
     161           0 :         eLang = LANGUAGE_ENGLISH;
     162             :     else
     163           0 :         eLang = (LanguageType) Application::GetSettings().GetLanguageTag().getLanguageType();
     164             : 
     165           0 :     aDevice.SetDigitLanguage( eLang );
     166             : 
     167             :     {
     168             :         SAL_INFO( "sfx.doc", "PERFORMANCE SfxObjectShell::CreatePreviewMetaFile_Impl" );
     169           0 :         ((SfxObjectShell*)this)->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), nAspect );
     170             :     }
     171           0 :     pFile->Stop();
     172             : 
     173           0 :     return pFile;
     174             : }
     175             : 
     176             : 
     177             : 
     178           0 : void SfxObjectShell::UpdateDocInfoForSave()
     179             : {
     180           0 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     181             : 
     182             :     // clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
     183           0 :     if ( SvtSecurityOptions().IsOptionSet(
     184           0 :             SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
     185             :     {
     186           0 :         xDocProps->resetUserData( OUString() );
     187             :     }
     188           0 :     else if ( IsModified() )
     189             :     {
     190           0 :         OUString aUserName = SvtUserOptions().GetFullName();
     191           0 :         if ( !IsUseUserData() )
     192             :         {
     193             :             // remove all data pointing to the current user
     194           0 :             if (xDocProps->getAuthor().equals(aUserName)) {
     195           0 :                 xDocProps->setAuthor( OUString() );
     196             :             }
     197           0 :             xDocProps->setModifiedBy( OUString() );
     198           0 :             if (xDocProps->getPrintedBy().equals(aUserName)) {
     199           0 :                 xDocProps->setPrintedBy( OUString() );
     200             :             }
     201             :         }
     202             :         else
     203             :         {
     204             :             // update ModificationAuthor, revision and editing time
     205           0 :             ::DateTime now( ::DateTime::SYSTEM );
     206           0 :             xDocProps->setModificationDate( util::DateTime(
     207           0 :                 now.GetNanoSec(), now.GetSec(), now.GetMin(),
     208           0 :                 now.GetHour(), now.GetDay(), now.GetMonth(),
     209           0 :                 now.GetYear(), false) );
     210           0 :             xDocProps->setModifiedBy( aUserName );
     211           0 :             if ( !HasName() || pImp->bIsSaving )
     212             :                 // QUESTION: not in case of "real" SaveAs as this is meant to create a new document
     213           0 :                 UpdateTime_Impl( xDocProps );
     214           0 :         }
     215           0 :     }
     216           0 : }
     217             : 
     218             : 
     219             : 
     220             : static void
     221           0 : lcl_add(util::Duration & rDur, Time const& rTime)
     222             : {
     223             :     // here we don't care about overflow: rDur is converted back to seconds
     224             :     // anyway, and Time cannot store more than ~4000 hours
     225           0 :     rDur.Hours   += rTime.GetHour();
     226           0 :     rDur.Minutes += rTime.GetMin();
     227           0 :     rDur.Seconds += rTime.GetSec();
     228           0 : }
     229             : 
     230             : // Update the processing time
     231           0 : void SfxObjectShell::UpdateTime_Impl(
     232             :     const uno::Reference<document::XDocumentProperties> & i_xDocProps)
     233             : {
     234             :     // Get old time from documentinfo
     235           0 :     const sal_Int32 secs = i_xDocProps->getEditingDuration();
     236             :     util::Duration editDuration(sal_False, 0, 0, 0,
     237           0 :             secs/3600, (secs%3600)/60, secs%60, 0);
     238             : 
     239             :     // Initialize some local member! Its necessary for wollow operations!
     240           0 :     DateTime    aNow( DateTime::SYSTEM );   // Date and time at current moment
     241           0 :     Time        n24Time     (24,0,0,0)  ;   // Time-value for 24 hours - see follow calculation
     242           0 :     sal_uIntPtr     nDays       = 0         ;   // Count of days between now and last editing
     243           0 :     Time        nAddTime    (0)         ;   // Value to add on aOldTime
     244             : 
     245             :     // Safe impossible cases!
     246             :     // User has changed time to the past between last editing and now ... its not possible!!!
     247             :     DBG_ASSERT( !(aNow.GetDate()<pImp->nTime.GetDate()), "Timestamp of last change is in the past ?!..." );
     248             : 
     249             :     // Do the follow only, if user has NOT changed time to the past.
     250             :     // Else add a time of 0 to aOldTime ... !!!
     251           0 :     if (aNow.GetDate()>=pImp->nTime.GetDate())
     252             :     {
     253             :         // Get count of days last editing.
     254           0 :         nDays = aNow.GetSecFromDateTime(pImp->nTime.GetDate())/86400 ;
     255             : 
     256           0 :         if (nDays==0)
     257             :         {
     258             :             // If no day between now and last editing - calculate time directly.
     259           0 :             nAddTime    =   (const Time&)aNow - (const Time&)pImp->nTime ;
     260             :         }
     261           0 :         else if (nDays<=31)
     262             :         {
     263             :             // If time of working without save greater then 1 month (!) ....
     264             :             // we add 0 to aOldTime!
     265             : 
     266             :             // If 1 or up to 31 days between now and last editing - calculate time indirectly.
     267             :             // nAddTime = (24h - nTime) + (nDays * 24h) + aNow
     268           0 :             --nDays;
     269           0 :              nAddTime    =  nDays*n24Time.GetTime() ;
     270           0 :             nAddTime    +=  n24Time-(const Time&)pImp->nTime        ;
     271           0 :             nAddTime    +=  aNow                    ;
     272             :         }
     273             : 
     274           0 :         lcl_add(editDuration, nAddTime);
     275             :     }
     276             : 
     277           0 :     pImp->nTime = aNow;
     278             :     try {
     279           0 :         const sal_Int32 newSecs( (editDuration.Hours*3600)
     280           0 :             + (editDuration.Minutes*60) + editDuration.Seconds);
     281           0 :         i_xDocProps->setEditingDuration(newSecs);
     282           0 :         i_xDocProps->setEditingCycles(i_xDocProps->getEditingCycles() + 1);
     283             :     }
     284           0 :     catch (const lang::IllegalArgumentException &)
     285             :     {
     286             :         // ignore overflow
     287             :     }
     288           0 : }
     289             : 
     290             : 
     291             : 
     292           0 : SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
     293             : (
     294             :     Window*             pParent,
     295             :     const SfxItemSet&   rSet
     296             : )
     297             : {
     298           0 :     return new SfxDocumentInfoDialog(pParent, rSet);
     299             : }
     300             : 
     301             : 
     302             : 
     303           0 : SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
     304             : {
     305           0 :     return 0;
     306             : }
     307             : 
     308             : struct Styles_Impl
     309             : {
     310             :     SfxStyleSheetBase *pSource;
     311             :     SfxStyleSheetBase *pDest;
     312             : };
     313             : 
     314           0 : void SfxObjectShell::LoadStyles
     315             : (
     316             :     SfxObjectShell &rSource         /*  the document template from which
     317             :                                         the styles are to be loaded */
     318             : )
     319             : 
     320             : /*  [Description]
     321             : 
     322             :     This method is called by the SFx if template styles are to be loaded.
     323             :     Existing styles are in this case overwritten. The document has then to be
     324             :     newly formatted. Therefore, the application of this method is usually
     325             :     overloaded and its implementation is calling the implementation in
     326             :     the base class.
     327             : */
     328             : 
     329             : {
     330           0 :     SfxStyleSheetBasePool *pSourcePool = rSource.GetStyleSheetPool();
     331             :     DBG_ASSERT(pSourcePool, "Source-DocumentShell ohne StyleSheetPool");
     332           0 :     SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool();
     333             :     DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool");
     334           0 :     pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_ALL);
     335           0 :     boost::scoped_array<Styles_Impl> pFound(new Styles_Impl[pSourcePool->Count()]);
     336           0 :     sal_uInt16 nFound = 0;
     337             : 
     338           0 :     SfxStyleSheetBase *pSource = pSourcePool->First();
     339           0 :     while ( pSource )
     340             :     {
     341             :         SfxStyleSheetBase *pDest =
     342           0 :             pMyPool->Find( pSource->GetName(), pSource->GetFamily() );
     343           0 :         if ( !pDest )
     344             :         {
     345           0 :             pDest = &pMyPool->Make( pSource->GetName(),
     346           0 :                     pSource->GetFamily(), pSource->GetMask());
     347             :             // Setting of Parents, the next style
     348             :         }
     349           0 :         pFound[nFound].pSource = pSource;
     350           0 :         pFound[nFound].pDest = pDest;
     351           0 :         ++nFound;
     352           0 :         pSource = pSourcePool->Next();
     353             :     }
     354             : 
     355           0 :     for ( sal_uInt16 i = 0; i < nFound; ++i )
     356             :     {
     357           0 :         pFound[i].pDest->GetItemSet().PutExtended(pFound[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
     358           0 :         if(pFound[i].pSource->HasParentSupport())
     359           0 :             pFound[i].pDest->SetParent(pFound[i].pSource->GetParent());
     360           0 :         if(pFound[i].pSource->HasFollowSupport())
     361           0 :             pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent());
     362           0 :     }
     363           0 : }
     364             : 
     365             : 
     366             : 
     367           0 : void SfxObjectShell::UpdateFromTemplate_Impl(  )
     368             : 
     369             : /*  [Description]
     370             : 
     371             :     This internal method checks whether the document was created from a
     372             :     template, and if this is newer than the document. If this is the case,
     373             :     the user is asked if the Templates (StyleSheets) should be updated.
     374             :     If this is answered positively, the StyleSheets are updated.
     375             : */
     376             : 
     377             : {
     378             :     // Storage-medium?
     379           0 :     SfxMedium *pFile = GetMedium();
     380             :     DBG_ASSERT( pFile, "cannot UpdateFromTemplate without medium" );
     381           0 :     if ( !pFile )
     382           0 :         return;
     383             : 
     384           0 :     if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
     385             :         // update only for documents loaded from the local file system
     386           0 :         return;
     387             : 
     388             :     // only for own storage formats
     389           0 :     uno::Reference< embed::XStorage > xDocStor = pFile->GetStorage();
     390           0 :     if ( !pFile->GetFilter() || !pFile->GetFilter()->IsOwnFormat() )
     391           0 :         return;
     392             : 
     393           0 :     SFX_ITEMSET_ARG( pFile->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, false);
     394           0 :     sal_Int16 bCanUpdateFromTemplate = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
     395             : 
     396             :     // created from template?
     397           0 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     398           0 :     OUString aTemplName( xDocProps->getTemplateName() );
     399           0 :     OUString aTemplURL( xDocProps->getTemplateURL() );
     400           0 :     OUString aFoundName;
     401             : 
     402           0 :     if ( !aTemplName.isEmpty() || (!aTemplURL.isEmpty() && !IsReadOnly()) )
     403             :     {
     404             :         // try to locate template, first using filename this must be done
     405             :         // because writer global document uses this "great" idea to manage
     406             :         // the templates of all parts in the master document but it is NOT
     407             :         // an error if the template filename points not to a valid file
     408           0 :         SfxDocumentTemplates aTempl;
     409           0 :         aTempl.Construct();
     410           0 :         if (!aTemplURL.isEmpty())
     411             :         {
     412             :             try {
     413           0 :                 aFoundName = ::rtl::Uri::convertRelToAbs(GetMedium()->GetName(),
     414           0 :                             aTemplURL);
     415           0 :             } catch (::rtl::MalformedUriException const&) {
     416             :                 assert(false); // don't think that's supposed to happen?
     417             :             }
     418             :         }
     419             : 
     420           0 :         if( aFoundName.isEmpty() && !aTemplName.isEmpty() )
     421             :             // if the template filename did not lead to success,
     422             :             // try to get a file name for the logical template name
     423           0 :             aTempl.GetFull( OUString(), aTemplName, aFoundName );
     424             :     }
     425             : 
     426           0 :     if ( !aFoundName.isEmpty() )
     427             :     {
     428             :         // check existence of template storage
     429           0 :         aTemplURL = aFoundName;
     430           0 :         bool bLoad = false;
     431             : 
     432             :         // should the document checked against changes in the template ?
     433           0 :         if ( IsQueryLoadTemplate() )
     434             :         {
     435             :             // load document properties of template
     436           0 :             bool bOK = false;
     437           0 :             util::DateTime aTemplDate;
     438             :             try
     439             :             {
     440             :                 Reference<document::XDocumentProperties> const
     441             :                     xTemplateDocProps( document::DocumentProperties::create(
     442           0 :                             ::comphelper::getProcessComponentContext()));
     443           0 :                 xTemplateDocProps->loadFromMedium(aTemplURL,
     444           0 :                         Sequence<beans::PropertyValue>());
     445           0 :                 aTemplDate = xTemplateDocProps->getModificationDate();
     446           0 :                 bOK = true;
     447             :             }
     448           0 :             catch (const Exception& e)
     449             :             {
     450             :                 SAL_INFO("sfx.doc", "caught exception" << e.Message);
     451             :             }
     452             : 
     453             :             // if modify date was read successfully
     454           0 :             if ( bOK )
     455             :             {
     456             :                 // compare modify data of template with the last check date of the document
     457           0 :                 const util::DateTime aInfoDate( xDocProps->getTemplateDate() );
     458           0 :                 if ( aTemplDate > aInfoDate )
     459             :                 {
     460             :                     // ask user
     461           0 :                     if( bCanUpdateFromTemplate == document::UpdateDocMode::QUIET_UPDATE
     462           0 :                     || bCanUpdateFromTemplate == document::UpdateDocMode::FULL_UPDATE )
     463           0 :                         bLoad = true;
     464           0 :                     else if ( bCanUpdateFromTemplate == document::UpdateDocMode::ACCORDING_TO_CONFIG )
     465             :                     {
     466           0 :                         OUString sMessage( SfxResId(STR_QRYTEMPL_MESSAGE).toString() );
     467           0 :                         sMessage = sMessage.replaceAll( "$(ARG1)", aTemplName );
     468           0 :                         sfx2::QueryTemplateBox aBox( GetDialogParent(), sMessage );
     469           0 :                         if ( RET_YES == aBox.Execute() )
     470           0 :                             bLoad = true;
     471             :                     }
     472             : 
     473           0 :                     if( !bLoad )
     474             :                     {
     475             :                         // user refuses, so don't ask again for this document
     476           0 :                         SetQueryLoadTemplate(false);
     477           0 :                         SetModified( true );
     478             :                     }
     479             :                 }
     480             :             }
     481             : 
     482           0 :             if ( bLoad )
     483             :             {
     484             :                 // styles should be updated, create document in organizer mode to read in the styles
     485             :                 //TODO: testen!
     486           0 :                 SfxObjectShellLock xTemplDoc = CreateObjectByFactoryName( GetFactory().GetFactoryName(), SFX_CREATE_MODE_ORGANIZER );
     487           0 :                 xTemplDoc->DoInitNew(0);
     488             : 
     489             :                 // TODO/MBA: do we need a BaseURL? Then LoadFrom must be extended!
     490             :                 //xTemplDoc->SetBaseURL( aFoundName );
     491             : 
     492             :                 // TODO/LATER: make sure that we don't use binary templates!
     493           0 :                 SfxMedium aMedium( aFoundName, STREAM_STD_READ );
     494           0 :                 if ( xTemplDoc->LoadFrom( aMedium ) )
     495             :                 {
     496             :                     // transfer styles from xTemplDoc to this document
     497             :                     // TODO/MBA: make sure that no BaseURL is needed in *this* document
     498           0 :                     LoadStyles(*xTemplDoc);
     499             : 
     500             :                     // remember date/time of check
     501           0 :                     xDocProps->setTemplateDate(aTemplDate);
     502             :                     // TODO/LATER: new functionality to store document info is required ( didn't work for SO7 XML format )
     503           0 :                 }
     504             :             }
     505             :         }
     506           0 :     }
     507             : }
     508             : 
     509           0 : bool SfxObjectShell::IsHelpDocument() const
     510             : {
     511           0 :     const SfxFilter* pFilter = GetMedium()->GetFilter();
     512           0 :     return (pFilter && pFilter->GetFilterName() == "writer_web_HTML_help");
     513             : }
     514             : 
     515           0 : void SfxObjectShell::ResetFromTemplate( const OUString& rTemplateName, const OUString& rFileName )
     516             : {
     517             :     // only care about reseting this data for openoffice formats otherwise
     518           0 :     if ( IsOwnStorageFormat_Impl( *GetMedium())  )
     519             :     {
     520           0 :         uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     521           0 :         xDocProps->setTemplateURL( OUString() );
     522           0 :         xDocProps->setTemplateName( OUString() );
     523           0 :         xDocProps->setTemplateDate( util::DateTime() );
     524           0 :         xDocProps->resetUserData( OUString() );
     525             : 
     526             :         // TODO/REFACTOR:
     527             :         // Title?
     528             : 
     529           0 :         if( ::utl::LocalFileHelper::IsLocalFile( rFileName ) )
     530             :         {
     531           0 :             OUString aFoundName;
     532           0 :             if( SFX_APP()->Get_Impl()->GetDocumentTemplates()->GetFull( OUString(), rTemplateName, aFoundName ) )
     533             :             {
     534           0 :                 INetURLObject aObj( rFileName );
     535           0 :                 xDocProps->setTemplateURL( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
     536           0 :                 xDocProps->setTemplateName( rTemplateName );
     537             : 
     538           0 :                 ::DateTime now( ::DateTime::SYSTEM );
     539           0 :                 xDocProps->setTemplateDate( util::DateTime(
     540           0 :                     now.GetNanoSec(), now.GetSec(), now.GetMin(),
     541           0 :                     now.GetHour(), now.GetDay(), now.GetMonth(),
     542           0 :                     now.GetYear(), false) );
     543             : 
     544           0 :                 SetQueryLoadTemplate( true );
     545           0 :             }
     546           0 :         }
     547             :     }
     548           0 : }
     549             : 
     550           0 : bool SfxObjectShell::IsQueryLoadTemplate() const
     551             : {
     552           0 :     return pImp->bQueryLoadTemplate;
     553             : }
     554             : 
     555           0 : bool SfxObjectShell::IsUseUserData() const
     556             : {
     557           0 :     return pImp->bUseUserData;
     558             : }
     559             : 
     560           0 : void SfxObjectShell::SetQueryLoadTemplate( bool bNew )
     561             : {
     562           0 :     if ( pImp->bQueryLoadTemplate != bNew )
     563           0 :         SetModified( true );
     564           0 :     pImp->bQueryLoadTemplate = bNew;
     565           0 : }
     566             : 
     567           0 : void SfxObjectShell::SetUseUserData( bool bNew )
     568             : {
     569           0 :     if ( pImp->bUseUserData != bNew )
     570           0 :         SetModified( true );
     571           0 :     pImp->bUseUserData = bNew;
     572           0 : }
     573             : 
     574           0 : bool SfxObjectShell::IsLoadReadonly() const
     575             : {
     576           0 :     return pImp->bLoadReadonly;
     577             : }
     578             : 
     579           0 : bool SfxObjectShell::IsSaveVersionOnClose() const
     580             : {
     581           0 :     return pImp->bSaveVersionOnClose;
     582             : }
     583             : 
     584           0 : void SfxObjectShell::SetLoadReadonly( bool bNew )
     585             : {
     586           0 :     if ( pImp->bLoadReadonly != bNew )
     587           0 :         SetModified( true );
     588           0 :     pImp->bLoadReadonly = bNew;
     589           0 : }
     590             : 
     591           0 : void SfxObjectShell::SetSaveVersionOnClose( bool bNew )
     592             : {
     593           0 :     if ( pImp->bSaveVersionOnClose != bNew )
     594           0 :         SetModified( true );
     595           0 :     pImp->bSaveVersionOnClose = bNew;
     596           0 : }
     597             : 
     598           0 : sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const
     599             : {
     600           0 :     return pImp->m_nModifyPasswordHash;
     601             : }
     602             : 
     603           0 : bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash )
     604             : {
     605           0 :     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
     606           0 :       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
     607             :     {
     608             :         // the hash can be changed only in editable documents,
     609             :         // or during loading of document
     610           0 :         pImp->m_nModifyPasswordHash = nHash;
     611           0 :         return true;
     612             :     }
     613             : 
     614           0 :     return false;
     615             : }
     616             : 
     617           0 : uno::Sequence< beans::PropertyValue > SfxObjectShell::GetModifyPasswordInfo() const
     618             : {
     619           0 :     return pImp->m_aModifyPasswordInfo;
     620             : }
     621             : 
     622           0 : bool SfxObjectShell::SetModifyPasswordInfo( const uno::Sequence< beans::PropertyValue >& aInfo )
     623             : {
     624           0 :     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
     625           0 :       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
     626             :     {
     627             :         // the hash can be changed only in editable documents,
     628             :         // or during loading of document
     629           0 :         pImp->m_aModifyPasswordInfo = aInfo;
     630           0 :         return true;
     631             :     }
     632             : 
     633           0 :     return false;
     634             : }
     635             : 
     636           0 : void SfxObjectShell::SetModifyPasswordEntered( bool bEntered )
     637             : {
     638           0 :     pImp->m_bModifyPasswordEntered = bEntered;
     639           0 : }
     640             : 
     641           0 : bool SfxObjectShell::IsModifyPasswordEntered()
     642             : {
     643           0 :     return pImp->m_bModifyPasswordEntered;
     644           3 : }
     645             : 
     646             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10