|
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: CCalcView is a view class of Calculator application. |
|
15 * Base class of CCalcView is CAknView. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <avkon.hrh> |
|
23 #include <eikon.hrh> |
|
24 #include <eikmenup.h> |
|
25 #include <aknnotewrappers.h> |
|
26 #include <AiwServiceHandler.h> |
|
27 |
|
28 #include <aknbutton.h> |
|
29 |
|
30 #include <hlplch.h> // For HlpLauncher |
|
31 #include <featmgr.h> // Feature Manager |
|
32 |
|
33 #include <Calcsoft.rsg> |
|
34 |
|
35 #include "CalcView.h" |
|
36 #include "CalcCont.h" |
|
37 #include "CalcEdit.h" |
|
38 #include "CalcAppUi.h" |
|
39 #include "CalcDoc.h" |
|
40 #include "CalcHistory.h" |
|
41 #include "CalcOutSheet.h" |
|
42 #include "CalcFunc.h" |
|
43 #include "CalcEnv.h" |
|
44 #include "calc.hrh" |
|
45 #include "CalcEditline.h" |
|
46 |
|
47 //#include "CalcCmdBtn.h" |
|
48 |
|
49 #include <layoutmetadata.cdl.h> |
|
50 #include <AiwMenu.h> |
|
51 #include <AiwCommon.h> |
|
52 |
|
53 |
|
54 // LOCAL CONSTANTS AND MACROS |
|
55 |
|
56 |
|
57 // ================= MEMBER FUNCTIONS ======================= |
|
58 |
|
59 |
|
60 // Two-phased constructor. |
|
61 CCalcView* CCalcView::NewLC() |
|
62 { |
|
63 CCalcView* self = new (ELeave) CCalcView(); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // default constructor can leave. |
|
70 void CCalcView::ConstructL() |
|
71 { |
|
72 |
|
73 BaseConstructL(R_CALC_VIEW_INFO); |
|
74 |
|
75 iCalcDocument = STATIC_CAST(CCalcDocument*, AppUi()->Document()); |
|
76 |
|
77 iCalcDocument->SetCalcView( this ); |
|
78 CreateContainerL(); |
|
79 iCalcDocument->LoadStateL(); |
|
80 |
|
81 /******** Initialize the ServiceHandler in the ConstructL *****/ |
|
82 |
|
83 iServiceHandler = CAiwServiceHandler::NewL(); |
|
84 |
|
85 /***** Attach the Menu Items of the Calculator and also the Interest *****/ |
|
86 |
|
87 iServiceHandler->AttachMenuL(R_CALC_POPUPMENU, R_AIWHELPAPP_INTEREST); |
|
88 |
|
89 this->iLastResultSetected = EFalse; |
|
90 } |
|
91 |
|
92 // Destructor |
|
93 CCalcView::~CCalcView() |
|
94 { |
|
95 delete iContainer; |
|
96 if(iServiceHandler) |
|
97 { |
|
98 delete iServiceHandler; |
|
99 iServiceHandler = NULL; |
|
100 } |
|
101 |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CCalcView::State |
|
106 // Return current state |
|
107 // (other items were commented in a header). |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 CCalcView::TStateNo CCalcView::State() const |
|
111 { |
|
112 return iState; |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------- |
|
116 // CCalcView::LatestInput |
|
117 // Return type of latest input |
|
118 // (other items were commented in a header). |
|
119 // ---------------------------------------------------- |
|
120 // |
|
121 CCalcView::TKindOfInput CCalcView::LatestInput() const |
|
122 { |
|
123 return iLatestInput; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------- |
|
127 // CCalcView::UpdateState |
|
128 // Update state by using kind of input |
|
129 // (other items were commented in a header). |
|
130 // ---------------------------------------------------- |
|
131 // |
|
132 void CCalcView::UpdateState |
|
133 (const TKindOfInput& aKind) |
|
134 { |
|
135 iLatestInput = aKind; |
|
136 |
|
137 switch (aKind) |
|
138 { |
|
139 case EOperand: |
|
140 case EMemoryRecall: |
|
141 { |
|
142 switch (iState) |
|
143 { |
|
144 case EInitialMode: |
|
145 case ESelectResult: |
|
146 iState = EOperandOnly; |
|
147 break; |
|
148 case EOperandAndOperator: |
|
149 iState = EOperandAndOperatorAndOperand; |
|
150 break; |
|
151 default: |
|
152 break; |
|
153 } |
|
154 break; |
|
155 } |
|
156 case EOperatorResult: |
|
157 { |
|
158 iState = EOperatorOnlyResult; |
|
159 break; |
|
160 } |
|
161 case EOperator: |
|
162 { |
|
163 iState = EOperandAndOperator; |
|
164 break; |
|
165 } |
|
166 case EEqual: |
|
167 { |
|
168 iState = ESelectResult; |
|
169 break; |
|
170 } |
|
171 case EMemorySave: |
|
172 { |
|
173 switch (iState) |
|
174 { |
|
175 case EOperandAndOperatorAndOperand: |
|
176 iState = ESelectResult; |
|
177 break; |
|
178 case ESelectResult: |
|
179 iState = EOperandOnly; |
|
180 break; |
|
181 default: |
|
182 break; |
|
183 } |
|
184 break; |
|
185 } |
|
186 case EAllClear: |
|
187 { |
|
188 iState = EOperandOnly; |
|
189 break; |
|
190 } |
|
191 default: |
|
192 { |
|
193 break; |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // ---------------------------------------------------- |
|
200 // CCalcView::ErrorMsgL |
|
201 // Display error message |
|
202 // (other items were commented in a header). |
|
203 // ---------------------------------------------------- |
|
204 // |
|
205 void CCalcView::ErrorMsgL |
|
206 (TInt aErrorCode) |
|
207 { |
|
208 TInt resourceId(0); |
|
209 |
|
210 switch (aErrorCode) |
|
211 { |
|
212 case KErrOverflow: |
|
213 { |
|
214 resourceId = R_CALC_ERROR_OUTOFRANGE; |
|
215 break; |
|
216 } |
|
217 case KErrDivideByZero: |
|
218 { |
|
219 resourceId = R_CALC_ERROR_DIVISIONBYZERO; |
|
220 |
|
221 // UpdateState( EOperator ); |
|
222 break; |
|
223 } |
|
224 case KErrNotSupported: |
|
225 { |
|
226 resourceId = R_CALC_ERROR_NEGATIVEVALUESQRT; |
|
227 break; |
|
228 } |
|
229 default: |
|
230 { |
|
231 return; |
|
232 } |
|
233 } |
|
234 |
|
235 //Localisation of scalable UI. |
|
236 HBufC* message = iCoeEnv->AllocReadResourceLC(resourceId) ; |
|
237 CAknErrorNote* note = new (ELeave) CAknErrorNote(); |
|
238 note->ExecuteLD(*message); |
|
239 CleanupStack::PopAndDestroy(message); |
|
240 |
|
241 } |
|
242 |
|
243 |
|
244 // ---------------------------------------------------- |
|
245 // CCalcView::DynInitMainMenuPane |
|
246 // Delete meaningless items from main menu. |
|
247 // (other items were commented in a header). |
|
248 // ---------------------------------------------------- |
|
249 // |
|
250 void CCalcView::DynInitMainMenuPane |
|
251 (CEikMenuPane* aMenuPane) |
|
252 { |
|
253 |
|
254 |
|
255 |
|
256 switch (iState) |
|
257 { |
|
258 case ESelectResult: |
|
259 { |
|
260 aMenuPane->DeleteMenuItem(ECalcCmdLastResult); |
|
261 break; |
|
262 } |
|
263 case EInitialMode: |
|
264 { |
|
265 aMenuPane->DeleteMenuItem(ECalcCmdClearCalcAndHistory); |
|
266 break; |
|
267 } |
|
268 case EOperandOnly: |
|
269 { |
|
270 if (iCalcDocument->History()->Count() == 0) |
|
271 { |
|
272 aMenuPane->DeleteMenuItem(ECalcCmdClearCalcAndHistory); |
|
273 } |
|
274 if(iLastResultSetected) |
|
275 { |
|
276 aMenuPane->DeleteMenuItem(ECalcCmdLastResult); |
|
277 } |
|
278 break; |
|
279 } |
|
280 case EOperandAndOperator: |
|
281 case EOperandAndOperatorAndOperand: |
|
282 if(iLastResultSetected) |
|
283 { |
|
284 aMenuPane->DeleteMenuItem(ECalcCmdLastResult); |
|
285 } |
|
286 break; |
|
287 default: |
|
288 { |
|
289 break; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 |
|
295 // ---------------------------------------------------- |
|
296 // CCalcView::DynInitMemoryMenuPane |
|
297 // Delete meaningless items from menu of memory |
|
298 // (other items were commented in a header). |
|
299 // ---------------------------------------------------- |
|
300 // |
|
301 void CCalcView::DynInitMemoryMenuPane |
|
302 (CEikMenuPane* aMenuPane) |
|
303 { |
|
304 if (!iCalcDocument->HasMemory()) |
|
305 { |
|
306 aMenuPane->DeleteMenuItem(ECalcCmdMemoryClear); |
|
307 } |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------- |
|
311 // CCalcView::NotifyChangeDecimal |
|
312 // Call when decimal separator is changed. |
|
313 // (other items were commented in a header). |
|
314 // --------------------------------------------------------- |
|
315 // |
|
316 void CCalcView::NotifyChangeDecimal(TChar aOld, TChar aNew) |
|
317 { |
|
318 iContainer->NotifyChangeDecimal(aOld, aNew); |
|
319 } |
|
320 |
|
321 |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CCalcView::HandleCommandL |
|
325 // Handling command. |
|
326 // (other items were commented in a header). |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 void CCalcView::HandleCommandL |
|
330 ( TInt aCommand ) |
|
331 { |
|
332 // Handle the command generated by: |
|
333 // 1. menu item selection |
|
334 // 2. short-cut key press |
|
335 |
|
336 switch ( aCommand ) |
|
337 { |
|
338 case ECalcCmdResult: |
|
339 { |
|
340 HandleResultL(); |
|
341 break; |
|
342 } |
|
343 case ECalcCmdAdd: |
|
344 { |
|
345 HandleOperatorL(TCalcEditLine::ECalcAdd); |
|
346 break; |
|
347 } |
|
348 case ECalcCmdSubtract: |
|
349 { |
|
350 HandleOperatorL(TCalcEditLine::ECalcSubtract); |
|
351 break; |
|
352 } |
|
353 case ECalcCmdMultiply: |
|
354 { |
|
355 HandleOperatorL(TCalcEditLine::ECalcMultiply); |
|
356 break; |
|
357 } |
|
358 case ECalcCmdDivide: |
|
359 { |
|
360 HandleOperatorL(TCalcEditLine::ECalcDivide); |
|
361 break; |
|
362 } |
|
363 case ECalcCmdChangeSign: |
|
364 { |
|
365 this->iLastResultSetected = EFalse; |
|
366 HandleChangeSignL(); |
|
367 break; |
|
368 } |
|
369 case ECalcCmdLastResult: |
|
370 { |
|
371 HandleLastResultL(); |
|
372 break; |
|
373 } |
|
374 case ECalcCmdPercent: |
|
375 { |
|
376 HandleOperatorL(TCalcEditLine::ECalcPercent); |
|
377 // The result is always is displayed |
|
378 // after the percent button is pressed. |
|
379 // But if there was a error in the calculation |
|
380 // this if will enable us to not call the |
|
381 // HandleResultL and thus making sure that |
|
382 // the state of the buttons is identical to the |
|
383 // situation before the calculation. |
|
384 if (iState == EOperatorOnlyResult) |
|
385 HandleResultL(); |
|
386 break; |
|
387 } |
|
388 case ECalcCmdSqrt: |
|
389 { |
|
390 HandleOperatorL(TCalcEditLine::ECalcSqrt); |
|
391 // HandleResultL only if sqrt was pressed after single operand. |
|
392 if (iState == EOperatorOnlyResult) |
|
393 HandleResultL(); |
|
394 break; |
|
395 } |
|
396 case ECalcCmdMemorySave: |
|
397 { |
|
398 HandleMemorySaveL(); |
|
399 break; |
|
400 } |
|
401 case ECalcCmdMemoryRecall: |
|
402 { |
|
403 this->iLastResultSetected = EFalse; |
|
404 HandleMemoryRecallL(); |
|
405 break; |
|
406 } |
|
407 case ECalcCmdMemoryClear: |
|
408 { |
|
409 HandleMemoryClearL(); |
|
410 break; |
|
411 } |
|
412 case ECalcCmdScrollUp: |
|
413 { |
|
414 HandleScrollUp(); |
|
415 break; |
|
416 } |
|
417 case ECalcCmdScrollDown: |
|
418 { |
|
419 HandleScrollDown(); |
|
420 break; |
|
421 } |
|
422 case ECalcCmdClearCalcAndHistory: |
|
423 { |
|
424 DoClearCalcAndHistoryL(); |
|
425 break; |
|
426 } |
|
427 case EAknSoftkeyExit: |
|
428 case EEikCmdExit: |
|
429 { |
|
430 STATIC_CAST(CCalcAppUi*, AppUi())->ExitCalculator(); |
|
431 break; |
|
432 } |
|
433 case ECalcCmdHelp: |
|
434 { |
|
435 if (FeatureManager::FeatureSupported( KFeatureIdHelp )) |
|
436 { |
|
437 HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), AppUi()->AppHelpContextL()); |
|
438 } |
|
439 break; |
|
440 } |
|
441 case EAknSoftkeySelect: |
|
442 { |
|
443 iContainer->HandleMiddleSoftKey(); |
|
444 break; |
|
445 } |
|
446 |
|
447 //Below cases are possible only for Touch UI Layouts |
|
448 case ECalcCmdOne: |
|
449 { |
|
450 iContainer->SetOperatorFromTouchL(1); |
|
451 } |
|
452 break; |
|
453 case ECalcCmdTwo: |
|
454 { |
|
455 iContainer->SetOperatorFromTouchL(2); |
|
456 } |
|
457 break; |
|
458 case ECalcCmdThree: |
|
459 { |
|
460 iContainer->SetOperatorFromTouchL(3); |
|
461 } |
|
462 break; |
|
463 case ECalcCmdFour: |
|
464 { |
|
465 iContainer->SetOperatorFromTouchL(4); |
|
466 } |
|
467 break; |
|
468 case ECalcCmdFive: |
|
469 { |
|
470 iContainer->SetOperatorFromTouchL(5); |
|
471 } |
|
472 break; |
|
473 case ECalcCmdSix: |
|
474 { |
|
475 iContainer->SetOperatorFromTouchL(6); |
|
476 } |
|
477 break; |
|
478 case ECalcCmdSeven: |
|
479 { |
|
480 iContainer->SetOperatorFromTouchL(7); |
|
481 } |
|
482 break; |
|
483 |
|
484 case ECalcCmdEight: |
|
485 { |
|
486 iContainer->SetOperatorFromTouchL(8); |
|
487 } |
|
488 break; |
|
489 |
|
490 case ECalcCmdNine: |
|
491 { |
|
492 iContainer->SetOperatorFromTouchL(9); |
|
493 } |
|
494 break; |
|
495 |
|
496 case ECalcCmdZero: |
|
497 { |
|
498 iContainer->SetOperatorFromTouchL(0); |
|
499 } |
|
500 break; |
|
501 |
|
502 case ECalcCmdSeparator: |
|
503 { |
|
504 iContainer->SetSeparatorFromTouchL(); |
|
505 } |
|
506 break; |
|
507 case ECalcCmdCancel: |
|
508 { |
|
509 TInt repeat( iContainer->FuncmapSubPane()->IsKeyLongPressed() ); |
|
510 iContainer->ClearInputKeyL( repeat ); |
|
511 } |
|
512 break; |
|
513 |
|
514 /****** If none of the cases handle the Aiw Help then it will come to the default case ****/ |
|
515 default: |
|
516 { |
|
517 CArrayFix<TCoeHelpContext>* buf = AppUi()->AppHelpContextL(); |
|
518 TCoeHelpContext& helpContext = buf->At(0); |
|
519 TAiwVariant uidVariant; |
|
520 TAiwVariant contextVariant; |
|
521 uidVariant.Set(helpContext.iMajor); |
|
522 TAiwGenericParam uidParam(EGenericParamHelpItem, uidVariant); contextVariant.Set(helpContext.iContext); |
|
523 contextVariant.Set(helpContext.iContext); |
|
524 TAiwGenericParam contextParam(EGenericParamHelpItem, contextVariant); |
|
525 CAiwGenericParamList* list = CAiwGenericParamList::NewLC(); |
|
526 list->AppendL(uidParam); |
|
527 list->AppendL(contextParam); |
|
528 iServiceHandler->ExecuteMenuCmdL(aCommand,*list,iServiceHandler->OutParamListL()); |
|
529 CleanupStack::PopAndDestroy(list); |
|
530 delete buf; |
|
531 buf= NULL; |
|
532 break; |
|
533 } |
|
534 } |
|
535 } |
|
536 |
|
537 |
|
538 // C++ default constructor can NOT contain any code, that |
|
539 // might leave. |
|
540 // |
|
541 CCalcView::CCalcView(): |
|
542 iState(EInitialMode), |
|
543 iLatestInput(EOperand) |
|
544 { |
|
545 } |
|
546 |
|
547 |
|
548 // --------------------------------------------------------- |
|
549 // CCalcView::CreateContainerL |
|
550 // Create CCalcContainer class |
|
551 // (other items were commented in a header). |
|
552 // --------------------------------------------------------- |
|
553 // |
|
554 void CCalcView::CreateContainerL() |
|
555 { |
|
556 iContainer = CCalcContainer::NewL(this); |
|
557 |
|
558 iContainer->SetMopParent(this); |
|
559 |
|
560 TRect mainPaneRect ; |
|
561 TRect statusPaneRect; |
|
562 |
|
563 if (Layout_Meta_Data::IsLandscapeOrientation()) |
|
564 |
|
565 { |
|
566 |
|
567 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect); |
|
568 |
|
569 } |
|
570 |
|
571 else |
|
572 |
|
573 { |
|
574 |
|
575 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect); |
|
576 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect); |
|
577 |
|
578 mainPaneRect.iTl= statusPaneRect.iTl; |
|
579 |
|
580 } |
|
581 |
|
582 |
|
583 iContainer->SetRect(mainPaneRect); |
|
584 iEditorSubPane = iContainer->EditorPane(); |
|
585 iOutputSheet = iContainer->OutputSheet(); |
|
586 } |
|
587 |
|
588 |
|
589 // --------------------------------------------------------- |
|
590 // CCalcView::HandleResultL |
|
591 // Handle result command |
|
592 // (other items were commented in a header). |
|
593 // --------------------------------------------------------- |
|
594 // |
|
595 void CCalcView::HandleResultL() |
|
596 { |
|
597 if (!HandleEqualSubRoutineL()) |
|
598 { |
|
599 iEditorSubPane->DrawNow(); |
|
600 UpdateState(EEqual); |
|
601 iContainer->SetChangeSignEnableL(); |
|
602 iContainer->SetSqrtEnableL(); |
|
603 iContainer->ShowPercentButton(EFalse); |
|
604 iContainer->SetClearKeyEnable(); |
|
605 } |
|
606 } |
|
607 |
|
608 |
|
609 // --------------------------------------------------------- |
|
610 // CCalcView::HandleChangeSignL |
|
611 // Handle ChangeSign command |
|
612 // (other items were commented in a header). |
|
613 // --------------------------------------------------------- |
|
614 // |
|
615 void CCalcView::HandleChangeSignL() |
|
616 { |
|
617 iEditorSubPane->DoChangeSignL(iState); |
|
618 |
|
619 if (iState == CCalcView::EOperandAndOperator) |
|
620 { |
|
621 UpdateState(EMemoryRecall); |
|
622 } |
|
623 } |
|
624 |
|
625 // --------------------------------------------------------- |
|
626 // CCalcView::HandleLastResultL |
|
627 // Handle LastResult command |
|
628 // (other items were commented in a header). |
|
629 // --------------------------------------------------------- |
|
630 // |
|
631 void CCalcView::HandleLastResultL() |
|
632 { |
|
633 iLastResultSetected = ETrue; |
|
634 // Recall "LastResult", which is the answer based on latest "=" input. |
|
635 iEditorSubPane->DoMemoryRecallOrLastResult( |
|
636 iCalcDocument->LastResult(), iState); |
|
637 |
|
638 UpdateState(EMemoryRecall); |
|
639 if ( iState == EOperandOnly && |
|
640 iEditorSubPane->EditLine().CheckZeroL() ) |
|
641 { |
|
642 UpdateState(EAllClear); |
|
643 } |
|
644 iContainer->SetChangeSignEnableL(); |
|
645 iContainer->SetSqrtEnableL(); |
|
646 iContainer->SetClearKeyEnable(); |
|
647 |
|
648 //highlighting the sign "%". |
|
649 if ( iState == EOperandAndOperatorAndOperand ) |
|
650 { |
|
651 iContainer->SetPercentEnableL(); |
|
652 } |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------- |
|
656 // CCalcView::HandleMemorySaveL |
|
657 // Handle MemorySave command |
|
658 // (other items were commented in a header). |
|
659 // --------------------------------------------------------- |
|
660 // |
|
661 void CCalcView::HandleMemorySaveL() |
|
662 { |
|
663 CCalcView::TKindOfInput kindOfInput(CCalcView::EMemorySave); |
|
664 |
|
665 if (iState == EOperandAndOperatorAndOperand) |
|
666 { |
|
667 if (HandleEqualSubRoutineL()) // Calculate result |
|
668 { |
|
669 return; |
|
670 } |
|
671 } |
|
672 else |
|
673 { |
|
674 if (iState == ESelectResult) |
|
675 { |
|
676 iCalcDocument->AddEmptyLine(); |
|
677 iOutputSheet->ScrollToBottomL(); |
|
678 iContainer->ScrollArrowUpdate(); |
|
679 iEditorSubPane->SetOperator(TCalcEditLine::ECalcOperatorNone); |
|
680 |
|
681 if (iEditorSubPane->EditLine().CheckZeroL()) |
|
682 { |
|
683 kindOfInput = CCalcView::EAllClear; |
|
684 } |
|
685 } |
|
686 } |
|
687 iCalcDocument->MemorySaveL(iEditorSubPane->EditorNumber()); |
|
688 iEditorSubPane->DrawNow(); |
|
689 UpdateState(kindOfInput); |
|
690 iContainer->SetChangeSignEnableL(); |
|
691 iContainer->SetSqrtEnableL(); |
|
692 } |
|
693 |
|
694 // --------------------------------------------------------- |
|
695 // CCalcView::HandleMemoryRecallL |
|
696 // Handle MemoryRecall command |
|
697 // (other items were commented in a header). |
|
698 // --------------------------------------------------------- |
|
699 // |
|
700 void CCalcView::HandleMemoryRecallL() |
|
701 { |
|
702 iEditorSubPane->DoMemoryRecallOrLastResult( |
|
703 iCalcDocument->Memory(), iState ); |
|
704 |
|
705 if ( iState == ESelectResult ) |
|
706 { |
|
707 iCalcDocument->AddEmptyLine(); |
|
708 iOutputSheet->ScrollToBottomL(); |
|
709 iContainer->ScrollArrowUpdate(); |
|
710 } |
|
711 |
|
712 UpdateState( EMemoryRecall ); |
|
713 if ( iState == EOperandOnly && |
|
714 iEditorSubPane->EditLine().CheckZeroL() ) |
|
715 { |
|
716 UpdateState( EAllClear ); |
|
717 } |
|
718 |
|
719 iContainer->SetChangeSignEnableL(); |
|
720 iContainer->SetSqrtEnableL(); |
|
721 |
|
722 iContainer->SetClearKeyEnable(); |
|
723 |
|
724 // highlighting the sign "%". |
|
725 if ( iState == EOperandAndOperatorAndOperand ) |
|
726 { |
|
727 iContainer->SetPercentEnableL(); |
|
728 } |
|
729 } |
|
730 |
|
731 // --------------------------------------------------------- |
|
732 // CCalcView::HandleMemoryClear |
|
733 // Handle MemoryClear command |
|
734 // (other items were commented in a header). |
|
735 // --------------------------------------------------------- |
|
736 // |
|
737 |
|
738 void CCalcView::HandleMemoryClearL() |
|
739 { |
|
740 iCalcDocument->MemoryClearL(); |
|
741 iEditorSubPane->DrawNow(); |
|
742 } |
|
743 |
|
744 // --------------------------------------------------------- |
|
745 // CCalcView::HandleScrollUp |
|
746 // Handle Scroll up button command |
|
747 // (other items were commented in a header). |
|
748 // --------------------------------------------------------- |
|
749 // |
|
750 void CCalcView::HandleScrollUp() |
|
751 { |
|
752 iOutputSheet->ScrollUp(); |
|
753 iContainer->ScrollArrowUpdate(); |
|
754 } |
|
755 |
|
756 // --------------------------------------------------------- |
|
757 // CCalcView::HandleScrollDown |
|
758 // Handle Scroll down button command |
|
759 // (other items were commented in a header). |
|
760 // --------------------------------------------------------- |
|
761 // |
|
762 void CCalcView::HandleScrollDown() |
|
763 { |
|
764 iOutputSheet->ScrollDown(); |
|
765 iContainer->ScrollArrowUpdate(); |
|
766 } |
|
767 |
|
768 // --------------------------------------------------------- |
|
769 // CCalcView::DoClearCalcAndHistoryL |
|
770 // Clear calculation history and clear calculation. |
|
771 // (other items were commented in a header). |
|
772 // --------------------------------------------------------- |
|
773 // |
|
774 void CCalcView::DoClearCalcAndHistoryL() |
|
775 { |
|
776 iCalcDocument->History()->ClearHistory(); |
|
777 iOutputSheet->NotifyClearHistoryL(); |
|
778 iContainer->ScrollArrowUpdate(); |
|
779 // Clear calculation |
|
780 TKeyEvent keyEvent; |
|
781 keyEvent.iCode = EKeyBackspace; |
|
782 keyEvent.iRepeats = 1; |
|
783 iEditorSubPane->OfferKeyEventL(keyEvent, EEventKey); |
|
784 iContainer->ShowPercentButton(EFalse); |
|
785 } |
|
786 |
|
787 |
|
788 // --------------------------------------------------------- |
|
789 // CCalcView::HandleOperatorL |
|
790 // Operator Handler common routin. |
|
791 // (other items were commented in a header). |
|
792 // --------------------------------------------------------- |
|
793 // |
|
794 void CCalcView::HandleOperatorL |
|
795 (TCalcEditLine::TCalcOperatorType aOperator) |
|
796 { |
|
797 TCalcEditLine editLine(iEditorSubPane->EditLine()); |
|
798 TReal64 editorNumber(iEditorSubPane->EditorNumber()); |
|
799 TReal64 result(editorNumber); |
|
800 |
|
801 this->iLastResultSetected = EFalse; |
|
802 // User has pressed % |
|
803 if (aOperator == TCalcEditLine::ECalcPercent) |
|
804 { |
|
805 if (iState == EOperandAndOperatorAndOperand) |
|
806 { |
|
807 editLine.TrimZeroL(); |
|
808 // Save the previous operator |
|
809 TCalcEditLine::TCalcOperatorType previousOperator = editLine.Operator(); |
|
810 // Set the operator to percent |
|
811 editLine.SetOperator(TCalcEditLine::ECalcPercent); |
|
812 |
|
813 |
|
814 // Calculate |
|
815 TRAPD(errorCode3, |
|
816 result = iCalcDocument->CalculateAndModifyHistoryL( |
|
817 editorNumber, editLine, previousOperator)); |
|
818 |
|
819 if (errorCode3) |
|
820 { |
|
821 ErrorMsgL(errorCode3); |
|
822 return; |
|
823 } |
|
824 |
|
825 iOutputSheet->ScrollToBottomL(); |
|
826 // Show the correct operand in the output sheet |
|
827 aOperator = previousOperator; |
|
828 // Set the state to EOperatorResult so that the HandleResult knows what to do |
|
829 UpdateState(EOperatorResult); |
|
830 } |
|
831 } |
|
832 |
|
833 // User has pressed sqrt |
|
834 else if (aOperator == TCalcEditLine::ECalcSqrt) |
|
835 { |
|
836 // We are in a middle of calculation chain |
|
837 if (iState == EOperandAndOperatorAndOperand) |
|
838 { |
|
839 editLine.TrimZeroL(); |
|
840 // Save the previous operator |
|
841 TCalcEditLine::TCalcOperatorType previousOperator = editLine.Operator(); |
|
842 // Set the operator to sqrt |
|
843 editLine.SetOperator(TCalcEditLine::ECalcSqrt); |
|
844 |
|
845 // First calculate the sqrt |
|
846 TRAPD(errorCode, |
|
847 result = iCalcDocument->CalculateAndNoHistoryL( |
|
848 editorNumber, editLine)); |
|
849 |
|
850 if (errorCode) |
|
851 { |
|
852 ErrorMsgL(errorCode); |
|
853 return; |
|
854 } |
|
855 |
|
856 // Set the operator to previous one |
|
857 editLine.SetOperator(previousOperator); |
|
858 // Result goes to the outputsheet |
|
859 editLine.SetNumber(result); |
|
860 |
|
861 // Calculate again |
|
862 TRAPD(errorCode2, |
|
863 result = iCalcDocument->CalculateAndAddHistoryL( |
|
864 result, editLine)); |
|
865 |
|
866 if (errorCode2) |
|
867 { |
|
868 ErrorMsgL(errorCode2); |
|
869 return; |
|
870 } |
|
871 // Set this so that we will display correct operator in the output sheet |
|
872 aOperator = previousOperator; |
|
873 iOutputSheet->ScrollToBottomL(); |
|
874 UpdateState(EOperator); |
|
875 // Dimm the square root and percent |
|
876 iContainer->ShowSqrtButton(EFalse); |
|
877 iContainer->ShowPercentButton(EFalse); |
|
878 } |
|
879 // Only operand and sqrt |
|
880 else |
|
881 { |
|
882 editLine.SetOperator(aOperator); |
|
883 |
|
884 // Trap harness, because the CalculateAndHistoryL leaves in case of negative operand |
|
885 TRAPD(errorCode, |
|
886 result = iCalcDocument->CalculateAndAddHistoryL( |
|
887 editorNumber, editLine)); |
|
888 |
|
889 if (errorCode) |
|
890 { |
|
891 ErrorMsgL(errorCode); |
|
892 return; |
|
893 } |
|
894 |
|
895 iOutputSheet->ScrollToBottomL(); |
|
896 //Set the state to EOperatorResult so that we know to call HandleResult later |
|
897 UpdateState(EOperatorResult); |
|
898 } |
|
899 } |
|
900 // Current state is state4 and previous input is MS, |
|
901 // provisional result is get and show this the editor. |
|
902 // And a line is not added to OutputSheet because a line |
|
903 // is already added. |
|
904 |
|
905 else if (iState == ESelectResult) |
|
906 { |
|
907 iCalcDocument->AddEmptyLine(); |
|
908 editLine.SetOperator(TCalcEditLine::ECalcOperatorNone); |
|
909 // Because the state is "User has selected result", |
|
910 // this function does not occur leave. |
|
911 result = iCalcDocument->CalculateAndAddHistoryL( |
|
912 editorNumber, editLine); |
|
913 iOutputSheet->ScrollToBottomL(); |
|
914 UpdateState(EOperator); |
|
915 iContainer->SetSqrtEnableL(); |
|
916 } |
|
917 |
|
918 // If a input is a operator and state is updated, |
|
919 // calculate and update history. |
|
920 else if (iState != EOperandAndOperator) |
|
921 { |
|
922 editLine.TrimZeroL(); |
|
923 |
|
924 // If the number in the EditLine is not a operand |
|
925 // we need to dim square root and percent buttons |
|
926 if (iState == EOperandAndOperatorAndOperand) |
|
927 { |
|
928 iContainer->ShowSqrtButton(EFalse); |
|
929 iContainer->ShowPercentButton(EFalse); |
|
930 } |
|
931 // Calculate by user's input |
|
932 TRAPD(errorCode, |
|
933 result = iCalcDocument->CalculateAndAddHistoryL( |
|
934 editorNumber, editLine)); |
|
935 |
|
936 if (errorCode) |
|
937 { |
|
938 ErrorMsgL(errorCode); |
|
939 return; |
|
940 } |
|
941 iOutputSheet->ScrollToBottomL(); |
|
942 UpdateState(EOperator); |
|
943 } |
|
944 |
|
945 iEditorSubPane->SetEditorNumber(result); |
|
946 iEditorSubPane->SetOperator(aOperator); |
|
947 |
|
948 if ( aOperator != TCalcEditLine::ECalcSqrt ) |
|
949 { |
|
950 iEditorSubPane->DrawNow(); |
|
951 } |
|
952 iContainer->ScrollArrowUpdate(); |
|
953 iContainer->SetChangeSignEnableL(); |
|
954 iContainer->SetClearKeyEnable(); |
|
955 if (aOperator == TCalcEditLine::ECalcAdd ||aOperator == TCalcEditLine::ECalcSubtract || |
|
956 aOperator == TCalcEditLine::ECalcMultiply ||aOperator == TCalcEditLine::ECalcDivide ) |
|
957 { |
|
958 iContainer->SetChangeSignDisable(); |
|
959 } |
|
960 |
|
961 } |
|
962 |
|
963 |
|
964 // --------------------------------------------------------- |
|
965 // CCalcView::HandleEqualSubRoutineL |
|
966 // Common routine for select result and MemorySave on two operands |
|
967 // and operator or State4. |
|
968 // (other items were commented in a header). |
|
969 // --------------------------------------------------------- |
|
970 // |
|
971 TInt CCalcView::HandleEqualSubRoutineL() |
|
972 { |
|
973 TCalcEditLine editLine(iEditorSubPane->EditLine()); |
|
974 TInt calculationError(KErrNone); |
|
975 TReal64 result(0); |
|
976 |
|
977 if (iState == EOperandAndOperator || iState == EOperatorOnlyResult) |
|
978 { |
|
979 // User has selected equal or operand and sqrt, or percent |
|
980 result = iCalcDocument->ProvisionalResult(); |
|
981 } |
|
982 else |
|
983 { |
|
984 editLine.TrimZeroL(); |
|
985 // We are calculating the intermediate result. |
|
986 // So we need to dim the sqrt and percent buttons. |
|
987 iContainer->ShowSqrtButton(EFalse); |
|
988 iContainer->ShowPercentButton(EFalse); |
|
989 |
|
990 if (iState == ESelectResult) |
|
991 { |
|
992 iCalcDocument->AddEmptyLine(); |
|
993 editLine.SetOperator(TCalcEditLine::ECalcOperatorNone); |
|
994 } |
|
995 TRAP(calculationError, |
|
996 result = iCalcDocument->CalculateAndAddHistoryL( |
|
997 iEditorSubPane->EditorNumber(), editLine)); |
|
998 } |
|
999 |
|
1000 // If overflow or division by zero occurs, |
|
1001 // error message is displayed. |
|
1002 if (calculationError) |
|
1003 { |
|
1004 ErrorMsgL(calculationError); |
|
1005 |
|
1006 } |
|
1007 else |
|
1008 { |
|
1009 iCalcDocument->AddEqualLineAndUpdateLastResultL(); |
|
1010 iEditorSubPane->SetEditorNumber(result); |
|
1011 iEditorSubPane->SetOperator(TCalcEditLine::ECalcEqual); |
|
1012 // Show result on the sheet |
|
1013 CCalcOutputSheet* sheet = iContainer->OutputSheet(); |
|
1014 sheet->ScrollToBottomL(); |
|
1015 iContainer->ScrollArrowUpdate(); |
|
1016 } |
|
1017 return calculationError; |
|
1018 } |
|
1019 |
|
1020 // ---------------------------------------------------- |
|
1021 // CCalcView::DoActivateL |
|
1022 // This is called when CCalcView becomes active. |
|
1023 // (other items were commented in a header). |
|
1024 // ---------------------------------------------------- |
|
1025 // |
|
1026 void CCalcView::DoActivateL |
|
1027 (const TVwsViewId& /* aPrevViewId */, |
|
1028 TUid /* aCustomMessageId */, |
|
1029 const TDesC8& /* aCustomMessage */) |
|
1030 { |
|
1031 AppUi()->AddToStackL(*this, iContainer); |
|
1032 iContainer->ActivateL(); |
|
1033 } |
|
1034 |
|
1035 // ---------------------------------------------------- |
|
1036 // CCalcView::DoDeactivate |
|
1037 // This is called when CCalcView becomes deactive. |
|
1038 // (other items were commented in a header). |
|
1039 // ---------------------------------------------------- |
|
1040 // |
|
1041 void CCalcView::DoDeactivate() |
|
1042 { |
|
1043 if (iContainer) |
|
1044 { |
|
1045 AppUi()->RemoveFromStack(iContainer); |
|
1046 } |
|
1047 } |
|
1048 |
|
1049 // --------------------------------------------------------- |
|
1050 // CCalcView::Id |
|
1051 // Return UID of CCalcView |
|
1052 // (other items were commented in a header). |
|
1053 // --------------------------------------------------------- |
|
1054 // |
|
1055 TUid CCalcView::Id() const |
|
1056 { |
|
1057 return TUid::Uid(KCalcViewId); |
|
1058 } |
|
1059 |
|
1060 // --------------------------------------------------------- |
|
1061 // CCalcView::DynInitMenuPaneL |
|
1062 // This app can have only one menu. |
|
1063 // But menu of Calculator application is changed on State, memory etc. |
|
1064 // Therefore to delete meaningless items from menu, this function is defined. |
|
1065 // (other items were commented in a header). |
|
1066 // --------------------------------------------------------- |
|
1067 // |
|
1068 void CCalcView::DynInitMenuPaneL |
|
1069 (TInt aResourceId, |
|
1070 CEikMenuPane* aMenuPane) |
|
1071 { |
|
1072 if(iServiceHandler->HandleSubmenuL(*aMenuPane)) |
|
1073 { |
|
1074 return; |
|
1075 } |
|
1076 switch (aResourceId) |
|
1077 { |
|
1078 case (R_CALC_POPUPMENU): |
|
1079 { |
|
1080 |
|
1081 DynInitMainMenuPane(aMenuPane); |
|
1082 |
|
1083 /***** Get the context of the Help topic from here *****/ |
|
1084 CArrayFix<TCoeHelpContext>* buf= AppUi()->AppHelpContextL(); |
|
1085 TInt i= buf->Count(); |
|
1086 if(i!=0) |
|
1087 { |
|
1088 /***** Check whether our flag is defined or not *****/ |
|
1089 #ifdef RD_HELP_AIW_INTEGRATION |
|
1090 |
|
1091 /***** Call the AiwProvider's AddItemsL to attach the mnu items********/ |
|
1092 |
|
1093 iServiceHandler->InitializeMenuPaneL(*aMenuPane,aResourceId, |
|
1094 ECmdLast,iServiceHandler->InParamListL()); |
|
1095 /**** Set the old embedded help as dimmed one ****/ |
|
1096 aMenuPane->SetItemDimmed(ECalcCmdHelp, ETrue); |
|
1097 #else |
|
1098 /**** Set the Aiw Help as dimmed one as our feature flag is not defined ****/ |
|
1099 aMenuPane->SetItemDimmed(ECmdAiwPlaceHolder,ETrue); |
|
1100 #endif |
|
1101 } |
|
1102 else |
|
1103 { |
|
1104 /**** If the Feature flag is not defined dont show the Aiw Help ****/ |
|
1105 aMenuPane->SetItemDimmed(ECmdAiwPlaceHolder,ETrue); |
|
1106 } |
|
1107 |
|
1108 /******* Delete the buffer and make it to NULL *****/ |
|
1109 delete buf; |
|
1110 buf = NULL; |
|
1111 if (!FeatureManager::FeatureSupported( KFeatureIdHelp )) |
|
1112 { |
|
1113 aMenuPane->DeleteMenuItem(ECalcCmdHelp); |
|
1114 aMenuPane->DeleteMenuItem(ECmdAiwPlaceHolder); |
|
1115 } |
|
1116 break; |
|
1117 } |
|
1118 |
|
1119 case (R_CALC_MEMORY_MENU): |
|
1120 { |
|
1121 DynInitMemoryMenuPane(aMenuPane); |
|
1122 break; |
|
1123 } |
|
1124 default: |
|
1125 { |
|
1126 break; |
|
1127 } |
|
1128 } |
|
1129 } |
|
1130 // --------------------------------------------------------- |
|
1131 // CCalcView::HandleForegroundEventL |
|
1132 //Refresh and draw display ,paper and function map Icons. |
|
1133 // --------------------------------------------------------- |
|
1134 // |
|
1135 void CCalcView::HandleForegroundEventL(TBool aForeground) |
|
1136 { |
|
1137 if( (aForeground) && (STATIC_CAST(CCalcAppUi*, AppUi())->IsSkinChanged()) ) |
|
1138 { |
|
1139 iEditorSubPane->RefreshDisplaySideLBitmap(); |
|
1140 iEditorSubPane->RefreshDisplayCenterBitmap(); |
|
1141 iEditorSubPane->RefreshDisplaySideRBitmap(); |
|
1142 |
|
1143 iEditorSubPane->DrawNow(); |
|
1144 |
|
1145 iOutputSheet->RefreshPaperBitmap(); |
|
1146 iOutputSheet->RefreshScalablePaperBitmap(); |
|
1147 #ifdef __SCALABLE_ICONS |
|
1148 iOutputSheet->RefreshResultsLineBitmap(); |
|
1149 #endif |
|
1150 iOutputSheet->DrawNow(); |
|
1151 |
|
1152 iContainer->FunctionSubPane()->RefreshButtonIcons(); |
|
1153 for(TInt i =0; i< 10; i++) |
|
1154 { |
|
1155 iContainer->FunctionSubPane()->GetButtonBitmapControl(i)->DrawNow(); |
|
1156 } |
|
1157 } |
|
1158 else |
|
1159 { |
|
1160 CAknView::HandleForegroundEventL(aForeground); |
|
1161 } |
|
1162 } |
|
1163 |
|
1164 |
|
1165 // End of File |