LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/misc - pgfnote.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 157 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 <cmdid.h>
      21             : #include <hintids.hxx>
      22             : #include <svx/dialogs.hrc>
      23             : #include <svx/drawitem.hxx>
      24             : #include <svx/xtable.hxx>               // XColorList
      25             : #include <sal/macros.h>
      26             : #include <vcl/field.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <unotools/localedatawrapper.hxx>
      29             : #include <unotools/syslocale.hxx>
      30             : #include <editeng/borderline.hxx>
      31             : #include <editeng/sizeitem.hxx>
      32             : #include <svx/pageitem.hxx>
      33             : #include <svl/eitem.hxx>
      34             : #include <editeng/ulspitem.hxx>
      35             : #include <uitool.hxx>
      36             : #include <pagedesc.hxx>
      37             : #include <pgfnote.hxx>
      38             : #include <uiitems.hxx>
      39             : #include <sfx2/objsh.hxx>
      40             : 
      41             : #include <globals.hrc>
      42             : #include <misc.hrc>
      43             : #include <pgfnote.hrc>
      44             : 
      45             : 
      46             : using namespace ::com::sun::star;
      47             : 
      48             : static sal_uInt16 aPageRg[] = {
      49             :     FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
      50             :     0
      51             : };
      52             : 
      53             : /*------------------------------------------------------------------------
      54             :  Description:  handler to switch between the different possibilities
      55             :                how the footnote region's height can be set.
      56             : ------------------------------------------------------------------------*/
      57           0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightPage)
      58             : {
      59           0 :     aMaxHeightEdit.Enable(sal_False);
      60           0 :     return 0;
      61             : }
      62           0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightPage)
      63             : 
      64             : 
      65           0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightMetric)
      66             : {
      67           0 :     aMaxHeightEdit.Enable();
      68           0 :     aMaxHeightEdit.GrabFocus();
      69           0 :     return 0;
      70             : }
      71           0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightMetric)
      72             : 
      73             : /*------------------------------------------------------------------------
      74             :  Description:   handler limit values
      75             : ------------------------------------------------------------------------*/
      76           0 : IMPL_LINK_NOARG(SwFootNotePage, HeightModify)
      77             : {
      78             :     aMaxHeightEdit.SetMax(aMaxHeightEdit.Normalize(lMaxHeight -
      79           0 :             (aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)) +
      80           0 :             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
      81           0 :             FUNIT_TWIP);
      82           0 :     if(aMaxHeightEdit.GetValue() < 0)
      83           0 :         aMaxHeightEdit.SetValue(0);
      84             :     aDistEdit.SetMax(aDistEdit.Normalize(lMaxHeight -
      85           0 :             (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
      86           0 :             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
      87           0 :             FUNIT_TWIP);
      88           0 :     if(aDistEdit.GetValue() < 0)
      89           0 :         aDistEdit.SetValue(0);
      90             :     aLineDistEdit.SetMax(aLineDistEdit.Normalize(lMaxHeight -
      91           0 :             (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
      92           0 :             aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)))),
      93           0 :             FUNIT_TWIP);
      94           0 :     return 0;
      95             : }
      96             : 
      97           0 : IMPL_LINK_NOARG(SwFootNotePage, LineWidthChanged_Impl)
      98             : {
      99             :     sal_Int64 nVal = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
     100             :                 aLineWidthEdit.GetValue( ),
     101           0 :                 aLineWidthEdit.GetDecimalDigits( ),
     102           0 :                 aLineWidthEdit.GetUnit(), MAP_TWIP ));
     103           0 :     aLineTypeBox.SetWidth( nVal );
     104             : 
     105           0 :     return 0;
     106             : }
     107             : 
     108           0 : IMPL_LINK_NOARG(SwFootNotePage, LineColorSelected_Impl)
     109             : {
     110           0 :     aLineTypeBox.SetColor( aLineColorBox.GetSelectEntryColor() );
     111           0 :     return 0;
     112             : }
     113             : 
     114             : // CTOR / DTOR -----------------------------------------------------------
     115             : 
     116           0 : SwFootNotePage::SwFootNotePage(Window *pParent, const SfxItemSet &rSet) :
     117             : 
     118             :     SfxTabPage(pParent, SW_RES(TP_FOOTNOTE_PAGE), rSet),
     119             :     aPosHeader(this,        SW_RES(FL_FOOTNOTE_SIZE)),
     120             :     aMaxHeightPageBtn(this, SW_RES(RB_MAXHEIGHT_PAGE)),
     121             :     aMaxHeightBtn(this,     SW_RES(RB_MAXHEIGHT)),
     122             :     aMaxHeightEdit(this,    SW_RES(ED_MAXHEIGHT)),
     123             :     aDistLbl(this,          SW_RES(FT_DIST)),
     124             :     aDistEdit(this,         SW_RES(ED_DIST)),
     125             : 
     126             :     aLineHeader(this,       SW_RES(FL_LINE)),
     127             :     aLinePosLbl(this,       SW_RES(FT_LINEPOS)),
     128             :     aLinePosBox(this,       SW_RES(DLB_LINEPOS)),
     129             :     aLineTypeLbl(this,      SW_RES(FT_LINETYPE)),
     130             :     aLineTypeBox(this,      SW_RES(DLB_LINETYPE)),
     131             :     aLineWidthLbl(this,     SW_RES(FT_LINEWIDTH)),
     132             :     aLineWidthEdit(this,    SW_RES(ED_LINEWIDTH)),
     133             :     aLineColorLbl(this,     SW_RES(FT_LINECOLOR)),
     134             :     aLineColorBox(this,     SW_RES(DLB_LINECOLOR)),
     135             :     aLineLengthLbl(this,    SW_RES(FT_LINELENGTH)),
     136             :     aLineLengthEdit(this,   SW_RES(ED_LINELENGTH)),
     137             :     aLineDistLbl(this,      SW_RES(FT_LINEDIST)),
     138           0 :     aLineDistEdit(this,     SW_RES(ED_LINEDIST))
     139             :     {
     140           0 :     FreeResource();
     141             : 
     142           0 :     SetExchangeSupport();
     143           0 :     FieldUnit aMetric = ::GetDfltMetric(sal_False);
     144           0 :     SetMetric( aMaxHeightEdit,  aMetric );
     145           0 :     SetMetric( aDistEdit,       aMetric );
     146           0 :     SetMetric( aLineDistEdit,   aMetric );
     147           0 :     MeasurementSystem eSys = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
     148           0 :     long nHeightValue = MEASURE_METRIC != eSys ? 1440 : 1134;
     149           0 :     aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(nHeightValue),FUNIT_TWIP);
     150           0 :     aMaxHeightEdit.SetAccessibleRelationLabeledBy(&aMaxHeightBtn);
     151           0 : }
     152             : 
     153           0 : SwFootNotePage::~SwFootNotePage()
     154             : {
     155           0 : }
     156             : 
     157           0 : SfxTabPage* SwFootNotePage::Create(Window *pParent, const SfxItemSet &rSet)
     158             : {
     159           0 :     return new SwFootNotePage(pParent, rSet);
     160             : }
     161             : 
     162           0 : void SwFootNotePage::Reset(const SfxItemSet &rSet)
     163             : {
     164             :     // if no example exists, otherwise Init here in Activate
     165           0 :     SwPageFtnInfo* pDefFtnInfo = 0;
     166             :     const SwPageFtnInfo* pFtnInfo;
     167           0 :     const SfxPoolItem* pItem = SfxTabPage::GetItem(rSet, FN_PARAM_FTN_INFO);
     168           0 :     if( pItem )
     169             :     {
     170           0 :         pFtnInfo = &((const SwPageFtnInfoItem*)pItem)->GetPageFtnInfo();
     171             :     }
     172             :     else
     173             :     {
     174             :         // when "standard" is being activated the footnote item is deleted,
     175             :         // that's why a footnote structure has to be created here
     176           0 :         pDefFtnInfo = new SwPageFtnInfo();
     177           0 :         pFtnInfo = pDefFtnInfo;
     178             :     }
     179             :         // footnote area's height
     180           0 :     SwTwips lHeight = pFtnInfo->GetHeight();
     181           0 :     if(lHeight)
     182             :     {
     183           0 :         aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(lHeight),FUNIT_TWIP);
     184           0 :         aMaxHeightBtn.Check(sal_True);
     185             :     }
     186             :     else
     187             :     {
     188           0 :         aMaxHeightPageBtn.Check(sal_True);
     189           0 :         aMaxHeightEdit.Enable(sal_False);
     190             :     }
     191           0 :     aMaxHeightPageBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightPage));
     192           0 :     aMaxHeightBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightMetric));
     193           0 :     Link aLk = LINK(this, SwFootNotePage, HeightModify);
     194           0 :     aMaxHeightEdit.SetLoseFocusHdl( aLk );
     195           0 :     aDistEdit.SetLoseFocusHdl( aLk );
     196           0 :     aLineDistEdit.SetLoseFocusHdl( aLk );
     197             : 
     198             :     // Separator width
     199           0 :     aLineWidthEdit.SetModifyHdl( LINK( this, SwFootNotePage, LineWidthChanged_Impl ) );
     200             : 
     201             :     sal_Int64 nWidthPt = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
     202           0 :             sal_Int64( pFtnInfo->GetLineWidth() ), aLineWidthEdit.GetDecimalDigits(),
     203           0 :             MAP_TWIP, aLineWidthEdit.GetUnit( ) ));
     204           0 :     aLineWidthEdit.SetValue( nWidthPt );
     205             : 
     206             :     // Separator style
     207           0 :     aLineTypeBox.SetSourceUnit( FUNIT_TWIP );
     208             : 
     209           0 :     aLineTypeBox.SetNone(SW_RESSTR(SW_STR_NONE));
     210             :     aLineTypeBox.InsertEntry(
     211             :         ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::SOLID),
     212           0 :         table::BorderLineStyle::SOLID );
     213             :     aLineTypeBox.InsertEntry(
     214             :         ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DOTTED),
     215           0 :         table::BorderLineStyle::DOTTED );
     216             :     aLineTypeBox.InsertEntry(
     217             :         ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DASHED),
     218           0 :         table::BorderLineStyle::DASHED );
     219           0 :     aLineTypeBox.SetWidth( pFtnInfo->GetLineWidth( ) );
     220           0 :     aLineTypeBox.SelectEntry( pFtnInfo->GetLineStyle() );
     221             : 
     222             :     // Separator Color
     223           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     224           0 :     const SfxPoolItem*  pColorItem  = NULL;
     225           0 :     XColorListRef pColorList;
     226             : 
     227             :     OSL_ENSURE( pDocSh, "DocShell not found!" );
     228             : 
     229           0 :     if ( pDocSh )
     230             :     {
     231           0 :         pColorItem = pDocSh->GetItem( SID_COLOR_TABLE );
     232           0 :         if ( pColorItem != NULL )
     233           0 :             pColorList = ( (SvxColorListItem*)pColorItem )->GetColorList();
     234             :     }
     235             : 
     236             :     OSL_ENSURE( pColorList.is(), "ColorTable not found!" );
     237             : 
     238           0 :     if ( pColorList.is() )
     239             :     {
     240           0 :         aLineColorBox.SetUpdateMode( sal_False );
     241             : 
     242           0 :         for ( long i = 0; i < pColorList->Count(); ++i )
     243             :         {
     244           0 :             XColorEntry* pEntry = pColorList->GetColor(i);
     245           0 :             aLineColorBox.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     246             :         }
     247           0 :         aLineColorBox.SetUpdateMode( sal_True );
     248             :     }
     249             : 
     250             :     // select color in the list or add it as a user color
     251           0 :     sal_uInt16 nSelPos = aLineColorBox.GetEntryPos( pFtnInfo->GetLineColor() );
     252           0 :     if( nSelPos == LISTBOX_ENTRY_NOTFOUND )
     253           0 :         nSelPos = aLineColorBox.InsertEntry( pFtnInfo->GetLineColor(),
     254           0 :                 String( SW_RES( RID_SVXSTR_COLOR_USER ) ) );
     255             : 
     256           0 :     aLineColorBox.SetSelectHdl( LINK( this, SwFootNotePage, LineColorSelected_Impl ) );
     257           0 :     aLineColorBox.SelectEntryPos( nSelPos );
     258           0 :     aLineTypeBox.SetColor( pFtnInfo->GetLineColor() );
     259             : 
     260             : 
     261             :     // position
     262           0 :     aLinePosBox.SelectEntryPos( static_cast< sal_uInt16 >(pFtnInfo->GetAdj()) );
     263             : 
     264             :         // width
     265           0 :     Fraction aTmp( 100, 1 );
     266           0 :     aTmp *= pFtnInfo->GetWidth();
     267           0 :     aLineLengthEdit.SetValue( static_cast<long>(aTmp) );
     268             : 
     269             :         // gap footnote area
     270           0 :     aDistEdit.SetValue(aDistEdit.Normalize(pFtnInfo->GetTopDist()),FUNIT_TWIP);
     271             :     aLineDistEdit.SetValue(
     272           0 :         aLineDistEdit.Normalize(pFtnInfo->GetBottomDist()), FUNIT_TWIP);
     273           0 :     ActivatePage( rSet );
     274           0 :     delete pDefFtnInfo;
     275           0 : }
     276             : 
     277             : /*--------------------------------------------------------------------
     278             :     Description:    stuff attributes into the set, when OK
     279             :  --------------------------------------------------------------------*/
     280           0 : sal_Bool SwFootNotePage::FillItemSet(SfxItemSet &rSet)
     281             : {
     282           0 :     SwPageFtnInfoItem aItem((const SwPageFtnInfoItem&)GetItemSet().Get(FN_PARAM_FTN_INFO));
     283             : 
     284             :     // that's the original
     285           0 :     SwPageFtnInfo &rFtnInfo = aItem.GetPageFtnInfo();
     286             : 
     287             :         // footnote area's height
     288           0 :     if(aMaxHeightBtn.IsChecked())
     289             :         rFtnInfo.SetHeight( static_cast< SwTwips >(
     290           0 :                 aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP))));
     291             :     else
     292           0 :         rFtnInfo.SetHeight(0);
     293             : 
     294             :         // gap footnote area
     295             :     rFtnInfo.SetTopDist(  static_cast< SwTwips >(
     296           0 :             aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP))));
     297             :     rFtnInfo.SetBottomDist(  static_cast< SwTwips >(
     298           0 :             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP))));
     299             : 
     300             :     // Separator style
     301           0 :     rFtnInfo.SetLineStyle( ::editeng::SvxBorderStyle( aLineTypeBox.GetSelectEntryStyle() ) );
     302             : 
     303             :     // Separator width
     304             :     long nWidth = static_cast<long>(MetricField::ConvertDoubleValue(
     305             :                    aLineWidthEdit.GetValue( ),
     306           0 :                    aLineWidthEdit.GetDecimalDigits( ),
     307           0 :                    aLineWidthEdit.GetUnit(), MAP_TWIP ));
     308           0 :     rFtnInfo.SetLineWidth( nWidth );
     309             : 
     310             :     // Separator color
     311           0 :     rFtnInfo.SetLineColor( aLineColorBox.GetSelectEntryColor() );
     312             : 
     313             :         // Position
     314           0 :     rFtnInfo.SetAdj((SwFtnAdj)aLinePosBox.GetSelectEntryPos());
     315             : 
     316             :         // Breite
     317           0 :     rFtnInfo.SetWidth(Fraction( static_cast< long >(aLineLengthEdit.GetValue()), 100));
     318             : 
     319             :     const SfxPoolItem* pOldItem;
     320           0 :     if(0 == (pOldItem = GetOldItem( rSet, FN_PARAM_FTN_INFO )) ||
     321           0 :                 aItem != *pOldItem )
     322           0 :         rSet.Put(aItem);
     323             : 
     324           0 :     return sal_True;
     325             : }
     326             : 
     327           0 : void SwFootNotePage::ActivatePage(const SfxItemSet& rSet)
     328             : {
     329           0 :     const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( RES_FRM_SIZE );
     330           0 :     lMaxHeight = rSize.GetSize().Height();
     331             : 
     332             :     const SfxPoolItem* pItem;
     333           0 :     if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), sal_False, &pItem ) )
     334             :     {
     335           0 :         const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
     336             :         const SfxBoolItem& rHeaderOn =
     337           0 :             (const SfxBoolItem&)rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) );
     338             : 
     339           0 :         if ( rHeaderOn.GetValue() )
     340             :         {
     341             :             const SvxSizeItem& rSizeItem =
     342           0 :                 (const SvxSizeItem&)rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE));
     343           0 :             lMaxHeight -= rSizeItem.GetSize().Height();
     344             :         }
     345             :     }
     346             : 
     347           0 :     if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
     348           0 :             sal_False, &pItem ) )
     349             :     {
     350           0 :         const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
     351             :         const SfxBoolItem& rFooterOn =
     352           0 :             (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
     353             : 
     354           0 :         if ( rFooterOn.GetValue() )
     355             :         {
     356             :             const SvxSizeItem& rSizeItem =
     357           0 :                 (const SvxSizeItem&)rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) );
     358           0 :             lMaxHeight -= rSizeItem.GetSize().Height();
     359             :         }
     360             :     }
     361             : 
     362           0 :     if ( rSet.GetItemState( RES_UL_SPACE , sal_False ) == SFX_ITEM_SET )
     363             :     {
     364           0 :         const SvxULSpaceItem &rUL = (const SvxULSpaceItem&)rSet.Get( RES_UL_SPACE );
     365           0 :         lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
     366             :     }
     367             : 
     368           0 :     lMaxHeight *= 8;
     369           0 :     lMaxHeight /= 10;
     370             : 
     371             :     // set maximum values
     372           0 :     HeightModify(0);
     373           0 : }
     374             : 
     375           0 : int SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
     376             : {
     377           0 :     if(_pSet)
     378           0 :         FillItemSet(*_pSet);
     379             : 
     380           0 :     return sal_True;
     381             : }
     382             : 
     383           0 : sal_uInt16* SwFootNotePage::GetRanges()
     384             : {
     385           0 :     return aPageRg;
     386           0 : }
     387             : 
     388             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10