xref: /trunk/main/vcl/inc/vcl/ctrl.hxx (revision e1beba7d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_CTRL_HXX
25 #define _SV_CTRL_HXX
26 
27 #include <tools/link.hxx>
28 #include <vcl/sv.h>
29 #include <vcl/dllapi.h>
30 #include <vcl/window.hxx>
31 #include <vcl/salnativewidgets.hxx>
32 
33 // forward
34 namespace vcl { struct ImplControlData; struct ControlLayoutData; }
35 
36 // -----------
37 // - Control -
38 // -----------
39 
40 class VCL_DLLPUBLIC Control : public Window
41 {
42 protected:
43     ::vcl::ImplControlData* mpControlData;
44 
45 private:
46     bool                    mbHasControlFocus;
47 	Link					maGetFocusHdl;
48 	Link					maLoseFocusHdl;
49 
50 	SAL_DLLPRIVATE void     ImplInitControlData();
51 
52     // Copy assignment is forbidden and not implemented.
53 	SAL_DLLPRIVATE          Control (const Control &);
54 	SAL_DLLPRIVATE          Control & operator= (const Control &);
55 
56 protected:
57 					Control( WindowType nType );
58     virtual void	FillLayoutData() const;
59 
60     // helper method for composite controls
61     void			AppendLayoutData( const Control& rSubControl ) const;
62 
63     /// creates the mpData->mpLayoutData structure
64     void            CreateLayoutData() const;
65     /// determines whether we currently have layout data
66     bool            HasLayoutData() const;
67     /// returns the current layout data
68     ::vcl::ControlLayoutData*
69                     GetLayoutData() const;
70 
71     /** this calls both our event listeners, and a specified handler
72 
73         If the Control instance is destroyed during any of those calls, the
74         method properly handles this (in particular, it doesn't crash :)
75 
76         @param nEvent
77             the event to notify to our event listeners
78         @param rHandler
79             the handler to call
80         @param pCaller
81             the parameter to pass to the handler call
82         @return
83             if the Control instance has been destroyed in any of the call
84     */
85     sal_Bool        ImplCallEventListenersAndHandler(
86                     sal_uLong nEvent, const Link& rHandler, void* pCaller
87                 );
88 
89     /** draws the given text onto the given device
90 
91         If no reference device is set, the draw request will simply be forwarded to OutputDevice::DrawText. Otherwise,
92         the text will be rendered according to the metrics at the reference device.
93 
94         Note that the given rectangle might be modified, it will contain the result of a GetTextRect call (either
95         directly at the target device, or taking the reference device into account) when returning.
96     */
97     void        DrawControlText( OutputDevice& _rTargetDevice, Rectangle& _io_rRect,
98                                  const XubString& _rStr, sal_uInt16 _nStyle,
99                                  MetricVector* _pVector, String* _pDisplayText ) const;
100 
101     virtual const Font&
102                 GetCanonicalFont( const StyleSettings& _rStyle ) const;
103     virtual const Color&
104                 GetCanonicalTextColor( const StyleSettings& _rStyle ) const;
105 
106     void ImplInitSettings( const sal_Bool _bFont, const sal_Bool _bForeground );
107 
108 //#if 0 // _SOLAR__PRIVATE
109 public:
110     SAL_DLLPRIVATE void ImplClearLayoutData() const;
111     /** draws a frame around the give rectangle, onto the given device
112 
113         only to be used from within the <member>Window::Draw</member> method of your sub class.
114 
115         The frame is always drawn with a single line (without 3D effects). In addition, any mono
116         color set at the control's settings is respected. Yet more additionally, if we're living
117         in a themed desktop, this theming is ignored.
118 
119         Note that this makes sense, since the *only known* clients of <member>Window::Draw</member>
120         are form controls, when printed or print-previewed. For form controls embedded in office documents,
121         you don't want to have the theme look.
122 
123         @param pDev
124             the device to draw onto
125         @param rRect
126             the rect for drawing the frame. Upon returning from the call, the rect will be inflated
127             by the space occupied by the drawn pixels.
128     */
129     SAL_DLLPRIVATE void ImplDrawFrame( OutputDevice* pDev, Rectangle& rRect );
130 //#endif
131 
132 public:
133 	explicit		Control( Window* pParent, WinBits nWinStyle = 0 );
134 	explicit		Control( Window* pParent, const ResId& );
135 	virtual			~Control();
136 
137 	virtual void	GetFocus();
138 	virtual void	LoseFocus();
139 	virtual long	Notify( NotifyEvent& rNEvt );
140     virtual void	StateChanged( StateChangedType nStateChange );
141     virtual void    Resize();
142     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
143 
144     // invalidates layout data
145     virtual void	SetText( const String& rStr );
146     // gets the displayed text
147     virtual String GetDisplayText() const;
148     // returns the bounding box for the character at index nIndex (in control coordinates)
149     Rectangle GetCharacterBounds( long nIndex ) const;
150     // returns the character index for corresponding to rPoint (in control coordinates)
151     // -1 is returned if no character is at that point
152     long GetIndexForPoint( const Point& rPoint ) const;
153     // returns the number of lines in the result of GetDisplayText()
154     long GetLineCount() const;
155     // returns the interval [start,end] of line nLine
156     // returns [-1,-1] for an invalid line
157     Pair GetLineStartEnd( long nLine ) const;
158     /** ToRelativeLineIndex changes a layout data index to a count relative to its line.
159 
160     <p>This is equivalent to getting the line start/end pairs with
161     <member>GetLineStartEnd</member> until the index lies within [start,end] of a line
162     </p>
163 
164     @param nIndex
165     the absolute index inside the display text to be changed to a relative index
166 
167     @returns
168     the relative index inside the displayed line or -1 if the absolute index does
169     not match any line
170     */
171     long ToRelativeLineIndex( long nIndex ) const;
172 
SetGetFocusHdl(const Link & rLink)173 	void			SetGetFocusHdl( const Link& rLink ) { maGetFocusHdl = rLink; }
GetGetFocusHdl() const174 	const Link& 	GetGetFocusHdl() const	 { return maGetFocusHdl; }
SetLoseFocusHdl(const Link & rLink)175 	void			SetLoseFocusHdl( const Link& rLink ) { maLoseFocusHdl = rLink; }
GetLoseFocusHdl() const176 	const Link& 	GetLoseFocusHdl() const { return maLoseFocusHdl; }
177 
178     /** determines whether the control currently has the focus
179     */
HasControlFocus() const180     bool            HasControlFocus() const { return mbHasControlFocus; }
181 
182     void			SetLayoutDataParent( const Control* pParent ) const;
183 
184     virtual Size    GetOptimalSize(WindowSizeType eType) const;
185 
186     /** sets a reference device used for rendering control text
187         @seealso DrawControlText
188     */
189     void            SetReferenceDevice( OutputDevice* _referenceDevice );
190     OutputDevice*   GetReferenceDevice() const;
191 
GetUnzoomedControlPointFont() const192     Font            GetUnzoomedControlPointFont() const
193     {
194         Font aFont( GetCanonicalFont( GetSettings().GetStyleSettings() ) );
195         if ( IsControlFont() )
196             aFont.Merge( GetControlFont() );
197         return aFont;
198     }
199 };
200 
201 #endif	// _SV_CTRL_HXX
202