KWWidgets
|
00001 /* 00002 * tkOleDND.cpp -- 00003 * 00004 * This file implements the windows portion of the drag&drop mechanish 00005 * for the tk toolkit. The protocol in use under windows is the 00006 * OLE protocol. Based on code wrote by Gordon Chafee. 00007 * 00008 * This software is copyrighted by: 00009 * George Petasis, National Centre for Scientific Research "Demokritos", 00010 * Aghia Paraskevi, Athens, Greece. 00011 * e-mail: petasis@iit.demokritos.gr 00012 * Laurent Riesterer, Rennes, France. 00013 * e-mail: laurent.riesterer@free.fr 00014 * 00015 * The following terms apply to all files associated 00016 * with the software unless explicitly disclaimed in individual files. 00017 * 00018 * The authors hereby grant permission to use, copy, modify, distribute, 00019 * and license this software and its documentation for any purpose, provided 00020 * that existing copyright notices are retained in all copies and that this 00021 * notice is included verbatim in any distributions. No written agreement, 00022 * license, or royalty fee is required for any of the authorized uses. 00023 * Modifications to this software may be copyrighted by their authors 00024 * and need not follow the licensing terms described here, provided that 00025 * the new terms are clearly indicated on the first page of each file where 00026 * they apply. 00027 * 00028 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY 00029 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 00030 * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY 00031 * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 00035 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 00036 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE 00037 * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE 00038 * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 00039 * MODIFICATIONS. 00040 */ 00041 00042 #ifndef _OLE_DND_H 00043 #define _OLE_DND_H 00044 00045 00046 #include "vtkTcl.h" 00047 #include "vtkTk.h" 00048 00049 #include <windows.h> 00050 #include <ole2.h> 00051 00052 #ifdef DND_ENABLE_DROP_TARGET_HELPER 00053 #include <atlbase.h> 00054 #include <shlobj.h> /* for IDropTargetHelper */ 00055 #include <shlguid.h> 00056 /* We need this declaration for CComPtr, which uses __uuidof() */ 00057 struct __declspec(uuid("{4657278B-411B-11d2-839A-00C04FD918D0}")) 00058 IDropTargetHelper; 00059 #endif /* DND_ENABLE_DROP_TARGET_HELPER */ 00060 00061 #include <tcl.h> 00062 #include <tk.h> 00063 #include "tkDND.h" 00064 #include "tkOleDND_TEnumFormatEtc.h" 00065 00066 #ifdef DND_DEBUG 00067 extern FILE *TkDND_Log; 00068 #endif 00069 00070 typedef struct _OLEDND_Struct { 00071 Tk_Window MainWindow; /* The main window of our application */ 00072 Tcl_Interp *interp; /* A Tcl Interpreter */ 00073 Display *display; /* Display Pointer */ 00074 int x; /* Current position of the mouse */ 00075 int y; /* Current position of the mouse */ 00076 int button; /* Current button used for drag operation */ 00077 Tk_Window CursorWindow; /* A window to replace cursor */ 00078 char * CursorCallback; /* A Callback to update cursor window */ 00079 00080 Tk_Window DraggerWindow; /* Window of the drag source */ 00081 DWORD DraggerActions; /* Actions supported by the drag source */ 00082 Tcl_DString DraggerTypes; /* The list of types of the drag source */ 00083 CLIPFORMAT DesiredType; /* The drop desired type */ 00084 char *DesiredTypeStr; /* The drop desired type (string) */ 00085 char DesiredAction[10]; /* The drop desired action */ 00086 int CallbackStatus; /* The return value of last tcl callback */ 00087 Tcl_Obj *data; /* The object contained data to be dropped */ 00088 int length; /* length of the data */ 00089 00090 /* Some useful CLIPFORMATS... */ 00091 CLIPFORMAT UniformResourceLocator; /* Netscape, IE */ 00092 CLIPFORMAT FileName; /* Windows Explorer */ 00093 CLIPFORMAT HTML_Format; /* Word, IE */ 00094 CLIPFORMAT RichTextFormat; /* Word, IE */ 00095 CLIPFORMAT FileGroupDescriptor; /* Explorer, files not in the file */ 00096 CLIPFORMAT FileGroupDescriptorW; /* system */ 00097 } OleDND; 00098 #define DndClass OleDND 00099 00100 /***************************************************************************** 00101 * Drop Source Related Class. 00102 ****************************************************************************/ 00103 class TkDND_DropSource: public IDropSource { 00104 private: 00105 ULONG m_refCnt; /* Reference count */ 00106 DndInfo *infoPtr; /* Pointer to hash table entry */ 00107 00108 public: 00109 TkDND_DropSource(DndInfo *infoPtr); 00110 ~TkDND_DropSource(void); 00111 00112 /* IUnknown interface members */ 00113 STDMETHODIMP QueryInterface(REFIID, LPVOID *); 00114 STDMETHODIMP_(ULONG) AddRef(void); 00115 STDMETHODIMP_(ULONG) Release(void); 00116 00117 /* IDropSource interface members */ 00118 STDMETHODIMP QueryContinueDrag(BOOL, DWORD); 00119 STDMETHODIMP GiveFeedback(DWORD); 00120 }; /* TkDND_DropSource */ 00121 00122 /***************************************************************************** 00123 * Data object Related Class (needed by Drag Source for OLE DND)... 00124 ****************************************************************************/ 00125 class TkDND_DataObject: public IDataObject { 00126 private: 00127 ULONG m_refCnt; /* Reference Count */ 00128 DndInfo *infoPtr; /* Pointer to hash table entry */ 00129 00130 /* The clipboard formats that can be handled */ 00131 UINT m_numTypes; /* Number of types in list */ 00132 UINT m_maxTypes; /* Number of types that fit */ 00133 FORMATETC *m_typeList; /* List of types */ 00134 00135 public: 00136 TkDND_DataObject(DndInfo *infoPtr); 00137 ~TkDND_DataObject(void); 00138 00139 /* IUnknown interface members */ 00140 STDMETHODIMP QueryInterface(REFIID, LPVOID *); 00141 STDMETHODIMP_(ULONG) AddRef(void); 00142 STDMETHODIMP_(ULONG) Release(void); 00143 00144 /* IDataObject interface methods */ 00145 STDMETHODIMP GetData(LPFORMATETC, LPSTGMEDIUM); 00146 STDMETHODIMP GetDataHere(LPFORMATETC, LPSTGMEDIUM); 00147 STDMETHODIMP QueryGetData(LPFORMATETC); 00148 STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC, LPFORMATETC); 00149 STDMETHODIMP SetData(LPFORMATETC, LPSTGMEDIUM, BOOL); 00150 STDMETHODIMP EnumFormatEtc(DWORD, LPENUMFORMATETC *); 00151 STDMETHODIMP DAdvise(LPFORMATETC, DWORD, LPADVISESINK, DWORD *); 00152 STDMETHODIMP DUnadvise(DWORD); 00153 STDMETHODIMP EnumDAdvise(IEnumSTATDATA **); 00154 00155 /* TkDND additional interface methods */ 00156 int AddDataType(UINT clipFormat); 00157 int DelDataType(UINT clipFormat); 00158 }; /* TkDND_DataObject */ 00159 00160 /***************************************************************************** 00161 * Drop Target Related Class. 00162 ****************************************************************************/ 00163 class TkDND_DropTarget; 00164 typedef class TkDND_DropTarget *PTDropTarget; 00165 class TkDND_DropTarget: public IDropTarget { 00166 private: 00167 ULONG m_refCnt; /* Reference count */ 00168 DndInfo *infoPtr; /* Pointer to hash table entry */ 00169 DWORD KeyState; /* Remember KeyState for <DragLeave> */ 00170 LPDATAOBJECT DataObject; /* Keep data object available */ 00171 #ifdef DND_ENABLE_DROP_TARGET_HELPER 00172 CComPtr<IDropTargetHelper> DropHelper; /* IDropTargetHelper support. This 00173 helper does some interesting 00174 things, like drawing explorer 00175 icons during drops... */ 00176 int UseDropHelper; /* A flag whether to use the helper 00177 or not... */ 00178 #endif /* DND_ENABLE_DROP_TARGET_HELPER */ 00179 00180 public: 00181 TkDND_DropTarget(DndInfo *info); 00182 ~TkDND_DropTarget(void); 00183 00184 /* IUnknown interface members */ 00185 STDMETHODIMP QueryInterface(REFIID, LPVOID *); 00186 STDMETHODIMP_(ULONG) AddRef(void); 00187 STDMETHODIMP_(ULONG) Release(void); 00188 00189 /* IDropTarget interface members */ 00190 STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL,LPDWORD); 00191 STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD); 00192 STDMETHODIMP DragLeave(void); 00193 STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD); 00194 00195 /* TkDND additional interface methods */ 00196 DWORD ParseAction(void); 00197 Tcl_Obj *GetAndConvertData(LPDATAOBJECT, 00198 DndType *, char *, FORMATETC *, STGMEDIUM *); 00199 }; /* TkDND_DropTarget */ 00200 00201 #endif _OLE_DND_H