Back to index

lightning-sunbird  0.9+nobinonly
nsSanePlugin.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Rusty Lynch <rusty.lynch@intel.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 /*
00040  * Declares the nsSanePluginInterface class for the SANE plugin.
00041  */
00042 
00043 #ifndef __NS_SANE_PLUGIN_H__
00044 #define __NS_SANE_PLUGIN_H__
00045 
00046 #include "prthread.h"
00047 #include "nscore.h"
00048 #include "nsplugin.h"
00049 #include "gdksuperwin.h"
00050 #include "gtkmozbox.h"
00051 #include "gtk/gtk.h"
00052 #include "nsIPlugin.h"
00053 #include "nsSanePluginControl.h"
00054 #include "nsIScriptContext.h"
00055 #include "nsIServiceManager.h"
00056 #include "nsISupports.h"
00057 #include "nsISupportsUtils.h"
00058 #include "nsIEventQueueService.h"
00059 #include "nsIEventQueue.h"
00060 
00062 // Needed for encoding jpeg images
00063 extern "C"
00064 {
00065 #include <jpeglib.h>
00066 }
00067 
00069 // Needed for SANE interface
00070 extern "C"
00071 {
00072 #include <sane/sane.h>
00073 #include <sane/sanei.h>
00074 #include <sane/saneopts.h>
00075 }
00076 
00077 typedef struct _PlatformInstance
00078 {
00079     Window        window;
00080     GtkWidget   * widget;
00081     GdkSuperWin * superwin;
00082     Display     * display;
00083     uint16        x;
00084     uint16        y;
00085     uint32        width; 
00086     uint32        height;
00087 
00088 } PlatformInstance;
00089 
00090 // Threaded routine for grabbing a frame from device.
00091 // If a callback for onScanComplete was set in the embed/object
00092 // tag, then this routine will call it before exiting.
00093 //void PR_CALLBACK scanimage_thread_routine( void * arg);
00094 void PR_CALLBACK scanimage_thread_routine( void * arg );
00095 
00096 class nsSanePluginInstance : public nsIPluginInstance, 
00097                              public nsISanePluginInstance
00098 {
00099     friend void PR_CALLBACK scanimage_thread_routine( void *);
00100 
00101     public:
00102   
00103     nsSanePluginInstance(void);
00104     virtual ~nsSanePluginInstance(void);
00105 
00107     // nsIPluginInstance inherited interface
00108     NS_IMETHOD Initialize(nsIPluginInstancePeer* peer);
00109     NS_IMETHOD GetPeer(nsIPluginInstancePeer* *result);
00110     NS_IMETHOD Start(void);
00111     NS_IMETHOD Stop(void);
00112     NS_IMETHOD Destroy( void );
00113     NS_IMETHOD SetWindow( nsPluginWindow* window );
00114     NS_IMETHOD NewStream( nsIPluginStreamListener** listener );
00115     NS_IMETHOD Print( nsPluginPrint* platformPrint );
00116     NS_IMETHOD GetValue( nsPluginInstanceVariable variable, void *value );
00117 
00118     // Not used for this platform! Only a placeholder.
00119     NS_IMETHOD HandleEvent( nsPluginEvent* event, PRBool* handled );
00120 
00121     // End of nsIPlugIninstance inherited interface.
00123 
00125     // nsSanePluginInstance specific methods:
00126     NS_DECL_ISUPPORTS ;
00127     
00128     // Execute given callback in window's JavaScript
00129     NS_IMETHOD DoScanCompleteCallback();
00130     NS_IMETHOD DoInitCompleteCallback();
00131 
00132     void SetMode(nsPluginMode mode) { fMode = mode; }
00133     void SetState(PRInt32 aState) { mState = aState; };
00134     NS_IMETHOD PaintImage(void);
00135     char * GetImageFilename();
00136     GtkWidget * GetFileSelection();
00137     PRBool IsUIThread();
00138     nsresult OpenSaneDeviceIF( void );
00139 
00140     //*** Methods exposed through the XPConnect interface ***
00141     NS_DECL_NSISANEPLUGININSTANCE
00142 
00143 private:
00144 
00145     GtkWidget                  *mDrawing_area;
00146     GtkWidget                  *mEvent_box;
00147     PlatformInstance            fPlatform;
00148     char                        mImageFilename[255];
00149     GtkWidget                  *mFileSelection;
00150     GdkRectangle                mZoom_box;
00151     unsigned char              *mRGBData;
00152     int                         mRGBWidth, mRGBHeight;
00153 
00154     // line attributes for zoom box
00155     PRInt32                     mLineWidth;
00156     GdkLineStyle                mLineStyle;
00157     GdkCapStyle                 mCapStyle;
00158     GdkJoinStyle                mJoinStyle;
00159 
00160     // zoom box change variables
00161     float                       mTopLeftXChange;
00162     float                       mTopLeftYChange;
00163     float                       mBottomRightXChange;
00164     float                       mBottomRightYChange;
00165 
00166     // jpeg compression attributes
00167     int                         mCompQuality;
00168     enum J_DCT_METHOD           mCompMethod;
00169 
00170     // sane specific members
00171     SANE_Handle                 mSaneHandle;
00172     SANE_String                 mSaneDevice;
00173     SANE_Bool                   mSaneOpen;
00174     PRBool                      mSuccess;
00175     PRInt32                     mState;
00176 
00177     // needed for JavaScript Callbacks
00178     char                        *mOnScanCompleteScript;
00179     char                        *mOnInitCompleteScript;
00180     PRThread                    *mScanThread;
00181     PRThread                    *mUIThread;
00182 
00183 protected:
00184 
00185     nsIPluginInstancePeer*      fPeer;
00186     nsPluginWindow*             fWindow;
00187     nsPluginMode                fMode;
00188     nsIPluginManager*           mPluginManager;
00189 
00190 private:
00191 
00192     int                         WritePNMHeader (int fd, SANE_Frame format, 
00193                                                 int width, int height, 
00194                                                 int depth);
00195 
00196     void                        PlatformNew( void );
00197     nsresult                    PlatformDestroy( void );
00198     PRInt16                     PlatformHandleEvent( nsPluginEvent* event );
00199     nsresult                    PlatformSetWindow( nsPluginWindow* window );  
00200 };
00201 
00202 class nsSanePluginStreamListener : public nsIPluginStreamListener
00203 {
00204     public:
00205   
00206     NS_DECL_ISUPPORTS ;
00207   
00208     /*
00209      * Notify the observer that the URL has started to load.  This method is
00210      * called only once, at the beginning of a URL load.<BR><BR>
00211      *
00212      * @return The return value is currently ignored.  In the future it may be
00213      * used to cancel the URL load..
00214      */
00215     NS_IMETHOD OnStartBinding( nsIPluginStreamInfo* pluginInfo );
00216   
00228     NS_IMETHOD OnDataAvailable( nsIPluginStreamInfo* pluginInfo,
00229                                 nsIInputStream* input, 
00230                                 PRUint32 length );
00231     NS_IMETHOD OnFileAvailable( nsIPluginStreamInfo* pluginInfo,
00232                          const char* fileName );
00233   
00247     NS_IMETHOD OnStopBinding( nsIPluginStreamInfo* pluginInfo,
00248                               nsresult status );
00249     NS_IMETHOD OnNotify( const char* url, nsresult status );
00250     NS_IMETHOD GetStreamType( nsPluginStreamType *result );
00251   
00253     // snPluginStreamListener specific methods:
00254   
00255     nsSanePluginStreamListener( nsSanePluginInstance* inst );
00256     virtual ~nsSanePluginStreamListener( void );
00257   
00258     nsSanePluginInstance* mPlugInst;
00259 };
00260 
00261 #endif // __NS_SANE_PLUGIN_H__