|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Handles of drawing text on navi and title panes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <aknappui.h> |
|
20 #include <aknnavide.h> |
|
21 #include <aknnavi.h> |
|
22 #include <aknnavilabel.h> |
|
23 #include <akntitle.h> |
|
24 #include <AknUtils.h> |
|
25 #include <AknIconUtils.h> |
|
26 #include <avkon.rsg> |
|
27 #include <AknStatuspaneUtils.h> |
|
28 #include <aknlayoutscalable_avkon.cdl.h> |
|
29 #include <AknLayout2ScalableDef.h> |
|
30 #include <e32property.h> |
|
31 #include <avkondomainpskeys.h> |
|
32 #include <telinformationpskeys.h> |
|
33 #include <AknNaviDecoratorObserver.h> |
|
34 #include <AknTitlePaneObserver.h> |
|
35 #include "aistatuspanel.h" |
|
36 #include "debug.h" |
|
37 |
|
38 using namespace AiNativeUiController; |
|
39 |
|
40 // Read capability: ReadDeviceData. |
|
41 _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData ); |
|
42 // Write capability: WriteDeviceData. |
|
43 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData ); |
|
44 |
|
45 |
|
46 void CAiStatusPanel::ConstructL() |
|
47 { |
|
48 // Display info |
|
49 RProperty::Define( |
|
50 KPSUidTelInformation, |
|
51 KTelDisplayInfo, |
|
52 RProperty::EByteArray, |
|
53 KReadPolicy, |
|
54 KWritePolicy ); |
|
55 |
|
56 // RenderTitlePaneL() can be called without the bitmap set to valid handle |
|
57 iBitmapHandle = KErrNotFound; |
|
58 // Get pointer to status pane |
|
59 iStatusPane = static_cast<CAknAppUi*>( CEikonEnv::Static()-> |
|
60 EikAppUi() )->StatusPane(); |
|
61 |
|
62 // If status pane can't be initialized, let framework handle the problem |
|
63 if( !iStatusPane ) |
|
64 { |
|
65 User::Leave( KErrNotFound ); |
|
66 } |
|
67 |
|
68 //Get pointer to title pane |
|
69 iTitlePane = ( CAknTitlePane* )iStatusPane->ControlL( |
|
70 TUid::Uid( EEikStatusPaneUidTitle ) ); |
|
71 |
|
72 // If title pane can't be initialized, let framework handle the problem |
|
73 if( !iTitlePane ) |
|
74 { |
|
75 User::Leave( KErrNotFound ); |
|
76 } |
|
77 |
|
78 //Get pointer to navi pane |
|
79 iNaviPane = (CAknNavigationControlContainer *)iStatusPane-> |
|
80 ControlL(TUid::Uid(EEikStatusPaneUidNavi)); |
|
81 |
|
82 // If navi pane can't be initialized, let framework handle the problem |
|
83 if( !iNaviPane ) |
|
84 { |
|
85 User::Leave( KErrNotFound ); |
|
86 } |
|
87 |
|
88 // Construct navi pane |
|
89 //iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC() ); |
|
90 //iNaviPane->PushL( *iNaviDecorator ); |
|
91 |
|
92 #ifdef _DEBUG |
|
93 _LIT(titlepanetext, "Operator"); |
|
94 SetTitlePaneTextL(titlepanetext); |
|
95 #endif |
|
96 } |
|
97 |
|
98 |
|
99 CAiStatusPanel* CAiStatusPanel::NewL() |
|
100 { |
|
101 CAiStatusPanel* self = new( ELeave ) CAiStatusPanel; |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 CAiStatusPanel::~CAiStatusPanel() |
|
111 { |
|
112 delete iTitlePaneText; |
|
113 delete iNaviPaneText; |
|
114 delete iNaviDecorator; |
|
115 } |
|
116 |
|
117 |
|
118 CAiStatusPanel::CAiStatusPanel() |
|
119 { |
|
120 } |
|
121 |
|
122 |
|
123 void CAiStatusPanel::RenderTextOnNaviPaneL() |
|
124 { |
|
125 if( iNaviPaneText ) |
|
126 { |
|
127 if (!iNaviDecorator) |
|
128 { |
|
129 iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC() ); |
|
130 |
|
131 iNaviDecorator->SetNaviDecoratorObserver( iNaviDecoratorObserver ); |
|
132 |
|
133 iNaviPane->PushL( *iNaviDecorator ); |
|
134 } |
|
135 CAknNaviLabel* naviLabel = |
|
136 static_cast< CAknNaviLabel* >( iNaviDecorator->DecoratedControl() ); |
|
137 if( naviLabel ) |
|
138 { |
|
139 naviLabel->SetTextL( *iNaviPaneText ); |
|
140 iNaviDecorator->DrawDeferred(); |
|
141 } |
|
142 else |
|
143 { |
|
144 User::Leave( KErrNotFound ); |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
|
149 iNaviPane->Pop( iNaviDecorator ); |
|
150 delete iNaviDecorator; |
|
151 iNaviDecorator = NULL; |
|
152 } |
|
153 } |
|
154 |
|
155 void CAiStatusPanel::RenderTextOnTitlePaneL() |
|
156 { |
|
157 __PRINTS("XAI: Rendering text to title pane"); |
|
158 if( !iTitlePaneText ) |
|
159 { |
|
160 __PRINTS("XAI: Rendering text to title pane - invalid text, aborting"); |
|
161 return; |
|
162 } |
|
163 |
|
164 TTelTitleDisplay displayText; |
|
165 displayText.iLogoHandle = 0; |
|
166 displayText.iLogoMaskHandle = 0; |
|
167 TBool scroll = !IsKeyLockEnabled(); |
|
168 iTitlePane->SetText( iTitlePaneText, scroll ); |
|
169 displayText.iDisplayTag.Copy( |
|
170 iTitlePaneText->Left(displayText.iDisplayTag.MaxLength()) ); |
|
171 |
|
172 // SetText took ownership |
|
173 iTitlePaneText = NULL; |
|
174 |
|
175 UpdatePhoneDisplayInfo( displayText ); |
|
176 __PRINTS("XAI: Rendering text to title pane - done"); |
|
177 } |
|
178 |
|
179 |
|
180 void CAiStatusPanel::RenderBitmapOnTitlePaneL() |
|
181 { |
|
182 __PRINTS("XAI: Rendering bitmap to title pane"); |
|
183 if( iBitmapHandle == KErrNotFound ) |
|
184 { |
|
185 __PRINTS("XAI: Rendering bitmap to title pane - invalid bitmap handle, aborting"); |
|
186 return; |
|
187 } |
|
188 |
|
189 TSize size; |
|
190 TRect rect; |
|
191 TBool hasTitlePane = AknLayoutUtils::LayoutMetricsRect( |
|
192 AknLayoutUtils::ETitlePane, rect ); |
|
193 if ( !hasTitlePane ) |
|
194 { |
|
195 // no title pane, size is unknown. |
|
196 User::Leave( KErrNotReady ); |
|
197 } |
|
198 User::LeaveIfError( GetTitlePaneSize( size ) ); |
|
199 |
|
200 // CAknIcon takes ownership of bitmaps. |
|
201 CFbsBitmap* dupMain = new ( ELeave ) CFbsBitmap; |
|
202 CleanupStack::PushL( dupMain ); |
|
203 User::LeaveIfError( |
|
204 dupMain->Duplicate( iBitmapHandle ) ); |
|
205 |
|
206 CFbsBitmap* dupMask = NULL; |
|
207 if ( iMaskHandle != KErrNotFound ) |
|
208 { |
|
209 dupMask = new ( ELeave ) CFbsBitmap; |
|
210 CleanupStack::PushL( dupMask ); |
|
211 User::LeaveIfError( |
|
212 dupMask->Duplicate( iMaskHandle ) ); |
|
213 } |
|
214 |
|
215 //bitmapIcon is not pushed to cleanupstack, ownership |
|
216 //is transferred later |
|
217 CAknIcon* bitmapIcon = CAknIcon::NewL(); |
|
218 bitmapIcon->SetMask( dupMask ); // ownership transferred |
|
219 if ( iMaskHandle != KErrNotFound ) |
|
220 { |
|
221 CleanupStack::Pop( dupMask ); |
|
222 } |
|
223 |
|
224 bitmapIcon->SetBitmap( dupMain ); // ownership transferred |
|
225 CleanupStack::Pop( dupMain ); |
|
226 |
|
227 //ownership of bitmapIcon is transferred |
|
228 CAknIcon* scalableIcon = AknIconUtils::CreateIconL( bitmapIcon ); |
|
229 CleanupStack::PushL( scalableIcon ); |
|
230 |
|
231 AknIconUtils::SetSize( scalableIcon->Bitmap(), size, |
|
232 EAspectRatioPreservedAndUnusedSpaceRemoved ); |
|
233 AknIconUtils::SetSize( scalableIcon->Mask(), size, |
|
234 EAspectRatioPreservedAndUnusedSpaceRemoved ); |
|
235 |
|
236 // Title pane takes ownership of icons. |
|
237 CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap; |
|
238 CleanupStack::PushL( bitmap ); |
|
239 User::LeaveIfError( bitmap->Duplicate( scalableIcon->Bitmap()->Handle() ) ); |
|
240 |
|
241 // Check if icon has mask |
|
242 CFbsBitmap* bitmapMask = NULL; |
|
243 if ( scalableIcon->Mask() ) |
|
244 { |
|
245 bitmapMask = new ( ELeave ) CFbsBitmap; |
|
246 CleanupStack::PushL( bitmapMask ); |
|
247 User::LeaveIfError( |
|
248 bitmapMask->Duplicate( scalableIcon->Mask()->Handle() ) ); |
|
249 } |
|
250 |
|
251 // Set the icon in title pane... |
|
252 iTitlePane->SetPicture( bitmap, bitmapMask ); |
|
253 |
|
254 const TInt bitmapHandle = bitmap ? bitmap->Handle() : 0; |
|
255 const TInt bitmapMaskHandle = bitmapMask ? bitmapMask->Handle() : 0; |
|
256 |
|
257 // ... and inform TSY to use it |
|
258 TTelTitleDisplay displayText; |
|
259 displayText.iDisplayTag.Zero(); |
|
260 displayText.iLogoHandle = bitmapHandle; |
|
261 displayText.iLogoMaskHandle = bitmapMaskHandle; |
|
262 |
|
263 UpdatePhoneDisplayInfo( displayText ); |
|
264 |
|
265 if ( bitmapMask ) |
|
266 { |
|
267 CleanupStack::Pop( bitmapMask ); |
|
268 } |
|
269 CleanupStack::Pop( bitmap ); |
|
270 CleanupStack::PopAndDestroy( scalableIcon ); |
|
271 |
|
272 |
|
273 // Assume invalid bitmaps. Client needs to set the handles again |
|
274 // Otherwise invalid handles could be hold here and when drawing |
|
275 // undetermined stuff could occurr |
|
276 iBitmapHandle = KErrNotFound; |
|
277 iMaskHandle = KErrNotFound; |
|
278 __PRINTS("XAI: Rendering bitmap to title pane - done"); |
|
279 } |
|
280 |
|
281 TInt CAiStatusPanel::GetTitlePaneSize( TSize& aSize ) |
|
282 { |
|
283 TRect titlePaneRect; |
|
284 TBool hasTitlePane = AknLayoutUtils::LayoutMetricsRect( |
|
285 AknLayoutUtils::ETitlePane, titlePaneRect ); |
|
286 |
|
287 if ( !hasTitlePane ) |
|
288 { |
|
289 return KErrNotFound; |
|
290 } |
|
291 |
|
292 TAknLayoutRect oplogoLayout; |
|
293 |
|
294 if ( AknStatuspaneUtils::StaconPaneActive() ) |
|
295 { |
|
296 // stacon |
|
297 oplogoLayout.LayoutRect( titlePaneRect, |
|
298 AknLayoutScalable_Avkon::title_pane_stacon_g2(0).LayoutLine() ); |
|
299 } |
|
300 else if ( AknStatuspaneUtils::FlatLayoutActive() ) |
|
301 { |
|
302 // flat |
|
303 oplogoLayout.LayoutRect( titlePaneRect, |
|
304 AknLayoutScalable_Avkon::title_pane_stacon_g2(0).LayoutLine() ); |
|
305 } |
|
306 else |
|
307 { |
|
308 // usual idle |
|
309 oplogoLayout.LayoutRect( titlePaneRect, |
|
310 AknLayout::Title_pane_elements_Line_1() ); |
|
311 } |
|
312 |
|
313 aSize = oplogoLayout.Rect().Size(); |
|
314 |
|
315 return KErrNone; |
|
316 } |
|
317 |
|
318 |
|
319 void CAiStatusPanel::UpdatePhoneDisplayInfo( const TTelTitleDisplay& aDisplayInfo ) |
|
320 { |
|
321 TBool changed = EFalse; |
|
322 TBool indicatorChanged = |
|
323 aDisplayInfo.iDisplayTag != iDisplayInfo.iDisplayTag || |
|
324 aDisplayInfo.iLogoHandle != iDisplayInfo.iLogoHandle || |
|
325 aDisplayInfo.iLogoMaskHandle != iDisplayInfo.iLogoMaskHandle; |
|
326 |
|
327 if ( indicatorChanged ) |
|
328 { |
|
329 changed = ETrue; |
|
330 iDisplayInfo.iDisplayTag = aDisplayInfo.iDisplayTag; |
|
331 iDisplayInfo.iLogoHandle = aDisplayInfo.iLogoHandle; |
|
332 iDisplayInfo.iLogoMaskHandle = aDisplayInfo.iLogoMaskHandle; |
|
333 } |
|
334 |
|
335 if ( changed ) |
|
336 { |
|
337 TTelTitleDisplay::TDisplayInfoPckg pckg( iDisplayInfo ); |
|
338 RProperty::Set( |
|
339 KPSUidTelInformation, |
|
340 KTelDisplayInfo, |
|
341 pckg ); |
|
342 } |
|
343 } |
|
344 |
|
345 |
|
346 void CAiStatusPanel::SetNaviPaneTextL( const TDesC& aText ) |
|
347 { |
|
348 delete iNaviPaneText; |
|
349 iNaviPaneText = NULL; |
|
350 if ( !AknStatuspaneUtils::FlatLayoutActive() ) |
|
351 { |
|
352 HBufC* temp = aText.AllocL(); |
|
353 iNaviPaneText = temp; |
|
354 } |
|
355 } |
|
356 |
|
357 |
|
358 |
|
359 void CAiStatusPanel::SetTitlePaneTextL( const TDesC& aText ) |
|
360 { |
|
361 HBufC* temp = aText.AllocL(); |
|
362 delete iTitlePaneText; |
|
363 iTitlePaneText = temp; |
|
364 } |
|
365 |
|
366 |
|
367 void CAiStatusPanel::SetTitlePaneBitmapL( TInt aBitmapHandle, TInt aMaskHandle ) |
|
368 { |
|
369 iBitmapHandle = aBitmapHandle; |
|
370 iMaskHandle = aMaskHandle; |
|
371 } |
|
372 |
|
373 |
|
374 void CAiStatusPanel::RenderTitlePaneL() |
|
375 { |
|
376 RenderTextOnTitlePaneL(); |
|
377 RenderBitmapOnTitlePaneL(); |
|
378 } |
|
379 |
|
380 |
|
381 void CAiStatusPanel::RenderNaviPaneL() |
|
382 { |
|
383 RenderTextOnNaviPaneL(); |
|
384 } |
|
385 |
|
386 void CAiStatusPanel::StopTitlePaneScrollingL() |
|
387 { |
|
388 //stop scrolling |
|
389 if( iTitlePane->Text() ) |
|
390 { |
|
391 iTitlePane->SetTextL( *iTitlePane->Text(), EFalse ); |
|
392 } |
|
393 } |
|
394 |
|
395 void CAiStatusPanel::ScrollTitlePaneTextL() |
|
396 { |
|
397 // start scrolling |
|
398 if( iTitlePane->Text() ) |
|
399 { |
|
400 iTitlePane->SetTextL( *iTitlePane->Text(), ETrue ); |
|
401 } |
|
402 } |
|
403 |
|
404 void CAiStatusPanel::SetNaviDecoratorObserver( MAknNaviDecoratorObserver* aObserver ) |
|
405 { |
|
406 iNaviDecoratorObserver = aObserver; |
|
407 } |
|
408 |
|
409 void CAiStatusPanel::SetTitlePaneObserver( MAknTitlePaneObserver* aObserver ) |
|
410 { |
|
411 iTitlePane->SetTitlePaneObserver( aObserver ); |
|
412 } |
|
413 |
|
414 TBool CAiStatusPanel::IsKeyLockEnabled() |
|
415 { |
|
416 TInt value; |
|
417 TInt err = RProperty::Get(KPSUidAvkonDomain, KAknKeyguardStatus, value); |
|
418 if ( err != KErrNone ) |
|
419 return EFalse; |
|
420 switch( value ) |
|
421 { |
|
422 case EKeyguardLocked: |
|
423 case EKeyguardAutolockEmulation: |
|
424 return ETrue; |
|
425 case EKeyguardNotActive: |
|
426 default: |
|
427 return EFalse; |
|
428 } |
|
429 } |
|
430 |