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

Generated by: LCOV version 1.11