LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - envfmt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 273 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : 
      22             : #include <editeng/paperinf.hxx>
      23             : #include <editeng/tstpitem.hxx>
      24             : #include <editeng/lrspitem.hxx>
      25             : #include <editeng/brushitem.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <vcl/menu.hxx>
      28             : 
      29             : #include <cmdid.h>
      30             : #include <frmatr.hxx>
      31             : #include <swtypes.hxx>
      32             : #include <wrtsh.hxx>
      33             : #include <view.hxx>
      34             : #include <basesh.hxx>
      35             : #include <drpcps.hxx>
      36             : #include <envfmt.hxx>
      37             : #include <fmtcol.hxx>
      38             : #include "swuipardlg.hxx"
      39             : #include <chrdlgmodes.hxx>
      40             : #include <pattern.hxx>
      41             : #include <poolfmt.hxx>
      42             : #include <uitool.hxx>
      43             : 
      44             : #include <vector>
      45             : #include <algorithm>
      46             : 
      47             : #include <boost/scoped_array.hpp>
      48             : #include <boost/scoped_ptr.hpp>
      49             : 
      50             : #include "swabstdlg.hxx"
      51             : #include "chrdlg.hrc"
      52             : #include <swuiexp.hxx>
      53             : 
      54             : namespace {
      55             :     /// Converts a ranges array to a list containing one entry for each
      56             :     /// element covered by the ranges.
      57             :     /// @param aRanges An array containing zero or more range specifications and
      58             :     ///                terminated by one or more zero entries. A range
      59             :     ///                specification is two consecutive entries that specify
      60             :     ///                the start and end points of the range.
      61             :     /// @returns A vector containing one element for each item covered by the
      62             :     ///          ranges. This is not guaranteed to be sorted and may contain
      63             :     ///          duplicates if the original ranges contained overlaps.
      64           0 :     static std::vector<sal_uInt16> lcl_convertRangesToList(const sal_uInt16 aRanges[]) {
      65           0 :         std::vector<sal_uInt16> aVec;
      66           0 :         int i = 0;
      67           0 :         while (aRanges[i])
      68             :         {
      69           0 :             for (sal_uInt16 n = aRanges[i]; n <= aRanges[i+1]; ++n)
      70             :             {
      71           0 :                 aVec.push_back(n);
      72             :             }
      73           0 :             i += 2;
      74             :         }
      75           0 :         return aVec;
      76             :     }
      77             : 
      78             :     /// Converts a list of elements to a ranges array.
      79             :     /// @param rElements Vector of the initial elements, this need not be sorted,
      80             :     ///                  and may contain duplicate items. The vector is sorted
      81             :     ///                  on exit from this function but may still contain duplicates.
      82             :     /// @returns An array containing zero or more range specifications and
      83             :     ///          terminated by one or more zero entries. A range specification
      84             :     ///          is two consecutive entries that specify the start and end
      85             :     ///          points of the range. This list will be sorted and will not
      86             :     ///          contain any overlapping ranges.
      87           0 :     static sal_uInt16* lcl_convertListToRanges(std::vector<sal_uInt16> &rElements) {
      88           0 :         std::sort(rElements.begin(), rElements.end());
      89           0 :         std::vector<sal_uInt16> aRanges;
      90             :         size_t i;
      91           0 :         for (i = 0; i < rElements.size(); ++i)
      92             :         {
      93             :             //Push the start of the this range.
      94           0 :             aRanges.push_back(rElements[i]);
      95             :             //Seek to the end of this range.
      96           0 :             while (i + 1 < rElements.size() && rElements[i+1] - rElements[i] <= 1)
      97             :             {
      98           0 :                 ++i;
      99             :             }
     100             :             //Push the end of this range (may be the same as the start).
     101           0 :             aRanges.push_back( rElements[i] );
     102             :         }
     103             : 
     104             :         // Convert the vector to an array with terminating zero
     105           0 :         sal_uInt16 *pNewRanges = new sal_uInt16[aRanges.size() + 1];
     106           0 :         for (i = 0; i < aRanges.size(); ++i)
     107             :         {
     108           0 :             pNewRanges[i] = aRanges[i];
     109             :         }
     110           0 :         pNewRanges[i] = 0;
     111           0 :         return pNewRanges;
     112             :     }
     113             : 
     114             : }
     115             : 
     116             : static long lUserW = 5669; // 10 cm
     117             : static long lUserH = 5669; // 10 cm
     118             : 
     119           0 : SwEnvFormatPage::SwEnvFormatPage(vcl::Window* pParent, const SfxItemSet& rSet)
     120             :     : SfxTabPage(pParent, "EnvFormatPage",
     121           0 :         "modules/swriter/ui/envformatpage.ui", &rSet)
     122             : {
     123           0 :     get(m_pAddrLeftField, "leftaddr");
     124           0 :     get(m_pAddrTopField, "topaddr");
     125           0 :     get(m_pSendLeftField,"leftsender");
     126           0 :     get(m_pSendTopField, "topsender");
     127           0 :     get(m_pSizeFormatBox, "format");
     128           0 :     get(m_pSizeWidthField, "width");
     129           0 :     get(m_pSizeHeightField, "height");
     130           0 :     get(m_pPreview, "preview");
     131           0 :     get(m_pAddrEditButton, "addredit");
     132           0 :     get(m_pSendEditButton, "senderedit");
     133           0 :     SetExchangeSupport();
     134             : 
     135             :     // Metrics
     136           0 :     FieldUnit aMetric = ::GetDfltMetric(false);
     137           0 :     SetMetric(*m_pAddrLeftField, aMetric);
     138           0 :     SetMetric(*m_pAddrTopField, aMetric);
     139           0 :     SetMetric(*m_pSendLeftField, aMetric);
     140           0 :     SetMetric(*m_pSendTopField, aMetric);
     141           0 :     SetMetric(*m_pSizeWidthField, aMetric);
     142           0 :     SetMetric(*m_pSizeHeightField, aMetric);
     143             : 
     144             :     // Install handlers
     145           0 :     Link<> aLk = LINK(this, SwEnvFormatPage, ModifyHdl);
     146           0 :     m_pAddrLeftField->SetUpHdl( aLk );
     147           0 :     m_pAddrTopField->SetUpHdl( aLk );
     148           0 :     m_pSendLeftField->SetUpHdl( aLk );
     149           0 :     m_pSendTopField->SetUpHdl( aLk );
     150           0 :     m_pSizeWidthField->SetUpHdl( aLk );
     151           0 :     m_pSizeHeightField->SetUpHdl( aLk );
     152             : 
     153           0 :     m_pAddrLeftField->SetDownHdl( aLk );
     154           0 :     m_pAddrTopField->SetDownHdl( aLk );
     155           0 :     m_pSendLeftField->SetDownHdl( aLk );
     156           0 :     m_pSendTopField->SetDownHdl( aLk );
     157           0 :     m_pSizeWidthField->SetDownHdl( aLk );
     158           0 :     m_pSizeHeightField->SetDownHdl( aLk );
     159             : 
     160           0 :     m_pAddrLeftField->SetLoseFocusHdl( aLk );
     161           0 :     m_pAddrTopField->SetLoseFocusHdl( aLk );
     162           0 :     m_pSendLeftField->SetLoseFocusHdl( aLk );
     163           0 :     m_pSendTopField->SetLoseFocusHdl( aLk );
     164           0 :     m_pSizeWidthField->SetLoseFocusHdl( aLk );
     165           0 :     m_pSizeHeightField->SetLoseFocusHdl( aLk );
     166             : 
     167           0 :     Link<MenuButton *, void> aLk2 = LINK(this, SwEnvFormatPage, EditHdl );
     168           0 :     m_pAddrEditButton->SetSelectHdl( aLk2 );
     169           0 :     m_pSendEditButton->SetSelectHdl( aLk2 );
     170             : 
     171           0 :     m_pPreview->SetBorderStyle( WindowBorderStyle::MONO );
     172             : 
     173           0 :     m_pSizeFormatBox->SetSelectHdl(LINK(this, SwEnvFormatPage, FormatHdl));
     174             : 
     175             :     // m_pSizeFormatBox
     176           0 :     for (sal_uInt16 i = PAPER_A3; i <= PAPER_KAI32BIG; i++)
     177             :     {
     178           0 :         if (i != PAPER_USER)
     179             :         {
     180           0 :             const OUString aPaperName = SvxPaperInfo::GetName((Paper) i);
     181             : 
     182           0 :             if (aPaperName.isEmpty())
     183           0 :                 continue;
     184             : 
     185           0 :             sal_Int32 nPos = 0;
     186           0 :             while (nPos < m_pSizeFormatBox->GetEntryCount() &&
     187           0 :                    m_pSizeFormatBox->GetEntry(nPos) < aPaperName)
     188             :             {
     189           0 :                 ++nPos;
     190             :             }
     191           0 :             m_pSizeFormatBox->InsertEntry(aPaperName, nPos);
     192           0 :             aIDs.insert( aIDs.begin() + nPos, i);
     193             :         }
     194             :     }
     195           0 :     m_pSizeFormatBox->InsertEntry(SvxPaperInfo::GetName(PAPER_USER));
     196           0 :     aIDs.push_back( (sal_uInt16) PAPER_USER );
     197             : 
     198           0 : }
     199             : 
     200           0 : SwEnvFormatPage::~SwEnvFormatPage()
     201             : {
     202           0 :     disposeOnce();
     203           0 : }
     204             : 
     205           0 : void SwEnvFormatPage::dispose()
     206             : {
     207           0 :     m_pAddrLeftField.clear();
     208           0 :     m_pAddrTopField.clear();
     209           0 :     m_pAddrEditButton.clear();
     210           0 :     m_pSendLeftField.clear();
     211           0 :     m_pSendTopField.clear();
     212           0 :     m_pSendEditButton.clear();
     213           0 :     m_pSizeFormatBox.clear();
     214           0 :     m_pSizeWidthField.clear();
     215           0 :     m_pSizeHeightField.clear();
     216           0 :     m_pPreview.clear();
     217           0 :     SfxTabPage::dispose();
     218           0 : }
     219             : 
     220             : 
     221           0 : IMPL_LINK( SwEnvFormatPage, ModifyHdl, Edit *, pEdit )
     222             : {
     223           0 :     long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
     224           0 :     long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));
     225             : 
     226           0 :     long lWidth  = std::max(lWVal, lHVal);
     227           0 :     long lHeight = std::min(lWVal, lHVal);
     228             : 
     229           0 :     if (pEdit == m_pSizeWidthField || pEdit == m_pSizeHeightField)
     230             :     {
     231           0 :         long nRotatedWidth = lHeight;
     232           0 :         long nRotatedHeight = lWidth;
     233             :         Paper ePaper = SvxPaperInfo::GetSvxPaper(
     234           0 :             Size(nRotatedWidth, nRotatedHeight), MAP_TWIP, true);
     235           0 :         for (size_t i = 0; i < aIDs.size(); ++i)
     236           0 :             if (aIDs[i] == (sal_uInt16)ePaper)
     237           0 :                 m_pSizeFormatBox->SelectEntryPos(static_cast<sal_Int32>(i));
     238             : 
     239             :         // remember user size
     240           0 :         if (aIDs[m_pSizeFormatBox->GetSelectEntryPos()] == (sal_uInt16)PAPER_USER)
     241             :         {
     242           0 :             lUserW = lWidth ;
     243           0 :             lUserH = lHeight;
     244             :         }
     245             : 
     246           0 :         m_pSizeFormatBox->GetSelectHdl().Call(m_pSizeFormatBox);
     247             :     }
     248             :     else
     249             :     {
     250           0 :         FillItem(GetParentSwEnvDlg()->aEnvItem);
     251           0 :         SetMinMax();
     252           0 :         m_pPreview->Invalidate();
     253             :     }
     254           0 :     return 0;
     255             : }
     256             : 
     257           0 : IMPL_LINK_TYPED( SwEnvFormatPage, EditHdl, MenuButton *, pButton, void )
     258             : {
     259           0 :     SwWrtShell* pSh = GetParentSwEnvDlg()->pSh;
     260             :     OSL_ENSURE(pSh, "Shell missing");
     261             : 
     262             :     // determine collection-ptr
     263           0 :     bool bSender = pButton != m_pAddrEditButton;
     264             : 
     265             :     SwTextFormatColl* pColl = pSh->GetTextCollFromPool( static_cast< sal_uInt16 >(
     266           0 :         bSender ? RES_POOLCOLL_SENDADRESS : RES_POOLCOLL_JAKETADRESS));
     267             :     OSL_ENSURE(pColl, "Text collection missing");
     268             : 
     269           0 :     OString sIdent(pButton->GetCurItemIdent());
     270             : 
     271           0 :     if (sIdent == "character")
     272             :     {
     273           0 :         SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
     274             : 
     275             :         // In order for the background color not to get ironed over:
     276           0 :         SfxAllItemSet aTmpSet(*pCollSet);
     277           0 :         ::ConvertAttrCharToGen(aTmpSet, CONV_ATTR_ENV);
     278             : 
     279           0 :         SwAbstractDialogFactory* pFact = swui::GetFactory();
     280             :         OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     281             : 
     282           0 :         const OUString sFormatStr = pColl->GetName();
     283           0 :         boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSwCharDlg(GetParentSwEnvDlg(), pSh->GetView(), aTmpSet, DLG_CHAR_ENV, &sFormatStr));
     284             :         OSL_ENSURE(pDlg, "Dialog creation failed!");
     285           0 :         if (pDlg->Execute() == RET_OK)
     286             :         {
     287           0 :             SfxItemSet aOutputSet( *pDlg->GetOutputItemSet() );
     288           0 :             ::ConvertAttrGenToChar(aOutputSet, aTmpSet, CONV_ATTR_ENV);
     289           0 :             pCollSet->Put(aOutputSet);
     290           0 :         }
     291             :     }
     292           0 :     else if (sIdent == "paragraph")
     293             :     {
     294           0 :         SfxItemSet *pCollSet = GetCollItemSet(pColl, bSender);
     295             : 
     296             :         // In order for the tabulators not to get ironed over:
     297           0 :         SfxAllItemSet aTmpSet(*pCollSet);
     298             : 
     299             :         // Insert tabs, default tabs into ItemSet
     300             :         const SvxTabStopItem& rDefTabs = static_cast<const SvxTabStopItem&>(
     301           0 :             pSh->GetView().GetCurShell()->GetPool().GetDefaultItem(RES_PARATR_TABSTOP));
     302             : 
     303           0 :         const sal_uInt16 nDefDist = static_cast<sal_uInt16>(::GetTabDist( rDefTabs ));
     304           0 :         SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist );
     305           0 :         aTmpSet.Put( aDefDistItem );
     306             : 
     307             :         // Current tab
     308           0 :         SfxUInt16Item aTabPos( SID_ATTR_TABSTOP_POS, 0 );
     309           0 :         aTmpSet.Put( aTabPos );
     310             : 
     311             :         // left border as offset
     312           0 :         const long nOff = static_cast<const SvxLRSpaceItem&>(aTmpSet.Get( RES_LR_SPACE )).
     313           0 :                                                             GetTextLeft();
     314           0 :         SfxInt32Item aOff( SID_ATTR_TABSTOP_OFFSET, nOff );
     315           0 :         aTmpSet.Put( aOff );
     316             : 
     317             :         // set BoxInfo
     318           0 :         ::PrepareBoxInfo( aTmpSet, *pSh );
     319             : 
     320           0 :         const OUString sFormatStr = pColl->GetName();
     321           0 :         VclPtrInstance< SwParaDlg > pDlg(GetParentSwEnvDlg(), pSh->GetView(), aTmpSet, DLG_ENVELOP, &sFormatStr);
     322             : 
     323           0 :         if ( pDlg->Execute() == RET_OK )
     324             :         {
     325             :             // maybe relocate defaults
     326           0 :             const SfxPoolItem* pItem = 0;
     327           0 :             SfxItemSet* pOutputSet = const_cast<SfxItemSet*>(pDlg->GetOutputItemSet());
     328             :             sal_uInt16 nNewDist;
     329             : 
     330           0 :             if( SfxItemState::SET == pOutputSet->GetItemState( SID_ATTR_TABSTOP_DEFAULTS,
     331           0 :                 false, &pItem ) &&
     332           0 :                 nDefDist != (nNewDist = static_cast<const SfxUInt16Item*>(pItem)->GetValue()) )
     333             :             {
     334           0 :                 SvxTabStopItem aDefTabs( 0, 0, SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP );
     335           0 :                 MakeDefTabs( nNewDist, aDefTabs );
     336           0 :                 pSh->SetDefault( aDefTabs );
     337           0 :                 pOutputSet->ClearItem( SID_ATTR_TABSTOP_DEFAULTS );
     338             :             }
     339           0 :             if( pOutputSet->Count() )
     340             :             {
     341           0 :                 pCollSet->Put(*pOutputSet);
     342             :             }
     343           0 :         }
     344           0 :     }
     345           0 : }
     346             : 
     347             : // A temporary Itemset that gets discarded at abort
     348           0 : SfxItemSet *SwEnvFormatPage::GetCollItemSet(SwTextFormatColl* pColl, bool bSender)
     349             : {
     350           0 :     SfxItemSet *&pAddrSet = bSender ? GetParentSwEnvDlg()->pSenderSet : GetParentSwEnvDlg()->pAddresseeSet;
     351           0 :     if (!pAddrSet)
     352             :     {
     353             :         // determine range (merge both Itemsets' ranges)
     354           0 :         const sal_uInt16 *pRanges = pColl->GetAttrSet().GetRanges();
     355             : 
     356             :         static sal_uInt16 const aRanges[] =
     357             :         {
     358             :             RES_PARATR_BEGIN, RES_PARATR_ADJUST,
     359             :             RES_PARATR_TABSTOP, RES_PARATR_END-1,
     360             :             RES_LR_SPACE, RES_UL_SPACE,
     361             :             RES_BACKGROUND, RES_SHADOW,
     362             :             SID_ATTR_TABSTOP_POS, SID_ATTR_TABSTOP_POS,
     363             :             SID_ATTR_TABSTOP_DEFAULTS, SID_ATTR_TABSTOP_DEFAULTS,
     364             :             SID_ATTR_TABSTOP_OFFSET, SID_ATTR_TABSTOP_OFFSET,
     365             :             SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
     366             :             0, 0
     367             :         };
     368             : 
     369             :         // BruteForce merge because MergeRange in SvTools is buggy:
     370           0 :         std::vector<sal_uInt16> pVec = ::lcl_convertRangesToList(pRanges);
     371           0 :         std::vector<sal_uInt16> aVec = ::lcl_convertRangesToList(aRanges);
     372           0 :         pVec.insert(pVec.end(), aVec.begin(), aVec.end());
     373           0 :         boost::scoped_array<sal_uInt16> pNewRanges(::lcl_convertListToRanges(pVec));
     374             : 
     375           0 :         pAddrSet = new SfxItemSet(GetParentSwEnvDlg()->pSh->GetView().GetCurShell()->GetPool(),
     376           0 :                                   pNewRanges.get());
     377           0 :         pAddrSet->Put(pColl->GetAttrSet());
     378             :     }
     379             : 
     380           0 :     return pAddrSet;
     381             : }
     382             : 
     383           0 : IMPL_LINK_NOARG(SwEnvFormatPage, FormatHdl)
     384             : {
     385             :     long lWidth;
     386             :     long lHeight;
     387             :     long lSendFromLeft;
     388             :     long lSendFromTop;
     389             :     long lAddrFromLeft;
     390             :     long lAddrFromTop;
     391             : 
     392           0 :     const sal_uInt16 nPaper = aIDs[m_pSizeFormatBox->GetSelectEntryPos()];
     393           0 :     if (nPaper != (sal_uInt16)PAPER_USER)
     394             :     {
     395           0 :         Size aSz = SvxPaperInfo::GetPaperSize((Paper)nPaper);
     396           0 :         lWidth  = std::max(aSz.Width(), aSz.Height());
     397           0 :         lHeight = std::min(aSz.Width(), aSz.Height());
     398             :     }
     399             :     else
     400             :     {
     401           0 :         lWidth  = lUserW;
     402           0 :         lHeight = lUserH;
     403             :     }
     404             : 
     405           0 :     lSendFromLeft = 566;            // 1cm
     406           0 :     lSendFromTop  = 566;            // 1cm
     407           0 :     lAddrFromLeft = lWidth  / 2;
     408           0 :     lAddrFromTop  = lHeight / 2;
     409             : 
     410           0 :     SetFieldVal(*m_pAddrLeftField, lAddrFromLeft);
     411           0 :     SetFieldVal(*m_pAddrTopField , lAddrFromTop );
     412           0 :     SetFieldVal(*m_pSendLeftField, lSendFromLeft);
     413           0 :     SetFieldVal(*m_pSendTopField , lSendFromTop );
     414             : 
     415           0 :     SetFieldVal(*m_pSizeWidthField , lWidth );
     416           0 :     SetFieldVal(*m_pSizeHeightField, lHeight);
     417             : 
     418           0 :     SetMinMax();
     419             : 
     420           0 :     FillItem(GetParentSwEnvDlg()->aEnvItem);
     421           0 :     m_pPreview->Invalidate();
     422           0 :     return 0;
     423             : }
     424             : 
     425           0 : void SwEnvFormatPage::SetMinMax()
     426             : {
     427           0 :     long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
     428           0 :     long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));
     429             : 
     430           0 :     long lWidth  = std::max(lWVal, lHVal),
     431           0 :          lHeight = std::min(lWVal, lHVal);
     432             : 
     433             :     // Min and Max
     434           0 :     m_pAddrLeftField->SetMin((long) 100 * (GetFieldVal(*m_pSendLeftField) + 566), FUNIT_TWIP);
     435           0 :     m_pAddrLeftField->SetMax((long) 100 * (lWidth  - 2 * 566), FUNIT_TWIP);
     436           0 :     m_pAddrTopField->SetMin((long) 100 * (GetFieldVal(*m_pSendTopField ) + 2 * 566), FUNIT_TWIP);
     437           0 :     m_pAddrTopField->SetMax((long) 100 * (lHeight - 2 * 566), FUNIT_TWIP);
     438           0 :     m_pSendLeftField->SetMin((long) 100 * (566), FUNIT_TWIP);
     439           0 :     m_pSendLeftField->SetMax((long) 100 * (GetFieldVal(*m_pAddrLeftField) - 566), FUNIT_TWIP);
     440           0 :     m_pSendTopField->SetMin((long) 100 * (566), FUNIT_TWIP);
     441           0 :     m_pSendTopField->SetMax((long) 100 * (GetFieldVal(*m_pAddrTopField ) - 2 * 566), FUNIT_TWIP);
     442             : 
     443             :     // First and last
     444           0 :     m_pAddrLeftField->SetFirst(m_pAddrLeftField->GetMin());
     445           0 :     m_pAddrLeftField->SetLast(m_pAddrLeftField->GetMax());
     446           0 :     m_pAddrTopField->SetFirst(m_pAddrTopField->GetMin());
     447           0 :     m_pAddrTopField->SetLast(m_pAddrTopField->GetMax());
     448           0 :     m_pSendLeftField->SetFirst(m_pSendLeftField->GetMin());
     449           0 :     m_pSendLeftField->SetLast(m_pSendLeftField->GetMax());
     450           0 :     m_pSendTopField->SetFirst(m_pSendTopField->GetMin());
     451           0 :     m_pSendTopField->SetLast(m_pSendTopField->GetMax());
     452             : 
     453             :     // Reformat fields
     454           0 :     m_pAddrLeftField->Reformat();
     455           0 :     m_pAddrTopField->Reformat();
     456           0 :     m_pSendLeftField->Reformat();
     457           0 :     m_pSendTopField->Reformat();
     458           0 :     m_pSizeWidthField->Reformat();
     459           0 :     m_pSizeHeightField->Reformat();
     460           0 : }
     461             : 
     462           0 : VclPtr<SfxTabPage> SwEnvFormatPage::Create(vcl::Window* pParent, const SfxItemSet* rSet)
     463             : {
     464           0 :     return VclPtr<SwEnvFormatPage>::Create(pParent, *rSet);
     465             : }
     466             : 
     467           0 : void SwEnvFormatPage::ActivatePage(const SfxItemSet& rSet)
     468             : {
     469           0 :     SfxItemSet aSet(rSet);
     470           0 :     aSet.Put(GetParentSwEnvDlg()->aEnvItem);
     471           0 :     Reset(&aSet);
     472           0 : }
     473             : 
     474           0 : SfxTabPage::sfxpg SwEnvFormatPage::DeactivatePage(SfxItemSet* _pSet)
     475             : {
     476           0 :     if( _pSet )
     477           0 :         FillItemSet(_pSet);
     478           0 :     return SfxTabPage::LEAVE_PAGE;
     479             : }
     480             : 
     481           0 : void SwEnvFormatPage::FillItem(SwEnvItem& rItem)
     482             : {
     483           0 :     rItem.lAddrFromLeft = static_cast< sal_Int32 >(GetFieldVal(*m_pAddrLeftField));
     484           0 :     rItem.lAddrFromTop  = static_cast< sal_Int32 >(GetFieldVal(*m_pAddrTopField ));
     485           0 :     rItem.lSendFromLeft = static_cast< sal_Int32 >(GetFieldVal(*m_pSendLeftField));
     486           0 :     rItem.lSendFromTop  = static_cast< sal_Int32 >(GetFieldVal(*m_pSendTopField ));
     487             : 
     488           0 :     const sal_uInt16 nPaper = aIDs[m_pSizeFormatBox->GetSelectEntryPos()];
     489           0 :     if (nPaper == (sal_uInt16)PAPER_USER)
     490             :     {
     491           0 :         long lWVal = static_cast< long >(GetFieldVal(*m_pSizeWidthField ));
     492           0 :         long lHVal = static_cast< long >(GetFieldVal(*m_pSizeHeightField));
     493           0 :         rItem.lWidth  = std::max(lWVal, lHVal);
     494           0 :         rItem.lHeight = std::min(lWVal, lHVal);
     495             :     }
     496             :     else
     497             :     {
     498           0 :         long lWVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Width ();
     499           0 :         long lHVal = SvxPaperInfo::GetPaperSize((Paper)nPaper).Height();
     500           0 :         rItem.lWidth  = std::max(lWVal, lHVal);
     501           0 :         rItem.lHeight = std::min(lWVal, lHVal);
     502             :     }
     503           0 : }
     504             : 
     505           0 : bool SwEnvFormatPage::FillItemSet(SfxItemSet* rSet)
     506             : {
     507           0 :     FillItem(GetParentSwEnvDlg()->aEnvItem);
     508           0 :     rSet->Put(GetParentSwEnvDlg()->aEnvItem);
     509           0 :     return true;
     510             : }
     511             : 
     512           0 : void SwEnvFormatPage::Reset(const SfxItemSet* rSet)
     513             : {
     514           0 :     const SwEnvItem& rItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP));
     515             : 
     516             :     Paper ePaper = SvxPaperInfo::GetSvxPaper(
     517           0 :         Size( std::min(rItem.lWidth, rItem.lHeight),
     518           0 :         std::max(rItem.lWidth, rItem.lHeight)), MAP_TWIP, true);
     519           0 :     for (size_t i = 0; i < aIDs.size(); ++i)
     520           0 :         if (aIDs[i] == (sal_uInt16)ePaper)
     521           0 :             m_pSizeFormatBox->SelectEntryPos(static_cast<sal_Int32>(i));
     522             : 
     523             :     // Metric fields
     524           0 :     SetFieldVal(*m_pAddrLeftField, rItem.lAddrFromLeft);
     525           0 :     SetFieldVal(*m_pAddrTopField, rItem.lAddrFromTop );
     526           0 :     SetFieldVal(*m_pSendLeftField, rItem.lSendFromLeft);
     527           0 :     SetFieldVal(*m_pSendTopField, rItem.lSendFromTop );
     528           0 :     SetFieldVal(*m_pSizeWidthField  , std::max(rItem.lWidth, rItem.lHeight));
     529           0 :     SetFieldVal(*m_pSizeHeightField , std::min(rItem.lWidth, rItem.lHeight));
     530           0 :     SetMinMax();
     531             : 
     532           0 :     DELETEZ(GetParentSwEnvDlg()->pSenderSet);
     533           0 :     DELETEZ(GetParentSwEnvDlg()->pAddresseeSet);
     534           0 : }
     535             : 
     536             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11