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

Generated by: LCOV version 1.10