Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / ctrl.hxx
blobcb68cfe8f78a578763a85f87e0708a0a010ae574
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/solar.h>
25 #include <vcl/dllapi.h>
26 #include <vcl/window.hxx>
27 #include <vcl/salnativewidgets.hxx>
29 // forward
30 namespace vcl { struct ImplControlData; struct ControlLayoutData; }
31 class StyleSettings;
34 class VCL_DLLPUBLIC Control : public vcl::Window
36 protected:
37 vcl::ImplControlData* mpControlData;
39 private:
40 bool mbHasControlFocus;
41 bool mbShowAccelerator;
42 Link<Control&,void> maGetFocusHdl;
43 Link<Control&,void> maLoseFocusHdl;
45 SAL_DLLPRIVATE void ImplInitControlData();
47 Control (const Control &) = delete;
48 Control & operator= (const Control &) = delete;
50 protected:
51 Control( WindowType nType );
52 virtual void FillLayoutData() const;
54 // helper method for composite controls
55 void AppendLayoutData( const Control& rSubControl ) const;
57 /// creates the mpData->mpLayoutData structure
58 void CreateLayoutData() const;
59 /// determines whether we currently have layout data
60 bool HasLayoutData() const;
62 /** this calls both our event listeners, and a specified handler
64 If the Control instance is destroyed during any of those calls, the
65 method properly handles this (in particular, it doesn't crash :)
67 @param nEvent
68 the event to notify to our event listeners
69 @param callHandler
70 the lambda function that calls the handler
71 @return
72 if the Control instance has been destroyed in any of the call
74 bool ImplCallEventListenersAndHandler(
75 VclEventId nEvent, std::function<void()> const & callHandler
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
85 returning.
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;
98 virtual const Color&
99 GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
101 void ImplInitSettings();
103 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
105 public:
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.
119 @param pDev
120 the device to draw onto
121 @param rRect
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 );
127 public:
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( 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 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( 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
155 @param nIndex
156 the absolute index inside the display text to be changed to a relative index
158 @returns
159 the relative index inside the displayed line or -1 if the absolute index does
160 not match any line
162 long ToRelativeLineIndex( long nIndex ) const;
164 void SetGetFocusHdl( const Link<Control&,void>& rLink ) { maGetFocusHdl = rLink; }
165 void SetLoseFocusHdl( const Link<Control&,void>& rLink ) { maLoseFocusHdl = rLink; }
166 const Link<Control&,void>& GetLoseFocusHdl() const { return maLoseFocusHdl; }
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
177 @see DrawControlText
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: */