|
| 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 | + /** |
| 35 | + * @brief wxDropTarget implementation which raises events in a target wxEvtHandler |
| 36 | + * |
| 37 | + * @param handler wxEvtHandler to receive events. |
| 38 | + * @param data Initial wxDataObject to receive data. |
| 39 | + * |
| 40 | + * This class proxies wxDropTarget to a wxWindow or other wxEvtHandler to be processed there. |
| 41 | + * |
| 42 | + * The following events will be raised: |
| 43 | + * |
| 44 | + * DROP_ENTER - Pointer entered drop target. |
| 45 | + * DROP_LEAVE - Pointer left drop target. |
| 46 | + * DROP_MOTION - Pointer moved within drop target. |
| 47 | + * DROP_DROP - Mouse button was released over drop target. |
| 48 | + * DROP_DATA - Raised after DROP_DROP accepts the data. |
| 49 | + */ |
| 50 | + class ProxyDropTarget: public wxDropTarget |
| 51 | + { |
| 52 | + private: |
| 53 | + wxEvtHandler *m_handler; |
| 54 | + |
| 55 | + public: |
| 56 | + ProxyDropTarget(wxEvtHandler *handler, wxDataObject *data = NULL); |
| 57 | + |
| 58 | + virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult defResult) override; |
| 59 | + virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult defResult) override; |
| 60 | + virtual bool OnDrop(wxCoord x, wxCoord y) override; |
| 61 | + virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult defResult) override; |
| 62 | + virtual void OnLeave() override; |
| 63 | + }; |
| 64 | + |
| 65 | + /** |
| 66 | + * @brief Event object raised by ProxyDropTarget |
| 67 | + */ |
| 68 | + class DropEvent: public wxEvent |
| 69 | + { |
| 70 | + private: |
| 71 | + wxCoord m_x, m_y; |
| 72 | + |
| 73 | + wxDragResult m_default_result; |
| 74 | + wxDragResult m_result; |
| 75 | + |
| 76 | + bool m_accept; |
| 77 | + |
| 78 | + public: |
| 79 | + DropEvent(wxEventType eventType, wxCoord x, wxCoord y, wxDragResult defResult); |
| 80 | + virtual ~DropEvent() override = default; |
| 81 | + |
| 82 | + virtual wxEvent *Clone() const override; |
| 83 | + |
| 84 | + /** |
| 85 | + * @brief Returns the mouse position within the drop target. |
| 86 | + * |
| 87 | + * Valid for DROP_ENTER, DROP_MOTION, DROP_DROP and DROP_DATA events. |
| 88 | + */ |
| 89 | + wxCoord GetX() const; |
| 90 | + |
| 91 | + /** |
| 92 | + * @brief Returns the mouse position within the drop target. |
| 93 | + * |
| 94 | + * Valid for DROP_ENTER, DROP_MOTION, DROP_DROP and DROP_DATA events. |
| 95 | + */ |
| 96 | + wxCoord GetY() const; |
| 97 | + |
| 98 | + /** |
| 99 | + * @brief Returns the requested drag type (move/copy/etc). |
| 100 | + * |
| 101 | + * Valid for DROP_ENTER, DROP_MOTION and DROP_DATA events. |
| 102 | + */ |
| 103 | + wxDragResult GetDefaultResult() const; |
| 104 | + |
| 105 | + /** |
| 106 | + * @brief Set the drag event type. |
| 107 | + * |
| 108 | + * Valid for DROP_ENTER, DROP_MOTION and DROP_DATA events. Defaults to the value |
| 109 | + * returned by GetDefaultResult(). |
| 110 | + */ |
| 111 | + void SetResult(wxDragResult result); |
| 112 | + |
| 113 | + /** |
| 114 | + * @brief Accept the data in a DROP_DROP event. |
| 115 | + * |
| 116 | + * The default behaviour is to accept data if AcceptData() or RejectData() is not |
| 117 | + * called within the DROP_DROP event. |
| 118 | + */ |
| 119 | + void AcceptData(bool accept = true); |
| 120 | + |
| 121 | + /** |
| 122 | + * @brief Reject the data in a DROP_DROP event. |
| 123 | + * * The default behaviour is to accept data if AcceptData() or RejectData() is not |
| 124 | + * called within the DROP_DROP event. |
| 125 | + */ |
| 126 | + void RejectData(); |
| 127 | + |
| 128 | + friend ProxyDropTarget; |
| 129 | + }; |
| 130 | +} |
| 131 | + |
| 132 | +#endif /* !REHEX_PROXYDROPTARGET_HPP */ |
0 commit comments