Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : :
31 : : #include <editeng/paperinf.hxx>
32 : : #include <editeng/tstpitem.hxx>
33 : : #include <editeng/lrspitem.hxx>
34 : : #include <editeng/brshitem.hxx>
35 : : #include <vcl/msgbox.hxx>
36 : : #include <vcl/menu.hxx>
37 : :
38 : : #include <cmdid.h>
39 : : #include <frmatr.hxx>
40 : : #include <swtypes.hxx>
41 : : #include <wrtsh.hxx>
42 : : #include <view.hxx>
43 : : #include <basesh.hxx>
44 : : #include <drpcps.hxx>
45 : : #include <envfmt.hxx>
46 : : #include <fmtcol.hxx>
47 : : #include "swuipardlg.hxx"
48 : : #include <pattern.hxx>
49 : : #include <poolfmt.hxx>
50 : : #include <uiborder.hxx>
51 : : #include <uitool.hxx>
52 : :
53 : : #include <envfmt.hrc>
54 : :
55 : : #include <vector>
56 : : #include <algorithm>
57 : :
58 : : #include "swabstdlg.hxx"
59 : : #include "chrdlg.hrc"
60 : :
61 : : namespace {
62 : : /// Converts a ranges array to a list containing one entry for each
63 : : /// element covered by the ranges.
64 : : /// @param aRanges An array containing zero or more range specifications and
65 : : /// terminated by one or more zero entries. A range
66 : : /// specification is two consecutive entries that specify
67 : : /// the start and end points of the range.
68 : : /// @returns A vector containing one element for each item covered by the
69 : : /// ranges. This is not gauranteed to be sorted and may contain
70 : : /// duplicates if the original ranges contained overlaps.
71 : 0 : static std::vector<sal_uInt16> lcl_convertRangesToList(const sal_uInt16 aRanges[]) {
72 : 0 : std::vector<sal_uInt16> aVec;
73 : 0 : int i = 0;
74 : 0 : while (aRanges[i])
75 : : {
76 : 0 : for (sal_uInt16 n = aRanges[i]; n <= aRanges[i+1]; ++n)
77 : : {
78 : 0 : aVec.push_back(n);
79 : : }
80 : 0 : i += 2;
81 : : }
82 : 0 : return aVec;
83 : : }
84 : :
85 : : /// Converts a list of elements to a ranges array.
86 : : /// @param rElements Vector of the initial elements, this need not be sorted,
87 : : /// and may contain duplicate items. The vector is sorted
88 : : /// on exit from this function but may still contain duplicates.
89 : : /// @returns An array containing zero or more range specifications and
90 : : /// terminated by one or more zero entries. A range specification
91 : : /// is two consecutive entries that specify the start and end
92 : : /// points of the range. This list will be sorted and will not
93 : : /// contain any overlapping ranges.
94 : 0 : static sal_uInt16* lcl_convertListToRanges(std::vector<sal_uInt16> &rElements) {
95 : 0 : std::sort(rElements.begin(), rElements.end());
96 : 0 : std::vector<sal_uInt16> aRanges;
97 : : size_t i;
98 : 0 : for (i = 0; i < rElements.size(); ++i)
99 : : {
100 : : //Push the start of the this range.
101 : 0 : aRanges.push_back(rElements[i]);
102 : : //Seek to the end of this range.
103 : 0 : while (i + 1 < rElements.size() && rElements[i+1] - rElements[i] <= 1)
104 : : {
105 : 0 : ++i;
106 : : }
107 : : //Push the end of this range (may be the same as the start).
108 : 0 : aRanges.push_back( rElements[i] );
109 : : }
110 : :
111 : : // Convert the vector to an array with terminating zero
112 : 0 : sal_uInt16 *pNewRanges = new sal_uInt16[aRanges.size() + 1];
113 : 0 : for (i = 0; i < aRanges.size(); ++i)
114 : : {
115 : 0 : pNewRanges[i] = aRanges[i];
116 : : }
117 : 0 : pNewRanges[i] = 0;
118 : 0 : return pNewRanges;
119 : : }
120 : :
121 : : }
122 : :
123 : : namespace swui
124 : : {
125 : : SwAbstractDialogFactory * GetFactory();
126 : : }
127 : :
128 : : static PopupMenu *pMenu;
129 : : static long lUserW = 5669; // 10 cm
130 : : static long lUserH = 5669; // 10 cm
131 : :
132 : 0 : SwEnvFmtPage::SwEnvFmtPage(Window* pParent, const SfxItemSet& rSet) :
133 : :
134 : : SfxTabPage(pParent, SW_RES(TP_ENV_FMT), rSet),
135 : :
136 : : aAddrFL (this, SW_RES( FL_ADDRESSEE )),
137 : : aAddrPosInfo (this, SW_RES( TXT_ADDR_POS )),
138 : : aAddrLeftText (this, SW_RES( TXT_ADDR_LEFT )),
139 : : aAddrLeftField (this, SW_RES( FLD_ADDR_LEFT )),
140 : : aAddrTopText (this, SW_RES( TXT_ADDR_TOP )),
141 : : aAddrTopField (this, SW_RES( FLD_ADDR_TOP )),
142 : : aAddrFormatInfo (this, SW_RES( TXT_ADDR_FORMAT )),
143 : : aAddrEditButton (this, SW_RES( BTN_ADDR_EDIT )),
144 : : aSendFL (this, SW_RES( FL_SENDER )),
145 : : aSendPosInfo (this, SW_RES( TXT_SEND_POS )),
146 : : aSendLeftText (this, SW_RES( TXT_SEND_LEFT )),
147 : : aSendLeftField (this, SW_RES( FLD_SEND_LEFT )),
148 : : aSendTopText (this, SW_RES( TXT_SEND_TOP )),
149 : : aSendTopField (this, SW_RES( FLD_SEND_TOP )),
150 : : aSendFormatInfo (this, SW_RES( TXT_SEND_FORMAT )),
151 : : aSendEditButton (this, SW_RES( BTN_SEND_EDIT )),
152 : : aSizeFL (this, SW_RES( FL_SIZE )),
153 : : aSizeFormatText (this, SW_RES( TXT_SIZE_FORMAT )),
154 : : aSizeFormatBox (this, SW_RES( BOX_SIZE_FORMAT )),
155 : : aSizeWidthText (this, SW_RES( TXT_SIZE_WIDTH )),
156 : : aSizeWidthField (this, SW_RES( FLD_SIZE_WIDTH )),
157 : : aSizeHeightText (this, SW_RES( TXT_SIZE_HEIGHT )),
158 : : aSizeHeightField (this, SW_RES( FLD_SIZE_HEIGHT )),
159 : 0 : aPreview (this, SW_RES( WIN_PREVIEW ))
160 : :
161 : : {
162 : 0 : FreeResource();
163 : 0 : SetExchangeSupport();
164 : :
165 : : // Metrics
166 : 0 : FieldUnit aMetric = ::GetDfltMetric(sal_False);
167 : 0 : SetMetric(aAddrLeftField, aMetric);
168 : 0 : SetMetric(aAddrTopField, aMetric);
169 : 0 : SetMetric(aSendLeftField, aMetric);
170 : 0 : SetMetric(aSendTopField, aMetric);
171 : 0 : SetMetric(aSizeWidthField, aMetric);
172 : 0 : SetMetric(aSizeHeightField, aMetric);
173 : :
174 : : // Hook in Menues
175 : 0 : ::pMenu = new PopupMenu(SW_RES(MNU_EDIT));
176 : 0 : aAddrEditButton.SetPopupMenu(::pMenu);
177 : 0 : aSendEditButton.SetPopupMenu(::pMenu);
178 : :
179 : : // Install handlers
180 : 0 : Link aLk = LINK(this, SwEnvFmtPage, ModifyHdl);
181 : 0 : aAddrLeftField .SetUpHdl( aLk );
182 : 0 : aAddrTopField .SetUpHdl( aLk );
183 : 0 : aSendLeftField .SetUpHdl( aLk );
184 : 0 : aSendTopField .SetUpHdl( aLk );
185 : 0 : aSizeWidthField .SetUpHdl( aLk );
186 : 0 : aSizeHeightField.SetUpHdl( aLk );
187 : :
188 : 0 : aAddrLeftField .SetDownHdl( aLk );
189 : 0 : aAddrTopField .SetDownHdl( aLk );
190 : 0 : aSendLeftField .SetDownHdl( aLk );
191 : 0 : aSendTopField .SetDownHdl( aLk );
192 : 0 : aSizeWidthField .SetDownHdl( aLk );
193 : 0 : aSizeHeightField.SetDownHdl( aLk );
194 : :
195 : 0 : aAddrLeftField .SetLoseFocusHdl( aLk );
196 : 0 : aAddrTopField .SetLoseFocusHdl( aLk );
197 : 0 : aSendLeftField .SetLoseFocusHdl( aLk );
198 : 0 : aSendTopField .SetLoseFocusHdl( aLk );
199 : 0 : aSizeWidthField .SetLoseFocusHdl( aLk );
200 : 0 : aSizeHeightField.SetLoseFocusHdl( aLk );
201 : :
202 : 0 : aLk = LINK(this, SwEnvFmtPage, EditHdl );
203 : 0 : aAddrEditButton.SetSelectHdl( aLk );
204 : 0 : aSendEditButton.SetSelectHdl( aLk );
205 : :
206 : 0 : aPreview.SetBorderStyle( WINDOW_BORDER_MONO );
207 : :
208 : 0 : aSizeFormatBox .SetSelectHdl(LINK(this, SwEnvFmtPage, FormatHdl));
209 : :
210 : : // aSizeFormatBox
211 : 0 : for (sal_uInt16 i = PAPER_A3; i <= PAPER_KAI32BIG; i++)
212 : : {
213 : 0 : if (i != PAPER_USER)
214 : : {
215 : 0 : String aPaperName = SvxPaperInfo::GetName((Paper) i),
216 : 0 : aEntryName;
217 : :
218 : 0 : sal_uInt16 nPos = 0;
219 : 0 : sal_Bool bFound = sal_False;
220 : 0 : while (nPos < aSizeFormatBox.GetEntryCount() && !bFound)
221 : : {
222 : 0 : aEntryName = aSizeFormatBox.GetEntry(i);
223 : 0 : if (aEntryName < aPaperName)
224 : 0 : nPos++;
225 : : else
226 : 0 : bFound = sal_True;
227 : : }
228 : 0 : aSizeFormatBox.InsertEntry(aPaperName, nPos);
229 : 0 : aIDs.insert( aIDs.begin() + nPos, (sal_uInt16) i);
230 : : }
231 : : }
232 : 0 : aSizeFormatBox.InsertEntry(SvxPaperInfo::GetName(PAPER_USER));
233 : 0 : aIDs.push_back( (sal_uInt16) PAPER_USER );
234 : :
235 : 0 : }
236 : :
237 : 0 : SwEnvFmtPage::~SwEnvFmtPage()
238 : : {
239 : 0 : aAddrEditButton.SetPopupMenu(0);
240 : 0 : aSendEditButton.SetPopupMenu(0);
241 : 0 : delete ::pMenu;
242 : 0 : }
243 : :
244 : 0 : IMPL_LINK_INLINE_START( SwEnvFmtPage, ModifyHdl, Edit *, pEdit )
245 : : {
246 : 0 : long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
247 : 0 : long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
248 : :
249 : 0 : long lWidth = Max(lWVal, lHVal);
250 : 0 : long lHeight = Min(lWVal, lHVal);
251 : :
252 : 0 : if (pEdit == &aSizeWidthField || pEdit == &aSizeHeightField)
253 : : {
254 : : Paper ePaper = SvxPaperInfo::GetSvxPaper(
255 : 0 : Size(lHeight, lWidth), MAP_TWIP, sal_True);
256 : 0 : for (sal_uInt16 i = 0; i < (sal_uInt16)aIDs.size(); i++)
257 : 0 : if (aIDs[i] == (sal_uInt16)ePaper)
258 : 0 : aSizeFormatBox.SelectEntryPos(i);
259 : :
260 : : // remember user size
261 : 0 : if (aIDs[aSizeFormatBox.GetSelectEntryPos()] == (sal_uInt16)PAPER_USER)
262 : : {
263 : 0 : lUserW = lWidth ;
264 : 0 : lUserH = lHeight;
265 : : }
266 : :
267 : 0 : aSizeFormatBox.GetSelectHdl().Call(&aSizeFormatBox);
268 : : }
269 : : else
270 : : {
271 : 0 : FillItem(GetParent()->aEnvItem);
272 : 0 : SetMinMax();
273 : 0 : aPreview.Invalidate();
274 : : }
275 : 0 : return 0;
276 : : }
277 : 0 : IMPL_LINK_INLINE_END( SwEnvFmtPage, ModifyHdl, Edit *, pEdit )
278 : :
279 : 0 : IMPL_LINK( SwEnvFmtPage, EditHdl, MenuButton *, pButton )
280 : : {
281 : 0 : SwWrtShell* pSh = GetParent()->pSh;
282 : : OSL_ENSURE(pSh, "Shell missing");
283 : :
284 : : // determine collection-ptr
285 : 0 : sal_Bool bSender = pButton != &aAddrEditButton;
286 : :
287 : : SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool( static_cast< sal_uInt16 >(
288 : 0 : bSender ? RES_POOLCOLL_SENDADRESS : RES_POOLCOLL_JAKETADRESS));
289 : : OSL_ENSURE(pColl, "Text collection missing");
290 : :
291 : 0 : switch (pButton->GetCurItemId())
292 : : {
293 : : case MID_CHAR:
294 : : {
295 : 0 : SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
296 : :
297 : : // In order for the background color not to get ironed over:
298 : 0 : SfxAllItemSet aTmpSet(*pCollSet);
299 : :
300 : : // The CHRATR_BACKGROUND attribute gets transformed into a
301 : : // RES_BACKGROUND for the dialog and back again ...
302 : : const SfxPoolItem *pTmpBrush;
303 : :
304 : 0 : if( SFX_ITEM_SET == aTmpSet.GetItemState( RES_CHRATR_BACKGROUND,
305 : 0 : sal_True, &pTmpBrush ) )
306 : : {
307 : 0 : SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
308 : 0 : aTmpBrush.SetWhich( RES_BACKGROUND );
309 : 0 : aTmpSet.Put( aTmpBrush );
310 : : }
311 : : else
312 : 0 : aTmpSet.ClearItem( RES_BACKGROUND );
313 : :
314 : 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
315 : : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
316 : :
317 : 0 : SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg( GetParent(), pSh->GetView(), aTmpSet, DLG_CHAR ,&pColl->GetName() );
318 : : OSL_ENSURE(pDlg, "Dialogdiet fail!");
319 : 0 : if (pDlg->Execute() == RET_OK)
320 : : {
321 : 0 : SfxItemSet aOutputSet( *pDlg->GetOutputItemSet() );
322 : 0 : if( SFX_ITEM_SET == aOutputSet.GetItemState( RES_BACKGROUND,
323 : 0 : sal_False, &pTmpBrush ) )
324 : : {
325 : 0 : SvxBrushItem aTmpBrush( *((SvxBrushItem*)pTmpBrush) );
326 : 0 : aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
327 : 0 : pCollSet->Put( aTmpBrush );
328 : : }
329 : 0 : aOutputSet.ClearItem( RES_BACKGROUND );
330 : : //pColl->SetAttr( aTmpSet );
331 : 0 : pCollSet->Put(aOutputSet);
332 : : }
333 : 0 : delete pDlg;
334 : : }
335 : 0 : break;
336 : :
337 : : case MID_PARA:
338 : : {
339 : 0 : SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
340 : :
341 : : // In order for the tabulators not to get ironed over:
342 : 0 : SfxAllItemSet aTmpSet(*pCollSet);
343 : :
344 : : // Insert tabs, default tabs into ItemSet
345 : : const SvxTabStopItem& rDefTabs = (const SvxTabStopItem&)
346 : 0 : pSh->GetView().GetCurShell()->GetPool().GetDefaultItem(RES_PARATR_TABSTOP);
347 : :
348 : 0 : sal_uInt16 nDefDist = ::GetTabDist( rDefTabs );
349 : 0 : SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist );
350 : 0 : aTmpSet.Put( aDefDistItem );
351 : :
352 : : // Current tab
353 : 0 : SfxUInt16Item aTabPos( SID_ATTR_TABSTOP_POS, 0 );
354 : 0 : aTmpSet.Put( aTabPos );
355 : :
356 : : // left border as offset
357 : 0 : const long nOff = ((SvxLRSpaceItem&)aTmpSet.Get( RES_LR_SPACE )).
358 : 0 : GetTxtLeft();
359 : 0 : SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET, nOff );
360 : 0 : aTmpSet.Put( aOff );
361 : :
362 : : // set BoxInfo
363 : 0 : ::PrepareBoxInfo( aTmpSet, *pSh );
364 : :
365 : 0 : SwParaDlg *pDlg = new SwParaDlg(GetParent(), pSh->GetView(), aTmpSet, DLG_ENVELOP, &pColl->GetName());
366 : :
367 : 0 : if ( pDlg->Execute() == RET_OK )
368 : : {
369 : : // maybe relocate defaults
370 : 0 : const SfxPoolItem* pItem = 0;
371 : 0 : SfxItemSet* pOutputSet = (SfxItemSet*)pDlg->GetOutputItemSet();
372 : : sal_uInt16 nNewDist;
373 : :
374 : 0 : if( SFX_ITEM_SET == pOutputSet->GetItemState( SID_ATTR_TABSTOP_DEFAULTS,
375 : 0 : sal_False, &pItem ) &&
376 : 0 : nDefDist != (nNewDist = ((SfxUInt16Item*)pItem)->GetValue()) )
377 : : {
378 : 0 : SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP );
379 : 0 : MakeDefTabs( nNewDist, aDefTabs );
380 : 0 : pSh->SetDefault( aDefTabs );
381 : 0 : pOutputSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS );
382 : : }
383 : 0 : if( pOutputSet->Count() )
384 : : {
385 : 0 : pCollSet->Put(*pOutputSet);
386 : : }
387 : : }
388 : 0 : delete pDlg;
389 : : }
390 : 0 : break;
391 : : }
392 : 0 : return 0;
393 : : }
394 : :
395 : : /*------------------------------------------------------------------------
396 : : Description: A temporary Itemset that gets discarded at abort
397 : : ------------------------------------------------------------------------*/
398 : :
399 : 0 : SfxItemSet *SwEnvFmtPage::GetCollItemSet(SwTxtFmtColl* pColl, sal_Bool bSender)
400 : : {
401 : 0 : SfxItemSet *&pAddrSet = bSender ? GetParent()->pSenderSet : GetParent()->pAddresseeSet;
402 : :
403 : 0 : if (!pAddrSet)
404 : : {
405 : : // determine range (merge both Itemsets' ranges)
406 : 0 : const sal_uInt16 *pRanges = pColl->GetAttrSet().GetRanges();
407 : :
408 : : static sal_uInt16 const aRanges[] =
409 : : {
410 : : RES_PARATR_BEGIN, RES_PARATR_ADJUST,
411 : : RES_PARATR_TABSTOP, RES_PARATR_END-1,
412 : : RES_LR_SPACE, RES_UL_SPACE,
413 : : RES_BACKGROUND, RES_SHADOW,
414 : : SID_ATTR_TABSTOP_POS, SID_ATTR_TABSTOP_POS,
415 : : SID_ATTR_TABSTOP_DEFAULTS, SID_ATTR_TABSTOP_DEFAULTS,
416 : : SID_ATTR_TABSTOP_OFFSET, SID_ATTR_TABSTOP_OFFSET,
417 : : SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
418 : : 0, 0
419 : : };
420 : :
421 : : // BruteForce merge because MergeRange in SvTools is buggy:
422 : 0 : std::vector<sal_uInt16> pVec = ::lcl_convertRangesToList(pRanges);
423 : 0 : std::vector<sal_uInt16> aVec = ::lcl_convertRangesToList(aRanges);
424 : 0 : pVec.insert(pVec.end(), aVec.begin(), aVec.end());
425 : 0 : sal_uInt16 *pNewRanges = ::lcl_convertListToRanges(pVec);
426 : :
427 : 0 : pAddrSet = new SfxItemSet(GetParent()->pSh->GetView().GetCurShell()->GetPool(),
428 : 0 : pNewRanges);
429 : 0 : pAddrSet->Put(pColl->GetAttrSet());
430 : 0 : delete[] pNewRanges;
431 : : }
432 : :
433 : 0 : return pAddrSet;
434 : : }
435 : :
436 : 0 : IMPL_LINK_NOARG(SwEnvFmtPage, FormatHdl)
437 : : {
438 : : long lWidth;
439 : : long lHeight;
440 : : long lSendFromLeft;
441 : : long lSendFromTop;
442 : : long lAddrFromLeft;
443 : : long lAddrFromTop;
444 : :
445 : 0 : sal_uInt16 nPaper = aIDs[aSizeFormatBox.GetSelectEntryPos()];
446 : 0 : if (nPaper != (sal_uInt16)PAPER_USER)
447 : : {
448 : 0 : Size aSz = SvxPaperInfo::GetPaperSize((Paper)nPaper);
449 : 0 : lWidth = Max(aSz.Width(), aSz.Height());
450 : 0 : lHeight = Min(aSz.Width(), aSz.Height());
451 : : }
452 : : else
453 : : {
454 : 0 : lWidth = lUserW;
455 : 0 : lHeight = lUserH;
456 : : }
457 : :
458 : 0 : lSendFromLeft = 566; // 1cm
459 : 0 : lSendFromTop = 566; // 1cm
460 : 0 : lAddrFromLeft = lWidth / 2;
461 : 0 : lAddrFromTop = lHeight / 2;
462 : :
463 : 0 : SetFldVal(aAddrLeftField, lAddrFromLeft);
464 : 0 : SetFldVal(aAddrTopField , lAddrFromTop );
465 : 0 : SetFldVal(aSendLeftField, lSendFromLeft);
466 : 0 : SetFldVal(aSendTopField , lSendFromTop );
467 : :
468 : 0 : SetFldVal(aSizeWidthField , lWidth );
469 : 0 : SetFldVal(aSizeHeightField, lHeight);
470 : :
471 : 0 : SetMinMax();
472 : :
473 : 0 : FillItem(GetParent()->aEnvItem);
474 : 0 : aPreview.Invalidate();
475 : 0 : return 0;
476 : : }
477 : :
478 : 0 : void SwEnvFmtPage::SetMinMax()
479 : : {
480 : 0 : long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
481 : 0 : long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
482 : :
483 : 0 : long lWidth = Max(lWVal, lHVal),
484 : 0 : lHeight = Min(lWVal, lHVal);
485 : :
486 : : // Min and Max
487 : 0 : aAddrLeftField.SetMin((long) 100 * (GetFldVal(aSendLeftField) + 566), FUNIT_TWIP);
488 : 0 : aAddrLeftField.SetMax((long) 100 * (lWidth - 2 * 566), FUNIT_TWIP);
489 : 0 : aAddrTopField .SetMin((long) 100 * (GetFldVal(aSendTopField ) + 2 * 566), FUNIT_TWIP);
490 : 0 : aAddrTopField .SetMax((long) 100 * (lHeight - 2 * 566), FUNIT_TWIP);
491 : 0 : aSendLeftField.SetMin((long) 100 * (566), FUNIT_TWIP);
492 : 0 : aSendLeftField.SetMax((long) 100 * (GetFldVal(aAddrLeftField) - 566), FUNIT_TWIP);
493 : 0 : aSendTopField .SetMin((long) 100 * (566), FUNIT_TWIP);
494 : 0 : aSendTopField .SetMax((long) 100 * (GetFldVal(aAddrTopField ) - 2 * 566), FUNIT_TWIP);
495 : :
496 : : // First and last
497 : 0 : aAddrLeftField.SetFirst(aAddrLeftField.GetMin());
498 : 0 : aAddrLeftField.SetLast (aAddrLeftField.GetMax());
499 : 0 : aAddrTopField .SetFirst(aAddrTopField .GetMin());
500 : 0 : aAddrTopField .SetLast (aAddrTopField .GetMax());
501 : 0 : aSendLeftField.SetFirst(aSendLeftField.GetMin());
502 : 0 : aSendLeftField.SetLast (aSendLeftField.GetMax());
503 : 0 : aSendTopField .SetFirst(aSendTopField .GetMin());
504 : 0 : aSendTopField .SetLast (aSendTopField .GetMax());
505 : :
506 : : // Reformat fields
507 : 0 : aAddrLeftField .Reformat();
508 : 0 : aAddrTopField .Reformat();
509 : 0 : aSendLeftField .Reformat();
510 : 0 : aSendTopField .Reformat();
511 : 0 : aSizeWidthField .Reformat();
512 : 0 : aSizeHeightField.Reformat();
513 : 0 : }
514 : :
515 : 0 : SfxTabPage* SwEnvFmtPage::Create(Window* pParent, const SfxItemSet& rSet)
516 : : {
517 : 0 : return new SwEnvFmtPage(pParent, rSet);
518 : : }
519 : :
520 : 0 : void SwEnvFmtPage::ActivatePage(const SfxItemSet& rSet)
521 : : {
522 : 0 : SfxItemSet aSet(rSet);
523 : 0 : aSet.Put(GetParent()->aEnvItem);
524 : 0 : Reset(aSet);
525 : 0 : }
526 : :
527 : 0 : int SwEnvFmtPage::DeactivatePage(SfxItemSet* _pSet)
528 : : {
529 : 0 : if( _pSet )
530 : 0 : FillItemSet(*_pSet);
531 : 0 : return SfxTabPage::LEAVE_PAGE;
532 : : }
533 : :
534 : 0 : void SwEnvFmtPage::FillItem(SwEnvItem& rItem)
535 : : {
536 : 0 : rItem.lAddrFromLeft = static_cast< sal_Int32 >(GetFldVal(aAddrLeftField));
537 : 0 : rItem.lAddrFromTop = static_cast< sal_Int32 >(GetFldVal(aAddrTopField ));
538 : 0 : rItem.lSendFromLeft = static_cast< sal_Int32 >(GetFldVal(aSendLeftField));
539 : 0 : rItem.lSendFromTop = static_cast< sal_Int32 >(GetFldVal(aSendTopField ));
540 : :
541 : 0 : sal_uInt16 nPaper = aIDs[aSizeFormatBox.GetSelectEntryPos()];
542 : 0 : if (nPaper == (sal_uInt16)PAPER_USER)
543 : : {
544 : 0 : long lWVal = static_cast< long >(GetFldVal(aSizeWidthField ));
545 : 0 : long lHVal = static_cast< long >(GetFldVal(aSizeHeightField));
546 : 0 : rItem.lWidth = Max(lWVal, lHVal);
547 : 0 : rItem.lHeight = Min(lWVal, lHVal);
548 : : }
549 : : else
550 : : {
551 : 0 : long lWVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Width ();
552 : 0 : long lHVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Height();
553 : 0 : rItem.lWidth = Max(lWVal, lHVal);
554 : 0 : rItem.lHeight = Min(lWVal, lHVal);
555 : : }
556 : 0 : }
557 : :
558 : 0 : sal_Bool SwEnvFmtPage::FillItemSet(SfxItemSet& rSet)
559 : : {
560 : 0 : FillItem(GetParent()->aEnvItem);
561 : 0 : rSet.Put(GetParent()->aEnvItem);
562 : 0 : return sal_True;
563 : : }
564 : :
565 : 0 : void SwEnvFmtPage::Reset(const SfxItemSet& rSet)
566 : : {
567 : 0 : const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
568 : :
569 : : Paper ePaper = SvxPaperInfo::GetSvxPaper(
570 : : Size( Min(rItem.lWidth, rItem.lHeight),
571 : 0 : Max(rItem.lWidth, rItem.lHeight)), MAP_TWIP, sal_True);
572 : 0 : for (sal_uInt16 i = 0; i < (sal_uInt16) aIDs.size(); i++)
573 : 0 : if (aIDs[i] == (sal_uInt16)ePaper)
574 : 0 : aSizeFormatBox.SelectEntryPos(i);
575 : :
576 : : // Metric fields
577 : 0 : SetFldVal(aAddrLeftField, rItem.lAddrFromLeft);
578 : 0 : SetFldVal(aAddrTopField , rItem.lAddrFromTop );
579 : 0 : SetFldVal(aSendLeftField, rItem.lSendFromLeft);
580 : 0 : SetFldVal(aSendTopField , rItem.lSendFromTop );
581 : 0 : SetFldVal(aSizeWidthField , Max(rItem.lWidth, rItem.lHeight));
582 : 0 : SetFldVal(aSizeHeightField , Min(rItem.lWidth, rItem.lHeight));
583 : 0 : SetMinMax();
584 : :
585 : 0 : DELETEZ(GetParent()->pSenderSet);
586 : 0 : DELETEZ(GetParent()->pAddresseeSet);
587 : 0 : }
588 : :
589 : :
590 : :
591 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|