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
25 #include <svtools/svtdllapi.h>
26 #include <tools/link.hxx>
27 #include <vcl/image.hxx>
28 #include <svtools/treelistbox.hxx>
29 #include <o3tl/typed_flags_set.hxx>
31 class SvTreeListEntry
;
45 enum class SvItemStateFlags
55 template<> struct typed_flags
<SvItemStateFlags
> : is_typed_flags
<SvItemStateFlags
, 0x0f> {};
58 struct SvLBoxButtonData_Impl
;
60 class SVT_DLLPUBLIC SvLBoxButtonData
63 Link
<SvLBoxButtonData
*,void> aLink
;
66 std::unique_ptr
<SvLBoxButtonData_Impl
> pImpl
;
68 std::vector
<Image
> aBmps
; // indices s. constants BMP_ ....
70 SVT_DLLPRIVATE
void SetWidthAndHeight();
71 SVT_DLLPRIVATE
void InitData( bool _bRadioBtn
, const Control
* pControlForSettings
);
73 // include creating default images (CheckBox or RadioButton)
74 SvLBoxButtonData( const Control
* pControlForSettings
);
75 SvLBoxButtonData( const Control
* pControlForSettings
, bool _bRadioBtn
);
79 static SvBmp
GetIndex( SvItemStateFlags nItemState
);
82 void SetLink( const Link
<SvLBoxButtonData
*,void>& rLink
) { aLink
=rLink
; }
84 // as buttons are not derived from LinkHdl
87 void StoreButtonState( SvTreeListEntry
* pEntry
);
88 static SvButtonState
ConvertToButtonState( SvItemStateFlags nItemFlags
);
90 SvTreeListEntry
* GetActEntry() const;
92 void SetImage(SvBmp nIndex
, const Image
& aImage
) { aBmps
[static_cast<int>(nIndex
)] = aImage
; }
93 Image
& GetImage(SvBmp nIndex
) { return aBmps
[static_cast<int>(nIndex
)]; }
95 void SetDefaultImages( const Control
* pControlForSettings
);
96 // set images according to the color scheme of the Control
97 // pControlForSettings == NULL: settings are taken from Application
98 bool HasDefaultImages() const;
101 // **********************************************************************
103 class SVT_DLLPUBLIC SvLBoxString
: public SvLBoxItem
109 SvLBoxString(const OUString
& rText
);
111 virtual ~SvLBoxString() override
;
113 virtual SvLBoxItemType
GetType() const override
;
114 virtual void InitViewData(SvTreeListBox
* pView
,
115 SvTreeListEntry
* pEntry
,
116 SvViewDataItem
* pViewData
= nullptr) override
;
118 const OUString
& GetText() const
122 void SetText(const OUString
& rText
)
127 virtual void Paint(const Point
& rPos
, SvTreeListBox
& rOutDev
,
128 vcl::RenderContext
& rRenderContext
,
129 const SvViewDataEntry
* pView
,
130 const SvTreeListEntry
& rEntry
) override
;
132 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
135 class SVT_DLLPUBLIC SvLBoxButton
: public SvLBoxItem
138 SvLBoxButtonData
* pData
;
139 SvLBoxButtonKind
const eKind
;
140 SvItemStateFlags nItemFlags
;
142 static void ImplAdjustBoxSize( Size
& io_rCtrlSize
, ControlType i_eType
, vcl::RenderContext
const & pRenderContext
);
144 // An SvLBoxButton can be of three different kinds: an
145 // enabled checkbox (the normal kind), a disabled checkbox
146 // (which cannot be modified via UI), or a static image
147 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
149 SvLBoxButton( SvLBoxButtonKind eTheKind
, SvLBoxButtonData
* pBData
);
151 virtual ~SvLBoxButton() override
;
152 virtual void InitViewData(SvTreeListBox
* pView
,
153 SvTreeListEntry
* pEntry
,
154 SvViewDataItem
* pViewData
= nullptr) override
;
156 virtual SvLBoxItemType
GetType() const override
;
157 void ClickHdl( SvTreeListEntry
* );
159 virtual void Paint(const Point
& rPos
,
160 SvTreeListBox
& rOutDev
,
161 vcl::RenderContext
& rRenderContext
,
162 const SvViewDataEntry
* pView
,
163 const SvTreeListEntry
& rEntry
) override
;
165 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
167 SvItemStateFlags
GetButtonFlags() const
171 bool IsStateChecked() const
173 return bool(nItemFlags
& SvItemStateFlags::CHECKED
);
175 bool IsStateUnchecked() const
177 return bool(nItemFlags
& SvItemStateFlags::UNCHECKED
);
179 bool IsStateTristate() const
181 return bool(nItemFlags
& SvItemStateFlags::TRISTATE
);
183 bool IsStateHilighted() const
185 return bool(nItemFlags
& SvItemStateFlags::HILIGHTED
);
187 void SetStateChecked();
188 void SetStateUnchecked();
189 void SetStateTristate();
190 void SetStateHilighted(bool bHilight
);
191 void SetStateInvisible();
193 SvLBoxButtonKind
GetKind() const { return eKind
; }
195 // Check whether this button can be modified via UI
196 bool CheckModification() const;
199 inline void SvLBoxButton::SetStateChecked()
201 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
202 nItemFlags
|= SvItemStateFlags::CHECKED
;
205 inline void SvLBoxButton::SetStateUnchecked()
207 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
208 nItemFlags
|= SvItemStateFlags::UNCHECKED
;
210 inline void SvLBoxButton::SetStateTristate()
212 nItemFlags
&= SvItemStateFlags::HILIGHTED
;
213 nItemFlags
|= SvItemStateFlags::TRISTATE
;
215 inline void SvLBoxButton::SetStateHilighted( bool bHilight
)
218 nItemFlags
|= SvItemStateFlags::HILIGHTED
;
220 nItemFlags
&= ~SvItemStateFlags::HILIGHTED
;
223 struct SvLBoxContextBmp_Impl
;
225 class SVT_DLLPUBLIC SvLBoxContextBmp
: public SvLBoxItem
227 std::unique_ptr
<SvLBoxContextBmp_Impl
> m_pImpl
;
229 SvLBoxContextBmp(const Image
& aBmp1
,
233 virtual ~SvLBoxContextBmp() override
;
235 virtual SvLBoxItemType
GetType() const override
;
236 virtual void InitViewData(SvTreeListBox
* pView
,
237 SvTreeListEntry
* pEntry
,
238 SvViewDataItem
* pViewData
= nullptr) override
;
239 virtual void Paint(const Point
& rPos
,
240 SvTreeListBox
& rOutDev
,
241 vcl::RenderContext
& rRenderContext
,
242 const SvViewDataEntry
* pView
,
243 const SvTreeListEntry
& rEntry
) override
;
245 virtual std::unique_ptr
<SvLBoxItem
> Clone(SvLBoxItem
const * pSource
) const override
;
247 void SetModeImages(const Image
& rBitmap1
, const Image
& rBitmap2
);
249 inline void SetBitmap1(const Image
& rImage
);
250 inline void SetBitmap2(const Image
& rImage
);
251 inline const Image
& GetBitmap1() const;
252 inline const Image
& GetBitmap2() const;
255 Image
& implGetImageStore(bool bFirst
);
258 inline void SvLBoxContextBmp::SetBitmap1(const Image
& _rImage
)
260 implGetImageStore(true) = _rImage
;
263 inline void SvLBoxContextBmp::SetBitmap2(const Image
& _rImage
)
265 implGetImageStore(false) = _rImage
;
268 inline const Image
& SvLBoxContextBmp::GetBitmap1() const
270 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(true);
274 inline const Image
& SvLBoxContextBmp::GetBitmap2() const
276 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(false);
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */