LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/sidebar - PageSizeControl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 84 1.2 %
Date: 2013-07-09 Functions: 2 9 22.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include "PageSizeControl.hxx"
      20             : #include "PagePropertyPanel.hxx"
      21             : #include "PagePropertyPanel.hrc"
      22             : 
      23             : #include <cmdid.h>
      24             : #include <swtypes.hxx>
      25             : 
      26             : #include <svx/sidebar/ValueSetWithTextControl.hxx>
      27             : 
      28             : #include <tools/inetmime.hxx>
      29             : #include <editeng/paperinf.hxx>
      30             : #include <sfx2/bindings.hxx>
      31             : #include <sfx2/dispatch.hxx>
      32             : 
      33             : 
      34             : namespace sw { namespace sidebar {
      35             : 
      36           0 : PageSizeControl::PageSizeControl(
      37             :     Window* pParent,
      38             :     PagePropertyPanel& rPanel,
      39             :     const Paper ePaper,
      40             :     const sal_Bool bLandscape,
      41             :     const FieldUnit eFUnit )
      42             :     : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_SIZE) )
      43           0 :     , mpSizeValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::TEXT_TEXT, this, SW_RES(VS_SIZE) ) )
      44             :     , maMoreButton( this, SW_RES(CB_SIZE_MORE) )
      45             :     , maWidthHeightField( this, SW_RES(FLD_WIDTH_HEIGHT) )
      46             :     , mePaper( ePaper )
      47             :     , maPaperList()
      48           0 :     , mrPagePropPanel(rPanel)
      49             : {
      50           0 :     maWidthHeightField.Hide();
      51           0 :     SetFieldUnit( maWidthHeightField, eFUnit );
      52             : 
      53           0 :     maPaperList.push_back( PAPER_A3 );
      54           0 :     maPaperList.push_back( PAPER_A4 );
      55           0 :     maPaperList.push_back( PAPER_A5 );
      56           0 :     maPaperList.push_back( PAPER_B4_ISO );
      57           0 :     maPaperList.push_back( PAPER_B5_ISO );
      58           0 :     maPaperList.push_back( PAPER_ENV_C5 );
      59           0 :     maPaperList.push_back( PAPER_LETTER );
      60           0 :     maPaperList.push_back( PAPER_LEGAL );
      61             : 
      62           0 :     mpSizeValueSet->SetStyle( mpSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT );
      63           0 :     mpSizeValueSet->SetColor( GetSettings().GetStyleSettings().GetMenuColor() );
      64             : 
      65           0 :     sal_uInt16 nSelectedItem = 0;
      66             :     {
      67           0 :         XubString aMetricStr;
      68             :         {
      69           0 :             const XubString aText = maWidthHeightField.GetText();
      70           0 :             for (short i = aText.Len() - 1; i >= 0; i--)
      71             :             {
      72           0 :                 sal_Unicode c = aText.GetChar(i);
      73           0 :                 if ( INetMIME::isAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') )
      74             :                 {
      75           0 :                     aMetricStr.Insert(c, 0);
      76             :                 }
      77             :                 else
      78             :                 {
      79           0 :                     if (aMetricStr.Len())
      80             :                     {
      81           0 :                         break;
      82             :                     }
      83             :                 }
      84           0 :             }
      85             :         }
      86             : 
      87           0 :         const LocaleDataWrapper& localeDataWrapper = maWidthHeightField.GetLocaleDataWrapper();
      88           0 :         String WidthStr;
      89           0 :         String HeightStr;
      90           0 :         String ItemText2;
      91           0 :         for ( ::std::vector< Paper >::size_type nPaperIdx = 0;
      92           0 :               nPaperIdx < maPaperList.size();
      93             :               ++nPaperIdx )
      94             :         {
      95           0 :             Size aPaperSize = SvxPaperInfo::GetPaperSize( maPaperList[ nPaperIdx ] );
      96           0 :             if ( bLandscape )
      97             :             {
      98           0 :                 Swap( aPaperSize );
      99             :             }
     100           0 :             maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Width() ), FUNIT_TWIP );
     101           0 :             WidthStr = localeDataWrapper.getNum(
     102           0 :                 maWidthHeightField.GetValue(),
     103           0 :                 maWidthHeightField.GetDecimalDigits(),
     104           0 :                 maWidthHeightField.IsUseThousandSep(),
     105           0 :                 maWidthHeightField.IsShowTrailingZeros() );
     106             : 
     107           0 :             maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Height() ), FUNIT_TWIP);
     108           0 :             HeightStr = localeDataWrapper.getNum(
     109           0 :                 maWidthHeightField.GetValue(),
     110           0 :                 maWidthHeightField.GetDecimalDigits(),
     111           0 :                 maWidthHeightField.IsUseThousandSep(),
     112           0 :                 maWidthHeightField.IsShowTrailingZeros() );
     113             : 
     114           0 :             ItemText2 = WidthStr;
     115           0 :             ItemText2 += OUString(" x ");
     116           0 :             ItemText2 += HeightStr;
     117           0 :             ItemText2 += OUString(" ");
     118           0 :             ItemText2 += aMetricStr;
     119             : 
     120             :             mpSizeValueSet->AddItem(
     121           0 :                 SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ),
     122             :                 ItemText2,
     123           0 :                 0 );
     124             : 
     125           0 :             if ( maPaperList[ nPaperIdx ] == mePaper )
     126             :             {
     127           0 :                 nSelectedItem = nPaperIdx + 1;
     128             :             }
     129           0 :         }
     130             :     }
     131             : 
     132           0 :     mpSizeValueSet->SetNoSelection();
     133           0 :     mpSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl,ImplSizeHdl ) );
     134           0 :     mpSizeValueSet->Show();
     135             : 
     136           0 :     mpSizeValueSet->SelectItem( nSelectedItem );
     137           0 :     mpSizeValueSet->Format();
     138           0 :     mpSizeValueSet->StartSelection();
     139             : 
     140           0 :     maMoreButton.SetClickHdl( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) );
     141           0 :     maMoreButton.GrabFocus();
     142             : 
     143           0 :     FreeResource();
     144           0 : }
     145             : 
     146             : 
     147           0 : PageSizeControl::~PageSizeControl(void)
     148             : {
     149           0 :     delete mpSizeValueSet;
     150           0 : }
     151             : 
     152             : 
     153           0 : IMPL_LINK(PageSizeControl, ImplSizeHdl, void *, pControl)
     154             : {
     155           0 :     mpSizeValueSet->SetNoSelection();
     156           0 :     if ( pControl == mpSizeValueSet )
     157             :     {
     158           0 :         const sal_uInt16 nSelectedPaper = mpSizeValueSet->GetSelectItemId();
     159           0 :         const Paper ePaper = maPaperList[nSelectedPaper - 1];
     160           0 :         if ( ePaper != mePaper )
     161             :         {
     162           0 :             mePaper = ePaper;
     163           0 :             mrPagePropPanel.ExecuteSizeChange( mePaper );
     164             :         }
     165             :     }
     166             : 
     167           0 :     mrPagePropPanel.ClosePageSizePopup();
     168           0 :     return 0;
     169             : }
     170             : 
     171           0 : IMPL_LINK(PageSizeControl, MoreButtonClickHdl_Impl, void *, EMPTYARG)
     172             : {
     173           0 :     mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SFX_CALLMODE_ASYNCHRON );
     174             : 
     175           0 :     mrPagePropPanel.ClosePageSizePopup();
     176           0 :     return 0;
     177             : }
     178             : 
     179             : 
     180          99 : } } // end of namespace sw::sidebar
     181             : 

Generated by: LCOV version 1.10