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 <PivotLayoutTreeListBase.hxx>
13 #include <PivotLayoutDialog.hxx>
15 ScPivotLayoutTreeListBase::ScPivotLayoutTreeListBase(std::unique_ptr
<weld::TreeView
> xControl
, SvPivotTreeListType eType
)
16 : mxControl(std::move(xControl
))
17 , maDropTargetHelper(*this)
21 mxControl
->connect_focus_in(LINK(this, ScPivotLayoutTreeListBase
, GetFocusHdl
));
22 mxControl
->connect_mnemonic_activate(LINK(this, ScPivotLayoutTreeListBase
, MnemonicActivateHdl
));
23 mxControl
->connect_focus_out(LINK(this, ScPivotLayoutTreeListBase
, LoseFocusHdl
));
26 ScPivotLayoutTreeListBase::~ScPivotLayoutTreeListBase()
30 void ScPivotLayoutTreeListBase::Setup(ScPivotLayoutDialog
* pParent
)
35 ScPivotLayoutTreeDropTarget::ScPivotLayoutTreeDropTarget(ScPivotLayoutTreeListBase
& rTreeView
)
36 : DropTargetHelper(rTreeView
.get_widget().get_drop_target())
37 , m_rTreeView(rTreeView
)
41 sal_Int8
ScPivotLayoutTreeDropTarget::AcceptDrop(const AcceptDropEvent
& rEvt
)
43 // to enable the autoscroll when we're close to the edges
44 weld::TreeView
& rWidget
= m_rTreeView
.get_widget();
45 rWidget
.get_dest_row_at_pos(rEvt
.maPosPixel
, nullptr, true);
46 return DND_ACTION_MOVE
;
49 sal_Int8
ScPivotLayoutTreeDropTarget::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
51 weld::TreeView
& rWidget
= m_rTreeView
.get_widget();
52 weld::TreeView
* pSource
= rWidget
.get_drag_source();
54 return DND_ACTION_NONE
;
56 std::unique_ptr
<weld::TreeIter
> xTarget(rWidget
.make_iterator());
58 if (rWidget
.get_dest_row_at_pos(rEvt
.maPosPixel
, xTarget
.get(), true))
59 nTargetPos
= rWidget
.get_iter_index_in_parent(*xTarget
);
60 m_rTreeView
.InsertEntryForSourceTarget(*pSource
, nTargetPos
);
61 rWidget
.unset_drag_dest_row();
62 return DND_ACTION_NONE
;
65 void ScPivotLayoutTreeListBase::PushEntriesToPivotFieldVector(ScPivotFieldVector
& rVector
)
67 std::unique_ptr
<weld::TreeIter
> xEachEntry(mxControl
->make_iterator());
68 if (!mxControl
->get_iter_first(*xEachEntry
))
71 std::optional
<ScPivotField
> oDataField
;
75 ScItemValue
* pItemValue
= weld::fromId
<ScItemValue
*>(mxControl
->get_id(*xEachEntry
));
76 ScPivotFuncData
& rFunctionData
= pItemValue
->maFunctionData
;
79 aField
.nCol
= rFunctionData
.mnCol
;
80 aField
.mnOriginalDim
= rFunctionData
.mnOriginalDim
;
81 aField
.nFuncMask
= rFunctionData
.mnFuncMask
;
82 aField
.mnDupCount
= rFunctionData
.mnDupCount
;
83 aField
.maFieldRef
= rFunctionData
.maFieldRef
;
85 if (aField
.nCol
== PIVOT_DATA_FIELD
)
88 rVector
.push_back(aField
);
89 } while (mxControl
->iter_next(*xEachEntry
));
92 rVector
.push_back(*oDataField
);
95 void ScPivotLayoutTreeListBase::InsertEntryForSourceTarget(weld::TreeView
& /*pSource*/, int /*nTarget*/)
99 void ScPivotLayoutTreeListBase::RemoveEntryForItem(const ScItemValue
* pItemValue
)
101 OUString
sId(weld::toId(pItemValue
));
102 int nPos
= mxControl
->find_id(sId
);
105 mxControl
->remove(nPos
);
108 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, GetFocusHdl
, weld::Widget
&, void)
112 mpParent
->mpPreviouslyFocusedListBox
= this;
115 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, MnemonicActivateHdl
, weld::Widget
&, bool)
117 if (!mpParent
|| !mpParent
->mpPreviouslyFocusedListBox
)
119 weld::TreeView
& rSource
= mpParent
->mpPreviouslyFocusedListBox
->get_widget();
120 int nEntry
= rSource
.get_cursor_index();
122 InsertEntryForSourceTarget(rSource
, -1);
126 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, LoseFocusHdl
, weld::Widget
&, void)
130 mpParent
->mpPreviouslyFocusedListBox
= nullptr;
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */