summaryrefslogtreecommitdiff
path: root/sw/source/ui/table/tautofmt.cxx
diff options
context:
space:
mode:
authorFurkan Tokac <furkantokac34@gmail.com>2018-02-22 23:17:59 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-02-28 10:50:56 +0100
commitf7bf3cf5c9c7f72da0c881b50c2ccc4b6d550af2 (patch)
treeeee231c2474bdfd77e55ffca4c580a984ba67acc /sw/source/ui/table/tautofmt.cxx
parente07a1a5d6957dbb4dc19cb4d274406e8e075c729 (diff)
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 <furkantokac34@gmail.com> Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Heiko Tietze <tietze.heiko@gmail.com> Tested-by: Heiko Tietze <tietze.heiko@gmail.com> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sw/source/ui/table/tautofmt.cxx')
-rw-r--r--sw/source/ui/table/tautofmt.cxx532
1 files changed, 1 insertions, 531 deletions
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: */