LCOV - code coverage report
Current view: top level - sw/source/uibase/misc - glshell.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 62 114 54.4 %
Date: 2015-06-13 12:38:46 Functions: 16 40 40.0 %
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         196 : SFX_IMPL_SUPERCLASS_INTERFACE(SwGlosDocShell, SwDocShell)
      60             : 
      61          59 : void SwGlosDocShell::InitInterface_Impl()
      62             : {
      63          59 : }
      64             : 
      65         118 : SFX_IMPL_SUPERCLASS_INTERFACE(SwWebGlosDocShell, SwWebDocShell)
      66             : 
      67          59 : void SwWebGlosDocShell::InitInterface_Impl()
      68             : {
      69          59 : }
      70             : 
      71         681 : 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 = static_cast< 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           2 : static bool lcl_Save( SwWrtShell& rSh, const OUString& rGroupName,
     105             :                 const OUString& rShortNm, const OUString& rLongNm )
     106             : {
     107           2 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     108           2 :     boost::scoped_ptr<SwTextBlocks> pBlock(::GetGlossaries()->GetGroupDoc( rGroupName ));
     109             : 
     110           4 :     SvxMacro aStart(aEmptyOUStr, aEmptyOUStr);
     111           4 :     SvxMacro aEnd(aEmptyOUStr, aEmptyOUStr);
     112             :     SwGlossaryHdl* pGlosHdl;
     113             : 
     114           2 :     pGlosHdl = rSh.GetView().GetGlosHdl();
     115           2 :     pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock.get() );
     116             : 
     117           2 :     sal_uInt16 nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
     118           2 :                                 rCfg.IsSaveRelFile(),
     119           6 :                                 pBlock->IsOnlyTextBlock( rShortNm ) );
     120             : 
     121           2 :     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           2 :     rSh.EnterStdMode();
     129           2 :     if( USHRT_MAX != nRet )
     130           2 :         rSh.ResetModified();
     131           4 :     return nRet != USHRT_MAX;
     132             : }
     133             : 
     134           1 : SwGlosDocShell::SwGlosDocShell(bool bNewShow)
     135             :     : SwDocShell( (bNewShow)
     136           1 :             ? SfxObjectCreateMode::STANDARD : SfxObjectCreateMode::INTERNAL )
     137             : {
     138           1 :     SetHelpId(SW_GLOSDOCSHELL);
     139           1 : }
     140             : 
     141           0 : SwGlosDocShell::~SwGlosDocShell(  )
     142             : {
     143           0 : }
     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           2 : 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           2 :     if ( GetWrtShell() )
     163           2 :         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( SfxObjectCreateMode::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           1 : SwDocShellRef SwGlossaries::EditGroupDoc( const OUString& rGroup, const OUString& rShortName, bool bShow )
     204             : {
     205           1 :     SwDocShellRef xDocSh;
     206             : 
     207           1 :     SwTextBlocks* pGroup = GetGroupDoc( rGroup );
     208           1 :     if (pGroup && pGroup->GetCount())
     209             :     {
     210             :         // query which view is registered. In WebWriter there is no normal view
     211           1 :         sal_uInt16 nViewId = 0 != SwView::Factory() ? 2 : 6;
     212           1 :         const OUString sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
     213             : 
     214           1 :         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           1 :             SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
     226           1 :             xDocSh = pDocSh;
     227           1 :             pDocSh->DoInitNew( 0 );
     228           1 :             pDocSh->SetLongName( sLongName );
     229           1 :             pDocSh->SetShortName( rShortName );
     230           1 :             pDocSh->SetGroupName( rGroup );
     231             :         }
     232             : 
     233             :         // set document title
     234           1 :         SfxViewFrame* pFrame = bShow ? SfxViewFrame::LoadDocument( *xDocSh, nViewId ) : SfxViewFrame::LoadHiddenDocument( *xDocSh, nViewId );
     235           2 :         const OUString aDocTitle(SW_RESSTR( STR_GLOSSARY ) + " " + sLongName);
     236             : 
     237             :         bool const bDoesUndo =
     238           1 :             xDocSh->GetDoc()->GetIDocumentUndoRedo().DoesUndo();
     239           1 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( false );
     240             : 
     241           1 :         xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
     242           1 :         if( !xDocSh->GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) )
     243             :         {
     244             :             // we create a default SfxPrinter.
     245             :             // ItemSet is deleted by Sfx!
     246           1 :             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           1 :                         0 );
     251           1 :             VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( pSet );
     252             : 
     253             :             // and append it to the document.
     254           1 :             xDocSh->GetDoc()->getIDocumentDeviceAccess().setPrinter( pPrinter, true, true );
     255             :         }
     256             : 
     257           1 :         xDocSh->SetTitle( aDocTitle );
     258             :         try
     259             :         {
     260             :             // set the UI-title
     261           1 :             uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
     262           1 :             xTitle->setTitle( aDocTitle );
     263             :         }
     264           0 :         catch (const uno::Exception&)
     265             :         {
     266             :         }
     267             : 
     268           1 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( bDoesUndo );
     269           1 :         xDocSh->GetDoc()->getIDocumentState().ResetModified();
     270           1 :         if ( bShow )
     271           1 :             pFrame->GetFrame().Appear();
     272             :     }
     273           1 :     delete pGroup;
     274           1 :     return xDocSh;
     275         177 : }
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11