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

Generated by: LCOV version 1.10