]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GuiSelection.C
make it compile again
[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
25 #include "BufferView.h"
26 #include "debug.h"
27
28 #include "frontends/Application.h"
29 #include "frontends/Gui.h"
30 #include "frontends/LyXView.h"
31
32 #include <gtkmm.h>
33
34 using std::endl;
35 using std::string;
36
37 namespace lyx {
38 namespace frontend {
39
40 docstring const GuiSelection::get() const
41 {
42         Glib::RefPtr<Gtk::Clipboard> clipboard =
43                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
44         string const str = clipboard->wait_for_text();
45         lyxerr[Debug::ACTION] << "GuiSelection::get: " << str << endl;
46         return lyx::from_utf8(str);
47 }
48
49
50 void GuiSelection::put(docstring const & str)
51 {
52         string const utf8 = lyx::to_utf8(str);
53         lyxerr[Debug::ACTION] << "GuiSelection::put: " << utf8 << endl;
54         Glib::RefPtr<Gtk::Clipboard> clipboard =
55                 Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
56         clipboard->set_text(utf8);
57 }
58
59
60 void GuiSelection::onClipboardGet(Gtk::SelectionData & /*selection_data*/,
61                 guint /*info*/)
62 {
63         // FIXME: This assumes only one LyXView
64         lyx::docstring const sel = theApp->gui().view(0).view()->requestSelection();
65         if (!sel.empty())
66                 put(sel);
67 }
68
69
70 void GuiSelection::onClipboardClear()
71 {
72         // FIXME: This assumes only one LyXView
73         theApp->gui().view(0).view()->clearSelection();
74 }
75
76
77 void GuiSelection::haveSelection(bool toHave)
78 {
79         if (toHave) {
80                 Glib::RefPtr<Gtk::Clipboard> clipboard =
81                         Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
82                 std::vector<Gtk::TargetEntry> listTargets;
83                 listTargets.push_back(Gtk::TargetEntry("UTF8_STRING"));
84                 clipboard->set(listTargets,
85                                 sigc::mem_fun(const_cast<GuiSelection&>(*this),
86                                         &GuiSelection::onClipboardGet),
87                                 sigc::mem_fun(const_cast<GuiSelection&>(*this),
88                                         &GuiSelection::onClipboardClear));
89         }
90 }
91
92 } // namespace frontend
93 } // namespace lyx