[Libreoffice-commits] core.git: include/svx sc/sdi sc/source svx/source

Mohammed Abdul Azeem azeemmysore at gmail.com
Sat Mar 19 14:19:24 UTC 2016


 include/svx/tbcontrl.hxx         |   18 +++
 sc/sdi/scalc.sdi                 |    3 
 sc/source/ui/app/scdll.cxx       |    3 
 sc/source/ui/view/formatsh.cxx   |   67 ++++++++++---
 svx/source/tbxctrls/tbcontrl.cxx |  198 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 274 insertions(+), 15 deletions(-)

New commits:
commit bf17a8dfbb9f966c90b5d6eb0a7b8e7838392d27
Author: Mohammed Abdul Azeem <azeemmysore at gmail.com>
Date:   Mon Mar 7 01:35:57 2016 +0530

    tdf#82641 Currency drop-down list
    
    Currency drop-down list has been added. It retains
    the position of selected entry. Clicking on button
    toggles between the previously selected currency
    and number formats.
    
    Change-Id: I0dea8fc2773497bfaababa418f119d0a5e76cb03
    Reviewed-on: https://gerrit.libreoffice.org/22958
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx
index 179e8e7..928f75f 100644
--- a/include/svx/tbcontrl.hxx
+++ b/include/svx/tbcontrl.hxx
@@ -290,6 +290,24 @@ public:
                               const SfxPoolItem* pState) override;
 };
 
+class SVX_DLLPUBLIC SvxCurrencyToolBoxControl : public SfxToolBoxControl
+{
+private:
+    OUString     m_aFormatString;
+    LanguageType m_eLanguage;
+    sal_uInt32   m_nFormatKey;
+public:
+    SFX_DECL_TOOLBOX_CONTROL();
+    SvxCurrencyToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
+    virtual ~SvxCurrencyToolBoxControl();
+    virtual void Select( sal_uInt16 nSelectModifier ) override;
+    virtual VclPtr<SfxPopupWindow> CreatePopupWindow() override;
+    virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState,
+                              const SfxPoolItem* pState) override;
+};
+
+
+
 #endif // INCLUDED_SVX_TBCONTRL_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 99a5313..14169f0 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3735,7 +3735,7 @@ SfxStringItem NumberFormat SID_NUMBER_FORMAT
 
 
 SfxVoidItem NumberFormatCurrency SID_NUMBER_CURRENCY
-()
+(SfxUInt32Item NumberFormatCurrency SID_NUMBER_CURRENCY)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -3744,6 +3744,7 @@ SfxVoidItem NumberFormatCurrency SID_NUMBER_CURRENCY
     Container = FALSE,
     RecordAbsolute = FALSE,
     RecordPerSet;
+    SlotType = SfxUInt32Item
 
     AccelConfig = TRUE,
     MenuConfig = TRUE,
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index e83cc18..d35328a9 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -146,7 +146,8 @@ void ScDLL::Init()
     ScPageBreakShell    ::RegisterInterface(pMod);
 
     // Own Controller
-    ScZoomSliderControl ::RegisterControl(SID_PREVIEW_SCALINGFACTOR, pMod);
+    ScZoomSliderControl             ::RegisterControl(SID_PREVIEW_SCALINGFACTOR, pMod);
+    SvxCurrencyToolBoxControl       ::RegisterControl(SID_NUMBER_CURRENCY, pMod);
 
     // SvxToolboxController
     SvxTbxCtlDraw                   ::RegisterControl(SID_INSERT_DRAW,          pMod);
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 240cc74..0850aad 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -988,11 +988,11 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
 
 void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
 {
-    ScModule*           pScMod      = SC_MOD();
-    ScTabViewShell* pTabViewShell   = GetViewData()->GetViewShell();
-    const SfxItemSet*   pReqArgs    = rReq.GetArgs();
-    sal_uInt16              nSlot   = rReq.GetSlot();
-    SfxBindings& rBindings          = pTabViewShell->GetViewFrame()->GetBindings();
+    ScModule*           pScMod          = SC_MOD();
+    ScTabViewShell*     pTabViewShell   = GetViewData()->GetViewShell();
+    const SfxItemSet*   pReqArgs        = rReq.GetArgs();
+    sal_uInt16          nSlot           = rReq.GetSlot();
+    SfxBindings&        rBindings       = pTabViewShell->GetViewFrame()->GetBindings();
 
     pTabViewShell->HideListBox();                   // Autofilter-DropDown-Listbox
 
@@ -1062,11 +1062,43 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
             rReq.Done();
             break;
         case SID_NUMBER_CURRENCY:
-            if ((nType & css::util::NumberFormat::CURRENCY))
-                pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
+            if(pReqArgs)
+            {
+                const SfxPoolItem* pItem;
+                if ( pReqArgs->HasItem( SID_NUMBER_CURRENCY, &pItem ) )
+                {
+                    sal_uInt32 nNewFormat = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
+                    ScDocument* pDoc = pViewData->GetDocument();
+                    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+                    const SfxItemSet& rOldSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
+
+                    LanguageType eOldLang = static_cast<const SvxLanguageItem&>(
+                                            rOldSet.Get( ATTR_LANGUAGE_FORMAT ) ).GetLanguage();
+                    sal_uInt32 nOldFormat = static_cast<const SfxUInt32Item&>(
+                                            rOldSet.Get( ATTR_VALUE_FORMAT ) ).GetValue();
+
+                    if ( nOldFormat != nNewFormat )
+                    {
+                        const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat );
+                        ScPatternAttr aNewAttrs( pDoc->GetPool() );
+                        SfxItemSet& rSet = aNewAttrs.GetItemSet();
+                        LanguageType eNewLang = pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
+                        if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW )
+                            rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
+                        rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
+                        pTabViewShell->ApplySelectionPattern( aNewAttrs );
+                    }
+                    else
+                        pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
+                }
+            }
             else
-                pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
-            aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::CURRENCY)) );
+            {
+                if ( ( nType & css::util::NumberFormat::CURRENCY ) )
+                    pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
+                else
+                    pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
+            }
             rBindings.Invalidate( nSlot );
             rReq.Done();
             break;
@@ -1975,7 +2007,6 @@ void ScFormatShell::GetAttrState( SfxItemSet& rSet )
             case SID_BACKGROUND_COLOR:
             {
                 rSet.Put( SvxColorItem( rBrushItem.GetColor(), SID_BACKGROUND_COLOR ) );
-
                 if(SfxItemState::DONTCARE == rAttrSet.GetItemState(ATTR_BACKGROUND))
                 {
                     rSet.InvalidateItem(SID_BACKGROUND_COLOR);
@@ -2544,15 +2575,25 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
 
                 }
                 break;
+            case SID_NUMBER_CURRENCY:
+                {
+                    const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
+                    if( SfxItemState::DONTCARE != rAttrSet.GetItemState( ATTR_VALUE_FORMAT ) )
+                    {
+                        sal_uInt32 nNumberFormat = static_cast<const SfxUInt32Item&>(
+                                                   rAttrSet.Get( ATTR_VALUE_FORMAT ) ).GetValue();
+                        rSet.Put( SfxUInt32Item( nWhich, nNumberFormat ) );
+                    }
+                    else
+                        rSet.InvalidateItem( nWhich );
+                }
+                break;
             case SID_NUMBER_SCIENTIFIC:
                 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::SCIENTIFIC)) );
                 break;
             case SID_NUMBER_DATE:
                 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::DATE)) );
                 break;
-            case SID_NUMBER_CURRENCY:
-                rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::CURRENCY)) );
-                break;
             case SID_NUMBER_PERCENT:
                 rSet.Put( SfxBoolItem(nWhich, (nType & css::util::NumberFormat::PERCENT)) );
                 break;
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index a7a8a3f..7549769 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -55,6 +55,7 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/status/ItemStatus.hpp>
+#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
 #include <svx/dialogs.hrc>
 #include <svx/svxitems.hrc>
 #include "helpid.hrc"
@@ -92,6 +93,8 @@
 #include <svx/xlnclit.hxx>
 #include <svx/xfillit0.hxx>
 #include <svx/xflclit.hxx>
+#include <svl/currencytable.hxx>
+#include <svtools/langtab.hxx>
 
 #define MAX_MRU_FONTNAME_ENTRIES    5
 
@@ -113,6 +116,7 @@ SFX_IMPL_TOOLBOX_CONTROL( SvxFontNameToolBoxControl, SvxFontItem );
 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameToolBoxControl, SvxBoxItem );
 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameLineStyleToolBoxControl, SvxLineItem );
 SFX_IMPL_TOOLBOX_CONTROL( SvxSimpleUndoRedoController, SfxStringItem );
+SFX_IMPL_TOOLBOX_CONTROL( SvxCurrencyToolBoxControl, SfxUInt32Item );
 
 class SvxStyleBox_Impl : public ComboBox
 {
@@ -290,6 +294,30 @@ public:
     virtual void dispose() override { m_aLineStyleLb.disposeAndClear(); SfxPopupWindow::dispose(); }
 };
 
