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

Generated by: LCOV version 1.10