merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / misc / glshell.cxx
blob4156650fdcdb0ba2914f835dddfa2200f9a6fd51
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: glshell.cxx,v $
10 * $Revision: 1.17.236.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <com/sun/star/frame/XTitle.hpp>
36 #include <tools/list.hxx>
37 #include <svtools/eitem.hxx>
38 #include <svtools/stritem.hxx>
39 #include <sfx2/printer.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/sfxsids.hrc>
42 #include <svx/srchitem.hxx>
43 #include <svtools/macitem.hxx>
44 #include <gloshdl.hxx>
46 #include <svx/acorrcfg.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/objface.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <uitool.hxx>
51 #include <wrtsh.hxx>
52 #include <view.hxx>
53 #include <glshell.hxx>
54 #include <doc.hxx>
55 #include <glosdoc.hxx>
56 #include <shellio.hxx>
57 #include <initui.hxx> // fuer ::GetGlossaries()
58 #ifndef _CMDID_H
59 #include <cmdid.h>
60 #endif
61 #ifndef _SWERROR_H
62 #include <swerror.h>
63 #endif
64 #ifndef _MISC_HRC
65 #include <misc.hrc>
66 #endif
69 #define SwWebGlosDocShell
70 #define SwGlosDocShell
71 #include <sfx2/msg.hxx>
72 #include <swslots.hxx>
74 using namespace ::com::sun::star;
76 SFX_IMPL_INTERFACE( SwGlosDocShell, SwDocShell, SW_RES(0) )
80 SFX_IMPL_INTERFACE( SwWebGlosDocShell, SwWebDocShell, SW_RES(0) )
85 TYPEINIT1( SwGlosDocShell, SwDocShell );
86 TYPEINIT1( SwWebGlosDocShell, SwWebDocShell );
89 void lcl_Execute( SwDocShell& rSh, SfxRequest& rReq )
91 if ( rReq.GetSlot() == SID_SAVEDOC )
93 if( !rSh.HasName() )
95 rReq.SetReturnValue( SfxBoolItem( 0, rSh.Save() ) );
97 else
99 const SfxBoolItem* pRes = ( const SfxBoolItem* )
100 rSh.ExecuteSlot( rReq,
101 rSh.SfxObjectShell::GetInterface() );
102 if( pRes->GetValue() )
103 rSh.GetDoc()->ResetModified();
109 void lcl_GetState( SwDocShell& rSh, SfxItemSet& rSet )
111 if( SFX_ITEM_AVAILABLE >= rSet.GetItemState( SID_SAVEDOC, FALSE ))
113 if( !rSh.GetDoc()->IsModified() )
114 rSet.DisableItem( SID_SAVEDOC );
115 else
116 rSet.Put( SfxStringItem( SID_SAVEDOC, SW_RESSTR(STR_SAVE_GLOSSARY)));
121 BOOL lcl_Save( SwWrtShell& rSh, const String& rGroupName,
122 const String& rShortNm, const String& rLongNm )
124 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
125 SwTextBlocks * pBlock = ::GetGlossaries()->GetGroupDoc( rGroupName );
127 SvxMacro aStart(aEmptyStr, aEmptyStr);
128 SvxMacro aEnd(aEmptyStr, aEmptyStr);
129 SwGlossaryHdl* pGlosHdl;
131 pGlosHdl = rSh.GetView().GetGlosHdl();
132 pGlosHdl->GetMacros( rShortNm, aStart, aEnd, pBlock );
134 USHORT nRet = rSh.SaveGlossaryDoc( *pBlock, rLongNm, rShortNm,
135 pCfg->IsSaveRelFile(),
136 pBlock->IsOnlyTextBlock( rShortNm ) );
138 if(aStart.GetMacName().Len() || aEnd.GetMacName().Len() )
140 SvxMacro* pStart = aStart.GetMacName().Len() ? &aStart : 0;
141 SvxMacro* pEnd = aEnd.GetMacName().Len() ? &aEnd : 0;
142 pGlosHdl->SetMacros( rShortNm, pStart, pEnd, pBlock );
145 rSh.EnterStdMode();
146 if( USHRT_MAX != nRet )
147 rSh.ResetModified();
148 delete pBlock;
149 return nRet != USHRT_MAX;
152 /*--------------------------------------------------------------------
153 Beschreibung:
154 --------------------------------------------------------------------*/
157 SwGlosDocShell::SwGlosDocShell( sal_Bool bNewShow)
159 SwDocShell( bShow ? SFX_CREATE_MODE_STANDARD : SFX_CREATE_MODE_INTERNAL )
160 ,bShow ( bNewShow )
162 SetHelpId(SW_GLOSDOCSHELL);
165 /*--------------------------------------------------------------------
166 Beschreibung:
167 --------------------------------------------------------------------*/
170 SwGlosDocShell::~SwGlosDocShell( )
174 /*--------------------------------------------------------------------
175 Beschreibung:
176 --------------------------------------------------------------------*/
179 void SwGlosDocShell::Execute( SfxRequest& rReq )
181 ::lcl_Execute( *this, rReq );
184 /*--------------------------------------------------------------------
185 Beschreibung:
186 --------------------------------------------------------------------*/
189 void SwGlosDocShell::GetState( SfxItemSet& rSet )
191 ::lcl_GetState( *this, rSet );
194 /*--------------------------------------------------------------------
195 Beschreibung:
196 --------------------------------------------------------------------*/
199 BOOL SwGlosDocShell::Save()
201 // In case of an API object which holds this document, it is possible that the WrtShell is already
202 // dead. For instance, if the doc is modified via this API object, and then, upon office shutdown,
203 // the document's view is closed (by the SFX framework) _before_ the API object is release and
204 // tries to save the doc, again.
205 // 96380 - 2002-03-03 - fs@openoffice.org
206 if ( GetWrtShell() )
207 return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
208 else
210 SetModified( FALSE );
211 return FALSE;
216 /*\f*/
218 /*--------------------------------------------------------------------
219 Beschreibung:
220 --------------------------------------------------------------------*/
223 SwWebGlosDocShell::SwWebGlosDocShell()
224 : SwWebDocShell( SFX_CREATE_MODE_STANDARD )
226 SetHelpId(SW_WEBGLOSDOCSHELL);
229 /*--------------------------------------------------------------------
230 Beschreibung:
231 --------------------------------------------------------------------*/
234 SwWebGlosDocShell::~SwWebGlosDocShell( )
238 /*--------------------------------------------------------------------
239 Beschreibung:
240 --------------------------------------------------------------------*/
243 void SwWebGlosDocShell::Execute( SfxRequest& rReq )
245 ::lcl_Execute( *this, rReq );
247 /*--------------------------------------------------------------------
248 Beschreibung:
249 --------------------------------------------------------------------*/
252 void SwWebGlosDocShell::GetState( SfxItemSet& rSet )
254 ::lcl_GetState( *this, rSet );
257 /*--------------------------------------------------------------------
258 Beschreibung:
259 --------------------------------------------------------------------*/
262 BOOL SwWebGlosDocShell::Save()
264 // same comment as in SwGlosDocShell::Save - see there
265 if ( GetWrtShell() )
266 return ::lcl_Save( *GetWrtShell(), aGroupName, aShortName, aLongName );
267 else
269 SetModified( FALSE );
270 return FALSE;
274 /*--------------------------------------------------------------------
275 Beschreibung:
276 --------------------------------------------------------------------*/
278 SV_IMPL_REF ( SwDocShell )
280 SwDocShellRef SwGlossaries::EditGroupDoc( const String& rGroup, const String& rShortName, BOOL bShow )
282 SwDocShellRef xDocSh;
284 SwTextBlocks* pGroup = GetGroupDoc( rGroup );
285 if( pGroup && pGroup->GetCount() )
287 // erfrage welche View registriert ist. Im WebWriter gibts es keine
288 // normale View
289 USHORT nViewId = 0 != &SwView::Factory() ? 2 : 6;
290 String sLongName = pGroup->GetLongName(pGroup->GetIndex( rShortName ));
292 if( 6 == nViewId )
294 SwWebGlosDocShell* pDocSh = new SwWebGlosDocShell();
295 xDocSh = pDocSh;
296 pDocSh->DoInitNew( 0 );
297 pDocSh->SetLongName( sLongName );
298 pDocSh->SetShortName( rShortName);
299 pDocSh->SetGroupName( rGroup );
301 else
303 SwGlosDocShell* pDocSh = new SwGlosDocShell(bShow);
304 xDocSh = pDocSh;
305 pDocSh->DoInitNew( 0 );
306 pDocSh->SetLongName( sLongName );
307 pDocSh->SetShortName( rShortName );
308 pDocSh->SetGroupName( rGroup );
311 // Dokumenttitel setzen
312 SfxViewFrame* pFrame = SfxViewFrame::CreateViewFrame( *xDocSh, nViewId, !bShow );
313 String aDocTitle(SW_RES( STR_GLOSSARY ));
314 aDocTitle += ' ';
315 aDocTitle += sLongName;
317 BOOL bDoesUndo = xDocSh->GetDoc()->DoesUndo();
318 xDocSh->GetDoc()->DoUndo( FALSE );
320 xDocSh->GetWrtShell()->InsertGlossary( *pGroup, rShortName );
321 if( !xDocSh->GetDoc()->getPrinter( false ) )
323 // wir erzeugen einen default SfxPrinter.
324 // Das ItemSet wird vom Sfx geloescht!
325 SfxItemSet *pSet = new SfxItemSet( xDocSh->GetDoc()->GetAttrPool(),
326 FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
327 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
328 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
329 0 );
330 SfxPrinter* pPrinter = new SfxPrinter( pSet );
332 // und haengen ihn ans Dokument.
333 xDocSh->GetDoc()->setPrinter( pPrinter, true, true );
336 xDocSh->SetTitle( aDocTitle );
339 // set the UI-title
340 uno::Reference< frame::XTitle > xTitle( xDocSh->GetModel(), uno::UNO_QUERY_THROW );
341 xTitle->setTitle( aDocTitle );
343 catch( uno::Exception& )
346 xDocSh->GetDoc()->DoUndo( bDoesUndo );
347 xDocSh->GetDoc()->ResetModified();
348 if ( bShow )
349 pFrame->GetFrame()->Appear();
351 delete pGroup;
353 return xDocSh;