Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / toolkit / svlbitm.hxx
blobc9aaaa46d9f39e61b2c64139813f4dbe665ce36a
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:
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 .
20 #pragma once
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
26 #include <memory>
27 #include <vcl/dllapi.h>
28 #include <tools/link.hxx>
29 #include <vcl/image.hxx>
30 #include <vcl/toolkit/treelistbox.hxx>
31 #include <o3tl/typed_flags_set.hxx>
33 class SvTreeListEntry;
34 class SvLBoxButton;
37 enum class SvBmp
39 UNCHECKED = 0,
40 CHECKED = 1,
41 TRISTATE = 2,
42 HIUNCHECKED = 3,
43 HICHECKED = 4,
44 HITRISTATE = 5
47 enum class SvItemStateFlags
49 NONE = 0x00,
50 UNCHECKED = 0x01,
51 CHECKED = 0x02,
52 TRISTATE = 0x04,
53 HIGHLIGHTED = 0x08
55 namespace o3tl
57 template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
60 struct SvLBoxButtonData_Impl;
62 class SvLBoxButtonData
64 private:
65 Link<SvLBoxButtonData*,void> aLink;
66 tools::Long nWidth;
67 tools::Long nHeight;
68 std::unique_ptr<SvLBoxButtonData_Impl> pImpl;
69 bool bDataOk;
70 std::vector<Image> aBmps; // indices s. constants BMP_...
72 void SetWidthAndHeight();
73 void InitData( bool _bRadioBtn, const Control* pControlForSettings );
74 public:
75 // include creating default images (CheckBox or RadioButton)
76 SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
78 ~SvLBoxButtonData();
80 static SvBmp GetIndex( SvItemStateFlags nItemState );
81 tools::Long Width();
82 tools::Long Height();
83 void SetLink( const Link<SvLBoxButtonData*,void>& rLink) { aLink=rLink; }
84 bool IsRadio() const;
85 // as buttons are not derived from LinkHdl
86 void CallLink();
88 void StoreButtonState(SvTreeListEntry* pActEntry, SvLBoxButton* pActBox);
89 static SvButtonState ConvertToButtonState( SvItemStateFlags nItemFlags );
91 SvTreeListEntry* GetActEntry() const;
92 SvLBoxButton* GetActBox() const;
94 void SetImage(SvBmp nIndex, const Image& aImage) { aBmps[static_cast<int>(nIndex)] = aImage; }
95 Image& GetImage(SvBmp nIndex) { return aBmps[static_cast<int>(nIndex)]; }
97 void SetDefaultImages( const Control* pControlForSettings );
98 // set images according to the color scheme of the Control
99 // pControlForSettings == NULL: settings are taken from Application
100 bool HasDefaultImages() const;
103 // **********************************************************************
105 class VCL_DLLPUBLIC SvLBoxString : public SvLBoxItem
107 private:
108 bool mbEmphasized;
109 bool mbCustom;
110 double mfAlign;
111 protected:
112 OUString maText;
114 public:
115 SvLBoxString(OUString aText);
116 SvLBoxString();
117 virtual ~SvLBoxString() override;
119 virtual SvLBoxItemType GetType() const override;
120 virtual void InitViewData(SvTreeListBox* pView,
121 SvTreeListEntry* pEntry,
122 SvViewDataItem* pViewData = nullptr) override;
124 virtual int CalcWidth(const SvTreeListBox* pView) const override;
126 void Align(double fAlign) { mfAlign = fAlign; }
128 void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
129 bool IsEmphasized() const { return mbEmphasized; }
131 void SetCustomRender() { mbCustom = true; }
133 const OUString& GetText() const
135 return maText;
137 void SetText(const OUString& rText)
139 maText = rText;
142 virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
143 vcl::RenderContext& rRenderContext,
144 const SvViewDataEntry* pView,
145 const SvTreeListEntry& rEntry) override;
147 virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
150 class SvLBoxButton final : public SvLBoxItem
152 bool isVis;
153 SvLBoxButtonData* pData;
154 SvItemStateFlags nItemFlags;
156 static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext const & pRenderContext);
157 public:
158 // An SvLBoxButton can be of two different kinds: an
159 // enabled checkbox (the normal kind), or a static image
160 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
161 // for that kind).
162 SvLBoxButton( SvLBoxButtonData* pBData );
163 SvLBoxButton();
164 virtual ~SvLBoxButton() override;
165 virtual void InitViewData(SvTreeListBox* pView,
166 SvTreeListEntry* pEntry,
167 SvViewDataItem* pViewData = nullptr) override;
169 virtual SvLBoxItemType GetType() const override;
170 void ClickHdl( SvTreeListEntry* );
172 virtual void Paint(const Point& rPos,
173 SvTreeListBox& rOutDev,
174 vcl::RenderContext& rRenderContext,
175 const SvViewDataEntry* pView,
176 const SvTreeListEntry& rEntry) override;
178 virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
180 SvItemStateFlags GetButtonFlags() const
182 return nItemFlags;
184 bool IsStateChecked() const
186 return bool(nItemFlags & SvItemStateFlags::CHECKED);
188 bool IsStateUnchecked() const
190 return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
192 bool IsStateTristate() const
194 return bool(nItemFlags & SvItemStateFlags::TRISTATE);
196 bool IsStateHilighted() const
198 return bool(nItemFlags & SvItemStateFlags::HIGHLIGHTED);
200 void SetStateChecked();
201 void SetStateUnchecked();
202 void SetStateTristate();
203 void SetStateHilighted(bool bHilight);
206 inline void SvLBoxButton::SetStateChecked()
208 nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
209 nItemFlags |= SvItemStateFlags::CHECKED;
212 inline void SvLBoxButton::SetStateUnchecked()
214 nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
215 nItemFlags |= SvItemStateFlags::UNCHECKED;
217 inline void SvLBoxButton::SetStateTristate()
219 nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
220 nItemFlags |= SvItemStateFlags::TRISTATE;
222 inline void SvLBoxButton::SetStateHilighted( bool bHilight )
224 if ( bHilight )
225 nItemFlags |= SvItemStateFlags::HIGHLIGHTED;
226 else
227 nItemFlags &= ~SvItemStateFlags::HIGHLIGHTED;
230 struct SvLBoxContextBmp_Impl;
232 class VCL_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
234 std::unique_ptr<SvLBoxContextBmp_Impl> m_pImpl;
235 public:
236 SvLBoxContextBmp(const Image& aBmp1,
237 const Image& aBmp2,
238 bool bExpanded);
239 SvLBoxContextBmp();
240 virtual ~SvLBoxContextBmp() override;
242 virtual SvLBoxItemType GetType() const override;
243 virtual void InitViewData(SvTreeListBox* pView,
244 SvTreeListEntry* pEntry,
245 SvViewDataItem* pViewData = nullptr) override;
246 virtual void Paint(const Point& rPos,
247 SvTreeListBox& rOutDev,
248 vcl::RenderContext& rRenderContext,
249 const SvViewDataEntry* pView,
250 const SvTreeListEntry& rEntry) override;
252 virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
254 void SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
256 inline void SetBitmap1(const Image& rImage);
257 inline void SetBitmap2(const Image& rImage);
258 inline const Image& GetBitmap1() const;
259 inline const Image& GetBitmap2() const;
261 private:
262 Image& implGetImageStore(bool bFirst);
265 inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
267 implGetImageStore(true) = _rImage;
270 inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
272 implGetImageStore(false) = _rImage;
275 inline const Image& SvLBoxContextBmp::GetBitmap1() const
277 Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
278 return rImage;
281 inline const Image& SvLBoxContextBmp::GetBitmap2() const
283 Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
284 return rImage;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */