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> maGetFocusHdl
;
42 Link
<Control
&,void> maLoseFocusHdl
;
44 SAL_DLLPRIVATE
void ImplInitControlData();
46 Control (const Control
&) = delete;
47 Control
& operator= (const Control
&) = delete;
50 Control( WindowType nType
);
51 virtual void FillLayoutData() const;
53 // helper method for composite controls
54 void AppendLayoutData( const Control
& rSubControl
) const;
56 /// creates the mpData->mpLayoutData structure
57 void CreateLayoutData() const;
58 /// determines whether we currently have layout data
59 bool HasLayoutData() const;
61 /** this calls both our event listeners, and a specified handler
63 If the Control instance is destroyed during any of those calls, the
64 method properly handles this (in particular, it doesn't crash :)
67 the event to notify to our event listeners
69 the lambda function that calls the handler
71 if the Control instance has been destroyed in any of the call
73 bool ImplCallEventListenersAndHandler(
74 VclEventId nEvent
, std::function
<void()> const & callHandler
77 void CallEventListeners( VclEventId nEvent
, void* pData
= nullptr );
79 /** draws the given text onto the given device
81 If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
82 the text will be rendered according to the metrics at the reference device.
84 return will contain the result of a GetTextRect call (either directly
85 at the target device, or taking the reference device into account) when
88 tools::Rectangle
DrawControlText( OutputDevice
& _rTargetDevice
, const tools::Rectangle
& _rRect
,
89 const OUString
& _rStr
, DrawTextFlags _nStyle
,
90 MetricVector
* _pVector
, OUString
* _pDisplayText
,
91 const Size
* i_pDeviceSize
= nullptr ) const;
93 tools::Rectangle
GetControlTextRect( OutputDevice
& _rTargetDevice
, const tools::Rectangle
& rRect
,
94 const OUString
& _rStr
, DrawTextFlags _nStyle
,
95 Size
* o_pDeviceSize
= nullptr ) const;
97 virtual const vcl::Font
&
98 GetCanonicalFont( const StyleSettings
& _rStyle
) const;
100 GetCanonicalTextColor( const StyleSettings
& _rStyle
) const;
102 void ImplInitSettings();
104 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
107 SAL_DLLPRIVATE
void ImplClearLayoutData() const;
108 /** draws a frame around the give rectangle, onto the given device
110 only to be used from within the Window::Draw method of your sub class.
112 The frame is always drawn with a single line (without 3D effects). In addition, any mono
113 color set at the control's settings is respected. Yet more additionally, if we're living
114 in a themed desktop, this theming is ignored.
116 Note that this makes sense, since the *only known* clients of Window::Draw
117 are form controls, when printed or print-previewed. For form controls embedded in office documents,
118 you don't want to have the theme look.
121 the device to draw onto
123 the rect for drawing the frame. Upon returning from the call, the rect will be inflated
124 by the space occupied by the drawn pixels.
126 SAL_DLLPRIVATE
void ImplDrawFrame( OutputDevice
* pDev
, tools::Rectangle
& rRect
);
129 explicit Control( vcl::Window
* pParent
, WinBits nWinStyle
= 0 );
130 virtual ~Control() override
;
131 virtual void dispose() override
;
133 virtual void EnableRTL ( bool bEnable
= true ) override
;
135 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
136 virtual void StateChanged( StateChangedType nStateChange
) override
;
137 virtual void Resize() override
;
139 // invalidates layout data
140 virtual void SetText( const OUString
& rStr
) override
;
141 // gets the displayed text
142 virtual OUString
GetDisplayText() const override
;
143 // returns the bounding box for the character at index nIndex (in control coordinates)
144 tools::Rectangle
GetCharacterBounds( long nIndex
) const;
145 // returns the character index for corresponding to rPoint (in control coordinates)
146 // -1 is returned if no character is at that point
147 long GetIndexForPoint( const Point
& rPoint
) const;
148 // returns the interval [start,end] of line nLine
149 // returns [-1,-1] for an invalid line
150 Pair
GetLineStartEnd( long nLine
) const;
151 /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
153 This is equivalent to getting the line start/end pairs with
154 GetLineStartEnd() until the index lies within [start,end] of a line
157 the absolute index inside the display text to be changed to a relative index
160 the relative index inside the displayed line or -1 if the absolute index does
163 long ToRelativeLineIndex( long nIndex
) const;
165 void SetGetFocusHdl( const Link
<Control
&,void>& rLink
) { maGetFocusHdl
= rLink
; }
166 void SetLoseFocusHdl( const Link
<Control
&,void>& rLink
) { maLoseFocusHdl
= rLink
; }
168 /** determines whether the control currently has the focus
170 bool HasControlFocus() const { return mbHasControlFocus
; }
172 void SetLayoutDataParent( const Control
* pParent
) const;
174 virtual Size
GetOptimalSize() const override
;
176 /** sets a reference device used for rendering control text
179 void SetReferenceDevice( OutputDevice
* _referenceDevice
);
180 OutputDevice
* GetReferenceDevice() const;
182 vcl::Font
GetUnzoomedControlPointFont() const;
183 void SetShowAccelerator (bool val
);
186 #endif // INCLUDED_VCL_CTRL_HXX
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */