|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * Common control container class for Phonebook 2 application. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2ControlContainer.h" |
|
22 |
|
23 // Phonebook 2 |
|
24 #include <MPbk2KeyEventHandler.h> |
|
25 #include <MPbk2PointerEventHandler.h> |
|
26 |
|
27 // SYSTEM INCLUDES |
|
28 #include <AknUtils.h> |
|
29 |
|
30 // Debugging headers |
|
31 #include <Pbk2Debug.h> |
|
32 |
|
33 /// Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 #ifdef _DEBUG |
|
37 |
|
38 enum TPanicCode |
|
39 { |
|
40 EPanicPostCond_Constructor = 1, |
|
41 EPanicPreCond_ConstructL, |
|
42 EPanicPostCond_ConstructL, |
|
43 EPanicPostCond_DestroyControl, |
|
44 EPanicPreCond_SetCoeControlL, |
|
45 EPanicPostCond_SetCoeControlL, |
|
46 EPanicPreCond_ComponentControl, |
|
47 }; |
|
48 |
|
49 void Panic(TPanicCode aReason) |
|
50 { |
|
51 _LIT( KPanicText, "CPbk2ControlContainerImpl" ); |
|
52 User::Panic( KPanicText, aReason ); |
|
53 } |
|
54 |
|
55 #endif // _DEBUG |
|
56 |
|
57 } // namespace |
|
58 |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // CPbk2ControlContainerImpl::CPbk2ControlContainerImpl |
|
62 // -------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CPbk2ControlContainerImpl::CPbk2ControlContainerImpl |
|
65 ( MPbk2KeyEventHandler* aKeyEventHandler, |
|
66 MPbk2PointerEventHandler* aPointerHandler ) : |
|
67 iKeyEventHandler( aKeyEventHandler ), |
|
68 iPointerEventHandler( aPointerHandler ) |
|
69 { |
|
70 SetComponentsToInheritVisibility( ETrue ); |
|
71 __ASSERT_DEBUG(!iControl, Panic(EPanicPostCond_Constructor)); |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CPbk2ControlContainerImpl::~CPbk2ControlContainerImpl |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CPbk2ControlContainerImpl::~CPbk2ControlContainerImpl() |
|
79 { |
|
80 if (iOwnsControl) |
|
81 { |
|
82 delete iControl; |
|
83 } |
|
84 delete iLongTapDetector; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2ControlContainerImpl::ConstructL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C void CPbk2ControlContainerImpl::ConstructL |
|
92 ( MObjectProvider& aProvider ) |
|
93 { |
|
94 // PreCond |
|
95 __ASSERT_DEBUG(!iControl, Panic(EPanicPreCond_ConstructL)); |
|
96 |
|
97 SetMopParent(&aProvider); |
|
98 |
|
99 // Create a window, this is the top-level container control |
|
100 CreateWindowL(); |
|
101 |
|
102 // PostCond |
|
103 __ASSERT_DEBUG(!iControl && OwnsWindow(), Panic(EPanicPostCond_ConstructL)); |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CPbk2ControlContainerImpl::CoeControl |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C CCoeControl* CPbk2ControlContainerImpl::CoeControl() const |
|
111 { |
|
112 return iControl; |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CPbk2ControlContainerImpl::DestroyControl |
|
117 // -------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C void CPbk2ControlContainerImpl::DestroyControl() |
|
120 { |
|
121 if (iOwnsControl) |
|
122 { |
|
123 delete iControl; |
|
124 iControl = NULL; |
|
125 __ASSERT_DEBUG(!CoeControl(), Panic(EPanicPostCond_DestroyControl)); |
|
126 } |
|
127 } |
|
128 |
|
129 // -------------------------------------------------------------------------- |
|
130 // CPbk2ControlContainerImpl::KeyEventHandler |
|
131 // -------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C MPbk2KeyEventHandler* |
|
134 CPbk2ControlContainerImpl::KeyEventHandler() const |
|
135 { |
|
136 return iKeyEventHandler; |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2ControlContainerImpl::PointerEventHandler |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C MPbk2PointerEventHandler* |
|
144 CPbk2ControlContainerImpl::PointerEventHandler() const |
|
145 { |
|
146 return iPointerEventHandler; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CPbk2ControlContainerImpl::SetKeyEventHandler |
|
151 // -------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void CPbk2ControlContainerImpl::SetKeyEventHandler |
|
154 (MPbk2KeyEventHandler* aKeyEventHandler) |
|
155 { |
|
156 iKeyEventHandler = aKeyEventHandler; |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // CPbk2ControlContainerImpl::SetHelpContext |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void CPbk2ControlContainerImpl::SetHelpContext |
|
164 (const TCoeHelpContext& aContext) |
|
165 { |
|
166 iHelpContext = aContext; |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------------- |
|
170 // CPbk2ControlContainerImpl::GetHelpContext |
|
171 // -------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CPbk2ControlContainerImpl::GetHelpContext |
|
174 (TCoeHelpContext& aContext) const |
|
175 { |
|
176 aContext = iHelpContext; |
|
177 } |
|
178 |
|
179 // -------------------------------------------------------------------------- |
|
180 // CPbk2ControlContainerImpl::LongTapDetectorL |
|
181 // -------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C CAknLongTapDetector& CPbk2ControlContainerImpl::LongTapDetectorL() |
|
184 { |
|
185 if ( !iLongTapDetector ) |
|
186 { |
|
187 iLongTapDetector = CAknLongTapDetector::NewL( this ); |
|
188 } |
|
189 return *iLongTapDetector; |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPbk2ControlContainerImpl::SetCoeControl |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C void CPbk2ControlContainerImpl::SetCoeControl( |
|
197 CCoeControl* aControl, |
|
198 const TRect& aRect, |
|
199 TBool aOwnsControl /* = ETrue */ ) |
|
200 { |
|
201 __ASSERT_DEBUG(OwnsWindow(), Panic(EPanicPreCond_SetCoeControlL)); |
|
202 |
|
203 // Set the control |
|
204 if (aControl != iControl) |
|
205 { |
|
206 if (iOwnsControl) |
|
207 { |
|
208 delete iControl; |
|
209 } |
|
210 iControl = aControl; |
|
211 } |
|
212 |
|
213 // Store ownership request |
|
214 iOwnsControl = aOwnsControl; |
|
215 RemoveForegroundObserver(); |
|
216 |
|
217 // Set rectangle |
|
218 SetRect(aRect); |
|
219 |
|
220 __ASSERT_DEBUG(CoeControl()==aControl, Panic(EPanicPostCond_SetCoeControlL)); |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------- |
|
224 // CPbk2ControlContainerImpl::OfferKeyEventL |
|
225 // -------------------------------------------------------------------------- |
|
226 // |
|
227 EXPORT_C TKeyResponse CPbk2ControlContainerImpl::OfferKeyEventL |
|
228 (const TKeyEvent& aKeyEvent, TEventCode aType) |
|
229 { |
|
230 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
231 ("CPbk2ControlContainerImpl::OfferKeyEventL(0x%x),Code=%d,Mod=%x,Type=%d"), |
|
232 this, aKeyEvent.iCode, aKeyEvent.iModifiers, aType ); |
|
233 |
|
234 TKeyResponse ret = EKeyWasNotConsumed; |
|
235 |
|
236 // Offer key event first to the key event handler |
|
237 if ( iKeyEventHandler && iKeyEventHandler->Pbk2ProcessKeyEventL |
|
238 ( aKeyEvent, aType ) ) |
|
239 { |
|
240 ret = EKeyWasConsumed; |
|
241 } |
|
242 // Not consumed by the key handler, offer to the control next |
|
243 if ( ( ret == EKeyWasNotConsumed ) && iControl ) |
|
244 { |
|
245 ret = iControl->OfferKeyEventL( aKeyEvent, aType ); |
|
246 } |
|
247 return ret; |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // CPbk2ControlContainerImpl::CountComponentControls |
|
252 // -------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C TInt CPbk2ControlContainerImpl::CountComponentControls() const |
|
255 { |
|
256 // iControl is the only subcontrol |
|
257 return iControl ? 1 : 0; |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CPbk2ControlContainerImpl::ComponentControl |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 EXPORT_C CCoeControl* CPbk2ControlContainerImpl::ComponentControl |
|
265 ( TInt PBK2_DEBUG_ONLY( aIndex ) ) const |
|
266 { |
|
267 // PreCond: Assert that the control is assigned and aIndex is sensible |
|
268 __ASSERT_DEBUG( iControl && aIndex == 0, |
|
269 Panic( EPanicPreCond_ComponentControl ) ); |
|
270 |
|
271 // iControl is the only subcontrol |
|
272 return iControl; |
|
273 } |
|
274 |
|
275 // -------------------------------------------------------------------------- |
|
276 // CPbk2ControlContainerImpl::SizeChanged |
|
277 // This control is only a container; sets iControl's rectangle |
|
278 // to this control's rectangle. |
|
279 // -------------------------------------------------------------------------- |
|
280 // |
|
281 EXPORT_C void CPbk2ControlContainerImpl::SizeChanged() |
|
282 { |
|
283 if ( iControl ) |
|
284 { |
|
285 // Set the control's rectangle to fill this container's rectangle |
|
286 iControl->SetRect( Rect() ); |
|
287 } |
|
288 } |
|
289 |
|
290 // -------------------------------------------------------------------------- |
|
291 // CPbk2ControlContainerImpl::FocusChanged |
|
292 // Forwards focus changed events. |
|
293 // -------------------------------------------------------------------------- |
|
294 // |
|
295 EXPORT_C void CPbk2ControlContainerImpl::FocusChanged( TDrawNow aDrawNow ) |
|
296 { |
|
297 if ( iControl && !IsNonFocusing() ) |
|
298 { |
|
299 iControl->SetFocus( IsFocused(), aDrawNow ); |
|
300 } |
|
301 |
|
302 if ( iObserver && iControl ) |
|
303 { |
|
304 TRAP_IGNORE( iObserver->HandleForegroundEventL( IsFocused() ) ); |
|
305 } |
|
306 } |
|
307 |
|
308 // -------------------------------------------------------------------------- |
|
309 // CPbk2ControlContainerImpl::HandlePointerEventL |
|
310 // -------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C void CPbk2ControlContainerImpl::HandlePointerEventL( |
|
313 const TPointerEvent& aPointerEvent ) |
|
314 { |
|
315 if ( AknLayoutUtils::PenEnabled() ) |
|
316 { |
|
317 // Offer pointer event first to the control |
|
318 if ( iControl ) |
|
319 { |
|
320 iControl->HandlePointerEventL( aPointerEvent ); |
|
321 } |
|
322 |
|
323 // Offer pointer event next to the pointer event handler |
|
324 if ( iPointerEventHandler ) |
|
325 { |
|
326 iPointerEventHandler->Pbk2ProcessPointerEventL( aPointerEvent ); |
|
327 } |
|
328 } |
|
329 } |
|
330 |
|
331 // -------------------------------------------------------------------------- |
|
332 // CPbk2ControlContainerImpl::HandleLongTapEventL |
|
333 // -------------------------------------------------------------------------- |
|
334 // |
|
335 EXPORT_C void CPbk2ControlContainerImpl::HandleLongTapEventL( |
|
336 const TPoint& aPenEventLocation, |
|
337 const TPoint& aPenEventScreenLocation ) |
|
338 { |
|
339 if ( AknLayoutUtils::PenEnabled() ) |
|
340 { |
|
341 // Offer long tap event to the pointer event handler |
|
342 if ( iPointerEventHandler ) |
|
343 { |
|
344 iPointerEventHandler->Pbk2HandleLongTapEventL( |
|
345 aPenEventLocation, aPenEventScreenLocation ); |
|
346 } |
|
347 } |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // CPbk2ControlContainerImpl::AddForegroundObserver |
|
352 // -------------------------------------------------------------------------- |
|
353 // |
|
354 EXPORT_C void CPbk2ControlContainerImpl::AddForegroundObserver |
|
355 ( MPbk2ControlContainerForegroundEventObserver* aObserver ) |
|
356 { |
|
357 iObserver = aObserver; |
|
358 } |
|
359 |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CPbk2ControlContainerImpl::RemoveForegroundObserver |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C void CPbk2ControlContainerImpl::RemoveForegroundObserver() |
|
366 { |
|
367 iObserver = NULL; |
|
368 } |
|
369 |
|
370 // End of File |