|
1 /* |
|
2 * Copyright (c) 2005 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: Declares navi pane control for application. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <gsmuset.h> // CCnvCharacterSetConverter |
|
21 #include <aknenv.h> // CAknEnv |
|
22 #include <aknnavide.h> // CAknNavigationDecorator |
|
23 #include <aknEditStateIndicator.h> |
|
24 #include <AknIndicatorContainer.h> |
|
25 #include <aknnavilabel.h> |
|
26 #include "UssdComms.h" |
|
27 |
|
28 #include "UssdAppUi.h" |
|
29 #include "UssdNaviPane.h" |
|
30 |
|
31 #include <AknUtils.h> |
|
32 // CONSTANTS |
|
33 |
|
34 // Unicode char codes for GSM 03.38 7 bit ext table characters |
|
35 static const TUint KUssdEdEuroSymbol = 0x20ac; |
|
36 static const TUint KUssdEdLeftSquareBracket = 0x5b; |
|
37 static const TUint KUssdEdReverseSolidus = 0x5c; |
|
38 static const TUint KUssdEdRightSquareBracket = 0x5d; |
|
39 static const TUint KUssdEdCircumflexAccent = 0x5e; |
|
40 static const TUint KUssdEdLeftCurlyBracket = 0x7b; |
|
41 static const TUint KUssdEdVerticalLine = 0x7c; |
|
42 static const TUint KUssdEdRightCurlyBracket = 0x7d; |
|
43 static const TUint KUssdEdTilde = 0x7e; |
|
44 static const TUint KUssdDownwardsArrowLeft = 0x21B2; |
|
45 static const TUint KUssdDownwardsArrowRight = 0x21B3; |
|
46 static const TUint KUssdCharDwithLine = 0xD0; |
|
47 static const TUint KUssdCharBigRhoo = 0xDE; |
|
48 static const TUint KUssdCharSmallDelta = 0xF0; |
|
49 static const TUint KUssdCharSmallFii = 0xFE; |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CUssdNaviPane::CUssdNaviPane |
|
54 // C++ constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CUssdNaviPane::CUssdNaviPane( CUssdAppUi& aAppUi ): iAppUi( aAppUi ) |
|
59 { |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CUssdNaviPane::NewL |
|
64 // |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CUssdNaviPane* CUssdNaviPane::NewL( CUssdAppUi& aAppUi ) |
|
69 { |
|
70 CUssdNaviPane* self = new ( ELeave ) CUssdNaviPane( aAppUi ); |
|
71 CleanupStack::PushL( self ); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop( self ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CUssdNaviPane::ConstructL |
|
79 // |
|
80 // Symbian 2nd phase constructor can leave. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CUssdNaviPane::ConstructL() |
|
84 { |
|
85 |
|
86 CreateExtraNaviLabelL(); |
|
87 |
|
88 iCharacterSetConverter = CCnvCharacterSetConverter::NewL(); |
|
89 |
|
90 iCharacterSetConverter->PrepareToConvertToOrFromL( |
|
91 KCharacterSetIdentifierSms7Bit, |
|
92 iCoeEnv->FsSession() ); |
|
93 |
|
94 iCharacterSetConverter->SetDowngradeForExoticLineTerminatingCharacters( |
|
95 CCnvCharacterSetConverter::EDowngradeExoticLineTerminatingCharactersToJustLineFeed ); |
|
96 |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CUssdNaviPane::~CUssdNaviPane |
|
101 // |
|
102 // Destructor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CUssdNaviPane::~CUssdNaviPane() |
|
106 { |
|
107 |
|
108 if ( iNaviPane && iNaviDecorator ) |
|
109 { |
|
110 iNaviPane->Pop( iNaviDecorator ); |
|
111 delete iNaviDecorator; |
|
112 iNaviDecorator = NULL; |
|
113 iNaviPane = NULL; |
|
114 } |
|
115 |
|
116 delete iCharacterSetConverter; |
|
117 iCharacterSetConverter = NULL; |
|
118 |
|
119 iNaviLabel = NULL; |
|
120 |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------- |
|
124 // CUssdNaviPane::CreateExtraNaviLabelL |
|
125 // Creates an extra navi label. |
|
126 // (other items were commented in a header). |
|
127 // ---------------------------------------------------- |
|
128 // |
|
129 void CUssdNaviPane::CreateExtraNaviLabelL() |
|
130 { |
|
131 |
|
132 CEikStatusPane* sp = iAppUi.StatusPane(); |
|
133 iNaviPane = static_cast<CAknNavigationControlContainer*>( |
|
134 sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
135 |
|
136 iNaviDecorator = iNaviPane->CreateNavigationLabelL( |
|
137 KNullDesC ); |
|
138 iNaviLabel = static_cast<CAknNaviLabel*>( |
|
139 iNaviDecorator->DecoratedControl() ); |
|
140 iNaviPane->PushL( *iNaviDecorator ) ; |
|
141 |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CUssdNaviPane::UpdateMsgLengthL |
|
146 // Update the message length information to navipane |
|
147 // (other items were commented in a header). |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 TInt CUssdNaviPane::UpdateMsgLengthL( const TDesC& aInputString, |
|
151 CCoeControl* aControl ) |
|
152 { |
|
153 TInt maxLen(0); |
|
154 const TInt txtLen = aInputString.Length(); |
|
155 |
|
156 HBufC* digitBuffer = HBufC::NewLC( EAknMaxIntegerDigits ); |
|
157 TPtr bufPtr( digitBuffer->Des() ); |
|
158 |
|
159 if ( NeedsToBeSentAsUnicodeL( aInputString ) ) |
|
160 { |
|
161 bufPtr.AppendNum( KUssdEditorMaxLenght/2 - txtLen ); |
|
162 maxLen=KUssdEditorMaxLenght/2; |
|
163 } |
|
164 else |
|
165 { |
|
166 TInt extendedCount = CountExtendedTableChars( aInputString ); |
|
167 TInt totalLen = KUssdEditorMaxLenght - ( txtLen + extendedCount ); |
|
168 if ( totalLen < 0 ) // last was alphabet extended when one left |
|
169 { |
|
170 GenerateBackSpaceKeyL( aControl ); |
|
171 extendedCount--; |
|
172 totalLen = totalLen+2; |
|
173 } |
|
174 bufPtr.AppendNum( totalLen ); |
|
175 maxLen=KUssdEditorMaxLenght-extendedCount; |
|
176 } |
|
177 |
|
178 AknTextUtils::LanguageSpecificNumberConversion( bufPtr ); |
|
179 |
|
180 // Giving msg length string to indicator container |
|
181 MAknEditingStateIndicator* stateIndicator = |
|
182 iAvkonEnv->EditingStateIndicator(); |
|
183 if ( stateIndicator ) |
|
184 { |
|
185 CAknIndicatorContainer* iIndicatorContainerSMS = |
|
186 stateIndicator->IndicatorContainer(); |
|
187 if ( iIndicatorContainerSMS ) |
|
188 { |
|
189 iIndicatorContainerSMS->SetIndicatorState( |
|
190 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), |
|
191 EAknIndicatorStateOn ); |
|
192 iIndicatorContainerSMS->SetIndicatorValueL( |
|
193 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), |
|
194 *digitBuffer ); |
|
195 } |
|
196 } |
|
197 |
|
198 iNaviLabel->SetTextL( *digitBuffer ); |
|
199 CleanupStack::PopAndDestroy( digitBuffer ); |
|
200 |
|
201 return maxLen; |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CUssdNaviPane::NeedsToBeSentAsUnicodeL |
|
207 // Checks if there are any unicode characters in the message |
|
208 // (other items were commented in a header). |
|
209 // --------------------------------------------------------- |
|
210 // |
|
211 TBool CUssdNaviPane::NeedsToBeSentAsUnicodeL( const TDesC& aInputString ) const |
|
212 { |
|
213 |
|
214 TBool needsToBeSentAsUnicode = EFalse; |
|
215 |
|
216 for ( TPtrC remainderOfInputString( aInputString ); |
|
217 remainderOfInputString.Length()>0 ; ) |
|
218 { |
|
219 TBuf8<KUssdEditorMaxLenght> notUsedForeignParam; |
|
220 TInt numberOfUnconvertibleCharacters = 0; |
|
221 const TInt returnValue = |
|
222 iCharacterSetConverter->ConvertFromUnicode( |
|
223 notUsedForeignParam, |
|
224 remainderOfInputString, |
|
225 numberOfUnconvertibleCharacters ); |
|
226 if ( ( returnValue < 0 ) || |
|
227 ( numberOfUnconvertibleCharacters > 0 )) |
|
228 // if there was an error in trying to do the conversion, or if |
|
229 // there was an unconvertible character (e.g. a Chinese character) |
|
230 { |
|
231 TUint uChar; |
|
232 for ( TInt i = 0;i < remainderOfInputString.Length();i++ ) |
|
233 { |
|
234 uChar = TUint( remainderOfInputString[ i ] ); |
|
235 if ( uChar == KUssdDownwardsArrowLeft || |
|
236 uChar == KUssdDownwardsArrowRight || |
|
237 uChar == KUssdCharDwithLine || |
|
238 uChar == KUssdCharBigRhoo || |
|
239 uChar == KUssdCharSmallDelta || |
|
240 uChar == KUssdCharSmallFii ) |
|
241 { |
|
242 numberOfUnconvertibleCharacters--; |
|
243 } |
|
244 } |
|
245 |
|
246 if ( returnValue < 0 || numberOfUnconvertibleCharacters > 0 ) |
|
247 { |
|
248 // if there was an error in trying to do the conversion, or if there was an |
|
249 // unconvertible character (e.g. a Chinese character) |
|
250 needsToBeSentAsUnicode = ETrue; |
|
251 break; |
|
252 } |
|
253 } |
|
254 |
|
255 remainderOfInputString.Set( |
|
256 remainderOfInputString.Right( returnValue ) ); |
|
257 } |
|
258 return needsToBeSentAsUnicode; |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // CUssdNaviPane::CountExtendedTableChars |
|
263 // Counts if there are 7bit extended table characters in message |
|
264 // (other items were commented in a header). |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 TInt CUssdNaviPane::CountExtendedTableChars( const TDesC& aInputString ) const |
|
268 { |
|
269 const TInt total = aInputString.Length(); |
|
270 TInt extChars = 0; |
|
271 |
|
272 TUint uChar; |
|
273 for ( TInt i=0; i < total; i++ ) |
|
274 { |
|
275 uChar = TUint(aInputString[i]); |
|
276 if (( uChar == KUssdEdLeftSquareBracket) || |
|
277 ( uChar == KUssdEdReverseSolidus ) || |
|
278 ( uChar == KUssdEdRightSquareBracket ) || |
|
279 ( uChar == KUssdEdCircumflexAccent ) || |
|
280 ( uChar == KUssdEdLeftCurlyBracket ) || |
|
281 ( uChar == KUssdEdVerticalLine ) || |
|
282 ( uChar == KUssdEdRightCurlyBracket ) || |
|
283 ( uChar == KUssdEdTilde ) || |
|
284 ( uChar == KUssdEdEuroSymbol )) |
|
285 { |
|
286 extChars = extChars + 1; |
|
287 } |
|
288 } |
|
289 return extChars; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CUssdNaviPane::GenerateBackSpaceKeyL |
|
294 // Generates a backspace key press event. |
|
295 // (other items were commented in a header). |
|
296 // --------------------------------------------------------- |
|
297 // |
|
298 void CUssdNaviPane::GenerateBackSpaceKeyL( CCoeControl* aControl ) |
|
299 { |
|
300 TKeyEvent keyEvent; |
|
301 keyEvent.iCode = EKeyBackspace; |
|
302 keyEvent.iScanCode = EStdKeyBackspace; |
|
303 keyEvent.iRepeats = 1; |
|
304 keyEvent.iModifiers = 0; |
|
305 TEventCode type = EEventKey; |
|
306 |
|
307 if ( aControl ) |
|
308 { |
|
309 aControl->OfferKeyEventL( keyEvent, type ); |
|
310 } |
|
311 } |
|
312 |
|
313 // End of File |