Back to index

lightning-sunbird  0.9+nobinonly
nsDataObj.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _NSDATAOBJ_H_
00039 #define _NSDATAOBJ_H_
00040 
00041 #include <unknwn.h>
00042 #include <basetyps.h>
00043 #include <objidl.h>
00044 // The above are required for __MINGW32__
00045 #include <oleidl.h>
00046 
00047 //#include "Ddforw.h"
00048 #include "nsString.h"
00049 #include "nsILocalFile.h"
00050 #include "nsIURI.h"
00051 
00052 #define MAX_FORMATS 32
00053 
00054 /* 
00055  * CFSTR_SHELLURL is deprecated and doesn't have a Unicode version.
00056  * Therefore we are using CFSTR_INETURL instead of CFSTR_SHELLURL.
00057  * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/transferring/clipboard.asp
00058  */
00059 #ifndef CFSTR_INETURLA
00060 #define CFSTR_INETURLA    "UniformResourceLocator"
00061 #endif
00062 #ifndef CFSTR_INETURLW
00063 #define CFSTR_INETURLW    "UniformResourceLocatorW"
00064 #endif
00065 
00066 // For support of MinGW w32api v2.4. 
00067 // When the next version of w32api is released with shlobj.h rev 1.35 
00068 // http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/winsup/w32api/include/shlobj.h?cvsroot=src
00069 // then that can be made the base required version and this code should be removed.
00070 #ifndef CFSTR_FILEDESCRIPTORA
00071 # define CFSTR_FILEDESCRIPTORA   "FileGroupDescriptor"
00072 #endif
00073 #ifndef CFSTR_FILEDESCRIPTORW
00074 # define CFSTR_FILEDESCRIPTORW   "FileGroupDescriptorW"
00075 #endif
00076 
00077 #ifdef __MINGW32__
00078 # include <w32api.h>
00079 # if __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION == 0)
00080 #  ifndef FILEGROUPDESCRIPTORA
00081 #   define FILEGROUPDESCRIPTORA    FILEGROUPDESCRIPTOR
00082 #  endif
00083 #  ifndef LPFILEGROUPDESCRIPTORA
00084 #   define LPFILEGROUPDESCRIPTORA  LPFILEGROUPDESCRIPTOR
00085 #  endif
00086 typedef struct _FILEDESCRIPTORW {
00087    DWORD dwFlags;
00088    CLSID clsid;
00089    SIZEL sizel;
00090    POINTL pointl;
00091    DWORD dwFileAttributes;
00092    FILETIME ftCreationTime;
00093    FILETIME ftLastAccessTime;
00094    FILETIME ftLastWriteTime;
00095    DWORD nFileSizeHigh;
00096    DWORD nFileSizeLow;
00097    WCHAR cFileName[MAX_PATH];
00098 } FILEDESCRIPTORW,*LPFILEDESCRIPTORW;
00099 typedef struct _FILEGROUPDESCRIPTORW {
00100    UINT cItems;
00101    FILEDESCRIPTORW fgd[1];
00102 } FILEGROUPDESCRIPTORW,*LPFILEGROUPDESCRIPTORW;
00103 # endif /*__W32API_MAJOR_VERSION*/
00104 #endif /*__MINGW32__*/
00105 
00106 class nsVoidArray;
00107 class CEnumFormatEtc;
00108 class nsITransferable;
00109 
00110 /*
00111  * This ole registered class is used to facilitate drag-drop of objects which
00112  * can be adapted by an object derived from CfDragDrop. The CfDragDrop is
00113  * associated with instances via SetDragDrop().
00114  */
00115 class nsDataObj : public IDataObject
00116 {
00117   public: // construction, destruction
00118     nsDataObj(nsIURI *uri = nsnull);
00119     ~nsDataObj();
00120 
00121        public: // IUnknown methods - see iunknown.h for documentation
00122               STDMETHODIMP_(ULONG) AddRef        ();
00123               STDMETHODIMP                QueryInterface(REFIID, void**);
00124               STDMETHODIMP_(ULONG) Release       ();
00125 
00126     // support for clipboard
00127     void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE);
00128     void SetTransferable(nsITransferable * aTransferable);
00129 
00130               // Return the registered OLE class ID of this object's CfDataObj.
00131               CLSID GetClassID() const;
00132 
00133        public: // IDataObject methods - these are general comments. see CfDragDrop
00134                        // for overriding behavior
00135 
00136               // Store data in pSTM according to the format specified by pFE, if the
00137               // format is supported (supported formats are specified in CfDragDrop::
00138               // GetFormats) and return NOERROR; otherwise return DATA_E_FORMATETC. It
00139               // is the callers responsibility to free pSTM if NOERROR is returned.
00140               STDMETHODIMP GetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM);
00141 
00142               // Similar to GetData except that the caller allocates the structure
00143               // referenced by pSTM.
00144               STDMETHODIMP GetDataHere (LPFORMATETC pFE, LPSTGMEDIUM pSTM);
00145 
00146               // Returns S_TRUE if this object supports the format specified by pSTM,
00147               // S_FALSE otherwise.
00148               STDMETHODIMP QueryGetData (LPFORMATETC pFE);
00149 
00150               // Set pCanonFE to the cannonical format of pFE if one exists and return
00151               // NOERROR, otherwise return DATA_S_SAMEFORMATETC. A cannonical format
00152               // implies an identical rendering.
00153               STDMETHODIMP GetCanonicalFormatEtc (LPFORMATETC pFE, LPFORMATETC pCanonFE);
00154 
00155               // Set this objects data according to the format specified by pFE and
00156               // the storage medium specified by pSTM and return NOERROR, if the format
00157               // is supported. If release is TRUE this object must release the storage
00158               // associated with pSTM.
00159               STDMETHODIMP SetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release);
00160 
00161               // Set ppEnum to an IEnumFORMATETC object which will iterate all of the
00162               // data formats that this object supports. direction is either DATADIR_GET
00163               // or DATADIR_SET.
00164               STDMETHODIMP EnumFormatEtc  (DWORD direction, LPENUMFORMATETC* ppEnum);
00165 
00166               // Set up an advisory connection to this object based on the format specified
00167               // by pFE, flags, and the pAdvise. Set pConn to the established advise
00168               // connection.
00169               STDMETHODIMP DAdvise (LPFORMATETC pFE, DWORD flags, LPADVISESINK pAdvise,
00170                                                                 DWORD* pConn);
00171 
00172               // Turn off advising of a previous call to DAdvise which set pConn.
00173               STDMETHODIMP DUnadvise (DWORD pConn);
00174 
00175               // Set ppEnum to an IEnumSTATDATA object which will iterate over the
00176               // existing objects which have established advisory connections to this
00177       // object.
00178               STDMETHODIMP EnumDAdvise (LPENUMSTATDATA *ppEnum);
00179 
00180        public: // other methods
00181 
00182               // Return the total reference counts of all instances of this class.
00183               static ULONG GetCumRefCount();
00184 
00185               // Return the reference count (which helps determine if another app has
00186               // released the interface pointer after a drop).
00187               ULONG GetRefCount() const;
00188 
00189        protected:
00190        
00191            // Help determine if the drag should create an internet shortcut
00192          PRBool IsInternetShortcut ( ) ;
00193 
00194               virtual HRESULT AddSetFormat(FORMATETC&  FE);
00195               virtual HRESULT AddGetFormat(FORMATETC&  FE);
00196 
00197               virtual HRESULT GetText ( const nsACString& aDF, FORMATETC& aFE, STGMEDIUM & aSTG );
00198               virtual HRESULT GetFile ( const nsACString& aDF, FORMATETC& aFE, STGMEDIUM& aSTG );
00199               virtual HRESULT GetBitmap ( const nsACString& inFlavor, FORMATETC&  FE, STGMEDIUM&  STM);
00200               virtual HRESULT GetDib ( const nsACString& inFlavor, FORMATETC &, STGMEDIUM & aSTG );
00201               virtual HRESULT GetMetafilePict(FORMATETC&  FE, STGMEDIUM&  STM);
00202 
00203     virtual HRESULT GetUniformResourceLocator ( FORMATETC& aFE, STGMEDIUM& aSTG, PRBool aIsUnicode ) ;
00204     virtual HRESULT ExtractUniformResourceLocatorA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00205     virtual HRESULT ExtractUniformResourceLocatorW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00206     virtual HRESULT GetFileDescriptor ( FORMATETC& aFE, STGMEDIUM& aSTG, PRBool aIsUnicode ) ;
00207     virtual HRESULT GetFileContents ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00208     virtual HRESULT GetPreferredDropEffect ( FORMATETC& aFE, STGMEDIUM& aSTG );
00209    
00210               virtual HRESULT SetBitmap(FORMATETC&  FE, STGMEDIUM&  STM);
00211               virtual HRESULT SetDib   (FORMATETC&  FE, STGMEDIUM&  STM);
00212               virtual HRESULT SetText  (FORMATETC&  FE, STGMEDIUM&  STM);
00213               virtual HRESULT SetMetafilePict(FORMATETC&  FE, STGMEDIUM&  STM);
00214 
00215       // Provide the structures needed for an internet shortcut by the shell
00216     virtual HRESULT GetFileDescriptorInternetShortcutA ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00217     virtual HRESULT GetFileDescriptorInternetShortcutW ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00218     virtual HRESULT GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG ) ;
00219 
00220     nsresult ExtractShortcutURL ( nsString & outURL ) ;
00221     nsresult ExtractShortcutTitle ( nsString & outTitle ) ;
00222     
00223       // munge our HTML data to win32's CF_HTML spec. Will null terminate
00224     nsresult BuildPlatformHTML ( const char* inOurHTML, char** outPlatformHTML ) ;
00225 
00226     // Used for the SourceURL part of CF_HTML
00227     nsCString mSourceURL;
00228 
00229     nsString mStringData;
00230 
00231     BOOL FormatsMatch(const FORMATETC& source, const FORMATETC& target) const;
00232 
00233        static ULONG g_cRef;              // the cum reference count of all instances
00234               ULONG        m_cRef;              // the reference count
00235 
00236     nsVoidArray * mDataFlavors;       // we own and its contents
00237 
00238     nsITransferable  * mTransferable; // nsDataObj owns and ref counts nsITransferable, 
00239                                       // the nsITransferable does know anything about the nsDataObj
00240 
00241     CEnumFormatEtc   * m_enumFE;      // Ownership Rules: 
00242                                       // nsDataObj owns and ref counts CEnumFormatEtc,
00243 
00244     nsCOMPtr<nsILocalFile> mCachedTempFile;
00245 };
00246 
00247 
00248 #endif  // _NSDATAOBJ_H_
00249