/src/libreoffice/include/vcl/ctrl.hxx
Line | Count | Source |
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 <vcl/dllapi.h> |
26 | | #include <vcl/window.hxx> |
27 | | #include <optional> |
28 | | #include <vector> |
29 | | |
30 | | // forward |
31 | | class StyleSettings; |
32 | | class Control; |
33 | | class Pair; |
34 | | class Point; |
35 | | class Size; |
36 | | |
37 | | namespace tools { class Rectangle; } |
38 | | |
39 | | namespace vcl |
40 | | { |
41 | | |
42 | | struct UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) ControlLayoutData |
43 | | { |
44 | | // contains the string really displayed |
45 | | // there must be exactly one bounding rectangle in m_aUnicodeBoundRects |
46 | | // for every character in m_aDisplayText |
47 | | OUString m_aDisplayText; |
48 | | // the bounding rectangle of every character |
49 | | // where one character may consist of many glyphs |
50 | | std::vector< tools::Rectangle > m_aUnicodeBoundRects; |
51 | | // start indices of lines |
52 | | std::vector< tools::Long > m_aLineIndices; |
53 | | // notify parent control on destruction |
54 | | VclPtr<const Control> m_pParent; |
55 | | |
56 | | ControlLayoutData(); |
57 | | ~ControlLayoutData(); |
58 | | |
59 | | tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const; |
60 | | // returns the character index for corresponding to rPoint (in control coordinates) |
61 | | // -1 is returned if no character is at that point |
62 | | tools::Long GetIndexForPoint( const Point& rPoint ) const; |
63 | | // returns the interval [start,end] of line nLine |
64 | | // returns [-1,-1] for an invalid line |
65 | | ::Pair GetLineStartEnd( tools::Long nLine ) const; |
66 | | /** ToRelativeLineIndex changes a layout data index to a count relative to its line. |
67 | | |
68 | | This is equivalent to getting the line start/end pairs with |
69 | | GetLineStartEnd until the index lies within [start,end] of a line |
70 | | |
71 | | @param nIndex |
72 | | the absolute index inside the display text to be changed to a relative index |
73 | | |
74 | | @returns |
75 | | the relative index inside the displayed line or -1 if the absolute index does |
76 | | not match any line |
77 | | */ |
78 | | tools::Long ToRelativeLineIndex( tools::Long nIndex ) const; |
79 | | }; |
80 | | |
81 | | } // namespace vcl |
82 | | |
83 | | class VCL_DLLPUBLIC Control : public vcl::Window |
84 | | { |
85 | | protected: |
86 | | mutable std::optional<vcl::ControlLayoutData> mxLayoutData; |
87 | | VclPtr<OutputDevice> mpReferenceDevice; |
88 | | |
89 | | private: |
90 | | bool mbHasControlFocus; |
91 | | bool mbShowAccelerator; |
92 | | Link<Control&,void> maLoseFocusHdl; |
93 | | |
94 | | SAL_DLLPRIVATE void ImplInitControlData(); |
95 | | |
96 | | Control (const Control &) = delete; |
97 | | Control & operator= (const Control &) = delete; |
98 | | |
99 | | protected: |
100 | | SAL_DLLPRIVATE Control( WindowType eType ); |
101 | | virtual void FillLayoutData() const; |
102 | | |
103 | | // helper method for composite controls |
104 | | SAL_DLLPRIVATE void AppendLayoutData( const Control& rSubControl ) const; |
105 | | |
106 | | /// creates the mpData->mpLayoutData structure |
107 | | SAL_DLLPRIVATE void CreateLayoutData() const; |
108 | | /// determines whether we currently have layout data |
109 | | SAL_DLLPRIVATE bool HasLayoutData() const; |
110 | | |
111 | | /** this calls both our event listeners, and a specified handler |
112 | | |
113 | | If the Control instance is destroyed during any of those calls, the |
114 | | method properly handles this (in particular, it doesn't crash :) |
115 | | |
116 | | @param nEvent |
117 | | the event to notify to our event listeners |
118 | | @param callHandler |
119 | | the lambda function that calls the handler |
120 | | @return |
121 | | if the Control instance has been destroyed in any of the call |
122 | | */ |
123 | | bool ImplCallEventListenersAndHandler( |
124 | | VclEventId nEvent, std::function<void()> const & callHandler |
125 | | ); |
126 | | |
127 | | void CallEventListeners( VclEventId nEvent, void* pData = nullptr ); |
128 | | |
129 | | /** draws the given text onto the given device |
130 | | |
131 | | If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise, |
132 | | the text will be rendered according to the metrics at the reference device. |
133 | | |
134 | | return will contain the result of a GetTextRect call (either directly |
135 | | at the target device, or taking the reference device into account) when |
136 | | returning. |
137 | | */ |
138 | | SAL_DLLPRIVATE tools::Rectangle DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& _rRect, |
139 | | const OUString& _rStr, DrawTextFlags _nStyle, |
140 | | std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText, |
141 | | const Size* i_pDeviceSize = nullptr ) const; |
142 | | |
143 | | SAL_DLLPRIVATE tools::Rectangle GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect, |
144 | | const OUString& _rStr, DrawTextFlags _nStyle, |
145 | | Size* o_pDeviceSize = nullptr ) const; |
146 | | |
147 | | virtual const vcl::Font& |
148 | | GetCanonicalFont( const StyleSettings& _rStyle ) const; |
149 | | virtual const Color& |
150 | | GetCanonicalTextColor( const StyleSettings& _rStyle ) const; |
151 | | |
152 | | void ImplInitSettings(); |
153 | | |
154 | | virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; |
155 | | |
156 | | virtual bool FocusWindowBelongsToControl(const vcl::Window* pFocusWin) const; |
157 | | public: |
158 | | SAL_DLLPRIVATE void ImplClearLayoutData() const; |
159 | | /** draws a frame around the give rectangle, onto the given device |
160 | | |
161 | | only to be used from within the Window::Draw method of your sub class. |
162 | | |
163 | | The frame is always drawn with a single line (without 3D effects). In addition, any mono |
164 | | color set at the control's settings is respected. Yet more additionally, if we're living |
165 | | in a themed desktop, this theming is ignored. |
166 | | |
167 | | Note that this makes sense, since the *only known* clients of Window::Draw |
168 | | are form controls, when printed or print-previewed. For form controls embedded in office documents, |
169 | | you don't want to have the theme look. |
170 | | |
171 | | @param pDev |
172 | | the device to draw onto |
173 | | @param rRect |
174 | | the rect for drawing the frame. Upon returning from the call, the rect will be inflated |
175 | | by the space occupied by the drawn pixels. |
176 | | */ |
177 | | SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect ); |
178 | | |
179 | | public: |
180 | | explicit Control( vcl::Window* pParent, WinBits nWinStyle = 0 ); |
181 | | virtual ~Control() override; |
182 | | virtual void dispose() override; |
183 | | |
184 | | virtual void EnableRTL ( bool bEnable = true ) override; |
185 | | |
186 | | virtual bool EventNotify( NotifyEvent& rNEvt ) override; |
187 | | virtual void StateChanged( StateChangedType nStateChange ) override; |
188 | | virtual void Resize() override; |
189 | | |
190 | | // invalidates layout data |
191 | | virtual void SetText( const OUString& rStr ) override; |
192 | | // gets the displayed text |
193 | | virtual OUString GetDisplayText() const override; |
194 | | // returns the bounding box for the character at index nIndex (in control coordinates) |
195 | | tools::Rectangle GetCharacterBounds( tools::Long nIndex ) const; |
196 | | // returns the character index for corresponding to rPoint (in control coordinates) |
197 | | // -1 is returned if no character is at that point |
198 | | tools::Long GetIndexForPoint( const Point& rPoint ) const; |
199 | | // returns the interval [start,end] of line nLine |
200 | | // returns [-1,-1] for an invalid line |
201 | | Pair GetLineStartEnd( tools::Long nLine ) const; |
202 | | /** ToRelativeLineIndex changes a layout data index to a count relative to its line. |
203 | | |
204 | | This is equivalent to getting the line start/end pairs with |
205 | | GetLineStartEnd() until the index lies within [start,end] of a line |
206 | | |
207 | | @param nIndex |
208 | | the absolute index inside the display text to be changed to a relative index |
209 | | |
210 | | @returns |
211 | | the relative index inside the displayed line or -1 if the absolute index does |
212 | | not match any line |
213 | | */ |
214 | | SAL_DLLPRIVATE tools::Long ToRelativeLineIndex( tools::Long nIndex ) const; |
215 | | |
216 | 0 | void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; } |
217 | | |
218 | | /** determines whether the control currently has the focus |
219 | | */ |
220 | 0 | bool HasControlFocus() const { return mbHasControlFocus; } |
221 | | |
222 | | SAL_DLLPRIVATE void SetLayoutDataParent( const Control* pParent ) const; |
223 | | |
224 | | virtual Size GetOptimalSize() const override; |
225 | | |
226 | | /** sets a reference device used for rendering control text |
227 | | @see DrawControlText |
228 | | */ |
229 | | void SetReferenceDevice( OutputDevice* _referenceDevice ); |
230 | | OutputDevice* GetReferenceDevice() const; |
231 | | |
232 | | SAL_DLLPRIVATE vcl::Font GetUnzoomedControlPointFont() const; |
233 | | void SetShowAccelerator (bool val); |
234 | | |
235 | | /// Notify the LOK client about an invalidated area. |
236 | | virtual void LogicInvalidate( const tools::Rectangle* pRectangle ) override; |
237 | | |
238 | 0 | virtual void FlashWindow() const override {}; |
239 | | }; |
240 | | |
241 | | #endif // INCLUDED_VCL_CTRL_HXX |
242 | | |
243 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |