LibreOffice Module vcl (master)  1
ivctrl.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 #ifndef INCLUDED_VCL_IVCTRL_HXX
21 #define INCLUDED_VCL_IVCTRL_HXX
22 
23 #include <memory>
24 #include <vcl/dllapi.h>
25 #include <vcl/ctrl.hxx>
26 #include <vcl/layout.hxx>
27 #include <tools/link.hxx>
28 #include <vcl/image.hxx>
29 #include <o3tl/deleter.hxx>
30 #include <o3tl/typed_flags_set.hxx>
31 
33 
34 enum class SvxIconViewFlags
35 {
36  NONE = 0x0000,
37  POS_LOCKED = 0x0001,
38  SELECTED = 0x0002,
39  FOCUSED = 0x0004,
40  POS_MOVED = 0x0008, // Moved by Drag and Drop, but not logged
41 };
42 namespace o3tl
43 {
44  template<> struct typed_flags<SvxIconViewFlags> : is_typed_flags<SvxIconViewFlags, 0x000f> {};
45 }
46 
48 {
49  Full = 1, // Enlarge BoundRect southwards
50  Short // Shorten with "..."
51 };
52 
54 {
55  Free, // Free pixel-perfect positioning
56  AutoArrange, // Auto arrange
57 };
58 
60 {
61  Image const aImage;
62 
63  OUString aText;
64  OUString aQuickHelpText;
65  void* pUserData;
66 
67  friend class SvxIconChoiceCtrl_Impl;
68  friend class IcnCursor_Impl;
69  friend class EntryList_Impl;
70  friend class IcnGridMap_Impl;
71 
72  tools::Rectangle aRect; // Bounding-Rectangle of the entry
73  tools::Rectangle aGridRect; // Only valid in Grid-mode
74  sal_Int32 nPos;
75 
76  /*
77  The insert position in the Insertlist is equal to the (sort) order stated at the Insert
78  (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order
79  can differ. The entries will be linked because of this.
80  */
81  SvxIconChoiceCtrlEntry* pblink; // backward (linker neighbour)
82  SvxIconChoiceCtrlEntry* pflink; // forward (rechter neighbour)
83 
85  sal_uInt16 nX,nY; // for keyboard control
87 
88  void ClearFlags( SvxIconViewFlags nMask ) { nFlags &= ~nMask; }
89  void SetFlags( SvxIconViewFlags nMask ) { nFlags |= nMask; }
90  void AssignFlags( SvxIconViewFlags _nFlags ) { nFlags = _nFlags; }
91 
92  // set left neighbour (A <-> B ==> A <-> this <-> B)
94  {
95  pA->pflink->pblink = this; // X <- B
96  this->pflink = pA->pflink; // X -> B
97  this->pblink = pA; // A <- X
98  pA->pflink = this; // A -> X
99  }
100  // Unlink (A <-> this <-> B ==> A <-> B)
101  void Unlink()
102  {
103  this->pblink->pflink = this->pflink;
104  this->pflink->pblink = this->pblink;
105  this->pflink = nullptr;
106  this->pblink = nullptr;
107  }
108 
109 public:
110  SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage );
111 
112  const Image& GetImage () const { return aImage; }
113  void SetText ( const OUString& rText ) { aText = rText; }
114  const OUString& GetText () const { return aText; }
115  OUString VCL_DLLPUBLIC GetDisplayText() const;
116  void SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; }
117  const OUString& GetQuickHelpText() const { return aQuickHelpText; }
118  void SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
119  void* GetUserData () { return pUserData; }
120 
122  SvxIconViewFlags GetFlags() const { return nFlags; }
123  bool IsSelected() const { return bool(nFlags & SvxIconViewFlags::SELECTED); }
124  bool IsFocused() const { return bool(nFlags & SvxIconViewFlags::FOCUSED); }
125  bool IsPosLocked() const { return bool(nFlags & SvxIconViewFlags::POS_LOCKED); }
126 };
127 
129 {
130  long nWidth;
131 
132 public:
134  nWidth( 100 ) {}
136 
137  void SetWidth( long nWd ) { nWidth = nWd; }
138  long GetWidth() const { return nWidth; }
139 };
140 
141 
142 /*
143  Window-Bits:
144  WB_ICON // Text beneath the icon
145  WB_SMALL_ICON // Text right to the icon, position does not mind
146  WB_DETAILS // Text right to the icon, limited positioning
147  WB_BORDER
148  WB_NOHIDESELECTION // Draw selection inactively, if not focused.
149  WB_NOHSCROLL
150  WB_NOVSCROLL
151  WB_NOSELECTION
152  WB_SMART_ARRANGE // Keep Visible-Area at arrange
153  WB_ALIGN_TOP // Align line vy line LTR
154  WB_ALIGN_LEFT // Align columns from top to bottom
155  WB_NODRAGSELECTION // No selection with tracking rectangle
156  WB_NOCOLUMNHEADER // No Headerbar in Details view (Headerbar not implemented)
157  WB_NOPOINTERFOCUS // No GrabFocus at MouseButtonDown
158  WB_HIGHLIGHTFRAME // The entry beneath the mouse will be highlighted
159  WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously
160 */
161 
162 #define WB_ICON WB_RECTSTYLE
163 #define WB_SMALLICON WB_SMALLSTYLE
164 #define WB_DETAILS WB_VCENTER
165 #define WB_NOHSCROLL WB_SPIN
166 #define WB_NOVSCROLL WB_DRAG
167 #define WB_NOSELECTION WB_REPEAT
168 #define WB_NODRAGSELECTION WB_PATHELLIPSIS
169 #define WB_SMART_ARRANGE 0x01000000 // used to be WB_PASSWORD
170 #define WB_ALIGN_TOP WB_TOP
171 #define WB_ALIGN_LEFT WB_LEFT
172 #define WB_NOCOLUMNHEADER WB_CENTER
173 #define WB_HIGHLIGHTFRAME WB_IGNORETAB
174 #define WB_NOASYNCSELECTHDL WB_NOLABEL
175 
176 class MnemonicGenerator;
177 
179 {
181 
183  std::unique_ptr<SvxIconChoiceCtrl_Impl, o3tl::default_delete<SvxIconChoiceCtrl_Impl>> _pImpl;
184 
185 protected:
186 
187  virtual void KeyInput( const KeyEvent& rKEvt ) override;
188  virtual void Command( const CommandEvent& rCEvt ) override;
189  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
190  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
191  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
192  virtual void MouseMove( const MouseEvent& rMEvt ) override;
193  virtual void Resize() override;
194  virtual void GetFocus() override;
195  virtual void LoseFocus() override;
196  void ClickIcon();
197  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
198  virtual void RequestHelp( const HelpEvent& rHEvt ) override;
199  static void DrawEntryImage(
200  SvxIconChoiceCtrlEntry const * pEntry,
201  const Point& rPos,
202  OutputDevice& rDev );
203 
204  static OUString GetEntryText( SvxIconChoiceCtrlEntry const * pEntry );
205 
206  virtual void FillLayoutData() const override;
207 
208  void CallImplEventListeners(VclEventId nEvent, void* pData);
209 
210 public:
211 
212  SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle );
213  virtual ~SvtIconChoiceCtrl() override;
214  virtual void dispose() override;
215 
216  WinBits GetStyle() const;
217 
218  void SetChoiceWithCursor();
219 
220  void SetFont( const vcl::Font& rFont );
221  void SetPointFont( const vcl::Font& rFont );
222 
223  void SetClickHdl( const Link<SvtIconChoiceCtrl*,void>& rLink ) { _aClickIconHdl = rLink; }
224  const Link<SvtIconChoiceCtrl*,void>& GetClickHdl() const { return _aClickIconHdl; }
225 
227  void SetBackground( const Wallpaper& rWallpaper );
228 
229  void ArrangeIcons();
230 
231 
232  SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
233  const Image& rImage);
234 
235  void RemoveEntry(sal_Int32 nEntryListPos);
236 
244  void CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
245 
246  bool DoKeyInput( const KeyEvent& rKEvt );
247 
248  sal_Int32 GetEntryCount() const;
249  SvxIconChoiceCtrlEntry* GetEntry( sal_Int32 nPos ) const;
250  sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const;
251  using Window::SetCursor;
252  void SetCursor( SvxIconChoiceCtrlEntry* pEntry );
254 
255  // Re-calculation of cached view-data and invalidation of those in the view
256  void InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
257 
258  // Entry is selected, if the BoundRect is selected
259  SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel ) const;
260 
261  // sal_uLong is the position of the selected element in the list
262  SvxIconChoiceCtrlEntry* GetSelectedEntry() const;
263 
264 #ifdef DBG_UTIL
266 #endif
267 
268  void SetSelectionMode( SelectionMode eMode );
269 
270  tools::Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
271  tools::Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
272 
273  void SetNoSelection();
274 
275  // ACCESSIBILITY ==========================================================
276 
278  virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
279 };
280 
281 struct VerticalTabPageData;
282 
283 class VerticalTabControl final : public VclHBox
284 {
287 
288  std::vector<std::unique_ptr<VerticalTabPageData>> maPageList;
290 
293 
294  DECL_LINK(ChosePageHdl_Impl, SvtIconChoiceCtrl*, void);
295 
296  void ActivatePage();
297  bool DeactivatePage();
298 
299  VerticalTabPageData* GetPageData(const OString& rId) const;
301 
302 public:
304  virtual ~VerticalTabControl() override;
305  virtual void dispose() override;
306 
307  sal_uInt16 GetPageCount() const { return m_xChooser->GetEntryCount(); }
308 
309  OString GetCurPageId() const { return m_sCurrentPageId; }
310  void SetCurPageId(const OString& rId);
311 
312  sal_uInt16 GetPagePos(const OString& rPageId) const;
313  OString GetPageId(sal_uInt16 nIndex) const;
314  VclPtr<vcl::Window> GetPage(const OString& rPageId);
315 
316  void RemovePage(const OString& rPageId);
317  void InsertPage(const OString& rPageId, const OUString& rLabel, const Image& rImage, const OUString& rTooltip, VclPtr<vcl::Window> xPage);
318 
319  void SetActivatePageHdl( const Link<VerticalTabControl*,void>& rLink ) { m_aActivateHdl = rLink; }
320  void SetDeactivatePageHdl( const Link<VerticalTabControl*, bool>& rLink ) { m_aDeactivateHdl = rLink; }
321 
322  OUString GetPageText(const OString& rPageId) const;
323  void SetPageText(const OString& rPageId, const OUString& rText);
324 
325  vcl::Window* GetPageParent() { return m_xBox.get(); }
326 };
327 
328 #endif // INCLUDED_VCL_IVCTRL_HXX
329 
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Link< SvtIconChoiceCtrl *, void > _aClickIconHdl
Definition: ivctrl.hxx:182
void AssignFlags(SvxIconViewFlags _nFlags)
Definition: ivctrl.hxx:90
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:413
OString GetCurPageId() const
Definition: ivctrl.hxx:309
VerticalTabControl(vcl::Window *pParent)
Definition: ivctrl.cxx:442
void SetWidth(long nWd)
Definition: ivctrl.hxx:137
sal_uInt16 GetPagePos(const OString &rPageId) const
Definition: ivctrl.cxx:590
SvxIconChoiceCtrlEntry * GetEntry(const Point &rDocPos, bool bHit=false)
Definition: imivctl1.cxx:1588
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
DECL_LINK(ChosePageHdl_Impl, SvtIconChoiceCtrl *, void)
Image const aImage
Definition: ivctrl.hxx:61
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
SelectionMode
Definition: vclenum.hxx:26
SvxIconChoiceCtrlEntry * pflink
Definition: ivctrl.hxx:82
long GetWidth() const
Definition: ivctrl.hxx:138
virtual ~VerticalTabControl() override
Definition: ivctrl.cxx:462
bool IsSelected() const
Definition: ivctrl.hxx:123
virtual void MouseButtonUp(const MouseEvent &rMEvt)
Definition: mouse.cxx:420
SvxIconViewFlags nFlags
Definition: ivctrl.hxx:86
std::unique_ptr< SvxIconChoiceCtrl_Impl, o3tl::default_delete< SvxIconChoiceCtrl_Impl > > _pImpl
Definition: ivctrl.hxx:183
SvxIconChoiceCtrlEntry * pblink
Definition: ivctrl.hxx:81
sal_Int64 WinBits
tools::Rectangle aRect
Definition: ivctrl.hxx:72
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
VerticalTabPageData * GetPageData(const OString &rId) const
Definition: ivctrl.cxx:510
void SetBackground()
void SetQuickHelpText(const OUString &rText)
Definition: ivctrl.hxx:116
void SetCurPageId(const OString &rId)
Definition: ivctrl.cxx:524
const OUString & GetQuickHelpText() const
Definition: ivctrl.hxx:117
void SetEntryTextMode(SvxIconChoiceCtrlTextMode, SvxIconChoiceCtrlEntry *pEntry)
Definition: imivctl1.cxx:2513
VclPtr< VclVBox > m_xBox
Definition: ivctrl.hxx:286
void SetUserData(void *_pUserData)
Definition: ivctrl.hxx:118
VclEventId
Definition: vclevent.hxx:41
size_t GetEntryCount() const
Definition: imivctl.hxx:383
void SetFlags(SvxIconViewFlags nMask)
Definition: ivctrl.hxx:89
sal_Int32 GetEntryCount() const
Definition: ivctrl.cxx:249
tools::Rectangle aGridRect
Definition: ivctrl.hxx:73
void SetPageText(const OString &rPageId, const OUString &rText)
Definition: ivctrl.cxx:614
void RemovePage(const OString &rPageId)
Definition: ivctrl.cxx:574
void ClearFlags(SvxIconViewFlags nMask)
Definition: ivctrl.hxx:88
VclPtr< vcl::Window > GetPage(const OString &rPageId)
Definition: ivctrl.cxx:598
OUString GetPageText(const OString &rPageId) const
Definition: ivctrl.cxx:606
OString m_sCurrentPageId
Definition: ivctrl.hxx:289
SvxIconViewFlags GetFlags() const
Definition: ivctrl.hxx:122
OUString aQuickHelpText
Definition: ivctrl.hxx:64
VclPtr< SvtIconChoiceCtrl > m_xChooser
Definition: ivctrl.hxx:285
void ActivatePage()
Definition: ivctrl.cxx:486
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
SvxIconChoiceCtrlTextMode eTextMode
Definition: ivctrl.hxx:84
void SetClickHdl(const Link< SvtIconChoiceCtrl *, void > &rLink)
Definition: ivctrl.hxx:223
SvxIconChoiceCtrlTextMode GetTextMode() const
Definition: ivctrl.hxx:121
vcl::Cursor * GetCursor() const
Definition: window2.cxx:1192
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
SvxIconViewFlags
Definition: ivctrl.hxx:34
void InsertPage(const OString &rPageId, const OUString &rLabel, const Image &rImage, const OUString &rTooltip, VclPtr< vcl::Window > xPage)
Definition: ivctrl.cxx:556
virtual void LoseFocus()
Definition: window.cxx:1818
void InvalidateEntry(SvxIconChoiceCtrlEntry *)
Definition: imivctl1.cxx:2611
void SetBacklink(SvxIconChoiceCtrlEntry *pA)
Definition: ivctrl.hxx:93
const Link< SvtIconChoiceCtrl *, void > & GetClickHdl() const
Definition: ivctrl.hxx:224
void SetPointFont(vcl::RenderContext &rRenderContext, const vcl::Font &rFont)
Definition: window.cxx:2136
void RemoveEntry(size_t nPos)
Definition: imivctl1.cxx:248
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1768
SvxIconChoiceCtrlTextMode
Definition: ivctrl.hxx:47
friend class EntryList_Impl
Definition: ivctrl.hxx:69
virtual void Resize() override
Definition: ctrl.cxx:74
Definition: ctrl.hxx:33
virtual void GetFocus()
Definition: window.cxx:1804
bool IsFocused() const
Definition: ivctrl.hxx:124
void SetCursor(vcl::Cursor *pCursor)
Definition: window.cxx:3017
void SetFont(const vcl::Font &rNewFont)
void SetActivatePageHdl(const Link< VerticalTabControl *, void > &rLink)
Definition: ivctrl.hxx:319
Definition: image.hxx:40
void CreateAutoMnemonics(MnemonicGenerator *_pGenerator)
Definition: imivctl1.cxx:255
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1013
Link< VerticalTabControl *, bool > m_aDeactivateHdl
Definition: ivctrl.hxx:292
void InsertEntry(std::unique_ptr< SvxIconChoiceCtrlEntry >, size_t nPos)
Definition: imivctl1.cxx:210
void SetDeactivatePageHdl(const Link< VerticalTabControl *, bool > &rLink)
Definition: ivctrl.hxx:320
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
virtual void MouseMove(const MouseEvent &rMEvt)
Definition: mouse.cxx:407
sal_Int32 GetEntryListPos(SvxIconChoiceCtrlEntry const *) const
Definition: imivctl1.cxx:2679
WinBits GetStyle() const
Definition: window2.cxx:942
const Image & GetImage() const
Definition: ivctrl.hxx:112
OString GetPageId(sal_uInt16 nIndex) const
Definition: ivctrl.cxx:551
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1886
const OUString & GetText() const
Definition: ivctrl.hxx:114
void SetSelectionMode(SelectionMode eMode)
Definition: imivctl.hxx:393
Link< VerticalTabControl *, void > m_aActivateHdl
Definition: ivctrl.hxx:291
virtual void RequestHelp(const HelpEvent &rHEvt)
Definition: window.cxx:1832
bool IsPosLocked() const
Definition: ivctrl.hxx:125
SvxIconChoiceCtrlEntry(const OUString &rText, const Image &rImage)
Definition: ivctrl.cxx:39
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ivctrl.cxx:467
SvxIconChoiceCtrlPositionMode
Definition: ivctrl.hxx:53
void SetText(const OUString &rText)
Definition: ivctrl.hxx:113
OUString VCL_DLLPUBLIC GetDisplayText() const
Definition: ivctrl.cxx:54
sal_uInt16 GetPageCount() const
Definition: ivctrl.hxx:307
vcl::Window * GetPageParent()
Definition: ivctrl.hxx:325
std::vector< std::unique_ptr< VerticalTabPageData > > maPageList
Definition: ivctrl.hxx:288
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
bool DeactivatePage()
Definition: ivctrl.cxx:491