summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svx/tbcontrl.hxx15
-rw-r--r--sc/sdi/scalc.sdi3
-rw-r--r--sc/source/ui/app/scdll.cxx3
-rw-r--r--sc/source/ui/view/formatsh.cxx57
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx141
5 files changed, 201 insertions, 18 deletions
diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx
index 179e8e7316d3..e4782ddd5fde 100644
--- a/include/svx/tbcontrl.hxx
+++ b/include/svx/tbcontrl.hxx
@@ -290,6 +290,21 @@ public:
const SfxPoolItem* pState) override;
};
+class SVX_DLLPUBLIC SvxCurrencyToolBoxControl : public SfxToolBoxControl
+{
+private:
+ sal_uInt16 m_nSelectedEntry;
+public:
+ SFX_DECL_TOOLBOX_CONTROL();
+ SvxCurrencyToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
+ virtual ~SvxCurrencyToolBoxControl();
+ 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 853bc79495eb..b84bb7d7f95a 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 e83cc1895114..d35328a901b2 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 714348725f1e..92c488278b8f 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -57,6 +57,7 @@
#include <editeng/shaditem.hxx>
#include <editeng/justifyitem.hxx>
#include <editeng/fhgtitem.hxx>
+#include <svtools/langtab.hxx>
#include "formatsh.hxx"
#include "sc.hrc"
@@ -988,11 +989,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,13 +1063,34 @@ 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 nFormatKey = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
+ ScDocument* pDoc = pViewData->GetDocument();
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ ScPatternAttr aNewAttrs( pDoc->GetPool() );
+ SfxItemSet& rSet = aNewAttrs.GetItemSet();
+
+ const SvNumberformat* pNewEntry = pFormatter->GetEntry( nFormatKey );
+ LanguageType eOldLang = static_cast<const SvxLanguageItem&>(
+ rSet.Get( ATTR_LANGUAGE_FORMAT )).GetLanguage();
+ 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, nFormatKey ) );
+ pTabViewShell->ApplySelectionPattern( aNewAttrs );
+ }
+ }
else
- pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
- aSet.Put( SfxBoolItem(nSlot, !(nType & css::util::NumberFormat::CURRENCY)) );
- rBindings.Invalidate( nSlot );
- rReq.Done();
+ {
+ if ((nType & css::util::NumberFormat::CURRENCY))
+ pTabViewShell->SetNumberFormat( css::util::NumberFormat::NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( css::util::NumberFormat::CURRENCY );
+ }
break;
case SID_NUMBER_PERCENT:
if ((nType & css::util::NumberFormat::PERCENT))
@@ -1975,7 +1997,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 +2565,21 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
}
break;
+ case SID_NUMBER_CURRENCY:
+ {
+ const SfxItemSet& rAttrSet = pTabViewShell->GetSelectionPattern()->GetItemSet();
+ if(SfxItemState::DONTCARE == rAttrSet.GetItemState(ATTR_VALUE_FORMAT))
+ {
+ 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 a7a8a3fa85aa..3e7b37577f84 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,10 @@
#include <svx/xlnclit.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xflclit.hxx>
+#include <svl/currencytable.hxx>
+#include <svtools/langtab.hxx>
+#include <i18nlangtag/languagetag.hxx>
+
#define MAX_MRU_FONTNAME_ENTRIES 5
@@ -113,6 +118,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
{
@@ -285,11 +291,33 @@ protected:
virtual void GetFocus() override;
virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
public:
- SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, vcl::Window* pParentWindow );
+ SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rxFrame, vcl::Window* pParentWindow );
virtual ~SvxLineWindow_Impl() { disposeOnce(); }
virtual void dispose() override { m_aLineStyleLb.disposeAndClear(); SfxPopupWindow::dispose(); }
};
+class SvxCurrencyList_Impl : public SfxPopupWindow
+{
+private:
+ VclPtr<ListBox> m_pCurrencyLb;
+ sal_uInt16& m_rSelectedPos;
+
+ struct FormatDetails
+ {
+ rtl::OUString aFormatString;
+ LanguageType aLanguage;
+ inline FormatDetails(rtl::OUString aFmtStr, LanguageType aLang) : aFormatString(aFmtStr), aLanguage(aLang) {}
+ };
+ std::vector<FormatDetails> m_aFormatEntries;
+ DECL_LINK_TYPED( SelectHdl, ListBox&, void );
+
+public:
+ SvxCurrencyList_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, vcl::Window* pParentWindow,
+ const Reference< css::uno::XComponentContext >& rxContext, sal_uInt16& rSelectedPos );
+ virtual ~SvxCurrencyList_Impl() { disposeOnce(); }
+ virtual void dispose() override { m_pCurrencyLb.disposeAndClear(); SfxPopupWindow::dispose(); }
+};
+
class SvxStyleToolBoxControl;
class SfxStyleControllerItem_Impl : public SfxStatusListener
@@ -1840,6 +1868,55 @@ 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, sal_uInt16& rSelectedPos ) :
+ SfxPopupWindow( nId, rxFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION | WB_AUTOSIZE | WB_3DLOOK ) ),
+ m_pCurrencyLb( VclPtr<ListBox>::Create(this) ),
+ m_rSelectedPos(rSelectedPos)
+{
+ 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);
+ 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,
+ FormatDetails( aStringsDtor[nDefaultFormat], rCurrencyTable[i].GetLanguage() ) );
+ }
+ sal_uInt16 nPos(0);
+ for(std::vector< OUString >::iterator i = aList.begin(); i != aList.end(); ++i, ++nPos)
+ {
+ m_pCurrencyLb->InsertEntry (*i);
+ m_pCurrencyLb->SetEntryData( nPos, reinterpret_cast<void*>( &m_aFormatEntries[nPos] ) );
+ }
+ m_pCurrencyLb->SetSelectHdl( LINK( this, SvxCurrencyList_Impl, SelectHdl ) );
+ SetText( SVX_RESSTR( RID_SVXSTR_TBLAFMT_CURRENCY ) );
+ m_pCurrencyLb->SelectEntryPos( m_rSelectedPos );
+ m_pCurrencyLb->Show();
+}
+
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 +1973,36 @@ 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();
+
+ m_rSelectedPos = m_pCurrencyLb->GetSelectEntryPos();
+ FormatDetails* aFormat = reinterpret_cast<FormatDetails*> (m_pCurrencyLb->GetEntryData( m_rSelectedPos ) );
+ sal_uInt32 nFormatKey;
+ try
+ {
+ uno::Reference< util::XNumberFormatsSupplier > xRef( GetFrame()->getController()->getModel(), uno::UNO_QUERY );
+ uno::Reference< util::XNumberFormats > rxNumberFormats(xRef->getNumberFormats(), uno::UNO_QUERY_THROW);
+ css::lang::Locale aLocale = LanguageTag::convertToLocale(aFormat->aLanguage);
+ nFormatKey = rxNumberFormats->queryKey( aFormat->aFormatString, aLocale, false );
+ if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
+ nFormatKey = rxNumberFormats->addNew( aFormat->aFormatString, aLocale );
+ }
+ catch( const uno::Exception& )
+ {
+ nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND;
+ }
+
+ Sequence< PropertyValue > aArgs( 1 );
+ aArgs[0].Name = "NumberFormatCurrency";
+ aArgs[0].Value = makeAny( nFormatKey );
+ SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
+ ".uno:NumberFormatCurrency",
+ aArgs );
+}
+
IMPL_LINK_NOARG_TYPED(SvxLineWindow_Impl, SelectHdl, ListBox&, void)
{
SvxLineItem aLineItem( SID_FRAME_LINESTYLE );
@@ -2904,6 +3011,38 @@ 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_nSelectedEntry(0)
+{
+ rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
+}
+
+SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {}
+
+VclPtr<SfxPopupWindow> SvxCurrencyToolBoxControl::CreatePopupWindow()
+{
+ VclPtr<SvxCurrencyList_Impl> pCurrencyWin = VclPtr<SvxCurrencyList_Impl>::Create( GetSlotId(), m_xFrame, &GetToolBox(), getContext(), m_nSelectedEntry );
+ pCurrencyWin->StartPopupMode( &GetToolBox(),
+ FloatWinPopupFlags::GrabFocus |
+ FloatWinPopupFlags::AllowTearOff |
+ FloatWinPopupFlags::NoAppFocusClose );
+ SetPopupWindow( pCurrencyWin );
+
+ return pCurrencyWin;
+}
+
+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 )
{