LibreOffice Module vcl (master)  1
svlbitm.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #ifndef INCLUDED_VCL_SVLBITM_HXX
22 #define INCLUDED_VCL_SVLBITM_HXX
23 
24 #include <memory>
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>
30 
31 class SvTreeListEntry;
32 class SvLBoxButton;
33 
34 
35 enum class SvBmp
36 {
37  UNCHECKED = 0,
38  CHECKED = 1,
39  TRISTATE = 2,
40  HIUNCHECKED = 3,
41  HICHECKED = 4,
42  HITRISTATE = 5
43 };
44 
45 enum class SvItemStateFlags
46 {
47  NONE = 0x00,
48  UNCHECKED = 0x01,
49  CHECKED = 0x02,
50  TRISTATE = 0x04,
51  HILIGHTED = 0x08
52 };
53 namespace o3tl
54 {
55  template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
56 }
57 
59 
61 {
62 private:
64  long nWidth;
65  long nHeight;
66  std::unique_ptr<SvLBoxButtonData_Impl> pImpl;
67  bool bDataOk;
68  std::vector<Image> aBmps; // indices s. constants BMP_...
69 
70  VCL_DLLPRIVATE void SetWidthAndHeight();
71  VCL_DLLPRIVATE void InitData( bool _bRadioBtn, const Control* pControlForSettings );
72 public:
73  // include creating default images (CheckBox or RadioButton)
74  SvLBoxButtonData( const Control* pControlForSettings );
75  SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
76 
78 
79  static SvBmp GetIndex( SvItemStateFlags nItemState );
80  long Width();
81  long Height();
82  void SetLink( const Link<SvLBoxButtonData*,void>& rLink) { aLink=rLink; }
83  bool IsRadio() const;
84  // as buttons are not derived from LinkHdl
85  void CallLink();
86 
87  void StoreButtonState(SvTreeListEntry* pActEntry, SvLBoxButton* pActBox);
88  static SvButtonState ConvertToButtonState( SvItemStateFlags nItemFlags );
89 
90  SvTreeListEntry* GetActEntry() const;
91  SvLBoxButton* GetActBox() const;
92 
93  void SetImage(SvBmp nIndex, const Image& aImage) { aBmps[static_cast<int>(nIndex)] = aImage; }
94  Image& GetImage(SvBmp nIndex) { return aBmps[static_cast<int>(nIndex)]; }
95 
96  void SetDefaultImages( const Control* pControlForSettings );
97  // set images according to the color scheme of the Control
98  // pControlForSettings == NULL: settings are taken from Application
99  bool HasDefaultImages() const;
100 };
101 
102 // **********************************************************************
103 
105 {
106 private:
108 protected:
109  OUString maText;
110 
111 public:
112  SvLBoxString(const OUString& rText);
113  SvLBoxString();
114  virtual ~SvLBoxString() override;
115 
116  virtual SvLBoxItemType GetType() const override;
117  virtual void InitViewData(SvTreeListBox* pView,
118  SvTreeListEntry* pEntry,
119  SvViewDataItem* pViewData = nullptr) override;
120 
121  virtual int CalcWidth(const SvTreeListBox* pView) const override;
122 
123  void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
124  bool IsEmphasized() const { return mbEmphasized; }
125 
126  const OUString& GetText() const
127  {
128  return maText;
129  }
130  void SetText(const OUString& rText)
131  {
132  maText = rText;
133  }
134 
135  virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
136  vcl::RenderContext& rRenderContext,
137  const SvViewDataEntry* pView,
138  const SvTreeListEntry& rEntry) override;
139 
140  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
141 };
142 
143 class SvLBoxButton : public SvLBoxItem
144 {
145  bool isVis;
148 
149  static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext const & pRenderContext);
150 public:
151  // An SvLBoxButton can be of two different kinds: an
152  // enabled checkbox (the normal kind), or a static image
153  // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
154  // for that kind).
155  SvLBoxButton( SvLBoxButtonData* pBData );
156  SvLBoxButton();
157  virtual ~SvLBoxButton() override;
158  virtual void InitViewData(SvTreeListBox* pView,
159  SvTreeListEntry* pEntry,
160  SvViewDataItem* pViewData = nullptr) override;
161 
162  virtual SvLBoxItemType GetType() const override;
163  void ClickHdl( SvTreeListEntry* );
164 
165  virtual void Paint(const Point& rPos,
166  SvTreeListBox& rOutDev,
167  vcl::RenderContext& rRenderContext,
168  const SvViewDataEntry* pView,
169  const SvTreeListEntry& rEntry) override;
170 
171  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
172 
174  {
175  return nItemFlags;
176  }
177  bool IsStateChecked() const
178  {
179  return bool(nItemFlags & SvItemStateFlags::CHECKED);
180  }
181  bool IsStateUnchecked() const
182  {
183  return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
184  }
185  bool IsStateTristate() const
186  {
187  return bool(nItemFlags & SvItemStateFlags::TRISTATE);
188  }
189  bool IsStateHilighted() const
190  {
191  return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
192  }
193  void SetStateChecked();
194  void SetStateUnchecked();
195  void SetStateTristate();
196  void SetStateHilighted(bool bHilight);
197 };
198 
200 {
203 }
204 
206 {
209 }
211 {
214 }
215 inline void SvLBoxButton::SetStateHilighted( bool bHilight )
216 {
217  if ( bHilight )
219  else
221 }
222 
223 struct SvLBoxContextBmp_Impl;
224 
226 {
227  std::unique_ptr<SvLBoxContextBmp_Impl> m_pImpl;
228 public:
229  SvLBoxContextBmp(const Image& aBmp1,
230  const Image& aBmp2,
231  bool bExpanded);
233  virtual ~SvLBoxContextBmp() override;
234 
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;
244 
245  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
246 
247  void SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
248 
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;
253 
254 private:
255  Image& implGetImageStore(bool bFirst);
256 };
257 
258 inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
259 {
260  implGetImageStore(true) = _rImage;
261 }
262 
263 inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
264 {
265  implGetImageStore(false) = _rImage;
266 }
267 
268 inline const Image& SvLBoxContextBmp::GetBitmap1() const
269 {
270  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
271  return rImage;
272 }
273 
274 inline const Image& SvLBoxContextBmp::GetBitmap2() const
275 {
276  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
277  return rImage;
278 }
279 
280 #endif
281 
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Image & GetImage(SvBmp nIndex)
Definition: svlbitm.hxx:94
virtual std::unique_ptr< SvLBoxItem > Clone(SvLBoxItem const *pSource) const =0
static void ImplAdjustBoxSize(Size &io_rCtrlSize, ControlType i_eType, vcl::RenderContext const &pRenderContext)
Definition: svlbitm.cxx:346
Image & implGetImageStore(bool bFirst)
Definition: svlbitm.cxx:433
std::unique_ptr< SvLBoxButtonData_Impl > pImpl
Definition: svlbitm.hxx:66
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void SetImage(SvBmp nIndex, const Image &aImage)
Definition: svlbitm.hxx:93
SvItemStateFlags
Definition: svlbitm.hxx:45
bool mbEmphasized
Definition: svlbitm.hxx:107
const OUString & GetText() const
Definition: svlbitm.hxx:126
virtual void InitViewData(SvTreeListBox *pView, SvTreeListEntry *pEntry, SvViewDataItem *pViewData=nullptr)=0
virtual int CalcWidth(const SvTreeListBox *pView) const
void SetBitmap2(const Image &rImage)
Definition: svlbitm.hxx:263
SvLBoxButtonData * pData
Definition: svlbitm.hxx:146
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
void SetBitmap1(const Image &rImage)
Definition: svlbitm.hxx:258
const Image & GetBitmap2() const
Definition: svlbitm.hxx:274
std::unique_ptr< SvLBoxContextBmp_Impl > m_pImpl
Definition: svlbitm.hxx:227
SvLBoxItemType
bool IsStateHilighted() const
Definition: svlbitm.hxx:189
void SetStateTristate()
Definition: svlbitm.hxx:210
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry) override
Definition: svlbitm.cxx:300
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry)=0
std::vector< Image > aBmps
Definition: svlbitm.hxx:68
bool IsEmphasized() const
Definition: svlbitm.hxx:124
SvBmp
Definition: svlbitm.hxx:35
void SetStateUnchecked()
Definition: svlbitm.hxx:205
void SetLink(const Link< SvLBoxButtonData *, void > &rLink)
Definition: svlbitm.hxx:82
virtual void InitViewData(SvTreeListBox *pView, SvTreeListEntry *pEntry, SvViewDataItem *pViewData=nullptr) override
Definition: svlbitm.cxx:375
Link< SvLBoxButtonData *, void > aLink
Definition: svlbitm.hxx:63
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
bool IsStateChecked() const
Definition: svlbitm.hxx:177
void SetStateHilighted(bool bHilight)
Definition: svlbitm.hxx:215
virtual std::unique_ptr< SvLBoxItem > Clone(SvLBoxItem const *pSource) const override
Definition: svlbitm.cxx:339
SvButtonState
Definition: treelistbox.hxx:57
const Image & GetBitmap1() const
Definition: svlbitm.hxx:268
SvItemStateFlags nItemFlags
Definition: svlbitm.hxx:147
SvItemStateFlags GetButtonFlags() const
Definition: svlbitm.hxx:173
virtual ~SvLBoxButton() override
Definition: svlbitm.cxx:281
virtual SvLBoxItemType GetType() const =0
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
virtual SvLBoxItemType GetType() const override
Definition: svlbitm.cxx:285
bool IsStateTristate() const
Definition: svlbitm.hxx:185
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:290
Definition: ctrl.hxx:33
void Emphasize(bool bEmphasize)
Definition: svlbitm.hxx:123
Definition: image.hxx:40
bool IsStateUnchecked() const
Definition: svlbitm.hxx:181
OUString maText
Definition: svlbitm.hxx:109
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
void SetStateChecked()
Definition: svlbitm.hxx:199
void SetText(const OUString &rText)
Definition: svlbitm.hxx:130