2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 00:27:45 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-07-21 13:52:38 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// INCLUDE ---------------------------------------------------------------
|
|
|
|
|
2008-05-20 12:12:40 +00:00
|
|
|
#include "dbfunc.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "scitems.hxx"
|
|
|
|
#include <sfx2/bindings.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <vcl/sound.hxx>
|
|
|
|
#include <vcl/waitobj.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/zforlist.hxx>
|
2006-05-02 14:51:47 +00:00
|
|
|
#include <sfx2/app.hxx>
|
2009-09-01 00:42:43 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
|
|
|
|
#include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
|
2004-08-03 11:46:58 +00:00
|
|
|
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
|
2007-11-20 16:43:01 +00:00
|
|
|
#include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
|
2008-05-20 12:12:40 +00:00
|
|
|
#include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
|
2009-09-01 00:42:43 +00:00
|
|
|
#include <com/sun/star/sheet/GeneralFunction.hpp>
|
2004-07-23 12:01:21 +00:00
|
|
|
#include <com/sun/star/sheet/MemberResultFlags.hpp>
|
2008-05-20 12:12:40 +00:00
|
|
|
#include <com/sun/star/sheet/XDimensionsSupplier.hpp>
|
2009-09-01 00:42:43 +00:00
|
|
|
#include <com/sun/star/sheet/XDrillDownDataSupplier.hpp>
|
2004-07-23 12:01:21 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "global.hxx"
|
|
|
|
#include "globstr.hrc"
|
|
|
|
#include "sc.hrc"
|
|
|
|
#include "undotab.hxx"
|
|
|
|
#include "undodat.hxx"
|
2011-05-13 23:11:42 -04:00
|
|
|
#include "dbdata.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "rangenam.hxx"
|
|
|
|
#include "rangeutl.hxx"
|
|
|
|
#include "docsh.hxx"
|
|
|
|
#include "olinetab.hxx"
|
|
|
|
#include "consoli.hxx"
|
|
|
|
#include "olinefun.hxx"
|
|
|
|
#include "dpobject.hxx"
|
|
|
|
#include "dpsave.hxx"
|
2004-08-03 11:46:58 +00:00
|
|
|
#include "dpdimsave.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "dbdocfun.hxx"
|
2004-07-23 12:01:21 +00:00
|
|
|
#include "dpoutput.hxx"
|
2007-11-26 14:21:00 +00:00
|
|
|
#include "dptabsrc.hxx"
|
2011-04-27 17:21:25 -04:00
|
|
|
#include "dpshttab.hxx"
|
|
|
|
#include "dpsdbtab.hxx"
|
2002-11-20 13:36:29 +00:00
|
|
|
#include "editable.hxx"
|
2008-05-20 12:12:40 +00:00
|
|
|
#include "docpool.hxx"
|
|
|
|
#include "patattr.hxx"
|
|
|
|
#include "unonames.hxx"
|
|
|
|
#include "cell.hxx"
|
2009-06-19 19:51:20 +00:00
|
|
|
#include "userlist.hxx"
|
2011-11-05 00:56:38 -04:00
|
|
|
#include "queryentry.hxx"
|
2011-11-23 21:32:01 -05:00
|
|
|
#include "markdata.hxx"
|
2008-05-20 12:12:40 +00:00
|
|
|
|
2011-02-06 00:56:21 +01:00
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
2008-05-20 12:12:40 +00:00
|
|
|
#include <memory>
|
2009-06-19 19:51:20 +00:00
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-07-23 12:01:21 +00:00
|
|
|
using namespace com::sun::star;
|
2008-05-20 12:12:40 +00:00
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::Sequence;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
|
|
|
using ::com::sun::star::beans::XPropertySet;
|
2009-06-19 02:29:09 +00:00
|
|
|
using ::com::sun::star::container::XNameAccess;
|
|
|
|
using ::com::sun::star::sheet::XDimensionsSupplier;
|
|
|
|
using ::rtl::OUString;
|
2009-06-19 19:51:20 +00:00
|
|
|
using ::rtl::OUStringHash;
|
2009-06-19 02:29:09 +00:00
|
|
|
using ::rtl::OUStringBuffer;
|
2008-05-20 12:12:40 +00:00
|
|
|
using ::std::auto_ptr;
|
2009-06-19 19:51:20 +00:00
|
|
|
using ::std::list;
|
|
|
|
using ::std::vector;
|
2004-07-23 12:01:21 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// STATIC DATA -----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
|
|
|
|
|
|
//
|
|
|
|
// Outliner
|
|
|
|
//
|
|
|
|
|
|
|
|
// Outline-Gruppierung erzeugen
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::MakeOutline( sal_Bool bColumns, sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScRange aRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.MakeOutline( aRange, bColumns, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_NOMULTISELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Outline-Gruppierung loeschen
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::RemoveOutline( sal_Bool bColumns, sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScRange aRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.RemoveOutline( aRange, bColumns, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_NOMULTISELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Menue-Status: Outlines loeschen
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::TestRemoveOutline( sal_Bool& rCol, sal_Bool& rRow )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bColFound = false;
|
|
|
|
sal_Bool bRowFound = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOL nStartCol, nEndCol;
|
|
|
|
SCROW nStartRow, nEndRow;
|
|
|
|
SCTAB nStartTab, nEndTab;
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = nStartTab;
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
|
|
|
|
if (pTable)
|
|
|
|
{
|
|
|
|
ScOutlineArray* pArray;
|
|
|
|
ScOutlineEntry* pEntry;
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOLROW nStart;
|
|
|
|
SCCOLROW nEnd;
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bColMarked = ( nStartRow == 0 && nEndRow == MAXROW );
|
|
|
|
sal_Bool bRowMarked = ( nStartCol == 0 && nEndCol == MAXCOL );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Spalten
|
|
|
|
|
|
|
|
if ( !bRowMarked || bColMarked ) // nicht wenn ganze Zeilen markiert
|
|
|
|
{
|
|
|
|
pArray = pTable->GetColArray();
|
|
|
|
ScSubOutlineIterator aColIter( pArray );
|
|
|
|
while ((pEntry=aColIter.GetNext()) != NULL && !bColFound)
|
|
|
|
{
|
|
|
|
nStart = pEntry->GetStart();
|
|
|
|
nEnd = pEntry->GetEnd();
|
2004-06-04 10:59:26 +00:00
|
|
|
if ( nStartCol<=static_cast<SCCOL>(nEnd) && nEndCol>=static_cast<SCCOL>(nStart) )
|
2011-01-17 13:20:22 +01:00
|
|
|
bColFound = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zeilen
|
|
|
|
|
|
|
|
if ( !bColMarked || bRowMarked ) // nicht wenn ganze Spalten markiert
|
|
|
|
{
|
|
|
|
pArray = pTable->GetRowArray();
|
|
|
|
ScSubOutlineIterator aRowIter( pArray );
|
|
|
|
while ((pEntry=aRowIter.GetNext()) != NULL && !bRowFound)
|
|
|
|
{
|
|
|
|
nStart = pEntry->GetStart();
|
|
|
|
nEnd = pEntry->GetEnd();
|
|
|
|
if ( nStartRow<=nEnd && nEndRow>=nStart )
|
2011-01-17 13:20:22 +01:00
|
|
|
bRowFound = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rCol = bColFound;
|
|
|
|
rRow = bRowFound;
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::RemoveAllOutlines( sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bOk = aFunc.RemoveAllOutlines( nTab, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
|
|
|
|
if (bOk)
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-Outlines
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::AutoOutline( sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab ); // ganze Tabelle, wenn nichts markiert
|
|
|
|
ScMarkData& rMark = GetViewData()->GetMarkData();
|
|
|
|
if ( rMark.IsMarked() || rMark.IsMultiMarked() )
|
|
|
|
{
|
|
|
|
rMark.MarkToMulti();
|
|
|
|
rMark.GetMultiMarkArea( aRange );
|
|
|
|
}
|
|
|
|
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.AutoOutline( aRange, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Outline-Ebene auswaehlen
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::SelectLevel( sal_Bool bColumns, sal_uInt16 nLevel, sal_Bool bRecord, sal_Bool bPaint )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bOk = aFunc.SelectLevel( nTab, bColumns, nLevel, bRecord, bPaint, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
|
|
|
|
if (bOk)
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
|
|
|
|
// einzelne Outline-Gruppe einblenden
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::ShowOutline( sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry, sal_Bool bRecord, sal_Bool bPaint )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bOk = aFunc.ShowOutline( nTab, bColumns, nLevel, nEntry, bRecord, bPaint, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
|
|
|
|
if ( bOk && bPaint )
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
|
|
|
|
// einzelne Outline-Gruppe ausblenden
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::HideOutline( sal_Bool bColumns, sal_uInt16 nLevel, sal_uInt16 nEntry, sal_Bool bRecord, sal_Bool bPaint )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bOk = aFunc.HideOutline( nTab, bColumns, nLevel, nEntry, bRecord, bPaint, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
|
|
|
|
if ( bOk && bPaint )
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Menue-Status: markierten Bereich ein-/ausblenden
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool ScDBFunc::OutlinePossible(sal_Bool bHide)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bEnable = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOL nStartCol;
|
|
|
|
SCROW nStartRow;
|
|
|
|
SCTAB nStartTab;
|
|
|
|
SCCOL nEndCol;
|
|
|
|
SCROW nEndRow;
|
|
|
|
SCTAB nEndTab;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
|
|
|
|
if (pTable)
|
|
|
|
{
|
|
|
|
ScOutlineArray* pArray;
|
|
|
|
ScOutlineEntry* pEntry;
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOLROW nStart;
|
|
|
|
SCCOLROW nEnd;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Spalten
|
|
|
|
|
|
|
|
pArray = pTable->GetColArray();
|
|
|
|
ScSubOutlineIterator aColIter( pArray );
|
|
|
|
while ((pEntry=aColIter.GetNext()) != NULL && !bEnable)
|
|
|
|
{
|
|
|
|
nStart = pEntry->GetStart();
|
|
|
|
nEnd = pEntry->GetEnd();
|
|
|
|
if ( bHide )
|
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
if ( nStartCol<=static_cast<SCCOL>(nEnd) && nEndCol>=static_cast<SCCOL>(nStart) )
|
2000-09-18 16:07:07 +00:00
|
|
|
if (!pEntry->IsHidden())
|
2011-01-17 13:20:22 +01:00
|
|
|
bEnable = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( nStart>=nStartCol && nEnd<=nEndCol )
|
|
|
|
if (pEntry->IsHidden())
|
2011-01-17 13:20:22 +01:00
|
|
|
bEnable = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zeilen
|
|
|
|
|
|
|
|
pArray = pTable->GetRowArray();
|
|
|
|
ScSubOutlineIterator aRowIter( pArray );
|
|
|
|
while ((pEntry=aRowIter.GetNext()) != NULL)
|
|
|
|
{
|
|
|
|
nStart = pEntry->GetStart();
|
|
|
|
nEnd = pEntry->GetEnd();
|
|
|
|
if ( bHide )
|
|
|
|
{
|
|
|
|
if ( nStartRow<=nEnd && nEndRow>=nStart )
|
|
|
|
if (!pEntry->IsHidden())
|
2011-01-17 13:20:22 +01:00
|
|
|
bEnable = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( nStart>=nStartRow && nEnd<=nEndRow )
|
|
|
|
if (pEntry->IsHidden())
|
2011-01-17 13:20:22 +01:00
|
|
|
bEnable = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// markierten Bereich einblenden
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::ShowMarkedOutlines( sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScRange aRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bDone = aFunc.ShowMarkedOutlines( aRange, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
if (bDone)
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_NOMULTISELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// markierten Bereich ausblenden
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::HideMarkedOutlines( sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScRange aRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScOutlineDocFunc aFunc(*pDocSh);
|
|
|
|
HideCursor();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bDone = aFunc.HideMarkedOutlines( aRange, bRecord, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
ShowCursor();
|
|
|
|
if (bDone)
|
|
|
|
UpdateScrollBars();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_NOMULTISELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//
|
|
|
|
// Teilergebnisse
|
|
|
|
//
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::DoSubTotals( const ScSubTotalParam& rParam, sal_Bool bRecord,
|
2000-09-18 16:07:07 +00:00
|
|
|
const ScSortParam* pForceNewSort )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bDo = !rParam.bRemoveOnly; // sal_False = nur loeschen
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScDocument* pDoc = pDocSh->GetDocument();
|
|
|
|
ScMarkData& rMark = GetViewData()->GetMarkData();
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2001-02-14 14:34:08 +00:00
|
|
|
if (bRecord && !pDoc->IsUndoEnabled())
|
2011-03-10 16:55:21 -05:00
|
|
|
bRecord = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScDBData* pDBData = pDoc->GetDBAtArea( nTab, rParam.nCol1, rParam.nRow1,
|
|
|
|
rParam.nCol2, rParam.nRow2 );
|
|
|
|
if (!pDBData)
|
|
|
|
{
|
2011-03-01 19:05:02 +01:00
|
|
|
OSL_FAIL( "SubTotals: keine DBData" );
|
2000-09-18 16:07:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-20 13:36:29 +00:00
|
|
|
ScEditableTester aTester( pDoc, nTab, 0,rParam.nRow1+1, MAXCOL,MAXROW );
|
|
|
|
if (!aTester.IsEditable())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2002-11-20 13:36:29 +00:00
|
|
|
ErrorMessage(aTester.GetMessageId());
|
2000-09-18 16:07:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDoc->HasAttrib( rParam.nCol1, rParam.nRow1+1, nTab,
|
|
|
|
rParam.nCol2, rParam.nRow2, nTab, HASATTR_MERGED | HASATTR_OVERLAPPED ))
|
|
|
|
{
|
|
|
|
ErrorMessage(STR_MSSG_INSERTCELLS_0); // nicht in zusammengefasste einfuegen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitObject aWait( GetViewData()->GetDialogParent() );
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bOk = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
if (rParam.bReplace)
|
|
|
|
if (pDoc->TestRemoveSubTotals( nTab, rParam ))
|
|
|
|
{
|
|
|
|
bOk = ( MessBox( GetViewData()->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
|
|
|
|
// "StarCalc" "Daten loeschen?"
|
|
|
|
ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ),
|
|
|
|
ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_1 ) ).Execute()
|
|
|
|
== RET_YES );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bOk)
|
|
|
|
{
|
|
|
|
ScDocShellModificator aModificator( *pDocSh );
|
|
|
|
|
|
|
|
ScSubTotalParam aNewParam( rParam ); // Bereichsende wird veraendert
|
|
|
|
ScDocument* pUndoDoc = NULL;
|
|
|
|
ScOutlineTable* pUndoTab = NULL;
|
|
|
|
ScRangeName* pUndoRange = NULL;
|
|
|
|
ScDBCollection* pUndoDB = NULL;
|
|
|
|
|
|
|
|
if (bRecord) // alte Daten sichern
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bOldFilter = bDo && rParam.bDoSort;
|
2011-01-04 18:40:11 +00:00
|
|
|
SCTAB nTabCount = pDoc->GetTableCount();
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
|
|
|
|
ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
|
|
|
|
if (pTable)
|
|
|
|
{
|
|
|
|
pUndoTab = new ScOutlineTable( *pTable );
|
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOLROW nOutStartCol; // Zeilen/Spaltenstatus
|
|
|
|
SCCOLROW nOutStartRow;
|
|
|
|
SCCOLROW nOutEndCol;
|
|
|
|
SCCOLROW nOutEndRow;
|
2000-09-18 16:07:07 +00:00
|
|
|
pTable->GetColArray()->GetRange( nOutStartCol, nOutEndCol );
|
|
|
|
pTable->GetRowArray()->GetRange( nOutStartRow, nOutEndRow );
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
|
2011-03-10 16:55:21 -05:00
|
|
|
pDoc->CopyToDocument( static_cast<SCCOL>(nOutStartCol), 0, nTab, static_cast<SCCOL>(nOutEndCol), MAXROW, nTab, IDF_NONE, false, pUndoDoc );
|
|
|
|
pDoc->CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, IDF_NONE, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2011-03-10 16:55:21 -05:00
|
|
|
pUndoDoc->InitUndo( pDoc, nTab, nTab, false, bOldFilter );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Datenbereich sichern - incl. Filter-Ergebnis
|
|
|
|
pDoc->CopyToDocument( 0,rParam.nRow1+1,nTab, MAXCOL,rParam.nRow2,nTab,
|
2011-03-10 16:55:21 -05:00
|
|
|
IDF_ALL, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// alle Formeln wegen Referenzen
|
|
|
|
pDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
|
2011-03-10 16:55:21 -05:00
|
|
|
IDF_FORMULA, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// DB- und andere Bereiche
|
|
|
|
ScRangeName* pDocRange = pDoc->GetRangeName();
|
2011-03-04 19:25:02 -05:00
|
|
|
if (!pDocRange->empty())
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoRange = new ScRangeName( *pDocRange );
|
|
|
|
ScDBCollection* pDocDB = pDoc->GetDBCollection();
|
2011-05-12 16:26:26 -04:00
|
|
|
if (!pDocDB->empty())
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoDB = new ScDBCollection( *pDocDB );
|
|
|
|
}
|
|
|
|
|
|
|
|
ScOutlineTable* pOut = pDoc->GetOutlineTable( nTab );
|
|
|
|
if (pOut)
|
2011-04-01 00:09:18 -04:00
|
|
|
{
|
|
|
|
// Remove all existing outlines in the specified range.
|
|
|
|
ScOutlineArray* pRowArray = pOut->GetRowArray();
|
|
|
|
sal_uInt16 nDepth = pRowArray->GetDepth();
|
|
|
|
for (sal_uInt16 i = 0; i < nDepth; ++i)
|
|
|
|
{
|
2012-02-03 23:35:49 -05:00
|
|
|
bool bSize;
|
2011-04-01 00:09:18 -04:00
|
|
|
pRowArray->Remove(aNewParam.nRow1, aNewParam.nRow2, bSize);
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if (rParam.bReplace)
|
|
|
|
pDoc->RemoveSubTotals( nTab, aNewParam );
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bSuccess = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
if (bDo)
|
|
|
|
{
|
|
|
|
// Sortieren
|
|
|
|
if ( rParam.bDoSort || pForceNewSort )
|
|
|
|
{
|
|
|
|
pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
|
|
|
|
|
|
|
|
// Teilergebnis-Felder vor die Sortierung setzen
|
|
|
|
// (doppelte werden weggelassen, kann darum auch wieder aufgerufen werden)
|
|
|
|
|
|
|
|
ScSortParam aOldSort;
|
|
|
|
pDBData->GetSortParam( aOldSort );
|
|
|
|
ScSortParam aSortParam( aNewParam, pForceNewSort ? *pForceNewSort : aOldSort );
|
2011-03-10 16:55:21 -05:00
|
|
|
Sort( aSortParam, false, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = pDoc->DoSubTotals( nTab, aNewParam );
|
|
|
|
}
|
|
|
|
ScRange aDirtyRange( aNewParam.nCol1, aNewParam.nRow1, nTab,
|
|
|
|
aNewParam.nCol2, aNewParam.nRow2, nTab );
|
|
|
|
pDoc->SetDirty( aDirtyRange );
|
|
|
|
|
|
|
|
if (bRecord)
|
|
|
|
{
|
|
|
|
pDocSh->GetUndoManager()->AddUndoAction(
|
|
|
|
new ScUndoSubTotals( pDocSh, nTab,
|
|
|
|
rParam, aNewParam.nRow2,
|
|
|
|
pUndoDoc, pUndoTab, // pUndoDBData,
|
|
|
|
pUndoRange, pUndoDB ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
// "Kann keine Zeilen einfuegen"
|
|
|
|
ErrorMessage(STR_MSSG_DOSUBTOTALS_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// merken
|
|
|
|
pDBData->SetSubTotalParam( aNewParam );
|
|
|
|
pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
|
|
|
|
pDoc->CompileDBFormula();
|
|
|
|
|
|
|
|
DoneBlockMode();
|
|
|
|
InitOwnBlockMode();
|
|
|
|
rMark.SetMarkArea( ScRange( aNewParam.nCol1,aNewParam.nRow1,nTab,
|
|
|
|
aNewParam.nCol2,aNewParam.nRow2,nTab ) );
|
2008-02-19 14:34:47 +00:00
|
|
|
MarkDataChanged();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-09-09 22:08:28 -04:00
|
|
|
pDocSh->PostPaint(ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab),
|
|
|
|
PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
aModificator.SetDocumentModified();
|
|
|
|
|
|
|
|
SelectionChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Consolidate
|
|
|
|
//
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::Consolidate( const ScConsolidateParam& rParam, sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocShell = GetViewData()->GetDocShell();
|
|
|
|
pDocShell->DoConsolidate( rParam, bRecord );
|
2011-01-17 13:20:22 +01:00
|
|
|
SetTabNo( rParam.nTab, sal_True );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Pivot
|
|
|
|
//
|
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
String lcl_MakePivotTabName( const String& rPrefix, SCTAB nNumber )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
String aName = rPrefix;
|
|
|
|
aName += String::CreateFromInt32( nNumber );
|
|
|
|
return aName;
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
bool ScDBFunc::MakePivotTable( const ScDPSaveData& rData, const ScRange& rDest, sal_Bool bNewTable,
|
|
|
|
const ScDPObject& rSource, sal_Bool bApi )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-03-02 21:32:00 +01:00
|
|
|
// error message if no fields are set
|
2000-09-18 16:07:07 +00:00
|
|
|
// this must be removed when drag&drop of fields from a toolbox is available
|
|
|
|
|
|
|
|
if ( rData.IsEmpty() && !bApi )
|
|
|
|
{
|
|
|
|
ErrorMessage(STR_PIVOT_NODATA);
|
2008-11-27 15:23:33 +00:00
|
|
|
return false;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bUndo(pDoc->IsUndoEnabled());
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScRange aDestRange = rDest;
|
|
|
|
if ( bNewTable )
|
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nSrcTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
String aName( ScGlobal::GetRscString(STR_PIVOT_TABLE) );
|
2011-08-26 19:33:59 -04:00
|
|
|
rtl::OUString aStr;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
pDoc->GetName( nSrcTab, aStr );
|
|
|
|
aName += '_';
|
2011-08-26 19:33:59 -04:00
|
|
|
aName += String(aStr);
|
2000-09-18 16:07:07 +00:00
|
|
|
aName += '_';
|
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nNewTab = nSrcTab+1;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB i=1;
|
2000-09-18 16:07:07 +00:00
|
|
|
while ( !pDoc->InsertTab( nNewTab, lcl_MakePivotTabName( aName, i ) ) && i <= MAXTAB )
|
|
|
|
i++;
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bAppend = ( nNewTab+1 == pDoc->GetTableCount() );
|
2001-02-14 14:34:08 +00:00
|
|
|
if (bUndo)
|
|
|
|
{
|
|
|
|
pDocSh->GetUndoManager()->AddUndoAction(
|
|
|
|
new ScUndoInsertTab( pDocSh, nNewTab, bAppend, lcl_MakePivotTabName( aName, i ) ));
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
GetViewData()->InsertTab( nNewTab );
|
2011-01-17 13:20:22 +01:00
|
|
|
SetTabNo( nNewTab, sal_True );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
aDestRange = ScRange( 0, 0, nNewTab );
|
|
|
|
}
|
|
|
|
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor(
|
|
|
|
aDestRange.aStart.Col(), aDestRange.aStart.Row(), aDestRange.aStart.Tab() );
|
|
|
|
|
|
|
|
ScDPObject aObj( rSource );
|
|
|
|
aObj.SetOutRange( aDestRange );
|
2004-08-03 11:46:58 +00:00
|
|
|
if ( pDPObj && !rData.GetExistingDimensionData() )
|
|
|
|
{
|
|
|
|
// copy dimension data from old object - lost in the dialog
|
|
|
|
//! change the dialog to keep the dimension data
|
|
|
|
|
|
|
|
ScDPSaveData aNewData( rData );
|
|
|
|
const ScDPSaveData* pOldData = pDPObj->GetSaveData();
|
|
|
|
if ( pOldData )
|
|
|
|
{
|
|
|
|
const ScDPDimensionSaveData* pDimSave = pOldData->GetExistingDimensionData();
|
|
|
|
aNewData.SetDimensionData( pDimSave );
|
|
|
|
}
|
|
|
|
aObj.SetSaveData( aNewData );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aObj.SetSaveData( rData );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-01-21 12:28:11 -05:00
|
|
|
bool bAllowMove = (pDPObj != NULL); // allow re-positioning when editing existing table
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDBDocFunc aFunc( *pDocSh );
|
2011-03-10 16:55:21 -05:00
|
|
|
bool bSuccess = aFunc.DataPilotUpdate( pDPObj, &aObj, sal_True, false, bAllowMove );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
CursorPosChanged(); // shells may be switched
|
|
|
|
|
|
|
|
if ( bNewTable )
|
|
|
|
{
|
|
|
|
pDocSh->PostPaintExtras();
|
|
|
|
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
|
|
|
|
}
|
2008-11-27 15:23:33 +00:00
|
|
|
|
|
|
|
return bSuccess;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScDBFunc::DeletePivotTable()
|
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScDocument* pDoc = pDocSh->GetDocument();
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(),
|
|
|
|
GetViewData()->GetTabNo() );
|
|
|
|
if ( pDPObj )
|
|
|
|
{
|
|
|
|
ScDBDocFunc aFunc( *pDocSh );
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.DataPilotUpdate( pDPObj, NULL, sal_True, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
CursorPosChanged(); // shells may be switched
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_PIVOT_NOTFOUND);
|
|
|
|
}
|
2010-02-08 11:44:10 +01:00
|
|
|
|
2011-02-28 21:27:41 -05:00
|
|
|
void ScDBFunc::RecalcPivotTable()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
ScDocShell* pDocSh = GetViewData()->GetDocShell();
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(),
|
|
|
|
GetViewData()->GetTabNo() );
|
2012-03-13 14:33:21 -04:00
|
|
|
if (pDPObj)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-04-27 17:21:25 -04:00
|
|
|
// Remove existing data cache for the data that this datapilot uses,
|
|
|
|
// to force re-build data cache.
|
2012-03-13 14:33:21 -04:00
|
|
|
ScDBDocFunc aFunc(*pDocSh);
|
2012-03-14 00:31:56 -04:00
|
|
|
aFunc.RefreshPivotTables(pDPObj, false);
|
2012-01-12 15:22:32 -05:00
|
|
|
|
2011-02-28 21:27:41 -05:00
|
|
|
CursorPosChanged(); // shells may be switched
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorMessage(STR_PIVOT_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
void ScDBFunc::GetSelectedMemberList(ScDPUniqueStringSet& rEntries, long& rDimension)
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
|
|
|
if ( !pDPObj )
|
|
|
|
return;
|
|
|
|
|
|
|
|
long nStartDimension = -1;
|
|
|
|
long nStartHierarchy = -1;
|
|
|
|
long nStartLevel = -1;
|
|
|
|
|
|
|
|
ScRangeListRef xRanges;
|
|
|
|
GetViewData()->GetMultiArea( xRanges ); // incl. cursor if nothing is selected
|
2010-12-08 22:38:24 -08:00
|
|
|
size_t nRangeCount = xRanges->size();
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bContinue = true;
|
2004-07-23 12:01:21 +00:00
|
|
|
|
2010-12-08 22:38:24 -08:00
|
|
|
for (size_t nRangePos=0; nRangePos < nRangeCount && bContinue; nRangePos++)
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2010-12-10 16:07:50 -05:00
|
|
|
ScRange aRange = *(*xRanges)[nRangePos];
|
2004-07-23 12:01:21 +00:00
|
|
|
SCCOL nStartCol = aRange.aStart.Col();
|
|
|
|
SCROW nStartRow = aRange.aStart.Row();
|
|
|
|
SCCOL nEndCol = aRange.aEnd.Col();
|
|
|
|
SCROW nEndRow = aRange.aEnd.Row();
|
|
|
|
SCTAB nTab = aRange.aStart.Tab();
|
|
|
|
|
|
|
|
for (SCROW nRow=nStartRow; nRow<=nEndRow && bContinue; nRow++)
|
|
|
|
for (SCCOL nCol=nStartCol; nCol<=nEndCol && bContinue; nCol++)
|
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
sheet::DataPilotTableHeaderData aData;
|
|
|
|
pDPObj->GetHeaderPositionData(ScAddress(nCol, nRow, nTab), aData);
|
|
|
|
if ( aData.Dimension < 0 )
|
2011-03-10 16:55:21 -05:00
|
|
|
bContinue = false; // not part of any dimension
|
2004-07-23 12:01:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( nStartDimension < 0 ) // first member?
|
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
nStartDimension = aData.Dimension;
|
|
|
|
nStartHierarchy = aData.Hierarchy;
|
|
|
|
nStartLevel = aData.Level;
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
2008-05-20 12:12:40 +00:00
|
|
|
if ( aData.Dimension != nStartDimension ||
|
|
|
|
aData.Hierarchy != nStartHierarchy ||
|
|
|
|
aData.Level != nStartLevel )
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2011-03-10 16:55:21 -05:00
|
|
|
bContinue = false; // cannot mix dimensions
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( bContinue )
|
|
|
|
{
|
|
|
|
// accept any part of a member description, also subtotals,
|
|
|
|
// but don't stop if empty parts are contained
|
2008-05-20 12:12:40 +00:00
|
|
|
if ( aData.Flags & sheet::MemberResultFlags::HASMEMBER )
|
2012-02-03 14:23:19 -05:00
|
|
|
rEntries.insert(aData.MemberName);
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rDimension = nStartDimension; // dimension from which the found members came
|
|
|
|
if (!bContinue)
|
2012-02-03 14:23:19 -05:00
|
|
|
rEntries.clear(); // remove all if not valid
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
bool ScDBFunc::HasSelectionForDateGroup( ScDPNumGroupInfo& rOldInfo, sal_Int32& rParts )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
|
|
|
// determine if the date group dialog has to be shown for the current selection
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
bool bFound = false;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
|
|
|
SCCOL nCurX = GetViewData()->GetCurX();
|
|
|
|
SCROW nCurY = GetViewData()->GetCurY();
|
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( nCurX, nCurY, nTab );
|
|
|
|
if ( pDPObj )
|
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
2004-08-03 11:46:58 +00:00
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
if (!aEntries.empty())
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
String aBaseDimName( aDimName );
|
|
|
|
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bInGroupDim = false;
|
|
|
|
sal_Bool bFoundParts = false;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
|
|
|
ScDPDimensionSaveData* pDimData =
|
|
|
|
const_cast<ScDPDimensionSaveData*>( pDPObj->GetSaveData()->GetExistingDimensionData() );
|
|
|
|
if ( pDimData )
|
|
|
|
{
|
|
|
|
const ScDPSaveNumGroupDimension* pNumGroupDim = pDimData->GetNumGroupDim( aDimName );
|
|
|
|
const ScDPSaveGroupDimension* pGroupDim = pDimData->GetNamedGroupDim( aDimName );
|
|
|
|
if ( pNumGroupDim )
|
|
|
|
{
|
|
|
|
// existing num group dimension
|
|
|
|
|
|
|
|
if ( pNumGroupDim->GetDatePart() != 0 )
|
|
|
|
{
|
|
|
|
// dimension has date info -> edit settings of this dimension
|
|
|
|
// (parts are collected below)
|
|
|
|
|
|
|
|
rOldInfo = pNumGroupDim->GetDateInfo();
|
2011-01-17 13:20:22 +01:00
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2012-02-28 16:11:53 -05:00
|
|
|
else if ( pNumGroupDim->GetInfo().mbDateValues )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
|
|
|
// Numerical grouping with DateValues flag is used for grouping
|
|
|
|
// of days with a "Number of days" value.
|
|
|
|
|
|
|
|
rOldInfo = pNumGroupDim->GetInfo();
|
2005-03-29 11:55:42 +00:00
|
|
|
rParts = com::sun::star::sheet::DataPilotFieldGroupBy::DAYS; // not found in CollectDateParts
|
2011-01-17 13:20:22 +01:00
|
|
|
bFoundParts = sal_True;
|
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2011-01-17 13:20:22 +01:00
|
|
|
bInGroupDim = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
else if ( pGroupDim )
|
|
|
|
{
|
|
|
|
// existing additional group dimension
|
|
|
|
|
|
|
|
if ( pGroupDim->GetDatePart() != 0 )
|
|
|
|
{
|
|
|
|
// dimension has date info -> edit settings of this dimension
|
|
|
|
// (parts are collected below)
|
|
|
|
|
|
|
|
rOldInfo = pGroupDim->GetDateInfo();
|
|
|
|
aBaseDimName = pGroupDim->GetSourceDimName();
|
2011-01-17 13:20:22 +01:00
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2011-01-17 13:20:22 +01:00
|
|
|
bInGroupDim = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( bFound && !bFoundParts )
|
|
|
|
{
|
|
|
|
// collect date parts from all group dimensions
|
|
|
|
rParts = pDimData->CollectDateParts( aBaseDimName );
|
|
|
|
}
|
|
|
|
if ( !bFound && !bInGroupDim )
|
|
|
|
{
|
|
|
|
// create new date group dimensions if the selection is a single cell
|
|
|
|
// in a normal dimension with date content
|
|
|
|
|
|
|
|
ScRange aSelRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if ( (GetViewData()->GetSimpleArea( aSelRange ) == SC_MARK_SIMPLE) &&
|
|
|
|
aSelRange.aStart == aSelRange.aEnd )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2007-02-27 12:49:45 +00:00
|
|
|
SCCOL nSelCol = aSelRange.aStart.Col();
|
|
|
|
SCROW nSelRow = aSelRange.aStart.Row();
|
|
|
|
SCTAB nSelTab = aSelRange.aStart.Tab();
|
|
|
|
if ( pDoc->HasValueData( nSelCol, nSelRow, nSelTab ) )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uLong nIndex = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(
|
2007-02-27 12:49:45 +00:00
|
|
|
nSelCol, nSelRow, nSelTab, ATTR_VALUE_FORMAT))->GetValue();
|
2004-08-03 11:46:58 +00:00
|
|
|
short nType = pDoc->GetFormatTable()->GetType(nIndex);
|
|
|
|
if ( nType == NUMBERFORMAT_DATE || nType == NUMBERFORMAT_TIME || nType == NUMBERFORMAT_DATETIME )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
// use currently selected value for automatic limits
|
2012-02-28 16:11:53 -05:00
|
|
|
if( rOldInfo.mbAutoStart )
|
|
|
|
rOldInfo.mfStart = pDoc->GetValue( aSelRange.aStart );
|
|
|
|
if( rOldInfo.mbAutoEnd )
|
|
|
|
rOldInfo.mfEnd = pDoc->GetValue( aSelRange.aStart );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
bool ScDBFunc::HasSelectionForNumGroup( ScDPNumGroupInfo& rOldInfo )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
|
|
|
// determine if the numeric group dialog has to be shown for the current selection
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
bool bFound = false;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
|
|
|
SCCOL nCurX = GetViewData()->GetCurX();
|
|
|
|
SCROW nCurY = GetViewData()->GetCurY();
|
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( nCurX, nCurY, nTab );
|
|
|
|
if ( pDPObj )
|
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
2004-08-03 11:46:58 +00:00
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
if (!aEntries.empty())
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bInGroupDim = false;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
|
|
|
ScDPDimensionSaveData* pDimData =
|
|
|
|
const_cast<ScDPDimensionSaveData*>( pDPObj->GetSaveData()->GetExistingDimensionData() );
|
|
|
|
if ( pDimData )
|
|
|
|
{
|
|
|
|
const ScDPSaveNumGroupDimension* pNumGroupDim = pDimData->GetNumGroupDim( aDimName );
|
|
|
|
if ( pNumGroupDim )
|
|
|
|
{
|
|
|
|
// existing num group dimension
|
|
|
|
// -> edit settings of this dimension
|
|
|
|
|
|
|
|
rOldInfo = pNumGroupDim->GetInfo();
|
2011-01-17 13:20:22 +01:00
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
else if ( pDimData->GetNamedGroupDim( aDimName ) )
|
2011-01-17 13:20:22 +01:00
|
|
|
bInGroupDim = sal_True; // in a group dimension
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
if ( !bFound && !bInGroupDim )
|
|
|
|
{
|
|
|
|
// create a new num group dimension if the selection is a single cell
|
|
|
|
// in a normal dimension with numeric content
|
|
|
|
|
|
|
|
ScRange aSelRange;
|
2008-04-18 10:44:03 +00:00
|
|
|
if ( (GetViewData()->GetSimpleArea( aSelRange ) == SC_MARK_SIMPLE) &&
|
|
|
|
aSelRange.aStart == aSelRange.aEnd )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
|
|
|
if ( pDoc->HasValueData( aSelRange.aStart.Col(), aSelRange.aStart.Row(),
|
|
|
|
aSelRange.aStart.Tab() ) )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
bFound = sal_True;
|
2004-08-03 11:46:58 +00:00
|
|
|
// use currently selected value for automatic limits
|
2012-02-28 16:11:53 -05:00
|
|
|
if( rOldInfo.mbAutoStart )
|
|
|
|
rOldInfo.mfStart = pDoc->GetValue( aSelRange.aStart );
|
|
|
|
if( rOldInfo.mbAutoEnd )
|
|
|
|
rOldInfo.mfEnd = pDoc->GetValue( aSelRange.aStart );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScDBFunc::DateGroupDataPilot( const ScDPNumGroupInfo& rInfo, sal_Int32 nParts )
|
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
2012-03-05 16:23:57 -05:00
|
|
|
if (!pDPObj)
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if (aEntries.empty())
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData(); // created if not there
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// find original base
|
2012-03-05 16:37:38 -05:00
|
|
|
rtl::OUString aBaseDimName = aDimName;
|
2012-03-05 16:23:57 -05:00
|
|
|
if( const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName ) )
|
|
|
|
aBaseDimName = pBaseGroupDim->GetSourceDimName();
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// remove all existing parts (the grouping is built completely new)
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
/* Remove numeric group dimension (exists once at most). No need
|
|
|
|
to delete anything in save data (grouping was done inplace in
|
|
|
|
an existing base dimension). */
|
|
|
|
pDimData->RemoveNumGroupDimension( aBaseDimName );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
/* Remove named group dimension(s). Collect deleted dimension
|
|
|
|
names which may be reused while recreating the groups.
|
|
|
|
Dimensions have to be removed from dimension save data and from
|
|
|
|
save data too. */
|
|
|
|
std::vector<rtl::OUString> aDeletedNames;
|
|
|
|
const ScDPSaveGroupDimension* pExistingGroup = pDimData->GetGroupDimForBase( aBaseDimName );
|
|
|
|
while ( pExistingGroup )
|
|
|
|
{
|
2012-03-05 21:17:14 -05:00
|
|
|
rtl::OUString aGroupDimName = pExistingGroup->GetGroupDimName();
|
2012-03-05 16:23:57 -05:00
|
|
|
pDimData->RemoveGroupDimension( aGroupDimName ); // pExistingGroup is deleted
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// also remove SaveData settings for the dimension that no longer exists
|
|
|
|
aData.RemoveDimensionByName( aGroupDimName );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
/* The name can be used for the new group dimensions, although
|
|
|
|
it is still in use with the DataPilotSource. */
|
|
|
|
aDeletedNames.push_back( aGroupDimName );
|
|
|
|
|
|
|
|
// see if there are more group dimensions
|
|
|
|
pExistingGroup = pDimData->GetGroupDimForBase( aBaseDimName );
|
|
|
|
|
|
|
|
if ( pExistingGroup && pExistingGroup->GetGroupDimName() == aGroupDimName )
|
|
|
|
{
|
|
|
|
// still get the same group dimension?
|
|
|
|
OSL_FAIL("couldn't remove group dimension");
|
|
|
|
pExistingGroup = NULL; // avoid endless loop
|
|
|
|
}
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if ( nParts )
|
|
|
|
{
|
|
|
|
// create date group dimensions
|
|
|
|
|
|
|
|
ScDPNumGroupInfo aEmpty;
|
|
|
|
bool bFirst = true;
|
|
|
|
sal_Int32 nMask = 1;
|
|
|
|
for (sal_uInt16 nBit=0; nBit<32; nBit++)
|
|
|
|
{
|
|
|
|
if ( nParts & nMask )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
if ( bFirst )
|
|
|
|
{
|
|
|
|
// innermost part: create NumGroupDimension (replacing original values)
|
|
|
|
// Dimension name is left unchanged
|
|
|
|
|
|
|
|
if ( (nParts == sheet::DataPilotFieldGroupBy::DAYS) && (rInfo.mfStep >= 1.0) )
|
|
|
|
{
|
|
|
|
// only days, and a step value specified: use numerical grouping
|
|
|
|
// with DateValues flag, not date grouping
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPNumGroupInfo aNumInfo( rInfo );
|
|
|
|
aNumInfo.mbDateValues = true;
|
|
|
|
|
|
|
|
ScDPSaveNumGroupDimension aNumGroupDim( aBaseDimName, aNumInfo );
|
|
|
|
pDimData->AddNumGroupDimension( aNumGroupDim );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScDPSaveNumGroupDimension aNumGroupDim( aBaseDimName, rInfo, nMask );
|
|
|
|
pDimData->AddNumGroupDimension( aNumGroupDim );
|
|
|
|
}
|
|
|
|
|
|
|
|
bFirst = false;
|
|
|
|
}
|
|
|
|
else
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
// additional parts: create GroupDimension (shown as additional dimensions)
|
2012-03-05 16:37:38 -05:00
|
|
|
rtl::OUString aGroupDimName =
|
|
|
|
pDimData->CreateDateGroupDimName(nMask, *pDPObj, true, &aDeletedNames);
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveGroupDimension aGroupDim( aBaseDimName, aGroupDimName );
|
|
|
|
aGroupDim.SetDateInfo( rInfo, nMask );
|
|
|
|
pDimData->AddGroupDimension( aGroupDim );
|
|
|
|
|
|
|
|
// set orientation
|
|
|
|
ScDPSaveDimension* pSaveDimension = aData.GetDimensionByName( aGroupDimName );
|
|
|
|
if ( pSaveDimension->GetOrientation() == sheet::DataPilotFieldOrientation_HIDDEN )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveDimension* pOldDimension = aData.GetDimensionByName( aBaseDimName );
|
|
|
|
pSaveDimension->SetOrientation( pOldDimension->GetOrientation() );
|
|
|
|
long nPosition = 0; //! before (immediate) base
|
|
|
|
aData.SetPosition( pSaveDimension, nPosition );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 16:23:57 -05:00
|
|
|
nMask *= 2;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-05 16:23:57 -05:00
|
|
|
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
2012-03-05 16:30:43 -05:00
|
|
|
pDPObj->SetSaveData( aData );
|
2012-03-14 00:31:56 -04:00
|
|
|
aFunc.RefreshPivotTableGroups(pDPObj);
|
2012-03-05 16:23:57 -05:00
|
|
|
|
|
|
|
// unmark cell selection
|
|
|
|
Unmark();
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScDBFunc::NumGroupDataPilot( const ScDPNumGroupInfo& rInfo )
|
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
2012-03-05 16:23:57 -05:00
|
|
|
if (!pDPObj)
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if (aEntries.empty())
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData(); // created if not there
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveNumGroupDimension* pExisting = pDimData->GetNumGroupDimAcc( aDimName );
|
|
|
|
if ( pExisting )
|
|
|
|
{
|
|
|
|
// modify existing group dimension
|
|
|
|
pExisting->SetGroupInfo( rInfo );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2012-03-05 16:23:57 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// create new group dimension
|
|
|
|
ScDPSaveNumGroupDimension aNumGroupDim( aDimName, rInfo );
|
|
|
|
pDimData->AddNumGroupDimension( aNumGroupDim );
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
2012-03-05 16:30:43 -05:00
|
|
|
pDPObj->SetSaveData( aData );
|
2012-03-14 00:31:56 -04:00
|
|
|
aFunc.RefreshPivotTableGroups(pDPObj);
|
2012-03-05 16:23:57 -05:00
|
|
|
|
|
|
|
// unmark cell selection
|
|
|
|
Unmark();
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScDBFunc::GroupDataPilot()
|
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
2012-03-05 16:23:57 -05:00
|
|
|
if (!pDPObj)
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if (aEntries.empty())
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
|
|
|
|
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData(); // created if not there
|
|
|
|
|
|
|
|
// find original base
|
2012-03-13 16:30:49 -04:00
|
|
|
rtl::OUString aBaseDimName = aDimName;
|
2012-03-05 16:23:57 -05:00
|
|
|
const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName );
|
|
|
|
if ( pBaseGroupDim )
|
|
|
|
{
|
|
|
|
// any entry's SourceDimName is the original base
|
|
|
|
aBaseDimName = pBaseGroupDim->GetSourceDimName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// find existing group dimension
|
|
|
|
// (using the selected dim, can be intermediate group dim)
|
|
|
|
ScDPSaveGroupDimension* pGroupDimension = pDimData->GetGroupDimAccForBase( aDimName );
|
|
|
|
|
|
|
|
// remove the selected items from their groups
|
|
|
|
// (empty groups are removed, too)
|
|
|
|
if ( pGroupDimension )
|
|
|
|
{
|
|
|
|
ScDPUniqueStringSet::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
|
|
|
|
for (; it != itEnd; ++it)
|
|
|
|
{
|
|
|
|
const rtl::OUString& aEntryName = *it;
|
2004-08-03 11:46:58 +00:00
|
|
|
if ( pBaseGroupDim )
|
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
// for each selected (intermediate) group, remove all its items
|
|
|
|
// (same logic as for adding, below)
|
|
|
|
const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
|
|
|
|
if ( pBaseGroup )
|
|
|
|
pBaseGroup->RemoveElementsFromGroups( *pGroupDimension ); // remove all elements
|
|
|
|
else
|
|
|
|
pGroupDimension->RemoveFromGroups( aEntryName );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2012-03-05 16:23:57 -05:00
|
|
|
else
|
|
|
|
pGroupDimension->RemoveFromGroups( aEntryName );
|
|
|
|
}
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveGroupDimension* pNewGroupDim = NULL;
|
|
|
|
if ( !pGroupDimension )
|
|
|
|
{
|
|
|
|
// create a new group dimension
|
2012-03-05 16:37:38 -05:00
|
|
|
rtl::OUString aGroupDimName =
|
|
|
|
pDimData->CreateGroupDimName(aBaseDimName, *pDPObj, false, NULL);
|
2012-03-05 16:23:57 -05:00
|
|
|
pNewGroupDim = new ScDPSaveGroupDimension( aBaseDimName, aGroupDimName );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
pGroupDimension = pNewGroupDim; // make changes to the new dim if none existed
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if ( pBaseGroupDim )
|
|
|
|
{
|
|
|
|
// If it's a higher-order group dimension, pre-allocate groups for all
|
|
|
|
// non-selected original groups, so the individual base members aren't
|
|
|
|
// used for automatic groups (this would make the original groups hard
|
|
|
|
// to find).
|
|
|
|
//! Also do this when removing groups?
|
|
|
|
//! Handle this case dynamically with automatic groups?
|
|
|
|
|
|
|
|
long nGroupCount = pBaseGroupDim->GetGroupCount();
|
|
|
|
for ( long nGroup = 0; nGroup < nGroupCount; nGroup++ )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetGroupByIndex( nGroup );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if (!aEntries.count(pBaseGroup->GetGroupName()))
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-03-05 16:23:57 -05:00
|
|
|
// add an additional group for each item that is not in the selection
|
|
|
|
ScDPSaveGroupItem aGroup( pBaseGroup->GetGroupName() );
|
|
|
|
aGroup.AddElementsFromGroup( *pBaseGroup );
|
|
|
|
pGroupDimension->AddGroupItem( aGroup );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-05 16:23:57 -05:00
|
|
|
}
|
|
|
|
}
|
2012-03-05 16:37:38 -05:00
|
|
|
rtl::OUString aGroupDimName = pGroupDimension->GetGroupDimName();
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-23 10:36:32 -04:00
|
|
|
rtl::OUString aGroupName = pGroupDimension->CreateGroupName(ScGlobal::GetRscString(STR_PIVOT_GROUP));
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveGroupItem aGroup( aGroupName );
|
|
|
|
ScDPUniqueStringSet::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
|
|
|
|
for (; it != itEnd; ++it)
|
|
|
|
{
|
|
|
|
const rtl::OUString& aEntryName = *it;
|
|
|
|
if ( pBaseGroupDim )
|
|
|
|
{
|
|
|
|
// for each selected (intermediate) group, add all its items
|
|
|
|
const ScDPSaveGroupItem* pBaseGroup = pBaseGroupDim->GetNamedGroup( aEntryName );
|
|
|
|
if ( pBaseGroup )
|
|
|
|
aGroup.AddElementsFromGroup( *pBaseGroup );
|
|
|
|
else
|
|
|
|
aGroup.AddElement( aEntryName ); // no group found -> automatic group, add the item itself
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aGroup.AddElement( aEntryName ); // no group dimension, add all items directly
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
pGroupDimension->AddGroupItem( aGroup );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if ( pNewGroupDim )
|
|
|
|
{
|
|
|
|
pDimData->AddGroupDimension( *pNewGroupDim );
|
|
|
|
delete pNewGroupDim; // AddGroupDimension copies the object
|
|
|
|
// don't access pGroupDimension after here
|
|
|
|
}
|
|
|
|
pGroupDimension = pNewGroupDim = NULL;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// set orientation
|
|
|
|
ScDPSaveDimension* pSaveDimension = aData.GetDimensionByName( aGroupDimName );
|
|
|
|
if ( pSaveDimension->GetOrientation() == sheet::DataPilotFieldOrientation_HIDDEN )
|
|
|
|
{
|
|
|
|
ScDPSaveDimension* pOldDimension = aData.GetDimensionByName( aDimName );
|
|
|
|
pSaveDimension->SetOrientation( pOldDimension->GetOrientation() );
|
|
|
|
long nPosition = 0; //! before (immediate) base
|
|
|
|
aData.SetPosition( pSaveDimension, nPosition );
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
2012-03-05 16:30:43 -05:00
|
|
|
pDPObj->SetSaveData( aData );
|
2012-03-14 00:31:56 -04:00
|
|
|
aFunc.RefreshPivotTableGroups(pDPObj);
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// unmark cell selection
|
|
|
|
Unmark();
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScDBFunc::UngroupDataPilot()
|
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
2012-03-05 16:23:57 -05:00
|
|
|
if (!pDPObj)
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
if (aEntries.empty())
|
|
|
|
return;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
2012-03-14 00:31:56 -04:00
|
|
|
if (!aData.GetExistingDimensionData())
|
|
|
|
// There is nothing to ungroup.
|
|
|
|
return;
|
|
|
|
|
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData();
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:37:38 -05:00
|
|
|
bool bApply = false;
|
2012-02-03 14:23:19 -05:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
ScDPSaveGroupDimension* pGroupDim = pDimData->GetNamedGroupDimAcc( aDimName );
|
|
|
|
const ScDPSaveNumGroupDimension* pNumGroupDim = pDimData->GetNumGroupDim( aDimName );
|
|
|
|
if ( ( pGroupDim && pGroupDim->GetDatePart() != 0 ) ||
|
|
|
|
( pNumGroupDim && pNumGroupDim->GetDatePart() != 0 ) )
|
|
|
|
{
|
|
|
|
// Date grouping: need to remove all affected group dimensions.
|
|
|
|
// This is done using DateGroupDataPilot with nParts=0.
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
DateGroupDataPilot( ScDPNumGroupInfo(), 0 );
|
|
|
|
// bApply remains FALSE
|
|
|
|
// dimension pointers become invalid
|
|
|
|
}
|
|
|
|
else if ( pGroupDim )
|
|
|
|
{
|
|
|
|
ScDPUniqueStringSet::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
|
|
|
|
for (; it != itEnd; ++it)
|
|
|
|
pGroupDim->RemoveGroup(*it);
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-03-05 16:23:57 -05:00
|
|
|
// remove group dimension if empty
|
|
|
|
bool bEmptyDim = pGroupDim->IsEmpty();
|
|
|
|
if ( !bEmptyDim )
|
|
|
|
{
|
|
|
|
// If all remaining groups in the dimension aren't shown, remove
|
|
|
|
// the dimension too, as if it was completely empty.
|
|
|
|
ScDPUniqueStringSet aVisibleEntries;
|
|
|
|
pDPObj->GetMemberResultNames( aVisibleEntries, nSelectDimension );
|
|
|
|
bEmptyDim = pGroupDim->HasOnlyHidden( aVisibleEntries );
|
|
|
|
}
|
|
|
|
if ( bEmptyDim )
|
|
|
|
{
|
|
|
|
pDimData->RemoveGroupDimension( aDimName ); // pGroupDim is deleted
|
|
|
|
|
|
|
|
// also remove SaveData settings for the dimension that no longer exists
|
|
|
|
aData.RemoveDimensionByName( aDimName );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2012-03-05 16:37:38 -05:00
|
|
|
bApply = true;
|
2012-03-05 16:23:57 -05:00
|
|
|
}
|
|
|
|
else if ( pNumGroupDim )
|
|
|
|
{
|
|
|
|
// remove the numerical grouping
|
|
|
|
pDimData->RemoveNumGroupDimension( aDimName );
|
|
|
|
// SaveData settings can remain unchanged - the same dimension still exists
|
2012-03-05 16:37:38 -05:00
|
|
|
bApply = true;
|
2012-03-05 16:23:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bApply )
|
|
|
|
{
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
2012-03-05 16:30:43 -05:00
|
|
|
pDPObj->SetSaveData( aData );
|
2012-03-14 00:31:56 -04:00
|
|
|
aFunc.RefreshPivotTableGroups(pDPObj);
|
2012-03-05 16:23:57 -05:00
|
|
|
|
|
|
|
// unmark cell selection
|
|
|
|
Unmark();
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:56:29 +00:00
|
|
|
static OUString lcl_replaceMemberNameInSubtotal(const OUString& rSubtotal, const OUString& rMemberName)
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
sal_Int32 n = rSubtotal.getLength();
|
|
|
|
const sal_Unicode* p = rSubtotal.getStr();
|
|
|
|
OUStringBuffer aBuf, aWordBuf;
|
|
|
|
for (sal_Int32 i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
sal_Unicode c = p[i];
|
|
|
|
if (c == sal_Unicode(' '))
|
|
|
|
{
|
|
|
|
OUString aWord = aWordBuf.makeStringAndClear();
|
|
|
|
if (aWord.equals(rMemberName))
|
|
|
|
aBuf.append(sal_Unicode('?'));
|
|
|
|
else
|
|
|
|
aBuf.append(aWord);
|
|
|
|
aBuf.append(c);
|
|
|
|
}
|
2009-06-19 02:56:29 +00:00
|
|
|
else if (c == sal_Unicode('\\'))
|
|
|
|
{
|
|
|
|
// Escape a backslash character.
|
|
|
|
aWordBuf.append(c);
|
|
|
|
aWordBuf.append(c);
|
|
|
|
}
|
|
|
|
else if (c == sal_Unicode('?'))
|
|
|
|
{
|
|
|
|
// A literal '?' must be escaped with a backslash ('\');
|
|
|
|
aWordBuf.append(sal_Unicode('\\'));
|
|
|
|
aWordBuf.append(c);
|
|
|
|
}
|
2009-06-19 02:29:09 +00:00
|
|
|
else
|
|
|
|
aWordBuf.append(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aWordBuf.getLength() > 0)
|
|
|
|
{
|
|
|
|
OUString aWord = aWordBuf.makeStringAndClear();
|
|
|
|
if (aWord.equals(rMemberName))
|
|
|
|
aBuf.append(sal_Unicode('?'));
|
|
|
|
else
|
|
|
|
aBuf.append(aWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aBuf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2012-02-17 23:58:02 -05:00
|
|
|
void ScDBFunc::DataPilotInput( const ScAddress& rPos, const rtl::OUString& rString )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
using namespace ::com::sun::star::sheet;
|
|
|
|
|
2004-08-03 11:46:58 +00:00
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( rPos.Col(), rPos.Row(), rPos.Tab() );
|
2009-06-19 02:29:09 +00:00
|
|
|
if (!pDPObj)
|
|
|
|
return;
|
|
|
|
|
2012-02-17 23:58:02 -05:00
|
|
|
rtl::OUString aOldText;
|
2009-06-19 02:29:09 +00:00
|
|
|
pDoc->GetString( rPos.Col(), rPos.Row(), rPos.Tab(), aOldText );
|
|
|
|
|
|
|
|
if ( aOldText == rString )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
// nothing to do: silently exit
|
|
|
|
return;
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nErrorId = 0;
|
2009-06-19 02:29:09 +00:00
|
|
|
|
|
|
|
pDPObj->BuildAllDimensionMembers();
|
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
2012-02-22 15:32:32 -05:00
|
|
|
bool bChange = false;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nOrient = DataPilotFieldOrientation_HIDDEN;
|
2009-06-19 02:29:09 +00:00
|
|
|
long nField = pDPObj->GetHeaderDim( rPos, nOrient );
|
|
|
|
if ( nField >= 0 )
|
|
|
|
{
|
|
|
|
// changing a field title
|
|
|
|
if ( aData.GetExistingDimensionData() )
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
// only group dimensions can be renamed
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData();
|
|
|
|
ScDPSaveGroupDimension* pGroupDim = pDimData->GetNamedGroupDimAcc( aOldText );
|
|
|
|
if ( pGroupDim )
|
|
|
|
{
|
|
|
|
// valid name: not empty, no existing dimension (group or other)
|
2012-02-17 23:58:02 -05:00
|
|
|
if (!rString.isEmpty() && !pDPObj->IsDimNameInUse(rString))
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
2012-02-17 23:59:23 -05:00
|
|
|
pGroupDim->Rename( rString );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
// also rename in SaveData to preserve the field settings
|
|
|
|
ScDPSaveDimension* pSaveDim = aData.GetDimensionByName( aOldText );
|
2012-02-17 23:59:23 -05:00
|
|
|
pSaveDim->SetName( rString );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-02-22 15:32:32 -05:00
|
|
|
bChange = true;
|
2009-06-19 02:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nOrient == DataPilotFieldOrientation_COLUMN || nOrient == DataPilotFieldOrientation_ROW)
|
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bDataLayout = false;
|
|
|
|
OUString aDimName = pDPObj->GetDimName(nField, bDataLayout);
|
2009-06-19 02:29:09 +00:00
|
|
|
ScDPSaveDimension* pDim = bDataLayout ? aData.GetDataLayoutDimension() : aData.GetDimensionByName(aDimName);
|
|
|
|
if (pDim)
|
|
|
|
{
|
2012-02-17 23:58:02 -05:00
|
|
|
if (!rString.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
2012-02-17 23:58:02 -05:00
|
|
|
if (rString.equalsIgnoreAsciiCase(aDimName))
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
pDim->RemoveLayoutName();
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else if (!pDPObj->IsDimNameInUse(rString))
|
|
|
|
{
|
|
|
|
pDim->SetLayoutName(rString);
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pDPObj->IsDataDescriptionCell(rPos))
|
|
|
|
{
|
|
|
|
// There is only one data dimension.
|
|
|
|
ScDPSaveDimension* pDim = aData.GetFirstDimension(sheet::DataPilotFieldOrientation_DATA);
|
|
|
|
if (pDim)
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2012-02-17 23:58:02 -05:00
|
|
|
if (!rString.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
2011-01-31 20:50:54 -05:00
|
|
|
if (pDim->GetName().equalsIgnoreAsciiCase(rString))
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
pDim->RemoveLayoutName();
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else if (!pDPObj->IsDimNameInUse(rString))
|
|
|
|
{
|
|
|
|
pDim->SetLayoutName(rString);
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is not a field header.
|
|
|
|
sheet::DataPilotTableHeaderData aPosData;
|
|
|
|
pDPObj->GetHeaderPositionData(rPos, aPosData);
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-02-17 23:58:02 -05:00
|
|
|
if ((aPosData.Flags & MemberResultFlags::HASMEMBER) && !aOldText.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
if ( aData.GetExistingDimensionData() && !(aPosData.Flags & MemberResultFlags::SUBTOTAL))
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( aPosData.Dimension, bIsDataLayout );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
|
|
|
ScDPDimensionSaveData* pDimData = aData.GetDimensionData();
|
2009-06-19 02:29:09 +00:00
|
|
|
ScDPSaveGroupDimension* pGroupDim = pDimData->GetNamedGroupDimAcc( aDimName );
|
2004-08-03 11:46:58 +00:00
|
|
|
if ( pGroupDim )
|
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
// valid name: not empty, no existing group in this dimension
|
|
|
|
//! ignore case?
|
2012-02-17 23:59:23 -05:00
|
|
|
if (!rString.isEmpty() && !pGroupDim->GetNamedGroup(rString))
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
ScDPSaveGroupItem* pGroup = pGroupDim->GetNamedGroupAcc( aOldText );
|
|
|
|
if ( pGroup )
|
2012-02-17 23:59:23 -05:00
|
|
|
pGroup->Rename( rString ); // rename the existing group
|
2009-06-19 02:29:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// create a new group to replace the automatic group
|
2012-02-17 23:59:23 -05:00
|
|
|
ScDPSaveGroupItem aGroup( rString );
|
2009-06-19 02:29:09 +00:00
|
|
|
aGroup.AddElement( aOldText );
|
|
|
|
pGroupDim->AddGroupItem( aGroup );
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
// in both cases also adjust savedata, to preserve member settings (show details)
|
|
|
|
ScDPSaveDimension* pSaveDim = aData.GetDimensionByName( aDimName );
|
|
|
|
ScDPSaveMember* pSaveMember = pSaveDim->GetExistingMemberByName( aOldText );
|
|
|
|
if ( pSaveMember )
|
2012-02-17 23:59:23 -05:00
|
|
|
pSaveMember->SetName( rString );
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-02-17 23:58:02 -05:00
|
|
|
bChange = true;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
2009-06-19 02:29:09 +00:00
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2009-06-19 02:29:09 +00:00
|
|
|
else if ((aPosData.Flags & MemberResultFlags::GRANDTOTAL))
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
aData.SetGrandTotalName(rString);
|
|
|
|
bChange = true;
|
|
|
|
}
|
2012-01-06 14:22:10 -02:00
|
|
|
else if (aPosData.Dimension >= 0 && !aPosData.MemberName.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bDataLayout = false;
|
|
|
|
OUString aDimName = pDPObj->GetDimName(static_cast<long>(aPosData.Dimension), bDataLayout);
|
2009-06-19 02:29:09 +00:00
|
|
|
if (bDataLayout)
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
// data dimension
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((aPosData.Flags & MemberResultFlags::SUBTOTAL))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ScDPSaveDimension* pDim = aData.GetDimensionByName(aPosData.MemberName);
|
|
|
|
if (!pDim)
|
|
|
|
break;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2012-02-17 23:58:02 -05:00
|
|
|
if (rString.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPosData.MemberName.equalsIgnoreAsciiCase(rString))
|
|
|
|
{
|
|
|
|
pDim->RemoveLayoutName();
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else if (!pDPObj->IsDimNameInUse(rString))
|
|
|
|
{
|
|
|
|
pDim->SetLayoutName(rString);
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
while (false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// field member
|
|
|
|
do
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
ScDPSaveDimension* pDim = aData.GetDimensionByName(aDimName);
|
|
|
|
if (!pDim)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ScDPSaveMember* pMem = pDim->GetExistingMemberByName(aPosData.MemberName);
|
|
|
|
if (!pMem)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((aPosData.Flags & MemberResultFlags::SUBTOTAL))
|
2004-08-03 11:46:58 +00:00
|
|
|
{
|
2009-06-19 02:29:09 +00:00
|
|
|
// Change subtotal only when the table has one data dimension.
|
|
|
|
if (aData.GetDataDimensionCount() > 1)
|
|
|
|
break;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-09-01 00:42:43 +00:00
|
|
|
// display name for subtotal is allowed only if the subtotal type is 'Automatic'.
|
|
|
|
if (pDim->GetSubTotalsCount() != 1)
|
|
|
|
break;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-09-01 00:42:43 +00:00
|
|
|
if (pDim->GetSubTotalFunc(0) != sheet::GeneralFunction_AUTO)
|
|
|
|
break;
|
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
const OUString* pLayoutName = pMem->GetLayoutName();
|
|
|
|
String aMemberName;
|
|
|
|
if (pLayoutName)
|
|
|
|
aMemberName = *pLayoutName;
|
2004-08-03 11:46:58 +00:00
|
|
|
else
|
2009-06-19 02:29:09 +00:00
|
|
|
aMemberName = aPosData.MemberName;
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
String aNew = lcl_replaceMemberNameInSubtotal(rString, aMemberName);
|
|
|
|
pDim->SetSubtotalName(aNew);
|
|
|
|
bChange = true;
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
else
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
// Check to make sure the member name isn't
|
|
|
|
// already used.
|
2012-02-17 23:58:02 -05:00
|
|
|
if (!rString.isEmpty())
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
2012-02-17 23:58:02 -05:00
|
|
|
if (rString.equalsIgnoreAsciiCase(pMem->GetName()))
|
2009-06-19 02:29:09 +00:00
|
|
|
{
|
|
|
|
pMem->RemoveLayoutName();
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else if (!pDim->IsMemberNameInUse(rString))
|
|
|
|
{
|
|
|
|
pMem->SetLayoutName(rString);
|
|
|
|
bChange = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nErrorId = STR_INVALIDNAME;
|
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
2009-06-19 02:29:09 +00:00
|
|
|
while (false);
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-19 02:29:09 +00:00
|
|
|
}
|
2004-08-03 11:46:58 +00:00
|
|
|
|
2009-06-19 02:29:09 +00:00
|
|
|
if ( bChange )
|
|
|
|
{
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
2012-02-22 15:32:32 -05:00
|
|
|
pDPObj->SetSaveData( aData );
|
|
|
|
aFunc.DataPilotUpdate( pDPObj, pDPObj, true, false );
|
2009-06-19 02:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !nErrorId )
|
|
|
|
nErrorId = STR_ERR_DATAPILOT_INPUT;
|
|
|
|
ErrorMessage( nErrorId );
|
2004-08-03 11:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 16:43:01 +00:00
|
|
|
void lcl_MoveToEnd( ScDPSaveDimension& rDim, const String& rItemName )
|
|
|
|
{
|
|
|
|
ScDPSaveMember* pNewMember = NULL;
|
|
|
|
const ScDPSaveMember* pOldMember = rDim.GetExistingMemberByName( rItemName );
|
|
|
|
if ( pOldMember )
|
|
|
|
pNewMember = new ScDPSaveMember( *pOldMember );
|
|
|
|
else
|
|
|
|
pNewMember = new ScDPSaveMember( rItemName );
|
|
|
|
rDim.AddMember( pNewMember );
|
|
|
|
// AddMember takes ownership of the new pointer,
|
|
|
|
// puts it to the end of the list even if it was in the list before.
|
|
|
|
}
|
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
struct ScOUStringCollate
|
|
|
|
{
|
|
|
|
CollatorWrapper* mpCollator;
|
|
|
|
|
|
|
|
ScOUStringCollate(CollatorWrapper* pColl) : mpCollator(pColl) {}
|
|
|
|
|
|
|
|
bool operator()(const rtl::OUString& rStr1, const rtl::OUString& rStr2) const
|
|
|
|
{
|
|
|
|
return ( mpCollator->compareString(rStr1, rStr2) < 0 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-19 19:51:20 +00:00
|
|
|
bool ScDBFunc::DataPilotSort( const ScAddress& rPos, bool bAscending, sal_uInt16* pUserListId )
|
|
|
|
{
|
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor(rPos.Col(), rPos.Row(), rPos.Tab());
|
|
|
|
if (!pDPObj)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We need to run this to get all members later.
|
2010-04-21 15:30:43 +02:00
|
|
|
if ( pUserListId )
|
|
|
|
pDPObj->BuildAllDimensionMembers();
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nOrientation;
|
2009-06-19 19:51:20 +00:00
|
|
|
long nDimIndex = pDPObj->GetHeaderDim(rPos, nOrientation);
|
|
|
|
if (nDimIndex < 0)
|
|
|
|
// Invalid dimension index. Bail out.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ScDPSaveData* pSaveData = pDPObj->GetSaveData();
|
|
|
|
if (!pSaveData)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ScDPSaveData aNewSaveData(*pSaveData);
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName(nDimIndex, bDataLayout);
|
2009-06-19 19:51:20 +00:00
|
|
|
ScDPSaveDimension* pSaveDim = aNewSaveData.GetDimensionByName(aDimName);
|
|
|
|
if (!pSaveDim)
|
|
|
|
return false;
|
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
// manual evaluation of sort order is only needed if a user list id is given
|
|
|
|
if ( pUserListId )
|
2009-06-19 19:51:20 +00:00
|
|
|
{
|
2010-04-21 15:30:43 +02:00
|
|
|
typedef ScDPSaveDimension::MemberList MemList;
|
|
|
|
const MemList& rDimMembers = pSaveDim->GetMembers();
|
|
|
|
list<OUString> aMembers;
|
2011-02-06 00:56:21 +01:00
|
|
|
boost::unordered_set<OUString, ::rtl::OUStringHash> aMemberSet;
|
2010-04-21 15:30:43 +02:00
|
|
|
size_t nMemberCount = 0;
|
|
|
|
for (MemList::const_iterator itr = rDimMembers.begin(), itrEnd = rDimMembers.end();
|
|
|
|
itr != itrEnd; ++itr)
|
|
|
|
{
|
|
|
|
ScDPSaveMember* pMem = *itr;
|
|
|
|
aMembers.push_back(pMem->GetName());
|
|
|
|
aMemberSet.insert(pMem->GetName());
|
|
|
|
++nMemberCount;
|
|
|
|
}
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
// Sort the member list in ascending order.
|
|
|
|
ScOUStringCollate aCollate( ScGlobal::GetCollator() );
|
|
|
|
aMembers.sort(aCollate);
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
// Collect and rank those custom sort strings that also exist in the member name list.
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2011-02-06 00:56:21 +01:00
|
|
|
typedef boost::unordered_map<OUString, sal_uInt16, OUStringHash> UserSortMap;
|
2010-04-21 15:30:43 +02:00
|
|
|
UserSortMap aSubStrs;
|
|
|
|
sal_uInt16 nSubCount = 0;
|
|
|
|
if (pUserListId)
|
2009-06-19 19:51:20 +00:00
|
|
|
{
|
2010-04-21 15:30:43 +02:00
|
|
|
ScUserList* pUserList = ScGlobal::GetUserList();
|
|
|
|
if (!pUserList)
|
2009-06-19 19:51:20 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
{
|
2011-06-01 19:14:40 -04:00
|
|
|
size_t n = pUserList->size();
|
|
|
|
if (!n || *pUserListId >= static_cast<sal_uInt16>(n))
|
2010-04-21 15:30:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-01 19:14:40 -04:00
|
|
|
const ScUserListData* pData = (*pUserList)[*pUserListId];
|
2010-04-21 15:30:43 +02:00
|
|
|
if (pData)
|
|
|
|
{
|
|
|
|
sal_uInt16 n = pData->GetSubCount();
|
|
|
|
for (sal_uInt16 i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
OUString aSub = pData->GetSubStr(i);
|
|
|
|
if (!aMemberSet.count(aSub))
|
|
|
|
// This string doesn't exist in the member name set. Don't add this.
|
|
|
|
continue;
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
aSubStrs.insert(UserSortMap::value_type(aSub, nSubCount++));
|
|
|
|
}
|
2009-06-19 19:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
// Rank all members.
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
vector<OUString> aRankedNames(nMemberCount);
|
|
|
|
sal_uInt16 nCurStrId = 0;
|
|
|
|
for (list<OUString>::const_iterator itr = aMembers.begin(), itrEnd = aMembers.end();
|
|
|
|
itr != itrEnd; ++itr)
|
|
|
|
{
|
|
|
|
OUString aName = *itr;
|
|
|
|
sal_uInt16 nRank = 0;
|
|
|
|
UserSortMap::const_iterator itrSub = aSubStrs.find(aName);
|
|
|
|
if (itrSub == aSubStrs.end())
|
|
|
|
nRank = nSubCount + nCurStrId++;
|
|
|
|
else
|
|
|
|
nRank = itrSub->second;
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
if (!bAscending)
|
|
|
|
nRank = static_cast< sal_uInt16 >( nMemberCount - nRank - 1 );
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
aRankedNames[nRank] = aName;
|
|
|
|
}
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
// Re-order ScDPSaveMember instances with the new ranks.
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
for (vector<OUString>::const_iterator itr = aRankedNames.begin(), itrEnd = aRankedNames.end();
|
|
|
|
itr != itrEnd; ++itr)
|
|
|
|
{
|
|
|
|
const ScDPSaveMember* pOldMem = pSaveDim->GetExistingMemberByName(*itr);
|
|
|
|
if (!pOldMem)
|
|
|
|
// All members are supposed to be present.
|
|
|
|
continue;
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
ScDPSaveMember* pNewMem = new ScDPSaveMember(*pOldMem);
|
|
|
|
pSaveDim->AddMember(pNewMem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the sorting mode to manual for now. We may introduce a new sorting
|
|
|
|
// mode later on.
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
sheet::DataPilotFieldSortInfo aSortInfo;
|
|
|
|
aSortInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
|
|
|
|
pSaveDim->SetSortInfo(&aSortInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// without user list id, just apply sorting mode
|
2009-06-19 19:51:20 +00:00
|
|
|
|
2010-04-21 15:30:43 +02:00
|
|
|
sheet::DataPilotFieldSortInfo aSortInfo;
|
|
|
|
aSortInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
|
|
|
|
aSortInfo.IsAscending = bAscending;
|
|
|
|
pSaveDim->SetSortInfo(&aSortInfo);
|
|
|
|
}
|
2009-06-19 19:51:20 +00:00
|
|
|
|
|
|
|
// Update the datapilot with the newly sorted field members.
|
|
|
|
|
|
|
|
auto_ptr<ScDPObject> pNewObj(new ScDPObject(*pDPObj));
|
|
|
|
pNewObj->SetSaveData(aNewSaveData);
|
|
|
|
ScDBDocFunc aFunc(*GetViewData()->GetDocShell());
|
|
|
|
|
|
|
|
return aFunc.DataPilotUpdate(pDPObj, pNewObj.get(), true, false);
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool ScDBFunc::DataPilotMove( const ScRange& rSource, const ScAddress& rDest )
|
2007-11-20 16:43:01 +00:00
|
|
|
{
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bRet = false;
|
2007-11-20 16:43:01 +00:00
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
ScDPObject* pDPObj = pDoc->GetDPAtCursor( rSource.aStart.Col(), rSource.aStart.Row(), rSource.aStart.Tab() );
|
|
|
|
if ( pDPObj && pDPObj == pDoc->GetDPAtCursor( rDest.Col(), rDest.Row(), rDest.Tab() ) )
|
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
sheet::DataPilotTableHeaderData aDestData;
|
|
|
|
pDPObj->GetHeaderPositionData( rDest, aDestData );
|
|
|
|
bool bValid = ( aDestData.Dimension >= 0 ); // dropping onto a field
|
2007-11-20 16:43:01 +00:00
|
|
|
|
|
|
|
// look through the source range
|
2011-02-06 00:56:21 +01:00
|
|
|
boost::unordered_set< rtl::OUString, rtl::OUStringHash, std::equal_to<rtl::OUString> > aMembersSet; // for lookup
|
2008-05-20 12:12:40 +00:00
|
|
|
std::vector< rtl::OUString > aMembersVector; // members in original order, for inserting
|
2007-11-20 16:43:01 +00:00
|
|
|
aMembersVector.reserve( std::max( static_cast<SCSIZE>( rSource.aEnd.Col() - rSource.aStart.Col() + 1 ),
|
|
|
|
static_cast<SCSIZE>( rSource.aEnd.Row() - rSource.aStart.Row() + 1 ) ) );
|
|
|
|
for (SCROW nRow = rSource.aStart.Row(); bValid && nRow <= rSource.aEnd.Row(); ++nRow )
|
|
|
|
for (SCCOL nCol = rSource.aStart.Col(); bValid && nCol <= rSource.aEnd.Col(); ++nCol )
|
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
sheet::DataPilotTableHeaderData aSourceData;
|
|
|
|
pDPObj->GetHeaderPositionData( ScAddress( nCol, nRow, rSource.aStart.Tab() ), aSourceData );
|
2012-01-06 14:22:10 -02:00
|
|
|
if ( aSourceData.Dimension == aDestData.Dimension && !aSourceData.MemberName.isEmpty() )
|
2007-11-20 16:43:01 +00:00
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
if ( aMembersSet.find( aSourceData.MemberName ) == aMembersSet.end() )
|
2007-11-20 16:43:01 +00:00
|
|
|
{
|
2008-05-20 12:12:40 +00:00
|
|
|
aMembersSet.insert( aSourceData.MemberName );
|
|
|
|
aMembersVector.push_back( aSourceData.MemberName );
|
2007-11-20 16:43:01 +00:00
|
|
|
}
|
|
|
|
// duplicates are ignored
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bValid = false; // empty (subtotal) or different field
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bValid )
|
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( aDestData.Dimension, bIsDataLayout );
|
2007-11-20 16:43:01 +00:00
|
|
|
if ( !bIsDataLayout )
|
|
|
|
{
|
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
|
|
|
ScDPSaveDimension* pDim = aData.GetDimensionByName( aDimName );
|
|
|
|
|
|
|
|
// get all member names in source order
|
|
|
|
uno::Sequence<rtl::OUString> aMemberNames;
|
2009-09-02 03:53:11 +00:00
|
|
|
pDPObj->GetMemberNames( aDestData.Dimension, aMemberNames );
|
2007-11-20 16:43:01 +00:00
|
|
|
|
|
|
|
bool bInserted = false;
|
|
|
|
|
|
|
|
sal_Int32 nMemberCount = aMemberNames.getLength();
|
|
|
|
for (sal_Int32 nMemberPos=0; nMemberPos<nMemberCount; ++nMemberPos)
|
|
|
|
{
|
|
|
|
String aMemberStr( aMemberNames[nMemberPos] );
|
|
|
|
|
2008-05-20 12:12:40 +00:00
|
|
|
if ( !bInserted && aMemberNames[nMemberPos] == aDestData.MemberName )
|
2007-11-20 16:43:01 +00:00
|
|
|
{
|
|
|
|
// insert dragged items before this item
|
2008-05-20 12:12:40 +00:00
|
|
|
for ( std::vector<rtl::OUString>::const_iterator aIter = aMembersVector.begin();
|
2007-11-20 16:43:01 +00:00
|
|
|
aIter != aMembersVector.end(); ++aIter )
|
|
|
|
lcl_MoveToEnd( *pDim, *aIter );
|
|
|
|
bInserted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( aMembersSet.find( aMemberStr ) == aMembersSet.end() ) // skip dragged items
|
|
|
|
lcl_MoveToEnd( *pDim, aMemberStr );
|
|
|
|
}
|
|
|
|
// insert dragged item at end if dest wasn't found (for example, empty)
|
|
|
|
if ( !bInserted )
|
2008-05-20 12:12:40 +00:00
|
|
|
for ( std::vector<rtl::OUString>::const_iterator aIter = aMembersVector.begin();
|
2007-11-20 16:43:01 +00:00
|
|
|
aIter != aMembersVector.end(); ++aIter )
|
|
|
|
lcl_MoveToEnd( *pDim, *aIter );
|
|
|
|
|
|
|
|
// Items that were in SaveData, but not in the source, end up at the start of the list.
|
|
|
|
|
|
|
|
// set flag for manual sorting
|
|
|
|
sheet::DataPilotFieldSortInfo aSortInfo;
|
|
|
|
aSortInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
|
|
|
|
pDim->SetSortInfo( &aSortInfo );
|
|
|
|
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
|
|
|
ScDPObject* pNewObj = new ScDPObject( *pDPObj );
|
|
|
|
pNewObj->SetSaveData( aData );
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.DataPilotUpdate( pDPObj, pNewObj, sal_True, false ); //! bApi for drag&drop?
|
2007-11-20 16:43:01 +00:00
|
|
|
delete pNewObj;
|
|
|
|
|
|
|
|
Unmark(); // entry was moved - no use in leaving the old cell selected
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
bRet = sal_True;
|
2007-11-20 16:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
bool ScDBFunc::HasSelectionForDrillDown( sal_uInt16& rOrientation )
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
bool bRet = false;
|
2004-07-23 12:01:21 +00:00
|
|
|
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
|
|
|
if ( pDPObj )
|
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
2004-07-23 12:01:21 +00:00
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
if (!aEntries.empty())
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-07-23 12:01:21 +00:00
|
|
|
if ( !bIsDataLayout )
|
|
|
|
{
|
|
|
|
ScDPSaveData* pSaveData = pDPObj->GetSaveData();
|
|
|
|
ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName( aDimName );
|
|
|
|
if ( pDim )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nDimOrient = pDim->GetOrientation();
|
2004-07-23 12:01:21 +00:00
|
|
|
ScDPSaveDimension* pInner = pSaveData->GetInnermostDimension( nDimOrient );
|
|
|
|
if ( pDim == pInner )
|
|
|
|
{
|
|
|
|
rOrientation = nDimOrient;
|
2012-02-03 14:23:19 -05:00
|
|
|
bRet = true;
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
void ScDBFunc::SetDataPilotDetails(bool bShow, const rtl::OUString* pNewDimensionName)
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
|
|
|
ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
|
|
|
|
GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
|
|
|
|
if ( pDPObj )
|
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet aEntries;
|
2004-07-23 12:01:21 +00:00
|
|
|
long nSelectDimension = -1;
|
|
|
|
GetSelectedMemberList( aEntries, nSelectDimension );
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
if (!aEntries.empty())
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2011-05-28 16:52:40 -04:00
|
|
|
bool bIsDataLayout;
|
|
|
|
OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout );
|
2004-07-23 12:01:21 +00:00
|
|
|
if ( !bIsDataLayout )
|
|
|
|
{
|
|
|
|
ScDPSaveData aData( *pDPObj->GetSaveData() );
|
|
|
|
ScDPSaveDimension* pDim = aData.GetDimensionByName( aDimName );
|
|
|
|
|
|
|
|
if ( bShow && pNewDimensionName )
|
|
|
|
{
|
|
|
|
// add the new dimension with the same orientation, at the end
|
|
|
|
|
|
|
|
ScDPSaveDimension* pNewDim = aData.GetDimensionByName( *pNewDimensionName );
|
|
|
|
ScDPSaveDimension* pDuplicated = NULL;
|
|
|
|
if ( pNewDim->GetOrientation() == sheet::DataPilotFieldOrientation_DATA )
|
|
|
|
{
|
|
|
|
// Need to duplicate the dimension, create column/row in addition to data:
|
|
|
|
// The duplicated dimension inherits the existing settings, pNewDim is modified below.
|
|
|
|
pDuplicated = aData.DuplicateDimension( *pNewDimensionName );
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nOrientation = pDim->GetOrientation();
|
2004-07-23 12:01:21 +00:00
|
|
|
pNewDim->SetOrientation( nOrientation );
|
|
|
|
|
|
|
|
long nPosition = LONG_MAX;
|
|
|
|
aData.SetPosition( pNewDim, nPosition );
|
|
|
|
|
|
|
|
ScDPSaveDimension* pDataLayout = aData.GetDataLayoutDimension();
|
|
|
|
if ( pDataLayout->GetOrientation() == nOrientation &&
|
|
|
|
aData.GetDataDimensionCount() <= 1 )
|
|
|
|
{
|
|
|
|
// If there is only one data dimension, the data layout dimension
|
|
|
|
// must still be the last one in its orientation.
|
|
|
|
aData.SetPosition( pDataLayout, nPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pDuplicated )
|
|
|
|
{
|
|
|
|
// The duplicated (data) dimension needs to be behind the original dimension
|
|
|
|
aData.SetPosition( pDuplicated, nPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide details for all visible members (selected are changed below).
|
|
|
|
//! Use all members from source level instead (including non-visible)?
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet aVisibleEntries;
|
2004-07-23 12:01:21 +00:00
|
|
|
pDPObj->GetMemberResultNames( aVisibleEntries, nSelectDimension );
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet::const_iterator it = aVisibleEntries.begin(), itEnd = aVisibleEntries.end();
|
|
|
|
for (; it != itEnd; ++it)
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
const rtl::OUString& aVisName = *it;
|
2004-07-23 12:01:21 +00:00
|
|
|
ScDPSaveMember* pMember = pDim->GetMemberByName( aVisName );
|
2011-03-10 16:55:21 -05:00
|
|
|
pMember->SetShowDetails( false );
|
2004-07-23 12:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPUniqueStringSet::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
|
|
|
|
for (; it != itEnd; ++it)
|
2004-07-23 12:01:21 +00:00
|
|
|
{
|
2012-02-03 14:23:19 -05:00
|
|
|
ScDPSaveMember* pMember = pDim->GetMemberByName(*it);
|
2004-07-23 12:01:21 +00:00
|
|
|
pMember->SetShowDetails( bShow );
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply changes
|
|
|
|
ScDBDocFunc aFunc( *GetViewData()->GetDocShell() );
|
|
|
|
ScDPObject* pNewObj = new ScDPObject( *pDPObj );
|
|
|
|
pNewObj->SetSaveData( aData );
|
2011-03-10 16:55:21 -05:00
|
|
|
aFunc.DataPilotUpdate( pDPObj, pNewObj, sal_True, false );
|
2004-07-23 12:01:21 +00:00
|
|
|
delete pNewObj;
|
|
|
|
|
|
|
|
// unmark cell selection
|
|
|
|
Unmark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-20 12:12:40 +00:00
|
|
|
void ScDBFunc::ShowDataPilotSourceData( ScDPObject& rDPObj, const Sequence<sheet::DataPilotFieldFilter>& rFilters )
|
2007-11-26 14:21:00 +00:00
|
|
|
{
|
2008-11-27 15:23:33 +00:00
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
if (pDoc->GetDocumentShell()->IsReadOnly())
|
|
|
|
{
|
|
|
|
ErrorMessage(STR_READONLYERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-20 12:12:40 +00:00
|
|
|
Reference<sheet::XDimensionsSupplier> xDimSupplier = rDPObj.GetSource();
|
|
|
|
Reference<container::XNameAccess> xDims = xDimSupplier->getDimensions();
|
|
|
|
Reference<sheet::XDrillDownDataSupplier> xDDSupplier(xDimSupplier, UNO_QUERY);
|
|
|
|
if (!xDDSupplier.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Sequence< Sequence<Any> > aTabData = xDDSupplier->getDrillDownData(rFilters);
|
|
|
|
sal_Int32 nRowSize = aTabData.getLength();
|
|
|
|
if (nRowSize <= 1)
|
|
|
|
// There is no data to show. Bail out.
|
|
|
|
return;
|
|
|
|
|
|
|
|
sal_Int32 nColSize = aTabData[0].getLength();
|
|
|
|
|
|
|
|
SCTAB nNewTab = GetViewData()->GetTabNo();
|
|
|
|
|
|
|
|
auto_ptr<ScDocument> pInsDoc(new ScDocument(SCDOCMODE_CLIP));
|
|
|
|
pInsDoc->ResetClip( pDoc, nNewTab );
|
2008-05-23 07:37:43 +00:00
|
|
|
for (SCROW nRow = 0; nRow < nRowSize; ++nRow)
|
2007-11-26 14:21:00 +00:00
|
|
|
{
|
2008-05-23 07:37:43 +00:00
|
|
|
for (SCCOL nCol = 0; nCol < nColSize; ++nCol)
|
2008-05-20 12:12:40 +00:00
|
|
|
{
|
|
|
|
const Any& rAny = aTabData[nRow][nCol];
|
|
|
|
rtl::OUString aStr;
|
|
|
|
double fVal;
|
|
|
|
if (rAny >>= aStr)
|
|
|
|
pInsDoc->PutCell( ScAddress(nCol, nRow, nNewTab), new ScStringCell(String(aStr)) );
|
|
|
|
else if (rAny >>= fVal)
|
|
|
|
pInsDoc->SetValue(nCol, nRow, nNewTab, fVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set number format (important for dates)
|
2008-05-23 07:37:43 +00:00
|
|
|
for (SCCOL nCol = 0; nCol < nColSize; ++nCol)
|
2008-05-20 12:12:40 +00:00
|
|
|
{
|
|
|
|
rtl::OUString aStr;
|
|
|
|
if (!(aTabData[0][nCol] >>= aStr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Reference<XPropertySet> xPropSet(xDims->getByName(aStr), UNO_QUERY);
|
|
|
|
if (!xPropSet.is())
|
|
|
|
continue;
|
|
|
|
|
2012-02-09 12:58:07 -05:00
|
|
|
Any any = xPropSet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_NUMBERFO)) );
|
2008-05-20 12:12:40 +00:00
|
|
|
sal_Int32 nNumFmt = 0;
|
|
|
|
if (!(any >>= nNumFmt))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ScPatternAttr aPattern( pInsDoc->GetPool() );
|
2011-01-17 13:20:22 +01:00
|
|
|
aPattern.GetItemSet().Put( SfxUInt32Item(ATTR_VALUE_FORMAT, static_cast<sal_uInt32>(nNumFmt)) );
|
2008-05-20 12:12:40 +00:00
|
|
|
pInsDoc->ApplyPatternAreaTab(nCol, 1, nCol, nRowSize-1, nNewTab, aPattern);
|
2007-11-26 14:21:00 +00:00
|
|
|
}
|
2008-05-20 12:12:40 +00:00
|
|
|
|
|
|
|
SCCOL nEndCol = 0;
|
|
|
|
SCROW nEndRow = 0;
|
|
|
|
pInsDoc->GetCellArea( nNewTab, nEndCol, nEndRow );
|
|
|
|
pInsDoc->SetClipArea( ScRange( 0, 0, nNewTab, nEndCol, nEndRow, nNewTab ) );
|
|
|
|
|
2010-10-20 14:54:59 +02:00
|
|
|
::svl::IUndoManager* pMgr = GetViewData()->GetDocShell()->GetUndoManager();
|
2008-05-20 12:12:40 +00:00
|
|
|
String aUndo = ScGlobal::GetRscString( STR_UNDO_DOOUTLINE );
|
|
|
|
pMgr->EnterListAction( aUndo, aUndo );
|
|
|
|
|
2011-11-06 18:11:43 +01:00
|
|
|
rtl::OUString aNewTabName;
|
2008-05-20 12:12:40 +00:00
|
|
|
pDoc->CreateValidTabName(aNewTabName);
|
|
|
|
if ( InsertTable(aNewTabName, nNewTab) )
|
|
|
|
PasteFromClip( IDF_ALL, pInsDoc.get() );
|
|
|
|
|
|
|
|
pMgr->LeaveListAction();
|
2007-11-26 14:21:00 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
//
|
|
|
|
// DB-Operationen (Sortieren, Filtern, Teilergebnisse) wiederholen
|
|
|
|
//
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
void ScDBFunc::RepeatDB( sal_Bool bRecord )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOL nCurX = GetViewData()->GetCurX();
|
|
|
|
SCROW nCurY = GetViewData()->GetCurY();
|
|
|
|
SCTAB nTab = GetViewData()->GetTabNo();
|
2000-09-18 16:07:07 +00:00
|
|
|
ScDocument* pDoc = GetViewData()->GetDocument();
|
|
|
|
ScDBData* pDBData = GetDBData();
|
2001-02-14 14:34:08 +00:00
|
|
|
if (bRecord && !pDoc->IsUndoEnabled())
|
2011-03-10 16:55:21 -05:00
|
|
|
bRecord = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScQueryParam aQueryParam;
|
|
|
|
pDBData->GetQueryParam( aQueryParam );
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bQuery = aQueryParam.GetEntry(0).bDoQuery;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScSortParam aSortParam;
|
|
|
|
pDBData->GetSortParam( aSortParam );
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bSort = aSortParam.bDoSort[0];
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScSubTotalParam aSubTotalParam;
|
|
|
|
pDBData->GetSubTotalParam( aSubTotalParam );
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_Bool bSubTotal = aSubTotalParam.bGroupActive[0] && !aSubTotalParam.bRemoveOnly;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if ( bQuery || bSort || bSubTotal )
|
|
|
|
{
|
2011-03-10 16:55:21 -05:00
|
|
|
sal_Bool bQuerySize = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
ScRange aOldQuery;
|
|
|
|
ScRange aNewQuery;
|
|
|
|
if (bQuery && !aQueryParam.bInplace)
|
|
|
|
{
|
|
|
|
ScDBData* pDest = pDoc->GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
|
2011-01-17 13:20:22 +01:00
|
|
|
aQueryParam.nDestTab, sal_True );
|
2000-09-18 16:07:07 +00:00
|
|
|
if (pDest && pDest->IsDoSize())
|
|
|
|
{
|
|
|
|
pDest->GetArea( aOldQuery );
|
2011-01-17 13:20:22 +01:00
|
|
|
bQuerySize = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nDummy;
|
|
|
|
SCCOL nStartCol;
|
|
|
|
SCROW nStartRow;
|
|
|
|
SCCOL nEndCol;
|
|
|
|
SCROW nEndRow;
|
2000-09-18 16:07:07 +00:00
|
|
|
pDBData->GetArea( nDummy, nStartCol, nStartRow, nEndCol, nEndRow );
|
|
|
|
|
|
|
|
//! Undo nur benoetigte Daten ?
|
|
|
|
|
|
|
|
ScDocument* pUndoDoc = NULL;
|
|
|
|
ScOutlineTable* pUndoTab = NULL;
|
|
|
|
ScRangeName* pUndoRange = NULL;
|
|
|
|
ScDBCollection* pUndoDB = NULL;
|
|
|
|
|
|
|
|
if (bRecord)
|
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nTabCount = pDoc->GetTableCount();
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
|
|
|
|
ScOutlineTable* pTable = pDoc->GetOutlineTable( nTab );
|
|
|
|
if (pTable)
|
|
|
|
{
|
|
|
|
pUndoTab = new ScOutlineTable( *pTable );
|
|
|
|
|
2004-06-04 10:59:26 +00:00
|
|
|
SCCOLROW nOutStartCol; // Zeilen/Spaltenstatus
|
|
|
|
SCCOLROW nOutStartRow;
|
|
|
|
SCCOLROW nOutEndCol;
|
|
|
|
SCCOLROW nOutEndRow;
|
2000-09-18 16:07:07 +00:00
|
|
|
pTable->GetColArray()->GetRange( nOutStartCol, nOutEndCol );
|
|
|
|
pTable->GetRowArray()->GetRange( nOutStartRow, nOutEndRow );
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
pUndoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
|
2011-03-10 16:55:21 -05:00
|
|
|
pDoc->CopyToDocument( static_cast<SCCOL>(nOutStartCol), 0, nTab, static_cast<SCCOL>(nOutEndCol), MAXROW, nTab, IDF_NONE, false, pUndoDoc );
|
|
|
|
pDoc->CopyToDocument( 0, nOutStartRow, nTab, MAXCOL, nOutEndRow, nTab, IDF_NONE, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2011-03-10 16:55:21 -05:00
|
|
|
pUndoDoc->InitUndo( pDoc, nTab, nTab, false, sal_True );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Datenbereich sichern - incl. Filter-Ergebnis
|
2011-03-10 16:55:21 -05:00
|
|
|
pDoc->CopyToDocument( 0,nStartRow,nTab, MAXCOL,nEndRow,nTab, IDF_ALL, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// alle Formeln wegen Referenzen
|
2011-03-10 16:55:21 -05:00
|
|
|
pDoc->CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1, IDF_FORMULA, false, pUndoDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// DB- und andere Bereiche
|
|
|
|
ScRangeName* pDocRange = pDoc->GetRangeName();
|
2011-03-04 19:25:02 -05:00
|
|
|
if (!pDocRange->empty())
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoRange = new ScRangeName( *pDocRange );
|
|
|
|
ScDBCollection* pDocDB = pDoc->GetDBCollection();
|
2011-05-12 16:26:26 -04:00
|
|
|
if (!pDocDB->empty())
|
2000-09-18 16:07:07 +00:00
|
|
|
pUndoDB = new ScDBCollection( *pDocDB );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bSort && bSubTotal)
|
|
|
|
{
|
|
|
|
// Sortieren ohne SubTotals
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
aSubTotalParam.bRemoveOnly = sal_True; // wird unten wieder zurueckgesetzt
|
2011-03-10 16:55:21 -05:00
|
|
|
DoSubTotals( aSubTotalParam, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bSort)
|
|
|
|
{
|
|
|
|
pDBData->GetSortParam( aSortParam ); // Bereich kann sich geaendert haben
|
2011-03-10 16:55:21 -05:00
|
|
|
Sort( aSortParam, false, false);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
if (bQuery)
|
|
|
|
{
|
|
|
|
pDBData->GetQueryParam( aQueryParam ); // Bereich kann sich geaendert haben
|
|
|
|
ScRange aAdvSource;
|
|
|
|
if (pDBData->GetAdvancedQuerySource(aAdvSource))
|
2009-06-15 10:46:14 +00:00
|
|
|
{
|
|
|
|
pDoc->CreateQueryParam(
|
|
|
|
aAdvSource.aStart.Col(), aAdvSource.aStart.Row(),
|
|
|
|
aAdvSource.aEnd.Col(), aAdvSource.aEnd.Row(),
|
|
|
|
aAdvSource.aStart.Tab(), aQueryParam );
|
2011-03-10 16:55:21 -05:00
|
|
|
Query( aQueryParam, &aAdvSource, false );
|
2009-06-15 10:46:14 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2011-03-10 16:55:21 -05:00
|
|
|
Query( aQueryParam, NULL, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// bei nicht-inplace kann die Tabelle umgestellt worden sein
|
|
|
|
if ( !aQueryParam.bInplace && aQueryParam.nDestTab != nTab )
|
|
|
|
SetTabNo( nTab );
|
|
|
|
}
|
|
|
|
if (bSubTotal)
|
|
|
|
{
|
|
|
|
pDBData->GetSubTotalParam( aSubTotalParam ); // Bereich kann sich geaendert haben
|
2011-03-10 16:55:21 -05:00
|
|
|
aSubTotalParam.bRemoveOnly = false;
|
|
|
|
DoSubTotals( aSubTotalParam, false );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bRecord)
|
|
|
|
{
|
2004-06-04 10:59:26 +00:00
|
|
|
SCTAB nDummyTab;
|
|
|
|
SCCOL nDummyCol;
|
|
|
|
SCROW nDummyRow, nNewEndRow;
|
|
|
|
pDBData->GetArea( nDummyTab, nDummyCol,nDummyRow, nDummyCol,nNewEndRow );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
const ScRange* pOld = NULL;
|
|
|
|
const ScRange* pNew = NULL;
|
|
|
|
if (bQuerySize)
|
|
|
|
{
|
|
|
|
ScDBData* pDest = pDoc->GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
|
2011-01-17 13:20:22 +01:00
|
|
|
aQueryParam.nDestTab, sal_True );
|
2000-09-18 16:07:07 +00:00
|
|
|
if (pDest)
|
|
|
|
{
|
|
|
|
pDest->GetArea( aNewQuery );
|
|
|
|
pOld = &aOldQuery;
|
|
|
|
pNew = &aNewQuery;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
|
|
|
|
new ScUndoRepeatDB( GetViewData()->GetDocShell(), nTab,
|
|
|
|
nStartCol, nStartRow, nEndCol, nEndRow,
|
|
|
|
nNewEndRow,
|
|
|
|
nCurX, nCurY,
|
|
|
|
pUndoDoc, pUndoTab,
|
|
|
|
pUndoRange, pUndoDB,
|
|
|
|
pOld, pNew ) );
|
|
|
|
}
|
|
|
|
|
2011-09-09 22:08:28 -04:00
|
|
|
GetViewData()->GetDocShell()->PostPaint(
|
|
|
|
ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab),
|
|
|
|
PAINT_GRID | PAINT_LEFT | PAINT_TOP | PAINT_SIZE);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else // "Keine Operationen auszufuehren"
|
|
|
|
ErrorMessage(STR_MSSG_REPEATDB_0);
|
|
|
|
}
|
2010-10-12 15:59:00 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|