1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_CTRL_HXX
21 #define INCLUDED_VCL_CTRL_HXX
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>
38 struct VCL_DLLPUBLIC ControlLayoutData
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
50 VclPtr
<const Control
> m_pParent
;
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;
64 /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
66 This is equivalent to getting the line start/end pairs with
67 GetLineStartEnd until the index lies within [start,end] of a line
70 the absolute index inside the display text to be changed to a relative index
73 the relative index inside the displayed line or -1 if the absolute index does
76 tools::Long
ToRelativeLineIndex( tools::Long nIndex
) const;
81 class VCL_DLLPUBLIC Control
: public vcl::Window
84 mutable std::optional
<vcl::ControlLayoutData
> mxLayoutData
;
85 VclPtr
<OutputDevice
> mpReferenceDevice
;
88 bool mbHasControlFocus
;
89 bool mbShowAccelerator
;
90 Link
<Control
&,void> maLoseFocusHdl
;
92 SAL_DLLPRIVATE
void ImplInitControlData();
94 Control (const Control
&) = delete;
95 Control
& operator= (const Control
&) = delete;
98 Control( WindowType nType
);
99 virtual void FillLayoutData() const;
101 // helper method for composite controls
102 void AppendLayoutData( const Control
& rSubControl
) const;
104 /// creates the mpData->mpLayoutData structure
105 void CreateLayoutData() const;
106 /// determines whether we currently have layout data
107 bool HasLayoutData() const;
109 /** this calls both our event listeners, and a specified handler
111 If the Control instance is destroyed during any of those calls, the
112 method properly handles this (in particular, it doesn't crash :)
115 the event to notify to our event listeners
117 the lambda function that calls the handler
119 if the Control instance has been destroyed in any of the call
121 bool ImplCallEventListenersAndHandler(
122 VclEventId nEvent
, std::function
<void()> const & callHandler
125 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
127 /** draws the given text onto the given device
129 If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
130 the text will be rendered according to the metrics at the reference device.
132 return will contain the result of a GetTextRect call (either directly
133 at the target device, or taking the reference device into account) when
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;
141 tools::Rectangle
GetControlTextRect( OutputDevice
& _rTargetDevice
, const tools::Rectangle
& rRect
,
142 const OUString
& _rStr
, DrawTextFlags _nStyle
,
143 Size
* o_pDeviceSize
= nullptr ) const;
145 virtual const vcl::Font
&
146 GetCanonicalFont( const StyleSettings
& _rStyle
) const;
148 GetCanonicalTextColor( const StyleSettings
& _rStyle
) const;
150 void ImplInitSettings();
152 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
154 virtual bool FocusWindowBelongsToControl(const vcl::Window
* pFocusWin
) const;
156 SAL_DLLPRIVATE
void ImplClearLayoutData() const;
157 /** draws a frame around the give rectangle, onto the given device
159 only to be used from within the Window::Draw method of your sub class.
161 The frame is always drawn with a single line (without 3D effects). In addition, any mono
162 color set at the control's settings is respected. Yet more additionally, if we're living
163 in a themed desktop, this theming is ignored.
165 Note that this makes sense, since the *only known* clients of Window::Draw
166 are form controls, when printed or print-previewed. For form controls embedded in office documents,
167 you don't want to have the theme look.
170 the device to draw onto
172 the rect for drawing the frame. Upon returning from the call, the rect will be inflated
173 by the space occupied by the drawn pixels.
175 SAL_DLLPRIVATE
void ImplDrawFrame( OutputDevice
* pDev
, tools::Rectangle
& rRect
);
178 explicit Control( vcl::Window
* pParent
, WinBits nWinStyle
= 0 );
179 virtual ~Control() override
;
180 virtual void dispose() override
;
182 virtual void EnableRTL ( bool bEnable
= true ) override
;
184 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
185 virtual void StateChanged( StateChangedType nStateChange
) override
;
186 virtual void Resize() override
;
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;
200 /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
202 This is equivalent to getting the line start/end pairs with
203 GetLineStartEnd() until the index lies within [start,end] of a line
206 the absolute index inside the display text to be changed to a relative index
209 the relative index inside the displayed line or -1 if the absolute index does
212 tools::Long
ToRelativeLineIndex( tools::Long nIndex
) const;
214 void SetLoseFocusHdl( const Link
<Control
&,void>& rLink
) { maLoseFocusHdl
= rLink
; }
216 /** determines whether the control currently has the focus
218 bool HasControlFocus() const { return mbHasControlFocus
; }
220 void SetLayoutDataParent( const Control
* pParent
) const;
222 virtual Size
GetOptimalSize() const override
;
224 /** sets a reference device used for rendering control text
227 void SetReferenceDevice( OutputDevice
* _referenceDevice
);
228 OutputDevice
* GetReferenceDevice() const;
230 vcl::Font
GetUnzoomedControlPointFont() const;
231 void SetShowAccelerator (bool val
);
233 /// Notify the LOK client about an invalidated area.
234 virtual void LogicInvalidate( const tools::Rectangle
* pRectangle
) override
;
237 #endif // INCLUDED_VCL_CTRL_HXX
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */