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