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