summaryrefslogtreecommitdiffstats
path: root/sw/source/uibase/table
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/source/uibase/table
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--sw/source/uibase/table/chartins.cxx228
-rw-r--r--sw/source/uibase/table/swtablerep.cxx150
-rw-r--r--sw/source/uibase/table/tablemgr.cxx352
-rw-r--r--sw/source/uibase/table/tablepg.hxx183
4 files changed, 913 insertions, 0 deletions
diff --git a/sw/source/uibase/table/chartins.cxx b/sw/source/uibase/table/chartins.cxx
new file mode 100644
index 000000000..fd73a71ef
--- /dev/null
+++ b/sw/source/uibase/table/chartins.cxx
@@ -0,0 +1,228 @@
+/* -*- 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 <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
+#include <IDocumentUndoRedo.hxx>
+#include <IDocumentChartDataProviderAccess.hxx>
+
+#include <swmodule.hxx>
+#include <wrtsh.hxx>
+#include <docsh.hxx>
+#include <view.hxx>
+#include <chartins.hxx>
+#include <tablemgr.hxx>
+#include <frmfmt.hxx>
+#include <unochart.hxx>
+
+#include <edtwin.hxx>
+
+#include <cmdid.h>
+#include <anchoredobject.hxx>
+
+#include <cppuhelper/bootstrap.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <com/sun/star/awt/Point.hpp>
+#include <com/sun/star/awt/Size.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <svtools/dialogclosedlistener.hxx>
+#include <com/sun/star/chart2/data/XDataProvider.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+Point SwGetChartDialogPos( const vcl::Window *pParentWin, const Size& rDialogSize, const tools::Rectangle& rLogicChart )
+{
+ // positioning code according to spec; similar to Calc fuins2.cxx
+ Point aRet;
+
+ OSL_ENSURE( pParentWin, "Window not found" );
+ if (pParentWin)
+ {
+ tools::Rectangle aObjPixel = pParentWin->LogicToPixel( rLogicChart, pParentWin->GetMapMode() );
+ tools::Rectangle aObjAbs( pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.TopLeft() ),
+ pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.BottomRight() ) );
+
+ tools::Rectangle aDesktop = pParentWin->GetDesktopRectPixel();
+ Size aSpace = pParentWin->LogicToPixel(Size(8, 12), MapMode(MapUnit::MapAppFont));
+
+ bool bLayoutRTL = ::GetActiveView()->GetWrtShell().IsTableRightToLeft();
+ bool bCenterHor = false;
+
+ if ( aDesktop.Bottom() - aObjAbs.Bottom() >= rDialogSize.Height() + aSpace.Height() )
+ {
+ // first preference: below the chart
+ aRet.setY( aObjAbs.Bottom() + aSpace.Height() );
+ bCenterHor = true;
+ }
+ else if ( aObjAbs.Top() - aDesktop.Top() >= rDialogSize.Height() + aSpace.Height() )
+ {
+ // second preference: above the chart
+ aRet.setY( aObjAbs.Top() - rDialogSize.Height() - aSpace.Height() );
+ bCenterHor = true;
+ }
+ else
+ {
+ bool bFitLeft = ( aObjAbs.Left() - aDesktop.Left() >= rDialogSize.Width() + aSpace.Width() );
+ bool bFitRight = ( aDesktop.Right() - aObjAbs.Right() >= rDialogSize.Width() + aSpace.Width() );
+
+ if ( bFitLeft || bFitRight )
+ {
+ // if both fit, prefer right in RTL mode, left otherwise
+ bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
+ if ( bPutRight )
+ aRet.setX( aObjAbs.Right() + aSpace.Width() );
+ else
+ aRet.setX( aObjAbs.Left() - rDialogSize.Width() - aSpace.Width() );
+
+ // center vertically
+ aRet.setY( aObjAbs.Top() + ( aObjAbs.GetHeight() - rDialogSize.Height() ) / 2 );
+ }
+ else
+ {
+ // doesn't fit on any edge - put at the bottom of the screen
+ aRet.setY( aDesktop.Bottom() - rDialogSize.Height() );
+ bCenterHor = true;
+ }
+ }
+ if ( bCenterHor )
+ aRet.setX( aObjAbs.Left() + ( aObjAbs.GetWidth() - rDialogSize.Width() ) / 2 );
+
+ // limit to screen (centering might lead to invalid positions)
+ if ( aRet.X() + rDialogSize.Width() - 1 > aDesktop.Right() )
+ aRet.setX( aDesktop.Right() - rDialogSize.Width() + 1 );
+ if ( aRet.X() < aDesktop.Left() )
+ aRet.setX( aDesktop.Left() );
+ if ( aRet.Y() + rDialogSize.Height() - 1 > aDesktop.Bottom() )
+ aRet.setY( aDesktop.Bottom() - rDialogSize.Height() + 1 );
+ if ( aRet.Y() < aDesktop.Top() )
+ aRet.setY( aDesktop.Top() );
+ }
+
+ return aRet;
+}
+
+SwInsertChart::SwInsertChart( const Link<css::ui::dialogs::DialogClosedEvent*, void>& rLink )
+{
+ SwView *pView = ::GetActiveView();
+
+ // get range string of marked data
+ SwWrtShell &rWrtShell = pView->GetWrtShell();
+ uno::Reference< chart2::data::XDataProvider > xDataProvider;
+ uno::Reference< frame::XModel > xChartModel;
+ OUString aRangeString;
+
+ if( rWrtShell.IsCursorInTable())
+ {
+ if (!rWrtShell.IsTableMode())
+ {
+ // select whole table
+ rWrtShell.GetView().GetViewFrame()->GetDispatcher()->
+ Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
+ }
+ if( ! rWrtShell.IsTableComplexForChart())
+ {
+ SwFrameFormat* pTableFormat = rWrtShell.GetTableFormat();
+ aRangeString = pTableFormat->GetName() + "." + rWrtShell.GetBoxNms();
+
+ // get table data provider
+ xDataProvider.set( pView->GetDocShell()->getIDocumentChartDataProviderAccess().GetChartDataProvider( true ) );
+ }
+ }
+
+ SwFlyFrameFormat *pFlyFrameFormat = nullptr;
+ xChartModel.set( SwTableFUNC( &rWrtShell ).InsertChart( xDataProvider, xDataProvider.is(), aRangeString, &pFlyFrameFormat ));
+
+ //open wizard
+ //@todo get context from writer if that has one
+ uno::Reference< uno::XComponentContext > xContext(
+ ::cppu::defaultBootstrap_InitialComponentContext() );
+ if( xContext.is() && xChartModel.is() && xDataProvider.is())
+ {
+ uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
+ if(xMCF.is())
+ {
+ uno::Reference< ui::dialogs::XAsynchronousExecutableDialog > xDialog(
+ xMCF->createInstanceWithContext(
+ "com.sun.star.comp.chart2.WizardDialog", xContext),
+ uno::UNO_QUERY);
+ uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
+ if( xInit.is() )
+ {
+ // initialize dialog
+ uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
+ {
+ {"ParentWindow", uno::Any(uno::Reference< awt::XWindow >())},
+ {"ChartModel", uno::Any(xChartModel)}
+ }));
+ xInit->initialize( aSeq );
+
+ // try to set the dialog's position so it doesn't hide the chart
+ uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
+ if ( xDialogProps.is() )
+ {
+ try
+ {
+ //get dialog size:
+ awt::Size aDialogAWTSize;
+ if( xDialogProps->getPropertyValue("Size")
+ >>= aDialogAWTSize )
+ {
+ Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
+ if ( !aDialogSize.IsEmpty() )
+ {
+ //calculate and set new position
+ SwRect aSwRect;
+ if (pFlyFrameFormat)
+ aSwRect = pFlyFrameFormat->GetAnchoredObj()->GetObjRectWithSpaces();
+ tools::Rectangle aRect( aSwRect.SVRect() );
+ Point aDialogPos = SwGetChartDialogPos( &rWrtShell.GetView().GetEditWin(), aDialogSize, aRect );
+ xDialogProps->setPropertyValue("Position",
+ uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
+ }
+ }
+ }
+ catch (const uno::Exception&)
+ {
+ OSL_FAIL("Chart wizard couldn't be positioned automatically" );
+ }
+ }
+
+ ::svt::DialogClosedListener* pListener = new ::svt::DialogClosedListener();
+ pListener->SetDialogClosedLink( rLink );
+ css::uno::Reference<css::ui::dialogs::XDialogClosedListener> xListener( pListener );
+
+ xDialog->startExecuteModal( xListener );
+ }
+ else
+ {
+ uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
+ if( xComponent.is())
+ xComponent->dispose();
+ }
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/table/swtablerep.cxx b/sw/source/uibase/table/swtablerep.cxx
new file mode 100644
index 000000000..97e852233
--- /dev/null
+++ b/sw/source/uibase/table/swtablerep.cxx
@@ -0,0 +1,150 @@
+/* -*- 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 <tabcol.hxx>
+#include "tablepg.hxx"
+
+#include <swtablerep.hxx>
+#include <memory>
+
+SwTableRep::SwTableRep( const SwTabCols& rTabCol )
+ :
+ m_nTableWidth(0),
+ m_nSpace(0),
+ m_nLeftSpace(0),
+ m_nRightSpace(0),
+ m_nAlign(0),
+ m_nWidthPercent(0),
+ m_bLineSelected(false),
+ m_bWidthChanged(false),
+ m_bColsChanged(false)
+{
+ m_nAllCols = m_nColCount = rTabCol.Count();
+ m_pTColumns.reset( new TColumn[ m_nColCount + 1 ] );
+ SwTwips nStart = 0,
+ nEnd;
+ for( sal_uInt16 i = 0; i < m_nAllCols; ++i )
+ {
+ nEnd = rTabCol[ i ] - rTabCol.GetLeft();
+ m_pTColumns[ i ].nWidth = nEnd - nStart;
+ m_pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
+ if(!m_pTColumns[ i ].bVisible)
+ m_nColCount --;
+ nStart = nEnd;
+ }
+ m_pTColumns[ m_nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
+ m_pTColumns[ m_nAllCols ].bVisible = true;
+ m_nColCount++;
+ m_nAllCols++;
+}
+
+SwTableRep::~SwTableRep()
+{
+}
+
+bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
+{
+ long nOldLeft = rTabCols.GetLeft(),
+ nOldRight = rTabCols.GetRight();
+
+ bool bSingleLine = false;
+
+ for ( size_t i = 0; i < rTabCols.Count(); ++i )
+ if(!m_pTColumns[i].bVisible)
+ {
+ bSingleLine = true;
+ break;
+ }
+
+ SwTwips nPos = 0;
+ const SwTwips nLeft = GetLeftSpace();
+ rTabCols.SetLeft(nLeft);
+ if(bSingleLine)
+ {
+ // The invisible separators are taken from the old TabCols,
+ // the visible coming from pTColumns.
+ std::unique_ptr<TColumn[]> pOldTColumns(new TColumn[m_nAllCols + 1]);
+ SwTwips nStart = 0;
+ for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
+ {
+ const SwTwips nEnd = rTabCols[i] - rTabCols.GetLeft();
+ pOldTColumns[i].nWidth = nEnd - nStart;
+ pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
+ nStart = nEnd;
+ }
+ pOldTColumns[m_nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
+ pOldTColumns[m_nAllCols - 1].bVisible = true;
+
+ sal_uInt16 nOldPos = 0;
+ sal_uInt16 nNewPos = 0;
+ SwTwips nOld = 0;
+ SwTwips nNew = 0;
+ bool bOld = false;
+ bool bFirst = true;
+
+ for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
+ {
+ while((bFirst || bOld ) && nOldPos < m_nAllCols )
+ {
+ nOld += pOldTColumns[nOldPos].nWidth;
+ nOldPos++;
+ if(!pOldTColumns[nOldPos - 1].bVisible)
+ break;
+ }
+ while((bFirst || !bOld ) && nNewPos < m_nAllCols )
+ {
+ nNew += m_pTColumns[nNewPos].nWidth;
+ nNewPos++;
+ if(pOldTColumns[nNewPos - 1].bVisible)
+ break;
+ }
+ bFirst = false;
+ // They have to be inserted sorted.
+ bOld = nOld < nNew;
+ nPos = bOld ? nOld : nNew;
+ rTabCols[i] = nPos + nLeft;
+ rTabCols.SetHidden( i, bOld );
+ }
+ rTabCols.SetRight(nLeft + m_nTableWidth);
+ }
+ else
+ {
+ for ( sal_uInt16 i = 0; i < m_nAllCols - 1; ++i )
+ {
+ nPos += m_pTColumns[i].nWidth;
+ rTabCols[i] = nPos + rTabCols.GetLeft();
+ rTabCols.SetHidden( i, !m_pTColumns[i].bVisible );
+ rTabCols.SetRight(nLeft + m_pTColumns[m_nAllCols - 1].nWidth + nPos);
+ }
+ }
+
+ // intercept rounding errors
+ if(std::abs(nOldLeft - rTabCols.GetLeft()) < 3)
+ rTabCols.SetLeft(nOldLeft);
+
+ if(std::abs(nOldRight - rTabCols.GetRight()) < 3)
+ rTabCols.SetRight(nOldRight);
+
+ if(GetRightSpace() >= 0 &&
+ rTabCols.GetRight() > rTabCols.GetRightMax())
+ rTabCols.SetRight(rTabCols.GetRightMax());
+ return bSingleLine;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/table/tablemgr.cxx b/sw/source/uibase/table/tablemgr.cxx
new file mode 100644
index 000000000..ecf9b6dea
--- /dev/null
+++ b/sw/source/uibase/table/tablemgr.cxx
@@ -0,0 +1,352 @@
+/* -*- 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 <com/sun/star/chart/ChartDataRowSource.hpp>
+#include <com/sun/star/chart2/data/XDataProvider.hpp>
+#include <com/sun/star/chart2/data/XDataReceiver.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/embed/EmbedVerbs.hpp>
+#include <com/sun/star/embed/XComponentSupplier.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+
+#include <comphelper/classids.hxx>
+#include <svx/charthelper.hxx>
+#include <svtools/embedhlp.hxx>
+
+#include <edtwin.hxx>
+#include <wrtsh.hxx>
+#include <view.hxx>
+#include <swundo.hxx>
+#include <tablemgr.hxx>
+#include <frmfmt.hxx>
+#include <swabstdlg.hxx>
+#include <swcli.hxx>
+#include <docsh.hxx>
+#include <unotbl.hxx>
+#include <unochart.hxx>
+
+#include <comphelper/lok.hxx>
+
+using namespace ::com::sun::star;
+
+// Adjust line height (dialogue)
+void SwTableFUNC::ColWidthDlg(weld::Window *pParent)
+{
+ InitTabCols();
+ SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+ ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwTableWidthDlg(pParent, *this));
+ pDlg->Execute();
+}
+
+// Determine the width
+SwTwips SwTableFUNC::GetColWidth(sal_uInt16 nNum) const
+{
+ SwTwips nWidth = 0;
+
+ if( aCols.Count() > 0 )
+ {
+ if(aCols.Count() == GetColCount())
+ {
+ if(nNum == aCols.Count())
+ nWidth = aCols.GetRight() - aCols[nNum-1];
+ else
+ {
+ if(nNum == 0)
+ nWidth = aCols[nNum] - aCols.GetLeft();
+ else
+ nWidth = aCols[nNum] - aCols[nNum-1];
+ }
+ }
+ else
+ {
+ SwTwips nRValid = nNum < GetColCount() ?
+ aCols[GetRightSeparator(nNum)] :
+ aCols.GetRight();
+ SwTwips nLValid = nNum ?
+ aCols[GetRightSeparator(nNum - 1)] :
+ aCols.GetLeft();
+ nWidth = nRValid - nLValid;
+ }
+ }
+ else
+ nWidth = aCols.GetRight();
+ return nWidth;
+}
+
+SwTwips SwTableFUNC::GetMaxColWidth( sal_uInt16 nNum ) const
+{
+ OSL_ENSURE(nNum <= aCols.Count(), "Index out of Area");
+
+ if ( GetColCount() > 0 )
+ {
+ // The maximum width arises from the own width and
+ // the width each of the neighbor cells reduced by MINLAY.
+ SwTwips nMax;
+ if(nNum == 0)
+ nMax = GetColWidth(1) - MINLAY;
+ else
+ {
+ nMax = GetColWidth(nNum-1);
+ if(nNum == GetColCount())
+ nMax -= MINLAY;
+ else
+ nMax += GetColWidth(nNum+1) - 2 * MINLAY;
+ }
+ return nMax + GetColWidth(nNum);
+ }
+ else
+ return GetColWidth(nNum);
+}
+
+void SwTableFUNC::SetColWidth(sal_uInt16 nNum, SwTwips nNewWidth )
+{
+ // set current width
+ // move all of the following
+ bool bCurrentOnly = false;
+
+ if ( aCols.Count() > 0 )
+ {
+ if(aCols.Count() != GetColCount())
+ bCurrentOnly = true;
+ SwTwips nWidth = GetColWidth(nNum);
+
+ int nDiff = static_cast<int>(nNewWidth - nWidth);
+ if( !nNum )
+ aCols[ GetRightSeparator(0) ] += nDiff;
+ else if( nNum < GetColCount() )
+ {
+ if(nDiff < GetColWidth(nNum + 1) - MINLAY)
+ aCols[ GetRightSeparator(nNum) ] += nDiff;
+ else
+ {
+ int nDiffLeft = nDiff - static_cast<int>(GetColWidth(nNum + 1)) + int(MINLAY);
+ aCols[ GetRightSeparator(nNum) ] += (nDiff - nDiffLeft);
+ aCols[ GetRightSeparator(nNum - 1) ] -= nDiffLeft;
+ }
+ }
+ else
+ aCols[ GetRightSeparator(nNum-1) ] -= nDiff;
+ }
+ else
+ aCols.SetRight( std::min( nNewWidth, aCols.GetRightMax()) );
+
+ pSh->StartAllAction();
+ pSh->SetTabCols( aCols, bCurrentOnly );
+ pSh->EndAllAction();
+}
+
+void SwTableFUNC::InitTabCols()
+{
+ OSL_ENSURE(pSh, "no Shell");
+
+ if( pFormat && pSh)
+ pSh->GetTabCols( aCols );
+}
+
+SwTableFUNC::SwTableFUNC(SwWrtShell *pShell)
+ : pFormat(pShell->GetTableFormat()),
+ pSh(pShell)
+{
+}
+
+SwTableFUNC::~SwTableFUNC()
+{
+}
+
+void SwTableFUNC::UpdateChart()
+{
+ //Update of the fields triggered by the user, all Charts of
+ //the table will be brought up to date
+ SwFrameFormat *pFormat2 = pSh->GetTableFormat();
+ if ( pFormat2 && pSh->HasOLEObj( pFormat2->GetName() ) )
+ {
+ pSh->StartAllAction();
+ pSh->UpdateCharts( pFormat2->GetName() );
+ pSh->EndAllAction();
+ }
+}
+
+uno::Reference< frame::XModel > SwTableFUNC::InsertChart(
+ uno::Reference< chart2::data::XDataProvider > const &rxDataProvider,
+ bool bFillWithData,
+ const OUString &rCellRange,
+ SwFlyFrameFormat** ppFlyFrameFormat )
+{
+ uno::Reference< frame::XModel > xChartModel;
+ pSh->StartUndo( SwUndoId::UI_INSERT_CHART );
+ pSh->StartAllAction();
+
+ OUString aName;
+ if (pSh->IsCursorInTable())
+ {
+ aName = pSh->GetTableFormat()->GetName();
+ // insert node before table
+ pSh->MoveTable( GotoCurrTable, fnTableStart );
+ pSh->Up( false );
+ if ( pSh->IsCursorInTable() )
+ {
+ if ( aName != pSh->GetTableFormat()->GetName() )
+ pSh->Down( false ); // two adjacent tables
+ }
+ pSh->SplitNode();
+ }
+
+ // insert chart
+ OUString aObjName;
+ comphelper::EmbeddedObjectContainer aCnt;
+ uno::Reference < embed::XEmbeddedObject > xObj =
+ aCnt.CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aObjName );
+
+ ::svt::EmbeddedObjectRef aEmbObjRef( xObj, css::embed::Aspects::MSOLE_CONTENT );
+ if ( xObj.is() )
+ {
+
+ SwFlyFrameFormat* pTmp = nullptr;
+ pSh->InsertOleObject( aEmbObjRef, &pTmp );
+ if (ppFlyFrameFormat)
+ *ppFlyFrameFormat = pTmp;
+
+ xChartModel.set( xObj->getComponent(), uno::UNO_QUERY );
+ if( xChartModel.is() )
+ {
+ // Create a default chart type.
+ uno::Reference<chart2::XChartDocument> xChartDoc(xChartModel, uno::UNO_QUERY);
+ if (xChartDoc.is())
+ xChartDoc->createDefaultChart();
+
+ xChartModel->lockControllers(); //#i79578# don't request a new replacement image for charts to often - block change notifications
+ }
+
+ // set the table name at the OLE-node
+ if (!aName.isEmpty())
+ pSh->SetChartName( aName );
+ }
+ pSh->EndAllAction();
+
+ if (xObj.is() && !comphelper::LibreOfficeKit::isActive())
+ {
+ // Let the chart be activated after the inserting (unless
+ // via LibreOfficeKit)
+ SfxInPlaceClient* pClient = pSh->GetView().FindIPClient( xObj, &pSh->GetView().GetEditWin() );
+ if ( !pClient )
+ {
+ pClient = new SwOleClient( &pSh->GetView(), &pSh->GetView().GetEditWin(), aEmbObjRef );
+ pSh->SetCheckForOLEInCaption( true );
+ }
+ pSh->CalcAndSetScale( aEmbObjRef );
+ //#50270# We don't need to handle errors,
+ //this does the DoVerb in the SfxViewShell.
+ ErrCode nErr = pClient->DoVerb(embed::EmbedVerbs::MS_OLEVERB_SHOW);
+ (void) nErr;
+
+ // #i121334#
+ ChartHelper::AdaptDefaultsForChart( xObj );
+ }
+
+ uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartModel, uno::UNO_QUERY );
+ if (bFillWithData && xDataReceiver.is() && rxDataProvider.is())
+ {
+ xDataReceiver->attachDataProvider( rxDataProvider );
+
+ uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pSh->GetView().GetDocShell()->GetModel(), uno::UNO_QUERY );
+ xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
+
+ // default values for ranges that do not consist of a single row or column
+ bool bHasCategories = true;
+ bool bFirstCellAsLabel = true;
+ chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
+
+ SwRangeDescriptor aDesc;
+ FillRangeDescriptor( aDesc, rCellRange );
+ bool bSingleRowCol = aDesc.nTop == aDesc.nBottom || aDesc.nLeft == aDesc.nRight;
+ if (bSingleRowCol)
+ {
+ aDesc.Normalize();
+ sal_Int32 nRowLen = aDesc.nRight - aDesc.nLeft + 1;
+ sal_Int32 nColLen = aDesc.nBottom - aDesc.nTop + 1;
+
+ bHasCategories = false;
+ if (nRowLen == 1 && nColLen == 1)
+ bFirstCellAsLabel = false;
+ else if (nRowLen > 1)
+ eDataRowSource = chart::ChartDataRowSource_ROWS;
+ else if (nColLen > 1)
+ eDataRowSource = chart::ChartDataRowSource_COLUMNS;
+ else {
+ OSL_FAIL("unexpected state" );
+ }
+ }
+
+ uno::Sequence< beans::PropertyValue > aArgs( 4 );
+ aArgs[0] = beans::PropertyValue(
+ "CellRangeRepresentation", -1,
+ uno::makeAny( rCellRange ), beans::PropertyState_DIRECT_VALUE );
+ aArgs[1] = beans::PropertyValue(
+ "HasCategories", -1,
+ uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
+ aArgs[2] = beans::PropertyValue(
+ "FirstCellAsLabel", -1,
+ uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
+ aArgs[3] = beans::PropertyValue(
+ "DataRowSource", -1,
+ uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
+ xDataReceiver->setArguments( aArgs );
+ }
+
+ pSh->EndUndo( SwUndoId::UI_INSERT_CHART );
+
+ if( xChartModel.is() )
+ xChartModel->unlockControllers(); //#i79578# don't request a new replacement image for charts to often
+ return xChartModel;
+}
+
+sal_uInt16 SwTableFUNC::GetCurColNum() const
+{
+ const size_t nPos = pSh->GetCurTabColNum();
+ size_t nCount = 0;
+ for( size_t i = 0; i < nPos; i++ )
+ if(aCols.IsHidden(i))
+ nCount ++;
+ return nPos - nCount;
+}
+
+sal_uInt16 SwTableFUNC::GetColCount() const
+{
+ size_t nCount = 0;
+ for(size_t i = 0; i < aCols.Count(); i++ )
+ if(aCols.IsHidden(i))
+ nCount ++;
+ return aCols.Count() - nCount;
+}
+
+int SwTableFUNC::GetRightSeparator(int nNum) const
+{
+ OSL_ENSURE( nNum < static_cast<int>(GetColCount()) ,"Index out of range");
+ int i = 0;
+ while( nNum >= 0 )
+ {
+ if( !aCols.IsHidden(i) )
+ nNum--;
+ i++;
+ }
+ return i - 1;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/table/tablepg.hxx b/sw/source/uibase/table/tablepg.hxx
new file mode 100644
index 000000000..f2a6311fb
--- /dev/null
+++ b/sw/source/uibase/table/tablepg.hxx
@@ -0,0 +1,183 @@
+/* -*- 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_TABLE_TABLEPG_HXX
+#define INCLUDED_SW_SOURCE_UIBASE_TABLE_TABLEPG_HXX
+#include <sfx2/tabdlg.hxx>
+#include <prcntfld.hxx>
+#include <swtypes.hxx>
+#include <svx/frmdirlbox.hxx>
+
+class SwWrtShell;
+class SwTableRep;
+struct ImplSVEvent;
+
+struct TColumn
+{
+ SwTwips nWidth;
+ bool bVisible;
+};
+
+class SwFormatTablePage : public SfxTabPage
+{
+ SwTableRep* pTableData;
+ SwTwips nSaveWidth;
+ SwTwips nMinTableWidth;
+ bool bModified;
+ bool bFull:1;
+ bool bHtmlMode : 1;
+
+ std::unique_ptr<weld::Entry> m_xNameED;
+ std::unique_ptr<weld::Label> m_xWidthFT;
+ std::unique_ptr<SwPercentField> m_xWidthMF;
+ std::unique_ptr<weld::CheckButton> m_xRelWidthCB;
+
+ std::unique_ptr<weld::RadioButton> m_xFullBtn;
+ std::unique_ptr<weld::RadioButton> m_xLeftBtn;
+ std::unique_ptr<weld::RadioButton> m_xFromLeftBtn;
+ std::unique_ptr<weld::RadioButton> m_xRightBtn;
+ std::unique_ptr<weld::RadioButton> m_xCenterBtn;
+ std::unique_ptr<weld::RadioButton> m_xFreeBtn;
+
+ std::unique_ptr<weld::Label> m_xLeftFT;
+ std::unique_ptr<SwPercentField> m_xLeftMF;
+ std::unique_ptr<weld::Label> m_xRightFT;
+ std::unique_ptr<SwPercentField> m_xRightMF;
+ std::unique_ptr<weld::Label> m_xTopFT;
+ std::unique_ptr<weld::MetricSpinButton> m_xTopMF;
+ std::unique_ptr<weld::Label> m_xBottomFT;
+ std::unique_ptr<weld::MetricSpinButton> m_xBottomMF;
+
+ std::unique_ptr<svx::FrameDirectionListBox> m_xTextDirectionLB;
+ std::unique_ptr<weld::Widget> m_xProperties;
+
+ void Init();
+ void ModifyHdl(const weld::MetricSpinButton& rEdit);
+
+ DECL_LINK(AutoClickHdl, weld::ToggleButton&, void);
+ DECL_LINK(RelWidthClickHdl, weld::ToggleButton&, void);
+ void RightModify();
+ DECL_LINK(ValueChangedHdl, weld::MetricSpinButton&, void);
+
+public:
+ SwFormatTablePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet );
+ static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet);
+ virtual ~SwFormatTablePage() override;
+
+ virtual bool FillItemSet( SfxItemSet* rSet ) override;
+ virtual void Reset( const SfxItemSet* rSet ) override;
+ virtual void ActivatePage( const SfxItemSet& rSet ) override;
+ virtual DeactivateRC DeactivatePage( SfxItemSet* pSet ) override;
+};
+
+// TabPage Format/Table/Columns
+#define MET_FIELDS 6 //Number of the used MetricFields
+
+class SwTableColumnPage : public SfxTabPage
+{
+ SwTableRep* m_pTableData;
+ ImplSVEvent* m_pSizeHdlEvent;
+ SwTwips m_nTableWidth;
+ SwTwips m_nMinWidth;
+ sal_uInt16 m_nMetFields;
+ sal_uInt16 m_nNoOfCols;
+ sal_uInt16 m_nNoOfVisibleCols;
+ // Remember the width, when switching to autoalign
+ sal_uInt16 m_aValueTable[MET_FIELDS];// primary assignment of the MetricFields
+ bool m_bModified:1;
+ bool m_bModifyTable:1;
+ bool m_bPercentMode:1;
+
+ SwPercentField m_aFieldArr[MET_FIELDS];
+ std::unique_ptr<weld::Label> m_aTextArr[MET_FIELDS];
+ std::unique_ptr<weld::CheckButton> m_xModifyTableCB;
+ std::unique_ptr<weld::CheckButton> m_xProportionalCB;
+ std::unique_ptr<weld::Label> m_xSpaceFT;
+ std::unique_ptr<weld::MetricSpinButton> m_xSpaceED;
+ std::unique_ptr<weld::Button> m_xUpBtn;
+ std::unique_ptr<weld::Button> m_xDownBtn;
+
+ void Init(bool bWeb);
+ DECL_LINK(AutoClickHdl, weld::Button&, void);
+ void ModifyHdl(const weld::MetricSpinButton* pEdit);
+ DECL_LINK(ValueChangedHdl, weld::MetricSpinButton&, void);
+ DECL_LINK(ModeHdl, weld::ToggleButton&, void);
+ void UpdateCols( sal_uInt16 nCurrentPos );
+ SwTwips GetVisibleWidth(sal_uInt16 nPos);
+ void SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth);
+ DECL_LINK(SizeHdl, void*, void);
+
+public:
+ SwTableColumnPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet);
+ static std::unique_ptr<SfxTabPage> Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet);
+ virtual ~SwTableColumnPage() override;
+
+ virtual bool FillItemSet( SfxItemSet* rSet ) override;
+ virtual void Reset( const SfxItemSet* rSet ) override;
+ virtual void ActivatePage( const SfxItemSet& rSet ) override;
+ virtual DeactivateRC DeactivatePage( SfxItemSet* pSet ) override;
+
+};
+
+class SwTextFlowPage : public SfxTabPage
+{
+ SwWrtShell* pShell;
+ bool bPageBreak;
+ bool bHtmlMode;
+
+ std::unique_ptr<weld::CheckButton> m_xPgBrkCB;
+ std::unique_ptr<weld::RadioButton> m_xPgBrkRB;
+ std::unique_ptr<weld::RadioButton> m_xColBrkRB;
+ std::unique_ptr<weld::RadioButton> m_xPgBrkBeforeRB;
+ std::unique_ptr<weld::RadioButton> m_xPgBrkAfterRB;
+ std::unique_ptr<weld::CheckButton> m_xPageCollCB;
+ std::unique_ptr<weld::ComboBox> m_xPageCollLB;
+ std::unique_ptr<weld::CheckButton> m_xPageNoCB;
+ std::unique_ptr<weld::SpinButton> m_xPageNoNF;
+ std::unique_ptr<weld::CheckButton> m_xSplitCB;
+ std::unique_ptr<weld::CheckButton> m_xSplitRowCB;
+ std::unique_ptr<weld::CheckButton> m_xKeepCB;
+ std::unique_ptr<weld::CheckButton> m_xHeadLineCB;
+ std::unique_ptr<weld::Widget> m_xRepeatHeaderCombo;
+ std::unique_ptr<weld::SpinButton> m_xRepeatHeaderNF;
+ std::unique_ptr<weld::ComboBox> m_xTextDirectionLB;
+ std::unique_ptr<weld::ComboBox> m_xVertOrientLB;
+
+ DECL_LINK(PageBreakHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(ApplyCollClickHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(PageBreakPosHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(PageBreakTypeHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(PageNoClickHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(SplitHdl_Impl, weld::ToggleButton&, void);
+ DECL_LINK(HeadLineCBClickHdl, weld::ToggleButton&, void);
+
+public:
+ SwTextFlowPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet);
+ static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet);
+ virtual ~SwTextFlowPage() override;
+ virtual bool FillItemSet( SfxItemSet* rSet ) override;
+ virtual void Reset( const SfxItemSet* rSet ) override;
+
+ void SetShell(SwWrtShell* pSh);
+
+ void DisablePageBreak();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */