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 .
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
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
;
47 enum class SvItemStateFlags
57 template<> struct typed_flags
<SvItemStateFlags
> : is_typed_flags
<SvItemStateFlags
, 0x0f> {};
60 struct SvLBoxButtonData_Impl
;
62 class SvLBoxButtonData
65 Link
<SvLBoxButtonData
*,void> aLink
;
68 std::unique_ptr
<SvLBoxButtonData_Impl
> pImpl
;
70 std::vector
<Image
> aBmps
; // indices s. constants BMP_...
72 void SetWidthAndHeight();
73 void InitData( bool _bRadioBtn
, const Control
* pControlForSettings
);
75 // include creating default images (CheckBox or RadioButton)
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
115 SvLBoxString(OUString aText
);
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
137 void SetText(const OUString
& 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
153 SvLBoxButtonData
* pData
;
154 SvItemStateFlags nItemFlags
;
156 static void ImplAdjustBoxSize( Size
& io_rCtrlSize
, ControlType i_eType
, vcl::RenderContext
const & pRenderContext
);
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
162 SvLBoxButton( SvLBoxButtonData
* pBData
);
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
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
)
225 nItemFlags
|= SvItemStateFlags::HIGHLIGHTED
;
227 nItemFlags
&= ~SvItemStateFlags::HIGHLIGHTED
;
230 struct SvLBoxContextBmp_Impl
;
232 class VCL_DLLPUBLIC SvLBoxContextBmp
: public SvLBoxItem
234 std::unique_ptr
<SvLBoxContextBmp_Impl
> m_pImpl
;
236 SvLBoxContextBmp(const Image
& aBmp1
,
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;
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);
281 inline const Image
& SvLBoxContextBmp::GetBitmap2() const
283 Image
& rImage
= const_cast<SvLBoxContextBmp
*>(this)->implGetImageStore(false);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */