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

Generated by: LCOV version 1.10