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 .
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
; }
36 class VCL_DLLPUBLIC Control
: public Window
39 ::vcl::ImplControlData
* mpControlData
;
42 bool mbHasControlFocus
;
46 SAL_DLLPRIVATE
void ImplInitControlData();
48 // Copy assignment is forbidden and not implemented.
49 SAL_DLLPRIVATE
Control (const Control
&);
50 SAL_DLLPRIVATE Control
& operator= (const Control
&);
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;
63 /// returns the current layout data
64 ::vcl::ControlLayoutData
*
65 GetLayoutData() const;
67 /** this calls both our event listeners, and a specified handler
69 If the Control instance is destroyed during any of those calls, the
70 method properly handles this (in particular, it doesn't crash :)
73 the event to notify to our event listeners
77 the parameter to pass to the handler call
79 if the Control instance has been destroyed in any of the call
81 sal_Bool
ImplCallEventListenersAndHandler(
82 sal_uLong nEvent
, const Link
& rHandler
, void* pCaller
85 /** draws the given text onto the given device
87 If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
88 the text will be rendered according to the metrics at the reference device.
90 Note that the given rectangle might be modified, it will contain the result of a GetTextRect call (either
91 directly at the target device, or taking the reference device into account) when returning.
93 void DrawControlText( OutputDevice
& _rTargetDevice
, Rectangle
& _io_rRect
,
94 const OUString
& _rStr
, sal_uInt16 _nStyle
,
95 MetricVector
* _pVector
, OUString
* _pDisplayText
) const;
98 GetCanonicalFont( const StyleSettings
& _rStyle
) const;
100 GetCanonicalTextColor( const StyleSettings
& _rStyle
) const;
102 void ImplInitSettings( const sal_Bool _bFont
, const sal_Bool _bForeground
);
105 SAL_DLLPRIVATE
void ImplClearLayoutData() const;
106 /** draws a frame around the give rectangle, onto the given device
108 only to be used from within the <member>Window::Draw</member> method of your sub class.
110 The frame is always drawn with a single line (without 3D effects). In addition, any mono
111 color set at the control's settings is respected. Yet more additionally, if we're living
112 in a themed desktop, this theming is ignored.
114 Note that this makes sense, since the *only known* clients of <member>Window::Draw</member>
115 are form controls, when printed or print-previewed. For form controls embedded in office documents,
116 you don't want to have the theme look.
119 the device to draw onto
121 the rect for drawing the frame. Upon returning from the call, the rect will be inflated
122 by the space occupied by the drawn pixels.
124 SAL_DLLPRIVATE
void ImplDrawFrame( OutputDevice
* pDev
, Rectangle
& rRect
);
127 explicit Control( Window
* pParent
, WinBits nWinStyle
= 0 );
128 explicit Control( Window
* pParent
, const ResId
& );
131 virtual void GetFocus();
132 virtual void LoseFocus();
133 virtual long Notify( NotifyEvent
& rNEvt
);
134 virtual void StateChanged( StateChangedType nStateChange
);
135 virtual void Resize();
136 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
138 // invalidates layout data
139 virtual void SetText( const OUString
& rStr
);
140 // gets the displayed text
141 virtual OUString
GetDisplayText() const;
142 // returns the bounding box for the character at index nIndex (in control coordinates)
143 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 <p>This is equivalent to getting the line start/end pairs with
153 <member>GetLineStartEnd</member> 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;
178 /** sets a reference device used for rendering control text
179 @seealso DrawControlText
181 void SetReferenceDevice( OutputDevice
* _referenceDevice
);
182 OutputDevice
* GetReferenceDevice() const;
184 Font
GetUnzoomedControlPointFont() const
186 Font
aFont( GetCanonicalFont( GetSettings().GetStyleSettings() ) );
187 if ( IsControlFont() )
188 aFont
.Merge( GetControlFont() );
193 #endif // _SV_CTRL_HXX
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */