]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiClipboard.C
GUI API Cleanup step 2: merge of the "younes" branch. What's missing
[lyx.git] / src / frontends / qt4 / GuiClipboard.C
1 // -*- C++ -*-
2 /**
3  * \file 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 John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include "GuiClipboard.h"
14 #include "qt_helpers.h"
15
16 #include "debug.h"
17
18 #include <QApplication>
19 #include <QClipboard>
20 #include <QString>
21
22 #include <string>
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 #ifdef Q_WS_X11
35 QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection;
36 #else
37 // FIXME external clipboard support is mostly broken for windows
38 // because the following fixe would involves too much side effects WRT mouse selection.
39 //QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Clipboard;
40 QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection;
41 #endif
42
43 void GuiClipboard::haveSelection(bool own)
44 {
45         if (!qApp->clipboard()->supportsSelection())
46                 return;
47
48         if (own) {
49                 qApp->clipboard()->setText(QString(), CLIPBOARD_MODE);
50         }
51         // We don't need to do anything if own = false, as this case is
52         // handled by QT.
53 }
54
55
56 string const GuiClipboard::get() const
57 {
58         QString str = qApp->clipboard()->text(CLIPBOARD_MODE);
59         lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
60         if (str.isNull())
61                 return string();
62
63         return internalLineEnding(fromqstr(str));
64 }
65
66
67 void GuiClipboard::put(string const & str)
68 {
69         lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
70
71         qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE);
72 }
73
74 } // namespace frontend
75 } // namespace lyx