bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / misc / glshell.cxx
bloba4c0239db2a50eabb31ba7e7636c556d3021a219
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/frame/XTitle.hpp>
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>
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>
49 #define SwWebGlosDocShell
50 #define SwGlosDocShell
52 #include <sfx2/msg.hxx>
53 #include <swslots.hxx>
55 using namespace ::com::sun::star;
57 SFX_IMPL_INTERFACE( SwGlosDocShell, SwDocShell, SW_RES(0) )
61 SFX_IMPL_INTERFACE( SwWebGlosDocShell, SwWebDocShell, SW_RES(0) )
65 TYPEINIT1( SwGlosDocShell, SwDocShell );
66 TYPEINIT1( SwWebGlosDocShell, SwWebDocShell );
68 static void lcl_Execute( SwDocShell& rSh, SfxRequest& rReq )
70 if ( rReq.GetSlot() == SID_SAVEDOC )
72 if( !rSh.HasName() )
74 rReq.SetReturnValue( SfxBoolItem( 0, rSh.Save() ) );
76 else
78 const SfxBoolItem* pRes = ( const SfxBoolItem* )
79 rSh.ExecuteSlot( rReq,
80 rSh.SfxObjectShell::GetInterface() );
81 if( pRes->GetValue() )
82 rSh.GetDoc()->ResetModified();
87 static void lcl_GetState( SwDocShell& rSh, SfxItemSet& rSet )
89 if( SFX_ITEM_AVAILABLE >= rSet.GetItemState( SID_SAVEDOC, sal_False ))
91 if( !rSh.GetDoc()->IsModified() )
92 rSet.DisableItem( SID_SAVEDOC );
93 else
94 rSet.Put( SfxStringItem( SID_SAVEDOC, SW_RESSTR(STR_SAVE_GLOSSARY)));
98 static sal_Bool lcl_Save( SwWrtShell& rSh, const String& rGroupName,
99 const String& rShortNm, const String& rLongNm )
101 const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
102 SwTextBlocks * pBlock = ::GetGlossaries()->GetGroupDoc( rGroupName );
104 SvxMacro aStart(aEmptyStr, aEmptyStr);
105 SvxMacro aEnd(aEmptyStr, aEmptyStr);
106 SwGlossaryHdl* pGlosHdl;
108 pGlosHdl = rSh.GetView().GetGlosHdl();
109 pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock );
111 sal_uInt16 nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
112 rCfg.IsSaveRelFile(),
113 pBlock->IsOnlyTextBlock( rShortNm ) );
115 if(aStart.HasMacro() || aEnd.HasMacro() )
117 SvxMacro* pStart = aStart.HasMacro() ? &aStart : 0;
118 SvxMacro* pEnd = aEnd.HasMacro() ? &aEnd : 0;
119 pGlosHdl->SetMacros( rShortNm, pStart, pEnd, pBlock );
122 rSh.EnterStdMode();
123 if( USHRT_MAX != nRet )
124 rSh.ResetModified();
125 delete pBlock;
126 return nRet != USHRT_MAX;
129 SwGlosDocShell::SwGlosDocShell(sal_Bool bNewShow)
130 : SwDocShell( (bNewShow)
131 ? SFX_CREATE_MODE_STANDARD : SFX_CREATE_MODE_INTERNAL )
133 SetHelpId(SW_GLOSDOCSHELL);
136 SwGlosDocShell::~SwGlosDocShell( )
140 void SwGlosDocShell::Execute( SfxRequest& rReq )
142 ::lcl_Execute( *this, rReq );
145 void SwGlosDocShell::GetState( SfxItemSet& rSet )
147 ::lcl_GetState( *this, rSet );
150 sal_Bool SwGlosDocShell::Save()
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 if ( GetWrtShell() )
158 return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
159 else
161 SetModified( sal_False );
162 return sal_False;
166 SwWebGlosDocShell::SwWebGlosDocShell()
167 : SwWebDocShell( SFX_CREATE_MODE_STANDARD )
169 SetHelpId(SW_WEBGLOSDOCSHELL);
172 SwWebGlosDocShell::~SwWebGlosDocShell( )
176 void SwWebGlosDocShell::Execute( SfxRequest& rReq )
178 ::lcl_Execute( *this, rReq );
181 void SwWebGlosDocShell::GetState( SfxItemSet& rSet )
183 ::lcl_GetState( *this, rSet );
186 sal_Bool SwWebGlosDocShell::Save()
188 // same comment as in SwGlosDocShell::Save - see there
189 if ( GetWrtShell() )
190 return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
191 else
193 SetModified( sal_False );
194 return sal_False;
198 SV_IMPL_REF ( SwDocShell )
200 SwDocShellRef SwGlossaries::EditGroupDoc( const String& rGroup, const String& rShortName, sal_Bool bShow )
202 SwDocShellRef xDocSh;
204 SwTextBlocks* pGroup = GetGroupDoc( rGroup );
205 if( pGroup && pGroup->GetCount() )
207 // query which view is registered. In WebWriter there is no normal view
208 sal_uInt16 nViewId = 0 != &SwView::Factory() ? 2 : 6;
209 String sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
211 if( 6 == nViewId )
213 SwWebGlosDocShell* pDocSh = new SwWebGlosDocShell();
214 xDocSh = pDocSh;
215 pDocSh->DoInitNew( 0 );
216 pDocSh->SetLongName( sLongName );
217 pDocSh->SetShortName( rShortName);
218 pDocSh->SetGroupName( rGroup );
220 else
222 SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
223 xDocSh = pDocSh;
224 pDocSh->DoInitNew( 0 );
225 pDocSh->SetLongName( sLongName );
226 pDocSh->SetShortName( rShortName );
227 pDocSh->SetGroupName( rGroup );
230 // set document title
231 SfxViewFrame* pFrame = bShow ? SfxViewFrame::LoadDocument( *xDocSh, nViewId ) : SfxViewFrame::LoadHiddenDocument( *xDocSh, nViewId );
232 String aDocTitle(SW_RES( STR_GLOSSARY ));
233 aDocTitle += ' ';
234 aDocTitle += sLongName;
236 bool const bDoesUndo =
237 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoesUndo();
238 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( false );
240 xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
241 if( !xDocSh->GetDoc()->getPrinter( false ) )
243 // we create a default SfxPrinter.
244 // ItemSet is deleted by Sfx!
245 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 );
250 SfxPrinter* pPrinter = new SfxPrinter( pSet );
252 // and append it to the document.
253 xDocSh->GetDoc()->setPrinter( pPrinter, true, true );
256 xDocSh->SetTitle( aDocTitle );
259 // set the UI-title
260 uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
261 xTitle->setTitle( aDocTitle );
263 catch (const uno::Exception&)
267 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( bDoesUndo );
268 xDocSh->GetDoc()->ResetModified();
269 if ( bShow )
270 pFrame->GetFrame().Appear();
272 delete pGroup;
274 return xDocSh;
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */