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