calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / source / ui / dbgui / PivotLayoutTreeListBase.cxx
blob45af29a4f1a4cf192a74bedbceddb2442d6deccd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
18 , meType(eType)
19 , mpParent(nullptr)
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)
32 mpParent = 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();
53 if (!pSource)
54 return DND_ACTION_NONE;
56 std::unique_ptr<weld::TreeIter> xTarget(rWidget.make_iterator());
57 int nTargetPos = -1;
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))
69 return;
72 ScItemValue* pItemValue = weld::fromId<ScItemValue*>(mxControl->get_id(*xEachEntry));
73 ScPivotFuncData& rFunctionData = pItemValue->maFunctionData;
75 ScPivotField aField;
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);
93 if (nPos == -1)
94 return;
95 mxControl->remove(nPos);
98 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase, GetFocusHdl, weld::Widget&, void)
100 if (!mpParent)
101 return;
102 mpParent->mpPreviouslyFocusedListBox = this;
105 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase, MnemonicActivateHdl, weld::Widget&, bool)
107 if (!mpParent || !mpParent->mpPreviouslyFocusedListBox)
108 return false;
109 weld::TreeView& rSource = mpParent->mpPreviouslyFocusedListBox->get_widget();
110 int nEntry = rSource.get_cursor_index();
111 if (nEntry != -1)
112 InsertEntryForSourceTarget(rSource, -1);
113 return true;
116 IMPL_LINK_NOARG(ScPivotLayoutTreeListBase, LoseFocusHdl, weld::Widget&, void)
118 if (!mpParent)
119 return;
120 mpParent->mpPreviouslyFocusedListBox = nullptr;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */