|
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: An App UI class, CCalcAppUi, derived from CAknAppUi |
|
15 * Mainly menu command is handled. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <avkon.hrh> |
|
23 #include <bacntf.h> // For CEnvironmentChangeNotifier |
|
24 #include <Calcsoft.rsg> |
|
25 #include <featmgr.h> |
|
26 |
|
27 #include "CalcApp.h" |
|
28 #include "CalcAppUi.h" |
|
29 #include "CalcDoc.h" |
|
30 #include "CalcHistory.h" |
|
31 #include "CalcEnv.h" |
|
32 #include "CalcView.h" |
|
33 #include "calc.hrh" |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // |
|
44 CCalcAppUi::CCalcAppUi() |
|
45 { |
|
46 } |
|
47 |
|
48 // Destructor |
|
49 CCalcAppUi::~CCalcAppUi() |
|
50 { |
|
51 delete iCalcAppEnv; |
|
52 iCalcAppEnv = NULL; |
|
53 |
|
54 if (iLocaleChangeNotifier) |
|
55 { |
|
56 iLocaleChangeNotifier->Cancel(); |
|
57 } |
|
58 |
|
59 if (iLocaleChangeNotifier) |
|
60 { |
|
61 delete iLocaleChangeNotifier; |
|
62 iLocaleChangeNotifier = NULL; |
|
63 } |
|
64 FeatureManager::UnInitializeLib(); |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CCalcAppUi::ExitCalculator |
|
70 // Exit Calculator application. |
|
71 // (other items were commented in a header). |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CCalcAppUi::ExitCalculator() |
|
75 { |
|
76 TRAP_IGNORE(CEikAppUi::SaveL()); // Save memory and last result |
|
77 Exit(); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CCalcAppUi::LocaleCallback |
|
82 // Called when locale is changed or application is launched. |
|
83 // (other items were commented in a header). |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 TInt CCalcAppUi::LocaleCallback |
|
87 (TAny* aThisPtr) |
|
88 { |
|
89 STATIC_CAST(CCalcAppUi*, aThisPtr)->HandleLocaleChangeEvent(); |
|
90 return 0; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CCalcAppUi::HandleLocaleChangeEvent |
|
95 // Handle locale change event. |
|
96 // (other items were commented in a header). |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 void CCalcAppUi::HandleLocaleChangeEvent() |
|
100 { |
|
101 TLocale locale; |
|
102 TChar newDecimal(locale.DecimalSeparator()); |
|
103 TChar oldDecimal(iCalcAppEnv->DecimalSeparator()); |
|
104 |
|
105 if (newDecimal != oldDecimal) |
|
106 { |
|
107 iCalcAppEnv->SetDecimalSeparator(newDecimal); |
|
108 CCalcView* view = STATIC_CAST(CCalcView*, iView); |
|
109 view->NotifyChangeDecimal(oldDecimal, newDecimal); |
|
110 CCalcDocument* doc = STATIC_CAST(CCalcDocument*, Document()); |
|
111 doc->History()->NotifyChangeDecimal(oldDecimal, newDecimal); |
|
112 } |
|
113 } |
|
114 |
|
115 // Second-phase constructor. |
|
116 void CCalcAppUi::ConstructL() |
|
117 { |
|
118 // Allow base class (CEikAppUi) to perform necessary construction |
|
119 BaseConstructL(CAknAppUi::EAknEnableSkin | EAknEnableMSK); |
|
120 |
|
121 FeatureManager::InitializeLibL(); |
|
122 |
|
123 iCalcAppEnv = CCalcAppEnv::NewL(this); |
|
124 |
|
125 CCalcView* calcView = CCalcView::NewLC(); |
|
126 AddViewL(calcView); |
|
127 CleanupStack::Pop(calcView); |
|
128 |
|
129 // Get pointer to CCalcDocument |
|
130 CCalcDocument* doc = STATIC_CAST(CCalcDocument*, Document()); |
|
131 // CCalcDocument needs the pointer to the iCalcAppEnv |
|
132 doc->SetAppEnv(iCalcAppEnv); |
|
133 |
|
134 // Set locale change notifier |
|
135 TCallBack callBack(LocaleCallback, this); |
|
136 iLocaleChangeNotifier = CEnvironmentChangeNotifier::NewL |
|
137 (EActivePriorityLogonA, callBack); |
|
138 |
|
139 if(iLocaleChangeNotifier->IsActive()) |
|
140 iLocaleChangeNotifier->Cancel(); |
|
141 iLocaleChangeNotifier->Start(); |
|
142 |
|
143 //EISkin2.6 |
|
144 //Set IsSkinchanged value to EFalse when the application launches. |
|
145 SetSkinChanged(EFalse); |
|
146 |
|
147 TFileName path; |
|
148 iEikonEnv->FsSession().PrivatePath(path); |
|
149 iEikonEnv->FsSession().MkDirAll(path); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // CCalcAppUi::HandleCommandL |
|
154 // Handle Exit command. |
|
155 // (other items were commented in a header). |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 void CCalcAppUi::HandleCommandL(TInt aCommand) |
|
159 { |
|
160 if (aCommand == EEikCmdExit) |
|
161 { |
|
162 ExitCalculator(); |
|
163 } |
|
164 } |
|
165 //EISkin2.6 |
|
166 //---------------------------------------------------------- |
|
167 //CCalcAppUi::HandleResourceChangeL |
|
168 // To Handle Skin Change event |
|
169 // Update Bitmaps |
|
170 //---------------------------------------------------------- |
|
171 void CCalcAppUi::HandleResourceChangeL(TInt aType) |
|
172 { |
|
173 if (aType == KAknsMessageSkinChange) |
|
174 { |
|
175 iCalcAppEnv->LoadFuncMapBitmapSkinChangeL(); |
|
176 SetSkinChanged(ETrue); |
|
177 } |
|
178 else |
|
179 { |
|
180 CAknViewAppUi::HandleResourceChangeL(aType); |
|
181 } |
|
182 } |
|
183 |
|
184 //---------------------------------------------------------- |
|
185 //CCalcAppUi::HandleWsEventL |
|
186 // Handles events sent to the application by the window server. |
|
187 // When EKeyOK is long pressed, to avoid being filtered by the AppUi, |
|
188 // send this event directly to the container. |
|
189 // Thus the container can get the EKeyOK key event. |
|
190 //---------------------------------------------------------- |
|
191 void CCalcAppUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination ) |
|
192 { |
|
193 CAknViewAppUi::HandleWsEventL(aEvent, aDestination); //pass the event to appui |
|
194 if ( aEvent.Type() == EEventKey) |
|
195 { |
|
196 //judge the key is EKeyOK or not and the key is long pressed or not |
|
197 TKeyEvent* key = aEvent.Key(); |
|
198 if ( key->iCode == EKeyOK && key->iRepeats ) |
|
199 { |
|
200 //send EEventKey to the Container |
|
201 TopFocusedControl()->OfferKeyEventL( *key, EEventKey ); |
|
202 } |
|
203 } |
|
204 } |
|
205 // End of File |