|
1 /* |
|
2 * Copyright (c) 2005 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: Screensaver GifAnimation plug-in implementation header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_GIFANIMATIONPLUGIN_H |
|
21 #define C_GIFANIMATIONPLUGIN_H |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <coecntrl.h> |
|
25 #include <coemain.h> |
|
26 #include <fbs.h> |
|
27 #include <barsread.h> |
|
28 |
|
29 #include <npupp.h> |
|
30 #include <PluginAdapterInterface.h> |
|
31 #include <CEcomBrowserPluginInterface.h> |
|
32 #include <MIHLViewerObserver.h> |
|
33 |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class MIHLFileImage; |
|
37 class MIHLBitmap; |
|
38 class MIHLImageViewer; |
|
39 |
|
40 class CCoeControl; |
|
41 class CGifAnimationPlugin; |
|
42 |
|
43 // CONSTANTS |
|
44 /** implementation id GifAnim Ecom Plugin */ |
|
45 const TInt KGifAnimationPluginImplementationValue = 0x102750B4; |
|
46 |
|
47 /****************************************** |
|
48 * This class is specific to ECom Style Plugin. |
|
49 * This is used for passing plugin specific initialization information |
|
50 * to and from browser. |
|
51 *******************************************/ |
|
52 |
|
53 class CGifAnimationPluginEcomMain : public CEcomBrowserPluginInterface |
|
54 { |
|
55 public: // Functions from base classes |
|
56 |
|
57 /** |
|
58 * Instance factory |
|
59 * @param aInitParam an optional parameter |
|
60 */ |
|
61 static CGifAnimationPluginEcomMain* NewL(TAny* aInitParam); |
|
62 |
|
63 /** |
|
64 * Destructor. |
|
65 */ |
|
66 virtual ~CGifAnimationPluginEcomMain(); |
|
67 |
|
68 /** |
|
69 * @return pointer to functions struct. |
|
70 */ |
|
71 NPNetscapeFuncs* Funcs() { return iNpf; } |
|
72 |
|
73 private: // Constructors |
|
74 CGifAnimationPluginEcomMain( NPNetscapeFuncs* aNpf ); |
|
75 void Construct( NPPluginFuncs* aPluginFuncs ); |
|
76 private: // new functions |
|
77 /** |
|
78 * Sets pointers to interface functions |
|
79 * @param aPpf structure to fill |
|
80 */ |
|
81 NPError InitializeFuncs( NPPluginFuncs* aPpf ); |
|
82 |
|
83 private: // Data |
|
84 // pointer to plug-in function pointers struct |
|
85 NPNetscapeFuncs* iNpf; |
|
86 }; |
|
87 |
|
88 /**************************************** |
|
89 Class CGifAnimationPluginControl |
|
90 Class to Handle UI related actions |
|
91 ****************************************/ |
|
92 class CGifAnimationPluginControl : public CCoeControl, |
|
93 public MIHLViewerObserver |
|
94 |
|
95 { |
|
96 public: // Constructor and Destructor |
|
97 |
|
98 /** |
|
99 * Function: NewL |
|
100 * |
|
101 * Description: Get instance of a CGifAnimationPluginControl object. |
|
102 * @param aParentControl a parent class to register to |
|
103 * @param aPluginAdapter pointer to plugin adapter |
|
104 */ |
|
105 static CGifAnimationPluginControl* NewL( CCoeControl* aParentControl, |
|
106 MPluginAdapter* aPluginAdapter); |
|
107 |
|
108 /** |
|
109 * Destructor. |
|
110 */ |
|
111 ~CGifAnimationPluginControl(); |
|
112 |
|
113 public: // From MIHLViewerObserver |
|
114 /** |
|
115 * From MIHLViewerObserver Notifies client |
|
116 * when viewer bitmap content is changed. |
|
117 * Leave situation is handled in ViewerError() callback. |
|
118 */ |
|
119 void ViewerBitmapChangedL(); |
|
120 |
|
121 /** |
|
122 * From MIHLViewerObserver Notifies client if error occurs in viewer. |
|
123 * @param aError IN System wide error code. |
|
124 */ |
|
125 void ViewerError( TInt aError ); |
|
126 |
|
127 public: // new methods |
|
128 /** |
|
129 * Loads the image into display. |
|
130 * @param aImageFileName image file name - expected to be valid image |
|
131 */ |
|
132 void LoadImageL( const TDesC& aImageFileName ); |
|
133 |
|
134 /** |
|
135 * @return last error, if any |
|
136 */ |
|
137 TInt GetLastError() const; |
|
138 |
|
139 /** |
|
140 * Start animation. |
|
141 */ |
|
142 void StartAnimationL(); |
|
143 |
|
144 /** |
|
145 * Stop animation. |
|
146 */ |
|
147 void StopAnimation(); |
|
148 |
|
149 /** |
|
150 * Checks that the file is a valid image file. |
|
151 * Will leave otherwise |
|
152 * |
|
153 * @param aImageFileName image file name - expected to be valid image |
|
154 */ |
|
155 static void CheckFileIsValidL( const TDesC& aImageFileName ); |
|
156 |
|
157 |
|
158 private: // new methods |
|
159 |
|
160 /** |
|
161 * @return ETrue if loaded image is animation. |
|
162 */ |
|
163 TBool IsAnimation() const; |
|
164 |
|
165 /** |
|
166 * Cancel animation. |
|
167 */ |
|
168 void CancelAnimation(); |
|
169 |
|
170 /** |
|
171 * Performs image loading steps. |
|
172 * Uses file name stored in LoadImageL() |
|
173 */ |
|
174 void DoImageLoadingL(); |
|
175 |
|
176 /** |
|
177 * Frees resources allocated with LoadImageL() |
|
178 */ |
|
179 void DeleteAnimation(); |
|
180 |
|
181 /** |
|
182 * If loading content fails, non-leaving HandleCallback |
|
183 * must be call always that parent can update its state |
|
184 * properly. |
|
185 */ |
|
186 void HandleCallback( TInt aError ); |
|
187 |
|
188 /** |
|
189 * Informes that the plug-in wants to terminate |
|
190 */ |
|
191 void InformPluginFinished(); |
|
192 |
|
193 /** |
|
194 * Informs that DRM rights should not be consumed |
|
195 */ |
|
196 void SetPreviewMode(); |
|
197 |
|
198 private: // from CCoeControl |
|
199 void Draw(const TRect& aRect) const; |
|
200 void SizeChanged(); |
|
201 |
|
202 private: // Constructor |
|
203 /** |
|
204 * Constructor. |
|
205 */ |
|
206 CGifAnimationPluginControl(); |
|
207 |
|
208 /** |
|
209 * ConstructL |
|
210 * |
|
211 * 2nd phase constructor. |
|
212 * @param aParentControl a parent class to register to |
|
213 * @param aPluginAdapter pointer to plugin adapter |
|
214 */ |
|
215 void ConstructL( CCoeControl *aParentControl, |
|
216 MPluginAdapter* aPluginAdapter ); |
|
217 |
|
218 private: // Data |
|
219 |
|
220 /** |
|
221 * Possible animation states |
|
222 */ |
|
223 enum TAnimationState |
|
224 { |
|
225 EAnimationNotReady=1, // the file was not loaded yet or corrupt |
|
226 EAnimationLoading=2, |
|
227 EAnimationPlaying=3 |
|
228 }; |
|
229 |
|
230 // Source image |
|
231 MIHLFileImage* iSourceImage; |
|
232 |
|
233 // Destination bitmap |
|
234 MIHLBitmap* iDrawingBitmap; |
|
235 |
|
236 // the bitmap is used for scaling our way, IHL will not do scaling |
|
237 CFbsBitmap* iScalingBitmap; |
|
238 |
|
239 // the mask for scaled bitmap |
|
240 CFbsBitmap* iScalingBitmapMask; |
|
241 |
|
242 // size of target bitmap |
|
243 TSize iTargetSize; |
|
244 |
|
245 // new size of target bitmap |
|
246 TSize iTargetNewSize; |
|
247 |
|
248 // Image viewer used as engine |
|
249 MIHLImageViewer* iEngine; |
|
250 |
|
251 // Internal animation state. |
|
252 TAnimationState iAnimationState; |
|
253 |
|
254 // path and name of file being loaded |
|
255 TFileName iFileName; |
|
256 |
|
257 // code of last loading error occured |
|
258 TInt iLastError; |
|
259 |
|
260 // pointer to adapter, we do not own the instance |
|
261 MPluginAdapter* iPluginAdapter; |
|
262 |
|
263 // if true, no DRM rights are consumed |
|
264 TBool isPreviewMode; |
|
265 }; |
|
266 |
|
267 |
|
268 /******************************************************* |
|
269 Class CGifAnimationPlugin |
|
270 ********************************************************/ |
|
271 |
|
272 class CGifAnimationPlugin : public CBase |
|
273 { |
|
274 public: // Constructor and Destructor |
|
275 /** |
|
276 * Instance factory |
|
277 */ |
|
278 static CGifAnimationPlugin* NewL( NPP anInstance ); |
|
279 /** |
|
280 * Destructor |
|
281 */ |
|
282 ~CGifAnimationPlugin(); |
|
283 |
|
284 /** |
|
285 * Notifies host that plug-in has finished. |
|
286 */ |
|
287 void PrepareToExitL(); |
|
288 |
|
289 /** |
|
290 * @return ref of <code>CGifAnimationPluginControl</code> |
|
291 */ |
|
292 CGifAnimationPluginControl* Control(); |
|
293 |
|
294 /** |
|
295 * @return pointer on NPP instance |
|
296 */ |
|
297 NPP Instance(); |
|
298 |
|
299 /** |
|
300 * Sets the parent window to plug-in. If already set, only updates size. |
|
301 * @param aWindow a parent window |
|
302 * @param aRect a parent window rectangle |
|
303 */ |
|
304 void SetWindowL( const NPWindow *aWindow, const TRect& aRect ); |
|
305 |
|
306 private: |
|
307 /** |
|
308 * Construct. |
|
309 * |
|
310 * 2nd phase constructor. |
|
311 * @param anInstance NPP structure |
|
312 */ |
|
313 void Construct( NPP anInstance ); |
|
314 |
|
315 private: |
|
316 // pointer to adapter |
|
317 MPluginAdapter* iPluginAdapter; |
|
318 |
|
319 // pointer to Container |
|
320 CGifAnimationPluginControl* iControl; |
|
321 |
|
322 // structure with pointers |
|
323 NPP iInstance; |
|
324 }; |
|
325 |
|
326 /**************************************************************************** |
|
327 * |
|
328 * Plugin API methods |
|
329 * |
|
330 */ |
|
331 |
|
332 /** |
|
333 * Create a plugin. |
|
334 */ |
|
335 NPError GifAnimationPluginNewp( NPMIMEType pluginType, |
|
336 NPP instance, |
|
337 uint16 mode, |
|
338 CDesCArray* argn, |
|
339 CDesCArray* argv, |
|
340 NPSavedData* saved ); |
|
341 |
|
342 /** |
|
343 * Destroy a plugin. |
|
344 */ |
|
345 NPError GifAnimationPluginDestroy(NPP instance, NPSavedData** save); |
|
346 |
|
347 /** |
|
348 * This is the parent window of a plugin. |
|
349 */ |
|
350 NPError GifAnimationPluginSetWindow(NPP instance, NPWindow* window); |
|
351 |
|
352 /** |
|
353 * A new data stream has been created for sending data to the plugin. |
|
354 */ |
|
355 NPError GifAnimationPluginNewStream( NPP instance, |
|
356 NPMIMEType type, |
|
357 NPStream* stream, |
|
358 NPBool seekable, |
|
359 uint16* stype ); |
|
360 |
|
361 /** |
|
362 * A data stream has been terminated. |
|
363 */ |
|
364 NPError GifAnimationPluginDestroyStream( NPP instance, |
|
365 NPStream* stream, |
|
366 NPReason reason ); |
|
367 |
|
368 /** |
|
369 * A data stream has been fully saved to a file. |
|
370 */ |
|
371 void GifAnimationPluginAsFile( NPP instance, |
|
372 NPStream* stream, |
|
373 const TDesC& fname ); |
|
374 |
|
375 /** |
|
376 * Return the maximum number of bytes this plugin can accept from the stream. |
|
377 * @param instance - the plug-in instance |
|
378 * @param stream - the stream to use |
|
379 */ |
|
380 int32 GifAnimationPluginWriteReady( NPP instance, NPStream* stream ); |
|
381 |
|
382 /** |
|
383 * Receive more data - return number of bytes processed. |
|
384 * |
|
385 * @param instance - the plug-in instance |
|
386 * @param stream - the stream to read from |
|
387 * @param buffer - contains the data. |
|
388 * @param len - the number of bytes in buffer. |
|
389 * @param offset - the number of bytes already sent/processed. |
|
390 * @return TInt number of bytes processed. |
|
391 */ |
|
392 int32 GifAnimationPluginWrite( NPP instance, |
|
393 NPStream* stream, |
|
394 int32 offset, |
|
395 int32 len, |
|
396 void* buffer ); |
|
397 |
|
398 /** |
|
399 * Generic hook to retrieve values/attributes from the plugin. |
|
400 */ |
|
401 NPError GifAnimationPluginGetValue( NPP instance, |
|
402 NPPVariable variable, |
|
403 void *ret_value ); |
|
404 |
|
405 /** |
|
406 * Generic hook to set values/attributes within the plugin. |
|
407 */ |
|
408 NPError GifAnimationPluginSetValue( NPP instance, |
|
409 NPNVariable variable, |
|
410 void *ret_value ); |
|
411 |
|
412 /** |
|
413 * Event |
|
414 */ |
|
415 int16 GifAnimationPluginEvent( NPP instance, void* event ); |
|
416 |
|
417 /** |
|
418 * Notify |
|
419 */ |
|
420 void GifAnimationPluginURLNotify( NPP instance, |
|
421 const TDesC& url, |
|
422 NPReason reason, |
|
423 void* notifyData ); |
|
424 |
|
425 /** |
|
426 * Print |
|
427 */ |
|
428 void GifAnimationPluginPrint( NPP instance, NPPrint* platformPrint ); |
|
429 |
|
430 #endif // C_GIFANIMATIONPLUGIN_H |