|
1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Generic Phonebook 2 control container. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CPBK2CONTROLCONTAINER_H |
|
21 #define CPBK2CONTROLCONTAINER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <coecntrl.h> |
|
25 #include <aknlongtapdetector.h> |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class MPbk2KeyEventHandler; |
|
29 class MObjectProvider; |
|
30 class MPbk2PointerEventHandler; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 class MPbk2ControlContainerForegroundEventObserver |
|
35 { |
|
36 public: // Interface |
|
37 |
|
38 /** |
|
39 * Destructor. |
|
40 */ |
|
41 virtual ~MPbk2ControlContainerForegroundEventObserver() |
|
42 {} |
|
43 |
|
44 /** |
|
45 * Foreground event handling function intended for overriding by sub classes. |
|
46 * @param aForeground - Indicates the required focus state of the control. |
|
47 */ |
|
48 |
|
49 virtual void HandleForegroundEventL(TBool aForeground) = 0; |
|
50 |
|
51 }; |
|
52 |
|
53 /** |
|
54 * Generic Phonebook 2 control container implementation class. |
|
55 * Control container's task is to dispatch key presses to an |
|
56 * application-side key event handler. If key event is not |
|
57 * processed application-side, it is passed to the contained control. |
|
58 * Do not use this class directly, instead use more safely typed template |
|
59 * class CPbk2ControlContainer. |
|
60 * |
|
61 * @see CPbkControlContainer |
|
62 */ |
|
63 class CPbk2ControlContainerImpl : public CCoeControl, |
|
64 public MAknLongTapDetectorCallBack |
|
65 { |
|
66 protected: // Constructors and destructor |
|
67 |
|
68 /** |
|
69 * Constructor. |
|
70 * |
|
71 * @param aKeyHandler Key event handler. |
|
72 * @param aPointerHandler Pointer event handler. |
|
73 */ |
|
74 IMPORT_C CPbk2ControlContainerImpl( |
|
75 MPbk2KeyEventHandler* aKeyHandler, |
|
76 MPbk2PointerEventHandler* aPointerHandler ); |
|
77 |
|
78 /** |
|
79 * Destructor. |
|
80 */ |
|
81 IMPORT_C virtual ~CPbk2ControlContainerImpl(); |
|
82 |
|
83 /** |
|
84 * Second phase constructor. |
|
85 * |
|
86 * @param aProvider The object provider (MOP). |
|
87 */ |
|
88 IMPORT_C void ConstructL( |
|
89 MObjectProvider& aProvider ); |
|
90 |
|
91 public: // Interface |
|
92 |
|
93 /** |
|
94 * Returns the contained control. |
|
95 * |
|
96 * @return Contained control. |
|
97 */ |
|
98 IMPORT_C CCoeControl* CoeControl() const; |
|
99 |
|
100 /** |
|
101 * Destroys the contained control if it is owned by this container. |
|
102 */ |
|
103 IMPORT_C void DestroyControl(); |
|
104 |
|
105 /** |
|
106 * Returns the key event handler. |
|
107 * |
|
108 * @return Key event handler. |
|
109 */ |
|
110 IMPORT_C MPbk2KeyEventHandler* KeyEventHandler() const; |
|
111 |
|
112 /** |
|
113 * Returns the pointer event handler. |
|
114 * |
|
115 * @return Pointer event handler. |
|
116 */ |
|
117 IMPORT_C MPbk2PointerEventHandler* PointerEventHandler() const; |
|
118 |
|
119 /** |
|
120 * Sets the key event handler aKeyEventHandler. |
|
121 * |
|
122 * @param aKeyEventHandler Key event handler to set. |
|
123 */ |
|
124 IMPORT_C void SetKeyEventHandler( |
|
125 MPbk2KeyEventHandler* aKeyEventHandler ); |
|
126 |
|
127 /** |
|
128 * Set controls help context. |
|
129 * |
|
130 * @param aContect Help context to set. |
|
131 */ |
|
132 IMPORT_C void SetHelpContext( |
|
133 const TCoeHelpContext& aContext ); |
|
134 |
|
135 /** |
|
136 * Get controls help context. |
|
137 * |
|
138 * @param aContext Retrieved help context. |
|
139 */ |
|
140 IMPORT_C void GetHelpContext( |
|
141 TCoeHelpContext& aContext ) const; |
|
142 |
|
143 /** |
|
144 * Returns the long tap detector. Should be called only if pen |
|
145 * input is supported. |
|
146 * |
|
147 * @return Reference to the long tap detector. |
|
148 */ |
|
149 IMPORT_C CAknLongTapDetector& LongTapDetectorL(); |
|
150 |
|
151 protected: // Interface |
|
152 |
|
153 /** |
|
154 * Set the contained control to aControl and this container's |
|
155 * rectangle to aRect. |
|
156 * |
|
157 * @param aControl The control to set in this container. |
|
158 * @param aRect Initial rectangle for this container and |
|
159 * the contained control. |
|
160 * @param aOwnsControl If ETrue this object takes ownership of |
|
161 * aControl. |
|
162 */ |
|
163 IMPORT_C void SetCoeControl( |
|
164 CCoeControl* aControl, |
|
165 const TRect& aRect, |
|
166 TBool aOwnsControl = ETrue ); |
|
167 |
|
168 protected: // From CCoeControl |
|
169 |
|
170 IMPORT_C TKeyResponse OfferKeyEventL( |
|
171 const TKeyEvent& aKeyEvent, |
|
172 TEventCode aType ); |
|
173 IMPORT_C TInt CountComponentControls() const; |
|
174 IMPORT_C CCoeControl* ComponentControl( |
|
175 TInt aIndex ) const; |
|
176 IMPORT_C void SizeChanged(); |
|
177 IMPORT_C void FocusChanged( |
|
178 TDrawNow aDrawNow ); |
|
179 IMPORT_C void HandlePointerEventL( |
|
180 const TPointerEvent& aPointerEvent ); |
|
181 |
|
182 public: // From MAknLongTapDetectorCallBack |
|
183 |
|
184 void HandleLongTapEventL( |
|
185 const TPoint& aPenEventLocation, |
|
186 const TPoint& aPenEventScreenLocation ); |
|
187 |
|
188 public: |
|
189 /* |
|
190 * Register for HandleForegroundEventL events. |
|
191 * |
|
192 * Note: |
|
193 * SetCoeControl also removes the foreground Observer |
|
194 * |
|
195 * @param aObserver - Observer which implements MPbk2ControlContainerFocusObserver class |
|
196 */ |
|
197 IMPORT_C void AddForegroundObserver( |
|
198 MPbk2ControlContainerForegroundEventObserver* aObserver ); |
|
199 |
|
200 /* |
|
201 * UnRegister from HandleForegroundEventL events. |
|
202 * |
|
203 * Note: |
|
204 * SetCoeControl also removes the foreground Observer |
|
205 * |
|
206 * @param aObserver - Observer which implements MPbk2ControlContainerFocusObserver class |
|
207 */ |
|
208 IMPORT_C void RemoveForegroundObserver(); |
|
209 |
|
210 private: // Data |
|
211 /// Own: The view-side UI control |
|
212 CCoeControl* iControl; |
|
213 /// Own: Indicates whether this object owns iControl |
|
214 TBool iOwnsControl; |
|
215 /// Ref: This control container's key event handler |
|
216 MPbk2KeyEventHandler* iKeyEventHandler; |
|
217 /// ref: This control ccontainer's pointer event handler |
|
218 MPbk2PointerEventHandler* iPointerEventHandler; |
|
219 /// Own: This controls help context |
|
220 TCoeHelpContext iHelpContext; |
|
221 /// Own: Long tap detector |
|
222 CAknLongTapDetector* iLongTapDetector; |
|
223 /// Doesnt Own : Observer for HandleForegroundEventL events. |
|
224 MPbk2ControlContainerForegroundEventObserver* iObserver; |
|
225 }; |
|
226 |
|
227 |
|
228 /** |
|
229 * Thin template wrapper for CPbk2ControlContainerImpl. |
|
230 * Implements Control() function to return the actual control type |
|
231 * passed to ConstructL. |
|
232 */ |
|
233 template<class ControlType> |
|
234 class CPbk2ControlContainer : public CPbk2ControlContainerImpl |
|
235 { |
|
236 protected: // Constructors and destructor |
|
237 |
|
238 /** |
|
239 * Constructor. |
|
240 * |
|
241 * @param aKeyEventHandler Key event handler. |
|
242 * @param aPointerEventHandler Pointer event handler. |
|
243 */ |
|
244 inline CPbk2ControlContainer( |
|
245 MPbk2KeyEventHandler* aKeyEventHandler, |
|
246 MPbk2PointerEventHandler* aPointerEventHandler ); |
|
247 |
|
248 /// Compiler-generated destructor is ok for this class |
|
249 |
|
250 public: // Interface |
|
251 |
|
252 /** |
|
253 * Creates a new instance of this class. |
|
254 * |
|
255 * @param aKeyEventHandler Key event handler. |
|
256 * @param aPointerEventHandler Pointer event handler. |
|
257 * @param aProvider The object provider (MOP). |
|
258 * @return New instance of this class |
|
259 */ |
|
260 static CPbk2ControlContainer<ControlType>* NewL( |
|
261 MPbk2KeyEventHandler* aKeyEventHandler, |
|
262 MPbk2PointerEventHandler* aPointerEventHandler, |
|
263 MObjectProvider& aProvider ); |
|
264 |
|
265 /** |
|
266 * Creates a new instance of this class. |
|
267 * |
|
268 * @param aKeyEventHandler Key event handler. |
|
269 * @param aPointerEventHandler Pointer event handler. |
|
270 * @param aProvider The object provider (MOP). |
|
271 * @return New instance of this class |
|
272 */ |
|
273 static CPbk2ControlContainer<ControlType>* NewLC( |
|
274 MPbk2KeyEventHandler* aKeyEventHandler, |
|
275 MPbk2PointerEventHandler* aPointerEventHandler, |
|
276 MObjectProvider& aProvider ); |
|
277 |
|
278 /** |
|
279 * Returns the contained control. |
|
280 * |
|
281 * @return Contained control. |
|
282 */ |
|
283 inline ControlType* Control() const; |
|
284 |
|
285 /** |
|
286 * Set the contained control to aControl and this container's |
|
287 * rectangle to aRect. |
|
288 * |
|
289 * @param aControl The control to set in this container. |
|
290 * @param aRect Initial rectangle for this container and |
|
291 * the contained control. |
|
292 * @param aOwnsControl If ETrue this object takes ownership of |
|
293 * aControl. |
|
294 */ |
|
295 inline void SetControl( |
|
296 ControlType* aControl, |
|
297 const TRect& aRect, |
|
298 TBool aOwnsControl = ETrue ); |
|
299 }; |
|
300 |
|
301 // INLINE IMPLEMENTATION |
|
302 |
|
303 // -------------------------------------------------------------------------- |
|
304 // CPbk2ControlContainer<ControlType>::CPbk2ControlContainer |
|
305 // -------------------------------------------------------------------------- |
|
306 // |
|
307 template<class ControlType> |
|
308 inline CPbk2ControlContainer<ControlType>::CPbk2ControlContainer |
|
309 ( MPbk2KeyEventHandler* aKeyEventHandler, |
|
310 MPbk2PointerEventHandler* aPointerEventHandler ) : |
|
311 CPbk2ControlContainerImpl( aKeyEventHandler, aPointerEventHandler ) |
|
312 { |
|
313 } |
|
314 |
|
315 // -------------------------------------------------------------------------- |
|
316 // CPbk2ControlContainer<ControlType>::NewL |
|
317 // -------------------------------------------------------------------------- |
|
318 // |
|
319 template<class ControlType> |
|
320 CPbk2ControlContainer<ControlType>* CPbk2ControlContainer<ControlType>::NewL |
|
321 ( MPbk2KeyEventHandler* aKeyEventHandler, |
|
322 MPbk2PointerEventHandler* aPointerEventHandler, |
|
323 MObjectProvider& aProvider ) |
|
324 { |
|
325 CPbk2ControlContainer<ControlType>* self = |
|
326 CPbk2ControlContainer<ControlType>::NewLC |
|
327 ( aKeyEventHandler, aPointerEventHandler, aProvider ); |
|
328 CleanupStack::Pop(); // self |
|
329 return self; |
|
330 } |
|
331 |
|
332 // -------------------------------------------------------------------------- |
|
333 // CPbk2ControlContainer<ControlType>::NewLC |
|
334 // -------------------------------------------------------------------------- |
|
335 // |
|
336 template<class ControlType> |
|
337 CPbk2ControlContainer<ControlType>* CPbk2ControlContainer<ControlType>::NewLC |
|
338 ( MPbk2KeyEventHandler* aKeyEventHandler, |
|
339 MPbk2PointerEventHandler* aPointerEventHandler, |
|
340 MObjectProvider& aProvider ) |
|
341 { |
|
342 CPbk2ControlContainer<ControlType>* self = |
|
343 new ( ELeave ) CPbk2ControlContainer<ControlType> |
|
344 ( aKeyEventHandler, aPointerEventHandler ); |
|
345 CleanupStack::PushL( self ); |
|
346 self->ConstructL( aProvider ); |
|
347 return self; |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // CPbk2ControlContainer<ControlType>::Control |
|
352 // -------------------------------------------------------------------------- |
|
353 // |
|
354 template<class ControlType> |
|
355 inline ControlType* CPbk2ControlContainer<ControlType>::Control() const |
|
356 { |
|
357 return static_cast<ControlType*> |
|
358 ( CPbk2ControlContainerImpl::CoeControl() ); |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CPbk2ControlContainer<ControlType>::SetControl |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 template<class ControlType> |
|
366 inline void CPbk2ControlContainer<ControlType>::SetControl( |
|
367 ControlType* aControl, const TRect& aRect, |
|
368 TBool aOwnsControl/*=ETrue*/ ) |
|
369 { |
|
370 CPbk2ControlContainerImpl::SetCoeControl |
|
371 ( aControl, aRect, aOwnsControl ); |
|
372 } |
|
373 |
|
374 |
|
375 #endif // CPBK2CONTROLCONTAINER_H |
|
376 |
|
377 // End of File |