]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiClipboard.C
* src/frontends/gtk/GuiImplementation.C: include config.h
[lyx.git] / src / frontends / qt4 / GuiClipboard.C
1 // -*- C++ -*-
2 /**
3  * \file qt4/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 <config.h>
14
15 #include "GuiClipboard.h"
16 #include "qt_helpers.h"
17
18 #include "debug.h"
19
20 #include <QApplication>
21 #include <QClipboard>
22 #include <QString>
23
24 #include <string>
25
26 #include "support/lstrings.h"
27 using lyx::support::internalLineEnding;
28 using lyx::support::externalLineEnding;
29
30 using std::endl;
31 using std::string;
32
33 namespace lyx {
34 namespace frontend {
35
36 #ifdef Q_WS_X11
37 QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection;
38 #else
39 // FIXME external clipboard support is mostly broken for windows
40 // because the following fixe would involves too much side effects WRT mouse selection.
41 //QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Clipboard;
42 QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection;
43 #endif
44
45 void GuiClipboard::haveSelection(bool own)
46 {
47         if (!qApp->clipboard()->supportsSelection())
48                 return;
49
50         if (own) {
51                 qApp->clipboard()->setText(QString(), CLIPBOARD_MODE);
52         }
53         // We don't need to do anything if own = false, as this case is
54         // handled by QT.
55 }
56
57
58 string const GuiClipboard::get() const
59 {
60         QString str = qApp->clipboard()->text(CLIPBOARD_MODE);
61         lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
62         if (str.isNull())
63                 return string();
64
65         return internalLineEnding(fromqstr(str));
66 }
67
68
69 void GuiClipboard::put(string const & str)
70 {
71         lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
72
73         qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE);
74 }
75
76 } // namespace frontend
77 } // namespace lyx