weld SvxSearchDialog

I have to use the other way to specify an a11y role, both are implemented in
the vcl parser, but in my gtk3-3.24.7 the role tag crashes the gtk parser,
while the other route works fine.

The CONTENT_FLOWS_TO accessibility relation is another additional complexity
over the norm

Change-Id: Ia096bcbe9f00f9944e4e4d5ad9bb1a52d19c7b3f
Reviewed-on: https://gerrit.libreoffice.org/69569
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/svx/srchdlg.hxx b/include/svx/srchdlg.hxx
index 5b202ae..aa995ed 100644
--- a/include/svx/srchdlg.hxx
+++ b/include/svx/srchdlg.hxx
@@ -89,13 +89,13 @@ enum class SearchLabel
class SvxSearchDialog;
class SVX_DLLPUBLIC SvxSearchDialogWrapper : public SfxChildWindow
{
    VclPtr<SvxSearchDialog> dialog;
    std::shared_ptr<SvxSearchDialog> dialog;
public:
    SvxSearchDialogWrapper( vcl::Window*pParent, sal_uInt16 nId,
                            SfxBindings* pBindings, SfxChildWinInfo const * pInfo );

    virtual ~SvxSearchDialogWrapper () override;
    SvxSearchDialog *getDialog () { return dialog;}
    SvxSearchDialog *getDialog () { return dialog.get();}
    static void SetSearchLabel(const SearchLabel& rSL);
    static void SetSearchLabel(const OUString& sStr);
    static OUString GetSearchLabel();
@@ -109,18 +109,18 @@ public:

 */

class SvxSearchDialog : public SfxModelessDialog
class SVX_DLLPUBLIC SvxSearchDialog : public SfxModelessDialogController
{
friend class SvxSearchController;
friend class SvxSearchDialogWrapper;
friend class SvxJSearchOptionsDialog;

public:
    SvxSearchDialog( vcl::Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind );
    SvxSearchDialog(weld::Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind );
    virtual ~SvxSearchDialog() override;
    virtual void dispose() override;

    virtual bool    Close() override;
    virtual void    EndDialog() override;
    virtual void    Close() override;

    // Window
    virtual void    Activate() override;
@@ -132,74 +132,16 @@ public:

    TransliterationFlags        GetTransliterationFlags() const;

    void SetDocWin( vcl::Window* pDocWin ) { mpDocWin = pDocWin; }
    vcl::Window* GetDocWin() { return mpDocWin; }
    void SetDocWin(vcl::Window* pDocWin);
    void SetSrchFlag( bool bSuccess ) { mbSuccess = bSuccess; }
    bool GetSrchFlag() { return mbSuccess; }
    virtual css::uno::Reference< css::awt::XWindowPeer >
        GetComponentInterface( bool bCreate = true ) override;

    void            SetSaveToModule(bool b);

    void SetSearchLabel(const OUString& rStr) { m_pSearchLabel->SetText(rStr); }
    void SetSearchLabel(const OUString& rStr) { m_xSearchLabel->set_label(rStr); }

private:
    VclPtr<vcl::Window>         mpDocWin;
    bool            mbSuccess;

    VclPtr<VclFrame>       m_pSearchFrame;
    VclPtr<ComboBox>       m_pSearchLB;
    VclPtr<ListBox>        m_pSearchTmplLB;
    VclPtr<FixedText>      m_pSearchAttrText;
    VclPtr<FixedText>      m_pSearchLabel;

    VclPtr<VclFrame>       m_pReplaceFrame;
    VclPtr<ComboBox>       m_pReplaceLB;
    VclPtr<ListBox>        m_pReplaceTmplLB;
    VclPtr<FixedText>      m_pReplaceAttrText;

    VclPtr<PushButton>     m_pSearchBtn;
    VclPtr<PushButton>     m_pBackSearchBtn;
    VclPtr<PushButton>     m_pSearchAllBtn;
    VclPtr<PushButton>     m_pReplaceBtn;
    VclPtr<PushButton>     m_pReplaceAllBtn;

    VclPtr<VclFrame>       m_pComponentFrame;
    VclPtr<PushButton>     m_pSearchComponent1PB;
    VclPtr<PushButton>     m_pSearchComponent2PB;

    VclPtr<CheckBox>       m_pMatchCaseCB;
    VclPtr<CheckBox>       m_pSearchFormattedCB;
    VclPtr<CheckBox>       m_pWordBtn;

    VclPtr<PushButton>     m_pCloseBtn;
    VclPtr<CheckBox>       m_pIncludeDiacritics;
    VclPtr<CheckBox>       m_pIncludeKashida;
    VclPtr<VclExpander>    m_pOtherOptionsExpander;
    VclPtr<CheckBox>       m_pSelectionBtn;
    VclPtr<CheckBox>       m_pRegExpBtn;
    VclPtr<CheckBox>       m_pWildcardBtn;
    VclPtr<CheckBox>       m_pSimilarityBox;
    VclPtr<PushButton>     m_pSimilarityBtn;
    VclPtr<CheckBox>       m_pLayoutBtn;
    VclPtr<CheckBox>       m_pNotesBtn;
    VclPtr<CheckBox>       m_pJapMatchFullHalfWidthCB;
    VclPtr<CheckBox>       m_pJapOptionsCB;
    VclPtr<CheckBox>       m_pReplaceBackwardsCB;
    VclPtr<PushButton>     m_pJapOptionsBtn;

    VclPtr<PushButton>     m_pAttributeBtn;
    VclPtr<PushButton>     m_pFormatBtn;
    VclPtr<PushButton>     m_pNoFormatBtn;

    VclPtr<VclContainer>   m_pCalcGrid;
    VclPtr<FixedText>      m_pCalcSearchInFT;
    VclPtr<ListBox>        m_pCalcSearchInLB;
    VclPtr<FixedText>      m_pCalcSearchDirFT;
    VclPtr<RadioButton>    m_pRowsBtn;
    VclPtr<RadioButton>    m_pColumnsBtn;
    VclPtr<CheckBox>       m_pAllSheetsCB;

    bool            mbClosing;

    SfxBindings&    rBindings;
    bool            bWriter;
@@ -234,41 +176,95 @@ private:

    bool m_executingSubDialog = false;

    DECL_LINK( ModifyHdl_Impl, Edit&, void );
    DECL_LINK( FlagHdl_Impl, Button*, void );
    DECL_LINK( CommandHdl_Impl, Button*, void );
    DECL_LINK(TemplateHdl_Impl, Button*, void);
    DECL_LINK( FocusHdl_Impl, Control&, void );
    DECL_LINK( LBSelectHdl_Impl, ListBox&, void );
    DECL_LINK(LoseFocusHdl_Impl, Control&, void);
    DECL_LINK(FormatHdl_Impl, Button*, void);
    DECL_LINK(NoFormatHdl_Impl, Button*, void);
    DECL_LINK(AttributeHdl_Impl, Button*, void);
    DECL_LINK( TimeoutHdl_Impl, Timer*, void );
    void            ClickHdl_Impl(void const * pCtrl);
    std::unique_ptr<weld::Frame> m_xSearchFrame;
    std::unique_ptr<weld::ComboBox> m_xSearchLB;
    std::unique_ptr<weld::ComboBox> m_xSearchTmplLB;
    std::unique_ptr<weld::Label> m_xSearchAttrText;
    std::unique_ptr<weld::Label> m_xSearchLabel;

    void            Construct_Impl();
    void            InitControls_Impl();
    void            ShowOptionalControls_Impl();
    void            Init_Impl( bool bHasItemSet );
    void            InitAttrList_Impl( const SfxItemSet* pSSet,
    std::unique_ptr<weld::Frame> m_xReplaceFrame;
    std::unique_ptr<weld::ComboBox> m_xReplaceLB;
    std::unique_ptr<weld::ComboBox> m_xReplaceTmplLB;
    std::unique_ptr<weld::Label> m_xReplaceAttrText;

    std::unique_ptr<weld::Button> m_xSearchBtn;
    std::unique_ptr<weld::Button> m_xBackSearchBtn;
    std::unique_ptr<weld::Button> m_xSearchAllBtn;
    std::unique_ptr<weld::Button> m_xReplaceBtn;
    std::unique_ptr<weld::Button> m_xReplaceAllBtn;

    std::unique_ptr<weld::Frame> m_xComponentFrame;
    std::unique_ptr<weld::Button> m_xSearchComponent1PB;
    std::unique_ptr<weld::Button> m_xSearchComponent2PB;

    std::unique_ptr<weld::CheckButton> m_xMatchCaseCB;
    std::unique_ptr<weld::CheckButton> m_xSearchFormattedCB;
    std::unique_ptr<weld::CheckButton> m_xWordBtn;

    std::unique_ptr<weld::Button> m_xCloseBtn;
    std::unique_ptr<weld::CheckButton> m_xIncludeDiacritics;
    std::unique_ptr<weld::CheckButton> m_xIncludeKashida;
    std::unique_ptr<weld::Expander> m_xOtherOptionsExpander;
    std::unique_ptr<weld::CheckButton> m_xSelectionBtn;
    std::unique_ptr<weld::CheckButton> m_xRegExpBtn;
    std::unique_ptr<weld::CheckButton> m_xWildcardBtn;
    std::unique_ptr<weld::CheckButton> m_xSimilarityBox;
    std::unique_ptr<weld::Button> m_xSimilarityBtn;
    std::unique_ptr<weld::CheckButton> m_xLayoutBtn;
    std::unique_ptr<weld::CheckButton> m_xNotesBtn;
    std::unique_ptr<weld::CheckButton> m_xJapMatchFullHalfWidthCB;
    std::unique_ptr<weld::CheckButton> m_xJapOptionsCB;
    std::unique_ptr<weld::CheckButton> m_xReplaceBackwardsCB;
    std::unique_ptr<weld::Button> m_xJapOptionsBtn;

    std::unique_ptr<weld::Button> m_xAttributeBtn;
    std::unique_ptr<weld::Button> m_xFormatBtn;
    std::unique_ptr<weld::Button> m_xNoFormatBtn;

    std::unique_ptr<weld::Widget> m_xCalcGrid;
    std::unique_ptr<weld::Label> m_xCalcSearchInFT;
    std::unique_ptr<weld::ComboBox> m_xCalcSearchInLB;
    std::unique_ptr<weld::Label> m_xCalcSearchDirFT;
    std::unique_ptr<weld::RadioButton> m_xRowsBtn;
    std::unique_ptr<weld::RadioButton> m_xColumnsBtn;
    std::unique_ptr<weld::CheckButton> m_xAllSheetsCB;
    std::unique_ptr<weld::Label> m_xCalcStrFT;

    DECL_DLLPRIVATE_LINK( ModifyHdl_Impl, weld::ComboBox&, void );
    DECL_DLLPRIVATE_LINK( FlagHdl_Impl, weld::Button&, void );
    DECL_DLLPRIVATE_LINK( CommandHdl_Impl, weld::Button&, void );
    DECL_DLLPRIVATE_LINK(TemplateHdl_Impl, weld::Button&, void);
    DECL_DLLPRIVATE_LINK( FocusHdl_Impl, weld::Widget&, void );
    DECL_DLLPRIVATE_LINK( LBSelectHdl_Impl, weld::ComboBox&, void );
    DECL_DLLPRIVATE_LINK(LoseFocusHdl_Impl, weld::Widget&, void);
    DECL_DLLPRIVATE_LINK(FormatHdl_Impl, weld::Button&, void);
    DECL_DLLPRIVATE_LINK(NoFormatHdl_Impl, weld::Button&, void);
    DECL_DLLPRIVATE_LINK(AttributeHdl_Impl, weld::Button&, void);
    DECL_DLLPRIVATE_LINK( TimeoutHdl_Impl, Timer*, void );
    SVX_DLLPRIVATE void ClickHdl_Impl(const weld::Widget* pCtrl);

    SVX_DLLPRIVATE void Construct_Impl();
    SVX_DLLPRIVATE void InitControls_Impl();
    SVX_DLLPRIVATE void ShowOptionalControls_Impl();
    SVX_DLLPRIVATE void Init_Impl( bool bHasItemSet );
    SVX_DLLPRIVATE void InitAttrList_Impl( const SfxItemSet* pSSet,
                                       const SfxItemSet* pRSet );
    void            Remember_Impl( const OUString &rStr, bool bSearch );
    void            PaintAttrText_Impl();
    OUString&       BuildAttrText_Impl( OUString& rStr, bool bSrchFlag ) const;
    SVX_DLLPRIVATE void Remember_Impl( const OUString &rStr, bool bSearch );
    SVX_DLLPRIVATE void PaintAttrText_Impl();
    SVX_DLLPRIVATE OUString& BuildAttrText_Impl( OUString& rStr, bool bSrchFlag ) const;

    void            TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool );
    void            EnableControls_Impl( const SearchOptionFlags nFlags );
    void            EnableControl_Impl( Control const * pCtrl );
    void            SetItem_Impl( const SvxSearchItem* pItem );
    SVX_DLLPRIVATE void TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool );
    SVX_DLLPRIVATE void EnableControls_Impl( const SearchOptionFlags nFlags );
    SVX_DLLPRIVATE void EnableControl_Impl(const weld::Widget& rCtrl);
    SVX_DLLPRIVATE void SetItem_Impl( const SvxSearchItem* pItem );

    void            SetModifyFlag_Impl( const Control* pCtrl );
    void            SaveToModule_Impl();
    SVX_DLLPRIVATE void SetModifyFlag_Impl(const weld::Widget* pCtrl);
    SVX_DLLPRIVATE void SaveToModule_Impl();

    void            ApplyTransliterationFlags_Impl( TransliterationFlags nSettings );
    bool            IsOtherOptionsExpanded();
    SVX_DLLPRIVATE void ApplyTransliterationFlags_Impl( TransliterationFlags nSettings );
    SVX_DLLPRIVATE bool IsOtherOptionsExpanded();

    short executeSubDialog(VclAbstractDialog * dialog);
    SVX_DLLPRIVATE short executeSubDialog(VclAbstractDialog * dialog);
};

#endif
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 96f292c..a180243 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -141,6 +141,11 @@ public:
    virtual void set_accessible_relation_labeled_by(weld::Widget* pLabel) = 0;
    virtual void set_accessible_relation_label_for(weld::Widget* pLabeled) = 0;

    virtual void
    add_extra_accessible_relation(const css::accessibility::AccessibleRelation& rRelation)
        = 0;
    virtual void clear_extra_accessible_relations() = 0;

    virtual void set_tooltip_text(const OUString& rTip) = 0;
    virtual OUString get_tooltip_text() const = 0;

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index fff03ed..c109e80 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -67,6 +67,7 @@ enum class PointerStyle;

namespace com { namespace sun { namespace star {
namespace accessibility {
    struct AccessibleRelation;
    class XAccessible;
}

@@ -1252,6 +1253,9 @@ public:
    void                                SetAccessibleRelationMemberOf( vcl::Window* pMemberOf );
    vcl::Window*                        GetAccessibleRelationMemberOf() const;

    void                                AddExtraAccessibleRelation(const css::accessibility::AccessibleRelation &rRelation);
    const std::vector<css::accessibility::AccessibleRelation>& GetExtraAccessibleRelations() const;
    void                                ClearExtraAccessibleRelations();

    // to avoid sending accessibility events in cases like closing dialogs
    // by default checks complete parent path
diff --git a/sc/source/ui/view/tabvwshe.cxx b/sc/source/ui/view/tabvwshe.cxx
index 0059534..faeb5d0 100644
--- a/sc/source/ui/view/tabvwshe.cxx
+++ b/sc/source/ui/view/tabvwshe.cxx
@@ -233,11 +233,11 @@ void ScTabViewShell::ExecSearch( SfxRequest& rReq )

                    ScGlobal::SetSearchItem( *pSearchItem );
                    bool bSuccess = SearchAndReplace( pSearchItem, true, rReq.IsAPI() );
                    const SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
                    SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
                            SvxSearchDialogWrapper::GetChildWindowId());
                    if (pChildWindow)
                    {
                        SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetWindow());
                        SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetController().get());
                        if( pSearchDlg )
                        {
                            ScTabView* pTabView = GetViewData().GetView();
@@ -303,11 +303,11 @@ void ScTabViewShell::ExecSearch( SfxRequest& rReq )
                            rReq.IsAPI() ? SfxCallMode::API|SfxCallMode::SYNCHRON :
                                            SfxCallMode::RECORD,
                            { &aSearchItem });
                    const SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
                    SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
                            SvxSearchDialogWrapper::GetChildWindowId());
                    if (pChildWindow)
                    {
                        SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetWindow());
                        SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetController().get());
                        if( pSearchDlg )
                        {
                            ScTabView* pTabView = GetViewData().GetView();
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index df322f5..6c537dc 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -507,7 +507,7 @@ bool SdOutliner::StartSearchAndReplace (const SvxSearchItem* pSearchItem)
        if (pChildWin)
        {
            SvxSearchDialog* pSearchDlg =
                static_cast<SvxSearchDialog*>(pChildWin->GetWindow());
                static_cast<SvxSearchDialog*>(pChildWin->GetController().get());
            pSearchDlg->SetDocWin( pViewShell->GetActiveWindow() );
            pSearchDlg->SetSrchFlag(false);
        }
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index cf9808c..99522e3 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -13861,7 +13861,6 @@ svtools/source/uno/wizard/wizardpagecontroller.cxx
svtools/source/uno/wizard/wizardpagecontroller.hxx
svtools/source/uno/wizard/wizardshell.cxx
svtools/source/uno/wizard/wizardshell.hxx
svx/inc/AccessibleSvxFindReplaceDialog.hxx
svx/inc/AccessibleTableShape.hxx
svx/inc/GalleryControl.hxx
svx/inc/dragmt3d.hxx
@@ -13980,7 +13979,6 @@ svx/source/accessibility/AccessibleOLEShape.cxx
svx/source/accessibility/AccessibleShape.cxx
svx/source/accessibility/AccessibleShapeInfo.cxx
svx/source/accessibility/AccessibleShapeTreeInfo.cxx
svx/source/accessibility/AccessibleSvxFindReplaceDialog.cxx
svx/source/accessibility/AccessibleTextEventQueue.cxx
svx/source/accessibility/AccessibleTextEventQueue.hxx
svx/source/accessibility/AccessibleTextHelper.cxx
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index b9acb5e..b8043c4 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -89,7 +89,6 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
    svx/source/accessibility/AccessibleShape \
    svx/source/accessibility/AccessibleShapeInfo \
    svx/source/accessibility/AccessibleShapeTreeInfo \
    svx/source/accessibility/AccessibleSvxFindReplaceDialog \
    svx/source/accessibility/AccessibleTextEventQueue \
    svx/source/accessibility/AccessibleTextHelper \
    svx/source/accessibility/ChildrenManager \
diff --git a/svx/inc/AccessibleSvxFindReplaceDialog.hxx b/svx/inc/AccessibleSvxFindReplaceDialog.hxx
deleted file mode 100644
index a460dcc..0000000
--- a/svx/inc/AccessibleSvxFindReplaceDialog.hxx
+++ /dev/null
@@ -1,55 +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_INC_ACCESSIBLESVXFINDREPLACEDIALOG_HXX
#define INCLUDED_SVX_INC_ACCESSIBLESVXFINDREPLACEDIALOG_HXX

#include <toolkit/awt/vclxwindow.hxx>
#include <toolkit/awt/vclxaccessiblecomponent.hxx>
#include <toolkit/awt/vclxwindows.hxx>


class VCLXAccessibleSvxFindReplaceDialog : public VCLXAccessibleComponent
{
public:
    VCLXAccessibleSvxFindReplaceDialog(VCLXWindow* pVCLXindow);
    virtual ~VCLXAccessibleSvxFindReplaceDialog() override;
    virtual void FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet ) override;
    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;

};


class VCLXSvxFindReplaceDialog : public VCLXDialog
{
public:
    VCLXSvxFindReplaceDialog(vcl::Window* pSplDlg)
    {
        SetWindow(pSplDlg);
    }
private:
    virtual css::uno::Reference< css::accessibility::XAccessibleContext >  CreateAccessibleContext() override
    {
        return new VCLXAccessibleSvxFindReplaceDialog(this);
    }
};
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/accessibility/AccessibleSvxFindReplaceDialog.cxx b/svx/source/accessibility/AccessibleSvxFindReplaceDialog.cxx
deleted file mode 100644
index 1e0ca23..0000000
--- a/svx/source/accessibility/AccessibleSvxFindReplaceDialog.cxx
+++ /dev/null
@@ -1,95 +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 <AccessibleSvxFindReplaceDialog.hxx>
#include <svx/srchdlg.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <unotools/accessiblerelationsethelper.hxx>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessibleGetAccFlowTo.hpp>

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

VCLXAccessibleSvxFindReplaceDialog::VCLXAccessibleSvxFindReplaceDialog(VCLXWindow* pVCLXindow)
    :VCLXAccessibleComponent( pVCLXindow )
{

}

VCLXAccessibleSvxFindReplaceDialog::~VCLXAccessibleSvxFindReplaceDialog()
{
}

void VCLXAccessibleSvxFindReplaceDialog::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
{
    VCLXAccessibleComponent::FillAccessibleRelationSet( rRelationSet );
    VclPtr<vcl::Window> pDlg = GetWindow();
    if ( !pDlg )
        return;

    SvxSearchDialog* pSrchDlg = static_cast<SvxSearchDialog*>( pDlg.get() );
    vcl::Window* pDocWin = pSrchDlg->GetDocWin();
    if ( !pDocWin )
    {
        return;
    }
    Reference < css::accessibility::XAccessible > xDocAcc = pDocWin->GetAccessible();
    if ( !xDocAcc.is() )
    {
        return;
    }
    Reference< css::accessibility::XAccessibleGetAccFlowTo > xGetAccFlowTo( xDocAcc, UNO_QUERY );
    if ( !xGetAccFlowTo.is() )
    {
        return;
    }

    const sal_Int32 FORFINDREPLACEFLOWTO = 2;
    uno::Sequence<uno::Any> aAnySeq = xGetAccFlowTo->getAccFlowTo( Any(pSrchDlg->GetSrchFlag()),  FORFINDREPLACEFLOWTO );

    sal_Int32 nLen = aAnySeq.getLength();
    if ( nLen )
    {
        uno::Sequence< uno::Reference< uno::XInterface > > aSequence( nLen );
        for ( sal_Int32 i = 0; i < nLen; i++ )
        {
            uno::Reference < css::accessibility::XAccessible > xAcc;
            aAnySeq[i] >>= xAcc;
            aSequence[i] = xAcc;
        }
        rRelationSet.AddRelation( css::accessibility::AccessibleRelation( css::accessibility::AccessibleRelationType::CONTENT_FLOWS_TO, aSequence ) );
    }
}

// XServiceInfo


OUString VCLXAccessibleSvxFindReplaceDialog::getImplementationName()
{
    return OUString( "VCLXAccessibleSvxFindReplaceDialog" );
}


Sequence< OUString > VCLXAccessibleSvxFindReplaceDialog::getSupportedServiceNames()
{
    Sequence< OUString > aNames { "VCLXAccessibleSvxFindReplaceDialog" };
    return aNames;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx
index d23071a..c887d9c 100644
--- a/svx/source/dialog/srchdlg.cxx
+++ b/svx/source/dialog/srchdlg.cxx
@@ -34,6 +34,9 @@
#include <svl/cjkoptions.hxx>
#include <svl/ctloptions.hxx>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/accessibility/AccessibleRelation.hpp>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessibleGetAccFlowTo.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
@@ -58,7 +61,6 @@
#include <svx/svxitems.hrc>

#include <svl/srchitem.hxx>
#include <AccessibleSvxFindReplaceDialog.hxx>
#include <svx/pageitem.hxx>
#include "srchctrl.hxx"
#include <svx/dialmgr.hxx>
@@ -107,13 +109,14 @@ namespace o3tl {

namespace
{
    bool GetCheckBoxValue(const CheckBox *pBox)
    bool GetCheckBoxValue(const weld::CheckButton& rBox)
    {
        return pBox->IsEnabled() && pBox->IsChecked();
        return rBox.get_sensitive() && rBox.get_active();
    }
    bool GetNegatedCheckBoxValue(const CheckBox *pBox)

    bool GetNegatedCheckBoxValue(const weld::CheckButton& rBox)
    {
        return pBox->IsEnabled() && !pBox->IsChecked();
        return rBox.get_sensitive() && !rBox.get_active();
    }
}

@@ -142,7 +145,7 @@ struct SearchDlg_Impl
    }
};

static void ListToStrArr_Impl( sal_uInt16 nId, std::vector<OUString>& rStrLst, ComboBox& rCBox )
static void ListToStrArr_Impl( sal_uInt16 nId, std::vector<OUString>& rStrLst, weld::ComboBox& rCBox )
{
    const SfxStringListItem* pSrchItem =
        static_cast<const SfxStringListItem*>(SfxGetpApp()->GetItem( nId ));
@@ -154,7 +157,7 @@ static void ListToStrArr_Impl( sal_uInt16 nId, std::vector<OUString>& rStrLst, C
        for (const OUString & s : aLst)
        {
            rStrLst.push_back(s);
            rCBox.InsertEntry(s);
            rCBox.append_text(s);
        }
    }
}
@@ -173,13 +176,11 @@ SearchAttrItemList::SearchAttrItemList( const SearchAttrItemList& rList ) :
            (*this)[i].pItem = (*this)[i].pItem->Clone();
}


SearchAttrItemList::~SearchAttrItemList()
{
    Clear();
}


void SearchAttrItemList::Put( const SfxItemSet& rSet )
{
    if ( !rSet.Count() )
@@ -251,11 +252,11 @@ void SearchAttrItemList::Remove(size_t nPos)
    SrchAttrItemList::erase( begin() + nPos, begin() + nPos + nLen );
}

SvxSearchDialog::SvxSearchDialog( vcl::Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind )
    : SfxModelessDialog(&rBind, pChildWin, pParent, "FindReplaceDialog",
        "svx/ui/findreplacedialog.ui")
    , mpDocWin(nullptr)
SvxSearchDialog::SvxSearchDialog(weld::Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind)
    : SfxModelessDialogController(&rBind, pChildWin, pParent,
                                  "svx/ui/findreplacedialog.ui", "FindReplaceDialog")
    , mbSuccess(false)
    , mbClosing(false)
    , rBindings(rBind)
    , bWriter(false)
    , bSearch(true)
@@ -267,151 +268,84 @@ SvxSearchDialog::SvxSearchDialog( vcl::Window* pParent, SfxChildWindow* pChildWi
    , nModifyFlag(ModifyFlags::NONE)
    , pReplaceList(new SearchAttrItemList)
    , nTransliterationFlags(TransliterationFlags::NONE)
    , m_xSearchFrame(m_xBuilder->weld_frame("searchframe"))
    , m_xSearchLB(m_xBuilder->weld_combo_box("searchterm"))
    , m_xSearchTmplLB(m_xBuilder->weld_combo_box("searchlist"))
    , m_xSearchAttrText(m_xBuilder->weld_label("searchdesc"))
    , m_xSearchLabel(m_xBuilder->weld_label("searchlabel"))
    , m_xReplaceFrame(m_xBuilder->weld_frame("replaceframe"))
    , m_xReplaceLB(m_xBuilder->weld_combo_box("replaceterm"))
    , m_xReplaceTmplLB(m_xBuilder->weld_combo_box("replacelist"))
    , m_xReplaceAttrText(m_xBuilder->weld_label("replacedesc"))
    , m_xSearchBtn(m_xBuilder->weld_button("search"))
    , m_xBackSearchBtn(m_xBuilder->weld_button("backsearch"))
    , m_xSearchAllBtn(m_xBuilder->weld_button("searchall"))
    , m_xReplaceBtn(m_xBuilder->weld_button("replace"))
    , m_xReplaceAllBtn(m_xBuilder->weld_button("replaceall"))
    , m_xComponentFrame(m_xBuilder->weld_frame("componentframe"))
    , m_xSearchComponent1PB(m_xBuilder->weld_button("component1"))
    , m_xSearchComponent2PB(m_xBuilder->weld_button("component2"))
    , m_xMatchCaseCB(m_xBuilder->weld_check_button("matchcase"))
    , m_xSearchFormattedCB(m_xBuilder->weld_check_button("searchformatted"))
    , m_xWordBtn(m_xBuilder->weld_check_button("wholewords"))
    , m_xCloseBtn(m_xBuilder->weld_button("close"))
    , m_xIncludeDiacritics(m_xBuilder->weld_check_button("includediacritics"))
    , m_xIncludeKashida(m_xBuilder->weld_check_button("includekashida"))
    , m_xOtherOptionsExpander(m_xBuilder->weld_expander("OptionsExpander"))
    , m_xSelectionBtn(m_xBuilder->weld_check_button("selection"))
    , m_xRegExpBtn(m_xBuilder->weld_check_button("regexp"))
    , m_xWildcardBtn(m_xBuilder->weld_check_button("wildcard"))
    , m_xSimilarityBox(m_xBuilder->weld_check_button("similarity"))
    , m_xSimilarityBtn(m_xBuilder->weld_button("similaritybtn"))
    , m_xLayoutBtn(m_xBuilder->weld_check_button("layout"))
    , m_xNotesBtn(m_xBuilder->weld_check_button("notes"))
    , m_xJapMatchFullHalfWidthCB(m_xBuilder->weld_check_button("matchcharwidth"))
    , m_xJapOptionsCB(m_xBuilder->weld_check_button("soundslike"))
    , m_xReplaceBackwardsCB(m_xBuilder->weld_check_button("replace_backwards"))
    , m_xJapOptionsBtn(m_xBuilder->weld_button("soundslikebtn"))
    , m_xAttributeBtn(m_xBuilder->weld_button("attributes"))
    , m_xFormatBtn(m_xBuilder->weld_button("format"))
    , m_xNoFormatBtn(m_xBuilder->weld_button("noformat"))
    , m_xCalcGrid(m_xBuilder->weld_widget("calcgrid"))
    , m_xCalcSearchInFT(m_xBuilder->weld_label("searchinlabel"))
    , m_xCalcSearchInLB(m_xBuilder->weld_combo_box("calcsearchin"))
    , m_xCalcSearchDirFT(m_xBuilder->weld_label("searchdir"))
    , m_xRowsBtn(m_xBuilder->weld_radio_button("rows"))
    , m_xColumnsBtn(m_xBuilder->weld_radio_button("cols"))
    , m_xAllSheetsCB(m_xBuilder->weld_check_button("allsheets"))
    , m_xCalcStrFT(m_xBuilder->weld_label("entirecells"))
{
    get(m_pSearchFrame, "searchframe");
    get(m_pSearchLB, "searchterm");
    get(m_pSearchTmplLB, "searchlist");
    m_pSearchTmplLB->SetStyle(m_pSearchTmplLB->GetStyle() | WB_SORT);
    get(m_pSearchBtn, "search");
    get(m_pBackSearchBtn, "backsearch");
    get(m_pSearchAllBtn, "searchall");
    get(m_pSearchAttrText, "searchdesc");
    m_pSearchAttrText->SetStyle(m_pSearchAttrText->GetStyle() | WB_PATHELLIPSIS);
    m_pSearchAttrText->Hide();
    get(m_pSearchLabel, "searchlabel");
    m_pSearchLabel->SetStyle(m_pSearchLabel->GetStyle() | WB_PATHELLIPSIS);
    m_pSearchLabel->Show();
    m_xSearchTmplLB->make_sorted();
    m_xSearchAttrText->hide();
    m_xSearchLabel->show();

    get(m_pReplaceFrame, "replaceframe");
    get(m_pReplaceLB, "replaceterm");
    get(m_pReplaceTmplLB, "replacelist");
    m_pReplaceTmplLB->SetStyle(m_pReplaceTmplLB->GetStyle() | WB_SORT);
    get(m_pReplaceBtn, "replace");
    get(m_pReplaceAllBtn, "replaceall");
    get(m_pReplaceAttrText, "replacedesc");
    m_pReplaceAttrText->SetStyle(m_pReplaceAttrText->GetStyle() | WB_PATHELLIPSIS);
    m_pReplaceAttrText->Hide();
    m_xReplaceTmplLB->make_sorted();
    m_xReplaceAttrText->hide();

    get(m_pComponentFrame, "componentframe");
    get(m_pSearchComponent1PB, "component1");
    get(m_pSearchComponent2PB, "component2");
    aCalcStr = m_xCalcStrFT->get_label();

    get(m_pMatchCaseCB, "matchcase");
    get(m_pSearchFormattedCB, "searchformatted");
    get(m_pWordBtn, "wholewords");
    aCalcStr = get<FixedText>("entirecells")->GetText();

    get(m_pCloseBtn, "close");

    get(m_pOtherOptionsExpander, "OptionsExpander");
    get(m_pIncludeDiacritics, "includediacritics");
    get(m_pIncludeKashida, "includekashida");
    get(m_pSelectionBtn, "selection");
    get(m_pReplaceBackwardsCB, "replace_backwards");
    get(m_pRegExpBtn, "regexp");
    get(m_pWildcardBtn, "wildcard");
    get(m_pSimilarityBox, "similarity");
    get(m_pSimilarityBtn, "similaritybtn");
    get(m_pLayoutBtn, "layout");
    get(m_pNotesBtn, "notes");
    get(m_pJapMatchFullHalfWidthCB, "matchcharwidth");
    get(m_pJapOptionsCB, "soundslike");
    get(m_pJapOptionsBtn, "soundslikebtn");

    get(m_pAttributeBtn, "attributes");
    get(m_pFormatBtn, "format");
    get(m_pNoFormatBtn, "noformat");

    get(m_pCalcGrid, "calcgrid");
    get(m_pCalcSearchInFT, "searchinlabel");
    get(m_pCalcSearchInLB, "calcsearchin");
    get(m_pCalcSearchDirFT, "searchdir");
    get(m_pRowsBtn, "rows");
    get(m_pColumnsBtn, "cols");
    get(m_pAllSheetsCB, "allsheets");

    // m_pSimilarityBtn->set_height_request(m_pSimilarityBox->get_preferred_size().Height());
    // m_pJapOptionsBtn->set_height_request(m_pJapOptionsCB->get_preferred_size().Height());
    // m_xSimilarityBtn->set_height_request(m_xSimilarityBox->get_preferred_size().Height());
    // m_xJapOptionsBtn->set_height_request(m_xJapOptionsCB->get_preferred_size().Height());

    //tdf#122322
    nRememberSize = officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();

    long nTermWidth = approximate_char_width() * 32;
    m_pSearchLB->set_width_request(nTermWidth);
    m_pSearchTmplLB->set_width_request(nTermWidth);
    m_pReplaceLB->set_width_request(nTermWidth);
    m_pReplaceTmplLB->set_width_request(nTermWidth);
    auto nTermWidth = m_xSearchLB->get_approximate_digit_width() * 28;
    m_xSearchLB->set_size_request(nTermWidth, -1);
    m_xSearchTmplLB->set_size_request(nTermWidth, -1);
    m_xReplaceLB->set_size_request(nTermWidth, -1);
    m_xReplaceTmplLB->set_size_request(nTermWidth, -1);

    Construct_Impl();
}


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

void SvxSearchDialog::dispose()
{
    Hide();

    rBindings.EnterRegistrations();
    pSearchController.reset();
    pOptionsController.reset();
    pFamilyController.reset();
    rBindings.LeaveRegistrations();

    pSearchItem.reset();
    pImpl.reset();
    pSearchList.reset();
    pReplaceList.reset();
    mpDocWin.clear();
    m_pSearchFrame.clear();
    m_pSearchLB.clear();
    m_pSearchTmplLB.clear();
    m_pSearchAttrText.clear();
    m_pSearchLabel.clear();
    m_pReplaceFrame.clear();
    m_pReplaceLB.clear();
    m_pReplaceTmplLB.clear();
    m_pReplaceAttrText.clear();
    m_pSearchBtn.clear();
    m_pBackSearchBtn.clear();
    m_pSearchAllBtn.clear();
    m_pReplaceBtn.clear();
    m_pReplaceAllBtn.clear();
    m_pComponentFrame.clear();
    m_pSearchComponent1PB.clear();
    m_pSearchComponent2PB.clear();
    m_pMatchCaseCB.clear();
    m_pSearchFormattedCB.clear();
    m_pWordBtn.clear();
    m_pCloseBtn.clear();
    m_pIncludeDiacritics.clear();
    m_pIncludeKashida.clear();
    m_pOtherOptionsExpander.clear();
    m_pSelectionBtn.clear();
    m_pReplaceBackwardsCB.clear();
    m_pRegExpBtn.clear();
    m_pWildcardBtn.clear();
    m_pSimilarityBox.clear();
    m_pSimilarityBtn.clear();
    m_pLayoutBtn.clear();
    m_pNotesBtn.clear();
    m_pJapMatchFullHalfWidthCB.clear();
    m_pJapOptionsCB.clear();
    m_pJapOptionsBtn.clear();
    m_pAttributeBtn.clear();
    m_pFormatBtn.clear();
    m_pNoFormatBtn.clear();
    m_pCalcGrid.clear();
    m_pCalcSearchInFT.clear();
    m_pCalcSearchInLB.clear();
    m_pCalcSearchDirFT.clear();
    m_pRowsBtn.clear();
    m_pColumnsBtn.clear();
    m_pAllSheetsCB.clear();
    SfxModelessDialog::dispose();
}

void SvxSearchDialog::Construct_Impl()
@@ -422,20 +356,20 @@ void SvxSearchDialog::Construct_Impl()
        LINK( this, SvxSearchDialog, TimeoutHdl_Impl ) );
    EnableControls_Impl( SearchOptionFlags::NONE );

    // Store old Text from m_pWordBtn
    // Store old Text from m_xWordBtn
    aCalcStr += "#";
    aCalcStr += m_pWordBtn->GetText();
    aCalcStr += m_xWordBtn->get_label();

    aLayoutStr = SvxResId( RID_SVXSTR_SEARCH_STYLES );
    aLayoutWriterStr = SvxResId( RID_SVXSTR_WRITER_STYLES );
    aLayoutCalcStr = SvxResId( RID_SVXSTR_CALC_STYLES );
    aStylesStr = m_pLayoutBtn->GetText();
    aStylesStr = m_xLayoutBtn->get_label();

    // Get stored search-strings from the application
    ListToStrArr_Impl(SID_SEARCHDLG_SEARCHSTRINGS,
                       aSearchStrings, *m_pSearchLB);
                       aSearchStrings, *m_xSearchLB);
    ListToStrArr_Impl(SID_SEARCHDLG_REPLACESTRINGS,
                       aReplaceStrings, *m_pReplaceLB);
                       aReplaceStrings, *m_xReplaceLB);

    InitControls_Impl();

@@ -467,25 +401,25 @@ void SvxSearchDialog::Construct_Impl()
    SvtCJKOptions aCJKOptions;
    if(!aCJKOptions.IsJapaneseFindEnabled())
    {
        m_pJapOptionsCB->Check( false );
        m_pJapOptionsCB->Hide();
        m_pJapOptionsBtn->Hide();
        m_xJapOptionsCB->set_active( false );
        m_xJapOptionsCB->hide();
        m_xJapOptionsBtn->hide();
    }
    if(!aCJKOptions.IsCJKFontEnabled())
    {
        m_pJapMatchFullHalfWidthCB->Hide();
        m_xJapMatchFullHalfWidthCB->hide();
    }
    SvtCTLOptions aCTLOptions;
    // Do not disable and hide the m_pIncludeDiacritics button.
    // Do not disable and hide the m_xIncludeDiacritics button.
    // Include Diacritics == Not Ignore Diacritics => A does not match A-Umlaut (Diaeresis).
    // Confusingly these have negated names (following the UI) but the actual
    // transliteration is to *ignore* diacritics if "included" (sensitive) is
    // _not_ checked.
    if(!aCTLOptions.IsCTLFontEnabled())
    {
        m_pIncludeDiacritics->Check( true );
        m_pIncludeKashida->Check( true );
        m_pIncludeKashida->Hide();
        m_xIncludeDiacritics->set_active( true );
        m_xIncludeKashida->set_active( true );
        m_xIncludeKashida->hide();
    }
    //component extension - show component search buttons if the commands
    // vnd.sun.star::SearchViaComponent1 and 2 are supported
@@ -524,32 +458,38 @@ void SvxSearchDialog::Construct_Impl()
                OUString sTemp;
                uno::Any aRet = xDirectAccess->getByName("ComponentSearchGroupLabel");
                aRet >>= sTemp;
                m_pComponentFrame->get_label_widget()->SetText(sTemp);
                m_xComponentFrame->set_label(sTemp);
                aRet = xDirectAccess->getByName("ComponentSearchCommandLabel1");
                aRet >>= sTemp;
                m_pSearchComponent1PB->SetText( sTemp );
                m_xSearchComponent1PB->set_label( sTemp );
                aRet = xDirectAccess->getByName("ComponentSearchCommandLabel2");
                aRet >>= sTemp;
                m_pSearchComponent2PB->SetText( sTemp );
                m_xSearchComponent2PB->set_label( sTemp );
            }
        }
        catch(uno::Exception&){}

        if(!m_pSearchComponent1PB->GetText().isEmpty() && bSearchComponent1 )
        if(!m_xSearchComponent1PB->get_label().isEmpty() && bSearchComponent1 )
        {
            m_pComponentFrame->Show();
            m_pSearchComponent1PB->Show();
            m_xComponentFrame->show();
            m_xSearchComponent1PB->show();
        }
        if( !m_pSearchComponent2PB->GetText().isEmpty() )
        if( !m_xSearchComponent2PB->get_label().isEmpty() )
        {
            m_pComponentFrame->Show();
            m_pSearchComponent2PB->Show();
            m_xComponentFrame->show();
            m_xSearchComponent2PB->show();
        }
    }
}

void SvxSearchDialog::EndDialog()
{
    mbClosing = true;
    SfxModelessDialogController::EndDialog();
    mbClosing = false;
}

bool SvxSearchDialog::Close()
void SvxSearchDialog::Close()
{
    // remember strings
    if (!aSearchStrings.empty())
@@ -560,34 +500,38 @@ bool SvxSearchDialog::Close()

    // save settings to configuration
    SvtSearchOptions aOpt;
    aOpt.SetWholeWordsOnly          ( m_pWordBtn->IsChecked() );
    aOpt.SetBackwards               ( m_pReplaceBackwardsCB->IsChecked() );
    aOpt.SetUseRegularExpression    ( m_pRegExpBtn->IsChecked() );
    aOpt.SetUseWildcard             ( m_pWildcardBtn->IsChecked() );
    aOpt.SetSearchForStyles         ( m_pLayoutBtn->IsChecked() );
    aOpt.SetSimilaritySearch        ( m_pSimilarityBox->IsChecked() );
    aOpt.SetUseAsianOptions         ( m_pJapOptionsCB->IsChecked() );
    aOpt.SetNotes                   ( m_pNotesBtn->IsChecked() );
    aOpt.SetIgnoreDiacritics_CTL    ( !m_pIncludeDiacritics->IsChecked() );
    aOpt.SetIgnoreKashida_CTL       ( !m_pIncludeKashida->IsChecked() );
    aOpt.SetSearchFormatted         ( m_pSearchFormattedCB->IsChecked() );
    aOpt.SetWholeWordsOnly          ( m_xWordBtn->get_active() );
    aOpt.SetBackwards               ( m_xReplaceBackwardsCB->get_active() );
    aOpt.SetUseRegularExpression    ( m_xRegExpBtn->get_active() );
    aOpt.SetUseWildcard             ( m_xWildcardBtn->get_active() );
    aOpt.SetSearchForStyles         ( m_xLayoutBtn->get_active() );
    aOpt.SetSimilaritySearch        ( m_xSimilarityBox->get_active() );
    aOpt.SetUseAsianOptions         ( m_xJapOptionsCB->get_active() );
    aOpt.SetNotes                   ( m_xNotesBtn->get_active() );
    aOpt.SetIgnoreDiacritics_CTL    ( !m_xIncludeDiacritics->get_active() );
    aOpt.SetIgnoreKashida_CTL       ( !m_xIncludeKashida->get_active() );
    aOpt.SetSearchFormatted         ( m_xSearchFormattedCB->get_active() );
    aOpt.Commit();

    if (mbClosing)
        return;

    const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
    rBindings.GetDispatcher()->Execute( FID_SEARCH_OFF, SfxCallMode::SLOT, ppArgs );
    rBindings.Execute( SID_SEARCH_DLG );
    rBindings.Invalidate(SID_SEARCH_DLG);

    return true;
    SfxViewShell* pViewShell = SfxViewShell::Current();
    if (pViewShell)
        pViewShell->GetViewFrame()->ToggleChildWindow(SID_SEARCH_DLG);
}


TransliterationFlags SvxSearchDialog::GetTransliterationFlags() const
{
    if (!m_pMatchCaseCB->IsChecked())
    if (!m_xMatchCaseCB->get_active())
        nTransliterationFlags |=  TransliterationFlags::IGNORE_CASE;
    else
        nTransliterationFlags &= ~TransliterationFlags::IGNORE_CASE;
    if ( !m_pJapMatchFullHalfWidthCB->IsChecked())
    if ( !m_xJapMatchFullHalfWidthCB->get_active())
        nTransliterationFlags |=  TransliterationFlags::IGNORE_WIDTH;
    else
        nTransliterationFlags &= ~TransliterationFlags::IGNORE_WIDTH;
@@ -604,97 +548,95 @@ void SvxSearchDialog::ApplyTransliterationFlags_Impl( TransliterationFlags nSett
{
    nTransliterationFlags = nSettings;
    bool bVal(nSettings & TransliterationFlags::IGNORE_CASE);
    m_pMatchCaseCB->Check( !bVal );
    m_xMatchCaseCB->set_active( !bVal );
    bVal = bool(nSettings & TransliterationFlags::IGNORE_WIDTH);
    m_pJapMatchFullHalfWidthCB->Check( !bVal );
    m_xJapMatchFullHalfWidthCB->set_active( !bVal );
}


bool SvxSearchDialog::IsOtherOptionsExpanded()
{
    return m_pReplaceBackwardsCB->IsChecked() ||
           m_pSelectionBtn->IsChecked() ||
           m_pRegExpBtn->IsChecked() ||
           m_pLayoutBtn->IsChecked() ||
           m_pSimilarityBox->IsChecked() ||
           m_pJapMatchFullHalfWidthCB->IsChecked() ||
           m_pJapOptionsCB->IsChecked() ||
           m_pWildcardBtn->IsChecked() ||
           m_pNotesBtn->IsChecked() ||
           m_pIncludeKashida->IsChecked() ||
           m_pIncludeDiacritics->IsChecked();
    return m_xReplaceBackwardsCB->get_active() ||
           m_xSelectionBtn->get_active() ||
           m_xRegExpBtn->get_active() ||
           m_xLayoutBtn->get_active() ||
           m_xSimilarityBox->get_active() ||
           m_xJapMatchFullHalfWidthCB->get_active() ||
           m_xJapOptionsCB->get_active() ||
           m_xWildcardBtn->get_active() ||
           m_xNotesBtn->get_active() ||
           m_xIncludeKashida->get_active() ||
           m_xIncludeDiacritics->get_active();
}


void SvxSearchDialog::Activate()
{
    // apply possible transliteration changes of the SvxSearchItem member
    DBG_ASSERT( pSearchItem, "SearchItem missing" );
    if (pSearchItem)
    {
        m_pMatchCaseCB->Check( pSearchItem->GetExact() );
        m_pJapMatchFullHalfWidthCB->Check( !pSearchItem->IsMatchFullHalfWidthForms() );
        m_xMatchCaseCB->set_active( pSearchItem->GetExact() );
        m_xJapMatchFullHalfWidthCB->set_active( !pSearchItem->IsMatchFullHalfWidthForms() );
    }

    SfxModelessDialog::Activate();
    SfxModelessDialogController::Activate();
}


void SvxSearchDialog::InitControls_Impl()
{
    // CaseSensitives AutoComplete
    m_pSearchLB->EnableAutocomplete( true, true );
    m_pSearchLB->Show();
    m_pReplaceLB->EnableAutocomplete( true, true );
    m_pReplaceLB->Show();
    m_xSearchLB->set_entry_completion( true, true );
    m_xSearchLB->show();
    m_xReplaceLB->set_entry_completion( true, true );
    m_xReplaceLB->show();

    m_pFormatBtn->Disable();
    m_pAttributeBtn->Disable();
    m_xFormatBtn->set_sensitive(false);
    m_xAttributeBtn->set_sensitive(false);

    m_pSearchLB->SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
    m_pReplaceLB->SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
    m_xSearchLB->connect_changed( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
    m_xReplaceLB->connect_changed( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );

    Link<Control&,void> aLink = LINK( this, SvxSearchDialog, FocusHdl_Impl );
    m_pSearchLB->SetGetFocusHdl( aLink );
    m_pReplaceLB->SetGetFocusHdl( aLink );
    Link<weld::Widget&,void> aLink = LINK( this, SvxSearchDialog, FocusHdl_Impl );
    m_xSearchLB->connect_focus_in( aLink );
    m_xReplaceLB->connect_focus_in( aLink );

    aLink = LINK( this, SvxSearchDialog, LoseFocusHdl_Impl );
    m_pSearchLB->SetLoseFocusHdl( aLink );
    m_pReplaceLB->SetLoseFocusHdl( aLink );
    m_xSearchLB->connect_focus_out( aLink );
    m_xReplaceLB->connect_focus_out( aLink );

    m_pSearchTmplLB->SetLoseFocusHdl( aLink );
    m_pReplaceTmplLB->SetLoseFocusHdl( aLink );
    m_xSearchTmplLB->connect_focus_out( aLink );
    m_xReplaceTmplLB->connect_focus_out( aLink );

    Link<Button*,void> aLink2 = LINK( this, SvxSearchDialog, CommandHdl_Impl );
    m_pSearchBtn->SetClickHdl( aLink2 );
    m_pBackSearchBtn->SetClickHdl( aLink2 );
    m_pSearchAllBtn->SetClickHdl( aLink2 );
    m_pReplaceBtn->SetClickHdl( aLink2 );
    m_pReplaceAllBtn->SetClickHdl( aLink2 );
    m_pCloseBtn->SetClickHdl( aLink2 );
    m_pSimilarityBtn->SetClickHdl( aLink2 );
    m_pJapOptionsBtn->SetClickHdl( aLink2 );
    m_pSearchComponent1PB->SetClickHdl( aLink2 );
    m_pSearchComponent2PB->SetClickHdl( aLink2 );
    Link<weld::Button&,void> aLink2 = LINK( this, SvxSearchDialog, CommandHdl_Impl );
    m_xSearchBtn->connect_clicked( aLink2 );
    m_xBackSearchBtn->connect_clicked( aLink2 );
    m_xSearchAllBtn->connect_clicked( aLink2 );
    m_xReplaceBtn->connect_clicked( aLink2 );
    m_xReplaceAllBtn->connect_clicked( aLink2 );
    m_xCloseBtn->connect_clicked( aLink2 );
    m_xSimilarityBtn->connect_clicked( aLink2 );
    m_xJapOptionsBtn->connect_clicked( aLink2 );
    m_xSearchComponent1PB->connect_clicked( aLink2 );
    m_xSearchComponent2PB->connect_clicked( aLink2 );

    aLink2 = LINK( this, SvxSearchDialog, FlagHdl_Impl );
    m_pReplaceBackwardsCB->SetClickHdl( aLink2 );
    m_pWordBtn->SetClickHdl( aLink2 );
    m_pSelectionBtn->SetClickHdl( aLink2 );
    m_pMatchCaseCB->SetClickHdl( aLink2 );
    m_pRegExpBtn->SetClickHdl( aLink2 );
    m_pWildcardBtn->SetClickHdl( aLink2 );
    m_pNotesBtn->SetClickHdl( aLink2 );
    m_pSimilarityBox->SetClickHdl( aLink2 );
    m_pJapOptionsCB->SetClickHdl( aLink2 );
    m_pJapMatchFullHalfWidthCB->SetClickHdl( aLink2 );
    m_pIncludeDiacritics->SetClickHdl( aLink2 );
    m_pIncludeKashida->SetClickHdl( aLink2 );
    m_pLayoutBtn->SetClickHdl( LINK( this, SvxSearchDialog, TemplateHdl_Impl ) );
    m_pFormatBtn->SetClickHdl( LINK( this, SvxSearchDialog, FormatHdl_Impl ) );
    m_pNoFormatBtn->SetClickHdl(
    m_xReplaceBackwardsCB->connect_clicked( aLink2 );
    m_xWordBtn->connect_clicked( aLink2 );
    m_xSelectionBtn->connect_clicked( aLink2 );
    m_xMatchCaseCB->connect_clicked( aLink2 );
    m_xRegExpBtn->connect_clicked( aLink2 );
    m_xWildcardBtn->connect_clicked( aLink2 );
    m_xNotesBtn->connect_clicked( aLink2 );
    m_xSimilarityBox->connect_clicked( aLink2 );
    m_xJapOptionsCB->connect_clicked( aLink2 );
    m_xJapMatchFullHalfWidthCB->connect_clicked( aLink2 );
    m_xIncludeDiacritics->connect_clicked( aLink2 );
    m_xIncludeKashida->connect_clicked( aLink2 );
    m_xLayoutBtn->connect_clicked( LINK( this, SvxSearchDialog, TemplateHdl_Impl ) );
    m_xFormatBtn->connect_clicked( LINK( this, SvxSearchDialog, FormatHdl_Impl ) );
    m_xNoFormatBtn->connect_clicked(
        LINK( this, SvxSearchDialog, NoFormatHdl_Impl ) );
    m_pAttributeBtn->SetClickHdl(
    m_xAttributeBtn->connect_clicked(
        LINK( this, SvxSearchDialog, AttributeHdl_Impl ) );
}

@@ -734,36 +676,36 @@ void SvxSearchDialog::ShowOptionalControls_Impl()
        eFactory == SvtModuleOptions::EFactory::WRITERGLOBAL;
    bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;

    m_pLayoutBtn->Show(!bDrawApp);
    m_pNotesBtn->Show(bWriterApp);
    m_pRegExpBtn->Show(!bDrawApp);
    m_pWildcardBtn->Show(bCalcApp); /* TODO:WILDCARD enable for other apps if hey handle it */
    m_pReplaceBackwardsCB->Show();
    m_pSimilarityBox->Show();
    m_pSimilarityBtn->Show();
    m_pSelectionBtn->Show();
    m_pIncludeDiacritics->Show();
    m_pIncludeKashida->Show(aCTLOptions.IsCTLFontEnabled());
    m_pJapMatchFullHalfWidthCB->Show(aCJKOptions.IsCJKFontEnabled());
    m_pJapOptionsCB->Show(aCJKOptions.IsJapaneseFindEnabled());
    m_pJapOptionsBtn->Show(aCJKOptions.IsJapaneseFindEnabled());
    m_xLayoutBtn->set_visible(!bDrawApp);
    m_xNotesBtn->set_visible(bWriterApp);
    m_xRegExpBtn->set_visible(!bDrawApp);
    m_xWildcardBtn->set_visible(bCalcApp); /* TODO:WILDCARD enable for other apps if hey handle it */
    m_xReplaceBackwardsCB->show();
    m_xSimilarityBox->show();
    m_xSimilarityBtn->show();
    m_xSelectionBtn->show();
    m_xIncludeDiacritics->show();
    m_xIncludeKashida->set_visible(aCTLOptions.IsCTLFontEnabled());
    m_xJapMatchFullHalfWidthCB->set_visible(aCJKOptions.IsCJKFontEnabled());
    m_xJapOptionsCB->set_visible(aCJKOptions.IsJapaneseFindEnabled());
    m_xJapOptionsBtn->set_visible(aCJKOptions.IsJapaneseFindEnabled());

    if (bWriter)
    {
        m_pAttributeBtn->Show();
        m_pFormatBtn->Show();
        m_pNoFormatBtn->Show();
        m_xAttributeBtn->show();
        m_xFormatBtn->show();
        m_xNoFormatBtn->show();
    }

    if (bCalcApp)
    {
        m_pCalcSearchInFT->Show();
        m_pCalcSearchInLB->Show();
        m_pCalcSearchDirFT->Show();
        m_pRowsBtn->Show();
        m_pColumnsBtn->Show();
        m_pAllSheetsCB->Show();
        m_pSearchFormattedCB->Show();
        m_xCalcSearchInFT->show();
        m_xCalcSearchInLB->show();
        m_xCalcSearchDirFT->show();
        m_xRowsBtn->show();
        m_xColumnsBtn->show();
        m_xAllSheetsCB->show();
        m_xSearchFormattedCB->show();
    }
}

@@ -802,45 +744,45 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
    bWriter = ( pSearchItem->GetAppFlag() == SvxSearchApp::WRITER );

    if ( !( nModifyFlag & ModifyFlags::Word ) )
         m_pWordBtn->Check( pSearchItem->GetWordOnly() );
         m_xWordBtn->set_active( pSearchItem->GetWordOnly() );
    if ( !( nModifyFlag & ModifyFlags::Exact ) )
        m_pMatchCaseCB->Check( pSearchItem->GetExact() );
        m_xMatchCaseCB->set_active( pSearchItem->GetExact() );
    if ( !( nModifyFlag & ModifyFlags::Backwards ) )
        m_pReplaceBackwardsCB->Check( bReplaceBackwards ); //adjustment to replace backwards
        m_xReplaceBackwardsCB->set_active( bReplaceBackwards ); //adjustment to replace backwards
    if ( !( nModifyFlag & ModifyFlags::Notes ) )
        m_pNotesBtn->Check( pSearchItem->GetNotes() );
        m_xNotesBtn->set_active( pSearchItem->GetNotes() );
    if ( !( nModifyFlag & ModifyFlags::Selection ) )
        m_pSelectionBtn->Check( pSearchItem->GetSelection() );
        m_xSelectionBtn->set_active( pSearchItem->GetSelection() );
    if ( !( nModifyFlag & ModifyFlags::Regexp ) )
        m_pRegExpBtn->Check( pSearchItem->GetRegExp() );
        m_xRegExpBtn->set_active( pSearchItem->GetRegExp() );
    if ( !( nModifyFlag & ModifyFlags::Wildcard ) )
        m_pWildcardBtn->Check( pSearchItem->GetWildcard() );
        m_xWildcardBtn->set_active( pSearchItem->GetWildcard() );
    if ( !( nModifyFlag & ModifyFlags::Layout ) )
        m_pLayoutBtn->Check( pSearchItem->GetPattern() );
    if (m_pNotesBtn->IsChecked())
        m_pLayoutBtn->Disable();
    m_pSimilarityBox->Check( pSearchItem->IsLevenshtein() );
    if ( m_pJapOptionsCB->IsVisible() )
        m_pJapOptionsCB->Check( pSearchItem->IsUseAsianOptions() );
    m_pIncludeDiacritics->Check( !aOpt.IsIgnoreDiacritics_CTL() );
    if ( m_pIncludeKashida->IsVisible() )
        m_pIncludeKashida->Check( !aOpt.IsIgnoreKashida_CTL() );
        m_xLayoutBtn->set_active( pSearchItem->GetPattern() );
    if (m_xNotesBtn->get_active())
        m_xLayoutBtn->set_sensitive(false);
    m_xSimilarityBox->set_active( pSearchItem->IsLevenshtein() );
    if ( m_xJapOptionsCB->get_visible() )
        m_xJapOptionsCB->set_active( pSearchItem->IsUseAsianOptions() );
    m_xIncludeDiacritics->set_active( !aOpt.IsIgnoreDiacritics_CTL() );
    if ( m_xIncludeKashida->get_visible() )
        m_xIncludeKashida->set_active( !aOpt.IsIgnoreKashida_CTL() );
    if ( SvxSearchDialog::IsOtherOptionsExpanded() )
        m_pOtherOptionsExpander->set_expanded( true );
        m_xOtherOptionsExpander->set_expanded( true );
    ApplyTransliterationFlags_Impl( pSearchItem->GetTransliterationFlags() );

    ShowOptionalControls_Impl();

    if ( pSearchItem->GetAppFlag() == SvxSearchApp::CALC )
    {
        m_pCalcGrid->Show();
        m_pSearchFormattedCB->Check( aOpt.IsSearchFormatted() );
        Link<Button*,void> aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
        m_pCalcSearchInLB->SetSelectHdl( LINK( this, SvxSearchDialog, LBSelectHdl_Impl ) );
        m_pRowsBtn->SetClickHdl( aLink );
        m_pColumnsBtn->SetClickHdl( aLink );
        m_pAllSheetsCB->SetClickHdl( aLink );
        m_pSearchFormattedCB->SetClickHdl( aLink );
        m_xCalcGrid->show();
        m_xSearchFormattedCB->set_active( aOpt.IsSearchFormatted() );
        Link<weld::Button&,void> aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
        m_xCalcSearchInLB->connect_changed( LINK( this, SvxSearchDialog, LBSelectHdl_Impl ) );
        m_xRowsBtn->connect_clicked( aLink );
        m_xColumnsBtn->connect_clicked( aLink );
        m_xAllSheetsCB->connect_clicked( aLink );
        m_xSearchFormattedCB->connect_clicked( aLink );

        ModifyFlags nModifyFlagCheck;
        switch ( pSearchItem->GetCellType() )
@@ -861,46 +803,46 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
                std::abort(); // cannot happen
        }
        if ( !(nModifyFlag & nModifyFlagCheck) )
            m_pCalcSearchInLB->SelectEntryPos( static_cast<sal_Int32>(pSearchItem->GetCellType()) );
            m_xCalcSearchInLB->set_active( static_cast<sal_Int32>(pSearchItem->GetCellType()) );

        m_pWordBtn->SetText( aCalcStr.getToken( 0, '#' ) );
        m_xWordBtn->set_label( aCalcStr.getToken( 0, '#' ) );

        if ( pSearchItem->GetRowDirection() &&
             !( nModifyFlag & ModifyFlags::Rows ) )
            m_pRowsBtn->Check();
            m_xRowsBtn->set_active(true);
        else if ( !pSearchItem->GetRowDirection() &&
                  !( nModifyFlag & ModifyFlags::Columns ) )
            m_pColumnsBtn->Check();
            m_xColumnsBtn->set_active(true);

        if ( !( nModifyFlag & ModifyFlags::AllTables ) )
            m_pAllSheetsCB->Check( pSearchItem->IsAllTables() );
            m_xAllSheetsCB->set_active( pSearchItem->IsAllTables() );

        // only look for formatting in Writer
        m_pFormatBtn->Hide();
        m_pNoFormatBtn->Hide();
        m_pAttributeBtn->Hide();
        m_xFormatBtn->hide();
        m_xNoFormatBtn->hide();
        m_xAttributeBtn->hide();
    }
    else
    {
        m_pSearchFormattedCB->Hide();
        m_pWordBtn->SetText( aCalcStr.getToken( 1, '#' ) );
        m_xSearchFormattedCB->hide();
        m_xWordBtn->set_label( aCalcStr.getToken( 1, '#' ) );

        if ( pSearchItem->GetAppFlag() == SvxSearchApp::DRAW )
        {
            m_pSearchAllBtn->Hide();
            m_xSearchAllBtn->hide();

            m_pRegExpBtn->Hide();
            m_pWildcardBtn->Hide();
            m_pLayoutBtn->Hide();
            m_xRegExpBtn->hide();
            m_xWildcardBtn->hide();
            m_xLayoutBtn->hide();

            // only look for formatting in Writer
            m_pFormatBtn->Hide();
            m_pNoFormatBtn->Hide();
            m_pAttributeBtn->Hide();
            m_xFormatBtn->hide();
            m_xNoFormatBtn->hide();
            m_xAttributeBtn->hide();
        }
        else
        {
            m_pWildcardBtn->Hide(); /* TODO:WILDCARD do not hide for other apps if they handle it */
            m_xWildcardBtn->hide(); /* TODO:WILDCARD do not hide for other apps if they handle it */

            if ( !pSearchList )
            {
@@ -923,11 +865,11 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )

    // similarity search?
    if ( !( nModifyFlag & ModifyFlags::Similarity ) )
        m_pSimilarityBox->Check( pSearchItem->IsLevenshtein() );
        m_xSimilarityBox->set_active( pSearchItem->IsLevenshtein() );
    bSet = true;

    FlagHdl_Impl(m_pSimilarityBox);
    FlagHdl_Impl(m_pJapOptionsCB);
    FlagHdl_Impl(*m_xSimilarityBox);
    FlagHdl_Impl(*m_xJapOptionsCB);

    bool bDisableSearch = false;
    SfxViewShell* pViewShell = SfxViewShell::Current();
@@ -937,11 +879,11 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
        bool bText = !bSearchPattern;

        if ( pViewShell->HasSelection( bText ) )
            EnableControl_Impl(m_pSelectionBtn);
            EnableControl_Impl(*m_xSelectionBtn);
        else
        {
            m_pSelectionBtn->Check( false );
            m_pSelectionBtn->Disable();
            m_xSelectionBtn->set_active( false );
            m_xSelectionBtn->set_sensitive(false);
        }
    }

@@ -953,8 +895,8 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
        if ( pShell && pShell->GetStyleSheetPool() )
        {
            // Templates designed
            m_pSearchTmplLB->Clear();
            m_pReplaceTmplLB->Clear();
            m_xSearchTmplLB->clear();
            m_xReplaceTmplLB->clear();
            SfxStyleSheetBasePool* pStylePool = pShell->GetStyleSheetPool();
            pStylePool->SetSearchMask( pSearchItem->GetFamily() );
            SfxStyleSheetBase* pBase = pStylePool->First();
@@ -962,29 +904,29 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
            while ( pBase )
            {
                if ( pBase->IsUsed() )
                    m_pSearchTmplLB->InsertEntry( pBase->GetName() );
                m_pReplaceTmplLB->InsertEntry( pBase->GetName() );
                    m_xSearchTmplLB->append_text( pBase->GetName() );
                m_xReplaceTmplLB->append_text( pBase->GetName() );
                pBase = pStylePool->Next();
            }
            m_pSearchTmplLB->SelectEntry( pSearchItem->GetSearchString() );
            m_pReplaceTmplLB->SelectEntry( pSearchItem->GetReplaceString() );
            m_xSearchTmplLB->set_active_text( pSearchItem->GetSearchString() );
            m_xReplaceTmplLB->set_active_text( pSearchItem->GetReplaceString() );

        }
        m_pSearchTmplLB->Show();
        m_xSearchTmplLB->show();

        if ( bConstruct )
            // Grab focus only after creating
            m_pSearchTmplLB->GrabFocus();
        m_pReplaceTmplLB->Show();
        m_pSearchLB->Hide();
        m_pReplaceLB->Hide();
            m_xSearchTmplLB->grab_focus();
        m_xReplaceTmplLB->show();
        m_xSearchLB->hide();
        m_xReplaceLB->hide();

        m_pWordBtn->Disable();
        m_pRegExpBtn->Disable();
        m_pWildcardBtn->Disable();
        m_pMatchCaseCB->Disable();
        m_xWordBtn->set_sensitive(false);
        m_xRegExpBtn->set_sensitive(false);
        m_xWildcardBtn->set_sensitive(false);
        m_xMatchCaseCB->set_sensitive(false);

        bDisableSearch = !m_pSearchTmplLB->GetEntryCount();
        bDisableSearch = !m_xSearchTmplLB->get_count();
    }
    else
    {
@@ -992,7 +934,7 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
        bool bSetReplace = !( nModifyFlag & ModifyFlags::Replace );

        if ( !(pSearchItem->GetSearchString().isEmpty()) && bSetSearch )
            m_pSearchLB->SetText( pSearchItem->GetSearchString() );
            m_xSearchLB->set_entry_text( pSearchItem->GetSearchString() );
        else if (!aSearchStrings.empty())
        {
            bool bAttributes =
@@ -1000,7 +942,7 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
                  ( pReplaceList && pReplaceList->Count() ) );

            if ( bSetSearch && !bAttributes )
                m_pSearchLB->SetText(aSearchStrings[0]);
                m_xSearchLB->set_entry_text(aSearchStrings[0]);

            OUString aReplaceTxt = pSearchItem->GetReplaceString();

@@ -1008,72 +950,72 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern )
                aReplaceTxt = aReplaceStrings[0];

            if ( bSetReplace && !bAttributes )
                m_pReplaceLB->SetText( aReplaceTxt );
                m_xReplaceLB->set_entry_text( aReplaceTxt );
        }
        m_pSearchLB->Show();
        m_xSearchLB->show();

        if ( bConstruct )
            // Grab focus only after creating
            m_pSearchLB->GrabFocus();
        m_pReplaceLB->Show();
        m_pSearchTmplLB->Hide();
        m_pReplaceTmplLB->Hide();
            m_xSearchLB->grab_focus();
        m_xReplaceLB->show();
        m_xSearchTmplLB->hide();
        m_xReplaceTmplLB->hide();

        EnableControl_Impl(m_pRegExpBtn);
        EnableControl_Impl(m_pWildcardBtn);
        EnableControl_Impl(m_pMatchCaseCB);
        EnableControl_Impl(*m_xRegExpBtn);
        EnableControl_Impl(*m_xWildcardBtn);
        EnableControl_Impl(*m_xMatchCaseCB);

        if ( m_pRegExpBtn->IsChecked() )
            m_pWordBtn->Disable();
        if ( m_xRegExpBtn->get_active() )
            m_xWordBtn->set_sensitive(false);
        else
            EnableControl_Impl(m_pWordBtn);
            EnableControl_Impl(*m_xWordBtn);

        bDisableSearch = m_pSearchLB->GetText().isEmpty() &&
            m_pSearchAttrText->GetText().isEmpty();
        bDisableSearch = m_xSearchLB->get_active_text().isEmpty() &&
            m_xSearchAttrText->get_label().isEmpty();
    }
    FocusHdl_Impl(*m_pSearchLB);
    FocusHdl_Impl(*m_xSearchLB);

    if ( bDisableSearch )
    {
        m_pSearchBtn->Disable();
        m_pBackSearchBtn->Disable();
        m_pSearchAllBtn->Disable();
        m_pReplaceBtn->Disable();
        m_pReplaceAllBtn->Disable();
        m_pComponentFrame->Enable(false);
        m_xSearchBtn->set_sensitive(false);
        m_xBackSearchBtn->set_sensitive(false);
        m_xSearchAllBtn->set_sensitive(false);
        m_xReplaceBtn->set_sensitive(false);
        m_xReplaceAllBtn->set_sensitive(false);
        m_xComponentFrame->set_sensitive(false);
    }
    else
    {
        EnableControl_Impl(m_pSearchBtn);
        EnableControl_Impl(m_pBackSearchBtn);
        EnableControl_Impl(m_pReplaceBtn);
        if (!bWriter || !m_pNotesBtn->IsChecked())
        EnableControl_Impl(*m_xSearchBtn);
        EnableControl_Impl(*m_xBackSearchBtn);
        EnableControl_Impl(*m_xReplaceBtn);
        if (!bWriter || !m_xNotesBtn->get_active())
        {
            EnableControl_Impl(m_pSearchAllBtn);
            EnableControl_Impl(m_pReplaceAllBtn);
            EnableControl_Impl(*m_xSearchAllBtn);
            EnableControl_Impl(*m_xReplaceAllBtn);
        }
        if (bWriter && pSearchItem->GetNotes())
        {
            m_pSearchAllBtn->Disable();
            m_pReplaceAllBtn->Disable();
            m_xSearchAllBtn->set_sensitive(false);
            m_xReplaceAllBtn->set_sensitive(false);
        }
    }

    if (!m_pSearchAttrText->GetText().isEmpty())
        EnableControl_Impl(m_pNoFormatBtn);
    if (!m_xSearchAttrText->get_label().isEmpty())
        EnableControl_Impl(*m_xNoFormatBtn);
    else
        m_pNoFormatBtn->Disable();
        m_xNoFormatBtn->set_sensitive(false);

    if ( !pSearchList )
    {
        m_pAttributeBtn->Disable();
        m_pFormatBtn->Disable();
        m_xAttributeBtn->set_sensitive(false);
        m_xFormatBtn->set_sensitive(false);
    }

    if ( m_pLayoutBtn->IsChecked() )
    if ( m_xLayoutBtn->get_active() )
    {
        pImpl->bSaveToModule = false;
        TemplateHdl_Impl(m_pLayoutBtn);
        TemplateHdl_Impl(*m_xLayoutBtn);
        pImpl->bSaveToModule = true;
    }
}
@@ -1112,13 +1054,13 @@ void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
        {
            pSearchList->Put( *pSSet );

            m_pSearchAttrText->SetText( BuildAttrText_Impl( aDesc, true ) );
            m_xSearchAttrText->set_label( BuildAttrText_Impl( aDesc, true ) );

            if ( !aDesc.isEmpty() )
            {
                if (!m_pSearchAttrText->IsVisible())
                if (!m_xSearchAttrText->get_visible())
                {
                    m_pSearchAttrText->Show();
                    m_xSearchAttrText->show();
                    bSetOptimalLayoutSize = true;
                }
                bFormat |= true;
@@ -1134,13 +1076,13 @@ void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
        {
            pReplaceList->Put( *pRSet );

            m_pReplaceAttrText->SetText( BuildAttrText_Impl( aDesc, false ) );
            m_xReplaceAttrText->set_label( BuildAttrText_Impl( aDesc, false ) );

            if ( !aDesc.isEmpty() )
            {
                if (!m_pReplaceAttrText->IsVisible())
                if (!m_xReplaceAttrText->get_visible())
                {
                    m_pReplaceAttrText->Show();
                    m_xReplaceAttrText->show();
                    bSetOptimalLayoutSize = true;
                }
                bFormat |= true;
@@ -1149,244 +1091,242 @@ void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
    }

    if (bSetOptimalLayoutSize)
        setOptimalLayoutSize();
        m_xDialog->resize_to_request();
}


IMPL_LINK( SvxSearchDialog, LBSelectHdl_Impl, ListBox&, rCtrl, void )
IMPL_LINK( SvxSearchDialog, LBSelectHdl_Impl, weld::ComboBox&, rCtrl, void )
{
    ClickHdl_Impl(&rCtrl);
}

IMPL_LINK( SvxSearchDialog, FlagHdl_Impl, Button *, pCtrl, void )
IMPL_LINK( SvxSearchDialog, FlagHdl_Impl, weld::Button&, rCtrl, void )
{
    ClickHdl_Impl(pCtrl);
    ClickHdl_Impl(&rCtrl);
}

void SvxSearchDialog::ClickHdl_Impl(void const * pCtrl)
void SvxSearchDialog::ClickHdl_Impl(const weld::Widget* pCtrl)
{
    if ( pCtrl && !bSet )
        SetModifyFlag_Impl( static_cast<Control const *>(pCtrl) );
        SetModifyFlag_Impl(pCtrl);
    else
        bSet = false;

    if (pCtrl == m_pSimilarityBox)
    if (pCtrl == m_xSimilarityBox.get())
    {
        bool bIsChecked = m_pSimilarityBox->IsChecked();
        bool bIsChecked = m_xSimilarityBox->get_active();

        if ( bIsChecked )
        {
            m_pSimilarityBtn->Enable();
            m_pRegExpBtn->Check( false );
            m_pRegExpBtn->Disable();
            m_pWildcardBtn->Check( false );
            m_pWildcardBtn->Disable();
            EnableControl_Impl(m_pWordBtn);
            m_xSimilarityBtn->set_sensitive(true);
            m_xRegExpBtn->set_active( false );
            m_xRegExpBtn->set_sensitive(false);
            m_xWildcardBtn->set_active( false );
            m_xWildcardBtn->set_sensitive(false);
            EnableControl_Impl(*m_xWordBtn);

            if ( m_pLayoutBtn->IsChecked() )
            if ( m_xLayoutBtn->get_active() )
            {
                EnableControl_Impl(m_pMatchCaseCB);
                m_pLayoutBtn->Check( false );
                EnableControl_Impl(*m_xMatchCaseCB);
                m_xLayoutBtn->set_active( false );
            }
            m_pRegExpBtn->Disable();
            m_pWildcardBtn->Disable();
            m_pLayoutBtn->Disable();
            m_pFormatBtn->Disable();
            m_pNoFormatBtn->Disable();
            m_pAttributeBtn->Disable();
            m_xRegExpBtn->set_sensitive(false);
            m_xWildcardBtn->set_sensitive(false);
            m_xLayoutBtn->set_sensitive(false);
            m_xFormatBtn->set_sensitive(false);
            m_xNoFormatBtn->set_sensitive(false);
            m_xAttributeBtn->set_sensitive(false);
        }
        else
        {
            EnableControl_Impl(m_pRegExpBtn);
            EnableControl_Impl(m_pWildcardBtn);
            if (!m_pNotesBtn->IsChecked())
                EnableControl_Impl(m_pLayoutBtn);
            EnableControl_Impl(m_pFormatBtn);
            EnableControl_Impl(m_pAttributeBtn);
            m_pSimilarityBtn->Disable();
            EnableControl_Impl(*m_xRegExpBtn);
            EnableControl_Impl(*m_xWildcardBtn);
            if (!m_xNotesBtn->get_active())
                EnableControl_Impl(*m_xLayoutBtn);
            EnableControl_Impl(*m_xFormatBtn);
            EnableControl_Impl(*m_xAttributeBtn);
            m_xSimilarityBtn->set_sensitive(false);
        }
        pSearchItem->SetLevenshtein( bIsChecked );
    }
    else if (pCtrl == m_pNotesBtn)
    else if (pCtrl == m_xNotesBtn.get())
    {
        if (m_pNotesBtn->IsChecked())
        if (m_xNotesBtn->get_active())
        {
            m_pLayoutBtn->Disable();
            m_pSearchAllBtn->Disable();
            m_pReplaceAllBtn->Disable();
            m_xLayoutBtn->set_sensitive(false);
            m_xSearchAllBtn->set_sensitive(false);
            m_xReplaceAllBtn->set_sensitive(false);
        }
        else
        {
            EnableControl_Impl(m_pLayoutBtn);
            ModifyHdl_Impl(*m_pSearchLB);
            EnableControl_Impl(*m_xLayoutBtn);
            ModifyHdl_Impl(*m_xSearchLB);
        }
    }
    else
    {
        if ( m_pLayoutBtn->IsChecked() && !bFormat )
        if ( m_xLayoutBtn->get_active() && !bFormat )
        {
            m_pWordBtn->Check( false );
            m_pWordBtn->Disable();
            m_pRegExpBtn->Check( false );
            m_pRegExpBtn->Disable();
            m_pWildcardBtn->Check( false );
            m_pWildcardBtn->Disable();
            m_pMatchCaseCB->Check( false );
            m_pMatchCaseCB->Disable();
            m_pNotesBtn->Disable();
            m_xWordBtn->set_active( false );
            m_xWordBtn->set_sensitive(false);
            m_xRegExpBtn->set_active( false );
            m_xRegExpBtn->set_sensitive(false);
            m_xWildcardBtn->set_active( false );
            m_xWildcardBtn->set_sensitive(false);
            m_xMatchCaseCB->set_active( false );
            m_xMatchCaseCB->set_sensitive(false);
            m_xNotesBtn->set_sensitive(false);

            if ( m_pSearchTmplLB->GetEntryCount() )
            if ( m_xSearchTmplLB->get_count() )
            {
                EnableControl_Impl(m_pSearchBtn);
                EnableControl_Impl(m_pBackSearchBtn);
                EnableControl_Impl(m_pSearchAllBtn);
                EnableControl_Impl(m_pReplaceBtn);
                EnableControl_Impl(m_pReplaceAllBtn);
                EnableControl_Impl(*m_xSearchBtn);
                EnableControl_Impl(*m_xBackSearchBtn);
                EnableControl_Impl(*m_xSearchAllBtn);
                EnableControl_Impl(*m_xReplaceBtn);
                EnableControl_Impl(*m_xReplaceAllBtn);
            }
        }
        else
        {
            EnableControl_Impl(m_pRegExpBtn);
            EnableControl_Impl(m_pWildcardBtn);
            EnableControl_Impl(m_pMatchCaseCB);
            EnableControl_Impl(m_pNotesBtn);
            EnableControl_Impl(*m_xRegExpBtn);
            EnableControl_Impl(*m_xWildcardBtn);
            EnableControl_Impl(*m_xMatchCaseCB);
            EnableControl_Impl(*m_xNotesBtn);

            if ( m_pRegExpBtn->IsChecked() )
            if ( m_xRegExpBtn->get_active() )
            {
                m_pWordBtn->Check( false );
                m_pWordBtn->Disable();
                m_pWildcardBtn->Check( false );
                m_pWildcardBtn->Disable();
                m_pSimilarityBox->Check( false );
                m_pSimilarityBox->Disable();
                m_pSimilarityBtn->Disable();
                m_xWordBtn->set_active( false );
                m_xWordBtn->set_sensitive(false);
                m_xWildcardBtn->set_active( false );
                m_xWildcardBtn->set_sensitive(false);
                m_xSimilarityBox->set_active( false );
                m_xSimilarityBox->set_sensitive(false);
                m_xSimilarityBtn->set_sensitive(false);
            }
            else if ( m_pWildcardBtn->IsChecked() )
            else if ( m_xWildcardBtn->get_active() )
            {
                m_pRegExpBtn->Check( false );
                m_pRegExpBtn->Disable();
                m_pSimilarityBox->Check( false );
                m_pSimilarityBox->Disable();
                m_pSimilarityBtn->Disable();
                m_xRegExpBtn->set_active( false );
                m_xRegExpBtn->set_sensitive(false);
                m_xSimilarityBox->set_active( false );
                m_xSimilarityBox->set_sensitive(false);
                m_xSimilarityBtn->set_sensitive(false);
            }
            else
            {
                EnableControl_Impl(m_pWordBtn);
                EnableControl_Impl(m_pSimilarityBox);
                EnableControl_Impl(*m_xWordBtn);
                EnableControl_Impl(*m_xSimilarityBox);
            }

            // Search-string in place? then enable Buttons
            bSet = true;
            ModifyHdl_Impl(*m_pSearchLB);
            ModifyHdl_Impl(*m_xSearchLB);
        }
    }

    if (pCtrl == m_pAllSheetsCB)
    if (pCtrl == m_xAllSheetsCB.get())
    {
        bSet = true;
        ModifyHdl_Impl(*m_pSearchLB);
        ModifyHdl_Impl(*m_xSearchLB);
    }

    if (pCtrl == m_pJapOptionsCB)
    if (pCtrl == m_xJapOptionsCB.get())
    {
        bool bEnableJapOpt = m_pJapOptionsCB->IsChecked();
        m_pMatchCaseCB->Enable(!bEnableJapOpt );
        m_pJapMatchFullHalfWidthCB->Enable(!bEnableJapOpt );
        m_pJapOptionsBtn->Enable( bEnableJapOpt );
        bool bEnableJapOpt = m_xJapOptionsCB->get_active();
        m_xMatchCaseCB->set_sensitive(!bEnableJapOpt );
        m_xJapMatchFullHalfWidthCB->set_sensitive(!bEnableJapOpt );
        m_xJapOptionsBtn->set_sensitive( bEnableJapOpt );
    }

    if ( pImpl->bSaveToModule )
        SaveToModule_Impl();
}


IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
IMPL_LINK(SvxSearchDialog, CommandHdl_Impl, weld::Button&, rBtn, void)
{
    bool bInclusive = ( m_pLayoutBtn->GetText() == aLayoutStr );
    bool bInclusive = ( m_xLayoutBtn->get_label() == aLayoutStr );

    if ( ( pBtn == m_pSearchBtn )   ||
        (pBtn == m_pBackSearchBtn)  ||
         ( pBtn == m_pSearchAllBtn )||
         ( pBtn == m_pReplaceBtn )  ||
         ( pBtn == m_pReplaceAllBtn ) )
    if ( ( &rBtn == m_xSearchBtn.get() )   ||
         (&rBtn == m_xBackSearchBtn.get())  ||
         ( &rBtn == m_xSearchAllBtn.get() )||
         ( &rBtn == m_xReplaceBtn.get() )  ||
         ( &rBtn == m_xReplaceAllBtn.get() ) )
    {
        if ( m_pLayoutBtn->IsChecked() && !bInclusive )
        if ( m_xLayoutBtn->get_active() && !bInclusive )
        {
            pSearchItem->SetSearchString ( m_pSearchTmplLB->GetSelectedEntry() );
            pSearchItem->SetReplaceString( m_pReplaceTmplLB->GetSelectedEntry() );
            pSearchItem->SetSearchString ( m_xSearchTmplLB->get_active_text() );
            pSearchItem->SetReplaceString( m_xReplaceTmplLB->get_active_text() );
        }
        else
        {
            pSearchItem->SetSearchString ( m_pSearchLB->GetText() );
            pSearchItem->SetReplaceString( m_pReplaceLB->GetText() );
            pSearchItem->SetSearchString ( m_xSearchLB->get_active_text() );
            pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() );

            if ( pBtn == m_pReplaceBtn )
                Remember_Impl( m_pReplaceLB->GetText(), false );
            if ( &rBtn == m_xReplaceBtn.get() )
                Remember_Impl( m_xReplaceLB->get_active_text(), false );
            else
            {
                Remember_Impl( m_pSearchLB->GetText(), true );
                Remember_Impl( m_xSearchLB->get_active_text(), true );

                if ( pBtn == m_pReplaceAllBtn )
                    Remember_Impl( m_pReplaceLB->GetText(), false );
                if ( &rBtn == m_xReplaceAllBtn.get() )
                    Remember_Impl( m_xReplaceLB->get_active_text(), false );
            }
        }

        pSearchItem->SetRegExp( false );
        pSearchItem->SetWildcard( false );
        pSearchItem->SetLevenshtein( false );
        if (GetCheckBoxValue(m_pRegExpBtn))
        if (GetCheckBoxValue(*m_xRegExpBtn))
            pSearchItem->SetRegExp( true );
        else if (GetCheckBoxValue(m_pWildcardBtn))
        else if (GetCheckBoxValue(*m_xWildcardBtn))
            pSearchItem->SetWildcard( true );
        else if (GetCheckBoxValue(m_pSimilarityBox))
        else if (GetCheckBoxValue(*m_xSimilarityBox))
            pSearchItem->SetLevenshtein( true );

        pSearchItem->SetWordOnly(GetCheckBoxValue(m_pWordBtn));
        pSearchItem->SetWordOnly(GetCheckBoxValue(*m_xWordBtn));

        bool bSetBackwards = false;
        if( pBtn == m_pBackSearchBtn)
        if( &rBtn == m_xBackSearchBtn.get())
        {
            bSetBackwards = true;
        }
        else if( pBtn == m_pReplaceBtn)
        else if( &rBtn == m_xReplaceBtn.get())
        {
            bSetBackwards = GetCheckBoxValue(m_pReplaceBackwardsCB);
            bReplaceBackwards = GetCheckBoxValue(m_pReplaceBackwardsCB);
            bSetBackwards = GetCheckBoxValue(*m_xReplaceBackwardsCB);
            bReplaceBackwards = GetCheckBoxValue(*m_xReplaceBackwardsCB);
        }

        pSearchItem->SetBackward(bSetBackwards);

        pSearchItem->SetNotes(GetCheckBoxValue(m_pNotesBtn));
        pSearchItem->SetPattern(GetCheckBoxValue(m_pLayoutBtn));
        pSearchItem->SetSelection(GetCheckBoxValue(m_pSelectionBtn));
        pSearchItem->SetUseAsianOptions(GetCheckBoxValue(m_pJapOptionsCB));
        pSearchItem->SetNotes(GetCheckBoxValue(*m_xNotesBtn));
        pSearchItem->SetPattern(GetCheckBoxValue(*m_xLayoutBtn));
        pSearchItem->SetSelection(GetCheckBoxValue(*m_xSelectionBtn));
        pSearchItem->SetUseAsianOptions(GetCheckBoxValue(*m_xJapOptionsCB));
        TransliterationFlags nFlags = GetTransliterationFlags();
        if( !pSearchItem->IsUseAsianOptions())
            nFlags &= TransliterationFlags::IGNORE_CASE |
                      TransliterationFlags::IGNORE_WIDTH;
        if (GetNegatedCheckBoxValue(m_pIncludeDiacritics))
        if (GetNegatedCheckBoxValue(*m_xIncludeDiacritics))
            nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
        if (GetNegatedCheckBoxValue(m_pIncludeKashida))
        if (GetNegatedCheckBoxValue(*m_xIncludeKashida))
            nFlags |= TransliterationFlags::IGNORE_KASHIDA_CTL;
        pSearchItem->SetTransliterationFlags( nFlags );

        if ( !bWriter )
        {
            if ( m_pCalcSearchInLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND )
                pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_pCalcSearchInLB->GetSelectedEntryPos()) );
            if ( m_xCalcSearchInLB->get_active() != -1)
                pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_xCalcSearchInLB->get_active()) );

            pSearchItem->SetRowDirection( m_pRowsBtn->IsChecked() );
            pSearchItem->SetAllTables( m_pAllSheetsCB->IsChecked() );
            pSearchItem->SetSearchFormatted( m_pSearchFormattedCB->IsChecked() );
            pSearchItem->SetRowDirection( m_xRowsBtn->get_active() );
            pSearchItem->SetAllTables( m_xAllSheetsCB->get_active() );
            pSearchItem->SetSearchFormatted( m_xSearchFormattedCB->get_active() );
        }

        if ((pBtn == m_pSearchBtn) ||  (pBtn == m_pBackSearchBtn))
        if ((&rBtn == m_xSearchBtn.get()) ||  (&rBtn == m_xBackSearchBtn.get()))
            pSearchItem->SetCommand( SvxSearchCmd::FIND );
        else if ( pBtn == m_pSearchAllBtn )
        else if ( &rBtn == m_xSearchAllBtn.get() )
            pSearchItem->SetCommand( SvxSearchCmd::FIND_ALL );
        else if ( pBtn == m_pReplaceBtn )
        else if ( &rBtn == m_xReplaceBtn.get() )
            pSearchItem->SetCommand( SvxSearchCmd::REPLACE );
        else if ( pBtn == m_pReplaceAllBtn )
        else if ( &rBtn == m_xReplaceAllBtn.get() )
            pSearchItem->SetCommand( SvxSearchCmd::REPLACE_ALL );

        // when looking for templates, delete format lists
@@ -1402,15 +1342,15 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
        const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
        rBindings.ExecuteSynchron( FID_SEARCH_NOW, ppArgs );
    }
    else if ( pBtn == m_pCloseBtn )
    else if ( &rBtn == m_xCloseBtn.get() )
    {
        if ( !m_pLayoutBtn->IsChecked() || bInclusive )
        if ( !m_xLayoutBtn->get_active() || bInclusive )
        {
            OUString aStr( m_pSearchLB->GetText() );
            OUString aStr( m_xSearchLB->get_active_text() );

            if ( !aStr.isEmpty() )
                Remember_Impl( aStr, true );
            aStr = m_pReplaceLB->GetText();
            aStr = m_xReplaceLB->get_active_text();

            if ( !aStr.isEmpty() )
                Remember_Impl( aStr, false );
@@ -1418,10 +1358,10 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
        SaveToModule_Impl();
        Close();
    }
    else if (pBtn == m_pSimilarityBtn)
    else if (&rBtn == m_xSimilarityBtn.get())
    {
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog(GetFrameWeld(),
        ScopedVclPtr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog(m_xDialog.get(),
                                                                    pSearchItem->IsLEVRelaxed(),
                                                                    pSearchItem->GetLEVOther(),
                                                                    pSearchItem->GetLEVShorter(),
@@ -1435,12 +1375,12 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
            SaveToModule_Impl();
        }
    }
    else if (pBtn == m_pJapOptionsBtn)
    else if (&rBtn == m_xJapOptionsBtn.get())
    {
        SfxItemSet aSet( SfxGetpApp()->GetPool() );
        pSearchItem->SetTransliterationFlags( GetTransliterationFlags() );
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog(GetFrameWeld(), aSet,
        ScopedVclPtr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog(m_xDialog.get(), aSet,
                pSearchItem->GetTransliterationFlags() ));
        int nRet = executeSubDialog(aDlg.get());
        if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true
@@ -1450,15 +1390,15 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
            ApplyTransliterationFlags_Impl( nFlags );
        }
    }
    else if (pBtn == m_pSearchComponent1PB || pBtn == m_pSearchComponent2PB)
    else if (&rBtn == m_xSearchComponent1PB.get() || &rBtn == m_xSearchComponent2PB.get())
    {
        uno::Sequence < beans::PropertyValue > aArgs(2);
        beans::PropertyValue* pArgs = aArgs.getArray();
        pArgs[0].Name = "SearchString";
        pArgs[0].Value <<= m_pSearchLB->GetText();
        pArgs[0].Value <<= m_xSearchLB->get_active_text();
        pArgs[1].Name = "ParentWindow";
        pArgs[1].Value <<= VCLUnoHelper::GetInterface( this );
        if(pBtn == m_pSearchComponent1PB)
        pArgs[1].Value <<= m_xDialog->GetXWindow();
        if (&rBtn == m_xSearchComponent1PB.get())
        {
            if ( pImpl->xCommand1Dispatch.is() )
                pImpl->xCommand1Dispatch->dispatch(pImpl->aCommand1URL, aArgs);
@@ -1472,7 +1412,7 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn, void )
}


IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, Edit&, rEd, void )
IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, weld::ComboBox&, rEd, void )
{
    if ( !bSet )
        SetModifyFlag_Impl( &rEd );
@@ -1482,39 +1422,38 @@ IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, Edit&, rEd, void )
    // Calc allows searching for empty cells.
    bool bAllowEmptySearch = (pSearchItem->GetAppFlag() == SvxSearchApp::CALC);

    if ( &rEd == m_pSearchLB || &rEd == m_pReplaceLB )
    if (&rEd == m_xSearchLB.get() || &rEd == m_xReplaceLB.get())
    {
        sal_Int32 nSrchTxtLen = m_pSearchLB->GetText().getLength();
        sal_Int32 nSrchTxtLen = m_xSearchLB->get_active_text().getLength();
        sal_Int32 nReplTxtLen = 0;
        if (bAllowEmptySearch)
            nReplTxtLen = m_pReplaceLB->GetText().getLength();
        sal_Int32 nAttrTxtLen = m_pSearchAttrText->GetText().getLength();
            nReplTxtLen = m_xReplaceLB->get_active_text().getLength();
        sal_Int32 nAttrTxtLen = m_xSearchAttrText->get_label().getLength();

        if (nSrchTxtLen || nReplTxtLen || nAttrTxtLen)
        {
            EnableControl_Impl(m_pSearchBtn);
            EnableControl_Impl(m_pBackSearchBtn);
            EnableControl_Impl(m_pReplaceBtn);
            if (!bWriter || !m_pNotesBtn->IsChecked())
            EnableControl_Impl(*m_xSearchBtn);
            EnableControl_Impl(*m_xBackSearchBtn);
            EnableControl_Impl(*m_xReplaceBtn);
            if (!bWriter || !m_xNotesBtn->get_active())
            {
                EnableControl_Impl(m_pSearchAllBtn);
                EnableControl_Impl(m_pReplaceAllBtn);
                EnableControl_Impl(*m_xSearchAllBtn);
                EnableControl_Impl(*m_xReplaceAllBtn);
            }
        }
        else
        {
            m_pComponentFrame->Enable(false);
            m_pSearchBtn->Disable();
            m_pBackSearchBtn->Disable();
            m_pSearchAllBtn->Disable();
            m_pReplaceBtn->Disable();
            m_pReplaceAllBtn->Disable();
            m_xComponentFrame->set_sensitive(false);
            m_xSearchBtn->set_sensitive(false);
            m_xBackSearchBtn->set_sensitive(false);
            m_xSearchAllBtn->set_sensitive(false);
            m_xReplaceBtn->set_sensitive(false);
            m_xReplaceAllBtn->set_sensitive(false);
        }
    }
}


IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, weld::Button&, void)
{
    if ( pImpl->bSaveToModule )
        SaveToModule_Impl();
@@ -1523,7 +1462,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, Button*, void)
        return;
    OUString sDesc;

    if ( m_pLayoutBtn->IsChecked() )
    if ( m_xLayoutBtn->get_active() )
    {
        if ( !pFamilyController )
        {
@@ -1555,32 +1494,32 @@ IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, Button*, void)
            pFamilyController.reset(
                new SvxSearchController( nId, rBindings, *this ) );
            rBindings.LeaveRegistrations();
            m_pSearchTmplLB->Clear();
            m_pReplaceTmplLB->Clear();
            m_xSearchTmplLB->clear();
            m_xReplaceTmplLB->clear();

            m_pSearchTmplLB->Show();
            m_pReplaceTmplLB->Show();
            m_pSearchLB->Hide();
            m_pReplaceLB->Hide();
            m_xSearchTmplLB->show();
            m_xReplaceTmplLB->show();
            m_xSearchLB->hide();
            m_xReplaceLB->hide();

            m_pSearchAttrText->SetText( sDesc );
            m_pReplaceAttrText->SetText( sDesc );
            m_xSearchAttrText->set_label( sDesc );
            m_xReplaceAttrText->set_label( sDesc );

            if(!sDesc.isEmpty())
            {
                if (!m_pReplaceAttrText->IsVisible() || !m_pReplaceAttrText->IsVisible())
                if (!m_xReplaceAttrText->get_visible() || !m_xReplaceAttrText->get_visible())
                {
                    m_pSearchAttrText->Show();
                    m_pReplaceAttrText->Show();
                    setOptimalLayoutSize();
                    m_xSearchAttrText->show();
                    m_xReplaceAttrText->show();
                    m_xDialog->resize_to_request();
                }
            }
        }
        m_pFormatBtn->Disable();
        m_pNoFormatBtn->Disable();
        m_pAttributeBtn->Disable();
        m_pSimilarityBox->Disable();
        m_pSimilarityBtn->Disable();
        m_xFormatBtn->set_sensitive(false);
        m_xNoFormatBtn->set_sensitive(false);
        m_xAttributeBtn->set_sensitive(false);
        m_xSimilarityBox->set_sensitive(false);
        m_xSimilarityBtn->set_sensitive(false);
    }
    else
    {
@@ -1589,44 +1528,43 @@ IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, Button*, void)
        pFamilyController.reset();
        rBindings.LeaveRegistrations();

        m_pSearchLB->Show();
        m_pReplaceLB->Show();
        m_pSearchTmplLB->Hide();
        m_pReplaceTmplLB->Hide();
        m_xSearchLB->show();
        m_xReplaceLB->show();
        m_xSearchTmplLB->hide();
        m_xReplaceTmplLB->hide();

        m_pSearchAttrText->SetText( BuildAttrText_Impl( sDesc, true ) );
        m_pReplaceAttrText->SetText( BuildAttrText_Impl( sDesc, false ) );
        m_xSearchAttrText->set_label( BuildAttrText_Impl( sDesc, true ) );
        m_xReplaceAttrText->set_label( BuildAttrText_Impl( sDesc, false ) );

        if(!sDesc.isEmpty())
        {
            if (!m_pReplaceAttrText->IsVisible() || !m_pReplaceAttrText->IsVisible())
            if (!m_xReplaceAttrText->get_visible() || !m_xReplaceAttrText->get_visible())
            {
                m_pSearchAttrText->Show();
                m_pReplaceAttrText->Show();
                setOptimalLayoutSize();
                m_xSearchAttrText->show();
                m_xReplaceAttrText->show();
                m_xDialog->resize_to_request();
            }
        }

        EnableControl_Impl(m_pFormatBtn);
        EnableControl_Impl(m_pAttributeBtn);
        EnableControl_Impl(m_pSimilarityBox);
        EnableControl_Impl(*m_xFormatBtn);
        EnableControl_Impl(*m_xAttributeBtn);
        EnableControl_Impl(*m_xSimilarityBox);

        FocusHdl_Impl( bSearch ? *m_pSearchLB : *m_pReplaceLB );
        FocusHdl_Impl( bSearch ? *m_xSearchLB : *m_xReplaceLB );
    }
    bSet = true;
    pImpl->bSaveToModule = false;
    FlagHdl_Impl(m_pLayoutBtn);
    FlagHdl_Impl(*m_xLayoutBtn);
    pImpl->bSaveToModule = true;
}


void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch )
{
    if ( rStr.isEmpty() )
        return;

    std::vector<OUString>* pArr = _bSearch ? &aSearchStrings : &aReplaceStrings;
    ComboBox* pListBox = _bSearch ? m_pSearchLB.get() : m_pReplaceLB.get();
    weld::ComboBox* pListBox = _bSearch ? m_xSearchLB.get() : m_xReplaceLB.get();

    // ignore identical strings
    if (std::find(pArr->begin(), pArr->end(), rStr) != pArr->end())
@@ -1635,52 +1573,51 @@ void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch )
    // delete oldest entry at maximum occupancy (ListBox and Array)
    if(nRememberSize < pArr->size())
    {
        pListBox->RemoveEntryAt(static_cast<sal_uInt16>(nRememberSize - 1));
        pListBox->remove(static_cast<sal_uInt16>(nRememberSize - 1));
        (*pArr)[nRememberSize - 1] = rStr;
        pArr->erase(pArr->begin() + nRememberSize - 1);
    }

    pArr->insert(pArr->begin(), rStr);
    pListBox->InsertEntry(rStr, 0);
    pListBox->insert_text(0, rStr);
}


void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool )
{
    OUString aOldSrch( m_pSearchTmplLB->GetSelectedEntry() );
    OUString aOldRepl( m_pReplaceTmplLB->GetSelectedEntry() );
    m_pSearchTmplLB->Clear();
    m_pReplaceTmplLB->Clear();
    OUString aOldSrch( m_xSearchTmplLB->get_active_text() );
    OUString aOldRepl( m_xReplaceTmplLB->get_active_text() );
    m_xSearchTmplLB->clear();
    m_xReplaceTmplLB->clear();
    rPool.SetSearchMask( pSearchItem->GetFamily() );
    m_pSearchTmplLB->SetUpdateMode( false );
    m_pReplaceTmplLB->SetUpdateMode( false );
    m_xSearchTmplLB->freeze();
    m_xReplaceTmplLB->freeze();
    SfxStyleSheetBase* pBase = rPool.First();

    while ( pBase )
    {
        if ( pBase->IsUsed() )
            m_pSearchTmplLB->InsertEntry( pBase->GetName() );
        m_pReplaceTmplLB->InsertEntry( pBase->GetName() );
            m_xSearchTmplLB->append_text( pBase->GetName() );
        m_xReplaceTmplLB->append_text( pBase->GetName() );
        pBase = rPool.Next();
    }
    m_pSearchTmplLB->SetUpdateMode( true );
    m_pReplaceTmplLB->SetUpdateMode( true );
    m_pSearchTmplLB->SelectEntryPos(0);
    m_xSearchTmplLB->thaw();
    m_xReplaceTmplLB->thaw();
    m_xSearchTmplLB->set_active(0);

    if ( !aOldSrch.isEmpty() )
        m_pSearchTmplLB->SelectEntry( aOldSrch );
    m_pReplaceTmplLB->SelectEntryPos(0);
        m_xSearchTmplLB->set_active_text( aOldSrch );
    m_xReplaceTmplLB->set_active(0);

    if ( !aOldRepl.isEmpty() )
        m_pReplaceTmplLB->SelectEntry( aOldRepl );
        m_xReplaceTmplLB->set_active_text( aOldRepl );

    if ( m_pSearchTmplLB->GetEntryCount() )
    if ( m_xSearchTmplLB->get_count() )
    {
        EnableControl_Impl(m_pSearchBtn);
        EnableControl_Impl(m_pBackSearchBtn);
        EnableControl_Impl(m_pSearchAllBtn);
        EnableControl_Impl(m_pReplaceBtn);
        EnableControl_Impl(m_pReplaceAllBtn);
        EnableControl_Impl(*m_xSearchBtn);
        EnableControl_Impl(*m_xBackSearchBtn);
        EnableControl_Impl(*m_xSearchAllBtn);
        EnableControl_Impl(*m_xReplaceBtn);
        EnableControl_Impl(*m_xReplaceAllBtn);
    }
}

@@ -1692,21 +1629,11 @@ void SvxSearchDialog::EnableControls_Impl( const SearchOptionFlags nFlags )
    else
        nOptions = nFlags;

    if ( nOptions == SearchOptionFlags::NONE )
    {
        if ( IsVisible() )
        {
            Hide();
            return;
        }
    }
    else if ( !IsVisible() )
        Show();
    bool bNoSearch = true;

    bool bEnableSearch = bool( SearchOptionFlags::SEARCH & nOptions );
    m_pSearchBtn->Enable(bEnableSearch);
    m_pBackSearchBtn->Enable(bEnableSearch);
    m_xSearchBtn->set_sensitive(bEnableSearch);
    m_xBackSearchBtn->set_sensitive(bEnableSearch);

    if( bEnableSearch )
        bNoSearch = false;
@@ -1714,96 +1641,96 @@ void SvxSearchDialog::EnableControls_Impl( const SearchOptionFlags nFlags )

    if ( SearchOptionFlags::SEARCHALL & nOptions )
    {
        m_pSearchAllBtn->Enable();
        m_xSearchAllBtn->set_sensitive(true);
        bNoSearch = false;
    }
    else
        m_pSearchAllBtn->Disable();
        m_xSearchAllBtn->set_sensitive(false);
    if ( SearchOptionFlags::REPLACE & nOptions )
    {
        m_pReplaceBtn->Enable();
        m_pReplaceFrame->get_label_widget()->Enable();
        m_pReplaceLB->Enable();
        m_pReplaceTmplLB->Enable();
        m_xReplaceBtn->set_sensitive(true);
        m_xReplaceFrame->set_sensitive(true);
        m_xReplaceLB->set_sensitive(true);
        m_xReplaceTmplLB->set_sensitive(true);
        bNoSearch = false;
    }
    else
    {
        m_pReplaceBtn->Disable();
        m_pReplaceFrame->get_label_widget()->Disable();
        m_pReplaceLB->Disable();
        m_pReplaceTmplLB->Disable();
        m_xReplaceBtn->set_sensitive(false);
        m_xReplaceFrame->set_sensitive(false);
        m_xReplaceLB->set_sensitive(false);
        m_xReplaceTmplLB->set_sensitive(false);
    }
    if ( SearchOptionFlags::REPLACE_ALL & nOptions )
    {
        m_pReplaceAllBtn->Enable();
        m_xReplaceAllBtn->set_sensitive(true);
        bNoSearch = false;
    }
    else
        m_pReplaceAllBtn->Disable();
    m_pComponentFrame->Enable(!bNoSearch);
    m_pSearchBtn->Enable( !bNoSearch );
    m_pBackSearchBtn->Enable( !bNoSearch );
    m_pSearchFrame->get_label_widget()->Enable( !bNoSearch );
    m_pSearchLB->Enable( !bNoSearch );
    m_pNotesBtn->Enable();
        m_xReplaceAllBtn->set_sensitive(false);
    m_xComponentFrame->set_sensitive(!bNoSearch);
    m_xSearchBtn->set_sensitive( !bNoSearch );
    m_xBackSearchBtn->set_sensitive( !bNoSearch );
    m_xSearchFrame->set_sensitive( !bNoSearch );
    m_xSearchLB->set_sensitive( !bNoSearch );
    m_xNotesBtn->set_sensitive(true);

    if ( SearchOptionFlags::WHOLE_WORDS & nOptions )
        m_pWordBtn->Enable();
        m_xWordBtn->set_sensitive(true);
    else
        m_pWordBtn->Disable();
        m_xWordBtn->set_sensitive(false);
    if ( SearchOptionFlags::BACKWARDS & nOptions )
    {
        m_pBackSearchBtn->Enable();
        m_pReplaceBackwardsCB->Enable();
        m_xBackSearchBtn->set_sensitive(true);
        m_xReplaceBackwardsCB->set_sensitive(true);
    }
    else
    {
        m_pBackSearchBtn->Disable();
        m_pReplaceBackwardsCB->Disable();
        m_xBackSearchBtn->set_sensitive(false);
        m_xReplaceBackwardsCB->set_sensitive(false);
    }
    if ( SearchOptionFlags::REG_EXP & nOptions )
        m_pRegExpBtn->Enable();
        m_xRegExpBtn->set_sensitive(true);
    else
        m_pRegExpBtn->Disable();
        m_xRegExpBtn->set_sensitive(false);
    if ( SearchOptionFlags::WILDCARD & nOptions )
        m_pWildcardBtn->Enable();
        m_xWildcardBtn->set_sensitive(true);
    else
        m_pWildcardBtn->Disable();
        m_xWildcardBtn->set_sensitive(false);
    if ( SearchOptionFlags::EXACT & nOptions )
        m_pMatchCaseCB->Enable();
        m_xMatchCaseCB->set_sensitive(true);
    else
        m_pMatchCaseCB->Disable();
        m_xMatchCaseCB->set_sensitive(false);
    if ( SearchOptionFlags::SELECTION & nOptions )
        m_pSelectionBtn->Enable();
        m_xSelectionBtn->set_sensitive(true);
    else
        m_pSelectionBtn->Disable();
        m_xSelectionBtn->set_sensitive(false);
    if ( SearchOptionFlags::FAMILIES & nOptions )
        m_pLayoutBtn->Enable();
        m_xLayoutBtn->set_sensitive(true);
    else
        m_pLayoutBtn->Disable();
        m_xLayoutBtn->set_sensitive(false);
    if ( SearchOptionFlags::FORMAT & nOptions )
    {
        m_pAttributeBtn->Enable();
        m_pFormatBtn->Enable();
        m_pNoFormatBtn->Enable();
        m_xAttributeBtn->set_sensitive(true);
        m_xFormatBtn->set_sensitive(true);
        m_xNoFormatBtn->set_sensitive(true);
    }
    else
    {
        m_pAttributeBtn->Disable();
        m_pFormatBtn->Disable();
        m_pNoFormatBtn->Disable();
        m_xAttributeBtn->set_sensitive(false);
        m_xFormatBtn->set_sensitive(false);
        m_xNoFormatBtn->set_sensitive(false);
    }

    if ( SearchOptionFlags::SIMILARITY & nOptions )
    {
        m_pSimilarityBox->Enable();
        m_pSimilarityBtn->Enable();
        m_xSimilarityBox->set_sensitive(true);
        m_xSimilarityBtn->set_sensitive(true);
    }
    else
    {
        m_pSimilarityBox->Disable();
        m_pSimilarityBtn->Disable();
        m_xSimilarityBox->set_sensitive(false);
        m_xSimilarityBtn->set_sensitive(false);
    }

    if ( pSearchItem )
@@ -1811,110 +1738,108 @@ void SvxSearchDialog::EnableControls_Impl( const SearchOptionFlags nFlags )
                   ( !pSearchList || !pSearchList->Count() ) );
}


void SvxSearchDialog::EnableControl_Impl( Control const * pCtrl )
void SvxSearchDialog::EnableControl_Impl(const weld::Widget& rCtrl)
{
    if (m_pSearchBtn == pCtrl && ( SearchOptionFlags::SEARCH & nOptions ) )
    if (m_xSearchBtn.get() == &rCtrl && ( SearchOptionFlags::SEARCH & nOptions ) )
    {
        m_pComponentFrame->Enable();
        m_pSearchBtn->Enable();
        m_xComponentFrame->set_sensitive(true);
        m_xSearchBtn->set_sensitive(true);
        return;
    }
    if ( m_pSearchAllBtn == pCtrl &&
    if ( m_xSearchAllBtn.get() == &rCtrl &&
         ( SearchOptionFlags::SEARCHALL & nOptions )  )
    {
        m_pSearchAllBtn->Enable();
        m_xSearchAllBtn->set_sensitive(true);
        return;
    }
    if ( m_pReplaceBtn == pCtrl && ( SearchOptionFlags::REPLACE & nOptions )  )
    if ( m_xReplaceBtn.get() == &rCtrl && ( SearchOptionFlags::REPLACE & nOptions )  )
    {
        m_pReplaceBtn->Enable();
        m_xReplaceBtn->set_sensitive(true);
        return;
    }
    if ( m_pReplaceAllBtn == pCtrl &&
    if ( m_xReplaceAllBtn.get() == &rCtrl &&
         ( SearchOptionFlags::REPLACE_ALL & nOptions ) )
    {
        m_pReplaceAllBtn->Enable();
        m_xReplaceAllBtn->set_sensitive(true);
        return;
    }
    if ( m_pWordBtn == pCtrl && ( SearchOptionFlags::WHOLE_WORDS & nOptions ) )
    if ( m_xWordBtn.get() == &rCtrl && ( SearchOptionFlags::WHOLE_WORDS & nOptions ) )
    {
        m_pWordBtn->Enable();
        m_xWordBtn->set_sensitive(true);
        return;
    }
    if ( SearchOptionFlags::BACKWARDS & nOptions )
    {
        if( m_pBackSearchBtn == pCtrl )
        if( m_xBackSearchBtn.get() == &rCtrl )
        {
            m_pBackSearchBtn->Enable();
            m_xBackSearchBtn->set_sensitive(true);
            return;
        }
        else if ( m_pReplaceBackwardsCB == pCtrl )
        else if ( m_xReplaceBackwardsCB.get() == &rCtrl )
        {
            m_pReplaceBackwardsCB->Enable();
            m_xReplaceBackwardsCB->set_sensitive(true);
            return;
        }
    }
    if (m_pNotesBtn == pCtrl)
    if (m_xNotesBtn.get() == &rCtrl)
    {
        m_pNotesBtn->Enable();
        m_xNotesBtn->set_sensitive(true);
        return;
    }
    if ( m_pRegExpBtn == pCtrl && ( SearchOptionFlags::REG_EXP & nOptions )
        && !m_pSimilarityBox->IsChecked() && !m_pWildcardBtn->IsChecked())
    if ( m_xRegExpBtn.get() == &rCtrl && ( SearchOptionFlags::REG_EXP & nOptions )
        && !m_xSimilarityBox->get_active() && !m_xWildcardBtn->get_active())
    {
        m_pRegExpBtn->Enable();
        m_xRegExpBtn->set_sensitive(true);
        return;
    }
    if ( m_pWildcardBtn == pCtrl && ( SearchOptionFlags::WILDCARD & nOptions )
        && !m_pSimilarityBox->IsChecked() && !m_pRegExpBtn->IsChecked())
    if ( m_xWildcardBtn.get() == &rCtrl && ( SearchOptionFlags::WILDCARD & nOptions )
        && !m_xSimilarityBox->get_active() && !m_xRegExpBtn->get_active())
    {
        m_pWildcardBtn->Enable();
        m_xWildcardBtn->set_sensitive(true);
        return;
    }
    if ( m_pMatchCaseCB == pCtrl && ( SearchOptionFlags::EXACT & nOptions ) )
    if ( m_xMatchCaseCB.get() == &rCtrl && ( SearchOptionFlags::EXACT & nOptions ) )
    {
        if (!m_pJapOptionsCB->IsChecked())
            m_pMatchCaseCB->Enable();
        if (!m_xJapOptionsCB->get_active())
            m_xMatchCaseCB->set_sensitive(true);
        return;
    }
    if ( m_pSelectionBtn == pCtrl && ( SearchOptionFlags::SELECTION & nOptions ) )
    if ( m_xSelectionBtn.get() == &rCtrl && ( SearchOptionFlags::SELECTION & nOptions ) )
    {
        m_pSelectionBtn->Enable();
        m_xSelectionBtn->set_sensitive(true);
        return;
    }
    if ( m_pLayoutBtn == pCtrl && ( SearchOptionFlags::FAMILIES & nOptions ) )
    if ( m_xLayoutBtn.get() == &rCtrl && ( SearchOptionFlags::FAMILIES & nOptions ) )
    {
        m_pLayoutBtn->Enable();
        m_xLayoutBtn->set_sensitive(true);
        return;
    }
    if ( m_pAttributeBtn == pCtrl
    if ( m_xAttributeBtn.get() == &rCtrl
         && ( SearchOptionFlags::FORMAT & nOptions )
         && pSearchList )
    {
        m_pAttributeBtn->Enable( pImpl->bFocusOnSearch );
        m_xAttributeBtn->set_sensitive( pImpl->bFocusOnSearch );
    }
    if ( m_pFormatBtn == pCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
    if ( m_xFormatBtn.get() == &rCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
    {
        m_pFormatBtn->Enable();
        m_xFormatBtn->set_sensitive(true);
        return;
    }
    if ( m_pNoFormatBtn == pCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
    if ( m_xNoFormatBtn.get() == &rCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
    {
        m_pNoFormatBtn->Enable();
        m_xNoFormatBtn->set_sensitive(true);
        return;
    }
    if ( m_pSimilarityBox == pCtrl && ( SearchOptionFlags::SIMILARITY & nOptions )
        && !m_pRegExpBtn->IsChecked() && !m_pWildcardBtn->IsChecked())
    if ( m_xSimilarityBox.get() == &rCtrl && ( SearchOptionFlags::SIMILARITY & nOptions )
        && !m_xRegExpBtn->get_active() && !m_xWildcardBtn->get_active())
    {
        m_pSimilarityBox->Enable();
        m_xSimilarityBox->set_sensitive(true);

        if ( m_pSimilarityBox->IsChecked() )
            m_pSimilarityBtn->Enable();
        if ( m_xSimilarityBox->get_active() )
            m_xSimilarityBtn->set_sensitive(true);
    }
}


void SvxSearchDialog::SetItem_Impl( const SvxSearchItem* pItem )
{
    //TODO: save pItem and process later if m_executingSubDialog?
@@ -1926,44 +1851,43 @@ void SvxSearchDialog::SetItem_Impl( const SvxSearchItem* pItem )
    }
}


IMPL_LINK( SvxSearchDialog, FocusHdl_Impl, Control&, rControl, void )
IMPL_LINK(SvxSearchDialog, FocusHdl_Impl, weld::Widget&, rControl, void)
{
    sal_Int32 nTxtLen = m_pSearchAttrText->GetText().getLength();
    Control* pCtrl = &rControl;
    if ( pCtrl == m_pSearchLB )
    sal_Int32 nTxtLen = m_xSearchAttrText->get_label().getLength();
    weld::Widget* pCtrl = &rControl;
    if (pCtrl == m_xSearchLB.get())
    {
        if ( pCtrl->HasChildPathFocus() )
        if (pCtrl->has_focus())
            pImpl->bFocusOnSearch = true;
        pCtrl = m_pSearchLB;
        pCtrl = m_xSearchLB.get();
        bSearch = true;

        if( nTxtLen )
            EnableControl_Impl(m_pNoFormatBtn);
            EnableControl_Impl(*m_xNoFormatBtn);
        else
            m_pNoFormatBtn->Disable();
        EnableControl_Impl(m_pAttributeBtn);
            m_xNoFormatBtn->set_sensitive(false);
        EnableControl_Impl(*m_xAttributeBtn);
    }
    else
    {
        pImpl->bFocusOnSearch = false;
        pCtrl = m_pReplaceLB;
        pCtrl = m_xReplaceLB.get();
        bSearch = false;

        if (!m_pReplaceAttrText->GetText().isEmpty())
            EnableControl_Impl(m_pNoFormatBtn);
        if (!m_xReplaceAttrText->get_label().isEmpty())
            EnableControl_Impl(*m_xNoFormatBtn);
        else
            m_pNoFormatBtn->Disable();
        m_pAttributeBtn->Disable();
            m_xNoFormatBtn->set_sensitive(false);
        m_xAttributeBtn->set_sensitive(false);
    }
    bSet = true;

    static_cast<ComboBox*>(pCtrl)->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );

    ModifyHdl_Impl( static_cast<Edit&>(*pCtrl) );
    weld::ComboBox &rComboBox = dynamic_cast<weld::ComboBox&>(*pCtrl);
    rComboBox.select_entry_region(0, -1);
    ModifyHdl_Impl(rComboBox);

    if (bFormat && nTxtLen)
        m_pLayoutBtn->SetText(aLayoutStr);
        m_xLayoutBtn->set_label(aLayoutStr);
    else
    {
        SvtModuleOptions::EFactory eFactory = getModule(rBindings);
@@ -1974,25 +1898,23 @@ IMPL_LINK( SvxSearchDialog, FocusHdl_Impl, Control&, rControl, void )
        bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;

        if (bWriterApp)
            m_pLayoutBtn->SetText(aLayoutWriterStr);
            m_xLayoutBtn->set_label(aLayoutWriterStr);
        else
        {
            if (bCalcApp)
                m_pLayoutBtn->SetText(aLayoutCalcStr);
                m_xLayoutBtn->set_label(aLayoutCalcStr);
            else
                m_pLayoutBtn->SetText(aStylesStr);
                m_xLayoutBtn->set_label(aStylesStr);
        }
    }
}


IMPL_LINK_NOARG(SvxSearchDialog, LoseFocusHdl_Impl, Control&, void)
IMPL_LINK_NOARG(SvxSearchDialog, LoseFocusHdl_Impl, weld::Widget&, void)
{
    SaveToModule_Impl();
}


IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl, weld::Button&, void)
{
    SfxObjectShell* pSh = SfxObjectShell::Current();

@@ -2032,7 +1954,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl, Button*, void)


    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTabItemDialog(GetFrameWeld(), aSet));
    ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTabItemDialog(m_xDialog.get(), aSet));
    pDlg->SetText( aTxt );

    if ( executeSubDialog(pDlg.get()) == RET_OK )
@@ -2063,8 +1985,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl, Button*, void)
    }
}


IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl, weld::Button&, void)
{
    SvtModuleOptions::EFactory eFactory = getModule(rBindings);
    bool bWriterApp =
@@ -2074,75 +1995,73 @@ IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl, Button*, void)
    bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;

    if (bCalcApp)
        m_pLayoutBtn->SetText( aLayoutCalcStr );
        m_xLayoutBtn->set_label( aLayoutCalcStr );
    else
    {
        if (bWriterApp)
            m_pLayoutBtn->SetText( aLayoutWriterStr);
            m_xLayoutBtn->set_label( aLayoutWriterStr);
        else
            m_pLayoutBtn->SetText( aStylesStr );
            m_xLayoutBtn->set_label( aStylesStr );
    }

    bFormat = false;
    m_pLayoutBtn->Check( false );
    m_xLayoutBtn->set_active( false );

    bool bSetOptimalLayoutSize = false;

    if ( bSearch )
    {
        pSearchList->Clear();
        m_pSearchAttrText->SetText( "" );
        if (m_pSearchAttrText->IsVisible())
        m_xSearchAttrText->set_label( "" );
        if (m_xSearchAttrText->get_visible())
        {
            m_pSearchAttrText->Hide();
            m_xSearchAttrText->hide();
            bSetOptimalLayoutSize = true;
        }
    }
    else
    {
        pReplaceList->Clear();
        m_pReplaceAttrText->SetText( "" );
        if (m_pReplaceAttrText->IsVisible())
        m_xReplaceAttrText->set_label( "" );
        if (m_xReplaceAttrText->get_visible())
        {
            m_pReplaceAttrText->Hide();
            m_xReplaceAttrText->hide();
            bSetOptimalLayoutSize = true;
        }
    }

    if (bSetOptimalLayoutSize)
        setOptimalLayoutSize();
        m_xDialog->resize_to_request();

    pImpl->bSaveToModule = false;
    TemplateHdl_Impl(m_pLayoutBtn);
    TemplateHdl_Impl(*m_xLayoutBtn);
    pImpl->bSaveToModule = true;
    m_pNoFormatBtn->Disable();
    m_xNoFormatBtn->set_sensitive(false);
}


IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl, weld::Button&, void)
{
    if ( !pSearchList || !pImpl->pRanges )
        return;

    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxSearchAttributeDialog(GetFrameWeld(), *pSearchList, pImpl->pRanges.get()));
    ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxSearchAttributeDialog(m_xDialog.get(), *pSearchList, pImpl->pRanges.get()));
    executeSubDialog(pDlg.get());
    PaintAttrText_Impl();
}


IMPL_LINK( SvxSearchDialog, TimeoutHdl_Impl, Timer *, pTimer, void )
{
    SfxViewShell* pViewShell = SfxViewShell::Current();

    if ( pViewShell )
    {
        if ( pViewShell->HasSelection( m_pSearchLB->IsVisible() ) )
            EnableControl_Impl(m_pSelectionBtn);
        if ( pViewShell->HasSelection( m_xSearchLB->get_visible() ) )
            EnableControl_Impl(*m_xSelectionBtn);
        else
        {
            m_pSelectionBtn->Check( false );
            m_pSelectionBtn->Disable();
            m_xSelectionBtn->set_active( false );
            m_xSelectionBtn->set_sensitive(false);
        }
    }

@@ -2227,127 +2146,126 @@ void SvxSearchDialog::PaintAttrText_Impl()

    if ( bSearch )
    {
        m_pSearchAttrText->SetText( aDesc );
        if (!aDesc.isEmpty() && !m_pSearchAttrText->IsVisible())
        m_xSearchAttrText->set_label( aDesc );
        if (!aDesc.isEmpty() && !m_xSearchAttrText->get_visible())
        {
            m_pSearchAttrText->Show();
            m_xSearchAttrText->show();
            bSetOptimalLayoutSize = true;
        }

        FocusHdl_Impl(*m_pSearchLB);
        FocusHdl_Impl(*m_xSearchLB);
    }
    else
    {
        m_pReplaceAttrText->SetText( aDesc );
        if (!aDesc.isEmpty() && !m_pReplaceAttrText->IsVisible())
        m_xReplaceAttrText->set_label( aDesc );
        if (!aDesc.isEmpty() && !m_xReplaceAttrText->get_visible())
        {
            m_pReplaceAttrText->Show();
            m_xReplaceAttrText->show();
            bSetOptimalLayoutSize = true;
        }

        FocusHdl_Impl(*m_pReplaceLB);
        FocusHdl_Impl(*m_xReplaceLB);
    }

    if (bSetOptimalLayoutSize)
        setOptimalLayoutSize();
        m_xDialog->resize_to_request();
}

void SvxSearchDialog::SetModifyFlag_Impl( const Control* pCtrl )
void SvxSearchDialog::SetModifyFlag_Impl( const weld::Widget* pCtrl )
{
    if ( m_pSearchLB == pCtrl )
    if (m_xSearchLB.get() == pCtrl)
        nModifyFlag |= ModifyFlags::Search;
    else if ( m_pReplaceLB == pCtrl )
    else if ( m_xReplaceLB.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Replace;
    else if ( m_pWordBtn == pCtrl )
    else if ( m_xWordBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Word;
    else if ( m_pMatchCaseCB == pCtrl )
    else if ( m_xMatchCaseCB.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Exact;
    else if ( m_pReplaceBackwardsCB == pCtrl )
    else if ( m_xReplaceBackwardsCB.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Backwards;
    else if ( m_pNotesBtn == pCtrl )
    else if ( m_xNotesBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Notes;
    else if ( m_pSelectionBtn == pCtrl )
    else if ( m_xSelectionBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Selection;
    else if ( m_pRegExpBtn == pCtrl )
    else if ( m_xRegExpBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Regexp;
    else if ( m_pWildcardBtn == pCtrl )
    else if ( m_xWildcardBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Wildcard;
    else if ( m_pLayoutBtn == pCtrl )
    else if ( m_xLayoutBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Layout;
    else if ( m_pSimilarityBox == pCtrl )
    else if ( m_xSimilarityBox.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Similarity;
    else if ( m_pCalcSearchInLB == pCtrl )
    else if ( m_xCalcSearchInLB.get() == pCtrl )
    {
        nModifyFlag |= ModifyFlags::Formulas;
        nModifyFlag |= ModifyFlags::Values;
        nModifyFlag |= ModifyFlags::CalcNotes;
    }
    else if ( m_pRowsBtn == pCtrl )
    else if ( m_xRowsBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Rows;
    else if ( m_pColumnsBtn == pCtrl )
    else if ( m_xColumnsBtn.get() == pCtrl )
        nModifyFlag |= ModifyFlags::Columns;
    else if ( m_pAllSheetsCB == pCtrl )
    else if ( m_xAllSheetsCB.get() == pCtrl )
        nModifyFlag |= ModifyFlags::AllTables;
}


void SvxSearchDialog::SaveToModule_Impl()
{
    if ( !pSearchItem )
        return;

    if ( m_pLayoutBtn->IsChecked() )
    if ( m_xLayoutBtn->get_active() )
    {
        pSearchItem->SetSearchString ( m_pSearchTmplLB->GetSelectedEntry() );
        pSearchItem->SetReplaceString( m_pReplaceTmplLB->GetSelectedEntry() );
        pSearchItem->SetSearchString ( m_xSearchTmplLB->get_active_text() );
        pSearchItem->SetReplaceString( m_xReplaceTmplLB->get_active_text() );
    }
    else
    {
        pSearchItem->SetSearchString ( m_pSearchLB->GetText() );
        pSearchItem->SetReplaceString( m_pReplaceLB->GetText() );
        Remember_Impl( m_pSearchLB->GetText(), true );
        pSearchItem->SetSearchString ( m_xSearchLB->get_active_text() );
        pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() );
        Remember_Impl( m_xSearchLB->get_active_text(), true );
    }

    pSearchItem->SetRegExp( false );
    pSearchItem->SetWildcard( false );
    pSearchItem->SetLevenshtein( false );
    if (GetCheckBoxValue(m_pRegExpBtn))
    if (GetCheckBoxValue(*m_xRegExpBtn))
        pSearchItem->SetRegExp( true );
    else if (GetCheckBoxValue(m_pWildcardBtn))
    else if (GetCheckBoxValue(*m_xWildcardBtn))
        pSearchItem->SetWildcard( true );
    else if (GetCheckBoxValue(m_pSimilarityBox))
    else if (GetCheckBoxValue(*m_xSimilarityBox))
        pSearchItem->SetLevenshtein( true );

    pSearchItem->SetWordOnly(GetCheckBoxValue(m_pWordBtn));
    pSearchItem->SetBackward(GetCheckBoxValue(m_pReplaceBackwardsCB));
    pSearchItem->SetNotes(GetCheckBoxValue(m_pNotesBtn));
    pSearchItem->SetPattern(GetCheckBoxValue(m_pLayoutBtn));
    pSearchItem->SetSelection(GetCheckBoxValue(m_pSelectionBtn));
    pSearchItem->SetUseAsianOptions(GetCheckBoxValue(m_pJapOptionsCB));
    pSearchItem->SetWordOnly(GetCheckBoxValue(*m_xWordBtn));
    pSearchItem->SetBackward(GetCheckBoxValue(*m_xReplaceBackwardsCB));
    pSearchItem->SetNotes(GetCheckBoxValue(*m_xNotesBtn));
    pSearchItem->SetPattern(GetCheckBoxValue(*m_xLayoutBtn));
    pSearchItem->SetSelection(GetCheckBoxValue(*m_xSelectionBtn));
    pSearchItem->SetUseAsianOptions(GetCheckBoxValue(*m_xJapOptionsCB));

    SvtSearchOptions aOpt;
    aOpt.SetIgnoreDiacritics_CTL(GetNegatedCheckBoxValue(m_pIncludeDiacritics));
    aOpt.SetIgnoreKashida_CTL(GetNegatedCheckBoxValue(m_pIncludeKashida));
    aOpt.SetIgnoreDiacritics_CTL(GetNegatedCheckBoxValue(*m_xIncludeDiacritics));
    aOpt.SetIgnoreKashida_CTL(GetNegatedCheckBoxValue(*m_xIncludeKashida));
    aOpt.Commit();

    TransliterationFlags nFlags = GetTransliterationFlags();
    if( !pSearchItem->IsUseAsianOptions())
        nFlags &= TransliterationFlags::IGNORE_CASE |
                   TransliterationFlags::IGNORE_WIDTH;
    if (GetNegatedCheckBoxValue(m_pIncludeDiacritics))
    if (GetNegatedCheckBoxValue(*m_xIncludeDiacritics))
        nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
    if (GetNegatedCheckBoxValue(m_pIncludeKashida))
    if (GetNegatedCheckBoxValue(*m_xIncludeKashida))
        nFlags |= TransliterationFlags::IGNORE_KASHIDA_CTL;
    pSearchItem->SetTransliterationFlags( nFlags );

    if ( !bWriter )
    {
        if ( m_pCalcSearchInLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND )
            pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_pCalcSearchInLB->GetSelectedEntryPos()) );
        if (m_xCalcSearchInLB->get_active() != -1)
            pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_xCalcSearchInLB->get_active()) );

        pSearchItem->SetRowDirection( m_pRowsBtn->IsChecked() );
        pSearchItem->SetAllTables( m_pAllSheetsCB->IsChecked() );
        pSearchItem->SetSearchFormatted( m_pSearchFormattedCB->IsChecked() );
        pSearchItem->SetRowDirection( m_xRowsBtn->get_active() );
        pSearchItem->SetAllTables( m_xAllSheetsCB->get_active() );
        pSearchItem->SetSearchFormatted( m_xSearchFormattedCB->get_active() );
    }

    pSearchItem->SetCommand( SvxSearchCmd::FIND );
@@ -2356,18 +2274,39 @@ void SvxSearchDialog::SaveToModule_Impl()
    rBindings.GetDispatcher()->Execute( SID_SEARCH_ITEM, SfxCallMode::SLOT, ppArgs );
}

css::uno::Reference< css::awt::XWindowPeer >
        SvxSearchDialog::GetComponentInterface( bool bCreate )
void SvxSearchDialog::SetDocWin(vcl::Window* pDocWin)
{
    css::uno::Reference< css::awt::XWindowPeer > xPeer( Window::GetComponentInterface(false) );
    if ( !xPeer.is() && bCreate )
    m_xDialog->clear_extra_accessible_relations();

    if (!pDocWin)
        return;

    Reference<css::accessibility::XAccessible> xDocAcc = pDocWin->GetAccessible();
    if (!xDocAcc.is())
    {
        css::awt::XWindowPeer* pPeer = new VCLXSvxFindReplaceDialog(this);
        SetComponentInterface(pPeer);
        return pPeer;
        return;
    }
    else
        return xPeer;
    Reference<css::accessibility::XAccessibleGetAccFlowTo> xGetAccFlowTo(xDocAcc, UNO_QUERY);
    if (!xGetAccFlowTo.is())
    {
        return;
    }

    const sal_Int32 FORFINDREPLACEFLOWTO = 2;
    uno::Sequence<uno::Any> aAnySeq = xGetAccFlowTo->getAccFlowTo(Any(GetSrchFlag()),  FORFINDREPLACEFLOWTO);

    sal_Int32 nLen = aAnySeq.getLength();
    if (nLen)
    {
        uno::Sequence<uno::Reference<uno::XInterface>> aSequence(nLen);
        for (sal_Int32 i = 0; i < nLen; ++i)
        {
            uno::Reference < css::accessibility::XAccessible > xAcc;
            aAnySeq[i] >>= xAcc;
            aSequence[i] = xAcc;
        }
        m_xDialog->add_extra_accessible_relation(css::accessibility::AccessibleRelation(css::accessibility::AccessibleRelationType::CONTENT_FLOWS_TO, aSequence));
    }
}

short SvxSearchDialog::executeSubDialog(VclAbstractDialog * dialog) {
@@ -2384,9 +2323,9 @@ SvxSearchDialogWrapper::SvxSearchDialogWrapper( vcl::Window* _pParent, sal_uInt1
                                                SfxBindings* pBindings,
                                                SfxChildWinInfo const * pInfo )
    : SfxChildWindow( _pParent, nId )
    , dialog (VclPtr<SvxSearchDialog>::Create(_pParent, this, *pBindings))
    , dialog(new SvxSearchDialog(_pParent->GetFrameWeld(), this, *pBindings))
{
    SetWindow(dialog);
    SetController(dialog);
    dialog->Initialize( pInfo );

    pBindings->Update( SID_SEARCH_ITEM );
diff --git a/svx/uiconfig/ui/findreplacedialog.ui b/svx/uiconfig/ui/findreplacedialog.ui
index 1fbade1..2d3a681 100644
--- a/svx/uiconfig/ui/findreplacedialog.ui
+++ b/svx/uiconfig/ui/findreplacedialog.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="GtkDialog" id="FindReplaceDialog">
@@ -7,7 +7,12 @@
    <property name="border_width">6</property>
    <property name="title" translatable="yes" context="findreplacedialog|FindReplaceDialog">Find &amp; Replace</property>
    <property name="resizable">False</property>
    <property name="default_width">0</property>
    <property name="default_height">0</property>
    <property name="type_hint">dialog</property>
    <child>
      <placeholder/>
    </child>
    <child internal-child="vbox">
      <object class="GtkBox" id="dialog-vbox3">
        <property name="can_focus">False</property>
@@ -91,7 +96,7 @@
                            <property name="margin_right">6</property>
                            <property name="hexpand">True</property>
                            <child>
                              <object class="GtkComboBox" id="searchterm">
                              <object class="GtkComboBoxText" id="searchterm">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="valign">center</property>
@@ -100,6 +105,7 @@
                                <child internal-child="entry">
                                  <object class="GtkEntry" id="combobox-entry">
                                    <property name="can_focus">True</property>
                                    <property name="activates_default">True</property>
                                  </object>
                                </child>
                              </object>
@@ -109,7 +115,7 @@
                              </packing>
                            </child>
                            <child>
                              <object class="GtkComboBox" id="searchlist">
                              <object class="GtkComboBoxText" id="searchlist">
                                <property name="can_focus">False</property>
                                <property name="no_show_all">True</property>
                                <property name="hexpand">True</property>
@@ -151,6 +157,7 @@
                            <property name="no_show_all">True</property>
                            <property name="hexpand">True</property>
                            <property name="wrap">True</property>
                            <property name="ellipsize">end</property>
                            <property name="xalign">0</property>
                            <property name="yalign">0.55000001192092896</property>
                          </object>
@@ -167,9 +174,11 @@
                            <property name="wrap">True</property>
                            <property name="ellipsize">end</property>
                            <property name="xalign">0</property>
                            <accessibility>
                              <role type="static"/>
                            </accessibility>
                            <child internal-child="accessible">
                              <object class="AtkObject" id="searchlabel-atkobject">
                                <property name="AtkObject::accessible-role" translatable="no">static</property>
                              </object>
                            </child>
                          </object>
                          <packing>
                            <property name="left_attach">1</property>
@@ -275,6 +284,18 @@
                            <property name="top_attach">3</property>
                          </packing>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                      </object>
                    </child>
                  </object>
@@ -325,7 +346,7 @@
                            <property name="margin_right">6</property>
                            <property name="hexpand">True</property>
                            <child>
                              <object class="GtkComboBox" id="replaceterm">
                              <object class="GtkComboBoxText" id="replaceterm">
                                <property name="visible">True</property>
                                <property name="can_focus">False</property>
                                <property name="valign">center</property>
@@ -334,6 +355,7 @@
                                <child internal-child="entry">
                                  <object class="GtkEntry" id="combobox-entry2">
                                    <property name="can_focus">True</property>
                                    <property name="activates_default">True</property>
                                  </object>
                                </child>
                              </object>
@@ -343,7 +365,7 @@
                              </packing>
                            </child>
                            <child>
                              <object class="GtkComboBox" id="replacelist">
                              <object class="GtkComboBoxText" id="replacelist">
                                <property name="can_focus">False</property>
                                <property name="no_show_all">True</property>
                                <property name="hexpand">True</property>
@@ -385,6 +407,7 @@
                            <property name="no_show_all">True</property>
                            <property name="hexpand">True</property>
                            <property name="wrap">True</property>
                            <property name="ellipsize">end</property>
                            <property name="xalign">0</property>
                          </object>
                          <packing>
@@ -392,6 +415,12 @@
                            <property name="top_attach">2</property>
                          </packing>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                        <child>
                          <placeholder/>
                        </child>
                      </object>
                    </child>
                  </object>
@@ -1030,6 +1059,7 @@
                                            <property name="use_underline">True</property>
                                            <property name="xalign">0</property>
                                            <property name="draw_indicator">True</property>
                                            <property name="group">rows</property>
                                            <accessibility>
                                              <relation type="member-of" target="searchdir"/>
                                            </accessibility>
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 672184d..72ccc90 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -655,7 +655,7 @@ SwCursor* SwShellCursor::Create( SwPaM* pRing ) const
short SwShellCursor::MaxReplaceArived()
{
    short nRet = RET_YES;
    vcl::Window* pDlg = SwView::GetSearchDialog();
    SvxSearchDialog* pDlg = SwView::GetSearchDialog();
    if( pDlg )
    {
        // Terminate old actions. The table-frames get constructed and
@@ -671,7 +671,7 @@ short SwShellCursor::MaxReplaceArived()
            }
            vActionCounts.push_back(nActCnt);
        }
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDlg->GetFrameWeld(), "modules/swriter/ui/asksearchdialog.ui"));
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDlg->getDialog(), "modules/swriter/ui/asksearchdialog.ui"));
        std::unique_ptr<weld::MessageDialog> xDialog(xBuilder->weld_message_dialog("AskSearchDialog"));
        nRet = xDialog->run();
        auto pActionCount = vActionCounts.begin();
diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx
index cade4bb..d7acc4f 100644
--- a/sw/source/ui/fldui/fldtdlg.cxx
+++ b/sw/source/ui/fldui/fldtdlg.cxx
@@ -204,8 +204,6 @@ void SwFieldDlg::ReInitTabPage(const OString& rPageId, bool bOnlyActivate)
// newly initialise after activation of a few TabPages
void SwFieldDlg::Activate()
{
    fprintf(stderr, "SwFieldDlg::Activate()\n");

    SwView* pView = ::GetActiveView();
    if( pView )
    {
diff --git a/toolkit/source/awt/vclxaccessiblecomponent.cxx b/toolkit/source/awt/vclxaccessiblecomponent.cxx
index d2adad1..6f768ac 100644
--- a/toolkit/source/awt/vclxaccessiblecomponent.cxx
+++ b/toolkit/source/awt/vclxaccessiblecomponent.cxx
@@ -375,6 +375,9 @@ void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelation
            uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pMemberOf->GetAccessible() };
            rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
        }

        for (const auto& rExtraRelation : pWindow->GetExtraAccessibleRelations())
            rRelationSet.AddRelation(rExtraRelation);
    }
}

diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index ecc28c7..bee0f55 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -275,7 +275,8 @@ public:
    css::uno::Reference< css::awt::XWindowPeer > mxWindowPeer;
    css::uno::Reference< css::accessibility::XAccessible > mxAccessible;
    std::shared_ptr< VclSizeGroup > m_xSizeGroup;
    std::vector< VclPtr<FixedText> > m_aMnemonicLabels;
    std::vector<VclPtr<FixedText>> m_aMnemonicLabels;
    std::vector<css::accessibility::AccessibleRelation> m_aExtraAccessibleRelations;
    std::unique_ptr<ImplAccessibleInfos> mpAccessibleInfos;
    VCLXWindow*         mpVCLXWindow;
    vcl::Region              maWinRegion;            //< region to 'shape' the VCL window (frame coordinates)
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 6a27b64..01069b1 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -480,6 +480,16 @@ public:
        m_xWidget->SetAccessibleRelationLabelFor(pAtkLabeled);
    }

    virtual void add_extra_accessible_relation(const css::accessibility::AccessibleRelation &rRelation) override
    {
        m_xWidget->AddExtraAccessibleRelation(rRelation);
    }

    virtual void clear_extra_accessible_relations() override
    {
        m_xWidget->ClearExtraAccessibleRelations();
    }

    virtual void set_tooltip_text(const OUString& rTip) override
    {
        m_xWidget->SetQuickHelpText(rTip);
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index 66df5fa..dfcec76 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -45,6 +45,7 @@
#include <salframe.hxx>
#include <scrwnd.hxx>

#include <com/sun/star/accessibility/AccessibleRelation.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>

using namespace com::sun::star;
@@ -1946,6 +1947,21 @@ const std::vector<VclPtr<FixedText> >& Window::list_mnemonic_labels() const
    return mpWindowImpl->m_aMnemonicLabels;
}

void Window::AddExtraAccessibleRelation(const css::accessibility::AccessibleRelation &rRelation)
{
    mpWindowImpl->m_aExtraAccessibleRelations.push_back(rRelation);
}

const std::vector<css::accessibility::AccessibleRelation>& Window::GetExtraAccessibleRelations() const
{
    return mpWindowImpl->m_aExtraAccessibleRelations;
}

void Window::ClearExtraAccessibleRelations()
{
    mpWindowImpl->m_aExtraAccessibleRelations.clear();
}

} /* namespace vcl */

void DrawFocusRect(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
diff --git a/vcl/unx/gtk/a11y/atkwrapper.cxx b/vcl/unx/gtk/a11y/atkwrapper.cxx
index 2aa1e50b..a6382c8 100644
--- a/vcl/unx/gtk/a11y/atkwrapper.cxx
+++ b/vcl/unx/gtk/a11y/atkwrapper.cxx
@@ -496,8 +496,8 @@ wrapper_get_index_in_parent( AtkObject *atk_obj )

/*****************************************************************************/

static void
relation_set_add(AtkRelationSet *pSet, const accessibility::AccessibleRelation& rRelation)
AtkRelation*
atk_object_wrapper_relation_new(const accessibility::AccessibleRelation& rRelation)
{
    sal_uInt32 nTargetCount = rRelation.TargetSet.getLength();

@@ -515,8 +515,8 @@ relation_set_add(AtkRelationSet *pSet, const accessibility::AccessibleRelation& 
            aTargets.data(), nTargetCount,
            mapRelationType( rRelation.RelationType )
        );
    atk_relation_set_add( pSet, pRel );
    g_object_unref( G_OBJECT( pRel ) );

    return pRel;
}

static AtkRelationSet *
@@ -540,7 +540,9 @@ wrapper_ref_relation_set( AtkObject *atk_obj )
            sal_Int32 nRelations = xRelationSet.is() ? xRelationSet->getRelationCount() : 0;
            for( sal_Int32 n = 0; n < nRelations; n++ )
            {
                relation_set_add(pSet, xRelationSet->getRelation(n));
                AtkRelation *pRel = atk_object_wrapper_relation_new(xRelationSet->getRelation(n));
                atk_relation_set_add(pSet, pRel);
                g_object_unref(pRel);
            }
        }
        catch(const uno::Exception &) {
diff --git a/vcl/unx/gtk/a11y/atkwrapper.hxx b/vcl/unx/gtk/a11y/atkwrapper.hxx
index ef33397..8725e54 100644
--- a/vcl/unx/gtk/a11y/atkwrapper.hxx
+++ b/vcl/unx/gtk/a11y/atkwrapper.hxx
@@ -98,6 +98,8 @@ void                   atk_object_wrapper_dispose(AtkObjectWrapper* wrapper);

AtkStateType mapAtkState( sal_Int16 nState );

AtkRelation*           atk_object_wrapper_relation_new(const css::accessibility::AccessibleRelation& rRelation);

void                   actionIfaceInit(AtkActionIface *iface);
void                   componentIfaceInit(AtkComponentIface *iface);
void                   editableTextIfaceInit(AtkEditableTextIface *iface);
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 18aaf55..d728668 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1299,6 +1299,7 @@ private:
    gulong m_nDragLeaveSignalId;

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

    static void signalSizeAllocate(GtkWidget*, GdkRectangle* allocation, gpointer widget)
    {
@@ -1758,6 +1759,33 @@ public:
        g_object_unref(pRelationSet);
    }

    virtual void add_extra_accessible_relation(const css::accessibility::AccessibleRelation &rRelation) override
    {
        AtkObject* pAtkObject = gtk_widget_get_accessible(m_pWidget);
        if (!pAtkObject)
            return;

        AtkRelationSet *pRelationSet = atk_object_ref_relation_set(pAtkObject);
        AtkRelation *pRel = atk_object_wrapper_relation_new(rRelation);
        m_aExtraAtkRelations.push_back(pRel);
        atk_relation_set_add(pRelationSet, pRel);
        g_object_unref(pRel);
        g_object_unref(pRelationSet);
    }

    virtual void clear_extra_accessible_relations() override
    {
        AtkObject* pAtkObject = gtk_widget_get_accessible(m_pWidget);
        if (!pAtkObject)
            return;

        AtkRelationSet *pRelationSet = atk_object_ref_relation_set(pAtkObject);
        for (AtkRelation* pRel : m_aExtraAtkRelations)
            atk_relation_set_remove(pRelationSet, pRel);
        m_aExtraAtkRelations.clear();
        g_object_unref(pRelationSet);
    }

    virtual bool get_extents_relative_to(weld::Widget& rRelative, int& x, int &y, int& width, int &height) override
    {
        //for toplevel windows this is sadly futile under wayland, so we can't tell where a dialog is in order to allow