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 #ifndef INCLUDED_VCL_TREELISTENTRY_HXX
21 #define INCLUDED_VCL_TREELISTENTRY_HXX
22 
23 #include <vcl/dllapi.h>
24 #include <tools/solar.h>
25 #include <tools/color.hxx>
26 #include <vcl/treelistbox.hxx>
27 #include <vcl/treelistentries.hxx>
28 #include <o3tl/typed_flags_set.hxx>
29 
30 #include <boost/optional.hpp>
31 #include <vector>
32 #include <memory>
33 
34 // flags related to the model
35 enum class SvTLEntryFlags
36 {
37     NONE                = 0x0000,
38     CHILDREN_ON_DEMAND  = 0x0001,
39     DISABLE_DROP        = 0x0002,
40     // is set if RequestingChildren has not set any children
41     NO_NODEBMP          = 0x0004,
42     // entry had or has children
43     HAD_CHILDREN        = 0x0010,
44     SEMITRANSPARENT     = 0x8000,      // draw semi-transparent entry bitmaps
45 };
46 namespace o3tl
47 {
48     template<> struct typed_flags<SvTLEntryFlags> : is_typed_flags<SvTLEntryFlags, 0x8017> {};
49 }
50 
51 class VCL_DLLPUBLIC SvTreeListEntry
52 {
53     friend class SvTreeList;
54     friend class SvListView;
55     friend class SvTreeListBox;
56 
57     typedef std::vector<std::unique_ptr<SvLBoxItem>> ItemsType;
58 
59     SvTreeListEntry*    pParent;
60     SvTreeListEntries   m_Children;
61     sal_uLong           nAbsPos;
62     sal_uLong           nListPos;
63     ItemsType           m_Items;
64     void*               pUserData;
65     SvTLEntryFlags      nEntryFlags;
66     Color               maBackColor;
67     boost::optional<Color> mxTextColor;
68 
69 private:
70     void ClearChildren();
71     void SetListPositions();
72     void InvalidateChildrensListPositions();
73 
74     SvTreeListEntry(const SvTreeListEntry& r) = delete;
75     void operator=(SvTreeListEntry const&) = delete;
76 
77 public:
78     static const size_t ITEM_NOT_FOUND = SAL_MAX_SIZE;
79 
80     SvTreeListEntry();
81     virtual ~SvTreeListEntry();
82 
83     bool HasChildren() const;
84     bool HasChildListPos() const;
85     sal_uLong GetChildListPos() const;
86 
GetChildEntries()87     SvTreeListEntries& GetChildEntries() { return m_Children; }
GetChildEntries() const88     const SvTreeListEntries& GetChildEntries() const { return m_Children; }
89 
90     void Clone(SvTreeListEntry* pSource);
91 
92     size_t ItemCount() const;
93 
94     // MAY ONLY BE CALLED IF THE ENTRY HAS NOT YET BEEN INSERTED INTO
95     // THE MODEL, AS OTHERWISE NO VIEW-DEPENDENT DATA ARE ALLOCATED
96     // FOR THE ITEM!
97     void        AddItem(std::unique_ptr<SvLBoxItem> pItem);
98     void ReplaceItem(std::unique_ptr<SvLBoxItem> pNewItem, size_t nPos);
99     const SvLBoxItem& GetItem( size_t nPos ) const;
100     SvLBoxItem& GetItem( size_t nPos );
101     const SvLBoxItem* GetFirstItem(SvLBoxItemType eType) const;
102     SvLBoxItem* GetFirstItem(SvLBoxItemType eType);
103     size_t GetPos( const SvLBoxItem* pItem ) const;
GetUserData() const104     void*       GetUserData() const { return pUserData;}
105     void        SetUserData( void* pPtr );
106     void        EnableChildrenOnDemand( bool bEnable=true );
107     bool        HasChildrenOnDemand() const;
108 
GetFlags() const109     SvTLEntryFlags GetFlags() const { return nEntryFlags;}
110     void SetFlags( SvTLEntryFlags nFlags );
111 
SetBackColor(const Color & rColor)112     void SetBackColor( const Color& rColor ) { maBackColor = rColor; }
GetBackColor() const113     const Color& GetBackColor() const { return maBackColor; }
114 
SetTextColor(boost::optional<Color> xColor)115     void SetTextColor( boost::optional<Color> xColor ) { mxTextColor = xColor; }
GetTextColor() const116     boost::optional<Color> const & GetTextColor() const { return mxTextColor; }
117 
GetParent() const118     SvTreeListEntry* GetParent() const { return pParent; }
119 
120     SvTreeListEntry* NextSibling() const;
121     SvTreeListEntry* PrevSibling() const;
122     SvTreeListEntry* LastSibling() const;
123 };
124 
125 #endif
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
128