The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
clipboard.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #include "desktop/clipboard.hpp"
19 #include <algorithm>
20 
21 #include <SDL_events.h>
22 #include <SDL_clipboard.h>
23 
24 #define CLIPBOARD_FUNCS_DEFINED
25 
26 /*
27  * Note SDL 2.0 has its own clipboard routines, but they don't support
28  * different clipboards (yet).
29  */
30 
31 namespace desktop {
32 
33 namespace clipboard {
34 
35 void copy_to_clipboard(const std::string& text, const bool)
36 {
37  SDL_SetClipboardText(text.c_str());
38 }
39 
41 {
42  char* clipboard = SDL_GetClipboardText();
43  if(!clipboard) {
44  return std::string();
45  }
46 
47  const std::string result(clipboard);
48  SDL_free(clipboard);
49  return result;
50 }
51 
52 void handle_system_event(const SDL_Event& /*event*/)
53 {
54 }
55 
56 bool available()
57 {
58  return true;
59 }
60 
61 } // end namespace clipboard
62 
63 } // end namespace desktop
64 
std::vector< char_t > string
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:56
std::string copy_from_clipboard(const bool)
Copies text from the clipboard.
Definition: clipboard.cpp:40
void handle_system_event(const SDL_Event &)
Definition: clipboard.cpp:52
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:35