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 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{
83protected:
84 mutable std::optional<vcl::ControlLayoutData> mxLayoutData;
86
87private:
91
92 SAL_DLLPRIVATE void ImplInitControlData();
93
94 Control (const Control &) = delete;
95 Control & operator= (const Control &) = delete;
96
97protected:
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 virtual bool FocusWindowBelongsToControl(const vcl::Window* pFocusWin) const;
155public:
156 SAL_DLLPRIVATE void ImplClearLayoutData() const;
175 SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect );
176
177public:
178 explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 );
179 virtual ~Control() override;
180 virtual void dispose() override;
181
182 virtual void EnableRTL ( bool bEnable = true ) override;
183
184 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
185 virtual void StateChanged( StateChangedType nStateChange ) override;
186 virtual void Resize() override;
187
188 // invalidates layout data
189 virtual void SetText( const OUString& rStr ) override;
190 // gets the displayed text
191 virtual OUString GetDisplayText() const override;
192 // returns the bounding box for the character at index nIndex (in control coordinates)
193 tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const;
194 // returns the character index for corresponding to rPoint (in control coordinates)
195 // -1 is returned if no character is at that point
196 tools::Long GetIndexForPoint( const Point& rPoint ) const;
197 // returns the interval [start,end] of line nLine
198 // returns [-1,-1] for an invalid line
199 Pair GetLineStartEnd( tools::Long nLine ) const;
212 tools::Long ToRelativeLineIndex( tools::Long nIndex ) const;
213
214 void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
215
218 bool HasControlFocus() const { return mbHasControlFocus; }
219
220 void SetLayoutDataParent( const Control* pParent ) const;
221
222 virtual Size GetOptimalSize() const override;
223
227 void SetReferenceDevice( OutputDevice* _referenceDevice );
228 OutputDevice* GetReferenceDevice() const;
229
230 vcl::Font GetUnzoomedControlPointFont() const;
231 void SetShowAccelerator (bool val);
232
234 virtual void LogicInvalidate( const tools::Rectangle* pRectangle ) override;
235};
236
237#endif // INCLUDED_VCL_CTRL_HXX
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawTextFlags
Definition: ctrl.hxx:82
std::optional< vcl::ControlLayoutData > mxLayoutData
Definition: ctrl.hxx:84
Link< Control &, void > maLoseFocusHdl
Definition: ctrl.hxx:90
VclPtr< OutputDevice > mpReferenceDevice
Definition: ctrl.hxx:85
Control(const Control &)=delete
bool mbHasControlFocus
Definition: ctrl.hxx:88
bool HasControlFocus() const
determines whether the control currently has the focus
Definition: ctrl.hxx:218
void SetLoseFocusHdl(const Link< Control &, void > &rLink)
Definition: ctrl.hxx:214
bool mbShowAccelerator
Definition: ctrl.hxx:89
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