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.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 // Too hard to make concept checks work with this file
16 #ifdef _GLIBCXX_CONCEPT_CHECKS
17 #undef _GLIBCXX_CONCEPT_CHECKS
19 #ifdef _GLIBCPP_CONCEPT_CHECKS
20 #undef _GLIBCPP_CONCEPT_CHECKS
23 #include "GuiSelection.h"
25 #include "BufferView.h"
28 #include "frontends/Application.h"
29 #include "frontends/Gui.h"
30 #include "frontends/LyXView.h"
40 docstring const GuiSelection::get() const
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);
50 void GuiSelection::put(docstring const & str)
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);
60 void GuiSelection::onClipboardGet(Gtk::SelectionData & /*selection_data*/,
63 // FIXME: This assumes only one LyXView
64 lyx::docstring const sel = theApp->gui().view(0).view()->requestSelection();
70 void GuiSelection::onClipboardClear()
72 // FIXME: This assumes only one LyXView
73 theApp->gui().view(0).view()->clearSelection();
77 void GuiSelection::haveSelection(bool 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));
92 } // namespace frontend