1 /* |
|
2 * Copyright (c) 2007-2008 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: image provider for liw buffer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <fbs.h> |
|
20 #include <AknsSkinInstance.h> |
|
21 #include <AknsUtils.h> |
|
22 #include <liwcommon.h> |
|
23 #include <liwbufferextension.h> |
|
24 #include <s32mem.h> |
|
25 #include "hnattrimgprovliwimage.h" |
|
26 #include "hnextbmpiconholder.h" |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS ============================= |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CHnAttrImgProvLiwImage::CHnAttrImgProvLiwImage() |
|
36 { |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CHnAttrImgProvLiwImage::ConstructL( TLiwVariant*& aBitmap, |
|
44 TLiwVariant*& aMaskBitmap ) |
|
45 { |
|
46 ASSERT( aBitmap ); |
|
47 CFbsBitmap* mask = NULL; |
|
48 CFbsBitmap* bitmap = CreateBitmapFromVariantL( *aBitmap ); |
|
49 if ( bitmap ) |
|
50 { |
|
51 if( aMaskBitmap ) |
|
52 { |
|
53 mask = CreateBitmapFromVariantL( *aMaskBitmap ); |
|
54 } |
|
55 CreateIconL( bitmap, mask ); |
|
56 } |
|
57 else if ( aBitmap->TypeId() == LIW::EVariantTypeBuffer ) |
|
58 { |
|
59 CLiwBitmapBuffer* bmpBuff = |
|
60 static_cast<CLiwBitmapBuffer*>( aBitmap->AsBuffer() ); |
|
61 CLiwBitmapBuffer* maskBuff = |
|
62 static_cast<CLiwBitmapBuffer*>( |
|
63 aMaskBitmap ? aMaskBitmap->AsBuffer() : NULL ); |
|
64 if ( bmpBuff ) |
|
65 { |
|
66 bitmap = bmpBuff->AsBitmap(); |
|
67 } |
|
68 if ( maskBuff ) |
|
69 { |
|
70 mask = maskBuff->AsBitmap(); |
|
71 } |
|
72 if ( bitmap ) |
|
73 { |
|
74 CreateExtIconL( bitmap, mask, bmpBuff, maskBuff ); |
|
75 } |
|
76 } |
|
77 if ( !bitmap ) |
|
78 { |
|
79 //No point to keep variant as bitmap was not created |
|
80 aBitmap->Reset(); |
|
81 delete aBitmap; |
|
82 aBitmap = NULL; |
|
83 } |
|
84 if ( aMaskBitmap && !mask ) |
|
85 { |
|
86 //No point to keep variant as bitmap was not created |
|
87 aMaskBitmap->Reset(); |
|
88 delete aMaskBitmap; |
|
89 aMaskBitmap = NULL; |
|
90 } |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CHnAttrImgProvLiwImage::CreateExtIconL( CFbsBitmap* aBitmap, |
|
98 CFbsBitmap* aMask, CLiwBitmapBuffer* aExtBmp, |
|
99 CLiwBitmapBuffer* aExtMask ) |
|
100 { |
|
101 // the condition in the assertion below means: if you provide aMask then |
|
102 // you must also provide aExtMask |
|
103 __ASSERT_DEBUG( aBitmap && aExtBmp && ( !aMask || aExtMask ), |
|
104 User::Invariant() ); |
|
105 |
|
106 CGulIcon* newIcon = CGulIcon::NewL( aBitmap, aMask ); |
|
107 CleanupStack::PushL( newIcon ); |
|
108 newIcon->SetBitmapsOwnedExternally( ETrue ); |
|
109 CHnExtBmpIconHolder *newIconHolder = new (ELeave) CHnExtBmpIconHolder(); |
|
110 newIconHolder->SetGulIcon( newIcon , aExtBmp, aExtMask ); |
|
111 CleanupStack::Pop( newIcon ); |
|
112 |
|
113 if ( iIconHolder ) |
|
114 { |
|
115 iIconHolder->Close(); |
|
116 } |
|
117 iIconHolder = newIconHolder; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C CHnAttrImgProvLiwImage* CHnAttrImgProvLiwImage::NewL( |
|
125 TLiwVariant*& aBitmap, TLiwVariant*& aMaskBitmap ) |
|
126 { |
|
127 CHnAttrImgProvLiwImage* self = NewLC( aBitmap, aMaskBitmap ); |
|
128 CleanupStack::Pop( self ); |
|
129 return self; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C CHnAttrImgProvLiwImage* CHnAttrImgProvLiwImage::NewLC( |
|
137 TLiwVariant*& aBitmap, TLiwVariant*& aMaskBitmap ) |
|
138 { |
|
139 CHnAttrImgProvLiwImage* self = new( ELeave ) CHnAttrImgProvLiwImage; |
|
140 CleanupStack::PushL( self ); |
|
141 self->ConstructL( aBitmap, aMaskBitmap ); |
|
142 return self; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 CHnAttrImgProvLiwImage::~CHnAttrImgProvLiwImage() |
|
150 { |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CHnAttrImgProvLiwImage::RemoveLiwObjects() |
|
158 { |
|
159 if ( iIconHolder ) |
|
160 { |
|
161 iIconHolder->Close(); |
|
162 iIconHolder = NULL; |
|
163 } |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 const TDesC8& CHnAttrImgProvLiwImage::Value( ) |
|
171 { |
|
172 return iValue; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 CFbsBitmap* CHnAttrImgProvLiwImage::CreateBitmapFromVariantL( |
|
180 const TLiwVariant& aVariant ) |
|
181 { |
|
182 CFbsBitmap* bitmap( NULL ); |
|
183 TInt handle = 0; |
|
184 |
|
185 if ( ExtractBitmapHandleFromVariant( aVariant, handle ) == KErrNone ) |
|
186 { |
|
187 CFbsBitmap* tempBitmap = new( ELeave ) CFbsBitmap; |
|
188 if ( tempBitmap->Duplicate( handle ) == KErrNone ) |
|
189 { |
|
190 bitmap = tempBitmap; |
|
191 } |
|
192 else |
|
193 { |
|
194 delete tempBitmap; |
|
195 } |
|
196 } |
|
197 else if ( aVariant.TypeId() == LIW::EVariantTypeDesC8 ) |
|
198 { |
|
199 CFbsBitmap* tempBitmap = new ( ELeave ) CFbsBitmap; |
|
200 CleanupStack::PushL( tempBitmap ); |
|
201 TPtrC8 buf = aVariant.AsData(); |
|
202 RDesReadStream stream( buf ); |
|
203 CleanupClosePushL( stream ); |
|
204 tempBitmap->InternalizeL( stream ); |
|
205 CleanupStack::PopAndDestroy( &stream ); |
|
206 CleanupStack::Pop( tempBitmap ); |
|
207 bitmap = tempBitmap; |
|
208 } |
|
209 return bitmap; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TInt CHnAttrImgProvLiwImage::ExtractBitmapHandleFromVariant( |
|
217 const TLiwVariant& aVariant, TInt& aHandle ) |
|
218 { |
|
219 TInt err = KErrNone; |
|
220 switch ( aVariant.TypeId() ) |
|
221 { |
|
222 case LIW::EVariantTypeTInt32: |
|
223 aHandle = static_cast<TInt>( aVariant.AsTInt32() ); |
|
224 break; |
|
225 case LIW::EVariantTypeTUint: |
|
226 aHandle = static_cast<TInt>( aVariant.AsTUint() ); |
|
227 break; |
|
228 case LIW::EVariantTypeTInt64: |
|
229 aHandle = static_cast<TInt>( aVariant.AsTInt64() ); |
|
230 break; |
|
231 case LIW::EVariantTypeTBool: |
|
232 // Putting a TInt into a TLiwVariant will result in the variant |
|
233 // storing a TBool variable. CFbsBitmap::Handle() returns TInt, so |
|
234 // we can assume that the TBool stored in aVariant is in fact TInt. |
|
235 aHandle = static_cast<TInt>( aVariant.AsTBool() ); |
|
236 break; |
|
237 default: |
|
238 err = KErrNotFound; |
|
239 } |
|
240 return err; |
|
241 } |
|