The Battle for Wesnoth  1.15.11+dev
clipboard.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #include "desktop/clipboard.hpp"
17 #include <algorithm>
18 
19 #include <SDL2/SDL_events.h>
20 #include <SDL2/SDL_clipboard.h>
21 
22 #define CLIPBOARD_FUNCS_DEFINED
23 
24 /*
25  * Note SDL 2.0 has its own clipboard routines, but they don't support
26  * different clipboards (yet).
27  */
28 
29 namespace desktop {
30 
31 namespace clipboard {
32 
33 void copy_to_clipboard(const std::string& text, const bool)
34 {
35  SDL_SetClipboardText(text.c_str());
36 }
37 
38 std::string copy_from_clipboard(const bool)
39 {
40  char* clipboard = SDL_GetClipboardText();
41  if(!clipboard) {
42  return std::string();
43  }
44 
45  const std::string result(clipboard);
46  SDL_free(clipboard);
47  return result;
48 }
49 
50 void handle_system_event(const SDL_Event& /*event*/)
51 {
52 }
53 
54 bool available()
55 {
56  return true;
57 }
58 
59 } // end namespace clipboard
60 
61 } // end namespace desktop
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:54
std::string copy_from_clipboard(const bool)
Copies text from the clipboard.
Definition: clipboard.cpp:38
void handle_system_event(const SDL_Event &)
Definition: clipboard.cpp:50
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:33