diff --git a/examples/draganddrop/source/draganddrop_sample.d b/examples/draganddrop/source/draganddrop_sample.d index e46ab30..cb711c7 100644 --- a/examples/draganddrop/source/draganddrop_sample.d +++ b/examples/draganddrop/source/draganddrop_sample.d @@ -36,10 +36,7 @@ class MainForm : Form } else { - this.load ~= (Control sender, EventArgs e) { - // TODO: Currently it must be set after the handle is created. - this.allowDrop = true; - }; + this.allowDrop = true; this.dragEnter ~= (Control sender, DragEventArgs e) { // Do nothing }; @@ -72,6 +69,7 @@ class MainForm : Form { _label.text = _label.text ~ fileName ~ "\n"; } + this.allowDrop = false; // Example: Accept only once. }; this.dragLeave ~= (Control sender, EventArgs e) { // Do nothing diff --git a/source/dfl/control.d b/source/dfl/control.d index c5016ef..419585d 100644 --- a/source/dfl/control.d +++ b/source/dfl/control.d @@ -1057,7 +1057,7 @@ class Control: DObject, IWindow // docmain version(DFL_NO_DRAG_DROP) {} else { /// - @property void allowDrop(bool byes) // setter + private void allowDropImplement(bool byes) { /+ if(dyes) @@ -1070,9 +1070,9 @@ class Control: DObject, IWindow // docmain { if(!droptarget) { - droptarget = new DropTarget(this); if(isHandleCreated) { + droptarget = new DropTarget(this); switch(RegisterDragDrop(hwnd, droptarget)) { case S_OK: @@ -1090,11 +1090,32 @@ class Control: DObject, IWindow // docmain } else { - destroy(droptarget); // delete is deprecated. - RevokeDragDrop(hwnd); + if(droptarget) + { + destroy(droptarget); // delete is deprecated. + droptarget = null; + switch(RevokeDragDrop(hwnd)) + { + case S_OK: + break; + case DRAGDROP_E_NOTREGISTERED: + case DRAGDROP_E_INVALIDHWND: + case E_OUTOFMEMORY: + throw new DflException("Unable to revoke drag-drop"); + default: + assert(0); + } + } } } + /// + @property void allowDrop(bool byes) // setter + { + _allowDrop = byes; + allowDropImplement(_allowDrop); + } + /// ditto @property bool allowDrop() // getter { @@ -1102,7 +1123,7 @@ class Control: DObject, IWindow // docmain return (_exStyle() & WS_EX_ACCEPTFILES) != 0; +/ - return droptarget !is null; + return _allowDrop; } } @@ -4575,14 +4596,11 @@ class Control: DObject, IWindow // docmain version(DFL_NO_DRAG_DROP) {} else { - if(droptarget) - { - if(S_OK != RegisterDragDrop(hwnd, droptarget)) - { - droptarget = null; - throw new DflException("Unable to register drag-drop"); - } - } + // Need to do "allowDrop = true/false" after created handle. + // When do "allowDrop = true" in MyForm.this(), + // Now is _allowDrop == true and droptarget is null. + // Therefore call here allowDropImplement() without change _allowDrop value. + allowDropImplement(_allowDrop); } debug @@ -7165,6 +7183,7 @@ class Control: DObject, IWindow // docmain version(DFL_NO_DRAG_DROP) {} else { DropTarget droptarget = null; + bool _allowDrop = false; } // Note: WS_VISIBLE is not reliable.