Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_CTRL_HXX
21 : #define INCLUDED_VCL_CTRL_HXX
22 :
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>
28 :
29 : // forward
30 : namespace vcl { struct ImplControlData; struct ControlLayoutData; }
31 : class StyleSettings;
32 :
33 :
34 : // - Control -
35 :
36 :
37 : class VCL_DLLPUBLIC Control : public Window
38 : {
39 : protected:
40 : ::vcl::ImplControlData* mpControlData;
41 :
42 : private:
43 : bool mbHasControlFocus;
44 : Link maGetFocusHdl;
45 : Link maLoseFocusHdl;
46 :
47 : SAL_DLLPRIVATE void ImplInitControlData();
48 :
49 : // Copy assignment is forbidden and not implemented.
50 : SAL_DLLPRIVATE Control (const Control &);
51 : SAL_DLLPRIVATE Control & operator= (const Control &);
52 :
53 : protected:
54 : Control( WindowType nType );
55 : virtual void FillLayoutData() const;
56 :
57 : // helper method for composite controls
58 : void AppendLayoutData( const Control& rSubControl ) const;
59 :
60 : /// creates the mpData->mpLayoutData structure
61 : void CreateLayoutData() const;
62 : /// determines whether we currently have layout data
63 : bool HasLayoutData() const;
64 : /// returns the current layout data
65 : ::vcl::ControlLayoutData*
66 : GetLayoutData() const;
67 :
68 : /** this calls both our event listeners, and a specified handler
69 :
70 : If the Control instance is destroyed during any of those calls, the
71 : method properly handles this (in particular, it doesn't crash :)
72 :
73 : @param nEvent
74 : the event to notify to our event listeners
75 : @param rHandler
76 : the handler to call
77 : @param pCaller
78 : the parameter to pass to the handler call
79 : @return
80 : if the Control instance has been destroyed in any of the call
81 : */
82 : bool ImplCallEventListenersAndHandler(
83 : sal_uLong nEvent, const Link& rHandler, void* pCaller
84 : );
85 :
86 : /** draws the given text onto the given device
87 :
88 : If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
89 : the text will be rendered according to the metrics at the reference device.
90 :
91 : Note that the given rectangle might be modified, it will contain the result of a GetTextRect call (either
92 : directly at the target device, or taking the reference device into account) when returning.
93 : */
94 : void DrawControlText( OutputDevice& _rTargetDevice, Rectangle& _io_rRect,
95 : const OUString& _rStr, sal_uInt16 _nStyle,
96 : MetricVector* _pVector, OUString* _pDisplayText ) const;
97 :
98 : virtual const Font&
99 : GetCanonicalFont( const StyleSettings& _rStyle ) const;
100 : virtual const Color&
101 : GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
102 :
103 : void ImplInitSettings( const bool _bFont, const bool _bForeground );
104 :
105 : public:
106 : SAL_DLLPRIVATE void ImplClearLayoutData() const;
107 : /** draws a frame around the give rectangle, onto the given device
108 :
109 : only to be used from within the Window::Draw method of your sub class.
110 :
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.
114 :
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.
118 :
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.
124 : */
125 : SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, Rectangle& rRect );
126 :
127 : public:
128 : explicit Control( Window* pParent, WinBits nWinStyle = 0 );
129 : explicit Control( Window* pParent, const ResId& );
130 : virtual ~Control();
131 :
132 : virtual void EnableRTL ( bool bEnable = true ) SAL_OVERRIDE;
133 :
134 : virtual void GetFocus() SAL_OVERRIDE;
135 : virtual void LoseFocus() SAL_OVERRIDE;
136 : virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
137 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
138 : virtual void Resize() SAL_OVERRIDE;
139 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
140 :
141 : // invalidates layout data
142 : virtual void SetText( const OUString& rStr ) SAL_OVERRIDE;
143 : // gets the displayed text
144 : virtual OUString GetDisplayText() const SAL_OVERRIDE;
145 : // returns the bounding box for the character at index nIndex (in control coordinates)
146 : Rectangle GetCharacterBounds( long nIndex ) const;
147 : // returns the character index for corresponding to rPoint (in control coordinates)
148 : // -1 is returned if no character is at that point
149 : long GetIndexForPoint( const Point& rPoint ) const;
150 : // returns the interval [start,end] of line nLine
151 : // returns [-1,-1] for an invalid line
152 : Pair GetLineStartEnd( long nLine ) const;
153 : /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
154 :
155 : This is equivalent to getting the line start/end pairs with
156 : GetLineStartEnd() until the index lies within [start,end] of a line
157 :
158 : @param nIndex
159 : the absolute index inside the display text to be changed to a relative index
160 :
161 : @returns
162 : the relative index inside the displayed line or -1 if the absolute index does
163 : not match any line
164 : */
165 : long ToRelativeLineIndex( long nIndex ) const;
166 :
167 0 : void SetGetFocusHdl( const Link& rLink ) { maGetFocusHdl = rLink; }
168 : const Link& GetGetFocusHdl() const { return maGetFocusHdl; }
169 0 : void SetLoseFocusHdl( const Link& rLink ) { maLoseFocusHdl = rLink; }
170 0 : const Link& GetLoseFocusHdl() const { return maLoseFocusHdl; }
171 :
172 : /** determines whether the control currently has the focus
173 : */
174 0 : bool HasControlFocus() const { return mbHasControlFocus; }
175 :
176 : void SetLayoutDataParent( const Control* pParent ) const;
177 :
178 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
179 :
180 : /** sets a reference device used for rendering control text
181 : @see DrawControlText
182 : */
183 : void SetReferenceDevice( OutputDevice* _referenceDevice );
184 : OutputDevice* GetReferenceDevice() const;
185 :
186 : Font GetUnzoomedControlPointFont() const;
187 : };
188 :
189 : #endif // INCLUDED_VCL_CTRL_HXX
190 :
191 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|