changeset 137:3665cb9211b2

DropTarget
author Frank Benoit <benoit@tionex.de>
date Wed, 13 Feb 2008 14:52:31 +0100
parents 04e357b8343d
children b479f7e2f431
files dwt/dnd/DropTarget.d dwt/dnd/TableDropTargetEffect.d dwt/dnd/TreeDropTargetEffect.d dwt/internal/win32/OS.d dwt/internal/win32/WINAPI.d
diffstat 5 files changed, 49 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dnd/DropTarget.d	Wed Feb 13 14:24:54 2008 +0100
+++ b/dwt/dnd/DropTarget.d	Wed Feb 13 14:52:31 2008 +0100
@@ -35,6 +35,10 @@
 import dwt.dnd.DNDListener;
 import dwt.dnd.DNDEvent;
 import dwt.dnd.DND;
+import dwt.dnd.TableDropTargetEffect;
+import dwt.dnd.TreeDropTargetEffect;
+
+import dwt.dwthelper.utils;
 
 /**
  *
@@ -154,9 +158,9 @@
     createCOMInterfaces();
     this.AddRef();
 
-    if (COM.CoLockObjectExternal(iDropTarget.getAddress(), true, true) !is COM.S_OK)
+    if (COM.CoLockObjectExternal(iDropTarget, true, true) !is COM.S_OK)
         DND.error(DND.ERROR_CANNOT_INIT_DROP);
-    if (COM.RegisterDragDrop( control.handle, iDropTarget.getAddress()) !is COM.S_OK)
+    if (COM.RegisterDragDrop( control.handle, iDropTarget) !is COM.S_OK)
         DND.error(DND.ERROR_CANNOT_INIT_DROP);
 
     controlListener = new class() Listener {
@@ -233,7 +237,7 @@
     addListener (DND.DropAccept, typedListener);
 }
 
-int AddRef() {
+ULONG AddRef() {
     refCount++;
     return refCount;
 }
@@ -255,20 +259,20 @@
     iDropTarget = null;
 }
 
-int DragEnter(int pDataObject, int grfKeyState, int pt_x, int pt_y, int pdwEffect) {
+HRESULT DragEnter(IDataObject pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) {
     selectedDataType = null;
     selectedOperation = DND.DROP_NONE;
     if (iDataObject !is null) iDataObject.Release();
     iDataObject = null;
 
     DNDEvent event = new DNDEvent();
-    if (!setEventData(event, pDataObject, grfKeyState, pt_x, pt_y, pdwEffect)) {
+    if (!setEventData(event, pDataObject, grfKeyState, pt, pdwEffect)) {
         *pdwEffect = COM.DROPEFFECT_NONE;
         return COM.S_FALSE;
     }
 
     // Remember the iDataObject because it is not passed into the DragOver callback
-    iDataObject = new IDataObject(pDataObject);
+    iDataObject = pDataObject;
     iDataObject.AddRef();
 
     int allowedOperations = event.operations;
@@ -297,7 +301,7 @@
     return COM.S_OK;
 }
 
-int DragLeave() {
+HRESULT DragLeave() {
     keyOperation = -1;
 
     if (iDataObject is null) return COM.S_FALSE;
@@ -314,12 +318,12 @@
     return COM.S_OK;
 }
 
-int DragOver(int grfKeyState, int pt_x, int pt_y, int pdwEffect) {
+HRESULT DragOver(int grfKeyState, POINTL pt, DWORD* pdwEffect) {
     if (iDataObject is null) return COM.S_FALSE;
     int oldKeyOperation = keyOperation;
 
     DNDEvent event = new DNDEvent();
-    if (!setEventData(event, iDataObject.getAddress(), grfKeyState, pt_x, pt_y, pdwEffect)) {
+    if (!setEventData(event, iDataObject, grfKeyState, pt, pdwEffect)) {
         keyOperation = -1;
         *pdwEffect = COM.DROPEFFECT_NONE;
         return COM.S_FALSE;
@@ -360,19 +364,19 @@
     return COM.S_OK;
 }
 
-int Drop(int pDataObject, int grfKeyState, int pt_x, int pt_y, int pdwEffect) {
+HRESULT Drop(IDataObject pDataObject, int grfKeyState, POINTL pt, DWORD* pdwEffect) {
     DNDEvent event = new DNDEvent();
     event.widget = this;
     event.time = OS.GetMessageTime();
     if (dropEffect !is null) {
-        event.item = dropEffect.getItem(pt_x, pt_y);
+        event.item = dropEffect.getItem(pt.x, pt.y);
     }
     event.detail = DND.DROP_NONE;
     notifyListeners(DND.DragLeave, event);
     refresh();
 
     event = new DNDEvent();
-    if (!setEventData(event, pDataObject, grfKeyState, pt_x, pt_y, pdwEffect)) {
+    if (!setEventData(event, pDataObject, grfKeyState, pt, pdwEffect)) {
         keyOperation = -1;
         *pdwEffect = COM.DROPEFFECT_NONE;
         return COM.S_FALSE;
@@ -493,7 +497,7 @@
     transferAgents = null;
     control = null;
 
-    COM.CoLockObjectExternal(iDropTarget.getAddress(), false, true);
+    COM.CoLockObjectExternal(iDropTarget, false, true);
 
     this.Release();
 
@@ -532,12 +536,12 @@
  * Ownership of ppvObject transfers from callee to caller so reference count on ppvObject
  * must be incremented before returning.  Caller is responsible for releasing ppvObject.
  */
-int QueryInterface(int riid, int ppvObject) {
+HRESULT QueryInterface(REFIID riid, void ** ppvObject) {
 
     if (riid is null || ppvObject is null)
         return COM.E_INVALIDARG;
     if (COM.IsEqualGUID(riid, &COM.IIDIUnknown) || COM.IsEqualGUID(riid, &COM.IIDIDropTarget)) {
-        *ppvObject = cast(void*)cast(IUnknown) iDropTarget.getAddress();
+        *ppvObject = cast(void*)cast(IDropTarget) iDropTarget;
         AddRef();
         return COM.S_OK;
     }
@@ -546,7 +550,7 @@
     return COM.E_NOINTERFACE;
 }
 
-int Release() {
+ULONG Release() {
     refCount--;
 
     if (refCount is 0) {
@@ -559,11 +563,11 @@
 
 void refresh() {
     if (control is null || control.isDisposed()) return;
-    int handle = control.handle;
+    auto handle = control.handle;
     RECT lpRect;
     if (OS.GetUpdateRect(handle, &lpRect, false)) {
         OS.ImageList_DragShowNolock(false);
-        OS.RedrawWindow(handle, *lpRect, 0, OS.RDW_UPDATENOW | OS.RDW_INVALIDATE);
+        OS.RedrawWindow(handle, &lpRect, null, OS.RDW_UPDATENOW | OS.RDW_INVALIDATE);
         OS.ImageList_DragShowNolock(true);
     }
 }
@@ -608,8 +612,8 @@
     dropEffect = effect;
 }
 
-bool setEventData(DNDEvent event, int pDataObject, int grfKeyState, int pt_x, int pt_y, int pdwEffect) {
-    if (pDataObject is 0 || pdwEffect is 0) return false;
+bool setEventData(DNDEvent event, IDataObject pDataObject, int grfKeyState, POINTL pt, DWORD* pdwEffect) {
+    if (pDataObject is null || pdwEffect is null) return false;
 
     // get allowed operations
     int style = getStyle();
@@ -631,21 +635,21 @@
 
     // Get allowed transfer types
     TransferData[] dataTypes = new TransferData[0];
-    IDataObject dataObject = new IDataObject(pDataObject);
+    IDataObject dataObject = pDataObject;
     dataObject.AddRef();
     try {
-        int[1] address;
+        IEnumFORMATETC[1] address;
         if (dataObject.EnumFormatEtc(COM.DATADIR_GET, address.ptr) !is COM.S_OK) {
             return false;
         }
-        IEnumFORMATETC enumFormatetc = new IEnumFORMATETC(address[0]);
+        IEnumFORMATETC enumFormatetc = address[0];
         try {
             // Loop over enumerator and save any types that match what we are looking for
-            int rgelt = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, FORMATETC.sizeof);
+            auto rgelt = cast(FORMATETC*) OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, FORMATETC.sizeof);
             try {
-                int[] pceltFetched = new int[1];
+                uint[1] pceltFetched;
                 enumFormatetc.Reset();
-                while (enumFormatetc.Next(1, rgelt, pceltFetched) is COM.S_OK && pceltFetched[0] is 1) {
+                while (enumFormatetc.Next(1, rgelt, pceltFetched.ptr) is COM.S_OK && pceltFetched[0] is 1) {
                     TransferData transferData = new TransferData();
                     transferData.formatetc = new FORMATETC();
                     COM.MoveMemory(transferData.formatetc, rgelt, FORMATETC.sizeof);
@@ -674,14 +678,14 @@
     if (dataTypes.length is 0) return false;
 
     event.widget = this;
-    event.x = pt_x;
-    event.y = pt_y;
+    event.x = pt.x;
+    event.y = pt.y;
     event.time = OS.GetMessageTime();
     event.feedback = DND.FEEDBACK_SELECT;
     event.dataTypes = dataTypes;
     event.dataType = dataTypes[0];
     if (dropEffect !is null) {
-        event.item = dropEffect.getItem(pt_x, pt_y);
+        event.item = dropEffect.getItem(pt.x, pt.y);
     }
     event.operations = operations[0];
     event.detail = operation;
@@ -717,14 +721,14 @@
     ULONG AddRef()  { return parent.AddRef(); }
     ULONG Release() { return parent.Release(); }
 
-    HRESULT DragEnter( IDataObject pDataObj, DWORD grfKeyState, POINT pt, DWORD *pdwEffect ) {
+    HRESULT DragEnter( IDataObject pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect ) {
         return parent.DragEnter(pDataObj, grfKeyState, pt, pdwEffect);
     }
-    HRESULT DragOver( DWORD grfKeyState, POINT pt, DWORD *pdwEffect ) {
+    HRESULT DragOver( DWORD grfKeyState, POINTL pt, DWORD *pdwEffect ) {
         return parent.DragOver(grfKeyState, pt, pdwEffect);
     }
     HRESULT DragLeave(){ return parent.DragLeave(); }
-    HRESULT Drop(IDataObject pDataObj,DWORD grfKeyState,POINT pt,DWORD *pdwEffect){
+    HRESULT Drop(IDataObject pDataObj,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect){
         return parent.Drop(pDataObj, grfKeyState, pt, pdwEffect);
     }
 }
--- a/dwt/dnd/TableDropTargetEffect.d	Wed Feb 13 14:24:54 2008 +0100
+++ b/dwt/dnd/TableDropTargetEffect.d	Wed Feb 13 14:52:31 2008 +0100
@@ -17,6 +17,9 @@
 import dwt.widgets.Table;
 import dwt.widgets.TableItem;
 
+import dwt.dnd.DropTargetEffect;
+import dwt.dnd.DropTargetEvent;
+
 /**
  * This class provides a default drag under effect (eg. select, insert and scroll)
  * when a drag occurs over a <code>Table</code>.
@@ -105,7 +108,7 @@
      * @see DropTargetEvent
      */
     public void dragLeave(DropTargetEvent event) {
-        Table table = (Table) control;
+        Table table = cast(Table) control;
         int handle = table.handle;
         if (dropHighlight !is null) {
             LVITEM lvItem = new LVITEM ();
@@ -135,7 +138,7 @@
      * @see DND#FEEDBACK_SCROLL
      */
     public void dragOver(DropTargetEvent event) {
-        Table table = (Table) getControl();
+        Table table = cast(Table) getControl();
         int effect = checkEffect(event.feedback);
         int handle = table.handle;
         Point coordinates = new Point(event.x, event.y);
--- a/dwt/dnd/TreeDropTargetEffect.d	Wed Feb 13 14:24:54 2008 +0100
+++ b/dwt/dnd/TreeDropTargetEffect.d	Wed Feb 13 14:52:31 2008 +0100
@@ -17,6 +17,9 @@
 import dwt.widgets.Tree;
 import dwt.widgets.TreeItem;
 
+import dwt.dnd.DropTargetEffect;
+import dwt.dnd.DropTargetEvent;
+
 /**
  * This class provides a default drag under effect (eg. select, insert, scroll and expand)
  * when a drag occurs over a <code>Tree</code>.
@@ -116,7 +119,7 @@
      * @see DropTargetEvent
      */
     public void dragLeave(DropTargetEvent event) {
-        Tree tree = (Tree) control;
+        Tree tree = cast(Tree) control;
         int handle = tree.handle;
         if (dropIndex !is -1) {
             TVITEM tvItem = new TVITEM ();
@@ -156,7 +159,7 @@
      * @see DND#FEEDBACK_SCROLL
      */
     public void dragOver(DropTargetEvent event) {
-        Tree tree = (Tree) getControl();
+        Tree tree = cast(Tree) getControl();
         int effect = checkEffect(event.feedback);
         int handle = tree.handle;
         Point coordinates = new Point(event.x, event.y);
@@ -257,7 +260,7 @@
             * Since the insert mark can not be queried from the tree,
             * use the Tree API rather than calling the OS directly.
             */
-            TreeItem item = (TreeItem)tree.getDisplay().findWidget(tree.handle, hItem);
+            TreeItem item = cast(TreeItem)tree.getDisplay().findWidget(tree.handle, hItem);
             if (item !is null) {
                 if (item !is insertItem || before !is insertBefore) {
                     tree.setInsertMark(item, before);
--- a/dwt/internal/win32/OS.d	Wed Feb 13 14:24:54 2008 +0100
+++ b/dwt/internal/win32/OS.d	Wed Feb 13 14:52:31 2008 +0100
@@ -4659,6 +4659,7 @@
 alias WINAPI.ImageList_DragEnter ImageList_DragEnter;
 alias WINAPI.ImageList_DragLeave ImageList_DragLeave;
 alias WINAPI.ImageList_DragMove ImageList_DragMove;
+alias WINAPI.ImageList_DragShowNolock ImageList_DragShowNolock;
 alias WINAPI.ImageList_EndDrag ImageList_EndDrag;
 alias WINAPI.ImageList_GetIcon ImageList_GetIcon;
 alias WINAPI.ImageList_GetIconSize ImageList_GetIconSize;
--- a/dwt/internal/win32/WINAPI.d	Wed Feb 13 14:24:54 2008 +0100
+++ b/dwt/internal/win32/WINAPI.d	Wed Feb 13 14:52:31 2008 +0100
@@ -1605,7 +1605,7 @@
     WINBOOL ImageList_DragLeave(HWND);
     WINBOOL ImageList_DragMove(int, int);
 //     WINBOOL ImageList_SetDragCursorImage(HIMAGELIST, int, int, int);
-//     WINBOOL ImageList_DragShowNolock(WINBOOL);
+    WINBOOL ImageList_DragShowNolock(WINBOOL);
 //     HIMAGELIST ImageList_GetDragImage(POINT*, POINT*);
 //     WINBOOL ImageList_GetIconSize(HIMAGELIST, int*, int*);
 //     WINBOOL ImageList_SetIconSize(HIMAGELIST, int, int);