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 #pragma once
21 
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
25 
26 #include <memory>
27 #include <vcl/dllapi.h>
28 #include <tools/link.hxx>
29 #include <vcl/image.hxx>
31 #include <o3tl/typed_flags_set.hxx>
32 
33 class SvTreeListEntry;
34 class SvLBoxButton;
35 
36 
37 enum class SvBmp
38 {
39  UNCHECKED = 0,
40  CHECKED = 1,
41  TRISTATE = 2,
42  HIUNCHECKED = 3,
43  HICHECKED = 4,
44  HITRISTATE = 5
45 };
46 
47 enum class SvItemStateFlags
48 {
49  NONE = 0x00,
50  UNCHECKED = 0x01,
51  CHECKED = 0x02,
52  TRISTATE = 0x04,
53  HILIGHTED = 0x08
54 };
55 namespace o3tl
56 {
57  template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
58 }
59 
61 
63 {
64 private:
68  std::unique_ptr<SvLBoxButtonData_Impl> pImpl;
69  bool bDataOk;
70  std::vector<Image> aBmps; // indices s. constants BMP_...
71 
72  VCL_DLLPRIVATE void SetWidthAndHeight();
73  VCL_DLLPRIVATE void InitData( bool _bRadioBtn, const Control* pControlForSettings );
74 public:
75  // include creating default images (CheckBox or RadioButton)
76  SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
77 
79 
80  static SvBmp GetIndex( SvItemStateFlags nItemState );
83  void SetLink( const Link<SvLBoxButtonData*,void>& rLink) { aLink=rLink; }
84  bool IsRadio() const;
85  // as buttons are not derived from LinkHdl
86  void CallLink();
87 
88  void StoreButtonState(SvTreeListEntry* pActEntry, SvLBoxButton* pActBox);
89  static SvButtonState ConvertToButtonState( SvItemStateFlags nItemFlags );
90 
91  SvTreeListEntry* GetActEntry() const;
92  SvLBoxButton* GetActBox() const;
93 
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)]; }
96 
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;
101 };
102 
103 // **********************************************************************
104 
106 {
107 private:
109  bool mbCustom;
110  double mfAlign;
111 protected:
112  OUString maText;
113 
114 public:
115  SvLBoxString(const OUString& rText);
116  SvLBoxString();
117  virtual ~SvLBoxString() override;
118 
119  virtual SvLBoxItemType GetType() const override;
120  virtual void InitViewData(SvTreeListBox* pView,
121  SvTreeListEntry* pEntry,
122  SvViewDataItem* pViewData = nullptr) override;
123 
124  virtual int CalcWidth(const SvTreeListBox* pView) const override;
125 
126  void Align(double fAlign) { mfAlign = fAlign; }
127 
128  void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
129  bool IsEmphasized() const { return mbEmphasized; }
130 
131  void SetCustomRender() { mbCustom = true; }
132 
133  const OUString& GetText() const
134  {
135  return maText;
136  }
137  void SetText(const OUString& rText)
138  {
139  maText = rText;
140  }
141 
142  virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
143  vcl::RenderContext& rRenderContext,
144  const SvViewDataEntry* pView,
145  const SvTreeListEntry& rEntry) override;
146 
147  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
148 };
149 
150 class SvLBoxButton : public SvLBoxItem
151 {
152  bool isVis;
155 
156  static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext const & pRenderContext);
157 public:
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
161  // for that kind).
162  SvLBoxButton( SvLBoxButtonData* pBData );
163  SvLBoxButton();
164  virtual ~SvLBoxButton() override;
165  virtual void InitViewData(SvTreeListBox* pView,
166  SvTreeListEntry* pEntry,
167  SvViewDataItem* pViewData = nullptr) override;
168 
169  virtual SvLBoxItemType GetType() const override;
170  void ClickHdl( SvTreeListEntry* );
171 
172  virtual void Paint(const Point& rPos,
173  SvTreeListBox& rOutDev,
174  vcl::RenderContext& rRenderContext,
175  const SvViewDataEntry* pView,
176  const SvTreeListEntry& rEntry) override;
177 
178  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
179 
181  {
182  return nItemFlags;
183  }
184  bool IsStateChecked() const
185  {
186  return bool(nItemFlags & SvItemStateFlags::CHECKED);
187  }
188  bool IsStateUnchecked() const
189  {
190  return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
191  }
192  bool IsStateTristate() const
193  {
194  return bool(nItemFlags & SvItemStateFlags::TRISTATE);
195  }
196  bool IsStateHilighted() const
197  {
198  return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
199  }
200  void SetStateChecked();
201  void SetStateUnchecked();
202  void SetStateTristate();
203  void SetStateHilighted(bool bHilight);
204 };
205 
207 {
210 }
211 
213 {
216 }
218 {
221 }
222 inline void SvLBoxButton::SetStateHilighted( bool bHilight )
223 {
224  if ( bHilight )
226  else
228 }
229 
230 struct SvLBoxContextBmp_Impl;
231 
233 {
234  std::unique_ptr<SvLBoxContextBmp_Impl> m_pImpl;
235 public:
236  SvLBoxContextBmp(const Image& aBmp1,
237  const Image& aBmp2,
238  bool bExpanded);
240  virtual ~SvLBoxContextBmp() override;
241 
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;
251 
252  virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const * pSource) const override;
253 
254  void SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
255 
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;
260 
261 private:
262  Image& implGetImageStore(bool bFirst);
263 };
264 
265 inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
266 {
267  implGetImageStore(true) = _rImage;
268 }
269 
270 inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
271 {
272  implGetImageStore(false) = _rImage;
273 }
274 
275 inline const Image& SvLBoxContextBmp::GetBitmap1() const
276 {
277  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
278  return rImage;
279 }
280 
281 inline const Image& SvLBoxContextBmp::GetBitmap2() const
282 {
283  Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
284  return rImage;
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long nHeight
Definition: svlbitm.hxx:67
Image & GetImage(SvBmp nIndex)
Definition: svlbitm.hxx:95
bool mbCustom
Definition: svlbitm.hxx:109
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:409
Image & implGetImageStore(bool bFirst)
Definition: svlbitm.cxx:496
std::unique_ptr< SvLBoxButtonData_Impl > pImpl
Definition: svlbitm.hxx:68
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
void SetImage(SvBmp nIndex, const Image &aImage)
Definition: svlbitm.hxx:94
SvItemStateFlags
Definition: svlbitm.hxx:47
double mfAlign
Definition: svlbitm.hxx:110
bool mbEmphasized
Definition: svlbitm.hxx:108
const OUString & GetText() const
Definition: svlbitm.hxx:133
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:270
SvLBoxButtonData * pData
Definition: svlbitm.hxx:153
View-dependent data for a tree list entry created in the virtual function SvTreeListBox::CreateViewDa...
void Align(double fAlign)
Definition: svlbitm.hxx:126
void SetBitmap1(const Image &rImage)
Definition: svlbitm.hxx:265
const Image & GetBitmap2() const
Definition: svlbitm.hxx:281
std::unique_ptr< SvLBoxContextBmp_Impl > m_pImpl
Definition: svlbitm.hxx:234
SvLBoxItemType
bool IsStateHilighted() const
Definition: svlbitm.hxx:196
void SetStateTristate()
Definition: svlbitm.hxx:217
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry) override
Definition: svlbitm.cxx:363
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:70
bool IsEmphasized() const
Definition: svlbitm.hxx:129
SvBmp
Definition: svlbitm.hxx:37
void SetStateUnchecked()
Definition: svlbitm.hxx:212
void SetLink(const Link< SvLBoxButtonData *, void > &rLink)
Definition: svlbitm.hxx:83
virtual void InitViewData(SvTreeListBox *pView, SvTreeListEntry *pEntry, SvViewDataItem *pViewData=nullptr) override
Definition: svlbitm.cxx:438
Link< SvLBoxButtonData *, void > aLink
Definition: svlbitm.hxx:65
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:184
void SetStateHilighted(bool bHilight)
Definition: svlbitm.hxx:222
virtual std::unique_ptr< SvLBoxItem > Clone(SvLBoxItem const *pSource) const override
Definition: svlbitm.cxx:402
SvButtonState
Definition: treelistbox.hxx:57
const Image & GetBitmap1() const
Definition: svlbitm.hxx:275
SvItemStateFlags nItemFlags
Definition: svlbitm.hxx:154
SvItemStateFlags GetButtonFlags() const
Definition: svlbitm.hxx:180
virtual ~SvLBoxButton() override
Definition: svlbitm.cxx:344
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:348
bool IsStateTristate() const
Definition: svlbitm.hxx:192
void ClickHdl(SvTreeListEntry *)
Definition: svlbitm.cxx:353
Definition: ctrl.hxx:33
void Emphasize(bool bEmphasize)
Definition: svlbitm.hxx:128
void SetCustomRender()
Definition: svlbitm.hxx:131
Definition: image.hxx:39
bool IsStateUnchecked() const
Definition: svlbitm.hxx:188
OUString maText
Definition: svlbitm.hxx:112
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
tools::Long nWidth
Definition: svlbitm.hxx:66
void SetStateChecked()
Definition: svlbitm.hxx:206
void SetText(const OUString &rText)
Definition: svlbitm.hxx:137