diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-12-27 17:18:44 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-01-01 13:19:28 +0100 |
commit | b199e335c01f265ba2604c020928b63356b42d15 (patch) | |
tree | 1015423b1bb5b45ce28e8a4a47ea6e20188b8795 /svx | |
parent | f0fc4ac88d0d82ee81e0a55bdc54421f955705f0 (diff) |
weld NumberFormatPropertyPanel
including GtkMenuToolButton hackery to support a toggled state
Change-Id: Ia1cf5fd7d56c2e475194cd2d0431611f278f5a33
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85873
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/UIConfig_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 154 | ||||
-rw-r--r-- | svx/uiconfig/ui/currencywindow.ui | 95 |
3 files changed, 249 insertions, 1 deletions
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk index 6193d0c52475..689e59fa9ec1 100644 --- a/svx/UIConfig_svx.mk +++ b/svx/UIConfig_svx.mk @@ -26,6 +26,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\ svx/uiconfig/ui/chinesedictionary \ svx/uiconfig/ui/classificationdialog \ svx/uiconfig/ui/colorwindow \ + svx/uiconfig/ui/currencywindow \ svx/uiconfig/ui/colsmenu \ svx/uiconfig/ui/compressgraphicdialog \ svx/uiconfig/ui/convertmenu \ diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 50eaa75212d1..b4c7ca5e4e9f 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -32,6 +32,7 @@ #include <vcl/bitmapaccess.hxx> #include <vcl/menubtn.hxx> #include <vcl/vclptr.hxx> +#include <vcl/weldutils.hxx> #include <svtools/valueset.hxx> #include <svtools/ctrlbox.hxx> #include <svl/style.hxx> @@ -3740,16 +3741,167 @@ void SvxSimpleUndoRedoController::StateChanged( sal_uInt16, SfxItemState eState, SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) : PopupWindowController( rContext, nullptr, OUString() ), m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ), - m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND ) + m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND ), + m_pToolbar(nullptr) { } SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {} +namespace +{ + + class ToolbarPopup : public svtools::ToolbarPopupBase + { + protected: + std::unique_ptr<weld::Builder> m_xBuilder; + std::unique_ptr<weld::Container> m_xTopLevel; + public: + ToolbarPopup(const css::uno::Reference<css::frame::XFrame>& rFrame, weld::Widget* pParent, const OUString& rUIFile, const OString& rId) + : ToolbarPopupBase(rFrame) + , m_xBuilder(Application::CreateBuilder(pParent, rUIFile)) + , m_xTopLevel(m_xBuilder->weld_container(rId)) + { + } + weld::Container* getTopLevel() + { + return m_xTopLevel.get(); + } + }; + + class CurrencyList_Impl : public ToolbarPopup + { + private: + rtl::Reference<SvxCurrencyToolBoxControl> m_xControl; + std::unique_ptr<weld::Label> m_xLabel; + std::unique_ptr<weld::TreeView> m_xCurrencyLb; + std::unique_ptr<weld::Button> m_xOkBtn; + OUString& m_rSelectedFormat; + LanguageType& m_eSelectedLanguage; + + std::vector<OUString> m_aFormatEntries; + LanguageType m_eFormatLanguage; + DECL_LINK(RowActivatedHdl, weld::TreeView&, bool); + DECL_LINK(FocusHdl, weld::Widget&, void); + DECL_LINK(OKHdl, weld::Button&, void); + + public: + CurrencyList_Impl(SvxCurrencyToolBoxControl* pControl, weld::Widget* pParent, OUString& rSelectedFormat, LanguageType& eSelectedLanguage) + : ToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/currencywindow.ui", "CurrencyWindow") + , m_xControl(pControl) + , m_xLabel(m_xBuilder->weld_label("label")) + , m_xCurrencyLb(m_xBuilder->weld_tree_view("currency")) + , m_xOkBtn(m_xBuilder->weld_button("ok")) + , m_rSelectedFormat(rSelectedFormat) + , m_eSelectedLanguage(eSelectedLanguage) + { + m_xTopLevel->connect_focus_in(LINK(this, CurrencyList_Impl, FocusHdl)); + + m_xCurrencyLb->set_size_request(-1, m_xCurrencyLb->get_height_rows(12)); + + std::vector< OUString > aList; + std::vector< sal_uInt16 > aCurrencyList; + const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable(); + sal_uInt16 nLen = rCurrencyTable.size(); + + SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM ); + m_eFormatLanguage = aFormatter.GetLanguage(); + + SvxCurrencyToolBoxControl::GetCurrencySymbols( aList, true, aCurrencyList ); + + sal_uInt16 nPos = 0, nCount = 0; + sal_Int32 nSelectedPos = -1; + bool bIsSymbol; + NfWSStringsDtor aStringsDtor; + + for( const auto& rItem : aList ) + { + sal_uInt16& rCurrencyIndex = aCurrencyList[ nCount ]; + if ( rCurrencyIndex < nLen ) + { + m_xCurrencyLb->append_text(rItem); + const NfCurrencyEntry& aCurrencyEntry = rCurrencyTable[ rCurrencyIndex ]; + + bIsSymbol = nPos >= nLen; + + sal_uInt16 nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, aCurrencyEntry, bIsSymbol ); + const OUString& rFormatStr = aStringsDtor[ nDefaultFormat ]; + m_aFormatEntries.push_back( rFormatStr ); + if( rFormatStr == m_rSelectedFormat ) + nSelectedPos = nPos; + ++nPos; + } + ++nCount; + } + // enable multiple selection enabled so we can start with nothing selected + m_xCurrencyLb->set_selection_mode(SelectionMode::Multiple); + m_xCurrencyLb->connect_row_activated( LINK( this, CurrencyList_Impl, RowActivatedHdl ) ); + m_xLabel->set_label(SvxResId(RID_SVXSTR_TBLAFMT_CURRENCY)); + m_xCurrencyLb->select( nSelectedPos ); + m_xOkBtn->connect_clicked(LINK(this, CurrencyList_Impl, OKHdl)); + } + + }; + + IMPL_LINK_NOARG(CurrencyList_Impl, FocusHdl, weld::Widget&, void) + { + m_xCurrencyLb->grab_focus(); + } + + IMPL_LINK_NOARG(CurrencyList_Impl, OKHdl, weld::Button&, void) + { + RowActivatedHdl(*m_xCurrencyLb); + } + + IMPL_LINK_NOARG(CurrencyList_Impl, RowActivatedHdl, weld::TreeView&, bool) + { + if (!m_xControl.is()) + return true; + + // multiple selection enabled so we can start with nothing selected, + // so force single selection after something is picked + int nSelected = m_xCurrencyLb->get_selected_index(); + if (nSelected == -1) + return true; + + m_xCurrencyLb->set_selection_mode(SelectionMode::Single); + + m_rSelectedFormat = m_aFormatEntries[nSelected]; + m_eSelectedLanguage = m_eFormatLanguage; + + m_xControl->execute(nSelected + 1); + + m_xControl->EndPopupMode(); + + return true; + } +} + +void SvxCurrencyToolBoxControl::EndPopupMode() +{ + m_pToolbar->set_menu_item_active(m_aCommandURL.toUtf8(), false); +} + +void SvxCurrencyToolBoxControl::dispose() +{ + m_xPopover.reset(); + svt::PopupWindowController::dispose(); +} + void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) { PopupWindowController::initialize(rArguments); + if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(getParent().get())) + { + m_pToolbar = dynamic_cast<weld::Toolbar*>(pTunnel->getWidget()); + assert(m_pToolbar && "must be a toolbar"); + auto xPopover = std::make_unique<CurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage); + m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), xPopover->getTopLevel()); + m_xPopover = std::move(xPopover); + return; + } + ToolBox* pToolBox = nullptr; sal_uInt16 nId = 0; if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) diff --git a/svx/uiconfig/ui/currencywindow.ui b/svx/uiconfig/ui/currencywindow.ui new file mode 100644 index 000000000000..982536c65c7e --- /dev/null +++ b/svx/uiconfig/ui/currencywindow.ui @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface domain="svx"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> + <object class="GtkPopover" id="CurrencyWindow"> + <property name="can_focus">False</property> + <property name="no_show_all">True</property> + <property name="border_width">4</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkLabel" id="label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">currency</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="hscrollbar_policy">never</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTreeView" id="currency"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore1</property> + <property name="headers_visible">False</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> + <property name="show_expanders">False</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="selection"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="ok"> + <property name="label">gtk-ok</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + </object> +</interface> |