LCOV - code coverage report
Current view: top level - sw/source/uibase/sidebar - PageSizeControl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 78 1.3 %
Date: 2014-11-03 Functions: 2 9 22.2 %
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 "PageSizeControl.hxx"
      21             : #include "PagePropertyPanel.hxx"
      22             : #include "PagePropertyPanel.hrc"
      23             : 
      24             : #include <cmdid.h>
      25             : #include <swtypes.hxx>
      26             : 
      27             : #include <svx/sidebar/ValueSetWithTextControl.hxx>
      28             : 
      29             : #include <rtl/character.hxx>
      30             : #include <editeng/paperinf.hxx>
      31             : #include <sfx2/bindings.hxx>
      32             : #include <sfx2/dispatch.hxx>
      33             : 
      34             : #include <vcl/settings.hxx>
      35             : 
      36             : namespace sw { namespace sidebar {
      37             : 
      38           0 : PageSizeControl::PageSizeControl(
      39             :     vcl::Window* pParent,
      40             :     PagePropertyPanel& rPanel,
      41             :     const Paper ePaper,
      42             :     const bool bLandscape,
      43             :     const FieldUnit eFUnit )
      44             :     : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_SIZE) )
      45           0 :     , mpSizeValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::TEXT_TEXT, this, SW_RES(VS_SIZE) ) )
      46             :     , maMoreButton( this, SW_RES(CB_SIZE_MORE) )
      47             :     , maWidthHeightField( this, SW_RES(FLD_WIDTH_HEIGHT) )
      48             :     , mePaper( ePaper )
      49             :     , maPaperList()
      50           0 :     , mrPagePropPanel(rPanel)
      51             : {
      52           0 :     maWidthHeightField.Hide();
      53           0 :     SetFieldUnit( maWidthHeightField, eFUnit );
      54             : 
      55           0 :     maPaperList.push_back( PAPER_A3 );
      56           0 :     maPaperList.push_back( PAPER_A4 );
      57           0 :     maPaperList.push_back( PAPER_A5 );
      58           0 :     maPaperList.push_back( PAPER_B4_ISO );
      59           0 :     maPaperList.push_back( PAPER_B5_ISO );
      60           0 :     maPaperList.push_back( PAPER_ENV_C5 );
      61           0 :     maPaperList.push_back( PAPER_LETTER );
      62           0 :     maPaperList.push_back( PAPER_LEGAL );
      63             : 
      64           0 :     mpSizeValueSet->SetStyle( mpSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT );
      65           0 :     mpSizeValueSet->SetColor( GetSettings().GetStyleSettings().GetMenuColor() );
      66             : 
      67           0 :     sal_uInt16 nSelectedItem = 0;
      68             :     {
      69           0 :         OUString aMetricStr;
      70             :         {
      71           0 :             const OUString aText = maWidthHeightField.GetText();
      72           0 :             for (short i = aText.getLength() - 1; i >= 0; i--)
      73             :             {
      74           0 :                 sal_Unicode c = aText[i];
      75           0 :                 if ( rtl::isAsciiAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') )
      76             :                 {
      77           0 :                     aMetricStr = OUString(c) + aMetricStr;
      78             :                 }
      79             :                 else
      80             :                 {
      81           0 :                     if (!aMetricStr.isEmpty())
      82             :                     {
      83           0 :                         break;
      84             :                     }
      85             :                 }
      86           0 :             }
      87             :         }
      88             : 
      89           0 :         const LocaleDataWrapper& localeDataWrapper = maWidthHeightField.GetLocaleDataWrapper();
      90           0 :         OUString aWidthStr;
      91           0 :         OUString aHeightStr;
      92           0 :         OUString aItemText2;
      93           0 :         for ( ::std::vector< Paper >::size_type nPaperIdx = 0;
      94           0 :               nPaperIdx < maPaperList.size();
      95             :               ++nPaperIdx )
      96             :         {
      97           0 :             Size aPaperSize = SvxPaperInfo::GetPaperSize( maPaperList[ nPaperIdx ] );
      98           0 :             if ( bLandscape )
      99             :             {
     100           0 :                 Swap( aPaperSize );
     101             :             }
     102           0 :             maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Width() ), FUNIT_TWIP );
     103           0 :             aWidthStr = localeDataWrapper.getNum(
     104             :                 maWidthHeightField.GetValue(),
     105           0 :                 maWidthHeightField.GetDecimalDigits(),
     106           0 :                 maWidthHeightField.IsUseThousandSep(),
     107           0 :                 maWidthHeightField.IsShowTrailingZeros() );
     108             : 
     109           0 :             maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Height() ), FUNIT_TWIP);
     110           0 :             aHeightStr = localeDataWrapper.getNum(
     111             :                 maWidthHeightField.GetValue(),
     112           0 :                 maWidthHeightField.GetDecimalDigits(),
     113           0 :                 maWidthHeightField.IsUseThousandSep(),
     114           0 :                 maWidthHeightField.IsShowTrailingZeros() );
     115             : 
     116           0 :             aItemText2 = aWidthStr + " x " + aHeightStr + " " + aMetricStr;
     117             : 
     118             :             mpSizeValueSet->AddItem(
     119           0 :                 SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ),
     120             :                 aItemText2,
     121           0 :                 0 );
     122             : 
     123           0 :             if ( maPaperList[ nPaperIdx ] == mePaper )
     124             :             {
     125           0 :                 nSelectedItem = nPaperIdx + 1;
     126             :             }
     127           0 :         }
     128             :     }
     129             : 
     130           0 :     mpSizeValueSet->SetNoSelection();
     131           0 :     mpSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl,ImplSizeHdl ) );
     132           0 :     mpSizeValueSet->Show();
     133             : 
     134           0 :     mpSizeValueSet->SelectItem( nSelectedItem );
     135           0 :     mpSizeValueSet->Format();
     136           0 :     mpSizeValueSet->StartSelection();
     137             : 
     138           0 :     maMoreButton.SetClickHdl( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) );
     139           0 :     maMoreButton.GrabFocus();
     140             : 
     141           0 :     FreeResource();
     142           0 : }
     143             : 
     144           0 : PageSizeControl::~PageSizeControl(void)
     145             : {
     146           0 :     delete mpSizeValueSet;
     147           0 : }
     148             : 
     149           0 : IMPL_LINK(PageSizeControl, ImplSizeHdl, void *, pControl)
     150             : {
     151           0 :     mpSizeValueSet->SetNoSelection();
     152           0 :     if ( pControl == mpSizeValueSet )
     153             :     {
     154           0 :         const sal_uInt16 nSelectedPaper = mpSizeValueSet->GetSelectItemId();
     155           0 :         const Paper ePaper = maPaperList[nSelectedPaper - 1];
     156           0 :         if ( ePaper != mePaper )
     157             :         {
     158           0 :             mePaper = ePaper;
     159           0 :             mrPagePropPanel.ExecuteSizeChange( mePaper );
     160             :         }
     161             :     }
     162             : 
     163           0 :     mrPagePropPanel.ClosePageSizePopup();
     164           0 :     return 0;
     165             : }
     166             : 
     167           0 : IMPL_LINK(PageSizeControl, MoreButtonClickHdl_Impl, void *, EMPTYARG)
     168             : {
     169           0 :     mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SfxCallMode::ASYNCHRON );
     170             : 
     171           0 :     mrPagePropPanel.ClosePageSizePopup();
     172           0 :     return 0;
     173             : }
     174             : 
     175         270 : } } // end of namespace sw::sidebar
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10