|
1 // Copyright (c) 2003-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 "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Help Picture module |
|
15 // |
|
16 // |
|
17 |
|
18 #include "hlppict.h" |
|
19 |
|
20 // User includes |
|
21 #include "hlppanic.h" |
|
22 #include "HLPDB.H" |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include "hlpmodel_internal.h" |
|
25 #endif |
|
26 |
|
27 // System includes |
|
28 #include <fbs.h> |
|
29 #include <coemain.h> |
|
30 |
|
31 |
|
32 // |
|
33 // ----> CHlpPicture (source) |
|
34 // |
|
35 |
|
36 CHlpPicture::CHlpPicture(CHlpDatabase& aDatabase, CHlpModel& aHlpModel) |
|
37 :iDatabase(aDatabase), iHlpModel(&aHlpModel) |
|
38 { |
|
39 } |
|
40 |
|
41 CHlpPicture::~CHlpPicture() |
|
42 { |
|
43 delete iImage; |
|
44 |
|
45 if (iHlpModel) |
|
46 iHlpModel->RemoveHelpPicture(this); |
|
47 } |
|
48 |
|
49 void CHlpPicture::ConstructL(const CStreamStore& aStore, TStreamId aStreamId) |
|
50 { |
|
51 // Just restore for now |
|
52 __ASSERT_ALWAYS(iHlpModel, Panic(EHlpNoHelpModelPointer)); |
|
53 const THlpZoomState aZoomState = iHlpModel->ZoomSize(); |
|
54 RestoreL(aStore, aStreamId, iDatabase, aZoomState); |
|
55 } |
|
56 |
|
57 /** Constructs a new CHlpPicture object and returns a pointer to it, |
|
58 pushing it onto the cleanup stack. |
|
59 |
|
60 @param aStore A reference to a stream store. |
|
61 @param aStreamId The ID of the stream to be used. |
|
62 @param aDatabase A reference to a CHlpDatabase object. |
|
63 @param aHlpModel A reference to a CHlpModel object. |
|
64 @return A pointer to a CHlpPicture object. |
|
65 @pre Valid stream store, stream ID, database and Hlpmodel |
|
66 objects are passed to the function. |
|
67 @post A CHlpPicture object has been created and has been pushed |
|
68 onto the cleanup stack. */ |
|
69 CHlpPicture* CHlpPicture::NewLC(const CStreamStore& aStore, TStreamId aStreamId, CHlpDatabase& aDatabase, CHlpModel& aHlpModel) |
|
70 { |
|
71 CHlpPicture* picture = new(ELeave) CHlpPicture(aDatabase, aHlpModel); |
|
72 CleanupStack::PushL(picture); |
|
73 picture->ConstructL(aStore, aStreamId); |
|
74 return picture; |
|
75 } |
|
76 |
|
77 // |
|
78 // |
|
79 // |
|
80 |
|
81 void CHlpPicture::Draw(CGraphicsContext& aGc, const TPoint& aTopLeft, const TRect& aClipRect, MGraphicsDeviceMap* aMap) const |
|
82 { |
|
83 if (iImageCountForPicture != KHlpModelMaximumNumberOfImagesForV6Point2Files) |
|
84 { |
|
85 // If there is only one image to represent this image, then we revert to using |
|
86 // the scaling code, as per v6.0 and 6.1 |
|
87 TSize size; |
|
88 GetSizeInPixels(aMap, size); |
|
89 TRect destRect(aTopLeft, size); |
|
90 |
|
91 TMargins cropMargins; |
|
92 GetCropInTwips(cropMargins); |
|
93 TSize originalSize; |
|
94 GetOriginalSizeInTwips(originalSize); |
|
95 |
|
96 TRect sourceRect(TPoint(cropMargins.iLeft,cropMargins.iTop), TPoint(originalSize.iWidth-cropMargins.iRight,originalSize.iHeight-cropMargins.iBottom)); |
|
97 sourceRect = CCoeEnv::Static()->ScreenDevice()->TwipsToPixels(sourceRect); |
|
98 aGc.SetClippingRect(aClipRect); |
|
99 aGc.DrawBitmap(destRect, iImage, sourceRect); |
|
100 } |
|
101 else |
|
102 { |
|
103 // There are (by default anyway) 3 images available for use at various zoom states, |
|
104 // hence we must ensure that we don't scale the bitmap. |
|
105 TMargins cropMargins; |
|
106 GetCropInTwips(cropMargins); |
|
107 |
|
108 TRect sourceRect; |
|
109 TRect destRect; |
|
110 |
|
111 TSize size(iImage->SizeInPixels()); |
|
112 destRect = TRect(aTopLeft, size); |
|
113 sourceRect = TRect(TPoint(cropMargins.iLeft, cropMargins.iTop), TPoint(size.iWidth - cropMargins.iRight, size.iHeight - cropMargins.iBottom)); |
|
114 |
|
115 aGc.SetClippingRect(aClipRect); |
|
116 aGc.DrawBitmap(destRect, iImage, sourceRect); |
|
117 } |
|
118 } |
|
119 |
|
120 void CHlpPicture::ExternalizeL(RWriteStream& aStream) const |
|
121 { |
|
122 aStream.WriteUint32L(iImageId); |
|
123 } |
|
124 |
|
125 void CHlpPicture::GetCropInTwips(TMargins& aMargins) const |
|
126 { |
|
127 aMargins.iLeft = aMargins.iRight = aMargins.iTop = aMargins.iBottom = 0; |
|
128 } |
|
129 |
|
130 /** Converts a bitmap size to twips before any scaling is applied. |
|
131 |
|
132 @param aSize The size of the bitmap rectangle in pixels. |
|
133 @pre None. |
|
134 @post The bitmap rectangle size is expressed in twips. */ |
|
135 void CHlpPicture::GetOriginalSizeInTwips(TSize& aSize) const |
|
136 { |
|
137 __ASSERT_ALWAYS(iHlpModel, Panic(EHlpNoHelpModelPointer)); |
|
138 aSize = iImage->SizeInPixels(); |
|
139 |
|
140 if (iImageCountForPicture != KHlpModelMaximumNumberOfImagesForV6Point2Files) |
|
141 { |
|
142 // ER6 and 6.1 scale-based code |
|
143 TRect rect(aSize); |
|
144 rect = CCoeEnv::Static()->ScreenDevice()->PixelsToTwips(rect); |
|
145 aSize = rect.Size(); |
|
146 } |
|
147 else |
|
148 { |
|
149 // Fetch the zoom |
|
150 const TReal zoomValue = static_cast<TReal>(iHlpModel->CurrentZoomFactor()); |
|
151 const TReal scaleFactor = static_cast<TReal>(KHlpModelDefaultZoomFactorAsRealNumber / zoomValue); |
|
152 |
|
153 // Scale up or down (in pixels) accordingly |
|
154 aSize.iWidth = static_cast<TInt>(aSize.iWidth * scaleFactor); |
|
155 aSize.iHeight = static_cast<TInt>(aSize.iHeight * scaleFactor); |
|
156 |
|
157 // Now scale into twips |
|
158 aSize = CCoeEnv::Static()->ScreenDevice()->PixelsToTwips(TRect(TPoint(0,0), aSize)).Size(); |
|
159 } |
|
160 } |
|
161 |
|
162 void CHlpPicture::HandleHelpModelDestruction() |
|
163 { |
|
164 iHlpModel = NULL; |
|
165 } |
|
166 |
|
167 void CHlpPicture::SetScaleFactor(TInt /*aScaleFactorWidth*/, TInt /*aScaleFactorHeight*/) |
|
168 { |
|
169 } |
|
170 |
|
171 void CHlpPicture::SetCropInTwips(const TMargins& /*aMargins*/) |
|
172 { |
|
173 } |
|
174 |
|
175 TInt CHlpPicture::ScaleFactorWidth() const |
|
176 { |
|
177 return KHlpModelZoomFactorMedium; |
|
178 } |
|
179 |
|
180 TInt CHlpPicture::ScaleFactorHeight() const |
|
181 { |
|
182 return KHlpModelZoomFactorMedium; |
|
183 } |
|
184 |
|
185 // |
|
186 // |
|
187 // |
|
188 |
|
189 /** Replaces any currently used bitmap with the bitmap that |
|
190 corresponds to the new zoom size. |
|
191 |
|
192 @param aNewZoom The new zoom size. |
|
193 @pre A valid zoom size is passed to the function. |
|
194 @post All currently used bitmaps are replaced with bitmaps |
|
195 that correspond to the new zoom size. */ |
|
196 void CHlpPicture::HandleZoomChangedL(THlpZoomState aNewZoom) |
|
197 { |
|
198 CFbsBitmap* bitmap = iDatabase.ImageForIdLC(iImageId, aNewZoom); |
|
199 delete iImage; |
|
200 iImage = bitmap; |
|
201 CleanupStack::Pop(); |
|
202 } |
|
203 |
|
204 // |
|
205 // |
|
206 // |
|
207 |
|
208 /** Replaces any currently used bitmap with the bitmap |
|
209 that corresponds to the new zoom size. |
|
210 |
|
211 @param aNewZoom The new zoom size. |
|
212 @pre A valid zoom size is passed to the function. |
|
213 @post All currently used bitmaps are replaced with bitmaps |
|
214 that correspond to the new zoom size. |
|
215 |
|
216 @see CHlpDatabase::ImageForIdLC() |
|
217 @see CHlpDatabase::ImageCountForIdL() |
|
218 @see RStoreReadStream::OpenLC() */ |
|
219 void CHlpPicture::RestoreL(const CStreamStore& aStore, TStreamId aStreamId, CHlpDatabase& aDatabase, THlpZoomState aZoomState) |
|
220 { |
|
221 RStoreReadStream stream; |
|
222 stream.OpenLC(aStore, aStreamId); |
|
223 iImageId = stream.ReadUint32L(); |
|
224 CleanupStack::PopAndDestroy(); // stream |
|
225 iImageCountForPicture = aDatabase.ImageCountForIdL(iImageId); |
|
226 |
|
227 // Fetch the specified bitmap from the help files image table. |
|
228 // This method will leave if the image isn't in the table. |
|
229 CFbsBitmap* bitmap = aDatabase.ImageForIdLC(iImageId, aZoomState); |
|
230 delete iImage; |
|
231 iImage = bitmap; |
|
232 CleanupStack::Pop(); // bitmap |
|
233 } |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |