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

Generated by: LCOV version 1.10