sw/Library_swui.mk                         |    1 
 sw/source/ui/table/autoformatpreview.cxx   |  482 ++++++++++++++++++++++++++
 sw/source/ui/table/instable.cxx            |  140 +++++--
 sw/source/ui/table/tautofmt.cxx            |  532 -----------------------------
 sw/source/uibase/inc/autoformatpreview.hxx |   91 ++++
 sw/source/uibase/inc/instable.hxx          |   62 ++-
 sw/source/uibase/inc/tautofmt.hxx          |   21 -
 sw/uiconfig/swriter/ui/inserttable.ui      |   71 ++-
 8 files changed, 773 insertions(+), 627 deletions(-)

New commits:
commit f7bf3cf5c9c7f72da0c881b50c2ccc4b6d550af2
Author: Furkan Tokac <furkantoka...@gmail.com>
Date:   Thu Feb 22 23:17:59 2018 +0200

    tdf#113558: Replace 'AutoFormat' button in insert table dialog.
    
    Writer > Table > Insert Table... > AutoFormat part is moved to
    "Insert Table..." dialog box with realtime style preview.
    
    Change-Id: I72ed46401fb053156a4787450fc974951923d049
    Reviewed-on: https://gerrit.libreoffice.org/49886
    Reviewed-by: Furkan Tokac <furkantoka...@gmail.com>
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Heiko Tietze <tietze.he...@gmail.com>
    Tested-by: Heiko Tietze <tietze.he...@gmail.com>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk
index e33d16450b11..23c737e2a740 100644
--- a/sw/Library_swui.mk
+++ b/sw/Library_swui.mk
@@ -146,6 +146,7 @@ $(eval $(call gb_Library_add_exception_objects,swui,\
     sw/source/ui/misc/titlepage \
     sw/source/ui/table/colwd \
     sw/source/ui/table/convert \
+    sw/source/ui/table/autoformatpreview \
     sw/source/ui/table/instable \
     sw/source/ui/table/mergetbl \
     sw/source/ui/table/rowht \
diff --git a/sw/source/ui/table/autoformatpreview.cxx 
b/sw/source/ui/table/autoformatpreview.cxx
new file mode 100644
index 000000000000..8386dcb16cb3
--- /dev/null
+++ b/sw/source/ui/table/autoformatpreview.cxx
@@ -0,0 +1,482 @@
+/* -*- 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 <vcl/builderfactory.hxx>
+#include <com/sun/star/i18n/BreakIterator.hpp>
+#include <svtools/scriptedtext.hxx>
+#include <drawinglayer/processor2d/processor2dtools.hxx>
+#include <strings.hrc>
+
+#include <autoformatpreview.hxx>
+
+#define FRAME_OFFSET 4
+
+AutoFormatPreview::AutoFormatPreview(vcl::Window* pParent, WinBits nStyle)
+    : Window(pParent, nStyle)
+    , aCurData(OUString())
+    , aVD(VclPtr<VirtualDevice>::Create(*this))
+    , 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);
+    pNumFormat = new SvNumberFormatter(xContext, LANGUAGE_SYSTEM);
+
+    Init();
+}
+
+VCL_BUILDER_FACTORY_CONSTRUCTOR(AutoFormatPreview, 0)
+
+void AutoFormatPreview::Resize()
+{
+    aPrvSize = Size(GetSizePixel().Width() - 6, GetSizePixel().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();
+}
+
+AutoFormatPreview::~AutoFormatPreview() { disposeOnce(); }
+
+void AutoFormatPreview::dispose()
+{
+    delete pNumFormat;
+    vcl::Window::dispose();
+}
+
+static void lcl_SetFontProperties(vcl::Font& rFont, const SvxFontItem& 
rFontItem,
+                                  const SvxWeightItem& rWeightItem,
+                                  const SvxPostureItem& rPostureItem)
+{
+    rFont.SetFamily(rFontItem.GetFamily());
+    rFont.SetFamilyName(rFontItem.GetFamilyName());
+    rFont.SetStyleName(rFontItem.GetStyleName());
+    rFont.SetCharSet(rFontItem.GetCharSet());
+    rFont.SetPitch(rFontItem.GetPitch());
+    rFont.SetWeight(rWeightItem.GetValue());
+    rFont.SetItalic(rPostureItem.GetValue());
+}
+
+#define SETONALLFONTS(MethodName, Value)                                       
                    \
+    rFont.MethodName(Value);                                                   
                    \
+    rCJKFont.MethodName(Value);                                                
                    \
+    rCTLFont.MethodName(Value);
+
+void AutoFormatPreview::MakeFonts(sal_uInt8 nIndex, vcl::Font& rFont, 
vcl::Font& rCJKFont,
+                                  vcl::Font& rCTLFont)
+{
+    const SwBoxAutoFormat& rBoxFormat = aCurData.GetBoxFormat(nIndex);
+
+    rFont = rCJKFont = rCTLFont = GetFont();
+    Size aFontSize(rFont.GetFontSize().Width(), 10 * 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 = 
pNumFormat->GetIndexPuttingAndConverting(sFormat, eLng, eSys,
+                                                                           
nType, bNew, nCheckPos);
+                Color* pDummy;
+                pNumFormat->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(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.AdjustY((nRowHeight - aStrSize.Height()) / 2);
+
+    // horizontal
+    if (mbRTL)
+        aPos.AdjustX(nRightX);
+    else if (aCurData.IsJustify())
+    {
+        const SvxAdjustItem& rAdj = 
aCurData.GetBoxFormat(nFormatIndex).GetAdjust();
+        switch (rAdj.GetAdjust())
+        {
+            case SvxAdjust::Left:
+                aPos.AdjustX(FRAME_OFFSET);
+                break;
+            case SvxAdjust::Right:
+                aPos.AdjustX(nRightX);
+                break;
+            default:
+                aPos.AdjustX((cellRect.GetWidth() - aStrSize.Width()) / 2);
+                break;
+        }
+    }
+    else
+    {
+        // Standard align:
+        if (nCol == 0 || nIndex == 4)
+        {
+            // Text-Label left or sum left aligned
+            aPos.AdjustX(FRAME_OFFSET);
+        }
+        else
+        {
+            // numbers/dates right aligned
+            aPos.AdjustX(nRightX);
+        }
+    }
+
+    aScriptedText.DrawText(aPos);
+}
+
+#undef FRAME_OFFSET
+
+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()
+{
+    SetBorderStyle(GetBorderStyle() | WindowBorderStyle::MONO);
+    maArray.Initialize(5, 5);
+    nLabelColWidth = 0;
+    nDataColWidth1 = 0;
+    nDataColWidth2 = 0;
+    nRowHeight = 0;
+    CalcCellArray(false);
+    CalcLineMap();
+}
+
+void AutoFormatPreview::CalcCellArray(bool _bFitWidth)
+{
+    maArray.SetXOffset(2);
+    maArray.SetAllColWidths(_bFitWidth ? nDataColWidth2 : nDataColWidth1);
+    maArray.SetColWidth(0, nLabelColWidth);
+    maArray.SetColWidth(4, nLabelColWidth);
+
+    maArray.SetYOffset(2);
+    maArray.SetAllRowHeights(nRowHeight);
+
+    aPrvSize.setWidth(maArray.GetWidth() + 4);
+    aPrvSize.setHeight(maArray.GetHeight() + 4);
+}
+
+inline void lclSetStyleFromBorder(svx::frame::Style& rStyle,
+                                  const ::editeng::SvxBorderLine* pBorder)
+{
+    rStyle.Set(pBorder, 0.05, 5);
+}
+
+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();
+    Invalidate(tools::Rectangle(Point(0, 0), GetSizePixel()));
+}
+
+void AutoFormatPreview::DoPaint(vcl::RenderContext& rRenderContext)
+{
+    DrawModeFlags nOldDrawMode = aVD->GetDrawMode();
+    if (rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
+        aVD->SetDrawMode(DrawModeFlags::SettingsLine | 
DrawModeFlags::SettingsFill
+                         | DrawModeFlags::SettingsText | 
DrawModeFlags::SettingsGradient);
+
+    Bitmap thePreview;
+    Point aCenterPos;
+    Size theWndSize = GetSizePixel();
+    Color oldColor;
+    vcl::Font aFont;
+
+    aFont = aVD->GetFont();
+    aFont.SetTransparent(true);
+
+    aVD->SetFont(aFont);
+    aVD->SetLineColor();
+    const Color& rWinColor = 
rRenderContext.GetSettings().GetStyleSettings().GetWindowColor();
+    aVD->SetBackground(Wallpaper(rWinColor));
+    aVD->SetFillColor(rWinColor);
+    aVD->SetOutputSizePixel(aPrvSize);
+
+    // Draw cells on virtual device
+    // and save the result
+    PaintCells(*aVD.get());
+    thePreview = aVD->GetBitmap(Point(0, 0), aPrvSize);
+
+    // Draw the Frame and center the preview:
+    // (virtual Device for window output)
+    aVD->SetOutputSizePixel(theWndSize);
+    oldColor = aVD->GetLineColor();
+    aVD->SetLineColor();
+    aVD->DrawRect(tools::Rectangle(Point(0, 0), theWndSize));
+
+    rRenderContext.SetLineColor(oldColor);
+
+    aCenterPos = Point((theWndSize.Width() - aPrvSize.Width()) / 2,
+                       (theWndSize.Height() - aPrvSize.Height()) / 2);
+    aVD->DrawBitmap(aCenterPos, thePreview);
+
+    // Output in the preview window:
+    rRenderContext.DrawBitmap(Point(0, 0), aVD->GetBitmap(Point(0, 0), 
theWndSize));
+
+    aVD->SetDrawMode(nOldDrawMode);
+}
+
+void AutoFormatPreview::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& /*rRect*/)
+{
+    DoPaint(rRenderContext);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/table/instable.cxx b/sw/source/ui/table/instable.cxx
index 90f50d67ace1..1cb841d5ef01 100644
--- a/sw/source/ui/table/instable.cxx
+++ b/sw/source/ui/table/instable.cxx
@@ -17,21 +17,13 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <vcl/msgbox.hxx>
-
-#include <wrtsh.hxx>
-#include <view.hxx>
-#include <itabenum.hxx>
 #include <instable.hxx>
-#include <tblafmt.hxx>
+#include <shellres.hxx>
 #include <modcfg.hxx>
 #include <swmodule.hxx>
 #include <sfx2/htmlmode.hxx>
 #include <viewopt.hxx>
-
 #include <swabstdlg.hxx>
-#include <swuiexp.hxx>
-#include <memory>
 
 #define ROW_COL_PROD 16384
 
@@ -44,8 +36,6 @@ void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& 
rRow, sal_uInt16& rC
     rRow = static_cast<sal_uInt16>(m_pRowNF->GetValue());
     rCol = static_cast<sal_uInt16>(m_pColNF->GetValue());
 
-    if (m_pBorderCB->IsChecked())
-        nInsMode |= tabopts::DEFAULT_BORDER;
     if (m_pHeaderCB->IsChecked())
         nInsMode |= tabopts::HEADLINE;
     if (m_pRepeatHeaderCB->IsEnabled() && m_pRepeatHeaderCB->IsChecked())
@@ -77,11 +67,11 @@ SwInsTableDlg::SwInsTableDlg( SwView& rView )
     get(m_pHeaderCB, "headercb");
     get(m_pRepeatHeaderCB, "repeatcb");
     get(m_pDontSplitCB, "dontsplitcb");
-    get(m_pBorderCB, "bordercb");
-    get(m_pAutoFormatBtn, "autoformat");
     get(m_pInsertBtn, "ok");
     get(m_pRepeatGroup, "repeatgroup");
     get(m_pRepeatHeaderNF, "repeatheaderspin");
+    get(m_pLbFormat, "formatlbinstable");
+    get(m_pWndPreview, "previewinstable");
 
     m_pNameEdit->SetText(pShell->GetUniqueTableName());
     m_pNameEdit->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName));
@@ -90,7 +80,6 @@ SwInsTableDlg::SwInsTableDlg( SwView& rView )
 
     m_pRowNF->SetMax(ROW_COL_PROD/m_pColNF->GetValue());
     m_pColNF->SetMax(ROW_COL_PROD/m_pRowNF->GetValue());
-    m_pAutoFormatBtn->SetClickHdl(LINK(this, SwInsTableDlg, AutoFormatHdl));
 
     m_pInsertBtn->SetClickHdl(LINK(this, SwInsTableDlg, OKHdl));
 
@@ -103,19 +92,13 @@ SwInsTableDlg::SwInsTableDlg( SwView& rView )
     m_pHeaderCB->Check( 0 != (nInsTableFlags & tabopts::HEADLINE) );
     m_pRepeatHeaderCB->Check(aInsOpts.mnRowsToRepeat > 0);
     if(bHTMLMode)
-    {
         m_pDontSplitCB->Hide();
-        m_pBorderCB->SetPosPixel(m_pDontSplitCB->GetPosPixel());
-    }
     else
-    {
         m_pDontSplitCB->Check( 0 == (nInsTableFlags & tabopts::SPLIT_LAYOUT) );
-    }
-    m_pBorderCB->Check( 0 != (nInsTableFlags & tabopts::DEFAULT_BORDER) );
 
     m_pRepeatHeaderNF->SetModifyHdl( LINK( this, SwInsTableDlg, 
ModifyRepeatHeaderNF_Hdl ) );
-    m_pHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl));
-    m_pRepeatHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, 
ReapeatHeaderCheckBoxHdl));
+    m_pHeaderCB->SetClickHdl( LINK( this, SwInsTableDlg, CheckBoxHdl ) );
+    m_pRepeatHeaderCB->SetClickHdl( LINK( this, SwInsTableDlg, 
ReapeatHeaderCheckBoxHdl ) );
     ReapeatHeaderCheckBoxHdl(nullptr);
     CheckBoxHdl(nullptr);
 
@@ -125,11 +108,52 @@ SwInsTableDlg::SwInsTableDlg( SwView& rView )
     else
         --nMax;
     m_pRepeatHeaderNF->SetMax( nMax );
+
+    InitAutoTableFormat();
 }
 
-IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, Button*, void)
+void SwInsTableDlg::InitAutoTableFormat()
 {
-    EndDialog(RET_OK);
+    m_pWndPreview->DetectRTL(pShell);
+
+    m_pLbFormat->SetSelectHdl( LINK( this, SwInsTableDlg, SelFormatHdl ) );
+
+    pTableTable = new SwTableAutoFormatTable;
+    pTableTable->Load();
+
+    // Add "- none -" style autoformat table.
+    m_pLbFormat->InsertEntry( SwViewShell::GetShellRes()->aStrNone ); // 
Insert to listbox
+
+    // Add other styles of autoformat tables.
+    for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size());
+            i < nCount; i++)
+    {
+        SwTableAutoFormat const& rFormat = (*pTableTable)[ i ];
+        m_pLbFormat->InsertEntry(rFormat.GetName());
+        if (pTAutoFormat && rFormat.GetName() == pTAutoFormat->GetName())
+            lbIndex = i;
+    }
+
+    // Change this min variable if you add autotable manually.
+    minTableIndexInLb = 1;
+    maxTableIndexInLb = minTableIndexInLb + 
static_cast<sal_uInt8>(pTableTable->size());
+    lbIndex = 1;
+    m_pLbFormat->SelectEntryPos( lbIndex );
+    tbIndex = lbIndexToTableIndex(lbIndex);
+
+    SelFormatHdl( *m_pLbFormat );
+}
+
+sal_uInt8 SwInsTableDlg::lbIndexToTableIndex( const sal_uInt8 listboxIndex )
+{
+    if( minTableIndexInLb != maxTableIndexInLb &&
+            minTableIndexInLb <= listboxIndex &&
+            listboxIndex < maxTableIndexInLb )
+    {
+        return listboxIndex - minTableIndexInLb;
+    }
+
+    return 255;
 }
 
 SwInsTableDlg::~SwInsTableDlg()
@@ -140,6 +164,7 @@ SwInsTableDlg::~SwInsTableDlg()
 void SwInsTableDlg::dispose()
 {
     delete pTAutoFormat;
+    m_pLbFormat.clear();
     m_pNameEdit.clear();
     m_pColNF.clear();
     m_pRowNF.clear();
@@ -148,12 +173,65 @@ void SwInsTableDlg::dispose()
     m_pRepeatHeaderNF.clear();
     m_pRepeatGroup.clear();
     m_pDontSplitCB.clear();
-    m_pBorderCB.clear();
     m_pInsertBtn.clear();
-    m_pAutoFormatBtn.clear();
+    m_pWndPreview.clear();
+    pTableTable->Save();
+    delete pTableTable;
     SfxModalDialog::dispose();
 }
 
+static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
+{
+    pTableAutoFormat->SetFont( bVal );
+    pTableAutoFormat->SetJustify( bVal );
+    pTableAutoFormat->SetFrame( bVal );
+    pTableAutoFormat->SetBackground( bVal );
+    pTableAutoFormat->SetValueFormat( bVal );
+    pTableAutoFormat->SetWidthHeight( bVal );
+}
+
+
+IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, ListBox&, void)
+{
+    // Get index of selected item from the listbox
+    lbIndex = static_cast<sal_uInt8>(m_pLbFormat->GetSelectedEntryPos());
+    tbIndex = lbIndexToTableIndex( lbIndex );
+
+    // To understand this index maping, look InitAutoTableFormat function to
+    // see how listbox item is implemented.
+    if( tbIndex < 255 )
+        m_pWndPreview->NotifyChange( (*pTableTable)[tbIndex] );
+    else
+    {
+        SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone );
+        lcl_SetProperties( &aTmp, false );
+
+        m_pWndPreview->NotifyChange( aTmp );
+    }
+}
+
+IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, Button*, void)
+{
+    if( tbIndex < 255 )
+        pShell->SetTableStyle((*pTableTable)[tbIndex]);
+
+    if( tbIndex < 255 )
+    {
+        if( pTAutoFormat )
+            *pTAutoFormat = (*pTableTable)[ tbIndex ];
+        else
+            pTAutoFormat = new SwTableAutoFormat( (*pTableTable)[ tbIndex ] );
+    }
+    else
+    {
+        delete pTAutoFormat;
+        pTAutoFormat = new SwTableAutoFormat( 
SwViewShell::GetShellRes()->aStrNone );
+        lcl_SetProperties( pTAutoFormat, false );
+    }
+
+    EndDialog(RET_OK);
+}
+
 IMPL_LINK( SwInsTableDlg, ModifyName, Edit&, rEdit, void )
 {
     OUString sTableName = rEdit.GetText();
@@ -194,16 +272,6 @@ IMPL_LINK( SwInsTableDlg, ModifyRowCol, Edit&, rEdit, void 
)
             m_pRepeatHeaderNF->SetValue( std::min( nEnteredValRepeatHeaderNF, 
nMax ) );
     }
 }
-IMPL_LINK( SwInsTableDlg, AutoFormatHdl, Button*, pButton, void )
-{
-    SwAbstractDialogFactory* pFact = swui::GetFactory();
-    OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
-
-    ScopedVclPtr<AbstractSwAutoFormatDlg> 
pDlg(pFact->CreateSwAutoFormatDlg(pButton,pShell, false, pTAutoFormat));
-    OSL_ENSURE(pDlg, "Dialog creation failed!");
-    if( RET_OK == pDlg->Execute())
-        pDlg->FillAutoFormatOfIndex( pTAutoFormat );
-}
 
 IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl, Button*, void)
 {
diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx
index 75edc414fe14..f930e53799f1 100644
--- a/sw/source/ui/table/tautofmt.cxx
+++ b/sw/source/ui/table/tautofmt.cxx
@@ -18,85 +18,11 @@
  */
 
 #include <memory>
-#include <vcl/edit.hxx>
-#include <vcl/layout.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/settings.hxx>
-#include <vcl/builderfactory.hxx>
 #include <vcl/weld.hxx>
-#include <svl/zforlist.hxx>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/i18n/BreakIterator.hpp>
-#include <comphelper/processfactory.hxx>
-#include <svtools/scriptedtext.hxx>
-#include <svtools/accessibilityoptions.hxx>
-#include <svx/framelinkarray.hxx>
-#include <drawinglayer/processor2d/processor2dtools.hxx>
-
-#include <app.hrc>
 #include <strings.hrc>
-#include <swmodule.hxx>
-#include <swtypes.hxx>
 #include <view.hxx>
-#include <wrtsh.hxx>
-#include <tblafmt.hxx>
-#include <tautofmt.hxx>
 #include <shellres.hxx>
-
-using namespace com::sun::star;
-
-#define FRAME_OFFSET 4
-
-class AutoFormatPreview : public vcl::Window
-{
-public:
-    AutoFormatPreview(vcl::Window* pParent, WinBits nStyle);
-    virtual ~AutoFormatPreview() override;
-    virtual void dispose() override;
-
-    void NotifyChange( const SwTableAutoFormat& rNewData );
-
-    void DetectRTL(SwWrtShell const * pWrtShell);
-
-    virtual void Resize() override;
-protected:
-    virtual void Paint( vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect ) override;
-
-private:
-    SwTableAutoFormat          aCurData;
-    ScopedVclPtr<VirtualDevice> aVD;
-    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;
-    SvNumberFormatter*      pNumFormat;
-
-    uno::Reference<i18n::XBreakIterator> m_xBreak;
-
-    void    Init();
-    void    DoPaint(vcl::RenderContext& rRenderContext);
-    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(sal_uInt8 nIndex, vcl::Font& rFont, vcl::Font& rCJKFont, 
vcl::Font& rCTLFont);
-};
+#include <tautofmt.hxx>
 
 class SwStringInputDlg : public ModalDialog
 {
@@ -511,460 +437,4 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, OkHdl, Button*, void)
     EndDialog( RET_OK );
 }
 
-AutoFormatPreview::AutoFormatPreview(vcl::Window* pParent, WinBits nStyle) :
-        Window          ( pParent, nStyle ),
-        aCurData        ( OUString() ),
-        aVD             ( VclPtr<VirtualDevice>::Create(*this) ),
-        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);
-    pNumFormat = new SvNumberFormatter( xContext, LANGUAGE_SYSTEM );
-
-    Init();
-}
-
-VCL_BUILDER_FACTORY_CONSTRUCTOR(AutoFormatPreview, 0)
-
-void AutoFormatPreview::Resize()
-{
-    aPrvSize = Size(GetSizePixel().Width() - 6, GetSizePixel().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();
-}
-
-AutoFormatPreview::~AutoFormatPreview()
-{
-    disposeOnce();
-}
-
-void AutoFormatPreview::dispose()
-{
-    delete pNumFormat;
-    vcl::Window::dispose();
-}
-
-static void lcl_SetFontProperties(
-        vcl::Font& rFont,
-        const SvxFontItem& rFontItem,
-        const SvxWeightItem& rWeightItem,
-        const SvxPostureItem& rPostureItem )
-{
-    rFont.SetFamily     ( rFontItem.GetFamily() );
-    rFont.SetFamilyName ( rFontItem.GetFamilyName() );
-    rFont.SetStyleName  ( rFontItem.GetStyleName() );
-    rFont.SetCharSet    ( rFontItem.GetCharSet() );
-    rFont.SetPitch      ( rFontItem.GetPitch() );
-    rFont.SetWeight     ( rWeightItem.GetValue() );
-    rFont.SetItalic     ( rPostureItem.GetValue() );
-}
-
-#define SETONALLFONTS( MethodName, Value )                  \
-rFont.MethodName( Value );                                  \
-rCJKFont.MethodName( Value );                               \
-rCTLFont.MethodName( Value );
-
-void AutoFormatPreview::MakeFonts( sal_uInt8 nIndex, vcl::Font& rFont, 
vcl::Font& rCJKFont, vcl::Font& rCTLFont )
-{
-    const SwBoxAutoFormat& rBoxFormat = aCurData.GetBoxFormat( nIndex );
-
-    rFont = rCJKFont = rCTLFont = GetFont();
-    Size aFontSize( rFont.GetFontSize().Width(), 10 * 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 = 
pNumFormat->GetIndexPuttingAndConverting(sFormat, eLng,
-                                                                    eSys, 
nType, bNew, nCheckPos);
-            Color* pDummy;
-            pNumFormat->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(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.AdjustY((nRowHeight - aStrSize.Height()) / 2 );
-
-    // horizontal
-    if (mbRTL)
-        aPos.AdjustX(nRightX );
-    else if (aCurData.IsJustify())
-    {
-        const SvxAdjustItem& rAdj = 
aCurData.GetBoxFormat(nFormatIndex).GetAdjust();
-        switch (rAdj.GetAdjust())
-        {
-            case SvxAdjust::Left:
-                aPos.AdjustX(FRAME_OFFSET );
-                break;
-            case SvxAdjust::Right:
-                aPos.AdjustX(nRightX );
-                break;
-            default:
-                aPos.AdjustX((cellRect.GetWidth() - aStrSize.Width()) / 2 );
-                break;
-        }
-    }
-    else
-    {
-        // Standard align:
-        if (nCol == 0 || nIndex == 4)
-        {
-            // Text-Label left or sum left aligned
-            aPos.AdjustX(FRAME_OFFSET );
-        }
-        else
-        {
-            // numbers/dates right aligned
-            aPos.AdjustX(nRightX );
-        }
-    }
-
-    aScriptedText.DrawText(aPos);
-
-}
-
-#undef FRAME_OFFSET
-
-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()
-{
-    SetBorderStyle( GetBorderStyle() | WindowBorderStyle::MONO );
-    maArray.Initialize( 5, 5 );
-    nLabelColWidth = 0;
-    nDataColWidth1 = 0;
-    nDataColWidth2 = 0;
-    nRowHeight = 0;
-    CalcCellArray( false );
-    CalcLineMap();
-}
-
-void AutoFormatPreview::CalcCellArray( bool _bFitWidth )
-{
-    maArray.SetXOffset( 2 );
-    maArray.SetAllColWidths( _bFitWidth ? nDataColWidth2 : nDataColWidth1 );
-    maArray.SetColWidth( 0, nLabelColWidth );
-    maArray.SetColWidth( 4, nLabelColWidth );
-
-    maArray.SetYOffset( 2 );
-    maArray.SetAllRowHeights( nRowHeight );
-
-    aPrvSize.setWidth( maArray.GetWidth() + 4 );
-    aPrvSize.setHeight( maArray.GetHeight() + 4 );
-}
-
-inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const 
::editeng::SvxBorderLine* pBorder )
-{
-    rStyle.Set( pBorder, 0.05, 5 );
-}
-
-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();
-    Invalidate(tools::Rectangle(Point(0,0), GetSizePixel()));
-}
-
-void AutoFormatPreview::DoPaint(vcl::RenderContext& rRenderContext)
-{
-    DrawModeFlags nOldDrawMode = aVD->GetDrawMode();
-    if (rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
-        aVD->SetDrawMode(DrawModeFlags::SettingsLine | 
DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | 
DrawModeFlags::SettingsGradient);
-
-    Bitmap thePreview;
-    Point aCenterPos;
-    Size theWndSize = GetSizePixel();
-    Color oldColor;
-    vcl::Font aFont;
-
-    aFont = aVD->GetFont();
-    aFont.SetTransparent( true );
-
-    aVD->SetFont(aFont);
-    aVD->SetLineColor();
-    const Color& rWinColor = 
rRenderContext.GetSettings().GetStyleSettings().GetWindowColor();
-    aVD->SetBackground(Wallpaper(rWinColor));
-    aVD->SetFillColor(rWinColor);
-    aVD->SetOutputSizePixel(aPrvSize);
-
-    // Draw cells on virtual device
-    // and save the result
-    PaintCells(*aVD.get());
-    thePreview = aVD->GetBitmap(Point(0,0), aPrvSize);
-
-    // Draw the Frame and center the preview:
-    // (virtual Device for window output)
-    aVD->SetOutputSizePixel(theWndSize);
-    oldColor = aVD->GetLineColor();
-    aVD->SetLineColor();
-    aVD->DrawRect(tools::Rectangle(Point(0,0), theWndSize));
-
-    rRenderContext.SetLineColor(oldColor);
-
-    aCenterPos = Point((theWndSize.Width()  - aPrvSize.Width())  / 2,
-                       (theWndSize.Height() - aPrvSize.Height()) / 2);
-    aVD->DrawBitmap(aCenterPos, thePreview);
-
-    // Output in the preview window:
-    rRenderContext.DrawBitmap(Point(0, 0), aVD->GetBitmap(Point(0,0), 
theWndSize));
-
-    aVD->SetDrawMode(nOldDrawMode);
-}
-
-void AutoFormatPreview::Paint( vcl::RenderContext& rRenderContext, const 
tools::Rectangle& /*rRect*/ )
-{
-    DoPaint(rRenderContext);
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/autoformatpreview.hxx 
b/sw/source/uibase/inc/autoformatpreview.hxx
new file mode 100644
index 000000000000..30be17fc218d
--- /dev/null
+++ b/sw/source/uibase/inc/autoformatpreview.hxx
@@ -0,0 +1,91 @@
+/* -*- 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_SW_SOURCE_UIBASE_INC_AUTOFORMATPREVIEW_HXX
+#define INCLUDED_SW_SOURCE_UIBASE_INC_AUTOFORMATPREVIEW_HXX
+
+#include <com/sun/star/i18n/XBreakIterator.hpp>
+#include <sal/types.h>
+#include <svx/framelinkarray.hxx>
+#include <svl/zforlist.hxx>
+#include <tools/gen.hxx>
+#include <tools/link.hxx>
+#include <rtl/ustring.hxx>
+#include <vcl/outdev.hxx>
+#include <vcl/vclptr.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/font.hxx>
+
+#include "wrtsh.hxx"
+#include <tblafmt.hxx>
+
+class AutoFormatPreview : public vcl::Window
+{
+public:
+    AutoFormatPreview(vcl::Window* pParent, WinBits nStyle);
+    virtual ~AutoFormatPreview() override;
+    virtual void dispose() override;
+
+    void NotifyChange(const SwTableAutoFormat& rNewData);
+
+    void DetectRTL(SwWrtShell const* pWrtShell);
+
+    virtual void Resize() override;
+
+protected:
+    virtual void Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect) override;
+
+private:
+    SwTableAutoFormat aCurData;
+    ScopedVclPtr<VirtualDevice> aVD;
+    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;
+    SvNumberFormatter* pNumFormat;
+
+    uno::Reference<i18n::XBreakIterator> m_xBreak;
+
+    void Init();
+    void DoPaint(vcl::RenderContext& rRenderContext);
+    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(sal_uInt8 nIndex, vcl::Font& rFont, vcl::Font& rCJKFont, 
vcl::Font& rCTLFont);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/instable.hxx 
b/sw/source/uibase/inc/instable.hxx
index 9992a16ba9eb..dfc82f034c9e 100644
--- a/sw/source/uibase/inc/instable.hxx
+++ b/sw/source/uibase/inc/instable.hxx
@@ -19,48 +19,64 @@
 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_INSTABLE_HXX
 #define INCLUDED_SW_SOURCE_UIBASE_INC_INSTABLE_HXX
 
+#include <sfx2/basedlgs.hxx>
+#include <sal/types.h>
 #include <rtl/ustring.hxx>
+#include <tools/link.hxx>
+#include <vcl/vclreferencebase.hxx>
 #include <vcl/button.hxx>
-#include <vcl/field.hxx>
 #include <vcl/edit.hxx>
+#include <vcl/field.hxx>
 #include <vcl/layout.hxx>
-#include <sfx2/basedlgs.hxx>
-#include "actctrl.hxx"
 
-class SwWrtShell;
-class SwTableAutoFormat;
-class SwView;
-struct SwInsertTableOptions;
+#include "wrtsh.hxx"
+#include "autoformatpreview.hxx"
+#include <view.hxx>
+#include <tblafmt.hxx>
+#include <itabenum.hxx>
 
 class SwInsTableDlg : public SfxModalDialog
 {
-    VclPtr<Edit>           m_pNameEdit;
     TextFilter      m_aTextFilter;
+    VclPtr<Edit>    m_pNameEdit;
 
-    VclPtr<NumericField>   m_pColNF;
-    VclPtr<NumericField>   m_pRowNF;
+    VclPtr<NumericField>    m_pColNF;
+    VclPtr<NumericField>    m_pRowNF;
 
-    VclPtr<CheckBox>       m_pHeaderCB;
-    VclPtr<CheckBox>       m_pRepeatHeaderCB;
-    VclPtr<NumericField>   m_pRepeatHeaderNF;
-    VclPtr<VclContainer>   m_pRepeatGroup;
+    VclPtr<CheckBox>        m_pHeaderCB;
+    VclPtr<CheckBox>        m_pRepeatHeaderCB;
+    VclPtr<NumericField>    m_pRepeatHeaderNF;
+    VclPtr<VclContainer>    m_pRepeatGroup;
 
-    VclPtr<CheckBox>       m_pDontSplitCB;
-    VclPtr<CheckBox>       m_pBorderCB;
+    VclPtr<CheckBox>        m_pDontSplitCB;
 
-    VclPtr<PushButton>     m_pInsertBtn;
-    VclPtr<PushButton>     m_pAutoFormatBtn;
+    VclPtr<PushButton>      m_pInsertBtn;
+
+    VclPtr<ListBox>         m_pLbFormat;
+
+    VclPtr<AutoFormatPreview> m_pWndPreview;
 
     SwWrtShell*     pShell;
-    SwTableAutoFormat* pTAutoFormat;
+    SwTableAutoFormatTable* pTableTable;
+    SwTableAutoFormat*      pTAutoFormat;
+
+    sal_uInt8       lbIndex;
+    sal_uInt8       tbIndex;
+    sal_uInt8       minTableIndexInLb;
+    sal_uInt8       maxTableIndexInLb;
     sal_Int64       nEnteredValRepeatHeaderNF;
 
+    // Returns 255 if mapping is not possible.
+    // This means there cannot be more than 255 autotable style.
+    sal_uInt8 lbIndexToTableIndex( const sal_uInt8 listboxIndex );
+    void InitAutoTableFormat();
+
+    DECL_LINK( SelFormatHdl, ListBox&, void );
     DECL_LINK( ModifyName, Edit&, void );
     DECL_LINK( ModifyRowCol, Edit&, void );
-    DECL_LINK( AutoFormatHdl, Button*, void );
-    DECL_LINK( OKHdl, Button*, void);
-    DECL_LINK( CheckBoxHdl, Button*, void);
-    DECL_LINK( ReapeatHeaderCheckBoxHdl, Button*, void);
+    DECL_LINK( OKHdl, Button*, void );
+    DECL_LINK( CheckBoxHdl, Button*, void );
+    DECL_LINK( ReapeatHeaderCheckBoxHdl, Button*, void );
     DECL_LINK( ModifyRepeatHeaderNF_Hdl, Edit&, void );
 
 public:
diff --git a/sw/source/uibase/inc/tautofmt.hxx 
b/sw/source/uibase/inc/tautofmt.hxx
index 169b741a150a..cd294065b377 100644
--- a/sw/source/uibase/inc/tautofmt.hxx
+++ b/sw/source/uibase/inc/tautofmt.hxx
@@ -18,20 +18,21 @@
  */
 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_TAUTOFMT_HXX
 #define INCLUDED_SW_SOURCE_UIBASE_INC_TAUTOFMT_HXX
-#include <sfx2/basedlgs.hxx>
-
-#include <vcl/fixed.hxx>
-
-#include <vcl/lstbox.hxx>
 
+#include <tools/link.hxx>
+#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/morebtn.hxx>
-
-#include <vcl/virdev.hxx>
+#include "wrtsh.hxx"
+#include "autoformatpreview.hxx"
+#include <tblafmt.hxx>
 
 class SwTableAutoFormat;
-class AutoFormatPreview;
 class SwTableAutoFormatTable;
 class SwWrtShell;
 
@@ -61,7 +62,7 @@ class SwAutoFormatDlg : public SfxModalDialog
     VclPtr<AutoFormatPreview> m_pWndPreview;
 
     SwWrtShell*             pShell;
-    SwTableAutoFormatTable*      pTableTable;
+    SwTableAutoFormatTable*     pTableTable;
     sal_uInt8                   nIndex;
     sal_uInt8                   nDfltStylePos;
     bool                    bCoreDataChanged : 1;
diff --git a/sw/uiconfig/swriter/ui/inserttable.ui 
b/sw/uiconfig/swriter/ui/inserttable.ui
index 4adfcf48c16e..deb2ddd8936c 100644
--- a/sw/uiconfig/swriter/ui/inserttable.ui
+++ b/sw/uiconfig/swriter/ui/inserttable.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.18.3 -->
 <interface domain="sw">
   <requires lib="gtk+" version="3.0"/>
   <object class="GtkAdjustment" id="adjustment1">
@@ -48,7 +48,7 @@
                 <property name="receives_default">True</property>
               </object>
               <packing>
-                <property name="expand">False</property>
+                <property name="expand">True</property>
                 <property name="fill">True</property>
                 <property name="position">0</property>
               </packing>
@@ -278,22 +278,6 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkCheckButton" id="bordercb">
-                            <property name="label" translatable="yes" 
context="inserttable|bordercb">_Border</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_underline">True</property>
-                            <property name="xalign">0</property>
-                            <property name="active">True</property>
-                            <property name="draw_indicator">True</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">0</property>
-                            <property name="top_attach">4</property>
-                          </packing>
-                        </child>
-                        <child>
                           <object class="GtkCheckButton" id="dontsplitcb">
                             <property name="label" translatable="yes" 
context="inserttable|dontsplitcb">Don’t _split table over pages</property>
                             <property name="visible">True</property>
@@ -351,19 +335,52 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="autoformat">
-                            <property name="label" translatable="yes" 
context="inserttable|autoformat">Auto_Format</property>
+                          <object class="GtkGrid" id="grid1">
+                            <property name="width_request">400</property>
+                            <property name="height_request">200</property>
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="halign">end</property>
-                            <property name="hexpand">True</property>
-                            <property name="use_underline">True</property>
-                            <property name="image_position">right</property>
+                            <property name="can_focus">False</property>
+                            <property name="row_spacing">6</property>
+                            <property name="column_spacing">6</property>
+                            <child>
+                              <object class="swuilo-AutoFormatPreview" 
id="previewinstable">
+                                <property name="width_request">200</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>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="top_attach">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkScrolledWindow" 
id="scrolledwindowinstable">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="shadow_type">in</property>
+                                <child>
+                                  <object class="GtkTreeView" 
id="formatlbinstable:border">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="vexpand">True</property>
+                                    <child internal-child="selection">
+                                      <object class="GtkTreeSelection" 
id="treeviewinstable-selection1"/>
+                                    </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">0</property>
-                            <property name="top_attach">5</property>
+                            <property name="top_attach">4</property>
                           </packing>
                         </child>
                       </object>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to