Back to index

lightning-sunbird  0.9+nobinonly
nsDataObjCollection.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 _NSDATAOBJCOLLECTION_H_
00039 #define _NSDATAOBJCOLLECTION_H_
00040 
00041 #define INITGUID // needed for initializing the IID_IDataObjCollection GUID
00042 
00043 #include <unknwn.h>
00044 #include <basetyps.h>
00045 #include <objidl.h>
00046 // The above are required for __MINGW32__
00047 #include <oleidl.h>
00048 
00049 #include "nsString.h"
00050 #include "nsVoidArray.h"
00051 
00052 class CEnumFormatEtc;
00053 class nsITransferable;
00054 
00055 #define MULTI_MIME "Mozilla/IDataObjectCollectionFormat"
00056 
00057 #if NOT_YET
00058 // {6e99c280-d820-11d3-bb6f-bbf26bfe623c}
00059 EXTERN_C GUID CDECL IID_DATA_OBJ_COLLECTION = 
00060     { 0x6e99c280, 0xd820, 0x11d3, { 0xbb, 0x6f, 0xbb, 0xf2, 0x6b, 0xfe, 0x62, 0x3c } };
00061 
00062 
00063 class nsPIDataObjCollection : IUnknown
00064 {
00065 public:
00066 
00067   STDMETHODIMP AddDataObject(IDataObject * aDataObj) = 0;
00068   STDMETHODIMP GetNumDataObjects(PRInt32* outNum) = 0;
00069   STDMETHODIMP GetDataObjectAt(PRUint32 aItem, IDataObject** outItem) = 0;
00070 
00071 };
00072 #endif
00073 
00074 // {25589C3E-1FAC-47b9-BF43-CAEA89B79533}
00075 DEFINE_GUID(IID_IDataObjCollection, 
00076 0x25589c3e, 0x1fac, 0x47b9, 0xbf, 0x43, 0xca, 0xea, 0x89, 0xb7, 0x95, 0x33);
00077 
00078 // An interface to make sure we have the right kind of object for D&D
00079 // this way we can filter out collection objects that aren't ours
00080 class nsIDataObjCollection : public IUnknown {
00081 public:
00082   
00083 };
00084 
00085 /*
00086  * This ole registered class is used to facilitate drag-drop of objects which
00087  * can be adapted by an object derived from CfDragDrop. The CfDragDrop is
00088  * associated with instances via SetDragDrop().
00089  */
00090  
00091 class nsDataObjCollection : public IDataObject, public nsIDataObjCollection //, public nsPIDataObjCollection
00092 {
00093        public: // construction, destruction
00094               nsDataObjCollection();
00095               ~nsDataObjCollection();
00096 
00097        public: // IUnknown methods - see iunknown.h for documentation
00098               STDMETHODIMP_(ULONG) AddRef        ();
00099               STDMETHODIMP                QueryInterface(REFIID, void**);
00100               STDMETHODIMP_(ULONG) Release       ();
00101 
00102        public: // DataGet and DataSet helper methods
00103               virtual HRESULT AddSetFormat(FORMATETC&  FE);
00104               virtual HRESULT AddGetFormat(FORMATETC&  FE);
00105 
00106               virtual HRESULT GetBitmap(FORMATETC&  FE, STGMEDIUM&  STM);
00107               virtual HRESULT GetDib   (FORMATETC&  FE, STGMEDIUM&  STM);
00108               virtual HRESULT GetMetafilePict(FORMATETC&  FE, STGMEDIUM&  STM);
00109 
00110               virtual HRESULT SetBitmap(FORMATETC&  FE, STGMEDIUM&  STM);
00111               virtual HRESULT SetDib   (FORMATETC&  FE, STGMEDIUM&  STM);
00112               virtual HRESULT SetMetafilePict(FORMATETC&  FE, STGMEDIUM&  STM);
00113 
00114     // support for clipboard
00115     void AddDataFlavor(nsString * aDataFlavor, LPFORMATETC aFE);
00116     void SetTransferable(nsITransferable * aTransferable);
00117 
00118 #if NOT_YET
00119     // from nsPIDataObjCollection
00120     STDMETHODIMP AddDataObject(IDataObject * aDataObj);
00121     STDMETHODIMP GetNumDataObjects(PRInt32* outNum) { *outNum = mDataObjects->Count(); }
00122     STDMETHODIMP GetDataObjectAt(PRUint32 aItem, IDataObject** outItem) { *outItem = (IDataObject *)mDataObjects->SafeElementAt(aItem); }
00123 #endif
00124 
00125     // from nsPIDataObjCollection
00126     void AddDataObject(IDataObject * aDataObj);
00127     PRInt32 GetNumDataObjects() { return mDataObjects->Count(); }
00128     IDataObject* GetDataObjectAt(PRUint32 aItem) { return (IDataObject *)mDataObjects->SafeElementAt(aItem); }
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               // Set the adapter to dragDrop 
00183               //void SetDragDrop(CfDragDrop& dragDrop);
00184 
00185               // Return the adapter
00186               //CfDragDrop& GetDragDrop() const;
00187 
00188               // Return the total reference counts of all instances of this class.
00189               static ULONG GetCumRefCount();
00190 
00191               // Return the reference count (which helps determine if another app has
00192               // released the interface pointer after a drop).
00193               ULONG GetRefCount() const;
00194 
00195        protected:
00196     nsString mStringData;
00197 
00198     BOOL FormatsMatch(const FORMATETC& source, const FORMATETC& target) const;
00199 
00200        static ULONG g_cRef;              // the cum reference count of all instances
00201               ULONG        m_cRef;              // the reference count
00202 
00203     nsVoidArray * mDataFlavors;       // we own and its contents
00204 
00205     nsITransferable  * mTransferable; // nsDataObjCollection owns and ref counts nsITransferable, 
00206                                       // the nsITransferable does know anything about the nsDataObjCollection
00207 
00208     CEnumFormatEtc   * m_enumFE;      // Ownership Rules: 
00209                                       // nsDataObjCollection owns and ref counts CEnumFormatEtc,
00210 
00211     nsVoidArray * mDataObjects;      
00212 
00213 };
00214 
00215 
00216 #endif  //