|
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: |
|
15 * GMS picture viewer control - compatible with Editor Base. |
|
16 * It is based very much on the CMmsImageControl. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __GMSPICTURECONTROL_H_ |
|
23 #define __GMSPICTURECONTROL_H_ |
|
24 |
|
25 // INCLUDES |
|
26 |
|
27 #include <MsgBaseControl.h> // for CMsgBaseControl |
|
28 |
|
29 // DATA TYPES |
|
30 |
|
31 enum TGmsPicControlPanic |
|
32 { |
|
33 ENoParent, |
|
34 ENoImageFile, |
|
35 EBadImageContent, |
|
36 EConversionError, |
|
37 EScalingError, |
|
38 ENullPtr |
|
39 }; |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 |
|
43 class CImageDecoder; |
|
44 class CFbsBitmap; |
|
45 class CGmsAOCallBack; |
|
46 class MIHLScaler; |
|
47 |
|
48 // CLASS DECLARATION |
|
49 |
|
50 /** |
|
51 * Message Editor Base compatible control for handling GMS pictures. |
|
52 */ |
|
53 class CGmsPictureControl : public CMsgBaseControl |
|
54 { |
|
55 |
|
56 public: // Constructor and destructor |
|
57 |
|
58 /** |
|
59 * Two-phased constructor. |
|
60 * @param aParent parent control |
|
61 * @return new object |
|
62 */ |
|
63 IMPORT_C static CGmsPictureControl* NewL(const CCoeControl* aParent); |
|
64 |
|
65 /** |
|
66 * Destructor. |
|
67 */ |
|
68 IMPORT_C ~CGmsPictureControl(); |
|
69 |
|
70 public: // new functions |
|
71 |
|
72 /** |
|
73 * Loads the image into display. |
|
74 * After calling LoadImageL and adding image control to view using |
|
75 * iView->AddControlL call you must call imagecontrol->SizeChanged() |
|
76 * to make image appear in view. |
|
77 * @param aImageFile image file name - expected to be valid image |
|
78 * @param aMaxHeight maximum height of the displayed image - default is |
|
79 * 0 = {max display size or max thumbnail size}. |
|
80 */ |
|
81 IMPORT_C void LoadImageL( |
|
82 const TFileName& aImageFile, TUint aMaxHeight = 0); |
|
83 |
|
84 /** |
|
85 * Gives the resolution of the original image read from a file. |
|
86 * @return Original image resolution |
|
87 */ |
|
88 IMPORT_C TSize OriginalImageResolution() const; |
|
89 |
|
90 public: // from CMsgBaseControl |
|
91 |
|
92 /** |
|
93 * Returns the current control rect. |
|
94 * @return Current control rect. |
|
95 */ |
|
96 TRect CurrentLineRect(); |
|
97 |
|
98 /** |
|
99 * Calculates and sets the size of the control and returns new size as |
|
100 * reference aSize. |
|
101 * @param aSize Reference to TSize which gives and gets the size. |
|
102 */ |
|
103 void SetAndGetSizeL(TSize& aSize); |
|
104 |
|
105 /** |
|
106 * Handles clipboard operation. |
|
107 * @param aFunc The clipboard function. |
|
108 */ |
|
109 void ClipboardL(TMsgClipboardFunc aFunc); |
|
110 |
|
111 /** |
|
112 * Handles editing operation. |
|
113 * @param aFunc The edit operation. |
|
114 */ |
|
115 void EditL(TMsgEditFunc aFunc); |
|
116 |
|
117 /** |
|
118 * Checks if the focus change up or down is possible and |
|
119 * returns ETrue if it is. |
|
120 * @param aDirection The direction of focus change. |
|
121 * @return ETrue if focus change is possible. |
|
122 */ |
|
123 TBool IsFocusChangePossible(TMsgFocusDirection aDirection) const; |
|
124 |
|
125 /** |
|
126 * Checks if the cursor location is on the topmost or downmost position |
|
127 * and returns ETrue if it is. |
|
128 * @param aLocation Topmost or bottom. |
|
129 * @return ETrue if cursor is in the specified part. |
|
130 */ |
|
131 TBool IsCursorLocation(TMsgCursorLocation aLocation) const; |
|
132 |
|
133 /** |
|
134 * Returns edit permission flags. |
|
135 * @return Edit permission flags. |
|
136 */ |
|
137 TUint32 EditPermission() const; |
|
138 |
|
139 /** |
|
140 * Resets (= clears) contents of the control. |
|
141 */ |
|
142 void Reset(); |
|
143 |
|
144 /** |
|
145 * Prepares control for viewing. |
|
146 * @param aEvent Event |
|
147 * @param aParam Parameter |
|
148 */ |
|
149 void NotifyViewEvent(TMsgViewEvent aEvent, TInt aParam); |
|
150 |
|
151 public: // TCallBack |
|
152 |
|
153 /** |
|
154 * TCallBack function for image conversion. |
|
155 * @param aPtr this class instance |
|
156 * @return always zero |
|
157 */ |
|
158 static TInt ConversionReady( TAny* aPtr ); |
|
159 |
|
160 static TInt ScalingReady( TAny* aPtr ); |
|
161 |
|
162 protected: // from CMsgBaseControl |
|
163 |
|
164 /** |
|
165 * Prepares for read only or non read only state. |
|
166 * @param aReadOnly Whether to prepare for read only or non-read only. |
|
167 */ |
|
168 void PrepareForReadOnly(TBool aReadOnly); |
|
169 |
|
170 protected: // from CCoeControl |
|
171 |
|
172 /** |
|
173 * CMsgBaseControl requires that this method is implemented. |
|
174 */ |
|
175 TInt CountComponentControls() const; |
|
176 |
|
177 /** |
|
178 * CMsgBaseControl requires that this method is implemented. |
|
179 */ |
|
180 CCoeControl* ComponentControl(TInt /*aIndex*/) const; |
|
181 |
|
182 /** |
|
183 * CMsgBaseControl requires that this method is implemented. |
|
184 */ |
|
185 void FocusChanged( TDrawNow /*aDrawNow*/ ); |
|
186 |
|
187 /** |
|
188 * Called when size is changed. |
|
189 */ |
|
190 void SizeChanged(); |
|
191 |
|
192 /** |
|
193 * Handles bitmap drawing. |
|
194 */ |
|
195 void Draw(const TRect& aRect) const; |
|
196 |
|
197 private: // New functions |
|
198 |
|
199 /** |
|
200 * Helper method which creates or rescales iScaledBitmap unless |
|
201 * image hasn't been loaded or conversion is currently ongoing. |
|
202 * @param aSize size for which to scale |
|
203 * @return ETrue if scaling was possible |
|
204 */ |
|
205 TBool ScaleIfPossibleL( TSize aSize ); |
|
206 |
|
207 /** |
|
208 * Callback method called when image conversion is ready. |
|
209 */ |
|
210 void DoConversionReady(); |
|
211 |
|
212 /** |
|
213 * Callback method called when image scaling is ready. |
|
214 */ |
|
215 void DoScalingReady(); |
|
216 |
|
217 /** |
|
218 * Panic wrapper. |
|
219 * @param aCode panic code |
|
220 */ |
|
221 void Panic(TGmsPicControlPanic aCode); |
|
222 |
|
223 /** |
|
224 * Calculates the size for the image control. |
|
225 * NOTE: This method is old and used only if scalable layout IF is not available. |
|
226 * @param aProposedSize size given by the framework. Our size is either this or smaller. |
|
227 * @return new size for the control |
|
228 */ |
|
229 TSize CalculateControlSize(TSize& aProposedSize); |
|
230 |
|
231 /** |
|
232 * Calculates the size for the image itself according to control rect. |
|
233 * NOTE: This method is old and used only if scalable layout IF is not available. |
|
234 * @return image size |
|
235 */ |
|
236 TSize CalculateImageSize() const; |
|
237 |
|
238 private: // Constructors |
|
239 |
|
240 /** |
|
241 * Second phase constructor. |
|
242 * @param aParent The parent. |
|
243 */ |
|
244 void ConstructL(const CCoeControl* aParent); |
|
245 |
|
246 /** |
|
247 * Constructor |
|
248 */ |
|
249 CGmsPictureControl(); |
|
250 |
|
251 private: //Data |
|
252 |
|
253 /// File server session |
|
254 RFs iFs; |
|
255 |
|
256 /// Maximum height. |
|
257 TUint iMaxHeight; |
|
258 |
|
259 /// Own: Image converter |
|
260 CImageDecoder* iConverter; |
|
261 |
|
262 /// Own: Active object which calls callback method when |
|
263 /// conversion has finished |
|
264 CGmsAOCallBack* iConversionAO; |
|
265 |
|
266 /// Own: Active object which calls callback method when |
|
267 /// scaling has finished |
|
268 CGmsAOCallBack* iScalingAO; |
|
269 |
|
270 /// Own: Bitmap, unscaled original |
|
271 CFbsBitmap* iBitmap; |
|
272 |
|
273 /// Own: Bitmap, scaled for current layout size |
|
274 CFbsBitmap* iScaledBitmap; |
|
275 |
|
276 /// Own: Bitmap scaler |
|
277 MIHLScaler* iScaler; |
|
278 |
|
279 /// Own: The rect of the bitmap |
|
280 TRect iBitmapRect; |
|
281 }; |
|
282 |
|
283 #endif // __GMSPICTURECONTROL_H_ |
|
284 |
|
285 // end of file |