LCOV - code coverage report
Current view: top level - sc/source/ui/sidebar - NumberFormatPropertyPanel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 153 0.7 %
Date: 2014-11-03 Functions: 2 16 12.5 %
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 <sfx2/sidebar/ResourceDefinitions.hrc>
      21             : #include <sfx2/sidebar/Theme.hxx>
      22             : #include <sfx2/sidebar/ControlFactory.hxx>
      23             : #include "NumberFormatPropertyPanel.hxx"
      24             : #include "sc.hrc"
      25             : #include "scresid.hxx"
      26             : #include <sfx2/bindings.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <sfx2/imagemgr.hxx>
      29             : #include <vcl/fixed.hxx>
      30             : #include <vcl/lstbox.hxx>
      31             : #include <vcl/field.hxx>
      32             : #include <vcl/toolbox.hxx>
      33             : #include <svl/intitem.hxx>
      34             : #include <svl/stritem.hxx>
      35             : 
      36             : using namespace css;
      37             : using namespace css::uno;
      38             : using ::sfx2::sidebar::Theme;
      39             : 
      40             : const char UNO_NUMERICFIELD[]         = ".uno:NumericField";
      41             : const char UNO_NUMBERFORMATPERCENT[]  = ".uno:NumberFormatPercent";
      42             : const char UNO_NUMBERFORMATCURRENCY[] = ".uno:NumberFormatCurrency";
      43             : const char UNO_NUMBERFORMATDATE[]     = ".uno:NumberFormatDate";
      44             : const char UNO_INSERTFIXEDTEXT[]      = ".uno:InsertFixedText";
      45             : 
      46             : namespace sc { namespace sidebar {
      47             : 
      48           0 : NumberFormatPropertyPanel::NumberFormatPropertyPanel(
      49             :     vcl::Window* pParent,
      50             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      51             :     SfxBindings* pBindings)
      52             :   : PanelLayout(pParent,"NumberFormatPropertyPanel", "modules/scalc/ui/sidebarnumberformat.ui", rxFrame),
      53             :     maNumFormatControl(SID_NUMBER_TYPE_FORMAT, *pBindings, *this),
      54             :     maFormatControl(SID_NUMBER_FORMAT, *pBindings, *this),
      55             : 
      56             :     mnCategorySelected(0),
      57             :     mxFrame(rxFrame),
      58             :     maContext(),
      59           0 :     mpBindings(pBindings)
      60             : {
      61           0 :     get(mpLbCategory,   "category");
      62           0 :     get(mpTBCategory,   "numberformat");
      63           0 :     get(mpEdDecimals,   "decimalplaces");
      64           0 :     get(mpEdLeadZeroes, "leadingzeroes");
      65           0 :     get(mpBtnNegRed,    "negativenumbersred");
      66           0 :     get(mpBtnThousand,  "thousandseparator");
      67             : 
      68           0 :     Initialize();
      69           0 : }
      70             : 
      71           0 : NumberFormatPropertyPanel::~NumberFormatPropertyPanel()
      72             : {
      73           0 : }
      74             : 
      75           0 : void NumberFormatPropertyPanel::Initialize()
      76             : {
      77           0 :     Link aLink = LINK(this, NumberFormatPropertyPanel, NumFormatSelectHdl);
      78           0 :     mpLbCategory->SetSelectHdl ( aLink );
      79           0 :     mpLbCategory->SelectEntryPos(0);
      80           0 :     mpLbCategory->SetAccessibleName(OUString( "Category"));
      81           0 :     mpLbCategory->SetDropDownLineCount(mpLbCategory->GetEntryCount());
      82             : 
      83           0 :     aLink = LINK(this, NumberFormatPropertyPanel, NumFormatHdl);
      84           0 :     mpTBCategory->SetSelectHdl ( aLink );
      85             : 
      86           0 :     aLink = LINK(this, NumberFormatPropertyPanel, NumFormatValueHdl);
      87             : 
      88           0 :     mpEdDecimals->SetModifyHdl( aLink );
      89           0 :     mpEdLeadZeroes->SetModifyHdl( aLink );
      90           0 :     mpEdDecimals->SetAccessibleName(OUString( "Decimal Places"));
      91           0 :     mpEdLeadZeroes->SetAccessibleName(OUString( "Leading Zeroes"));
      92             : 
      93           0 :     mpBtnNegRed->SetClickHdl( aLink );
      94           0 :     mpBtnThousand->SetClickHdl( aLink );
      95             : 
      96           0 :     mpTBCategory->SetAccessibleRelationLabeledBy(mpTBCategory);
      97           0 : }
      98             : 
      99           0 : IMPL_LINK( NumberFormatPropertyPanel, NumFormatHdl, ToolBox*, pBox )
     100             : {
     101           0 :     const OUString aCommand(pBox->GetItemCommand(pBox->GetCurItemId()));
     102           0 :     sal_uInt16 nId = 0;
     103             : 
     104           0 :     if(aCommand == UNO_NUMERICFIELD)
     105           0 :         nId = 1;
     106           0 :     else if(aCommand == UNO_NUMBERFORMATPERCENT)
     107           0 :         nId = 2;
     108           0 :     else if(aCommand == UNO_NUMBERFORMATCURRENCY)
     109           0 :         nId = 3;
     110           0 :     else if(aCommand == UNO_NUMBERFORMATDATE)
     111           0 :         nId = 4;
     112           0 :     else if(aCommand == UNO_INSERTFIXEDTEXT)
     113           0 :         nId = 9;
     114             : 
     115           0 :     if( nId != mnCategorySelected )
     116             :     {
     117           0 :         SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT,  nId );
     118           0 :         GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
     119             :     }
     120           0 :     return 0L;
     121             : }
     122             : 
     123           0 : IMPL_LINK( NumberFormatPropertyPanel, NumFormatSelectHdl, ListBox*, pBox )
     124             : {
     125           0 :     sal_uInt16 nVal = pBox->GetSelectEntryPos();
     126           0 :     if( nVal != mnCategorySelected )
     127             :     {
     128           0 :         SfxUInt16Item aItem( SID_NUMBER_TYPE_FORMAT,  nVal );
     129           0 :         GetBindings()->GetDispatcher()->Execute(SID_NUMBER_TYPE_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
     130           0 :         mnCategorySelected = nVal;
     131             :     }
     132           0 :     return 0L;
     133             : }
     134             : 
     135           0 : IMPL_LINK( NumberFormatPropertyPanel, NumFormatValueHdl, void*, EMPTYARG )
     136             : {
     137           0 :     OUString      aFormat;
     138           0 :     OUString      sBreak = ",";
     139           0 :     bool          bThousand     =    mpBtnThousand->IsEnabled()
     140           0 :         && mpBtnThousand->IsChecked();
     141           0 :     bool          bNegRed       =    mpBtnNegRed->IsEnabled()
     142           0 :         && mpBtnNegRed->IsChecked();
     143           0 :     sal_uInt16        nPrecision    = (mpEdDecimals->IsEnabled())
     144           0 :         ? (sal_uInt16)mpEdDecimals->GetValue()
     145           0 :         : (sal_uInt16)0;
     146           0 :     sal_uInt16        nLeadZeroes   = (mpEdLeadZeroes->IsEnabled())
     147           0 :         ? (sal_uInt16)mpEdLeadZeroes->GetValue()
     148           0 :         : (sal_uInt16)0;
     149             : 
     150           0 :     OUString sThousand = OUString::number(static_cast<sal_Int32>(bThousand));
     151           0 :     OUString sNegRed = OUString::number(static_cast<sal_Int32>(bNegRed));
     152           0 :     OUString sPrecision = OUString::number(nPrecision);
     153           0 :     OUString sLeadZeroes = OUString::number(nLeadZeroes);
     154             : 
     155           0 :     aFormat += sThousand;
     156           0 :     aFormat += sBreak;
     157           0 :     aFormat += sNegRed;
     158           0 :     aFormat += sBreak;
     159           0 :     aFormat += sPrecision;
     160           0 :     aFormat += sBreak;
     161           0 :     aFormat += sLeadZeroes;
     162           0 :     aFormat += sBreak;
     163             : 
     164           0 :     SfxStringItem aItem( SID_NUMBER_FORMAT,  aFormat );
     165           0 :     GetBindings()->GetDispatcher()->Execute(SID_NUMBER_FORMAT, SfxCallMode::RECORD, &aItem, 0L);
     166           0 :     return 0L;
     167             : }
     168             : 
     169           0 : NumberFormatPropertyPanel* NumberFormatPropertyPanel::Create (
     170             :     vcl::Window* pParent,
     171             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
     172             :     SfxBindings* pBindings)
     173             : {
     174           0 :     if (pParent == NULL)
     175           0 :         throw lang::IllegalArgumentException("no parent Window given to NumberFormatPropertyPanel::Create", NULL, 0);
     176           0 :     if ( ! rxFrame.is())
     177           0 :         throw lang::IllegalArgumentException("no XFrame given to NumberFormatPropertyPanel::Create", NULL, 1);
     178           0 :     if (pBindings == NULL)
     179           0 :         throw lang::IllegalArgumentException("no SfxBindings given to NumberFormatPropertyPanel::Create", NULL, 2);
     180             : 
     181             :     return new NumberFormatPropertyPanel(
     182             :         pParent,
     183             :         rxFrame,
     184           0 :         pBindings);
     185             : }
     186             : 
     187           0 : void NumberFormatPropertyPanel::DataChanged(
     188             :     const DataChangedEvent& rEvent)
     189             : {
     190             :     (void)rEvent;
     191           0 : }
     192             : 
     193           0 : void NumberFormatPropertyPanel::HandleContextChange(
     194             :     const ::sfx2::sidebar::EnumContext aContext)
     195             : {
     196           0 :     if(maContext == aContext)
     197             :     {
     198             :         // Nothing to do.
     199           0 :         return;
     200             :     }
     201             : 
     202           0 :     maContext = aContext;
     203             : 
     204             :     // todo
     205             : }
     206             : 
     207           0 : void NumberFormatPropertyPanel::NotifyItemUpdate(
     208             :     sal_uInt16 nSID,
     209             :     SfxItemState eState,
     210             :     const SfxPoolItem* pState,
     211             :     const bool bIsEnabled)
     212             : {
     213             :     (void)bIsEnabled;
     214             : 
     215           0 :     switch(nSID)
     216             :     {
     217             :     case SID_NUMBER_TYPE_FORMAT:
     218             :         {
     219           0 :             if( eState >= SfxItemState::DEFAULT)
     220             :             {
     221           0 :                 const SfxInt16Item* pItem = static_cast<const SfxInt16Item*>(pState);
     222           0 :                 sal_uInt16 nVal = pItem->GetValue();
     223           0 :                 mnCategorySelected = nVal;
     224           0 :                 mpLbCategory->SelectEntryPos(nVal);
     225           0 :                 if( nVal < 4 )
     226             :                 {
     227           0 :                     mpBtnThousand->Enable();
     228           0 :                     mpBtnNegRed->Enable();
     229           0 :                     mpEdDecimals->Enable();
     230           0 :                     mpEdLeadZeroes->Enable();
     231             :                 }
     232             :                 else
     233             :                 {
     234           0 :                     mpBtnThousand->Disable();
     235           0 :                     mpBtnNegRed->Disable();
     236           0 :                     mpEdDecimals->Disable();
     237           0 :                     mpEdLeadZeroes->Disable();
     238             :                 }
     239             :             }
     240             :             else
     241             :             {
     242           0 :                 mpLbCategory->SetNoSelection();
     243           0 :                 mnCategorySelected = 0;
     244           0 :                 mpBtnThousand->Disable();
     245           0 :                 mpBtnNegRed->Disable();
     246           0 :                 mpEdDecimals->Disable();
     247           0 :                 mpEdLeadZeroes->Disable();
     248             :             }
     249             :         }
     250           0 :         break;
     251             :     case SID_NUMBER_FORMAT:
     252             :         {
     253           0 :             bool          bThousand     =    false;
     254           0 :             bool          bNegRed       =    false;
     255           0 :             sal_uInt16        nPrecision    =    0;
     256           0 :             sal_uInt16        nLeadZeroes   =    0;
     257           0 :             if( eState >= SfxItemState::DEFAULT)
     258             :             {
     259           0 :                 const SfxStringItem* pItem = static_cast<const SfxStringItem*>(pState);
     260           0 :                 OUString aCode = pItem->GetValue();
     261             :             /*  if(aCode.Equals(String::CreateFromAscii("General")))
     262             :                 {
     263             :                     mnCategorySelected = 0;
     264             :                     mpLbCategory->SelectEntryPos(0);
     265             :                     mpBtnThousand->Check(0);
     266             :                     mpBtnNegRed->Check(0);
     267             :                     mpEdDecimals->SetValue(0);
     268             :                     mpEdLeadZeroes->SetValue(1);
     269             :                     break;
     270             :                 }
     271             :                 else if( mpLbCategory->GetSelectEntryPos() == 0 )
     272             :                 {
     273             :                     mnCategorySelected = 1;
     274             :                     mpLbCategory->SelectEntryPos(1);
     275             :                 }*/
     276           0 :                 sal_uInt16 aLen = aCode.getLength();
     277           0 :                 OUString* sFormat = new OUString[4];
     278           0 :                 OUString  sTmpStr = "";
     279           0 :                 sal_uInt16 nCount = 0;
     280           0 :                 sal_uInt16 nStrCount = 0;
     281           0 :                 while( nCount < aLen )
     282             :                 {
     283           0 :                     sal_Unicode cChar = aCode[nCount];
     284           0 :                     if(cChar == ',')
     285             :                     {
     286           0 :                         sFormat[nStrCount] = sTmpStr;
     287           0 :                         sTmpStr = "";
     288           0 :                         nStrCount++;
     289             :                     }
     290             :                     else
     291             :                     {
     292           0 :                         sTmpStr += OUString(cChar);
     293             :                     }
     294           0 :                     nCount++;
     295             :                 }
     296           0 :                 bThousand   =    sFormat[0].toInt32();
     297           0 :                 bNegRed     =    sFormat[1].toInt32();
     298           0 :                 nPrecision  =    (sal_uInt16)sFormat[2].toInt32();
     299           0 :                 nLeadZeroes =    (sal_uInt16)sFormat[3].toInt32();
     300           0 :                 delete[] sFormat;
     301             :             }
     302             :             else
     303             :             {
     304           0 :                 bThousand   =    false;
     305           0 :                 bNegRed     =    false;
     306           0 :                 nPrecision  =    0;
     307           0 :                 nLeadZeroes =    1;
     308             :             }
     309           0 :             mpBtnThousand->Check(bThousand);
     310           0 :             mpBtnNegRed->Check(bNegRed);
     311           0 :             mpEdDecimals->SetValue(nPrecision);
     312           0 :             mpEdLeadZeroes->SetValue(nLeadZeroes);
     313             :         }
     314             :     default:
     315             :         ;
     316             :     }
     317           0 : }
     318             : 
     319         228 : }} // end of namespace ::sc::sidebar
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10