xref: /AOO41X/main/sw/source/ui/app/appenv.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #if STLPORT_VERSION>=321
33*cdf0e10cSrcweir #include <cstdarg>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <hintids.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <sfx2/request.hxx>
40*cdf0e10cSrcweir #include <svx/svxids.hrc>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <svtools/svmedit.hxx>
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
45*cdf0e10cSrcweir #include <sfx2/app.hxx>
46*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
47*cdf0e10cSrcweir #include <sfx2/printer.hxx>
48*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
49*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
50*cdf0e10cSrcweir #include <editeng/boxitem.hxx>
51*cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
52*cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
53*cdf0e10cSrcweir #include <editeng/pbinitem.hxx>
54*cdf0e10cSrcweir #include <editeng/paperinf.hxx>
55*cdf0e10cSrcweir #include <editeng/brkitem.hxx>
56*cdf0e10cSrcweir #include <fmthdft.hxx>
57*cdf0e10cSrcweir #include <swwait.hxx>
58*cdf0e10cSrcweir #include <paratr.hxx>
59*cdf0e10cSrcweir #include <swmodule.hxx>
60*cdf0e10cSrcweir #include <wrtsh.hxx>
61*cdf0e10cSrcweir #include <view.hxx>
62*cdf0e10cSrcweir #include <docsh.hxx>
63*cdf0e10cSrcweir #include <frmatr.hxx>
64*cdf0e10cSrcweir #include <fldbas.hxx>
65*cdf0e10cSrcweir #include <swundo.hxx>
66*cdf0e10cSrcweir #include <IDocumentDeviceAccess.hxx>
67*cdf0e10cSrcweir #include <dbmgr.hxx>
68*cdf0e10cSrcweir #include <fmtcol.hxx>
69*cdf0e10cSrcweir #include <frmmgr.hxx>
70*cdf0e10cSrcweir #include <fldmgr.hxx>
71*cdf0e10cSrcweir #include <pagedesc.hxx>
72*cdf0e10cSrcweir #include <poolfmt.hxx>
73*cdf0e10cSrcweir #include <expfld.hxx>
74*cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
75*cdf0e10cSrcweir #include <crsskip.hxx>
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #include <cmdid.h>
78*cdf0e10cSrcweir #ifndef _GLOBALS_HRC
79*cdf0e10cSrcweir #include <globals.hrc>
80*cdf0e10cSrcweir #endif
81*cdf0e10cSrcweir #ifndef _APP_HRC
82*cdf0e10cSrcweir #include <app.hrc>
83*cdf0e10cSrcweir #endif
84*cdf0e10cSrcweir #ifndef _POOLFMT_HRC
85*cdf0e10cSrcweir #include <poolfmt.hrc>
86*cdf0e10cSrcweir #endif
87*cdf0e10cSrcweir #include "swabstdlg.hxx"
88*cdf0e10cSrcweir #include "envelp.hrc"
89*cdf0e10cSrcweir #include "envimg.hxx"
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir #define ENV_NEWDOC		RET_OK
92*cdf0e10cSrcweir #define ENV_INSERT		RET_USER
93*cdf0e10cSrcweir #define ENV_CANCEL		SHRT_MAX
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir // --------------------------------------------------------------------------
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir // Funktion wird fuer Etiketten und Briefumschlaege benutzt!
100*cdf0e10cSrcweir //	im applab.cxx und appenv.cxx
101*cdf0e10cSrcweir String InsertLabEnvText( SwWrtShell& rSh, SwFldMgr& rFldMgr, const String& rText )
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir 	String sRet;
104*cdf0e10cSrcweir 	String aText(rText);
105*cdf0e10cSrcweir 	aText.EraseAllChars( '\r' );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	sal_uInt16 nTokenPos = 0;
109*cdf0e10cSrcweir 	while( STRING_NOTFOUND != nTokenPos )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		String aLine = aText.GetToken( 0, '\n', nTokenPos );
112*cdf0e10cSrcweir 		while ( aLine.Len() )
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			String sTmpText;
115*cdf0e10cSrcweir 			sal_Bool bField = sal_False;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 			sal_uInt16 nPos = aLine.Search( '<' );
118*cdf0e10cSrcweir 			if ( nPos )
119*cdf0e10cSrcweir 			{
120*cdf0e10cSrcweir 				sTmpText = aLine.Copy( 0, nPos );
121*cdf0e10cSrcweir 				aLine.Erase( 0, nPos );
122*cdf0e10cSrcweir //				sTmpText = aLine.Cut( 0, nPos );
123*cdf0e10cSrcweir 			}
124*cdf0e10cSrcweir 			else
125*cdf0e10cSrcweir 			{
126*cdf0e10cSrcweir 				nPos = aLine.Search( '>' );
127*cdf0e10cSrcweir 				if ( nPos == STRING_NOTFOUND )
128*cdf0e10cSrcweir 				{
129*cdf0e10cSrcweir 					sTmpText = aLine;
130*cdf0e10cSrcweir 					aLine.Erase();
131*cdf0e10cSrcweir //					sTmpText = aLine.Cut();
132*cdf0e10cSrcweir 				}
133*cdf0e10cSrcweir 				else
134*cdf0e10cSrcweir 				{
135*cdf0e10cSrcweir 					sTmpText = aLine.Copy( 0, nPos + 1);
136*cdf0e10cSrcweir 					aLine.Erase( 0, nPos + 1);
137*cdf0e10cSrcweir //					sTmpText = aLine.Cut( 0, nPos + 1 );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 					// Datenbankfelder muesen mind. 3 Punkte beinhalten!
140*cdf0e10cSrcweir 					String sDBName( sTmpText.Copy( 1, sTmpText.Len() - 2));
141*cdf0e10cSrcweir 					sal_uInt16 nCnt = sDBName.GetTokenCount('.');
142*cdf0e10cSrcweir 					if (nCnt >= 3)
143*cdf0e10cSrcweir 					{
144*cdf0e10cSrcweir                         ::ReplacePoint(sDBName, sal_True);
145*cdf0e10cSrcweir                         SwInsertFld_Data aData(TYP_DBFLD, 0, sDBName, aEmptyStr, 0, &rSh );
146*cdf0e10cSrcweir                         rFldMgr.InsertFld( aData );
147*cdf0e10cSrcweir 						sRet = sDBName;
148*cdf0e10cSrcweir 						bField = sal_True;
149*cdf0e10cSrcweir 					}
150*cdf0e10cSrcweir 				}
151*cdf0e10cSrcweir 			}
152*cdf0e10cSrcweir 			if ( !bField )
153*cdf0e10cSrcweir 				rSh.Insert( sTmpText );
154*cdf0e10cSrcweir 		}
155*cdf0e10cSrcweir 		rSh.InsertLineBreak();
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 	rSh.DelLeft();	// Letzten Linebreak wieder l???schen
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	return sRet;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir // ----------------------------------------------------------------------------
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir void lcl_CopyCollAttr(SwWrtShell* pOldSh, SwWrtShell* pNewSh, sal_uInt16 nCollId)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir 	sal_uInt16 nCollCnt = pOldSh->GetTxtFmtCollCount();
168*cdf0e10cSrcweir 	SwTxtFmtColl* pColl;
169*cdf0e10cSrcweir 	for( sal_uInt16 nCnt = 0; nCnt < nCollCnt; ++nCnt )
170*cdf0e10cSrcweir 		if(nCollId == (pColl = &pOldSh->GetTxtFmtColl(nCnt))->GetPoolFmtId())
171*cdf0e10cSrcweir             pNewSh->GetTxtCollFromPool(nCollId)->SetFmtAttr(pColl->GetAttrSet());
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir // ----------------------------------------------------------------------------
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir void SwModule::InsertEnv( SfxRequest& rReq )
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir static sal_uInt16 nTitleNo = 0;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	SwDocShell		*pMyDocSh;
182*cdf0e10cSrcweir 	SfxViewFrame	*pFrame;
183*cdf0e10cSrcweir     SwView          *pNewView;
184*cdf0e10cSrcweir 	SwWrtShell		*pOldSh,
185*cdf0e10cSrcweir 					*pSh;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	//aktuelle Shell besorgen
188*cdf0e10cSrcweir 	pMyDocSh = (SwDocShell*) SfxObjectShell::Current();
189*cdf0e10cSrcweir 	pOldSh	 = pMyDocSh ? pMyDocSh->GetWrtShell() : 0;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	// Neues Dokument erzeugen (kein Show!)
192*cdf0e10cSrcweir 	SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
193*cdf0e10cSrcweir 	xDocSh->DoInitNew( 0 );
194*cdf0e10cSrcweir     pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
195*cdf0e10cSrcweir     pNewView = (SwView*) pFrame->GetViewShell();
196*cdf0e10cSrcweir     pNewView->AttrChangedNotify( &pNewView->GetWrtShell() );//Damit SelectShell gerufen wird.
197*cdf0e10cSrcweir     pSh = pNewView->GetWrtShellPtr();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	String aTmp( SW_RES(STR_ENV_TITLE) );
200*cdf0e10cSrcweir 	aTmp += String::CreateFromInt32( ++nTitleNo );
201*cdf0e10cSrcweir 	xDocSh->SetTitle( aTmp );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	// Ggf. alte Collections "Absender" und "Empfaenger" in neues
204*cdf0e10cSrcweir 	// Dokument kopieren
205*cdf0e10cSrcweir 	if ( pOldSh )
206*cdf0e10cSrcweir 	{
207*cdf0e10cSrcweir 		::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS);
208*cdf0e10cSrcweir 		::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS);
209*cdf0e10cSrcweir 	}
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	// SwEnvItem aus Config lesen
212*cdf0e10cSrcweir 	SwEnvCfgItem aEnvCfg;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	//Haben wir schon einen Briefumschlag.
215*cdf0e10cSrcweir 	sal_Bool bEnvChange = sal_False;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	SfxItemSet aSet(GetPool(), FN_ENVELOP, FN_ENVELOP, 0);
218*cdf0e10cSrcweir 	aSet.Put(aEnvCfg.GetItem());
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     SfxPrinter* pTempPrinter = pSh->getIDocumentDeviceAccess()->getPrinter( true );
221*cdf0e10cSrcweir 	if(pOldSh )
222*cdf0e10cSrcweir 	{
223*cdf0e10cSrcweir 		const SwPageDesc& rCurPageDesc = pOldSh->GetPageDesc(pOldSh->GetCurPageDesc());
224*cdf0e10cSrcweir 		String sJacket;
225*cdf0e10cSrcweir 		SwStyleNameMapper::FillUIName( RES_POOLPAGE_JAKET, sJacket );
226*cdf0e10cSrcweir 		bEnvChange = rCurPageDesc.GetName() == sJacket;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         IDocumentDeviceAccess* pIDDA_old = pOldSh->getIDocumentDeviceAccess();
229*cdf0e10cSrcweir         if( pIDDA_old->getPrinter( false ) )
230*cdf0e10cSrcweir 		{
231*cdf0e10cSrcweir             IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
232*cdf0e10cSrcweir             pIDDA->setJobsetup( *pIDDA_old->getJobsetup() );
233*cdf0e10cSrcweir 			//#69563# if it isn't the same printer then the pointer has been invalidated!
234*cdf0e10cSrcweir             pTempPrinter = pIDDA->getPrinter( true );
235*cdf0e10cSrcweir 		}
236*cdf0e10cSrcweir 		pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	}
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	Window *pParent = pOldSh ? pOldSh->GetWin() : 0;
241*cdf0e10cSrcweir 	SfxAbstractTabDialog * pDlg=NULL;
242*cdf0e10cSrcweir     short nMode = ENV_INSERT;
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     SFX_REQUEST_ARG( rReq, pItem, SwEnvItem, FN_ENVELOP, sal_False );
245*cdf0e10cSrcweir     if ( !pItem )
246*cdf0e10cSrcweir     {
247*cdf0e10cSrcweir         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
248*cdf0e10cSrcweir         DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir         pDlg = pFact->CreateSwEnvDlg( pParent, aSet, pOldSh, pTempPrinter, !bEnvChange, DLG_ENV );
251*cdf0e10cSrcweir         DBG_ASSERT(pDlg, "Dialogdiet fail!");
252*cdf0e10cSrcweir         nMode = pDlg->Execute();
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir     else
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         SFX_REQUEST_ARG( rReq, pBoolItem, SfxBoolItem, FN_PARAM_1, sal_False );
257*cdf0e10cSrcweir         if ( pBoolItem && pBoolItem->GetValue() )
258*cdf0e10cSrcweir             nMode = ENV_NEWDOC;
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	if (nMode == ENV_NEWDOC || nMode == ENV_INSERT)
262*cdf0e10cSrcweir 	{
263*cdf0e10cSrcweir 		SwWait aWait( (SwDocShell&)*xDocSh, sal_True );
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 		// Dialog auslesen, Item in Config speichern
266*cdf0e10cSrcweir         const SwEnvItem& rItem = pItem ? *pItem : (const SwEnvItem&) pDlg->GetOutputItemSet()->Get(FN_ENVELOP);
267*cdf0e10cSrcweir 		aEnvCfg.GetItem() = rItem;
268*cdf0e10cSrcweir 		aEnvCfg.Commit();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 		//Wenn wir Drucken uebernehmen wir den eingestellten Jobsetup aus
271*cdf0e10cSrcweir 		//dem Dialog. Die Informationen muessen hier vor dem evtl. zerstoeren
272*cdf0e10cSrcweir 		//der neuen Shell gesetzt werden, weil deren Drucker an den Dialog
273*cdf0e10cSrcweir 		//gereicht wurde.
274*cdf0e10cSrcweir 		if ( nMode != ENV_NEWDOC )
275*cdf0e10cSrcweir 		{
276*cdf0e10cSrcweir 			ASSERT(pOldSh, "Kein Dokument - war 'Einfuegen' nicht disabled???");
277*cdf0e10cSrcweir             SvxPaperBinItem aItem( RES_PAPER_BIN );
278*cdf0e10cSrcweir             aItem.SetValue((sal_uInt8)pSh->getIDocumentDeviceAccess()->getPrinter(true)->GetPaperBin());
279*cdf0e10cSrcweir             pOldSh->GetPageDescFromPool(RES_POOLPAGE_JAKET)->GetMaster().SetFmtAttr(aItem);
280*cdf0e10cSrcweir 		}
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 		SwWrtShell *pTmp = nMode == ENV_INSERT ? pOldSh : pSh;
283*cdf0e10cSrcweir 		const SwPageDesc* pFollow = 0;
284*cdf0e10cSrcweir 		SwTxtFmtColl *pSend = pTmp->GetTxtCollFromPool( RES_POOLCOLL_SENDADRESS ),
285*cdf0e10cSrcweir 					 *pAddr = pTmp->GetTxtCollFromPool( RES_POOLCOLL_JAKETADRESS);
286*cdf0e10cSrcweir 		const String &rSendMark = pSend->GetName();
287*cdf0e10cSrcweir 		const String &rAddrMark = pAddr->GetName();
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 		if (nMode == ENV_INSERT)
290*cdf0e10cSrcweir 		{
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 			SetView(&pOldSh->GetView()); // Pointer auf oberste View restaurieren
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 			//Neues Dok wieder loeschen
295*cdf0e10cSrcweir 			xDocSh->DoClose();
296*cdf0e10cSrcweir 			pSh = pOldSh;
297*cdf0e10cSrcweir             //#i4251# selected text or objects in the document should
298*cdf0e10cSrcweir             //not be deleted on inserting envelopes
299*cdf0e10cSrcweir             pSh->EnterStdMode();
300*cdf0e10cSrcweir 			// Los geht's (Einfuegen)
301*cdf0e10cSrcweir             pSh->StartUndo(UNDO_UI_INSERT_ENVELOPE, NULL);
302*cdf0e10cSrcweir 			pSh->StartAllAction();
303*cdf0e10cSrcweir 			pSh->SttEndDoc(sal_True);
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 			if (bEnvChange)
306*cdf0e10cSrcweir 			{
307*cdf0e10cSrcweir 				// Folgevorlage: Seite 2
308*cdf0e10cSrcweir 				pFollow = pSh->GetPageDesc(pSh->GetCurPageDesc()).GetFollow();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 				// Text der ersten Seite loeschen
311*cdf0e10cSrcweir 				if ( !pSh->SttNxtPg(sal_True) )
312*cdf0e10cSrcweir 					pSh->EndPg(sal_True);
313*cdf0e10cSrcweir 				pSh->DelRight();
314*cdf0e10cSrcweir 				// Rahmen der ersten Seite loeschen
315*cdf0e10cSrcweir 				if( pSh->GotoFly( rSendMark ) )
316*cdf0e10cSrcweir 				{
317*cdf0e10cSrcweir 					pSh->EnterSelFrmMode();
318*cdf0e10cSrcweir 					pSh->DelRight();
319*cdf0e10cSrcweir 				}
320*cdf0e10cSrcweir 				if ( pSh->GotoFly( rAddrMark ) )
321*cdf0e10cSrcweir 				{
322*cdf0e10cSrcweir 					pSh->EnterSelFrmMode();
323*cdf0e10cSrcweir 					pSh->DelRight();
324*cdf0e10cSrcweir 				}
325*cdf0e10cSrcweir 				pSh->SttEndDoc(sal_True);
326*cdf0e10cSrcweir 			}
327*cdf0e10cSrcweir 			else
328*cdf0e10cSrcweir 				// Folgevorlage: Seite 1
329*cdf0e10cSrcweir 				pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc());
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 			// Seitenumbruch einfuegen
332*cdf0e10cSrcweir 			if ( pSh->IsCrsrInTbl() )
333*cdf0e10cSrcweir 			{
334*cdf0e10cSrcweir 				pSh->SplitNode();
335*cdf0e10cSrcweir 				pSh->Right( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
336*cdf0e10cSrcweir                 SfxItemSet aBreakSet( pSh->GetAttrPool(), RES_BREAK, RES_BREAK, 0 );
337*cdf0e10cSrcweir                 aBreakSet.Put( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) );
338*cdf0e10cSrcweir                 pSh->SetTblAttr( aBreakSet );
339*cdf0e10cSrcweir 			}
340*cdf0e10cSrcweir 			else
341*cdf0e10cSrcweir 				pSh->InsertPageBreak(0, sal_False);
342*cdf0e10cSrcweir 			pSh->SttEndDoc(sal_True);
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 		else
345*cdf0e10cSrcweir 		{
346*cdf0e10cSrcweir 			pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc());
347*cdf0e10cSrcweir 			// Los geht's (Drucken)
348*cdf0e10cSrcweir 			pSh->StartAllAction();
349*cdf0e10cSrcweir 			pSh->DoUndo(sal_False);
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 			// Neue Collections "Absender" und "Empfaenger" wieder in neues
352*cdf0e10cSrcweir 			// Dokument kopieren
353*cdf0e10cSrcweir 			if ( pOldSh )
354*cdf0e10cSrcweir 			{
355*cdf0e10cSrcweir 				::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS);
356*cdf0e10cSrcweir 				::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS);
357*cdf0e10cSrcweir 			}
358*cdf0e10cSrcweir 		}
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 		SET_CURR_SHELL(pSh);
361*cdf0e10cSrcweir 		pSh->SetNewDoc();		// Performanceprobleme vermeiden
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 		// Flys dieser Seite merken
364*cdf0e10cSrcweir 		SvPtrarr aFlyArr(0, 5);
365*cdf0e10cSrcweir 		if( ENV_NEWDOC != nMode && !bEnvChange )
366*cdf0e10cSrcweir 			pSh->GetPageObjs( aFlyArr );
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 		// Page-Desc ermitteln
369*cdf0e10cSrcweir 		SwPageDesc* pDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_JAKET);
370*cdf0e10cSrcweir 		SwFrmFmt&   rFmt  = pDesc->GetMaster();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         Printer *pPrt = pSh->getIDocumentDeviceAccess()->getPrinter( true );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 		// Raender (setzen sich zusammen aus Shift-Offset und
375*cdf0e10cSrcweir 		// Ausrichtung)
376*cdf0e10cSrcweir 		Size aPaperSize = pPrt->PixelToLogic( pPrt->GetPaperSizePixel(),
377*cdf0e10cSrcweir 											  MAP_TWIP);
378*cdf0e10cSrcweir 		if ( !aPaperSize.Width() && !aPaperSize.Height() )
379*cdf0e10cSrcweir             		aPaperSize = SvxPaperInfo::GetPaperSize(PAPER_A4);
380*cdf0e10cSrcweir 		if ( aPaperSize.Width() > aPaperSize.Height() )
381*cdf0e10cSrcweir 			Swap( aPaperSize );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 		long lLeft  = rItem.lShiftRight,
384*cdf0e10cSrcweir 			 lUpper = rItem.lShiftDown;
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 		sal_uInt16 nPageW = (sal_uInt16) Max(rItem.lWidth, rItem.lHeight),
387*cdf0e10cSrcweir 			   nPageH = (sal_uInt16) Min(rItem.lWidth, rItem.lHeight);
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 		switch (rItem.eAlign)
390*cdf0e10cSrcweir 		{
391*cdf0e10cSrcweir 			case ENV_HOR_LEFT: break;
392*cdf0e10cSrcweir 			case ENV_HOR_CNTR: lLeft  += Max(0L, long(aPaperSize.Width() - nPageW)) / 2;
393*cdf0e10cSrcweir 							   break;
394*cdf0e10cSrcweir 			case ENV_HOR_RGHT: lLeft  += Max(0L, long(aPaperSize.Width() - nPageW));
395*cdf0e10cSrcweir 							   break;
396*cdf0e10cSrcweir 			case ENV_VER_LEFT: lUpper += Max(0L, long(aPaperSize.Width() - nPageH));
397*cdf0e10cSrcweir 							   break;
398*cdf0e10cSrcweir 			case ENV_VER_CNTR: lUpper += Max(0L, long(aPaperSize.Width() - nPageH)) / 2;
399*cdf0e10cSrcweir 							   break;
400*cdf0e10cSrcweir 			case ENV_VER_RGHT: break;
401*cdf0e10cSrcweir 		}
402*cdf0e10cSrcweir         SvxLRSpaceItem aLRMargin( RES_LR_SPACE );
403*cdf0e10cSrcweir         SvxULSpaceItem aULMargin( RES_UL_SPACE );
404*cdf0e10cSrcweir 		aLRMargin.SetLeft ((sal_uInt16) lLeft );
405*cdf0e10cSrcweir 		aULMargin.SetUpper((sal_uInt16) lUpper);
406*cdf0e10cSrcweir 		aLRMargin.SetRight(0);
407*cdf0e10cSrcweir 		aULMargin.SetLower(0);
408*cdf0e10cSrcweir         rFmt.SetFmtAttr(aLRMargin);
409*cdf0e10cSrcweir         rFmt.SetFmtAttr(aULMargin);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 		// Kopf-, Fusszeilen
412*cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
413*cdf0e10cSrcweir 		pDesc->ChgHeaderShare(sal_False);
414*cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
415*cdf0e10cSrcweir 		pDesc->ChgFooterShare(sal_False);
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 		// Seitennumerierung
418*cdf0e10cSrcweir 		pDesc->SetUseOn(nsUseOnPage::PD_ALL);
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 		// Einstellen der Seitengroesse
421*cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtFrmSize(ATT_FIX_SIZE,
422*cdf0e10cSrcweir 											nPageW + lLeft, nPageH + lUpper));
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 		// Einstellen der Numerierungsart der Seite
425*cdf0e10cSrcweir 		SvxNumberType aType;
426*cdf0e10cSrcweir 		aType.SetNumberingType(SVX_NUM_NUMBER_NONE);
427*cdf0e10cSrcweir 		pDesc->SetNumType(aType);
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 		// Folgevorlage
430*cdf0e10cSrcweir 		if (pFollow)
431*cdf0e10cSrcweir 			pDesc->SetFollow(pFollow);
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 		// Landscape
434*cdf0e10cSrcweir 		pDesc->SetLandscape( rItem.eAlign >= ENV_VER_LEFT &&
435*cdf0e10cSrcweir 							 rItem.eAlign <= ENV_VER_RGHT);
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 		// Page-Desc anwenden
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		sal_uInt16 nPos;
440*cdf0e10cSrcweir 		pSh->FindPageDescByName( pDesc->GetName(),
441*cdf0e10cSrcweir 									sal_False,
442*cdf0e10cSrcweir 									&nPos );
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 		pSh->ChgPageDesc( nPos, *pDesc);
446*cdf0e10cSrcweir 		pSh->ChgCurPageDesc(*pDesc);
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 		// Rahmen einfuegen
449*cdf0e10cSrcweir 		SwFlyFrmAttrMgr aMgr(sal_False, pSh, FRMMGR_TYPE_ENVELP);
450*cdf0e10cSrcweir 		SwFldMgr aFldMgr;
451*cdf0e10cSrcweir         aMgr.SetHeightSizeType(ATT_VAR_SIZE);
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir         //Defaults ueberschreiben!
454*cdf0e10cSrcweir         aMgr.GetAttrSet().Put( SvxBoxItem(RES_BOX) );
455*cdf0e10cSrcweir         aMgr.SetULSpace( 0L, 0L );
456*cdf0e10cSrcweir         aMgr.SetLRSpace( 0L, 0L );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 		// Absender
459*cdf0e10cSrcweir 		if (rItem.bSend)
460*cdf0e10cSrcweir 		{
461*cdf0e10cSrcweir 			pSh->SttEndDoc(sal_True);
462*cdf0e10cSrcweir             aMgr.InsertFlyFrm(FLY_AT_PAGE,
463*cdf0e10cSrcweir 				Point(rItem.lSendFromLeft + lLeft, rItem.lSendFromTop  + lUpper),
464*cdf0e10cSrcweir 				Size (rItem.lAddrFromLeft - rItem.lSendFromLeft, 0));
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 			pSh->EnterSelFrmMode();
467*cdf0e10cSrcweir 			pSh->SetFlyName( rSendMark );
468*cdf0e10cSrcweir 			pSh->UnSelectFrm();
469*cdf0e10cSrcweir 			pSh->LeaveSelFrmMode();
470*cdf0e10cSrcweir 			pSh->SetTxtFmtColl( pSend );
471*cdf0e10cSrcweir 			InsertLabEnvText( *pSh, aFldMgr, rItem.aSendText );
472*cdf0e10cSrcweir 			aMgr.UpdateAttrMgr();
473*cdf0e10cSrcweir 		}
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 		// Empfaenger
476*cdf0e10cSrcweir 		pSh->SttEndDoc(sal_True);
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir         aMgr.InsertFlyFrm(FLY_AT_PAGE,
479*cdf0e10cSrcweir 			Point(rItem.lAddrFromLeft + lLeft, rItem.lAddrFromTop  + lUpper),
480*cdf0e10cSrcweir 			Size (nPageW - rItem.lAddrFromLeft - 566, 0));
481*cdf0e10cSrcweir 		pSh->EnterSelFrmMode();
482*cdf0e10cSrcweir 		pSh->SetFlyName( rAddrMark );
483*cdf0e10cSrcweir 		pSh->UnSelectFrm();
484*cdf0e10cSrcweir 		pSh->LeaveSelFrmMode();
485*cdf0e10cSrcweir 		pSh->SetTxtFmtColl( pAddr );
486*cdf0e10cSrcweir 		InsertLabEnvText(*pSh, aFldMgr, rItem.aAddrText);
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 		// Flys auf die "alten" Seiten verschieben
489*cdf0e10cSrcweir 		if (aFlyArr.Count())
490*cdf0e10cSrcweir 			pSh->SetPageObjsNewPage(aFlyArr, 1);
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 		// Fertig
493*cdf0e10cSrcweir 		pSh->SttEndDoc(sal_True);
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 		pSh->EndAllAction();
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 		if (nMode == ENV_NEWDOC)
498*cdf0e10cSrcweir 			pSh->DoUndo(sal_True);
499*cdf0e10cSrcweir 		else
500*cdf0e10cSrcweir             pSh->EndUndo(UNDO_UI_INSERT_ENVELOPE);
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 		if (nMode == ENV_NEWDOC)
503*cdf0e10cSrcweir 		{
504*cdf0e10cSrcweir 			pFrame->GetFrame().Appear();
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 			if ( rItem.aAddrText.indexOf('<') >= 0 )
507*cdf0e10cSrcweir 			{
508*cdf0e10cSrcweir 				static sal_uInt16 __READONLY_DATA aInva[] =
509*cdf0e10cSrcweir 									{
510*cdf0e10cSrcweir 										SID_SBA_BRW_UPDATE,
511*cdf0e10cSrcweir 										SID_SBA_BRW_INSERT,
512*cdf0e10cSrcweir 										SID_SBA_BRW_MERGE,
513*cdf0e10cSrcweir 										0
514*cdf0e10cSrcweir 									};
515*cdf0e10cSrcweir 				pFrame->GetBindings().Invalidate( aInva );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 				// Datenbankbeamer oeffnen
518*cdf0e10cSrcweir                 ShowDBObj(*pNewView, pSh->GetDBData());
519*cdf0e10cSrcweir 			}
520*cdf0e10cSrcweir 		}
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir         if ( !pItem )
523*cdf0e10cSrcweir         {
524*cdf0e10cSrcweir             rReq.AppendItem( rItem );
525*cdf0e10cSrcweir             if ( nMode == ENV_NEWDOC )
526*cdf0e10cSrcweir                 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, sal_True ) );
527*cdf0e10cSrcweir         }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir         rReq.Done();
530*cdf0e10cSrcweir 	}
531*cdf0e10cSrcweir 	else	//Abbruch
532*cdf0e10cSrcweir 	{
533*cdf0e10cSrcweir         rReq.Ignore();
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 		xDocSh->DoClose();
536*cdf0e10cSrcweir 		--nTitleNo;
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 		// Pointer auf oberste View restaurieren
539*cdf0e10cSrcweir 		if (pOldSh)
540*cdf0e10cSrcweir 			SetView(&pOldSh->GetView());
541*cdf0e10cSrcweir 	}
542*cdf0e10cSrcweir 	delete pDlg;
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 
546