Skip to content

Commit 7fe1e13

Browse files
committed
[WIP] Prototype tool panel docking using DnD APIs.
1 parent c8fcc66 commit 7fe1e13

File tree

8 files changed

+928
-55
lines changed

8 files changed

+928
-55
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ APP_OBJS := \
440440
src/PopupTipWindow.$(BUILD_TYPE).o \
441441
src/ProceduralBitmap.$(BUILD_TYPE).o \
442442
src/profile.$(BUILD_TYPE).o \
443+
src/ProxyDropTarget.$(BUILD_TYPE).o \
443444
src/RangeChoiceLinear.$(BUILD_TYPE).o \
444445
src/RangeDialog.$(BUILD_TYPE).o \
445446
src/RangeProcessor.$(BUILD_TYPE).o \
@@ -563,6 +564,7 @@ TEST_OBJS := \
563564
src/Palette.$(BUILD_TYPE).o \
564565
src/PopupTipWindow.$(BUILD_TYPE).o \
565566
src/ProceduralBitmap.$(BUILD_TYPE).o \
567+
src/ProxyDropTarget.$(BUILD_TYPE).o \
566568
src/RangeDialog.$(BUILD_TYPE).o \
567569
src/RangeProcessor.$(BUILD_TYPE).o \
568570
src/search.$(BUILD_TYPE).o \

src/ProxyDropTarget.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* Reverse Engineer's Hex Editor
2+
* Copyright (C) 2025 Daniel Collins <solemnwarning@solemnwarning.net>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 as published by
6+
* the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program; if not, write to the Free Software Foundation, Inc., 51
15+
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16+
*/
17+
18+
#include "platform.hpp"
19+
20+
#include <assert.h>
21+
22+
#include "ProxyDropTarget.hpp"
23+
24+
wxDEFINE_EVENT(REHex::DROP_ENTER, REHex::DropEvent);
25+
wxDEFINE_EVENT(REHex::DROP_LEAVE, REHex::DropEvent);
26+
wxDEFINE_EVENT(REHex::DROP_MOTION, REHex::DropEvent);
27+
wxDEFINE_EVENT(REHex::DROP_DROP, REHex::DropEvent);
28+
wxDEFINE_EVENT(REHex::DROP_DATA, REHex::DropEvent);
29+
30+
REHex::ProxyDropTarget::ProxyDropTarget(wxEvtHandler *handler, wxDataObject *data):
31+
wxDropTarget(data),
32+
m_handler(handler) {}
33+
34+
wxDragResult REHex::ProxyDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult defResult)
35+
{
36+
DropEvent event(DROP_DATA, x, y, defResult);
37+
m_handler->ProcessEvent(event);
38+
39+
return event.m_result;
40+
}
41+
42+
wxDragResult REHex::ProxyDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult defResult)
43+
{
44+
DropEvent event(DROP_MOTION, x, y, defResult);
45+
m_handler->ProcessEvent(event);
46+
47+
return event.m_result;
48+
}
49+
50+
bool REHex::ProxyDropTarget::OnDrop(wxCoord x, wxCoord y)
51+
{
52+
DropEvent event(DROP_DROP, x, y, wxDragNone);
53+
m_handler->ProcessEvent(event);
54+
55+
return event.m_accept;
56+
}
57+
58+
wxDragResult REHex::ProxyDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult defResult)
59+
{
60+
DropEvent event(DROP_ENTER, x, y, defResult);
61+
m_handler->ProcessEvent(event);
62+
63+
return event.m_result;
64+
}
65+
66+
void REHex::ProxyDropTarget::OnLeave()
67+
{
68+
DropEvent event(DROP_LEAVE, -1, -1, wxDragNone);
69+
m_handler->ProcessEvent(event);
70+
}
71+
72+
REHex::DropEvent::DropEvent(wxEventType eventType, wxCoord x, wxCoord y, wxDragResult defResult):
73+
wxEvent(0, eventType),
74+
m_x(x),
75+
m_y(y),
76+
m_default_result(defResult),
77+
m_result(defResult),
78+
m_accept(true) {}
79+
80+
wxEvent *REHex::DropEvent::Clone() const
81+
{
82+
return new DropEvent(*this);
83+
}
84+
85+
wxCoord REHex::DropEvent::GetX() const
86+
{
87+
assert(GetEventType() == DROP_ENTER || GetEventType() == DROP_MOTION || GetEventType() == DROP_DROP || GetEventType() == DROP_DATA);
88+
return m_x;
89+
}
90+
91+
wxCoord REHex::DropEvent::GetY() const
92+
{
93+
assert(GetEventType() == DROP_ENTER || GetEventType() == DROP_MOTION || GetEventType() == DROP_DROP || GetEventType() == DROP_DATA);
94+
return m_y;
95+
}
96+
97+
wxDragResult REHex::DropEvent::GetDefaultResult() const
98+
{
99+
assert(GetEventType() == DROP_ENTER || GetEventType() == DROP_MOTION || GetEventType() == DROP_DATA);
100+
return m_default_result;
101+
}
102+
103+
void REHex::DropEvent::SetResult(wxDragResult result)
104+
{
105+
assert(GetEventType() == DROP_ENTER || GetEventType() == DROP_MOTION || GetEventType() == DROP_DATA);
106+
m_result = result;
107+
}
108+
109+
void REHex::DropEvent::AcceptData(bool accept)
110+
{
111+
assert(GetEventType() == DROP_DROP);
112+
m_accept = accept;
113+
}
114+
115+
void REHex::DropEvent::RejectData()
116+
{
117+
assert(GetEventType() == DROP_DROP);
118+
m_accept = false;
119+
}

src/ProxyDropTarget.hpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Reverse Engineer's Hex Editor
2+
* Copyright (C) 2025 Daniel Collins <solemnwarning@solemnwarning.net>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 as published by
6+
* the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program; if not, write to the Free Software Foundation, Inc., 51
15+
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16+
*/
17+
18+
#ifndef REHEX_PROXYDROPTARGET_HPP
19+
#define REHEX_PROXYDROPTARGET_HPP
20+
21+
#include <wx/dnd.h>
22+
#include <wx/event.h>
23+
24+
namespace REHex
25+
{
26+
class DropEvent;
27+
28+
wxDECLARE_EVENT(DROP_ENTER, DropEvent);
29+
wxDECLARE_EVENT(DROP_LEAVE, DropEvent);
30+
wxDECLARE_EVENT(DROP_MOTION, DropEvent);
31+
wxDECLARE_EVENT(DROP_DROP, DropEvent);
32+
wxDECLARE_EVENT(DROP_DATA, DropEvent);
33+
34+
class ProxyDropTarget: public wxDropTarget
35+
{
36+
private:
37+
wxEvtHandler *m_handler;
38+
39+
public:
40+
ProxyDropTarget(wxEvtHandler *handler, wxDataObject *data = NULL);
41+
42+
virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult defResult) override;
43+
virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult defResult) override;
44+
virtual bool OnDrop(wxCoord x, wxCoord y) override;
45+
virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult defResult) override;
46+
virtual void OnLeave() override;
47+
};
48+
49+
class DropEvent: public wxEvent
50+
{
51+
private:
52+
wxCoord m_x, m_y;
53+
54+
wxDragResult m_default_result;
55+
wxDragResult m_result;
56+
57+
bool m_accept;
58+
59+
public:
60+
DropEvent(wxEventType eventType, wxCoord x, wxCoord y, wxDragResult defResult);
61+
virtual ~DropEvent() override = default;
62+
63+
virtual wxEvent *Clone() const override;
64+
65+
wxCoord GetX() const;
66+
wxCoord GetY() const;
67+
68+
wxDragResult GetDefaultResult() const;
69+
void SetResult(wxDragResult result);
70+
71+
void AcceptData(bool accept);
72+
void RejectData();
73+
74+
friend ProxyDropTarget;
75+
};
76+
}
77+
78+
#endif /* !REHEX_PROXYDROPTARGET_HPP */

0 commit comments

Comments
 (0)