|
| 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 | +} |
0 commit comments