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  bool mbCustom;
109  double mfAlign;
110 protected:
111  OUString maText;
112 
113 public:
114  SvLBoxString(const OUString& rText);
115  SvLBoxString();
116  virtual ~SvLBoxString() override;
117 
118  virtual SvLBoxItemType GetType() const override;
119  virtual void InitViewData(SvTreeListBox* pView,
120  SvTreeListEntry* pEntry,
121  SvViewDataItem* pViewData = nullptr) override;
122 
123  virtual int CalcWidth(const SvTreeListBox* pView) const override;
124 
125  void Align(double fAlign) { mfAlign = fAlign; }
126 
127  void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
128  bool IsEmphasized() const { return mbEmphasized; }
129 
130  void SetCustomRender() { mbCustom = true; }
131 
132  const OUString& GetText() const
133  {
134  return maText;
135  }
136  void SetText(const OUString& rText)
137  {
138  maText = rText;
139  }
140 
141  virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
142  vcl::RenderContext& rRenderContext,
143  const SvViewDataEntry* pView,
144  const SvTreeListEntry& rEntry) override;
145 
146  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
147 };
148 
149 class SvLBoxButton : public SvLBoxItem
150 {
151  bool isVis;
154 
155  static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext const & pRenderContext);
156 public:
157  // An SvLBoxButton can be of two different kinds: an
158  // enabled checkbox (the normal kind), or a static image
159  // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
160  // for that kind).
161  SvLBoxButton( SvLBoxButtonData* pBData );
162  SvLBoxButton();
163  virtual ~SvLBoxButton() override;
164  virtual void InitViewData(SvTreeListBox* pView,
165  SvTreeListEntry* pEntry,
166  SvViewDataItem* pViewData = nullptr) override;
167 
168  virtual SvLBoxItemType GetType() const override;
169  void ClickHdl( SvTreeListEntry* );
170 
171  virtual void Paint(const Point& rPos,
172  SvTreeListBox& rOutDev,
173  vcl::RenderContext& rRenderContext,
174  const SvViewDataEntry* pView,
175  const SvTreeListEntry& rEntry) override;
176 
177  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
178 
180  {
181  return nItemFlags;
182  }
183  bool IsStateChecked() const
184  {
185  return bool(nItemFlags & SvItemStateFlags::CHECKED);
186  }
187  bool IsStateUnchecked() const
188  {
189  return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
190  }
191  bool IsStateTristate() const
192  {
193  return bool(nItemFlags & SvItemStateFlags::TRISTATE);
194  }
195  bool IsStateHilighted() const
196  {
197  return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
198  }
199  void SetStateChecked();
200  void SetStateUnchecked();
201  void SetStateTristate();
202  void SetStateHilighted(bool bHilight);
203 };
204 
206 {
209 }
210 
212 {
215 }
217 {
220 }
221 inline void SvLBoxButton::SetStateHilighted( bool bHilight )
222 {
223  if ( bHilight )
225  else
227 }
228 
229 struct SvLBoxContextBmp_Impl;
230 
232 {
233  std::unique_ptr<SvLBoxContextBmp_Impl> m_pImpl;
234 public:
235  SvLBoxContextBmp(const Image& aBmp1,
236  const Image& aBmp2,
237  bool bExpanded);
239  virtual ~SvLBoxContextBmp() override;
240 
241  virtual SvLBoxItemType GetType() const override;
242  virtual void InitViewData(SvTreeListBox* pView,
243  SvTreeListEntry* pEntry,
244  SvViewDataItem* pViewData = nullptr) override;
245  virtual void Paint(const Point& rPos,
246  SvTreeListBox& rOutDev,
247  vcl::RenderContext& rRenderContext,
248  const SvViewDataEntry* pView,
249  const SvTreeListEntry& rEntry) override;
250 
251  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
252 
253  void SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
254 
255  inline void SetBitmap1(const Image& rImage);
256  inline void SetBitmap2(const Image& rImage);
257  inline const Image& GetBitmap1() const;
258  inline const Image& GetBitmap2() const;
259 
260 private:
261  Image& implGetImageStore(bool bFirst);
262 };
263 
264 inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
265 {
266  implGetImageStore(true) = _rImage;
267 }
268 
269 inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
270 {
271  implGetImageStore(false) = _rImage;
272 }
273 
274 inline const Image& SvLBoxContextBmp::GetBitmap1() const
275 {
276  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
277  return rImage;
278 }
279 
280 inline const Image& SvLBoxContextBmp::GetBitmap2() const
281 {
282  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
283  return rImage;
284 }
285 
286 #endif
287 
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Image & GetImage(SvBmp nIndex)
Definition: svlbitm.hxx:94
bool mbCustom
Definition: svlbitm.hxx:108
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:417
Image & implGetImageStore(bool bFirst)
Definition: svlbitm.cxx:504
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
double mfAlign
Definition: svlbitm.hxx:109
bool mbEmphasized
Definition: svlbitm.hxx:107
const OUString & GetText() const
Definition: svlbitm.hxx:132
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:269
SvLBoxButtonData * pData
Definition: svlbitm.hxx:152
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
void Align(double fAlign)
Definition: svlbitm.hxx:125
void SetBitmap1(const Image &rImage)
Definition: svlbitm.hxx:264
const Image & GetBitmap2() const
Definition: svlbitm.hxx:280
std::unique_ptr< SvLBoxContextBmp_Impl > m_pImpl
Definition: svlbitm.hxx:233
SvLBoxItemType
bool IsStateHilighted() const
Definition: svlbitm.hxx:195
void SetStateTristate()
Definition: svlbitm.hxx:216
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry) override
Definition: svlbitm.cxx:371
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:128
SvBmp
Definition: svlbitm.hxx:35
void SetStateUnchecked()
Definition: svlbitm.hxx:211
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:446
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:302
bool IsStateChecked() const
Definition: svlbitm.hxx:183
void SetStateHilighted(bool bHilight)
Definition: svlbitm.hxx:221
virtual std::unique_ptr< SvLBoxItem > Clone(SvLBoxItem const *pSource) const override
Definition: svlbitm.cxx:410
SvButtonState
Definition: treelistbox.hxx:57
const Image & GetBitmap1() const
Definition: svlbitm.hxx:274
SvItemStateFlags nItemFlags
Definition: svlbitm.hxx:153
SvItemStateFlags GetButtonFlags() const
Definition: svlbitm.hxx:179
virtual ~SvLBoxButton() override
Definition: svlbitm.cxx:352
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:356
bool IsStateTristate() const
Definition: svlbitm.hxx:191
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:361
Definition: ctrl.hxx:33
void Emphasize(bool bEmphasize)
Definition: svlbitm.hxx:127
void SetCustomRender()
Definition: svlbitm.hxx:130
Definition: image.hxx:40
bool IsStateUnchecked() const
Definition: svlbitm.hxx:187
OUString maText
Definition: svlbitm.hxx:111
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
void SetStateChecked()
Definition: svlbitm.hxx:205
void SetText(const OUString &rText)
Definition: svlbitm.hxx:136