1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
12 #include "PivotLayoutTreeList.hxx"
13 #include "PivotLayoutDialog.hxx"
15 #include <vcl/builderfactory.hxx>
16 #include <svtools/treelistentry.hxx>
18 #include "scabstdlg.hxx"
22 VCL_BUILDER_FACTORY_ARGS(ScPivotLayoutTreeList
,
23 WB_BORDER
| WB_TABSTOP
| WB_CLIPCHILDREN
|
26 ScPivotLayoutTreeList::ScPivotLayoutTreeList(vcl::Window
* pParent
, WinBits nBits
) :
27 ScPivotLayoutTreeListBase(pParent
, nBits
)
30 ScPivotLayoutTreeList::~ScPivotLayoutTreeList()
33 void ScPivotLayoutTreeList::Setup(ScPivotLayoutDialog
* pParent
, SvPivotTreeListType eType
)
39 bool ScPivotLayoutTreeList::DoubleClickHdl()
41 SvTreeListEntry
* pEntry
= GetCurEntry();
45 ScItemValue
* pCurrentItemValue
= static_cast<ScItemValue
*>(pEntry
->GetUserData());
46 ScPivotFuncData
& rCurrentFunctionData
= pCurrentItemValue
->maFunctionData
;
48 if (mpParent
->IsDataElement(rCurrentFunctionData
.mnCol
))
51 SCCOL nCurrentColumn
= rCurrentFunctionData
.mnCol
;
52 ScDPLabelData
* pCurrentLabelData
= mpParent
->GetLabelData(nCurrentColumn
);
53 if (!pCurrentLabelData
)
56 ScAbstractDialogFactory
* pFactory
= ScAbstractDialogFactory::Create();
58 vector
<ScDPName
> aDataFieldNames
;
59 mpParent
->PushDataFieldNames(aDataFieldNames
);
61 boost::scoped_ptr
<AbstractScDPSubtotalDlg
> pDialog(
62 pFactory
->CreateScDPSubtotalDlg(this, mpParent
->maPivotTableObject
, *pCurrentLabelData
, rCurrentFunctionData
, aDataFieldNames
, true));
64 if (pDialog
->Execute() == RET_OK
)
66 pDialog
->FillLabelData(*pCurrentLabelData
);
67 rCurrentFunctionData
.mnFuncMask
= pDialog
->GetFuncMask();
73 void ScPivotLayoutTreeList::FillFields(ScPivotFieldVector
& rFieldVector
)
77 ScPivotFieldVector::iterator it
;
78 for (it
= rFieldVector
.begin(); it
!= rFieldVector
.end(); ++it
)
80 ScPivotField
& rField
= *it
;
81 ScItemValue
* pItemValue
= mpParent
->GetItem(rField
.nCol
);
82 InsertEntry(pItemValue
->maName
, NULL
, false, TREELIST_APPEND
, pItemValue
);
86 void ScPivotLayoutTreeList::InsertEntryForSourceTarget(SvTreeListEntry
* pSource
, SvTreeListEntry
* pTarget
)
88 ScItemValue
* pItemValue
= static_cast<ScItemValue
*>(pSource
->GetUserData());
89 ScItemValue
* pOriginalItemValue
= pItemValue
->mpOriginalItemValue
;
91 // Don't allow to add "Data" element to page fields
92 if(meType
== PAGE_LIST
&& mpParent
->IsDataElement(pItemValue
->maFunctionData
.mnCol
))
95 mpParent
->ItemInserted(pOriginalItemValue
, meType
);
97 sal_uLong nPosition
= (pTarget
== NULL
) ? TREELIST_APPEND
: GetModel()->GetAbsPos(pTarget
) + 1;
98 InsertEntryForItem(pOriginalItemValue
, nPosition
);
101 void ScPivotLayoutTreeList::InsertEntryForItem(ScItemValue
* pItemValue
, sal_uLong nPosition
)
103 OUString rName
= pItemValue
->maName
;
104 InsertEntry(rName
, NULL
, false, nPosition
, pItemValue
);
107 void ScPivotLayoutTreeList::KeyInput(const KeyEvent
& rKeyEvent
)
109 vcl::KeyCode aCode
= rKeyEvent
.GetKeyCode();
110 sal_uInt16 nCode
= aCode
.GetCode();
112 if (nCode
== KEY_DELETE
)
114 const SvTreeListEntry
* pEntry
= GetCurEntry();
116 GetModel()->Remove(pEntry
);
119 SvTreeListBox::KeyInput(rKeyEvent
);
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */