From fbc8f81aa7824218fe8b0d50e6633026386f0610 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Tue, 12 May 2020 12:22:28 +0200 Subject: Move SalInstanceComboBox to header file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iafa449cc1ebba93cc69da194857ea33b8f8510b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94049 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- vcl/inc/salvtables.hxx | 359 +++++++++++++++++++- vcl/source/app/salvtables.cxx | 771 ++++++++++++++---------------------------- 2 files changed, 621 insertions(+), 509 deletions(-) diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 9342903b49ae..de8a3c6704f2 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -16,6 +16,10 @@ #include #include #include +#include +#include +#include +#include class SalInstanceBuilder : public weld::Builder { @@ -151,6 +155,36 @@ public: virtual ~SalInstanceBuilder() override; }; +class SalInstanceMenu : public weld::Menu +{ +private: + VclPtr m_xMenu; + + bool m_bTakeOwnership; + sal_uInt16 m_nLastId; + + DECL_LINK(SelectMenuHdl, ::Menu*, bool); + +public: + SalInstanceMenu(PopupMenu* pMenu, bool bTakeOwnership); + virtual OString popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect) override; + virtual void set_sensitive(const OString& rIdent, bool bSensitive) override; + virtual void set_active(const OString& rIdent, bool bActive) override; + virtual bool get_active(const OString& rIdent) const override; + virtual void set_label(const OString& rIdent, const OUString& rLabel) override; + virtual OUString get_label(const OString& rIdent) const override; + virtual void set_visible(const OString& rIdent, bool bShow) override; + virtual void clear() override; + virtual void insert(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 remove(const OString& rId) override; + virtual int n_children() const override; + PopupMenu* getMenu() const; + virtual ~SalInstanceMenu() override; +}; + class SalInstanceWidget : public virtual weld::Widget { protected: @@ -622,4 +656,327 @@ public: virtual ~SalInstanceSpinButton() override; }; -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ +//ComboBox and ListBox have similar apis, ComboBoxes in LibreOffice have an edit box and ListBoxes +//don't. This distinction isn't there in Gtk. Use a template to sort this problem out. +template +class SalInstanceComboBox : public SalInstanceContainer, public virtual weld::ComboBox +{ +protected: + // owner for ListBox/ComboBox UserData + std::vector> m_aUserData; + VclPtr m_xComboBox; + ScopedVclPtr m_xMenuButton; + OUString m_sMenuButtonRow; + +public: + SalInstanceComboBox(vcl_type* pComboBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership) + : SalInstanceContainer(pComboBox, pBuilder, bTakeOwnership) + , m_xComboBox(pComboBox) + { + } + + virtual int get_active() const override + { + const sal_Int32 nRet = m_xComboBox->GetSelectedEntryPos(); + if (nRet == LISTBOX_ENTRY_NOTFOUND) + return -1; + return nRet; + } + + const OUString* getEntryData(int index) const + { + return static_cast(m_xComboBox->GetEntryData(index)); + } + + // ComboBoxes are comprised of multiple subwidgets, consider the lot as + // one thing for focus + virtual bool has_focus() const override + { + return m_xWidget->HasChildPathFocus() + || (m_xMenuButton && (m_xMenuButton->HasFocus() || m_xMenuButton->InPopupMode())); + } + + virtual OUString get_active_id() const override + { + sal_Int32 nPos = m_xComboBox->GetSelectedEntryPos(); + const OUString* pRet; + if (nPos != LISTBOX_ENTRY_NOTFOUND) + pRet = getEntryData(m_xComboBox->GetSelectedEntryPos()); + else + pRet = nullptr; + if (!pRet) + return OUString(); + return *pRet; + } + + virtual void set_active_id(const OUString& rStr) override + { + for (int i = 0; i < get_count(); ++i) + { + const OUString* pId = getEntryData(i); + if (!pId) + continue; + if (*pId == rStr) + m_xComboBox->SelectEntryPos(i); + } + } + + virtual void set_active(int pos) override + { + if (pos == -1) + { + m_xComboBox->SetNoSelection(); + return; + } + m_xComboBox->SelectEntryPos(pos); + } + + virtual OUString get_text(int pos) const override { return m_xComboBox->GetEntry(pos); } + + virtual OUString get_id(int pos) const override + { + const OUString* pRet = getEntryData(pos); + if (!pRet) + return OUString(); + return *pRet; + } + + virtual void set_id(int row, const OUString& rId) override + { + m_aUserData.emplace_back(std::make_unique(rId)); + m_xComboBox->SetEntryData(row, m_aUserData.back().get()); + } + + virtual void insert_vector(const std::vector& rItems, + bool bKeepExisting) override + { + freeze(); + if (!bKeepExisting) + clear(); + for (const auto& rItem : rItems) + { + insert(-1, rItem.sString, rItem.sId.isEmpty() ? nullptr : &rItem.sId, + rItem.sImage.isEmpty() ? nullptr : &rItem.sImage, nullptr); + } + thaw(); + } + + virtual int get_count() const override { return m_xComboBox->GetEntryCount(); } + + virtual int find_text(const OUString& rStr) const override + { + const sal_Int32 nRet = m_xComboBox->GetEntryPos(rStr); + if (nRet == LISTBOX_ENTRY_NOTFOUND) + return -1; + return nRet; + } + + virtual int find_id(const OUString& rStr) const override + { + for (int i = 0; i < get_count(); ++i) + { + const OUString* pId = getEntryData(i); + if (!pId) + continue; + if (*pId == rStr) + return i; + } + return -1; + } + + virtual void clear() override + { + m_xComboBox->Clear(); + m_aUserData.clear(); + } + + virtual void make_sorted() override + { + m_xComboBox->SetStyle(m_xComboBox->GetStyle() | WB_SORT); + } + + virtual bool get_popup_shown() const override { return m_xComboBox->IsInDropDown(); } + + virtual void connect_popup_toggled(const Link& rLink) override + { + weld::ComboBox::connect_popup_toggled(rLink); + ensure_event_listener(); + } + + void call_signal_custom_render(UserDrawEvent* pEvent) + { + vcl::RenderContext* pRenderContext = pEvent->GetRenderContext(); + auto nPos = pEvent->GetItemId(); + const tools::Rectangle& rRect = pEvent->GetRect(); + const OUString sId = get_id(nPos); + signal_custom_render(*pRenderContext, rRect, pEvent->IsSelected(), sId); + m_xComboBox->DrawEntry(*pEvent, false, false); // draw separator + + if (m_xMenuButton && m_xMenuButton->IsVisible() && m_sMenuButtonRow == sId) + { + if (m_xMenuButton->GetParent() != pEvent->GetWindow()) + m_xMenuButton->SetParent(pEvent->GetWindow()); + int nButtonWidth = get_menu_button_width(); + m_xMenuButton->SetSizePixel(Size(nButtonWidth, rRect.GetHeight())); + m_xMenuButton->SetPosPixel(Point(rRect.GetWidth() - nButtonWidth, rRect.getY())); + } + } + + VclPtr create_render_virtual_device() const override + { + return VclPtr::Create(); + } + + virtual void set_item_menu(const OString& rIdent, weld::Menu* pMenu) override + { + SalInstanceMenu* pInstanceMenu = dynamic_cast(pMenu); + + PopupMenu* pPopup = pInstanceMenu ? pInstanceMenu->getMenu() : nullptr; + + if (!m_xMenuButton) + m_xMenuButton + = VclPtr::Create(m_xComboBox, WB_FLATBUTTON | WB_NOPOINTERFOCUS); + + m_xMenuButton->SetPopupMenu(pPopup); + m_xMenuButton->Show(pPopup != nullptr); + m_sMenuButtonRow = OUString::fromUtf8(rIdent); + } + + int get_menu_button_width() const override + { + const int nButtonWidth = 20; + return nButtonWidth; + } + + void CallHandleEventListener(VclWindowEvent& rEvent) + { + if (rEvent.GetId() == VclEventId::DropdownPreOpen + || rEvent.GetId() == VclEventId::DropdownClose) + { + signal_popup_toggled(); + return; + } + SalInstanceContainer::HandleEventListener(rEvent); + } +}; + +class SalInstanceComboBoxWithoutEdit : public SalInstanceComboBox +{ +private: + DECL_LINK(SelectHdl, ListBox&, void); + +public: + SalInstanceComboBoxWithoutEdit(ListBox* pListBox, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); + + virtual OUString get_active_text() const override; + + virtual void remove(int pos) override; + + virtual void insert(int pos, const OUString& rStr, const OUString* pId, + const OUString* pIconName, VirtualDevice* pImageSurface) override; + + virtual void insert_separator(int pos, const OUString& /*rId*/) override; + + virtual bool has_entry() const override; + + virtual bool changed_by_direct_pick() const override; + + virtual void set_entry_message_type(weld::EntryMessageType /*eType*/) override; + + virtual void set_entry_text(const OUString& /*rText*/) override; + + virtual void select_entry_region(int /*nStartPos*/, int /*nEndPos*/) override; + + virtual bool get_entry_selection_bounds(int& /*rStartPos*/, int& /*rEndPos*/) override; + + virtual void set_entry_width_chars(int /*nChars*/) override; + + virtual void set_entry_max_length(int /*nChars*/) override; + + virtual void set_entry_completion(bool, bool bCaseSensitive = false) override; + + virtual void set_entry_placeholder_text(const OUString&) override; + + virtual void set_entry_font(const vcl::Font&) override; + + virtual vcl::Font get_entry_font() override; + + virtual void set_custom_renderer() override; + + virtual int get_max_mru_count() const override; + + virtual void set_max_mru_count(int) override; + + virtual OUString get_mru_entries() const override; + + virtual void set_mru_entries(const OUString&) override; + + virtual void HandleEventListener(VclWindowEvent& rEvent) override; + + virtual ~SalInstanceComboBoxWithoutEdit() override; +}; + +class SalInstanceComboBoxWithEdit : public SalInstanceComboBox +{ +private: + DECL_LINK(ChangeHdl, Edit&, void); + DECL_LINK(EntryActivateHdl, Edit&, bool); + DECL_LINK(SelectHdl, ::ComboBox&, void); + DECL_LINK(UserDrawHdl, UserDrawEvent*, void); + WeldTextFilter m_aTextFilter; + bool m_bInSelect; + +public: + SalInstanceComboBoxWithEdit(::ComboBox* pComboBox, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); + + virtual bool has_entry() const override; + + virtual bool changed_by_direct_pick() const override; + + virtual void set_entry_message_type(weld::EntryMessageType eType) override; + + virtual OUString get_active_text() const override; + + virtual void remove(int pos) override; + + virtual void insert(int pos, const OUString& rStr, const OUString* pId, + const OUString* pIconName, VirtualDevice* pImageSurface) override; + + virtual void insert_separator(int pos, const OUString& /*rId*/) override; + + virtual void set_entry_text(const OUString& rText) override; + + virtual void set_entry_width_chars(int nChars) override; + + virtual void set_entry_max_length(int nChars) override; + + virtual void set_entry_completion(bool bEnable, bool bCaseSensitive = false) override; + + virtual void set_entry_placeholder_text(const OUString& rText) override; + + virtual void select_entry_region(int nStartPos, int nEndPos) override; + + virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) override; + + virtual void set_entry_font(const vcl::Font& rFont) override; + + virtual vcl::Font get_entry_font() override; + + virtual void set_custom_renderer() override; + + virtual int get_max_mru_count() const override; + + virtual void set_max_mru_count(int nCount) override; + + virtual OUString get_mru_entries() const override; + + virtual void set_mru_entries(const OUString& rEntries) override; + + virtual void HandleEventListener(VclWindowEvent& rEvent) override; + + virtual ~SalInstanceComboBoxWithEdit() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index a5e027a5de1f..a6d9ed05753d 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -669,86 +668,70 @@ sal_uInt16 insert_to_menu(sal_uInt16 nLastId, PopupMenu* pMenu, int pos, const O } } -namespace +SalInstanceMenu::SalInstanceMenu(PopupMenu* pMenu, bool bTakeOwnership) + : m_xMenu(pMenu) + , m_bTakeOwnership(bTakeOwnership) { -class SalInstanceMenu : public weld::Menu + const auto nCount = m_xMenu->GetItemCount(); + m_nLastId = nCount ? pMenu->GetItemId(nCount - 1) : 0; + m_xMenu->SetSelectHdl(LINK(this, SalInstanceMenu, SelectMenuHdl)); +} +OString SalInstanceMenu::popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect) { -private: - VclPtr m_xMenu; - - bool m_bTakeOwnership; - sal_uInt16 m_nLastId; - - DECL_LINK(SelectMenuHdl, ::Menu*, bool); - -public: - SalInstanceMenu(PopupMenu* pMenu, bool bTakeOwnership) - : m_xMenu(pMenu) - , m_bTakeOwnership(bTakeOwnership) - { - const auto nCount = m_xMenu->GetItemCount(); - m_nLastId = nCount ? pMenu->GetItemId(nCount - 1) : 0; - m_xMenu->SetSelectHdl(LINK(this, SalInstanceMenu, SelectMenuHdl)); - } - virtual OString popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect) override - { - SalInstanceWidget* pVclWidget = dynamic_cast(pParent); - assert(pVclWidget); - m_xMenu->Execute(pVclWidget->getWidget(), rRect, - PopupMenuFlags::ExecuteDown | PopupMenuFlags::NoMouseUpClose); - return m_xMenu->GetCurItemIdent(); - } - virtual void set_sensitive(const OString& rIdent, bool bSensitive) override - { - m_xMenu->EnableItem(rIdent, bSensitive); - } - virtual void set_active(const OString& rIdent, bool bActive) override - { - m_xMenu->CheckItem(rIdent, bActive); - } - virtual bool get_active(const OString& rIdent) const override - { - return m_xMenu->IsItemChecked(m_xMenu->GetItemId(rIdent)); - } - virtual void set_label(const OString& rIdent, const OUString& rLabel) override - { - m_xMenu->SetItemText(m_xMenu->GetItemId(rIdent), rLabel); - } - virtual OUString get_label(const OString& rIdent) const override - { - return m_xMenu->GetItemText(m_xMenu->GetItemId(rIdent)); - } - virtual void set_visible(const OString& rIdent, bool bShow) override - { - m_xMenu->ShowItem(m_xMenu->GetItemId(rIdent), bShow); - } - virtual void clear() override { m_xMenu->Clear(); } - virtual void insert(int pos, const OUString& rId, const OUString& rStr, - const OUString* pIconName, VirtualDevice* pImageSurface, - TriState eCheckRadioFalse) override - { - m_nLastId - = insert_to_menu(m_nLastId, m_xMenu, pos, rId, rStr, pIconName, pImageSurface, eCheckRadioFalse); - } - virtual void insert_separator(int pos, const OUString& rId) override - { - auto nInsertPos = pos == -1 ? MENU_APPEND : pos; - m_xMenu->InsertSeparator(rId.toUtf8(), nInsertPos); - } - virtual void remove(const OString& rId) override - { - m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId(rId))); - } - virtual int n_children() const override { return m_xMenu->GetItemCount(); } - PopupMenu* getMenu() const { return m_xMenu.get(); } - virtual ~SalInstanceMenu() override - { - m_xMenu->SetSelectHdl(Link<::Menu*, bool>()); - if (m_bTakeOwnership) - m_xMenu.disposeAndClear(); - } -}; - + SalInstanceWidget* pVclWidget = dynamic_cast(pParent); + assert(pVclWidget); + m_xMenu->Execute(pVclWidget->getWidget(), rRect, + PopupMenuFlags::ExecuteDown | PopupMenuFlags::NoMouseUpClose); + return m_xMenu->GetCurItemIdent(); +} +void SalInstanceMenu::set_sensitive(const OString& rIdent, bool bSensitive) +{ + m_xMenu->EnableItem(rIdent, bSensitive); +} +void SalInstanceMenu::set_active(const OString& rIdent, bool bActive) +{ + m_xMenu->CheckItem(rIdent, bActive); +} +bool SalInstanceMenu::get_active(const OString& rIdent) const +{ + return m_xMenu->IsItemChecked(m_xMenu->GetItemId(rIdent)); +} +void SalInstanceMenu::set_label(const OString& rIdent, const OUString& rLabel) +{ + m_xMenu->SetItemText(m_xMenu->GetItemId(rIdent), rLabel); +} +OUString SalInstanceMenu::get_label(const OString& rIdent) const +{ + return m_xMenu->GetItemText(m_xMenu->GetItemId(rIdent)); +} +void SalInstanceMenu::set_visible(const OString& rIdent, bool bShow) +{ + m_xMenu->ShowItem(m_xMenu->GetItemId(rIdent), bShow); +} +void SalInstanceMenu::clear() { m_xMenu->Clear(); } +void SalInstanceMenu::insert(int pos, const OUString& rId, const OUString& rStr, + const OUString* pIconName, VirtualDevice* pImageSurface, + TriState eCheckRadioFalse) +{ + m_nLastId + = insert_to_menu(m_nLastId, m_xMenu, pos, rId, rStr, pIconName, pImageSurface, eCheckRadioFalse); +} +void SalInstanceMenu::insert_separator(int pos, const OUString& rId) +{ + auto nInsertPos = pos == -1 ? MENU_APPEND : pos; + m_xMenu->InsertSeparator(rId.toUtf8(), nInsertPos); +} +void SalInstanceMenu::remove(const OString& rId) +{ + m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId(rId))); +} +int SalInstanceMenu::n_children() const { return m_xMenu->GetItemCount(); } +PopupMenu* SalInstanceMenu::getMenu() const { return m_xMenu.get(); } +SalInstanceMenu::~SalInstanceMenu() +{ + m_xMenu->SetSelectHdl(Link<::Menu*, bool>()); + if (m_bTakeOwnership) + m_xMenu.disposeAndClear(); } IMPL_LINK_NOARG(SalInstanceMenu, SelectMenuHdl, ::Menu*, bool) @@ -5724,320 +5707,107 @@ IMPL_LINK_NOARG(SalInstanceDrawingArea, StartDragHdl, VclDrawingArea*, bool) return false; } -namespace -{ -//ComboBox and ListBox have similar apis, ComboBoxes in LibreOffice have an edit box and ListBoxes -//don't. This distinction isn't there in Gtk. Use a template to sort this problem out. -template -class SalInstanceComboBox : public SalInstanceContainer, public virtual weld::ComboBox +SalInstanceComboBoxWithoutEdit::SalInstanceComboBoxWithoutEdit(ListBox* pListBox, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceComboBox(pListBox, pBuilder, bTakeOwnership) { -protected: - // owner for ListBox/ComboBox UserData - std::vector> m_aUserData; - VclPtr m_xComboBox; - ScopedVclPtr m_xMenuButton; - OUString m_sMenuButtonRow; - -public: - SalInstanceComboBox(vcl_type* pComboBox, SalInstanceBuilder* pBuilder, bool bTakeOwnership) - : SalInstanceContainer(pComboBox, pBuilder, bTakeOwnership) - , m_xComboBox(pComboBox) - { - } - - virtual int get_active() const override - { - const sal_Int32 nRet = m_xComboBox->GetSelectedEntryPos(); - if (nRet == LISTBOX_ENTRY_NOTFOUND) - return -1; - return nRet; - } - - const OUString* getEntryData(int index) const - { - return static_cast(m_xComboBox->GetEntryData(index)); - } - - // ComboBoxes are comprised of multiple subwidgets, consider the lot as - // one thing for focus - virtual bool has_focus() const override - { - return m_xWidget->HasChildPathFocus() || (m_xMenuButton && (m_xMenuButton->HasFocus() || m_xMenuButton->InPopupMode())); - } - - virtual OUString get_active_id() const override - { - sal_Int32 nPos = m_xComboBox->GetSelectedEntryPos(); - const OUString* pRet; - if (nPos != LISTBOX_ENTRY_NOTFOUND) - pRet = getEntryData(m_xComboBox->GetSelectedEntryPos()); - else - pRet = nullptr; - if (!pRet) - return OUString(); - return *pRet; - } - - virtual void set_active_id(const OUString& rStr) override - { - for (int i = 0; i < get_count(); ++i) - { - const OUString* pId = getEntryData(i); - if (!pId) - continue; - if (*pId == rStr) - m_xComboBox->SelectEntryPos(i); - } - } - - virtual void set_active(int pos) override - { - if (pos == -1) - { - m_xComboBox->SetNoSelection(); - return; - } - m_xComboBox->SelectEntryPos(pos); - } - - virtual OUString get_text(int pos) const override { return m_xComboBox->GetEntry(pos); } - - virtual OUString get_id(int pos) const override - { - const OUString* pRet = getEntryData(pos); - if (!pRet) - return OUString(); - return *pRet; - } - - virtual void set_id(int row, const OUString& rId) override - { - m_aUserData.emplace_back(std::make_unique(rId)); - m_xComboBox->SetEntryData(row, m_aUserData.back().get()); - } - - virtual void insert_vector(const std::vector& rItems, - bool bKeepExisting) override - { - freeze(); - if (!bKeepExisting) - clear(); - for (const auto& rItem : rItems) - { - insert(-1, rItem.sString, rItem.sId.isEmpty() ? nullptr : &rItem.sId, - rItem.sImage.isEmpty() ? nullptr : &rItem.sImage, nullptr); - } - thaw(); - } - - virtual int get_count() const override { return m_xComboBox->GetEntryCount(); } - - virtual int find_text(const OUString& rStr) const override - { - const sal_Int32 nRet = m_xComboBox->GetEntryPos(rStr); - if (nRet == LISTBOX_ENTRY_NOTFOUND) - return -1; - return nRet; - } - - virtual int find_id(const OUString& rStr) const override - { - for (int i = 0; i < get_count(); ++i) - { - const OUString* pId = getEntryData(i); - if (!pId) - continue; - if (*pId == rStr) - return i; - } - return -1; - } - - virtual void clear() override - { - m_xComboBox->Clear(); - m_aUserData.clear(); - } - - virtual void make_sorted() override - { - m_xComboBox->SetStyle(m_xComboBox->GetStyle() | WB_SORT); - } - - virtual bool get_popup_shown() const override { return m_xComboBox->IsInDropDown(); } - - virtual void connect_popup_toggled(const Link& rLink) override - { - weld::ComboBox::connect_popup_toggled(rLink); - ensure_event_listener(); - } - - void call_signal_custom_render(UserDrawEvent* pEvent) - { - vcl::RenderContext* pRenderContext = pEvent->GetRenderContext(); - auto nPos = pEvent->GetItemId(); - const tools::Rectangle& rRect = pEvent->GetRect(); - const OUString sId = get_id(nPos); - signal_custom_render(*pRenderContext, rRect, pEvent->IsSelected(), sId); - m_xComboBox->DrawEntry(*pEvent, false, false); // draw separator - - if (m_xMenuButton && m_xMenuButton->IsVisible() && m_sMenuButtonRow == sId) - { - if (m_xMenuButton->GetParent() != pEvent->GetWindow()) - m_xMenuButton->SetParent(pEvent->GetWindow()); - int nButtonWidth = get_menu_button_width(); - m_xMenuButton->SetSizePixel(Size(nButtonWidth, rRect.GetHeight())); - m_xMenuButton->SetPosPixel(Point(rRect.GetWidth() - nButtonWidth, rRect.getY())); - } - } - - VclPtr create_render_virtual_device() const override - { - return VclPtr::Create(); - } - - virtual void set_item_menu(const OString& rIdent, weld::Menu* pMenu) override - { - SalInstanceMenu* pInstanceMenu = dynamic_cast(pMenu); - - PopupMenu* pPopup = pInstanceMenu ? pInstanceMenu->getMenu() : nullptr; - - if (!m_xMenuButton) - m_xMenuButton = VclPtr::Create(m_xComboBox, WB_FLATBUTTON | WB_NOPOINTERFOCUS); - - m_xMenuButton->SetPopupMenu(pPopup); - m_xMenuButton->Show(pPopup != nullptr); - m_sMenuButtonRow = OUString::fromUtf8(rIdent); - } + m_xComboBox->SetSelectHdl(LINK(this, SalInstanceComboBoxWithoutEdit, SelectHdl)); +} - int get_menu_button_width() const override - { - const int nButtonWidth = 20; - return nButtonWidth; - } +OUString SalInstanceComboBoxWithoutEdit::get_active_text() const { return m_xComboBox->GetSelectedEntry(); } - void CallHandleEventListener(VclWindowEvent& rEvent) - { - if (rEvent.GetId() == VclEventId::DropdownPreOpen || - rEvent.GetId() == VclEventId::DropdownClose) - { - signal_popup_toggled(); - return; - } - SalInstanceContainer::HandleEventListener(rEvent); - } -}; +void SalInstanceComboBoxWithoutEdit::remove(int pos) { m_xComboBox->RemoveEntry(pos); } -class SalInstanceComboBoxWithoutEdit : public SalInstanceComboBox +void SalInstanceComboBoxWithoutEdit::insert(int pos, const OUString& rStr, const OUString* pId, + const OUString* pIconName, VirtualDevice* pImageSurface) { -private: - DECL_LINK(SelectHdl, ListBox&, void); - -public: - SalInstanceComboBoxWithoutEdit(ListBox* pListBox, SalInstanceBuilder* pBuilder, - bool bTakeOwnership) - : SalInstanceComboBox(pListBox, pBuilder, bTakeOwnership) + auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; + sal_Int32 nInsertedAt; + if (!pIconName && !pImageSurface) + nInsertedAt = m_xComboBox->InsertEntry(rStr, nInsertPos); + else if (pIconName) + nInsertedAt = m_xComboBox->InsertEntry(rStr, createImage(*pIconName), nInsertPos); + else + nInsertedAt = m_xComboBox->InsertEntry(rStr, createImage(*pImageSurface), nInsertPos); + if (pId) { - m_xComboBox->SetSelectHdl(LINK(this, SalInstanceComboBoxWithoutEdit, SelectHdl)); - } - - virtual OUString get_active_text() const override { return m_xComboBox->GetSelectedEntry(); } - - virtual void remove(int pos) override { m_xComboBox->RemoveEntry(pos); } - - virtual void insert(int pos, const OUString& rStr, const OUString* pId, - const OUString* pIconName, VirtualDevice* pImageSurface) override - { - auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; - sal_Int32 nInsertedAt; - if (!pIconName && !pImageSurface) - nInsertedAt = m_xComboBox->InsertEntry(rStr, nInsertPos); - else if (pIconName) - nInsertedAt = m_xComboBox->InsertEntry(rStr, createImage(*pIconName), nInsertPos); - else - nInsertedAt = m_xComboBox->InsertEntry(rStr, createImage(*pImageSurface), nInsertPos); - if (pId) - { - m_aUserData.emplace_back(std::make_unique(*pId)); - m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); - } + m_aUserData.emplace_back(std::make_unique(*pId)); + m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); } +} - virtual void insert_separator(int pos, const OUString& /*rId*/) override - { - auto nInsertPos = pos == -1 ? m_xComboBox->GetEntryCount() : pos; - m_xComboBox->AddSeparator(nInsertPos - 1); - } +void SalInstanceComboBoxWithoutEdit::insert_separator(int pos, const OUString& /*rId*/) +{ + auto nInsertPos = pos == -1 ? m_xComboBox->GetEntryCount() : pos; + m_xComboBox->AddSeparator(nInsertPos - 1); +} - virtual bool has_entry() const override { return false; } +bool SalInstanceComboBoxWithoutEdit::has_entry() const { return false; } - virtual bool changed_by_direct_pick() const override { return true; } +bool SalInstanceComboBoxWithoutEdit::changed_by_direct_pick() const { return true; } - virtual void set_entry_message_type(weld::EntryMessageType /*eType*/) override - { - assert(false); - } +void SalInstanceComboBoxWithoutEdit::set_entry_message_type(weld::EntryMessageType /*eType*/) +{ + assert(false); +} - virtual void set_entry_text(const OUString& /*rText*/) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::set_entry_text(const OUString& /*rText*/) { assert(false); } - virtual void select_entry_region(int /*nStartPos*/, int /*nEndPos*/) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::select_entry_region(int /*nStartPos*/, int /*nEndPos*/) { assert(false); } - virtual bool get_entry_selection_bounds(int& /*rStartPos*/, int& /*rEndPos*/) override - { - assert(false); - return false; - } - - virtual void set_entry_width_chars(int /*nChars*/) override { assert(false); } +bool SalInstanceComboBoxWithoutEdit::get_entry_selection_bounds(int& /*rStartPos*/, int& /*rEndPos*/) +{ + assert(false); + return false; +} - virtual void set_entry_max_length(int /*nChars*/) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::set_entry_width_chars(int /*nChars*/) { assert(false); } - virtual void set_entry_completion(bool, bool) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::set_entry_max_length(int /*nChars*/) { assert(false); } - virtual void set_entry_placeholder_text(const OUString&) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::set_entry_completion(bool, bool) { assert(false); } - virtual void set_entry_font(const vcl::Font&) override { assert(false); } +void SalInstanceComboBoxWithoutEdit::set_entry_placeholder_text(const OUString&) { assert(false); } - virtual vcl::Font get_entry_font() override { assert(false); return vcl::Font(); } +void SalInstanceComboBoxWithoutEdit::set_entry_font(const vcl::Font&) { assert(false); } - virtual void set_custom_renderer() override - { - assert(false && "not implemented"); - } +vcl::Font SalInstanceComboBoxWithoutEdit::get_entry_font() { assert(false); return vcl::Font(); } - virtual int get_max_mru_count() const override - { - assert(false && "not implemented"); - return 0; - } +void SalInstanceComboBoxWithoutEdit::set_custom_renderer() +{ + assert(false && "not implemented"); +} - virtual void set_max_mru_count(int) override - { - assert(false && "not implemented"); - } +int SalInstanceComboBoxWithoutEdit::get_max_mru_count() const +{ + assert(false && "not implemented"); + return 0; +} - virtual OUString get_mru_entries() const override - { - assert(false && "not implemented"); - return OUString(); - } +void SalInstanceComboBoxWithoutEdit::set_max_mru_count(int) +{ + assert(false && "not implemented"); +} - virtual void set_mru_entries(const OUString&) override - { - assert(false && "not implemented"); - } +OUString SalInstanceComboBoxWithoutEdit::get_mru_entries() const +{ + assert(false && "not implemented"); + return OUString(); +} - virtual void HandleEventListener(VclWindowEvent& rEvent) override - { - CallHandleEventListener(rEvent); - } +void SalInstanceComboBoxWithoutEdit::set_mru_entries(const OUString&) +{ + assert(false && "not implemented"); +} - virtual ~SalInstanceComboBoxWithoutEdit() override - { - m_xComboBox->SetSelectHdl(Link()); - } -}; +void SalInstanceComboBoxWithoutEdit::HandleEventListener(VclWindowEvent& rEvent) +{ + CallHandleEventListener(rEvent); +} +SalInstanceComboBoxWithoutEdit::~SalInstanceComboBoxWithoutEdit() +{ + m_xComboBox->SetSelectHdl(Link()); } IMPL_LINK_NOARG(SalInstanceComboBoxWithoutEdit, SelectHdl, ListBox&, void) @@ -6045,178 +5815,163 @@ IMPL_LINK_NOARG(SalInstanceComboBoxWithoutEdit, SelectHdl, ListBox&, void) return signal_changed(); } -namespace -{ -class SalInstanceComboBoxWithEdit : public SalInstanceComboBox +SalInstanceComboBoxWithEdit::SalInstanceComboBoxWithEdit(::ComboBox* pComboBox, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceComboBox<::ComboBox>(pComboBox, pBuilder, bTakeOwnership) + , m_aTextFilter(m_aEntryInsertTextHdl) + , m_bInSelect(false) { -private: - DECL_LINK(ChangeHdl, Edit&, void); - DECL_LINK(EntryActivateHdl, Edit&, bool); - DECL_LINK(SelectHdl, ::ComboBox&, void); - DECL_LINK(UserDrawHdl, UserDrawEvent*, void); - WeldTextFilter m_aTextFilter; - bool m_bInSelect; -public: - SalInstanceComboBoxWithEdit(::ComboBox* pComboBox, SalInstanceBuilder* pBuilder, - bool bTakeOwnership) - : SalInstanceComboBox<::ComboBox>(pComboBox, pBuilder, bTakeOwnership) - , m_aTextFilter(m_aEntryInsertTextHdl) - , m_bInSelect(false) - { - m_xComboBox->SetModifyHdl(LINK(this, SalInstanceComboBoxWithEdit, ChangeHdl)); - m_xComboBox->SetSelectHdl(LINK(this, SalInstanceComboBoxWithEdit, SelectHdl)); - m_xComboBox->SetEntryActivateHdl(LINK(this, SalInstanceComboBoxWithEdit, EntryActivateHdl)); - m_xComboBox->SetTextFilter(&m_aTextFilter); - } + m_xComboBox->SetModifyHdl(LINK(this, SalInstanceComboBoxWithEdit, ChangeHdl)); + m_xComboBox->SetSelectHdl(LINK(this, SalInstanceComboBoxWithEdit, SelectHdl)); + m_xComboBox->SetEntryActivateHdl(LINK(this, SalInstanceComboBoxWithEdit, EntryActivateHdl)); + m_xComboBox->SetTextFilter(&m_aTextFilter); +} - virtual bool has_entry() const override { return true; } +bool SalInstanceComboBoxWithEdit::has_entry() const { return true; } - virtual bool changed_by_direct_pick() const override - { - return m_bInSelect && !m_xComboBox->IsModifyByKeyboard() && !m_xComboBox->IsTravelSelect(); - } - - virtual void set_entry_message_type(weld::EntryMessageType eType) override - { - if (eType == weld::EntryMessageType::Error) - m_xComboBox->SetControlForeground(Color(0xf0, 0, 0)); - else if (eType == weld::EntryMessageType::Warning) - m_xComboBox->SetControlForeground(COL_YELLOW); - else - m_xComboBox->SetControlForeground(); - } +bool SalInstanceComboBoxWithEdit::changed_by_direct_pick() const +{ + return m_bInSelect && !m_xComboBox->IsModifyByKeyboard() && !m_xComboBox->IsTravelSelect(); +} - virtual OUString get_active_text() const override { return m_xComboBox->GetText(); } +void SalInstanceComboBoxWithEdit::set_entry_message_type(weld::EntryMessageType eType) +{ + if (eType == weld::EntryMessageType::Error) + m_xComboBox->SetControlForeground(Color(0xf0, 0, 0)); + else if (eType == weld::EntryMessageType::Warning) + m_xComboBox->SetControlForeground(COL_YELLOW); + else + m_xComboBox->SetControlForeground(); +} - virtual void remove(int pos) override { m_xComboBox->RemoveEntryAt(pos); } +OUString SalInstanceComboBoxWithEdit::get_active_text() const { return m_xComboBox->GetText(); } - virtual void insert(int pos, const OUString& rStr, const OUString* pId, - const OUString* pIconName, VirtualDevice* pImageSurface) override - { - auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; - sal_Int32 nInsertedAt; - if (!pIconName && !pImageSurface) - nInsertedAt = m_xComboBox->InsertEntry(rStr, nInsertPos); - else if (pIconName) - nInsertedAt - = m_xComboBox->InsertEntryWithImage(rStr, createImage(*pIconName), nInsertPos); - else - nInsertedAt - = m_xComboBox->InsertEntryWithImage(rStr, createImage(*pImageSurface), nInsertPos); - if (pId) - { - m_aUserData.emplace_back(std::make_unique(*pId)); - m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); - } - } +void SalInstanceComboBoxWithEdit::remove(int pos) { m_xComboBox->RemoveEntryAt(pos); } - virtual void insert_separator(int pos, const OUString& /*rId*/) override +void SalInstanceComboBoxWithEdit::insert(int pos, const OUString& rStr, const OUString* pId, + const OUString* pIconName, VirtualDevice* pImageSurface) +{ + auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; + sal_Int32 nInsertedAt; + if (!pIconName && !pImageSurface) + nInsertedAt = m_xComboBox->InsertEntry(rStr, nInsertPos); + else if (pIconName) + nInsertedAt + = m_xComboBox->InsertEntryWithImage(rStr, createImage(*pIconName), nInsertPos); + else + nInsertedAt + = m_xComboBox->InsertEntryWithImage(rStr, createImage(*pImageSurface), nInsertPos); + if (pId) { - auto nInsertPos = pos == -1 ? m_xComboBox->GetEntryCount() : pos; - m_xComboBox->AddSeparator(nInsertPos - 1); + m_aUserData.emplace_back(std::make_unique(*pId)); + m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); } +} - virtual void set_entry_text(const OUString& rText) override { m_xComboBox->SetText(rText); } +void SalInstanceComboBoxWithEdit::insert_separator(int pos, const OUString& /*rId*/) +{ + auto nInsertPos = pos == -1 ? m_xComboBox->GetEntryCount() : pos; + m_xComboBox->AddSeparator(nInsertPos - 1); +} - virtual void set_entry_width_chars(int nChars) override - { - m_xComboBox->SetWidthInChars(nChars); - } +void SalInstanceComboBoxWithEdit::set_entry_text(const OUString& rText) { m_xComboBox->SetText(rText); } - virtual void set_entry_max_length(int nChars) override { m_xComboBox->SetMaxTextLen(nChars); } +void SalInstanceComboBoxWithEdit::set_entry_width_chars(int nChars) +{ + m_xComboBox->SetWidthInChars(nChars); +} - virtual void set_entry_completion(bool bEnable, bool bCaseSensitive) override - { - m_xComboBox->EnableAutocomplete(bEnable, bCaseSensitive); - } +void SalInstanceComboBoxWithEdit::set_entry_max_length(int nChars) { m_xComboBox->SetMaxTextLen(nChars); } - virtual void set_entry_placeholder_text(const OUString& rText) override - { - m_xComboBox->SetPlaceholderText(rText); - } +void SalInstanceComboBoxWithEdit::set_entry_completion(bool bEnable, bool bCaseSensitive) +{ + m_xComboBox->EnableAutocomplete(bEnable, bCaseSensitive); +} - virtual void select_entry_region(int nStartPos, int nEndPos) override - { - m_xComboBox->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); - } +void SalInstanceComboBoxWithEdit::set_entry_placeholder_text(const OUString& rText) +{ + m_xComboBox->SetPlaceholderText(rText); +} - virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) override - { - const Selection& rSelection = m_xComboBox->GetSelection(); - rStartPos = rSelection.Min(); - rEndPos = rSelection.Max(); - return rSelection.Len(); - } +void SalInstanceComboBoxWithEdit::select_entry_region(int nStartPos, int nEndPos) +{ + m_xComboBox->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); +} - virtual void set_entry_font(const vcl::Font& rFont) override - { - Edit* pEdit = m_xComboBox->GetSubEdit(); - assert(pEdit); - pEdit->SetPointFont(*pEdit, rFont); - pEdit->Invalidate(); - } +bool SalInstanceComboBoxWithEdit::get_entry_selection_bounds(int& rStartPos, int& rEndPos) +{ + const Selection& rSelection = m_xComboBox->GetSelection(); + rStartPos = rSelection.Min(); + rEndPos = rSelection.Max(); + return rSelection.Len(); +} - virtual vcl::Font get_entry_font() override - { - Edit* pEdit = m_xComboBox->GetSubEdit(); - assert(pEdit); - return pEdit->GetPointFont(*pEdit); - } +void SalInstanceComboBoxWithEdit::set_entry_font(const vcl::Font& rFont) +{ + Edit* pEdit = m_xComboBox->GetSubEdit(); + assert(pEdit); + pEdit->SetPointFont(*pEdit, rFont); + pEdit->Invalidate(); +} - virtual void set_custom_renderer() override - { - auto nOldEntryHeight = m_xComboBox->GetDropDownEntryHeight(); - auto nDropDownLineCount = m_xComboBox->GetDropDownLineCount(); +vcl::Font SalInstanceComboBoxWithEdit::get_entry_font() +{ + Edit* pEdit = m_xComboBox->GetSubEdit(); + assert(pEdit); + return pEdit->GetPointFont(*pEdit); +} - m_xComboBox->EnableUserDraw(true); - m_xComboBox->SetUserDrawHdl(LINK(this, SalInstanceComboBoxWithEdit, UserDrawHdl)); +void SalInstanceComboBoxWithEdit::set_custom_renderer() +{ + auto nOldEntryHeight = m_xComboBox->GetDropDownEntryHeight(); + auto nDropDownLineCount = m_xComboBox->GetDropDownLineCount(); - // adjust the line count to fit approx the height it would have been before - // using a custom renderer - auto nNewEntryHeight = m_xComboBox->GetDropDownEntryHeight(); - double fRatio = nOldEntryHeight / static_cast(nNewEntryHeight); - m_xComboBox->SetDropDownLineCount(nDropDownLineCount * fRatio); - } + m_xComboBox->EnableUserDraw(true); + m_xComboBox->SetUserDrawHdl(LINK(this, SalInstanceComboBoxWithEdit, UserDrawHdl)); - virtual int get_max_mru_count() const override - { - return m_xComboBox->GetMaxMRUCount(); - } + // adjust the line count to fit approx the height it would have been before + // using a custom renderer + auto nNewEntryHeight = m_xComboBox->GetDropDownEntryHeight(); + double fRatio = nOldEntryHeight / static_cast(nNewEntryHeight); + m_xComboBox->SetDropDownLineCount(nDropDownLineCount * fRatio); +} - virtual void set_max_mru_count(int nCount) override - { - return m_xComboBox->SetMaxMRUCount(nCount); - } +int SalInstanceComboBoxWithEdit::get_max_mru_count() const +{ + return m_xComboBox->GetMaxMRUCount(); +} - virtual OUString get_mru_entries() const override - { - return m_xComboBox->GetMRUEntries(); - } +void SalInstanceComboBoxWithEdit::set_max_mru_count(int nCount) +{ + return m_xComboBox->SetMaxMRUCount(nCount); +} - virtual void set_mru_entries(const OUString& rEntries) override - { - m_xComboBox->SetMRUEntries(rEntries); - } +OUString SalInstanceComboBoxWithEdit::get_mru_entries() const +{ + return m_xComboBox->GetMRUEntries(); +} - virtual void HandleEventListener(VclWindowEvent& rEvent) override - { - if (rEvent.GetId() == VclEventId::DropdownPreOpen) - { - Size aRowSize(signal_custom_get_size(*m_xComboBox)); - m_xComboBox->SetUserItemSize(aRowSize); - } - CallHandleEventListener(rEvent); - } +void SalInstanceComboBoxWithEdit::set_mru_entries(const OUString& rEntries) +{ + m_xComboBox->SetMRUEntries(rEntries); +} - virtual ~SalInstanceComboBoxWithEdit() override +void SalInstanceComboBoxWithEdit::HandleEventListener(VclWindowEvent& rEvent) +{ + if (rEvent.GetId() == VclEventId::DropdownPreOpen) { - m_xComboBox->SetTextFilter(nullptr); - m_xComboBox->SetEntryActivateHdl(Link()); - m_xComboBox->SetModifyHdl(Link()); - m_xComboBox->SetSelectHdl(Link<::ComboBox&, void>()); + Size aRowSize(signal_custom_get_size(*m_xComboBox)); + m_xComboBox->SetUserItemSize(aRowSize); } -}; + CallHandleEventListener(rEvent); +} +SalInstanceComboBoxWithEdit::~SalInstanceComboBoxWithEdit() +{ + m_xComboBox->SetTextFilter(nullptr); + m_xComboBox->SetEntryActivateHdl(Link()); + m_xComboBox->SetModifyHdl(Link()); + m_xComboBox->SetSelectHdl(Link<::ComboBox&, void>()); } IMPL_LINK_NOARG(SalInstanceComboBoxWithEdit, ChangeHdl, Edit&, void) -- cgit