vcl/inc/jsdialog/jsdialogbuilder.hxx | 8 + vcl/inc/salvtables.hxx | 49 ++++++++ vcl/jsdialog/jsdialogbuilder.cxx | 18 +++ vcl/source/app/salvtables.cxx | 199 ++++++++++++++++------------------- 4 files changed, 168 insertions(+), 106 deletions(-)
New commits: commit 91b52830dbbcc2ee2dabbc646249ed804af1964b Author: Szymon Kłos <[email protected]> AuthorDate: Thu Jun 10 15:40:33 2021 +0200 Commit: Szymon Kłos <[email protected]> CommitDate: Fri Jun 11 10:19:38 2021 +0200 jsdialog: weld MenuButton Change-Id: I79b753e070183daa809b23dbb7d3052000ebecd4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116995 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 266d19272a18..cbdd4669cab3 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -253,6 +253,7 @@ public: virtual std::unique_ptr<weld::IconView> weld_icon_view(const OString& id) override; virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const OString& id) override; virtual std::unique_ptr<weld::Frame> weld_frame(const OString& id) override; + virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const OString& id) override; static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, @@ -608,4 +609,11 @@ public: bool bTakeOwnership); }; +class JSMenuButton : public JSWidget<SalInstanceMenuButton, ::MenuButton> +{ +public: + JSMenuButton(JSDialogSender* pSender, ::MenuButton* pMenuButton, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 5cb55ed4f5d3..6657e830e3e6 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -873,6 +873,18 @@ std::unique_ptr<weld::Frame> JSInstanceBuilder::weld_frame(const OString& id) return pWeldWidget; } +std::unique_ptr<weld::MenuButton> JSInstanceBuilder::weld_menu_button(const OString& id) +{ + ::MenuButton* pMenuButton = m_xBuilder->get<::MenuButton>(id); + auto pWeldWidget + = pMenuButton ? std::make_unique<JSMenuButton>(this, pMenuButton, this, false) : nullptr; + + if (pWeldWidget) + RememberWidget(id, pWeldWidget.get()); + + return pWeldWidget; +} + weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, VclButtonsType eButtonType, @@ -1407,4 +1419,10 @@ JSFrame::JSFrame(JSDialogSender* pSender, ::VclFrame* pFrame, SalInstanceBuilder { } +JSMenuButton::JSMenuButton(JSDialogSender* pSender, ::MenuButton* pMenuButton, + SalInstanceBuilder* pBuilder, bool bTakeOwnership) + : JSWidget<SalInstanceMenuButton, ::MenuButton>(pSender, pMenuButton, pBuilder, bTakeOwnership) +{ +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ commit e4a4e866bfaef91fa7c92e3c0095fc3bf16b87bb Author: Szymon Kłos <[email protected]> AuthorDate: Thu Jun 10 15:32:49 2021 +0200 Commit: Szymon Kłos <[email protected]> CommitDate: Fri Jun 11 10:19:23 2021 +0200 Move SalInstanceMenuButton decl to header Change-Id: I5f5f0ceb58925874c6878760a99179a4936198fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116991 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Szymon Kłos <[email protected]> diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 52b71320c332..a1927efd633d 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1812,4 +1812,53 @@ public: virtual std::unique_ptr<weld::Label> weld_label_widget() const override; }; +class SalInstanceMenuButton : public SalInstanceButton, public virtual weld::MenuButton +{ +private: + VclPtr<::MenuButton> m_xMenuButton; + sal_uInt16 m_nLastId; + + DECL_LINK(MenuSelectHdl, ::MenuButton*, void); + DECL_LINK(ActivateHdl, ::MenuButton*, void); + +public: + SalInstanceMenuButton(::MenuButton* pButton, SalInstanceBuilder* pBuilder, bool bTakeOwnership); + + virtual void set_active(bool active) override; + + virtual bool get_active() const override; + + virtual void set_inconsistent(bool /*inconsistent*/) override; + + virtual bool get_inconsistent() const override; + + virtual void insert_item(int pos, const OUString& rId, const OUString& rStr, + const OUString* pIconName, VirtualDevice* pImageSurface, + TriState eCheckRadioFalse) override; + + virtual void insert_separator(int pos, const OUString& rId) override; + + virtual void set_item_sensitive(const OString& rIdent, bool bSensitive) override; + + virtual void remove_item(const OString& rId) override; + + virtual void clear() override; + + virtual void set_item_active(const OString& rIdent, bool bActive) override; + + virtual void set_item_label(const OString& rIdent, const OUString& rText) override; + + virtual OUString get_item_label(const OString& rIdent) const override; + + virtual void set_item_visible(const OString& rIdent, bool bShow) override; + + virtual void set_item_help_id(const OString& rIdent, const OString& rHelpId) override; + + virtual OString get_item_help_id(const OString& rIdent) const override; + + virtual void set_popover(weld::Widget* pPopover) override; + + virtual ~SalInstanceMenuButton() override; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 0501ff7fa359..ec19d667fb4d 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -2602,132 +2602,119 @@ weld::Button* SalInstanceAssistant::weld_widget_for_response(int nResponse) return nullptr; } -namespace -{ -class SalInstanceMenuButton : public SalInstanceButton, public virtual weld::MenuButton +SalInstanceMenuButton::SalInstanceMenuButton(::MenuButton* pButton, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceButton(pButton, pBuilder, bTakeOwnership) + , m_xMenuButton(pButton) + , m_nLastId(0) { -private: - VclPtr<::MenuButton> m_xMenuButton; - sal_uInt16 m_nLastId; - - DECL_LINK(MenuSelectHdl, ::MenuButton*, void); - DECL_LINK(ActivateHdl, ::MenuButton*, void); - -public: - SalInstanceMenuButton(::MenuButton* pButton, SalInstanceBuilder* pBuilder, bool bTakeOwnership) - : SalInstanceButton(pButton, pBuilder, bTakeOwnership) - , m_xMenuButton(pButton) - , m_nLastId(0) + m_xMenuButton->SetActivateHdl(LINK(this, SalInstanceMenuButton, ActivateHdl)); + m_xMenuButton->SetSelectHdl(LINK(this, SalInstanceMenuButton, MenuSelectHdl)); + if (PopupMenu* pMenu = m_xMenuButton->GetPopupMenu()) { - m_xMenuButton->SetActivateHdl(LINK(this, SalInstanceMenuButton, ActivateHdl)); - m_xMenuButton->SetSelectHdl(LINK(this, SalInstanceMenuButton, MenuSelectHdl)); - if (PopupMenu* pMenu = m_xMenuButton->GetPopupMenu()) - { - pMenu->SetMenuFlags(MenuFlags::NoAutoMnemonics); - const auto nCount = pMenu->GetItemCount(); - m_nLastId = nCount ? pMenu->GetItemId(nCount - 1) : 0; - } + pMenu->SetMenuFlags(MenuFlags::NoAutoMnemonics); + const auto nCount = pMenu->GetItemCount(); + m_nLastId = nCount ? pMenu->GetItemId(nCount - 1) : 0; } +} - virtual void set_active(bool active) override - { - if (active == get_active()) - return; - if (active) - m_xMenuButton->ExecuteMenu(); - else - m_xMenuButton->CancelMenu(); - } +void SalInstanceMenuButton::set_active(bool active) +{ + if (active == get_active()) + return; + if (active) + m_xMenuButton->ExecuteMenu(); + else + m_xMenuButton->CancelMenu(); +} - virtual bool get_active() const override { return m_xMenuButton->InPopupMode(); } +bool SalInstanceMenuButton::get_active() const { return m_xMenuButton->InPopupMode(); } - virtual void set_inconsistent(bool /*inconsistent*/) override - { - //not available - } +void SalInstanceMenuButton::set_inconsistent(bool /*inconsistent*/) +{ + //not available +} - virtual bool get_inconsistent() const override { return false; } +bool SalInstanceMenuButton::get_inconsistent() const { return false; } - virtual void insert_item(int pos, const OUString& rId, const OUString& rStr, - const OUString* pIconName, VirtualDevice* pImageSurface, - TriState eCheckRadioFalse) override - { - m_nLastId = insert_to_menu(m_nLastId, m_xMenuButton->GetPopupMenu(), pos, rId, rStr, - pIconName, pImageSurface, nullptr, eCheckRadioFalse); - } +void SalInstanceMenuButton::insert_item(int pos, const OUString& rId, const OUString& rStr, + const OUString* pIconName, VirtualDevice* pImageSurface, + TriState eCheckRadioFalse) +{ + m_nLastId = insert_to_menu(m_nLastId, m_xMenuButton->GetPopupMenu(), pos, rId, rStr, pIconName, + pImageSurface, nullptr, eCheckRadioFalse); +} - virtual void insert_separator(int pos, const OUString& rId) override - { - auto nInsertPos = pos == -1 ? MENU_APPEND : pos; - m_xMenuButton->GetPopupMenu()->InsertSeparator(rId.toUtf8(), nInsertPos); - } +void SalInstanceMenuButton::insert_separator(int pos, const OUString& rId) +{ + auto nInsertPos = pos == -1 ? MENU_APPEND : pos; + m_xMenuButton->GetPopupMenu()->InsertSeparator(rId.toUtf8(), nInsertPos); +} - virtual void set_item_sensitive(const OString& rIdent, bool bSensitive) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->EnableItem(rIdent, bSensitive); - } +void SalInstanceMenuButton::set_item_sensitive(const OString& rIdent, bool bSensitive) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->EnableItem(rIdent, bSensitive); +} - virtual void remove_item(const OString& rId) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->RemoveItem(pMenu->GetItemPos(pMenu->GetItemId(rId))); - } +void SalInstanceMenuButton::remove_item(const OString& rId) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->RemoveItem(pMenu->GetItemPos(pMenu->GetItemId(rId))); +} - virtual void clear() override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->Clear(); - } +void SalInstanceMenuButton::clear() +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->Clear(); +} - virtual void set_item_active(const OString& rIdent, bool bActive) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->CheckItem(rIdent, bActive); - } +void SalInstanceMenuButton::set_item_active(const OString& rIdent, bool bActive) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->CheckItem(rIdent, bActive); +} - virtual void set_item_label(const OString& rIdent, const OUString& rText) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->SetItemText(pMenu->GetItemId(rIdent), rText); - } +void SalInstanceMenuButton::set_item_label(const OString& rIdent, const OUString& rText) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->SetItemText(pMenu->GetItemId(rIdent), rText); +} - virtual OUString get_item_label(const OString& rIdent) const override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - return pMenu->GetItemText(pMenu->GetItemId(rIdent)); - } +OUString SalInstanceMenuButton::get_item_label(const OString& rIdent) const +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + return pMenu->GetItemText(pMenu->GetItemId(rIdent)); +} - virtual void set_item_visible(const OString& rIdent, bool bShow) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->ShowItem(pMenu->GetItemId(rIdent), bShow); - } +void SalInstanceMenuButton::set_item_visible(const OString& rIdent, bool bShow) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->ShowItem(pMenu->GetItemId(rIdent), bShow); +} - virtual void set_item_help_id(const OString& rIdent, const OString& rHelpId) override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - pMenu->SetHelpId(pMenu->GetItemId(rIdent), rHelpId); - } +void SalInstanceMenuButton::set_item_help_id(const OString& rIdent, const OString& rHelpId) +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + pMenu->SetHelpId(pMenu->GetItemId(rIdent), rHelpId); +} - virtual OString get_item_help_id(const OString& rIdent) const override - { - PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); - return pMenu->GetHelpId(pMenu->GetItemId(rIdent)); - } +OString SalInstanceMenuButton::get_item_help_id(const OString& rIdent) const +{ + PopupMenu* pMenu = m_xMenuButton->GetPopupMenu(); + return pMenu->GetHelpId(pMenu->GetItemId(rIdent)); +} - virtual void set_popover(weld::Widget* pPopover) override - { - SalInstanceWidget* pPopoverWidget = dynamic_cast<SalInstanceWidget*>(pPopover); - m_xMenuButton->SetPopover(pPopoverWidget ? pPopoverWidget->getWidget() : nullptr); - } +void SalInstanceMenuButton::set_popover(weld::Widget* pPopover) +{ + SalInstanceWidget* pPopoverWidget = dynamic_cast<SalInstanceWidget*>(pPopover); + m_xMenuButton->SetPopover(pPopoverWidget ? pPopoverWidget->getWidget() : nullptr); +} - virtual ~SalInstanceMenuButton() override - { - m_xMenuButton->SetSelectHdl(Link<::MenuButton*, void>()); - m_xMenuButton->SetActivateHdl(Link<::MenuButton*, void>()); - } -}; +SalInstanceMenuButton::~SalInstanceMenuButton() +{ + m_xMenuButton->SetSelectHdl(Link<::MenuButton*, void>()); + m_xMenuButton->SetActivateHdl(Link<::MenuButton*, void>()); } IMPL_LINK_NOARG(SalInstanceMenuButton, MenuSelectHdl, ::MenuButton*, void) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
