Back to index

lightning-sunbird  0.9+nobinonly
nsDragService.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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  * Christopher Blizzard <blizzard@mozilla.org>.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Christopher Blizzard <blizzard@mozilla.org>
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 #ifndef nsDragService_h__
00041 #define nsDragService_h__
00042 
00043 #include "nsBaseDragService.h"
00044 #include "nsIDragSessionGTK.h"
00045 #include "nsIObserver.h"
00046 #include <gtk/gtk.h>
00047 
00048 
00053 class nsDragService : public nsBaseDragService,
00054                       public nsIDragSessionGTK,
00055                       public nsIObserver
00056 {
00057 
00058 public:
00059   nsDragService();
00060   virtual ~nsDragService();
00061   
00062   NS_DECL_ISUPPORTS_INHERITED
00063 
00064   NS_DECL_NSIOBSERVER
00065 
00066   // nsIDragService
00067   NS_IMETHOD InvokeDragSession (nsIDOMNode *aDOMNode,
00068                                 nsISupportsArray * anArrayTransferables,
00069                                 nsIScriptableRegion * aRegion,
00070                                 PRUint32 aActionType);
00071   NS_IMETHOD StartDragSession();
00072   NS_IMETHOD EndDragSession();
00073 
00074   // nsIDragSession
00075   NS_IMETHOD SetCanDrop            (PRBool           aCanDrop);
00076   NS_IMETHOD GetCanDrop            (PRBool          *aCanDrop);
00077   NS_IMETHOD GetNumDropItems       (PRUint32 * aNumItems);
00078   NS_IMETHOD GetData               (nsITransferable * aTransferable,
00079                                     PRUint32 aItemIndex);
00080   NS_IMETHOD IsDataFlavorSupported (const char *aDataFlavor, PRBool *_retval);
00081 
00082   // nsIDragSessionGTK
00083 
00084   NS_IMETHOD TargetSetLastContext  (GtkWidget      *aWidget,
00085                                     GdkDragContext *aContext,
00086                                     guint           aTime);
00087   NS_IMETHOD TargetStartDragMotion (void);
00088   NS_IMETHOD TargetEndDragMotion   (GtkWidget      *aWidget,
00089                                     GdkDragContext *aContext,
00090                                     guint           aTime);
00091   NS_IMETHOD TargetDataReceived    (GtkWidget         *aWidget,
00092                                     GdkDragContext    *aContext,
00093                                     gint               aX,
00094                                     gint               aY,
00095                                     GtkSelectionData  *aSelection_data,
00096                                     guint              aInfo,
00097                                     guint32            aTime);
00098   
00099   NS_IMETHOD TargetSetTimeCallback (nsIDragSessionGTKTimeCB aCallback);
00100 
00101   // This is called when the drag started with the invisible widget
00102   // finishes.  It's called from within the drag service code but from
00103   // a callback - it needs to be public.
00104   void           SourceEndDrag(void);
00105   void           SourceDataGet(GtkWidget        *widget,
00106                                GdkDragContext   *context,
00107                                GtkSelectionData *selection_data,
00108                                guint             info,
00109                                guint32           aTime);
00110 
00111   //  END PUBLIC API
00112 
00113 private:
00114 
00115   // target side vars
00116 
00117   // the last widget that was the target of a drag
00118   GtkWidget      *mTargetWidget;
00119   GdkDragContext *mTargetDragContext;
00120   guint           mTargetTime;
00121   // is it OK to drop on us?
00122   PRBool          mCanDrop;
00123   // have we received our drag data?
00124   PRBool          mTargetDragDataReceived;
00125   // last data received and its length
00126   void           *mTargetDragData;
00127   PRUint32        mTargetDragDataLen;
00128   // is the current target drag context contain a list?
00129   PRBool         IsTargetContextList(void);
00130   // this will get the native data from the last target given a
00131   // specific flavor
00132   void           GetTargetDragData(GdkAtom aFlavor);
00133   // this will reset all of the target vars
00134   void           TargetResetData(void);
00135 
00136   // source side vars
00137   
00138   // the source of our drags
00139   GtkWidget     *mHiddenWidget;
00140   // our source data items
00141   nsCOMPtr<nsISupportsArray> mSourceDataItems;
00142   // get a list of the sources in gtk's format
00143   GtkTargetList *GetSourceList(void);
00144 
00145   // this is our callback to get the most recent event's time
00146   nsIDragSessionGTKTimeCB mTimeCB;
00147 
00148 };
00149 
00150 #endif // nsDragService_h__