]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GuiSelection.C
Split clipboard and X selection
[lyx.git] / src / frontends / gtk / GuiSelection.C
1 // -*- C++ -*-
2 /**
3  * \file gtk/GuiSelection.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 "GuiSelection.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 // FIXME: Wrong!
37 string const GuiSelection::get() const
38 {
39         Glib::RefPtr<Gtk::Clipboard> clipboard =
40                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
41         string const str = Glib::convert_with_fallback(
42                         clipboard->wait_for_text(), "ISO-8859-1", "UTF-8");
43         lyxerr[Debug::ACTION] << "GuiClipboard::get: " << str << endl;
44         return str;
45 }
46
47
48 // ENCODING: we assume that the backend passes us ISO-8859-1 and
49 // convert from that to UTF-8 before passing to GTK
50 // FIXME: Wrong!
51 void GuiSelection::put(string const & str)
52 {
53         lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl;
54         Glib::RefPtr<Gtk::Clipboard> clipboard =
55                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
56         clipboard->set_text(Glib::convert(str, "UTF-8", "ISO-8859-1"));
57 }
58
59 } // namespace frontend
60 } // namespace lyx