rework TextCharacterSpacingPopup to be a PopupWindowController

Change-Id: I3db8f93b99157f7ee8d6095f7dfc5c2b2e6890e8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86690
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/svx/TextCharacterSpacingPopup.hxx b/include/svx/TextCharacterSpacingPopup.hxx
index d698cfa..1efc2d9 100644
--- a/include/svx/TextCharacterSpacingPopup.hxx
+++ b/include/svx/TextCharacterSpacingPopup.hxx
@@ -19,20 +19,26 @@
#ifndef INCLUDED_SVX_TEXTCHARACTERSPACINGPOPUP_HXX
#define INCLUDED_SVX_TEXTCHARACTERSPACINGPOPUP_HXX

#include <sfx2/tbxctrl.hxx>
#include <svtools/popupwindowcontroller.hxx>
#include <svx/svxdllapi.h>

namespace svx {

class SVX_DLLPUBLIC TextCharacterSpacingPopup final : public SfxToolBoxControl
class SVX_DLLPUBLIC TextCharacterSpacingPopup final : public svt::PopupWindowController
{
public:
    SFX_DECL_TOOLBOX_CONTROL();

    TextCharacterSpacingPopup(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx);
    TextCharacterSpacingPopup(const css::uno::Reference<css::uno::XComponentContext>& rContext);
    virtual ~TextCharacterSpacingPopup() override;

    virtual VclPtr<SfxPopupWindow> CreatePopupWindow() override;
    using svt::ToolboxController::createPopupWindow;
    virtual VclPtr<vcl::Window> createPopupWindow( vcl::Window* pParent ) override;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;

    // XInitialization
    virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override;
};

} // end of namespace svx
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
index c9870ce..e89903c 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
@@ -1283,6 +1283,17 @@
          <value>com.sun.star.comp.svx.LineSpacingToolBoxControl</value>
        </prop>
      </node>
      <node oor:name="CharacterSpacingToolBoxControl" oor:op="replace">
        <prop oor:name="Command">
          <value>.uno:Spacing</value>
        </prop>
        <prop oor:name="Module">
          <value/>
        </prop>
        <prop oor:name="Controller">
          <value>com.sun.star.comp.svx.CharacterSpacingToolBoxControl</value>
        </prop>
      </node>
      <node oor:name="BorderStyleToolBoxControl" oor:op="replace">
        <prop oor:name="Command">
          <value>.uno:SetBorderStyle</value>
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index 4df0bf2..07ae6ae 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -153,7 +153,6 @@ void ScDLL::Init()
    SvxClipBoardControl             ::RegisterControl(SID_PASTE_UNFORMATTED,    pMod );
    SvxUndoRedoControl              ::RegisterControl(SID_UNDO,                 pMod );
    SvxUndoRedoControl              ::RegisterControl(SID_REDO,                 pMod );
    svx::TextCharacterSpacingPopup  ::RegisterControl(SID_ATTR_CHAR_KERNING,    pMod );
    svx::TextUnderlinePopup         ::RegisterControl(SID_ATTR_CHAR_UNDERLINE,  pMod );
    svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH,  pMod );
    sc::ScNumberFormatControl       ::RegisterControl(SID_NUMBER_TYPE_FORMAT,   pMod );
diff --git a/sd/source/ui/app/sddll.cxx b/sd/source/ui/app/sddll.cxx
index 43f40d8..281e96e 100644
--- a/sd/source/ui/app/sddll.cxx
+++ b/sd/source/ui/app/sddll.cxx
@@ -215,7 +215,6 @@ void SdDLL::RegisterControllers(SdModule* pMod)
    SvxClipBoardControl::RegisterControl( SID_PASTE, pMod );
    SvxClipBoardControl::RegisterControl( SID_PASTE_UNFORMATTED, pMod );

    svx::TextCharacterSpacingPopup::RegisterControl(SID_ATTR_CHAR_KERNING, pMod);
    svx::TextUnderlinePopup::RegisterControl(SID_ATTR_CHAR_UNDERLINE, pMod);

#if HAVE_FEATURE_AVMEDIA
diff --git a/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx b/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx
index 93ced9f..13d662b 100644
--- a/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx
+++ b/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx
@@ -27,9 +27,6 @@
#include <sfx2/sfxsids.hrc>
#include <sfx2/viewfrm.hxx>
#include <svtools/unitconv.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/lstbox.hxx>

#include <svl/itempool.hxx>

diff --git a/svx/source/sidebar/text/TextCharacterSpacingControl.cxx b/svx/source/sidebar/text/TextCharacterSpacingControl.cxx
index 3084b452..3de287a 100644
--- a/svx/source/sidebar/text/TextCharacterSpacingControl.cxx
+++ b/svx/source/sidebar/text/TextCharacterSpacingControl.cxx
@@ -26,6 +26,7 @@
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/sidebar/Theme.hxx>
#include <svx/TextCharacterSpacingPopup.hxx>
#include <vcl/button.hxx>
#include <vcl/settings.hxx>
#include <svl/itempool.hxx>
@@ -41,11 +42,11 @@

namespace svx {

TextCharacterSpacingControl::TextCharacterSpacingControl(sal_uInt16 nId, vcl::Window* pParent)
    : SfxPopupWindow(nId, pParent, "TextCharacterSpacingControl", "svx/ui/textcharacterspacingcontrol.ui")
,   mnId(nId)
,   mnCustomKern(0)
,   mnLastCus(SPACING_NOCUSTOM)
TextCharacterSpacingControl::TextCharacterSpacingControl(TextCharacterSpacingPopup* pControl, vcl::Window* pParent)
    : ToolbarPopup(pControl->getFrameInterface(), pParent, "TextCharacterSpacingControl", "svx/ui/textcharacterspacingcontrol.ui")
    , mnId(SID_ATTR_CHAR_KERNING)
    , mnCustomKern(0)
    , mnLastCus(SPACING_NOCUSTOM)
{
    get(maEditKerning, "kerning");

@@ -94,7 +95,7 @@ void TextCharacterSpacingControl::dispose()
    maLoose.clear();
    maLastCustom.clear();

    SfxPopupWindow::dispose();
    ToolbarPopup::dispose();
}

void TextCharacterSpacingControl::Initialize()
diff --git a/svx/source/sidebar/text/TextCharacterSpacingControl.hxx b/svx/source/sidebar/text/TextCharacterSpacingControl.hxx
index 6c3a649..d4f79cd 100644
--- a/svx/source/sidebar/text/TextCharacterSpacingControl.hxx
+++ b/svx/source/sidebar/text/TextCharacterSpacingControl.hxx
@@ -22,7 +22,7 @@
#include <sfx2/bindings.hxx>
#include <vcl/fixed.hxx>
#include <vcl/field.hxx>
#include <sfx2/tbxctrl.hxx>
#include <svtools/toolbarmenu.hxx>

namespace svx {
#define SPACING_NOCUSTOM                0
@@ -31,10 +31,12 @@ namespace svx {

#define SIDEBAR_SPACING_GLOBAL_VALUE   "PopupPanel_Spacing"

class TextCharacterSpacingControl : public SfxPopupWindow
class TextCharacterSpacingPopup;

class TextCharacterSpacingControl final : public svtools::ToolbarPopup
{
public:
    explicit TextCharacterSpacingControl(sal_uInt16 nId, vcl::Window* pParent);
    explicit TextCharacterSpacingControl(TextCharacterSpacingPopup* pControl, vcl::Window* pParent);
    virtual ~TextCharacterSpacingControl() override;
    virtual void dispose() override;

@@ -48,7 +50,7 @@ private:
    VclPtr<PushButton> maLoose;
    VclPtr<PushButton> maLastCustom;

    sal_uInt16 const    mnId;
    sal_uInt16          mnId;
    long                mnCustomKern;
    short               mnLastCus;

diff --git a/svx/source/sidebar/text/TextCharacterSpacingPopup.cxx b/svx/source/sidebar/text/TextCharacterSpacingPopup.cxx
index cdf0f99..ea71043 100644
--- a/svx/source/sidebar/text/TextCharacterSpacingPopup.cxx
+++ b/svx/source/sidebar/text/TextCharacterSpacingPopup.cxx
@@ -24,27 +24,46 @@

using namespace svx;

SFX_IMPL_TOOLBOX_CONTROL(TextCharacterSpacingPopup, SvxKerningItem);

TextCharacterSpacingPopup::TextCharacterSpacingPopup(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
    : SfxToolBoxControl(nSlotId, nId, rTbx)
TextCharacterSpacingPopup::TextCharacterSpacingPopup(const css::uno::Reference<css::uno::XComponentContext>& rContext)
    : PopupWindowController(rContext, nullptr, OUString())
{
    rTbx.SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | rTbx.GetItemBits(nId));
}

void TextCharacterSpacingPopup::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
{
    PopupWindowController::initialize(rArguments);

    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL)
        pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWNONLY | pToolBox->GetItemBits(nId));
}

TextCharacterSpacingPopup::~TextCharacterSpacingPopup()
{
}

VclPtr<SfxPopupWindow> TextCharacterSpacingPopup::CreatePopupWindow()
VclPtr<vcl::Window> TextCharacterSpacingPopup::createPopupWindow(vcl::Window* pParent)
{
    VclPtr<TextCharacterSpacingControl> pControl = VclPtr<TextCharacterSpacingControl>::Create(GetSlotId(), &GetToolBox());
    return VclPtr<TextCharacterSpacingControl>::Create(this, pParent);
}

