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