Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
ControlElementDataObject.cpp
1/*
2 * Copyright (C) 2026 Thales Lima Oliveira <thales.oliveira@uftm.edu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "ControlElementDataObject.h"
19
20ControlElementDataObject::ControlElementDataObject()
21 : wxDataObjectSimple(wxDataFormat(wxT("PSPControlCopy")))
22{
23 // When used for reading clipboard data, we do NOT own the lists by default.
24 m_elementsLists = nullptr;
25 m_ownsLists = false;
26}
27
28ControlElementDataObject::ControlElementDataObject(
29 const std::vector<std::shared_ptr<ControlElement>>& elementList,
30 const std::vector<std::shared_ptr<ConnectionLine>>& connectionList)
31 : wxDataObjectSimple(wxDataFormat(wxT("PSPControlCopy")))
32{
33 m_elementsLists = new ControlElementsLists();
34 m_elementsLists->elementList = elementList;
35 m_elementsLists->connectionList = connectionList;
36 m_ownsLists = true;
37}
38
39ControlElementDataObject::~ControlElementDataObject()
40{
41 if (m_ownsLists && m_elementsLists) {
42 delete m_elementsLists;
43 m_elementsLists = nullptr;
44 }
45}
46
47size_t ControlElementDataObject::GetDataSize() const
48{
49 return sizeof(void*);
50}
51
52bool ControlElementDataObject::GetDataHere(void* buf) const
53{
54 *(ControlElementsLists**)buf = m_elementsLists;
55 return true;
56}
57
58bool ControlElementDataObject::SetData(size_t len, const void* buf)
59{
60 (void)len;
61 m_elementsLists = *(ControlElementsLists**)buf;
62 // The clipboard-owned data object owns the lists, not this stack reader.
63 m_ownsLists = false;
64 return true;
65}
66