    pControl->StartPopupMode(&GetToolBox(), FloatWinPopupFlags::GrabFocus);
OUString TextCharacterSpacingPopup::getImplementationName()
{
    return "com.sun.star.comp.svx.CharacterSpacingToolBoxControl";
}

    SetPopupWindow(pControl);
css::uno::Sequence<OUString> TextCharacterSpacingPopup::getSupportedServiceNames()
{
    return { "com.sun.star.frame.ToolbarController" };
}

    return pControl;
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_CharacterSpacingToolBoxControl_get_implementation(
    css::uno::XComponentContext* rContext,
    css::uno::Sequence<css::uno::Any> const & )
{
    return cppu::acquire(new TextCharacterSpacingPopup(rContext));
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/util/svx.component b/svx/util/svx.component
index 3231266..a27f470 100644
--- a/svx/util/svx.component
+++ b/svx/util/svx.component
@@ -108,4 +108,8 @@
    constructor="com_sun_star_comp_svx_LineSpacingToolBoxControl_get_implementation">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
  <implementation name="com.sun.star.comp.svx.CharacterSpacingToolBoxControl"
    constructor="com_sun_star_comp_svx_CharacterSpacingToolBoxControl_get_implementation">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
</component>
diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx
index 49b96b4..67c492e6 100644
--- a/sw/source/uibase/app/swmodule.cxx
+++ b/sw/source/uibase/app/swmodule.cxx
@@ -274,7 +274,6 @@ void SwDLL::RegisterControls()
    SvxTbxCtlDraw::RegisterControl(SID_INSERT_DRAW, pMod );
    SvxTbxCtlDraw::RegisterControl(SID_TRACK_CHANGES_BAR, pMod );
    SwTbxAutoTextCtrl::RegisterControl(FN_GLOSSARY_DLG, pMod );
    svx::TextCharacterSpacingPopup::RegisterControl(SID_ATTR_CHAR_KERNING, pMod);
    svx::TextUnderlinePopup::RegisterControl(SID_ATTR_CHAR_UNDERLINE, pMod);
    svx::ParaAboveSpacingControl::RegisterControl(SID_ATTR_PARA_ABOVESPACE, pMod);
    svx::ParaBelowSpacingControl::RegisterControl(SID_ATTR_PARA_BELOWSPACE, pMod);