weld gallery panel

Change-Id: I4aebb3f90e9943044d106a507972c39434988f03
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87003
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/cui/source/dialogs/cuigaldlg.cxx b/cui/source/dialogs/cuigaldlg.cxx
index 21726bb..fcf0d4c 100644
--- a/cui/source/dialogs/cuigaldlg.cxx
+++ b/cui/source/dialogs/cuigaldlg.cxx
@@ -367,7 +367,7 @@ void TakeProgress::LaunchThread()
    maTakeThread->launch();
}

ActualizeProgress::ActualizeProgress(weld::Window* pWindow, GalleryTheme* pThm)
ActualizeProgress::ActualizeProgress(weld::Widget* pWindow, GalleryTheme* pThm)
    : GenericDialogController(pWindow, "cui/ui/galleryupdateprogress.ui",
                              "GalleryUpdateProgress")
    , pIdle(nullptr)
@@ -416,7 +416,7 @@ IMPL_LINK( ActualizeProgress, ActualizeHdl, const INetURLObject&, rURL, void )
    m_xFtActualizeFile->set_label(GetReducedString(rURL, 30));
}

TitleDialog::TitleDialog(weld::Window* pParent, const OUString& rOldTitle)
TitleDialog::TitleDialog(weld::Widget* pParent, const OUString& rOldTitle)
    : GenericDialogController(pParent, "cui/ui/gallerytitledialog.ui", "GalleryTitleDialog")
    , m_xEdit(m_xBuilder->weld_entry("entry"))
{
@@ -428,7 +428,7 @@ TitleDialog::~TitleDialog()
{
}

GalleryIdDialog::GalleryIdDialog(weld::Window* pParent, GalleryTheme* _pThm)
GalleryIdDialog::GalleryIdDialog(weld::Widget* pParent, GalleryTheme* _pThm)
    : GenericDialogController(pParent, "cui/ui/gallerythemeiddialog.ui", "GalleryThemeIDDialog")
    , m_pThm(_pThm)
    , m_xBtnOk(m_xBuilder->weld_button("ok"))
@@ -476,7 +476,7 @@ IMPL_LINK_NOARG(GalleryIdDialog, ClickOkHdl, weld::Button&, void)
        m_xDialog->response(RET_OK);
}

GalleryThemeProperties::GalleryThemeProperties(weld::Window* pParent,
GalleryThemeProperties::GalleryThemeProperties(weld::Widget* pParent,
    ExchangeData* _pData, SfxItemSet const * pItemSet)
    : SfxTabDialogController(pParent, "cui/ui/gallerythemedialog.ui",
                             "GalleryThemeDialog", pItemSet)
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 1b84c07..0825c04 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -1103,7 +1103,7 @@ VclPtr<AbstractSpellDialog> AbstractDialogFactory_Impl::CreateSvxSpellDialog(
    return VclPtr<AbstractSpellDialog_Impl>::Create(std::make_unique<svx::SpellDialog>(pSpellChildWindow, pParent, pBindings));
}

VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateActualizeProgressDialog(weld::Window* pParent,
VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateActualizeProgressDialog(weld::Widget* pParent,
                                                                                               GalleryTheme* pThm)
{
   return VclPtr<CuiAbstractController_Impl>::Create(std::make_unique<ActualizeProgress>(pParent, pThm));
@@ -1136,19 +1136,19 @@ VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateSvxScriptOrgDialog(w
    return VclPtr<CuiAbstractController_Impl>::Create(std::make_unique<SvxScriptOrgDialog>(pParent, rLanguage));
}

VclPtr<AbstractTitleDialog> AbstractDialogFactory_Impl::CreateTitleDialog(weld::Window* pParent,
VclPtr<AbstractTitleDialog> AbstractDialogFactory_Impl::CreateTitleDialog(weld::Widget* pParent,
                                            const OUString& rOldText)
{
   return VclPtr<AbstractTitleDialog_Impl>::Create(std::make_unique<TitleDialog>(pParent, rOldText));
}

VclPtr<AbstractGalleryIdDialog> AbstractDialogFactory_Impl::CreateGalleryIdDialog(weld::Window* pParent,
VclPtr<AbstractGalleryIdDialog> AbstractDialogFactory_Impl::CreateGalleryIdDialog(weld::Widget* pParent,
                                            GalleryTheme* pThm)
{
   return VclPtr<AbstractGalleryIdDialog_Impl>::Create(std::make_unique<GalleryIdDialog>(pParent, pThm));
}

VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateGalleryThemePropertiesDialog(weld::Window* pParent,
VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateGalleryThemePropertiesDialog(weld::Widget* pParent,
                                            ExchangeData* pData,
                                            SfxItemSet* pItemSet)
{
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index 1744172..9c60124 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -839,13 +839,14 @@ public:
                            SfxBindings* pBindings,
                            svx::SpellDialogChildWindow* pSpellChildWindow ) override;

    virtual VclPtr<VclAbstractDialog> CreateActualizeProgressDialog(weld::Window* pParent, GalleryTheme* pThm) override;
    virtual VclPtr<AbstractTitleDialog> CreateTitleDialog(weld::Window* pParent, const OUString& rOldText) override;
    virtual VclPtr<AbstractGalleryIdDialog> CreateGalleryIdDialog(weld::Window* pParent,
    virtual VclPtr<VclAbstractDialog> CreateActualizeProgressDialog(weld::Widget* pParent, GalleryTheme* pThm) override;
    virtual VclPtr<AbstractTitleDialog> CreateTitleDialog(weld::Widget* pParent, const OUString& rOldText) override;
    virtual VclPtr<AbstractGalleryIdDialog> CreateGalleryIdDialog(weld::Widget* pParent,
                                            GalleryTheme* pThm) override;
    virtual VclPtr<VclAbstractDialog> CreateGalleryThemePropertiesDialog(weld::Window* pParent,
    virtual VclPtr<VclAbstractDialog> CreateGalleryThemePropertiesDialog(weld::Widget* pParent,
                                            ExchangeData* pData,
                                            SfxItemSet* pItemSet) override;

    virtual VclPtr<AbstractURLDlg> CreateURLDialog(weld::Widget* pParent,
                                            const OUString& rURL, const OUString& rAltText, const OUString& rDescription,
                                            const OUString& rTarget, const OUString& rName,
diff --git a/cui/source/inc/cuigaldlg.hxx b/cui/source/inc/cuigaldlg.hxx
index f472d283..0ad85b6 100644
--- a/cui/source/inc/cuigaldlg.hxx
+++ b/cui/source/inc/cuigaldlg.hxx
@@ -147,7 +147,7 @@ private:
    DECL_LINK(ActualizeHdl, const INetURLObject&, void);

public:
    ActualizeProgress(weld::Window* pWindow, GalleryTheme* pThm);
    ActualizeProgress(weld::Widget* pWindow, GalleryTheme* pThm);
    virtual ~ActualizeProgress() override;

    virtual short run() override;
@@ -158,7 +158,7 @@ class TitleDialog : public weld::GenericDialogController
private:
    std::unique_ptr<weld::Entry> m_xEdit;
public:
    TitleDialog(weld::Window* pParent, const OUString& rOldText);
    TitleDialog(weld::Widget* pParent, const OUString& rOldText);
    virtual ~TitleDialog() override;
    OUString GetTitle() const { return m_xEdit->get_text(); }
};
@@ -172,7 +172,7 @@ private:

    DECL_LINK(ClickOkHdl, weld::Button&, void);
public:
    GalleryIdDialog(weld::Window* pParent, GalleryTheme* pThm);
    GalleryIdDialog(weld::Widget* pParent, GalleryTheme* pThm);
    virtual ~GalleryIdDialog() override;
    sal_uInt32 GetId() const { return m_xLbResName->get_active(); }
};
@@ -184,7 +184,7 @@ class GalleryThemeProperties : public SfxTabDialogController
    virtual void PageCreated(const OString& rId, SfxTabPage &rPage) override;

public:
    GalleryThemeProperties(weld::Window* pParent, ExchangeData* pData, SfxItemSet const * pItemSet);
    GalleryThemeProperties(weld::Widget* pParent, ExchangeData* pData, SfxItemSet const * pItemSet);
};

class TPGalleryThemeGeneral : public SfxTabPage
@@ -231,7 +231,7 @@ class TPGalleryThemeProperties : public SfxTabPage
    css::uno::Reference< css::media::XPlayer >              xMediaPlayer;
    css::uno::Reference< css::ui::dialogs::XFolderPicker2 > xFolderPicker;

    SvxGalleryPreview m_aWndPreview;
    DialogGalleryPreview m_aWndPreview;
    std::unique_ptr<weld::ComboBox> m_xCbbFileType;
    std::unique_ptr<weld::TreeView> m_xLbxFound;
    std::unique_ptr<weld::Button> m_xBtnSearch;
diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx
index f4c4b9c..05230e5 100644
--- a/include/sfx2/tabdlg.hxx
+++ b/include/sfx2/tabdlg.hxx
@@ -101,7 +101,7 @@ protected:
     */
    void SavePosAndId();
public:
    SfxTabDialogController(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID,
    SfxTabDialogController(weld::Widget* pParent, const OUString& rUIXMLDescription, const OString& rID,
                           const SfxItemSet * = nullptr, bool bEditFmt = false);
    virtual ~SfxTabDialogController() override;

diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index 5d520e2..fed1873 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -479,6 +479,8 @@ public:
    virtual void    LoseFocus() override;
    virtual void    Resize() override;
    virtual void    StyleUpdated() override;
    virtual void    Show() override;
    virtual void    Hide() override;
    virtual OUString RequestHelp(tools::Rectangle& rHelpRect) override;

    void            Select();
diff --git a/include/svx/galctrl.hxx b/include/svx/galctrl.hxx
index ddbcbb3..d88a156 100644
--- a/include/svx/galctrl.hxx
+++ b/include/svx/galctrl.hxx
@@ -24,52 +24,50 @@
#include <vcl/customweld.hxx>
#include <vcl/transfer.hxx>
#include <svtools/valueset.hxx>
#include <svtools/brwbox.hxx>
#include <vcl/GraphicObject.hxx>
#include <svx/svxdllapi.h>

class GalleryDragDrop;
class GalleryTheme;
class GalleryBrowser2;
class INetURLObject;

class GalleryPreview final : public vcl::Window, public DropTargetHelper, public DragSourceHelper
class GalleryPreview final : public weld::CustomWidgetController
{
private:

    GraphicObject       aGraphicObj;
    tools::Rectangle           aPreviewRect;
    GalleryTheme* const       mpTheme;
    std::unique_ptr<GalleryDragDrop> mxDragDropTargetHelper;
    std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
    GraphicObject aGraphicObj;
    tools::Rectangle aPreviewRect;
    GalleryBrowser2* mpParent;
    GalleryTheme* mpTheme;

    bool             ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const;
    void             InitSettings();

    // Window
    virtual void     Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
    virtual Size     GetOptimalSize() const override;
    virtual void     MouseButtonDown(const MouseEvent& rMEvt) override;
    virtual void     Command(const CommandEvent& rCEvt) override;
    virtual void     KeyInput( const KeyEvent& rKEvt ) override;
    virtual void     DataChanged( const DataChangedEvent& rDCEvt ) override;


    // DropTargetHelper
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

    // DragSourceHelper
    virtual void     StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
    virtual void     SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
    virtual bool     MouseButtonDown(const MouseEvent& rMEvt) override;
    virtual bool     Command(const CommandEvent& rCEvt) override;
    virtual bool     KeyInput( const KeyEvent& rKEvt ) override;

public:

    GalleryPreview(vcl::Window* pParent,
        WinBits nStyle = WB_TABSTOP | WB_BORDER,
        GalleryTheme* pTheme = nullptr);
    GalleryPreview(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow);
    void SetTheme(GalleryTheme* pTheme) { mpTheme = pTheme; }
    virtual ~GalleryPreview() override;

    virtual bool StartDrag() override;

    virtual void Show() override;
    virtual void Hide() override;

    void                SetGraphic( const Graphic& rGraphic ) { aGraphicObj.SetGraphic( rGraphic ); }
    static void         PreviewMedia( const INetURLObject& rURL );
};

class SVX_DLLPUBLIC SvxGalleryPreview final : public weld::CustomWidgetController
class SVX_DLLPUBLIC DialogGalleryPreview final : public weld::CustomWidgetController
{
private:
    GraphicObject aGraphicObj;
@@ -81,92 +79,40 @@ private:

public:

    SvxGalleryPreview();
    DialogGalleryPreview();

    virtual void        SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
    void                SetGraphic( const Graphic& rGraphic ) { aGraphicObj.SetGraphic( rGraphic ); }
    bool                SetGraphic( const INetURLObject& );
};

class GalleryIconView final : public ValueSet, public DropTargetHelper, public DragSourceHelper
class GalleryIconView final : public SvtValueSet
{
    using ValueSet::StartDrag;

private:
    std::unique_ptr<GalleryDragDrop> mxDragDropTargetHelper;

    GalleryBrowser2*    mpParent;
    GalleryTheme*       mpTheme;

    void                InitSettings();

    // ValueSet
    virtual void        UserDraw( const UserDrawEvent& rUDEvt ) override;

    // Window
    virtual void        MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual void        Command( const CommandEvent& rCEvt ) override;
    virtual void        KeyInput( const KeyEvent& rKEvt ) override;
    virtual void        DataChanged( const DataChangedEvent& rDCEvt ) override;
    virtual bool        MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual bool        Command( const CommandEvent& rCEvt ) override;
    virtual bool        KeyInput( const KeyEvent& rKEvt ) override;

    // DropTargetHelper
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt ) override;
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

    // DragSourceHelper
    virtual void        StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
    virtual void        SetDrawingArea(weld::DrawingArea* pDrawingArea) override;

public:

                        GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme );
};
    GalleryIconView(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow);
    void SetTheme(GalleryTheme* pTheme) { mpTheme = pTheme; }
    virtual ~GalleryIconView() override;

class GalleryListView final : public BrowseBox
{
    using BrowseBox::AcceptDrop;
    using BrowseBox::ExecuteDrop;
    virtual bool StartDrag() override;

private:

    Link<GalleryListView*,void>  maSelectHdl;
    GalleryTheme*       mpTheme;
    sal_uInt32          mnCurRow;

    void                InitSettings();

    // BrowseBox
    virtual bool        SeekRow( long nRow ) override;
    virtual void        PaintField( vcl::RenderContext& rDev, const tools::Rectangle& rRect, sal_uInt16 nColumnId ) const override;
    virtual void        DoubleClick( const BrowserMouseEvent& rEvt ) override;
    virtual void        Select() override;
    virtual sal_Int8    AcceptDrop( const BrowserAcceptDropEvent& rEvt ) override;
    virtual sal_Int8    ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) override;
    virtual void        KeyInput( const KeyEvent& rKEvt ) override;

    // Window
    virtual void        Command( const CommandEvent& rCEvt ) override;
    virtual void        DataChanged( const DataChangedEvent& rDCEvt ) override;

    // DragSourceHelper
    virtual void        StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;

public:

                        GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme );

    void                SetSelectHdl( const Link<GalleryListView*,void>& rSelectHdl ) { maSelectHdl = rSelectHdl; }

    /** GetCellText returns the text at the given position
        @param  _nRow
            the number of the row
        @param  _nColId
            the ID of the column
        @return
            the text out of the cell
    */
    virtual OUString  GetCellText(long _nRow, sal_uInt16 _nColId) const override;

    // from IAccessibleTableProvider
    virtual tools::Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex) override;
    virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint) override;
    static void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize);
};

#endif // INCLUDED_SVX_GALCTRL_HXX
diff --git a/include/svx/galmisc.hxx b/include/svx/galmisc.hxx
index b3236cf..2ac010e 100644
--- a/include/svx/galmisc.hxx
+++ b/include/svx/galmisc.hxx
@@ -91,7 +91,6 @@ bool                FileExists( const INetURLObject& rURL );
bool                CreateDir(  const INetURLObject& rURL );
bool                CopyFile(  const INetURLObject& rSrcURL, const INetURLObject& rDstURL );
bool                KillFile( const INetURLObject& rURL );
BitmapEx            GalleryResGetBitmapEx(const OUString& rId);

class SgaIMapInfo final : public SdrObjUserData, public SfxListener
{
@@ -131,22 +130,26 @@ class SVX_DLLPUBLIC GalleryProgress
class GalleryTheme;
class GraphicObject;

class GalleryTransferable final : public TransferableHelper
class GalleryTransferable final : public TransferDataContainer
{
friend class GalleryTheme;
using TransferableHelper::CopyToClipboard;

    GalleryTheme*                   mpTheme;
    SgaObjKind const                meObjectKind;
    sal_uInt32 const                mnObjectPos;
    SgaObjKind                      meObjectKind;
    sal_uInt32                      mnObjectPos;
    tools::SvRef<SotStorageStream>  mxModelStream;
    std::unique_ptr<GraphicObject>  mpGraphicObject;
    std::unique_ptr<INetURLObject>  mpURL;

    void                            InitData( bool bLazy );

public:
                                    GalleryTransferable( GalleryTheme* pTheme, sal_uInt32 nObjectPos, bool bLazy );
                                    virtual ~GalleryTransferable() override;

    void                            InitData( bool bLazy );
    void                            SelectObject(sal_uInt32 nObjectPos);
    sal_uInt32                      GetObject() const { return mnObjectPos; }

    // TransferableHelper
    virtual void                    AddSupportedFormats() override;
@@ -155,7 +158,7 @@ using TransferableHelper::CopyToClipboard;
    virtual void                    DragFinished( sal_Int8 nDropAction ) override;
    virtual void                    ObjectReleased() override;

    void                            StartDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions );
    bool                            StartDrag();
};

enum class GalleryHintType
diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index 64a3c7e..ff7200d 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -90,7 +90,11 @@ private:
    SAL_DLLPRIVATE bool         ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry);
    SAL_DLLPRIVATE void         ImplWrite();
    SAL_DLLPRIVATE const GalleryObject* ImplGetGalleryObject(sal_uInt32 nPos) const
                                { return aObjectList[ nPos ].get(); }
    {
        if (nPos < aObjectList.size())
            return aObjectList[ nPos ].get();
        return nullptr;
    }
    const GalleryObject*        ImplGetGalleryObject( const INetURLObject& rURL );

    SAL_DLLPRIVATE sal_uInt32   ImplGetGalleryObjectPos( const GalleryObject* pObj ) const
@@ -162,12 +166,12 @@ public:

