1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
44 enum class SvItemStateFlags
54 template<> struct typed_flags
<SvItemStateFlags
> : is_typed_flags
<SvItemStateFlags
, 0x0f> {};
57 struct SvLBoxButtonData_Impl
;
59 class SVT_DLLPUBLIC SvLBoxButtonData
65 SvLBoxButtonData_Impl
* pImpl
;
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
);
74 // include creating default images (CheckBox or RadioButton)
75 SvLBoxButtonData( const Control
* pControlForSettings
);
76 SvLBoxButtonData( const Control
* pControlForSettings
, bool _bRadioBtn
);
80 static SvBmp
GetIndex( SvItemStateFlags nItemState
);
83 void SetLink( const Link
<>& rLink
) { aLink
=rLink
; }
84 const Link
<>& GetLink() const { return aLink
; }
86 // as buttons are not derived from LinkHdl
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
113 SvLBoxString(SvTreeListEntry
*, sal_uInt16 nFlags
, const OUString
& rText
);
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
126 void SetText(const OUString
& 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
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
158 SvLBoxButtonData
* pData
;
159 SvLBoxButtonKind eKind
;
160 SvItemStateFlags nItemFlags
;
162 static void ImplAdjustBoxSize( Size
& io_rCtrlSize
, ControlType i_eType
, vcl::RenderContext
& pRenderContext
);
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
169 SvLBoxButton( SvTreeListEntry
* pEntry
,
170 SvLBoxButtonKind eTheKind
, sal_uInt16 nFlags
,
171 SvLBoxButtonData
* pBData
);
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
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
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
)
245 nItemFlags
|= SvItemStateFlags::HILIGHTED
;
247 nItemFlags
&= ~SvItemStateFlags::HILIGHTED
;
250 struct SvLBoxContextBmp_Impl
;
252 class SVT_DLLPUBLIC SvLBoxContextBmp
: public SvLBoxItem
254 SvLBoxContextBmp_Impl
* m_pImpl
;
256 SvLBoxContextBmp(SvTreeListEntry
* pEntry
,
257 sal_uInt16 nItemFlags
,
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;
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);
306 inline const Image
& SvLBoxContextBmp::GetBitmap2() const
308 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(false);
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */