FlightGear
next
ClipboardWindows.cxx
Go to the documentation of this file.
1
// Windows implementation of clipboard access for Nasal
2
//
3
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
4
//
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License as
7
// published by the Free Software Foundation; either version 2 of the
8
// License, or (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful, but
11
// WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19
#include "
NasalClipboard.hxx
"
20
21
#include <simgear/debug/logstream.hxx>
22
#include <windows.h>
23
28
class
ClipboardWindows
:
29
public
NasalClipboard
30
{
31
public
:
32
36
virtual
std::string
getText
(
Type
type)
37
{
38
if
( type ==
CLIPBOARD
)
39
{
40
std::string data;
41
42
if
( !OpenClipboard(NULL) )
43
return
data;
44
45
HANDLE hData = GetClipboardData( CF_TEXT );
46
char
* buff = (
char
*)GlobalLock( hData );
47
if
(buff)
48
data = buff;
49
GlobalUnlock( hData );
50
CloseClipboard();
51
52
return
data;
53
}
54
else
55
return
_selection
;
56
}
57
61
virtual
bool
setText
(
const
std::string& text,
Type
type)
62
{
63
if
( type ==
CLIPBOARD
)
64
{
65
if
( !OpenClipboard(NULL) )
66
return
false
;
67
68
bool
ret =
true
;
69
if
( !EmptyClipboard() )
70
ret =
false
;
71
else
if
( !text.empty() )
72
{
73
HGLOBAL hGlob = GlobalAlloc(GMEM_MOVEABLE, text.size() + 1);
74
if
( !hGlob )
75
ret =
false
;
76
else
77
{
78
memcpy(GlobalLock(hGlob), (
char
*)&text[0], text.size() + 1);
79
GlobalUnlock(hGlob);
80
81
if
( !SetClipboardData(CF_TEXT, hGlob) )
82
{
83
GlobalFree(hGlob);
84
ret =
false
;
85
}
86
}
87
}
88
89
CloseClipboard();
90
return
ret;
91
}
92
else
93
{
94
_selection
= text;
95
return
true
;
96
}
97
}
98
99
protected
:
100
101
std::string
_selection
;
102
};
103
104
//------------------------------------------------------------------------------
105
NasalClipboard::Ptr
NasalClipboard::create
()
106
{
107
return
NasalClipboard::Ptr
(
new
ClipboardWindows
);
108
}
NasalClipboard.hxx
ClipboardWindows
Windows does only support on clipboard and no selection.
Definition
ClipboardWindows.cxx:30
ClipboardWindows::_selection
std::string _selection
Definition
ClipboardWindows.cxx:101
ClipboardWindows::getText
virtual std::string getText(Type type)
Get clipboard contents as text.
Definition
ClipboardWindows.cxx:36
ClipboardWindows::setText
virtual bool setText(const std::string &text, Type type)
Set clipboard contents as text.
Definition
ClipboardWindows.cxx:61
NasalClipboard
Definition
NasalClipboard.hxx:28
NasalClipboard::create
static Ptr create()
Implementation supplied by actual platform implementation.
Definition
ClipboardFallback.cxx:61
NasalClipboard::Type
Type
Definition
NasalClipboard.hxx:32
NasalClipboard::CLIPBOARD
@ CLIPBOARD
Standard clipboard as supported by nearly all operating systems.
Definition
NasalClipboard.hxx:34
NasalClipboard::Ptr
std::shared_ptr< NasalClipboard > Ptr
Definition
NasalClipboard.hxx:42
src
Scripting
ClipboardWindows.cxx
Generated on Tue Jun 3 2025 12:58:41 for FlightGear by
1.13.2