]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GuiClipboard.C
Extracted from r14281
[lyx.git] / src / frontends / gtk / GuiClipboard.C
1 // -*- C++ -*-
2 /**
3  * \file gtk/GuiClipboard.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Huang Ying
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 // Too hard to make concept checks work with this file
16 #ifdef _GLIBCXX_CONCEPT_CHECKS
17 #undef _GLIBCXX_CONCEPT_CHECKS
18 #endif
19 #ifdef _GLIBCPP_CONCEPT_CHECKS
20 #undef _GLIBCPP_CONCEPT_CHECKS
21 #endif
22
23 #include "GuiClipboard.h"
24 #include "debug.h"
25
26 #include <gtkmm.h>
27
28 using std::endl;
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34 // ENCODING: Gtk::Clipboard returns UTF-8, we assume that the backend
35 // wants ISO-8859-1 and convert it to that.
36 string const GuiClipboard::get() const
37 {
38         Glib::RefPtr<Gtk::Clipboard> clipboard =
39                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
40         string const str = Glib::convert_with_fallback(
41                         clipboard->wait_for_text(), "ISO-8859-1", "UTF-8");
42         lyxerr[Debug::ACTION] << "GuiClipboard::get: " << str << endl;
43         return str;
44 }
45
46
47 // ENCODING: we assume that the backend passes us ISO-8859-1 and
48 // convert from that to UTF-8 before passing to GTK
49 void GuiClipboard::put(string const & str)
50 {
51         lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl;
52         Glib::RefPtr<Gtk::Clipboard> clipboard =
53                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
54         clipboard->set_text(Glib::convert(str, "UTF-8", "ISO-8859-1"));
55 }
56
57 } // namespace frontend
58 } // namespace lyx