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 <tools/link.hxx>
24 #include <vcl/dllapi.h>
25 #include <vcl/window.hxx>
29 namespace vcl
{ struct ImplControlData
; }
33 class VCL_DLLPUBLIC Control
: public vcl::Window
36 std::unique_ptr
<vcl::ImplControlData
> mpControlData
;
39 bool mbHasControlFocus
;
40 bool mbShowAccelerator
;
41 Link
<Control
&,void> maLoseFocusHdl
;
43 SAL_DLLPRIVATE
void ImplInitControlData();
45 Control (const Control
&) = delete;
46 Control
& operator= (const Control
&) = delete;
49 Control( WindowType nType
);
50 virtual void FillLayoutData() const;
52 // helper method for composite controls
53 void AppendLayoutData( const Control
& rSubControl
) const;
55 /// creates the mpData->mpLayoutData structure
56 void CreateLayoutData() const;
57 /// determines whether we currently have layout data
58 bool HasLayoutData() const;
60 /** this calls both our event listeners, and a specified handler
62 If the Control instance is destroyed during any of those calls, the
63 method properly handles this (in particular, it doesn't crash :)
66 the event to notify to our event listeners
68 the lambda function that calls the handler
70 if the Control instance has been destroyed in any of the call
72 bool ImplCallEventListenersAndHandler(
73 VclEventId nEvent
, std::function
<void()> const & callHandler
76 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
78 /** draws the given text onto the given device
80 If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
81 the text will be rendered according to the metrics at the reference device.
83 return will contain the result of a GetTextRect call (either directly
84 at the target device, or taking the reference device into account) when
87 tools::Rectangle
DrawControlText( OutputDevice
& _rTargetDevice
, const tools::Rectangle
& _rRect
,
88 const OUString
& _rStr
, DrawTextFlags _nStyle
,
89 MetricVector
* _pVector
, OUString
* _pDisplayText
,
90 const Size
* i_pDeviceSize
= nullptr ) const;
92 tools::Rectangle
GetControlTextRect( OutputDevice
& _rTargetDevice
, const tools::Rectangle
& rRect
,
93 const OUString
& _rStr
, DrawTextFlags _nStyle
,
94 Size
* o_pDeviceSize
= nullptr ) const;
96 virtual const vcl::Font
&
97 GetCanonicalFont( const StyleSettings
& _rStyle
) const;
99 GetCanonicalTextColor( const StyleSettings
& _rStyle
) const;
101 void ImplInitSettings();
103 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
106 SAL_DLLPRIVATE
void ImplClearLayoutData() const;
107 /** draws a frame around the give rectangle, onto the given device
109 only to be used from within the Window::Draw method of your sub class.
111 The frame is always drawn with a single line (without 3D effects). In addition, any mono
112 color set at the control's settings is respected. Yet more additionally, if we're living
113 in a themed desktop, this theming is ignored.
115 Note that this makes sense, since the *only known* clients of Window::Draw
116 are form controls, when printed or print-previewed. For form controls embedded in office documents,
117 you don't want to have the theme look.
120 the device to draw onto
122 the rect for drawing the frame. Upon returning from the call, the rect will be inflated
123 by the space occupied by the drawn pixels.
125 SAL_DLLPRIVATE
void ImplDrawFrame( OutputDevice
* pDev
, tools::Rectangle
& rRect
);
128 explicit Control( vcl::Window
* pParent
, WinBits nWinStyle
= 0 );
129 virtual ~Control() override
;
130 virtual void dispose() override
;
132 virtual void EnableRTL ( bool bEnable
= true ) override
;
134 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
135 virtual void StateChanged( StateChangedType nStateChange
) override
;
136 virtual void Resize() override
;
138 // invalidates layout data
139 virtual void SetText( const OUString
& rStr
) override
;
140 // gets the displayed text
141 virtual OUString
GetDisplayText() const override
;
142 // returns the bounding box for the character at index nIndex (in control coordinates)
143 tools::Rectangle
GetCharacterBounds( tools::Long nIndex
) const;
144 // returns the character index for corresponding to rPoint (in control coordinates)
145 // -1 is returned if no character is at that point
146 tools::Long
GetIndexForPoint( const Point
& rPoint
) const;
147 // returns the interval [start,end] of line nLine
148 // returns [-1,-1] for an invalid line
149 Pair
GetLineStartEnd( tools::Long nLine
) const;
150 /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
152 This is equivalent to getting the line start/end pairs with
153 GetLineStartEnd() until the index lies within [start,end] of a line
156 the absolute index inside the display text to be changed to a relative index
159 the relative index inside the displayed line or -1 if the absolute index does
162 tools::Long
ToRelativeLineIndex( tools::Long nIndex
) const;
164 void SetLoseFocusHdl( const Link
<Control
&,void>& rLink
) { maLoseFocusHdl
= rLink
; }
166 /** determines whether the control currently has the focus
168 bool HasControlFocus() const { return mbHasControlFocus
; }
170 void SetLayoutDataParent( const Control
* pParent
) const;
172 virtual Size
GetOptimalSize() const override
;
174 /** sets a reference device used for rendering control text
177 void SetReferenceDevice( OutputDevice
* _referenceDevice
);
178 OutputDevice
* GetReferenceDevice() const;
180 vcl::Font
GetUnzoomedControlPointFont() const;
181 void SetShowAccelerator (bool val
);
183 void LogicMouseButtonDown(const MouseEvent
& rMouseEvent
) override
;
184 void LogicMouseButtonUp(const MouseEvent
& rMouseEvent
) override
;
185 void LogicMouseMove(const MouseEvent
& rMouseEvent
) override
;
188 #endif // INCLUDED_VCL_CTRL_HXX
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */