xref: /aoo41x/main/sw/source/ui/envelp/envfmt.cxx (revision 69a74367)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 
33 
34 #include <hintids.hxx>
35 
36 #include <tools/pstm.hxx>
37 
38 #define _SVSTDARR_LONGSSORT
39 #define _SVSTDARR_LONGS
40 #include <svl/svstdarr.hxx>
41 #include <editeng/paperinf.hxx>
42 #ifndef _SVX_TSTPITEM_HXX //autogen
43 #include <editeng/tstpitem.hxx>
44 #endif
45 #include <editeng/lrspitem.hxx>
46 #include <editeng/brshitem.hxx>
47 #ifndef _MSGBOX_HXX //autogen
48 #include <vcl/msgbox.hxx>
49 #endif
50 #ifndef _MENU_HXX //autogen
51 #include <vcl/menu.hxx>
52 #endif
53 
54 #ifndef _CMDID_H
55 #include <cmdid.h>
56 #endif
57 #include <frmatr.hxx>
58 #include <swtypes.hxx>
59 #include <wrtsh.hxx>
60 #ifndef _VIEW_HXX
61 #include <view.hxx>
62 #endif
63 #ifndef _BASESH_HXX
64 #include <basesh.hxx>
65 #endif
66 #include <drpcps.hxx>
67 #include <envfmt.hxx>
68 #include <fmtcol.hxx>
69 #ifndef _PARDLG_HXX
70 #include "swuipardlg.hxx"
71 #endif
72 #include <pattern.hxx>
73 #include <poolfmt.hxx>
74 #include <uiborder.hxx>
75 #include <uitool.hxx>
76 
77 #ifndef _ENVFMT_HRC
78 #include <envfmt.hrc>
79 #endif
80 
81 #include "swabstdlg.hxx"
82 #include "chrdlg.hrc"
83 
84 namespace swui
85 {
86 	SwAbstractDialogFactory * GetFactory();
87 }
88 
89 static PopupMenu *pMenu;
90 static long lUserW = 5669; // 10 cm
91 static long lUserH = 5669; // 10 cm
92 
93 // --------------------------------------------------------------------------
94 
95 
SwEnvFmtPage(Window * pParent,const SfxItemSet & rSet)96 SwEnvFmtPage::SwEnvFmtPage(Window* pParent, const SfxItemSet& rSet) :
97 
98 	SfxTabPage(pParent, SW_RES(TP_ENV_FMT), rSet),
99 
100     aAddrFL             (this, SW_RES( FL_ADDRESSEE )),
101 	aAddrPosInfo   		(this, SW_RES( TXT_ADDR_POS )),
102 	aAddrLeftText  		(this, SW_RES( TXT_ADDR_LEFT )),
103 	aAddrLeftField 		(this, SW_RES( FLD_ADDR_LEFT )),
104 	aAddrTopText   		(this, SW_RES( TXT_ADDR_TOP )),
105 	aAddrTopField  		(this, SW_RES( FLD_ADDR_TOP )),
106 	aAddrFormatInfo		(this, SW_RES( TXT_ADDR_FORMAT )),
107 	aAddrEditButton		(this, SW_RES( BTN_ADDR_EDIT )),
108     aSendFL             (this, SW_RES( FL_SENDER )),
109 	aSendPosInfo		(this, SW_RES( TXT_SEND_POS )),
110 	aSendLeftText  		(this, SW_RES( TXT_SEND_LEFT )),
111 	aSendLeftField 		(this, SW_RES( FLD_SEND_LEFT )),
112 	aSendTopText   		(this, SW_RES( TXT_SEND_TOP )),
113 	aSendTopField  		(this, SW_RES( FLD_SEND_TOP )),
114 	aSendFormatInfo		(this, SW_RES( TXT_SEND_FORMAT )),
115 	aSendEditButton		(this, SW_RES( BTN_SEND_EDIT )),
116     aSizeFL             (this, SW_RES( FL_SIZE )),
117 	aSizeFormatText		(this, SW_RES( TXT_SIZE_FORMAT )),
118 	aSizeFormatBox 		(this, SW_RES( BOX_SIZE_FORMAT )),
119 	aSizeWidthText 		(this, SW_RES( TXT_SIZE_WIDTH )),
120 	aSizeWidthField		(this, SW_RES( FLD_SIZE_WIDTH )),
121 	aSizeHeightText		(this, SW_RES( TXT_SIZE_HEIGHT )),
122 	aSizeHeightField	(this, SW_RES( FLD_SIZE_HEIGHT )),
123 	aPreview       		(this, SW_RES( WIN_PREVIEW ))
124 
125 {
126 	FreeResource();
127 	SetExchangeSupport();
128 
129 	// Metriken
130 	FieldUnit aMetric = ::GetDfltMetric(sal_False);
131 	SetMetric(aAddrLeftField,   aMetric);
132 	SetMetric(aAddrTopField,    aMetric);
133 	SetMetric(aSendLeftField,   aMetric);
134 	SetMetric(aSendTopField,    aMetric);
135 	SetMetric(aSizeWidthField,  aMetric);
136 	SetMetric(aSizeHeightField, aMetric);
137 
138 	// Menues einhaengen
139 	::pMenu = new PopupMenu(SW_RES(MNU_EDIT));
140 	aAddrEditButton.SetPopupMenu(::pMenu);
141 	aSendEditButton.SetPopupMenu(::pMenu);
142 
143 	// Handler installieren
144 	Link aLk = LINK(this, SwEnvFmtPage, ModifyHdl);
145     aAddrLeftField  .SetUpHdl( aLk );
146     aAddrTopField   .SetUpHdl( aLk );
147     aSendLeftField  .SetUpHdl( aLk );
148     aSendTopField   .SetUpHdl( aLk );
149     aSizeWidthField .SetUpHdl( aLk );
150     aSizeHeightField.SetUpHdl( aLk );
151 
152     aAddrLeftField  .SetDownHdl( aLk );
153     aAddrTopField   .SetDownHdl( aLk );
154     aSendLeftField  .SetDownHdl( aLk );
155     aSendTopField   .SetDownHdl( aLk );
156     aSizeWidthField .SetDownHdl( aLk );
157     aSizeHeightField.SetDownHdl( aLk );
158 
159     aAddrLeftField  .SetLoseFocusHdl( aLk );
160     aAddrTopField   .SetLoseFocusHdl( aLk );
161     aSendLeftField  .SetLoseFocusHdl( aLk );
162     aSendTopField   .SetLoseFocusHdl( aLk );
163     aSizeWidthField .SetLoseFocusHdl( aLk );
164     aSizeHeightField.SetLoseFocusHdl( aLk );
165 
166 	aLk = LINK(this, SwEnvFmtPage, EditHdl );
167 	aAddrEditButton.SetSelectHdl( aLk );
168 	aSendEditButton.SetSelectHdl( aLk );
169 
170     aPreview.SetBorderStyle( WINDOW_BORDER_MONO );
171 
172 	aSizeFormatBox     .SetSelectHdl(LINK(this, SwEnvFmtPage, FormatHdl));
173 
174 	// aSizeFormatBox
175     for (sal_uInt16 i = PAPER_A3; i <= PAPER_KAI32BIG; i++)
176 	{
177 		if (i != PAPER_USER)
178 		{
179 			String aPaperName = SvxPaperInfo::GetName((Paper) i),
180 				   aEntryName;
181 
182 			sal_uInt16 nPos   = 0;
183 			sal_Bool   bFound = sal_False;
184 			while (nPos < aSizeFormatBox.GetEntryCount() && !bFound)
185 			{
186 				aEntryName = aSizeFormatBox.GetEntry(i);
187 				if (aEntryName < aPaperName)
188 					nPos++;
189 				else
190 					bFound = sal_True;
191 			}
192 			aSizeFormatBox.InsertEntry(aPaperName, nPos);
193 			aIDs.Insert((sal_uInt16) i, nPos);
194 		}
195 	}
196 	aSizeFormatBox.InsertEntry(SvxPaperInfo::GetName(PAPER_USER));
197 	aIDs.Insert((sal_uInt16) PAPER_USER, aIDs.Count());
198 
199 }
200 
201 // --------------------------------------------------------------------------
202 
203 
~SwEnvFmtPage()204 __EXPORT SwEnvFmtPage::~SwEnvFmtPage()
205 {
206 	aAddrEditButton.SetPopupMenu(0);
207 	aSendEditButton.SetPopupMenu(0);
208 	delete ::pMenu;
209 }
210 
211 // --------------------------------------------------------------------------
212 
213 
IMPL_LINK_INLINE_START(SwEnvFmtPage,ModifyHdl,Edit *,pEdit)214 IMPL_LINK_INLINE_START( SwEnvFmtPage, ModifyHdl, Edit *, pEdit )
215 {
216     long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
217     long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
218 
219     long lWidth  = Max(lWVal, lHVal);
220     long lHeight = Min(lWVal, lHVal);
221 
222     if (pEdit == &aSizeWidthField || pEdit == &aSizeHeightField)
223     {
224         Paper ePaper = SvxPaperInfo::GetSvxPaper(
225             Size(lHeight, lWidth), MAP_TWIP, sal_True);
226         for (sal_uInt16 i = 0; i < aIDs.Count(); i++)
227             if (aIDs[i] == (sal_uInt16)ePaper)
228                 aSizeFormatBox.SelectEntryPos(i);
229 
230         // Benutzergroesse merken
231         if (aIDs[aSizeFormatBox.GetSelectEntryPos()] == (sal_uInt16)PAPER_USER)
232         {
233             lUserW = lWidth ;
234             lUserH = lHeight;
235         }
236 
237         aSizeFormatBox.GetSelectHdl().Call(&aSizeFormatBox);
238     }
239     else
240     {
241         FillItem(GetParent()->aEnvItem);
242         SetMinMax();
243         aPreview.Invalidate();
244     }
245     return 0;
246 }
IMPL_LINK_INLINE_END(SwEnvFmtPage,ModifyHdl,Edit *,pEdit)247 IMPL_LINK_INLINE_END( SwEnvFmtPage, ModifyHdl, Edit *, pEdit )
248 
249 // --------------------------------------------------------------------------
250 
251 
252 IMPL_LINK( SwEnvFmtPage, EditHdl, MenuButton *, pButton )
253 {
254 	SwWrtShell* pSh = GetParent()->pSh;
255 	ASSERT(pSh, "Shell fehlt");
256 
257 	// Collection-Ptr ermitteln
258 	sal_Bool bSender = pButton != &aAddrEditButton;
259 
260     SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool( static_cast< sal_uInt16 >(
261         bSender ? RES_POOLCOLL_SENDADRESS : RES_POOLCOLL_JAKETADRESS));
262 	ASSERT(pColl, "Text-Collection fehlt");
263 
264 	switch (pButton->GetCurItemId())
265 	{
266 		case MID_CHAR:
267 		{
268             SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
269 
270 			// Damit die Hintergrundfarbe nicht uebergebuegelt wird:
271             SfxAllItemSet aTmpSet(*pCollSet);
272 
273 			// Das CHRATR_BACKGROUND-Attribut wird fuer den Dialog in
274 			// ein RES_BACKGROUND verwandelt und wieder zurueck ...
275 			const SfxPoolItem *pTmpBrush;
276 
277 			if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_CHRATR_BACKGROUND,
278 				sal_True, &pTmpBrush ) )
279 			{
280 				SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
281 				aTmpBrush.SetWhich( RES_BACKGROUND );
282 				aTmpSet.Put( aTmpBrush );
283 			}
284 			else
285 				aTmpSet.ClearItem( RES_BACKGROUND );
286 
287             SwAbstractDialogFactory* pFact = swui::GetFactory();
288             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
289 
290             SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( GetParent(), pSh->GetView(), aTmpSet, DLG_CHAR ,&pColl->GetName() );
291             DBG_ASSERT(pDlg, "Dialogdiet fail!");
292 			if (pDlg->Execute() == RET_OK)
293 			{
294 				SfxItemSet aOutputSet( *pDlg->GetOutputItemSet() );
295 				if( SFX_ITEM_SET == aOutputSet.GetItemState( RES_BACKGROUND,
296 					sal_False, &pTmpBrush ) )
297 				{
298 					SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
299 					aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
300                     pCollSet->Put( aTmpBrush );
301 				}
302 				aOutputSet.ClearItem( RES_BACKGROUND );
303                 pCollSet->Put(aOutputSet);
304 			}
305 			delete pDlg;
306 		}
307 		break;
308 
309 		case MID_PARA:
310 		{
311             SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
312 
313 			// Damit die Tabulatoren nicht uebergebuegelt werden:
314             SfxAllItemSet aTmpSet(*pCollSet);
315 
316 			// Tabulatoren, DefaultTabs ins ItemSet Stecken
317 			const SvxTabStopItem& rDefTabs = (const SvxTabStopItem&)
318 				pSh->GetView().GetCurShell()->GetPool().GetDefaultItem(RES_PARATR_TABSTOP);
319 
320 			sal_uInt16 nDefDist = ::GetTabDist( rDefTabs );
321 			SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist );
322 			aTmpSet.Put( aDefDistItem );
323 
324 			// Aktueller Tab
325 			SfxUInt16Item aTabPos( SID_ATTR_TABSTOP_POS, 0 );
326 			aTmpSet.Put( aTabPos );
327 
328 			// linker Rand als Offset
329 			const long nOff = ((SvxLRSpaceItem&)aTmpSet.Get( RES_LR_SPACE )).
330 																GetTxtLeft();
331 			SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET, nOff );
332 			aTmpSet.Put( aOff );
333 
334 			// BoxInfo setzen
335 			::PrepareBoxInfo( aTmpSet, *pSh );
336 
337 			SwParaDlg *pDlg = new SwParaDlg(GetParent(), pSh->GetView(), aTmpSet, DLG_ENVELOP, &pColl->GetName());
338 
339 			if ( pDlg->Execute() == RET_OK )
340 			{
341 				// Defaults evtl umsetzen
342 				const SfxPoolItem* pItem = 0;
343 				SfxItemSet* pOutputSet = (SfxItemSet*)pDlg->GetOutputItemSet();
344 				sal_uInt16 nNewDist;
345 				if( SFX_ITEM_SET == pOutputSet->GetItemState( SID_ATTR_TABSTOP_DEFAULTS,
346 					sal_False, &pItem ) &&
347 					nDefDist != (nNewDist = ((SfxUInt16Item*)pItem)->GetValue()) )
348 				{
349                     SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP );
350 					MakeDefTabs( nNewDist, aDefTabs );
351 					pSh->SetDefault( aDefTabs );
352 					pOutputSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS );
353 				}
354 				if( pOutputSet->Count() )
355 				{
356                     pCollSet->Put(*pOutputSet);
357 				}
358 			}
359 			delete pDlg;
360 		}
361 		break;
362 	}
363 	return 0;
364 }
365 
366 /*------------------------------------------------------------------------
367   Beschreibung: Ein temporaeres Itemset, das bei Abbruch verworfen wird
368 ------------------------------------------------------------------------*/
369 
GetCollItemSet(SwTxtFmtColl * pColl,sal_Bool bSender)370 SfxItemSet *SwEnvFmtPage::GetCollItemSet(SwTxtFmtColl* pColl, sal_Bool bSender)
371 {
372     SfxItemSet *&pAddrSet = bSender ? GetParent()->pSenderSet : GetParent()->pAddresseeSet;
373 
374     if (!pAddrSet)
375 	{
376 		// Range ermitteln (Ranges beider Itemsets mergen)
377 		const sal_uInt16 *pRanges = pColl->GetAttrSet().GetRanges();
378 
379 		static sal_uInt16 __READONLY_DATA aRanges[] =
380 		{
381 			RES_PARATR_BEGIN, RES_PARATR_ADJUST,
382 			RES_PARATR_TABSTOP, RES_PARATR_END-1,
383 			RES_LR_SPACE, RES_UL_SPACE,
384 			RES_BACKGROUND, RES_SHADOW,
385 			SID_ATTR_TABSTOP_POS, SID_ATTR_TABSTOP_POS,
386 			SID_ATTR_TABSTOP_DEFAULTS, SID_ATTR_TABSTOP_DEFAULTS,
387 			SID_ATTR_TABSTOP_OFFSET, SID_ATTR_TABSTOP_OFFSET,
388 			SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
389 			0, 0
390 		};
391 
392 		// BruteForce-Merge, weil MergeRange in SvTools buggy ist:
393 		sal_uInt16 i = 0;
394 		SvLongsSort aMergedRanges( 0, 10 );
395 
396 		while (pRanges[i])
397 		{
398 			for (sal_uInt16 nPos = pRanges[i]; nPos <= pRanges[i+1]; nPos++)
399 				aMergedRanges.Insert(nPos);
400 			i += 2;
401 		}
402 
403 		i = 0;
404 
405 		while (aRanges[i])
406 		{
407 			for (sal_uInt16 nPos = aRanges[i]; nPos <= aRanges[i+1]; nPos++)
408 				aMergedRanges.Insert(nPos);
409 			i += 2;
410 		}
411 
412 		// Ranges kompaktieren
413 		SvLongs aCompactedRanges( 0, 10 );
414 
415 		aCompactedRanges.Insert(aMergedRanges[0], aCompactedRanges.Count());
416 
417 		for (i = 0; i < aMergedRanges.Count(); i++)
418 		{
419 			while (i + 1 < aMergedRanges.Count() &&
420 				aMergedRanges[i+1] - aMergedRanges[i] == 1)
421 			{
422 				i++;
423 			}
424 			long nEnd = aMergedRanges[i];
425 			aCompactedRanges.Insert(nEnd, aCompactedRanges.Count());
426 
427 			if (i + 1 < aMergedRanges.Count())
428 			{
429 				long nStart = aMergedRanges[i+1];
430 				aCompactedRanges.Insert(nStart, aCompactedRanges.Count());
431 			}
432 		}
433 
434 		// Neue Ranges erzeugen
435 		sal_uInt16 *pNewRanges = new sal_uInt16[aCompactedRanges.Count() + 1];
436 		for (i = 0; i < aCompactedRanges.Count(); i++)
437 			pNewRanges[i] = (sal_uInt16)aCompactedRanges[i];
438 
439 		pNewRanges[i] = 0;
440 
441         pAddrSet = new SfxItemSet(GetParent()->pSh->GetView().GetCurShell()->GetPool(),
442 								pNewRanges);
443 
444         pAddrSet->Put(pColl->GetAttrSet());
445         delete[] pNewRanges;
446 	}
447 
448     return pAddrSet;
449 }
450 
451 // --------------------------------------------------------------------------
452 
453 
IMPL_LINK(SwEnvFmtPage,FormatHdl,ListBox *,EMPTYARG)454 IMPL_LINK( SwEnvFmtPage, FormatHdl, ListBox *, EMPTYARG )
455 {
456 	long lWidth;
457 	long lHeight;
458 	long lSendFromLeft;
459 	long lSendFromTop;
460 	long lAddrFromLeft;
461 	long lAddrFromTop;
462 
463 	sal_uInt16 nPaper = aIDs[aSizeFormatBox.GetSelectEntryPos()];
464 	if (nPaper != (sal_uInt16)PAPER_USER)
465 	{
466 		Size aSz = SvxPaperInfo::GetPaperSize((Paper)nPaper);
467 		lWidth  = Max(aSz.Width(), aSz.Height());
468 		lHeight = Min(aSz.Width(), aSz.Height());
469 	}
470 	else
471 	{
472 		lWidth  = lUserW;
473 		lHeight = lUserH;
474 	}
475 
476 	lSendFromLeft = 566;            // 1cm
477 	lSendFromTop  = 566;            // 1cm
478 	lAddrFromLeft = lWidth  / 2;
479 	lAddrFromTop  = lHeight / 2;
480 
481 	SetFldVal(aAddrLeftField, lAddrFromLeft);
482 	SetFldVal(aAddrTopField , lAddrFromTop );
483 	SetFldVal(aSendLeftField, lSendFromLeft);
484 	SetFldVal(aSendTopField , lSendFromTop );
485 
486 	SetFldVal(aSizeWidthField , lWidth );
487 	SetFldVal(aSizeHeightField, lHeight);
488 
489 	SetMinMax();
490 
491 	FillItem(GetParent()->aEnvItem);
492 	aPreview.Invalidate();
493 	return 0;
494 }
495 
496 // --------------------------------------------------------------------------
497 
498 
SetMinMax()499 void SwEnvFmtPage::SetMinMax()
500 {
501     long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
502     long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
503 
504 	long lWidth  = Max(lWVal, lHVal),
505 		 lHeight = Min(lWVal, lHVal);
506 
507 	// Min und Max
508 	aAddrLeftField.SetMin((long) 100 * (GetFldVal(aSendLeftField) + 566), FUNIT_TWIP);
509 	aAddrLeftField.SetMax((long) 100 * (lWidth  - 2 * 566), FUNIT_TWIP);
510 	aAddrTopField .SetMin((long) 100 * (GetFldVal(aSendTopField ) + 2 * 566), FUNIT_TWIP);
511 	aAddrTopField .SetMax((long) 100 * (lHeight - 2 * 566), FUNIT_TWIP);
512 	aSendLeftField.SetMin((long) 100 * (566), FUNIT_TWIP);
513 	aSendLeftField.SetMax((long) 100 * (GetFldVal(aAddrLeftField) - 566), FUNIT_TWIP);
514 	aSendTopField .SetMin((long) 100 * (566), FUNIT_TWIP);
515 	aSendTopField .SetMax((long) 100 * (GetFldVal(aAddrTopField ) - 2 * 566), FUNIT_TWIP);
516 
517 	// First und Last
518 	aAddrLeftField.SetFirst(aAddrLeftField.GetMin());
519 	aAddrLeftField.SetLast (aAddrLeftField.GetMax());
520 	aAddrTopField .SetFirst(aAddrTopField .GetMin());
521 	aAddrTopField .SetLast (aAddrTopField .GetMax());
522 	aSendLeftField.SetFirst(aSendLeftField.GetMin());
523 	aSendLeftField.SetLast (aSendLeftField.GetMax());
524 	aSendTopField .SetFirst(aSendTopField .GetMin());
525 	aSendTopField .SetLast (aSendTopField .GetMax());
526 
527 	// Fields neu formatieren
528 	aAddrLeftField  .Reformat();
529 	aAddrTopField   .Reformat();
530 	aSendLeftField  .Reformat();
531 	aSendTopField   .Reformat();
532 	aSizeWidthField .Reformat();
533 	aSizeHeightField.Reformat();
534 }
535 
536 // --------------------------------------------------------------------------
537 
538 
Create(Window * pParent,const SfxItemSet & rSet)539 SfxTabPage* __EXPORT SwEnvFmtPage::Create(Window* pParent, const SfxItemSet& rSet)
540 {
541 	return new SwEnvFmtPage(pParent, rSet);
542 }
543 
544 // ----------------------------------------------------------------------------
545 
546 
ActivatePage(const SfxItemSet & rSet)547 void __EXPORT SwEnvFmtPage::ActivatePage(const SfxItemSet& rSet)
548 {
549 	SfxItemSet aSet(rSet);
550 	aSet.Put(GetParent()->aEnvItem);
551 	Reset(aSet);
552 }
553 
554 // ----------------------------------------------------------------------------
555 
556 
DeactivatePage(SfxItemSet * _pSet)557 int __EXPORT SwEnvFmtPage::DeactivatePage(SfxItemSet* _pSet)
558 {
559     if( _pSet )
560         FillItemSet(*_pSet);
561 	return SfxTabPage::LEAVE_PAGE;
562 }
563 
564 // --------------------------------------------------------------------------
565 
566 
FillItem(SwEnvItem & rItem)567 void SwEnvFmtPage::FillItem(SwEnvItem& rItem)
568 {
569     rItem.lAddrFromLeft = static_cast< sal_Int32 >(GetFldVal(aAddrLeftField));
570     rItem.lAddrFromTop  = static_cast< sal_Int32 >(GetFldVal(aAddrTopField ));
571     rItem.lSendFromLeft = static_cast< sal_Int32 >(GetFldVal(aSendLeftField));
572     rItem.lSendFromTop  = static_cast< sal_Int32 >(GetFldVal(aSendTopField ));
573 
574 	sal_uInt16 nPaper = aIDs[aSizeFormatBox.GetSelectEntryPos()];
575 	if (nPaper == (sal_uInt16)PAPER_USER)
576 	{
577         long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
578         long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
579 		rItem.lWidth  = Max(lWVal, lHVal);
580 		rItem.lHeight = Min(lWVal, lHVal);
581 	}
582 	else
583 	{
584 		long lWVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Width ();
585 		long lHVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Height();
586 		rItem.lWidth  = Max(lWVal, lHVal);
587 		rItem.lHeight = Min(lWVal, lHVal);
588 	}
589 }
590 
591 // --------------------------------------------------------------------------
592 
593 
FillItemSet(SfxItemSet & rSet)594 sal_Bool __EXPORT SwEnvFmtPage::FillItemSet(SfxItemSet& rSet)
595 {
596 	FillItem(GetParent()->aEnvItem);
597 	rSet.Put(GetParent()->aEnvItem);
598 	return sal_True;
599 }
600 
601 // --------------------------------------------------------------------------
602 
603 
Reset(const SfxItemSet & rSet)604 void __EXPORT SwEnvFmtPage::Reset(const SfxItemSet& rSet)
605 {
606 	const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
607 
608 	Paper ePaper = SvxPaperInfo::GetSvxPaper(
609 		Size( Min(rItem.lWidth, rItem.lHeight),
610 		Max(rItem.lWidth, rItem.lHeight)), MAP_TWIP, sal_True);
611 	for (sal_uInt16 i = 0; i < (sal_uInt16) aIDs.Count(); i++)
612 		if (aIDs[i] == (sal_uInt16)ePaper)
613 			aSizeFormatBox.SelectEntryPos(i);
614 
615 	// Die MetricFields
616 	SetFldVal(aAddrLeftField, rItem.lAddrFromLeft);
617 	SetFldVal(aAddrTopField , rItem.lAddrFromTop );
618 	SetFldVal(aSendLeftField, rItem.lSendFromLeft);
619 	SetFldVal(aSendTopField , rItem.lSendFromTop );
620 	SetFldVal(aSizeWidthField  , Max(rItem.lWidth, rItem.lHeight));
621 	SetFldVal(aSizeHeightField , Min(rItem.lWidth, rItem.lHeight));
622 	SetMinMax();
623 
624 	DELETEZ(GetParent()->pSenderSet);
625 	DELETEZ(GetParent()->pAddresseeSet);
626 }
627 
628 
629 
630