← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3168: select the tab being dragged over during a drag & drop operation

 

------------------------------------------------------------
revno: 3168
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2013-01-18 21:17:24 +0100
message:
  select the tab being dragged over during a drag & drop operation
modified:
  dwt/include/dwt/widgets/TabView.h
  dwt/include/dwt/widgets/TextBox.h
  dwt/src/widgets/TabView.cpp
  dwt/src/widgets/TextBox.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/widgets/TabView.h'
--- dwt/include/dwt/widgets/TabView.h	2012-06-01 17:26:20 +0000
+++ dwt/include/dwt/widgets/TabView.h	2013-01-18 20:17:24 +0000
@@ -157,6 +157,8 @@
 		control(control), w(w), icon(icon), handleContextMenu(nullptr), marked(false) { }
 	};
 
+	class Dropper;
+
 	Theme theme;
 	ToolTipPtr tip;
 

=== modified file 'dwt/include/dwt/widgets/TextBox.h'
--- dwt/include/dwt/widgets/TextBox.h	2012-12-21 22:50:48 +0000
+++ dwt/include/dwt/widgets/TextBox.h	2013-01-18 20:17:24 +0000
@@ -202,6 +202,8 @@
 	static Message getUpdateMessage();
 
 private:
+	class Dropper;
+
 	unsigned lines;
 	Menu::Seed menuSeed;
 };

=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp	2012-11-05 20:39:11 +0000
+++ dwt/src/widgets/TabView.cpp	2013-01-18 20:17:24 +0000
@@ -75,6 +75,89 @@
 {
 }
 
+/* general drag & drop COM interface. this selects tabs when the mouse hovers their header during
+a drag & drop operation. nothing happens when a drop actually occurs however. */
+
+class TabView::Dropper : public IDropTarget {
+public:
+	Dropper(TabView* const w) : IDropTarget(), w(w), ref(0), dragging(false) { }
+
+	virtual HRESULT STDMETHODCALLTYPE QueryInterface(
+		/* [in] */ REFIID riid,
+		/* [iid_is][out]  _COM_Outptr_*/ void __RPC_FAR *__RPC_FAR *ppvObject)
+	{
+		if(!ppvObject) { return E_POINTER; }
+		if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropTarget)) {
+			*ppvObject = this;
+			AddRef();
+			return S_OK;
+		}
+		return E_NOINTERFACE;
+	}
+
+	virtual ULONG STDMETHODCALLTYPE AddRef( void)
+	{
+		return ++ref;
+	}
+
+	virtual ULONG STDMETHODCALLTYPE Release( void)
+	{
+		if(--ref == 0) { delete this; }
+		return ref;
+	}
+
+	virtual HRESULT STDMETHODCALLTYPE DragEnter(
+		/* [unique][in]  __RPC__in_opt*/ IDataObject * /*pDataObj*/,
+		/* [in] */ DWORD /*grfKeyState*/,
+		/* [in] */ POINTL pt,
+		/* [out][in]  __RPC__inout*/ DWORD *pdwEffect)
+	{
+		setPoint(pt);
+		*pdwEffect = dragging ? DROPEFFECT_COPY : DROPEFFECT_NONE;
+		return S_OK;
+	}
+
+	virtual HRESULT STDMETHODCALLTYPE DragOver(
+		/* [in] */ DWORD /*grfKeyState*/,
+		/* [in] */ POINTL pt,
+		/* [out][in]  __RPC__inout*/ DWORD *pdwEffect)
+	{
+		setPoint(pt);
+		*pdwEffect = dragging ? DROPEFFECT_COPY : DROPEFFECT_NONE;
+		return S_OK;
+	}
+
+	virtual HRESULT STDMETHODCALLTYPE DragLeave( void)
+	{
+		dragging = false;
+		return S_OK;
+	}
+
+	virtual HRESULT STDMETHODCALLTYPE Drop(
+		/* [unique][in]  __RPC__in_opt*/ IDataObject * /*pDataObj*/,
+		/* [in] */ DWORD /*grfKeyState*/,
+		/* [in] */ POINTL /*pt*/,
+		/* [out][in]  __RPC__inout*/ DWORD *pdwEffect)
+	{
+		*pdwEffect = DROPEFFECT_NONE;
+		return S_OK;
+	}
+
+private:
+	inline void setPoint(const POINTL& pt) {
+		auto i = w->hitTest(ScreenCoordinate(Point(pt.x, pt.y)));
+		auto tab = w->getTabInfo(i);
+		dragging = tab;
+		if(dragging && tab->w != w->getActive()) {
+			w->setActive(i);
+		}
+	}
+
+	TabView* const w;
+	ULONG ref;
+	bool dragging;
+};
+
 void TabView::create(const Seed & cs) {
 	if(cs.ctrlTab) {
 		addAccel(FCONTROL, VK_TAB, [this] { handleCtrlTab(false); });
@@ -132,6 +215,13 @@
 		tip->addRemoveStyle(TTS_NOPREFIX, true);
 		tip->onRaw([this](WPARAM, LPARAM lParam) { return handleToolTip(lParam); }, Message(WM_NOTIFY, TTN_GETDISPINFO));
 	}
+
+	auto dropper = new Dropper(this);
+	if(::RegisterDragDrop(handle(), dropper) == S_OK) {
+		onDestroy([this] { ::RevokeDragDrop(handle()); });
+	} else {
+		delete dropper;
+	}
 }
 
 void TabView::add(ContainerPtr w, const IconPtr& icon) {

=== modified file 'dwt/src/widgets/TextBox.cpp'
--- dwt/src/widgets/TextBox.cpp	2012-12-21 22:50:48 +0000
+++ dwt/src/widgets/TextBox.cpp	2013-01-18 20:17:24 +0000
@@ -59,7 +59,10 @@
 {
 }
 
-class Dropper : public IDropTarget {
+/* drag & drop COM interface. this allows one to drop text inside this text box. during the drag,
+the caret moves inside the box to show where the drop will occur. */
+
+class TextBoxBase::Dropper : public IDropTarget {
 public:
 	Dropper(TextBoxBase* const w) : IDropTarget(), w(w), ref(0), dragging(false) { }