|
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: Source file of "CCalcContainer", CCalcContainer class |
|
15 * which derived from CCoeControl class. Role of this class |
|
16 * is to update the calculator data and display on user's input. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <aknkeys.h> |
|
23 #include <AknUtils.h> // AknLayoutUtils::LayoutControl |
|
24 #include <Calcsoft.rsg> |
|
25 |
|
26 #include <layoutmetadata.cdl.h> |
|
27 |
|
28 // For skin support. |
|
29 #include <AknsDrawUtils.h> |
|
30 #include <AknsConstants.h> |
|
31 #include <AknsUtils.h> |
|
32 #include <AknsBasicBackgroundControlContext.h> |
|
33 #include <applayout.cdl.h> |
|
34 #include <aknlayoutscalable_apps.cdl.h> |
|
35 #include <csxhelp/calc.hlp.hrh> // for help context of Calculator |
|
36 #include "CalcApp.h" |
|
37 |
|
38 #include "CalcAppUi.h" |
|
39 #include "CalcCont.h" |
|
40 #include "CalcDoc.h" |
|
41 #include "CalcEdit.h" |
|
42 #include "CalcFunc.h" |
|
43 #include "CalcOutSheet.h" |
|
44 #include "calc.hrh" |
|
45 #include "CalcView.h" |
|
46 #include "CalcEnv.h" |
|
47 #include "CalcHistory.h" |
|
48 #include "CalcDrawingConst.laf" // for layout information |
|
49 |
|
50 |
|
51 #include <AknDef.h> |
|
52 #include <eiksbfrm.h> |
|
53 #include <eikscrlb.h> |
|
54 |
|
55 |
|
56 #define KEY_CODE_VAL 57 //for all number inputs |
|
57 #define ASCII_ZERO 48 |
|
58 |
|
59 // LOCAL CONSTANTS AND MACROS |
|
60 const TInt KCallBackDelay(1000000); // In microseconds |
|
61 const TInt KCallBackInterval(1000000); // In microseconds |
|
62 const TInt KCallBackPriority(CActive::EPriorityUserInput); |
|
63 |
|
64 // Count of controls in Calculator. |
|
65 // Controls are editor pane, output sheet, and function map. |
|
66 // Therefore, this count is 3. |
|
67 const TInt KCalcCountOfControls(3); |
|
68 |
|
69 // Define index of control |
|
70 enum TCalcControlIndex |
|
71 { |
|
72 ECalcControlFunctionMap, |
|
73 ECalcControlOutputSheet, |
|
74 ECalcControlEditorPane |
|
75 }; |
|
76 |
|
77 // If const TChar is used, complie error occurs in THUMB build. |
|
78 // To avoid this, #define is used. |
|
79 #define KCalcAsteriskBtn '*' |
|
80 |
|
81 |
|
82 // ================= MEMBER FUNCTIONS ======================= |
|
83 |
|
84 // Two-phased constructor. |
|
85 CCalcContainer* CCalcContainer::NewL( |
|
86 CCalcView* aView) |
|
87 { |
|
88 CCalcContainer* self = new (ELeave) CCalcContainer(); |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(aView); |
|
91 CleanupStack::Pop(self); |
|
92 return self; |
|
93 } |
|
94 |
|
95 |
|
96 // Destructor |
|
97 CCalcContainer::~CCalcContainer() |
|
98 { |
|
99 delete iEditorPane; |
|
100 delete iFuncmapPane; |
|
101 delete iSheetPane; |
|
102 |
|
103 delete iTimeout; |
|
104 |
|
105 if ( iTimeoutChr ) |
|
106 { |
|
107 delete iTimeoutChr; |
|
108 iTimeoutChr = NULL; |
|
109 } |
|
110 if ( iTimeoutShift ) |
|
111 { |
|
112 delete iTimeoutShift; |
|
113 iTimeoutShift = NULL; |
|
114 } |
|
115 |
|
116 delete iSkinContext; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CCalcContainer::ProcessPreinputL |
|
121 // This function is called when decimal point or a digit is inputted. |
|
122 // (other items were commented in a header). |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 void CCalcContainer::ProcessPreinputL() |
|
126 { |
|
127 TInt currentState = iView->State(); |
|
128 CCalcView::TKindOfInput latestInput(iView->LatestInput()); |
|
129 |
|
130 if (currentState == CCalcView::ESelectResult) |
|
131 // State 5 : User has selected result |
|
132 { |
|
133 iEditorPane->ResetL(); // Set editline "0" |
|
134 iView->UpdateState(CCalcView::EAllClear); |
|
135 iCalcDocument->AddEmptyLine(); |
|
136 iSheetPane->ScrollToBottomL(); |
|
137 ScrollArrowUpdate(); |
|
138 } |
|
139 else if (currentState == CCalcView::EOperandAndOperator || |
|
140 // State 3 : operand and operator |
|
141 latestInput == CCalcView::EMemoryRecall || |
|
142 latestInput == CCalcView::EMemorySave) |
|
143 { |
|
144 iEditorPane->ClearOperand(); |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CCalcContainer::InputClearL |
|
150 // This function should be called when editor is cleared. |
|
151 // (other items were commented in a header). |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 void CCalcContainer::InputClearL() |
|
155 { |
|
156 iEditorPane->ResetL(); |
|
157 iView->UpdateState(CCalcView::EAllClear); |
|
158 |
|
159 const TCalcEditLine lastLine((*(iCalcDocument->History()))[0]); |
|
160 // Get latest historical line. |
|
161 const TPtrC number(lastLine.NumberString()); |
|
162 |
|
163 // If latest historical line is not empty, |
|
164 // empty line is added in the history and the history is shown. |
|
165 if ( number.Length() ) |
|
166 { |
|
167 iCalcDocument->AddEmptyLine(); |
|
168 iSheetPane->ScrollToBottomL(); |
|
169 ScrollArrowUpdate(); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CCalcContainer::ScrollArrowUpdate |
|
175 // This function should be called when OutputSheet is scrolled |
|
176 // or history is added. |
|
177 // (other items were commented in a header). |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 void CCalcContainer::ScrollArrowUpdate() |
|
181 { |
|
182 iFuncmapPane->RedrawScrollButtons(); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CCalcContainer::SetChangeSignEnableL |
|
187 // This function is called when number of editor is changed. |
|
188 // (other items were commented in a header). |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 void CCalcContainer::SetChangeSignEnableL() |
|
192 { |
|
193 TCalcEditLine editLine(iEditorPane->EditLine()); |
|
194 TBool changeSignEnable(ETrue); |
|
195 |
|
196 if (editLine.NumberL() == 0.0) |
|
197 { |
|
198 changeSignEnable = EFalse; |
|
199 } |
|
200 |
|
201 iFuncmapPane->SetChangeSignEnable(changeSignEnable); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CCalcContainer::SetClearKeyEnable |
|
206 // This function is called when number of editor is changed. |
|
207 // (other items were commented in a header). |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 void CCalcContainer::SetClearKeyEnable() |
|
211 { |
|
212 TCalcEditLine editLine( iEditorPane->EditLine() ); |
|
213 TBool clearKeyEnable( ETrue ); |
|
214 |
|
215 // eitline's number is 0.0 and length is 1 and the no operator |
|
216 TRAP_IGNORE( |
|
217 { |
|
218 if ( editLine.CheckZeroL() && ( editLine.Operator() == |
|
219 TCalcEditLine::ECalcOperatorNone ) ) |
|
220 { |
|
221 clearKeyEnable = EFalse; |
|
222 } |
|
223 } |
|
224 ) |
|
225 iFuncmapPane->SetClearKeyEnable( clearKeyEnable ); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 // CCalcContainer::SetChangeSignDisable |
|
230 // This function is called when Operator +, - , *, / key is pressed. |
|
231 // (other items were commented in a header). |
|
232 // --------------------------------------------------------- |
|
233 // |
|
234 void CCalcContainer::SetChangeSignDisable() |
|
235 { |
|
236 |
|
237 TBool changeSignEnable(EFalse); |
|
238 iFuncmapPane->SetChangeSignEnable(changeSignEnable); |
|
239 |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------- |
|
243 // CCalcContainer::SetSqrtEnableL |
|
244 // This function is called when number of editor is changed. |
|
245 // (other items were commented in a header). |
|
246 // --------------------------------------------------------- |
|
247 // |
|
248 void CCalcContainer::SetSqrtEnableL() |
|
249 { |
|
250 TCalcEditLine editLine(iEditorPane->EditLine()); |
|
251 TBool sqrtEnable(ETrue); |
|
252 |
|
253 if ( editLine.NumberL() == 0.0 ) |
|
254 { |
|
255 sqrtEnable = EFalse; |
|
256 } |
|
257 iFuncmapPane->SetSqrtEnable(sqrtEnable); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CCalcContainer::SetPercentEnableL |
|
262 // This function is called when number of editor is changed. |
|
263 // (other items were commented in a header). |
|
264 // --------------------------------------------------------- |
|
265 // |
|
266 void CCalcContainer::SetPercentEnableL() |
|
267 { |
|
268 TCalcEditLine editLine(iEditorPane->EditLine()); |
|
269 TBool percentEnable(ETrue); |
|
270 |
|
271 if (editLine.NumberL() == 0.0) |
|
272 { |
|
273 percentEnable = EFalse; |
|
274 } |
|
275 iFuncmapPane->SetPercentEnable(percentEnable); |
|
276 } |
|
277 |
|
278 |
|
279 // --------------------------------------------------------- |
|
280 // CCalcContainer::TimeoutCallbackL |
|
281 // If no key is pressed after pressing *-button and a few time |
|
282 // passes, this function is called |
|
283 // (other items were commented in a header). |
|
284 // --------------------------------------------------------- |
|
285 // |
|
286 TInt CCalcContainer::TimeoutCallbackL( |
|
287 TAny* aObject) |
|
288 { |
|
289 STATIC_CAST(CCalcContainer*, aObject)->DoTimeoutL(); |
|
290 return 0; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------- |
|
294 // CCalcContainer::TimeoutCallbackL |
|
295 // If no key is pressed after pressing */button and a few time |
|
296 // passes, this function is called |
|
297 // (other items were commented in a header). |
|
298 // --------------------------------------------------------- |
|
299 // |
|
300 TInt CCalcContainer::TimeoutCallbackChrL( |
|
301 TAny* aObject) |
|
302 { |
|
303 STATIC_CAST( CCalcContainer*, aObject )->DoTimeoutChrL(); |
|
304 return 0; |
|
305 } |
|
306 // --------------------------------------------------------- |
|
307 // CCalcContainer::TimeoutCallbackL |
|
308 // If no key is pressed after pressing +#button and a few time |
|
309 // passes, this function is called |
|
310 // (other items were commented in a header). |
|
311 // --------------------------------------------------------- |
|
312 // |
|
313 TInt CCalcContainer::TimeoutCallbackShiftL( |
|
314 TAny* aObject) |
|
315 { |
|
316 STATIC_CAST(CCalcContainer*, aObject)->DoTimeoutShiftL(); |
|
317 return 0; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------- |
|
321 // CCalcContainer::NotifyChangeDecimal |
|
322 // Call when decimal separator is changed. |
|
323 // (other items were commented in a header). |
|
324 // --------------------------------------------------------- |
|
325 // |
|
326 void CCalcContainer::NotifyChangeDecimal(TChar aOld, TChar aNew) |
|
327 { |
|
328 iEditorPane->NotifyChangeDecimal(aOld, aNew); |
|
329 iSheetPane->DrawNow(); |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------- |
|
333 // CCalcContainer::SetErrorCode |
|
334 // Call from view when an error code is display. |
|
335 // --------------------------------------------------------- |
|
336 // |
|
337 void CCalcContainer::SetErrorCode(TInt aError) |
|
338 { |
|
339 iFuncmapPane->SetErrorCode( aError ); |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------- |
|
343 // CCalcContainer::GetHelpContext |
|
344 // This function is called when Help application is launched. |
|
345 // (other items were commented in a header). |
|
346 // --------------------------------------------------------- |
|
347 // |
|
348 void CCalcContainer::GetHelpContext( |
|
349 TCoeHelpContext& aContext) const |
|
350 { |
|
351 aContext.iMajor = KUidCalc; |
|
352 aContext.iContext = KCALC_HLP_MAIN; |
|
353 } |
|
354 |
|
355 // C++ default constructor can NOT contain any code, that |
|
356 // might leave. |
|
357 // |
|
358 CCalcContainer::CCalcContainer(): |
|
359 iPrevInput(EKeyNull) |
|
360 { |
|
361 } |
|
362 |
|
363 // Second-phase constructor |
|
364 void CCalcContainer::ConstructL( |
|
365 CCalcView* aView) |
|
366 { |
|
367 iView = aView; |
|
368 CCalcAppUi* appui = CCalcAppEnv::Static()->AppUi(); |
|
369 iCalcDocument = STATIC_CAST(CCalcDocument*, appui->Document()); |
|
370 |
|
371 // Make a window-owning control. |
|
372 CreateWindowL(); |
|
373 |
|
374 |
|
375 |
|
376 iFuncmapPane = CCalcFuncmapSubPane::NewL(this); |
|
377 iSheetPane = CCalcOutputSheet::NewL(this); |
|
378 iEditorPane = CCalcEditorSubPane::NewL(this); |
|
379 |
|
380 iTimeout = CPeriodic::NewL(KCallBackPriority); |
|
381 |
|
382 iTimeoutChr = CPeriodic::NewL( KCallBackPriority ); |
|
383 iTimeoutShift = CPeriodic::NewL( KCallBackPriority ); |
|
384 |
|
385 TRect rect(0, 0, 0, 0); |
|
386 // Temporary rect is passed. Correct rect is set in SizeChanged. |
|
387 iSkinContext = CAknsBasicBackgroundControlContext::NewL( |
|
388 KAknsIIDQsnBgAreaMainCalc, rect, EFalse); |
|
389 iValue = 0; |
|
390 |
|
391 // Set status pane layout usual. |
|
392 CEikonEnv::Static()->AppUiFactory()->StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL ); |
|
393 } |
|
394 |
|
395 void CCalcContainer::ActivateL() |
|
396 { |
|
397 |
|
398 CCoeControl::ActivateL(); |
|
399 SetChangeSignEnableL(); |
|
400 SetSqrtEnableL(); |
|
401 SetPercentEnableL(); |
|
402 ScrollArrowUpdate(); |
|
403 SetClearKeyEnable(); |
|
404 } |
|
405 |
|
406 |
|
407 // --------------------------------------------------------- |
|
408 // CCalcContainer::DoTimeoutL |
|
409 // If no key is pressed until timeout of *-key, |
|
410 // this function is called. |
|
411 // (other items were commented in a header). |
|
412 // --------------------------------------------------------- |
|
413 // |
|
414 void CCalcContainer::DoTimeoutL() |
|
415 { |
|
416 iTimeout->Cancel(); |
|
417 iFuncmapPane->NotifyTimeoutL(); |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------- |
|
421 // CCalcContainer::DoTimeoutL |
|
422 // If no key is pressed until timeout of */key, |
|
423 // this function is called. |
|
424 // (other items were commented in a header). |
|
425 // --------------------------------------------------------- |
|
426 // |
|
427 void CCalcContainer::DoTimeoutChrL() |
|
428 { |
|
429 iTimeoutChr->Cancel(); |
|
430 iFuncmapPane->NotifyTimeoutL(); |
|
431 } |
|
432 // --------------------------------------------------------- |
|
433 // CCalcContainer::DoTimeoutL |
|
434 // If no key is pressed until timeout of +#key, |
|
435 // this function is called. |
|
436 // (other items were commented in a header). |
|
437 // --------------------------------------------------------- |
|
438 // |
|
439 void CCalcContainer::DoTimeoutShiftL() |
|
440 { |
|
441 iTimeoutShift->Cancel(); |
|
442 iFuncmapPane->NotifyTimeoutL(); |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL |
|
447 // Called when any key is pressed. |
|
448 // If timeout notifier for *-key is active, make calculation or |
|
449 // stop notifier according to user's input. |
|
450 // (other items were commented in a header). |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 TBool CCalcContainer::HandleAsterKeyTimeoutForKeyPressL( |
|
454 const TKeyEvent& aKeyEvent, TEventCode aType) |
|
455 { |
|
456 if (!(iTimeout->IsActive())) |
|
457 { |
|
458 return EFalse; |
|
459 } |
|
460 |
|
461 TBool ret(EFalse); |
|
462 |
|
463 if (aKeyEvent.iModifiers & EModifierShift) |
|
464 { |
|
465 // Stop timer for *-key and make calculaiton. |
|
466 DoTimeoutL(); |
|
467 } |
|
468 |
|
469 if (aType == EEventKey) |
|
470 { |
|
471 switch (aKeyEvent.iCode) |
|
472 { |
|
473 // Stop timer and no calculation is made |
|
474 // if pressed arrow or OK key. |
|
475 // This depends on spec of Editing. |
|
476 case EKeyLeftArrow: |
|
477 case EKeyRightArrow: |
|
478 case EKeyUpArrow: |
|
479 case EKeyDownArrow: |
|
480 case EKeyOK: |
|
481 { |
|
482 DoTimeoutL(); |
|
483 ret = ETrue; |
|
484 break; |
|
485 } |
|
486 // Stop timer if *-key is pressed. |
|
487 // If release *-key, reset timer for the key. |
|
488 case KCalcAsteriskBtn: |
|
489 { |
|
490 iTimeout->Cancel(); |
|
491 break; |
|
492 } |
|
493 default: |
|
494 { |
|
495 // Stop timer for *-key and make calculaiton. |
|
496 DoTimeoutL(); |
|
497 break; |
|
498 } |
|
499 } |
|
500 } |
|
501 return ret; |
|
502 } |
|
503 |
|
504 // --------------------------------------------------------- |
|
505 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL |
|
506 // Called when any key is pressed. |
|
507 // If timeout notifier for */key is active, make calculation or |
|
508 // stop notifier according to user's input. |
|
509 // (other items were commented in a header). |
|
510 // --------------------------------------------------------- |
|
511 // |
|
512 TBool CCalcContainer::HandleChrKeyTimeoutForKeyPressL( |
|
513 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
514 { |
|
515 if ( !( iTimeoutChr->IsActive() ) ) |
|
516 { |
|
517 return EFalse; |
|
518 } |
|
519 |
|
520 TBool ret( EFalse ); |
|
521 |
|
522 if ( aKeyEvent.iModifiers & EModifierShift ) |
|
523 { |
|
524 DoTimeoutChrL(); |
|
525 } |
|
526 if ( aKeyEvent.iModifiers & EModifierFunc ) |
|
527 { |
|
528 // Stop timer for */key and make calculaiton. |
|
529 iTimeoutChr->Cancel(); |
|
530 } |
|
531 |
|
532 if ( aType == EEventKey ) |
|
533 { |
|
534 switch ( aKeyEvent.iCode ) |
|
535 { |
|
536 // Stop timer and no calculation is made |
|
537 // if pressed arrow or OK key. |
|
538 // This depends on spec of Editing. |
|
539 case EKeyLeftArrow: |
|
540 case EKeyRightArrow: |
|
541 case EKeyUpArrow: |
|
542 case EKeyDownArrow: |
|
543 case EKeyOK: |
|
544 { |
|
545 DoTimeoutChrL(); |
|
546 ret = ETrue; |
|
547 break; |
|
548 } |
|
549 default: |
|
550 { |
|
551 // Stop timer for */key and make calculaiton. |
|
552 DoTimeoutChrL(); |
|
553 break; |
|
554 } |
|
555 } |
|
556 } |
|
557 return ret; |
|
558 } |
|
559 // --------------------------------------------------------- |
|
560 // CCalcContainer::HandleAsterKeyTimeoutForKeyPressL |
|
561 // Called when any key is pressed. |
|
562 // If timeout notifier for +#key is active, make calculation or |
|
563 // stop notifier according to user's input. |
|
564 // (other items were commented in a header). |
|
565 // --------------------------------------------------------- |
|
566 // |
|
567 TBool CCalcContainer::HandleShiftKeyTimeoutForKeyPressL( |
|
568 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
569 { |
|
570 if ( !( iTimeoutShift->IsActive() ) ) |
|
571 { |
|
572 return EFalse; |
|
573 } |
|
574 |
|
575 TBool ret( EFalse ); |
|
576 |
|
577 if ( aKeyEvent.iModifiers & EModifierShift ) |
|
578 { |
|
579 // Stop timer for +#key and make calculaiton. |
|
580 iTimeoutShift->Cancel(); |
|
581 } |
|
582 if ( aKeyEvent.iModifiers & EModifierFunc ) |
|
583 { |
|
584 DoTimeoutShiftL(); |
|
585 } |
|
586 |
|
587 if ( aType == EEventKey ) |
|
588 { |
|
589 switch ( aKeyEvent.iCode ) |
|
590 { |
|
591 // Stop timer and no calculation is made |
|
592 // if pressed arrow or OK key. |
|
593 // This depends on spec of Editing. |
|
594 case EKeyLeftArrow: |
|
595 case EKeyRightArrow: |
|
596 case EKeyUpArrow: |
|
597 case EKeyDownArrow: |
|
598 case EKeyOK: |
|
599 { |
|
600 DoTimeoutShiftL(); |
|
601 ret = ETrue; |
|
602 break; |
|
603 } |
|
604 default: |
|
605 { |
|
606 // Stop timer for +#key and make calculaiton. |
|
607 DoTimeoutShiftL(); |
|
608 break; |
|
609 } |
|
610 } |
|
611 } |
|
612 return ret; |
|
613 } |
|
614 |
|
615 // --------------------------------------------------------- |
|
616 // CCalcContainer::CountComponentControls |
|
617 // Return count of control components. |
|
618 // (other items were commented in a header). |
|
619 // --------------------------------------------------------- |
|
620 // |
|
621 TInt CCalcContainer::CountComponentControls() const |
|
622 { |
|
623 return KCalcCountOfControls ; |
|
624 } |
|
625 |
|
626 // --------------------------------------------------------- |
|
627 // CCalcContainer::ComponentControl |
|
628 // Return control pointer which correspond to argument aIndex |
|
629 // (other items were commented in a header). |
|
630 // --------------------------------------------------------- |
|
631 // |
|
632 CCoeControl* CCalcContainer::ComponentControl |
|
633 ( TInt aIndex ) const |
|
634 { |
|
635 CCoeControl* control = NULL; |
|
636 |
|
637 switch (aIndex) |
|
638 { |
|
639 case ECalcControlEditorPane: |
|
640 { |
|
641 control = iEditorPane; |
|
642 break; |
|
643 } |
|
644 case ECalcControlFunctionMap: |
|
645 { |
|
646 control = iFuncmapPane; |
|
647 break; |
|
648 } |
|
649 case ECalcControlOutputSheet: |
|
650 { |
|
651 control = iSheetPane; |
|
652 break; |
|
653 } |
|
654 default: |
|
655 { |
|
656 break; |
|
657 } |
|
658 } |
|
659 |
|
660 return control; |
|
661 } |
|
662 |
|
663 // --------------------------------------------------------- |
|
664 // CCalcContainer::OfferKeyEventL |
|
665 // This function is called when a key is pressed. |
|
666 // (other items were commented in a header). |
|
667 // --------------------------------------------------------- |
|
668 // |
|
669 TKeyResponse CCalcContainer::OfferKeyEventL |
|
670 ( const TKeyEvent& aKeyEvent, |
|
671 TEventCode aType ) |
|
672 { |
|
673 switch (aType) |
|
674 { |
|
675 case EEventKeyDown: |
|
676 case EEventKey: |
|
677 { |
|
678 if (aKeyEvent.iScanCode != EStdKeyLeftArrow && |
|
679 aKeyEvent.iScanCode != EStdKeyRightArrow && |
|
680 aKeyEvent.iScanCode != EStdKeyUpArrow && |
|
681 aKeyEvent.iScanCode != EStdKeyDownArrow && |
|
682 aKeyEvent.iCode != EKeyOK && |
|
683 aKeyEvent.iCode != EKeyEnter && |
|
684 aKeyEvent.iScanCode != EStdKeyEnter ) |
|
685 { |
|
686 iFuncmapPane->NotifyOtherThanOkKeyPressed(); |
|
687 } |
|
688 iPrevInput = aKeyEvent.iCode; |
|
689 |
|
690 if(!(iFuncmapPane->IsQwertyKeypadActive())) |
|
691 { |
|
692 if (HandleAsterKeyTimeoutForKeyPressL(aKeyEvent, aType)) |
|
693 { |
|
694 return EKeyWasConsumed; |
|
695 } |
|
696 } |
|
697 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
698 else |
|
699 { |
|
700 if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty ) |
|
701 { |
|
702 if ( HandleChrKeyTimeoutForKeyPressL( aKeyEvent, aType ) ) |
|
703 { |
|
704 return EKeyWasConsumed; |
|
705 } |
|
706 if ( HandleShiftKeyTimeoutForKeyPressL( aKeyEvent, aType ) ) |
|
707 { |
|
708 return EKeyWasConsumed; |
|
709 } |
|
710 } |
|
711 } |
|
712 #endif |
|
713 iValue =1 ; |
|
714 break; |
|
715 } |
|
716 case EEventKeyUp: |
|
717 { |
|
718 if(!(iFuncmapPane->IsQwertyKeypadActive())) |
|
719 { |
|
720 |
|
721 if (iPrevInput == KCalcAsteriskBtn && !iTimeout->IsActive() && iValue ==1 ) |
|
722 { |
|
723 TCallBack callback(TimeoutCallbackL, this); |
|
724 iTimeout->Start((TTimeIntervalMicroSeconds32) KCallBackDelay, |
|
725 (TTimeIntervalMicroSeconds32) KCallBackInterval, |
|
726 callback); |
|
727 } |
|
728 } |
|
729 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
730 else |
|
731 { |
|
732 if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty ) |
|
733 { |
|
734 if ( aKeyEvent.iScanCode == EStdKeyLeftFunc && !iTimeoutChr->IsActive() && iValue == 1 ) |
|
735 { |
|
736 TCallBack callback( TimeoutCallbackChrL, this ); |
|
737 iTimeoutChr->Start( ( TTimeIntervalMicroSeconds32 ) KCallBackDelay, |
|
738 ( TTimeIntervalMicroSeconds32 ) KCallBackInterval, |
|
739 callback ); |
|
740 } |
|
741 if ( aKeyEvent.iScanCode == EStdKeyLeftShift && !iTimeoutShift->IsActive() && iValue == 1 ) |
|
742 { |
|
743 TCallBack callback( TimeoutCallbackShiftL, this ); |
|
744 iTimeoutShift->Start( ( TTimeIntervalMicroSeconds32 ) KCallBackDelay, |
|
745 ( TTimeIntervalMicroSeconds32 ) KCallBackInterval, |
|
746 callback ); |
|
747 } |
|
748 } |
|
749 } |
|
750 #endif |
|
751 |
|
752 iFuncmapPane->NotifyReleaseKeyL(); |
|
753 iValue =0; |
|
754 |
|
755 DrawNow(); //redraw screen when a button up |
|
756 break; |
|
757 } |
|
758 default: |
|
759 { |
|
760 break; |
|
761 } |
|
762 } |
|
763 |
|
764 TKeyResponse keyResponse(iFuncmapPane->OfferKeyEventL(aKeyEvent, aType)); |
|
765 if (keyResponse == EKeyWasNotConsumed) |
|
766 { |
|
767 if(iFuncmapPane->IsQwertyKeypadActive()) |
|
768 { |
|
769 iEditorPane->IsQwertyActive(); |
|
770 } |
|
771 else |
|
772 { |
|
773 iEditorPane->IsQwertyNotActive(); |
|
774 } |
|
775 // Edit buffer of line |
|
776 keyResponse = iEditorPane->OfferKeyEventL(aKeyEvent, aType); |
|
777 } |
|
778 return keyResponse; |
|
779 } |
|
780 |
|
781 // --------------------------------------------------------- |
|
782 // CCalcContainer::HandleResourceChange |
|
783 // Notifier for changing language |
|
784 // (other items were commented in a header). |
|
785 // --------------------------------------------------------- |
|
786 // |
|
787 void CCalcContainer::HandleResourceChange(TInt aType) |
|
788 { |
|
789 TRAP_IGNORE( HandleResourceChangeCalSoftL( aType ) ); |
|
790 } |
|
791 |
|
792 // --------------------------------------------------------- |
|
793 // CCalcContainer::HandleResourceChange |
|
794 // Notifier for changing language |
|
795 // (other items were commented in a header). |
|
796 // --------------------------------------------------------- |
|
797 // |
|
798 void CCalcContainer::HandleResourceChangeCalSoftL(TInt aType) |
|
799 { |
|
800 if ((aType == KEikDynamicLayoutVariantSwitch) || (aType == KAknsMessageSkinChange) ) |
|
801 { |
|
802 |
|
803 TRect mainPaneRect ; |
|
804 TRect statusPaneRect; |
|
805 TBool signstate = EFalse; |
|
806 TBool sqrtstate = EFalse; |
|
807 TBool percentstate = EFalse; |
|
808 TBool clearstate = EFalse; |
|
809 |
|
810 if ( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
811 { |
|
812 // when calculator is in Landscape layout, the statuspane displays |
|
813 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
814 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, statusPaneRect ); |
|
815 mainPaneRect.iTl = statusPaneRect.iTl; |
|
816 } |
|
817 else |
|
818 { |
|
819 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
820 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, statusPaneRect ); |
|
821 mainPaneRect.iTl = statusPaneRect.iTl; |
|
822 } |
|
823 |
|
824 |
|
825 //check if funcpane already exists |
|
826 |
|
827 TInt selected = 0; |
|
828 if(iFuncmapPane) |
|
829 { |
|
830 //store the states of the buttons |
|
831 signstate = iFuncmapPane->GetChangeSignButtonState(); |
|
832 sqrtstate = iFuncmapPane->GetSqrtButtonState(); |
|
833 percentstate = iFuncmapPane->GetPercentButtonState(); |
|
834 |
|
835 selected = iFuncmapPane->GetSelectedButtonId(); |
|
836 |
|
837 clearstate = iFuncmapPane->GetClearButtonState(); |
|
838 |
|
839 //delete the function pane |
|
840 delete(iFuncmapPane); |
|
841 iFuncmapPane = NULL; |
|
842 |
|
843 } |
|
844 //Reload the bitmaps |
|
845 (CCalcAppEnv::Static())->SetSkinChangedValue(EFalse); |
|
846 (CCalcAppEnv::Static())->UpdateAknConstArrayForFuncMap(); |
|
847 (CCalcAppEnv::Static())->LoadFuncMapBitmapL(); |
|
848 |
|
849 //Create the new pane |
|
850 iFuncmapPane = CCalcFuncmapSubPane::NewL(this); |
|
851 |
|
852 if ( AknLayoutUtils::PenEnabled() ) |
|
853 { |
|
854 iFuncmapPane->SetHighlightButton( 0, selected ); |
|
855 } |
|
856 |
|
857 iFuncmapPane->ActivateL(); |
|
858 |
|
859 SetRect(mainPaneRect); |
|
860 iFuncmapPane->NotifyLangChange(); |
|
861 DrawNow(); |
|
862 |
|
863 //Restore the states of the buttons |
|
864 iFuncmapPane->SetChangeSignEnable(signstate); |
|
865 iFuncmapPane->SetSqrtEnable(sqrtstate); |
|
866 iFuncmapPane->SetPercentEnable(percentstate); |
|
867 iFuncmapPane->SetClearKeyEnable( clearstate ); |
|
868 |
|
869 //Update scroll bar here |
|
870 ScrollArrowUpdate(); |
|
871 iSheetPane->HandleResourceChange(aType); |
|
872 } |
|
873 else |
|
874 { |
|
875 |
|
876 CCoeControl::HandleResourceChange(aType); |
|
877 } |
|
878 |
|
879 } |
|
880 |
|
881 |
|
882 // --------------------------------------------------------- |
|
883 // CCalcContainer::SizeChanged |
|
884 // Control size is set. |
|
885 // This function is called when the size changes. |
|
886 // (other items were commented in a header). |
|
887 // --------------------------------------------------------- |
|
888 // |
|
889 void CCalcContainer::SizeChanged() |
|
890 { |
|
891 TRect parentRect(Rect()); |
|
892 |
|
893 if (iSkinContext) |
|
894 { |
|
895 iSkinContext->SetRect(parentRect); |
|
896 } |
|
897 |
|
898 |
|
899 if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() ) |
|
900 { |
|
901 |
|
902 // Set layout of function map subpane, output sheet and editor sub pane. |
|
903 if( AknLayoutUtils::PenEnabled() ) |
|
904 { |
|
905 if (Layout_Meta_Data::IsLandscapeOrientation()) |
|
906 { |
|
907 |
|
908 AknLayoutUtils::LayoutControl( |
|
909 iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_with_lsc).LayoutLine()); |
|
910 |
|
911 AknLayoutUtils::LayoutControl( |
|
912 iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_with_lsc).LayoutLine()); |
|
913 |
|
914 AknLayoutUtils::LayoutControl( |
|
915 iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_with_lsc).LayoutLine()); |
|
916 } |
|
917 else |
|
918 { |
|
919 AknLayoutUtils::LayoutControl( |
|
920 iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_with_prt).LayoutLine()); |
|
921 |
|
922 AknLayoutUtils::LayoutControl( |
|
923 iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_with_prt).LayoutLine()); |
|
924 |
|
925 AknLayoutUtils::LayoutControl( |
|
926 iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_with_prt).LayoutLine()); |
|
927 } |
|
928 } |
|
929 else |
|
930 { |
|
931 AknLayoutUtils::LayoutControl( |
|
932 iFuncmapPane, parentRect, AknLayoutScalable_Apps::grid_calc_pane(enTouch_disabled).LayoutLine()); |
|
933 |
|
934 AknLayoutUtils::LayoutControl( |
|
935 iSheetPane, parentRect,AknLayoutScalable_Apps::calc_paper_pane(enTouch_disabled).LayoutLine()); |
|
936 |
|
937 AknLayoutUtils::LayoutControl( |
|
938 iEditorPane, parentRect,AknLayoutScalable_Apps::calc_display_pane(enTouch_disabled).LayoutLine()); |
|
939 |
|
940 } |
|
941 |
|
942 } |
|
943 else |
|
944 { |
|
945 // Set layout of function map subpane. |
|
946 AknLayoutUtils::LayoutControl( |
|
947 iFuncmapPane, parentRect, AppLayout::grid_calc_pane()); |
|
948 |
|
949 |
|
950 // Set layout of output sheet. |
|
951 AknLayoutUtils::LayoutControl( |
|
952 iSheetPane, parentRect,AppLayout::gqn_graf_calc_paper()); |
|
953 |
|
954 // Set layout of editor subpane. |
|
955 AknLayoutUtils::LayoutControl( |
|
956 iEditorPane, parentRect,AppLayout::Calculator_elements_Line_1()); |
|
957 } |
|
958 } |
|
959 |
|
960 // --------------------------------------------------------- |
|
961 // CCalcContainer::Draw |
|
962 // Clear whole screen. After this, draw editor, output sheet, |
|
963 // and function map. |
|
964 // (other items were commented in a header). |
|
965 // --------------------------------------------------------- |
|
966 // |
|
967 void CCalcContainer::Draw(const TRect& aRect) const |
|
968 { |
|
969 CWindowGc& gc = SystemGc(); |
|
970 gc.Clear(aRect); |
|
971 |
|
972 // Drawing skin |
|
973 if (iSkinContext) |
|
974 { |
|
975 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
976 |
|
977 AknsDrawUtils::Background( |
|
978 skin, iSkinContext, this, gc, aRect); |
|
979 } |
|
980 |
|
981 } |
|
982 |
|
983 // --------------------------------------------------------- |
|
984 // CCalcContainer::MopSupplyObject() |
|
985 // Pass skin information if need. |
|
986 // (other items were commented in a header). |
|
987 // --------------------------------------------------------- |
|
988 // |
|
989 TTypeUid::Ptr CCalcContainer::MopSupplyObject(TTypeUid aId) |
|
990 { |
|
991 if (aId.iUid == MAknsControlContext::ETypeId && iSkinContext) |
|
992 { |
|
993 return MAknsControlContext::SupplyMopObject(aId, iSkinContext); |
|
994 } |
|
995 |
|
996 return CCoeControl::MopSupplyObject(aId); |
|
997 } |
|
998 |
|
999 // --------------------------------------------------------- |
|
1000 // CCalcContainer::ShowSqrtButton() |
|
1001 // Enable (or disable) the square root button. |
|
1002 // (other items were commented in a header). |
|
1003 // --------------------------------------------------------- |
|
1004 // |
|
1005 void CCalcContainer::ShowSqrtButton(TBool aEnable) |
|
1006 { |
|
1007 TCalcEditLine editLine( iEditorPane->EditLine() ); |
|
1008 TBool sqrtEnable(ETrue); |
|
1009 TRAP_IGNORE( |
|
1010 if ( editLine.NumberL() == 0 ) |
|
1011 { |
|
1012 sqrtEnable = EFalse; |
|
1013 } |
|
1014 ) |
|
1015 |
|
1016 iFuncmapPane->SetSqrtEnable( sqrtEnable ); |
|
1017 } |
|
1018 |
|
1019 // --------------------------------------------------------- |
|
1020 // CCalcContainer::ShowPercentButton() |
|
1021 // Enable (or disable) the percent button. |
|
1022 // (other items were commented in a header). |
|
1023 // --------------------------------------------------------- |
|
1024 // |
|
1025 void CCalcContainer::ShowPercentButton(TBool aEnable) |
|
1026 { |
|
1027 iFuncmapPane->SetPercentEnable(aEnable); |
|
1028 } |
|
1029 |
|
1030 // --------------------------------------------------------- |
|
1031 // CCalcContainer::GetState() |
|
1032 // Returns the state of the calculator. |
|
1033 // (other items were commented in a header). |
|
1034 // --------------------------------------------------------- |
|
1035 // |
|
1036 CCalcView::TStateNo CCalcContainer::GetState() |
|
1037 { |
|
1038 return (iView->State()); |
|
1039 } |
|
1040 |
|
1041 // --------------------------------------------------------- |
|
1042 // CCalcContainer::HandlePointerEventL |
|
1043 // Handled when pen input occured. |
|
1044 // (other items were commented in a header). |
|
1045 // --------------------------------------------------------- |
|
1046 // |
|
1047 void CCalcContainer::HandlePointerEventL |
|
1048 ( const TPointerEvent& aPointerEvent ) |
|
1049 { |
|
1050 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
1051 } |
|
1052 |
|
1053 |
|
1054 // --------------------------------------------------------- |
|
1055 // --------------------------------------------------------- |
|
1056 // CCalcContainer::HandleMiddleSoftKey() |
|
1057 // Handled when MSK is selected. |
|
1058 // --------------------------------------------------------- |
|
1059 // |
|
1060 void CCalcContainer::HandleMiddleSoftKey() |
|
1061 |
|
1062 { |
|
1063 TRAP_IGNORE( iFuncmapPane->HandleMiddleSoftKeyOREKeyOKL() ); |
|
1064 } |
|
1065 |
|
1066 // --------------------------------------------------------- |
|
1067 // --------------------------------------------------------- |
|
1068 // SetOperatorFromTouchL |
|
1069 // Handle digit inputs |
|
1070 // --------------------------------------------------------- |
|
1071 // |
|
1072 void CCalcContainer::SetOperatorFromTouchL(TInt akey ) |
|
1073 { |
|
1074 //Simulate events as events are occurring from the KB Events |
|
1075 TKeyEvent eventkey; |
|
1076 TEventCode keycode; |
|
1077 keycode = EEventKeyDown; |
|
1078 eventkey.iCode = 0; |
|
1079 eventkey.iScanCode = ASCII_ZERO + akey; |
|
1080 |
|
1081 //First send Keydown event |
|
1082 OfferKeyEventL(eventkey,keycode); |
|
1083 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
1084 eventkey.iCode = ASCII_ZERO + akey; |
|
1085 #else |
|
1086 eventkey.iCode = KEY_CODE_VAL; |
|
1087 #endif |
|
1088 keycode = EEventKey; |
|
1089 |
|
1090 //Next send EventKey |
|
1091 OfferKeyEventL(eventkey,keycode); |
|
1092 |
|
1093 |
|
1094 //Finally send Keyup |
|
1095 eventkey.iScanCode = ASCII_ZERO + akey; |
|
1096 keycode = EEventKeyUp; |
|
1097 OfferKeyEventL(eventkey,keycode); |
|
1098 } |
|
1099 |
|
1100 // --------------------------------------------------------- |
|
1101 // --------------------------------------------------------- |
|
1102 // ClearInputKeyL |
|
1103 // Handle 'c' input key from Touch |
|
1104 // --------------------------------------------------------- |
|
1105 // |
|
1106 void CCalcContainer::ClearInputKeyL(TInt aRepeat) |
|
1107 { |
|
1108 //Simulate events as events are occurring from the KB Events |
|
1109 TKeyEvent eventkey; |
|
1110 TEventCode keycode; |
|
1111 keycode = EEventKeyDown; |
|
1112 eventkey.iCode = 0; |
|
1113 eventkey.iScanCode = 1; //for clear input key |
|
1114 eventkey.iRepeats = aRepeat; |
|
1115 |
|
1116 //First send Keydown event |
|
1117 OfferKeyEventL(eventkey,keycode); |
|
1118 eventkey.iCode = 8; //clear input key icode |
|
1119 keycode = EEventKey; |
|
1120 |
|
1121 //Next send EventKey |
|
1122 OfferKeyEventL(eventkey,keycode); |
|
1123 keycode = EEventKeyUp; |
|
1124 |
|
1125 //Finally send Keyup |
|
1126 OfferKeyEventL(eventkey,keycode); |
|
1127 |
|
1128 } |
|
1129 |
|
1130 |
|
1131 // --------------------------------------------------------- |
|
1132 // --------------------------------------------------------- |
|
1133 // SetSeparatorFromTouch |
|
1134 // Handle '.' input key from Touch |
|
1135 // --------------------------------------------------------- |
|
1136 // |
|
1137 void CCalcContainer::SetSeparatorFromTouchL() |
|
1138 { |
|
1139 // set the right iCode and iScanCode for |
|
1140 // decimal point |
|
1141 if ( iFuncmapPane->IsQwertyKeypadActive() ) |
|
1142 { |
|
1143 // Simulate events as events are occurring from the KB Events |
|
1144 TKeyEvent eventkey; |
|
1145 TEventCode keycode = EEventKeyDown; |
|
1146 eventkey.iCode = 0; |
|
1147 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
1148 if ( iFuncmapPane->GetKeyboardType() == EPtiKeyboardHalfQwerty ) |
|
1149 { |
|
1150 eventkey.iScanCode = 126; //scan code for separator |
|
1151 } |
|
1152 else |
|
1153 #endif |
|
1154 { |
|
1155 eventkey.iScanCode = 122; //scan code for separator |
|
1156 } |
|
1157 |
|
1158 // First send Keydown event |
|
1159 OfferKeyEventL( eventkey, keycode ); |
|
1160 eventkey.iCode = 46; // icode for separator |
|
1161 keycode = EEventKey; |
|
1162 |
|
1163 // Next send EventKey |
|
1164 OfferKeyEventL( eventkey, keycode ); |
|
1165 } |
|
1166 else |
|
1167 { |
|
1168 // Simulate events as events are occurring from the KB Events |
|
1169 TKeyEvent eventkey; |
|
1170 TEventCode keycode = EEventKeyDown; |
|
1171 eventkey.iCode = 0; |
|
1172 eventkey.iScanCode = 127; // scan code for separator |
|
1173 |
|
1174 // First send Keydown event |
|
1175 OfferKeyEventL( eventkey, keycode ); |
|
1176 eventkey.iCode = 35; // icode for separator |
|
1177 keycode = EEventKey; |
|
1178 |
|
1179 // Next send EventKey |
|
1180 OfferKeyEventL( eventkey, keycode ); |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 // End of File CALCCONT_CPP |