LCOV - code coverage report
Current view: top level - sw/source/uibase/misc - glshell.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 64 114 56.1 %
Date: 2014-11-03 Functions: 17 40 42.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10