convert selection menu to .ui

Change-Id: Ie4cf80202c333600ce027c78aa3c379ef33f4f80
Reviewed-on: https://gerrit.libreoffice.org/36449
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc
index d384997..2a23a21 100644
--- a/include/svx/dialogs.hrc
+++ b/include/svx/dialogs.hrc
@@ -251,7 +251,6 @@
#define RID_SVXSTR_OVERWRITE_TEXT           (RID_SVX_START + 212)

// Strings for the selection mode
#define RID_SVXMENU_SELECTION               (RID_SVX_START + 213)
#define RID_SVXBMP_SELECTION                (RID_SVX_START + 215)

#define RID_SVXSTR_XMLSEC_SIG_OK            (RID_SVX_START + 222)
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index 20c0eaa..633b8d6 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -69,6 +69,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
	svx/uiconfig/ui/rulermenu \
	svx/uiconfig/ui/safemodedialog \
	svx/uiconfig/ui/savemodifieddialog \
	svx/uiconfig/ui/selectionmenu \
	svx/uiconfig/ui/sidebararea \
	svx/uiconfig/ui/sidebarshadow \
	svx/uiconfig/ui/sidebargraphic \
diff --git a/svx/source/stbctrls/selctrl.cxx b/svx/source/stbctrls/selctrl.cxx
index af230c5..a98ed9e 100644
--- a/svx/source/stbctrls/selctrl.cxx
+++ b/svx/source/stbctrls/selctrl.cxx
@@ -17,6 +17,7 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <vcl/builder.hxx>
#include <vcl/menu.hxx>
#include <vcl/status.hxx>
#include <svl/intitem.hxx>
@@ -32,42 +33,48 @@
SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);

/// Popup menu to select the selection type
class SelectionTypePopup : public PopupMenu
class SelectionTypePopup
{
    VclBuilder        m_aBuilder;
    VclPtr<PopupMenu> m_xMenu;
    static sal_uInt16 id_to_state(const OString& rIdent);
    sal_uInt16 state_to_id(sal_uInt16 nState) const;
public:
    explicit SelectionTypePopup( sal_uInt16 nCurrent );
    explicit SelectionTypePopup(sal_uInt16 nCurrent);
    OUString GetItemTextForState(sal_uInt16 nState) { return m_xMenu->GetItemText(state_to_id(nState)); }
    sal_uInt16 GetState() const { return id_to_state(m_xMenu->GetCurItemIdent()); }
    sal_uInt16 Execute(vcl::Window* pWindow, const Point& rPopupPos) { return m_xMenu->Execute(pWindow, rPopupPos); }
};

/// Item id's cannot start from 0, so we need to convert
static sal_uInt16 id_to_state( sal_uInt16 nId )
sal_uInt16 SelectionTypePopup::id_to_state(const OString& rIdent)
{
    switch ( nId )
    if (rIdent == "block")
        return 3;
    else if (rIdent == "adding")
        return 2;
    else if (rIdent == "extending")
        return 1;
    else // fall through
        return 0;
}

sal_uInt16 SelectionTypePopup::state_to_id(sal_uInt16 nState) const
{
    switch (nState)
    {
        default: // fall through
        case SELECTION_STANDARD: return 0;
        case SELECTION_EXTENDED: return 1;
        case SELECTION_ADDED:    return 2;
        case SELECTION_BLOCK:    return 3;
        case 0: return m_xMenu->GetItemId("standard");
        case 1: return m_xMenu->GetItemId("extending");
        case 2: return m_xMenu->GetItemId("adding");
        case 3: return m_xMenu->GetItemId("block");
    }
}

/// Item id's cannot start from 0, so we need to convert
static sal_uInt16 state_to_id( sal_uInt16 nState )
SelectionTypePopup::SelectionTypePopup(sal_uInt16 nCurrent)
    : m_aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/selectionmenu.ui", "")
    , m_xMenu(m_aBuilder.get_menu("menu"))
{
    switch ( nState )
    {
        default: // fall through
        case 0: return SELECTION_STANDARD;
        case 1: return SELECTION_EXTENDED;
        case 2: return SELECTION_ADDED;
        case 3: return SELECTION_BLOCK;
    }
}

SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
    : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
{
    CheckItem( state_to_id( nCurrent ) );
    m_xMenu->CheckItem(state_to_id(nCurrent));
}

SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
@@ -89,20 +96,19 @@ void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
        const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
        mnState = pItem->GetValue();

        ScopedVclPtrInstance<SelectionTypePopup> aPop( mnState );
        GetStatusBar().SetQuickHelpText( GetId(), aPop->GetItemText( state_to_id( mnState ) ) );
        SelectionTypePopup aPop(mnState);
        GetStatusBar().SetQuickHelpText(GetId(), aPop.GetItemTextForState(mnState));
    }
}


bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
{
    ScopedVclPtrInstance<SelectionTypePopup> aPop( mnState );
    SelectionTypePopup aPop(mnState);
    StatusBar& rStatusbar = GetStatusBar();

    if ( aPop->Execute( &rStatusbar, rEvt.GetPosPixel() ) )
    if (aPop.Execute(&rStatusbar, rEvt.GetPosPixel()))
    {
        sal_uInt16 nNewState = id_to_state( aPop->GetCurItemId() );
        sal_uInt16 nNewState = aPop.GetState();
        if ( nNewState != mnState )
        {
            mnState = nNewState;
diff --git a/svx/source/stbctrls/stbctrls.h b/svx/source/stbctrls/stbctrls.h
index 77d4f7f..3b12d6f 100644
--- a/svx/source/stbctrls/stbctrls.h
+++ b/svx/source/stbctrls/stbctrls.h
@@ -30,11 +30,6 @@
#define PSZ_FUNC_SELECTION_COUNT    13
#define PSZ_FUNC_NONE               16

#define SELECTION_STANDARD  1
#define SELECTION_EXTENDED  2
#define SELECTION_ADDED     3
#define SELECTION_BLOCK     4

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/stbctrls/stbctrls.src b/svx/source/stbctrls/stbctrls.src
index e846cff..0039a2b 100644
--- a/svx/source/stbctrls/stbctrls.src
+++ b/svx/source/stbctrls/stbctrls.src
@@ -36,38 +36,6 @@ String RID_SVXSTR_OVERWRITE_TEXT
    Text [ en-US ] = "Overwrite" ;
};

// Selection type menu
Menu RID_SVXMENU_SELECTION
{
    ItemList =
    {
        MenuItem
        {
            Identifier = SELECTION_STANDARD ;
            RadioCheck = TRUE ;
            Text [ en-US ] = "Standard selection" ;
        };
        MenuItem
        {
            Identifier = SELECTION_EXTENDED ;
            RadioCheck = TRUE ;
            Text [ en-US ] = "Extending selection" ;
        };
        MenuItem
        {
            Identifier = SELECTION_ADDED ;
            RadioCheck = TRUE ;
            Text [ en-US ] = "Adding selection" ;
        };
        MenuItem
        {
            Identifier = SELECTION_BLOCK ;
            RadioCheck = TRUE ;
            Text [ en-US ] = "Block selection" ;
        };
    };
};

Bitmap RID_SVXBMP_SELECTION
{
    File = "selection_10x22.png" ;
diff --git a/svx/uiconfig/ui/selectionmenu.ui b/svx/uiconfig/ui/selectionmenu.ui
new file mode 100644
index 0000000..a306b52
--- /dev/null
+++ b/svx/uiconfig/ui/selectionmenu.ui
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkMenu" id="menu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkRadioMenuItem" id="standard">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes">Standard selection</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="extending">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes">Extending selection</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="adding">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes">Adding selection</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="block">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes">Block selection</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
</interface>