LibreOffice Module sw (master) 1
glshell.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/frame/XTitle.hpp>
24#include <svl/eitem.hxx>
25#include <svl/stritem.hxx>
26#include <sfx2/printer.hxx>
27#include <sfx2/request.hxx>
28#include <svl/macitem.hxx>
29#include <gloshdl.hxx>
30
31#include <editeng/acorrcfg.hxx>
32#include <sfx2/objface.hxx>
33#include <sfx2/viewfrm.hxx>
34#include <wrtsh.hxx>
35#include <view.hxx>
36#include <glshell.hxx>
37#include <doc.hxx>
38#include <IDocumentUndoRedo.hxx>
40#include <IDocumentState.hxx>
41#include <glosdoc.hxx>
42#include <shellio.hxx>
43#include <initui.hxx>
44#include <cmdid.h>
45#include <strings.hrc>
46
47#define ShellClass_SwWebGlosDocShell
48#define ShellClass_SwGlosDocShell
49
50#include <sfx2/msg.hxx>
51#include <swslots.hxx>
52#include <memory>
53#include <utility>
54
55using namespace ::com::sun::star;
56
58
59void SwGlosDocShell::InitInterface_Impl()
60{
61}
62
64
65void SwWebGlosDocShell::InitInterface_Impl()
66{
67}
68
69
70static void lcl_Execute( SwDocShell& rSh, SfxRequest& rReq )
71{
72 if ( rReq.GetSlot() != SID_SAVEDOC )
73 return;
74
75 if( !rSh.HasName() )
76 {
77 rReq.SetReturnValue( SfxBoolItem( 0, rSh.Save() ) );
78 }
79 else
80 {
81 const SfxBoolItem* pRes = static_cast< const SfxBoolItem* >(
82 rSh.ExecuteSlot( rReq,
83 rSh.SfxObjectShell::GetInterface() ));
84 if( pRes->GetValue() )
86 }
87}
88
89static void lcl_GetState( SwDocShell& rSh, SfxItemSet& rSet )
90{
91 if( SfxItemState::DEFAULT >= rSet.GetItemState( SID_SAVEDOC, false ))
92 {
93 if( !rSh.GetDoc()->getIDocumentState().IsModified() )
94 rSet.DisableItem( SID_SAVEDOC );
95 else
96 rSet.Put( SfxStringItem( SID_SAVEDOC, SwResId(STR_SAVE_GLOSSARY)));
97 }
98}
99
100static bool lcl_Save( SwWrtShell& rSh, const OUString& rGroupName,
101 const OUString& rShortNm, const OUString& rLongNm )
102{
103 const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
104 std::unique_ptr<SwTextBlocks> pBlock(::GetGlossaries()->GetGroupDoc( rGroupName ));
105
106 SvxMacro aStart { OUString(), OUString() };
107 SvxMacro aEnd { OUString(), OUString() };
108 SwGlossaryHdl* pGlosHdl;
109
110 pGlosHdl = rSh.GetView().GetGlosHdl();
111 pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock.get() );
112
113 sal_uInt16 nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
114 rCfg.IsSaveRelFile(),
115 pBlock->IsOnlyTextBlock( rShortNm ) );
116
117 if(aStart.HasMacro() || aEnd.HasMacro() )
118 {
119 SvxMacro* pStart = aStart.HasMacro() ? &aStart : nullptr;
120 SvxMacro* pEnd = aEnd.HasMacro() ? &aEnd : nullptr;
121 pGlosHdl->SetMacros( rShortNm, pStart, pEnd, pBlock.get() );
122 }
123
124 rSh.EnterStdMode();
125 if( USHRT_MAX != nRet )
126 rSh.ResetModified();
127 return nRet != USHRT_MAX;
128}
129
131 : SwDocShell( bNewShow
133{
134}
135
137{
138}
139
141{
142 ::lcl_Execute( *this, rReq );
143}
144
146{
147 ::lcl_GetState( *this, rSet );
148}
149
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 if ( GetWrtShell() )
159 else
160 {
161 SetModified( false );
162 return false;
163 }
164}
165
167{
168}
169
171{
172}
173
175{
176 ::lcl_Execute( *this, rReq );
177}
178
180{
181 ::lcl_GetState( *this, rSet );
182}
183
185{
186 // same comment as in SwGlosDocShell::Save - see there
187 if ( GetWrtShell() )
189 else
190 {
191 SetModified( false );
192 return false;
193 }
194}
195
196SwDocShellRef SwGlossaries::EditGroupDoc( const OUString& rGroup, const OUString& rShortName, bool bShow )
197{
198 SwDocShellRef xDocSh;
199
200 std::unique_ptr<SwTextBlocks> pGroup = GetGroupDoc( rGroup );
201 if (pGroup && pGroup->GetCount())
202 {
203 // query which view is registered. In WebWriter there is no normal view
204 SfxInterfaceId nViewId = nullptr != SwView::Factory() ? SFX_INTERFACE_SFXDOCSH : SfxInterfaceId(6);
205 const OUString sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
206
207 if( SfxInterfaceId(6) == nViewId )
208 {
209 SwWebGlosDocShell* pDocSh = new SwWebGlosDocShell();
210 xDocSh = pDocSh;
211 pDocSh->DoInitNew();
212 pDocSh->SetLongName( sLongName );
213 pDocSh->SetShortName( rShortName);
214 pDocSh->SetGroupName( rGroup );
215 }
216 else
217 {
218 SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
219 xDocSh = pDocSh;
220 pDocSh->DoInitNew();
221 pDocSh->SetLongName( sLongName );
222 pDocSh->SetShortName( rShortName );
223 pDocSh->SetGroupName( rGroup );
224 }
225
226 // set document title
227 SfxViewFrame* pFrame = bShow ? SfxViewFrame::LoadDocument( *xDocSh, nViewId ) : SfxViewFrame::LoadHiddenDocument( *xDocSh, nViewId );
228 const OUString aDocTitle(SwResId( STR_GLOSSARY ) + " " + sLongName);
229
230 bool const bDoesUndo =
231 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoesUndo();
232 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( false );
233
234 xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
235 if( !xDocSh->GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) )
236 {
237 // we create a default SfxPrinter.
238 // ItemSet is deleted by Sfx!
239 auto pSet = std::make_unique<SfxItemSetFixed<
240 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
241 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
243 ( xDocSh->GetDoc()->GetAttrPool() );
244 VclPtr<SfxPrinter> pPrinter = VclPtr<SfxPrinter>::Create( std::move(pSet) );
245
246 // and append it to the document.
247 xDocSh->GetDoc()->getIDocumentDeviceAccess().setPrinter( pPrinter, true, true );
248 }
249
250 xDocSh->SetTitle( aDocTitle );
251 try
252 {
253 // set the UI-title
254 uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
255 xTitle->setTitle( aDocTitle );
256 }
257 catch (const uno::Exception&)
258 {
259 }
260
261 xDocSh->GetDoc()->GetIDocumentUndoRedo().DoUndo( bDoesUndo );
262 xDocSh->GetDoc()->getIDocumentState().ResetModified();
263 if ( bShow )
264 pFrame->GetFrame().Appear();
265 }
266 return xDocSh;
267}
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ResetModified()=0
virtual bool IsModified() const =0
Changes of document?
bool GetValue() const
void Appear()
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
bool HasName() const
sal_uInt16 GetSlot() const
void SetReturnValue(const SfxPoolItem &)
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
static SfxViewFrame * LoadDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
SfxFrame & GetFrame() const
static SfxViewFrame * LoadHiddenDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
static SvxAutoCorrCfg & Get()
bool IsSaveRelFile() const
bool HasMacro() const
virtual bool Save() override
global IO.
Definition: docsh.cxx:265
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:225
virtual void SetModified(bool=true) override
Definition: docsh2.cxx:1429
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:400
void ResetModified()
Definition: edws.cxx:75
sal_uInt16 SaveGlossaryDoc(SwTextBlocks &rGlossary, const OUString &rName, const OUString &rShortName, bool bSaveRelFile, bool bOnlyText)
Save complete content of doc as glossary.
Definition: edglss.cxx:75
virtual bool Save() override
global IO.
Definition: glshell.cxx:150
OUString m_aShortName
Definition: glshell.hxx:26
void SetLongName(const OUString &rLongName)
Definition: glshell.hxx:44
virtual ~SwGlosDocShell() override
Definition: glshell.cxx:136
void SetShortName(const OUString &rShortName)
Definition: glshell.hxx:46
OUString m_aLongName
Definition: glshell.hxx:25
void GetState(SfxItemSet &)
Definition: glshell.cxx:145
SwGlosDocShell(bool bNewShow)
Definition: glshell.cxx:130
void SetGroupName(const OUString &rGroupName)
Definition: glshell.hxx:48
OUString m_aGroupName
Definition: glshell.hxx:27
void Execute(SfxRequest &)
Definition: glshell.cxx:140
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
Definition: glosdoc.cxx:158
SwDocShellRef EditGroupDoc(const OUString &rGrpName, const OUString &rShortName, bool bShow=true)
Definition: glshell.cxx:196
void SetMacros(const OUString &rName, const SvxMacro *pStart, const SvxMacro *pEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:560
void GetMacros(const OUString &rShortName, SvxMacro &rStart, SvxMacro &rEnd, SwTextBlocks *pGlossary=nullptr)
Definition: gloshdl.cxx:581
SwGlossaryHdl * GetGlosHdl()
Definition: view.cxx:1674
void SetGroupName(const OUString &rGroupName)
Definition: glshell.hxx:77
OUString m_aGroupName
Definition: glshell.hxx:56
virtual ~SwWebGlosDocShell() override
Definition: glshell.cxx:170
void Execute(SfxRequest &)
Definition: glshell.cxx:174
void GetState(SfxItemSet &)
Definition: glshell.cxx:179
void SetLongName(const OUString &rLongName)
Definition: glshell.hxx:73
virtual bool Save() override
global IO.
Definition: glshell.cxx:184
OUString m_aShortName
Definition: glshell.hxx:55
OUString m_aLongName
Definition: glshell.hxx:54
void SetShortName(const OUString &rShortName)
Definition: glshell.hxx:75
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void EnterStdMode()
Definition: select.cxx:551
const SwView & GetView() const
Definition: wrtsh.hxx:443
static VclPtr< reference_type > Create(Arg &&... arg)
#define FN_PARAM_ADDPRINTER
Definition: cmdid.h:786
SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell)
static void lcl_Execute(SwDocShell &rSh, SfxRequest &rReq)
Definition: glshell.cxx:70
static void lcl_GetState(SwDocShell &rSh, SfxItemSet &rSet)
Definition: glshell.cxx:89
static bool lcl_Save(SwWrtShell &rSh, const OUString &rGroupName, const OUString &rShortNm, const OUString &rLongNm)
Definition: glshell.cxx:100
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
Definition: initui.cxx:162
SfxObjectCreateMode
static SfxItemSet & rSet
constexpr auto SFX_INTERFACE_SFXDOCSH
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165