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 <tools/solar.h>
25 #include <vcl/dllapi.h>
26 #include <vcl/window.hxx>
27 #include <vcl/salnativewidgets.hxx>
30 namespace vcl
{ struct ImplControlData
; struct ControlLayoutData
; }
37 class VCL_DLLPUBLIC Control
: public vcl::Window
40 vcl::ImplControlData
* mpControlData
;
43 bool mbHasControlFocus
;
45 Link
<> maLoseFocusHdl
;
47 SAL_DLLPRIVATE
void ImplInitControlData();
49 Control (const Control
&) SAL_DELETED_FUNCTION
;
50 Control
& operator= (const Control
&) SAL_DELETED_FUNCTION
;
53 Control( WindowType nType
);
54 virtual void FillLayoutData() const;
56 // helper method for composite controls
57 void AppendLayoutData( const Control
& rSubControl
) const;
59 /// creates the mpData->mpLayoutData structure
60 void CreateLayoutData() const;
61 /// determines whether we currently have layout data
62 bool HasLayoutData() const;
64 /** this calls both our event listeners, and a specified handler
66 If the Control instance is destroyed during any of those calls, the
67 method properly handles this (in particular, it doesn't crash :)
70 the event to notify to our event listeners
74 the parameter to pass to the handler call
76 if the Control instance has been destroyed in any of the call
78 bool ImplCallEventListenersAndHandler(
79 sal_uLong nEvent
, const Link
<>& rHandler
, void* pCaller
82 /** draws the given text onto the given device
84 If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
85 the text will be rendered according to the metrics at the reference device.
87 Note that the given rectangle might be modified, it will contain the result of a GetTextRect call (either
88 directly at the target device, or taking the reference device into account) when returning.
90 void DrawControlText( OutputDevice
& _rTargetDevice
, Rectangle
& _io_rRect
,
91 const OUString
& _rStr
, DrawTextFlags _nStyle
,
92 MetricVector
* _pVector
, OUString
* _pDisplayText
) const;
94 virtual const vcl::Font
&
95 GetCanonicalFont( const StyleSettings
& _rStyle
) const;
97 GetCanonicalTextColor( const StyleSettings
& _rStyle
) const;
99 void ImplInitSettings( const bool _bFont
, const bool _bForeground
);
101 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) SAL_OVERRIDE
;
104 SAL_DLLPRIVATE
void ImplClearLayoutData() const;
105 /** draws a frame around the give rectangle, onto the given device
107 only to be used from within the Window::Draw method of your sub class.
109 The frame is always drawn with a single line (without 3D effects). In addition, any mono
110 color set at the control's settings is respected. Yet more additionally, if we're living
111 in a themed desktop, this theming is ignored.
113 Note that this makes sense, since the *only known* clients of Window::Draw
114 are form controls, when printed or print-previewed. For form controls embedded in office documents,
115 you don't want to have the theme look.
118 the device to draw onto
120 the rect for drawing the frame. Upon returning from the call, the rect will be inflated
121 by the space occupied by the drawn pixels.
123 SAL_DLLPRIVATE
void ImplDrawFrame( OutputDevice
* pDev
, Rectangle
& rRect
);
126 explicit Control( vcl::Window
* pParent
, WinBits nWinStyle
= 0 );
127 explicit Control( vcl::Window
* pParent
, const ResId
& );
129 virtual void dispose() SAL_OVERRIDE
;
131 virtual void EnableRTL ( bool bEnable
= true ) SAL_OVERRIDE
;
133 virtual void GetFocus() SAL_OVERRIDE
;
134 virtual void LoseFocus() SAL_OVERRIDE
;
135 virtual bool Notify( NotifyEvent
& rNEvt
) SAL_OVERRIDE
;
136 virtual void StateChanged( StateChangedType nStateChange
) SAL_OVERRIDE
;
137 virtual void Resize() SAL_OVERRIDE
;
139 // invalidates layout data
140 virtual void SetText( const OUString
& rStr
) SAL_OVERRIDE
;
141 // gets the displayed text
142 virtual OUString
GetDisplayText() const SAL_OVERRIDE
;
143 // returns the bounding box for the character at index nIndex (in control coordinates)
144 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
<>& rLink
) { maGetFocusHdl
= rLink
; }
166 const Link
<>& GetGetFocusHdl() const { return maGetFocusHdl
; }
167 void SetLoseFocusHdl( const Link
<>& rLink
) { maLoseFocusHdl
= rLink
; }
168 const Link
<>& GetLoseFocusHdl() const { return maLoseFocusHdl
; }
170 /** determines whether the control currently has the focus
172 bool HasControlFocus() const { return mbHasControlFocus
; }
174 void SetLayoutDataParent( const Control
* pParent
) const;
176 virtual Size
GetOptimalSize() const SAL_OVERRIDE
;
178 /** sets a reference device used for rendering control text
181 void SetReferenceDevice( OutputDevice
* _referenceDevice
);
182 OutputDevice
* GetReferenceDevice() const;
184 vcl::Font
GetUnzoomedControlPointFont() const;
187 #endif // INCLUDED_VCL_CTRL_HXX
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */