|
1 /* |
|
2 * Copyright (c) 2002-2009 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: |
|
15 * Declares container control for application. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "UssdComms.h" |
|
22 #include "UssdNaviPane.h" |
|
23 #include "UssdAppUi.h" |
|
24 #include "UssdContainer.h" |
|
25 #include "UssdEditorLines.h" |
|
26 #include <ussd.rsg> |
|
27 #include "UssdLayout.h" |
|
28 #include <aknkeys.h> |
|
29 #include "ussd.hrh" |
|
30 #include <eikedwin.h> |
|
31 #include <bldvariant.hrh> |
|
32 #include <featmgr.h> |
|
33 |
|
34 #include <centralrepository.h> |
|
35 #include <telinternalcrkeys.h> |
|
36 #include "telephonyvariant.hrh" |
|
37 |
|
38 #include <csxhelp/ussd.hlp.hrh> // for help context |
|
39 #include "UssdApp.h" // for applicationUID |
|
40 #include <AknUtils.h> |
|
41 |
|
42 // For skinning. |
|
43 #include <AknsBasicBackgroundControlContext.h> |
|
44 #include <AknsDrawUtils.h> |
|
45 #include <AknsUtils.h> |
|
46 #include <txtglobl.h> |
|
47 |
|
48 |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CUssdContainer::CUssdContainer |
|
54 // C++ constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CUssdContainer::CUssdContainer( CUssdAppUi& aAppUi ): iAppUi( aAppUi ) |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CUssdContainer::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CUssdContainer::ConstructL( const TRect& aRect ) |
|
69 { |
|
70 CreateWindowL(); |
|
71 |
|
72 // Create background control context for skins. |
|
73 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
74 KAknsIIDQsnBgAreaMainMessage, aRect, ETrue /*Parent absolute*/ ); |
|
75 |
|
76 // Create editor |
|
77 iEditor = CreateEdwinL(); |
|
78 |
|
79 // Lines |
|
80 iLines = new ( ELeave ) CUssdEditorLines; |
|
81 iLines->ConstructL( this ); |
|
82 |
|
83 TInt featureBitmask( 0 ); |
|
84 |
|
85 // Connecting and initialization KCRUidTelVariation |
|
86 CRepository* repository = CRepository::NewL( KCRUidTelVariation ); |
|
87 CleanupStack::PushL( repository ); |
|
88 |
|
89 // Get the value from Central Repository |
|
90 repository->Get( KTelVariationFlags, featureBitmask ); |
|
91 if ( featureBitmask & KTelephonyLVFlagUssdUIRemainingChars ) |
|
92 { |
|
93 iNaviPaneHandler = CUssdNaviPane::NewL( iAppUi ); |
|
94 } |
|
95 |
|
96 CleanupStack::PopAndDestroy( repository ); |
|
97 |
|
98 // Finish the job |
|
99 SetRect( aRect ); |
|
100 ActivateL(); |
|
101 |
|
102 iEditor->SetFocus( ETrue ); |
|
103 } |
|
104 |
|
105 |
|
106 // Destructor |
|
107 CUssdContainer::~CUssdContainer() |
|
108 { |
|
109 delete iLines; |
|
110 |
|
111 AknsUtils::DeregisterControlPosition( iEditor ); |
|
112 delete iEditor; |
|
113 delete iNaviPaneHandler; |
|
114 |
|
115 delete iBgContext; // For skinning, can be deleted, NULL if not exist. |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CUssdContainer::HandleEdwinEventL |
|
120 // Called by framework when the Editor is changed |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CUssdContainer::HandleEdwinEventL( CEikEdwin* /*aEdwin*/, |
|
125 TEdwinEvent aEventType ) |
|
126 { |
|
127 switch( aEventType ) |
|
128 { |
|
129 case EEventTextUpdate: |
|
130 { |
|
131 UpdateNavipaneMsgLengthL(); |
|
132 break; |
|
133 } |
|
134 default: |
|
135 break; |
|
136 } |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CUssdContainer::SizeChanged |
|
141 // Called by framework when the view size is changed |
|
142 // |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CUssdContainer::SizeChanged() |
|
146 { |
|
147 // Backgroud context |
|
148 iBgContext->SetParentPos( PositionRelativeToScreen() ); |
|
149 iBgContext->SetRect( Rect() ) ; |
|
150 // Edwin |
|
151 AknLayoutUtils::LayoutEdwin( |
|
152 iEditor, |
|
153 Rect(), |
|
154 UssdLayout::MessageWritingTexts3() ); |
|
155 |
|
156 // We need to make some room for scrollbar to fit |
|
157 // so the editor must be narrowed down a bit. |
|
158 |
|
159 TAknLayoutId layout = UssdLayout::CurrentLayout(); |
|
160 TRect sbr = iEditor->ScrollBarFrame()->VerticalScrollBar()->Rect(); |
|
161 |
|
162 if( layout != EAknLayoutIdABRW ) |
|
163 { |
|
164 TPoint editorTLPoint(Rect().iTl.iX, iEditor->Rect().iTl.iY); |
|
165 |
|
166 iEditor->SetExtent( editorTLPoint , |
|
167 TSize( Rect().Width() - sbr.Width(), sbr.Height() ) ); |
|
168 } |
|
169 else // right to left layout |
|
170 { |
|
171 TPoint editorTLPoint( ( Rect().iTl.iX + sbr.Width() ), |
|
172 iEditor->Rect().iTl.iY); |
|
173 |
|
174 iEditor->SetExtent( editorTLPoint , |
|
175 TSize( Rect().Width() - sbr.Width(), |
|
176 sbr.Height() ) ); |
|
177 } |
|
178 |
|
179 TRAP_IGNORE( UpdateNavipaneMsgLengthL() ); |
|
180 |
|
181 // overwite inputmode in portraitmode |
|
182 if ( Rect().Height() > Rect().Width() ) |
|
183 { |
|
184 iEditor->SetAknEditorCurrentInputMode( EAknEditorNumericInputMode ); |
|
185 } |
|
186 |
|
187 // Change the colour of the edwin if needed |
|
188 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
189 if ( skin ) |
|
190 { |
|
191 TRgb color; |
|
192 TInt error = AknsUtils::GetCachedColor( |
|
193 skin, |
|
194 color, |
|
195 KAknsIIDQsnTextColors, |
|
196 EAknsCIQsnTextColorsCG6 ); |
|
197 |
|
198 if ( error == KErrNone ) |
|
199 { |
|
200 TCharFormat charFormat; |
|
201 TCharFormatMask charFormatMask; |
|
202 ( reinterpret_cast< CGlobalText* >( iEditor->Text() ) ) |
|
203 ->GetCharFormat( charFormat, charFormatMask, 0, 0 ); |
|
204 |
|
205 charFormat.iFontPresentation.iTextColor = color; |
|
206 charFormatMask.SetAll(); |
|
207 |
|
208 CCharFormatLayer* charFormatLayer = NULL; |
|
209 |
|
210 TRAP( error, charFormatLayer = |
|
211 CCharFormatLayer::NewL( charFormat,charFormatMask ) ); |
|
212 |
|
213 if ( !error ) |
|
214 { |
|
215 iEditor->SetCharFormatLayer( charFormatLayer ); |
|
216 } |
|
217 } |
|
218 } |
|
219 |
|
220 // Set editor lines |
|
221 iLines->SetRect( Rect() ); |
|
222 |
|
223 AknsUtils::RegisterControlPosition( iEditor ); |
|
224 } |
|
225 |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CUssdContainer::CountComponentControls |
|
229 // |
|
230 // |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TInt CUssdContainer::CountComponentControls() const |
|
234 { |
|
235 return 2; // editor and lines |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CUssdContainer::ComponentControl |
|
241 // |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 CCoeControl* CUssdContainer::ComponentControl( TInt aIndex ) const |
|
245 { |
|
246 switch ( aIndex ) |
|
247 { |
|
248 case 0: |
|
249 return iEditor; |
|
250 case 1: |
|
251 return iLines; |
|
252 default: |
|
253 return NULL; |
|
254 } |
|
255 |
|
256 } |
|
257 |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CUssdContainer::Draw |
|
261 // |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CUssdContainer::Draw( const TRect& aRect ) const |
|
265 { |
|
266 CWindowGc& gc = SystemGc(); |
|
267 |
|
268 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
269 |
|
270 if ( iBgContext ) |
|
271 { |
|
272 AknsDrawUtils::Background( |
|
273 skin, iBgContext, this, gc, aRect); |
|
274 } |
|
275 else |
|
276 { |
|
277 // Otherwise clear the area |
|
278 gc.SetBrushColor( AKN_LAF_COLOR( UssdLayout::LayoutColourWhite() ) ); |
|
279 DrawUtils::ClearBetweenRects( gc, aRect, iEditor->Rect() ); |
|
280 } |
|
281 } |
|
282 |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CUssdContainer::OfferKeyEventL |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 TKeyResponse CUssdContainer::OfferKeyEventL( |
|
289 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
290 { |
|
291 TKeyResponse response = EKeyWasNotConsumed; |
|
292 |
|
293 // Special key handling comes first. |
|
294 if ( aKeyEvent.iScanCode == EStdKeyYes ) // Send key. |
|
295 { |
|
296 // The reason that the send key is handled via TStdScanCode rather than TKeyCode is that |
|
297 // we also have to be able to catch EEventKeyUp and EEventKeyDown key events in addition |
|
298 // to EEventKey. This is because TKeyEvent::iCode is always 0 when TEventCode is EEventKey. |
|
299 if ( iEditor->TextLength() ) |
|
300 { |
|
301 if ( aType == EEventKey ) |
|
302 { |
|
303 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
304 { |
|
305 iAppUi.HandleCommandL( EUssdMenuItemSend ); |
|
306 } |
|
307 else |
|
308 { |
|
309 iAppUi.HandleCommandL( EUssdSoftkeySend ); |
|
310 } |
|
311 } |
|
312 response = EKeyWasConsumed; // Dialer should not be launched when the USSD string exists and send key is used. |
|
313 } |
|
314 } |
|
315 else if ( aKeyEvent.iCode == EKeyEscape ) |
|
316 { |
|
317 iAppUi.HandleCommandL( EAknSoftkeyExit ); |
|
318 response = EKeyWasConsumed; |
|
319 } |
|
320 else // Default keys are handled here. |
|
321 { |
|
322 response = iEditor->OfferKeyEventL( aKeyEvent, aType ); |
|
323 |
|
324 if ( aType == EEventKey || aType == EEventKeyUp ) |
|
325 { |
|
326 UpdateNavipaneMsgLengthL(); |
|
327 } |
|
328 |
|
329 if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
330 { |
|
331 // Change softkeys if needed. |
|
332 iAppUi.SetSoftkeySendVisibleL( iEditor->TextLength() != 0 ); |
|
333 } |
|
334 |
|
335 iAppUi.Cba()->SetCommandSetL( R_USSD_SOFTKEYS_OPTIONS_EXIT_OPTIONS ); |
|
336 iAppUi.Cba()->DrawNow(); |
|
337 } |
|
338 |
|
339 return response; |
|
340 } |
|
341 |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CUssdContainer::Editor |
|
345 // Give editor |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 CEikEdwin& CUssdContainer::Editor() |
|
349 { |
|
350 return *iEditor; |
|
351 } |
|
352 |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CUssdContainer::FocusChanged |
|
356 // |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CUssdContainer::FocusChanged( TDrawNow aDrawNow ) |
|
360 { |
|
361 iEditor->SetFocus( IsFocused(), aDrawNow ); |
|
362 } |
|
363 |
|
364 |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CUssdContainer::GetHelpContext |
|
368 // This function is called when Help application is launched. |
|
369 // |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CUssdContainer::GetHelpContext( |
|
373 TCoeHelpContext& aContext ) const |
|
374 { |
|
375 // If help defined. |
|
376 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
377 { |
|
378 aContext.iMajor = KUidussd; |
|
379 aContext.iContext = KUSSD_HLP_EDITOR; |
|
380 } |
|
381 |
|
382 // If help not defined, do nothing |
|
383 } |
|
384 |
|
385 |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // CUssdContainer::HandleResourceChange |
|
389 // This function is called when Help application is launched. |
|
390 // |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 void CUssdContainer::HandleResourceChange( TInt aType ) |
|
394 { |
|
395 switch ( aType ) |
|
396 { |
|
397 case KEikColorResourceChange: |
|
398 case KAknsMessageSkinChange: |
|
399 { |
|
400 SizeChanged(); |
|
401 DrawDeferred(); |
|
402 break; |
|
403 } |
|
404 |
|
405 default: |
|
406 { |
|
407 CCoeControl::HandleResourceChange( aType ); |
|
408 } |
|
409 } |
|
410 } |
|
411 |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CUssdContainer::MopSupplyObject |
|
415 // |
|
416 // ----------------------------------------------------------------------------- |
|
417 // |
|
418 TTypeUid::Ptr CUssdContainer::MopSupplyObject( TTypeUid aId ) |
|
419 { |
|
420 if ( aId.iUid == MAknsControlContext::ETypeId ) |
|
421 { |
|
422 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
423 } |
|
424 return CCoeControl::MopSupplyObject( aId ); |
|
425 } |
|
426 |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CUssdContainer::CreateEdwinL |
|
430 // Creates new edwin |
|
431 // |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 CEikEdwin* CUssdContainer::CreateEdwinL() |
|
435 { |
|
436 CEikEdwin* newEditor = new ( ELeave ) CEikEdwin; |
|
437 CleanupStack::PushL( newEditor ); |
|
438 newEditor->SetContainerWindowL( *this ); |
|
439 //Set the editor observer |
|
440 newEditor->SetEdwinObserver( this ); |
|
441 |
|
442 newEditor->SetAknEditorAllowedInputModes( |
|
443 EAknEditorNumericInputMode | EAknEditorTextInputMode ); |
|
444 newEditor->SetAknEditorInputMode( EAknEditorNumericInputMode ); |
|
445 newEditor->SetAknEditorNumericKeymap( EAknEditorStandardNumberModeKeymap ); |
|
446 |
|
447 TInt editorFlags = EAknEditorFlagNoT9 | EAknEditorFlagEnableScrollBars; |
|
448 |
|
449 if ( FeatureManager::FeatureSupported( KFeatureIdJapanese ) ) |
|
450 { |
|
451 editorFlags |= EAknEditorFlagLatinInputModesOnly; |
|
452 } |
|
453 |
|
454 if( FeatureManager::FeatureSupported( KFeatureIdPenSupport ) ) |
|
455 { |
|
456 editorFlags |= EAknEditorFlagDeliverVirtualKeyEventsToApplication; |
|
457 } |
|
458 |
|
459 newEditor->SetAknEditorFlags( editorFlags ); |
|
460 |
|
461 // Get the layout, i.e. variant. |
|
462 EVariantFlag variant = AknLayoutUtils::Variant(); |
|
463 |
|
464 // According to layout, construct the editor. |
|
465 if ( variant == EApacVariant ) |
|
466 { |
|
467 // APAC variant |
|
468 AknEditUtils::ConstructEditingL( newEditor , R_USSD_EDWIN_EDITOR_APAC ); |
|
469 } |
|
470 else |
|
471 { |
|
472 // EEuropeanVariant (includes ABRW) |
|
473 AknEditUtils::ConstructEditingL( newEditor , R_USSD_EDWIN_EDITOR_ELAF ); |
|
474 } |
|
475 |
|
476 CleanupStack::Pop( newEditor ); |
|
477 return newEditor; |
|
478 } |
|
479 |
|
480 // --------------------------------------------------------- |
|
481 // CUssdContainer::UpdateNavipaneMsgLengthL |
|
482 // --------------------------------------------------------- |
|
483 void CUssdContainer::UpdateNavipaneMsgLengthL() |
|
484 { |
|
485 |
|
486 if ( iNaviPaneHandler ) |
|
487 { |
|
488 |
|
489 TInt maxLen=0; |
|
490 TBuf<KUssdEditorMaxLenght> inputTexts; |
|
491 |
|
492 iEditor->GetText( inputTexts ); |
|
493 |
|
494 maxLen = iNaviPaneHandler->UpdateMsgLengthL( inputTexts, this ); |
|
495 |
|
496 // if pasted more than 91 chinese characters then it must be |
|
497 // cutted and set correct message length in navi pane |
|
498 if ( inputTexts.Length() > maxLen ) |
|
499 { |
|
500 inputTexts.Copy( inputTexts.Left( maxLen ) ); |
|
501 iEditor->SetTextL( &inputTexts ); |
|
502 iNaviPaneHandler->UpdateMsgLengthL( inputTexts, this ); |
|
503 iEditor->DrawNow(); |
|
504 iEditor->SetCursorPosL( maxLen, EFalse ); |
|
505 } |
|
506 |
|
507 iEditor->SetMaxLength( maxLen ); |
|
508 |
|
509 } |
|
510 |
|
511 } |
|
512 |
|
513 // End of File |