|
1 /* |
|
2 * Copyright (c) 2002 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 * This contains all the state specific logic of the bio-control. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "WmlState.h" // Own header |
|
23 #include "WmlItemEngine.h" |
|
24 #include "WmlBioControl.h" // CWmlBioControl |
|
25 #include "WmlBioControl.pan" // Panic |
|
26 #include "WmlSubItemBase.h" // CWmlSubItemBase |
|
27 |
|
28 #include <StringLoader.h> // StringLoader |
|
29 #include <msgnamevalue.h> // CMsgNameValue |
|
30 #include <msgbiocontrolObserver.h> |
|
31 #include <CRichBio.h> // CRichBio |
|
32 #include <WMLBC.rsg> // resouce identifiers |
|
33 #include <bldvariant.hrh> |
|
34 #include <csxhelp/smart.hlp.hrh> |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // --------------------------------------------------------- |
|
39 // CWmlStateFactory::NewL() |
|
40 // --------------------------------------------------------- |
|
41 CWmlStateFactory* CWmlStateFactory::NewL( CWmlBioControl& aBioControl ) |
|
42 { |
|
43 CWmlStateFactory* self = new ( ELeave ) CWmlStateFactory; |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL( aBioControl ); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CWmlStateFactory::ConstructL() |
|
52 // --------------------------------------------------------- |
|
53 void CWmlStateFactory::ConstructL( CWmlBioControl& aBioControl ) |
|
54 { |
|
55 iBioControl = &aBioControl; |
|
56 iStateSingle = new (ELeave) CWmlStateSingle( this, aBioControl ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CWmlStateFactory::~CWmlStateFactory() |
|
61 // --------------------------------------------------------- |
|
62 CWmlStateFactory::~CWmlStateFactory() |
|
63 { |
|
64 delete iStateSingle; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CWmlStateFactory::SetInitialStateL() |
|
69 // --------------------------------------------------------- |
|
70 void CWmlStateFactory::SetInitialStateL( |
|
71 const TInt aBMCount ) |
|
72 { |
|
73 // Pre-condition is that state object is NULL |
|
74 __ASSERT_DEBUG(iState == NULL, |
|
75 Panic(EWmlBCStateObjectAlreadyCreated)); |
|
76 |
|
77 if ( aBMCount == 0 ) |
|
78 { |
|
79 // nothing to show... invalid message. |
|
80 User::Leave( KErrCorrupt ); |
|
81 } |
|
82 |
|
83 TWmlState state( EWmlBCInitial ); |
|
84 |
|
85 if ( aBMCount == 1 ) |
|
86 { |
|
87 state = EWmlBCViewerBookmarkOne; |
|
88 } |
|
89 else |
|
90 { |
|
91 // invalid message |
|
92 User::Leave( KErrNotSupported ); |
|
93 } |
|
94 |
|
95 ChangeStateL( state ); |
|
96 // Post condition is that we have state object. |
|
97 __ASSERT_DEBUG(iState, |
|
98 Panic(EWmlBCStateObjectNotCreated)); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CWmlStateFactory::ChangeStateL() |
|
103 // --------------------------------------------------------- |
|
104 void CWmlStateFactory::ChangeStateL( TWmlState aState ) |
|
105 { |
|
106 iStateEnum = aState; |
|
107 // Set the correct state object. |
|
108 switch ( aState ) |
|
109 { |
|
110 // Single mode |
|
111 case EWmlBCViewerBookmarkOne: |
|
112 { |
|
113 iState = iStateSingle; |
|
114 break; |
|
115 } |
|
116 // Illegal transitions |
|
117 default: |
|
118 { |
|
119 Panic( EIllegalStateTransition ); |
|
120 break; |
|
121 } |
|
122 } |
|
123 iState->EnterL( aState ); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CWmlStateFactory::State() |
|
128 // --------------------------------------------------------- |
|
129 MWmlState& CWmlStateFactory::State() const |
|
130 { |
|
131 return *iState; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CWmlState::CWmlState() |
|
136 // --------------------------------------------------------- |
|
137 CWmlState::CWmlState( CWmlStateFactory* aStateFactory, |
|
138 CWmlBioControl& aBioControl) : |
|
139 iStateFactory( aStateFactory ), |
|
140 iBioControl( &aBioControl ) |
|
141 { |
|
142 // Nothing more here... |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CWmlStateSingle::CWmlStateSingle() |
|
147 // --------------------------------------------------------- |
|
148 CWmlStateSingle::CWmlStateSingle( CWmlStateFactory* aStateFactory, |
|
149 CWmlBioControl& aBioControl) : |
|
150 CWmlState( aStateFactory, aBioControl ) |
|
151 { |
|
152 // Nothing more here... |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CWmlStateSingle::~CWmlStateSingle() |
|
157 // --------------------------------------------------------- |
|
158 CWmlStateSingle::~CWmlStateSingle() |
|
159 { |
|
160 // This owns nothing... |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CWmlStateSingle::SetAndGetSizeL() |
|
165 // --------------------------------------------------------- |
|
166 void CWmlStateSingle::SetAndGetSizeL( TSize& aSize ) |
|
167 { |
|
168 iBioControl->iRichBio->SetAndGetSizeL( aSize ); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CWmlStateSingle::HandleBioCommandL() |
|
173 // --------------------------------------------------------- |
|
174 TBool CWmlStateSingle::HandleBioCommandL( TInt aCommand ) |
|
175 { |
|
176 TBool retValue(EFalse); |
|
177 aCommand -= iBioControl->iBioControlObserver.FirstFreeCommand(); |
|
178 switch ( aCommand ) |
|
179 { |
|
180 case EAddBookmark: |
|
181 { |
|
182 iBioControl->iItemEngine->SaveCurrentItemL(); |
|
183 retValue = ETrue; |
|
184 break; |
|
185 } |
|
186 default: |
|
187 { |
|
188 break; |
|
189 } |
|
190 } |
|
191 return retValue; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------- |
|
195 // CWmlStateSingle::CurrentLineRect() |
|
196 // --------------------------------------------------------- |
|
197 TRect CWmlStateSingle::CurrentLineRect() const |
|
198 { |
|
199 return iBioControl->iRichBio->CurrentLineRect(); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // CWmlStateSingle::IsFocusChangePossible() |
|
204 // --------------------------------------------------------- |
|
205 TBool CWmlStateSingle::IsFocusChangePossible( |
|
206 TMsgFocusDirection aDirection ) const |
|
207 { |
|
208 if (aDirection == EMsgFocusUp) |
|
209 { |
|
210 return CursorInFirstLine(); |
|
211 } |
|
212 else |
|
213 { |
|
214 // Focus down will never release the focus out of this. |
|
215 return EFalse; |
|
216 } |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------- |
|
220 // CWmlStateSingle::HeaderTextLC() |
|
221 // --------------------------------------------------------- |
|
222 HBufC* CWmlStateSingle::HeaderTextLC() const |
|
223 { |
|
224 TInt resourceID(0); |
|
225 switch ( iState ) |
|
226 { |
|
227 case EWmlBCViewerBookmarkOne: |
|
228 { |
|
229 resourceID = R_QTN_SM_TITLE_ONE_BOOKMARK; |
|
230 break; |
|
231 } |
|
232 default: |
|
233 { |
|
234 // In detail state iState should not be anything else than above. |
|
235 Panic( EIllegalInternalState ); |
|
236 break; |
|
237 } |
|
238 } |
|
239 return StringLoader::LoadLC( resourceID ); |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------- |
|
243 // CWmlStateSingle::OptionMenuPermissionsL() |
|
244 // --------------------------------------------------------- |
|
245 void CWmlStateSingle::OptionMenuPermissionsL( TUint32& aPermissions ) const |
|
246 { |
|
247 switch ( iState ) |
|
248 { |
|
249 case EWmlBCViewerBookmarkOne: |
|
250 { |
|
251 aPermissions |= EMsgBioCallBack |
|
252 | EMsgBioDelete |
|
253 | EMsgBioMessInfo |
|
254 | EMsgBioMove |
|
255 | EMsgBioHelp |
|
256 | EMsgBioCreateCC; |
|
257 break; |
|
258 } |
|
259 default: |
|
260 { |
|
261 Panic(EIllegalCommandInCurrentState); |
|
262 break; |
|
263 } |
|
264 } |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CWmlStateSingle::SetMenuCommandSetL() |
|
269 // --------------------------------------------------------- |
|
270 void CWmlStateSingle::SetMenuCommandSetL( CEikMenuPane& aMenuPane ) |
|
271 { |
|
272 switch ( iState ) |
|
273 { |
|
274 case EWmlBCViewerBookmarkOne: |
|
275 { |
|
276 iBioControl->AddMenuItemL( aMenuPane, R_QTN_SM_ADD_BOOKMARKS, |
|
277 EAddBookmark, 1 ); |
|
278 break; |
|
279 } |
|
280 default: |
|
281 { |
|
282 break; |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CWmlStateSingle::VirtualHeight() |
|
289 // --------------------------------------------------------- |
|
290 TInt CWmlStateSingle::VirtualHeight() |
|
291 { |
|
292 TInt height = iBioControl->iRichBio->VirtualHeight(); |
|
293 return height; |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------- |
|
297 // CWmlStateSingle::VirtualVisibleTop() |
|
298 // --------------------------------------------------------- |
|
299 TInt CWmlStateSingle::VirtualVisibleTop() |
|
300 { |
|
301 TInt top = iBioControl->iRichBio->VirtualVisibleTop(); |
|
302 return top; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------- |
|
306 // CWmlStateSingle::IsCursorLocation() |
|
307 // --------------------------------------------------------- |
|
308 TBool CWmlStateSingle::IsCursorLocation( TMsgCursorLocation aLocation ) const |
|
309 { |
|
310 TBool location( iBioControl->iRichBio->IsCursorLocation( aLocation ) ); |
|
311 return location; |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------- |
|
315 // CWmlStateSingle::OfferKeyEventL() |
|
316 // --------------------------------------------------------- |
|
317 TKeyResponse CWmlStateSingle::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
318 TEventCode aType ) |
|
319 { |
|
320 return iBioControl->iRichBio->OfferKeyEventL( aKeyEvent, aType ); |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CWmlStateSingle::SizeChanged() |
|
325 // --------------------------------------------------------- |
|
326 void CWmlStateSingle::SizeChanged() |
|
327 { |
|
328 iBioControl->iRichBio->SetExtent(iBioControl->Position(), |
|
329 iBioControl->iRichBio->Size()); |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------- |
|
333 // CWmlStateSingle::FocusChanged() |
|
334 // --------------------------------------------------------- |
|
335 void CWmlStateSingle::FocusChanged( TDrawNow aDrawNow ) |
|
336 { |
|
337 iBioControl->iRichBio->SetFocus( iBioControl->IsFocused(), aDrawNow ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // CWmlStateSingle::CreateViewerL() |
|
342 // --------------------------------------------------------- |
|
343 void CWmlStateSingle::CreateViewerL( const CCoeControl& aContainer ) |
|
344 { |
|
345 CRichBio* richBio = CRichBio::NewL( &aContainer, ERichBioModeStandard ); |
|
346 CleanupStack::PushL( richBio ); |
|
347 |
|
348 CWmlSubItemBase& currentItem = iBioControl->iItemEngine->CurrentItem(); |
|
349 CArrayPtrFlat<CMsgNameValue>* labelsAndValues = |
|
350 currentItem.LabelsAndValuesLC(); |
|
351 TInt count = labelsAndValues->Count(); |
|
352 for ( TInt i = 0; i < count; i++ ) |
|
353 { |
|
354 CMsgNameValue* nameValue = labelsAndValues->At( i ); |
|
355 richBio->AddItemL( nameValue->Name(), nameValue->Value() ); |
|
356 } |
|
357 // We can't check the item because the object actually is |
|
358 // TCleanupItem |
|
359 CleanupStack::PopAndDestroy();// labelsAndValues ); |
|
360 |
|
361 CleanupStack::Pop( richBio ); |
|
362 iBioControl->iRichBio = richBio; |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------- |
|
366 // CWmlStateSingle::CursorInFirstLine() |
|
367 // --------------------------------------------------------- |
|
368 TBool CWmlStateSingle::CursorInFirstLine() const |
|
369 { |
|
370 return iBioControl->iRichBio->IsCursorLocation(EMsgTop); |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------- |
|
374 // CWmlStateSingle::GetHelpContext() |
|
375 // --------------------------------------------------------- |
|
376 void CWmlStateSingle::GetHelpContext(TCoeHelpContext& aHelpContext) const |
|
377 { |
|
378 switch ( iState ) |
|
379 { |
|
380 case EWmlBCViewerBookmarkOne: |
|
381 { |
|
382 aHelpContext.iContext = KSMART_HLP_ONEBOOKVIEWER; |
|
383 break; |
|
384 } |
|
385 default: |
|
386 { |
|
387 Panic( EIllegalStateTransition ); |
|
388 break; |
|
389 } |
|
390 } |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------- |
|
394 // CWmlStateSingle::EnterL() |
|
395 // --------------------------------------------------------- |
|
396 void CWmlStateSingle::EnterL( TWmlState aState ) |
|
397 { |
|
398 // This is a check for valid state transitions. |
|
399 switch ( aState ) |
|
400 { |
|
401 case EWmlBCViewerBookmarkOne: |
|
402 { |
|
403 break; |
|
404 } |
|
405 default: |
|
406 { |
|
407 Panic( EIllegalStateTransition ); |
|
408 break; |
|
409 } |
|
410 } |
|
411 iState = aState; |
|
412 iBioControl->UpdateHeaderTextL(); |
|
413 } |
|
414 |
|
415 // End of file |