]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSelection.C
get rid of QT3_SUPPORT and some cleanup
[lyx.git] / src / frontends / qt4 / GuiSelection.C
1 // -*- C++ -*-
2 /**
3  * \file qt4/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 John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiSelection.h"
16 #include "qt_helpers.h"
17
18 #include "debug.h"
19
20 #include <QApplication>
21 #include <QClipboard>
22 #include <QString>
23
24 #include "support/lstrings.h"
25 using lyx::support::internalLineEnding;
26 using lyx::support::externalLineEnding;
27
28 using std::endl;
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34 void GuiSelection::haveSelection(bool own)
35 {
36         if (!qApp->clipboard()->supportsSelection())
37                 return;
38
39         if (own)
40                 qApp->clipboard()->setText(QString(), QClipboard::Selection);
41         // We don't need to do anything if own = false, as this case is
42         // handled by QT.
43 }
44
45
46 string const GuiSelection::get() const
47 {
48         QString const str = qApp->clipboard()->text(QClipboard::Selection);
49         lyxerr[Debug::ACTION] << "GuiSelection::get: " << fromqstr(str)
50                               << endl;
51         if (str.isNull())
52                 return string();
53
54         return internalLineEnding(fromqstr(str));
55 }
56
57
58 void GuiSelection::put(string const & str)
59 {
60         lyxerr[Debug::ACTION] << "GuiSelection::put: " << str << endl;
61
62         qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
63                                    QClipboard::Selection);
64 }
65
66 } // namespace frontend
67 } // namespace lyx