Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/Clipboard.cc @ 1433

Last change on this file since 1433 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
RevLine 
[966]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[966]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 *
[968]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
[966]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    {
[968]38        try
[966]39        {
[968]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();
[966]49
[968]50                return true;
51            }
[966]52        }
[968]53        catch (...)
54        {
55        }
[966]56        return false;
57    }
58
59    std::string fromClipboard()
60    {
[968]61        try
[966]62        {
[968]63            if (OpenClipboard(0))
64            {
65                HANDLE hData = GetClipboardData(CF_TEXT);
66                std::string output = (char*)GlobalLock(hData);
67                GlobalUnlock(hData);
68                CloseClipboard();
[966]69
[968]70                return output;
71            }
[966]72        }
[968]73        catch (...)
74        {
75        }
[966]76        return "";
77    }
78#else
[968]79    std::string clipboard = "";
80
[966]81    bool toClipboard(std::string text)
82    {
[968]83        clipboard = text;
84        return true;
[966]85    }
[968]86
[966]87    std::string fromClipboard()
88    {
[968]89        return clipboard;
[966]90    }
91#endif
Note: See TracBrowser for help on using the repository browser.