xref: /trunk/main/sw/source/ui/app/appenv.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sw.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <cstdarg>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <hintids.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <sfx2/request.hxx>
30cdf0e10cSrcweir #include <svx/svxids.hrc>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <svtools/svmedit.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
35cdf0e10cSrcweir #include <sfx2/app.hxx>
36cdf0e10cSrcweir #include <sfx2/docfac.hxx>
37cdf0e10cSrcweir #include <sfx2/printer.hxx>
38cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
40cdf0e10cSrcweir #include <editeng/boxitem.hxx>
41cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
42cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
43cdf0e10cSrcweir #include <editeng/pbinitem.hxx>
44cdf0e10cSrcweir #include <editeng/paperinf.hxx>
45cdf0e10cSrcweir #include <editeng/brkitem.hxx>
46cdf0e10cSrcweir #include <fmthdft.hxx>
47cdf0e10cSrcweir #include <swwait.hxx>
48cdf0e10cSrcweir #include <paratr.hxx>
49cdf0e10cSrcweir #include <swmodule.hxx>
50cdf0e10cSrcweir #include <wrtsh.hxx>
51cdf0e10cSrcweir #include <view.hxx>
52cdf0e10cSrcweir #include <docsh.hxx>
53cdf0e10cSrcweir #include <frmatr.hxx>
54cdf0e10cSrcweir #include <fldbas.hxx>
55cdf0e10cSrcweir #include <swundo.hxx>
56cdf0e10cSrcweir #include <IDocumentDeviceAccess.hxx>
57cdf0e10cSrcweir #include <dbmgr.hxx>
58cdf0e10cSrcweir #include <fmtcol.hxx>
59cdf0e10cSrcweir #include <frmmgr.hxx>
60cdf0e10cSrcweir #include <fldmgr.hxx>
61cdf0e10cSrcweir #include <pagedesc.hxx>
62cdf0e10cSrcweir #include <poolfmt.hxx>
63cdf0e10cSrcweir #include <expfld.hxx>
64cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
65cdf0e10cSrcweir #include <crsskip.hxx>
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #include <cmdid.h>
68cdf0e10cSrcweir #ifndef _GLOBALS_HRC
69cdf0e10cSrcweir #include <globals.hrc>
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir #ifndef _APP_HRC
72cdf0e10cSrcweir #include <app.hrc>
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir #ifndef _POOLFMT_HRC
75cdf0e10cSrcweir #include <poolfmt.hrc>
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir #include "swabstdlg.hxx"
78cdf0e10cSrcweir #include "envelp.hrc"
79cdf0e10cSrcweir #include "envimg.hxx"
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #define ENV_NEWDOC      RET_OK
82cdf0e10cSrcweir #define ENV_INSERT      RET_USER
83cdf0e10cSrcweir #define ENV_CANCEL      SHRT_MAX
84cdf0e10cSrcweir 
85*21a9459fSSascha Mester // Method is used for envelopes and labels!
86*21a9459fSSascha Mester // in applab.cxx and appenv.cxx
InsertLabEnvText(SwWrtShell & rSh,SwFldMgr & rFldMgr,const String & rText)87cdf0e10cSrcweir String InsertLabEnvText( SwWrtShell& rSh, SwFldMgr& rFldMgr, const String& rText )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     String sRet;
90cdf0e10cSrcweir     String aText(rText);
91cdf0e10cSrcweir     aText.EraseAllChars( '\r' );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     sal_uInt16 nTokenPos = 0;
95cdf0e10cSrcweir     while( STRING_NOTFOUND != nTokenPos )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         String aLine = aText.GetToken( 0, '\n', nTokenPos );
98cdf0e10cSrcweir         while ( aLine.Len() )
99cdf0e10cSrcweir         {
100cdf0e10cSrcweir             String sTmpText;
101cdf0e10cSrcweir             sal_Bool bField = sal_False;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             sal_uInt16 nPos = aLine.Search( '<' );
104cdf0e10cSrcweir             if ( nPos )
105cdf0e10cSrcweir             {
106cdf0e10cSrcweir                 sTmpText = aLine.Copy( 0, nPos );
107cdf0e10cSrcweir                 aLine.Erase( 0, nPos );
108cdf0e10cSrcweir //              sTmpText = aLine.Cut( 0, nPos );
109cdf0e10cSrcweir             }
110cdf0e10cSrcweir             else
111cdf0e10cSrcweir             {
112cdf0e10cSrcweir                 nPos = aLine.Search( '>' );
113cdf0e10cSrcweir                 if ( nPos == STRING_NOTFOUND )
114cdf0e10cSrcweir                 {
115cdf0e10cSrcweir                     sTmpText = aLine;
116cdf0e10cSrcweir                     aLine.Erase();
117cdf0e10cSrcweir //                  sTmpText = aLine.Cut();
118cdf0e10cSrcweir                 }
119cdf0e10cSrcweir                 else
120cdf0e10cSrcweir                 {
121cdf0e10cSrcweir                     sTmpText = aLine.Copy( 0, nPos + 1);
122cdf0e10cSrcweir                     aLine.Erase( 0, nPos + 1);
123cdf0e10cSrcweir //                  sTmpText = aLine.Cut( 0, nPos + 1 );
124cdf0e10cSrcweir 
125*21a9459fSSascha Mester                     // Database Fields must at least contain 3 points!
126cdf0e10cSrcweir                     String sDBName( sTmpText.Copy( 1, sTmpText.Len() - 2));
127cdf0e10cSrcweir                     sal_uInt16 nCnt = sDBName.GetTokenCount('.');
128cdf0e10cSrcweir                     if (nCnt >= 3)
129cdf0e10cSrcweir                     {
130cdf0e10cSrcweir                         ::ReplacePoint(sDBName, sal_True);
131cdf0e10cSrcweir                         SwInsertFld_Data aData(TYP_DBFLD, 0, sDBName, aEmptyStr, 0, &rSh );
132cdf0e10cSrcweir                         rFldMgr.InsertFld( aData );
133cdf0e10cSrcweir                         sRet = sDBName;
134cdf0e10cSrcweir                         bField = sal_True;
135cdf0e10cSrcweir                     }
136cdf0e10cSrcweir                 }
137cdf0e10cSrcweir             }
138cdf0e10cSrcweir             if ( !bField )
139cdf0e10cSrcweir                 rSh.Insert( sTmpText );
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir         rSh.InsertLineBreak();
142cdf0e10cSrcweir     }
143*21a9459fSSascha Mester     rSh.DelLeft();  // Delete last Linebreak
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     return sRet;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // ----------------------------------------------------------------------------
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
lcl_CopyCollAttr(SwWrtShell * pOldSh,SwWrtShell * pNewSh,sal_uInt16 nCollId)151cdf0e10cSrcweir void lcl_CopyCollAttr(SwWrtShell* pOldSh, SwWrtShell* pNewSh, sal_uInt16 nCollId)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     sal_uInt16 nCollCnt = pOldSh->GetTxtFmtCollCount();
154cdf0e10cSrcweir     SwTxtFmtColl* pColl;
155cdf0e10cSrcweir     for( sal_uInt16 nCnt = 0; nCnt < nCollCnt; ++nCnt )
156cdf0e10cSrcweir         if(nCollId == (pColl = &pOldSh->GetTxtFmtColl(nCnt))->GetPoolFmtId())
157cdf0e10cSrcweir             pNewSh->GetTxtCollFromPool(nCollId)->SetFmtAttr(pColl->GetAttrSet());
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // ----------------------------------------------------------------------------
161cdf0e10cSrcweir 
InsertEnv(SfxRequest & rReq)162cdf0e10cSrcweir void SwModule::InsertEnv( SfxRequest& rReq )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir static sal_uInt16 nTitleNo = 0;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     SwDocShell      *pMyDocSh;
167cdf0e10cSrcweir     SfxViewFrame    *pFrame;
168cdf0e10cSrcweir     SwView          *pNewView;
169cdf0e10cSrcweir     SwWrtShell      *pOldSh,
170cdf0e10cSrcweir                     *pSh;
171cdf0e10cSrcweir 
172*21a9459fSSascha Mester     // Get Current Shell
173cdf0e10cSrcweir     pMyDocSh = (SwDocShell*) SfxObjectShell::Current();
174cdf0e10cSrcweir     pOldSh   = pMyDocSh ? pMyDocSh->GetWrtShell() : 0;
175cdf0e10cSrcweir 
176*21a9459fSSascha Mester     // Create new document (don't show!)
177cdf0e10cSrcweir     SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
178cdf0e10cSrcweir     xDocSh->DoInitNew( 0 );
179cdf0e10cSrcweir     pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
180cdf0e10cSrcweir     pNewView = (SwView*) pFrame->GetViewShell();
181cdf0e10cSrcweir     pNewView->AttrChangedNotify( &pNewView->GetWrtShell() ); // Damit SelectShell gerufen wird.
182cdf0e10cSrcweir     pSh = pNewView->GetWrtShellPtr();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     String aTmp( SW_RES(STR_ENV_TITLE) );
185cdf0e10cSrcweir     aTmp += String::CreateFromInt32( ++nTitleNo );
186cdf0e10cSrcweir     xDocSh->SetTitle( aTmp );
187cdf0e10cSrcweir 
188*21a9459fSSascha Mester     // Copy old Collections "Sender" and "Recipient" into new document
189cdf0e10cSrcweir     if ( pOldSh )
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS);
192cdf0e10cSrcweir         ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS);
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
195*21a9459fSSascha Mester     // Read SwEnvItem in Config
196cdf0e10cSrcweir     SwEnvCfgItem aEnvCfg;
197cdf0e10cSrcweir 
198*21a9459fSSascha Mester     // Do we already have an envelope.
199cdf0e10cSrcweir     sal_Bool bEnvChange = sal_False;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     SfxItemSet aSet(GetPool(), FN_ENVELOP, FN_ENVELOP, 0);
202cdf0e10cSrcweir     aSet.Put(aEnvCfg.GetItem());
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     SfxPrinter* pTempPrinter = pSh->getIDocumentDeviceAccess()->getPrinter( true );
205cdf0e10cSrcweir     if(pOldSh )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         const SwPageDesc& rCurPageDesc = pOldSh->GetPageDesc(pOldSh->GetCurPageDesc());
208cdf0e10cSrcweir         String sJacket;
209cdf0e10cSrcweir         SwStyleNameMapper::FillUIName( RES_POOLPAGE_JAKET, sJacket );
210cdf0e10cSrcweir         bEnvChange = rCurPageDesc.GetName() == sJacket;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         IDocumentDeviceAccess* pIDDA_old = pOldSh->getIDocumentDeviceAccess();
213cdf0e10cSrcweir         if( pIDDA_old->getPrinter( false ) )
214cdf0e10cSrcweir         {
215cdf0e10cSrcweir             IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
216cdf0e10cSrcweir             pIDDA->setJobsetup( *pIDDA_old->getJobsetup() );
217cdf0e10cSrcweir             //#69563# if it isn't the same printer then the pointer has been invalidated!
218cdf0e10cSrcweir             pTempPrinter = pIDDA->getPrinter( true );
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir         pTempPrinter->SetPaperBin(rCurPageDesc.GetMaster().GetPaperBin().GetValue());
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     Window *pParent = pOldSh ? pOldSh->GetWin() : 0;
225cdf0e10cSrcweir     SfxAbstractTabDialog * pDlg=NULL;
226cdf0e10cSrcweir     short nMode = ENV_INSERT;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     SFX_REQUEST_ARG( rReq, pItem, SwEnvItem, FN_ENVELOP, sal_False );
229cdf0e10cSrcweir     if ( !pItem )
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
232cdf0e10cSrcweir         DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         pDlg = pFact->CreateSwEnvDlg( pParent, aSet, pOldSh, pTempPrinter, !bEnvChange, DLG_ENV );
235cdf0e10cSrcweir         DBG_ASSERT(pDlg, "Dialogdiet fail!");
236cdf0e10cSrcweir         nMode = pDlg->Execute();
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir     else
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         SFX_REQUEST_ARG( rReq, pBoolItem, SfxBoolItem, FN_PARAM_1, sal_False );
241cdf0e10cSrcweir         if ( pBoolItem && pBoolItem->GetValue() )
242cdf0e10cSrcweir             nMode = ENV_NEWDOC;
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     if (nMode == ENV_NEWDOC || nMode == ENV_INSERT)
246cdf0e10cSrcweir     {
2478ef2f12bSOliver-Rainer Wittmann         SwWait aWait( (SwDocShell&)*xDocSh, true );
248cdf0e10cSrcweir 
249*21a9459fSSascha Mester         // Read dialog, save Item to Config
250cdf0e10cSrcweir         const SwEnvItem& rItem = pItem ? *pItem : (const SwEnvItem&) pDlg->GetOutputItemSet()->Get(FN_ENVELOP);
251cdf0e10cSrcweir         aEnvCfg.GetItem() = rItem;
252cdf0e10cSrcweir         aEnvCfg.Commit();
253cdf0e10cSrcweir 
254*21a9459fSSascha Mester         // When printing, we adopt the job setup specified in the dialog.
255*21a9459fSSascha Mester         // The information must be set here before the new shell is potentially
256*21a9459fSSascha Mester         // destroyed, because its printer was passed to the dialog.
257cdf0e10cSrcweir         if ( nMode != ENV_NEWDOC )
258cdf0e10cSrcweir         {
259cdf0e10cSrcweir             ASSERT(pOldSh, "Kein Dokument - war 'Einfuegen' nicht disabled???");
260cdf0e10cSrcweir             SvxPaperBinItem aItem( RES_PAPER_BIN );
261cdf0e10cSrcweir             aItem.SetValue((sal_uInt8)pSh->getIDocumentDeviceAccess()->getPrinter(true)->GetPaperBin());
262cdf0e10cSrcweir             pOldSh->GetPageDescFromPool(RES_POOLPAGE_JAKET)->GetMaster().SetFmtAttr(aItem);
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         SwWrtShell *pTmp = nMode == ENV_INSERT ? pOldSh : pSh;
266cdf0e10cSrcweir         const SwPageDesc* pFollow = 0;
267cdf0e10cSrcweir         SwTxtFmtColl *pSend = pTmp->GetTxtCollFromPool( RES_POOLCOLL_SENDADRESS ),
268cdf0e10cSrcweir                      *pAddr = pTmp->GetTxtCollFromPool( RES_POOLCOLL_JAKETADRESS);
269cdf0e10cSrcweir         const String &rSendMark = pSend->GetName();
270cdf0e10cSrcweir         const String &rAddrMark = pAddr->GetName();
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         if (nMode == ENV_INSERT)
273cdf0e10cSrcweir         {
274cdf0e10cSrcweir 
275cdf0e10cSrcweir             SetView(&pOldSh->GetView()); // Pointer auf oberste View restaurieren
276cdf0e10cSrcweir 
277*21a9459fSSascha Mester             // Delete new doc.
278cdf0e10cSrcweir             xDocSh->DoClose();
279cdf0e10cSrcweir             pSh = pOldSh;
280cdf0e10cSrcweir             //#i4251# selected text or objects in the document should
281cdf0e10cSrcweir             //not be deleted on inserting envelopes
282cdf0e10cSrcweir             pSh->EnterStdMode();
283*21a9459fSSascha Mester             // Let's go (paste)
284cdf0e10cSrcweir             pSh->StartUndo(UNDO_UI_INSERT_ENVELOPE, NULL);
285cdf0e10cSrcweir             pSh->StartAllAction();
286cdf0e10cSrcweir             pSh->SttEndDoc(sal_True);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir             if (bEnvChange)
289cdf0e10cSrcweir             {
290*21a9459fSSascha Mester                 // Follow-Up Template: Page 2
291cdf0e10cSrcweir                 pFollow = pSh->GetPageDesc(pSh->GetCurPageDesc()).GetFollow();
292cdf0e10cSrcweir 
293*21a9459fSSascha Mester                 // Delete text of first page
294cdf0e10cSrcweir                 if ( !pSh->SttNxtPg(sal_True) )
295cdf0e10cSrcweir                     pSh->EndPg(sal_True);
296cdf0e10cSrcweir                 pSh->DelRight();
297*21a9459fSSascha Mester                 // Delete frame of first page
298cdf0e10cSrcweir                 if( pSh->GotoFly( rSendMark ) )
299cdf0e10cSrcweir                 {
300cdf0e10cSrcweir                     pSh->EnterSelFrmMode();
301cdf0e10cSrcweir                     pSh->DelRight();
302cdf0e10cSrcweir                 }
303cdf0e10cSrcweir                 if ( pSh->GotoFly( rAddrMark ) )
304cdf0e10cSrcweir                 {
305cdf0e10cSrcweir                     pSh->EnterSelFrmMode();
306cdf0e10cSrcweir                     pSh->DelRight();
307cdf0e10cSrcweir                 }
308cdf0e10cSrcweir                 pSh->SttEndDoc(sal_True);
309cdf0e10cSrcweir             }
310cdf0e10cSrcweir             else
311*21a9459fSSascha Mester                 // Follow-Up Template: Page 1
312cdf0e10cSrcweir                 pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc());
313cdf0e10cSrcweir 
314*21a9459fSSascha Mester             // Add page break
315cdf0e10cSrcweir             if ( pSh->IsCrsrInTbl() )
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 pSh->SplitNode();
318cdf0e10cSrcweir                 pSh->Right( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
319cdf0e10cSrcweir                 SfxItemSet aBreakSet( pSh->GetAttrPool(), RES_BREAK, RES_BREAK, 0 );
320cdf0e10cSrcweir                 aBreakSet.Put( SvxFmtBreakItem(SVX_BREAK_PAGE_BEFORE, RES_BREAK) );
321cdf0e10cSrcweir                 pSh->SetTblAttr( aBreakSet );
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir             else
324cdf0e10cSrcweir                 pSh->InsertPageBreak(0, sal_False);
325cdf0e10cSrcweir             pSh->SttEndDoc(sal_True);
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir         else
328cdf0e10cSrcweir         {
329cdf0e10cSrcweir             pFollow = &pSh->GetPageDesc(pSh->GetCurPageDesc());
330*21a9459fSSascha Mester             // Let's go (printing)
331cdf0e10cSrcweir             pSh->StartAllAction();
332cdf0e10cSrcweir             pSh->DoUndo(sal_False);
333cdf0e10cSrcweir 
334*21a9459fSSascha Mester             // Copy new collections 'Sender' and 'Recipient'
335*21a9459fSSascha Mester             // into new document
336cdf0e10cSrcweir             if ( pOldSh )
337cdf0e10cSrcweir             {
338cdf0e10cSrcweir                 ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_JAKETADRESS);
339cdf0e10cSrcweir                 ::lcl_CopyCollAttr(pOldSh, pSh, RES_POOLCOLL_SENDADRESS);
340cdf0e10cSrcweir             }
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         SET_CURR_SHELL(pSh);
344*21a9459fSSascha Mester         pSh->SetNewDoc(); // Avoid Performance Issues
345cdf0e10cSrcweir 
346*21a9459fSSascha Mester         // Memorize (?) Fly's of this page ( Original comment was "Flys dieser Seite merken" )
347cdf0e10cSrcweir         SvPtrarr aFlyArr(0, 5);
348cdf0e10cSrcweir         if( ENV_NEWDOC != nMode && !bEnvChange )
349cdf0e10cSrcweir             pSh->GetPageObjs( aFlyArr );
350cdf0e10cSrcweir 
351*21a9459fSSascha Mester         // Get Page-Desc
352cdf0e10cSrcweir         SwPageDesc* pDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_JAKET);
353cdf0e10cSrcweir         SwFrmFmt&   rFmt  = pDesc->GetMaster();
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         Printer *pPrt = pSh->getIDocumentDeviceAccess()->getPrinter( true );
356cdf0e10cSrcweir 
357*21a9459fSSascha Mester         // Margins (consist of Shift-Offset and
358*21a9459fSSascha Mester         // Alignment)
359cdf0e10cSrcweir         Size aPaperSize = pPrt->PixelToLogic( pPrt->GetPaperSizePixel(),
360cdf0e10cSrcweir                                               MAP_TWIP);
361cdf0e10cSrcweir         if ( !aPaperSize.Width() && !aPaperSize.Height() )
362cdf0e10cSrcweir                     aPaperSize = SvxPaperInfo::GetPaperSize(PAPER_A4);
363cdf0e10cSrcweir         if ( aPaperSize.Width() > aPaperSize.Height() )
364cdf0e10cSrcweir             Swap( aPaperSize );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         long lLeft  = rItem.lShiftRight,
367cdf0e10cSrcweir              lUpper = rItem.lShiftDown;
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         sal_uInt16 nPageW = (sal_uInt16) Max(rItem.lWidth, rItem.lHeight),
370cdf0e10cSrcweir                nPageH = (sal_uInt16) Min(rItem.lWidth, rItem.lHeight);
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         switch (rItem.eAlign)
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             case ENV_HOR_LEFT: break;
375cdf0e10cSrcweir             case ENV_HOR_CNTR: lLeft  += Max(0L, long(aPaperSize.Width() - nPageW)) / 2;
376cdf0e10cSrcweir                                break;
377cdf0e10cSrcweir             case ENV_HOR_RGHT: lLeft  += Max(0L, long(aPaperSize.Width() - nPageW));
378cdf0e10cSrcweir                                break;
379cdf0e10cSrcweir             case ENV_VER_LEFT: lUpper += Max(0L, long(aPaperSize.Width() - nPageH));
380cdf0e10cSrcweir                                break;
381cdf0e10cSrcweir             case ENV_VER_CNTR: lUpper += Max(0L, long(aPaperSize.Width() - nPageH)) / 2;
382cdf0e10cSrcweir                                break;
383cdf0e10cSrcweir             case ENV_VER_RGHT: break;
384cdf0e10cSrcweir         }
385cdf0e10cSrcweir         SvxLRSpaceItem aLRMargin( RES_LR_SPACE );
386cdf0e10cSrcweir         SvxULSpaceItem aULMargin( RES_UL_SPACE );
387cdf0e10cSrcweir         aLRMargin.SetLeft ((sal_uInt16) lLeft );
388cdf0e10cSrcweir         aULMargin.SetUpper((sal_uInt16) lUpper);
389cdf0e10cSrcweir         aLRMargin.SetRight(0);
390cdf0e10cSrcweir         aULMargin.SetLower(0);
391cdf0e10cSrcweir         rFmt.SetFmtAttr(aLRMargin);
392cdf0e10cSrcweir         rFmt.SetFmtAttr(aULMargin);
393cdf0e10cSrcweir 
394*21a9459fSSascha Mester         // Header, Footer
395cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
396cdf0e10cSrcweir         pDesc->ChgHeaderShare(sal_False);
397cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
398cdf0e10cSrcweir         pDesc->ChgFooterShare(sal_False);
399cdf0e10cSrcweir 
400*21a9459fSSascha Mester         // Page Numbering
401cdf0e10cSrcweir         pDesc->SetUseOn(nsUseOnPage::PD_ALL);
402cdf0e10cSrcweir 
403*21a9459fSSascha Mester         // Setup the page size
404cdf0e10cSrcweir         rFmt.SetFmtAttr(SwFmtFrmSize(ATT_FIX_SIZE,
405cdf0e10cSrcweir                                             nPageW + lLeft, nPageH + lUpper));
406cdf0e10cSrcweir 
407*21a9459fSSascha Mester         // Setup kind of numbering
408cdf0e10cSrcweir         SvxNumberType aType;
409cdf0e10cSrcweir         aType.SetNumberingType(SVX_NUM_NUMBER_NONE);
410cdf0e10cSrcweir         pDesc->SetNumType(aType);
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         // Folgevorlage
413cdf0e10cSrcweir         if (pFollow)
414cdf0e10cSrcweir             pDesc->SetFollow(pFollow);
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         // Landscape
417cdf0e10cSrcweir         pDesc->SetLandscape( rItem.eAlign >= ENV_VER_LEFT &&
418cdf0e10cSrcweir                              rItem.eAlign <= ENV_VER_RGHT);
419cdf0e10cSrcweir 
420*21a9459fSSascha Mester         // Apply Page-Desc
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         sal_uInt16 nPos;
423cdf0e10cSrcweir         pSh->FindPageDescByName( pDesc->GetName(),
424cdf0e10cSrcweir                                     sal_False,
425cdf0e10cSrcweir                                     &nPos );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         pSh->ChgPageDesc( nPos, *pDesc);
429cdf0e10cSrcweir         pSh->ChgCurPageDesc(*pDesc);
430cdf0e10cSrcweir 
431*21a9459fSSascha Mester         // Insert Frame
432cdf0e10cSrcweir         SwFlyFrmAttrMgr aMgr(sal_False, pSh, FRMMGR_TYPE_ENVELP);
433cdf0e10cSrcweir         SwFldMgr aFldMgr;
434cdf0e10cSrcweir         aMgr.SetHeightSizeType(ATT_VAR_SIZE);
435cdf0e10cSrcweir 
436*21a9459fSSascha Mester         // Override Defaults!
437cdf0e10cSrcweir         aMgr.GetAttrSet().Put( SvxBoxItem(RES_BOX) );
438cdf0e10cSrcweir         aMgr.SetULSpace( 0L, 0L );
439cdf0e10cSrcweir         aMgr.SetLRSpace( 0L, 0L );
440cdf0e10cSrcweir 
441*21a9459fSSascha Mester         // Sender
442cdf0e10cSrcweir         if (rItem.bSend)
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir             pSh->SttEndDoc(sal_True);
445cdf0e10cSrcweir             aMgr.InsertFlyFrm(FLY_AT_PAGE,
446cdf0e10cSrcweir                 Point(rItem.lSendFromLeft + lLeft, rItem.lSendFromTop  + lUpper),
447cdf0e10cSrcweir                 Size (rItem.lAddrFromLeft - rItem.lSendFromLeft, 0));
448cdf0e10cSrcweir 
449cdf0e10cSrcweir             pSh->EnterSelFrmMode();
450cdf0e10cSrcweir             pSh->SetFlyName( rSendMark );
451cdf0e10cSrcweir             pSh->UnSelectFrm();
452cdf0e10cSrcweir             pSh->LeaveSelFrmMode();
453cdf0e10cSrcweir             pSh->SetTxtFmtColl( pSend );
454cdf0e10cSrcweir             InsertLabEnvText( *pSh, aFldMgr, rItem.aSendText );
455cdf0e10cSrcweir             aMgr.UpdateAttrMgr();
456cdf0e10cSrcweir         }
457cdf0e10cSrcweir 
458*21a9459fSSascha Mester         // Recipient
459cdf0e10cSrcweir         pSh->SttEndDoc(sal_True);
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         aMgr.InsertFlyFrm(FLY_AT_PAGE,
462cdf0e10cSrcweir             Point(rItem.lAddrFromLeft + lLeft, rItem.lAddrFromTop  + lUpper),
463cdf0e10cSrcweir             Size (nPageW - rItem.lAddrFromLeft - 566, 0));
464cdf0e10cSrcweir         pSh->EnterSelFrmMode();
465cdf0e10cSrcweir         pSh->SetFlyName( rAddrMark );
466cdf0e10cSrcweir         pSh->UnSelectFrm();
467cdf0e10cSrcweir         pSh->LeaveSelFrmMode();
468cdf0e10cSrcweir         pSh->SetTxtFmtColl( pAddr );
469cdf0e10cSrcweir         InsertLabEnvText(*pSh, aFldMgr, rItem.aAddrText);
470cdf0e10cSrcweir 
471*21a9459fSSascha Mester         // Move Flys to "old" Pages
472cdf0e10cSrcweir         if (aFlyArr.Count())
473cdf0e10cSrcweir             pSh->SetPageObjsNewPage(aFlyArr, 1);
474cdf0e10cSrcweir 
475*21a9459fSSascha Mester         // Done
476cdf0e10cSrcweir         pSh->SttEndDoc(sal_True);
477cdf0e10cSrcweir 
478cdf0e10cSrcweir         pSh->EndAllAction();
479cdf0e10cSrcweir 
480cdf0e10cSrcweir         if (nMode == ENV_NEWDOC)
481cdf0e10cSrcweir             pSh->DoUndo(sal_True);
482cdf0e10cSrcweir         else
483cdf0e10cSrcweir             pSh->EndUndo(UNDO_UI_INSERT_ENVELOPE);
484cdf0e10cSrcweir 
485cdf0e10cSrcweir         if (nMode == ENV_NEWDOC)
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir             pFrame->GetFrame().Appear();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir             if ( rItem.aAddrText.indexOf('<') >= 0 )
490cdf0e10cSrcweir             {
491cdf0e10cSrcweir                 static sal_uInt16 __READONLY_DATA aInva[] =
492cdf0e10cSrcweir                                     {
493cdf0e10cSrcweir                                         SID_SBA_BRW_UPDATE,
494cdf0e10cSrcweir                                         SID_SBA_BRW_INSERT,
495cdf0e10cSrcweir                                         SID_SBA_BRW_MERGE,
496cdf0e10cSrcweir                                         0
497cdf0e10cSrcweir                                     };
498cdf0e10cSrcweir                 pFrame->GetBindings().Invalidate( aInva );
499cdf0e10cSrcweir 
5007daebb42Smseidel                 // Datenbankbeamer öffnen
501cdf0e10cSrcweir                 ShowDBObj(*pNewView, pSh->GetDBData());
502cdf0e10cSrcweir             }
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir         if ( !pItem )
506cdf0e10cSrcweir         {
507cdf0e10cSrcweir             rReq.AppendItem( rItem );
508cdf0e10cSrcweir             if ( nMode == ENV_NEWDOC )
509cdf0e10cSrcweir                 rReq.AppendItem( SfxBoolItem( FN_PARAM_1, sal_True ) );
510cdf0e10cSrcweir         }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir         rReq.Done();
513cdf0e10cSrcweir     }
514*21a9459fSSascha Mester     else // Cancel
515cdf0e10cSrcweir     {
516cdf0e10cSrcweir         rReq.Ignore();
517cdf0e10cSrcweir 
518cdf0e10cSrcweir         xDocSh->DoClose();
519cdf0e10cSrcweir         --nTitleNo;
520cdf0e10cSrcweir 
521*21a9459fSSascha Mester         // Set Pointer to upper view
522cdf0e10cSrcweir         if (pOldSh)
523cdf0e10cSrcweir             SetView(&pOldSh->GetView());
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir     delete pDlg;
526cdf0e10cSrcweir }
5277daebb42Smseidel 
5287daebb42Smseidel /* vim: set noet sw=4 ts=4: */
529