+class SvxCurrencyToolBoxControl;
+class SvxCurrencyList_Impl : public SfxPopupWindow
+{
+private:
+    VclPtr<ListBox> m_pCurrencyLb;
+    rtl::Reference<SvxCurrencyToolBoxControl> m_xControl;
+    OUString&       m_rSelectedFormat;
+    LanguageType&   m_eSelectedLanguage;
+
+    std::vector<OUString> m_aFormatEntries;
+    LanguageType          m_eFormatLanguage;
+    DECL_LINK_TYPED( SelectHdl, ListBox&, void );
+
+public:
+    SvxCurrencyList_Impl( sal_uInt16 nId, const Reference< XFrame >& rxFrame,
+                          vcl::Window* pParentWindow,
+                          const Reference< css::uno::XComponentContext >& rxContext,
+                          SvxCurrencyToolBoxControl *pControl,
+                          OUString&     rSelectFormat,
+                          LanguageType& eSelectLanguage );
+    virtual ~SvxCurrencyList_Impl() { disposeOnce(); }
+    virtual void dispose() override;
+};
+
 class SvxStyleToolBoxControl;
 
 class SfxStyleControllerItem_Impl : public SfxStatusListener
@@ -1840,6 +1868,75 @@ static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ )
     return SvxBorderLine::threeDMediumColor( aMain );
 }
 
+SvxCurrencyList_Impl::SvxCurrencyList_Impl(
+    sal_uInt16 nId, const Reference< XFrame >& rxFrame,
+    vcl::Window* pParentWindow,
+    const Reference< XComponentContext >& rxContext,
+    SvxCurrencyToolBoxControl *pControl,
+    OUString& rSelectedFormat,
+    LanguageType& eSelectedLanguage ) :
+    SfxPopupWindow( nId, rxFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION | WB_AUTOSIZE | WB_3DLOOK ) ),
+    m_pCurrencyLb( VclPtr<ListBox>::Create(this) ),
+    m_xControl( pControl ),
+    m_rSelectedFormat( rSelectedFormat ),
+    m_eSelectedLanguage( eSelectedLanguage )
+{
+    m_pCurrencyLb->setPosSizePixel( 2, 2, 300, 140 );
+    SetOutputSizePixel( Size( 304, 144 ) );
+
+    std::vector< OUString > aList;
+    const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
+    sal_uInt16 nCount = rCurrencyTable.size();
+
+    CollatorWrapper aCollator( ::comphelper::getProcessComponentContext());
+    aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0);
+
+    const OUString aTwoSpace("  ");
+    SvNumberFormatter aFormatter = SvNumberFormatter(rxContext, LANGUAGE_SYSTEM);
+    m_eFormatLanguage = aFormatter.GetLanguage();
+    for(sal_uInt16 i = 0; i < nCount; ++i)
+    {
+        OUString aStr( rCurrencyTable[i].GetBankSymbol() );
+        aStr += aTwoSpace;
+        aStr += rCurrencyTable[i].GetSymbol();
+        aStr += aTwoSpace;
+        aStr += SvtLanguageTable::GetLanguageString( rCurrencyTable[i].GetLanguage() );
+        NfWSStringsDtor aStringsDtor;
+        sal_uInt16 nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, rCurrencyTable[i], false );
+
+        sal_uInt16 j = 0;
+        for(; j < aList.size(); ++j)
+            if ( aCollator.compareString( aStr, aList[j] ) < 0 )
+                break;
+
+        aList.insert( aList.begin() + j, aStr );
+        m_aFormatEntries.insert( m_aFormatEntries.begin() + j, aStringsDtor[nDefaultFormat] );
+    }
+
+    sal_uInt16 nPos = 0;
+    sal_Int32 nSelectedPos = -1;
+    for(std::vector< OUString >::iterator i = aList.begin(); i != aList.end(); ++i, ++nPos)
+    {
+        m_pCurrencyLb->InsertEntry (*i);
+        OUString *pFormatStr = &m_aFormatEntries[nPos];
+        m_pCurrencyLb->SetEntryData( nPos, reinterpret_cast<void*>( pFormatStr ) );
+        if( *pFormatStr == m_rSelectedFormat )
+            nSelectedPos = nPos;
+    }
+    m_pCurrencyLb->SetSelectHdl( LINK( this, SvxCurrencyList_Impl, SelectHdl ) );
+    SetText( SVX_RESSTR( RID_SVXSTR_TBLAFMT_CURRENCY ) );
+    if ( nSelectedPos >= 0 )
+        m_pCurrencyLb->SelectEntryPos( nSelectedPos );
+    m_pCurrencyLb->Show();
+}
+
+void SvxCurrencyList_Impl::dispose()
+{
+    m_xControl.clear();
+    m_pCurrencyLb.disposeAndClear();
+    SfxPopupWindow::dispose();
+}
+
 SvxLineWindow_Impl::SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, vcl::Window* pParentWindow ) :
 
     SfxPopupWindow( nId, rFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION | WB_AUTOSIZE ) ),
@@ -1896,6 +1993,27 @@ SvxLineWindow_Impl::SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame
     m_aLineStyleLb->Show();
 }
 
+IMPL_LINK_NOARG_TYPED(SvxCurrencyList_Impl, SelectHdl, ListBox&, void)
+{
+    if ( IsInPopupMode() )
+        EndPopupMode();
+
+    if (!m_xControl.is())
+        return;
+
+    OUString* pFormat = reinterpret_cast<OUString*> (
+        m_pCurrencyLb->GetEntryData( m_pCurrencyLb->GetSelectEntryPos() ) );
+
+    assert( pFormat );
+    if ( pFormat )
+    {
+        m_rSelectedFormat = *pFormat;
+        m_eSelectedLanguage = m_eFormatLanguage;
+    }
+
+    m_xControl->Select( m_pCurrencyLb->GetSelectEntryPos() + 1 );
+}
+
 IMPL_LINK_NOARG_TYPED(SvxLineWindow_Impl, SelectHdl, ListBox&, void)
 {
     SvxLineItem     aLineItem( SID_FRAME_LINESTYLE );
@@ -2904,6 +3022,86 @@ void SvxSimpleUndoRedoController::StateChanged( sal_uInt16, SfxItemState eState,
     rBox.EnableItem( GetId(), eState != SfxItemState::DISABLED );
 }
 
+SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) :
+    SfxToolBoxControl( nSlotId, nId, rBox ),
+    m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ),
+    m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND )
+{
+    rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
+}
+
+SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {}
+
+VclPtr<SfxPopupWindow> SvxCurrencyToolBoxControl::CreatePopupWindow()
+{
+    VclPtr<SvxCurrencyList_Impl> xCurrencyWin =
+        VclPtr<SvxCurrencyList_Impl>::Create( GetSlotId(), m_xFrame,
+                                              &GetToolBox(), getContext(),
+                                              this, m_aFormatString,
+                                              m_eLanguage );
+    xCurrencyWin->StartPopupMode( &GetToolBox(),
+                              FloatWinPopupFlags::GrabFocus |
+                              FloatWinPopupFlags::AllowTearOff |
+                              FloatWinPopupFlags::NoAppFocusClose );
+    SetPopupWindow( xCurrencyWin );
+
+    return xCurrencyWin;
+}
+
+void SvxCurrencyToolBoxControl::Select( sal_uInt16 nSelectModifier )
+{
+    if (getenv("DO_NOTHING"))
+        return;
+
+    sal_uInt32 nFormatKey;
+    if (m_aFormatString.isEmpty())
+        nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND;
+    else
+    {
+        if ( nSelectModifier > 0 )
+        {
+            try
+            {
+                uno::Reference< util::XNumberFormatsSupplier > xRef( m_xFrame->getController()->getModel(), uno::UNO_QUERY );
+                uno::Reference< util::XNumberFormats > rxNumberFormats( xRef->getNumberFormats(), uno::UNO_QUERY_THROW );
+                css::lang::Locale aLocale = LanguageTag::convertToLocale( m_eLanguage );
+                nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false );
+                if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
+                    nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale );
+                }
+                catch( const uno::Exception& )
+                {
+                    nFormatKey = m_nFormatKey;
+                }
+        }
+        else
+            nFormatKey = m_nFormatKey;
+    }
+
+    Sequence< PropertyValue > aArgs( 1 );
+    aArgs[0].Name = "NumberFormatCurrency";
+    if( nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
+    {
+        aArgs[0].Value = makeAny( nFormatKey );
+        m_nFormatKey = nFormatKey;
+    }
+    SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
+                                 ".uno:NumberFormatCurrency",
+                                 aArgs );
+}
+
+void SvxCurrencyToolBoxControl::StateChanged(
+    sal_uInt16, SfxItemState eState, const SfxPoolItem* )
+{
+    sal_uInt16                  nId     = GetId();
+    ToolBox&                    rTbx    = GetToolBox();
+
+    rTbx.EnableItem( nId, SfxItemState::DISABLED != eState );
+    rTbx.SetItemState( nId, (SfxItemState::DONTCARE == eState)
+                            ? TRISTATE_INDET
+                            : TRISTATE_FALSE );
+}
+
 
 static void lcl_CalcSizeValueSet( vcl::Window &rWin, ValueSet &rValueSet, const Size &aItemSize )
 {


More information about the Libreoffice-commits mailing list