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_VCL_SVLBITM_HXX
22 #define INCLUDED_VCL_SVLBITM_HXX
25 #include <vcl/dllapi.h>
26 #include <tools/link.hxx>
27 #include <vcl/image.hxx>
28 #include <vcl/treelistbox.hxx>
29 #include <o3tl/typed_flags_set.hxx>
31 class SvTreeListEntry
;
46 enum class SvItemStateFlags
56 template<> struct typed_flags
<SvItemStateFlags
> : is_typed_flags
<SvItemStateFlags
, 0x0f> {};
59 struct SvLBoxButtonData_Impl
;
61 class VCL_DLLPUBLIC SvLBoxButtonData
64 Link
<SvLBoxButtonData
*,void> aLink
;
67 std::unique_ptr
<SvLBoxButtonData_Impl
> pImpl
;
69 std::vector
<Image
> aBmps
; // indices s. constants BMP_ ....
71 VCL_DLLPRIVATE
void SetWidthAndHeight();
72 VCL_DLLPRIVATE
void InitData( bool _bRadioBtn
, const Control
* pControlForSettings
);
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
<SvLBoxButtonData
*,void>& rLink
) { aLink
=rLink
; }
85 // as buttons are not derived from LinkHdl
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
113 SvLBoxString(const OUString
& rText
);
115 virtual ~SvLBoxString() override
;
117 virtual SvLBoxItemType
GetType() const override
;
118 virtual void InitViewData(SvTreeListBox
* pView
,
119 SvTreeListEntry
* pEntry
,
120 SvViewDataItem
* pViewData
= nullptr) override
;
122 virtual int CalcWidth(const SvTreeListBox
* pView
) const override
;
124 void Emphasize(bool bEmphasize
) { mbEmphasized
= bEmphasize
; }
125 bool IsEmphasized() const { return mbEmphasized
; }
127 const OUString
& GetText() const
131 void SetText(const OUString
& rText
)
136 virtual void Paint(const Point
& rPos
, SvTreeListBox
& rOutDev
,
137 vcl::RenderContext
& rRenderContext
,
138 const SvViewDataEntry
* pView
,
139 const SvTreeListEntry
& rEntry
) override
;
141 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
144 class VCL_DLLPUBLIC SvLBoxButton
: public SvLBoxItem
147 SvLBoxButtonData
* pData
;
148 SvLBoxButtonKind
const eKind
;
149 SvItemStateFlags nItemFlags
;
151 static void ImplAdjustBoxSize( Size
& io_rCtrlSize
, ControlType i_eType
, vcl::RenderContext
const & pRenderContext
);
153 // An SvLBoxButton can be of three different kinds: an
154 // enabled checkbox (the normal kind), a disabled checkbox
155 // (which cannot be modified via UI), or a static image
156 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
158 SvLBoxButton( SvLBoxButtonKind eTheKind
, SvLBoxButtonData
* pBData
);
160 virtual ~SvLBoxButton() override
;
161 virtual void InitViewData(SvTreeListBox
* pView
,
162 SvTreeListEntry
* pEntry
,
163 SvViewDataItem
* pViewData
= nullptr) override
;
165 virtual SvLBoxItemType
GetType() const override
;
166 void ClickHdl( SvTreeListEntry
* );
168 virtual void Paint(const Point
& rPos
,
169 SvTreeListBox
& rOutDev
,
170 vcl::RenderContext
& rRenderContext
,
171 const SvViewDataEntry
* pView
,
172 const SvTreeListEntry
& rEntry
) override
;
174 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
176 SvItemStateFlags
GetButtonFlags() const
180 bool IsStateChecked() const
182 return bool(nItemFlags
& SvItemStateFlags::CHECKED
);
184 bool IsStateUnchecked() const
186 return bool(nItemFlags
& SvItemStateFlags::UNCHECKED
);
188 bool IsStateTristate() const
190 return bool(nItemFlags
& SvItemStateFlags::TRISTATE
);
192 bool IsStateHilighted() const
194 return bool(nItemFlags
& SvItemStateFlags::HILIGHTED
);
196 void SetStateChecked();
197 void SetStateUnchecked();
198 void SetStateTristate();
199 void SetStateHilighted(bool bHilight
);
201 SvLBoxButtonKind
GetKind() const { return eKind
; }
203 // Check whether this button can be modified via UI
204 bool CheckModification() const;
207 inline void SvLBoxButton::SetStateChecked()
209 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
210 nItemFlags
|= SvItemStateFlags::CHECKED
;
213 inline void SvLBoxButton::SetStateUnchecked()
215 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
216 nItemFlags
|= SvItemStateFlags::UNCHECKED
;
218 inline void SvLBoxButton::SetStateTristate()
220 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
221 nItemFlags
|= SvItemStateFlags::TRISTATE
;
223 inline void SvLBoxButton::SetStateHilighted( bool bHilight
)
226 nItemFlags
|= SvItemStateFlags::HILIGHTED
;
228 nItemFlags
&= ~SvItemStateFlags::HILIGHTED
;
231 struct SvLBoxContextBmp_Impl
;
233 class VCL_DLLPUBLIC SvLBoxContextBmp
: public SvLBoxItem
235 std::unique_ptr
<SvLBoxContextBmp_Impl
> m_pImpl
;
237 SvLBoxContextBmp(const Image
& aBmp1
,
241 virtual ~SvLBoxContextBmp() override
;
243 virtual SvLBoxItemType
GetType() const override
;
244 virtual void InitViewData(SvTreeListBox
* pView
,
245 SvTreeListEntry
* pEntry
,
246 SvViewDataItem
* pViewData
= nullptr) override
;
247 virtual void Paint(const Point
& rPos
,
248 SvTreeListBox
& rOutDev
,
249 vcl::RenderContext
& rRenderContext
,
250 const SvViewDataEntry
* pView
,
251 const SvTreeListEntry
& rEntry
) override
;
253 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
255 void SetModeImages(const Image
& rBitmap1
, const Image
& rBitmap2
);
257 inline void SetBitmap1(const Image
& rImage
);
258 inline void SetBitmap2(const Image
& rImage
);
259 inline const Image
& GetBitmap1() const;
260 inline const Image
& GetBitmap2() const;
263 Image
& implGetImageStore(bool bFirst
);
266 inline void SvLBoxContextBmp::SetBitmap1(const Image
& _rImage
)
268 implGetImageStore(true) = _rImage
;
271 inline void SvLBoxContextBmp::SetBitmap2(const Image
& _rImage
)
273 implGetImageStore(false) = _rImage
;
276 inline const Image
& SvLBoxContextBmp::GetBitmap1() const
278 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(true);
282 inline const Image
& SvLBoxContextBmp::GetBitmap2() const
284 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(false);
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */