Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : */
11 :
12 : #include "PivotLayoutTreeList.hxx"
13 : #include "PivotLayoutDialog.hxx"
14 :
15 : #include <svtools/treelistentry.hxx>
16 : #include "pivot.hxx"
17 : #include "scabstdlg.hxx"
18 :
19 : using namespace std;
20 :
21 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeScPivotLayoutTreeList(vcl::Window *pParent, VclBuilder::stringmap& )
22 : {
23 0 : return new ScPivotLayoutTreeList(pParent, WB_BORDER | WB_TABSTOP | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
24 : }
25 :
26 0 : ScPivotLayoutTreeList::ScPivotLayoutTreeList(vcl::Window* pParent, WinBits nBits) :
27 0 : ScPivotLayoutTreeListBase(pParent, nBits)
28 0 : {}
29 :
30 0 : ScPivotLayoutTreeList::~ScPivotLayoutTreeList()
31 0 : {}
32 :
33 0 : void ScPivotLayoutTreeList::Setup(ScPivotLayoutDialog* pParent, SvPivotTreeListType eType)
34 : {
35 0 : mpParent = pParent;
36 0 : meType = eType;
37 0 : }
38 :
39 0 : bool ScPivotLayoutTreeList::DoubleClickHdl()
40 : {
41 0 : ScItemValue* pCurrentItemValue = (ScItemValue*) GetCurEntry()->GetUserData();
42 0 : ScPivotFuncData& rCurrentFunctionData = pCurrentItemValue->maFunctionData;
43 :
44 0 : if (mpParent->IsDataElement(rCurrentFunctionData.mnCol))
45 0 : return false;
46 :
47 0 : SCCOL nCurrentColumn = rCurrentFunctionData.mnCol;
48 0 : ScDPLabelData* pCurrentLabelData = mpParent->GetLabelData(nCurrentColumn);
49 0 : if (!pCurrentLabelData)
50 0 : return false;
51 :
52 0 : ScAbstractDialogFactory* pFactory = ScAbstractDialogFactory::Create();
53 :
54 0 : vector<ScDPName> aDataFieldNames;
55 0 : mpParent->PushDataFieldNames(aDataFieldNames);
56 :
57 : boost::scoped_ptr<AbstractScDPSubtotalDlg> pDialog(
58 0 : pFactory->CreateScDPSubtotalDlg(this, mpParent->maPivotTableObject, *pCurrentLabelData, rCurrentFunctionData, aDataFieldNames, true));
59 :
60 0 : if (pDialog->Execute() == RET_OK)
61 : {
62 0 : pDialog->FillLabelData(*pCurrentLabelData);
63 0 : rCurrentFunctionData.mnFuncMask = pDialog->GetFuncMask();
64 : }
65 :
66 0 : return true;
67 : }
68 :
69 0 : void ScPivotLayoutTreeList::FillFields(ScPivotFieldVector& rFieldVector)
70 : {
71 0 : Clear();
72 :
73 0 : ScPivotFieldVector::iterator it;
74 0 : for (it = rFieldVector.begin(); it != rFieldVector.end(); ++it)
75 : {
76 0 : ScPivotField& rField = *it;
77 0 : ScItemValue* pItemValue = mpParent->GetItem(rField.nCol);
78 0 : InsertEntry(pItemValue->maName, NULL, false, TREELIST_APPEND, pItemValue);
79 : }
80 0 : }
81 :
82 0 : void ScPivotLayoutTreeList::InsertEntryForSourceTarget(SvTreeListEntry* pSource, SvTreeListEntry* pTarget)
83 : {
84 0 : ScItemValue* pItemValue = (ScItemValue*) pSource->GetUserData();
85 0 : ScItemValue* pOriginalItemValue = pItemValue->mpOriginalItemValue;
86 :
87 : // Don't allow to add "Data" element to page fields
88 0 : if(meType == PAGE_LIST && mpParent->IsDataElement(pItemValue->maFunctionData.mnCol))
89 0 : return;
90 :
91 0 : mpParent->ItemInserted(pOriginalItemValue, meType);
92 :
93 0 : sal_uLong nPosition = (pTarget == NULL) ? TREELIST_APPEND : GetModel()->GetAbsPos(pTarget) + 1;
94 0 : InsertEntryForItem(pOriginalItemValue, nPosition);
95 : }
96 :
97 0 : void ScPivotLayoutTreeList::InsertEntryForItem(ScItemValue* pItemValue, sal_uLong nPosition)
98 : {
99 0 : OUString rName = pItemValue->maName;
100 0 : InsertEntry(rName, NULL, false, nPosition, pItemValue);
101 0 : }
102 :
103 0 : void ScPivotLayoutTreeList::KeyInput(const KeyEvent& rKeyEvent)
104 : {
105 0 : vcl::KeyCode aCode = rKeyEvent.GetKeyCode();
106 0 : sal_uInt16 nCode = aCode.GetCode();
107 :
108 0 : switch (nCode)
109 : {
110 : case KEY_DELETE:
111 0 : GetModel()->Remove(GetCurEntry());
112 0 : return;
113 : }
114 0 : SvTreeListBox::KeyInput(rKeyEvent);
115 228 : }
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|