LibreOffice Module vcl (master) 1
treelistentry.cxx
Go to the documentation of this file.
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 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <memory>
22#include <vcl/svapp.hxx>
23#include <vcl/settings.hxx>
24#include <tools/debug.hxx>
25
27{
28 m_Children.clear();
29}
30
32{
33 sal_uInt32 nCur = 0;
34 for (auto const& pEntry : m_Children)
35 {
36 SvTreeListEntry& rEntry = *pEntry;
37 rEntry.nListPos &= 0x80000000;
38 rEntry.nListPos |= nCur;
39 ++nCur;
40 }
41
42 nListPos &= (~0x80000000); // remove the invalid bit.
43}
44
46{
47 nListPos |= 0x80000000;
48}
49
51 : pParent(nullptr)
52 , nAbsPos(0)
53 , nListPos(0)
54 , mnExtraIndent(0)
55 , pUserData(nullptr)
56 , nEntryFlags(SvTLEntryFlags::NONE)
57 , maBackColor(Application::GetSettings().GetStyleSettings().GetWindowColor())
58{
59}
60
62{
63#ifdef DBG_UTIL
64 pParent = nullptr;
65#endif
66
67 m_Children.clear();
68 m_Items.clear();
69}
70
72{
73 return !m_Children.empty();
74}
75
77{
78 return pParent && !(pParent->nListPos & 0x80000000);
79}
80
82{
83 if( pParent && (pParent->nListPos & 0x80000000) )
85 return ( nListPos & 0x7fffffff );
86}
87
88
90{
91 nListPos &= 0x80000000;
92 nListPos |= ( pSource->nListPos & 0x7fffffff);
93 nAbsPos = pSource->nAbsPos;
95
96 m_Items.clear();
97 for (auto const& it : pSource->m_Items)
98 {
99 SvLBoxItem* pItem = &(*it);
100 std::unique_ptr<SvLBoxItem> pNewItem(pItem->Clone(pItem));
101 m_Items.push_back(std::move(pNewItem));
102 }
103
104 pUserData = pSource->GetUserData();
105 nEntryFlags = pSource->nEntryFlags;
106}
107
109{
110 return m_Items.size();
111}
112
113void SvTreeListEntry::AddItem(std::unique_ptr<SvLBoxItem> pItem)
114{
115 m_Items.push_back(std::move(pItem));
116}
117
119{
120 if ( bEnable )
122 else
124}
125
126void SvTreeListEntry::ReplaceItem(std::unique_ptr<SvLBoxItem> pNewItem, size_t const nPos)
127{
128 DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
129 if (nPos >= m_Items.size())
130 {
131 // Out of bound. Bail out.
132 pNewItem.reset();
133 return;
134 }
135
136 m_Items.erase(m_Items.begin()+nPos);
137 m_Items.insert(m_Items.begin()+nPos, std::move(pNewItem));
138}
139
140const SvLBoxItem& SvTreeListEntry::GetItem( size_t nPos ) const
141{
142 return *m_Items[nPos];
143}
144
146{
147 return *m_Items[nPos];
148}
149
150namespace {
151
152class FindByType
153{
155public:
156 explicit FindByType(SvLBoxItemType eType) : meType(eType) {}
157 bool operator() (const std::unique_ptr<SvLBoxItem>& rpItem) const
158 {
159 return rpItem->GetType() == meType;
160 }
161};
162
163class FindByPointer
164{
165 const SvLBoxItem* mpItem;
166public:
167 explicit FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
168 bool operator() (const std::unique_ptr<SvLBoxItem>& rpItem) const
169 {
170 return rpItem.get() == mpItem;
171 }
172};
173
174}
175
177{
178 ItemsType::const_iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByType(eType));
179 return (it == m_Items.end()) ? nullptr : (*it).get();
180}
181
183{
184 ItemsType::iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByType(eType));
185 return (it == m_Items.end()) ? nullptr : (*it).get();
186}
187
188size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
189{
190 ItemsType::const_iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByPointer(pItem));
191 return it == m_Items.end() ? ITEM_NOT_FOUND : std::distance(m_Items.begin(), it);
192}
193
194
196{
197 pUserData = pPtr;
198}
199
201{
202 return static_cast<bool>(nEntryFlags & SvTLEntryFlags::CHILDREN_ON_DEMAND);
203}
204
206{
207 nEntryFlags = nFlags;
208}
209
211{
213 sal_uInt32 nPos = GetChildListPos();
214 nPos++;
215 return (nPos < rList.size()) ? rList[nPos].get() : nullptr;
216}
217
219{
221 sal_uInt32 nPos = GetChildListPos();
222 if ( nPos == 0 )
223 return nullptr;
224 nPos--;
225 return rList[nPos].get();
226}
227
228
230{
232 return (rChildren.empty()) ? nullptr : rChildren.back().get();
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:233
virtual std::unique_ptr< SvLBoxItem > Clone(SvLBoxItem const *pSource) const =0
void InvalidateChildrensListPositions()
SvTreeListEntry * PrevSibling() const
SvTreeListEntry * NextSibling() const
SvTreeListEntries m_Children
void Clone(SvTreeListEntry *pSource)
const SvLBoxItem * GetFirstItem(SvLBoxItemType eType) const
void * GetUserData() const
bool HasChildren() const
size_t ItemCount() const
size_t GetPos(const SvLBoxItem *pItem) const
virtual ~SvTreeListEntry()
bool HasChildrenOnDemand() const
bool HasChildListPos() const
const SvLBoxItem & GetItem(size_t nPos) const
sal_uInt32 mnExtraIndent
void ReplaceItem(std::unique_ptr< SvLBoxItem > pNewItem, size_t nPos)
static const size_t ITEM_NOT_FOUND
void EnableChildrenOnDemand(bool bEnable=true)
sal_uInt32 nAbsPos
void SetFlags(SvTLEntryFlags nFlags)
SvTreeListEntry * pParent
sal_uInt32 nListPos
void AddItem(std::unique_ptr< SvLBoxItem > pItem)
sal_uInt32 GetChildListPos() const
SvTLEntryFlags nEntryFlags
SvTreeListEntry * LastSibling() const
void SetUserData(void *pPtr)
#define DBG_ASSERT(sCon, aError)
DocumentType eType
void * p
sal_uInt16 nPos
NONE
SvLBoxItemType
Definition: treelistbox.hxx:96
std::vector< std::unique_ptr< SvTreeListEntry > > SvTreeListEntries
SvTLEntryFlags
RedlineType meType