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