LCOV - code coverage report
Current view: top level - sw/source/ui/misc - glshell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 114 54.4 %
Date: 2012-08-25 Functions: 17 42 40.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 94 362 26.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/frame/XTitle.hpp>
      31                 :            : 
      32                 :            : #include <svl/eitem.hxx>
      33                 :            : #include <svl/stritem.hxx>
      34                 :            : #include <sfx2/printer.hxx>
      35                 :            : #include <sfx2/request.hxx>
      36                 :            : #include <sfx2/sfxsids.hrc>
      37                 :            : #include <svl/srchitem.hxx>
      38                 :            : #include <svl/macitem.hxx>
      39                 :            : #include <gloshdl.hxx>
      40                 :            : 
      41                 :            : #include <editeng/acorrcfg.hxx>
      42                 :            : #include <sfx2/app.hxx>
      43                 :            : #include <sfx2/objface.hxx>
      44                 :            : #include <sfx2/viewfrm.hxx>
      45                 :            : #include <uitool.hxx>
      46                 :            : #include <wrtsh.hxx>
      47                 :            : #include <view.hxx>
      48                 :            : #include <glshell.hxx>
      49                 :            : #include <doc.hxx>
      50                 :            : #include <IDocumentUndoRedo.hxx>
      51                 :            : #include <glosdoc.hxx>
      52                 :            : #include <shellio.hxx>
      53                 :            : #include <initui.hxx>                   // for ::GetGlossaries()
      54                 :            : #include <cmdid.h>
      55                 :            : #include <swerror.h>
      56                 :            : #include <misc.hrc>
      57                 :            : 
      58                 :            : #define SwWebGlosDocShell
      59                 :            : #define SwGlosDocShell
      60                 :            : 
      61                 :            : #include <sfx2/msg.hxx>
      62                 :            : #include <swslots.hxx>
      63                 :            : 
      64                 :            : using namespace ::com::sun::star;
      65                 :            : 
      66 [ +  - ][ +  - ]:        146 : SFX_IMPL_INTERFACE( SwGlosDocShell, SwDocShell, SW_RES(0) )
         [ +  - ][ +  - ]
      67                 :            : {
      68                 :         73 : }
      69                 :            : 
      70 [ +  - ][ +  - ]:        146 : SFX_IMPL_INTERFACE( SwWebGlosDocShell, SwWebDocShell, SW_RES(0) )
         [ +  - ][ +  - ]
      71                 :            : {
      72                 :         73 : }
      73                 :            : 
      74 [ -  + ][ +  + ]:        668 : TYPEINIT1( SwGlosDocShell, SwDocShell );
      75 [ #  # ][ #  # ]:          0 : TYPEINIT1( SwWebGlosDocShell, SwWebDocShell );
      76                 :            : 
      77                 :          0 : void lcl_Execute( SwDocShell& rSh, SfxRequest& rReq )
      78                 :            : {
      79         [ #  # ]:          0 :     if ( rReq.GetSlot() == SID_SAVEDOC )
      80                 :            :     {
      81         [ #  # ]:          0 :         if( !rSh.HasName() )
      82                 :            :         {
      83         [ #  # ]:          0 :             rReq.SetReturnValue( SfxBoolItem( 0, rSh.Save() ) );
      84                 :            :         }
      85                 :            :         else
      86                 :            :         {
      87                 :            :             const SfxBoolItem* pRes = ( const SfxBoolItem* )
      88                 :            :                                         rSh.ExecuteSlot( rReq,
      89                 :          0 :                                         rSh.SfxObjectShell::GetInterface() );
      90         [ #  # ]:          0 :             if( pRes->GetValue() )
      91                 :          0 :                 rSh.GetDoc()->ResetModified();
      92                 :            :         }
      93                 :            :     }
      94                 :          0 : }
      95                 :            : 
      96                 :          0 : void lcl_GetState( SwDocShell& rSh, SfxItemSet& rSet )
      97                 :            : {
      98         [ #  # ]:          0 :     if( SFX_ITEM_AVAILABLE >= rSet.GetItemState( SID_SAVEDOC, sal_False ))
      99                 :            :     {
     100         [ #  # ]:          0 :         if( !rSh.GetDoc()->IsModified() )
     101                 :          0 :             rSet.DisableItem( SID_SAVEDOC );
     102                 :            :         else
     103 [ #  # ][ #  # ]:          0 :             rSet.Put( SfxStringItem( SID_SAVEDOC, SW_RESSTR(STR_SAVE_GLOSSARY)));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     104                 :            :     }
     105                 :          0 : }
     106                 :            : 
     107                 :          4 : sal_Bool lcl_Save( SwWrtShell& rSh, const String& rGroupName,
     108                 :            :                 const String& rShortNm, const String& rLongNm )
     109                 :            : {
     110         [ +  - ]:          4 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     111 [ +  - ][ +  - ]:          4 :     SwTextBlocks * pBlock = ::GetGlossaries()->GetGroupDoc( rGroupName );
     112                 :            : 
     113 [ +  - ][ +  - ]:          4 :     SvxMacro aStart(aEmptyStr, aEmptyStr);
                 [ +  - ]
     114 [ +  - ][ +  - ]:          4 :     SvxMacro aEnd(aEmptyStr, aEmptyStr);
                 [ +  - ]
     115                 :            :     SwGlossaryHdl* pGlosHdl;
     116                 :            : 
     117         [ +  - ]:          4 :     pGlosHdl = rSh.GetView().GetGlosHdl();
     118         [ +  - ]:          4 :     pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock );
     119                 :            : 
     120                 :            :     sal_uInt16 nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
     121                 :          4 :                                 rCfg.IsSaveRelFile(),
     122   [ +  -  +  - ]:          8 :                                 pBlock->IsOnlyTextBlock( rShortNm ) );
     123                 :            : 
     124 [ +  - ][ -  + ]:          4 :     if(aStart.HasMacro() || aEnd.HasMacro() )
                 [ -  + ]
     125                 :            :     {
     126         [ #  # ]:          0 :         SvxMacro* pStart = aStart.HasMacro() ? &aStart : 0;
     127         [ #  # ]:          0 :         SvxMacro* pEnd = aEnd.HasMacro() ? &aEnd : 0;
     128         [ #  # ]:          0 :         pGlosHdl->SetMacros( rShortNm, pStart, pEnd, pBlock );
     129                 :            :     }
     130                 :            : 
     131         [ +  - ]:          4 :     rSh.EnterStdMode();
     132         [ +  - ]:          4 :     if( USHRT_MAX != nRet )
     133         [ +  - ]:          4 :         rSh.ResetModified();
     134 [ +  - ][ +  - ]:          4 :     delete pBlock;
     135 [ +  - ][ +  - ]:          4 :     return nRet != USHRT_MAX;
     136                 :            : }
     137                 :            : 
     138                 :          2 : SwGlosDocShell::SwGlosDocShell(sal_Bool bNewShow)
     139                 :            :     : SwDocShell( (bNewShow)
     140                 :            :             ? SFX_CREATE_MODE_STANDARD : SFX_CREATE_MODE_INTERNAL )
     141 [ +  - ][ -  + ]:          2 :     , bShow ( bNewShow )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     142                 :            : {
     143 [ +  - ][ #  # ]:          2 :     SetHelpId(SW_GLOSDOCSHELL);
     144                 :          2 : }
     145                 :            : 
     146 [ #  # ][ #  # ]:          0 : SwGlosDocShell::~SwGlosDocShell(  )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     147                 :            : {
     148 [ #  # ][ #  # ]:          0 : }
                 [ #  # ]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     149                 :            : 
     150                 :          0 : void SwGlosDocShell::Execute( SfxRequest& rReq )
     151                 :            : {
     152                 :          0 :     ::lcl_Execute( *this, rReq );
     153                 :          0 : }
     154                 :            : 
     155                 :          0 : void SwGlosDocShell::GetState( SfxItemSet& rSet )
     156                 :            : {
     157                 :          0 :     ::lcl_GetState( *this, rSet );
     158                 :          0 : }
     159                 :            : 
     160                 :          4 : sal_Bool SwGlosDocShell::Save()
     161                 :            : {
     162                 :            :     // In case of an API object which holds this document, it is possible that the WrtShell is already
     163                 :            :     // dead. For instance, if the doc is modified via this API object, and then, upon office shutdown,
     164                 :            :     // the document's view is closed (by the SFX framework) _before_ the API object is release and
     165                 :            :     // tries to save the doc, again.
     166                 :            :     // 96380 - 2002-03-03 - fs@openoffice.org
     167         [ +  - ]:          4 :     if ( GetWrtShell() )
     168                 :          4 :         return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
     169                 :            :     else
     170                 :            :     {
     171                 :          0 :         SetModified( sal_False );
     172                 :          4 :         return sal_False;
     173                 :            :     }
     174                 :            : }
     175                 :            : 
     176                 :          0 : SwWebGlosDocShell::SwWebGlosDocShell()
     177 [ #  # ][ #  # ]:          0 :     : SwWebDocShell( SFX_CREATE_MODE_STANDARD )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     178                 :            : {
     179 [ #  # ][ #  # ]:          0 :     SetHelpId(SW_WEBGLOSDOCSHELL);
     180                 :          0 : }
     181                 :            : 
     182 [ #  # ][ #  # ]:          0 : SwWebGlosDocShell::~SwWebGlosDocShell(  )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     183                 :            : {
     184 [ #  # ][ #  # ]:          0 : }
                 [ #  # ]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     185                 :            : 
     186                 :          0 : void SwWebGlosDocShell::Execute( SfxRequest& rReq )
     187                 :            : {
     188                 :          0 :     ::lcl_Execute( *this, rReq );
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : void SwWebGlosDocShell::GetState( SfxItemSet& rSet )
     192                 :            : {
     193                 :          0 :     ::lcl_GetState( *this, rSet );
     194                 :          0 : }
     195                 :            : 
     196                 :          0 : sal_Bool SwWebGlosDocShell::Save()
     197                 :            : {
     198                 :            :     // same comment as in SwGlosDocShell::Save - see there
     199         [ #  # ]:          0 :     if ( GetWrtShell() )
     200                 :          0 :         return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
     201                 :            :     else
     202                 :            :     {
     203                 :          0 :         SetModified( sal_False );
     204                 :          0 :         return sal_False;
     205                 :            :     }
     206                 :            : }
     207                 :            : 
     208 [ +  - ][ +  - ]:          8 : SV_IMPL_REF ( SwDocShell )
         [ -  + ][ #  # ]
                 [ +  - ]
     209                 :            : 
     210                 :          2 : SwDocShellRef SwGlossaries::EditGroupDoc( const String& rGroup, const String& rShortName, sal_Bool bShow )
     211                 :            : {
     212                 :          2 :     SwDocShellRef xDocSh;
     213                 :            : 
     214         [ +  - ]:          2 :     SwTextBlocks* pGroup = GetGroupDoc( rGroup );
     215 [ +  - ][ +  - ]:          2 :     if( pGroup && pGroup->GetCount() )
         [ +  - ][ +  - ]
     216                 :            :     {
     217                 :            :         // query which view is registered. In WebWriter there is no normal view
     218         [ +  - ]:          2 :         sal_uInt16 nViewId = 0 != &SwView::Factory() ? 2 : 6;
     219 [ +  - ][ +  - ]:          2 :         String sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
                 [ +  - ]
     220                 :            : 
     221         [ -  + ]:          2 :         if( 6 == nViewId )
     222                 :            :         {
     223 [ #  # ][ #  # ]:          0 :             SwWebGlosDocShell* pDocSh = new SwWebGlosDocShell();
     224         [ #  # ]:          0 :             xDocSh = pDocSh;
     225         [ #  # ]:          0 :             pDocSh->DoInitNew( 0 );
     226         [ #  # ]:          0 :             pDocSh->SetLongName( sLongName );
     227         [ #  # ]:          0 :             pDocSh->SetShortName( rShortName);
     228         [ #  # ]:          0 :             pDocSh->SetGroupName( rGroup );
     229                 :            :         }
     230                 :            :         else
     231                 :            :         {
     232 [ +  - ][ +  - ]:          2 :             SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
     233         [ +  - ]:          2 :             xDocSh = pDocSh;
     234         [ +  - ]:          2 :             pDocSh->DoInitNew( 0 );
     235         [ +  - ]:          2 :             pDocSh->SetLongName( sLongName );
     236         [ +  - ]:          2 :             pDocSh->SetShortName( rShortName );
     237         [ +  - ]:          2 :             pDocSh->SetGroupName( rGroup );
     238                 :            :         }
     239                 :            : 
     240                 :            :         // set document title
     241 [ -  + ][ #  # ]:          2 :         SfxViewFrame* pFrame = bShow ? SfxViewFrame::LoadDocument( *xDocSh, nViewId ) : SfxViewFrame::LoadHiddenDocument( *xDocSh, nViewId );
                 [ +  - ]
     242         [ +  - ]:          2 :         String aDocTitle(SW_RES( STR_GLOSSARY ));
     243         [ +  - ]:          2 :         aDocTitle += ' ';
     244         [ +  - ]:          2 :         aDocTitle += sLongName;
     245                 :            : 
     246                 :            :         bool const bDoesUndo =
     247 [ +  - ][ +  - ]:          2 :             xDocSh->GetDoc()->GetIDocumentUndoRedo().DoesUndo();
     248 [ +  - ][ +  - ]:          2 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( false );
     249                 :            : 
     250         [ +  - ]:          2 :         xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
     251 [ +  - ][ +  - ]:          2 :         if( !xDocSh->GetDoc()->getPrinter( false ) )
     252                 :            :         {
     253                 :            :             // we create a default SfxPrinter.
     254                 :            :             // ItemSet is deleted by Sfx!
     255                 :          2 :             SfxItemSet *pSet = new SfxItemSet( xDocSh->GetDoc()->GetAttrPool(),
     256                 :            :                         FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
     257                 :            :                         SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     258                 :            :                         SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     259 [ +  - ][ +  - ]:          2 :                         0 );
     260 [ +  - ][ +  - ]:          2 :             SfxPrinter* pPrinter = new SfxPrinter( pSet );
     261                 :            : 
     262                 :            :             // and append it to the document.
     263         [ +  - ]:          2 :             xDocSh->GetDoc()->setPrinter( pPrinter, true, true );
     264                 :            :         }
     265                 :            : 
     266         [ +  - ]:          2 :         xDocSh->SetTitle( aDocTitle );
     267                 :            :         try
     268                 :            :         {
     269                 :            :             // set the UI-title
     270 [ +  - ][ +  - ]:          2 :             uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
     271 [ +  - ][ +  - ]:          2 :             xTitle->setTitle( aDocTitle );
         [ #  # ][ +  - ]
     272                 :            :         }
     273         [ #  # ]:          0 :         catch (const uno::Exception&)
     274                 :            :         {
     275                 :            :         }
     276                 :            : 
     277 [ +  - ][ +  - ]:          2 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( bDoesUndo );
     278         [ +  - ]:          2 :         xDocSh->GetDoc()->ResetModified();
     279         [ -  + ]:          2 :         if ( bShow )
     280 [ #  # ][ #  # ]:          0 :             pFrame->GetFrame().Appear();
     281                 :            : 
     282 [ +  - ][ +  - ]:          2 :         delete pGroup;
         [ +  - ][ +  - ]
     283                 :            :     }
     284                 :          2 :     return xDocSh;
     285                 :            : }
     286                 :            : 
     287                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10