sw/inc/swabstdlg.hxx                       |    8 
 sw/source/ui/dbui/dbinsdlg.cxx             |   30 -
 sw/source/ui/dialog/swdlgfact.cxx          |   14 
 sw/source/ui/dialog/swdlgfact.hxx          |   17 -
 sw/source/ui/table/autoformatpreview.cxx   |  439 +++++++++++++++++++++++++++--
 sw/source/ui/table/convert.cxx             |   13 
 sw/source/ui/table/tautofmt.cxx            |  306 +++++++++-----------
 sw/source/uibase/inc/autoformatpreview.hxx |   54 +++
 sw/source/uibase/inc/convert.hxx           |    2 
 sw/source/uibase/inc/dbinsdlg.hxx          |    2 
 sw/source/uibase/inc/instable.hxx          |    2 
 sw/source/uibase/inc/tautofmt.hxx          |   70 ++--
 sw/source/uibase/shells/tabsh.cxx          |    2 
 sw/uiconfig/swriter/ui/autoformattable.ui  |  214 ++++++++------
 sw/uiconfig/swriter/ui/inserttable.ui      |    2 
 15 files changed, 821 insertions(+), 354 deletions(-)

New commits:
commit d24dba40175256a317a3d2281c70d3240b74f4a0
Author: Caolán McNamara <caol...@redhat.com>
Date:   Thu Mar 1 10:40:27 2018 +0000

    weld autoformat dialog
    
    Change-Id: I93af2393d103d882d08b74e1e5a98b601ebd29dc
    Reviewed-on: https://gerrit.libreoffice.org/50586
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index f79fa593433c..89e70bc4237b 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -314,7 +314,7 @@ class AbstractSwAutoFormatDlg : public VclAbstractDialog
 protected:
     virtual ~AbstractSwAutoFormatDlg() override = default;
 public:
-    virtual void FillAutoFormatOfIndex( SwTableAutoFormat*& rToFill ) const = 
0;
+    virtual SwTableAutoFormat* FillAutoFormatOfIndex() const = 0;
 };
 
 class AbstractSwFieldDlg : public SfxAbstractTabDialog
@@ -432,9 +432,9 @@ public:
     virtual VclPtr<VclAbstractDialog> CreateSwColumnDialog(vcl::Window 
*pParent, SwWrtShell &rSh) = 0;
     virtual VclPtr<AbstractSplitTableDialog> CreateSplitTableDialog ( 
vcl::Window * pParent, SwWrtShell &rSh ) = 0;
 
-    virtual VclPtr<AbstractSwAutoFormatDlg> CreateSwAutoFormatDlg( 
vcl::Window* pParent, SwWrtShell* pShell,
-                                                            bool 
bSetAutoFormat = true,
-                                                            const 
SwTableAutoFormat* pSelFormat = nullptr ) = 0;
+    virtual VclPtr<AbstractSwAutoFormatDlg> 
CreateSwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pShell,
+                                                                  bool 
bSetAutoFormat = true,
+                                                                  const 
SwTableAutoFormat* pSelFormat = nullptr ) = 0;
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg ( vcl::Window* 
pParent, SfxItemSet& rSet, SwBorderModes nType ) = 0;
     virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg ( vcl::Window* pParent, 
SfxItemSet& rSet, SwWrtShell* pSh ) = 0;
 
diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx
index d96a5feac7f5..8a1df9b58491 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -191,7 +191,6 @@ SwInsertDBColAutoPilot::SwInsertDBColAutoPilot( SwView& 
rView,
     , aDBData(rData)
     , sNoTmpl(SwResId(SW_STR_NONE))
     , pView(&rView)
-    , pTAutoFormat(nullptr)
     , pTableSet(nullptr)
     , pRep(nullptr)
 {
@@ -421,7 +420,7 @@ void SwInsertDBColAutoPilot::dispose()
     delete pTableSet;
     delete pRep;
 
-    delete pTAutoFormat;
+    m_xTAutoFormat.reset();
     m_pRbAsTable.clear();
     m_pRbAsField.clear();
     m_pRbAsText.clear();
@@ -781,10 +780,10 @@ IMPL_LINK( SwInsertDBColAutoPilot, AutoFormatHdl, 
Button*, pButton, void )
     SwAbstractDialogFactory* pFact = swui::GetFactory();
     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-    ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(pButton, pView->GetWrtShellPtr(), false, 
pTAutoFormat));
+    ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(pButton->GetFrameWeld(), 
pView->GetWrtShellPtr(), false, m_xTAutoFormat.get()));
     OSL_ENSURE(pDlg, "Dialog creation failed!");
     if( RET_OK == pDlg->Execute())
-        pDlg->FillAutoFormatOfIndex( pTAutoFormat );
+        m_xTAutoFormat.reset(pDlg->FillAutoFormatOfIndex());
 }
 
 IMPL_LINK( SwInsertDBColAutoPilot, SelectHdl, ListBox&, rBox, void )
@@ -1044,7 +1043,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
         bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & 
HTMLMODE_ON);
         rSh.InsertTable(
             pModOpt->GetInsTableFlags(bHTML),
-            nRows, nCols, (pSelection ? pTAutoFormat : nullptr) );
+            nRows, nCols, (pSelection ? m_xTAutoFormat.get(): nullptr) );
         rSh.MoveTable( GotoPrevTable, fnTableStart );
 
         if( pSelection && pTableSet )
@@ -1189,13 +1188,13 @@ void SwInsertDBColAutoPilot::DataToDoc( const 
Sequence<Any>& rSelection,
         }
 
         rSh.MoveTable( GotoCurrTable, fnTableStart );
-        if( !pSelection && ( pTableSet || pTAutoFormat ))
+        if( !pSelection && ( pTableSet || m_xTAutoFormat ))
         {
             if( pTableSet )
                 SetTabSet();
 
-            if( pTAutoFormat )
-                rSh.SetTableStyle(*pTAutoFormat);
+            if (m_xTAutoFormat)
+                rSh.SetTableStyle(*m_xTAutoFormat);
         }
         rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
     }
@@ -1452,15 +1451,15 @@ void SwInsertDBColAutoPilot::SetTabSet()
     SwWrtShell& rSh = pView->GetWrtShell();
     const SfxPoolItem* pItem;
 
-    if( pTAutoFormat )
+    if (m_xTAutoFormat)
     {
-        if( pTAutoFormat->IsFrame() )
+        if (m_xTAutoFormat->IsFrame())
         {
             // border is from AutoFormat
             pTableSet->ClearItem( RES_BOX );
             pTableSet->ClearItem( SID_ATTR_BORDER_INNER );
         }
-        if( pTAutoFormat->IsBackground() )
+        if (m_xTAutoFormat->IsBackground())
         {
             pTableSet->ClearItem( RES_BACKGROUND );
             pTableSet->ClearItem( SID_ATTR_BRUSH_ROW );
@@ -1594,8 +1593,8 @@ void SwInsertDBColAutoPilot::ImplCommit()
     if( sNoTmpl != (sTmp = m_pLbDbParaColl->GetSelectedEntry()) )
         pValues[5].Value <<= sTmp;
 
-    if( pTAutoFormat )
-        pValues[6].Value <<= pTAutoFormat->GetName();
+    if (m_xTAutoFormat)
+        pValues[6].Value <<= m_xTAutoFormat->GetName();
 
     pValues[7].Value <<= m_pRbAsTable->IsChecked();
     pValues[8].Value <<= m_pRbAsField->IsChecked();
@@ -1774,8 +1773,7 @@ void SwInsertDBColAutoPilot::Load()
             else
                 m_pLbDbParaColl->SelectEntryPos( 0 );
 
-            delete pTAutoFormat;
-            pTAutoFormat = nullptr;
+            m_xTAutoFormat.reset();
             sTmp = pNewData->sTAutoFormatNm;
             if( !sTmp.isEmpty() )
             {
@@ -1785,7 +1783,7 @@ void SwInsertDBColAutoPilot::Load()
                 for( size_t nAutoFormat = aAutoFormatTable.size(); 
nAutoFormat; )
                     if( sTmp == aAutoFormatTable[ --nAutoFormat ].GetName() )
                     {
-                        pTAutoFormat = new SwTableAutoFormat( 
aAutoFormatTable[ nAutoFormat ] );
+                        m_xTAutoFormat.reset(new 
SwTableAutoFormat(aAutoFormatTable[nAutoFormat]));
                         break;
                     }
             }
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 47acb1cbef8c..ecb89281d7fd 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -103,7 +103,10 @@ IMPL_ABSTDLG_BASE(AbstractSwInsertDBColAutoPilot_Impl);
 IMPL_ABSTDLG_BASE(AbstractDropDownFieldDialog_Impl);
 IMPL_ABSTDLG_BASE(AbstractSwLabDlg_Impl);
 IMPL_ABSTDLG_BASE(AbstractSwSelGlossaryDlg_Impl);
-IMPL_ABSTDLG_BASE(AbstractSwAutoFormatDlg_Impl);
+short AbstractSwAutoFormatDlg_Impl::Execute()
+{
+    return m_xDlg->run();
+}
 IMPL_ABSTDLG_BASE(AbstractSwFieldDlg_Impl);
 IMPL_ABSTDLG_BASE(AbstractSwRenameXNamedDlg_Impl);
 IMPL_ABSTDLG_BASE(AbstractSwModalRedlineAcceptDlg_Impl);
@@ -298,9 +301,9 @@ void 
AbstractSwSelGlossaryDlg_Impl::SelectEntryPos(sal_Int32 nIdx)
     pDlg->SelectEntryPos( nIdx );
 }
 
-void AbstractSwAutoFormatDlg_Impl::FillAutoFormatOfIndex( SwTableAutoFormat*& 
rToFill ) const
+SwTableAutoFormat* AbstractSwAutoFormatDlg_Impl::FillAutoFormatOfIndex() const
 {
-    pDlg->FillAutoFormatOfIndex(rToFill);
+    return m_xDlg->FillAutoFormatOfIndex();
 }
 
 void AbstractSwFieldDlg_Impl::SetCurPageId( sal_uInt16 nId )
@@ -801,11 +804,10 @@ VclPtr<AbstractSwSelGlossaryDlg> 
SwAbstractDialogFactory_Impl::CreateSwSelGlossa
     return VclPtr<AbstractSwSelGlossaryDlg_Impl>::Create(pDlg);
 }
 
-VclPtr<AbstractSwAutoFormatDlg> 
SwAbstractDialogFactory_Impl::CreateSwAutoFormatDlg(vcl::Window* pParent,
+VclPtr<AbstractSwAutoFormatDlg> 
SwAbstractDialogFactory_Impl::CreateSwAutoFormatDlg(weld::Window* pParent,
     SwWrtShell* pShell, bool bSetAutoFormat, const SwTableAutoFormat* 
pSelFormat)
 {
-    VclPtr<SwAutoFormatDlg> pDlg = VclPtr<SwAutoFormatDlg>::Create(pParent, 
pShell, bSetAutoFormat, pSelFormat);
-    return VclPtr<AbstractSwAutoFormatDlg_Impl>::Create(pDlg);
+    return VclPtr<AbstractSwAutoFormatDlg_Impl>::Create(new 
SwAutoFormatDlg(pParent, pShell, bSetAutoFormat, pSelFormat));
 }
 
 VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwBorderDlg(vcl::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType )
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index dbc95b9c31e9..becab7e73700 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -196,8 +196,15 @@ class AbstractSwSelGlossaryDlg_Impl : public 
AbstractSwSelGlossaryDlg
 
 class AbstractSwAutoFormatDlg_Impl : public AbstractSwAutoFormatDlg
 {
-    DECL_ABSTDLG_BASE(AbstractSwAutoFormatDlg_Impl,SwAutoFormatDlg )
-    virtual void FillAutoFormatOfIndex( SwTableAutoFormat*& rToFill ) const 
override;
+protected:
+    std::unique_ptr<SwAutoFormatDlg> m_xDlg;
+public:
+    explicit AbstractSwAutoFormatDlg_Impl(SwAutoFormatDlg* p)
+        : m_xDlg(p)
+    {
+    }
+    virtual short Execute() override;
+    virtual SwTableAutoFormat* FillAutoFormatOfIndex() const override;
 };
 
 class AbstractSwFieldDlg_Impl : public AbstractSwFieldDlg
@@ -426,9 +433,9 @@ public:
     virtual VclPtr<VclAbstractDialog> CreateSwColumnDialog(vcl::Window 
*pParent, SwWrtShell &rSh) override;
     virtual VclPtr<AbstractSplitTableDialog> CreateSplitTableDialog ( 
vcl::Window * pParent, SwWrtShell &rSh ) override;
 
-    virtual VclPtr<AbstractSwAutoFormatDlg> CreateSwAutoFormatDlg( 
vcl::Window* pParent, SwWrtShell* pShell,
-                                                            bool 
bSetAutoFormat = true,
-                                                            const 
SwTableAutoFormat* pSelFormat = nullptr ) override;
+    virtual VclPtr<AbstractSwAutoFormatDlg> 
CreateSwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pShell,
+                                                                  bool 
bSetAutoFormat = true,
+                                                                  const 
SwTableAutoFormat* pSelFormat = nullptr) override;
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg (vcl::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType ) override;
 
     virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg ( vcl::Window* pParent, 
SfxItemSet& rSet, SwWrtShell* pSh ) override;
diff --git a/sw/source/ui/table/autoformatpreview.cxx 
b/sw/source/ui/table/autoformatpreview.cxx
index 8386dcb16cb3..f7ba3c709971 100644
--- a/sw/source/ui/table/autoformatpreview.cxx
+++ b/sw/source/ui/table/autoformatpreview.cxx
@@ -27,7 +27,7 @@
 
 #define FRAME_OFFSET 4
 
-AutoFormatPreview::AutoFormatPreview(vcl::Window* pParent, WinBits nStyle)
+AutoFormatPreviewWindow::AutoFormatPreviewWindow(vcl::Window* pParent, WinBits 
nStyle)
     : Window(pParent, nStyle)
     , aCurData(OUString())
     , aVD(VclPtr<VirtualDevice>::Create(*this))
@@ -48,9 +48,9 @@ AutoFormatPreview::AutoFormatPreview(vcl::Window* pParent, 
WinBits nStyle)
     Init();
 }
 
-VCL_BUILDER_FACTORY_CONSTRUCTOR(AutoFormatPreview, 0)
+VCL_BUILDER_FACTORY_CONSTRUCTOR(AutoFormatPreviewWindow, 0)
 
-void AutoFormatPreview::Resize()
+void AutoFormatPreviewWindow::Resize()
 {
     aPrvSize = Size(GetSizePixel().Width() - 6, GetSizePixel().Height() - 30);
     nLabelColWidth = (aPrvSize.Width() - 4) / 4 - 12;
@@ -60,7 +60,7 @@ void AutoFormatPreview::Resize()
     NotifyChange(aCurData);
 }
 
-void AutoFormatPreview::DetectRTL(SwWrtShell const* pWrtShell)
+void AutoFormatPreviewWindow::DetectRTL(SwWrtShell const* pWrtShell)
 {
     if (!pWrtShell->IsCursorInTable()) // We haven't created the table yet
         mbRTL = AllSettings::GetLayoutRTL();
@@ -68,9 +68,9 @@ void AutoFormatPreview::DetectRTL(SwWrtShell const* pWrtShell)
         mbRTL = pWrtShell->IsTableRightToLeft();
 }
 
-AutoFormatPreview::~AutoFormatPreview() { disposeOnce(); }
+AutoFormatPreviewWindow::~AutoFormatPreviewWindow() { disposeOnce(); }
 
-void AutoFormatPreview::dispose()
+void AutoFormatPreviewWindow::dispose()
 {
     delete pNumFormat;
     vcl::Window::dispose();
@@ -94,8 +94,8 @@ static void lcl_SetFontProperties(vcl::Font& rFont, const 
SvxFontItem& rFontItem
     rCJKFont.MethodName(Value);                                                
                    \
     rCTLFont.MethodName(Value);
 
-void AutoFormatPreview::MakeFonts(sal_uInt8 nIndex, vcl::Font& rFont, 
vcl::Font& rCJKFont,
-                                  vcl::Font& rCTLFont)
+void AutoFormatPreviewWindow::MakeFonts(sal_uInt8 nIndex, vcl::Font& rFont, 
vcl::Font& rCJKFont,
+                                        vcl::Font& rCTLFont)
 {
     const SwBoxAutoFormat& rBoxFormat = aCurData.GetBoxFormat(nIndex);
 
@@ -119,14 +119,15 @@ void AutoFormatPreview::MakeFonts(sal_uInt8 nIndex, 
vcl::Font& rFont, vcl::Font&
     SETONALLFONTS(SetTransparent, true);
 }
 
-sal_uInt8 AutoFormatPreview::GetFormatIndex(size_t nCol, size_t nRow) const
+sal_uInt8 AutoFormatPreviewWindow::GetFormatIndex(size_t nCol, size_t nRow) 
const
 {
     static const sal_uInt8 pnFormatMap[]
         = { 0, 1, 2, 1, 3, 4, 5, 6, 5, 7, 8, 9, 10, 9, 11, 4, 5, 6, 5, 7, 12, 
13, 14, 13, 15 };
     return pnFormatMap[maArray.GetCellIndex(nCol, nRow, mbRTL)];
 }
 
-void AutoFormatPreview::DrawString(vcl::RenderContext& rRenderContext, size_t 
nCol, size_t nRow)
+void AutoFormatPreviewWindow::DrawString(vcl::RenderContext& rRenderContext, 
size_t nCol,
+                                         size_t nRow)
 {
     // Output of the cell text:
     sal_uLong nNum;
@@ -309,9 +310,7 @@ void AutoFormatPreview::DrawString(vcl::RenderContext& 
rRenderContext, size_t nC
     aScriptedText.DrawText(aPos);
 }
 
-#undef FRAME_OFFSET
-
-void AutoFormatPreview::DrawBackground(vcl::RenderContext& rRenderContext)
+void AutoFormatPreviewWindow::DrawBackground(vcl::RenderContext& 
rRenderContext)
 {
     for (size_t nRow = 0; nRow < 5; ++nRow)
     {
@@ -332,7 +331,7 @@ void AutoFormatPreview::DrawBackground(vcl::RenderContext& 
rRenderContext)
     }
 }
 
-void AutoFormatPreview::PaintCells(vcl::RenderContext& rRenderContext)
+void AutoFormatPreviewWindow::PaintCells(vcl::RenderContext& rRenderContext)
 {
     // 1) background
     if (aCurData.IsBackground())
@@ -359,7 +358,7 @@ void AutoFormatPreview::PaintCells(vcl::RenderContext& 
rRenderContext)
     }
 }
 
-void AutoFormatPreview::Init()
+void AutoFormatPreviewWindow::Init()
 {
     SetBorderStyle(GetBorderStyle() | WindowBorderStyle::MONO);
     maArray.Initialize(5, 5);
@@ -371,7 +370,7 @@ void AutoFormatPreview::Init()
     CalcLineMap();
 }
 
-void AutoFormatPreview::CalcCellArray(bool _bFitWidth)
+void AutoFormatPreviewWindow::CalcCellArray(bool _bFitWidth)
 {
     maArray.SetXOffset(2);
     maArray.SetAllColWidths(_bFitWidth ? nDataColWidth2 : nDataColWidth1);
@@ -391,7 +390,7 @@ inline void lclSetStyleFromBorder(svx::frame::Style& rStyle,
     rStyle.Set(pBorder, 0.05, 5);
 }
 
-void AutoFormatPreview::CalcLineMap()
+void AutoFormatPreviewWindow::CalcLineMap()
 {
     for (size_t nRow = 0; nRow < 5; ++nRow)
     {
@@ -418,7 +417,7 @@ void AutoFormatPreview::CalcLineMap()
     }
 }
 
-void AutoFormatPreview::NotifyChange(const SwTableAutoFormat& rNewData)
+void AutoFormatPreviewWindow::NotifyChange(const SwTableAutoFormat& rNewData)
 {
     aCurData = rNewData;
     bFitWidth = aCurData.IsJustify(); // true;  //???
@@ -427,7 +426,7 @@ void AutoFormatPreview::NotifyChange(const 
SwTableAutoFormat& rNewData)
     Invalidate(tools::Rectangle(Point(0, 0), GetSizePixel()));
 }
 
-void AutoFormatPreview::DoPaint(vcl::RenderContext& rRenderContext)
+void AutoFormatPreviewWindow::DoPaint(vcl::RenderContext& rRenderContext)
 {
     DrawModeFlags nOldDrawMode = aVD->GetDrawMode();
     if (rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
@@ -474,9 +473,409 @@ void AutoFormatPreview::DoPaint(vcl::RenderContext& 
rRenderContext)
     aVD->SetDrawMode(nOldDrawMode);
 }
 
-void AutoFormatPreview::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& /*rRect*/)
+void AutoFormatPreviewWindow::Paint(vcl::RenderContext& rRenderContext,
+                                    const tools::Rectangle& /*rRect*/)
 {
     DoPaint(rRenderContext);
 }
 
+AutoFormatPreview::AutoFormatPreview(weld::DrawingArea* pDrawingArea)
+    : mxDrawingArea(pDrawingArea)
+    , aCurData(OUString())
+    , bFitWidth(false)
+    , mbRTL(false)
+    , aStrJan(SwResId(STR_JAN))
+    , aStrFeb(SwResId(STR_FEB))
+    , aStrMar(SwResId(STR_MAR))
+    , aStrNorth(SwResId(STR_NORTH))
+    , aStrMid(SwResId(STR_MID))
+    , aStrSouth(SwResId(STR_SOUTH))
+    , aStrSum(SwResId(STR_SUM))
+{
+    uno::Reference<uno::XComponentContext> xContext = 
comphelper::getProcessComponentContext();
+    m_xBreak = i18n::BreakIterator::create(xContext);
+    mxNumFormat.reset(new SvNumberFormatter(xContext, LANGUAGE_SYSTEM));
+
+    Init();
+
+    mxDrawingArea->connect_size_allocate(LINK(this, AutoFormatPreview, 
DoResize));
+    mxDrawingArea->connect_draw(LINK(this, AutoFormatPreview, DoPaint));
+}
+
+IMPL_LINK(AutoFormatPreview, DoResize, const Size&, rSize, void)
+{
+    aPrvSize = Size(rSize.Width() - 6, rSize.Height() - 30);
+    nLabelColWidth = (aPrvSize.Width() - 4) / 4 - 12;
+    nDataColWidth1 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3;
+    nDataColWidth2 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4;
+    nRowHeight = (aPrvSize.Height() - 4) / 5;
+    NotifyChange(aCurData);
+}
+
+void AutoFormatPreview::DetectRTL(SwWrtShell const* pWrtShell)
+{
+    if (!pWrtShell->IsCursorInTable()) // We haven't created the table yet
+        mbRTL = AllSettings::GetLayoutRTL();
+    else
+        mbRTL = pWrtShell->IsTableRightToLeft();
+}
+
+void AutoFormatPreview::MakeFonts(vcl::RenderContext& rRenderContext, 
sal_uInt8 nIndex,
+                                  vcl::Font& rFont, vcl::Font& rCJKFont, 
vcl::Font& rCTLFont)
+{
+    const SwBoxAutoFormat& rBoxFormat = aCurData.GetBoxFormat(nIndex);
+
+    rFont = rCJKFont = rCTLFont = rRenderContext.GetFont();
+    Size aFontSize(rFont.GetFontSize().Width(), 10 * 
rRenderContext.GetDPIScaleFactor());
+
+    lcl_SetFontProperties(rFont, rBoxFormat.GetFont(), rBoxFormat.GetWeight(),
+                          rBoxFormat.GetPosture());
+    lcl_SetFontProperties(rCJKFont, rBoxFormat.GetCJKFont(), 
rBoxFormat.GetCJKWeight(),
+                          rBoxFormat.GetCJKPosture());
+    lcl_SetFontProperties(rCTLFont, rBoxFormat.GetCTLFont(), 
rBoxFormat.GetCTLWeight(),
+                          rBoxFormat.GetCTLPosture());
+
+    SETONALLFONTS(SetUnderline, rBoxFormat.GetUnderline().GetValue());
+    SETONALLFONTS(SetOverline, rBoxFormat.GetOverline().GetValue());
+    SETONALLFONTS(SetStrikeout, rBoxFormat.GetCrossedOut().GetValue());
+    SETONALLFONTS(SetOutline, rBoxFormat.GetContour().GetValue());
+    SETONALLFONTS(SetShadow, rBoxFormat.GetShadowed().GetValue());
+    SETONALLFONTS(SetColor, rBoxFormat.GetColor().GetValue());
+    SETONALLFONTS(SetFontSize, aFontSize);
+    SETONALLFONTS(SetTransparent, true);
+}
+
+sal_uInt8 AutoFormatPreview::GetFormatIndex(size_t nCol, size_t nRow) const
+{
+    static const sal_uInt8 pnFormatMap[]
+        = { 0, 1, 2, 1, 3, 4, 5, 6, 5, 7, 8, 9, 10, 9, 11, 4, 5, 6, 5, 7, 12, 
13, 14, 13, 15 };
+    return pnFormatMap[maArray.GetCellIndex(nCol, nRow, mbRTL)];
+}
+
+void AutoFormatPreview::DrawString(vcl::RenderContext& rRenderContext, size_t 
nCol, size_t nRow)
+{
+    // Output of the cell text:
+    sal_uLong nNum;
+    double nVal;
+    OUString cellString;
+    sal_uInt8 nIndex = static_cast<sal_uInt8>(maArray.GetCellIndex(nCol, nRow, 
mbRTL));
+
+    switch (nIndex)
+    {
+        case 1:
+            cellString = aStrJan;
+            break;
+        case 2:
+            cellString = aStrFeb;
+            break;
+        case 3:
+            cellString = aStrMar;
+            break;
+        case 5:
+            cellString = aStrNorth;
+            break;
+        case 10:
+            cellString = aStrMid;
+            break;
+        case 15:
+            cellString = aStrSouth;
+            break;
+        case 4:
+        case 20:
+            cellString = aStrSum;
+            break;
+        case 6:
+        case 8:
+        case 16:
+        case 18:
+            nVal = nIndex;
+            nNum = 5;
+            goto MAKENUMSTR;
+        case 17:
+        case 7:
+            nVal = nIndex;
+            nNum = 6;
+            goto MAKENUMSTR;
+        case 11:
+        case 12:
+        case 13:
+            nVal = nIndex;
+            nNum = 12 == nIndex ? 10 : 9;
+            goto MAKENUMSTR;
+        case 9:
+            nVal = 21;
+            nNum = 7;
+            goto MAKENUMSTR;
+        case 14:
+            nVal = 36;
+            nNum = 11;
+            goto MAKENUMSTR;
+        case 19:
+            nVal = 51;
+            nNum = 7;
+            goto MAKENUMSTR;
+        case 21:
+            nVal = 33;
+            nNum = 13;
+            goto MAKENUMSTR;
+        case 22:
+            nVal = 36;
+            nNum = 14;
+            goto MAKENUMSTR;
+        case 23:
+            nVal = 39;
+            nNum = 13;
+            goto MAKENUMSTR;
+        case 24:
+            nVal = 108;
+            nNum = 15;
+            goto MAKENUMSTR;
+
+        MAKENUMSTR:
+            if (aCurData.IsValueFormat())
+            {
+                OUString sFormat;
+                LanguageType eLng, eSys;
+                aCurData.GetBoxFormat(sal_uInt8(nNum)).GetValueFormat(sFormat, 
eLng, eSys);
+
+                SvNumFormatType nType;
+                bool bNew;
+                sal_Int32 nCheckPos;
+                sal_uInt32 nKey = 
mxNumFormat->GetIndexPuttingAndConverting(sFormat, eLng, eSys,
+                                                                            
nType, bNew, nCheckPos);
+                Color* pDummy;
+                mxNumFormat->GetOutputString(nVal, nKey, cellString, &pDummy);
+            }
+            else
+                cellString = OUString::number(sal_Int32(nVal));
+            break;
+    }
+
+    if (cellString.isEmpty())
+        return;
+
+    SvtScriptedTextHelper aScriptedText(rRenderContext);
+    Size aStrSize;
+    sal_uInt8 nFormatIndex = GetFormatIndex(nCol, nRow);
+    const basegfx::B2DRange aCellRange(maArray.GetCellRange(nCol, nRow, true));
+    const tools::Rectangle cellRect(
+        basegfx::fround(aCellRange.getMinX()), 
basegfx::fround(aCellRange.getMinY()),
+        basegfx::fround(aCellRange.getMaxX()), 
basegfx::fround(aCellRange.getMaxY()));
+    Point aPos = cellRect.TopLeft();
+    long nRightX = 0;
+
+    Size theMaxStrSize(cellRect.GetWidth() - FRAME_OFFSET, 
cellRect.GetHeight() - FRAME_OFFSET);
+    if (aCurData.IsFont())
+    {
+        vcl::Font aFont, aCJKFont, aCTLFont;
+        MakeFonts(rRenderContext, nFormatIndex, aFont, aCJKFont, aCTLFont);
+        aScriptedText.SetFonts(&aFont, &aCJKFont, &aCTLFont);
+    }
+    else
+        aScriptedText.SetDefaultFont();
+
+    aScriptedText.SetText(cellString, m_xBreak);
+    aStrSize = aScriptedText.GetTextSize();
+
+    if (aCurData.IsFont() && theMaxStrSize.Height() < aStrSize.Height())
+    {
+        // If the string in this font does not
+        // fit into the cell, the standard font
+        // is taken again:
+        aScriptedText.SetDefaultFont();
+        aStrSize = aScriptedText.GetTextSize();
+    }
+
+    while (theMaxStrSize.Width() <= aStrSize.Width() && cellString.getLength() 
> 1)
+    {
+        cellString = cellString.copy(0, cellString.getLength() - 1);
+        aScriptedText.SetText(cellString, m_xBreak);
+        aStrSize = aScriptedText.GetTextSize();
+    }
+
+    nRightX = cellRect.GetWidth() - aStrSize.Width() - FRAME_OFFSET;
+
+    // vertical (always centering):
+    aPos.Y() += (nRowHeight - aStrSize.Height()) / 2;
+
+    // horizontal
+    if (mbRTL)
+        aPos.X() += nRightX;
+    else if (aCurData.IsJustify())
+    {
+        const SvxAdjustItem& rAdj = 
aCurData.GetBoxFormat(nFormatIndex).GetAdjust();
+        switch (rAdj.GetAdjust())
+        {
+            case SvxAdjust::Left:
+                aPos.X() += FRAME_OFFSET;
+                break;
+            case SvxAdjust::Right:
+                aPos.X() += nRightX;
+                break;
+            default:
+                aPos.X() += (cellRect.GetWidth() - aStrSize.Width()) / 2;
+                break;
+        }
+    }
+    else
+    {
+        // Standard align:
+        if (nCol == 0 || nIndex == 4)
+        {
+            // Text-Label left or sum left aligned
+            aPos.X() += FRAME_OFFSET;
+        }
+        else
+        {
+            // numbers/dates right aligned
+            aPos.X() += nRightX;
+        }
+    }
+
+    aScriptedText.DrawText(aPos);
+}
+
+void AutoFormatPreview::DrawBackground(vcl::RenderContext& rRenderContext)
+{
+    for (size_t nRow = 0; nRow < 5; ++nRow)
+    {
+        for (size_t nCol = 0; nCol < 5; ++nCol)
+        {
+            SvxBrushItem aBrushItem(
+                aCurData.GetBoxFormat(GetFormatIndex(nCol, 
nRow)).GetBackground());
+
+            rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
+            rRenderContext.SetLineColor();
+            rRenderContext.SetFillColor(aBrushItem.GetColor());
+            const basegfx::B2DRange aCellRange(maArray.GetCellRange(nCol, 
nRow, true));
+            rRenderContext.DrawRect(tools::Rectangle(
+                basegfx::fround(aCellRange.getMinX()), 
basegfx::fround(aCellRange.getMinY()),
+                basegfx::fround(aCellRange.getMaxX()), 
basegfx::fround(aCellRange.getMaxY())));
+            rRenderContext.Pop();
+        }
+    }
+}
+
+void AutoFormatPreview::PaintCells(vcl::RenderContext& rRenderContext)
+{
+    // 1) background
+    if (aCurData.IsBackground())
+        DrawBackground(rRenderContext);
+
+    // 2) values
+    for (size_t nRow = 0; nRow < 5; ++nRow)
+        for (size_t nCol = 0; nCol < 5; ++nCol)
+            DrawString(rRenderContext, nCol, nRow);
+
+    // 3) border
+    if (aCurData.IsFrame())
+    {
+        const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
+        std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> 
pProcessor2D(
+            drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
+                rRenderContext, aNewViewInformation2D));
+
+        if (pProcessor2D)
+        {
+            pProcessor2D->process(maArray.CreateB2DPrimitiveArray());
+            pProcessor2D.reset();
+        }
+    }
+}
+
+void AutoFormatPreview::Init()
+{
+    maArray.Initialize(5, 5);
+    nLabelColWidth = 0;
+    nDataColWidth1 = 0;
+    nDataColWidth2 = 0;
+    nRowHeight = 0;
+    CalcCellArray(false);
+    CalcLineMap();
+}
+
+void AutoFormatPreview::CalcCellArray(bool _bFitWidth)
+{
+    maArray.SetAllColWidths(_bFitWidth ? nDataColWidth2 : nDataColWidth1);
+    maArray.SetColWidth(0, nLabelColWidth);
+    maArray.SetColWidth(4, nLabelColWidth);
+
+    maArray.SetAllRowHeights(nRowHeight);
+
+    aPrvSize.Width() = maArray.GetWidth() + 4;
+    aPrvSize.Height() = maArray.GetHeight() + 4;
+}
+
+void AutoFormatPreview::CalcLineMap()
+{
+    for (size_t nRow = 0; nRow < 5; ++nRow)
+    {
+        for (size_t nCol = 0; nCol < 5; ++nCol)
+        {
+            svx::frame::Style aStyle;
+
+            const SvxBoxItem& rItem = 
aCurData.GetBoxFormat(GetFormatIndex(nCol, nRow)).GetBox();
+            lclSetStyleFromBorder(aStyle, rItem.GetLeft());
+            maArray.SetCellStyleLeft(nCol, nRow, aStyle);
+            lclSetStyleFromBorder(aStyle, rItem.GetRight());
+            maArray.SetCellStyleRight(nCol, nRow, aStyle);
+            lclSetStyleFromBorder(aStyle, rItem.GetTop());
+            maArray.SetCellStyleTop(nCol, nRow, aStyle);
+            lclSetStyleFromBorder(aStyle, rItem.GetBottom());
+            maArray.SetCellStyleBottom(nCol, nRow, aStyle);
+
+            // FIXME - uncomment to draw diagonal borders
+            //            lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, 
nRow, true ).GetLine() );
+            //            maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
+            //            lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, 
nRow, false ).GetLine() );
+            //            maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
+        }
+    }
+}
+
+void AutoFormatPreview::NotifyChange(const SwTableAutoFormat& rNewData)
+{
+    aCurData = rNewData;
+    bFitWidth = aCurData.IsJustify(); // true;  //???
+    CalcCellArray(bFitWidth);
+    CalcLineMap();
+    mxDrawingArea->queue_draw();
+}
+
+IMPL_LINK(AutoFormatPreview, DoPaint, vcl::RenderContext&, rRenderContext, 
void)
+{
+    rRenderContext.Push(PushFlags::ALL);
+
+    DrawModeFlags nOldDrawMode = rRenderContext.GetDrawMode();
+    if (rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
+        rRenderContext.SetDrawMode(DrawModeFlags::SettingsLine | 
DrawModeFlags::SettingsFill
+                                   | DrawModeFlags::SettingsText | 
DrawModeFlags::SettingsGradient);
+
+    Size theWndSize = rRenderContext.GetOutputSizePixel();
+
+    vcl::Font aFont(rRenderContext.GetFont());
+    aFont.SetTransparent(true);
+
+    rRenderContext.SetFont(aFont);
+    rRenderContext.SetLineColor();
+    const Color& rWinColor = 
rRenderContext.GetSettings().GetStyleSettings().GetWindowColor();
+    rRenderContext.SetBackground(Wallpaper(rWinColor));
+    rRenderContext.SetFillColor(rWinColor);
+
+    // Draw the Frame
+    Color oldColor = rRenderContext.GetLineColor();
+    rRenderContext.SetLineColor();
+    rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), theWndSize));
+    rRenderContext.SetLineColor(oldColor);
+
+    // Center the preview
+    maArray.SetXOffset(2 + (theWndSize.Width() - aPrvSize.Width()) / 2);
+    maArray.SetYOffset(2 + (theWndSize.Height() - aPrvSize.Height()) / 2);
+    // Draw cells on virtual device
+    PaintCells(rRenderContext);
+
+    rRenderContext.SetDrawMode(nOldDrawMode);
+    rRenderContext.Pop();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/table/convert.cxx b/sw/source/ui/table/convert.cxx
index 14e1b4729a61..6b918a59beae 100644
--- a/sw/source/ui/table/convert.cxx
+++ b/sw/source/ui/table/convert.cxx
@@ -87,8 +87,8 @@ void SwConvertTableDlg::GetValues(  sal_Unicode& rDelim,
     if (!mpDontSplitCB->IsChecked())
         nInsMode |= tabopts::SPLIT_LAYOUT;
 
-    if( pTAutoFormat )
-        prTAFormat = new SwTableAutoFormat( *pTAutoFormat );
+    if (mxTAutoFormat)
+        prTAFormat = new SwTableAutoFormat(*mxTAutoFormat);
 
     rInsTableOpts.mnInsMode = nInsMode;
 }
@@ -96,7 +96,6 @@ void SwConvertTableDlg::GetValues(  sal_Unicode& rDelim,
 SwConvertTableDlg::SwConvertTableDlg( SwView& rView, bool bToTable )
     : SfxModalDialog(&rView.GetViewFrame()->GetWindow(), 
"ConvertTextTableDialog", "modules/swriter/ui/converttexttable.ui" )
     , sConvertTextTable(SwResId(STR_CONVERT_TEXT_TABLE))
-    , pTAutoFormat(nullptr)
     , pShell(&rView.GetWrtShell())
 {
     get(mpTabBtn, "tabs");
@@ -179,7 +178,7 @@ SwConvertTableDlg:: ~SwConvertTableDlg()
 
 void SwConvertTableDlg::dispose()
 {
-    delete pTAutoFormat;
+    mxTAutoFormat.reset();
     mpTabBtn.clear();
     mpSemiBtn.clear();
     mpParaBtn.clear();
@@ -202,10 +201,10 @@ IMPL_LINK( SwConvertTableDlg, AutoFormatHdl, Button*, 
pButton, void )
     SwAbstractDialogFactory* pFact = swui::GetFactory();
     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-    ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(pButton, pShell, false, pTAutoFormat));
+    ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(pButton->GetFrameWeld(), pShell, false, 
mxTAutoFormat.get()));
     OSL_ENSURE(pDlg, "Dialog creation failed!");
-    if( RET_OK == pDlg->Execute())
-        pDlg->FillAutoFormatOfIndex( pTAutoFormat );
+    if (RET_OK == pDlg->Execute())
+        mxTAutoFormat.reset(pDlg->FillAutoFormatOfIndex());
 }
 
 IMPL_LINK( SwConvertTableDlg, BtnHdl, Button*, pButton, void )
diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx
index 1d18805430bb..fcbae6f6d46c 100644
--- a/sw/source/ui/table/tautofmt.cxx
+++ b/sw/source/ui/table/tautofmt.cxx
@@ -55,9 +55,22 @@ public:
 };
 
 // AutoFormat-Dialogue:
-SwAutoFormatDlg::SwAutoFormatDlg( vcl::Window* pParent, SwWrtShell* pWrtShell,
-                    bool bAutoFormat, const SwTableAutoFormat* pSelFormat )
-    : SfxModalDialog(pParent, "AutoFormatTableDialog", 
"modules/swriter/ui/autoformattable.ui")
+SwAutoFormatDlg::SwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pWrtShell,
+                                 bool bAutoFormat, const SwTableAutoFormat* 
pSelFormat)
+    : m_xBuilder(Application::CreateBuilder(pParent, 
"modules/swriter/ui/autoformattable.ui"))
+    , m_xDialog(m_xBuilder->weld_dialog("AutoFormatTableDialog"))
+    , m_xLbFormat(m_xBuilder->weld_tree_view("formatlb"))
+    , m_xBtnNumFormat(m_xBuilder->weld_check_button("numformatcb"))
+    , m_xBtnBorder(m_xBuilder->weld_check_button("bordercb"))
+    , m_xBtnFont(m_xBuilder->weld_check_button("fontcb"))
+    , m_xBtnPattern(m_xBuilder->weld_check_button("patterncb"))
+    , m_xBtnAlignment(m_xBuilder->weld_check_button("alignmentcb"))
+    , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
+    , m_xBtnAdd(m_xBuilder->weld_button("add"))
+    , m_xBtnRemove(m_xBuilder->weld_button("remove"))
+    , m_xBtnRename(m_xBuilder->weld_button("rename"))
+    , m_aWndPreview(m_xBuilder->weld_drawing_area("preview"))
+    , m_xTableTable(new SwTableAutoFormatTable)
     , aStrTitle(SwResId(STR_ADD_AUTOFORMAT_TITLE))
     , aStrLabel(SwResId(STR_ADD_AUTOFORMAT_LABEL))
     , aStrClose(SwResId(STR_BTN_AUTOFORMAT_CLOSE))
@@ -66,114 +79,78 @@ SwAutoFormatDlg::SwAutoFormatDlg( vcl::Window* pParent, 
SwWrtShell* pWrtShell,
     , aStrRenameTitle(SwResId(STR_RENAME_AUTOFORMAT_TITLE))
     , aStrInvalidFormat(SwResId(STR_INVALID_AUTOFORMAT_NAME))
     , pShell(pWrtShell)
-    , nIndex(0)
+    , m_nIndex(0)
     , nDfltStylePos(0)
     , bCoreDataChanged(false)
     , bSetAutoFormat(bAutoFormat)
 {
-    get(m_pLbFormat, "formatlb");
-    get(m_pFormatting, "formatting");
-    get(m_pBtnNumFormat, "numformatcb");
-    get(m_pBtnBorder, "bordercb");
-    get(m_pBtnFont, "fontcb");
-    get(m_pBtnPattern, "patterncb");
-    get(m_pBtnAlignment, "alignmentcb");
-    get(m_pBtnOk, "ok");
-    get(m_pBtnCancel, "cancel");
-    get(m_pBtnAdd, "add");
-    get(m_pBtnRemove, "remove");
-    get(m_pBtnRename, "rename");
-    get(m_pWndPreview, "preview");
-
-    m_pWndPreview->DetectRTL(pWrtShell);
-
-    pTableTable = new SwTableAutoFormatTable;
-    pTableTable->Load();
+    m_aWndPreview.DetectRTL(pWrtShell);
+    m_xTableTable->Load();
 
     Init(pSelFormat);
 }
 
 SwAutoFormatDlg::~SwAutoFormatDlg()
 {
-    disposeOnce();
-}
-
-void SwAutoFormatDlg::dispose()
-{
     if (bCoreDataChanged)
-        pTableTable->Save();
-    delete pTableTable;
-    m_pLbFormat.clear();
-    m_pFormatting.clear();
-    m_pBtnNumFormat.clear();
-    m_pBtnBorder.clear();
-    m_pBtnFont.clear();
-    m_pBtnPattern.clear();
-    m_pBtnAlignment.clear();
-    m_pBtnOk.clear();
-    m_pBtnCancel.clear();
-    m_pBtnAdd.clear();
-    m_pBtnRemove.clear();
-    m_pBtnRename.clear();
-    m_pWndPreview.clear();
-    SfxModalDialog::dispose();
+        m_xTableTable->Save();
+    m_xTableTable.reset();
 }
 
 void SwAutoFormatDlg::Init( const SwTableAutoFormat* pSelFormat )
 {
-    Link<Button*,void> aLk( LINK( this, SwAutoFormatDlg, CheckHdl ) );
-    m_pBtnBorder->SetClickHdl( aLk );
-    m_pBtnFont->SetClickHdl( aLk );
-    m_pBtnPattern->SetClickHdl( aLk );
-    m_pBtnAlignment->SetClickHdl( aLk );
-    m_pBtnNumFormat->SetClickHdl( aLk );
-
-    m_pBtnAdd->SetClickHdl ( LINK( this, SwAutoFormatDlg, AddHdl ) );
-    m_pBtnRemove->SetClickHdl ( LINK( this, SwAutoFormatDlg, RemoveHdl ) );
-    m_pBtnRename->SetClickHdl ( LINK( this, SwAutoFormatDlg, RenameHdl ) );
-    m_pBtnOk->SetClickHdl ( LINK( this, SwAutoFormatDlg, OkHdl ) );
-    m_pLbFormat->SetSelectHdl( LINK( this, SwAutoFormatDlg, SelFormatHdl ) );
-
-    m_pBtnAdd->Enable( bSetAutoFormat );
-
-    nIndex = 0;
+    Link<weld::ToggleButton&, void> aLk(LINK(this, SwAutoFormatDlg, CheckHdl));
+    m_xBtnBorder->connect_toggled(aLk);
+    m_xBtnFont->connect_toggled(aLk);
+    m_xBtnPattern->connect_toggled(aLk);
+    m_xBtnAlignment->connect_toggled(aLk);
+    m_xBtnNumFormat->connect_toggled(aLk);
+
+    m_xBtnAdd->connect_clicked(LINK(this, SwAutoFormatDlg, AddHdl));
+    m_xBtnRemove->connect_clicked(LINK(this, SwAutoFormatDlg, RemoveHdl));
+    m_xBtnRename->connect_clicked(LINK(this, SwAutoFormatDlg, RenameHdl));
+    m_xLbFormat->connect_changed(LINK(this, SwAutoFormatDlg, SelFormatHdl));
+
+    m_xBtnAdd->set_sensitive(bSetAutoFormat);
+
+    m_nIndex = 0;
     if( !bSetAutoFormat )
     {
         // Then the list to be expanded by the entry "- none -".
-        m_pLbFormat->InsertEntry( SwViewShell::GetShellRes()->aStrNone );
+        m_xLbFormat->append(SwViewShell::GetShellRes()->aStrNone);
         nDfltStylePos = 1;
-        nIndex = 255;
+        m_nIndex = 255;
     }
 
-    for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size());
+    for (sal_uInt8 i = 0, nCount = 
static_cast<sal_uInt8>(m_xTableTable->size());
             i < nCount; i++)
     {
-        SwTableAutoFormat const& rFormat = (*pTableTable)[ i ];
-        m_pLbFormat->InsertEntry(rFormat.GetName());
+        SwTableAutoFormat const& rFormat = (*m_xTableTable)[ i ];
+        m_xLbFormat->append(rFormat.GetName());
         if (pSelFormat && rFormat.GetName() == pSelFormat->GetName())
-            nIndex = i;
+            m_nIndex = i;
     }
 
-    m_pLbFormat->SelectEntryPos( 255 != nIndex ? (nDfltStylePos + nIndex) : 0 
);
-    SelFormatHdl( *m_pLbFormat );
+    m_xLbFormat->select(255 != m_nIndex ? (nDfltStylePos + m_nIndex) : 0);
+    SelFormatHdl(*m_xLbFormat);
 }
 
 void SwAutoFormatDlg::UpdateChecks( const SwTableAutoFormat& rFormat, bool 
bEnable )
 {
-    m_pBtnNumFormat->Enable( bEnable );
-    m_pBtnNumFormat->Check( rFormat.IsValueFormat() );
+    m_xBtnNumFormat->set_sensitive(bEnable);
+    m_xBtnNumFormat->set_active(rFormat.IsValueFormat());
 
-    m_pBtnBorder->Enable( bEnable );
-    m_pBtnBorder->Check( rFormat.IsFrame() );
+    m_xBtnBorder->set_sensitive(bEnable);
+    m_xBtnBorder->set_active(rFormat.IsFrame());
 
-    m_pBtnFont->Enable( bEnable );
-    m_pBtnFont->Check( rFormat.IsFont() );
+    m_xBtnFont->set_sensitive(bEnable);
+    m_xBtnFont->set_active(rFormat.IsFont());
 
-    m_pBtnPattern->Enable( bEnable );
-    m_pBtnPattern->Check( rFormat.IsBackground() );
+    m_xBtnPattern->set_sensitive(bEnable);
+    m_xBtnPattern->set_active(rFormat.IsBackground());
 
-    m_pBtnAlignment->Enable( bEnable );
-    m_pBtnAlignment->Check( rFormat.IsJustify() );
+    m_xBtnAlignment->set_sensitive(bEnable);
+    m_xBtnAlignment->set_active(rFormat.IsJustify());
 }
 
 static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
@@ -186,40 +163,37 @@ static void lcl_SetProperties( SwTableAutoFormat* 
pTableAutoFormat, bool bVal )
     pTableAutoFormat->SetWidthHeight( bVal );
 }
 
-void SwAutoFormatDlg::FillAutoFormatOfIndex( SwTableAutoFormat*& rToFill ) 
const
+SwTableAutoFormat* SwAutoFormatDlg::FillAutoFormatOfIndex() const
 {
-    if( 255 != nIndex )
-    {
-        if( rToFill )
-            *rToFill = (*pTableTable)[ nIndex ];
-        else
-            rToFill = new SwTableAutoFormat( (*pTableTable)[ nIndex ] );
-    }
-    else
+    if( 255 != m_nIndex )
     {
-        delete rToFill;
-        rToFill = new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone 
);
-        lcl_SetProperties( rToFill, false );
+        return new SwTableAutoFormat( (*m_xTableTable)[ m_nIndex ] );
     }
+
+    SwTableAutoFormat* pRet = new SwTableAutoFormat( 
SwViewShell::GetShellRes()->aStrNone );
+    lcl_SetProperties(pRet, false);
+    return pRet;
 }
 
 // Handler:
-
-IMPL_LINK( SwAutoFormatDlg, CheckHdl, Button *, pBtn, void )
+IMPL_LINK(SwAutoFormatDlg, CheckHdl, weld::ToggleButton&, rBtn, void)
 {
-    SwTableAutoFormat* pData  = &(*pTableTable)[nIndex];
-    bool bCheck = static_cast<CheckBox*>(pBtn)->IsChecked(), bDataChgd = true;
-
-    if( pBtn == m_pBtnNumFormat )
-        pData->SetValueFormat( bCheck );
-    else if ( pBtn == m_pBtnBorder )
-        pData->SetFrame( bCheck );
-    else if ( pBtn == m_pBtnFont )
-        pData->SetFont( bCheck );
-    else if ( pBtn == m_pBtnPattern )
-        pData->SetBackground( bCheck );
-    else if ( pBtn == m_pBtnAlignment )
-        pData->SetJustify( bCheck );
+    if (m_nIndex == 255)
+        return;
+
+    SwTableAutoFormat& rData  = (*m_xTableTable)[m_nIndex];
+    bool bCheck = rBtn.get_active(), bDataChgd = true;
+
+    if (&rBtn == m_xBtnNumFormat.get())
+        rData.SetValueFormat( bCheck );
+    else if (&rBtn == m_xBtnBorder.get())
+        rData.SetFrame( bCheck );
+    else if (&rBtn == m_xBtnFont.get())
+        rData.SetFont( bCheck );
+    else if (&rBtn == m_xBtnPattern.get())
+        rData.SetBackground( bCheck );
+    else if (&rBtn == m_xBtnAlignment.get())
+        rData.SetJustify( bCheck );
     else
         bDataChgd = false;
 
@@ -227,20 +201,20 @@ IMPL_LINK( SwAutoFormatDlg, CheckHdl, Button *, pBtn, 
void )
     {
         if( !bCoreDataChanged )
         {
-            m_pBtnCancel->SetText( aStrClose );
+            m_xBtnCancel->set_label(aStrClose);
             bCoreDataChanged = true;
         }
 
-        m_pWndPreview->NotifyChange( *pData );
+        m_aWndPreview.NotifyChange(rData);
     }
 }
 
-IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl, Button*, void)
+IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl, weld::Button&, void)
 {
     bool bOk = false, bFormatInserted = false;
     while( !bOk )
     {
-        SwStringInputDlg aDlg(GetFrameWeld(), aStrTitle, aStrLabel, 
OUString());
+        SwStringInputDlg aDlg(m_xDialog.get(), aStrTitle, aStrLabel, 
OUString());
         if (RET_OK == aDlg.run())
         {
             const OUString aFormatName(aDlg.GetInputString());
@@ -248,11 +222,11 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl, Button*, void)
             if ( !aFormatName.isEmpty() )
             {
                 size_t n;
-                for( n = 0; n < pTableTable->size(); ++n )
-                    if( (*pTableTable)[n].GetName() == aFormatName )
+                for( n = 0; n < m_xTableTable->size(); ++n )
+                    if( (*m_xTableTable)[n].GetName() == aFormatName )
                         break;
 
-                if( n >= pTableTable->size() )
+                if( n >= m_xTableTable->size() )
                 {
                     // Format with the name does not already exist, so take up.
                     std::unique_ptr<SwTableAutoFormat> pNewData(
@@ -261,29 +235,29 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl, Button*, void)
                     SAL_WARN_IF(!bGetOk, "sw.ui", "GetTableAutoFormat failed 
for: " << aFormatName);
 
                     // Insert sorted!!
-                    for( n = 1; n < pTableTable->size(); ++n )
-                        if( (*pTableTable)[ n ].GetName() > aFormatName )
+                    for( n = 1; n < m_xTableTable->size(); ++n )
+                        if( (*m_xTableTable)[ n ].GetName() > aFormatName )
                             break;
 
-                    pTableTable->InsertAutoFormat(n, std::move(pNewData));
-                    m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n );
-                    m_pLbFormat->SelectEntryPos( nDfltStylePos + n );
+                    m_xTableTable->InsertAutoFormat(n, std::move(pNewData));
+                    m_xLbFormat->insert(aFormatName, nDfltStylePos + n);
+                    m_xLbFormat->select(nDfltStylePos + n);
                     bFormatInserted = true;
-                    m_pBtnAdd->Enable( false );
+                    m_xBtnAdd->set_sensitive(false);
                     if ( !bCoreDataChanged )
                     {
-                        m_pBtnCancel->SetText( aStrClose );
+                        m_xBtnCancel->set_label(aStrClose);
                         bCoreDataChanged = true;
                     }
 
-                    SelFormatHdl( *m_pLbFormat );
+                    SelFormatHdl(*m_xLbFormat);
                     bOk = true;
                 }
             }
 
             if( !bFormatInserted )
             {
-                std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Error, 
VclButtonsType::OkCancel, aStrInvalidFormat));
+                std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Error, 
VclButtonsType::OkCancel, aStrInvalidFormat));
                 bOk = RET_CANCEL == xBox->run();
             }
         }
@@ -292,47 +266,49 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl, Button*, void)
     }
 }
 
-IMPL_LINK_NOARG(SwAutoFormatDlg, RemoveHdl, Button*, void)
+IMPL_LINK_NOARG(SwAutoFormatDlg, RemoveHdl, weld::Button&, void)
 {
     OUString aMessage = aStrDelMsg;
     aMessage += "\n\n";
-    aMessage += m_pLbFormat->GetSelectedEntry();
+    aMessage += m_xLbFormat->get_selected();
     aMessage += "\n";
 
-    std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question,
+    std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question,
                                               VclButtonsType::OkCancel, 
aStrDelTitle));
     xBox->set_secondary_text(aMessage);
 
     if (xBox->run() == RET_OK)
     {
-        m_pLbFormat->RemoveEntry( nDfltStylePos + nIndex );
-        m_pLbFormat->SelectEntryPos( nDfltStylePos + nIndex-1 );
+        sal_uInt8 nIndex = m_nIndex;
+
+        m_xLbFormat->remove(nDfltStylePos + nIndex);
+        m_xLbFormat->select(nDfltStylePos + nIndex - 1);
 
-        pTableTable->EraseAutoFormat(nIndex);
-        nIndex--;
+        m_xTableTable->EraseAutoFormat(nIndex);
+        m_nIndex = nIndex - 1;
 
-        if( !nIndex )
+        if( !m_nIndex )
         {
-            m_pBtnRemove->Enable(false);
-            m_pBtnRename->Enable(false);
+            m_xBtnRemove->set_sensitive(false);
+            m_xBtnRename->set_sensitive(false);
         }
 
         if( !bCoreDataChanged )
         {
-            m_pBtnCancel->SetText( aStrClose );
+            m_xBtnCancel->set_label(aStrClose);
             bCoreDataChanged = true;
         }
     }
 
-    SelFormatHdl( *m_pLbFormat );
+    SelFormatHdl(*m_xLbFormat);
 }
 
-IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl, Button*, void)
+IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl, weld::Button&, void)
 {
     bool bOk = false;
     while( !bOk )
     {
-        SwStringInputDlg aDlg(GetFrameWeld(), aStrRenameTitle, aStrLabel, 
m_pLbFormat->GetSelectedEntry());
+        SwStringInputDlg aDlg(m_xDialog.get(), aStrRenameTitle, aStrLabel, 
m_xLbFormat->get_selected());
         if (aDlg.run() == RET_OK)
         {
             bool bFormatRenamed = false;
@@ -341,37 +317,39 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl, Button*, void)
             if ( !aFormatName.isEmpty() )
             {
                 size_t n;
-                for( n = 0; n < pTableTable->size(); ++n )
-                    if ((*pTableTable)[n].GetName() == aFormatName)
+                for( n = 0; n < m_xTableTable->size(); ++n )
+                    if ((*m_xTableTable)[n].GetName() == aFormatName)
                         break;
 
-                if( n >= pTableTable->size() )
+                if( n >= m_xTableTable->size() )
                 {
+                    sal_uInt8 nIndex = m_nIndex;
+
                     // no format with this name exists, so rename it
-                    m_pLbFormat->RemoveEntry( nDfltStylePos + nIndex );
+                    m_xLbFormat->remove(nDfltStylePos + nIndex);
                     std::unique_ptr<SwTableAutoFormat> p(
-                            pTableTable->ReleaseAutoFormat(nIndex));
+                            m_xTableTable->ReleaseAutoFormat(nIndex));
 
                     p->SetName( aFormatName );
 
                     // keep all arrays sorted!
-                    for( n = 1; n < pTableTable->size(); ++n )
-                        if ((*pTableTable)[n].GetName() > aFormatName)
+                    for( n = 1; n < m_xTableTable->size(); ++n )
+                        if ((*m_xTableTable)[n].GetName() > aFormatName)
                         {
                             break;
                         }
 
-                    pTableTable->InsertAutoFormat( n, std::move(p) );
-                    m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n );
-                    m_pLbFormat->SelectEntryPos( nDfltStylePos + n );
+                    m_xTableTable->InsertAutoFormat( n, std::move(p) );
+                    m_xLbFormat->insert(aFormatName, nDfltStylePos + n);
+                    m_xLbFormat->select(nDfltStylePos + n);
 
                     if ( !bCoreDataChanged )
                     {
-                        m_pBtnCancel->SetText( aStrClose );
+                        m_xBtnCancel->set_label(aStrClose);
                         bCoreDataChanged = true;
                     }
 
-                    SelFormatHdl( *m_pLbFormat );
+                    SelFormatHdl(*m_xLbFormat);
                     bOk = true;
                     bFormatRenamed = true;
                 }
@@ -379,7 +357,7 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl, Button*, void)
 
             if( !bFormatRenamed )
             {
-                std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Error, 
VclButtonsType::OkCancel, aStrInvalidFormat));
+                std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Error, 
VclButtonsType::OkCancel, aStrInvalidFormat));
                 bOk = RET_CANCEL == xBox->run();
             }
         }
@@ -388,38 +366,40 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl, Button*, void)
     }
 }
 
-IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl, ListBox&, void)
+IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl, weld::TreeView&, void)
 {
     bool bBtnEnable = false;
-    sal_uInt8 nSelPos = 
static_cast<sal_uInt8>(m_pLbFormat->GetSelectedEntryPos()), nOldIdx = nIndex;
-    if( nSelPos >= nDfltStylePos )
+    sal_uInt8 nOldIdx = m_nIndex;
+    int nSelPos = m_xLbFormat->get_selected_index();
+    if (nSelPos >= nDfltStylePos)
     {
-        nIndex = nSelPos - nDfltStylePos;
-        m_pWndPreview->NotifyChange( (*pTableTable)[nIndex] );
-        bBtnEnable = 0 != nIndex;
-        UpdateChecks( (*pTableTable)[nIndex], true );
+        m_nIndex = nSelPos - nDfltStylePos;
+        m_aWndPreview.NotifyChange((*m_xTableTable)[m_nIndex]);
+        bBtnEnable = 0 != m_nIndex;
+        UpdateChecks( (*m_xTableTable)[m_nIndex], true );
     }
     else
     {
-        nIndex = 255;
+        m_nIndex = 255;
 
         SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone );
         lcl_SetProperties( &aTmp, false );
 
-        if( nOldIdx != nIndex )
-            m_pWndPreview->NotifyChange( aTmp );
+        if (nOldIdx != m_nIndex)
+            m_aWndPreview.NotifyChange(aTmp);
         UpdateChecks( aTmp, false );
     }
 
-    m_pBtnRemove->Enable( bBtnEnable );
-    m_pBtnRename->Enable( bBtnEnable );
+    m_xBtnRemove->set_sensitive(bBtnEnable);
+    m_xBtnRename->set_sensitive(bBtnEnable);
 }
 
-IMPL_LINK_NOARG(SwAutoFormatDlg, OkHdl, Button*, void)
+short SwAutoFormatDlg::run()
 {
-    if( bSetAutoFormat )
-        pShell->SetTableStyle((*pTableTable)[nIndex]);
-    EndDialog( RET_OK );
+    short nRet = m_xDialog->run();
+    if (nRet == RET_OK && bSetAutoFormat)
+        pShell->SetTableStyle((*m_xTableTable)[m_nIndex]);
+    return nRet;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/autoformatpreview.hxx 
b/sw/source/uibase/inc/autoformatpreview.hxx
index 30be17fc218d..3854e8b74090 100644
--- a/sw/source/uibase/inc/autoformatpreview.hxx
+++ b/sw/source/uibase/inc/autoformatpreview.hxx
@@ -29,16 +29,64 @@
 #include <vcl/outdev.hxx>
 #include <vcl/vclptr.hxx>
 #include <vcl/virdev.hxx>
+#include <vcl/weld.hxx>
 #include <vcl/font.hxx>
 
 #include "wrtsh.hxx"
 #include <tblafmt.hxx>
 
-class AutoFormatPreview : public vcl::Window
+class AutoFormatPreview
 {
 public:
-    AutoFormatPreview(vcl::Window* pParent, WinBits nStyle);
-    virtual ~AutoFormatPreview() override;
+    AutoFormatPreview(weld::DrawingArea* pDrawingArea);
+
+    void NotifyChange(const SwTableAutoFormat& rNewData);
+
+    void DetectRTL(SwWrtShell const* pWrtShell);
+
+private:
+    std::unique_ptr<weld::DrawingArea> mxDrawingArea;
+    SwTableAutoFormat aCurData;
+    svx::frame::Array maArray; /// Implementation to draw the frame borders.
+    bool bFitWidth;
+    bool mbRTL;
+    Size aPrvSize;
+    long nLabelColWidth;
+    long nDataColWidth1;
+    long nDataColWidth2;
+    long nRowHeight;
+    const OUString aStrJan;
+    const OUString aStrFeb;
+    const OUString aStrMar;
+    const OUString aStrNorth;
+    const OUString aStrMid;
+    const OUString aStrSouth;
+    const OUString aStrSum;
+    std::unique_ptr<SvNumberFormatter> mxNumFormat;
+
+    uno::Reference<i18n::XBreakIterator> m_xBreak;
+
+    void Init();
+    DECL_LINK(DoPaint, vcl::RenderContext&, void);
+    DECL_LINK(DoResize, const Size& rSize, void);
+    void CalcCellArray(bool bFitWidth);
+    void CalcLineMap();
+    void PaintCells(vcl::RenderContext& rRenderContext);
+
+    sal_uInt8 GetFormatIndex(size_t nCol, size_t nRow) const;
+
+    void DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t 
nRow);
+    void DrawBackground(vcl::RenderContext& rRenderContext);
+
+    void MakeFonts(vcl::RenderContext& rRenderContext, sal_uInt8 nIndex, 
vcl::Font& rFont,
+                   vcl::Font& rCJKFont, vcl::Font& rCTLFont);
+};
+
+class AutoFormatPreviewWindow : public vcl::Window
+{
+public:
+    AutoFormatPreviewWindow(vcl::Window* pParent, WinBits nStyle);
+    virtual ~AutoFormatPreviewWindow() override;
     virtual void dispose() override;
 
     void NotifyChange(const SwTableAutoFormat& rNewData);
diff --git a/sw/source/uibase/inc/convert.hxx b/sw/source/uibase/inc/convert.hxx
index faf7521a68d4..15fc35be7ab8 100644
--- a/sw/source/uibase/inc/convert.hxx
+++ b/sw/source/uibase/inc/convert.hxx
@@ -53,7 +53,7 @@ class SwConvertTableDlg: public SfxModalDialog
     VclPtr<PushButton>     mpAutoFormatBtn;
 
     OUString        sConvertTextTable;
-    SwTableAutoFormat* pTAutoFormat;
+    std::unique_ptr<SwTableAutoFormat> mxTAutoFormat;
     SwWrtShell*     pShell;
 
     DECL_LINK( AutoFormatHdl, Button*, void );
diff --git a/sw/source/uibase/inc/dbinsdlg.hxx 
b/sw/source/uibase/inc/dbinsdlg.hxx
index 94214ef4e37a..2ed40956a68d 100644
--- a/sw/source/uibase/inc/dbinsdlg.hxx
+++ b/sw/source/uibase/inc/dbinsdlg.hxx
@@ -126,7 +126,7 @@ class SwInsertDBColAutoPilot : public SfxModalDialog, 
public utl::ConfigItem
     OUString        sNoTmpl;
 
     SwView*         pView;
-    SwTableAutoFormat* pTAutoFormat;
+    std::unique_ptr<SwTableAutoFormat> m_xTAutoFormat;
 
     SfxItemSet*     pTableSet;
     SwTableRep*     pRep;
diff --git a/sw/source/uibase/inc/instable.hxx 
b/sw/source/uibase/inc/instable.hxx
index dfc82f034c9e..288f9debb7f1 100644
--- a/sw/source/uibase/inc/instable.hxx
+++ b/sw/source/uibase/inc/instable.hxx
@@ -54,7 +54,7 @@ class SwInsTableDlg : public SfxModalDialog
 
     VclPtr<ListBox>         m_pLbFormat;
 
-    VclPtr<AutoFormatPreview> m_pWndPreview;
+    VclPtr<AutoFormatPreviewWindow> m_pWndPreview;
 
     SwWrtShell*     pShell;
     SwTableAutoFormatTable* pTableTable;
diff --git a/sw/source/uibase/inc/tautofmt.hxx 
b/sw/source/uibase/inc/tautofmt.hxx
index cd294065b377..e7870e2c6f17 100644
--- a/sw/source/uibase/inc/tautofmt.hxx
+++ b/sw/source/uibase/inc/tautofmt.hxx
@@ -23,10 +23,7 @@
 #include <sfx2/basedlgs.hxx>
 #include <sal/types.h>
 #include <rtl/ustring.hxx>
-#include <vcl/vclreferencebase.hxx>
-#include <vcl/button.hxx>
-#include <vcl/layout.hxx>
-#include <vcl/window.hxx>
+#include <vcl/weld.hxx>
 
 #include "wrtsh.hxx"
 #include "autoformatpreview.hxx"
@@ -38,20 +35,23 @@ class SwWrtShell;
 
 enum AutoFormatLine { TOP_LINE, BOTTOM_LINE, LEFT_LINE, RIGHT_LINE };
 
-class SwAutoFormatDlg : public SfxModalDialog
+class SwAutoFormatDlg
 {
-    VclPtr<ListBox>        m_pLbFormat;
-    VclPtr<VclContainer>   m_pFormatting;
-    VclPtr<CheckBox>       m_pBtnNumFormat;
-    VclPtr<CheckBox>       m_pBtnBorder;
-    VclPtr<CheckBox>       m_pBtnFont;
-    VclPtr<CheckBox>       m_pBtnPattern;
-    VclPtr<CheckBox>       m_pBtnAlignment;
-    VclPtr<OKButton>       m_pBtnOk;
-    VclPtr<CancelButton>   m_pBtnCancel;
-    VclPtr<PushButton>     m_pBtnAdd;
-    VclPtr<PushButton>     m_pBtnRemove;
-    VclPtr<PushButton>     m_pBtnRename;
+    std::unique_ptr<weld::Builder> m_xBuilder;
+    std::unique_ptr<weld::Dialog> m_xDialog;
+    std::unique_ptr<weld::TreeView> m_xLbFormat;
+    std::unique_ptr<weld::Container> m_xFormatting;
+    std::unique_ptr<weld::CheckButton> m_xBtnNumFormat;
+    std::unique_ptr<weld::CheckButton> m_xBtnBorder;
+    std::unique_ptr<weld::CheckButton> m_xBtnFont;
+    std::unique_ptr<weld::CheckButton> m_xBtnPattern;
+    std::unique_ptr<weld::CheckButton> m_xBtnAlignment;
+    std::unique_ptr<weld::Button> m_xBtnCancel;
+    std::unique_ptr<weld::Button> m_xBtnAdd;
+    std::unique_ptr<weld::Button> m_xBtnRemove;
+    std::unique_ptr<weld::Button> m_xBtnRename;
+    AutoFormatPreview m_aWndPreview;
+    std::unique_ptr<SwTableAutoFormatTable> m_xTableTable;
     OUString        aStrTitle;
     OUString        aStrLabel;
     OUString        aStrClose;
@@ -59,33 +59,31 @@ class SwAutoFormatDlg : public SfxModalDialog
     OUString        aStrDelMsg;
     OUString        aStrRenameTitle;
     OUString        aStrInvalidFormat;
-    VclPtr<AutoFormatPreview> m_pWndPreview;
 
-    SwWrtShell*             pShell;
-    SwTableAutoFormatTable*     pTableTable;
-    sal_uInt8                   nIndex;
-    sal_uInt8                   nDfltStylePos;
-    bool                    bCoreDataChanged : 1;
-    bool                    bSetAutoFormat : 1;
+    SwWrtShell*     pShell;
+    sal_uInt8       m_nIndex;
+    sal_uInt8       nDfltStylePos;
+    bool            bCoreDataChanged : 1;
+    bool            bSetAutoFormat : 1;
 
     void Init( const SwTableAutoFormat* pSelFormat );
     void UpdateChecks( const SwTableAutoFormat&, bool bEnableBtn );
 
-    DECL_LINK( CheckHdl, Button*, void );
-    DECL_LINK(OkHdl, Button*, void);
-    DECL_LINK( AddHdl, Button*, void );
-    DECL_LINK( RemoveHdl, Button*, void );
-    DECL_LINK( RenameHdl, Button*, void );
-    DECL_LINK( SelFormatHdl, ListBox&, void );
+    DECL_LINK(CheckHdl, weld::ToggleButton&, void);
+    DECL_LINK(AddHdl, weld::Button&, void);
+    DECL_LINK(RemoveHdl, weld::Button&, void);
+    DECL_LINK(RenameHdl, weld::Button&, void);
+    DECL_LINK(SelFormatHdl, weld::TreeView&, void);
 
 public:
-    SwAutoFormatDlg( vcl::Window* pParent, SwWrtShell* pShell,
-                        bool bSetAutoFormat,
-                        const SwTableAutoFormat* pSelFormat );
-    virtual ~SwAutoFormatDlg() override;
-    virtual void dispose() override;
+    SwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pShell,
+                    bool bSetAutoFormat, const SwTableAutoFormat* pSelFormat);
 
-    void FillAutoFormatOfIndex( SwTableAutoFormat*& rToFill ) const;
+    short run();
+
+    SwTableAutoFormat* FillAutoFormatOfIndex() const;
+
+    ~SwAutoFormatDlg();
 };
 
 #endif // SW_AUTOFMT_HXX
diff --git a/sw/source/uibase/shells/tabsh.cxx 
b/sw/source/uibase/shells/tabsh.cxx
index 022bb8b4dd44..907d210997c3 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -827,7 +827,7 @@ void SwTableShell::Execute(SfxRequest &rReq)
             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
             OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-            ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(&GetView().GetViewFrame()->GetWindow(), 
&rSh));
+            ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(GetView().GetViewFrame()->GetWindow().GetFrameWeld(),
 &rSh));
             OSL_ENSURE(pDlg, "Dialog creation failed!");
             pDlg->Execute();
             break;
diff --git a/sw/uiconfig/swriter/ui/autoformattable.ui 
b/sw/uiconfig/swriter/ui/autoformattable.ui
index be0edd705823..b334d39b468d 100644
--- a/sw/uiconfig/swriter/ui/autoformattable.ui
+++ b/sw/uiconfig/swriter/ui/autoformattable.ui
@@ -1,73 +1,36 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.20.2 -->
 <interface domain="sw">
   <requires lib="gtk+" version="3.0"/>
-  <requires lib="LibreOffice" version="1.0"/>
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="AutoFormatTableDialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
     <property name="title" translatable="yes" 
context="autoformattable|AutoFormatTableDialog">AutoFormat</property>
     <property name="resizable">False</property>
+    <property name="modal">True</property>
     <property name="type_hint">dialog</property>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox" id="dialog-action_area1">
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
             <property name="homogeneous">True</property>
-            <property name="layout_style">start</property>
-            <child>
-              <object class="GtkButton" id="ok">
-                <property name="label">gtk-ok</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
+            <property name="layout_style">end</property>
             <child>
               <object class="GtkButton" id="cancel">
                 <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="help">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="add">
-                <property name="label">gtk-add</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
+                <property name="receives_default">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -77,11 +40,13 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="remove">
-                <property name="label">gtk-delete</property>
+              <object class="GtkButton" id="ok">
+                <property name="label">gtk-ok</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -91,16 +56,18 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="rename">
-                <property name="label" translatable="yes" 
context="autoformattable|rename">Rename</property>
+              <object class="GtkButton" id="help">
+                <property name="label">gtk-help</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
                 <property name="position">5</property>
+                <property name="secondary">True</property>
               </packing>
             </child>
           </object>
@@ -130,50 +97,129 @@
                     <property name="top_padding">6</property>
                     <property name="left_padding">12</property>
                     <child>
-                      <object class="GtkGrid" id="grid2">
-                        <property name="width_request">400</property>
-                        <property name="height_request">200</property>
+                      <object class="GtkGrid">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="row_spacing">6</property>
-                        <property name="column_spacing">6</property>
+                        <property name="column_spacing">12</property>
                         <child>
-                          <object class="swuilo-AutoFormatPreview" 
id="preview">
-                            <property name="width_request">200</property>
+                          <object class="GtkGrid" id="grid2">
+                            <property name="width_request">450</property>
                             <property name="height_request">200</property>
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="hexpand">True</property>
                             <property name="vexpand">True</property>
+                            <property name="row_spacing">6</property>
+                            <property name="column_spacing">6</property>
+                            <property name="column_homogeneous">True</property>
+                            <child>
+                              <object class="GtkDrawingArea" id="preview">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="hexpand">True</property>
+                                <property name="vexpand">True</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="top_attach">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkScrolledWindow">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="hexpand">True</property>
+                                <property name="vexpand">True</property>
+                                <property name="shadow_type">in</property>
+                                <child>
+                                  <object class="GtkTreeView" id="formatlb">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="vexpand">True</property>
+                                    <property 
name="model">liststore1</property>
+                                    <property 
name="headers_visible">False</property>
+                                    <property 
name="headers_clickable">False</property>
+                                    <property 
name="enable_search">False</property>
+                                    <property 
name="show_expanders">False</property>
+                                    <child internal-child="selection">
+                                      <object class="GtkTreeSelection" 
id="treeview-selection1"/>
+                                    </child>
+                                    <child>
+                                      <object class="GtkTreeViewColumn" 
id="treeviewcolumn1">
+                                        <child>
+                                          <object class="GtkCellRendererText" 
id="cellrenderertext1"/>
+                                          <attributes>
+                                            <attribute 
name="text">0</attribute>
+                                          </attributes>
+                                        </child>
+                                      </object>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">0</property>
+                                <property name="top_attach">0</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
-                            <property name="left_attach">1</property>
+                            <property name="left_attach">0</property>
                             <property name="top_attach">0</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkScrolledWindow" 
id="scrolledwindow1">
+                          <object class="GtkButtonBox">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="shadow_type">in</property>
+                            <property name="can_focus">False</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">6</property>
+                            <property name="layout_style">start</property>
                             <child>
-                              <object class="GtkTreeView" id="formatlb:border">
+                              <object class="GtkButton" id="add">
+                                <property name="label">gtk-add</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="vexpand">True</property>
-                                <child internal-child="selection">
-                                  <object class="GtkTreeSelection" 
id="treeview-selection1"/>
-                                </child>
+                                <property 
name="receives_default">False</property>
+                                <property name="use_stock">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="remove">
+                                <property name="label">gtk-delete</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property 
name="receives_default">False</property>
+                                <property name="use_stock">True</property>
                               </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="rename">
+                                <property name="label" translatable="yes" 
context="autoformattable|rename">Rename</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property 
name="receives_default">False</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">2</property>
+                              </packing>
                             </child>
                           </object>
                           <packing>
-                            <property name="left_attach">0</property>
+                            <property name="left_attach">1</property>
                             <property name="top_attach">0</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                       </object>
@@ -228,8 +274,6 @@
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">0</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
@@ -245,8 +289,6 @@
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">1</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
@@ -262,8 +304,6 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">0</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
@@ -279,8 +319,6 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">1</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
@@ -296,8 +334,6 @@
                           <packing>
                             <property name="left_attach">2</property>
                             <property name="top_attach">0</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
@@ -335,12 +371,12 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-5">ok</action-widget>
       <action-widget response="-6">cancel</action-widget>
+      <action-widget response="-5">ok</action-widget>
       <action-widget response="-11">help</action-widget>
-      <action-widget response="0">add</action-widget>
-      <action-widget response="0">remove</action-widget>
-      <action-widget response="0">rename</action-widget>
     </action-widgets>
+    <child>
+      <placeholder/>
+    </child>
   </object>
 </interface>
diff --git a/sw/uiconfig/swriter/ui/inserttable.ui 
b/sw/uiconfig/swriter/ui/inserttable.ui
index deb2ddd8936c..169a7762e3fc 100644
--- a/sw/uiconfig/swriter/ui/inserttable.ui
+++ b/sw/uiconfig/swriter/ui/inserttable.ui
@@ -343,7 +343,7 @@
                             <property name="row_spacing">6</property>
                             <property name="column_spacing">6</property>
                             <child>
-                              <object class="swuilo-AutoFormatPreview" 
id="previewinstable">
+                              <object class="swuilo-AutoFormatPreviewWindow" 
id="previewinstable">
                                 <property name="width_request">200</property>
                                 <property name="height_request">200</property>
                                 <property name="visible">True</property>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to