[Libreoffice-commits] core.git: sd/source sd/uiconfig sd/UIConfig_simpress.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 23 11:33:18 UTC 2021


 sd/UIConfig_simpress.mk              |    1 
 sd/source/ui/app/sdpopup.cxx         |  145 ++++++++++++++++++++---------------
 sd/source/ui/inc/sdpopup.hxx         |   15 +--
 sd/source/ui/view/drviews4.cxx       |   19 ++--
 sd/uiconfig/simpress/ui/fieldmenu.ui |    9 ++
 5 files changed, 112 insertions(+), 77 deletions(-)

New commits:
commit 8e7e9e4f176ea35786cac96935d8692997a3d701
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Feb 23 10:02:54 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Feb 23 12:32:33 2021 +0100

    weld fieldmenu
    
    Change-Id: I37a1609669631fdafcb4dea59a2a43c1c94e16e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111380
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sd/UIConfig_simpress.mk b/sd/UIConfig_simpress.mk
index a532a2819e2d..78339ddae976 100644
--- a/sd/UIConfig_simpress.mk
+++ b/sd/UIConfig_simpress.mk
@@ -120,6 +120,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/simpress,\
 	sd/uiconfig/simpress/ui/dlgfield \
 	sd/uiconfig/simpress/ui/dockinganimation \
 	sd/uiconfig/simpress/ui/effectmenu \
+	sd/uiconfig/simpress/ui/fieldmenu \
 	sd/uiconfig/simpress/ui/fontsizemenu \
 	sd/uiconfig/simpress/ui/fontstylemenu \
 	sd/uiconfig/simpress/ui/gluebox \
diff --git a/sd/source/ui/app/sdpopup.cxx b/sd/source/ui/app/sdpopup.cxx
index d4b81ea7fde5..9bdb2b93603a 100644
--- a/sd/source/ui/app/sdpopup.cxx
+++ b/sd/source/ui/app/sdpopup.cxx
@@ -21,6 +21,7 @@
 #include <sfx2/objsh.hxx>
 #include <sfx2/docfile.hxx>
 #include <unotools/useroptions.hxx>
+#include <vcl/svapp.hxx>
 
 #include <strings.hrc>
 #include <sdpopup.hxx>
@@ -31,11 +32,12 @@
 /*
  * Popup menu for editing of field command
  */
-SdFieldPopup::SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage ) :
-        PopupMenu   (),
-        pField      ( pInField )
+SdFieldPopup::SdFieldPopup(const SvxFieldData* pInField, LanguageType eLanguage)
+    : m_xBuilder(Application::CreateBuilder(nullptr, "modules/simpress/ui/fieldmenu.ui"))
+    , m_xPopup(m_xBuilder->weld_menu("menu"))
+    , m_pField(pInField)
 {
-    Fill( eLanguage );
+    Fill(eLanguage);
 }
 
 SdFieldPopup::~SdFieldPopup()
@@ -45,106 +47,124 @@ SdFieldPopup::~SdFieldPopup()
 void SdFieldPopup::Fill( LanguageType eLanguage )
 {
     sal_uInt16 nID = 1;
-    MenuItemBits nStyle = MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK;
-    InsertItem( nID++, SdResId( STR_FIX ), nStyle );
-    InsertItem( nID++, SdResId( STR_VAR ), nStyle );
-    InsertSeparator();
+    m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FIX));
+    m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_VAR));
+    m_xPopup->append_separator("separator1");
 
-    if( auto pDateField = dynamic_cast< const SvxDateField *>( pField ) )
+    if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
     {
         SvxDateField aDateField( *pDateField );
 
-        if( pDateField->GetType() == SvxDateType::Fix )
-            CheckItem( 1 );
+        if (pDateField->GetType() == SvxDateType::Fix)
+            m_xPopup->set_active("1", true);
         else
-            CheckItem( 2 );
+            m_xPopup->set_active("2", true);
 
         //SvxDateFormat::AppDefault,     // is not used
         //SvxDateFormat::System,         // is not used
-        InsertItem( nID++, SdResId( STR_STANDARD_SMALL ), nStyle );
-        InsertItem( nID++, SdResId( STR_STANDARD_BIG ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_SMALL));
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_BIG));
 
         SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
         aDateField.SetFormat( SvxDateFormat::A );    // 13.02.96
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
         aDateField.SetFormat( SvxDateFormat::B );    // 13.02.1996
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
         aDateField.SetFormat( SvxDateFormat::C );    // 13.Feb 1996
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
 
         aDateField.SetFormat( SvxDateFormat::D );    // 13.Februar 1996
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
         aDateField.SetFormat( SvxDateFormat::E );    // Die, 13.Februar 1996
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
         aDateField.SetFormat( SvxDateFormat::F );    // Dienstag, 13.Februar 1996
-        InsertItem( nID++, aDateField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aDateField.GetFormatted(*pNumberFormatter, eLanguage));
 
-        CheckItem( static_cast<sal_uInt16>( pDateField->GetFormat() ) + 1 ); // - 2 + 3 !
+        m_xPopup->set_active(OString::number(static_cast<sal_uInt16>( pDateField->GetFormat() ) + 1), true); // - 2 + 3 !
     }
-    else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( pField ) )
+    else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
     {
         SvxExtTimeField aTimeField( *pTimeField );
 
         if( pTimeField->GetType() == SvxTimeType::Fix )
-            CheckItem( 1 );
+            m_xPopup->set_active("1", true);
         else
-            CheckItem( 2 );
+            m_xPopup->set_active("2", true);
 
         //SvxTimeFormat::AppDefault,     // is not used
         //SvxTimeFormat::System,         // is not used
-        InsertItem( nID++, SdResId( STR_STANDARD_NORMAL ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_STANDARD_NORMAL));
 
         SvNumberFormatter* pNumberFormatter = SD_MOD()->GetNumberFormatter();
         aTimeField.SetFormat( SvxTimeFormat::HH24_MM );    // 13:49
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
         aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS );   // 13:49:38
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
         aTimeField.SetFormat( SvxTimeFormat::HH24_MM_SS_00 );  // 13:49:38.78
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
 
         aTimeField.SetFormat( SvxTimeFormat::HH12_MM );    // 01:49
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
         aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS );   // 01:49:38
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
         aTimeField.SetFormat( SvxTimeFormat::HH12_MM_SS_00 );  // 01:49:38.78
-        InsertItem( nID++, aTimeField.GetFormatted( *pNumberFormatter, eLanguage ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), aTimeField.GetFormatted(*pNumberFormatter, eLanguage));
         //SvxTimeFormat::HH12_MM_AMPM,  // 01:49 PM
         //SvxTimeFormat::HH12_MM_SS_AMPM, // 01:49:38 PM
         //SvxTimeFormat::HH12_MM_SS_00_AMPM // 01:49:38.78 PM
 
-        CheckItem( static_cast<sal_uInt16>( pTimeField->GetFormat() ) + 1 ); // - 2 + 3 !
+        m_xPopup->set_active(OString::number(static_cast<sal_uInt16>( pTimeField->GetFormat() ) + 1), true); // - 2 + 3 !
     }
-    else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( pField ) )
+    else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
     {
         //SvxExtFileField aFileField( *pFileField );
 
         if( pFileField->GetType() == SvxFileType::Fix )
-            CheckItem( 1 );
+            m_xPopup->set_active("1", true);
         else
-            CheckItem( 2 );
+            m_xPopup->set_active("1", true);
 
-        InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME_EXT ), nStyle );
-        InsertItem( nID++, SdResId( STR_FILEFORMAT_FULLPATH ), nStyle );
-        InsertItem( nID++, SdResId( STR_FILEFORMAT_PATH ), nStyle );
-        InsertItem( nID++, SdResId( STR_FILEFORMAT_NAME ), nStyle );
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_NAME_EXT));
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_FULLPATH));
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_PATH));
+        m_xPopup->append_radio(OUString::number(nID++), SdResId(STR_FILEFORMAT_NAME));
 
-        CheckItem( static_cast<sal_uInt16>( pFileField->GetFormat() ) + 3 );
+        m_xPopup->set_active(OString::number(static_cast<sal_uInt16>( pFileField->GetFormat() ) + 3), true);
     }
-    else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( pField ) )
+    else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
     {
         SvxAuthorField aAuthorField( *pAuthorField );
 
         if( pAuthorField->GetType() == SvxAuthorType::Fix )
-            CheckItem( 1 );
+            m_xPopup->set_active("1", true);
         else
-            CheckItem( 2 );
+            m_xPopup->set_active("2", true);
 
         for( sal_uInt16 i = 0; i < 4; i++ )
         {
             aAuthorField.SetFormat( static_cast<SvxAuthorFormat>(i) );
-            InsertItem( nID++, aAuthorField.GetFormatted(), nStyle );
+            m_xPopup->append_radio(OUString::number(nID++), aAuthorField.GetFormatted());
+        }
+        m_xPopup->set_active(OString::number(static_cast<sal_uInt16>( pAuthorField->GetFormat() ) + 3), true);
+    }
+}
+
+void SdFieldPopup::Execute(weld::Window* pParent, const tools::Rectangle& rRect)
+{
+    OString sIdent = m_xPopup->popup_at_rect(pParent, rRect);
+    if (!sIdent.isEmpty())
+    {
+        if (sIdent == "1" || sIdent == "2")
+        {
+            m_xPopup->set_active("1", sIdent == "1");
+            m_xPopup->set_active("2", sIdent == "2");
+        }
+        else
+        {
+            int nCount = m_xPopup->n_children();
+            for (int i = 3; i < nCount; i++)
+                m_xPopup->set_active(OString::number(i), sIdent == OString::number(i));
         }
-        CheckItem( static_cast<sal_uInt16>( pAuthorField->GetFormat() ) + 3 );
     }
 }
 
@@ -155,22 +175,23 @@ void SdFieldPopup::Fill( LanguageType eLanguage )
 SvxFieldData* SdFieldPopup::GetField()
 {
     SvxFieldData* pNewField = nullptr;
-    sal_uInt16 nCount = GetItemCount();
 
-    if( auto pDateField = dynamic_cast< const SvxDateField *>( pField ) )
+    sal_uInt16 nCount = m_xPopup->n_children();
+
+    if( auto pDateField = dynamic_cast< const SvxDateField *>( m_pField ) )
     {
         SvxDateType   eType;
         SvxDateFormat eFormat;
         sal_uInt16 i;
 
-        if( IsItemChecked( 1 ) )
+        if (m_xPopup->get_active("1"))
             eType = SvxDateType::Fix;
         else
             eType = SvxDateType::Var;
 
-        for( i = 3; i <= nCount; i++ )
+        for( i = 3; i < nCount; i++ )
         {
-            if( IsItemChecked( i ) )
+            if (m_xPopup->get_active(OString::number(i)))
                 break;
         }
         eFormat = static_cast<SvxDateFormat>( i - 1 );
@@ -189,20 +210,20 @@ SvxFieldData* SdFieldPopup::GetField()
             }
         }
     }
-    else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( pField ) )
+    else if( auto pTimeField = dynamic_cast< const SvxExtTimeField *>( m_pField ) )
     {
         SvxTimeType   eType;
         SvxTimeFormat eFormat;
         sal_uInt16 i;
 
-        if( IsItemChecked( 1 ) )
+        if (m_xPopup->get_active("1"))
             eType = SvxTimeType::Fix;
         else
             eType = SvxTimeType::Var;
 
-        for( i = 3; i <= nCount; i++ )
+        for( i = 3; i < nCount; i++ )
         {
-            if( IsItemChecked( i ) )
+            if (m_xPopup->get_active(OString::number(i)))
                 break;
         }
         eFormat = static_cast<SvxTimeFormat>( i - 1 );
@@ -222,20 +243,20 @@ SvxFieldData* SdFieldPopup::GetField()
 
         }
     }
-    else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( pField ) )
+    else if( auto pFileField = dynamic_cast< const SvxExtFileField *>( m_pField ) )
     {
         SvxFileType   eType;
         SvxFileFormat eFormat;
         sal_uInt16 i;
 
-        if( IsItemChecked( 1 ) )
+        if (m_xPopup->get_active("1"))
             eType = SvxFileType::Fix;
         else
             eType = SvxFileType::Var;
 
-        for( i = 3; i <= nCount; i++ )
+        for( i = 3; i < nCount; i++ )
         {
-            if( IsItemChecked( i ) )
+            if (m_xPopup->get_active(OString::number(i)))
                 break;
         }
         eFormat = static_cast<SvxFileFormat>( i - 3 );
@@ -258,20 +279,20 @@ SvxFieldData* SdFieldPopup::GetField()
             }
         }
     }
-    else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( pField ) )
+    else if( auto pAuthorField = dynamic_cast< const SvxAuthorField *>( m_pField ) )
     {
         SvxAuthorType   eType;
         SvxAuthorFormat eFormat;
         sal_uInt16 i;
 
-        if( IsItemChecked( 1 ) )
+        if (m_xPopup->get_active("1"))
             eType = SvxAuthorType::Fix;
         else
             eType = SvxAuthorType::Var;
 
-        for( i = 3; i <= nCount; i++ )
+        for( i = 3; i < nCount; i++ )
         {
-            if( IsItemChecked( i ) )
+            if (m_xPopup->get_active(OString::number(i)))
                 break;
         }
         eFormat = static_cast<SvxAuthorFormat>( i - 3 );
diff --git a/sd/source/ui/inc/sdpopup.hxx b/sd/source/ui/inc/sdpopup.hxx
index ae16440ef8c1..a61000ceed98 100644
--- a/sd/source/ui/inc/sdpopup.hxx
+++ b/sd/source/ui/inc/sdpopup.hxx
@@ -21,25 +21,26 @@
 #define INCLUDED_SD_SOURCE_UI_INC_SDPOPUP_HXX
 
 #include <i18nlangtag/lang.h>
-#include <vcl/menu.hxx>
+#include <vcl/weld.hxx>
 
 class SvxFieldData;
 
 /**
  * PopupMenu for editing field-commands
  */
-class SdFieldPopup : public PopupMenu
+class SdFieldPopup
 {
 private:
-    const SvxFieldData* pField;
+    std::unique_ptr<weld::Builder> m_xBuilder;
+    std::unique_ptr<weld::Menu> m_xPopup;
+    const SvxFieldData* m_pField;
 
     void                Fill( LanguageType eLanguage );
 
 public:
-                        SdFieldPopup( const SvxFieldData* pInField, LanguageType eLanguage );
-                        virtual ~SdFieldPopup() override;
-
-    //virtual void      Select();
+    SdFieldPopup(const SvxFieldData* pInField, LanguageType eLanguage);
+    void Execute(weld::Window* pParent, const tools::Rectangle& rRect);
+    ~SdFieldPopup();
 
     SvxFieldData*       GetField();
 };
diff --git a/sd/source/ui/view/drviews4.cxx b/sd/source/ui/view/drviews4.cxx
index ee6ab513e4f0..74844b847d73 100644
--- a/sd/source/ui/view/drviews4.cxx
+++ b/sd/source/ui/view/drviews4.cxx
@@ -20,9 +20,6 @@
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 
 #include <DrawViewShell.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/weld.hxx>
-
 #include <svl/intitem.hxx>
 #include <svl/stritem.hxx>
 #include <svl/urlbmk.hxx>
@@ -38,9 +35,12 @@
 #include <svx/svdopath.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <editeng/editview.hxx>
+#include <tools/diagnose_ex.h>
 #include <vcl/cursor.hxx>
 #include <vcl/commandevent.hxx>
-#include <tools/diagnose_ex.h>
+#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/weldutils.hxx>
 
 #include <app.hrc>
 #include <strings.hrc>
@@ -569,16 +569,19 @@ void DrawViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
             //fdo#44998 if the outliner has captured the mouse events release the lock
             //so the SdFieldPopup can get them
             pOLV->ReleaseMouse();
-            ScopedVclPtrInstance<SdFieldPopup> aFieldPopup( pFldItem->GetField(), eLanguage );
+            SdFieldPopup aFieldPopup(pFldItem->GetField(), eLanguage);
 
             if ( rCEvt.IsMouseEvent() )
                 aMPos = rCEvt.GetMousePosPixel();
             else
                 aMPos = Point( 20, 20 );
-            aFieldPopup->Execute( pWin, aMPos );
+            ::tools::Rectangle aRect(aMPos, Size(1, 1));
+            weld::Window* pParent = weld::GetPopupParent(*pWin, aRect);
+
+            aFieldPopup.Execute(pParent, aRect);
 
-            std::unique_ptr<SvxFieldData> pField(aFieldPopup->GetField());
-            if( pField )
+            std::unique_ptr<SvxFieldData> pField(aFieldPopup.GetField());
+            if (pField)
             {
                 SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
                 // select field, so that it will be deleted on insert
diff --git a/sd/uiconfig/simpress/ui/fieldmenu.ui b/sd/uiconfig/simpress/ui/fieldmenu.ui
new file mode 100644
index 000000000000..5bb702561dd2
--- /dev/null
+++ b/sd/uiconfig/simpress/ui/fieldmenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sd">
+  <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