|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "APGPRIV.H" |
|
17 #include <e32hal.h> |
|
18 #include <s32strm.h> |
|
19 #include "APGCLI.H" |
|
20 #include "APGICNFL.H" |
|
21 #include "APGSTD.H" |
|
22 |
|
23 #define KDefaultIconSizeInPixels TSize(96,96) |
|
24 |
|
25 CApaIconPicture* CApaIconPicture::NewL(const TSize& aIconSizeInTwips, const TUid aAppUid) |
|
26 { |
|
27 CApaIconPicture* self=new(ELeave) CApaIconPicture(aIconSizeInTwips, aAppUid); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 self->CreateIconL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CApaIconPicture::CApaIconPicture(const TSize& aIconSizeInTwips, const TUid aAppUid) |
|
36 : iAppUid(aAppUid), |
|
37 iOriginalSizeInTwips(aIconSizeInTwips), |
|
38 iScaleFactorWidth(1000), |
|
39 iScaleFactorHeight(1000) |
|
40 { |
|
41 __DECLARE_NAME(_S("CApaIconPicture")); |
|
42 } |
|
43 |
|
44 void CApaIconPicture::ConstructL() |
|
45 { |
|
46 TMachineInfoV1Buf machineInfoBuf; |
|
47 User::LeaveIfError( UserHal::MachineInfo(machineInfoBuf) ); |
|
48 TMachineInfoV1& machineInfo=machineInfoBuf(); |
|
49 iDisplaySizeInTwips = machineInfo.iPhysicalScreenSize; |
|
50 iDisplaySizeInPixels = machineInfo.iDisplaySizeInPixels; |
|
51 // |
|
52 } |
|
53 |
|
54 CApaIconPicture::~CApaIconPicture() |
|
55 { |
|
56 delete iIcon; |
|
57 } |
|
58 |
|
59 |
|
60 void CApaIconPicture::CreateIconL() |
|
61 { |
|
62 // calculate the size of icon required in pixels |
|
63 TSize sizeInPixels; |
|
64 sizeInPixels.iWidth = (iOriginalSizeInTwips.iWidth*iDisplaySizeInPixels.iWidth*ScaleFactorWidth())/(iDisplaySizeInTwips.iWidth*1000); |
|
65 sizeInPixels.iHeight = (iOriginalSizeInTwips.iHeight*iDisplaySizeInPixels.iHeight*ScaleFactorHeight())/(iDisplaySizeInTwips.iHeight*1000); |
|
66 // if the required icon is not square get a large one and gdi will squash it during drawing |
|
67 CApaMaskedBitmap* newIcon = CApaMaskedBitmap::NewLC(); |
|
68 RApaLsSession ls; |
|
69 CleanupClosePushL(ls); |
|
70 User::LeaveIfError(ls.Connect()); |
|
71 User::LeaveIfError(ls.GetAppIcon(iAppUid, sizeInPixels, *newIcon)); |
|
72 delete iIcon; |
|
73 iIcon = newIcon; |
|
74 CleanupStack::PopAndDestroy(&ls); |
|
75 CleanupStack::Pop(newIcon); |
|
76 // |
|
77 // set physical size |
|
78 TSize iconSizeInTwips; |
|
79 iconSizeInTwips.iWidth = (iOriginalSizeInTwips.iWidth*ScaleFactorWidth())/1000; |
|
80 iconSizeInTwips.iHeight = (iOriginalSizeInTwips.iHeight*ScaleFactorHeight())/1000; |
|
81 iIcon->SetSizeInTwips(iconSizeInTwips); |
|
82 } |
|
83 |
|
84 void CApaIconPicture::Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect, |
|
85 MGraphicsDeviceMap* aMap) const |
|
86 { |
|
87 __ASSERT_DEBUG(iIcon,Panic(EDPanicNoIconInPicture)); |
|
88 // |
|
89 TSize sizeInPixels(0,0); |
|
90 sizeInPixels.iWidth = aMap->HorizontalTwipsToPixels(iOriginalSizeInTwips.iWidth); |
|
91 sizeInPixels.iHeight = aMap->VerticalTwipsToPixels(iOriginalSizeInTwips.iHeight); |
|
92 sizeInPixels.iWidth = (ScaleFactorWidth()*sizeInPixels.iWidth)/1000; |
|
93 sizeInPixels.iHeight = (ScaleFactorHeight()*sizeInPixels.iHeight)/1000; |
|
94 // |
|
95 TRect originalRectInPixels(aTopLeft,sizeInPixels); |
|
96 aGc.SetClippingRect(aClipRect); |
|
97 aGc.DrawBitmap(originalRectInPixels,iIcon); |
|
98 aGc.CancelClippingRect(); |
|
99 } |
|
100 |
|
101 |
|
102 void CApaIconPicture::InternalizeL(RReadStream& /*aStream*/) |
|
103 {} //lint !e1762 Suppress member function could be made const |
|
104 |
|
105 |
|
106 |
|
107 void CApaIconPicture::ExternalizeL(RWriteStream& /*aStream*/)const |
|
108 {} |
|
109 |
|
110 |
|
111 void CApaIconPicture::GetOriginalSizeInTwips(TSize& aOriginalSize) const |
|
112 { |
|
113 aOriginalSize = iOriginalSizeInTwips; |
|
114 } |
|
115 |
|
116 |
|
117 void CApaIconPicture::SetScaleFactor(TInt aScaleFactorWidth,TInt aScaleFactorHeight) |
|
118 { |
|
119 iScaleFactorWidth = aScaleFactorWidth; |
|
120 iScaleFactorHeight = aScaleFactorHeight; |
|
121 TRAP_IGNORE(CreateIconL()); // ignore any error, just keep using the current icon instead |
|
122 } |
|
123 |
|
124 |
|
125 TInt CApaIconPicture::ScaleFactorWidth() const |
|
126 { |
|
127 return iScaleFactorWidth; |
|
128 } |
|
129 |
|
130 |
|
131 TInt CApaIconPicture::ScaleFactorHeight() const |
|
132 { |
|
133 return iScaleFactorHeight; |
|
134 } |
|
135 |
|
136 |
|
137 TPictureCapability CApaIconPicture::Capability() const |
|
138 { |
|
139 return TPictureCapability(TPictureCapability::ENotScaleable,EFalse); // scalable, not cropable |
|
140 } |