Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script_trigger/src/util/Clipboard.cc @ 2069

Last change on this file since 2069 was 1056, checked in by landauf, 17 years ago

don't panic, no codechanges!
added a link to www.orxonox.net

File size: 2.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 *   Windows version inspired by "Copy Text To Clipboard" by Laszlo Szathmary, 2007
28 *      http://www.loria.fr/~szathmar/off/projects/C/CopyTextToClipboard/index.php
29 */
30
31#include "Clipboard.h"
32
33#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
34    #include <windows.h>
35
36    bool toClipboard(std::string text)
37    {
38        try
39        {
40            if (OpenClipboard(0))
41            {
42                EmptyClipboard();
43                HGLOBAL clipbuffer = GlobalAlloc(GMEM_DDESHARE, text.size() + 1);
44                char* buffer = (char*)GlobalLock(clipbuffer);
45                strcpy(buffer, text.c_str());
46                GlobalUnlock(clipbuffer);
47                SetClipboardData(CF_TEXT, clipbuffer);
48                CloseClipboard();
49
50                return true;
51            }
52        }
53        catch (...)
54        {
55        }
56        return false;
57    }
58
59    std::string fromClipboard()
60    {
61        try
62        {
63            if (OpenClipboard(0))
64            {
65                HANDLE hData = GetClipboardData(CF_TEXT);
66                std::string output = (char*)GlobalLock(hData);
67                GlobalUnlock(hData);
68                CloseClipboard();
69
70                return output;
71            }
72        }
73        catch (...)
74        {
75        }
76        return "";
77    }
78#else
79    std::string clipboard = "";
80
81    bool toClipboard(std::string text)
82    {
83        clipboard = text;
84        return true;
85    }
86
87    std::string fromClipboard()
88    {
89        return clipboard;
90    }
91#endif
Note: See TracBrowser for help on using the repository browser.