LCOV - code coverage report
Current view: top level - sw/source/core/uibase/misc - glshell.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 111 0.0 %
Date: 2014-04-14 Functions: 0 38 0.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 <glosdoc.hxx>
      42             : #include <shellio.hxx>
      43             : #include <initui.hxx>
      44             : #include <cmdid.h>
      45             : #include <swerror.h>
      46             : #include <misc.hrc>
      47             : 
      48             : #define SwWebGlosDocShell
      49             : #define SwGlosDocShell
      50             : 
      51             : #include <sfx2/msg.hxx>
      52             : #include <swslots.hxx>
      53             : 
      54             : using namespace ::com::sun::star;
      55             : 
      56           0 : SFX_IMPL_INTERFACE( SwGlosDocShell, SwDocShell, SW_RES(0) )
      57             : {
      58           0 : }
      59             : 
      60           0 : SFX_IMPL_INTERFACE( SwWebGlosDocShell, SwWebDocShell, SW_RES(0) )
      61             : {
      62           0 : }
      63             : 
      64           0 : TYPEINIT1( SwGlosDocShell, SwDocShell );
      65           0 : TYPEINIT1( SwWebGlosDocShell, SwWebDocShell );
      66             : 
      67           0 : static void lcl_Execute( SwDocShell& rSh, SfxRequest& rReq )
      68             : {
      69           0 :     if ( rReq.GetSlot() == SID_SAVEDOC )
      70             :     {
      71           0 :         if( !rSh.HasName() )
      72             :         {
      73           0 :             rReq.SetReturnValue( SfxBoolItem( 0, rSh.Save() ) );
      74             :         }
      75             :         else
      76             :         {
      77             :             const SfxBoolItem* pRes = ( const SfxBoolItem* )
      78             :                                         rSh.ExecuteSlot( rReq,
      79           0 :                                         rSh.SfxObjectShell::GetInterface() );
      80           0 :             if( pRes->GetValue() )
      81           0 :                 rSh.GetDoc()->ResetModified();
      82             :         }
      83             :     }
      84           0 : }
      85             : 
      86           0 : static void lcl_GetState( SwDocShell& rSh, SfxItemSet& rSet )
      87             : {
      88           0 :     if( SFX_ITEM_AVAILABLE >= rSet.GetItemState( SID_SAVEDOC, false ))
      89             :     {
      90           0 :         if( !rSh.GetDoc()->IsModified() )
      91           0 :             rSet.DisableItem( SID_SAVEDOC );
      92             :         else
      93           0 :             rSet.Put( SfxStringItem( SID_SAVEDOC, SW_RESSTR(STR_SAVE_GLOSSARY)));
      94             :     }
      95           0 : }
      96             : 
      97           0 : static sal_Bool lcl_Save( SwWrtShell& rSh, const OUString& rGroupName,
      98             :                 const OUString& rShortNm, const OUString& rLongNm )
      99             : {
     100           0 :     const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
     101           0 :     SwTextBlocks * pBlock = ::GetGlossaries()->GetGroupDoc( rGroupName );
     102             : 
     103           0 :     SvxMacro aStart(aEmptyOUStr, aEmptyOUStr);
     104           0 :     SvxMacro aEnd(aEmptyOUStr, aEmptyOUStr);
     105             :     SwGlossaryHdl* pGlosHdl;
     106             : 
     107           0 :     pGlosHdl = rSh.GetView().GetGlosHdl();
     108           0 :     pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock );
     109             : 
     110             :     sal_uInt16 nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
     111           0 :                                 rCfg.IsSaveRelFile(),
     112           0 :                                 pBlock->IsOnlyTextBlock( rShortNm ) );
     113             : 
     114           0 :     if(aStart.HasMacro() || aEnd.HasMacro() )
     115             :     {
     116           0 :         SvxMacro* pStart = aStart.HasMacro() ? &aStart : 0;
     117           0 :         SvxMacro* pEnd = aEnd.HasMacro() ? &aEnd : 0;
     118           0 :         pGlosHdl->SetMacros( rShortNm, pStart, pEnd, pBlock );
     119             :     }
     120             : 
     121           0 :     rSh.EnterStdMode();
     122           0 :     if( USHRT_MAX != nRet )
     123           0 :         rSh.ResetModified();
     124           0 :     delete pBlock;
     125           0 :     return nRet != USHRT_MAX;
     126             : }
     127             : 
     128           0 : SwGlosDocShell::SwGlosDocShell(sal_Bool bNewShow)
     129             :     : SwDocShell( (bNewShow)
     130           0 :             ? SFX_CREATE_MODE_STANDARD : SFX_CREATE_MODE_INTERNAL )
     131             : {
     132           0 :     SetHelpId(SW_GLOSDOCSHELL);
     133           0 : }
     134             : 
     135           0 : SwGlosDocShell::~SwGlosDocShell(  )
     136             : {
     137           0 : }
     138             : 
     139           0 : void SwGlosDocShell::Execute( SfxRequest& rReq )
     140             : {
     141           0 :     ::lcl_Execute( *this, rReq );
     142           0 : }
     143             : 
     144           0 : void SwGlosDocShell::GetState( SfxItemSet& rSet )
     145             : {
     146           0 :     ::lcl_GetState( *this, rSet );
     147           0 : }
     148             : 
     149           0 : bool SwGlosDocShell::Save()
     150             : {
     151             :     // In case of an API object which holds this document, it is possible that the WrtShell is already
     152             :     // dead. For instance, if the doc is modified via this API object, and then, upon office shutdown,
     153             :     // the document's view is closed (by the SFX framework) _before_ the API object is release and
     154             :     // tries to save the doc, again.
     155             :     // 96380 - 2002-03-03 - fs@openoffice.org
     156           0 :     if ( GetWrtShell() )
     157           0 :         return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
     158             :     else
     159             :     {
     160           0 :         SetModified( false );
     161           0 :         return false;
     162             :     }
     163             : }
     164             : 
     165           0 : SwWebGlosDocShell::SwWebGlosDocShell()
     166           0 :     : SwWebDocShell( SFX_CREATE_MODE_STANDARD )
     167             : {
     168           0 :     SetHelpId(SW_WEBGLOSDOCSHELL);
     169           0 : }
     170             : 
     171           0 : SwWebGlosDocShell::~SwWebGlosDocShell(  )
     172             : {
     173           0 : }
     174             : 
     175           0 : void SwWebGlosDocShell::Execute( SfxRequest& rReq )
     176             : {
     177           0 :     ::lcl_Execute( *this, rReq );
     178           0 : }
     179             : 
     180           0 : void SwWebGlosDocShell::GetState( SfxItemSet& rSet )
     181             : {
     182           0 :     ::lcl_GetState( *this, rSet );
     183           0 : }
     184             : 
     185           0 : bool SwWebGlosDocShell::Save()
     186             : {
     187             :     // same comment as in SwGlosDocShell::Save - see there
     188           0 :     if ( GetWrtShell() )
     189           0 :         return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
     190             :     else
     191             :     {
     192           0 :         SetModified( false );
     193           0 :         return false;
     194             :     }
     195             : }
     196             : 
     197           0 : SwDocShellRef SwGlossaries::EditGroupDoc( const OUString& rGroup, const OUString& rShortName, sal_Bool bShow )
     198             : {
     199           0 :     SwDocShellRef xDocSh;
     200             : 
     201           0 :     SwTextBlocks* pGroup = GetGroupDoc( rGroup );
     202           0 :     if( pGroup && pGroup->GetCount() )
     203             :     {
     204             :         // query which view is registered. In WebWriter there is no normal view
     205           0 :         sal_uInt16 nViewId = 0 != &SwView::Factory() ? 2 : 6;
     206           0 :         const OUString sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
     207             : 
     208           0 :         if( 6 == nViewId )
     209             :         {
     210           0 :             SwWebGlosDocShell* pDocSh = new SwWebGlosDocShell();
     211           0 :             xDocSh = pDocSh;
     212           0 :             pDocSh->DoInitNew( 0 );
     213           0 :             pDocSh->SetLongName( sLongName );
     214           0 :             pDocSh->SetShortName( rShortName);
     215           0 :             pDocSh->SetGroupName( rGroup );
     216             :         }
     217             :         else
     218             :         {
     219           0 :             SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
     220           0 :             xDocSh = pDocSh;
     221           0 :             pDocSh->DoInitNew( 0 );
     222           0 :             pDocSh->SetLongName( sLongName );
     223           0 :             pDocSh->SetShortName( rShortName );
     224           0 :             pDocSh->SetGroupName( rGroup );
     225             :         }
     226             : 
     227             :         // set document title
     228           0 :         SfxViewFrame* pFrame = bShow ? SfxViewFrame::LoadDocument( *xDocSh, nViewId ) : SfxViewFrame::LoadHiddenDocument( *xDocSh, nViewId );
     229           0 :         const OUString aDocTitle(SW_RESSTR( STR_GLOSSARY ) + " " + sLongName);
     230             : 
     231             :         bool const bDoesUndo =
     232           0 :             xDocSh->GetDoc()->GetIDocumentUndoRedo().DoesUndo();
     233           0 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( false );
     234             : 
     235           0 :         xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
     236           0 :         if( !xDocSh->GetDoc()->getPrinter( false ) )
     237             :         {
     238             :             // we create a default SfxPrinter.
     239             :             // ItemSet is deleted by Sfx!
     240           0 :             SfxItemSet *pSet = new SfxItemSet( xDocSh->GetDoc()->GetAttrPool(),
     241             :                         FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
     242             :                         SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     243             :                         SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     244           0 :                         0 );
     245           0 :             SfxPrinter* pPrinter = new SfxPrinter( pSet );
     246             : 
     247             :             // and append it to the document.
     248           0 :             xDocSh->GetDoc()->setPrinter( pPrinter, true, true );
     249             :         }
     250             : 
     251           0 :         xDocSh->SetTitle( aDocTitle );
     252             :         try
     253             :         {
     254             :             // set the UI-title
     255           0 :             uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
     256           0 :             xTitle->setTitle( aDocTitle );
     257             :         }
     258           0 :         catch (const uno::Exception&)
     259             :         {
     260             :         }
     261             : 
     262           0 :         xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( bDoesUndo );
     263           0 :         xDocSh->GetDoc()->ResetModified();
     264           0 :         if ( bShow )
     265           0 :             pFrame->GetFrame().Appear();
     266             : 
     267           0 :         delete pGroup;
     268             :     }
     269           0 :     return xDocSh;
     270             : }
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10