LCOV - code coverage report
Current view: top level - sw/source/uibase/sidebar - PageSizeControl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 86 1.2 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.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 "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             :     , mpSizeValueSet( VclPtr<svx::sidebar::ValueSetWithTextControl>::Create( svx::sidebar::ValueSetWithTextControl::TEXT_TEXT, this, SW_RES(VS_SIZE) ) )
      46             :     , maMoreButton( VclPtr<PushButton>::Create( this, SW_RES(CB_SIZE_MORE) ) )
      47             :     , maWidthHeightField( VclPtr<MetricField>::Create( this, SW_RES(FLD_WIDTH_HEIGHT) ) )
      48             :     , mePaper( ePaper )
      49             :     , maPaperList()
      50           0 :     , mrPagePropPanel(rPanel)
      51             : {
      52           0 :     maWidthHeightField->Hide();
      53           0 :     SetFieldUnit( *maWidthHeightField.get(), 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           0 :                 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           0 :                 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->SetFormat();
     136           0 :     mpSizeValueSet->Invalidate();
     137           0 :     mpSizeValueSet->StartSelection();
     138             : 
     139           0 :     maMoreButton->SetClickHdl( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) );
     140           0 :     maMoreButton->GrabFocus();
     141             : 
     142           0 :     FreeResource();
     143           0 : }
     144             : 
     145           0 : PageSizeControl::~PageSizeControl()
     146             : {
     147           0 :     disposeOnce();
     148           0 : }
     149             : 
     150           0 : void PageSizeControl::dispose()
     151             : {
     152           0 :     mpSizeValueSet.disposeAndClear();
     153           0 :     maMoreButton.disposeAndClear();
     154           0 :     maWidthHeightField.disposeAndClear();
     155           0 :     svx::sidebar::PopupControl::dispose();
     156           0 : }
     157             : 
     158           0 : IMPL_LINK(PageSizeControl, ImplSizeHdl, void *, pControl)
     159             : {
     160           0 :     mpSizeValueSet->SetNoSelection();
     161           0 :     if ( pControl == mpSizeValueSet )
     162             :     {
     163           0 :         const sal_uInt16 nSelectedPaper = mpSizeValueSet->GetSelectItemId();
     164           0 :         const Paper ePaper = maPaperList[nSelectedPaper - 1];
     165           0 :         if ( ePaper != mePaper )
     166             :         {
     167           0 :             mePaper = ePaper;
     168           0 :             mrPagePropPanel.ExecuteSizeChange( mePaper );
     169             :         }
     170             :     }
     171             : 
     172           0 :     mrPagePropPanel.ClosePageSizePopup();
     173           0 :     return 0;
     174             : }
     175             : 
     176           0 : IMPL_LINK_NOARG(PageSizeControl, MoreButtonClickHdl_Impl)
     177             : {
     178           0 :     mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SfxCallMode::ASYNCHRON );
     179             : 
     180           0 :     mrPagePropPanel.ClosePageSizePopup();
     181           0 :     return 0;
     182             : }
     183             : 
     184         177 : } } // end of namespace sw::sidebar
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11