Branch libreoffice-5-0-4
[LibreOffice.git] / include / svtools / svlbitm.hxx
blob479d5c02c6a4ab104bc6cd757ea6c59a764693fe
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 .
21 #ifndef INCLUDED_SVTOOLS_SVLBITM_HXX
22 #define INCLUDED_SVTOOLS_SVLBITM_HXX
24 #include <svtools/svtdllapi.h>
25 #include <tools/link.hxx>
26 #include <vcl/image.hxx>
27 #include <svtools/treelistbox.hxx>
28 #include <o3tl/typed_flags_set.hxx>
30 class SvTreeListEntry;
33 enum class SvBmp
35 UNCHECKED = 0,
36 CHECKED = 1,
37 TRISTATE = 2,
38 HIUNCHECKED = 3,
39 HICHECKED = 4,
40 HITRISTATE = 5,
41 STATICIMAGE = 6
44 enum class SvItemStateFlags
46 NONE = 0x00,
47 UNCHECKED = 0x01,
48 CHECKED = 0x02,
49 TRISTATE = 0x04,
50 HILIGHTED = 0x08
52 namespace o3tl
54 template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
57 struct SvLBoxButtonData_Impl;
59 class SVT_DLLPUBLIC SvLBoxButtonData
61 private:
62 Link<> aLink;
63 long nWidth;
64 long nHeight;
65 SvLBoxButtonData_Impl* pImpl;
66 bool bDataOk;
67 SvButtonState eState;
68 std::vector<Image> aBmps; // indices s. constants BMP_ ....
70 SVT_DLLPRIVATE void SetWidthAndHeight();
71 SVT_DLLPRIVATE void InitData( bool bImagesFromDefault,
72 bool _bRadioBtn, const Control* pControlForSettings = NULL );
73 public:
74 // include creating default images (CheckBox or RadioButton)
75 SvLBoxButtonData( const Control* pControlForSettings );
76 SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
78 ~SvLBoxButtonData();
80 static SvBmp GetIndex( SvItemStateFlags nItemState );
81 long Width();
82 long Height();
83 void SetLink( const Link<>& rLink) { aLink=rLink; }
84 const Link<>& GetLink() const { return aLink; }
85 bool IsRadio();
86 // as buttons are not derived from LinkHdl
87 void CallLink();
89 void StoreButtonState( SvTreeListEntry* pEntry, SvItemStateFlags nItemFlags );
90 static SvButtonState ConvertToButtonState( SvItemStateFlags nItemFlags );
92 SvButtonState GetActButtonState() const { return eState; }
94 SvTreeListEntry* GetActEntry() const;
96 void SetImage(SvBmp nIndex, const Image& aImage) { aBmps[(int)nIndex] = aImage; }
97 Image& GetImage(SvBmp nIndex) { return aBmps[(int)nIndex]; }
99 void SetDefaultImages( const Control* pControlForSettings = NULL );
100 // set images according to the color scheeme of the Control
101 // pControlForSettings == NULL: settings are taken from Application
102 bool HasDefaultImages() const;
105 // **********************************************************************
107 class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
109 protected:
110 OUString maText;
112 public:
113 SvLBoxString(SvTreeListEntry*, sal_uInt16 nFlags, const OUString& rText);
114 SvLBoxString();
115 virtual ~SvLBoxString();
117 virtual sal_uInt16 GetType() const SAL_OVERRIDE;
118 virtual void InitViewData(SvTreeListBox* pView,
119 SvTreeListEntry* pEntry,
120 SvViewDataItem* pViewData) SAL_OVERRIDE;
122 OUString GetText() const
124 return maText;
126 void SetText(const OUString& rText)
128 maText = rText;
131 virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
132 vcl::RenderContext& rRenderContext,
133 const SvViewDataEntry* pView,
134 const SvTreeListEntry* pEntry) SAL_OVERRIDE;
136 virtual SvLBoxItem* Create() const SAL_OVERRIDE;
137 virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
140 class SvLBoxBmp : public SvLBoxItem
142 Image aBmp;
143 public:
144 SvLBoxBmp();
145 virtual ~SvLBoxBmp();
146 virtual sal_uInt16 GetType() const SAL_OVERRIDE;
147 virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
148 virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext,
149 const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
150 virtual SvLBoxItem* Create() const SAL_OVERRIDE;
151 virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
155 class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
157 bool isVis;
158 SvLBoxButtonData* pData;
159 SvLBoxButtonKind eKind;
160 SvItemStateFlags nItemFlags;
162 static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext& pRenderContext);
163 public:
164 // An SvLBoxButton can be of three different kinds: an
165 // enabled checkbox (the normal kind), a disabled checkbox
166 // (which cannot be modified via UI), or a static image
167 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
168 // for that kind).
169 SvLBoxButton( SvTreeListEntry* pEntry,
170 SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
171 SvLBoxButtonData* pBData );
172 SvLBoxButton();
173 virtual ~SvLBoxButton();
174 virtual void InitViewData(SvTreeListBox* pView,
175 SvTreeListEntry* pEntry,
176 SvViewDataItem* pViewData) SAL_OVERRIDE;
178 virtual sal_uInt16 GetType() const SAL_OVERRIDE;
179 bool ClickHdl(SvTreeListBox* pView, SvTreeListEntry* );
181 virtual void Paint(const Point& rPos,
182 SvTreeListBox& rOutDev,
183 vcl::RenderContext& rRenderContext,
184 const SvViewDataEntry* pView,
185 const SvTreeListEntry* pEntry) SAL_OVERRIDE;
187 virtual SvLBoxItem* Create() const SAL_OVERRIDE;
189 virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
190 SvItemStateFlags GetButtonFlags() const
192 return nItemFlags;
194 bool IsStateChecked() const
196 return bool(nItemFlags & SvItemStateFlags::CHECKED);
198 bool IsStateUnchecked() const
200 return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
202 bool IsStateTristate() const
204 return bool(nItemFlags & SvItemStateFlags::TRISTATE);
206 bool IsStateHilighted() const
208 return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
210 void SetStateChecked();
211 void SetStateUnchecked();
212 void SetStateTristate();
213 void SetStateHilighted(bool bHilight);
214 void SetStateInvisible();
216 SvLBoxButtonKind GetKind() const { return eKind; }
218 // Check whether this button can be modified via UI
219 bool CheckModification() const;
220 SvLBoxButtonData* GetButtonData() const
222 return pData;
226 inline void SvLBoxButton::SetStateChecked()
228 nItemFlags &= SvItemStateFlags::HILIGHTED;
229 nItemFlags |= SvItemStateFlags::CHECKED;
232 inline void SvLBoxButton::SetStateUnchecked()
234 nItemFlags &= SvItemStateFlags::HILIGHTED;
235 nItemFlags |= SvItemStateFlags::UNCHECKED;
237 inline void SvLBoxButton::SetStateTristate()
239 nItemFlags &= SvItemStateFlags::HILIGHTED;
240 nItemFlags |= SvItemStateFlags::TRISTATE;
242 inline void SvLBoxButton::SetStateHilighted( bool bHilight )
244 if ( bHilight )
245 nItemFlags |= SvItemStateFlags::HILIGHTED;
246 else
247 nItemFlags &= ~SvItemStateFlags::HILIGHTED;
250 struct SvLBoxContextBmp_Impl;
252 class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
254 SvLBoxContextBmp_Impl* m_pImpl;
255 public:
256 SvLBoxContextBmp(SvTreeListEntry* pEntry,
257 sal_uInt16 nItemFlags,
258 Image aBmp1,
259 Image aBmp2,
260 bool bExpanded);
261 SvLBoxContextBmp();
262 virtual ~SvLBoxContextBmp();
264 virtual sal_uInt16 GetType() const SAL_OVERRIDE;
265 virtual void InitViewData(SvTreeListBox* pView,
266 SvTreeListEntry* pEntry,
267 SvViewDataItem* pViewData) SAL_OVERRIDE;
268 virtual void Paint(const Point& rPos,
269 SvTreeListBox& rOutDev,
270 vcl::RenderContext& rRenderContext,
271 const SvViewDataEntry* pView,
272 const SvTreeListEntry* pEntry) SAL_OVERRIDE;
274 virtual SvLBoxItem* Create() const SAL_OVERRIDE;
275 virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
278 bool SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
279 void GetModeImages(Image& rBitmap1, Image& rBitmap2) const;
281 inline void SetBitmap1(const Image& rImage);
282 inline void SetBitmap2(const Image& rImage);
283 inline const Image& GetBitmap1() const;
284 inline const Image& GetBitmap2() const;
286 private:
287 Image& implGetImageStore(bool bFirst);
290 inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
292 implGetImageStore(true) = _rImage;
295 inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
297 implGetImageStore(false) = _rImage;
300 inline const Image& SvLBoxContextBmp::GetBitmap1() const
302 Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
303 return rImage;
306 inline const Image& SvLBoxContextBmp::GetBitmap2() const
308 Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
309 return rImage;
312 #endif
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */