[Libreoffice-commits] core.git: extensions/source extensions/uiconfig extensions/UIConfig_sbibliography.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 23 19:19:09 UTC 2021


 extensions/UIConfig_sbibliography.mk                   |    1 
 extensions/source/bibliography/toolbar.cxx             |   44 +++++++++--------
 extensions/source/bibliography/toolbar.hxx             |    5 +
 extensions/uiconfig/sbibliography/ui/autofiltermenu.ui |    9 +++
 4 files changed, 38 insertions(+), 21 deletions(-)

New commits:
commit b627cb4e9af7dbb43dfc41adfc549c67dd1756c5
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Feb 23 14:12:46 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Feb 23 20:18:21 2021 +0100

    weld bibliography autofilter menu
    
    Change-Id: I3abacb0b14897f144c213496161b94d431f51b88
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111404
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/extensions/UIConfig_sbibliography.mk b/extensions/UIConfig_sbibliography.mk
index cf4835829262..7b4056380912 100644
--- a/extensions/UIConfig_sbibliography.mk
+++ b/extensions/UIConfig_sbibliography.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_UIConfig_add_menubarfiles,modules/sbibliography,\
 ))
 
 $(eval $(call gb_UIConfig_add_uifiles,modules/sbibliography,\
+	extensions/uiconfig/sbibliography/ui/autofiltermenu \
 	extensions/uiconfig/sbibliography/ui/choosedatasourcedialog \
 	extensions/uiconfig/sbibliography/ui/combobox \
 	extensions/uiconfig/sbibliography/ui/editbox \
diff --git a/extensions/source/bibliography/toolbar.cxx b/extensions/source/bibliography/toolbar.cxx
index ea8ae0eeaee8..5ef3a8d5030c 100644
--- a/extensions/source/bibliography/toolbar.cxx
+++ b/extensions/source/bibliography/toolbar.cxx
@@ -34,9 +34,9 @@
 #include <svtools/imgdef.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
-#include <vcl/menu.hxx>
 #include <vcl/mnemonic.hxx>
 #include <vcl/event.hxx>
+#include <vcl/weldutils.hxx>
 #include <bitmaps.hlst>
 
 #include "bibtools.hxx"
@@ -228,9 +228,9 @@ BibToolBar::BibToolBar(vcl::Window* pParent, Link<void*,void> aLink)
     , pLbSource(xSource->get_widget())
     , xQuery(VclPtr<EditControl>::Create(this))
     , pEdQuery(xQuery->get_widget())
-    , pPopupMenu(VclPtr<PopupMenu>::Create())
+    , xBuilder(Application::CreateBuilder(nullptr, "modules/sbibliography/ui/autofiltermenu.ui"))
+    , xPopupMenu(xBuilder->weld_menu("menu"))
     , nMenuId(0)
-    , nSelMenuItem(0)
     , aLayoutManager(aLink)
     , nSymbolsSize(SFX_SYMBOLS_SIZE_SMALL)
 {
@@ -280,6 +280,8 @@ void BibToolBar::dispose()
     xQuery.disposeAndClear();
     pLbSource = nullptr;
     xSource.disposeAndClear();
+    xPopupMenu.reset();
+    xBuilder.reset();
     ToolBox::dispose();
 }
 
@@ -411,21 +413,23 @@ void BibToolBar::Click()
 
 void BibToolBar::ClearFilterMenu()
 {
-    pPopupMenu->Clear();
+    xPopupMenu->clear();
     nMenuId=0;
 }
-sal_uInt16 BibToolBar::InsertFilterItem(const OUString& aMenuEntry)
+
+sal_uInt16 BibToolBar::InsertFilterItem(const OUString& rMenuEntry)
 {
     nMenuId++;
-    pPopupMenu->InsertItem(nMenuId,aMenuEntry);
-
+    xPopupMenu->append_check(OUString::number(nMenuId), rMenuEntry);
     return nMenuId;
 }
-void BibToolBar::SelectFilterItem(sal_uInt16    nId)
+
+void BibToolBar::SelectFilterItem(sal_uInt16 nId)
 {
-    pPopupMenu->CheckItem(nId);
-    nSelMenuItem=nId;
-    aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) );
+    OString sId = OString::number(nId);
+    xPopupMenu->set_active(sId, true);
+    sSelMenuItem = sId;
+    aQueryField = MnemonicGenerator::EraseAllMnemonicChars(xPopupMenu->get_label(sId));
 }
 
 void BibToolBar::EnableSourceList(bool bFlag)
@@ -510,24 +514,26 @@ IMPL_LINK_NOARG( BibToolBar, SendSelHdl, Timer*, void )
     SendDispatch(nTBC_SOURCE, aPropVal);
 }
 
-IMPL_LINK_NOARG( BibToolBar, MenuHdl, ToolBox*, void)
+IMPL_LINK_NOARG(BibToolBar, MenuHdl, ToolBox*, void)
 {
-    sal_uInt16  nId=GetCurItemId();
+    sal_uInt16 nId = GetCurItemId();
     if (nId != nTBC_BT_AUTOFILTER)
         return;
 
     EndSelection();     // before SetDropMode (SetDropMode calls SetItemImage)
 
     SetItemDown(nTBC_BT_AUTOFILTER, true);
-    nId = pPopupMenu->Execute(this, GetItemRect(nTBC_BT_AUTOFILTER));
 
+    tools::Rectangle aRect(GetItemRect(nTBC_BT_AUTOFILTER));
+    weld::Window* pParent = weld::GetPopupParent(*this, aRect);
+    OString sId = xPopupMenu->popup_at_rect(pParent, aRect);
 
-    if(nId>0)
+    if (!sId.isEmpty())
     {
-        pPopupMenu->CheckItem(nSelMenuItem,false);
-        pPopupMenu->CheckItem(nId);
-        nSelMenuItem=nId;
-        aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) );
+        xPopupMenu->set_active(sSelMenuItem, false);
+        xPopupMenu->set_active(sId, true);
+        sSelMenuItem = sId;
+        aQueryField = MnemonicGenerator::EraseAllMnemonicChars(xPopupMenu->get_label(sId));
         Sequence<PropertyValue> aPropVal(2);
         PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray());
         pPropertyVal[0].Name = "QueryText";
diff --git a/extensions/source/bibliography/toolbar.hxx b/extensions/source/bibliography/toolbar.hxx
index afd1bd3ace38..ee4b58274e9e 100644
--- a/extensions/source/bibliography/toolbar.hxx
+++ b/extensions/source/bibliography/toolbar.hxx
@@ -148,9 +148,10 @@ class BibToolBar:   public ToolBox
         weld::ComboBox*         pLbSource;
         VclPtr<EditControl>     xQuery;
         weld::Entry*            pEdQuery;
-        ScopedVclPtr<PopupMenu> pPopupMenu;
+        std::unique_ptr<weld::Builder> xBuilder;
+        std::unique_ptr<weld::Menu> xPopupMenu;
         sal_uInt16              nMenuId;
-        sal_uInt16              nSelMenuItem;
+        OString                 sSelMenuItem;
         OUString                aQueryField;
         Link<void*,void>        aLayoutManager;
         sal_Int16               nSymbolsSize;
diff --git a/extensions/uiconfig/sbibliography/ui/autofiltermenu.ui b/extensions/uiconfig/sbibliography/ui/autofiltermenu.ui
new file mode 100644
index 000000000000..aa496513f25e
--- /dev/null
+++ b/extensions/uiconfig/sbibliography/ui/autofiltermenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="pcr">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="menu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list