|
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: application container control. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "AboutContainer.h" |
|
22 #include "AboutImage.h" |
|
23 #include "about.hrh" |
|
24 #include "about_test.hrh" |
|
25 #include <layoutmetadata.cdl.h> |
|
26 #include <about.rsg> |
|
27 #include <eiksbfrm.h> |
|
28 #include <eikscrlb.h> |
|
29 #include <eikrted.h> |
|
30 #include <txtrich.h> |
|
31 #include <barsread.h> |
|
32 #include <eikenv.h> |
|
33 #include <aknenv.h> |
|
34 #include <AknUtils.h> |
|
35 #include <aknconsts.h> |
|
36 #include <txtfrmat.h> |
|
37 #include <AknBidiTextUtils.h> |
|
38 #include <data_caging_path_literals.hrh> |
|
39 #include <f32file.h> |
|
40 #include <aknlayoutscalable_apps.cdl.h> |
|
41 #include <aknappui.h> |
|
42 #include <AknsDrawUtils.h> |
|
43 #include <AknsBasicBackgroundControlContext.h> |
|
44 #include <AknsConstants.h> |
|
45 #include <AknDef.h> |
|
46 #include <about.mbg> |
|
47 #include <StringLoader.h> |
|
48 |
|
49 // CONSTANTS |
|
50 |
|
51 _LIT( KAboutPanicCategory, "About" ); |
|
52 |
|
53 enum TAboutPanic |
|
54 { |
|
55 EAboutNotSupported = 0 |
|
56 }; |
|
57 |
|
58 /** |
|
59 * SCROLLING: |
|
60 * |
|
61 * Scrolling is implemented according to the following rules |
|
62 * when scrolling down: |
|
63 * |
|
64 * (same screens are shown again when scrolling up) |
|
65 * |
|
66 * - If the last line in previous screen was a text line, |
|
67 * next screen is started with that line, ie. the last |
|
68 * line is shown again in the next screen. |
|
69 * |
|
70 * - If previous screen ended with an image that did not |
|
71 * fully fit, next screen is started with that image so |
|
72 * that it can be seen as a whole. |
|
73 * |
|
74 * - If previous screen ended with an image that fit there fully, |
|
75 * next screen is started with next text line or image. |
|
76 */ |
|
77 |
|
78 // constructors |
|
79 |
|
80 CAboutContainer::CAboutContainer():iNumItem( 0 ) |
|
81 { |
|
82 } |
|
83 |
|
84 void CAboutContainer::ConstructL( const TRect& aRect ) |
|
85 { |
|
86 CreateWindowL(); |
|
87 |
|
88 iScrollBarDragged = EFalse; |
|
89 iBreakFlag = EFalse; |
|
90 iIsSvg = EFalse; |
|
91 iSkinContext = NULL; |
|
92 iText = NULL; |
|
93 iImages = NULL; |
|
94 iScreenStarts = NULL; |
|
95 iSBFrame = NULL; |
|
96 CalculateL(aRect); |
|
97 ActivateL(); |
|
98 } |
|
99 |
|
100 // destructor |
|
101 |
|
102 CAboutContainer::~CAboutContainer() |
|
103 { |
|
104 delete iSkinContext; |
|
105 delete iSBFrame; |
|
106 delete iScreenStarts; |
|
107 delete iIcon; |
|
108 |
|
109 if ( iText ) |
|
110 { |
|
111 iText->ResetAndDestroy(); |
|
112 delete iText; |
|
113 } |
|
114 |
|
115 if ( iImages ) |
|
116 { |
|
117 iImages->ResetAndDestroy(); |
|
118 delete iImages; |
|
119 } |
|
120 } |
|
121 |
|
122 void CAboutContainer::SizeChanged() |
|
123 { |
|
124 TRect parentRect(Rect()); |
|
125 if (iSkinContext) |
|
126 { |
|
127 iSkinContext->SetRect(parentRect); |
|
128 } |
|
129 } |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CAboutContainer::Draw() |
|
132 // ----------------------------------------------------------------------------- |
|
133 |
|
134 void CAboutContainer::Draw( const TRect& aRect ) const |
|
135 { |
|
136 CWindowGc& gc = SystemGc(); |
|
137 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
138 if (iSkinContext) |
|
139 {//Draw the skin background |
|
140 AknsDrawUtils::Background( |
|
141 skin, iSkinContext, this, gc, aRect); |
|
142 } |
|
143 else |
|
144 {// clear the area |
|
145 gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) ); |
|
146 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
147 gc.Clear( aRect ); |
|
148 } |
|
149 |
|
150 // draw text |
|
151 gc.UseFont( iFont ); |
|
152 // index of the first line on the screen in the text array |
|
153 TInt firstLine = 0 ; |
|
154 |
|
155 // The value of firstLine can not be the same. |
|
156 if ( !iScrollBarDragged ) |
|
157 { |
|
158 if ( ( iScreenStarts ) && (iScreenStarts->Count() >= iCurrentScreen ) ) |
|
159 { |
|
160 firstLine = ( ( *iScreenStarts )[ iCurrentScreen ] ); |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 if ( iCurrentScreen <= ( ( *iScreenStarts )[ iScreenStarts->Count() - 1 ] ) ) |
|
166 { |
|
167 firstLine = iCurrentScreen ; |
|
168 } |
|
169 } |
|
170 // index of the last line on the screen in the text array |
|
171 TInt lastLine( firstLine + iLinesPerScreen - 1 ); |
|
172 |
|
173 gc.SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
174 TPoint position( iTopBaseLineX, iTopBaseLineY ); |
|
175 TPoint topLeft; |
|
176 TSize rectSize( iLineWidth, iBaseLineDelta +iFont->DescentInPixels() ); |
|
177 |
|
178 for ( TInt index = firstLine ; |
|
179 index < iText->Count() && index <= lastLine ; |
|
180 index++, position.iY += iBaseLineDelta ) |
|
181 { |
|
182 HBufC* text = (*iText)[ index ]; |
|
183 |
|
184 if ( text ) |
|
185 { |
|
186 topLeft = TPoint( position.iX, position.iY-iBaseLineDelta ); |
|
187 TRgb color; |
|
188 TInt error = AknsUtils::GetCachedColor( skin, |
|
189 color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 ); |
|
190 |
|
191 if(error == KErrNone) |
|
192 { |
|
193 gc.SetPenColor(color); |
|
194 } |
|
195 gc.DrawText( *text, |
|
196 TRect( topLeft, rectSize ), |
|
197 iBaseLineDelta, |
|
198 iTextAlign ); |
|
199 } |
|
200 } |
|
201 |
|
202 gc.DiscardFont(); |
|
203 |
|
204 // draw images |
|
205 |
|
206 for ( TInt i = 0 ; i < iImages->Count() ; i++ ) |
|
207 { |
|
208 CAboutImage* image = (*iImages)[ i ]; |
|
209 |
|
210 // If part of the image resides in visible lines, draw it. |
|
211 if ( image->StartLine() <= lastLine && image->EndLine() >= firstLine ) |
|
212 { |
|
213 position.SetXY( iTopBaseLineX, iTopBaseLineY ); |
|
214 position.iY += ( image->StartLine() - firstLine ) * iBaseLineDelta; |
|
215 |
|
216 position.iY -= iBaseLineDelta - iFont->DescentInPixels(); |
|
217 // Now iY is the top line of rectangle where the picture is |
|
218 // centered in. |
|
219 position.iY += ( (image->Lines()+1) * iBaseLineDelta - |
|
220 iFont->HeightInPixels() - |
|
221 image->HeightInPixels() ) / 2; |
|
222 |
|
223 // If text is right-aligned, also align images to the right. |
|
224 |
|
225 if ( iTextAlign == CGraphicsContext::ERight ) |
|
226 { |
|
227 position.iX += ( iLineWidth - image->WidthInPixels() ); |
|
228 } |
|
229 |
|
230 gc.BitBlt( position, image->Bitmap(), aRect ); |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CAboutContainer::ActivateL() |
|
237 // ----------------------------------------------------------------------------- |
|
238 |
|
239 void CAboutContainer::ActivateL() |
|
240 { |
|
241 CCoeControl::ActivateL(); |
|
242 UpdateScrollIndicatorL(); |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CAboutContainer::SetTextL() |
|
247 // ----------------------------------------------------------------------------- |
|
248 |
|
249 void CAboutContainer::SetTextL( const TDesC& aText , const TInt aItem ) |
|
250 { |
|
251 CArrayFix<TPtrC>* wrappedArray = |
|
252 new( ELeave ) CArrayFixFlat<TPtrC>( 10 ); |
|
253 |
|
254 CleanupStack::PushL( wrappedArray ); |
|
255 |
|
256 HBufC* dataToDestroy = |
|
257 AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( |
|
258 aText, iLineWidth, *iFont, *wrappedArray |
|
259 ); |
|
260 |
|
261 TInt numLines( wrappedArray->Count() ); |
|
262 for ( TInt i = 0 ; i < numLines ; i++ ) |
|
263 { |
|
264 HBufC* line = (*wrappedArray)[i].AllocLC(); |
|
265 |
|
266 switch( aItem ) |
|
267 { |
|
268 // The fourteen string's setting |
|
269 case 14: |
|
270 { |
|
271 iBreakFlag = ETrue; |
|
272 break; |
|
273 } |
|
274 default: |
|
275 break; |
|
276 } |
|
277 if(!line->Length()) |
|
278 { |
|
279 iText->AppendL( NULL ); |
|
280 |
|
281 CleanupStack::PopAndDestroy(line); // line |
|
282 } |
|
283 else |
|
284 { |
|
285 if( iBreakFlag && ( numLines - 1 ) == i ) |
|
286 { |
|
287 iText->AppendL( line ); |
|
288 // Get the text's lines' count for set break |
|
289 TInt textCount = iText->Count(); |
|
290 TInt count = iLinesPerScreen - ( textCount % ( iLinesPerScreen - 1 ) ) - 1; |
|
291 if( iLinesPerScreen == count + 1 ) |
|
292 { |
|
293 // When the last line has content, we should set count zero |
|
294 count = 0; |
|
295 } |
|
296 for( TInt j = 0; j < count; j++ ) |
|
297 { |
|
298 iText->AppendL( NULL ); |
|
299 } |
|
300 CleanupStack::Pop( line ); // line |
|
301 iBreakFlag = EFalse; |
|
302 } |
|
303 else |
|
304 { |
|
305 iText->AppendL( line ); |
|
306 CleanupStack::Pop( line ); // line |
|
307 } |
|
308 } |
|
309 } |
|
310 iText->AppendL( NULL ); |
|
311 |
|
312 // If the last char was newline, add one extra, since |
|
313 // wrapping automatically removes it. |
|
314 if ( aText[ aText.Length() - 1 ] == '\n' ) |
|
315 { |
|
316 iText->AppendL( NULL ); |
|
317 } |
|
318 |
|
319 CleanupStack::PopAndDestroy(wrappedArray); // wrappedArray |
|
320 delete dataToDestroy; |
|
321 |
|
322 // update screen scrolling info array |
|
323 |
|
324 TInt lastLine( iText->Count() - 1 ); |
|
325 TInt screenStart( (*iScreenStarts)[ iScreenStarts->Count() - 1 ] ); |
|
326 |
|
327 TBool firstNewScreenHandled( EFalse ); |
|
328 |
|
329 while ( lastLine >= screenStart + iLinesPerScreen ) |
|
330 { |
|
331 if ( !firstNewScreenHandled && iDoNotShowLastLineAgain ) |
|
332 { |
|
333 screenStart++; |
|
334 firstNewScreenHandled = ETrue; |
|
335 } |
|
336 |
|
337 screenStart += iLinesPerScreen - 1; |
|
338 iScreenStarts->AppendL( screenStart ); |
|
339 if ( ( lastLine == screenStart + 1 ) && ( aItem == iNumItem - 1 ) ) |
|
340 { |
|
341 iScreenStarts->Delete( iScreenStarts->Count() - 1 ); |
|
342 } |
|
343 } |
|
344 |
|
345 // if text, last line is shown again in next screen |
|
346 iDoNotShowLastLineAgain = EFalse; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CAboutContainer::SetImageL() |
|
351 // ----------------------------------------------------------------------------- |
|
352 |
|
353 void CAboutContainer::SetImageL( const TDesC& aFileName, TInt aBitmapId ) |
|
354 { |
|
355 TInt firstLineOfImage( iText->Count() ); |
|
356 |
|
357 // If flag is ETrue, the file type is bmp |
|
358 CAboutImage* image = |
|
359 CAboutImage::NewLC( aFileName, aBitmapId, firstLineOfImage, iBaseLineDelta, ETrue ); |
|
360 |
|
361 // new lines to make room for the picture |
|
362 |
|
363 for ( TInt i = 0 ; i < image->Lines() ; i++ ) |
|
364 { |
|
365 iText->AppendL( NULL ); |
|
366 } |
|
367 |
|
368 iImages->AppendL( image ); |
|
369 CleanupStack::Pop(image); // image |
|
370 |
|
371 // update screen scrolling info array |
|
372 |
|
373 TInt lastLineOfImage( iText->Count() - 1 ); |
|
374 TInt screenStart( (*iScreenStarts)[ iScreenStarts->Count() - 1 ] ); |
|
375 |
|
376 TBool firstNewScreenHandled( EFalse ); |
|
377 |
|
378 // If the image was not fully shown in the first screen, |
|
379 // start the next screen with the image. |
|
380 |
|
381 if ( firstLineOfImage < screenStart + iLinesPerScreen && |
|
382 lastLineOfImage >= screenStart + iLinesPerScreen ) |
|
383 { |
|
384 screenStart = firstLineOfImage; |
|
385 iScreenStarts->AppendL( screenStart ); |
|
386 firstNewScreenHandled = ETrue; |
|
387 } |
|
388 |
|
389 while ( lastLineOfImage >= screenStart + iLinesPerScreen ) |
|
390 { |
|
391 if ( !firstNewScreenHandled && iDoNotShowLastLineAgain ) |
|
392 { |
|
393 screenStart++; |
|
394 firstNewScreenHandled = ETrue; |
|
395 } |
|
396 |
|
397 screenStart += iLinesPerScreen - 1; |
|
398 iScreenStarts->AppendL( screenStart ); |
|
399 } |
|
400 |
|
401 if ( lastLineOfImage == screenStart + iLinesPerScreen - 1 ) |
|
402 { |
|
403 iDoNotShowLastLineAgain = ETrue; |
|
404 } |
|
405 else |
|
406 { |
|
407 iDoNotShowLastLineAgain = EFalse; |
|
408 } |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // CAboutContainer::OfferKeyEventL() |
|
413 // ----------------------------------------------------------------------------- |
|
414 |
|
415 TKeyResponse CAboutContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
416 TEventCode aType ) |
|
417 { |
|
418 // Operation is different in dragging and thumbing. |
|
419 if ( ( iScrollBarDragged ) && ( aType == EEventKey ) ) |
|
420 { |
|
421 for( TInt i=0; i<iScreenStarts->Count(); i++ ) |
|
422 { |
|
423 if ( iCurrentScreen <= ( ( *iScreenStarts )[i] ) ) |
|
424 { |
|
425 // if last state is dragging, value of iCurrentScreen should be adjusted. |
|
426 switch ( aKeyEvent.iCode ) |
|
427 { |
|
428 case EKeyUpArrow: |
|
429 { |
|
430 iScrollBarDragged = EFalse; |
|
431 // Do nothing if the scroll bar is on the top, when pressing arrow up. |
|
432 if ( i != 0 ) |
|
433 { |
|
434 iCurrentScreen = ( i - 1 ); |
|
435 } |
|
436 DrawNow(); |
|
437 UpdateScrollIndicatorL(); |
|
438 break; |
|
439 } |
|
440 case EKeyDownArrow: |
|
441 { |
|
442 iScrollBarDragged = EFalse; |
|
443 if ( ( iCurrentScreen == ( *iScreenStarts )[i] ) |
|
444 // Do nothing if the scroll bar is on the bottom, when pressing arrow down. |
|
445 && ( i != ( iScreenStarts->Count() - 1 ) ) ) |
|
446 { |
|
447 iCurrentScreen = ( i + 1 ); |
|
448 } |
|
449 else |
|
450 { |
|
451 iCurrentScreen = i; |
|
452 } |
|
453 DrawNow(); |
|
454 UpdateScrollIndicatorL(); |
|
455 break; |
|
456 } |
|
457 default: |
|
458 break; |
|
459 } |
|
460 return EKeyWasConsumed; |
|
461 } |
|
462 } |
|
463 } |
|
464 |
|
465 if ( aType == EEventKey && iScreenStarts->Count() > 1 ) |
|
466 { |
|
467 switch ( aKeyEvent.iCode ) |
|
468 { |
|
469 case EKeyUpArrow: |
|
470 { |
|
471 if ( iCurrentScreen > 0 ) |
|
472 { |
|
473 iCurrentScreen--; |
|
474 DrawNow(); |
|
475 UpdateScrollIndicatorL(); |
|
476 } |
|
477 } |
|
478 break; |
|
479 |
|
480 case EKeyDownArrow: |
|
481 { |
|
482 if ( iCurrentScreen < iScreenStarts->Count() - 1 ) |
|
483 { |
|
484 iCurrentScreen++; |
|
485 DrawNow(); |
|
486 UpdateScrollIndicatorL(); |
|
487 } |
|
488 } |
|
489 break; |
|
490 |
|
491 default: |
|
492 break; |
|
493 } |
|
494 return EKeyWasConsumed; |
|
495 } |
|
496 |
|
497 // When pressing the Send Key and the event's type is not EEvenKey return EKeyWasNotConsumed |
|
498 return EKeyWasNotConsumed; |
|
499 } |
|
500 |
|
501 // ----------------------------------------------------------------------------- |
|
502 // CAboutContainer::UpdateScrollIndicatorL() |
|
503 // ----------------------------------------------------------------------------- |
|
504 |
|
505 void CAboutContainer::UpdateScrollIndicatorL() |
|
506 { |
|
507 if ( iScreenStarts->Count() <= 1 ) |
|
508 { |
|
509 return; |
|
510 } |
|
511 |
|
512 if ( !iSBFrame ) |
|
513 { |
|
514 iSBFrame = new( ELeave ) CEikScrollBarFrame( this,this, ETrue ); |
|
515 |
|
516 // Decide which type of scrollbar is to be shown |
|
517 CAknAppUi* appUi = iAvkonAppUi; |
|
518 if (AknLayoutUtils::DefaultScrollBarType(appUi) == CEikScrollBarFrame::EDoubleSpan) |
|
519 { |
|
520 // For EDoubleSpan type scrollbar |
|
521 iSBFrame->CreateDoubleSpanScrollBarsL(ETrue, EFalse); // non-window owning scrollbar |
|
522 iSBFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan); |
|
523 } |
|
524 else |
|
525 { |
|
526 // For EArrowHead type scrollbar |
|
527 iSBFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EArrowHead); |
|
528 } |
|
529 iSBFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
530 } |
|
531 |
|
532 TEikScrollBarModel hSbarModel; |
|
533 TEikScrollBarModel vSbarModel; |
|
534 |
|
535 // The member of vSbarModel shoul be changed because the state when dragging scroll bar shoul be considered. |
|
536 TInt spanAdjust = iLinesPerScreen - ( iText->Count() - ( *iScreenStarts )[ iScreenStarts->Count() - 1 ] + 1 ); |
|
537 if ( iScrollBarDragged ) |
|
538 { |
|
539 vSbarModel.iThumbPosition = iCurrentScreen; |
|
540 } |
|
541 else |
|
542 { |
|
543 vSbarModel.iThumbPosition = iCurrentScreen * ( iLinesPerScreen - 1 ); |
|
544 } |
|
545 vSbarModel.iScrollSpan = iText->Count() + spanAdjust; |
|
546 vSbarModel.iThumbSpan = ( iLinesPerScreen - 1 ); |
|
547 |
|
548 TRect rect(Rect()); |
|
549 TEikScrollBarFrameLayout layout; |
|
550 layout.iTilingMode = TEikScrollBarFrameLayout::EInclusiveRectConstant; |
|
551 |
|
552 if (iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan) |
|
553 { |
|
554 // For EDoubleSpan type scrollbar |
|
555 if (vSbarModel.iThumbPosition + vSbarModel.iThumbSpan > vSbarModel.iScrollSpan) |
|
556 { |
|
557 // Not let scrollbar values overflow |
|
558 vSbarModel.iThumbPosition = vSbarModel.iScrollSpan - vSbarModel.iThumbSpan; |
|
559 } |
|
560 |
|
561 TAknDoubleSpanScrollBarModel hDsSbarModel(hSbarModel); |
|
562 TAknDoubleSpanScrollBarModel vDsSbarModel(vSbarModel); |
|
563 |
|
564 // When resolution is changed, changing the drawing area of layout for the text. |
|
565 TRect currentRect( iAvkonAppUi->ClientRect() ); |
|
566 iSBFrame->TileL(&hDsSbarModel, &vDsSbarModel, currentRect, rect, layout); |
|
567 iSBFrame->SetVFocusPosToThumbPos(vDsSbarModel.FocusPosition()); |
|
568 } |
|
569 else |
|
570 { |
|
571 iSBFrame->TileL( &hSbarModel, &vSbarModel, rect, rect, layout ); |
|
572 iSBFrame->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition ); |
|
573 } |
|
574 } |
|
575 |
|
576 |
|
577 // End of File |
|
578 |
|
579 void CAboutContainer::CalculateL(const TRect& aRect) |
|
580 { |
|
581 TRect rect( 0, 0, 0, 0 ); |
|
582 iCurrentScreen = 0; |
|
583 |
|
584 if ( iSkinContext ) |
|
585 { |
|
586 delete iSkinContext; |
|
587 iSkinContext = NULL; |
|
588 } |
|
589 |
|
590 // Temporary rect is passed. Correct rect is set in SizeChanged. |
|
591 iSkinContext = CAknsBasicBackgroundControlContext::NewL( |
|
592 KAknsIIDQsnBgAreaMain , rect, EFalse ); |
|
593 |
|
594 iFont = AknLayoutUtils::FontFromId( EAknLogicalFontSecondaryFont ); |
|
595 |
|
596 // Calculate various text positioning parameters |
|
597 iBaseLineDelta = iFont->HeightInPixels() * 4 / 3; |
|
598 |
|
599 TInt mainPaneWidth( aRect.iBr.iX - aRect.iTl.iX ); |
|
600 TInt mainPaneHeight( aRect.iBr.iY - aRect.iTl.iY ); |
|
601 // Line width is 87% of client rect, horizontal margins 13% |
|
602 iLineWidth = mainPaneWidth * 87 / 100; |
|
603 iTopBaseLineX = ( mainPaneWidth - iLineWidth ) / 2; |
|
604 |
|
605 // top margin is 6.5% of the client rect |
|
606 TInt topMargin = mainPaneHeight * 65 / 1000; |
|
607 iTopBaseLineY = topMargin + iFont->AscentInPixels(); |
|
608 |
|
609 // minimum bottom margin is 3% of the client rect |
|
610 TInt bottomMargin = mainPaneHeight * 3 / 100; |
|
611 iLinesPerScreen = |
|
612 ( mainPaneHeight - topMargin - bottomMargin ) / iBaseLineDelta; |
|
613 |
|
614 TInt uiLanguage = User::Language(); |
|
615 |
|
616 if( uiLanguage == ELangArabic || uiLanguage == ELangFarsi || |
|
617 uiLanguage == ELangHebrew || uiLanguage == ELangUrdu ) |
|
618 { |
|
619 iTextAlign = CGraphicsContext::ERight; |
|
620 } |
|
621 else |
|
622 { |
|
623 iTextAlign = CGraphicsContext::ELeft; |
|
624 } |
|
625 |
|
626 |
|
627 if ( iText ) |
|
628 { |
|
629 iText->ResetAndDestroy(); |
|
630 delete iText; |
|
631 iText = NULL; |
|
632 } |
|
633 |
|
634 // Every text line on screen is one entry in this array |
|
635 iText = new( ELeave ) CArrayPtrFlat<HBufC>( 20 ); |
|
636 |
|
637 if ( iImages ) |
|
638 { |
|
639 iImages->ResetAndDestroy(); |
|
640 delete iImages; |
|
641 iImages = NULL; |
|
642 } |
|
643 |
|
644 // Every image on screen is one entry in this array |
|
645 iImages = new( ELeave ) CArrayPtrFlat<CAboutImage>( 1 ); |
|
646 |
|
647 if ( iScreenStarts ) |
|
648 { |
|
649 delete iScreenStarts; |
|
650 iScreenStarts = NULL; |
|
651 } |
|
652 // This array contains indices for lines that start the subsequent |
|
653 // screens, for custom scrolling |
|
654 iScreenStarts = new( ELeave ) CArrayFixFlat<TInt>( 5 ); |
|
655 // Initialisation: first screen starts at line 0. |
|
656 iScreenStarts->AppendL( 0 ); |
|
657 |
|
658 // Read text and image items to be shown on the screen from a resource file. |
|
659 #ifdef __ABOUT_USE_TEST_RESOURCE__ |
|
660 #include <about_test.rsg> |
|
661 // test resource |
|
662 _LIT(KDirAndFile, "Z:about_test.rsc"); |
|
663 TParse* fp = new(ELeave) TParse (); |
|
664 fp->Set (KDirAndFile, &KDC_APP_RESOURCE_DIR, NULL); |
|
665 TBuf<254> KAboutTestResourceFileName; |
|
666 KAboutTestResourceFileName.Copy(fp ->FullName()); |
|
667 delete fp; |
|
668 fp=NULL; |
|
669 |
|
670 TFileName fileName( KAboutTestResourceFileName ); |
|
671 BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), filename ); |
|
672 TInt testResourceFileOffset = iCoeEnv->AddResourceFileL( fileName ); |
|
673 TResourceReader reader; |
|
674 iEikonEnv->CreateResourceReaderLC( reader, R_ABOUT_TEST_MAIN_TEXT ); |
|
675 #else |
|
676 // real resource |
|
677 TResourceReader reader; |
|
678 iEikonEnv->CreateResourceReaderLC( reader, R_ABOUT_MAIN_TEXT ); |
|
679 #endif |
|
680 |
|
681 TInt NumItem( reader.ReadInt16() ); |
|
682 iNumItem = NumItem; |
|
683 |
|
684 for ( TInt i = 0 ; i < iNumItem ; i++ ) |
|
685 { |
|
686 TInt type = reader.ReadInt8(); |
|
687 if ( type == EAboutTextItem ) |
|
688 { |
|
689 HBufC* text; |
|
690 if ( reader.ReadInt8() == EAboutUpdateTime ) |
|
691 { |
|
692 TTime time; |
|
693 time.UniversalTime(); |
|
694 TDateTime currentTime = time.DateTime(); |
|
695 text = StringLoader::LoadLC( reader.ReadInt32(), |
|
696 currentTime.Year(), CEikonEnv::Static() ); |
|
697 } |
|
698 else |
|
699 { |
|
700 text = iEikonEnv->AllocReadResourceLC( reader.ReadInt32() ); |
|
701 } |
|
702 SetTextL( *text , i ); |
|
703 CleanupStack::PopAndDestroy( text ); |
|
704 } |
|
705 else if ( type == EAboutImageItem ) |
|
706 { |
|
707 TPtrC bitmapFile = reader.ReadTPtrC(); |
|
708 TInt bitmapId = reader.ReadInt16(); |
|
709 if( iIsSvg ) |
|
710 { |
|
711 TFileName svgPath; |
|
712 _LIT( KSvgFileName, "Z:about.mif" ); |
|
713 TParse* fpSvg = new( ELeave ) TParse (); |
|
714 fpSvg->Set( KSvgFileName, &KDC_APP_BITMAP_DIR, NULL ); |
|
715 svgPath.Copy( fpSvg ->FullName() ); |
|
716 delete fpSvg; |
|
717 fpSvg = NULL; |
|
718 SetImageL( svgPath, EMbmAboutQgn_graf_java_logo ); |
|
719 } |
|
720 else |
|
721 { |
|
722 SetImageL( bitmapFile, bitmapId ); |
|
723 } |
|
724 } |
|
725 else |
|
726 { |
|
727 User::Panic( KAboutPanicCategory, EAboutNotSupported ); |
|
728 } |
|
729 } |
|
730 |
|
731 CleanupStack::PopAndDestroy(); // reader |
|
732 |
|
733 #ifdef __ABOUT_USE_TEST_RESOURCE__ |
|
734 if ( testResourceFileOffset ) |
|
735 { |
|
736 iCoeEnv->DeleteResourceFile( testResourceFileOffset ); |
|
737 } |
|
738 #endif |
|
739 |
|
740 SetRect( aRect ); |
|
741 UpdateScrollIndicatorL(); |
|
742 } |
|
743 |
|
744 |
|
745 void CAboutContainer::HandleResourceChange(TInt aType) |
|
746 { |
|
747 |
|
748 switch ( aType ) |
|
749 { |
|
750 case KEikDynamicLayoutVariantSwitch : |
|
751 { |
|
752 TRAP_IGNORE(CalculateL(iAvkonAppUi->ClientRect())); |
|
753 DrawNow(); |
|
754 } |
|
755 break; |
|
756 case KEikMessageUnfadeWindows : |
|
757 case KAknsMessageSkinChange : |
|
758 { |
|
759 TRAP_IGNORE(iSBFrame->CreateDoubleSpanScrollBarsL(ETrue, EFalse)); // window owning scrollbar |
|
760 iSBFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan); |
|
761 TRAP_IGNORE(iSBFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOn)); |
|
762 TRAP_IGNORE(UpdateScrollIndicatorL()); |
|
763 } |
|
764 |
|
765 default: |
|
766 { |
|
767 CCoeControl::HandleResourceChange(aType); |
|
768 } |
|
769 break; |
|
770 } |
|
771 } |
|
772 // --------------------------------------------------------- |
|
773 // CAboutContainer::MopSupplyObject() |
|
774 // Pass skin information if need. |
|
775 // --------------------------------------------------------- |
|
776 |
|
777 TTypeUid::Ptr CAboutContainer::MopSupplyObject(TTypeUid aId) |
|
778 { |
|
779 if (aId.iUid == MAknsControlContext::ETypeId && iSkinContext) |
|
780 { |
|
781 return MAknsControlContext::SupplyMopObject(aId, iSkinContext); |
|
782 } |
|
783 |
|
784 return CCoeControl::MopSupplyObject(aId); |
|
785 } |
|
786 |
|
787 // --------------------------------------------------------- |
|
788 // CAboutContainer::HandleScrollEventL() |
|
789 // Capture Touch Events on the Scroll Bar |
|
790 // --------------------------------------------------------- |
|
791 void CAboutContainer::HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType) |
|
792 { |
|
793 //Only on page up/down,scroll up/down and drag events |
|
794 if((aEventType == EEikScrollPageDown) || (aEventType == EEikScrollPageUp) || |
|
795 (aEventType == EEikScrollThumbDragVert) || (aEventType == EEikScrollUp) || |
|
796 (aEventType == EEikScrollDown)) |
|
797 { |
|
798 //Get the current position from the scroll bar |
|
799 iCurrentScreen = aScrollBar->ThumbPosition(); |
|
800 |
|
801 // Reset flag when dragging scroll bar |
|
802 iScrollBarDragged = ETrue; |
|
803 //Refresh now |
|
804 DrawNow(); |
|
805 UpdateScrollIndicatorL(); |
|
806 } |
|
807 |
|
808 } |