|
1 /* |
|
2 * Copyright (c) 2006 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: Fader control in navi pane |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCAFadeControl.h" |
|
21 #include "MCAFadeTextObserver.h" |
|
22 #include "ChatDefinitions.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 #include "LayoutDebugPrint.h" |
|
25 #include "Impserrors.h" |
|
26 #include "CCAAppUi.h" |
|
27 #include "MCALayoutInfo.h" |
|
28 |
|
29 #include <eikenv.h> |
|
30 #include <aknutils.h> |
|
31 #include <aknnavi.h> |
|
32 #include <aknconsts.h> |
|
33 #include <aknenv.h> |
|
34 #include <applayout.cdl.h> |
|
35 #include <AknsDrawUtils.h> |
|
36 #include <AknsBasicBackgroundControlContext.h> |
|
37 |
|
38 |
|
39 //CONSTANTS |
|
40 const TInt KLafCount( 10 ); //Count of LAF indexes |
|
41 const TInt KDelayColorIndex( 5 ); //From LAF: Color 0 is in index 5 |
|
42 const TTimeIntervalMicroSeconds32 KIndicationDelay( 4000000 ); //4 seconds waiting |
|
43 const TUint16 KAIMMessageIcon( 0xF808 ); //PUA icon code for AIMMESSAGE |
|
44 |
|
45 // ========================= MEMBER FUNCTIONS ================================ |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CCAFadeControl::NewL |
|
49 // Two-phased constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CCAFadeControl* CCAFadeControl::NewL( const TRect& aRect ) |
|
53 { |
|
54 CCAFadeControl* self = CCAFadeControl::NewLC( aRect ); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CCAFadeControl::NewLC |
|
61 // Two-phased constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CCAFadeControl* CCAFadeControl::NewLC( const TRect& aRect ) |
|
65 { |
|
66 CCAFadeControl* self = new ( ELeave ) CCAFadeControl(); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL( aRect ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CCAFadeControl::ConstructL(const TRect& aRect) |
|
74 // Symbian OS two phased constructor |
|
75 // |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CCAFadeControl::ConstructL( const TRect& aRect ) |
|
79 { |
|
80 |
|
81 iLayoutInfo = static_cast<CCAAppUi*>( iEikonEnv->AppUi() )-> |
|
82 LayoutInfo(); |
|
83 // Currently we have 2 observers, so granularity of 2 is logical choice. |
|
84 iObserverArray = new ( ELeave ) CArrayPtrSeg<MCAFadeTextObserver>( 2 ); |
|
85 iIMessage = HBufC::NewL( KMaxWVIDLength + 1 );//1 is indication character |
|
86 iTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
87 |
|
88 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
89 KAknsIIDQsnBgNavipaneSolid, aRect, EFalse ); |
|
90 iViewRect = TRect( aRect ); |
|
91 CreateWindowL(); |
|
92 MakeVisible( EFalse ); |
|
93 } |
|
94 |
|
95 // Constructor |
|
96 CCAFadeControl::CCAFadeControl() |
|
97 : iTimerState( ETimerStopped ) |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 // Destructor |
|
103 CCAFadeControl::~CCAFadeControl() |
|
104 { |
|
105 |
|
106 if ( iObserverArray ) |
|
107 { |
|
108 iObserverArray->Reset(); |
|
109 delete iObserverArray; |
|
110 } |
|
111 delete iTimer; |
|
112 delete iIMessage; |
|
113 delete iClippedMessage; |
|
114 delete iBgContext; |
|
115 iTextLayouts.Close(); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CCAFadeControl::SizeChanged() |
|
120 // called by framework when the view size is changed |
|
121 // |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CCAFadeControl::SizeChanged() |
|
125 { |
|
126 TRect myNavePaneRect; |
|
127 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, |
|
128 myNavePaneRect ); |
|
129 |
|
130 LAYOUT_DP( D_LAYOUT_LIT( "CCAFadeControl::SizeChanged %d %d %d %d" ), |
|
131 myNavePaneRect.iTl.iX, myNavePaneRect.iTl.iY, |
|
132 myNavePaneRect.iBr.iX, myNavePaneRect.iBr.iY ); |
|
133 |
|
134 myNavePaneRect.Move( -myNavePaneRect.iTl.iX, -myNavePaneRect.iTl.iY ); |
|
135 |
|
136 iTextLayouts.Reset(); |
|
137 for ( TInt i( 0 ); i < KLafCount; i++ ) |
|
138 { |
|
139 TAknLayoutText text; |
|
140 TAknTextLineLayout textLayout; |
|
141 textLayout = iLayoutInfo->IM_navi_pane_texts_Line_1( i, 0 ); |
|
142 |
|
143 text.LayoutText( myNavePaneRect, textLayout ); |
|
144 iTextLayouts.Append( text ); |
|
145 LAYOUT_DP( D_LAYOUT_LIT( |
|
146 "CCAFadeControl::SizeChanged textRect %d %d %d %d" ), |
|
147 text.TextRect().iTl.iX, text.TextRect().iTl.iY, |
|
148 text.TextRect().iBr.iX, text.TextRect().iBr.iY ); |
|
149 } |
|
150 TAknWindowLineLayout navipaneLayout = |
|
151 AknLayout::Status_pane_elements_Line_1(); |
|
152 iNavipaneRect.LayoutRect( myNavePaneRect, navipaneLayout ); |
|
153 LAYOUT_DP( D_LAYOUT_LIT( "CCAFadeControl::SizeChanged %d %d %d %d" ), |
|
154 iNavipaneRect.Rect().iTl.iX, iNavipaneRect.Rect().iTl.iY, |
|
155 iNavipaneRect.Rect().iBr.iX, iNavipaneRect.Rect().iBr.iY ); |
|
156 |
|
157 UpdateClippedMessage(); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CCAFadeControl::CountComponentControls() const |
|
162 // |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CCAFadeControl::CountComponentControls() const |
|
167 { |
|
168 return 0; |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CCAFadeControl::ComponentControl(TInt aIndex) const |
|
173 // |
|
174 // |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 CCoeControl* CCAFadeControl::ComponentControl( TInt /*aIndex*/ ) const |
|
178 { |
|
179 return NULL; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CCAFadeControl::Draw(const TRect& aRect) const |
|
184 // |
|
185 // |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void CCAFadeControl::Draw( const TRect& /*aRect*/ ) const |
|
189 { |
|
190 CWindowGc& gc = SystemGc(); |
|
191 |
|
192 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
193 MAknsControlContext* cc = iBgContext; |
|
194 if ( !AknsDrawUtils::Background( skin, cc, gc, iViewRect ) ) |
|
195 { |
|
196 gc.Clear( iViewRect ); |
|
197 } |
|
198 iTextLayouts[iColorIndex].DrawText( gc, *iClippedMessage ); |
|
199 |
|
200 LAYOUT_DP( D_LAYOUT_LIT( "CCAFadeControl::Draw TextRect %d %d %d %d" ), |
|
201 iTextLayouts[iColorIndex].TextRect().iTl.iX, |
|
202 iTextLayouts[iColorIndex].TextRect().iTl.iY, |
|
203 iTextLayouts[iColorIndex].TextRect().iBr.iX, |
|
204 iTextLayouts[iColorIndex].TextRect().iBr.iY ); |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CCAFadeControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
209 // |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CCAFadeControl::HandleControlEventL( CCoeControl* /*aControl*/, |
|
214 TCoeEvent /*aEventType*/ ) |
|
215 { |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CCAFadeControl::FadeText() |
|
220 // (other items were commented in a header). |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 TInt CCAFadeControl::FadeText( TAny* aAnyPtr ) |
|
224 { |
|
225 if ( !aAnyPtr ) |
|
226 { |
|
227 return EFalse; |
|
228 } |
|
229 |
|
230 CCAFadeControl* view = reinterpret_cast< CCAFadeControl* >( aAnyPtr ); |
|
231 |
|
232 if ( view->iColorIndex < KLafCount - 1 ) |
|
233 { |
|
234 view->iColorIndex++; |
|
235 view->ReportChange(); |
|
236 if ( view->iColorIndex == KDelayColorIndex ) |
|
237 { |
|
238 //Delayed color is displayed 4 seconds |
|
239 view->StartTicker( KIndicationDelay ); |
|
240 } |
|
241 return ETrue; |
|
242 } |
|
243 |
|
244 view->iColorIndex = 0; |
|
245 view->Stop(); |
|
246 TInt count( view->iObserverArray->Count() ); |
|
247 for ( TInt i( 0 ); i < count; ++i ) |
|
248 { |
|
249 MCAFadeTextObserver* obs = view->iObserverArray->At( i ); |
|
250 if ( obs ) |
|
251 { |
|
252 obs->NotifyWhenCompleted(); |
|
253 } |
|
254 } |
|
255 return EFalse; |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------- |
|
259 // CCAFadeControl::Start() |
|
260 // (other items were commented in a header). |
|
261 // --------------------------------------------------------- |
|
262 // |
|
263 void CCAFadeControl::Start() |
|
264 { |
|
265 TRect myNavePaneRect; |
|
266 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, |
|
267 myNavePaneRect ); |
|
268 myNavePaneRect.Move( -myNavePaneRect.iTl.iX, -myNavePaneRect.iTl.iY ); |
|
269 |
|
270 TAknWindowLineLayout navipanelayout = AknLayout::navi_pane( 0 ); |
|
271 AknLayoutUtils::LayoutControl( this, myNavePaneRect, navipanelayout ); |
|
272 |
|
273 iTimerTick = KTimerInterval; |
|
274 |
|
275 if ( !IsActivated() ) |
|
276 { |
|
277 TRAPD( err, ActivateL() ); |
|
278 if ( err != KErrNone ) |
|
279 { |
|
280 CActiveScheduler::Current()->Error( err ); |
|
281 } |
|
282 } |
|
283 |
|
284 if ( !IsVisible() ) |
|
285 { |
|
286 MakeVisible( ETrue ); |
|
287 } |
|
288 |
|
289 StartTicker( 0 ); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CCAFadeControl::StartTicker() |
|
294 // (other items were commented in a header). |
|
295 // --------------------------------------------------------- |
|
296 // |
|
297 void CCAFadeControl::StartTicker( |
|
298 const TTimeIntervalMicroSeconds32 aDelayInternal ) |
|
299 { |
|
300 if ( iTimerState == ETimerActivated ) |
|
301 { |
|
302 iTimer->Cancel(); |
|
303 iTimerState = ETimerStopped; |
|
304 } |
|
305 TCallBack cb( FadeText, this ); |
|
306 iTimer->Start( aDelayInternal, iTimerTick, cb ); |
|
307 iTimerState = ETimerActivated; |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------- |
|
311 // CCAFadeControl::Stop() |
|
312 // (other items were commented in a header). |
|
313 // --------------------------------------------------------- |
|
314 // |
|
315 void CCAFadeControl::Stop() |
|
316 { |
|
317 if ( IsVisible() ) |
|
318 { |
|
319 MakeVisible( EFalse ); |
|
320 } |
|
321 StopTicker(); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------- |
|
325 // CCAFadeControl::AddObserver() |
|
326 // (other items were commented in a header). |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 void CCAFadeControl::AddObserver( MCAFadeTextObserver* aObserver ) |
|
330 { |
|
331 TRAPD( err, iObserverArray->AppendL( aObserver ) ); |
|
332 HandleError( err ); |
|
333 } |
|
334 |
|
335 // --------------------------------------------------------- |
|
336 // CCAFadeControl::SetMessage() |
|
337 // (other items were commented in a header). |
|
338 // --------------------------------------------------------- |
|
339 // |
|
340 void CCAFadeControl::SetMessage( const TDesC& aMsg ) |
|
341 { |
|
342 HBufC* temp = NULL; |
|
343 TRAPD( err, temp = HBufC::NewL( aMsg.Length() + 1 ) ); |
|
344 HandleError( err ); |
|
345 if ( temp ) |
|
346 { |
|
347 delete iIMessage; |
|
348 iIMessage = temp; |
|
349 TPtr imMsgPtr( iIMessage->Des() ); |
|
350 imMsgPtr.Append( TChar( KAIMMessageIcon ) ); |
|
351 imMsgPtr.Append( aMsg ); |
|
352 |
|
353 UpdateClippedMessage(); |
|
354 } |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------- |
|
358 // CCAFadeControl::Message() |
|
359 // (other items were commented in a header). |
|
360 // --------------------------------------------------------- |
|
361 // |
|
362 TPtrC CCAFadeControl::Message() const |
|
363 { |
|
364 return *iIMessage; |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------- |
|
368 // CCAFadeControl::IsActive() |
|
369 // (other items were commented in a header). |
|
370 // --------------------------------------------------------- |
|
371 // |
|
372 TBool CCAFadeControl::IsActive() |
|
373 { |
|
374 if ( iTimer ) |
|
375 { |
|
376 return iTimer->IsActive(); |
|
377 } |
|
378 return EFalse; |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // CCAFadeControl::Reset() |
|
383 // (other items were commented in a header). |
|
384 // --------------------------------------------------------- |
|
385 // |
|
386 void CCAFadeControl::Reset() |
|
387 { |
|
388 if ( iIMessage ) |
|
389 { |
|
390 TPtr mesgPtr( iIMessage->Des() ); |
|
391 mesgPtr.Zero(); |
|
392 } |
|
393 |
|
394 if ( iClippedMessage ) |
|
395 { |
|
396 TPtr clipPtr( iClippedMessage->Des() ); |
|
397 clipPtr.Zero(); |
|
398 DrawNow(); |
|
399 } |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------- |
|
403 // CCAFadeControl::StopTicker() |
|
404 // (other items were commented in a header). |
|
405 // --------------------------------------------------------- |
|
406 // |
|
407 void CCAFadeControl::StopTicker() |
|
408 { |
|
409 if ( iTimerState == ETimerActivated ) |
|
410 { |
|
411 iTimer->Cancel(); |
|
412 iTimerState = ETimerStopped; |
|
413 } |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------- |
|
417 // CCAFadeControl::ReportChange() |
|
418 // (other items were commented in a header). |
|
419 // --------------------------------------------------------- |
|
420 // |
|
421 void CCAFadeControl::ReportChange() |
|
422 { |
|
423 TRAPD( err, ReportEventL( MCoeControlObserver::EEventStateChanged ) ); |
|
424 HandleError( err ); |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------- |
|
428 // CCAFadeControl::HandleError |
|
429 // (other items were commented in a header). |
|
430 // --------------------------------------------------------- |
|
431 // |
|
432 void CCAFadeControl::HandleError( TInt aError ) |
|
433 { |
|
434 CHAT_DP( D_CHAT_LIT( "CCAFadeControl::HandleError, aError = %d" ), aError ); |
|
435 if ( ( aError > Imps_ERROR_BASE ) && ( aError < KErrNone ) ) |
|
436 { |
|
437 // propagate system errors to current active scheduler, |
|
438 // it should show a note |
|
439 CActiveScheduler::Current()->Error( aError ); |
|
440 } |
|
441 |
|
442 // imps errors are ignored at the moment as we don't have any |
|
443 // notes specified for them |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------- |
|
447 // CCAFadeControl::UpdateClippedMessage |
|
448 // (other items were commented in a header). |
|
449 // --------------------------------------------------------- |
|
450 // |
|
451 void CCAFadeControl::UpdateClippedMessage() |
|
452 { |
|
453 HBufC* temp = NULL; |
|
454 TRAPD( err, temp = iIMessage->AllocL() ); |
|
455 if ( err ) |
|
456 { |
|
457 delete temp; |
|
458 HandleError( err ); |
|
459 } |
|
460 |
|
461 if ( temp ) |
|
462 { |
|
463 delete iClippedMessage; |
|
464 iClippedMessage = temp; |
|
465 TPtr clipPtr( iClippedMessage->Des() ); |
|
466 |
|
467 const CFont* font = iTextLayouts[iColorIndex].Font(); |
|
468 AknTextUtils::ClipToFit( clipPtr, *font, Rect().Width() ); |
|
469 } |
|
470 } |
|
471 |
|
472 // End of file |