1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "ToolBoxDropTarget.h"
21 #include "View/DragAndDrop.h"
22 #include "View/ToolBoxConnector.h"
23 
24 #include <cassert>
25 
26 namespace TrenchBroom {
27     namespace View {
ToolBoxDropTarget(ToolBoxConnector * toolBoxConnector)28         ToolBoxDropTarget::ToolBoxDropTarget(ToolBoxConnector* toolBoxConnector) :
29         wxTextDropTarget(),
30         m_toolBoxConnector(toolBoxConnector) {
31             assert(m_toolBoxConnector != NULL);
32         }
33 
OnEnter(const wxCoord x,const wxCoord y,const wxDragResult def)34         wxDragResult ToolBoxDropTarget::OnEnter(const wxCoord x, const wxCoord y, const wxDragResult def) {
35             if (m_toolBoxConnector->dragEnter(x, y, getDragText()))
36                 return wxTextDropTarget::OnEnter(x, y, wxDragCopy);
37             return wxTextDropTarget::OnEnter(x, y, wxDragNone);
38         }
39 
OnDragOver(const wxCoord x,const wxCoord y,const wxDragResult def)40         wxDragResult ToolBoxDropTarget::OnDragOver(const wxCoord x, const wxCoord y, const wxDragResult def) {
41             if (m_toolBoxConnector->dragMove(x, y, getDragText()))
42                 return wxTextDropTarget::OnDragOver(x, y, wxDragCopy);
43             return wxTextDropTarget::OnDragOver(x, y, wxDragNone);
44         }
45 
OnLeave()46         void ToolBoxDropTarget::OnLeave() {
47             m_toolBoxConnector->dragLeave();
48             wxTextDropTarget::OnLeave();
49         }
50 
OnDropText(const wxCoord x,const wxCoord y,const wxString & data)51         bool ToolBoxDropTarget::OnDropText(const wxCoord x, const wxCoord y, const wxString& data) {
52             return m_toolBoxConnector->dragDrop(x, y, data.ToStdString());
53         }
54 
getDragText() const55         String ToolBoxDropTarget::getDragText() const {
56             wxDropSource* currentDropSource = DropSource::getCurrentDropSource();
57             assert(currentDropSource != NULL);
58             const wxTextDataObject* dataObject = static_cast<wxTextDataObject*>(currentDropSource->GetDataObject());
59             return dataObject->GetText().ToStdString();
60         }
61     }
62 }
63