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