|
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: Bio control for Wap bookmarks |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "WmlBioControl.h" // Own header |
|
23 #include "WmlItemEngine.h" // |
|
24 #include "WmlState.h" // CWmlState and inherited states |
|
25 #include "WmlBioControl.pan" |
|
26 #include "WmlLog.h" |
|
27 |
|
28 #include <akntitle.h> // CAknTitlePane |
|
29 #include <aknappui.h> |
|
30 #include <bsp.h> // CParsedField |
|
31 #include <biouids.h> // KUidMsvBIODataStream |
|
32 #include <CRichBio.h> // CRichBio |
|
33 #include <bldvariant.hrh> // |
|
34 #include <featmgr.h> |
|
35 #include <csxhelp/smart.hlp.hrh> |
|
36 |
|
37 // ================= LOCAL FUNCTIONS ======================= |
|
38 |
|
39 /** |
|
40 * This method is a helper method for destroying the contents |
|
41 * of the array, which is popped from the cleanupstack. |
|
42 */ |
|
43 static void CleanupResetAndDestroy(TAny* aSelf) |
|
44 { |
|
45 __ASSERT_DEBUG(aSelf, User::Panic( _L("wmlbc.dll"), ENullPtr )); |
|
46 CArrayPtrSeg<CParsedField>* self = |
|
47 static_cast<CArrayPtrSeg<CParsedField>* >(aSelf); |
|
48 self->ResetAndDestroy(); |
|
49 delete self; |
|
50 } |
|
51 |
|
52 // ================= MEMBER FUNCTIONS ======================= |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CWmlBioControl::NewL |
|
56 // --------------------------------------------------------- |
|
57 EXPORT_C CMsgBioControl* CWmlBioControl::NewL( |
|
58 MMsgBioControlObserver& aObserver, |
|
59 CMsvSession* aSession, |
|
60 TMsvId aId, |
|
61 TMsgBioMode aIsEditor, |
|
62 const RFile* aFile) |
|
63 { |
|
64 RDebug::Print(_L("WMLBC")); |
|
65 if ( aSession == NULL ) |
|
66 { |
|
67 User::Leave( KErrNotFound ); |
|
68 } |
|
69 |
|
70 CWmlBioControl* self = new ( ELeave ) CWmlBioControl( |
|
71 aObserver, aSession, aId, aIsEditor, aFile ); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------- |
|
79 // CWmlBioControl::~CWmlBioControl |
|
80 // --------------------------------------------------------- |
|
81 CWmlBioControl::~CWmlBioControl() |
|
82 { |
|
83 FeatureManager::UnInitializeLib(); |
|
84 delete iStateFactory; |
|
85 delete iRichBio; |
|
86 |
|
87 delete iItemEngine; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CWmlBioControl::SetAndGetSizeL |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 void CWmlBioControl::SetAndGetSizeL( TSize& aSize ) |
|
95 { |
|
96 iStateFactory->State().SetAndGetSizeL( aSize ); |
|
97 |
|
98 //the following compares the window size against the |
|
99 //"virtual" height of the viewer. This way there is no |
|
100 //scrolling if virtualHeight is less than window size |
|
101 if(iRichBio->VirtualHeight() <= Window().Size().iHeight) |
|
102 { |
|
103 aSize.iHeight = iRichBio->VirtualHeight(); |
|
104 SetSizeWithoutNotification(aSize); |
|
105 } |
|
106 else |
|
107 { |
|
108 SetSizeWithoutNotification(aSize); |
|
109 } |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CWmlBioControl::SetMenuCommandSetL |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 void CWmlBioControl::SetMenuCommandSetL( CEikMenuPane& aMenuPane ) |
|
117 { |
|
118 iStateFactory->State().SetMenuCommandSetL( aMenuPane ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CWmlBioControl::HandleBioCommandL() |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 TBool CWmlBioControl::HandleBioCommandL( TInt aCommand ) |
|
126 { |
|
127 return iStateFactory->State().HandleBioCommandL( aCommand ); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CWmlBioControl::CurrentLineRect |
|
132 // --------------------------------------------------------- |
|
133 // |
|
134 TRect CWmlBioControl::CurrentLineRect() const |
|
135 { |
|
136 TRect lineRect(0,0,0,0); |
|
137 lineRect = iStateFactory->State().CurrentLineRect(); |
|
138 return lineRect; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // CWmlBioControl::IsFocusChangePossible |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 TBool CWmlBioControl::IsFocusChangePossible( |
|
146 TMsgFocusDirection aDirection ) const |
|
147 { |
|
148 return iStateFactory->State().IsFocusChangePossible( aDirection ); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------- |
|
152 // CWmlBioControl::HeaderTextL |
|
153 // --------------------------------------------------------- |
|
154 // |
|
155 HBufC* CWmlBioControl::HeaderTextL() const |
|
156 { |
|
157 HBufC* title = iStateFactory->State().HeaderTextLC(); |
|
158 CleanupStack::Pop( title ); |
|
159 return title; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CWmlBioControl::UpdateHeaderTextL |
|
164 // --------------------------------------------------------- |
|
165 // |
|
166 void CWmlBioControl::UpdateHeaderTextL() const |
|
167 { |
|
168 HBufC* title = iStateFactory->State().HeaderTextLC(); |
|
169 CEikStatusPane* sp = |
|
170 ((CAknAppUi*)CEikonEnv::Static()->EikAppUi())->StatusPane(); |
|
171 CAknTitlePane* titlePane = STATIC_CAST(CAknTitlePane*, |
|
172 sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle))); |
|
173 titlePane->SetTextL( *title ); |
|
174 CleanupStack::PopAndDestroy( title ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CWmlBioControl::OptionMenuPermissionsL |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 TUint32 CWmlBioControl::OptionMenuPermissionsL() const |
|
182 { |
|
183 TUint32 permissions = EMsgBioExit; |
|
184 iStateFactory->State().OptionMenuPermissionsL( permissions ); |
|
185 return permissions; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CWmlBioControl::VirtualHeight |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 TInt CWmlBioControl::VirtualHeight() |
|
193 { |
|
194 return iStateFactory->State().VirtualHeight(); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // CWmlBioControl::VirtualVisibleTop |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 TInt CWmlBioControl::VirtualVisibleTop() |
|
202 { |
|
203 return iStateFactory->State().VirtualVisibleTop(); |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CWmlBioControl::IsCursorLocation |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 TBool CWmlBioControl::IsCursorLocation(TMsgCursorLocation aLocation) const |
|
211 { |
|
212 return iStateFactory->State().IsCursorLocation( aLocation ); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CWmlBioControl::OfferKeyEventL |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 TKeyResponse CWmlBioControl::OfferKeyEventL( |
|
220 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
221 { |
|
222 return iStateFactory->State().OfferKeyEventL( aKeyEvent, aType ); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CWmlBioControl::GetHelpContext |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 void CWmlBioControl::GetHelpContext(TCoeHelpContext& aHelpContext) const |
|
230 { |
|
231 const TUid KUidSmart = {0x101F4CDA}; |
|
232 iStateFactory->State().GetHelpContext(aHelpContext); // adds the context of current state |
|
233 aHelpContext.iMajor = KUidSmart; |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CWmlBioControl::HandleResourceChange |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 void CWmlBioControl::HandleResourceChange( TInt aType ) |
|
241 { |
|
242 LOG("CWmlBioControl::HandleResourceChange begin"); |
|
243 CMsgBioControl::HandleResourceChange( aType ); |
|
244 |
|
245 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
246 { |
|
247 iRichBio->Reset(); |
|
248 } |
|
249 LOG("CWmlBioControl::HandleResourceChange end"); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------- |
|
253 // CWmlBioControl::CountComponentControls |
|
254 // --------------------------------------------------------- |
|
255 // |
|
256 TInt CWmlBioControl::CountComponentControls() const |
|
257 { |
|
258 // There can richbio or... |
|
259 if ( iRichBio ) |
|
260 { |
|
261 return 1; |
|
262 } |
|
263 // No control at all. |
|
264 else |
|
265 { |
|
266 return 0; |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------- |
|
271 // CWmlBioControl::ComponentControl |
|
272 // --------------------------------------------------------- |
|
273 // |
|
274 CCoeControl* CWmlBioControl::ComponentControl( TInt /*aIndex*/ ) const |
|
275 { |
|
276 // Precondition is that we have richbio control, otherwise this |
|
277 // method should not be called at all. |
|
278 __ASSERT_DEBUG( iRichBio, Panic( ERichBioNull ) ); |
|
279 return iRichBio; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CWmlBioControl::SizeChanged() |
|
284 // --------------------------------------------------------- |
|
285 // |
|
286 void CWmlBioControl::SizeChanged() |
|
287 { |
|
288 iStateFactory->State().SizeChanged(); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------- |
|
292 // CWmlBioControl::FocusChanged |
|
293 // --------------------------------------------------------- |
|
294 // |
|
295 void CWmlBioControl::FocusChanged( TDrawNow aDrawNow ) |
|
296 { |
|
297 iStateFactory->State().FocusChanged( aDrawNow ); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------- |
|
301 // CWmlBioControl::SetContainerWindowL |
|
302 // --------------------------------------------------------- |
|
303 // |
|
304 void CWmlBioControl::SetContainerWindowL( const CCoeControl& aContainer ) |
|
305 { |
|
306 CCoeControl::SetContainerWindowL( aContainer ); |
|
307 // Let the state create the viewer. |
|
308 iStateFactory->State().CreateViewerL( aContainer ); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------- |
|
312 // CWmlBioControl::CWmlBioControl |
|
313 // --------------------------------------------------------- |
|
314 // |
|
315 CWmlBioControl::CWmlBioControl( |
|
316 MMsgBioControlObserver& aObserver, |
|
317 CMsvSession* aSession, |
|
318 TMsvId aId, |
|
319 TMsgBioMode aIsEditor, |
|
320 const RFile* aFile): |
|
321 CMsgBioControl( aObserver, |
|
322 aSession, |
|
323 aId, |
|
324 aIsEditor, |
|
325 aFile) |
|
326 { |
|
327 // all functionality in base class |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------- |
|
331 // Symbian OS default constructor can leave. |
|
332 // --------------------------------------------------------- |
|
333 // |
|
334 void CWmlBioControl::ConstructL() |
|
335 { |
|
336 SetExtension( this ); |
|
337 |
|
338 FeatureManager::InitializeLibL(); |
|
339 |
|
340 iStateFactory = CWmlStateFactory::NewL( *this ); |
|
341 |
|
342 // Load resources |
|
343 _LIT(KWMLBCResourceFileName, "wmlbc.rsc"); |
|
344 |
|
345 LoadResourceL( KWMLBCResourceFileName ); |
|
346 LoadStandardBioResourceL(); |
|
347 |
|
348 CArrayPtrSeg<CParsedField>* parsedFieldArray = |
|
349 ReadStoreLC( iId ); |
|
350 |
|
351 |
|
352 iItemEngine = CWmlItemEngine::NewL(); |
|
353 iItemEngine->CreateItemArraysL( *parsedFieldArray ); |
|
354 |
|
355 |
|
356 // Array was pushed inside the TCleanupItem and all it's |
|
357 // elements are also destroyed by this call |
|
358 CleanupStack::PopAndDestroy(); // parsedFieldArray |
|
359 |
|
360 TInt bmCount = iItemEngine->BookmarkCount(); |
|
361 |
|
362 if ( bmCount == 0 && !FeatureManager::FeatureSupported( KFeatureIdSmartmsgSMSWapApReceiving ) ) |
|
363 { |
|
364 User::Leave(KErrNotSupported); |
|
365 } |
|
366 |
|
367 iStateFactory->SetInitialStateL(bmCount); |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------- |
|
371 // CWmlBioControl::ReadStoreLC |
|
372 // --------------------------------------------------------- |
|
373 // |
|
374 CArrayPtrSeg<CParsedField>* CWmlBioControl::ReadStoreLC( |
|
375 const TMsvId aId ) |
|
376 { |
|
377 CMsvEntry* entry = MsvSession().GetEntryL( aId ); |
|
378 CleanupStack::PushL( entry ); |
|
379 |
|
380 if ( !entry->HasStoreL() ) |
|
381 { |
|
382 LOG("CWmlBioControl: No store for entry"); |
|
383 User::Leave( KErrNotFound ); |
|
384 } |
|
385 |
|
386 CMsvStore* store = entry->ReadStoreL(); |
|
387 CleanupStack::PushL( store ); |
|
388 |
|
389 RMsvReadStream readStream; |
|
390 readStream.OpenLC( *store, KUidMsvBIODataStream ); |
|
391 |
|
392 CArrayPtrSeg<CParsedField>* parsedFields = |
|
393 InternalizeFieldDataL( readStream ); |
|
394 |
|
395 CleanupStack::PopAndDestroy(3, entry); // readStream, store, entry |
|
396 |
|
397 CleanupStack::PushL( TCleanupItem(CleanupResetAndDestroy, parsedFields) ); |
|
398 |
|
399 return parsedFields; |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------- |
|
403 // CWmlBioControl::InternalizeFieldDataL |
|
404 // --------------------------------------------------------- |
|
405 // |
|
406 CArrayPtrSeg<CParsedField>* CWmlBioControl::InternalizeFieldDataL( |
|
407 RMsvReadStream& aReadStream ) |
|
408 { |
|
409 CArrayPtrSeg<CParsedField>* parsedFieldArray = |
|
410 new ( ELeave ) CArrayPtrSeg<CParsedField>(1); |
|
411 // Push array to the cleanupstack so that all of it's items |
|
412 // are destroyed when it's popped. |
|
413 CleanupStack::PushL( TCleanupItem(CleanupResetAndDestroy, parsedFieldArray) ); |
|
414 |
|
415 CParsedField* parsedField = NULL; |
|
416 |
|
417 const TInt streamCount = aReadStream.ReadUint8L(); // leaves on eof |
|
418 |
|
419 for ( TInt i=0; i < streamCount; i++ ) |
|
420 { |
|
421 parsedField = new (ELeave) CParsedField(); |
|
422 CleanupStack::PushL( parsedField ); |
|
423 parsedField->InternalizeL( aReadStream ); |
|
424 parsedFieldArray->AppendL( parsedField ); // takes ownership |
|
425 CleanupStack::Pop( parsedField ); |
|
426 } |
|
427 |
|
428 if ( parsedFieldArray->Count() == 0 ) |
|
429 { |
|
430 User::Leave( KErrMsgBioMessageNotValid ); // no data found |
|
431 } |
|
432 |
|
433 CleanupStack::Pop( parsedFieldArray ); |
|
434 return parsedFieldArray; |
|
435 } |
|
436 |
|
437 TAny* CWmlBioControl::BioControlExtension(TInt aExtensionId) |
|
438 { |
|
439 if ( aExtensionId == KMsgBioControlScrollExtension ) |
|
440 { |
|
441 return static_cast<MMsgBioControlScrollExtension*> (this); |
|
442 } |
|
443 else |
|
444 { |
|
445 return NULL; |
|
446 } |
|
447 } |
|
448 |
|
449 |
|
450 TInt CWmlBioControl::ExtScrollL( TInt aPixelsToScroll, |
|
451 TMsgScrollDirection aDirection ) |
|
452 { |
|
453 return iRichBio->ScrollL(aPixelsToScroll, aDirection); |
|
454 } |
|
455 |
|
456 void CWmlBioControl::ExtNotifyViewEvent( TMsgViewEvent aEvent, TInt aParam ) |
|
457 { |
|
458 iRichBio->NotifyViewEvent( aEvent, aParam ); |
|
459 } |
|
460 |
|
461 |
|
462 |
|
463 // End of File |