|
1 /* |
|
2 * Copyright (c) 2003 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: Implementation of CMIDUIManager |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <bldvariant.hrh> |
|
19 |
|
20 // CDictionaryFileStore API to open ini file |
|
21 #include <s32file.h> |
|
22 #include <bautils.h> |
|
23 #include <eikenv.h> |
|
24 #include <eikappui.h> |
|
25 #include <j2me/jdebug.h> |
|
26 |
|
27 #include "CMIDUIManager.h" |
|
28 // CMIDTickerController API to obtain instance |
|
29 #include "CMIDTicker.h" |
|
30 #include "CMIDDisplayable.h" |
|
31 #include "CMIDCanvas.h" |
|
32 #include "CMIDKeyDecoder.h" |
|
33 #include "CMIDScaler.h" |
|
34 #include "CMIDCanvasKeypad.h" |
|
35 #include "CMIDDefaultBackground.h" |
|
36 |
|
37 /** This macro is executed each time a trapped call returns an error code different than KErrNone */ |
|
38 #undef TRAP_INSTRUMENTATION_LEAVE |
|
39 #define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDDisplayable.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult); |
|
40 |
|
41 #ifdef CANVAS_ZOOM_SUPPORT |
|
42 const TUid KUidZoomIndex={0x10003EE0}; |
|
43 #endif |
|
44 |
|
45 CMIDUIManager* CMIDUIManager::NewL(MMIDEnv& aEnv) |
|
46 { |
|
47 CMIDUIManager* uiManager = new(ELeave)CMIDUIManager(aEnv); |
|
48 CleanupStack::PushL(uiManager); |
|
49 uiManager->ConstructL(); |
|
50 CleanupStack::Pop(uiManager); |
|
51 return uiManager; |
|
52 } |
|
53 |
|
54 void CMIDUIManager::ConstructL() |
|
55 { |
|
56 iEnv.AddObserverL(*this); |
|
57 RestoreIniL(); |
|
58 |
|
59 } |
|
60 |
|
61 CMIDUIManager::CMIDUIManager(MMIDEnv& aEnv) |
|
62 : iEnv(aEnv) |
|
63 { |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CMIDUIManager::~CMIDUIManager() |
|
71 { |
|
72 CloseDefaultDisplayable(); |
|
73 iEnv.RemoveObserver(*this); |
|
74 TRAP_IGNORE(StoreIniL()); |
|
75 delete iMenuHandler; |
|
76 delete iNaviPaneController; |
|
77 delete iKeyDecoder; |
|
78 delete iScaler; |
|
79 delete iCanvasKeypad; |
|
80 } |
|
81 |
|
82 void CMIDUIManager::ZoomIn() |
|
83 { |
|
84 #ifdef CANVAS_ZOOM_SUPPORT |
|
85 TInt zoomState = iZoomState; |
|
86 if (++ zoomState > EZoomMax) |
|
87 { |
|
88 zoomState=EZoomMin; |
|
89 } |
|
90 SetZoomState(zoomState); |
|
91 #endif |
|
92 } |
|
93 |
|
94 void CMIDUIManager::ZoomOut() |
|
95 { |
|
96 #ifdef CANVAS_ZOOM_SUPPORT |
|
97 TInt zoomState = iZoomState; |
|
98 if (-- zoomState < EZoomMin) |
|
99 { |
|
100 zoomState = EZoomMax; |
|
101 } |
|
102 SetZoomState(zoomState); |
|
103 #endif |
|
104 } |
|
105 |
|
106 #ifdef CANVAS_ZOOM_SUPPORT |
|
107 void CMIDUIManager::SetZoomState(TInt aZoomState) |
|
108 { |
|
109 if (iZoomState != aZoomState) |
|
110 { |
|
111 iZoomState = aZoomState; |
|
112 |
|
113 MMIDDisplayable* displayable = iEnv.Current(); |
|
114 MMIDComponent* content = (displayable ? displayable->Component() : NULL); |
|
115 if (content) |
|
116 { |
|
117 if (content->Type() == MMIDComponent::ECanvas) |
|
118 { |
|
119 CMIDCanvas* canvas = static_cast<CMIDCanvas*>(content); |
|
120 canvas->SetZoomState(iZoomState); |
|
121 } |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 *@return the current canvas zoom state. |
|
128 */ |
|
129 TInt CMIDUIManager::ZoomState() const |
|
130 { |
|
131 return iZoomState; |
|
132 } |
|
133 #endif |
|
134 |
|
135 void CMIDUIManager::StoreIniL() |
|
136 { |
|
137 #ifdef CANVAS_ZOOM_SUPPORT |
|
138 CDictionaryStore* iniFile = OpenIniFileLC(CCoeEnv::Static()->FsSession()); |
|
139 RDictionaryWriteStream writeStream; |
|
140 writeStream.AssignLC(*iniFile,KUidZoomIndex); |
|
141 writeStream.WriteInt32L(iZoomState); |
|
142 writeStream.CommitL(); |
|
143 iniFile->CommitL(); |
|
144 CleanupStack::PopAndDestroy(2); //writeStream, iniFile |
|
145 #endif |
|
146 } |
|
147 |
|
148 void CMIDUIManager::RestoreIniL() |
|
149 { |
|
150 #ifdef CANVAS_ZOOM_SUPPORT |
|
151 TInt zoomState; |
|
152 |
|
153 CDictionaryStore* iniFile=OpenIniFileLC(CCoeEnv::Static()->FsSession()); |
|
154 if (!iniFile->IsNullL()) |
|
155 { |
|
156 RDictionaryReadStream readStream; |
|
157 readStream.OpenLC(*iniFile,KUidZoomIndex); |
|
158 zoomState = readStream.ReadInt32L(); |
|
159 CleanupStack::PopAndDestroy(); //readStream |
|
160 } |
|
161 else |
|
162 { |
|
163 zoomState = EZoomMin; |
|
164 } |
|
165 CleanupStack::PopAndDestroy(iniFile); |
|
166 |
|
167 SetZoomState(zoomState); |
|
168 #endif |
|
169 } |
|
170 |
|
171 // |
|
172 // Opens the ini file if it exists, otherwise creates a new one |
|
173 // |
|
174 CDictionaryStore* CMIDUIManager::OpenIniFileLC(RFs& aFs) const |
|
175 { |
|
176 TBuf<KMaxFileName> iniName; |
|
177 iniName.Append(iEnv.MidletHome()); |
|
178 _LIT(KSeparator,"\\"); |
|
179 iniName.Append(KSeparator); |
|
180 iniName.Append(iEnv.MidletName()); |
|
181 _LIT(KIniExtension,".ini"); |
|
182 iniName.Append(KIniExtension); |
|
183 // |
|
184 // ensure that all directories in the path exist |
|
185 // |
|
186 aFs.MkDirAll(iniName); // ignore the error |
|
187 // |
|
188 CDictionaryStore* inifile=NULL; |
|
189 // |
|
190 // if first attempt to open ini fails because of corrupt file, delete it and try again. |
|
191 // |
|
192 TRAPD(err,inifile=CDictionaryFileStore::OpenL(aFs,iniName,iEnv.MidletUid())); |
|
193 if (err==KErrNone) |
|
194 CleanupStack::PushL(inifile); |
|
195 else if (err==KErrEof || err==KErrCorrupt) |
|
196 { |
|
197 User::LeaveIfError(aFs.Delete(iniName)); |
|
198 inifile=CDictionaryFileStore::OpenLC(aFs,iniName,iEnv.MidletUid()); |
|
199 err=KErrNone; |
|
200 } |
|
201 User::LeaveIfError(err); |
|
202 return inifile; |
|
203 } |
|
204 |
|
205 void CMIDUIManager::HandleResourceChangeL(TInt /*aType*/) |
|
206 { |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CMIDUIManager::HandleSwitchOnL(TBool aSwitchOn) |
|
214 { |
|
215 OpenNaviPaneControllerL()->ShowTickerL(aSwitchOn); |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 void CMIDUIManager::HandleForegroundL(TBool aForeground) |
|
223 { |
|
224 if (iNaviPaneController) |
|
225 { |
|
226 GetNaviPaneController()->ShowTickerL(aForeground); |
|
227 } |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 CMIDMenuHandler* CMIDUIManager::OpenMenuHandlerL() |
|
235 { |
|
236 if (!iMenuHandler) |
|
237 { |
|
238 iMenuHandler = CMIDMenuHandler::NewL(iEnv); |
|
239 } |
|
240 return iMenuHandler; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 CMIDMenuHandler* CMIDUIManager::GetMenuHandler() |
|
248 { |
|
249 return iMenuHandler; |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 CMIDNaviPaneController* CMIDUIManager::OpenNaviPaneControllerL() |
|
257 { |
|
258 if (!iNaviPaneController) |
|
259 { |
|
260 iNaviPaneController = CMIDNaviPaneController::NewL(); |
|
261 } |
|
262 return iNaviPaneController; |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 CMIDNaviPaneController* CMIDUIManager::GetNaviPaneController() |
|
270 { |
|
271 return iNaviPaneController; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 CMIDKeyDecoder* CMIDUIManager::OpenKeyDecoderL() |
|
279 { |
|
280 |
|
281 if (!iKeyDecoder) |
|
282 { |
|
283 iKeyDecoder = CMIDKeyDecoder::NewL(iEnv); |
|
284 } |
|
285 return iKeyDecoder; |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 CMIDKeyDecoder* CMIDUIManager::GetKeyDecoder() |
|
293 { |
|
294 return iKeyDecoder; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 CMIDScaler* CMIDUIManager::OpenScalerL() |
|
302 { |
|
303 if (!iScaler) |
|
304 { |
|
305 iScaler = CMIDScaler::NewL(); |
|
306 } |
|
307 iScaler->iRefC++; |
|
308 return iScaler; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 CMIDScaler* CMIDUIManager::GetScaler(TBool aIsOwner) |
|
316 { |
|
317 if (iScaler && aIsOwner) |
|
318 { |
|
319 iScaler->iRefC++; |
|
320 } |
|
321 return iScaler; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CMIDUIManager::CloseScaler(CMIDScaler* /*aScaler*/) |
|
329 { |
|
330 if (iScaler) |
|
331 { |
|
332 if (iScaler->iRefC > 0) |
|
333 { |
|
334 iScaler->iRefC--; |
|
335 } |
|
336 |
|
337 if (iScaler->iRefC <= 0) |
|
338 { |
|
339 delete iScaler; |
|
340 iScaler = NULL; |
|
341 } |
|
342 } |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 CMIDCanvasKeypad* CMIDUIManager::OpenCanvasKeypadL(MMIDDisplayable* aDisplayable) |
|
350 { |
|
351 if (aDisplayable) |
|
352 { |
|
353 if (!iCanvasKeypad) |
|
354 { |
|
355 iCanvasKeypad = CMIDCanvasKeypad::NewL(aDisplayable); |
|
356 } |
|
357 iCanvasKeypad->iRefC++; |
|
358 } |
|
359 return iCanvasKeypad; |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 CMIDCanvasKeypad* CMIDUIManager::GetCanvasKeypad(TBool aIsOwner) |
|
367 { |
|
368 if (iCanvasKeypad && aIsOwner) |
|
369 { |
|
370 iCanvasKeypad->iRefC++; |
|
371 } |
|
372 return iCanvasKeypad; |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 void CMIDUIManager::CloseCanvasKeypad(CMIDCanvasKeypad* aCanvasKeypad) |
|
380 { |
|
381 if (iCanvasKeypad && iCanvasKeypad == aCanvasKeypad) |
|
382 { |
|
383 if (iCanvasKeypad->iRefC > 0) |
|
384 { |
|
385 iCanvasKeypad->iRefC--; |
|
386 } |
|
387 |
|
388 if (iCanvasKeypad->iRefC <= 0) |
|
389 { |
|
390 delete iCanvasKeypad; |
|
391 iCanvasKeypad = NULL; |
|
392 } |
|
393 } |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 // parameter aVisible is for DafaultDisplayable visibility. |
|
401 CMIDDisplayable* CMIDUIManager::OpenDefaultDisplayableL(TBool aVisible) |
|
402 { |
|
403 if (!iDefaultDisplayable) |
|
404 { |
|
405 iDefaultDisplayable = CMIDDisplayable::NewL(iEnv, *this); |
|
406 CCoeControl& window = static_cast< CMIDDisplayable& >(*iDefaultDisplayable).ContentWindow(); |
|
407 iDefaultBackground = CMIDDefaultBackground::NewL(window); |
|
408 iDefaultDisplayable->SetComponentL(*iDefaultBackground); |
|
409 // call HandleCurrent with TRUE for store pointer of Displayable |
|
410 iDefaultDisplayable->HandleCurrentL(ETrue); |
|
411 // Default displayable is not currnet in this moment |
|
412 iDefaultDisplayable->HandleCurrentL(EFalse); |
|
413 iDefaultDisplayable->MakeVisible(aVisible); |
|
414 CEikonEnv::Static()->EikAppUi()->RemoveFromStack(iDefaultBackground); |
|
415 } |
|
416 return iDefaultDisplayable; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 CMIDDisplayable* CMIDUIManager::GetDefaultDisplayable() |
|
424 { |
|
425 return iDefaultDisplayable; |
|
426 } |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 void CMIDUIManager::CloseDefaultDisplayable() |
|
433 { |
|
434 if (iDefaultDisplayable) |
|
435 { |
|
436 // HandleCurrentL cannot leave when called with argument EFalse, |
|
437 // but because of naming convention we cannot trust that is the |
|
438 // case in the future so trap it anyway. |
|
439 TInt err = 0; |
|
440 DEBUG("CMIDMenuHandler::RemoveDefaultDisplayable - calling iDefaultDisplayable->HandleCurrentL"); |
|
441 TRAP(err, iDefaultDisplayable->HandleCurrentL(EFalse)); |
|
442 if (err != KErrNone) |
|
443 { |
|
444 DEBUG_INT("CMIDMenuHandler::RemoveDefaultDisplayable - Exception from HandleCurrentL. Error = %d", err); |
|
445 } |
|
446 |
|
447 delete iDefaultBackground; |
|
448 iDefaultBackground = NULL; |
|
449 |
|
450 iDefaultDisplayable->Dispose(); |
|
451 iDefaultDisplayable = NULL; |
|
452 } |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 TSize CMIDUIManager::ReadPointerEventSuppressorValues() |
|
460 { |
|
461 TSize values; |
|
462 TPtrC suppressorValues; |
|
463 //Read JAD attribute value |
|
464 if (iEnv.MidletAttribute(LcduiMidletAttributes::KAttribPointerEventSuppressorValues, |
|
465 suppressorValues) == KErrNone) |
|
466 { |
|
467 //JAD attribute found. |
|
468 //Attributes are parsed to TSize format + validity check performed. |
|
469 //TSize is used as return value for ease of use. |
|
470 //TSize.iWidth=first value, TSize.iHeight=second value |
|
471 values = TwoDesValuesToTSize(suppressorValues); |
|
472 } |
|
473 else |
|
474 { |
|
475 //No JAD attribute found. Error value returned->Use default values. |
|
476 values = TSize(KPESErrorValue, KPESErrorValue); |
|
477 } |
|
478 |
|
479 return values; |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // CMIDUIManager::TwoDesValuesToTSize |
|
484 // Utility to parse TPtrC to TSize (two values separated with comma). |
|
485 // @param TPtrC |
|
486 // @return TSize |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 TSize CMIDUIManager::TwoDesValuesToTSize(TPtrC values) |
|
490 { |
|
491 TSize newValues; |
|
492 TSize errorValues = TSize(KPESErrorValue, KPESErrorValue); |
|
493 TInt newIntValue1; |
|
494 TInt newIntValue2; |
|
495 // Assumed max. value is 9999. |
|
496 TBuf<KPESParameterLength> value1; |
|
497 // Assumed max. value is 9999. |
|
498 TBuf<KPESParameterLength> value2; |
|
499 TChar tmpChar; |
|
500 _LIT(lComma, ","); |
|
501 TChar comma(','); |
|
502 |
|
503 // value1 and value2 must be divided by comma |
|
504 if (values.Find(lComma) != KErrNotFound) |
|
505 { |
|
506 TLex16 lex(values); |
|
507 while (lex.Peek() != comma) |
|
508 { |
|
509 tmpChar = lex.Get(); |
|
510 if (tmpChar.IsDigit() && value1.Length() < KPESParameterLength) |
|
511 { |
|
512 value1.Append(tmpChar); |
|
513 } |
|
514 else if (!tmpChar.IsSpace()) |
|
515 { |
|
516 // If character is not digit or space |
|
517 return errorValues; |
|
518 } |
|
519 } |
|
520 lex.Get(); |
|
521 while (!lex.Eos()) |
|
522 { |
|
523 tmpChar = lex.Get(); |
|
524 if (tmpChar.IsDigit() && value2.Length() < KPESParameterLength) |
|
525 { |
|
526 value2.Append(tmpChar); |
|
527 } |
|
528 else if (!tmpChar.IsSpace()) |
|
529 { |
|
530 // If character is not digit or space |
|
531 return errorValues; |
|
532 } |
|
533 } |
|
534 |
|
535 // Width and height must have at least one digit each |
|
536 if (value1.Length() > 0 && value2.Length() > 0) |
|
537 { |
|
538 TLex16 widthLex(value1); |
|
539 widthLex.Val(newIntValue1); |
|
540 TLex16 heightLex(value2); |
|
541 heightLex.Val(newIntValue2); |
|
542 newValues.SetSize(TInt(newIntValue1), TInt(newIntValue2)); |
|
543 return newValues; |
|
544 } |
|
545 } |
|
546 // If there is no comma between the digits or there is no digits in value1 or value2 |
|
547 return errorValues; |
|
548 } |
|
549 |
|
550 // End of File |