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{
58}
59
61{
62#ifdef DBG_UTIL
63 pParent = nullptr;
64#endif
65
66 m_Children.clear();
67 m_Items.clear();
68}
69
71{
72 return !m_Children.empty();
73}
74
76{
77 return pParent && !(pParent->nListPos & 0x80000000);
78}
79
81{
82 if( pParent && (pParent->nListPos & 0x80000000) )
84 return ( nListPos & 0x7fffffff );
85}
86
87
89{
90 nListPos &= 0x80000000;
91 nListPos |= ( pSource->nListPos & 0x7fffffff);
92 nAbsPos = pSource->nAbsPos;
94
95 m_Items.clear();
96 for (auto const& it : pSource->m_Items)
97 {
98 SvLBoxItem* pItem = &(*it);
99 std::unique_ptr<SvLBoxItem> pNewItem(pItem->Clone(pItem));
100 m_Items.push_back(std::move(pNewItem));
101 }
102
103 pUserData = pSource->GetUserData();
104 nEntryFlags = pSource->nEntryFlags;
105}
106
108{
109 return m_Items.size();
110}
111
112void SvTreeListEntry::AddItem(std::unique_ptr<SvLBoxItem> pItem)
113{
114 m_Items.push_back(std::move(pItem));
115}
116
118{
119 if ( bEnable )
121 else
123}
124
125void SvTreeListEntry::ReplaceItem(std::unique_ptr<SvLBoxItem> pNewItem, size_t const nPos)
126{
127 DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
128 if (nPos >= m_Items.size())
129 {
130 // Out of bound. Bail out.
131 pNewItem.reset();
132 return;
133 }
134
135 m_Items.erase(m_Items.begin()+nPos);
136 m_Items.insert(m_Items.begin()+nPos, std::move(pNewItem));
137}
138
139const SvLBoxItem& SvTreeListEntry::GetItem( size_t nPos ) const
140{
141 return *m_Items[nPos];
142}
143
145{
146 return *m_Items[nPos];
147}
148
149namespace {
150
151class FindByType
152{
154public:
155 explicit FindByType(SvLBoxItemType eType) : meType(eType) {}
156 bool operator() (const std::unique_ptr<SvLBoxItem>& rpItem) const
157 {
158 return rpItem->GetType() == meType;
159 }
160};
161
162class FindByPointer
163{
164 const SvLBoxItem* mpItem;
165public:
166 explicit FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
167 bool operator() (const std::unique_ptr<SvLBoxItem>& rpItem) const
168 {
169 return rpItem.get() == mpItem;
170 }
171};
172
173}
174
176{
177 ItemsType::const_iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByType(eType));
178 return (it == m_Items.end()) ? nullptr : (*it).get();
179}
180
182{
183 ItemsType::iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByType(eType));
184 return (it == m_Items.end()) ? nullptr : (*it).get();
185}
186
187size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
188{
189 ItemsType::const_iterator it = std::find_if(m_Items.begin(), m_Items.end(), FindByPointer(pItem));
190 return it == m_Items.end() ? ITEM_NOT_FOUND : std::distance(m_Items.begin(), it);
191}
192
193
195{
196 pUserData = pPtr;
197}
198
200{
201 return static_cast<bool>(nEntryFlags & SvTLEntryFlags::CHILDREN_ON_DEMAND);
202}
203
205{
206 nEntryFlags = nFlags;
207}
208
210{
212 sal_uInt32 nPos = GetChildListPos();
213 nPos++;
214 return (nPos < rList.size()) ? rList[nPos].get() : nullptr;
215}
216
218{
220 sal_uInt32 nPos = GetChildListPos();
221 if ( nPos == 0 )
222 return nullptr;
223 nPos--;
224 return rList[nPos].get();
225}
226
227
229{
231 return (rChildren.empty()) ? nullptr : rChildren.back().get();
232}
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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