public:

    SAL_DLLPRIVATE SgaObjKind   GetObjectKind(sal_uInt32 nPos) const
                                {
                                    DBG_ASSERT( nPos < GetObjectCount(), "Position out of range" );
                                    return ImplGetGalleryObject( nPos )->eObjKind;
                                }

    SAL_DLLPRIVATE SgaObjKind GetObjectKind(sal_uInt32 nPos) const
    {
        if (nPos < GetObjectCount())
            return ImplGetGalleryObject( nPos )->eObjKind;
        return SgaObjKind::NONE;
    }

    SAL_DLLPRIVATE const INetURLObject& GetObjectURL(sal_uInt32 nPos) const
                                {
@@ -192,8 +196,7 @@ public:

    SAL_DLLPRIVATE bool         InsertTransferable(const css::uno::Reference< css::datatransfer::XTransferable >& rxTransferable, sal_uInt32 nInsertPos);

    SAL_DLLPRIVATE void         CopyToClipboard(vcl::Window* pWindow, sal_uInt32 nPos);
    SAL_DLLPRIVATE void         StartDrag(vcl::Window* pWindow, sal_uInt32 nPos);
    SAL_DLLPRIVATE void         CopyToClipboard(sal_uInt32 nPos);

public:

diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc
index 993b03a..02d249e 100644
--- a/include/svx/strings.hrc
+++ b/include/svx/strings.hrc
@@ -938,7 +938,6 @@
// Tango colors, see: http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
#define RID_SVXSTR_COLOR_TANGO_ALUMINIUM                    NC_("RID_SVXSTR_COLOR_TANGO_ALUMINIUM", "Tango: Aluminium")
#define RID_SVXSTR_GALLERYPROPS_GALTHEME                    NC_("RID_SVXSTR_GALLERYPROPS_GALTHEME", "Gallery Theme")
#define RID_SVXSTR_GALLERY_THEMEITEMS                       NC_("RID_SVXSTR_GALLERY_THEMEITEMS", "Theme Items")
#define RID_SVXSTR_GALLERY_PREVIEW                          NC_("RID_SVXSTR_GALLERY_PREVIEW", "Preview")
#define RID_SVXSTR_SUCCESSRECOV                             NC_("RID_SVXSTR_SUCCESSRECOV", "Successfully recovered")
#define RID_SVXSTR_ORIGDOCRECOV                             NC_("RID_SVXSTR_ORIGDOCRECOV", "Original document recovered")
@@ -966,10 +965,7 @@

#define RID_SVXSTR_GALLERY_FILTER                           NC_("RID_SVXSTR_GALLERY_FILTER", "Graphics filter")
#define RID_SVXSTR_GALLERY_NEWTHEME                         NC_("RID_SVXSTR_GALLERY_NEWTHEME", "New Theme")
#define RID_SVXSTR_GALLERY_CREATETHEME                      NC_("RID_SVXSTR_GALLERY_CREATETHEME", "New Theme...")
#define RID_SVXSTR_GALLERY_TITLE                            NC_("RID_SVXSTR_GALLERY_TITLE", "Title")
#define RID_SVXSTR_GALLERY_ICONVIEW                         NC_("RID_SVXSTR_GALLERY_ICONVIEW", "Icon View")
#define RID_SVXSTR_GALLERY_LISTVIEW                         NC_("RID_SVXSTR_GALLERY_LISTVIEW", "Detailed View")

#define RID_GALLERYSTR_THEME_3D                             NC_("RID_GALLERYSTR_THEME_3D", "3D Effects")
#define RID_GALLERYSTR_THEME_ANIMATIONS                     NC_("RID_GALLERYSTR_THEME_ANIMATIONS", "Animations")
diff --git a/include/svx/svxdlg.hxx b/include/svx/svxdlg.hxx
index 2fce5d6..22b6139 100644
--- a/include/svx/svxdlg.hxx
+++ b/include/svx/svxdlg.hxx
@@ -344,15 +344,16 @@ public:
                                            SfxBindings* pBindings,
                                            svx::SpellDialogChildWindow* pSpellChildWindow )=0;

    virtual VclPtr<VclAbstractDialog> CreateActualizeProgressDialog(weld::Window* pParent,
    virtual VclPtr<VclAbstractDialog> CreateActualizeProgressDialog(weld::Widget* pParent,
                                            GalleryTheme* pThm) = 0;
    virtual VclPtr<AbstractTitleDialog> CreateTitleDialog(weld::Window* pParent,
    virtual VclPtr<AbstractTitleDialog> CreateTitleDialog(weld::Widget* pParent,
                                             const OUString& rOldText) = 0;
    virtual VclPtr<AbstractGalleryIdDialog> CreateGalleryIdDialog(weld::Window* pParent,
    virtual VclPtr<AbstractGalleryIdDialog> CreateGalleryIdDialog(weld::Widget* pParent,
                                            GalleryTheme* pThm) = 0;
    virtual VclPtr<VclAbstractDialog> CreateGalleryThemePropertiesDialog(weld::Window* pParent,
    virtual VclPtr<VclAbstractDialog> CreateGalleryThemePropertiesDialog(weld::Widget* pParent,
                                            ExchangeData* pData,
                                            SfxItemSet* pItemSet ) = 0;

    virtual VclPtr<AbstractURLDlg> CreateURLDialog(weld::Widget* pParent,
                                            const OUString& rURL, const OUString& rAltText, const OUString& rDescription,
                                            const OUString& rTarget, const OUString& rName,
diff --git a/include/vcl/customweld.hxx b/include/vcl/customweld.hxx
index 330ab16..148bd6a 100644
--- a/include/vcl/customweld.hxx
+++ b/include/vcl/customweld.hxx
@@ -19,6 +19,7 @@ class VCL_DLLPUBLIC CustomWidgetController
private:
    Size m_aSize;
    weld::DrawingArea* m_pDrawingArea;
    DECL_LINK(DragBeginHdl, weld::DrawingArea&, bool);

public:
    virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible()
@@ -72,6 +73,14 @@ public:
    void SetPointer(PointerStyle ePointerStyle) { m_pDrawingArea->set_cursor(ePointerStyle); }
    void SetHelpId(const OString& rHelpId) { m_pDrawingArea->set_help_id(rHelpId); }
    void SetAccessibleName(const OUString& rName) { m_pDrawingArea->set_accessible_name(rName); }
    void SetDragDataTransferrable(rtl::Reference<TransferDataContainer>& rTransferrable,
                                  sal_uInt8 eDNDConstants)
    {
        m_pDrawingArea->enable_drag_source(rTransferrable, eDNDConstants);
        m_pDrawingArea->connect_drag_begin(LINK(this, CustomWidgetController, DragBeginHdl));
    }
    // return true to disallow drag, false to allow
    virtual bool StartDrag() { return false; }
    void set_size_request(int nWidth, int nHeight)
    {
        m_pDrawingArea->set_size_request(nWidth, nHeight);
diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx
index 9d82909..7989c01 100644
--- a/include/vcl/layout.hxx
+++ b/include/vcl/layout.hxx
@@ -19,6 +19,7 @@
#include <vcl/window.hxx>
#include <vcl/settings.hxx>
#include <vcl/event.hxx>
#include <vcl/transfer.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/IContext.hxx>
#include <vcl/commandevent.hxx>
@@ -630,10 +631,13 @@ public:
};

class VCL_DLLPUBLIC VclDrawingArea final : public Control
                                         , public DragSourceHelper
{
private:
    FactoryFunction m_pFactoryFunction;
    void* m_pUserData;
    rtl::Reference<TransferDataContainer> m_xTransferHelper;
    sal_Int8 m_nDragAction;
    Link<std::pair<vcl::RenderContext&, const tools::Rectangle&>, void> m_aPaintHdl;
    Link<const Size&, void> m_aResizeHdl;
    Link<const MouseEvent&, bool> m_aMousePressHdl;
@@ -644,6 +648,7 @@ private:
    Link<VclDrawingArea&, void> m_aStyleUpdatedHdl;
    Link<const CommandEvent&, bool> m_aCommandHdl;
    Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;
    Link<VclDrawingArea*, bool> m_aStartDragHdl;

    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override
    {
@@ -723,6 +728,7 @@ private:
            Help::ShowQuickHelp(this, aHelpArea, sHelpTip, eHelpWinStyle);
        }
    }
    virtual void StartDrag(sal_Int8 nAction, const Point& rPosPixel) override;
    virtual FactoryFunction GetUITestFactory() const override
    {
        if (m_pFactoryFunction)
@@ -733,8 +739,10 @@ private:
public:
    VclDrawingArea(vcl::Window *pParent, WinBits nStyle)
        : Control(pParent, nStyle)
        , DragSourceHelper(this)
        , m_pFactoryFunction(nullptr)
        , m_pUserData(nullptr)
        , m_nDragAction(0)
    {
        SetBackground();
    }
@@ -787,6 +795,15 @@ public:
    {
        m_aQueryTooltipHdl = rLink;
    }
    void SetStartDragHdl(const Link<VclDrawingArea*, bool>& rLink)
    {
        m_aStartDragHdl = rLink;
    }
    void SetDragHelper(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants)
    {
        m_xTransferHelper = rHelper;
        m_nDragAction = eDNDConstants;
    }
};

//Get first window of a pTopLevel window as
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 9ac53dd..c61b737 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1874,6 +1874,8 @@ protected:
    Link<const CommandEvent&, bool> m_aCommandHdl;
    Link<Widget&, tools::Rectangle> m_aGetFocusRectHdl;
    Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;
    // if handler returns true, drag is disallowed
    Link<DrawingArea&, bool> m_aDragBeginHdl;

    OUString signal_query_tooltip(tools::Rectangle& rHelpArea)
    {
@@ -1892,10 +1894,15 @@ public:
    {
        m_aQueryTooltipHdl = rLink;
    }
    void connect_drag_begin(const Link<DrawingArea&, bool>& rLink) { m_aDragBeginHdl = rLink; }
    virtual void queue_draw() = 0;
    virtual void queue_draw_area(int x, int y, int width, int height) = 0;
    virtual void queue_resize() = 0;

    virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rTransferrable,
                                    sal_uInt8 eDNDConstants)
        = 0;

    virtual void set_cursor(PointerStyle ePointerStyle) = 0;

    // use return here just to generate matching VirtualDevices
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index f21c4e5..210b6fb 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -302,7 +302,7 @@ const SfxItemSet* SfxTabPage::GetDialogExampleSet() const

SfxTabDialogController::SfxTabDialogController
(
    weld::Window* pParent,              // Parent Window
    weld::Widget* pParent,              // Parent Window
    const OUString& rUIXMLDescription, const OString& rID, // Dialog .ui path, Dialog Name
    const SfxItemSet* pItemSet,   // Itemset with the data;
                                  // can be NULL, when Pages are onDemand
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 4ffdd13..ce28416 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -14056,8 +14056,6 @@ svx/source/form/tbxform.cxx
svx/source/form/typemap.cxx
svx/source/form/xfm_addcondition.cxx
svx/source/gallery2/GalleryControl.cxx
svx/source/gallery2/GallerySplitter.cxx
svx/source/gallery2/GallerySplitter.hxx
svx/source/gallery2/codec.cxx
svx/source/gallery2/codec.hxx
svx/source/gallery2/galbrws1.cxx
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index 414f3ae..69d674b 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -4013,4 +4013,18 @@ void SvtValueSet::SetColor(const Color& rColor)
        Invalidate();
}

void SvtValueSet::Show()
{
    if (mxScrolledWindow)
        mxScrolledWindow->show();
    CustomWidgetController::Show();
}

void SvtValueSet::Hide()
{
    CustomWidgetController::Hide();
    if (mxScrolledWindow)
        mxScrolledWindow->hide();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 6613864..a2f22cd 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -181,7 +181,6 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
    svx/source/sidebar/nbdtmg \
    svx/source/sidebar/nbdtmgfact	\
    svx/source/sidebar/PanelFactory \
    svx/source/sidebar/PanelLayout \
    svx/source/sidebar/SelectionAnalyzer \
    svx/source/sidebar/SelectionChangeHandler \
    svx/source/sidebar/text/TextCharacterSpacingControl \
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 89067b0..e07289c 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -153,7 +153,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/gallery2/galobj \
    svx/source/gallery2/galtheme \
    svx/source/gallery2/GalleryControl \
    svx/source/gallery2/GallerySplitter \
    svx/source/items/chrtitem \
    svx/source/items/clipfmtitem \
    svx/source/items/customshapeitem \
@@ -274,6 +273,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/sdr/properties/connectorproperties \
    svx/source/sdr/properties/e3dcompoundproperties \
    svx/source/sdr/properties/oleproperties \
    svx/source/sidebar/PanelLayout \
    svx/source/svdraw/clonelist \
    svx/source/svdraw/charthelper \
    svx/source/svdraw/gradtrns \
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index aa3486a..bd58d87 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -96,6 +96,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
	svx/uiconfig/ui/selectionmenu \
	svx/uiconfig/ui/sidebararea \
	svx/uiconfig/ui/sidebarshadow \
	svx/uiconfig/ui/sidebargallery \
	svx/uiconfig/ui/sidebargraphic \
	svx/uiconfig/ui/sidebarline \
	svx/uiconfig/ui/sidebarparagraph \
diff --git a/svx/inc/GalleryControl.hxx b/svx/inc/GalleryControl.hxx
index 4ed3dd7..8e65bb5 100644
--- a/svx/inc/GalleryControl.hxx
+++ b/svx/inc/GalleryControl.hxx
@@ -19,13 +19,12 @@
#ifndef INCLUDED_SVX_INC_GALLERYCONTROL_HXX
#define INCLUDED_SVX_INC_GALLERYCONTROL_HXX

#include <vcl/window.hxx>
#include <svx/sidebar/PanelLayout.hxx>
#include <svx/svxdllapi.h>

class SfxBindings;

class Gallery;
class GallerySplitter;
class GalleryBrowser1;
class GalleryBrowser2;
class FmFormModel;
@@ -34,27 +33,20 @@ class Splitter;
namespace svx { namespace sidebar {


class SVX_DLLPUBLIC GalleryControl final : public vcl::Window
class SVX_DLLPUBLIC GalleryControl final : public PanelLayout
{
public:
    GalleryControl( vcl::Window* pParentWindow );

    bool GalleryKeyInput( const KeyEvent& rKEvt );

private:
    Gallery* mpGallery;
    VclPtr<GallerySplitter> mpSplitter;
    VclPtr<GalleryBrowser1> mpBrowser1;
    VclPtr<GalleryBrowser2> mpBrowser2;
    bool mbIsInitialResize;
    std::unique_ptr<GalleryBrowser1> mxBrowser1;
    std::unique_ptr<GalleryBrowser2> mxBrowser2;

    void InitSettings();

    virtual void Resize() override;
    virtual void GetFocus() override;

    DECL_LINK(SplitHdl, Splitter*, void);

    virtual ~GalleryControl() override;
    virtual void dispose() override;
};
diff --git a/svx/inc/bitmaps.hlst b/svx/inc/bitmaps.hlst
index 158b661..7316b88 100644
--- a/svx/inc/bitmaps.hlst
+++ b/svx/inc/bitmaps.hlst
@@ -145,8 +145,6 @@
#define RID_SVXBMP_GALLERY_SOUND_5                  "svx/res/galsnd5.png"
#define RID_SVXBMP_GALLERY_SOUND_6                  "svx/res/galsnd6.png"
#define RID_SVXBMP_GALLERY_SOUND_7                  "svx/res/galsnd7.png"
#define RID_SVXBMP_GALLERY_VIEW_ICON                "svx/res/galicon.png"
#define RID_SVXBMP_GALLERY_VIEW_LIST                "svx/res/gallist.png"

#define BMP_NONE_ICON                               "svx/res/symphony/blank.png"
#define BMP_WIDTH1_ICON                             "svx/res/symphony/width1.png"
diff --git a/svx/inc/galbrws2.hxx b/svx/inc/galbrws2.hxx
index d37ddad..6b25012 100644
--- a/svx/inc/galbrws2.hxx
+++ b/svx/inc/galbrws2.hxx
@@ -56,46 +56,39 @@ namespace o3tl
}


class GalleryToolBox final : public ToolBox
{
private:

    virtual void    KeyInput( const KeyEvent& rKEvt ) override;

public:

                    GalleryToolBox( GalleryBrowser2* pParent );
};


class Gallery;
class GalleryDragDrop;
class GalleryTheme;
class GalleryIconView;
class GalleryListView;
class GalleryPreview;
class GalleryTransferable;
class Menu;
class SgaObject;
struct DispatchInfo;

namespace svx { namespace sidebar { class GalleryControl; } }

class GalleryBrowser2 : public Control, public SfxListener
class GalleryBrowser2 : public SfxListener
{
    friend class GalleryBrowser;
    friend class svx::sidebar::GalleryControl;
    using Window::KeyInput;

private:

    SvtMiscOptions      maMiscOptions;
    Gallery*            mpGallery;
    GalleryTheme*       mpCurTheme;
    VclPtr<GalleryIconView>    mpIconView;
    VclPtr<GalleryListView>    mpListView;
    VclPtr<GalleryPreview> mpPreview;
    VclPtr<GalleryToolBox> maViewBox;
    VclPtr<FixedLine>   maSeparator;
    VclPtr<FixedText>   maInfoBar;
    std::unique_ptr<GalleryIconView> mxIconView;
    std::unique_ptr<weld::CustomWeld> mxIconViewWin;
    std::unique_ptr<weld::TreeView> mxListView;
    std::unique_ptr<GalleryDragDrop> mxDragDropTargetHelper;
    std::unique_ptr<GalleryPreview> mxPreview;
    std::unique_ptr<weld::CustomWeld> mxPreviewWin;
    std::unique_ptr<weld::ToggleButton> mxIconButton;
    std::unique_ptr<weld::ToggleButton> mxListButton;
    std::unique_ptr<weld::Label> mxInfoBar;
    rtl::Reference<GalleryTransferable> m_xHelper;
    sal_uInt32 mnCurActionPos;
    GalleryBrowserMode  meMode;
    GalleryBrowserMode  meLastMode;
@@ -103,24 +96,25 @@ private:
    css::uno::Reference< css::uno::XComponentContext > m_xContext;
    css::uno::Reference< css::util::XURLTransformer > m_xTransformer;

    void                InitSettings();

    void                ImplUpdateViews( sal_uInt16 nSelectionId );
    void                ImplUpdateInfoBar();
    sal_uInt32          ImplGetSelectedItemId( const Point* pSelPosPixel, Point& rSelPos );
    void                ImplSelectItemId(sal_uInt32 nItemId);

    // Control
    virtual void        Resize() override;
    virtual void        DataChanged( const DataChangedEvent& rDCEvt ) override;
    void                ImplUpdateSelection();
    void                UpdateVisibleRows();

    // SfxListener
    virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;

                        DECL_LINK( SelectObjectHdl, GalleryListView*, void );
                        DECL_LINK( SelectObjectValueSetHdl, ValueSet*, void );
                        DECL_LINK( SelectTbxHdl, ToolBox*, void );
                        DECL_LINK( MiscHdl, LinkParamNone*, void );
                        DECL_LINK( SelectObjectHdl, weld::TreeView&, void );
                        DECL_LINK( SelectObjectValueSetHdl, SvtValueSet*, void );
                        DECL_LINK( SelectTbxHdl, weld::ToggleButton&, void );
                        DECL_LINK( PopupMenuHdl, const CommandEvent&, bool );
                        DECL_LINK( KeyInputHdl, const KeyEvent&, bool );
                        DECL_LINK( RowActivatedHdl, weld::TreeView&, bool );
                        DECL_LINK( DragBeginHdl, weld::TreeView&, bool );
                        DECL_LINK( VisRowsScrolledHdl, weld::TreeView&, void );
                        DECL_LINK( SizeAllocHdl, const Size&, void );

private:

@@ -132,16 +126,15 @@ public:

public:

    GalleryBrowser2(vcl::Window* pParent, Gallery* pGallery);
    virtual ~GalleryBrowser2() override;
    virtual void dispose() override;
    GalleryBrowser2(weld::Builder& rBuilder, Gallery* pGallery);
    ~GalleryBrowser2();

    void                SelectTheme( const OUString& rThemeName );

    GalleryBrowserMode  GetMode() const { return meMode; }
    void                SetMode( GalleryBrowserMode eMode );

    vcl::Window*        GetViewWindow() const;
    weld::Widget*       GetViewWindow() const;

    void                Travel( GalleryBrowserTravel eTravel );

@@ -150,10 +143,11 @@ public:

    sal_Int8            AcceptDrop( DropTargetHelper& rTarget );
    sal_Int8            ExecuteDrop( const ExecuteDropEvent& rEvt );
    void                StartDrag( const Point* pDragPoint = nullptr );
    bool                StartDrag();
    void                TogglePreview();
    void                ShowContextMenu( const Point* pContextPoint );
    bool                KeyInput( const KeyEvent& rEvt, vcl::Window* pWindow );
    void                ShowContextMenu(const CommandEvent& rCEvt);
    bool                KeyInput(const KeyEvent& rEvt);
    bool                ViewBoxHasFocus() const;

    static css::uno::Reference< css::frame::XFrame > GetFrame();
    const css::uno::Reference< css::util::XURLTransformer >& GetURLTransformer() const { return m_xTransformer; }
@@ -165,6 +159,29 @@ public:
    DECL_STATIC_LINK( GalleryBrowser2, AsyncDispatch_Impl, void*, void );
};

class GalleryDragDrop : public DropTargetHelper
{
private:
    GalleryBrowser2* m_pParent;

    virtual sal_Int8 AcceptDrop(const AcceptDropEvent& /*rEvt*/) override
    {
        return m_pParent->AcceptDrop(*this);
    }

    virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
    {
        return m_pParent->ExecuteDrop(rEvt);
    }

public:
    GalleryDragDrop(GalleryBrowser2* pParent, const css::uno::Reference<css::datatransfer::dnd::XDropTarget>& rDropTarget)
        : DropTargetHelper(rDropTarget)
        , m_pParent(pParent)
    {
    }
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/inc/pch/precompiled_svx.hxx b/svx/inc/pch/precompiled_svx.hxx
index fd54e68..69189bb 100644
--- a/svx/inc/pch/precompiled_svx.hxx
+++ b/svx/inc/pch/precompiled_svx.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-01-14 14:50:22 using:
 Generated on 2020-01-17 19:33:52 using:
 ./bin/update_pch svx svx --cutoff=3 --exclude:system --exclude:module --include:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -47,27 +47,20 @@
#endif // PCH_LEVEL >= 1
#if PCH_LEVEL >= 2
#include <osl/diagnose.h>
#include <osl/diagnose.hxx>
#include <osl/doublecheckedlocking.h>
#include <osl/file.hxx>
#include <osl/getglobalmutex.hxx>
#include <osl/interlck.h>
#include <osl/mutex.hxx>
#include <osl/nlsupport.h>
#include <osl/security.hxx>
#include <osl/thread.h>
#include <rtl/alloc.h>
#include <rtl/bootstrap.hxx>
#include <rtl/instance.hxx>
#include <rtl/math.hxx>
#include <rtl/ref.hxx>
#include <rtl/string.h>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/tencinfo.h>
#include <rtl/textenc.h>
#include <rtl/uri.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.h>
#include <rtl/ustring.hxx>
#include <rtl/uuid.h>
#include <sal/config.h>
@@ -78,7 +71,7 @@
#include <sal/typesizes.h>
#include <vcl/BitmapFilter.hxx>
#include <vcl/EnumContext.hxx>
#include <vcl/IContext.hxx>
#include <vcl/GraphicObject.hxx>
#include <vcl/Scanline.hxx>
#include <vcl/alpha.hxx>
#include <vcl/bitmapex.hxx>
@@ -100,23 +93,17 @@
#include <vcl/fixed.hxx>
#include <vcl/font.hxx>
#include <vcl/gdimtf.hxx>
#include <vcl/gradient.hxx>
#include <vcl/graph.hxx>
#include <vcl/help.hxx>
#include <vcl/idle.hxx>
#include <vcl/image.hxx>
#include <vcl/imap.hxx>
#include <vcl/imapobj.hxx>
#include <vcl/layout.hxx>
#include <vcl/mapmod.hxx>
#include <vcl/menu.hxx>
#include <vcl/metric.hxx>
#include <vcl/outdev.hxx>
#include <vcl/ptrstyle.hxx>
#include <vcl/region.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/settings.hxx>
#include <vcl/split.hxx>
#include <vcl/status.hxx>
#include <vcl/svapp.hxx>
#include <vcl/task.hxx>
@@ -135,48 +122,35 @@
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <basegfx/point/b3dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b3dpolypolygon.hxx>
#include <basegfx/range/b2irectangle.hxx>
#include <basegfx/range/b3drange.hxx>
#include <basegfx/tuple/b2dtuple.hxx>
#include <basegfx/vector/b2enums.hxx>
#include <basegfx/vector/b3dvector.hxx>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleEventObject.hpp>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/XAccessible.hpp>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/awt/GradientStyle.hpp>
#include <com/sun/star/awt/Point.hpp>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#include <com/sun/star/beans/XMultiPropertyStates.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/LineCap.hpp>
#include <com/sun/star/drawing/TextFitToSizeType.hpp>
#include <com/sun/star/drawing/XShapeDescriptor.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XController2.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
@@ -185,32 +159,20 @@
#include <com/sun/star/frame/XStatusListener.hpp>
#include <com/sun/star/frame/XToolbarController.hpp>
#include <com/sun/star/i18n/BreakIterator.hpp>
#include <com/sun/star/i18n/UnicodeScript.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/lang/EventObject.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/style/NumberingType.hpp>
#include <com/sun/star/style/TabStop.hpp>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/text/DefaultNumberingProvider.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/text/XNumberingFormatter.hpp>
#include <com/sun/star/text/XNumberingTypeInfo.hpp>
#include <com/sun/star/text/XTextAppend.hpp>
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/XTextCopy.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/text/XTextRangeCompare.hpp>
#include <com/sun/star/text/XTextRangeMover.hpp>
#include <com/sun/star/text/textfield/Type.hpp>
#include <com/sun/star/ui/XContextChangeEventListener.hpp>
#include <com/sun/star/uno/Any.h>
@@ -228,16 +190,13 @@
#include <com/sun/star/uno/XWeak.hpp>
#include <com/sun/star/uno/genfunc.hxx>
#include <com/sun/star/util/NumberFormat.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/view/XSelectionChangeListener.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <comphelper/accessibleeventnotifier.hxx>
#include <comphelper/broadcasthelper.hxx>
#include <comphelper/comphelperdllapi.h>
#include <comphelper/interfacecontainer2.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/proparrhlp.hxx>
@@ -262,42 +221,37 @@
#include <cppuhelper/propshlp.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/weakagg.hxx>
#include <cppuhelper/weakref.hxx>
#include <drawinglayer/drawinglayerdllapi.h>
#include <drawinglayer/geometry/viewinformation2d.hxx>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/editdata.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editengdllapi.h>
#include <editeng/editstat.hxx>
#include <editeng/editview.hxx>
#include <editeng/eedata.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/flditem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/frmdir.hxx>
#include <editeng/itemtype.hxx>
#include <editeng/kernitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/memberids.h>
#include <editeng/numdef.hxx>
#include <editeng/numitem.hxx>
#include <editeng/outliner.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/paragraphdata.hxx>
#include <editeng/postitem.hxx>
#include <editeng/sizeitem.hxx>
#include <editeng/svxenum.hxx>
#include <editeng/svxfont.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/unoedhlp.hxx>
#include <editeng/unoedsrc.hxx>
#include <editeng/unolingu.hxx>
#include <editeng/unotext.hxx>
#include <editeng/wghtitem.hxx>
#include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx>
@@ -305,6 +259,7 @@
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/deleter.hxx>
#include <o3tl/optional.hxx>
#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <o3tl/underlyingenumvalue.hxx>
#include <officecfg/Office/Common.hxx>
@@ -352,12 +307,10 @@
#include <svl/stylesheetuser.hxx>
#include <svl/svldllapi.h>
#include <svl/typedwhich.hxx>
#include <svl/urihelper.hxx>
#include <svl/undo.hxx>
#include <svl/zforlist.hxx>
#include <svtools/colorcfg.hxx>
#include <svtools/ctrltool.hxx>
#include <svtools/ehdl.hxx>
#include <svtools/miscopt.hxx>
#include <svtools/popupwindowcontroller.hxx>
#include <svtools/svtdllapi.h>
#include <svtools/svtresid.hxx>
@@ -365,7 +318,6 @@
#include <svtools/toolboxcontroller.hxx>
#include <svtools/unitconv.hxx>
#include <svtools/valueset.hxx>
#include <toolkit/helper/convert.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <tools/color.hxx>
#include <tools/date.hxx>
@@ -374,7 +326,9 @@
#include <tools/diagnose_ex.h>
#include <tools/fldunit.hxx>
#include <tools/fontenum.hxx>
#include <tools/fract.hxx>
#include <tools/gen.hxx>
#include <tools/helpers.hxx>
#include <tools/link.hxx>
#include <tools/mapunit.hxx>
#include <tools/poly.hxx>
@@ -384,16 +338,15 @@
#include <tools/time.hxx>
#include <tools/toolsdllapi.h>
#include <tools/urlobj.hxx>
#include <unicode/uchar.h>
#include <uno/data.h>
#include <uno/sequence2.h>
#include <unotools/accessiblerelationsethelper.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <unotools/configitem.hxx>
#include <unotools/fontcvt.hxx>
#include <unotools/localedatawrapper.hxx>
#include <unotools/options.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/syslocale.hxx>
#include <unotools/unotoolsdllapi.h>
#include <unotools/viewoptions.hxx>
#endif // PCH_LEVEL >= 3
@@ -420,17 +373,14 @@
#include <svx/fmpage.hxx>
#include <svx/fmshell.hxx>
#include <svx/fmtools.hxx>
#include <svx/gallery.hxx>
#include <svx/galmisc.hxx>
#include <svx/itemwin.hxx>
#include <svx/itextprovider.hxx>
#include <svx/msdffdef.hxx>
#include <svx/obj3d.hxx>
#include <svx/pageitem.hxx>
#include <svx/rotmodit.hxx>
#include <svx/rulritem.hxx>
#include <svx/scene3d.hxx>
#include <svx/sdasitm.hxx>
#include <svx/sdooitm.hxx>
#include <svx/sdprcitm.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <svx/sdshitm.hxx>
@@ -441,24 +391,22 @@
#include <svx/srchdlg.hxx>
#include <svx/strarray.hxx>
#include <svx/svddef.hxx>
#include <svx/svdetc.hxx>
#include <svx/svditer.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdoashp.hxx>
#include <svx/svdoattr.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdogrp.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdorect.hxx>
#include <svx/svdotable.hxx>
#include <svx/svdotext.hxx>
#include <svx/svdoutl.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdtext.hxx>
#include <svx/svdtrans.hxx>
#include <svx/svdtypes.hxx>
#include <svx/svdview.hxx>
#include <svx/svx3ditems.hxx>
#include <svx/svxdlg.hxx>
#include <svx/svxdllapi.h>
#include <svx/tbxcolor.hxx>
@@ -466,10 +414,8 @@
#include <svx/unomid.hxx>
#include <svx/unopage.hxx>
#include <svx/unoprov.hxx>
#include <svx/unoshape.hxx>
#include <svx/unoshtxt.hxx>
#include <svx/viewpt3d.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xcolit.hxx>
#include <svx/xdef.hxx>
#include <svx/xenum.hxx>
@@ -486,10 +432,8 @@
#include <svx/xlnstit.hxx>
#include <svx/xlntrit.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/xoutbmp.hxx>
#include <svx/xtable.hxx>
#include <svx/zoomslideritem.hxx>
#include <uiobject.hxx>
#endif // PCH_LEVEL >= 4

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/inc/pch/precompiled_svxcore.hxx b/svx/inc/pch/precompiled_svxcore.hxx
index e1dc18d..bc5d37d9 100644
--- a/svx/inc/pch/precompiled_svxcore.hxx
+++ b/svx/inc/pch/precompiled_svxcore.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-01-14 14:50:28 using:
 Generated on 2020-01-19 20:29:49 using:
 ./bin/update_pch svx svxcore --cutoff=7 --exclude:system --include:module --exclude:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -61,12 +61,10 @@
#include <osl/getglobalmutex.hxx>
#include <osl/interlck.h>
#include <osl/mutex.hxx>
#include <osl/process.h>
#include <osl/thread.h>
#include <osl/time.h>
#include <rtl/alloc.h>
#include <rtl/character.hxx>
#include <rtl/crc.h>
#include <rtl/instance.hxx>
#include <rtl/locale.h>
#include <rtl/math.h>
@@ -93,7 +91,6 @@
#include <sal/saldllapi.h>
#include <sal/types.h>
#include <sal/typesizes.h>
#include <vcl/AccessibleBrowseBoxObjType.hxx>
#include <vcl/EnumContext.hxx>
#include <vcl/GraphicExternalLink.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
@@ -124,7 +121,6 @@
#include <vcl/gfxlink.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/headbar.hxx>
#include <vcl/idle.hxx>
#include <vcl/image.hxx>
#include <vcl/keycod.hxx>
@@ -145,6 +141,7 @@
#include <vcl/task.hxx>
#include <vcl/textfilter.hxx>
#include <vcl/timer.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/transfer.hxx>
#include <vcl/vclenum.hxx>
#include <vcl/vclevent.hxx>
@@ -331,7 +328,6 @@
#include <editeng/writingmodeitem.hxx>
#include <i18nlangtag/i18nlangtagdllapi.h>
#include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx>
#include <libxml/xmlwriter.h>
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/deleter.hxx>
@@ -386,7 +382,6 @@
#include <tools/helpers.hxx>
#include <tools/link.hxx>
#include <tools/mapunit.hxx>
#include <tools/poly.hxx>
#include <tools/ref.hxx>
#include <tools/solar.h>
#include <tools/stream.hxx>
@@ -415,7 +410,6 @@
#endif // PCH_LEVEL >= 3
#if PCH_LEVEL >= 4
#include <svx/XPropertyTable.hxx>
#include <svx/cube3d.hxx>
#include <svx/dialmgr.hxx>
#include <svx/e3dsceneupdater.hxx>
#include <svx/extrud3d.hxx>
@@ -458,7 +452,6 @@
#include <svx/sdtfchim.hxx>
#include <svx/sdynitm.hxx>
#include <svx/selectioncontroller.hxx>
#include <svx/sphere3d.hxx>
#include <svx/svddef.hxx>
#include <svx/svddrag.hxx>
#include <svx/svdedtv.hxx>
diff --git a/svx/source/gallery2/GalleryControl.cxx b/svx/source/gallery2/GalleryControl.cxx
index c3fc9a1..89ae895 100644
--- a/svx/source/gallery2/GalleryControl.cxx
+++ b/svx/source/gallery2/GalleryControl.cxx
@@ -23,43 +23,23 @@
#include <svx/gallery1.hxx>
#include "galbrws1.hxx"
#include <galbrws2.hxx>
#include "GallerySplitter.hxx"
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <sfx2/sidebar/Theme.hxx>

namespace svx::sidebar {

static const sal_Int32 gnInitialVerticalSplitPosition (150);

GalleryControl::GalleryControl (
    vcl::Window* pParentWindow)
    : Window(pParentWindow, WB_SIZEABLE|WB_MOVEABLE|WB_CLOSEABLE|WB_HIDE),
      mpGallery (Gallery::GetGalleryInstance()),
      mpSplitter(VclPtr<GallerySplitter>::Create(
              this,
              WB_HSCROLL,
              [this] () { return this->InitSettings(); })),
      mpBrowser1(VclPtr<GalleryBrowser1>::Create(
              this,
GalleryControl::GalleryControl(vcl::Window* pParent)
    : PanelLayout(pParent, "GalleryPanel", "svx/ui/sidebargallery.ui", nullptr, true)
    , mpGallery(Gallery::GetGalleryInstance())
    , mxBrowser1(new GalleryBrowser1(
              *m_xBuilder,
              mpGallery,
              [this] (KeyEvent const& rEvent, vcl::Window *const /*pWindow*/)
                  { return this->GalleryKeyInput(rEvent); },
              [this] ()
                  { return mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme()); })),
      mpBrowser2(VclPtr<GalleryBrowser2>::Create(this, mpGallery)),
      mbIsInitialResize(true)
                  { return mxBrowser2->SelectTheme(mxBrowser1->GetSelectedTheme()); }))
    , mxBrowser2(new GalleryBrowser2(*m_xBuilder, mpGallery))
{
    mpBrowser1->SelectTheme(0);
    mpBrowser1->Show();

    mpBrowser2->Show();

    mpSplitter->SetHorizontal(false);
    mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
    mpSplitter->Show();

    InitSettings();
    mxBrowser1->SelectTheme(0);
}

GalleryControl::~GalleryControl()
@@ -69,176 +49,18 @@ GalleryControl::~GalleryControl()

void GalleryControl::dispose()
{
    mpBrowser2.disposeAndClear();
    mpBrowser1.disposeAndClear();
    mpSplitter.disposeAndClear();
    vcl::Window::dispose();
}

void GalleryControl::InitSettings()
{
    SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
    SetControlBackground( GALLERY_DLG_COLOR );
    SetControlForeground( GALLERY_DLG_COLOR );

    mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
    mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
    mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );

    mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
    mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
    mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );

    mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
    mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
    mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );

    const Wallpaper aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
    mpSplitter->SetBackground(aBackground);
    SetBackground(aBackground);
    mpBrowser2->SetBackground(aBackground);
}

void GalleryControl::Resize()
{
    // call parent
    Window::Resize();

    // update hor/ver
    const Size aNewSize( GetOutputSizePixel() );
    if (aNewSize.Width()<=0 || aNewSize.Height()<=0)
        return;

    const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
    const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
    long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
    const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());

    if(bNewLayoutHorizontal != bOldLayoutHorizontal)
    {
        mpSplitter->SetHorizontal(bNewLayoutHorizontal);
    }
    else
    {
        if (mbIsInitialResize)
        {
            nSplitPos = gnInitialVerticalSplitPosition;
            if (nSplitPos > aNewSize.Height()/2)
                nSplitPos = aNewSize.Height()/2;
        }
    }
    mbIsInitialResize = false;

    const long nFrameLen = LogicToPixel(Size(3, 0), MapMode(MapUnit::MapAppFont)).Width();
    const long nFrameLen2 = nFrameLen << 1;

    if(bNewLayoutHorizontal)
    {
        mpBrowser1->SetPosSizePixel(
            Point( nFrameLen, nFrameLen ),
            Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );

        mpSplitter->SetPosSizePixel(
            Point( nSplitPos, 0),
            Size( nSplitSize, aNewSize.Height() ) );

        mpSplitter->SetDragRectPixel(
            tools::Rectangle(
                Point( nFrameLen2, 0 ),
                Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );

        mpBrowser2->SetPosSizePixel(
            Point( nSplitPos + nSplitSize, nFrameLen ),
            Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
    }
    else
    {
        mpBrowser1->SetPosSizePixel(
            Point( nFrameLen, nFrameLen ),
            Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));

        mpSplitter->SetPosSizePixel(
            Point( 0, nSplitPos),
            Size( aNewSize.Width(), nSplitSize ) );

        mpSplitter->SetDragRectPixel(
            tools::Rectangle(
                Point( 0, nFrameLen2 ),
                Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));

        mpBrowser2->SetPosSizePixel(
            Point( nFrameLen, nSplitPos + nSplitSize ),
            Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
    }
}

bool GalleryControl::GalleryKeyInput( const KeyEvent& rKEvt )
{
    const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
    bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
                           ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );

    if( bRet )
    {
        if( !rKEvt.GetKeyCode().IsShift() )
        {
            if( mpBrowser1->maNewTheme->HasFocus() )
                mpBrowser1->mpThemes->GrabFocus();
            else if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
                mpBrowser2->maViewBox->GrabFocus();
            else if( mpBrowser2->maViewBox->HasFocus() )
                mpBrowser2->GetViewWindow()->GrabFocus();
            else
            {
                if( mpBrowser1->maNewTheme->IsEnabled() )
                    mpBrowser1->maNewTheme->GrabFocus();
                else
                    mpBrowser1->mpThemes->GrabFocus();
            }
        }
        else
        {
            if( mpBrowser2->GetViewWindow()->HasFocus() )
                mpBrowser2->maViewBox->GrabFocus();
            else if( mpBrowser2->maViewBox->HasFocus() )
                mpBrowser1->mpThemes->GrabFocus();
            else if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
            {
                if( mpBrowser1->maNewTheme->IsEnabled() )
                    mpBrowser1->maNewTheme->GrabFocus();
                else
                    mpBrowser2->GetViewWindow()->GrabFocus();
            }
            else
                mpBrowser2->GetViewWindow()->GrabFocus();
        }
    }

    return bRet;
    mxBrowser2.reset();
    mxBrowser1.reset();
    PanelLayout::dispose();
}

void GalleryControl::GetFocus()
{
    Window::GetFocus();
    if (mpBrowser1)
        mpBrowser1->GrabFocus();
    if (mxBrowser1)
        mxBrowser1->GrabFocus();
}

IMPL_LINK_NOARG( GalleryControl, SplitHdl, Splitter*, void )
{
    if(mpSplitter->IsHorizontal())
    {
        mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
    }
    else
    {
        mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
    }

    Resize();
}


} // end of namespace svx::sidebar

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/GallerySplitter.cxx b/svx/source/gallery2/GallerySplitter.cxx
deleted file mode 100644
index 21dc47c..0000000
--- a/svx/source/gallery2/GallerySplitter.cxx
+++ /dev/null
@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "GallerySplitter.hxx"

GallerySplitter::GallerySplitter(
    vcl::Window* pParent,
    WinBits nStyle,
    const ::std::function<void ()>& rDataChangeFunctor)
    : Splitter(pParent, nStyle)
    , maDataChangeFunctor(rDataChangeFunctor)
{
}

void GallerySplitter::DataChanged( const DataChangedEvent& rDCEvt )
{
    Splitter::DataChanged( rDCEvt );
    if (maDataChangeFunctor)
        maDataChangeFunctor();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/GallerySplitter.hxx b/svx/source/gallery2/GallerySplitter.hxx
deleted file mode 100644
index 8c6e05f..0000000
--- a/svx/source/gallery2/GallerySplitter.hxx
+++ /dev/null
@@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SVX_SOURCE_GALLERY2_GALLERYSPLITTER_HXX
#define INCLUDED_SVX_SOURCE_GALLERY2_GALLERYSPLITTER_HXX

#include <vcl/split.hxx>

#include <functional>

class GallerySplitter : public Splitter
{
public:
    GallerySplitter(
        vcl::Window* pParent,
        WinBits nStyle,
        const ::std::function<void ()>& rDataChangeFunctor);

protected:
    virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;

private:
    ::std::function<void ()> const maDataChangeFunctor;
};


#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galbrws1.cxx b/svx/source/gallery2/galbrws1.cxx
index 8a435a5..aefb425 100644
--- a/svx/source/gallery2/galbrws1.cxx
+++ b/svx/source/gallery2/galbrws1.cxx
@@ -47,126 +47,53 @@

using namespace ::com::sun::star;


GalleryButton::GalleryButton( GalleryBrowser1* pParent, WinBits nWinBits ) :
    PushButton( pParent, nWinBits )
{
}

void GalleryButton::KeyInput( const KeyEvent& rKEvt )
{
    if( !static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( rKEvt, this ) )
        PushButton::KeyInput( rKEvt );
}


GalleryThemeListBox::GalleryThemeListBox( GalleryBrowser1* pParent, WinBits nWinBits ) :
    ListBox( pParent, nWinBits )
{
    InitSettings();
}

void GalleryThemeListBox::InitSettings()
{
    SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
    SetControlBackground( GALLERY_BG_COLOR );
    SetControlForeground( GALLERY_FG_COLOR );
}

void GalleryThemeListBox::DataChanged( const DataChangedEvent& rDCEvt )
{
    if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
        InitSettings();
    else
        ListBox::DataChanged( rDCEvt );
}

bool GalleryThemeListBox::PreNotify( NotifyEvent& rNEvt )
{
    bool bDone = false;

    if( rNEvt.GetType() == MouseNotifyEvent::COMMAND )
    {
        const CommandEvent* pCEvt = rNEvt.GetCommandEvent();

        if( pCEvt && pCEvt->GetCommand() == CommandEventId::ContextMenu )
            static_cast< GalleryBrowser1* >( GetParent() )->ShowContextMenu();
    }
    else if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
    {
        const KeyEvent* pKEvt = rNEvt.GetKeyEvent();

        if( pKEvt )
            bDone = static_cast< GalleryBrowser1* >( GetParent() )->KeyInput( *pKEvt, this );
    }

    return( bDone || ListBox::PreNotify( rNEvt ) );
}


GalleryBrowser1::GalleryBrowser1(
    vcl::Window* pParent,
    weld::Builder& rBuilder,
    Gallery* pGallery,
    const std::function<sal_Bool (const KeyEvent&,Window*)>& rKeyInputHandler,
    const std::function<void ()>& rThemeSlectionHandler)
    :
    Control               ( pParent, WB_TABSTOP ),
    maNewTheme            ( VclPtr<GalleryButton>::Create(this, WB_3DLOOK) ),
    mpThemes              ( VclPtr<GalleryThemeListBox>::Create( this, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_HSCROLL | WB_VSCROLL | WB_AUTOHSCROLL | WB_SORT ) ),
    mxNewTheme(rBuilder.weld_button("insert")),
    mxThemes(rBuilder.weld_tree_view("themelist")),
    mpGallery             ( pGallery ),
    mpExchangeData        ( new ExchangeData ),
    aImgNormal            ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_NORMAL ) ),
    aImgDefault           ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_DEFAULT ) ),
    aImgReadOnly          ( GalleryResGetBitmapEx( RID_SVXBMP_THEME_READONLY ) ),
    maKeyInputHandler(rKeyInputHandler),
    aImgNormal            ( RID_SVXBMP_THEME_NORMAL ),
    aImgDefault           ( RID_SVXBMP_THEME_DEFAULT ),
    aImgReadOnly          ( RID_SVXBMP_THEME_READONLY ),
    maThemeSlectionHandler(rThemeSlectionHandler)
{
    StartListening( *mpGallery );
    mxNewTheme->set_help_id(HID_GALLERY_NEWTHEME);
    mxNewTheme->connect_clicked( LINK( this, GalleryBrowser1, ClickNewThemeHdl ) );

    maNewTheme->SetHelpId( HID_GALLERY_NEWTHEME );
    maNewTheme->SetText( SvxResId(RID_SVXSTR_GALLERY_CREATETHEME));
    maNewTheme->SetClickHdl( LINK( this, GalleryBrowser1, ClickNewThemeHdl ) );
    mxThemes->make_sorted();
    mxThemes->set_help_id( HID_GALLERY_THEMELIST );
    mxThemes->connect_changed( LINK( this, GalleryBrowser1, SelectThemeHdl ) );
    mxThemes->connect_popup_menu(LINK(this, GalleryBrowser1, PopupMenuHdl));
    mxThemes->connect_key_press(LINK(this, GalleryBrowser1, KeyInputHdl));
    mxThemes->set_size_request(-1, mxThemes->get_height_rows(6));

    // disable creation of new themes if a writable directory is not available
    if( mpGallery->GetUserURL().GetProtocol() == INetProtocol::NotValid )
        maNewTheme->Disable();
        mxNewTheme->set_sensitive(false);

    mpThemes->SetHelpId( HID_GALLERY_THEMELIST );
    mpThemes->SetSelectHdl( LINK( this, GalleryBrowser1, SelectThemeHdl ) );
    mpThemes->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERYPROPS_GALTHEME));
    StartListening( *mpGallery );

    for( size_t i = 0, nCount = mpGallery->GetThemeCount(); i < nCount; i++ )
    for (size_t i = 0, nCount = mpGallery->GetThemeCount(); i < nCount; ++i)
        ImplInsertThemeEntry( mpGallery->GetThemeInfo( i ) );

    ImplAdjustControls();
    maNewTheme->Show();
    mpThemes->Show();
}

GalleryBrowser1::~GalleryBrowser1()
{
    disposeOnce();
}

void GalleryBrowser1::dispose()
{
    EndListening( *mpGallery );
    mpThemePropertiesDialog.clear();
    mpThemes.disposeAndClear();
    mpExchangeData.reset();
    maNewTheme.disposeAndClear();
    Control::dispose();
}

sal_uIntPtr GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEntry )
void GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEntry )
{
    static const bool bShowHiddenThemes = ( getenv( "GALLERY_SHOW_HIDDEN_THEMES" ) != nullptr );

    sal_uIntPtr nRet = LISTBOX_ENTRY_NOTFOUND;

    if( pEntry && ( !pEntry->IsHidden() || bShowHiddenThemes ) )
    {
        const Image* pImage;
        const OUString* pImage;

        if( pEntry->IsReadOnly() )
            pImage = &aImgReadOnly;
@@ -175,23 +102,8 @@ sal_uIntPtr GalleryBrowser1::ImplInsertThemeEntry( const GalleryThemeEntry* pEnt
        else
            pImage = &aImgNormal;

        nRet = mpThemes->InsertEntry( pEntry->GetThemeName(), *pImage );
        mxThemes->append("", pEntry->GetThemeName(), *pImage);
    }

    return nRet;
}

void GalleryBrowser1::ImplAdjustControls()
{
    const Size  aOutSize( GetOutputSizePixel() );
    const long  nNewThemeHeight = LogicToPixel(Size(0, 14), MapMode(MapUnit::MapAppFont)).Height();
    const long  nStartY = nNewThemeHeight + 4;

    maNewTheme->SetPosSizePixel( Point(),
                                Size( aOutSize.Width(), nNewThemeHeight ) );

    mpThemes->SetPosSizePixel( Point( 0, nStartY ),
                               Size( aOutSize.Width(), aOutSize.Height() - nStartY ) );
}

void GalleryBrowser1::ImplFillExchangeData( const GalleryTheme* pThm, ExchangeData& rData )
@@ -267,18 +179,20 @@ void GalleryBrowser1::ImplGalleryThemeProperties( const OUString & rThemeName, b
    ImplFillExchangeData( pTheme, *mpExchangeData );

    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    mpThemePropertiesDialog = pFact->CreateGalleryThemePropertiesDialog(GetFrameWeld(), mpExchangeData.get(), mpThemePropsDlgItemSet.get());
    VclPtr<VclAbstractDialog> xThemePropertiesDialog = pFact->CreateGalleryThemePropertiesDialog(mxThemes.get(), mpExchangeData.get(), mpThemePropsDlgItemSet.get());

    if ( bCreateNew )
    {
        mpThemePropertiesDialog->StartExecuteAsync([this](sal_Int32 nResult){
        xThemePropertiesDialog->StartExecuteAsync([xThemePropertiesDialog, this](sal_Int32 nResult){
            EndNewThemePropertiesDlgHdl(nResult);
            xThemePropertiesDialog->disposeOnce();
        });
    }
    else
    {
        mpThemePropertiesDialog->StartExecuteAsync([this](sal_Int32 nResult){
        xThemePropertiesDialog->StartExecuteAsync([xThemePropertiesDialog, this](sal_Int32 nResult){
            EndThemePropertiesDlgHdl(nResult);
            xThemePropertiesDialog->disposeOnce();
        });
    }
}
@@ -304,8 +218,8 @@ void GalleryBrowser1::ImplEndGalleryThemeProperties(bool bCreateNew, sal_Int32 n

        if ( bCreateNew )
        {
            mpThemes->SelectEntry( mpExchangeData->pTheme->GetName() );
            SelectThemeHdl( *mpThemes );
            mxThemes->select_text( mpExchangeData->pTheme->GetName() );
            SelectThemeHdl( *mxThemes );
        }
    }

@@ -316,9 +230,6 @@ void GalleryBrowser1::ImplEndGalleryThemeProperties(bool bCreateNew, sal_Int32 n
    {
        mpGallery->RemoveTheme( aThemeName );
    }

    // destroy mpThemeProps asynchronously
    Application::PostUserEvent( LINK( this, GalleryBrowser1, DestroyThemePropertiesDlgHdl ), nullptr, true );
}

void GalleryBrowser1::EndNewThemePropertiesDlgHdl(sal_Int32 nResult)
@@ -331,12 +242,6 @@ void GalleryBrowser1::EndThemePropertiesDlgHdl(sal_Int32 nResult)
    ImplEndGalleryThemeProperties(false, nResult);
}

IMPL_LINK( GalleryBrowser1, DestroyThemePropertiesDlgHdl, void*, /*p*/, void )
{
    mpThemePropertiesDialog.disposeAndClear();
    mpThemePropsDlgItemSet.reset();
}

void GalleryBrowser1::ImplExecute(const OString &rIdent)
{
    if (rIdent == "update")
@@ -344,17 +249,17 @@ void GalleryBrowser1::ImplExecute(const OString &rIdent)
        GalleryTheme*       pTheme = mpGallery->AcquireTheme( GetSelectedTheme(), *this );

        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr<VclAbstractDialog> aActualizeProgress(pFact->CreateActualizeProgressDialog(GetFrameWeld(), pTheme));
        ScopedVclPtr<VclAbstractDialog> aActualizeProgress(pFact->CreateActualizeProgressDialog(mxThemes.get(), pTheme));

        aActualizeProgress->Execute();
        mpGallery->ReleaseTheme( pTheme, *this );
    }
    else if (rIdent == "delete")
    {
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "svx/ui/querydeletethemedialog.ui"));
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(mxThemes.get(), "svx/ui/querydeletethemedialog.ui"));
        std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteThemeDialog"));
        if (xQuery->run() == RET_YES)
            mpGallery->RemoveTheme( mpThemes->GetSelectedEntry() );
            mpGallery->RemoveTheme( mxThemes->get_selected_text() );
    }
    else if (rIdent == "rename")
    {
@@ -362,7 +267,7 @@ void GalleryBrowser1::ImplExecute(const OString &rIdent)
        const OUString  aOldName( pTheme->GetName() );

        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog(GetFrameWeld(), aOldName));
        ScopedVclPtr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog(mxThemes.get(), aOldName));

        if( aDlg->Execute() == RET_OK )
        {
@@ -391,7 +296,7 @@ void GalleryBrowser1::ImplExecute(const OString &rIdent)
        {

            SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
            ScopedVclPtr<AbstractGalleryIdDialog> aDlg(pFact->CreateGalleryIdDialog(GetFrameWeld(), pTheme));
            ScopedVclPtr<AbstractGalleryIdDialog> aDlg(pFact->CreateGalleryIdDialog(mxThemes.get(), pTheme));
            if( aDlg->Execute() == RET_OK )
                pTheme->SetId( aDlg->GetId(), true );
        }
@@ -404,19 +309,12 @@ void GalleryBrowser1::ImplExecute(const OString &rIdent)
    }
}

void GalleryBrowser1::Resize()
void GalleryBrowser1::GrabFocus()
{
    Control::Resize();
    ImplAdjustControls();
}

void GalleryBrowser1::GetFocus()
{
    Control::GetFocus();
    if( maNewTheme->IsEnabled() )
        maNewTheme->GrabFocus();
    if (mxNewTheme->get_sensitive())
        mxNewTheme->grab_focus();
    else
        mpThemes->GrabFocus();
        mxThemes->grab_focus();
}

void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint )
@@ -431,41 +329,41 @@ void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint )

        case GalleryHintType::THEME_RENAMED:
        {
            const sal_Int32 nCurSelectPos = mpThemes->GetSelectedEntryPos();
            const sal_Int32 nRenameEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
            const sal_Int32 nCurSelectPos = mxThemes->get_selected_index();
            const sal_Int32 nRenameEntryPos = mxThemes->find_text( rGalleryHint.GetThemeName() );

            mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
            mxThemes->remove_text( rGalleryHint.GetThemeName() );
            ImplInsertThemeEntry( mpGallery->GetThemeInfo( rGalleryHint.GetStringData() ) );

            if( nCurSelectPos == nRenameEntryPos )
            {
                mpThemes->SelectEntry( rGalleryHint.GetStringData() );
                SelectThemeHdl( *mpThemes );
                mxThemes->select_text( rGalleryHint.GetStringData() );
                SelectThemeHdl( *mxThemes );
            }
        }
        break;

        case GalleryHintType::THEME_REMOVED:
        {
            mpThemes->RemoveEntry( rGalleryHint.GetThemeName() );
            mxThemes->remove_text( rGalleryHint.GetThemeName() );
        }
        break;

        case GalleryHintType::CLOSE_THEME:
        {
            const sal_Int32 nCurSelectPos = mpThemes->GetSelectedEntryPos();
            const sal_Int32 nCloseEntryPos = mpThemes->GetEntryPos( rGalleryHint.GetThemeName() );
            const sal_Int32 nCurSelectPos = mxThemes->get_selected_index();
            const sal_Int32 nCloseEntryPos = mxThemes->find_text( rGalleryHint.GetThemeName() );

            if( nCurSelectPos == nCloseEntryPos )
            {
                if( nCurSelectPos < ( mpThemes->GetEntryCount() - 1 ) )
                    mpThemes->SelectEntryPos( nCurSelectPos + 1 );
                if( nCurSelectPos < ( mxThemes->n_children() - 1 ) )
                    mxThemes->select( nCurSelectPos + 1 );
                else if( nCurSelectPos )
                    mpThemes->SelectEntryPos( nCurSelectPos - 1 );
                    mxThemes->select( nCurSelectPos - 1 );
                else
                    mpThemes->SetNoSelection();
                    mxThemes->select(-1);

                SelectThemeHdl( *mpThemes );
                SelectThemeHdl( *mxThemes );
            }
        }
        break;
@@ -475,121 +373,108 @@ void GalleryBrowser1::Notify( SfxBroadcaster&, const SfxHint& rHint )
    }
}

void GalleryBrowser1::ShowContextMenu()
void GalleryBrowser1::ShowContextMenu(const CommandEvent& rCEvt)
{
    Application::PostUserEvent( LINK( this, GalleryBrowser1, ShowContextMenuHdl ), this, true );
    PopupMenuHdl(rCEvt);
}

bool GalleryBrowser1::KeyInput( const KeyEvent& rKEvt, vcl::Window* pWindow )
IMPL_LINK(GalleryBrowser1, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
    bool bRet = false;
    if (maKeyInputHandler)
        bRet = maKeyInputHandler(rKEvt, pWindow);

    if( !bRet )
    std::vector<OString> aExecVector;
    ImplGetExecuteVector(aExecVector);
    OString sExecuteIdent;
    bool bMod1 = rKEvt.GetKeyCode().IsMod1();

    switch( rKEvt.GetKeyCode().GetCode() )
    {
        std::vector<OString> aExecVector;
        ImplGetExecuteVector(aExecVector);
        OString sExecuteIdent;
        bool bMod1 = rKEvt.GetKeyCode().IsMod1();
        case KEY_INSERT:
            ClickNewThemeHdl(*mxNewTheme);
        break;

        switch( rKEvt.GetKeyCode().GetCode() )
        case KEY_I:
        {
            case KEY_INSERT:
                ClickNewThemeHdl( nullptr );
            break;
            if( bMod1 )
               ClickNewThemeHdl(*mxNewTheme);
        }
        break;

            case KEY_I:
            {
                if( bMod1 )
                   ClickNewThemeHdl( nullptr );
            }
            break;
        case KEY_U:
        {
            if( bMod1 )
                sExecuteIdent = "update";
        }
        break;

            case KEY_U:
            {
                if( bMod1 )
                    sExecuteIdent = "update";
            }
            break;
        case KEY_DELETE:
            sExecuteIdent = "delete";
        break;

            case KEY_DELETE:
        case KEY_D:
        {
            if( bMod1 )
                sExecuteIdent = "delete";
            break;

            case KEY_D:
            {
                if( bMod1 )
                    sExecuteIdent = "delete";
            }
            break;

            case KEY_R:
            {
                if( bMod1 )
                    sExecuteIdent = "rename";
            }
            break;

            case KEY_RETURN:
            {
                if( bMod1 )
                    sExecuteIdent = "properties";
            }
            break;
        }
        break;

        if (!sExecuteIdent.isEmpty() && (std::find( aExecVector.begin(), aExecVector.end(), sExecuteIdent) != aExecVector.end()))
        case KEY_R:
        {
            ImplExecute(sExecuteIdent);
            bRet = true;
            if( bMod1 )
                sExecuteIdent = "rename";
        }
        break;

        case KEY_RETURN:
        {
            if( bMod1 )
                sExecuteIdent = "properties";
        }
        break;
    }

    if (!sExecuteIdent.isEmpty() && (std::find( aExecVector.begin(), aExecVector.end(), sExecuteIdent) != aExecVector.end()))
    {
        ImplExecute(sExecuteIdent);
        bRet = true;
    }

    return bRet;
}

IMPL_LINK_NOARG(GalleryBrowser1, ShowContextMenuHdl, void*, void)
IMPL_LINK(GalleryBrowser1, PopupMenuHdl, const CommandEvent&, rCEvt, bool)
{
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return false;

    std::vector<OString> aExecVector;
    ImplGetExecuteVector(aExecVector);

    if( aExecVector.empty() )
        return;
    if (aExecVector.empty())
        return true;

    VclBuilder aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/gallerymenu1.ui", "");
    VclPtr<PopupMenu> aMenu(aBuilder.get_menu("menu"));
    std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(mxThemes.get(), "svx/ui/gallerymenu1.ui"));
    std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu"));

    aMenu->EnableItem( aMenu->GetItemId("update"), std::find( aExecVector.begin(), aExecVector.end(), "update" ) != aExecVector.end() );
    aMenu->EnableItem( aMenu->GetItemId("rename"), std::find( aExecVector.begin(), aExecVector.end(), "rename" ) != aExecVector.end() );
    aMenu->EnableItem( aMenu->GetItemId("delete"), std::find( aExecVector.begin(), aExecVector.end(), "delete" ) != aExecVector.end() );
    aMenu->EnableItem( aMenu->GetItemId("assign"), std::find( aExecVector.begin(), aExecVector.end(), "assign" ) != aExecVector.end() );
    aMenu->EnableItem( aMenu->GetItemId("properties"), std::find( aExecVector.begin(), aExecVector.end(), "properties" ) != aExecVector.end() );
    aMenu->SetSelectHdl( LINK( this, GalleryBrowser1, PopupMenuHdl ) );
    aMenu->RemoveDisabledEntries();
    xMenu->set_visible("update", std::find( aExecVector.begin(), aExecVector.end(), "update" ) != aExecVector.end());
    xMenu->set_visible("rename", std::find( aExecVector.begin(), aExecVector.end(), "rename" ) != aExecVector.end());
    xMenu->set_visible("delete", std::find( aExecVector.begin(), aExecVector.end(), "delete" ) != aExecVector.end());
    xMenu->set_visible("assign", std::find( aExecVector.begin(), aExecVector.end(), "assign" ) != aExecVector.end());
    xMenu->set_visible("properties", std::find( aExecVector.begin(), aExecVector.end(), "properties" ) != aExecVector.end());

    const tools::Rectangle aThemesRect( mpThemes->GetPosPixel(), mpThemes->GetOutputSizePixel() );
    Point           aSelPos( mpThemes->GetBoundingRectangle( mpThemes->GetSelectedEntryPos() ).Center() );
    OString sCommand(xMenu->popup_at_rect(mxThemes.get(), tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1))));
    ImplExecute(sCommand);

    aSelPos.setX( std::max( std::min( aSelPos.X(), aThemesRect.Right() ), aThemesRect.Left() ) );
    aSelPos.setY( std::max( std::min( aSelPos.Y(), aThemesRect.Bottom() ), aThemesRect.Top() ) );

    aMenu->Execute( this, aSelPos );
    return true;
}

IMPL_LINK( GalleryBrowser1, PopupMenuHdl, Menu*, pMenu, bool )
{
    ImplExecute(pMenu->GetCurItemIdent());
    return false;
}

IMPL_LINK_NOARG(GalleryBrowser1, SelectThemeHdl, ListBox&, void)
IMPL_LINK_NOARG(GalleryBrowser1, SelectThemeHdl, weld::TreeView&, void)
{
    if (maThemeSlectionHandler)
        maThemeSlectionHandler();
}

IMPL_LINK_NOARG(GalleryBrowser1, ClickNewThemeHdl, Button*, void)
IMPL_LINK_NOARG(GalleryBrowser1, ClickNewThemeHdl, weld::Button&, void)
{
    OUString  aNewTheme( SvxResId(RID_SVXSTR_GALLERY_NEWTHEME) );
    OUString  aName( aNewTheme );
diff --git a/svx/source/gallery2/galbrws1.hxx b/svx/source/gallery2/galbrws1.hxx
index 825d773..288ff6d 100644
--- a/svx/source/gallery2/galbrws1.hxx
+++ b/svx/source/gallery2/galbrws1.hxx
@@ -31,31 +31,6 @@
class GalleryBrowser1;


class GalleryButton : public PushButton
{
private:

    virtual void    KeyInput( const KeyEvent& rKEvt ) override;

public:

                    GalleryButton( GalleryBrowser1* pParent, WinBits nWinBits );
};


class GalleryThemeListBox final : public ListBox
{
    void            InitSettings();

    virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;
    virtual bool    PreNotify( NotifyEvent& rNEvt ) override;

public:

                    GalleryThemeListBox( GalleryBrowser1* pParent, WinBits nWinBits );
};


class Gallery;
class GalleryThemeEntry;
class GalleryTheme;
@@ -65,31 +40,26 @@ class SfxItemSet;

namespace svx { namespace sidebar { class GalleryControl; } }

class GalleryBrowser1 : public Control, public SfxListener
class GalleryBrowser1 final : public SfxListener
{
    friend class GalleryBrowser;
    friend class svx::sidebar::GalleryControl;
    friend class GalleryThemeListBox;
    using Window::KeyInput;

private:

    VclPtr<GalleryButton>        maNewTheme;
    VclPtr<GalleryThemeListBox>  mpThemes;
    VclPtr<VclAbstractDialog>   mpThemePropertiesDialog; // to keep it alive during execution
    Gallery*                mpGallery;
    std::unique_ptr<weld::Button> mxNewTheme;
    std::unique_ptr<weld::TreeView> mxThemes;
    Gallery* mpGallery;
    std::unique_ptr<ExchangeData> mpExchangeData;
    std::unique_ptr<SfxItemSet>   mpThemePropsDlgItemSet;
    std::unique_ptr<SfxItemSet> mpThemePropsDlgItemSet;

    Image                   aImgNormal;
    Image                   aImgDefault;
    Image                   aImgReadOnly;
    OUString aImgNormal;
    OUString aImgDefault;
    OUString aImgReadOnly;

    ::std::function<sal_Bool (const KeyEvent&,Window*)> const maKeyInputHandler;
    ::std::function<void ()> const maThemeSlectionHandler;

    void                    ImplAdjustControls();
    sal_uIntPtr             ImplInsertThemeEntry( const GalleryThemeEntry* pEntry );
    void                    ImplInsertThemeEntry( const GalleryThemeEntry* pEntry );
    static void             ImplFillExchangeData( const GalleryTheme* pThm, ExchangeData& rData );
    void                    ImplGetExecuteVector(std::vector<OString>& o_aExec);
    void                    ImplExecute(const OString &rIdent);
@@ -98,33 +68,28 @@ private:
    void                    EndThemePropertiesDlgHdl(sal_Int32 nResult);
    void                    ImplEndGalleryThemeProperties(bool bCreateNew, sal_Int32 nResult);

    // Control
    virtual void            Resize() override;
    virtual void            GetFocus() override;

    // SfxListener
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;

                            DECL_LINK( ClickNewThemeHdl, Button*, void );
                            DECL_LINK( SelectThemeHdl, ListBox&, void );
                            DECL_LINK( ShowContextMenuHdl, void*, void );
                            DECL_LINK( PopupMenuHdl, Menu*, bool );
                            DECL_LINK( DestroyThemePropertiesDlgHdl, void*, void );
                            DECL_LINK( ClickNewThemeHdl, weld::Button&, void );
                            DECL_LINK( SelectThemeHdl, weld::TreeView&, void );
                            DECL_LINK( PopupMenuHdl, const CommandEvent&, bool );
                            DECL_LINK( KeyInputHdl, const KeyEvent&, bool );

public:

                            GalleryBrowser1(
                                vcl::Window* pParent,
                                weld::Builder& rBuilder,
                                Gallery* pGallery,
                                const ::std::function<sal_Bool (const KeyEvent&,Window*)>& rKeyInputHandler,
                                const ::std::function<void ()>& rThemeSlectionHandler);
                            virtual ~GalleryBrowser1() override;
    virtual void            dispose() override;

    void                    SelectTheme( sal_uInt16 nThemePos ) { mpThemes->SelectEntryPos( nThemePos ); SelectThemeHdl( *mpThemes ); }
    OUString                GetSelectedTheme() const { return mpThemes->GetEntryCount() ? mpThemes->GetSelectedEntry() : OUString(); }
                            ~GalleryBrowser1();

    void                    ShowContextMenu();
    void                    SelectTheme( sal_uInt16 nThemePos ) { mxThemes->select( nThemePos ); SelectThemeHdl( *mxThemes ); }
    OUString                GetSelectedTheme() const { return mxThemes->get_selected_text(); }
    void                    GrabFocus();

    void                    ShowContextMenu(const CommandEvent& rCEvt);
    bool                    KeyInput( const KeyEvent& rKEvt, vcl::Window* pWindow );
};

diff --git a/svx/source/gallery2/galbrws2.cxx b/svx/source/gallery2/galbrws2.cxx
index eb70b0d..d973a43 100644
--- a/svx/source/gallery2/galbrws2.cxx
+++ b/svx/source/gallery2/galbrws2.cxx
@@ -24,6 +24,7 @@
#include <svl/intitem.hxx>
#include <svl/eitem.hxx>
#include <vcl/transfer.hxx>
#include <vcl/virdev.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
@@ -59,9 +60,6 @@
#include <memory>
#include <cppuhelper/implbase.hxx>

#define TBX_ID_ICON 1
#define TBX_ID_LIST 2

GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON;

struct DispatchInfo
@@ -109,10 +107,10 @@ private:
    const GalleryTheme* mpTheme;
    sal_uInt32 const    mnObjectPos;
    bool const          mbPreview;
    VclBuilder          maBuilder;
    VclPtr<PopupMenu> mpPopupMenu;
    VclPtr<PopupMenu> mpBackgroundPopup;
    VclPtr<GalleryBrowser2> mpBrowser;
    std::unique_ptr<weld::Builder> mxBuilder;
    std::unique_ptr<weld::Menu> mxPopupMenu;
    std::unique_ptr<weld::Menu> mxBackgroundPopup;
    GalleryBrowser2*  mpBrowser;

    typedef std::map< int, CommandInfo > CommandInfoMap;
    CommandInfoMap   m_aCommandInfo;
@@ -120,15 +118,16 @@ private:
    static void Execute( const CommandInfo &rCmdInfo,
                  const css::uno::Sequence< css::beans::PropertyValue > &rArguments );

    DECL_LINK( MenuSelectHdl, Menu*, bool );
    DECL_LINK( BackgroundMenuSelectHdl, Menu*, bool );
    void MenuSelectHdl(const OString& rIdent);
    void BackgroundMenuSelectHdl(sal_uInt16 nId);
public:
    GalleryThemePopup( const GalleryTheme* pTheme,
                       sal_uInt32 nObjectPos,
                       bool bPreview,
                       GalleryBrowser2* pBrowser );
    GalleryThemePopup(weld::Widget* pParent,
                      const GalleryTheme* pTheme,
                      sal_uInt32 nObjectPos,
                      bool bPreview,
                      GalleryBrowser2* pBrowser);

    void ExecutePopup( vcl::Window *pParent, const ::Point &aPos );
    void ExecutePopup(weld::Widget* pParent, const ::Point &rPos);

    virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent &rEvent) override;
    virtual void SAL_CALL disposing( const css::lang::EventObject &rSource) override;
@@ -136,6 +135,7 @@ public:


GalleryThemePopup::GalleryThemePopup(
    weld::Widget* pParent,
    const GalleryTheme* pTheme,
    sal_uInt32 nObjectPos,
    bool bPreview,
@@ -143,13 +143,11 @@ GalleryThemePopup::GalleryThemePopup(
    : mpTheme( pTheme )
    , mnObjectPos( nObjectPos )
    , mbPreview( bPreview )
    , maBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/gallerymenu2.ui", "")
    , mpPopupMenu(maBuilder.get_menu("menu"))
    , mpBackgroundPopup( VclPtr<PopupMenu>::Create() )
    , mxBuilder(Application::CreateBuilder(pParent, "svx/ui/gallerymenu2.ui"))
    , mxPopupMenu(mxBuilder->weld_menu("menu"))
    , mxBackgroundPopup(mxBuilder->weld_menu("backgroundmenu"))
    , mpBrowser( pBrowser )
{
    mpPopupMenu->SetPopupMenu(mpPopupMenu->GetItemId("background"), mpBackgroundPopup);

    // SID_GALLERY_ENABLE_ADDCOPY
    m_aCommandInfo.emplace(
            SID_GALLERY_ENABLE_ADDCOPY,
@@ -173,26 +171,26 @@ void SAL_CALL GalleryThemePopup::statusChanged(
    {
        if ( !rEvent.IsEnabled )
        {
            mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("add"), false);
            mxPopupMenu->set_visible("add", false);
        }
    }
    else if ( rURL == ".uno:BackgroundImage" )
    {
        mpBackgroundPopup->Clear();
        mxBackgroundPopup->clear();
        if ( rEvent.IsEnabled )
        {
            OUString sItem;
            css::uno::Sequence< OUString > sItems;
            if ( ( rEvent.State >>= sItem ) && sItem.getLength() )
            {
                mpBackgroundPopup->InsertItem( 1, sItem );
                mxBackgroundPopup->append(OUString::number(1), sItem);
            }
            else if ( ( rEvent.State >>= sItems ) && sItems.hasElements() )
            {
                sal_uInt16 nId = 1;
                for ( const OUString& rStr : std::as_const(sItems) )
                {
                    mpBackgroundPopup->InsertItem( nId, rStr );
                    mxBackgroundPopup->append(OUString::number(nId), rStr);
                    nId++;
                }
            }
@@ -222,7 +220,7 @@ void GalleryThemePopup::Execute(
    }
}

void GalleryThemePopup::ExecutePopup( vcl::Window *pWindow, const ::Point &aPos )
void GalleryThemePopup::ExecutePopup(weld::Widget* pParent, const ::Point &rPos)
{
    css::uno::Reference< css::frame::XStatusListener > xThis( this );

@@ -232,27 +230,27 @@ void GalleryThemePopup::ExecutePopup( vcl::Window *pWindow, const ::Point &aPos 
    const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL );
    const bool bValidURL = ( aURL.GetProtocol() != INetProtocol::NotValid );

    mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("add"), bValidURL && SgaObjKind::Sound != eObjKind);
    mxPopupMenu->set_visible("add", bValidURL && SgaObjKind::Sound != eObjKind);

    mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("preview"), bValidURL);
    mpPopupMenu->CheckItem("preview", mbPreview);
    mxPopupMenu->set_visible("preview", bValidURL);
    mxPopupMenu->set_active("preview", mbPreview);

    if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() )
    {
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("delete"), false);
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("title"), false);
        mxPopupMenu->set_visible("delete", false);
        mxPopupMenu->set_visible("title", false);
        if (mpTheme->IsReadOnly())
            mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("paste"), false);
            mxPopupMenu->set_visible("paste", false);

        if (!mpTheme->GetObjectCount())
            mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("copy"), false);
            mxPopupMenu->set_visible("copy", false);
    }
    else
    {
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("delete"), !mbPreview);
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("title"));
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("copy"));
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("paste"));
        mxPopupMenu->set_visible("delete", !mbPreview);
        mxPopupMenu->set_visible("title", true);
        mxPopupMenu->set_visible("copy", true);
        mxPopupMenu->set_visible("paste", true);
    }

    // update status
@@ -286,44 +284,38 @@ void GalleryThemePopup::ExecutePopup( vcl::Window *pWindow, const ::Point &aPos 
        {}
    }

    if( !mpBackgroundPopup->GetItemCount() || ( eObjKind == SgaObjKind::SvDraw ) || ( eObjKind == SgaObjKind::Sound ) )
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("background"), false);
    if( !mxBackgroundPopup->n_children() || ( eObjKind == SgaObjKind::SvDraw ) || ( eObjKind == SgaObjKind::Sound ) )
        mxPopupMenu->set_visible("background", false);
    else
    {
        mpPopupMenu->EnableItem(mpPopupMenu->GetItemId("background"));
        mpBackgroundPopup->SetSelectHdl( LINK( this, GalleryThemePopup, BackgroundMenuSelectHdl ) );
    }
        mxPopupMenu->set_visible("background", true);

    mpPopupMenu->RemoveDisabledEntries();

    mpPopupMenu->SetSelectHdl( LINK( this, GalleryThemePopup, MenuSelectHdl ) );
    mpPopupMenu->Execute( pWindow, aPos );
    MenuSelectHdl(mxPopupMenu->popup_at_rect(pParent, tools::Rectangle(rPos, Size(1,1))));
}

IMPL_LINK( GalleryThemePopup, MenuSelectHdl, Menu*, pMenu, bool )
void GalleryThemePopup::MenuSelectHdl(const OString& rIdent)
{
    if( !pMenu )
        return false;
    if (rIdent.isEmpty())
        return;

    OString sIdent(pMenu->GetCurItemIdent());
    if (sIdent == "add")
    sal_uInt16 nSubMenuId = rIdent.toUInt32();
    if (nSubMenuId)
    {
        BackgroundMenuSelectHdl(nSubMenuId-1);
        return;
    }

    if (rIdent == "add")
    {
        const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_FORMATS );
        if (it != m_aCommandInfo.end())
            mpBrowser->DispatchAdd(it->second.Dispatch, it->second.URL);
    }
    else
        mpBrowser->Execute(sIdent);

    return false;
        mpBrowser->Execute(rIdent);
}

IMPL_LINK( GalleryThemePopup, BackgroundMenuSelectHdl, Menu*, pMenu, bool )
void GalleryThemePopup::BackgroundMenuSelectHdl(sal_uInt16 nPos)
{
    if( !pMenu )
        return false;

    sal_uInt16 nPos( pMenu->GetCurItemId() - 1 );
    OUString aURL( mpBrowser->GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
    OUString aFilterName( mpBrowser->GetFilterName() );

@@ -344,163 +336,80 @@ IMPL_LINK( GalleryThemePopup, BackgroundMenuSelectHdl, Menu*, pMenu, bool )
    const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_BG_BRUSH );
    if ( it != m_aCommandInfo.end() )
        Execute( it->second, aArgs );

    return false;
}

} // end anonymous namespace


GalleryToolBox::GalleryToolBox( GalleryBrowser2* pParent ) :
    ToolBox( pParent, WB_TABSTOP )
GalleryBrowser2::GalleryBrowser2(weld::Builder& rBuilder, Gallery* pGallery)
    : mpGallery(pGallery)
    , mpCurTheme(nullptr)
    , mxIconView(new GalleryIconView(this, rBuilder.weld_scrolled_window("galleryscroll")))
    , mxIconViewWin(new weld::CustomWeld(rBuilder, "gallery", *mxIconView))
    , mxListView(rBuilder.weld_tree_view("gallerylist"))
    , mxPreview(new GalleryPreview(this, rBuilder.weld_scrolled_window("previewscroll")))
    , mxPreviewWin(new weld::CustomWeld(rBuilder, "preview", *mxPreview))
    , mxIconButton(rBuilder.weld_toggle_button("icon"))
    , mxListButton(rBuilder.weld_toggle_button("list"))
    , mxInfoBar(rBuilder.weld_label("label"))
    , mnCurActionPos      ( 0xffffffff )
    , meMode              ( GALLERYBROWSERMODE_NONE )
    , meLastMode          ( GALLERYBROWSERMODE_NONE )
{
}

void GalleryToolBox::KeyInput( const KeyEvent& rKEvt )
{
    if( !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
    {
        if( KEY_ESCAPE != rKEvt.GetKeyCode().GetCode() )
            ToolBox::KeyInput(rKEvt);
    }
}


GalleryBrowser2::GalleryBrowser2( vcl::Window* pParent, Gallery* pGallery ) :
    Control             ( pParent, WB_TABSTOP ),
    mpGallery           ( pGallery ),
    mpCurTheme          ( nullptr ),
    mpIconView          ( VclPtr<GalleryIconView>::Create( this, nullptr ) ),
    mpListView          ( VclPtr<GalleryListView>::Create( this, nullptr ) ),
    mpPreview           ( VclPtr<GalleryPreview>::Create(this) ),
    maViewBox           ( VclPtr<GalleryToolBox>::Create(this) ),
    maSeparator         ( VclPtr<FixedLine>::Create(this, WB_VERT) ),
    maInfoBar           ( VclPtr<FixedText>::Create(this, WB_LEFT | WB_VCENTER) ),
    mnCurActionPos      ( 0xffffffff ),
    meMode              ( GALLERYBROWSERMODE_NONE ),
    meLastMode          ( GALLERYBROWSERMODE_NONE )
{

    m_xContext.set( ::comphelper::getProcessComponentContext() );

    int nHeight = mxListView->get_height_rows(10);
    mxListView->set_size_request(-1, nHeight);
    mxIconView->set_size_request(-1, nHeight);

    m_xTransformer.set(
        m_xContext->getServiceManager()->createInstanceWithContext(
            "com.sun.star.util.URLTransformer", m_xContext ),
        css::uno::UNO_QUERY );

    Image      aDummyImage;
    mxIconButton->set_help_id(HID_GALLERY_ICONVIEW);
    mxListButton->set_help_id(HID_GALLERY_LISTVIEW);

    maMiscOptions.AddListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );
    mxIconButton->connect_toggled( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
    mxListButton->connect_toggled( LINK( this, GalleryBrowser2, SelectTbxHdl ) );

    maViewBox->InsertItem( TBX_ID_ICON, aDummyImage );
    maViewBox->SetItemBits( TBX_ID_ICON, ToolBoxItemBits::RADIOCHECK | ToolBoxItemBits::AUTOCHECK );
    maViewBox->SetHelpId( TBX_ID_ICON, HID_GALLERY_ICONVIEW );
    maViewBox->SetQuickHelpText( TBX_ID_ICON, SvxResId(RID_SVXSTR_GALLERY_ICONVIEW) );
    mxIconView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectValueSetHdl ) );
    mxListView->connect_visible_range_changed(LINK(this, GalleryBrowser2, VisRowsScrolledHdl));
    mxListView->connect_size_allocate(LINK(this, GalleryBrowser2, SizeAllocHdl));
    mxListView->connect_changed( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
    mxListView->connect_popup_menu(LINK(this, GalleryBrowser2, PopupMenuHdl));
    mxListView->connect_key_press(LINK(this, GalleryBrowser2, KeyInputHdl));
    mxListView->connect_row_activated(LINK(this, GalleryBrowser2, RowActivatedHdl));
    mxDragDropTargetHelper.reset(new GalleryDragDrop(this, mxListView->get_drop_target()));
    mxListView->connect_drag_begin(LINK(this, GalleryBrowser2, DragBeginHdl));

    maViewBox->InsertItem( TBX_ID_LIST, aDummyImage );
    maViewBox->SetItemBits( TBX_ID_LIST, ToolBoxItemBits::RADIOCHECK | ToolBoxItemBits::AUTOCHECK );
    maViewBox->SetHelpId( TBX_ID_LIST, HID_GALLERY_LISTVIEW );
    maViewBox->SetQuickHelpText( TBX_ID_LIST, SvxResId(RID_SVXSTR_GALLERY_LISTVIEW) );

    MiscHdl( nullptr );
    maViewBox->SetSelectHdl( LINK( this, GalleryBrowser2, SelectTbxHdl ) );
    maViewBox->Show();

    mpIconView->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERY_THEMEITEMS));
    mpListView->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERY_THEMEITEMS));

    maInfoBar->Show();
    maSeparator->Show();

    mpIconView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectValueSetHdl ) );
    mpListView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );

    InitSettings();
    mxListView->set_help_id(HID_GALLERY_WINDOW);

    SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON );
}

    if(maInfoBar->GetText().isEmpty())
        mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
    else
        mpIconView->SetAccessibleRelationLabeledBy(maInfoBar.get());
IMPL_LINK(GalleryBrowser2, PopupMenuHdl, const CommandEvent&, rCEvt, bool)
{
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return false;
    ShowContextMenu(rCEvt);
    return true;
}

IMPL_LINK(GalleryBrowser2, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
    return KeyInput(rKEvt);
}

IMPL_LINK_NOARG(GalleryBrowser2, RowActivatedHdl, weld::TreeView&, bool)
{
    TogglePreview();
    return true;
}

GalleryBrowser2::~GalleryBrowser2()
{
    disposeOnce();
}

void GalleryBrowser2::dispose()
{
    maMiscOptions.RemoveListenerLink( LINK( this, GalleryBrowser2, MiscHdl ) );

    mpPreview.disposeAndClear();
    mpListView.disposeAndClear();
    mpIconView.disposeAndClear();

    if( mpCurTheme )
    if (mpCurTheme)
        mpGallery->ReleaseTheme( mpCurTheme, *this );
    maSeparator.disposeAndClear();
    maInfoBar.disposeAndClear();
    maViewBox.disposeAndClear();
    Control::dispose();
}

void GalleryBrowser2::InitSettings()
{
    vcl::Font  aInfoFont( maInfoBar->GetControlFont() );

    aInfoFont.SetWeight( WEIGHT_BOLD );
    aInfoFont.SetColor( GALLERY_FG_COLOR );
    maInfoBar->SetControlFont( aInfoFont );

    maInfoBar->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
    maInfoBar->SetControlBackground( GALLERY_DLG_COLOR );

    maSeparator->SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
    maSeparator->SetControlBackground( GALLERY_BG_COLOR );
    maSeparator->SetControlForeground( GALLERY_FG_COLOR );
}

void GalleryBrowser2::DataChanged( const DataChangedEvent& rDCEvt )
{
    if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
        InitSettings();
    else
        Control::DataChanged( rDCEvt );
}

void GalleryBrowser2::Resize()
{
    Control::Resize();

    mpIconView->Hide();
    mpListView->Hide();
    mpPreview->Hide();

    const Size  aOutSize( GetOutputSizePixel() );
    const Size  aBoxSize( maViewBox->GetOutputSizePixel() );
    const long  nOffset = 2, nSepWidth = 2;
    const long  nInfoBarX = aBoxSize.Width() + ( nOffset * 3 ) + nSepWidth;
    const Point aPt( 0, aBoxSize.Height() + 3 );
    const Size  aSz( aOutSize.Width(), aOutSize.Height() - aPt.Y() );

    maSeparator->SetPosSizePixel( Point( aBoxSize.Width() + nOffset, 0 ), Size( nSepWidth, aBoxSize.Height() ) );
    maInfoBar->SetPosSizePixel( Point( nInfoBarX, 0 ), Size( aOutSize.Width() - nInfoBarX, aBoxSize.Height() ) );

    mpIconView->SetPosSizePixel( aPt, aSz );
    mpListView->SetPosSizePixel( aPt, aSz );
    mpPreview->SetPosSizePixel( aPt, aSz );

    switch( GetMode() )
    {
        case GALLERYBROWSERMODE_ICON: mpIconView->Show(); break;
        case GALLERYBROWSERMODE_LIST: mpListView->Show(); break;
        case GALLERYBROWSERMODE_PREVIEW: mpPreview->Show(); break;

        default:
        break;
    }
}

void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint )
@@ -554,7 +463,7 @@ sal_Int8 GalleryBrowser2::ExecuteDrop( const ExecuteDropEvent& rEvt )

    if( mpCurTheme )
    {
        Point       aSelPos;
        Point aSelPos;
        const sal_uInt32 nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos );
        const sal_uInt32 nInsertPos = (nItemId ? (nItemId - 1) : mpCurTheme->GetObjectCount());

@@ -567,28 +476,29 @@ sal_Int8 GalleryBrowser2::ExecuteDrop( const ExecuteDropEvent& rEvt )
    return nRet;
}

void GalleryBrowser2::StartDrag( const Point* pDragPoint )
bool GalleryBrowser2::StartDrag()
{
    if( mpCurTheme )
    {
        Point       aSelPos;
        const sal_uInt32 nItemId = ImplGetSelectedItemId( pDragPoint, aSelPos );
    if (!mpCurTheme)
        return true;
    return m_xHelper->StartDrag();
}

        if( nItemId )
            mpCurTheme->StartDrag( this, nItemId - 1 );
    }
IMPL_LINK_NOARG(GalleryBrowser2, DragBeginHdl, weld::TreeView&, bool)
{
    return StartDrag();
}

void GalleryBrowser2::TogglePreview()
{
    SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode );
    GetViewWindow()->GrabFocus();
    GetViewWindow()->grab_focus();
}

void GalleryBrowser2::ShowContextMenu( const Point* pContextPoint )
void GalleryBrowser2::ShowContextMenu(const CommandEvent& rCEvt)
{
    Point aMousePos = rCEvt.GetMousePosPixel();
    Point aSelPos;
    const sal_uInt32 nItemId = ImplGetSelectedItemId( pContextPoint, aSelPos );
    const sal_uInt32 nItemId = ImplGetSelectedItemId( rCEvt.IsMouseEvent() ? &aMousePos : nullptr, aSelPos );

    if( mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() ) )
    {
@@ -597,28 +507,32 @@ void GalleryBrowser2::ShowContextMenu( const Point* pContextPoint )
        css::uno::Reference< css::frame::XFrame > xFrame( GetFrame() );
        if ( xFrame.is() )
        {
            weld::Widget* pParent = GetViewWindow();
            mnCurActionPos = nItemId - 1;
            rtl::Reference< GalleryThemePopup > rPopup(
            rtl::Reference< GalleryThemePopup > xPopup(
                new GalleryThemePopup(
                    pParent,
                    mpCurTheme,
                    mnCurActionPos,
                    GALLERYBROWSERMODE_PREVIEW == GetMode(),
                    this ) );
            rPopup->ExecutePopup( this, aSelPos  );
            xPopup->ExecutePopup(pParent, aSelPos);
        }
    }
}

bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, vcl::Window* /*pWindow*/ )
bool GalleryBrowser2::ViewBoxHasFocus() const
{
    return mxIconButton->has_focus() || mxListButton->has_focus();
}

bool GalleryBrowser2::KeyInput(const KeyEvent& rKEvt)
{
    Point       aSelPos;
    const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos );
    bool bRet = false;
    svx::sidebar::GalleryControl* pParentControl = dynamic_cast<svx::sidebar::GalleryControl*>(GetParent());
    if (pParentControl != nullptr)
        bRet = pParentControl->GalleryKeyInput(rKEvt);

    if( !bRet && !maViewBox->HasFocus() && nItemId && mpCurTheme )
    if (!ViewBoxHasFocus() && nItemId && mpCurTheme)
    {
        OString sExecuteIdent;
        INetURLObject       aURL;
@@ -693,40 +607,30 @@ bool GalleryBrowser2::KeyInput( const KeyEvent& rKEvt, vcl::Window* /*pWindow*/ 

void GalleryBrowser2::SelectTheme( const OUString& rThemeName )
{
    mpIconView.disposeAndClear();
    mpListView.disposeAndClear();
    mpPreview.disposeAndClear();

    if( mpCurTheme )
        mpGallery->ReleaseTheme( mpCurTheme, *this );

    mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this );

    mpIconView = VclPtr<GalleryIconView>::Create( this, mpCurTheme );
    mpListView = VclPtr<GalleryListView>::Create( this, mpCurTheme );
    mpPreview = VclPtr<GalleryPreview>::Create( this, WB_TABSTOP | WB_BORDER, mpCurTheme );
    m_xHelper.set(new GalleryTransferable(mpCurTheme, 0, true));
    rtl::Reference<TransferDataContainer> xHelper(m_xHelper.get());
    mxListView->enable_drag_source(xHelper, DND_ACTION_COPY | DND_ACTION_LINK);
    mxIconView->SetDragDataTransferrable(xHelper, DND_ACTION_COPY | DND_ACTION_LINK);
    mxPreview->SetDragDataTransferrable(xHelper, DND_ACTION_COPY | DND_ACTION_LINK);

    mpIconView->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERY_THEMEITEMS));
    mpListView->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERY_THEMEITEMS));
    mpPreview->SetAccessibleName(SvxResId(RID_SVXSTR_GALLERY_PREVIEW));

    mpIconView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectValueSetHdl ) );
    mpListView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectHdl ) );
    mxIconView->SetTheme(mpCurTheme);
    mxPreview->SetTheme(mpCurTheme);

    if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
        meMode = meLastMode;

    Resize();
    ImplUpdateViews( 1 );

    maViewBox->EnableItem( TBX_ID_ICON );
    maViewBox->EnableItem( TBX_ID_LIST );
    maViewBox->CheckItem( ( GALLERYBROWSERMODE_ICON == GetMode() ) ? TBX_ID_ICON : TBX_ID_LIST );

    if(maInfoBar->GetText().isEmpty())
        mpIconView->SetAccessibleRelationLabeledBy(mpIconView);
    else
        mpIconView->SetAccessibleRelationLabeledBy(maInfoBar.get());
    bool bIconMode = (GALLERYBROWSERMODE_ICON == GetMode());
    mxIconButton->set_sensitive(true);
    mxListButton->set_sensitive(true);
    mxIconButton->set_active(bIconMode);
    mxListButton->set_active(!bIconMode);
}

void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
@@ -739,37 +643,38 @@ void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
        {
            case GALLERYBROWSERMODE_ICON:
            {
                mpListView->Hide();
                mxListView->hide();

                mpPreview->Hide();
                mpPreview->SetGraphic( Graphic() );
                mxPreview->Hide();
                mxPreview->SetGraphic( Graphic() );
                GalleryPreview::PreviewMedia( INetURLObject() );

                mpIconView->Show();
                mxIconView->Show();

                maViewBox->EnableItem( TBX_ID_ICON );
                maViewBox->EnableItem( TBX_ID_LIST );
                mxIconButton->set_sensitive(true);
                mxListButton->set_sensitive(true);

                maViewBox->CheckItem( TBX_ID_ICON );
                maViewBox->CheckItem( TBX_ID_LIST, false );
                mxIconButton->set_active(true);
                mxListButton->set_active(false);
            }
            break;

            case GALLERYBROWSERMODE_LIST:
            {
                mpIconView->Hide();
                mxIconView->Hide();

                mpPreview->Hide();
                mpPreview->SetGraphic( Graphic() );
                mxPreview->Hide();
                mxPreview->SetGraphic( Graphic() );
                GalleryPreview::PreviewMedia( INetURLObject() );

                mpListView->Show();
                mxListView->show();
                UpdateVisibleRows();

                maViewBox->EnableItem( TBX_ID_ICON );
                maViewBox->EnableItem( TBX_ID_LIST );
                mxIconButton->set_sensitive(true);
                mxListButton->set_sensitive(true);

                maViewBox->CheckItem( TBX_ID_ICON, false );
                maViewBox->CheckItem( TBX_ID_LIST );
                mxIconButton->set_active(false);
                mxListButton->set_active(true);
            }
            break;

@@ -783,20 +688,20 @@ void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
                {
                    const sal_uInt32 nPos = nItemId - 1;

                    mpIconView->Hide();
                    mpListView->Hide();
                    mxIconView->Hide();
                    mxListView->hide();

                    if( mpCurTheme )
                        mpCurTheme->GetGraphic( nPos, aGraphic );

                    mpPreview->SetGraphic( aGraphic );
                    mpPreview->Show();
                    mxPreview->SetGraphic( aGraphic );
                    mxPreview->Show();

                    if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SgaObjKind::Sound )
                        GalleryPreview::PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );

                    maViewBox->EnableItem( TBX_ID_ICON, false );
                    maViewBox->EnableItem( TBX_ID_LIST, false );
                    mxIconButton->set_sensitive(false);
                    mxListButton->set_sensitive(false);
                }
            }
            break;
@@ -809,17 +714,17 @@ void GalleryBrowser2::SetMode( GalleryBrowserMode eMode )
    }
}

vcl::Window* GalleryBrowser2::GetViewWindow() const
weld::Widget* GalleryBrowser2::GetViewWindow() const
{
    vcl::Window* pRet;
    weld::Widget* pRet;

    switch( GetMode() )
    {
        case GALLERYBROWSERMODE_LIST: pRet = mpListView; break;
        case GALLERYBROWSERMODE_PREVIEW: pRet = mpPreview; break;
        case GALLERYBROWSERMODE_LIST: pRet = mxListView.get(); break;
        case GALLERYBROWSERMODE_PREVIEW: pRet = mxPreview->GetDrawingArea(); break;

        default:
            pRet = mpIconView;
            pRet = mxIconView->GetDrawingArea();
        break;
    }

@@ -863,12 +768,12 @@ void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )
                    const sal_uInt32 nPos = nNewItemId - 1;

                    mpCurTheme->GetGraphic( nPos, aGraphic );
                    mpPreview->SetGraphic( aGraphic );
                    mxPreview->SetGraphic( aGraphic );

                    if( SgaObjKind::Sound == mpCurTheme->GetObjectKind( nPos ) )
                        GalleryPreview::PreviewMedia( mpCurTheme->GetObjectURL( nPos ) );

                    mpPreview->Invalidate();
                    mxPreview->Invalidate();
                }
            }
        }
@@ -877,19 +782,20 @@ void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel )

void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )
{
    mpIconView->Hide();
    mpListView->Hide();
    mpPreview->Hide();
    mxIconView->Hide();
    mxListView->hide();
    mxPreview->Hide();

    mpIconView->Clear();
    mpListView->Clear();
    mxIconView->Clear();
    mxListView->clear();

    if( mpCurTheme )
    {
        for (sal_uInt32 i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount;)
        OUString sCreateOnDemand;
        for (sal_uInt32 i = 0, nCount = mpCurTheme->GetObjectCount(); i < nCount; ++i)
        {
            mpListView->RowInserted( i++ );
            mpIconView->InsertItem( static_cast<sal_uInt16>(i) );
            mxIconView->InsertItem(i + 1); // skip reserved id 0
            mxListView->append(OUString::number(i), sCreateOnDemand); // create on-demand in VisRowsScrolledHdl
        }

        ImplSelectItemId( std::min<sal_uInt16>( nSelectionId, mpCurTheme->GetObjectCount() ) );
@@ -897,9 +803,12 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )

    switch( GetMode() )
    {
        case GALLERYBROWSERMODE_ICON: mpIconView->Show(); break;
        case GALLERYBROWSERMODE_LIST: mpListView->Show(); break;
        case GALLERYBROWSERMODE_PREVIEW: mpPreview->Show(); break;
        case GALLERYBROWSERMODE_ICON: mxIconView->Show(); break;
        case GALLERYBROWSERMODE_LIST:
            mxListView->show();
            UpdateVisibleRows();
            break;
        case GALLERYBROWSERMODE_PREVIEW: mxPreview->Show(); break;

        default:
        break;
@@ -908,56 +817,146 @@ void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId )
    ImplUpdateInfoBar();
}

void GalleryBrowser2::UpdateVisibleRows()
{
    auto lambda = [this](weld::TreeIter& rEntry){
        // id is non-null if the preview is pending creation
        OUString sId(mxListView->get_id(rEntry));
        if (sId.isEmpty())
            return false;

        // get the icon for the listview
        VclPtr<VirtualDevice> xDev = mxListView->create_virtual_device();
        const Size aSize(28, 28);
        xDev->SetOutputSizePixel(aSize);
        BitmapEx aBitmapEx;
        Size aPreparedSize;

        OUString sItemTextTitle;
        OUString sItemTextPath;

        sal_Int32 i = sId.toUInt32();
        mpCurTheme->GetPreviewBitmapExAndStrings(i, aBitmapEx, aPreparedSize, sItemTextTitle, sItemTextPath);

        bool bNeedToCreate(aBitmapEx.IsEmpty());
        if (!bNeedToCreate && (sItemTextTitle.isEmpty() || aPreparedSize != aSize))
            bNeedToCreate = true;

        if (bNeedToCreate)
        {
            std::unique_ptr<SgaObject> xObj = mpCurTheme->AcquireObject(i);
            if (xObj)
            {
                aBitmapEx = xObj->createPreviewBitmapEx(aSize);
                sItemTextTitle = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Title);
                sItemTextPath = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Path);

                mpCurTheme->SetPreviewBitmapExAndStrings(i, aBitmapEx, aSize, sItemTextTitle, sItemTextPath);
            }
        }

        if (!aBitmapEx.IsEmpty())
        {
            const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
            const Point aPos(
                ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1),
                ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1));

            if (aBitmapEx.IsTransparent())
            {
                // draw checkered background
                GalleryIconView::drawTransparenceBackground(*xDev, aPos, aBitmapExSizePixel);
            }

            xDev->DrawBitmapEx(aPos, aBitmapEx);
        }

        mxListView->set_text(rEntry, sItemTextTitle);
        mxListView->set_image(rEntry, *xDev);
        mxListView->set_id(rEntry, OUString());

        return false;
    };

    // ensure all visible entries are up to date
    mxListView->visible_foreach(lambda);
    // and ensure all selected entries are up to date
    mxListView->selected_foreach(lambda);
}

IMPL_LINK_NOARG(GalleryBrowser2, VisRowsScrolledHdl, weld::TreeView&, void)
{
    UpdateVisibleRows();
}

IMPL_LINK_NOARG(GalleryBrowser2, SizeAllocHdl, const Size&, void)
{
    UpdateVisibleRows();
}

void GalleryBrowser2::ImplUpdateInfoBar()
{
    if( mpCurTheme )
         maInfoBar->SetText( mpCurTheme->GetName() );
    if (!mpCurTheme)
        return;
    mxInfoBar->set_label( mpCurTheme->GetName() );
}

void GalleryBrowser2::ImplUpdateSelection()
{
    if (!mpCurTheme)
        return;
    auto nSelectedObject = (GALLERYBROWSERMODE_ICON == GetMode()) ? (mxIconView->GetSelectedItemId() - 1) : mxListView->get_selected_index();
    m_xHelper->SelectObject(nSelectedObject);
}

sal_uInt32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos )
{
    const Size  aOutputSizePixel( GetOutputSizePixel() );
    sal_uInt32 nRet = 0;

    if( GALLERYBROWSERMODE_PREVIEW == GetMode() )
    {
        nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mpIconView->GetSelectedItemId() : ( mpListView->FirstSelectedRow() + 1 ) );
        nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mxIconView->GetSelectedItemId() : ( mxListView->get_selected_index() + 1 ) );

        if( pSelPos )
            rSelPos = GetPointerPosPixel();
            rSelPos = *pSelPos;
        else
            rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
    }
    else if( GALLERYBROWSERMODE_ICON == GetMode() )
    {
        if( pSelPos )
        {
            nRet = mpIconView->GetItemId( *pSelPos );
            rSelPos = GetPointerPosPixel();
            Size aOutputSizePixel(mxPreview->GetOutputSizePixel());
            rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 );
        }
    }
    else if (GALLERYBROWSERMODE_ICON == GetMode())
    {
        if (pSelPos)
        {
            nRet = mxIconView->GetItemId( *pSelPos );
            rSelPos = *pSelPos;
        }
        else
        {
            nRet = mpIconView->GetSelectedItemId();
            rSelPos = mpIconView->GetItemRect(nRet).Center();
            nRet = mxIconView->GetSelectedItemId();
            rSelPos = mxIconView->GetItemRect(nRet).Center();
        }
    }
    else
    {
        std::unique_ptr<weld::TreeIter> xIter = mxListView->make_iterator();
        if( pSelPos )
        {
            nRet = mpListView->GetRowAtYPosPixel( pSelPos->Y() ) + 1;
            rSelPos = GetPointerPosPixel();
            if (mxListView->get_dest_row_at_pos(*pSelPos, xIter.get()))
                nRet = mxListView->get_iter_index_in_parent(*xIter) + 1;
            rSelPos = *pSelPos;
        }
        else
        {
            nRet = mpListView->FirstSelectedRow() + 1;
            rSelPos = mpListView->GetFieldRectPixel( static_cast<sal_uInt16>(nRet), 1 ).Center();
            if (mxListView->get_selected(xIter.get()))
            {
                nRet = mxListView->get_iter_index_in_parent(*xIter) + 1;
                rSelPos = mxListView->get_row_area(*xIter).Center();
            }
        }
    }

    rSelPos.setX( std::max( std::min( rSelPos.X(), aOutputSizePixel.Width() - 1 ), 0L ) );
    rSelPos.setY( std::max( std::min( rSelPos.Y(), aOutputSizePixel.Height() - 1 ), 0L ) );

    if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) )
    {
        nRet = 0;
@@ -970,9 +969,9 @@ void GalleryBrowser2::ImplSelectItemId(sal_uInt32 nItemId)
{
    if( nItemId )
    {

        mpIconView->SelectItem(nItemId);
        mpListView->SelectRow( nItemId - 1 );
        mxIconView->SelectItem(nItemId);
        mxListView->select( nItemId - 1 );
        ImplUpdateSelection();
    }
}

@@ -1097,7 +1096,7 @@ void GalleryBrowser2::Execute(const OString &rIdent)
        {
            if (!mpCurTheme->IsReadOnly())
            {
                std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "svx/ui/querydeleteobjectdialog.ui"));
                std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetViewWindow(), "svx/ui/querydeleteobjectdialog.ui"));
                std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteObjectDialog"));
                if (xQuery->run() == RET_YES)
                {
@@ -1114,7 +1113,7 @@ void GalleryBrowser2::Execute(const OString &rIdent)
                const OUString  aOldTitle( GetItemText( *pObj, GalleryItemFlags::Title ) );

                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
                ScopedVclPtr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog(GetFrameWeld(), aOldTitle));
                ScopedVclPtr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog(GetViewWindow(), aOldTitle));
                if( aDlg->Execute() == RET_OK )
                {
                    OUString aNewTitle( aDlg->GetTitle() );
@@ -1132,26 +1131,13 @@ void GalleryBrowser2::Execute(const OString &rIdent)
        }
        else if (rIdent == "copy")
        {
            vcl::Window* pWindow;

            switch( GetMode() )
            {
                case GALLERYBROWSERMODE_ICON: pWindow = mpIconView; break;
                case GALLERYBROWSERMODE_LIST: pWindow = mpListView; break;
                case GALLERYBROWSERMODE_PREVIEW: pWindow = mpPreview; break;

                default:
                    pWindow = nullptr;
                break;
            }

            mpCurTheme->CopyToClipboard( pWindow, mnCurActionPos );
            mpCurTheme->CopyToClipboard(mnCurActionPos);
        }
        else if (rIdent == "paste")
        {
            if( !mpCurTheme->IsReadOnly() )
            {
                TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( this ) );
                TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromClipboard(GetSystemClipboard()));
                mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos );
             }
        }
@@ -1229,45 +1215,22 @@ OUString GalleryBrowser2::GetFilterName() const
    return aFilterName;
}


IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectValueSetHdl, ValueSet*, void)
IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectValueSetHdl, SvtValueSet*, void)
{
    ImplUpdateInfoBar();
    ImplUpdateSelection();
}

IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectHdl, GalleryListView*, void)
IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectHdl, weld::TreeView&, void)
{
    ImplUpdateInfoBar();
    ImplUpdateSelection();
}

IMPL_LINK( GalleryBrowser2, SelectTbxHdl, ToolBox*, pBox, void )
IMPL_LINK(GalleryBrowser2, SelectTbxHdl, weld::ToggleButton&, rBox, void)
{
    if( pBox->GetCurItemId() == TBX_ID_ICON )
        SetMode( GALLERYBROWSERMODE_ICON );
    else if( pBox->GetCurItemId() == TBX_ID_LIST )
        SetMode( GALLERYBROWSERMODE_LIST );
}

IMPL_LINK_NOARG(GalleryBrowser2, MiscHdl, LinkParamNone*, void)
{
    maViewBox->SetOutStyle( maMiscOptions.GetToolboxStyle() );

    BitmapEx aIconBmpEx(RID_SVXBMP_GALLERY_VIEW_ICON);
    BitmapEx aListBmpEx(RID_SVXBMP_GALLERY_VIEW_LIST);

    if( maMiscOptions.AreCurrentSymbolsLarge() )
    {
        const Size aLargeSize( 24, 24);

        aIconBmpEx.Scale( aLargeSize );
        aListBmpEx.Scale( aLargeSize );
    }

    maViewBox->SetItemImage(TBX_ID_ICON, Image(aIconBmpEx));
    maViewBox->SetItemImage(TBX_ID_LIST, Image(aListBmpEx));
    maViewBox->SetSizePixel( maViewBox->CalcWindowSizePixel() );

    Resize();
    if (&rBox == mxIconButton.get())
        SetMode(rBox.get_active() ? GALLERYBROWSERMODE_ICON : GALLERYBROWSERMODE_LIST);
    else if (&rBox == mxListButton.get())
        SetMode(rBox.get_active() ? GALLERYBROWSERMODE_LIST : GALLERYBROWSERMODE_ICON);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx
index c3489a1..cc9e6fa 100644
--- a/svx/source/gallery2/galctrl.cxx
+++ b/svx/source/gallery2/galctrl.cxx
@@ -41,74 +41,86 @@
#include <vcl/settings.hxx>
#include <bitmaps.hlst>

#define GALLERY_BRWBOX_TITLE    1

GalleryPreview::GalleryPreview(vcl::Window* pParent, WinBits nStyle, GalleryTheme* pTheme)
    : Window(pParent, nStyle)
    , DropTargetHelper(this)
    , DragSourceHelper(this)
    , mpTheme(pTheme)
GalleryPreview::GalleryPreview(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
    : mxScrolledWindow(std::move(xScrolledWindow))
    , mpParent(pParent)
    , mpTheme(nullptr)
{
    SetHelpId( HID_GALLERY_WINDOW );
    InitSettings();
}

Size GalleryPreview::GetOptimalSize() const
void GalleryPreview::Show()
{
    return LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont));
    mxScrolledWindow->show();
    weld::CustomWidgetController::Show();
}

void GalleryPreview::InitSettings()
void GalleryPreview::Hide()
{
    SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
    SetControlBackground( GALLERY_BG_COLOR );
    SetControlForeground( GALLERY_FG_COLOR );
    weld::CustomWidgetController::Hide();
    mxScrolledWindow->hide();
}

void GalleryPreview::DataChanged( const DataChangedEvent& rDCEvt )
GalleryPreview::~GalleryPreview()
{
    if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
        InitSettings();
    else
        Window::DataChanged( rDCEvt );
}

void GalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
    CustomWidgetController::SetDrawingArea(pDrawingArea);
    Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont));
    pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
    SetOutputSizePixel(aSize);

    pDrawingArea->set_help_id(HID_GALLERY_WINDOW);

    mxDragDropTargetHelper.reset(new GalleryDragDrop(mpParent, pDrawingArea->get_drop_target()));
}

namespace
{
    bool ImplGetGraphicCenterRect(const weld::CustomWidgetController& rWidget, const Graphic& rGraphic, tools::Rectangle& rResultRect)
    {
        const Size  aWinSize(rWidget.GetOutputSizePixel());
        Size        aNewSize(rWidget.GetDrawingArea()->get_ref_device().LogicToPixel(rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode()));
        bool        bRet = false;

        if( aNewSize.Width() && aNewSize.Height() )
        {
            // scale to fit window
            const double fGrfWH = static_cast<double>(aNewSize.Width()) / aNewSize.Height();
            const double fWinWH = static_cast<double>(aWinSize.Width()) / aWinSize.Height();

            if ( fGrfWH < fWinWH )
            {
                aNewSize.setWidth( static_cast<long>( aWinSize.Height() * fGrfWH ) );
                aNewSize.setHeight( aWinSize.Height() );
            }
            else
            {
                aNewSize.setWidth( aWinSize.Width() );
                aNewSize.setHeight( static_cast<long>( aWinSize.Width() / fGrfWH) );
            }

            const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
                                 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );

            rResultRect = tools::Rectangle( aNewPos, aNewSize );
            bRet = true;
        }

        return bRet;
    }
}

bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const
{
    const Size  aWinSize( GetOutputSizePixel() );
    Size        aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
    bool        bRet = false;

    if( aNewSize.Width() && aNewSize.Height() )
    {
        // scale to fit window
        const double fGrfWH = static_cast<double>(aNewSize.Width()) / aNewSize.Height();
        const double fWinWH = static_cast<double>(aWinSize.Width()) / aWinSize.Height();

        if ( fGrfWH < fWinWH )
        {
            aNewSize.setWidth( static_cast<long>( aWinSize.Height() * fGrfWH ) );
            aNewSize.setHeight( aWinSize.Height() );
        }
        else
        {
            aNewSize.setWidth( aWinSize.Width() );
            aNewSize.setHeight( static_cast<long>( aWinSize.Width() / fGrfWH) );
        }

        const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
                             ( aWinSize.Height() - aNewSize.Height() ) >> 1 );

        rResultRect = tools::Rectangle( aNewPos, aNewSize );
        bRet = true;
    }

    return bRet;
    return ::ImplGetGraphicCenterRect(*this, rGraphic, rResultRect);
}

void GalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
void GalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
{
    Window::Paint(rRenderContext, rRect);
    rRenderContext.SetBackground(Wallpaper(GALLERY_BG_COLOR));
    rRenderContext.Erase();

    if (ImplGetGraphicCenterRect(aGraphicObj.GetGraphic(), aPreviewRect))
    {
@@ -122,28 +134,28 @@ void GalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rect
    }
}

void GalleryPreview::MouseButtonDown(const MouseEvent& rMEvt)
bool GalleryPreview::MouseButtonDown(const MouseEvent& rMEvt)
{
    if (mpTheme && (rMEvt.GetClicks() == 2))
        static_cast<GalleryBrowser2*>(GetParent())->TogglePreview();
        mpParent->TogglePreview();
    return true;
}

void GalleryPreview::Command(const CommandEvent& rCEvt)
bool GalleryPreview::Command(const CommandEvent& rCEvt)
{
    Window::Command(rCEvt);

    if (mpTheme && (rCEvt.GetCommand() == CommandEventId::ContextMenu))
    {
        GalleryBrowser2* pGalleryBrowser = static_cast<GalleryBrowser2*>(GetParent());
        pGalleryBrowser->ShowContextMenu(rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : nullptr);
        mpParent->ShowContextMenu(rCEvt);
        return true;
    }
    return false;
}

void GalleryPreview::KeyInput(const KeyEvent& rKEvt)
bool GalleryPreview::KeyInput(const KeyEvent& rKEvt)
{
    if(mpTheme)
    {
        GalleryBrowser2* pBrowser = static_cast< GalleryBrowser2* >( GetParent() );
        GalleryBrowser2* pBrowser = mpParent;

        switch( rKEvt.GetKeyCode().GetCode() )
        {
@@ -171,46 +183,22 @@ void GalleryPreview::KeyInput(const KeyEvent& rKEvt)

            default:
            {
                if (!pBrowser->KeyInput(rKEvt, this))
                    Window::KeyInput(rKEvt);
                if (!pBrowser->KeyInput(rKEvt))
                    return false;
            }
            break;
        }

        return true;
    }
    else
    {
        Window::KeyInput(rKEvt);
    }
    return false;
}

sal_Int8 GalleryPreview::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
bool GalleryPreview::StartDrag()
{
    sal_Int8 nRet;

    if (mpTheme)
        nRet = static_cast<GalleryBrowser2*>(GetParent())->AcceptDrop(*this);
    else
        nRet = DND_ACTION_NONE;

    return nRet;
}

sal_Int8 GalleryPreview::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
    sal_Int8 nRet;

    if (mpTheme)
        nRet = static_cast<GalleryBrowser2*>(GetParent())->ExecuteDrop(rEvt);
    else
        nRet = DND_ACTION_NONE;

    return nRet;
}

void GalleryPreview::StartDrag( sal_Int8, const Point& )
{
    if(mpTheme)
        static_cast<GalleryBrowser2*>(GetParent())->StartDrag();
        return mpParent->StartDrag();
    return true;
}

void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
@@ -234,11 +222,11 @@ void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
#endif
}

SvxGalleryPreview::SvxGalleryPreview()
DialogGalleryPreview::DialogGalleryPreview()
{
}

void SvxGalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
void DialogGalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
    CustomWidgetController::SetDrawingArea(pDrawingArea);
    Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)));
@@ -246,7 +234,7 @@ void SvxGalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
    pDrawingArea->set_help_id(HID_GALLERY_WINDOW);
}

bool SvxGalleryPreview::SetGraphic( const INetURLObject& _aURL )
bool DialogGalleryPreview::SetGraphic( const INetURLObject& _aURL )
{
    bool bRet = true;
    Graphic aGraphic;
@@ -269,40 +257,12 @@ bool SvxGalleryPreview::SetGraphic( const INetURLObject& _aURL )
    return bRet;
}

bool SvxGalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const
bool DialogGalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const
{
    const Size  aWinSize(GetOutputSizePixel());
    Size        aNewSize(GetDrawingArea()->get_ref_device().LogicToPixel(rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode()));
    bool        bRet = false;

    if( aNewSize.Width() && aNewSize.Height() )
    {
        // scale to fit window
        const double fGrfWH = static_cast<double>(aNewSize.Width()) / aNewSize.Height();
        const double fWinWH = static_cast<double>(aWinSize.Width()) / aWinSize.Height();

        if ( fGrfWH < fWinWH )
        {
            aNewSize.setWidth( static_cast<long>( aWinSize.Height() * fGrfWH ) );
            aNewSize.setHeight( aWinSize.Height() );
        }
        else
        {
            aNewSize.setWidth( aWinSize.Width() );
            aNewSize.setHeight( static_cast<long>( aWinSize.Width() / fGrfWH) );
        }

        const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
                             ( aWinSize.Height() - aNewSize.Height() ) >> 1 );

        rResultRect = tools::Rectangle( aNewPos, aNewSize );
        bRet = true;
    }

    return bRet;
    return ::ImplGetGraphicCenterRect(*this, rGraphic, rResultRect);
}

void SvxGalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
void DialogGalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
{
    rRenderContext.SetBackground(Wallpaper(GALLERY_BG_COLOR));

@@ -318,9 +278,8 @@ void SvxGalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::R
    }
}

static void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize)
void GalleryIconView::drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize)
{

    // draw checkered background
    static const sal_uInt32 nLen(8);
    static const Color aW(COL_WHITE);
@@ -329,36 +288,30 @@ static void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rP
    rOut.DrawCheckered(rPos, rSize, nLen, aW, aG);
}

GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
        ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ),
        DropTargetHelper( this ),
        DragSourceHelper( this ),
        mpTheme ( pTheme )
GalleryIconView::GalleryIconView(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
    : SvtValueSet(std::move(xScrolledWindow))
    , mpParent(pParent)
    , mpTheme(nullptr)
{
}

GalleryIconView::~GalleryIconView()
{
}

void GalleryIconView::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
    SvtValueSet::SetDrawingArea(pDrawingArea);

    SetStyle(GetStyle() | WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET);
    EnableFullItemMode( false );

    SetHelpId( HID_GALLERY_WINDOW );
    InitSettings();
    SetExtraSpacing( 2 );
    SetItemWidth( S_THUMB + 6 );
    SetItemHeight( S_THUMB + 6 );
}

void GalleryIconView::InitSettings()
{
    SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
    SetControlBackground( GALLERY_BG_COLOR );
    SetControlForeground( GALLERY_FG_COLOR );
    SetColor( GALLERY_BG_COLOR );
}

void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt )
{
    if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
        InitSettings();
    else
        ValueSet::DataChanged( rDCEvt );
    mxDragDropTargetHelper.reset(new GalleryDragDrop(mpParent, pDrawingArea->get_drop_target()));
}

void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
@@ -413,7 +366,7 @@ void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
        if(aBitmapEx.IsTransparent())
        {
            // draw checkered background for full rectangle.
            drawTransparenceBackground(*pDev, rRect.TopLeft(), rRect.GetSize());
            GalleryIconView::drawTransparenceBackground(*pDev, rRect.TopLeft(), rRect.GetSize());
        }

        pDev->DrawBitmapEx(aPos, aBitmapEx);
@@ -422,247 +375,38 @@ void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
    SetItemText(nId, aItemTextTitle);
}

void GalleryIconView::MouseButtonDown(const MouseEvent& rMEvt)
bool GalleryIconView::MouseButtonDown(const MouseEvent& rMEvt)
{
    ValueSet::MouseButtonDown(rMEvt);
    bool bRet = SvtValueSet::MouseButtonDown(rMEvt);

    if (rMEvt.GetClicks() == 2)
        static_cast<GalleryBrowser2*>(GetParent())->TogglePreview();
        mpParent->TogglePreview();

    return bRet;
}

void GalleryIconView::Command(const CommandEvent& rCEvt)
bool GalleryIconView::Command(const CommandEvent& rCEvt)
{
    ValueSet::Command(rCEvt);
    bool bRet = SvtValueSet::Command(rCEvt);

    if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
    {
        GalleryBrowser2* pGalleryBrowser = static_cast<GalleryBrowser2*>(GetParent());
        pGalleryBrowser->ShowContextMenu(rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : nullptr);
        mpParent->ShowContextMenu(rCEvt);
    }

    return bRet;
}

void GalleryIconView::KeyInput(const KeyEvent& rKEvt)
bool GalleryIconView::KeyInput(const KeyEvent& rKEvt)
{
    if (!mpTheme || !static_cast<GalleryBrowser2*>(GetParent())->KeyInput(rKEvt, this))
        ValueSet::KeyInput(rKEvt);
}

sal_Int8 GalleryIconView::AcceptDrop(const AcceptDropEvent& /*rEvt*/)
{
    return static_cast<GalleryBrowser2*>(GetParent())->AcceptDrop(*this);
}

sal_Int8 GalleryIconView::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
    return static_cast<GalleryBrowser2*>(GetParent())->ExecuteDrop(rEvt);
}

void GalleryIconView::StartDrag(sal_Int8, const Point&)
{
    const CommandEvent aEvt(GetPointerPosPixel(), CommandEventId::StartDrag, true);
    vcl::Region aRegion;

    // call this to initiate dragging for ValueSet
    ValueSet::StartDrag(aEvt, aRegion);
    static_cast<GalleryBrowser2*>(GetParent())->StartDrag();
}

GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
    BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ),
    mpTheme( pTheme ),
    mnCurRow( 0 )
{

    SetHelpId( HID_GALLERY_WINDOW );

    InitSettings();

    SetMode( BrowserMode::AUTO_VSCROLL | BrowserMode::AUTOSIZE_LASTCOL | BrowserMode::AUTO_HSCROLL );
    SetDataRowHeight( 28 );
    InsertDataColumn( GALLERY_BRWBOX_TITLE, SvxResId(RID_SVXSTR_GALLERY_TITLE), 256  );
}

void GalleryListView::InitSettings()
{
    SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
    SetControlBackground( GALLERY_BG_COLOR );
    SetControlForeground( GALLERY_FG_COLOR );
}

void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt )
{
    if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
        InitSettings();
    else
        BrowseBox::DataChanged( rDCEvt );
}

bool GalleryListView::SeekRow( long nRow )
{
    mnCurRow = nRow;
    if (!mpTheme || !mpParent->KeyInput(rKEvt))
        return SvtValueSet::KeyInput(rKEvt);
    return true;
}

OUString GalleryListView::GetCellText(long _nRow, sal_uInt16 /*nColumnId*/) const
bool GalleryIconView::StartDrag()
{
    OUString sRet;
    if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
    {
        std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject( _nRow );

        if( pObj )
        {
            sRet = GalleryBrowser2::GetItemText( *pObj, GalleryItemFlags::Title );
        }
    }

    return sRet;
}

tools::Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)
{
    DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= SAL_MAX_UINT16, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow");
    tools::Rectangle aRect;
    if ( SeekRow(_nRow) )
    {
        SvxFont aFont( GetFont() );
        AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) );

        // get the bounds inside the string
        aStringWrap.GetCharacterBounds(nIndex, aRect);

        // offset to
    }
    return aRect;
}

sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
{
    DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= SAL_MAX_UINT16, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow");
    sal_Int32 nRet = -1;
    if ( SeekRow(_nRow) )
    {
        SvxFont aFont( GetFont() );
        AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) );
        nRet = aStringWrap.GetIndexAtPoint(_rPoint);
    }
    return nRet;
}

void GalleryListView::PaintField(vcl::RenderContext& rDev, const tools::Rectangle& rRect, sal_uInt16 /*nColumnId*/) const
{
    rDev.Push( PushFlags::CLIPREGION );
    rDev.IntersectClipRegion( rRect );

    if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) )
    {
        const Size aSize(rRect.GetHeight(), rRect.GetHeight());
        BitmapEx aBitmapEx;
        Size aPreparedSize;
        OUString aItemTextTitle;
        OUString aItemTextPath;

        mpTheme->GetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);

        bool bNeedToCreate(aBitmapEx.IsEmpty());

        if(!bNeedToCreate && (aItemTextTitle.isEmpty() || aPreparedSize != aSize))
            bNeedToCreate = true;

        if(bNeedToCreate)
        {
            std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject(mnCurRow);

            if(pObj)
            {
                aBitmapEx = pObj->createPreviewBitmapEx(aSize);
                aItemTextTitle = GalleryBrowser2::GetItemText(*pObj, GalleryItemFlags::Title);
                aItemTextPath = GalleryBrowser2::GetItemText(*pObj, GalleryItemFlags::Path);

                mpTheme->SetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
            }
        }

        const long nTextPosY(rRect.Top() + ((rRect.GetHeight() - rDev.GetTextHeight()) >> 1));

        if(!aBitmapEx.IsEmpty())
        {
            const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
            const Point aPos(
                ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
                ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());

            if(aBitmapEx.IsTransparent())
            {
                // draw checkered background
                drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel);
            }

            rDev.DrawBitmapEx(aPos, aBitmapEx);
        }

        rDev.DrawText(Point(rRect.Left() + rRect.GetHeight() + 6, nTextPosY), aItemTextTitle);
    }

    rDev.Pop();
}

void GalleryListView::Command( const CommandEvent& rCEvt )
{
    BrowseBox::Command( rCEvt );

    if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
    {
        const Point* pPos = nullptr;

        if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) )
            pPos = &rCEvt.GetMousePosPixel();

        static_cast<GalleryBrowser2*>( GetParent() )->ShowContextMenu( pPos );
    }
}

void GalleryListView::KeyInput( const KeyEvent& rKEvt )
{
    if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
        BrowseBox::KeyInput( rKEvt );
}

void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt )
{
    BrowseBox::DoubleClick( rEvt );

    if( rEvt.GetRow() != BROWSER_ENDOFSELECTION )
        static_cast<GalleryBrowser2*>( GetParent() )->TogglePreview();
}

void GalleryListView::Select()
{
    maSelectHdl.Call( this );
}

sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& )
{
    sal_Int8 nRet = DND_ACTION_NONE;

    if( mpTheme && !mpTheme->IsReadOnly() )
        nRet = DND_ACTION_COPY;

    return nRet;
}

sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
{
    ExecuteDropEvent aEvt( rEvt );

    aEvt.maPosPixel.AdjustY(GetTitleHeight() );

    return static_cast<GalleryBrowser2*>( GetParent() )->ExecuteDrop( aEvt );
}

void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel )
{
    static_cast<GalleryBrowser2*>( GetParent() )->StartDrag( &rPosPixel );
    return mpParent->StartDrag();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galmisc.cxx b/svx/source/gallery2/galmisc.cxx
index e933419..facb498 100644
--- a/svx/source/gallery2/galmisc.cxx
+++ b/svx/source/gallery2/galmisc.cxx
@@ -55,17 +55,6 @@

using namespace ::com::sun::star;

BitmapEx GalleryResGetBitmapEx(const OUString &rId)
{
    BitmapEx aBmpEx(rId);

    //TODO, check if any of these have no transparency layer
    if (!aBmpEx.IsTransparent())
        aBmpEx = BitmapEx(aBmpEx.GetBitmap(), COL_LIGHTMAGENTA);

    return aBmpEx;
}

GalleryGraphicImportRet GalleryGraphicImport( const INetURLObject& rURL, Graphic& rGraphic,
                             OUString& rFilterName )
{
@@ -375,13 +364,24 @@ void GalleryProgress::Update( sal_Int32 nVal, sal_Int32 nMaxVal )

GalleryTransferable::GalleryTransferable( GalleryTheme* pTheme, sal_uInt32 nObjectPos, bool bLazy ) :
    mpTheme( pTheme ),
    meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ),
    meObjectKind( pTheme ? mpTheme->GetObjectKind(nObjectPos) : SgaObjKind::NONE),
    mnObjectPos( nObjectPos )
{

    InitData( bLazy );
}

void GalleryTransferable::SelectObject(sal_uInt32 nObjectPos)
{
    if (nObjectPos == mnObjectPos)
        return;
    ClearFormats();
    mnObjectPos = nObjectPos;
    meObjectKind = mpTheme ? mpTheme->GetObjectKind(mnObjectPos) : SgaObjKind::NONE;
    ObjectReleased();
    InitData(true);
}

GalleryTransferable::~GalleryTransferable()
{
}
@@ -398,7 +398,7 @@ void GalleryTransferable::InitData( bool bLazy )
                {
                    Graphic aGraphic;

                    if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
                    if (mpTheme && mpTheme->GetGraphic(mnObjectPos, aGraphic))
                        mpGraphicObject.reset(new GraphicObject( aGraphic ));
                }

@@ -407,7 +407,7 @@ void GalleryTransferable::InitData( bool bLazy )
                    mxModelStream = new SotStorageStream( "" );
                    mxModelStream->SetBufferSize( 16348 );

                    if( !mpTheme->GetModelStream( mnObjectPos, mxModelStream ) )
                    if (!mpTheme || !mpTheme->GetModelStream(mnObjectPos, mxModelStream))
                        mxModelStream.clear();
                    else
                        mxModelStream->Seek( 0 );
@@ -425,7 +425,7 @@ void GalleryTransferable::InitData( bool bLazy )
            {
                mpURL.reset(new INetURLObject);

                if( !mpTheme->GetURL( mnObjectPos, *mpURL ) )
                if (!mpTheme || !mpTheme->GetURL(mnObjectPos, *mpURL))
                {
                    mpURL.reset();
                }
@@ -435,7 +435,7 @@ void GalleryTransferable::InitData( bool bLazy )
            {
                Graphic aGraphic;

                if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
                if (mpTheme && mpTheme->GetGraphic(mnObjectPos, aGraphic))
                    mpGraphicObject.reset(new GraphicObject( aGraphic ));
            }
        }
@@ -526,8 +526,11 @@ bool GalleryTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, v

void GalleryTransferable::DragFinished( sal_Int8 nDropAction )
{
    mpTheme->SetDragging( false );
    mpTheme->SetDragPos( 0 );
    if (mpTheme)
    {
        mpTheme->SetDragging( false );
        mpTheme->SetDragPos( 0 );
    }
    if ( nDropAction )
    {
        vcl::Window *pFocusWindow = Application::GetFocusWindow();
@@ -543,16 +546,16 @@ void GalleryTransferable::ObjectReleased()
    mpURL.reset();
}

void GalleryTransferable::StartDrag( vcl::Window* pWindow, sal_Int8 nDragSourceActions )
bool GalleryTransferable::StartDrag()
{
    INetURLObject aURL;

    if( mpTheme->GetURL( mnObjectPos, aURL ) && ( aURL.GetProtocol() != INetProtocol::NotValid ) )
    if (mpTheme && mpTheme->GetURL(mnObjectPos, aURL) && aURL.GetProtocol() != INetProtocol::NotValid)
    {
        mpTheme->SetDragging( true );
        mpTheme->SetDragPos( mnObjectPos );
        TransferableHelper::StartDrag( pWindow, nDragSourceActions );
        return false;
    }
    return true;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 6ca4c69..91a141f 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -1221,16 +1221,10 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans
    return bRet;
}

void GalleryTheme::CopyToClipboard(vcl::Window* pWindow, sal_uInt32 nPos)
void GalleryTheme::CopyToClipboard(sal_uInt32 nPos)
{
    GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
    pTransferable->CopyToClipboard( pWindow );
}

void GalleryTheme::StartDrag(vcl::Window* pWindow, sal_uInt32 nPos)
{
    GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
    pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
    pTransferable->CopyToClipboard(GetSystemClipboard());
}

SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
diff --git a/svx/uiconfig/ui/gallerymenu1.ui b/svx/uiconfig/ui/gallerymenu1.ui
index 0261a62..fd94952 100644
--- a/svx/uiconfig/ui/gallerymenu1.ui
+++ b/svx/uiconfig/ui/gallerymenu1.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="svx">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkMenu" id="menu">
@@ -24,6 +24,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu1|delete">_Delete</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
@@ -31,6 +32,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu1|rename">_Rename</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
@@ -44,6 +46,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu1|assign">Assign _ID</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
@@ -57,6 +60,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu1|properties">Propert_ies...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
diff --git a/svx/uiconfig/ui/gallerymenu2.ui b/svx/uiconfig/ui/gallerymenu2.ui
index 8cd3cc8..22f0e83 100644
--- a/svx/uiconfig/ui/gallerymenu2.ui
+++ b/svx/uiconfig/ui/gallerymenu2.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="svx">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkMenu" id="menu">
@@ -19,6 +19,12 @@
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu2|background">Insert as Bac_kground</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="backgroundmenu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
    <child>
@@ -46,6 +52,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu2|title">_Title</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
@@ -59,6 +66,7 @@
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="gallerymenu2|delete">_Delete</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
diff --git a/svx/uiconfig/ui/sidebargallery.ui b/svx/uiconfig/ui/sidebargallery.ui
new file mode 100644
index 0000000..12e319d
--- /dev/null
+++ b/svx/uiconfig/ui/sidebargallery.ui
@@ -0,0 +1,345 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="svx">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkImage" id="image1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">svx/res/galicon.png</property>
  </object>
  <object class="GtkImage" id="image2">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="icon_name">svx/res/gallist.png</property>
  </object>
  <object class="GtkTreeStore" id="liststore1">
    <columns>
      <!-- column-name image -->
      <column type="GdkPixbuf"/>
      <!-- column-name text -->
      <column type="gchararray"/>
      <!-- column-name id -->
      <column type="gchararray"/>
    </columns>
  </object>
  <object class="GtkTreeStore" id="liststore2">
    <columns>
      <!-- column-name image -->
      <column type="GdkPixbuf"/>
      <!-- column-name text -->
      <column type="gchararray"/>
      <!-- column-name id -->
      <column type="gchararray"/>
    </columns>
  </object>
  <object class="GtkGrid" id="GalleryPanel">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="hexpand">True</property>
    <property name="vexpand">True</property>
    <property name="border_width">6</property>
    <child>
      <object class="GtkGrid" id="container">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="hexpand">True</property>
        <property name="vexpand">True</property>
        <property name="border_width">6</property>
        <property name="row_spacing">6</property>
        <child>
          <object class="GtkPaned" id="splitter">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="hexpand">True</property>
            <property name="vexpand">True</property>
            <property name="orientation">vertical</property>
            <property name="wide_handle">True</property>
            <child>
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="hexpand">True</property>
                <property name="vexpand">True</property>
                <property name="row_spacing">6</property>
                <child>
                  <object class="GtkScrolledWindow">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="hexpand">True</property>
                    <property name="vexpand">True</property>
                    <property name="shadow_type">in</property>
                    <child>
                      <object class="GtkTreeView" id="themelist">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="hexpand">True</property>
                        <property name="vexpand">True</property>
                        <property name="model">liststore1</property>
                        <property name="headers_visible">False</property>
                        <property name="search_column">1</property>
                        <property name="show_expanders">False</property>
                        <child internal-child="selection">
                          <object class="GtkTreeSelection" id="treeview-selection2"/>
                        </child>
                        <child>
                          <object class="GtkTreeViewColumn" id="treeviewcolumn0">
                            <child>
                              <object class="GtkCellRendererPixbuf" id="cellrenderertext9"/>
                              <attributes>
                                <attribute name="pixbuf">0</attribute>
                              </attributes>
                            </child>
                          </object>
                        </child>
                        <child>
                          <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                            <child>
                              <object class="GtkCellRendererText" id="cellrenderertext2"/>
                              <attributes>
                                <attribute name="text">1</attribute>
                              </attributes>
                            </child>
                          </object>
                        </child>
                        <child internal-child="accessible">
                          <object class="AtkObject" id="themelist-atkobject">
                            <property name="AtkObject::accessible-name" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERYPROPS_GALTHEME">Gallery Theme</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="insert">
                    <property name="label" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERY_CREATETHEME">New Theme...</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="can_default">True</property>
                    <property name="receives_default">True</property>
                    <property name="use_underline">True</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="resize">True</property>
                <property name="shrink">True</property>
              </packing>
            </child>
            <child>
              <object class="GtkGrid">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="hexpand">True</property>
                <property name="vexpand">True</property>
                <property name="row_spacing">6</property>
                <child>
                  <object class="GtkGrid">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="halign">start</property>
                    <property name="hexpand">True</property>
                    <property name="column_spacing">6</property>
                    <child>
                      <object class="GtkToggleButton" id="icon">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <property name="tooltip_text" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERY_ICONVIEW">Icon View</property>
                        <property name="image">image1</property>
                        <property name="always_show_image">True</property>
                        <child internal-child="accessible">
                          <object class="AtkObject" id="icon-atkobject">
                            <property name="AtkObject::accessible-name" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERY_THEMEITEMS">Theme Items</property>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToggleButton" id="list">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <property name="tooltip_text" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERY_LISTVIEW">Detailed View</property>
                        <property name="image">image2</property>
                        <property name="always_show_image">True</property>
                        <child internal-child="accessible">
                          <object class="AtkObject" id="list-atkobject">
                            <property name="AtkObject::accessible-name" translatable="yes" context="sidebargallery|RID_SVXSTR_GALLERY_THEMEITEMS">Theme Items</property>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkLabel" id="label">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="use_underline">True</property>
                        <property name="mnemonic_widget">gallery</property>
                        <attributes>
                          <attribute name="weight" value="bold"/>
                        </attributes>
                      </object>
                      <packing>
                        <property name="left_attach">2</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkGrid">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="hexpand">True</property>
                    <property name="vexpand">True</property>
                    <child>
                      <object class="GtkScrolledWindow" id="galleryscroll">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="hexpand">True</property>
                        <property name="vexpand">True</property>
                        <property name="vscrollbar_policy">never</property>
                        <property name="shadow_type">in</property>
                        <child>
                          <object class="GtkViewport">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <child>
                              <object class="GtkDrawingArea" id="gallery">
                                <property name="visible">True</property>
                                <property name="can_focus">True</property>
                                <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
                                <property name="hexpand">True</property>
                                <property name="vexpand">True</property>
                              </object>
                            </child>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkScrolledWindow">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="hexpand">True</property>
                        <property name="vexpand">True</property>
                        <property name="shadow_type">in</property>
                        <child>
                          <object class="GtkTreeView" id="gallerylist">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="hexpand">True</property>
                            <property name="vexpand">True</property>
                            <property name="model">liststore2</property>
                            <property name="headers_visible">False</property>
                            <property name="reorderable">True</property>
                            <property name="search_column">1</property>
                            <property name="show_expanders">False</property>
                            <child internal-child="selection">
                              <object class="GtkTreeSelection" id="treeview-selection3"/>
                            </child>
                            <child>
                              <object class="GtkTreeViewColumn" id="treeviewcolumn10">
                                <child>
                                  <object class="GtkCellRendererPixbuf" id="cellrenderertext19"/>
                                  <attributes>
                                    <attribute name="pixbuf">0</attribute>
                                  </attributes>
                                </child>
                                <child>
                                  <object class="GtkCellRendererText" id="cellrenderertext12"/>
                                  <attributes>
                                    <attribute name="text">1</attribute>
                                  </attributes>
                                </child>
                              </object>
                            </child>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkScrolledWindow" id="previewscroll">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="hexpand">True</property>
                        <property name="vexpand">True</property>
                        <property name="hscrollbar_policy">never</property>
                        <property name="vscrollbar_policy">never</property>
                        <property name="shadow_type">in</property>
                        <child>
                          <object class="GtkViewport">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <child>
                              <object class="GtkDrawingArea" id="preview">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
                                <property name="hexpand">True</property>
                                <property name="vexpand">True</property>
                              </object>
                            </child>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="left_attach">2</property>
                        <property name="top_attach">0</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="resize">True</property>
                <property name="shrink">True</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left_attach">0</property>
            <property name="top_attach">0</property>
          </packing>
        </child>
      </object>
      <packing>
        <property name="left_attach">0</property>
        <property name="top_attach">0</property>
      </packing>
    </child>
  </object>
</interface>
diff --git a/vcl/source/app/customweld.cxx b/vcl/source/app/customweld.cxx
index d6465ff..07dc793 100644
--- a/vcl/source/app/customweld.cxx
+++ b/vcl/source/app/customweld.cxx
@@ -13,6 +13,11 @@ namespace weld
{
CustomWidgetController::~CustomWidgetController() {}

IMPL_LINK_NOARG(CustomWidgetController, DragBeginHdl, weld::DrawingArea&, bool)
{
    return StartDrag();
}

CustomWeld::CustomWeld(weld::Builder& rBuilder, const OString& rDrawingId,
                       CustomWidgetController& rWidgetController)
    : m_rWidgetController(rWidgetController)
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 3b66977..a8f90b2 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5711,6 +5711,7 @@ private:
    DECL_LINK(StyleUpdatedHdl, VclDrawingArea&, void);
    DECL_LINK(CommandHdl, const CommandEvent&, bool);
    DECL_LINK(QueryTooltipHdl, tools::Rectangle&, OUString);
    DECL_LINK(StartDragHdl, VclDrawingArea*, bool);

    // SalInstanceWidget has a generic listener for all these
    // events, ignore the ones we have specializations for
@@ -5757,6 +5758,7 @@ public:
        m_xDrawingArea->SetStyleUpdatedHdl(LINK(this, SalInstanceDrawingArea, StyleUpdatedHdl));
        m_xDrawingArea->SetCommandHdl(LINK(this, SalInstanceDrawingArea, CommandHdl));
        m_xDrawingArea->SetQueryTooltipHdl(LINK(this, SalInstanceDrawingArea, QueryTooltipHdl));
        m_xDrawingArea->SetStartDragHdl(LINK(this, SalInstanceDrawingArea, StartDragHdl));
    }

    virtual void queue_draw() override
@@ -5830,6 +5832,11 @@ public:
        return m_xDrawingArea->OutputToAbsoluteScreenPixel(Point());
    }

    virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants) override
    {
        m_xDrawingArea->SetDragHelper(rHelper, eDNDConstants);
    }

    virtual ~SalInstanceDrawingArea() override
    {
        m_xDrawingArea->SetQueryTooltipHdl(Link<tools::Rectangle&, OUString>());
@@ -5905,6 +5912,13 @@ IMPL_LINK(SalInstanceDrawingArea, QueryTooltipHdl, tools::Rectangle&, rHelpArea,
    return m_aQueryTooltipHdl.Call(rHelpArea);
}

IMPL_LINK_NOARG(SalInstanceDrawingArea, StartDragHdl, VclDrawingArea*, bool)
{
    if (m_aDragBeginHdl.Call(*this))
        return true;
    return false;
}

namespace {

//ComboBox and ListBox have similar apis, ComboBoxes in LibreOffice have an edit box and ListBoxes
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index be8313c..ce8b337 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -2694,4 +2694,16 @@ bool isLayoutEnabled(const vcl::Window *pWindow)
    return pChild && isContainerWindow(*pChild) && !pChild->GetWindow(GetWindowType::Next);
}

void VclDrawingArea::StartDrag(sal_Int8, const Point&)
{
    if (m_aStartDragHdl.Call(this))
        return;

    rtl::Reference<TransferDataContainer> xContainer = m_xTransferHelper;
    if (!m_xTransferHelper.is())
        return;

    xContainer->StartDrag(this, m_nDragAction);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 024b71c..486b522 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1792,6 +1792,18 @@ namespace

namespace {

GdkDragAction VclToGdk(sal_Int8 dragOperation)
{
    GdkDragAction eRet(static_cast<GdkDragAction>(0));
    if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
        eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_COPY);
    if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
        eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_MOVE);
    if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
        eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_LINK);
    return eRet;
}

class GtkInstanceWidget : public virtual weld::Widget
{
protected:
@@ -1894,6 +1906,25 @@ protected:
        return AllSettings::GetLayoutRTL();
    }

    void do_enable_drag_source(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants)
    {
        css::uno::Reference<css::datatransfer::XTransferable> xTrans(rHelper.get());
        css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> xListener(rHelper.get());

        ensure_drag_source();

        auto aFormats = xTrans->getTransferDataFlavors();
        std::vector<GtkTargetEntry> aGtkTargets(m_xDragSource->FormatsToGtk(aFormats));

        m_eDragAction = VclToGdk(eDNDConstants);
        drag_source_set(aGtkTargets, m_eDragAction);

        for (auto &a : aGtkTargets)
            g_free(a.target);

        m_xDragSource->set_datatransfer(xTrans, xListener);
    }

    void localizeDecimalSeparator()
    {
        // tdf#128867 if localize decimal separator is active we will always
@@ -1908,9 +1939,13 @@ private:
    bool m_bDraggedOver;
    sal_uInt16 m_nLastMouseButton;
    sal_uInt16 m_nLastMouseClicks;
    int m_nPressedButton;
    int m_nPressStartX;
    int m_nPressStartY;
    ImplSVEvent* m_pFocusInEvent;
    ImplSVEvent* m_pFocusOutEvent;
    GtkCssProvider* m_pBgCssProvider;
    GdkDragAction m_eDragAction;
    gulong m_nFocusInSignalId;
    gulong m_nMnemonicActivateSignalId;
    gulong m_nFocusOutSignalId;
@@ -1926,8 +1961,14 @@ private:
    gulong m_nDragDropSignalId;
    gulong m_nDragDropReceivedSignalId;
    gulong m_nDragLeaveSignalId;
    gulong m_nDragBeginSignalId;
    gulong m_nDragEndSignalId;
    gulong m_nDragFailedSignalId;
    gulong m_nDragDataDeleteignalId;
    gulong m_nDragGetSignalId;

    rtl::Reference<GtkDropTarget> m_xDropTarget;
    rtl::Reference<GtkDragSource> m_xDragSource;
    std::vector<AtkRelation*> m_aExtraAtkRelations;

    static void signalSizeAllocate(GtkWidget*, GdkRectangle* allocation, gpointer widget)
@@ -1964,6 +2005,8 @@ private:

    bool signal_button(GdkEventButton* pEvent)
    {
        m_nPressedButton = -1;

        Point aPos(pEvent->x, pEvent->y);
        if (SwapForRTL())
            aPos.setX(gtk_widget_get_allocated_width(m_pWidget) - 1 - aPos.X());
@@ -2026,6 +2069,14 @@ private:
                return false;
        }

        /* Save press to possibly begin a drag */
        if (pEvent->type != GDK_BUTTON_RELEASE)
        {
            m_nPressedButton = pEvent->button;
            m_nPressStartX = pEvent->x;
            m_nPressStartY = pEvent->y;
        }

        sal_uInt32 nModCode = GtkSalFrame::GetMouseModCode(pEvent->state);
        sal_uInt16 nCode = m_nLastMouseButton | (nModCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2));
        MouseEvent aMEvt(aPos, m_nLastMouseClicks, ImplGetMouseButtonMode(m_nLastMouseButton, nModCode), nCode, nCode);
@@ -2051,6 +2102,19 @@ private:

    bool signal_motion(const GdkEventMotion* pEvent)
    {
        GtkTargetList* pDragData = (m_eDragAction != 0 && m_nPressedButton != -1 && m_xDragSource.is()) ? gtk_drag_source_get_target_list(m_pWidget) : nullptr;
        if (pDragData && gtk_drag_check_threshold(m_pWidget, m_nPressStartX, m_nPressStartY, pEvent->x, pEvent->y) && !do_signal_drag_begin())
        {
            gtk_drag_begin_with_coordinates(m_pWidget,
                                            pDragData,
                                            m_eDragAction,
                                            m_nPressedButton,
                                            const_cast<GdkEvent*>(reinterpret_cast<const GdkEvent*>(pEvent)),
                                            m_nPressStartX, m_nPressStartY);
            m_nPressedButton = -1;
            return false;
        }

        if (!m_aMouseMotionHdl.IsSet())
            return false;

@@ -2132,6 +2196,80 @@ private:
        }
    }

    static void signalDragBegin(GtkWidget*, GdkDragContext* context, gpointer widget)
    {
        GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget);
        pThis->signal_drag_begin(context);
    }

    void ensure_drag_source()
    {
        if (!m_xDragSource)
        {
            m_xDragSource.set(new GtkDragSource);

            m_nDragFailedSignalId = g_signal_connect(m_pWidget, "drag-failed", G_CALLBACK(signalDragFailed), this);
            m_nDragDataDeleteignalId = g_signal_connect(m_pWidget, "drag-data-delete", G_CALLBACK(signalDragDelete), this);
            m_nDragGetSignalId = g_signal_connect(m_pWidget, "drag-data-get", G_CALLBACK(signalDragDataGet), this);
            m_nDragBeginSignalId = g_signal_connect(m_pWidget, "drag-begin", G_CALLBACK(signalDragBegin), this);
            m_nDragEndSignalId = g_signal_connect(m_pWidget, "drag-end", G_CALLBACK(signalDragEnd), this);
        }
    }

    virtual bool do_signal_drag_begin()
    {
        return false;
    }

    void signal_drag_begin(GdkDragContext* context)
    {
        if (do_signal_drag_begin())
        {
            gtk_drag_cancel(context);
            return;
        }
        if (!m_xDragSource)
            return;
        m_xDragSource->setActiveDragSource();
    }

    virtual void do_signal_drag_end()
    {
    }

    static void signalDragEnd(GtkWidget* /*widget*/, GdkDragContext* context, gpointer widget)
    {
        GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget);
        pThis->do_signal_drag_end();
        if (pThis->m_xDragSource.is())
            pThis->m_xDragSource->dragEnd(context);
    }

    static gboolean signalDragFailed(GtkWidget* /*widget*/, GdkDragContext* /*context*/, GtkDragResult /*result*/, gpointer widget)
    {
        GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget);
        pThis->m_xDragSource->dragFailed();
        return false;
    }

    static void signalDragDelete(GtkWidget* /*widget*/, GdkDragContext* /*context*/, gpointer widget)
    {
        GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget);
        pThis->m_xDragSource->dragDelete();
    }

    static void signalDragDataGet(GtkWidget* /*widget*/, GdkDragContext* /*context*/, GtkSelectionData *data, guint info,
                                  guint /*time*/, gpointer widget)
    {
        GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget);
        pThis->m_xDragSource->dragDataGet(data, info);
    }

    virtual void drag_source_set(const std::vector<GtkTargetEntry>& rGtkTargets, GdkDragAction eDragAction)
    {
        gtk_drag_source_set(m_pWidget, GDK_BUTTON1_MASK, rGtkTargets.data(), rGtkTargets.size(), eDragAction);
    }

    void set_background(const OUString* pColor)
    {
        if (!pColor && !m_pBgCssProvider)
@@ -2162,9 +2300,13 @@ public:
        , m_bDraggedOver(false)
        , m_nLastMouseButton(0)
        , m_nLastMouseClicks(0)
        , m_nPressedButton(-1)
        , m_nPressStartX(-1)
        , m_nPressStartY(-1)
        , m_pFocusInEvent(nullptr)
        , m_pFocusOutEvent(nullptr)
        , m_pBgCssProvider(nullptr)
        , m_eDragAction(GdkDragAction(0))
        , m_nFocusInSignalId(0)
        , m_nMnemonicActivateSignalId(0)
        , m_nFocusOutSignalId(0)
@@ -2180,6 +2322,11 @@ public:
        , m_nDragDropSignalId(0)
        , m_nDragDropReceivedSignalId(0)
        , m_nDragLeaveSignalId(0)
        , m_nDragBeginSignalId(0)
        , m_nDragEndSignalId(0)
        , m_nDragFailedSignalId(0)
        , m_nDragDataDeleteignalId(0)
        , m_nDragGetSignalId(0)
    {
        if (!bTakeOwnership)
            g_object_ref(m_pWidget);
@@ -2733,6 +2880,16 @@ public:
            g_signal_handler_disconnect(m_pWidget, m_nDragDropReceivedSignalId);
        if (m_nDragLeaveSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragLeaveSignalId);
        if (m_nDragEndSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragEndSignalId);
        if (m_nDragBeginSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragBeginSignalId);
        if (m_nDragFailedSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragFailedSignalId);
        if (m_nDragDataDeleteignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragDataDeleteignalId);
        if (m_nDragGetSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nDragGetSignalId);
        if (m_nKeyPressSignalId)
            g_signal_handler_disconnect(m_pWidget, m_nKeyPressSignalId);
        if (m_nKeyReleaseSignalId)
@@ -8227,18 +8384,6 @@ namespace
        return -1;
    }

    GdkDragAction VclToGdk(sal_Int8 dragOperation)
    {
        GdkDragAction eRet(static_cast<GdkDragAction>(0));
        if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
            eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_COPY);
        if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
            eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_MOVE);
        if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
            eRet = static_cast<GdkDragAction>(eRet | GDK_ACTION_LINK);
        return eRet;
    }

struct GtkInstanceTreeIter : public weld::TreeIter
{
    GtkInstanceTreeIter(const GtkInstanceTreeIter* pOrig)
@@ -8287,7 +8432,6 @@ private:
    std::vector<int> m_aSavedSortColumns;
    std::vector<int> m_aViewColToModelCol;
    std::vector<int> m_aModelColToViewCol;
    rtl::Reference<GtkDragSource> m_xDragSource;
    bool m_bWorkAroundBadDragRegion;
    bool m_bInDrag;
    gint m_nTextCol;
@@ -8301,11 +8445,6 @@ private:
    gulong m_nRowDeletedSignalId;
    gulong m_nRowInsertedSignalId;
    gulong m_nPopupMenuSignalId;
    gulong m_nDragBeginSignalId;
    gulong m_nDragEndSignalId;
    gulong m_nDragFailedSignalId;
    gulong m_nDragDataDeleteignalId;
    gulong m_nDragGetSignalId;
    gulong m_nKeyPressSignalId;
    gulong m_nQueryTooltipSignalId;
    ImplSVEvent* m_pChangeEvent;
@@ -8691,65 +8830,6 @@ private:
        return default_sort_func(pModel, a, b, m_xSorter.get());
    }

    static void signalDragBegin(GtkWidget*, GdkDragContext* context, gpointer widget)
    {
        GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
        pThis->signal_drag_begin(context);
    }

    void ensure_drag_source()
    {
        if (!m_xDragSource)
        {
            m_xDragSource.set(new GtkDragSource);

            m_nDragFailedSignalId = g_signal_connect(m_pWidget, "drag-failed", G_CALLBACK(signalDragFailed), this);
            m_nDragDataDeleteignalId = g_signal_connect(m_pWidget, "drag-data-delete", G_CALLBACK(signalDragDelete), this);
            m_nDragGetSignalId = g_signal_connect(m_pWidget, "drag-data-get", G_CALLBACK(signalDragDataGet), this);
        }
    }

    void signal_drag_begin(GdkDragContext* context)
    {
        if (m_aDragBeginHdl.Call(*this))
        {
            gtk_drag_cancel(context);
            return;
        }
        g_DragSource = this;
        if (!m_xDragSource)
            return;
        m_xDragSource->setActiveDragSource();
    }

    static void signalDragEnd(GtkWidget* /*widget*/, GdkDragContext* context, gpointer widget)
    {
        g_DragSource = nullptr;
        GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
        if (pThis->m_xDragSource.is())
            pThis->m_xDragSource->dragEnd(context);
    }

    static gboolean signalDragFailed(GtkWidget* /*widget*/, GdkDragContext* /*context*/, GtkDragResult /*result*/, gpointer widget)
    {
        GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
        pThis->m_xDragSource->dragFailed();
        return false;
    }

    static void signalDragDelete(GtkWidget* /*widget*/, GdkDragContext* /*context*/, gpointer widget)
    {
        GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
        pThis->m_xDragSource->dragDelete();
    }

    static void signalDragDataGet(GtkWidget* /*widget*/, GdkDragContext* /*context*/, GtkSelectionData *data, guint info,
                                  guint /*time*/, gpointer widget)
    {
        GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
        pThis->m_xDragSource->dragDataGet(data, info);
    }

    bool signal_key_press(GdkEventKey* pEvent)
    {
        if (pEvent->keyval != GDK_KEY_Left && pEvent->keyval != GDK_KEY_Right)
@@ -8828,11 +8908,6 @@ public:
        , m_nTestExpandRowSignalId(g_signal_connect(pTreeView, "test-expand-row", G_CALLBACK(signalTestExpandRow), this))
        , m_nVAdjustmentChangedSignalId(0)
        , m_nPopupMenuSignalId(g_signal_connect(pTreeView, "popup-menu", G_CALLBACK(signalPopupMenu), this))
        , m_nDragBeginSignalId(g_signal_connect(pTreeView, "drag-begin", G_CALLBACK(signalDragBegin), this))
        , m_nDragEndSignalId(g_signal_connect(pTreeView, "drag-end", G_CALLBACK(signalDragEnd), this))
        , m_nDragFailedSignalId(0)
        , m_nDragDataDeleteignalId(0)
        , m_nDragGetSignalId(0)
        , m_nKeyPressSignalId(g_signal_connect(pTreeView, "key-press-event", G_CALLBACK(signalKeyPress), this))
        , m_nQueryTooltipSignalId(0)
        , m_pChangeEvent(nullptr)
@@ -10034,20 +10109,12 @@ public:

    virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants) override
    {
        css::uno::Reference<css::datatransfer::XTransferable> xTrans(rHelper.get());
        css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> xListener(rHelper.get());
        do_enable_drag_source(rHelper, eDNDConstants);
    }

        ensure_drag_source();

        auto aFormats = xTrans->getTransferDataFlavors();
        std::vector<GtkTargetEntry> aGtkTargets(m_xDragSource->FormatsToGtk(aFormats));

        gtk_tree_view_enable_model_drag_source(m_pTreeView, GDK_BUTTON1_MASK, aGtkTargets.data(), aGtkTargets.size(), VclToGdk(eDNDConstants));

        for (auto &a : aGtkTargets)
            g_free(a.target);

        m_xDragSource->set_datatransfer(xTrans, xListener);
    virtual void drag_source_set(const std::vector<GtkTargetEntry>& rGtkTargets, GdkDragAction eDragAction) override
    {
        gtk_tree_view_enable_model_drag_source(m_pTreeView, GDK_BUTTON1_MASK, rGtkTargets.data(), rGtkTargets.size(), eDragAction);
    }

    virtual void set_selection_mode(SelectionMode eMode) override
@@ -10259,6 +10326,19 @@ public:
        return g_DragSource;
    }

    virtual bool do_signal_drag_begin() override
    {
        if (m_aDragBeginHdl.Call(*this))
            return true;
        g_DragSource = this;
        return false;
    }

    virtual void do_signal_drag_end() override
    {
        g_DragSource = nullptr;
    }

    // Under gtk 3.24.8 dragging into the TreeView is not highlighting
    // entire TreeView widget, just the rectangle which has no entries
    // in it, so as a workaround highlight the parent container
@@ -10298,14 +10378,6 @@ public:
        if (m_nQueryTooltipSignalId)
            g_signal_handler_disconnect(m_pTreeView, m_nQueryTooltipSignalId);
        g_signal_handler_disconnect(m_pTreeView, m_nKeyPressSignalId);
        g_signal_handler_disconnect(m_pTreeView, m_nDragEndSignalId);
        g_signal_handler_disconnect(m_pTreeView, m_nDragBeginSignalId);
        if (m_nDragFailedSignalId)
            g_signal_handler_disconnect(m_pTreeView, m_nDragFailedSignalId);
        if (m_nDragDataDeleteignalId)
            g_signal_handler_disconnect(m_pTreeView, m_nDragDataDeleteignalId);
        if (m_nDragGetSignalId)
            g_signal_handler_disconnect(m_pTreeView, m_nDragGetSignalId);
        g_signal_handler_disconnect(m_pTreeView, m_nPopupMenuSignalId);
        GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore);
        g_signal_handler_disconnect(pModel, m_nRowDeletedSignalId);
@@ -11557,6 +11629,18 @@ public:
        return OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8);
    }

    virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants) override
    {
        do_enable_drag_source(rHelper, eDNDConstants);
    }

    virtual bool do_signal_drag_begin() override
    {
        if (m_aDragBeginHdl.Call(*this))
            return true;
        return false;
    }

    virtual ~GtkInstanceDrawingArea() override
    {
        g_object_steal_data(G_OBJECT(m_pDrawingArea), "g-lo-GtkInstanceDrawingArea");