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
32class StyleSettings;
33class Control;
34
35namespace 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
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 interval [start,end] of line nLine
60 // returns [-1,-1] for an invalid line
61 ::Pair GetLineStartEnd( tools::Long nLine ) const;
74 tools::Long ToRelativeLineIndex( tools::Long nIndex ) const;
75};
76
77} // namespace vcl
78
80{
81protected:
82 mutable std::optional<vcl::ControlLayoutData> mxLayoutData;
84
85private:
89
90 SAL_DLLPRIVATE void ImplInitControlData();
91
92 Control (const Control &) = delete;
93 Control & operator= (const Control &) = delete;
94
95protected:
96 Control( WindowType nType );
97 virtual void FillLayoutData() const;
98
99 // helper method for composite controls
100 void AppendLayoutData( const Control& rSubControl ) const;
101
103 void CreateLayoutData() const;
105 bool HasLayoutData() const;
106
119 bool ImplCallEventListenersAndHandler(
120 VclEventId nEvent, std::function<void()> const & callHandler
121 );
122
123 void CallEventListeners( VclEventId nEvent, void* pData = nullptr );
124
134 tools::Rectangle DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& _rRect,
135 const OUString& _rStr, DrawTextFlags _nStyle,
136 std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText,
137 const Size* i_pDeviceSize = nullptr ) const;
138
139 tools::Rectangle GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect,
140 const OUString& _rStr, DrawTextFlags _nStyle,
141 Size* o_pDeviceSize = nullptr ) const;
142
143 virtual const vcl::Font&
144 GetCanonicalFont( const StyleSettings& _rStyle ) const;
145 virtual const Color&
146 GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
147
148 void ImplInitSettings();
149
150 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
151
152 virtual bool FocusWindowBelongsToControl(const vcl::Window* pFocusWin) const;
153public:
154 SAL_DLLPRIVATE void ImplClearLayoutData() const;
173 SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect );
174
175public:
176 explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 );
177 virtual ~Control() override;
178 virtual void dispose() override;
179
180 virtual void EnableRTL ( bool bEnable = true ) override;
181
182 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
183 virtual void StateChanged( StateChangedType nStateChange ) override;
184 virtual void Resize() override;
185
186 // invalidates layout data
187 virtual void SetText( const OUString& rStr ) override;
188 // gets the displayed text
189 virtual OUString GetDisplayText() const override;
190 // returns the bounding box for the character at index nIndex (in control coordinates)
191 tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const;
192 // returns the character index for corresponding to rPoint (in control coordinates)
193 // -1 is returned if no character is at that point
194 tools::Long GetIndexForPoint( const Point& rPoint ) const;
195 // returns the interval [start,end] of line nLine
196 // returns [-1,-1] for an invalid line
197 Pair GetLineStartEnd( tools::Long nLine ) const;
210 tools::Long ToRelativeLineIndex( tools::Long nIndex ) const;
211
212 void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
213
216 bool HasControlFocus() const { return mbHasControlFocus; }
217
218 void SetLayoutDataParent( const Control* pParent ) const;
219
220 virtual Size GetOptimalSize() const override;
221
225 void SetReferenceDevice( OutputDevice* _referenceDevice );
226 OutputDevice* GetReferenceDevice() const;
227
228 vcl::Font GetUnzoomedControlPointFont() const;
229 void SetShowAccelerator (bool val);
230
232 virtual void LogicInvalidate( const tools::Rectangle* pRectangle ) override;
233};
234
235#endif // INCLUDED_VCL_CTRL_HXX
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawTextFlags
Definition: ctrl.hxx:80
std::optional< vcl::ControlLayoutData > mxLayoutData
Definition: ctrl.hxx:82
Link< Control &, void > maLoseFocusHdl
Definition: ctrl.hxx:88
VclPtr< OutputDevice > mpReferenceDevice
Definition: ctrl.hxx:83
Control(const Control &)=delete
bool mbHasControlFocus
Definition: ctrl.hxx:86
bool HasControlFocus() const
determines whether the control currently has the focus
Definition: ctrl.hxx:216
void SetLoseFocusHdl(const Link< Control &, void > &rLink)
Definition: ctrl.hxx:212
bool mbShowAccelerator
Definition: ctrl.hxx:87
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
virtual void SetText(const OUString &rStr) override
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void dispose()
long Long
std::vector< tools::Rectangle > m_aUnicodeBoundRects
Definition: ctrl.hxx:46
std::vector< tools::Long > m_aLineIndices
Definition: ctrl.hxx:48
VclPtr< const Control > m_pParent
Definition: ctrl.hxx:50
OUString m_aDisplayText
Definition: ctrl.hxx:43
VclEventId
Definition: vclevent.hxx:38
StateChangedType
Definition: window.hxx:291
sal_Int64 WinBits
Definition: wintypes.hxx:109
WindowType
Definition: wintypes.hxx:27