LibreOffice Module vcl (master)  1
ctrl.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_CTRL_HXX
21 #define INCLUDED_VCL_CTRL_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <tools/link.hxx>
25 #include <tools/gen.hxx>
26 #include <vcl/dllapi.h>
27 #include <vcl/window.hxx>
28 #include <optional>
29 #include <vector>
30 
31 // forward
32 class StyleSettings;
33 class Control;
34 
35 namespace vcl
36 {
37 
39 {
40  // contains the string really displayed
41  // there must be exactly one bounding rectangle in m_aUnicodeBoundRects
42  // for every character in m_aDisplayText
43  OUString m_aDisplayText;
44  // the bounding rectangle of every character
45  // where one character may consist of many glyphs
46  std::vector< tools::Rectangle > m_aUnicodeBoundRects;
47  // start indices of lines
48  std::vector< tools::Long > m_aLineIndices;
49  // notify parent control on destruction
51 
54 
55  tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const;
56  // returns the character index for corresponding to rPoint (in control coordinates)
57  // -1 is returned if no character is at that point
58  tools::Long GetIndexForPoint( const Point& rPoint ) const;
59  // returns the number of lines in the result of GetDisplayText()
60  tools::Long GetLineCount() const;
61  // returns the interval [start,end] of line nLine
62  // returns [-1,-1] for an invalid line
63  ::Pair GetLineStartEnd( tools::Long nLine ) const;
76  tools::Long ToRelativeLineIndex( tools::Long nIndex ) const;
77 };
78 
79 } // namespace vcl
80 
82 {
83 protected:
84  mutable std::optional<vcl::ControlLayoutData> mxLayoutData;
86 
87 private:
91 
92  SAL_DLLPRIVATE void ImplInitControlData();
93 
94  Control (const Control &) = delete;
95  Control & operator= (const Control &) = delete;
96 
97 protected:
98  Control( WindowType nType );
99  virtual void FillLayoutData() const;
100 
101  // helper method for composite controls
102  void AppendLayoutData( const Control& rSubControl ) const;
103 
105  void CreateLayoutData() const;
107  bool HasLayoutData() const;
108 
121  bool ImplCallEventListenersAndHandler(
122  VclEventId nEvent, std::function<void()> const & callHandler
123  );
124 
125  void CallEventListeners( VclEventId nEvent, void* pData = nullptr );
126 
136  tools::Rectangle DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& _rRect,
137  const OUString& _rStr, DrawTextFlags _nStyle,
138  std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText,
139  const Size* i_pDeviceSize = nullptr ) const;
140 
141  tools::Rectangle GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect,
142  const OUString& _rStr, DrawTextFlags _nStyle,
143  Size* o_pDeviceSize = nullptr ) const;
144 
145  virtual const vcl::Font&
146  GetCanonicalFont( const StyleSettings& _rStyle ) const;
147  virtual const Color&
148  GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
149 
150  void ImplInitSettings();
151 
152  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
153 
154 public:
155  SAL_DLLPRIVATE void ImplClearLayoutData() const;
174  SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect );
175 
176 public:
177  explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 );
178  virtual ~Control() override;
179  virtual void dispose() override;
180 
181  virtual void EnableRTL ( bool bEnable = true ) override;
182 
183  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
184  virtual void StateChanged( StateChangedType nStateChange ) override;
185  virtual void Resize() override;
186 
187  // invalidates layout data
188  virtual void SetText( const OUString& rStr ) override;
189  // gets the displayed text
190  virtual OUString GetDisplayText() const override;
191  // returns the bounding box for the character at index nIndex (in control coordinates)
192  tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const;
193  // returns the character index for corresponding to rPoint (in control coordinates)
194  // -1 is returned if no character is at that point
195  tools::Long GetIndexForPoint( const Point& rPoint ) const;
196  // returns the interval [start,end] of line nLine
197  // returns [-1,-1] for an invalid line
198  Pair GetLineStartEnd( tools::Long nLine ) const;
211  tools::Long ToRelativeLineIndex( tools::Long nIndex ) const;
212 
213  void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
214 
217  bool HasControlFocus() const { return mbHasControlFocus; }
218 
219  void SetLayoutDataParent( const Control* pParent ) const;
220 
221  virtual Size GetOptimalSize() const override;
222 
226  void SetReferenceDevice( OutputDevice* _referenceDevice );
227  OutputDevice* GetReferenceDevice() const;
228 
229  vcl::Font GetUnzoomedControlPointFont() const;
230  void SetShowAccelerator (bool val);
231 
232  void LogicMouseButtonDown(const MouseEvent& rMouseEvent) override;
233  void LogicMouseButtonUp(const MouseEvent& rMouseEvent) override;
234  void LogicMouseMove(const MouseEvent& rMouseEvent) override;
235 };
236 
237 #endif // INCLUDED_VCL_CTRL_HXX
238 
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetText(const OUString &rStr)
Definition: window.cxx:3016
VclReferenceBase & operator=(const VclReferenceBase &)=delete
virtual void EnableRTL(bool bEnable=true)
Definition: window3.cxx:216
std::vector< tools::Long > m_aLineIndices
Definition: ctrl.hxx:48
std::optional< vcl::ControlLayoutData > mxLayoutData
Definition: ctrl.hxx:84
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
virtual Size GetOptimalSize() const
Definition: window3.cxx:26
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:137
DrawTextFlags
StateChangedType
Definition: window.hxx:289
std::vector< tools::Rectangle > m_aUnicodeBoundRects
Definition: ctrl.hxx:46
sal_Int64 WinBits
OUString m_aDisplayText
Definition: ctrl.hxx:43
VclEventId
Definition: vclevent.hxx:37
virtual OUString GetDisplayText() const
Definition: window.cxx:3051
bool mbShowAccelerator
Definition: ctrl.hxx:89
VclPtr< OutputDevice > mpReferenceDevice
Definition: ctrl.hxx:85
Link< Control &, void > maLoseFocusHdl
Definition: ctrl.hxx:90
virtual bool EventNotify(NotifyEvent &rNEvt)
Definition: event.cxx:104
bool mbHasControlFocus
Definition: ctrl.hxx:88
virtual void ApplySettings(vcl::RenderContext &rRenderContext)
Definition: window.cxx:3833
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:167
virtual void Resize()
Definition: window.cxx:1825
VclPtr< const Control > m_pParent
Definition: ctrl.hxx:50
virtual void LogicMouseButtonUp(const MouseEvent &)
Same as MouseButtonUp(), but coordinates are in logic unit. used for LOK.
Definition: window.hxx:1122
WindowType
Definition: ctrl.hxx:81
void SetLoseFocusHdl(const Link< Control &, void > &rLink)
Definition: ctrl.hxx:213
bool HasControlFocus() const
determines whether the control currently has the focus
Definition: ctrl.hxx:217
virtual void StateChanged(StateChangedType nStateChange)
Definition: window.cxx:1930
virtual void LogicMouseButtonDown(const MouseEvent &)
Same as MouseButtonDown(), but coordinates are in logic unit. used for LOK.
Definition: window.hxx:1120
virtual void LogicMouseMove(const MouseEvent &)
Same as MouseMove(), but coordinates are in logic unit. used for LOK.
Definition: window.hxx:1124
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: event.cxx:218