LCOV - code coverage report
Current view: top level - sfx2/source/doc - objcont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 152 501 30.3 %
Date: 2012-08-25 Functions: 22 35 62.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 162 975 16.6 %

           Branch data     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/XDocumentProperties.hpp>
      24                 :            : #include <com/sun/star/document/UpdateDocMode.hpp>
      25                 :            : #include <com/sun/star/frame/XLayoutManager.hpp>
      26                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      27                 :            : #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
      28                 :            : #include <com/sun/star/beans/XFastPropertySet.hpp>
      29                 :            : #include <vcl/msgbox.hxx>
      30                 :            : #include <svl/style.hxx>
      31                 :            : #include <vcl/wrkwin.hxx>
      32                 :            : 
      33                 :            : #include <svl/stritem.hxx>
      34                 :            : #include <svl/intitem.hxx>
      35                 :            : #include <svl/rectitem.hxx>
      36                 :            : #include <svl/eitem.hxx>
      37                 :            : #include <svl/urihelper.hxx>
      38                 :            : #include <svl/ctloptions.hxx>
      39                 :            : #include <comphelper/storagehelper.hxx>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <unotools/securityoptions.hxx>
      42                 :            : #include <svtools/sfxecode.hxx>
      43                 :            : #include <svtools/ehdl.hxx>
      44                 :            : #include <tools/datetime.hxx>
      45                 :            : #include <rtl/logfile.hxx>
      46                 :            : #include <math.h>
      47                 :            : 
      48                 :            : #include <unotools/saveopt.hxx>
      49                 :            : #include <unotools/useroptions.hxx>
      50                 :            : #include <unotools/localfilehelper.hxx>
      51                 :            : #include <vcl/virdev.hxx>
      52                 :            : #include <vcl/oldprintadaptor.hxx>
      53                 :            : 
      54                 :            : #include <sfx2/app.hxx>
      55                 :            : #include "sfx2/sfxresid.hxx"
      56                 :            : #include "appdata.hxx"
      57                 :            : #include <sfx2/dinfdlg.hxx>
      58                 :            : #include "fltfnc.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 "sfx2/basmgr.hxx"
      68                 :            : #include <sfx2/viewfrm.hxx>
      69                 :            : #include <sfx2/doctempl.hxx>
      70                 :            : #include "doc.hrc"
      71                 :            : #include <sfx2/sfxbasemodel.hxx>
      72                 :            : #include <sfx2/docfile.hxx>
      73                 :            : #include <sfx2/request.hxx>
      74                 :            : #include "openflag.hxx"
      75                 :            : #include "querytemplate.hxx"
      76                 :            : 
      77                 :            : using namespace ::com::sun::star;
      78                 :            : using namespace ::com::sun::star::uno;
      79                 :            : 
      80                 :            : //====================================================================
      81                 :            : 
      82                 :            : static
      83                 :          0 : bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight)
      84                 :            : {
      85         [ #  # ]:          0 :     if ( i_rLeft.Year != i_rRight.Year )
      86                 :          0 :         return i_rLeft.Year > i_rRight.Year;
      87                 :            : 
      88         [ #  # ]:          0 :     if ( i_rLeft.Month != i_rRight.Month )
      89                 :          0 :         return i_rLeft.Month > i_rRight.Month;
      90                 :            : 
      91         [ #  # ]:          0 :     if ( i_rLeft.Day != i_rRight.Day )
      92                 :          0 :         return i_rLeft.Day > i_rRight.Day;
      93                 :            : 
      94         [ #  # ]:          0 :     if ( i_rLeft.Hours != i_rRight.Hours )
      95                 :          0 :         return i_rLeft.Hours > i_rRight.Hours;
      96                 :            : 
      97         [ #  # ]:          0 :     if ( i_rLeft.Minutes != i_rRight.Minutes )
      98                 :          0 :         return i_rLeft.Minutes > i_rRight.Minutes;
      99                 :            : 
     100         [ #  # ]:          0 :     if ( i_rLeft.Seconds != i_rRight.Seconds )
     101                 :          0 :         return i_rLeft.Seconds > i_rRight.Seconds;
     102                 :            : 
     103         [ #  # ]:          0 :     if ( i_rLeft.HundredthSeconds != i_rRight.HundredthSeconds )
     104                 :          0 :         return i_rLeft.HundredthSeconds > i_rRight.HundredthSeconds;
     105                 :            : 
     106                 :          0 :     return sal_False;
     107                 :            : }
     108                 :            : 
     109                 :            : ::boost::shared_ptr<GDIMetaFile>
     110                 :       6847 : SfxObjectShell::GetPreviewMetaFile( sal_Bool bFullContent ) const
     111                 :            : {
     112                 :       6847 :     return CreatePreviewMetaFile_Impl( bFullContent );
     113                 :            : }
     114                 :            : 
     115                 :            : ::boost::shared_ptr<GDIMetaFile>
     116                 :       6847 : SfxObjectShell::CreatePreviewMetaFile_Impl( sal_Bool bFullContent ) const
     117                 :            : {
     118                 :            :     // DoDraw can only be called when no printing is done, otherwise
     119                 :            :     // the printer may be turned off
     120         [ +  - ]:       6847 :     SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
     121 [ +  + ][ +  - ]:       6870 :     if ( pFrame && pFrame->GetViewShell() &&
                 [ +  - ]
           [ -  +  #  # ]
                 [ -  + ]
     122 [ +  - ][ +  - ]:         23 :          pFrame->GetViewShell()->GetPrinter() &&
     123 [ #  # ][ #  # ]:          0 :          pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
     124         [ #  # ]:          0 :          return ::boost::shared_ptr<GDIMetaFile>();
     125                 :            : 
     126 [ +  - ][ +  - ]:       6847 :     ::boost::shared_ptr<GDIMetaFile> pFile(new GDIMetaFile);
                 [ +  - ]
     127                 :            : 
     128         [ +  - ]:       6847 :     VirtualDevice aDevice;
     129         [ +  - ]:       6847 :     aDevice.EnableOutput( sal_False );
     130                 :            : 
     131 [ +  - ][ +  - ]:       6847 :     MapMode aMode( ((SfxObjectShell*)this)->GetMapUnit() );
     132         [ +  - ]:       6847 :     aDevice.SetMapMode( aMode );
     133         [ +  - ]:       6847 :     pFile->SetPrefMapMode( aMode );
     134                 :            : 
     135                 :       6847 :     Size aTmpSize;
     136                 :            :     sal_Int8 nAspect;
     137         [ +  + ]:       6847 :     if ( bFullContent )
     138                 :            :     {
     139                 :       6816 :         nAspect = ASPECT_CONTENT;
     140 [ +  - ][ +  - ]:       6816 :         aTmpSize = GetVisArea( nAspect ).GetSize();
     141                 :            :     }
     142                 :            :     else
     143                 :            :     {
     144                 :         31 :         nAspect = ASPECT_THUMBNAIL;
     145         [ +  - ]:         31 :         aTmpSize = ((SfxObjectShell*)this)->GetFirstPageSize();
     146                 :            :     }
     147                 :            : 
     148                 :       6847 :     pFile->SetPrefSize( aTmpSize );
     149                 :            :     DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
     150                 :            :                 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
     151                 :            : 
     152         [ +  - ]:       6847 :     pFile->Record( &aDevice );
     153                 :            : 
     154                 :            :     LanguageType eLang;
     155         [ +  - ]:       6847 :     SvtCTLOptions aCTLOptions;
     156 [ +  - ][ -  + ]:       6847 :     if ( SvtCTLOptions::NUMERALS_HINDI == aCTLOptions.GetCTLTextNumerals() )
     157                 :          0 :         eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
     158 [ +  - ][ +  - ]:       6847 :     else if ( SvtCTLOptions::NUMERALS_ARABIC == aCTLOptions.GetCTLTextNumerals() )
     159                 :       6847 :         eLang = LANGUAGE_ENGLISH;
     160                 :            :     else
     161 [ #  # ][ #  # ]:          0 :         eLang = (LanguageType) Application::GetSettings().GetLanguage();
     162                 :            : 
     163         [ +  - ]:       6847 :     aDevice.SetDigitLanguage( eLang );
     164                 :            : 
     165                 :            :     {
     166         [ +  - ]:       6847 :         RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE SfxObjectShell::CreatePreviewMetaFile_Impl" );
     167 [ +  - ][ +  - ]:       6847 :         ((SfxObjectShell*)this)->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), nAspect );
         [ +  - ][ +  - ]
     168                 :            :     }
     169         [ +  - ]:       6847 :     pFile->Stop();
     170                 :            : 
     171 [ +  - ][ +  - ]:       6847 :     return pFile;
         [ +  - ][ +  - ]
                 [ +  - ]
     172                 :            : }
     173                 :            : 
     174                 :            : //====================================================================
     175                 :            : 
     176                 :         33 : void SfxObjectShell::UpdateDocInfoForSave()
     177                 :            : {
     178         [ +  - ]:         33 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     179                 :            : 
     180                 :            :     // clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
     181 [ +  - ][ -  + ]:         66 :     if ( SvtSecurityOptions().IsOptionSet(
     182 [ +  - ][ +  - ]:         66 :             SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
     183                 :            :     {
     184 [ #  # ][ #  # ]:          0 :         xDocProps->resetUserData( ::rtl::OUString() );
     185                 :            :     }
     186 [ +  - ][ +  + ]:         33 :     else if ( IsModified() )
     187                 :            :     {
     188 [ +  - ][ +  - ]:          4 :         String aUserName = SvtUserOptions().GetFullName();
         [ +  - ][ +  - ]
     189 [ +  - ][ -  + ]:          4 :         if ( !IsUseUserData() )
     190                 :            :         {
     191                 :            :             // remove all data pointing to the current user
     192 [ #  # ][ #  # ]:          0 :             if (xDocProps->getAuthor().equals(aUserName)) {
         [ #  # ][ #  # ]
     193 [ #  # ][ #  # ]:          0 :                 xDocProps->setAuthor( ::rtl::OUString() );
     194                 :            :             }
     195 [ #  # ][ #  # ]:          0 :             xDocProps->setModifiedBy( ::rtl::OUString() );
     196 [ #  # ][ #  # ]:          0 :             if (xDocProps->getPrintedBy().equals(aUserName)) {
         [ #  # ][ #  # ]
     197 [ #  # ][ #  # ]:          0 :                 xDocProps->setPrintedBy( ::rtl::OUString() );
     198                 :            :             }
     199                 :            :         }
     200                 :            :         else
     201                 :            :         {
     202                 :            :             // update ModificationAuthor, revision and editing time
     203         [ +  - ]:          4 :             ::DateTime now( ::DateTime::SYSTEM );
     204         [ +  - ]:          4 :             xDocProps->setModificationDate( util::DateTime(
     205                 :          4 :                 now.Get100Sec(), now.GetSec(), now.GetMin(),
     206                 :          4 :                 now.GetHour(), now.GetDay(), now.GetMonth(),
     207         [ +  - ]:          8 :                 now.GetYear() ) );
     208 [ +  - ][ +  - ]:          4 :             xDocProps->setModifiedBy( aUserName );
                 [ +  - ]
     209 [ #  # ][ +  - ]:          4 :             if ( !HasName() || pImp->bIsSaving )
                 [ -  + ]
     210                 :            :                 // QUESTION: not in case of "real" SaveAs as this is meant to create a new document
     211         [ +  - ]:          4 :                 UpdateTime_Impl( xDocProps );
     212         [ +  - ]:          4 :         }
     213                 :         33 :     }
     214                 :         33 : }
     215                 :            : 
     216                 :            : //--------------------------------------------------------------------
     217                 :            : 
     218                 :            : static void
     219                 :          4 : lcl_add(util::Duration & rDur, Time const& rTime)
     220                 :            : {
     221                 :            :     // here we don't care about overflow: rDur is converted back to seconds
     222                 :            :     // anyway, and Time cannot store more than ~4000 hours
     223                 :          4 :     rDur.Hours   += rTime.GetHour();
     224                 :          4 :     rDur.Minutes += rTime.GetMin();
     225                 :          4 :     rDur.Seconds += rTime.GetSec();
     226                 :          4 : }
     227                 :            : 
     228                 :            : // Update the processing time
     229                 :          4 : void SfxObjectShell::UpdateTime_Impl(
     230                 :            :     const uno::Reference<document::XDocumentProperties> & i_xDocProps)
     231                 :            : {
     232                 :            :     // Get old time from documentinfo
     233 [ +  - ][ +  - ]:          4 :     const sal_Int32 secs = i_xDocProps->getEditingDuration();
     234                 :            :     util::Duration editDuration(sal_False, 0, 0, 0,
     235                 :          4 :             secs/3600, (secs%3600)/60, secs%60, 0);
     236                 :            : 
     237                 :            :     // Initialize some local member! Its neccessary for wollow operations!
     238         [ +  - ]:          4 :     DateTime    aNow( DateTime::SYSTEM );   // Date and time at current moment
     239         [ +  - ]:          4 :     Time        n24Time     (24,0,0,0)  ;   // Time-value for 24 hours - see follow calculation
     240                 :          4 :     sal_uIntPtr     nDays       = 0         ;   // Count of days between now and last editing
     241                 :          4 :     Time        nAddTime    (0)         ;   // Value to add on aOldTime
     242                 :            : 
     243                 :            :     // Safe impossible cases!
     244                 :            :     // User has changed time to the past between last editing and now ... its not possible!!!
     245                 :            :     DBG_ASSERT( !(aNow.GetDate()<pImp->nTime.GetDate()), "Timestamp of last change is in the past ?!..." );
     246                 :            : 
     247                 :            :     // Do the follow only, if user has NOT changed time to the past.
     248                 :            :     // Else add a time of 0 to aOldTime ... !!!
     249         [ +  - ]:          4 :     if (aNow.GetDate()>=pImp->nTime.GetDate())
     250                 :            :     {
     251                 :            :         // Get count of days last editing.
     252         [ +  - ]:          4 :         nDays = aNow.GetSecFromDateTime(pImp->nTime.GetDate())/86400 ;
     253                 :            : 
     254         [ -  + ]:          4 :         if (nDays==0)
     255                 :            :         {
     256                 :            :             // If no day between now and last editing - calculate time directly.
     257 [ #  # ][ #  # ]:          0 :             nAddTime    =   (const Time&)aNow - (const Time&)pImp->nTime ;
     258                 :            :         }
     259                 :            :         else
     260                 :            :         // If time of working without save greater then 1 month (!) ....
     261                 :            :         // we add 0 to aOldTime!
     262         [ -  + ]:          4 :         if (nDays<=31)
     263                 :            :         {
     264                 :            :             // If 1 or up to 31 days between now and last editing - calculate time indirectly.
     265                 :            :             // nAddTime = (24h - nTime) + (nDays * 24h) + aNow
     266                 :          0 :             --nDays;
     267         [ #  # ]:          0 :              nAddTime    =  nDays*n24Time.GetTime() ;
     268         [ #  # ]:          0 :             nAddTime    +=  n24Time-(const Time&)pImp->nTime        ;
           [ #  #  #  # ]
     269         [ #  # ]:          0 :             nAddTime    +=  aNow                    ;
     270                 :            :         }
     271                 :            : 
     272                 :          4 :         lcl_add(editDuration, nAddTime);
     273                 :            :     }
     274                 :            : 
     275         [ +  - ]:          4 :     pImp->nTime = aNow;
     276                 :            :     try {
     277                 :            :         const sal_Int32 newSecs( (editDuration.Hours*3600)
     278                 :          4 :             + (editDuration.Minutes*60) + editDuration.Seconds);
     279 [ +  - ][ +  - ]:          4 :         i_xDocProps->setEditingDuration(newSecs);
     280 [ +  - ][ +  - ]:          4 :         i_xDocProps->setEditingCycles(i_xDocProps->getEditingCycles() + 1);
         [ +  - ][ +  - ]
     281                 :            :     }
     282         [ #  # ]:          0 :     catch (const lang::IllegalArgumentException &)
     283                 :            :     {
     284                 :            :         // ignore overflow
     285                 :            :     }
     286                 :          4 : }
     287                 :            : 
     288                 :            : //--------------------------------------------------------------------
     289                 :            : 
     290                 :          0 : SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
     291                 :            : (
     292                 :            :     Window*             pParent,
     293                 :            :     const SfxItemSet&   rSet
     294                 :            : )
     295                 :            : {
     296         [ #  # ]:          0 :     return new SfxDocumentInfoDialog(pParent, rSet);
     297                 :            : }
     298                 :            : 
     299                 :            : //--------------------------------------------------------------------
     300                 :            : 
     301                 :          0 : SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
     302                 :            : {
     303                 :          0 :     return 0;
     304                 :            : }
     305                 :            : 
     306                 :          0 : void SfxObjectShell::SetOrganizerSearchMask(
     307                 :            :     SfxStyleSheetBasePool* pStylePool) const
     308                 :            : {
     309                 :            :     pStylePool->SetSearchMask(
     310                 :            :         SFX_STYLE_FAMILY_ALL,
     311                 :          0 :         SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
     312                 :          0 : }
     313                 :            : 
     314                 :            : //--------------------------------------------------------------------
     315                 :            : 
     316                 :          0 : sal_uInt16 SfxObjectShell::GetContentCount(sal_uInt16 nIdx)
     317                 :            : {
     318   [ #  #  #  # ]:          0 :     switch(nIdx)
     319                 :            :     {
     320                 :            :         case INDEX_IGNORE:
     321                 :          0 :             return DEF_CONTENT_COUNT;
     322                 :            :         case CONTENT_STYLE:
     323                 :            :         {
     324                 :          0 :             SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
     325         [ #  # ]:          0 :             if(!pStylePool)
     326                 :          0 :                 return 0;
     327                 :          0 :             SetOrganizerSearchMask(pStylePool);
     328                 :          0 :             return pStylePool->Count();
     329                 :            :         }
     330                 :            :         case CONTENT_MACRO:
     331                 :          0 :             break;
     332                 :            :     }
     333                 :          0 :     return 0;
     334                 :            : }
     335                 :            : 
     336                 :            : 
     337                 :            : //--------------------------------------------------------------------
     338                 :            : //TODO/CLEANUP: remove this method
     339                 :          0 : void  SfxObjectShell::TriggerHelpPI(sal_uInt16 nIdx1, sal_uInt16 nIdx2)
     340                 :            : {
     341 [ #  # ][ #  # ]:          0 :     if(nIdx1==CONTENT_STYLE && nIdx2 != INDEX_IGNORE) //StyleSheets
     342                 :            :     {
     343                 :          0 :         SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
     344                 :          0 :         SetOrganizerSearchMask(pStylePool);
     345                 :            :     }
     346                 :          0 : }
     347                 :            : 
     348                 :          0 : sal_Bool SfxObjectShell::CanHaveChildren(sal_uInt16 nIdx1, sal_uInt16 nIdx2)
     349                 :            : {
     350   [ #  #  #  # ]:          0 :     switch(nIdx1)
     351                 :            :     {
     352                 :            :     case INDEX_IGNORE:
     353                 :          0 :         return true;
     354                 :            :     case CONTENT_STYLE:
     355 [ #  # ][ #  # ]:          0 :         return INDEX_IGNORE == nIdx2 || !GetStyleSheetPool() ? false : true;
     356                 :            :     case CONTENT_MACRO:
     357                 :          0 :         return false;
     358                 :            :     }
     359                 :          0 :     return false;
     360                 :            : }
     361                 :            : 
     362                 :            : //--------------------------------------------------------------------
     363                 :            : 
     364                 :          0 : void SfxObjectShell::GetContent(String &rText,
     365                 :            :                                 Bitmap &rClosedBitmap,
     366                 :            :                                 Bitmap &rOpenedBitmap,
     367                 :            :                                 sal_Bool &bCanDel,
     368                 :            :                                 sal_uInt16 i,
     369                 :            :                                 sal_uInt16 nIdx
     370                 :            : )
     371                 :            : {
     372                 :          0 :     bCanDel=true;
     373                 :            : 
     374   [ #  #  #  # ]:          0 :     switch(nIdx)
     375                 :            :     {
     376                 :            :         case INDEX_IGNORE:
     377                 :            :         {
     378                 :          0 :             sal_uInt16 nTextResId = 0;
     379                 :          0 :             sal_uInt16 nClosedBitmapResId = 0; // evtl. sp"ater mal unterschiedliche
     380                 :          0 :             sal_uInt16 nOpenedBitmapResId = 0; // "     "       "   "
     381      [ #  #  # ]:          0 :             switch(i)
     382                 :            :             {
     383                 :            :                 case CONTENT_STYLE:
     384                 :          0 :                     nTextResId = STR_STYLES;
     385                 :          0 :                     nClosedBitmapResId= BMP_STYLES_CLOSED;
     386                 :          0 :                     nOpenedBitmapResId= BMP_STYLES_OPENED;
     387                 :          0 :                     break;
     388                 :            :                 case CONTENT_MACRO:
     389                 :          0 :                     nTextResId = STR_MACROS;
     390                 :          0 :                     nClosedBitmapResId= BMP_STYLES_CLOSED;
     391                 :          0 :                     nOpenedBitmapResId= BMP_STYLES_OPENED;
     392                 :          0 :                     break;
     393                 :            :             }
     394                 :            : 
     395         [ #  # ]:          0 :             if ( nTextResId )
     396                 :            :             {
     397 [ #  # ][ #  # ]:          0 :                 rText = SfxResId(nTextResId).toString();
     398 [ #  # ][ #  # ]:          0 :                 rClosedBitmap = Bitmap(SfxResId(nClosedBitmapResId));
                 [ #  # ]
     399 [ #  # ][ #  # ]:          0 :                 rOpenedBitmap = Bitmap(SfxResId(nOpenedBitmapResId));
                 [ #  # ]
     400                 :            :             }
     401                 :          0 :             break;
     402                 :            :         }
     403                 :            : 
     404                 :            :         case CONTENT_STYLE:
     405                 :            :         {
     406                 :          0 :             SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
     407                 :          0 :             SetOrganizerSearchMask(pStylePool);
     408                 :          0 :             SfxStyleSheetBase *pStyle = (*pStylePool)[i];
     409                 :          0 :             rText = pStyle->GetName();
     410                 :          0 :             bCanDel=((pStyle->GetMask() & SFXSTYLEBIT_USERDEF)
     411                 :          0 :                      == SFXSTYLEBIT_USERDEF);
     412                 :            :             rClosedBitmap = rOpenedBitmap =
     413 [ #  # ][ #  # ]:          0 :                 GetStyleFamilyBitmap(pStyle->GetFamily());
     414                 :            :         }
     415                 :          0 :             break;
     416                 :            :         case CONTENT_MACRO:
     417                 :          0 :             break;
     418                 :            :     }
     419                 :          0 : }
     420                 :            : 
     421                 :            : //--------------------------------------------------------------------
     422                 :            : 
     423                 :          0 : Bitmap SfxObjectShell::GetStyleFamilyBitmap(SfxStyleFamily eFamily)
     424                 :            : {
     425                 :          0 :     sal_uInt16 nResId = 0;
     426   [ #  #  #  #  :          0 :     switch(eFamily)
                   #  # ]
     427                 :            :     {
     428                 :            :         case SFX_STYLE_FAMILY_CHAR:
     429                 :          0 :             nResId = BMP_STYLES_FAMILY1;
     430                 :          0 :             break;
     431                 :            :         case SFX_STYLE_FAMILY_PARA:
     432                 :          0 :             nResId = BMP_STYLES_FAMILY2;
     433                 :          0 :             break;
     434                 :            :         case SFX_STYLE_FAMILY_FRAME:
     435                 :          0 :             nResId = BMP_STYLES_FAMILY3;
     436                 :          0 :             break;
     437                 :            :         case SFX_STYLE_FAMILY_PAGE :
     438                 :          0 :             nResId = BMP_STYLES_FAMILY4;
     439                 :          0 :             break;
     440                 :            :         case SFX_STYLE_FAMILY_PSEUDO:
     441                 :            :         case SFX_STYLE_FAMILY_ALL:
     442                 :          0 :             break;
     443                 :            :     }
     444                 :            : 
     445         [ #  # ]:          0 :     if ( nResId )
     446         [ #  # ]:          0 :         return Bitmap(SfxResId(nResId));
     447                 :            :     else
     448                 :          0 :         return Bitmap();
     449                 :            : }
     450                 :            : 
     451                 :            : 
     452                 :            : //--------------------------------------------------------------------
     453                 :            : 
     454                 :          0 : sal_Bool SfxObjectShell::Insert(SfxObjectShell &rSource,
     455                 :            :                               sal_uInt16 nSourceIdx1,
     456                 :            :                               sal_uInt16 nSourceIdx2,
     457                 :            :                               sal_uInt16 /*nSourceIdx3*/,
     458                 :            :                               sal_uInt16 &nIdx1,
     459                 :            :                               sal_uInt16 &nIdx2,
     460                 :            :                               sal_uInt16 &/*nIdx3*/,
     461                 :            :                               sal_uInt16 &/*nDeleted*/)
     462                 :            : {
     463                 :          0 :     sal_Bool bRet = sal_False;
     464                 :            : 
     465 [ #  # ][ #  # ]:          0 :     if (INDEX_IGNORE == nIdx1 && CONTENT_STYLE == nSourceIdx1)
     466                 :          0 :         nIdx1 = CONTENT_STYLE;
     467                 :            : 
     468 [ #  # ][ #  # ]:          0 :     if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == nIdx1)
     469                 :            :     {
     470                 :          0 :         SfxStyleSheetBasePool* pHisPool  = rSource.GetStyleSheetPool();
     471                 :          0 :         SfxStyleSheetBasePool* pMyPool   = GetStyleSheetPool();
     472                 :          0 :         SetOrganizerSearchMask(pHisPool);
     473                 :          0 :         SetOrganizerSearchMask(pMyPool);
     474                 :          0 :         SfxStyleSheetBase* pHisSheet = NULL;
     475                 :            : 
     476 [ #  # ][ #  # ]:          0 :         if ( pHisPool && pHisPool->Count() > nSourceIdx2 )
                 [ #  # ]
     477                 :          0 :             pHisSheet = (*pHisPool)[nSourceIdx2];
     478                 :            : 
     479                 :            :         // Pasting is only needed if a style sheet is moved between
     480                 :            :         // different (!) Pools
     481                 :            : 
     482 [ #  # ][ #  # ]:          0 :         if ( pHisSheet && pMyPool != pHisPool )
     483                 :            :         {
     484         [ #  # ]:          0 :             if (INDEX_IGNORE == nIdx2)
     485                 :            :             {
     486         [ #  # ]:          0 :                 nIdx2 = pMyPool->Count();
     487                 :            :             }
     488                 :            : 
     489                 :            :             // if such a template already exists: delete!
     490 [ #  # ][ #  # ]:          0 :             String aOldName(pHisSheet->GetName());
     491                 :          0 :             SfxStyleFamily eOldFamily = pHisSheet->GetFamily();
     492                 :            : 
     493         [ #  # ]:          0 :             SfxStyleSheetBase* pExist = pMyPool->Find(aOldName, eOldFamily);
     494                 :            :             sal_Bool bUsedOrUserDefined;
     495         [ #  # ]:          0 :             if( pExist )
     496                 :            :             {
     497                 :            :                 bUsedOrUserDefined =
     498 [ #  # ][ #  # ]:          0 :                     pExist->IsUsed() || pExist->IsUserDefined();
                 [ #  # ]
     499         [ #  # ]:          0 :                 if( ErrorHandler::HandleError(
     500 [ #  # ][ #  # ]:          0 :                     *new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, aOldName ) )
         [ #  # ][ #  # ]
     501                 :            :                     != ERRCODE_BUTTON_OK )
     502                 :          0 :                     return sal_False;
     503                 :            :                 else
     504                 :            :                 {
     505         [ #  # ]:          0 :                     pMyPool->Replace( *pHisSheet, *pExist );
     506         [ #  # ]:          0 :                     SetModified( sal_True );
     507                 :          0 :                     nIdx2 = nIdx1 = INDEX_IGNORE;
     508                 :          0 :                     return sal_True;
     509                 :            :                 }
     510                 :            :             }
     511                 :            : 
     512                 :            :             SfxStyleSheetBase& rNewSheet = pMyPool->Make(
     513                 :            :                 aOldName, eOldFamily,
     514         [ #  # ]:          0 :                 pHisSheet->GetMask(), nIdx2);
     515                 :            : 
     516                 :            :             // Fill the Itemset of the new template
     517 [ #  # ][ #  # ]:          0 :             rNewSheet.GetItemSet().Set(pHisSheet->GetItemSet());
                 [ #  # ]
     518                 :            : 
     519                 :            :             // Who gets the new one as a Parent?
     520                 :            :             // Who is using the new one as Follow?
     521         [ #  # ]:          0 :             SfxStyleSheetBase* pTestSheet = pMyPool->First();
     522         [ #  # ]:          0 :             while (pTestSheet)
     523                 :            :             {
     524 [ #  # ][ #  # ]:          0 :                 if (pTestSheet->GetFamily() == eOldFamily &&
         [ #  # ][ #  # ]
     525         [ #  # ]:          0 :                     pTestSheet->HasParentSupport() &&
     526 [ #  # ][ #  # ]:          0 :                     pTestSheet->GetParent() == aOldName)
     527                 :            :                 {
     528         [ #  # ]:          0 :                     pTestSheet->SetParent(aOldName);
     529                 :            :                     // Rebuild Link
     530                 :            :                 }
     531                 :            : 
     532 [ #  # ][ #  # ]:          0 :                 if (pTestSheet->GetFamily() == eOldFamily &&
         [ #  # ][ #  # ]
     533         [ #  # ]:          0 :                     pTestSheet->HasFollowSupport() &&
     534 [ #  # ][ #  # ]:          0 :                     pTestSheet->GetFollow() == aOldName)
     535                 :            :                 {
     536         [ #  # ]:          0 :                     pTestSheet->SetFollow(aOldName);
     537                 :            :                     // Rebuild Link
     538                 :            :                 }
     539                 :            : 
     540         [ #  # ]:          0 :                 pTestSheet = pMyPool->Next();
     541                 :            :             }
     542                 :            :             bUsedOrUserDefined =
     543 [ #  # ][ #  # ]:          0 :                 rNewSheet.IsUsed() || rNewSheet.IsUserDefined();
                 [ #  # ]
     544                 :            : 
     545                 :            : 
     546                 :            :             // has a New Parent? if so, start search with the same name
     547 [ #  # ][ #  # ]:          0 :             if (pHisSheet->HasParentSupport())
     548                 :            :             {
     549         [ #  # ]:          0 :                 const String& rParentName = pHisSheet->GetParent();
     550         [ #  # ]:          0 :                 if (0 != rParentName.Len())
     551                 :            :                 {
     552                 :            :                     SfxStyleSheetBase* pParentOfNew =
     553         [ #  # ]:          0 :                         pMyPool->Find(rParentName, eOldFamily);
     554         [ #  # ]:          0 :                     if (pParentOfNew)
     555         [ #  # ]:          0 :                         rNewSheet.SetParent(rParentName);
     556                 :            :                 }
     557                 :            :             }
     558                 :            : 
     559                 :            :             // Has the new got a Follow? if so start search
     560                 :            :             // with the same name.
     561 [ #  # ][ #  # ]:          0 :             if (pHisSheet->HasFollowSupport())
     562                 :            :             {
     563         [ #  # ]:          0 :                 const String& rFollowName = pHisSheet->GetFollow();
     564         [ #  # ]:          0 :                 if (0 != rFollowName.Len())
     565                 :            :                 {
     566                 :            :                     SfxStyleSheetBase* pFollowOfNew =
     567         [ #  # ]:          0 :                         pMyPool->Find(rFollowName, eOldFamily);
     568         [ #  # ]:          0 :                     if (pFollowOfNew)
     569         [ #  # ]:          0 :                         rNewSheet.SetFollow(rFollowName);
     570                 :            :                 }
     571                 :            :             }
     572                 :            : 
     573         [ #  # ]:          0 :             SetModified( sal_True );
     574         [ #  # ]:          0 :             if( !bUsedOrUserDefined ) nIdx2 = nIdx1 = INDEX_IGNORE;
     575                 :            : 
     576 [ #  # ][ #  # ]:          0 :             bRet = sal_True;
     577                 :            :         }
     578                 :            :         else
     579                 :          0 :             bRet = sal_False;
     580                 :            :     }
     581                 :            : 
     582                 :          0 :     return bRet;
     583                 :            : }
     584                 :            : 
     585                 :            : //--------------------------------------------------------------------
     586                 :            : 
     587                 :          0 : sal_Bool SfxObjectShell::Remove
     588                 :            : (
     589                 :            :     sal_uInt16 nIdx1,
     590                 :            :     sal_uInt16 nIdx2,
     591                 :            :     sal_uInt16 /*nIdx3*/
     592                 :            : )
     593                 :            : {
     594                 :          0 :     sal_Bool bRet = sal_False;
     595                 :            : 
     596         [ #  # ]:          0 :     if (CONTENT_STYLE == nIdx1)
     597                 :            :     {
     598         [ #  # ]:          0 :         SfxStyleSheetBasePool* pMyPool  = GetStyleSheetPool();
     599                 :            : 
     600         [ #  # ]:          0 :         SetOrganizerSearchMask(pMyPool);
     601                 :            : 
     602         [ #  # ]:          0 :         SfxStyleSheetBase* pMySheet =  (*pMyPool)[nIdx2];
     603 [ #  # ][ #  # ]:          0 :         String aName(pMySheet->GetName());
     604         [ #  # ]:          0 :         String aEmpty;
     605                 :          0 :         SfxStyleFamily  eFamily = pMySheet->GetFamily();
     606         [ #  # ]:          0 :         pMyPool->Remove(pMySheet);
     607                 :          0 :         bRet = sal_True;
     608                 :            : 
     609         [ #  # ]:          0 :         SfxStyleSheetBase* pTestSheet = pMyPool->First();
     610         [ #  # ]:          0 :         while (pTestSheet)
     611                 :            :         {
     612 [ #  # ][ #  # ]:          0 :             if (pTestSheet->GetFamily() == eFamily &&
         [ #  # ][ #  # ]
     613         [ #  # ]:          0 :                 pTestSheet->HasParentSupport() &&
     614 [ #  # ][ #  # ]:          0 :                 pTestSheet->GetParent() == aName)
     615                 :            :             {
     616         [ #  # ]:          0 :                 pTestSheet->SetParent(aEmpty); // Remove link
     617                 :            :             }
     618                 :            : 
     619 [ #  # ][ #  # ]:          0 :             if (pTestSheet->GetFamily() == eFamily &&
         [ #  # ][ #  # ]
     620         [ #  # ]:          0 :                 pTestSheet->HasFollowSupport() &&
     621 [ #  # ][ #  # ]:          0 :                 pTestSheet->GetFollow() == aName)
     622                 :            :             {
     623         [ #  # ]:          0 :                 pTestSheet->SetFollow(aEmpty); // Remove link
     624                 :            :             }
     625                 :            : 
     626         [ #  # ]:          0 :             pTestSheet = pMyPool->Next();
     627                 :            :         }
     628                 :            : 
     629 [ #  # ][ #  # ]:          0 :         SetModified( sal_True );
                 [ #  # ]
     630                 :            :     }
     631                 :            : 
     632                 :          0 :     return bRet;
     633                 :            : }
     634                 :            : 
     635                 :            : //--------------------------------------------------------------------
     636                 :            : 
     637                 :          0 : sal_Bool SfxObjectShell::Print
     638                 :            : (
     639                 :            :     Printer&        rPrt,
     640                 :            :     sal_uInt16          nIdx1,
     641                 :            :     sal_uInt16          /*nIdx2*/,
     642                 :            :     sal_uInt16          /*nIdx3*/,
     643                 :            :     const String*   pObjectName
     644                 :            : )
     645                 :            : {
     646         [ #  # ]:          0 :     switch(nIdx1)
     647                 :            :     {
     648                 :            :       case CONTENT_STYLE:
     649                 :            :         {
     650         [ #  # ]:          0 :             SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
     651         [ #  # ]:          0 :             SetOrganizerSearchMask(pStylePool);
     652                 :            :             SfxStyleSheetIterator* pIter = pStylePool->CreateIterator(
     653 [ #  # ][ #  # ]:          0 :                 pStylePool->GetSearchFamily(), pStylePool->GetSearchMask() );
     654         [ #  # ]:          0 :             SfxStyleSheetBase *pStyle = pIter->First();
     655         [ #  # ]:          0 :             if ( !pStyle )
     656                 :          0 :                 return sal_True;
     657                 :            : 
     658                 :            :             // prepare adaptor for old style StartPage/EndPage printing
     659 [ #  # ][ #  # ]:          0 :             boost::shared_ptr< Printer > pPrinter( new Printer( rPrt.GetJobSetup() ) );
                 [ #  # ]
     660 [ #  # ][ #  # ]:          0 :             vcl::OldStylePrintAdaptor* pAdaptor = new vcl::OldStylePrintAdaptor( pPrinter );
     661         [ #  # ]:          0 :             boost::shared_ptr< vcl::PrinterController > pController( pAdaptor );
     662                 :            : 
     663         [ #  # ]:          0 :             pAdaptor->StartPage();
     664                 :            : 
     665 [ #  # ][ #  # ]:          0 :             pPrinter->SetMapMode(MapMode(MAP_10TH_MM));
                 [ #  # ]
     666 [ #  # ][ #  # ]:          0 :             Font aFont( DEFINE_CONST_UNICODE( "Arial" ), Size(0, 64));   // 18pt
                 [ #  # ]
     667         [ #  # ]:          0 :             aFont.SetWeight(WEIGHT_BOLD);
     668         [ #  # ]:          0 :             pPrinter->SetFont(aFont);
     669         [ #  # ]:          0 :             const Size aPageSize(pPrinter->GetOutputSize());
     670                 :          0 :             const sal_uInt16 nXIndent = 200;
     671                 :          0 :             sal_uInt16 nYIndent = 200;
     672                 :          0 :             Point aOutPos(nXIndent, nYIndent);
     673 [ #  # ][ #  # ]:          0 :             String aHeader(SfxResId(STR_PRINT_STYLES_HEADER).toString());
                 [ #  # ]
     674         [ #  # ]:          0 :             if ( pObjectName )
     675         [ #  # ]:          0 :                 aHeader += *pObjectName;
     676                 :            :             else
     677 [ #  # ][ #  # ]:          0 :                 aHeader += GetTitle();
                 [ #  # ]
     678         [ #  # ]:          0 :             long nTextHeight( pPrinter->GetTextHeight() );
     679         [ #  # ]:          0 :             pPrinter->DrawText(aOutPos, aHeader);
     680                 :          0 :             aOutPos.Y() += nTextHeight;
     681                 :          0 :             aOutPos.Y() += nTextHeight/2;
     682         [ #  # ]:          0 :             aFont.SetSize(Size(0, 35)); // 10pt
     683         [ #  # ]:          0 :             while(pStyle)
     684                 :            :             {
     685                 :            :                 // print template name
     686 [ #  # ][ #  # ]:          0 :                 String aStr(pStyle->GetName());
     687         [ #  # ]:          0 :                 aFont.SetWeight(WEIGHT_BOLD);
     688         [ #  # ]:          0 :                 pPrinter->SetFont(aFont);
     689         [ #  # ]:          0 :                 nTextHeight = pPrinter->GetTextHeight();
     690                 :            :                 // check for new page
     691         [ #  # ]:          0 :                 if ( aOutPos.Y() + nTextHeight*2 >
     692                 :          0 :                     aPageSize.Height() - (long) nYIndent )
     693                 :            :                 {
     694         [ #  # ]:          0 :                     pAdaptor->EndPage();
     695         [ #  # ]:          0 :                     pAdaptor->StartPage();
     696                 :          0 :                     aOutPos.Y() = nYIndent;
     697                 :            :                 }
     698         [ #  # ]:          0 :                 pPrinter->DrawText(aOutPos, aStr);
     699                 :          0 :                 aOutPos.Y() += nTextHeight;
     700                 :            : 
     701                 :            :                 // print template description
     702         [ #  # ]:          0 :                 aFont.SetWeight(WEIGHT_NORMAL);
     703         [ #  # ]:          0 :                 pPrinter->SetFont(aFont);
     704 [ #  # ][ #  # ]:          0 :                 aStr = pStyle->GetDescription();
                 [ #  # ]
     705                 :          0 :                 const char cDelim = ' ';
     706                 :          0 :                 sal_uInt16 nStart = 0, nIdx = 0;
     707                 :            : 
     708         [ #  # ]:          0 :                 nTextHeight = pPrinter->GetTextHeight();
     709                 :            :                 // break text into lines
     710         [ #  # ]:          0 :                 while(nIdx < aStr.Len())
     711                 :            :                 {
     712                 :          0 :                     sal_uInt16  nOld = nIdx;
     713                 :            :                     long nTextWidth;
     714         [ #  # ]:          0 :                     nIdx = aStr.Search(cDelim, nStart);
     715         [ #  # ]:          0 :                     nTextWidth = pPrinter->GetTextWidth(aStr, nStart, nIdx-nStart);
     716   [ #  #  #  # ]:          0 :                     while(nIdx != STRING_NOTFOUND &&
                 [ #  # ]
     717                 :          0 :                           aOutPos.X() + nTextWidth <
     718                 :          0 :                           aPageSize.Width() - (long) nXIndent)
     719                 :            :                     {
     720                 :          0 :                         nOld = nIdx;
     721         [ #  # ]:          0 :                         nIdx = aStr.Search(cDelim, nIdx+1);
     722         [ #  # ]:          0 :                         nTextWidth = pPrinter->GetTextWidth(aStr, nStart, nIdx-nStart);
     723                 :            :                     }
     724                 :            :                     String aTmp(aStr, nStart, nIdx == STRING_NOTFOUND?
     725                 :            :                                 STRING_LEN :
     726 [ #  # ][ #  # ]:          0 :                                 nOld-nStart);
     727         [ #  # ]:          0 :                     if ( aTmp.Len() )
     728                 :            :                     {
     729                 :          0 :                         nStart = nOld+1;    // trailing space
     730                 :            :                     }
     731                 :            :                     else
     732                 :            :                     {
     733                 :          0 :                         sal_uInt16 nChar = 1;
     734   [ #  #  #  # ]:          0 :                         while(
                 [ #  # ]
     735                 :          0 :                             nStart + nChar < aStr.Len() &&
     736                 :          0 :                             aOutPos.X() + pPrinter->GetTextWidth(
     737         [ #  # ]:          0 :                                 aStr, nStart, nChar) <
     738                 :          0 :                             aPageSize.Width() - nXIndent)
     739                 :          0 :                             ++nChar;
     740 [ #  # ][ #  # ]:          0 :                         aTmp = String(aStr, nStart, nChar-1);
                 [ #  # ]
     741                 :          0 :                         nIdx = nStart + nChar;
     742                 :          0 :                         nStart = nIdx;
     743                 :            :                     }
     744         [ #  # ]:          0 :                     if ( aOutPos.Y() + nTextHeight*2 >
     745                 :          0 :                         aPageSize.Height() - nYIndent )
     746                 :            :                     {
     747         [ #  # ]:          0 :                         pAdaptor->EndPage();
     748         [ #  # ]:          0 :                         pAdaptor->StartPage();
     749                 :          0 :                         aOutPos.Y() = nYIndent;
     750                 :            :                     }
     751         [ #  # ]:          0 :                     pPrinter->DrawText(aOutPos, aTmp);
     752         [ #  # ]:          0 :                     aOutPos.Y() += pPrinter->GetTextHeight();
     753         [ #  # ]:          0 :                 }
     754         [ #  # ]:          0 :                 pStyle = pIter->Next();
     755         [ #  # ]:          0 :             }
     756         [ #  # ]:          0 :             pAdaptor->EndPage();
     757                 :            : 
     758         [ #  # ]:          0 :             Printer::PrintJob( pController, rPrt.GetJobSetup() );
     759                 :            : 
     760 [ #  # ][ #  # ]:          0 :             delete pIter;
     761 [ #  # ][ #  # ]:          0 :             break;
         [ #  # ][ #  # ]
     762                 :            :         }
     763                 :            :       default:
     764                 :          0 :           return sal_False;
     765                 :            :     }
     766                 :          0 :     return sal_True;
     767                 :            : }
     768                 :            : 
     769                 :            : //--------------------------------------------------------------------
     770                 :            : 
     771                 :          0 : void SfxObjectShell::LoadStyles
     772                 :            : (
     773                 :            :     SfxObjectShell &rSource         /*  the document template from which
     774                 :            :                                         the styles are to be loaded */
     775                 :            : )
     776                 :            : 
     777                 :            : /*  [Description]
     778                 :            : 
     779                 :            :     This method is called by the SFx if template styles are to be loaded.
     780                 :            :     Existing styles are in this case overwritten. The document has then to be
     781                 :            :     newly formatted. Therefore, the application of this method is usually
     782                 :            :     overloaded and its implementation is calling the implementation in
     783                 :            :     the base class.
     784                 :            : */
     785                 :            : 
     786                 :            : {
     787                 :            :     struct Styles_Impl
     788                 :            :     {
     789                 :            :         SfxStyleSheetBase *pSource;
     790                 :            :         SfxStyleSheetBase *pDest;
     791                 :            :     };
     792                 :            : 
     793                 :          0 :     SfxStyleSheetBasePool *pSourcePool = rSource.GetStyleSheetPool();
     794                 :            :     DBG_ASSERT(pSourcePool, "Source-DocumentShell ohne StyleSheetPool");
     795                 :          0 :     SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool();
     796                 :            :     DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool");
     797                 :          0 :     pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, 0xffff);
     798                 :          0 :     Styles_Impl *pFound = new Styles_Impl[pSourcePool->Count()];
     799                 :          0 :     sal_uInt16 nFound = 0;
     800                 :            : 
     801                 :          0 :     SfxStyleSheetBase *pSource = pSourcePool->First();
     802         [ #  # ]:          0 :     while ( pSource )
     803                 :            :     {
     804                 :            :         SfxStyleSheetBase *pDest =
     805                 :          0 :             pMyPool->Find( pSource->GetName(), pSource->GetFamily() );
     806         [ #  # ]:          0 :         if ( !pDest )
     807                 :            :         {
     808                 :          0 :             pDest = &pMyPool->Make( pSource->GetName(),
     809                 :          0 :                     pSource->GetFamily(), pSource->GetMask());
     810                 :            :             // Setting of Parents, the next style
     811                 :            :         }
     812                 :          0 :         pFound[nFound].pSource = pSource;
     813                 :          0 :         pFound[nFound].pDest = pDest;
     814                 :          0 :         ++nFound;
     815                 :          0 :         pSource = pSourcePool->Next();
     816                 :            :     }
     817                 :            : 
     818         [ #  # ]:          0 :     for ( sal_uInt16 i = 0; i < nFound; ++i )
     819                 :            :     {
     820                 :          0 :         pFound[i].pDest->GetItemSet().PutExtended(pFound[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
     821         [ #  # ]:          0 :         if(pFound[i].pSource->HasParentSupport())
     822                 :          0 :             pFound[i].pDest->SetParent(pFound[i].pSource->GetParent());
     823         [ #  # ]:          0 :         if(pFound[i].pSource->HasFollowSupport())
     824                 :          0 :             pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent());
     825                 :            :     }
     826         [ #  # ]:          0 :     delete [] pFound;
     827                 :          0 : }
     828                 :            : 
     829                 :            : //--------------------------------------------------------------------
     830                 :            : 
     831                 :       1709 : void SfxObjectShell::UpdateFromTemplate_Impl(  )
     832                 :            : 
     833                 :            : /*  [Description]
     834                 :            : 
     835                 :            :     This internal method checks whether the document was created from a
     836                 :            :     template, and if this is newer than the document. If this is the case,
     837                 :            :     the user is asked if the Templates (StyleSheets) should be updated.
     838                 :            :     If this is answered positively, the StyleSheets are updated.
     839                 :            : */
     840                 :            : 
     841                 :            : {
     842                 :            :     // Storage-medium?
     843                 :       1709 :     SfxMedium *pFile = GetMedium();
     844                 :            :     DBG_ASSERT( pFile, "cannot UpdateFromTemplate without medium" );
     845         [ +  - ]:       1709 :     if ( !pFile )
     846                 :            :         return;
     847                 :            : 
     848 [ +  - ][ +  - ]:       1709 :     if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
                 [ +  + ]
     849                 :            :         // update only for documents loaded from the local file system
     850                 :            :         return;
     851                 :            : 
     852                 :            :     // only for own storage formats
     853         [ +  - ]:        609 :     uno::Reference< embed::XStorage > xDocStor = pFile->GetStorage();
     854 [ +  - ][ +  - ]:        609 :     if ( !pFile->GetFilter() || !pFile->GetFilter()->IsOwnFormat() )
         [ +  - ][ +  + ]
                 [ +  + ]
     855                 :            :         return;
     856                 :            : 
     857 [ +  - ][ +  - ]:         94 :     SFX_ITEMSET_ARG( pFile->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
                 [ +  - ]
     858         [ +  - ]:         94 :     sal_Int16 bCanUpdateFromTemplate = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
     859                 :            : 
     860                 :            :     // created from template?
     861         [ +  - ]:         94 :     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     862 [ +  - ][ +  - ]:         94 :     ::rtl::OUString aTemplName( xDocProps->getTemplateName() );
     863 [ +  - ][ +  - ]:         94 :     ::rtl::OUString aTemplURL( xDocProps->getTemplateURL() );
     864         [ +  - ]:         94 :     String aFoundName;
     865                 :            : 
     866 [ +  + ][ -  + ]:         94 :     if ( !aTemplName.isEmpty() || (!aTemplURL.isEmpty() && !IsReadOnly()) )
         [ #  # ][ #  # ]
                 [ +  + ]
     867                 :            :     {
     868                 :            :         // try to locate template, first using filename this must be done
     869                 :            :         // because writer global document uses this "great" idea to manage
     870                 :            :         // the templates of all parts in the master document but it is NOT
     871                 :            :         // an error if the template filename points not to a valid file
     872         [ +  - ]:          9 :         SfxDocumentTemplates aTempl;
     873         [ +  - ]:          9 :         aTempl.Construct();
     874         [ -  + ]:          9 :         if ( !aTemplURL.isEmpty() )
     875                 :            :         {
     876         [ #  # ]:          0 :             String aURL;
     877 [ #  # ][ #  # ]:          0 :             if( ::utl::LocalFileHelper::ConvertSystemPathToURL( aTemplURL, GetMedium()->GetName(), aURL ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     878 [ #  # ][ #  # ]:          0 :                 aFoundName = aURL;
     879                 :            :         }
     880                 :            : 
     881 [ +  - ][ +  - ]:          9 :         if( !aFoundName.Len() && !aTemplName.isEmpty() )
                 [ +  - ]
     882                 :            :             // if the template filename did not lead to success,
     883                 :            :             // try to get a file name for the logical template name
     884 [ +  - ][ +  - ]:          9 :             aTempl.GetFull( String(), aTemplName, aFoundName );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     885                 :            :     }
     886                 :            : 
     887         [ -  + ]:         94 :     if ( aFoundName.Len() )
     888                 :            :     {
     889                 :            :         // check existence of template storage
     890         [ #  # ]:          0 :         aTemplURL = aFoundName;
     891                 :          0 :         sal_Bool bLoad = sal_False;
     892                 :            : 
     893                 :            :         // should the document checked against changes in the template ?
     894 [ #  # ][ #  # ]:          0 :         if ( IsQueryLoadTemplate() )
     895                 :            :         {
     896                 :            :             // load document info of template
     897                 :          0 :             sal_Bool bOK = sal_False;
     898                 :          0 :             util::DateTime aTemplDate;
     899                 :            :             try
     900                 :            :             {
     901                 :            :                 Reference < document::XStandaloneDocumentInfo > xDocInfo (
     902 [ #  # ][ #  # ]:          0 :                     ::comphelper::getProcessServiceFactory()->createInstance(
     903                 :            :                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     904                 :          0 :                             "com.sun.star.document.StandaloneDocumentInfo") ) ),
     905 [ #  # ][ #  # ]:          0 :                     UNO_QUERY_THROW );
                 [ #  # ]
     906                 :            :                 Reference < beans::XFastPropertySet > xSet( xDocInfo,
     907         [ #  # ]:          0 :                     UNO_QUERY_THROW );
     908 [ #  # ][ #  # ]:          0 :                 xDocInfo->loadFromURL( aTemplURL );
     909 [ #  # ][ #  # ]:          0 :                 Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED );
     910                 :          0 :                 ::com::sun::star::util::DateTime aTmp;
     911 [ #  # ][ #  # ]:          0 :                 if ( aAny >>= aTemplDate )
     912                 :            :                 {
     913                 :            :                     // get modify date from document info
     914                 :          0 :                     bOK = sal_True;
     915         [ #  # ]:          0 :                 }
     916                 :            :             }
     917         [ #  # ]:          0 :             catch (const Exception&)
     918                 :            :             {
     919                 :            :             }
     920                 :            : 
     921                 :            :             // if modify date was read successfully
     922         [ #  # ]:          0 :             if ( bOK )
     923                 :            :             {
     924                 :            :                 // compare modify data of template with the last check date of the document
     925 [ #  # ][ #  # ]:          0 :                 const util::DateTime aInfoDate( xDocProps->getTemplateDate() );
     926         [ #  # ]:          0 :                 if ( aTemplDate > aInfoDate )
     927                 :            :                 {
     928                 :            :                     // ask user
     929 [ #  # ][ #  # ]:          0 :                     if( bCanUpdateFromTemplate == document::UpdateDocMode::QUIET_UPDATE
     930                 :            :                     || bCanUpdateFromTemplate == document::UpdateDocMode::FULL_UPDATE )
     931                 :          0 :                         bLoad = sal_True;
     932         [ #  # ]:          0 :                     else if ( bCanUpdateFromTemplate == document::UpdateDocMode::ACCORDING_TO_CONFIG )
     933                 :            :                     {
     934 [ #  # ][ #  # ]:          0 :                         String sMessage( SfxResId(STR_QRYTEMPL_MESSAGE).toString() );
                 [ #  # ]
     935 [ #  # ][ #  # ]:          0 :                         sMessage.SearchAndReplace( rtl::OUString("$(ARG1)"), aTemplName );
         [ #  # ][ #  # ]
                 [ #  # ]
     936 [ #  # ][ #  # ]:          0 :                         sfx2::QueryTemplateBox aBox( GetDialogParent(), sMessage );
     937 [ #  # ][ #  # ]:          0 :                         if ( RET_YES == aBox.Execute() )
     938 [ #  # ][ #  # ]:          0 :                             bLoad = sal_True;
     939                 :            :                     }
     940                 :            : 
     941         [ #  # ]:          0 :                     if( !bLoad )
     942                 :            :                     {
     943                 :            :                         // user refuses, so don't ask again for this document
     944         [ #  # ]:          0 :                         SetQueryLoadTemplate(sal_False);
     945         [ #  # ]:          0 :                         SetModified( sal_True );
     946                 :            :                     }
     947                 :            :                 }
     948                 :            :             }
     949                 :            : 
     950         [ #  # ]:          0 :             if ( bLoad )
     951                 :            :             {
     952                 :            :                 // styles should be updated, create document in organizer mode to read in the styles
     953                 :            :                 //TODO: testen!
     954 [ #  # ][ #  # ]:          0 :                 SfxObjectShellLock xTemplDoc = CreateObjectByFactoryName( GetFactory().GetFactoryName(), SFX_CREATE_MODE_ORGANIZER );
         [ #  # ][ #  # ]
                 [ #  # ]
     955         [ #  # ]:          0 :                 xTemplDoc->DoInitNew(0);
     956                 :            : 
     957                 :            :                 // TODO/MBA: do we need a BaseURL? Then LoadFrom must be extended!
     958                 :            :                 //xTemplDoc->SetBaseURL( aFoundName );
     959                 :            : 
     960                 :            :                 // TODO/LATER: make sure that we don't use binary templates!
     961         [ #  # ]:          0 :                 SfxMedium aMedium( aFoundName, STREAM_STD_READ );
     962 [ #  # ][ #  # ]:          0 :                 if ( xTemplDoc->LoadFrom( aMedium ) )
     963                 :            :                 {
     964                 :            :                     // transfer styles from xTemplDoc to this document
     965                 :            :                     // TODO/MBA: make sure that no BaseURL is needed in *this* document
     966         [ #  # ]:          0 :                     LoadStyles(*xTemplDoc);
     967                 :            : 
     968                 :            :                     // remember date/time of check
     969 [ #  # ][ #  # ]:          0 :                     xDocProps->setTemplateDate(aTemplDate);
     970                 :            :                     // TODO/LATER: new functionality to store document info is required ( didn't work for SO7 XML format )
     971 [ #  # ][ #  # ]:          0 :                 }
     972                 :            :             }
     973                 :            :         }
     974 [ +  - ][ +  + ]:       1709 :     }
     975                 :            : }
     976                 :            : 
     977                 :      13604 : sal_Bool SfxObjectShell::IsHelpDocument() const
     978                 :            : {
     979                 :      13604 :     const SfxFilter* pFilter = GetMedium()->GetFilter();
     980 [ -  + ][ +  + ]:      13604 :     return ( pFilter && pFilter->GetFilterName().CompareToAscii("writer_web_HTML_help") == COMPARE_EQUAL );
     981                 :            : }
     982                 :            : 
     983                 :          5 : void SfxObjectShell::ResetFromTemplate( const String& rTemplateName, const String& rFileName )
     984                 :            : {
     985                 :            :     // only care about reseting this data for openoffice formats otherwise
     986         [ +  - ]:          5 :     if ( IsOwnStorageFormat_Impl( *GetMedium())  )
     987                 :            :     {
     988         [ +  - ]:          5 :         uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
     989 [ +  - ][ +  - ]:          5 :         xDocProps->setTemplateURL( ::rtl::OUString() );
     990 [ +  - ][ +  - ]:          5 :         xDocProps->setTemplateName( ::rtl::OUString() );
     991 [ +  - ][ +  - ]:          5 :         xDocProps->setTemplateDate( util::DateTime() );
     992 [ +  - ][ +  - ]:          5 :         xDocProps->resetUserData( ::rtl::OUString() );
     993                 :            : 
     994                 :            :         // TODO/REFACTOR:
     995                 :            :         // Title?
     996                 :            : 
     997 [ +  - ][ +  - ]:          5 :         if( ::utl::LocalFileHelper::IsLocalFile( rFileName ) )
                 [ +  - ]
     998                 :            :         {
     999         [ +  - ]:          5 :             String aFoundName;
    1000 [ +  - ][ +  - ]:          5 :             if( SFX_APP()->Get_Impl()->GetDocumentTemplates()->GetFull( String(), rTemplateName, aFoundName ) )
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
    1001                 :            :             {
    1002 [ #  # ][ #  # ]:          0 :                 INetURLObject aObj( rFileName );
    1003 [ #  # ][ #  # ]:          0 :                 xDocProps->setTemplateURL( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
                 [ #  # ]
    1004 [ #  # ][ #  # ]:          0 :                 xDocProps->setTemplateName( rTemplateName );
                 [ #  # ]
    1005                 :            : 
    1006         [ #  # ]:          0 :                 ::DateTime now( ::DateTime::SYSTEM );
    1007         [ #  # ]:          0 :                 xDocProps->setTemplateDate( util::DateTime(
    1008                 :          0 :                     now.Get100Sec(), now.GetSec(), now.GetMin(),
    1009                 :          0 :                     now.GetHour(), now.GetDay(), now.GetMonth(),
    1010         [ #  # ]:          0 :                     now.GetYear() ) );
    1011                 :            : 
    1012 [ #  # ][ #  # ]:          0 :                 SetQueryLoadTemplate( sal_True );
    1013         [ +  - ]:          5 :             }
    1014                 :          5 :         }
    1015                 :            :     }
    1016                 :          5 : }
    1017                 :            : 
    1018                 :         51 : sal_Bool SfxObjectShell::IsQueryLoadTemplate() const
    1019                 :            : {
    1020                 :         51 :     return pImp->bQueryLoadTemplate;
    1021                 :            : }
    1022                 :            : 
    1023                 :         55 : sal_Bool SfxObjectShell::IsUseUserData() const
    1024                 :            : {
    1025                 :         55 :     return pImp->bUseUserData;
    1026                 :            : }
    1027                 :            : 
    1028                 :        169 : void SfxObjectShell::SetQueryLoadTemplate( sal_Bool bNew )
    1029                 :            : {
    1030         [ +  + ]:        169 :     if ( pImp->bQueryLoadTemplate != bNew )
    1031                 :         13 :         SetModified( sal_True );
    1032                 :        169 :     pImp->bQueryLoadTemplate = bNew;
    1033                 :        169 : }
    1034                 :            : 
    1035                 :        169 : void SfxObjectShell::SetUseUserData( sal_Bool bNew )
    1036                 :            : {
    1037         [ +  + ]:        169 :     if ( pImp->bUseUserData != bNew )
    1038                 :         10 :         SetModified( sal_True );
    1039                 :        169 :     pImp->bUseUserData = bNew;
    1040                 :        169 : }
    1041                 :            : 
    1042                 :       1521 : sal_Bool SfxObjectShell::IsLoadReadonly() const
    1043                 :            : {
    1044                 :       1521 :     return pImp->bLoadReadonly;
    1045                 :            : }
    1046                 :            : 
    1047                 :         51 : sal_Bool SfxObjectShell::IsSaveVersionOnClose() const
    1048                 :            : {
    1049                 :         51 :     return pImp->bSaveVersionOnClose;
    1050                 :            : }
    1051                 :            : 
    1052                 :        164 : void SfxObjectShell::SetLoadReadonly( sal_Bool bNew )
    1053                 :            : {
    1054         [ +  + ]:        164 :     if ( pImp->bLoadReadonly != bNew )
    1055                 :          2 :         SetModified( sal_True );
    1056                 :        164 :     pImp->bLoadReadonly = bNew;
    1057                 :        164 : }
    1058                 :            : 
    1059                 :        169 : void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew )
    1060                 :            : {
    1061         [ +  + ]:        169 :     if ( pImp->bSaveVersionOnClose != bNew )
    1062                 :          5 :         SetModified( sal_True );
    1063                 :        169 :     pImp->bSaveVersionOnClose = bNew;
    1064                 :        169 : }
    1065                 :            : 
    1066                 :       1075 : sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const
    1067                 :            : {
    1068                 :       1075 :     return pImp->m_nModifyPasswordHash;
    1069                 :            : }
    1070                 :            : 
    1071                 :        438 : sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash )
    1072                 :            : {
    1073 [ +  - ][ -  + ]:        438 :     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
         [ #  # ][ +  - ]
    1074                 :          0 :       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
    1075                 :            :     {
    1076                 :            :         // the hash can be changed only in editable documents,
    1077                 :            :         // or during loading of document
    1078                 :        438 :         pImp->m_nModifyPasswordHash = nHash;
    1079                 :        438 :         return sal_True;
    1080                 :            :     }
    1081                 :            : 
    1082                 :        438 :     return sal_False;
    1083                 :            : }
    1084                 :            : 
    1085                 :       1091 : uno::Sequence< beans::PropertyValue > SfxObjectShell::GetModifyPasswordInfo() const
    1086                 :            : {
    1087                 :       1091 :     return pImp->m_aModifyPasswordInfo;
    1088                 :            : }
    1089                 :            : 
    1090                 :        338 : sal_Bool SfxObjectShell::SetModifyPasswordInfo( const uno::Sequence< beans::PropertyValue >& aInfo )
    1091                 :            : {
    1092 [ +  - ][ -  + ]:        338 :     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
         [ #  # ][ +  - ]
    1093                 :          0 :       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
    1094                 :            :     {
    1095                 :            :         // the hash can be changed only in editable documents,
    1096                 :            :         // or during loading of document
    1097                 :        338 :         pImp->m_aModifyPasswordInfo = aInfo;
    1098                 :        338 :         return sal_True;
    1099                 :            :     }
    1100                 :            : 
    1101                 :        338 :     return sal_False;
    1102                 :            : }
    1103                 :            : 
    1104                 :         18 : void SfxObjectShell::SetModifyPasswordEntered( sal_Bool bEntered )
    1105                 :            : {
    1106                 :         18 :     pImp->m_bModifyPasswordEntered = bEntered;
    1107                 :         18 : }
    1108                 :            : 
    1109                 :          3 : sal_Bool SfxObjectShell::IsModifyPasswordEntered()
    1110                 :            : {
    1111                 :          3 :     return pImp->m_bModifyPasswordEntered;
    1112                 :            : }
    1113                 :            : 
    1114                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10