2006-06-26 17:18:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-07-08 13:27:43 +00:00
|
|
|
* \file qt4/GuiClipboard.C
|
2006-06-26 17:18:28 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-07-08 13:27:43 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
#include "GuiClipboard.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2007-01-13 18:29:50 +00:00
|
|
|
#include <QMimeData>
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
using lyx::support::internalLineEnding;
|
|
|
|
using lyx::support::externalLineEnding;
|
|
|
|
|
|
|
|
using std::endl;
|
2007-01-13 18:29:50 +00:00
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
char const * const mime_type = "application/x-lyx";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-01-13 18:29:50 +00:00
|
|
|
string const GuiClipboard::getAsLyX() const
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
|
2007-01-13 18:29:50 +00:00
|
|
|
// We don't convert encodings here since the encoding of the
|
|
|
|
// clipboard contents is specified in the data itself
|
|
|
|
QMimeData const * source =
|
|
|
|
qApp->clipboard()->mimeData(QClipboard::Clipboard);
|
|
|
|
if (!source) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::ACTION) << "' (no QMimeData)" << endl;
|
2007-01-13 18:29:50 +00:00
|
|
|
return string();
|
|
|
|
}
|
|
|
|
if (source->hasFormat(mime_type)) {
|
|
|
|
// data from ourself or some other LyX instance
|
|
|
|
QByteArray const ar = source->data(mime_type);
|
|
|
|
string const s(ar.data(), ar.count());
|
2007-04-01 14:35:42 +00:00
|
|
|
LYXERR(Debug::ACTION) << s << "'" << endl;
|
2007-01-13 18:29:50 +00:00
|
|
|
return s;
|
|
|
|
}
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::ACTION) << "'" << endl;
|
2007-01-13 18:29:50 +00:00
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring const GuiClipboard::getAsText() const
|
|
|
|
{
|
|
|
|
// text data from other applications
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
QString const str = qApp->clipboard()->text(QClipboard::Clipboard);
|
2007-04-01 14:35:42 +00:00
|
|
|
LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
|
|
|
|
<< fromqstr(str) << "'" << endl;
|
2006-06-26 17:18:28 +00:00
|
|
|
if (str.isNull())
|
2006-09-03 07:02:38 +00:00
|
|
|
return docstring();
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
return internalLineEnding(qstring_to_ucs4(str));
|
2006-06-26 17:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-13 18:29:50 +00:00
|
|
|
void GuiClipboard::put(string const & lyx, docstring const & text)
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2007-04-01 14:35:42 +00:00
|
|
|
LYXERR(Debug::ACTION) << "GuiClipboard::put(`" << lyx << "' `"
|
|
|
|
<< to_utf8(text) << "')" << endl;
|
2007-01-13 18:29:50 +00:00
|
|
|
// We don't convert the encoding of lyx since the encoding of the
|
|
|
|
// clipboard contents is specified in the data itself
|
|
|
|
QMimeData * data = new QMimeData;
|
|
|
|
if (!lyx.empty()) {
|
|
|
|
QByteArray const qlyx(lyx.c_str(), lyx.size());
|
|
|
|
data->setData(mime_type, qlyx);
|
|
|
|
}
|
|
|
|
// Don't test for text.empty() since we want to be able to clear the
|
|
|
|
// clipboard.
|
|
|
|
QString const qtext = toqstr(text);
|
|
|
|
data->setText(qtext);
|
|
|
|
qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
|
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2007-01-13 18:29:50 +00:00
|
|
|
bool GuiClipboard::hasLyXContents() const
|
|
|
|
{
|
|
|
|
QMimeData const * const source =
|
|
|
|
qApp->clipboard()->mimeData(QClipboard::Clipboard);
|
|
|
|
return source && source->hasFormat(mime_type);
|
2006-06-26 17:18:28 +00:00
|
|
|
}
|
|
|
|
|
2007-01-03 08:53:54 +00:00
|
|
|
|
|
|
|
bool GuiClipboard::isInternal() const
|
|
|
|
{
|
2007-01-27 16:55:25 +00:00
|
|
|
// ownsClipboard() is also true for stuff coming from dialogs, e.g.
|
|
|
|
// the preamble dialog
|
|
|
|
return qApp->clipboard()->ownsClipboard() && hasLyXContents();
|
2007-01-03 08:53:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-07 16:43:38 +00:00
|
|
|
|
|
|
|
bool GuiClipboard::empty() const
|
|
|
|
{
|
2007-02-21 21:47:44 +00:00
|
|
|
// We need to check both the plaintext and the LyX version of the
|
|
|
|
// clipboard. The plaintext version is empty if the LyX version
|
|
|
|
// contains only one inset, and the LyX version is empry if the
|
|
|
|
// clipboard does not come from LyX.
|
|
|
|
if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
|
|
|
|
return false;
|
|
|
|
return !hasLyXContents();
|
2007-01-07 16:43:38 +00:00
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|