|
1 /* |
|
2 * Copyright (c) 1997-1999 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <fbs.h> |
|
20 #include <coeutils.h> |
|
21 #include <eikimage.h> |
|
22 #include <eikenv.h> |
|
23 #include <barsread.h> |
|
24 #include "lafimage.h" |
|
25 #include <AknIconUtils.h> |
|
26 |
|
27 const TInt KFullEmphasis = 0x01; |
|
28 const TInt KPictureOwnedExternally = 0x10; |
|
29 const TInt KSameBitmapAndMask = 0x20; |
|
30 const TInt KBrushStyleSet = 0x40; |
|
31 |
|
32 EXPORT_C CEikImage::~CEikImage() |
|
33 { |
|
34 if (!(iImFlags&KPictureOwnedExternally)) |
|
35 { |
|
36 delete CONST_CAST(CFbsBitmap*,iBitmap); |
|
37 if (~iImFlags&KSameBitmapAndMask) |
|
38 delete CONST_CAST(CFbsBitmap*,iMaskBitmap); |
|
39 } |
|
40 } |
|
41 |
|
42 EXPORT_C CEikImage::CEikImage() |
|
43 { |
|
44 __DECLARE_NAME(_S("CEikImage")); |
|
45 } |
|
46 |
|
47 EXPORT_C void CEikImage::CreatePictureFromFileL( |
|
48 const TDesC& aFilename,TInt aMainId,TInt aMaskId) |
|
49 { |
|
50 iImFlags&=~KSameBitmapAndMask; |
|
51 if (aMaskId>=0) |
|
52 { |
|
53 AknIconUtils::CreateIconL( |
|
54 const_cast<CFbsBitmap*&>(iBitmap), |
|
55 const_cast<CFbsBitmap*&>(iMaskBitmap), |
|
56 aFilename, aMainId, aMaskId); |
|
57 } |
|
58 else |
|
59 { |
|
60 iBitmap = AknIconUtils::CreateIconL(aFilename, aMainId); |
|
61 } |
|
62 } |
|
63 |
|
64 // |
|
65 EXPORT_C const CFbsBitmap* CEikImage::Bitmap() const |
|
66 { |
|
67 return iBitmap; |
|
68 } |
|
69 // |
|
70 EXPORT_C const CFbsBitmap* CEikImage::Mask() const |
|
71 { |
|
72 return iMaskBitmap; |
|
73 } |
|
74 // |
|
75 EXPORT_C void CEikImage::SetBitmap(const CFbsBitmap* aBitmap) |
|
76 { |
|
77 iBitmap = aBitmap; |
|
78 } |
|
79 // |
|
80 EXPORT_C void CEikImage::SetMask(const CFbsBitmap* aMaskBitmap) |
|
81 { |
|
82 iMaskBitmap = aMaskBitmap; |
|
83 } |
|
84 |
|
85 /** |
|
86 * @internal |
|
87 * @deprecated |
|
88 */ |
|
89 EXPORT_C void CEikImage::SetNewBitmaps(const CFbsBitmap* aNewBitmap,const CFbsBitmap* aNewMask) |
|
90 { |
|
91 SetPicture(aNewBitmap,aNewMask); |
|
92 } |
|
93 |
|
94 EXPORT_C void CEikImage::SetPicture(const CFbsBitmap* aBitmap,const CFbsBitmap* aMaskBitmap) |
|
95 { |
|
96 if (!(iImFlags&KPictureOwnedExternally)) |
|
97 { |
|
98 delete CONST_CAST(CFbsBitmap*,iBitmap); |
|
99 if (iMaskBitmap && !(iImFlags&KSameBitmapAndMask)) |
|
100 delete CONST_CAST(CFbsBitmap*,iMaskBitmap); |
|
101 } |
|
102 iMaskBitmap=NULL; |
|
103 iImFlags&=~KSameBitmapAndMask; |
|
104 if (aMaskBitmap) |
|
105 { |
|
106 iMaskBitmap=aMaskBitmap; |
|
107 if (aBitmap==aMaskBitmap) |
|
108 iImFlags|=KSameBitmapAndMask; |
|
109 } |
|
110 iBitmap=aBitmap; |
|
111 } |
|
112 |
|
113 EXPORT_C void CEikImage::Draw(const TRect& aRect) const |
|
114 { |
|
115 CWindowGc& gc=SystemGc(); |
|
116 if (iImFlags & KBrushStyleSet) |
|
117 gc.SetBrushStyle(iBrushStyle); |
|
118 #ifdef __SERIES60_30__ |
|
119 gc.SetOpaque( ETrue ); // transparency off |
|
120 #endif // __SERIES60_30__ |
|
121 if (iBitmap) |
|
122 { |
|
123 LafImage::Draw(iEikonEnv->LafEnv(),*this,gc,aRect,iMargin,iAlignment,*iBitmap,iMaskBitmap,iImFlags&KFullEmphasis); |
|
124 } |
|
125 #ifdef __SERIES60_30__ |
|
126 gc.SetOpaque( EFalse ); // transparency back on |
|
127 #endif // __SERIES60_30__ |
|
128 } |
|
129 |
|
130 EXPORT_C TSize CEikImage::MinimumSize() |
|
131 { |
|
132 TSize size(0,0); |
|
133 if (iBitmap) |
|
134 { |
|
135 size = iBitmap->SizeInPixels(); |
|
136 } |
|
137 size += iMargin.SizeDelta(); |
|
138 return size; |
|
139 } |
|
140 |
|
141 EXPORT_C void CEikImage::SetEmphasis(TBool aEmphasis) |
|
142 { |
|
143 iImFlags&=~KFullEmphasis; |
|
144 if (aEmphasis) |
|
145 iImFlags|=KFullEmphasis; |
|
146 } |
|
147 |
|
148 EXPORT_C void CEikImage::SetPictureOwnedExternally(TBool aOwnership) |
|
149 { |
|
150 if (aOwnership) |
|
151 iImFlags|=KPictureOwnedExternally; |
|
152 else |
|
153 iImFlags&=~KPictureOwnedExternally; |
|
154 } |
|
155 // |
|
156 EXPORT_C TBool CEikImage::IsPictureOwnedExternally() |
|
157 { |
|
158 if (iImFlags&KPictureOwnedExternally) |
|
159 return ETrue; |
|
160 else |
|
161 return EFalse; |
|
162 } |
|
163 |
|
164 EXPORT_C void CEikImage::ConstructFromResourceL(TResourceReader& aReader) |
|
165 { |
|
166 iAlignment.SetHAlignment((TGulHAlignment)aReader.ReadInt16()); |
|
167 iAlignment.SetVAlignment((TGulVAlignment)aReader.ReadInt16()); |
|
168 const TPtrC bmpFile=aReader.ReadTPtrC(); |
|
169 const TInt bmpId=aReader.ReadInt16(); |
|
170 const TInt bmpMask=aReader.ReadInt16(); |
|
171 CreatePictureFromFileL(bmpFile,bmpId,bmpMask); |
|
172 aReader.ReadInt32(); // extension link |
|
173 } |
|
174 |
|
175 /** |
|
176 * Writes the internal state of the control and its components to aStream. |
|
177 * Does nothing in release mode. |
|
178 * Designed to be overidden and base called by subclasses. |
|
179 * |
|
180 * @internal |
|
181 * @since App-Framework_6.1 |
|
182 */ |
|
183 #ifndef _DEBUG |
|
184 EXPORT_C void CEikImage::WriteInternalStateL(RWriteStream&) const |
|
185 {} |
|
186 #else |
|
187 EXPORT_C void CEikImage::WriteInternalStateL(RWriteStream& aWriteStream) const |
|
188 { |
|
189 _LIT(KLitEikImgCtlStart, "<CEikImage>"); |
|
190 _LIT(KLitEikImgCtlEnd, "<\\CEikImage>"); |
|
191 _LIT(KLitEikImgBmp,"<iBitmap>"); |
|
192 _LIT(KLitEikImgBmpEnd,"<\\iBitmap>"); |
|
193 _LIT(KLitEikImgMskBmp,"<iMaskBitmap>"); |
|
194 _LIT(KLitEikImgMskBmpEnd,"<\\iMaskBitmap>"); |
|
195 _LIT(KLitEikImgFlgs,"<iImFlags>"); |
|
196 _LIT(KLitEikImgFlgsEnd,"<\\iImFlags>"); |
|
197 |
|
198 aWriteStream << KLitEikImgCtlStart; |
|
199 aWriteStream << KLitEikImgBmp; |
|
200 if(iBitmap) |
|
201 aWriteStream << *iBitmap; |
|
202 aWriteStream << KLitEikImgBmpEnd; |
|
203 aWriteStream << KLitEikImgMskBmp; |
|
204 if(iMaskBitmap) |
|
205 aWriteStream << *iMaskBitmap; |
|
206 aWriteStream << KLitEikImgMskBmpEnd; |
|
207 aWriteStream << KLitEikImgFlgs; |
|
208 aWriteStream.WriteInt32L(iImFlags); |
|
209 aWriteStream << KLitEikImgFlgsEnd; |
|
210 CEikAlignedControl::WriteInternalStateL(aWriteStream); |
|
211 aWriteStream << KLitEikImgCtlEnd; |
|
212 } |
|
213 #endif |
|
214 |
|
215 EXPORT_C void CEikImage::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
216 { |
|
217 CEikAlignedControl::HandlePointerEventL(aPointerEvent); |
|
218 } |
|
219 |
|
220 EXPORT_C void* CEikImage::ExtensionInterface( TUid /*aInterface*/ ) |
|
221 { |
|
222 return NULL; |
|
223 } |
|
224 |
|
225 EXPORT_C void CEikImage::Reserved_2() |
|
226 {} |
|
227 |
|
228 EXPORT_C void CEikImage::SetBrushStyle(CGraphicsContext::TBrushStyle aBrushStyle) |
|
229 { |
|
230 iImFlags |= KBrushStyleSet; |
|
231 iBrushStyle=aBrushStyle; |
|
232 }; |