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
))
72 ScItemValue
* pItemValue
= weld::fromId
<ScItemValue
*>(mxControl
->get_id(*xEachEntry
));
73 ScPivotFuncData
& rFunctionData
= pItemValue
->maFunctionData
;
76 aField
.nCol
= rFunctionData
.mnCol
;
77 aField
.mnOriginalDim
= rFunctionData
.mnOriginalDim
;
78 aField
.nFuncMask
= rFunctionData
.mnFuncMask
;
79 aField
.mnDupCount
= rFunctionData
.mnDupCount
;
80 aField
.maFieldRef
= rFunctionData
.maFieldRef
;
81 rVector
.push_back(aField
);
82 } while (mxControl
->iter_next(*xEachEntry
));
85 void ScPivotLayoutTreeListBase::InsertEntryForSourceTarget(weld::TreeView
& /*pSource*/, int /*nTarget*/)
89 void ScPivotLayoutTreeListBase::RemoveEntryForItem(const ScItemValue
* pItemValue
)
91 OUString
sId(weld::toId(pItemValue
));
92 int nPos
= mxControl
->find_id(sId
);
95 mxControl
->remove(nPos
);
98 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, GetFocusHdl
, weld::Widget
&, void)
102 mpParent
->mpPreviouslyFocusedListBox
= this;
105 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, MnemonicActivateHdl
, weld::Widget
&, bool)
107 if (!mpParent
|| !mpParent
->mpPreviouslyFocusedListBox
)
109 weld::TreeView
& rSource
= mpParent
->mpPreviouslyFocusedListBox
->get_widget();
110 int nEntry
= rSource
.get_cursor_index();
112 InsertEntryForSourceTarget(rSource
, -1);
116 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase
, LoseFocusHdl
, weld::Widget
&, void)
120 mpParent
->mpPreviouslyFocusedListBox
= nullptr;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */