From c9c6ed0b7fbccbbed8b5ef48d05cfefa5acfb99e Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 10 Jul 2006 11:32:25 +0000 Subject: [PATCH] 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 --- lib/ui/stdmenus.ui | 4 +- src/BufferView_pimpl.C | 4 +- src/CutAndPaste.C | 4 +- src/LyXAction.C | 1 + src/frontends/Clipboard.h | 14 ++++-- src/frontends/Gui.h | 3 ++ src/frontends/Makefile.am | 1 + src/frontends/Selection.h | 51 ++++++++++++++++++++ src/frontends/gtk/GuiClipboard.C | 6 ++- src/frontends/gtk/GuiClipboard.h | 14 ------ src/frontends/gtk/GuiImplementation.C | 4 +- src/frontends/gtk/GuiImplementation.h | 12 ++++- src/frontends/gtk/GuiSelection.C | 60 ++++++++++++++++++++++++ src/frontends/gtk/GuiSelection.h | 55 ++++++++++++++++++++++ src/frontends/gtk/Makefile.am | 1 + src/frontends/gtk/ghelpers.C | 1 + src/frontends/qt3/GuiClipboard.C | 4 +- src/frontends/qt3/GuiClipboard.h | 14 ------ src/frontends/qt3/GuiImplementation.h | 16 +++++-- src/frontends/qt3/GuiSelection.C | 55 ++++++++++++++++++++++ src/frontends/qt3/GuiSelection.h | 55 ++++++++++++++++++++++ src/frontends/qt3/Makefile.am | 1 + src/frontends/qt4/GuiClipboard.C | 27 ++--------- src/frontends/qt4/GuiClipboard.h | 3 -- src/frontends/qt4/GuiImplementation.C | 6 +++ src/frontends/qt4/GuiImplementation.h | 4 ++ src/frontends/qt4/GuiSelection.C | 67 +++++++++++++++++++++++++++ src/frontends/qt4/GuiSelection.h | 42 +++++++++++++++++ src/frontends/qt4/Makefile.am | 1 + src/insets/insetbox.C | 1 + src/insets/insetcharstyle.C | 1 + src/insets/insetert.C | 2 + src/insets/insettabular.C | 6 ++- src/lfuns.h | 1 + src/mathed/math_nestinset.C | 6 +-- src/text3.C | 27 ++++++++--- 36 files changed, 488 insertions(+), 86 deletions(-) create mode 100644 src/frontends/Selection.h create mode 100644 src/frontends/gtk/GuiSelection.C create mode 100644 src/frontends/gtk/GuiSelection.h create mode 100644 src/frontends/qt3/GuiSelection.C create mode 100644 src/frontends/qt3/GuiSelection.h create mode 100644 src/frontends/qt4/GuiSelection.C create mode 100644 src/frontends/qt4/GuiSelection.h diff --git a/lib/ui/stdmenus.ui b/lib/ui/stdmenus.ui index c03fcbe1fa..958abb3ad3 100644 --- a/lib/ui/stdmenus.ui +++ b/lib/ui/stdmenus.ui @@ -85,7 +85,7 @@ Menuset Item "Copy" "copy" Item "Paste" "paste" Submenu "Paste Recent" "pasterecent" - Submenu "Paste External Selection" "edit_paste" + Submenu "Paste External Clipboard/Selection" "edit_paste" Separator Item "Find & Replace...|F" "dialog-show findreplace" Separator @@ -118,6 +118,8 @@ Menuset End Menu "edit_paste" + Item "Clipboard as Lines|C" "clipboard-paste" + Item "Clipboard as Paragraphs|a" "clipboard-paste paragraph" Item "Selection as Lines|L" "primary-selection-paste" Item "Selection as Paragraphs|P" "primary-selection-paste paragraph" End diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index ea31aa1c46..95d85786b4 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -57,12 +57,12 @@ #include "insets/insettext.h" #include "frontends/Alert.h" -#include "frontends/Clipboard.h" #include "frontends/Dialogs.h" #include "frontends/FileDialog.h" #include "frontends/font_metrics.h" #include "frontends/Gui.h" #include "frontends/LyXView.h" +#include "frontends/Selection.h" #include "graphics/Previews.h" @@ -589,7 +589,7 @@ void BufferView::Pimpl::selectionRequested() xsel_cache_.set = cur.selection(); sel = cur.selectionAsString(false); if (!sel.empty()) - owner_->gui().clipboard().put(sel); + owner_->gui().selection().put(sel); } } diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index a418054c95..d88785bb14 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -498,8 +498,8 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut) // solved by running the line below only when the selection has // finished. The solution used currently just works, to make it // faster we need to be more clever and probably also have more - // calls to stuffClipboard. (Lgb) -// cur.bv().owner()->gui().clipboard().put(cur.selectionAsString(true)); + // calls to cur.bv().owner()->gui().selection().put. (Lgb) +// cur.bv().owner()->gui().selection().put(cur.selectionAsString(true)); // make sure that the depth behind the selection are restored, too diff --git a/src/LyXAction.C b/src/LyXAction.C index 8f52f86a08..ddef58b000 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -134,6 +134,7 @@ void LyXAction::init() { LFUN_CHAR_DELETE_FORWARD, "delete-forward", SingleParUpdate }, { LFUN_CHAR_FORWARD, "char-forward", ReadOnly | NoUpdate}, { LFUN_CHAR_FORWARD_SELECT, "forward-select", ReadOnly | SingleParUpdate }, + { LFUN_CLIPBOARD_PASTE, "clipboard-paste", Noop }, { LFUN_COMMAND_EXECUTE, "command-execute", NoBuffer }, { LFUN_COMMAND_PREFIX, "command-prefix", NoBuffer }, { LFUN_COMMAND_SEQUENCE, "command-sequence", NoBuffer }, diff --git a/src/frontends/Clipboard.h b/src/frontends/Clipboard.h index ca046429fe..d871b114e7 100644 --- a/src/frontends/Clipboard.h +++ b/src/frontends/Clipboard.h @@ -27,11 +27,17 @@ class Clipboard public: virtual ~Clipboard() {} - /// a selection exists - virtual void haveSelection(bool) = 0; - /// get the X clipboard contents + /** + * Get the window system clipboard contents. + * This should be called when the user requests to paste from the + * clipboard. + */ virtual std::string const get() const = 0; - /// fill the clipboard + /** + * Fill the window system clipboard. + * This should be called when the user requests to cut or copy to + * the clipboard. + */ virtual void put(std::string const &) = 0; }; diff --git a/src/frontends/Gui.h b/src/frontends/Gui.h index 7632177048..0260b1a366 100644 --- a/src/frontends/Gui.h +++ b/src/frontends/Gui.h @@ -25,6 +25,7 @@ namespace lyx { namespace frontend { class Clipboard; +class Selection; class WorkArea; @@ -38,6 +39,8 @@ public: /// virtual Clipboard & clipboard() = 0; + /// + virtual Selection & selection() = 0; /// virtual int newView(unsigned int width, unsigned int height) = 0; diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index 2e6d5c5a6d..b392163b97 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -32,6 +32,7 @@ libfrontends_la_SOURCES = \ Toolbars.h \ Clipboard.h \ Gui.h \ + Selection.h \ WorkArea.C \ WorkArea.h \ font_metrics.h \ diff --git a/src/frontends/Selection.h b/src/frontends/Selection.h new file mode 100644 index 0000000000..45ce213cd0 --- /dev/null +++ b/src/frontends/Selection.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +/** + * \file Selection.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef BASE_SELECTION_H +#define BASE_SELECTION_H + +#include + +namespace lyx { +namespace frontend { + +/** + * A Selection class manages the selection. + */ +class Selection +{ +public: + virtual ~Selection() {} + + /// Tell the window system whether we have a selection. + virtual void haveSelection(bool) = 0; + /** + * Get the X selection contents. + * This is a noop on systems that don't have a selection. + * The format is plain text. + * This should be called when the user presses the middle mouse + * button. + */ + virtual std::string const get() const = 0; + /** + * Fill the X selection. + * Does nothing on systems that don't have a selection. + * This should be called whenever some text is highlighted. + */ + virtual void put(std::string const &) = 0; +}; + +} // namespace frontend +} // namespace lyx + +#endif // BASE_SELECTION_H diff --git a/src/frontends/gtk/GuiClipboard.C b/src/frontends/gtk/GuiClipboard.C index 7aecf524dd..60895d462d 100644 --- a/src/frontends/gtk/GuiClipboard.C +++ b/src/frontends/gtk/GuiClipboard.C @@ -33,10 +33,11 @@ namespace frontend { // ENCODING: Gtk::Clipboard returns UTF-8, we assume that the backend // wants ISO-8859-1 and convert it to that. +// FIXME: Wrong! string const GuiClipboard::get() const { Glib::RefPtr clipboard = - Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); + Gtk::Clipboard::get(GDK_SELECTION_CLIPBOARD); string const str = Glib::convert_with_fallback( clipboard->wait_for_text(), "ISO-8859-1", "UTF-8"); lyxerr[Debug::ACTION] << "GuiClipboard::get: " << str << endl; @@ -46,11 +47,12 @@ string const GuiClipboard::get() const // ENCODING: we assume that the backend passes us ISO-8859-1 and // convert from that to UTF-8 before passing to GTK +// FIXME: Wrong! void GuiClipboard::put(string const & str) { lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl; Glib::RefPtr clipboard = - Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); + Gtk::Clipboard::get(GDK_SELECTION_CLIPBOARD); clipboard->set_text(Glib::convert(str, "UTF-8", "ISO-8859-1")); } diff --git a/src/frontends/gtk/GuiClipboard.h b/src/frontends/gtk/GuiClipboard.h index 93edbfe321..adb1ec7ed0 100644 --- a/src/frontends/gtk/GuiClipboard.h +++ b/src/frontends/gtk/GuiClipboard.h @@ -14,8 +14,6 @@ #include "frontends/Clipboard.h" -#include "GWorkArea.h" - namespace lyx { namespace frontend { @@ -25,28 +23,16 @@ namespace frontend { class GuiClipboard: public lyx::frontend::Clipboard { public: - GuiClipboard(GWorkArea * work_area) - : old_work_area_(work_area) - { - } - virtual ~GuiClipboard() {} /** Clipboard overloaded methods */ //@{ - void haveSelection(bool own) - { - old_work_area_->haveSelection(own); - } std::string const get() const; void put(std::string const & str); //@} - -private: - GWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/gtk/GuiImplementation.C b/src/frontends/gtk/GuiImplementation.C index da19b610c5..622aca7fce 100644 --- a/src/frontends/gtk/GuiImplementation.C +++ b/src/frontends/gtk/GuiImplementation.C @@ -39,7 +39,7 @@ int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int /*view_id old_work_area_.reset(new GWorkArea(*view_.get(), w, h)); old_screen_.reset(new GScreen(*old_work_area_.get())); work_area_.reset(new GuiWorkArea(old_screen_.get(), old_work_area_.get())); - clipboard_.reset(new GuiClipboard(old_work_area_.get())); + selection_.reset(new GuiSelection(old_work_area_.get())); // FIXME BufferView creation should be independant of WorkArea creation buffer_views_[0].reset(new BufferView(view_.get())); @@ -51,7 +51,7 @@ int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int /*view_id void GuiImplementation::destroyWorkArea(int /*id*/) { - clipboard_.reset(); + selection_.reset(); work_area_.reset(); old_work_area_.reset(); old_screen_.reset(); diff --git a/src/frontends/gtk/GuiImplementation.h b/src/frontends/gtk/GuiImplementation.h index a0720d9a3b..c102bf50e3 100644 --- a/src/frontends/gtk/GuiImplementation.h +++ b/src/frontends/gtk/GuiImplementation.h @@ -19,6 +19,7 @@ #include "GWorkArea.h" #include "GuiClipboard.h" +#include "GuiSelection.h" #include "GuiWorkArea.h" #include @@ -42,7 +43,12 @@ public: lyx::frontend::Clipboard & clipboard() { - return *clipboard_; + return clipboard_; + } + + lyx::frontend::Selection & selection() + { + return *selection_; } int newView(unsigned int w, unsigned int h); @@ -68,7 +74,9 @@ public: private: /// - boost::shared_ptr clipboard_; + GuiClipboard clipboard_; + /// + boost::shared_ptr selection_; /// boost::shared_ptr work_area_; /// diff --git a/src/frontends/gtk/GuiSelection.C b/src/frontends/gtk/GuiSelection.C new file mode 100644 index 0000000000..cae4af7abe --- /dev/null +++ b/src/frontends/gtk/GuiSelection.C @@ -0,0 +1,60 @@ +// -*- C++ -*- +/** + * \file gtk/GuiSelection.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Huang Ying + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +// Too hard to make concept checks work with this file +#ifdef _GLIBCXX_CONCEPT_CHECKS +#undef _GLIBCXX_CONCEPT_CHECKS +#endif +#ifdef _GLIBCPP_CONCEPT_CHECKS +#undef _GLIBCPP_CONCEPT_CHECKS +#endif + +#include "GuiSelection.h" +#include "debug.h" + +#include + +using std::endl; +using std::string; + +namespace lyx { +namespace frontend { + +// ENCODING: Gtk::Clipboard returns UTF-8, we assume that the backend +// wants ISO-8859-1 and convert it to that. +// FIXME: Wrong! +string const GuiSelection::get() const +{ + Glib::RefPtr clipboard = + Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); + string const str = Glib::convert_with_fallback( + clipboard->wait_for_text(), "ISO-8859-1", "UTF-8"); + lyxerr[Debug::ACTION] << "GuiClipboard::get: " << str << endl; + return str; +} + + +// ENCODING: we assume that the backend passes us ISO-8859-1 and +// convert from that to UTF-8 before passing to GTK +// FIXME: Wrong! +void GuiSelection::put(string const & str) +{ + lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl; + Glib::RefPtr clipboard = + Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); + clipboard->set_text(Glib::convert(str, "UTF-8", "ISO-8859-1")); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GuiSelection.h b/src/frontends/gtk/GuiSelection.h new file mode 100644 index 0000000000..4d62ad8923 --- /dev/null +++ b/src/frontends/gtk/GuiSelection.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +/** + * \file gtk/Selection.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SELECTION_H +#define SELECTION_H + +#include "frontends/Selection.h" + +#include "GWorkArea.h" + +namespace lyx { +namespace frontend { + +/** + * The GTK version of the Selection. + */ +class GuiSelection: public lyx::frontend::Selection +{ +public: + GuiSelection(GWorkArea * work_area) + : old_work_area_(work_area) + { + } + + virtual ~GuiSelection() {} + + /** Selection overloaded methods + */ + //@{ + void haveSelection(bool own) + { + old_work_area_->haveSelection(own); + } + + std::string const get() const; + + void put(std::string const & str); + //@} + +private: + GWorkArea * old_work_area_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // SELECTION_H diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 04d6ca5368..7351f5798a 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -112,6 +112,7 @@ libgtk_la_SOURCES = \ GUrl.C \ GUrl.h \ GuiClipboard.C GuiClipboard.h \ + GuiSelection.C GuiSelection.h \ GuiWorkArea.h \ GView.C \ GView.h \ diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C index 4dd0db5944..dd4ab6560f 100644 --- a/src/frontends/gtk/ghelpers.C +++ b/src/frontends/gtk/ghelpers.C @@ -54,6 +54,7 @@ Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func) case LFUN_UNDO: return Gtk::Stock::UNDO; case LFUN_REDO: return Gtk::Stock::REDO; case LFUN_PASTE: return Gtk::Stock::PASTE; + case LFUN_CLIPBOARD_PASTE: return Gtk::Stock::PASTE; case LFUN_PRIMARY_SELECTION_PASTE: return Gtk::Stock::PASTE; case LFUN_CUT: return Gtk::Stock::CUT; case LFUN_COPY: return Gtk::Stock::COPY; diff --git a/src/frontends/qt3/GuiClipboard.C b/src/frontends/qt3/GuiClipboard.C index 0961dedd5b..c91b788670 100644 --- a/src/frontends/qt3/GuiClipboard.C +++ b/src/frontends/qt3/GuiClipboard.C @@ -33,7 +33,7 @@ namespace frontend { string const GuiClipboard::get() const { - QString const str = qApp->clipboard()->text(QClipboard::Selection); + QString const str = qApp->clipboard()->text(QClipboard::Clipboard); lyxerr[Debug::ACTION] << "GuiClipboard::get: " << (const char*) str << endl; if (str.isNull()) @@ -48,7 +48,7 @@ void GuiClipboard::put(string const & str) lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl; qApp->clipboard()->setText(toqstr(externalLineEnding(str)), - QClipboard::Selection); + QClipboard::Clipboard); } } // namespace frontend diff --git a/src/frontends/qt3/GuiClipboard.h b/src/frontends/qt3/GuiClipboard.h index 89de047034..47f14f9c07 100644 --- a/src/frontends/qt3/GuiClipboard.h +++ b/src/frontends/qt3/GuiClipboard.h @@ -14,8 +14,6 @@ #include "frontends/Clipboard.h" -#include "QWorkArea.h" - namespace lyx { namespace frontend { @@ -25,28 +23,16 @@ namespace frontend { class GuiClipboard: public lyx::frontend::Clipboard { public: - GuiClipboard(QWorkArea * work_area) - : old_work_area_(work_area) - { - } - virtual ~GuiClipboard() {} /** Clipboard overloaded methods */ //@{ - void haveSelection(bool own) - { - old_work_area_->haveSelection(own); - } std::string const get() const; void put(std::string const & str); //@} - -private: - QWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/qt3/GuiImplementation.h b/src/frontends/qt3/GuiImplementation.h index 28aa612ec6..d74def1331 100644 --- a/src/frontends/qt3/GuiImplementation.h +++ b/src/frontends/qt3/GuiImplementation.h @@ -19,6 +19,7 @@ #include "QWorkArea.h" #include "GuiClipboard.h" +#include "GuiSelection.h" #include "GuiWorkArea.h" #include "BufferView.h" @@ -48,7 +49,12 @@ public: lyx::frontend::Clipboard& clipboard() { - return *clipboard_; + return clipboard_; + } + + lyx::frontend::Selection& selection() + { + return *selection_; } int newView(unsigned int /*w*/, unsigned int /*h*/) @@ -74,7 +80,7 @@ public: old_work_area_.reset(new FWorkArea(*view_.get(), w, h)); old_screen_.reset(new FScreen(*old_work_area_.get())); work_area_.reset(new GuiWorkArea(old_screen_.get(), old_work_area_.get())); - clipboard_.reset(new GuiClipboard(old_work_area_.get())); + selection_.reset(new GuiSelection(old_work_area_.get())); // FIXME BufferView creation should be independant of WorkArea creation buffer_views_[0].reset(new BufferView(view_.get())); @@ -90,7 +96,7 @@ public: void destroyWorkArea(int /*id*/) { - clipboard_.reset(); + selection_.reset(); work_area_.reset(); old_work_area_.reset(); old_screen_.reset(); @@ -98,7 +104,9 @@ public: private: /// - boost::shared_ptr clipboard_; + GuiClipboard clipboard_; + /// + boost::shared_ptr selection_; /// boost::shared_ptr work_area_; /// diff --git a/src/frontends/qt3/GuiSelection.C b/src/frontends/qt3/GuiSelection.C new file mode 100644 index 0000000000..4e10badc55 --- /dev/null +++ b/src/frontends/qt3/GuiSelection.C @@ -0,0 +1,55 @@ +// -*- C++ -*- +/** + * \file qt3/GuiSelection.C + * 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. + */ + +#include + +#include "GuiSelection.h" +#include "qt_helpers.h" + +#include "debug.h" + +#include +#include +#include + +#include "support/lstrings.h" +using lyx::support::internalLineEnding; +using lyx::support::externalLineEnding; + +using std::endl; +using std::string; + +namespace lyx { +namespace frontend { + +string const GuiSelection::get() const +{ + QString const str = qApp->clipboard()->text(QClipboard::Selection); + lyxerr[Debug::ACTION] << "GuiSelection::get: " << (const char*) str + << endl; + if (str.isNull()) + return string(); + + return internalLineEnding(fromqstr(str)); +} + + +void GuiSelection::put(string const & str) +{ + lyxerr[Debug::ACTION] << "GuiSelection::put: " << str << endl; + + qApp->clipboard()->setText(toqstr(externalLineEnding(str)), + QClipboard::Selection); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/qt3/GuiSelection.h b/src/frontends/qt3/GuiSelection.h new file mode 100644 index 0000000000..3f1c1365e1 --- /dev/null +++ b/src/frontends/qt3/GuiSelection.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +/** + * \file qt3/GuiSelection.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SELECTION_H +#define SELECTION_H + +#include "frontends/Selection.h" + +#include "QWorkArea.h" + +namespace lyx { +namespace frontend { + +/** + * The Qt3 version of the Selection. + */ +class GuiSelection: public lyx::frontend::Selection +{ +public: + GuiSelection(QWorkArea * work_area) + : old_work_area_(work_area) + { + } + + virtual ~GuiSelection() {} + + /** Selection overloaded methods + */ + //@{ + void haveSelection(bool own) + { + old_work_area_->haveSelection(own); + } + + std::string const get() const; + + void put(std::string const & str); + //@} + +private: + QWorkArea * old_work_area_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // SELECTION_H diff --git a/src/frontends/qt3/Makefile.am b/src/frontends/qt3/Makefile.am index 42af82c82b..ce4048ad14 100644 --- a/src/frontends/qt3/Makefile.am +++ b/src/frontends/qt3/Makefile.am @@ -29,6 +29,7 @@ libqt3_la_SOURCES = \ FileDialog.C \ GuiClipboard.C GuiClipboard.h \ GuiImplementation.h \ + GuiSelection.C GuiSelection.h \ GuiWorkArea.h \ LyXKeySymFactory.C \ QLMenubar.C QLMenubar.h \ diff --git a/src/frontends/qt4/GuiClipboard.C b/src/frontends/qt4/GuiClipboard.C index 6e951a4f45..d518f1a3c4 100644 --- a/src/frontends/qt4/GuiClipboard.C +++ b/src/frontends/qt4/GuiClipboard.C @@ -31,31 +31,9 @@ using std::string; namespace lyx { namespace frontend { -#ifdef Q_WS_X11 -QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection; -#else -// FIXME external clipboard support is mostly broken for windows -// because the following fixe would involves too much side effects WRT mouse selection. -//QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Clipboard; -QClipboard::Mode const CLIPBOARD_MODE = QClipboard::Selection; -#endif - -void GuiClipboard::haveSelection(bool own) -{ - if (!qApp->clipboard()->supportsSelection()) - return; - - if (own) { - qApp->clipboard()->setText(QString(), CLIPBOARD_MODE); - } - // We don't need to do anything if own = false, as this case is - // handled by QT. -} - - string const GuiClipboard::get() const { - QString str = qApp->clipboard()->text(CLIPBOARD_MODE); + QString const str = qApp->clipboard()->text(QClipboard::Clipboard); lyxerr[Debug::ACTION] << "GuiClipboard::get: " << (const char*) str << endl; if (str.isNull()) @@ -69,7 +47,8 @@ void GuiClipboard::put(string const & str) { lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl; - qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE); + qApp->clipboard()->setText(toqstr(externalLineEnding(str)), + QClipboard::Clipboard); } } // namespace frontend diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h index e821b2a4d6..8ccd709d60 100644 --- a/src/frontends/qt4/GuiClipboard.h +++ b/src/frontends/qt4/GuiClipboard.h @@ -25,14 +25,11 @@ namespace frontend { class GuiClipboard: public Clipboard { public: - GuiClipboard() {} - virtual ~GuiClipboard() {} /** Clipboard overloaded methods */ //@{ - void haveSelection(bool own); std::string const get() const; void put(std::string const & str); //@} diff --git a/src/frontends/qt4/GuiImplementation.C b/src/frontends/qt4/GuiImplementation.C index ee720bf659..b31375c80c 100644 --- a/src/frontends/qt4/GuiImplementation.C +++ b/src/frontends/qt4/GuiImplementation.C @@ -37,6 +37,12 @@ Clipboard& GuiImplementation::clipboard() } +Selection& GuiImplementation::selection() +{ + return selection_; +} + + int GuiImplementation::newView(unsigned int /*w*/, unsigned int /*h*/) { size_t const id = max_view_id_; diff --git a/src/frontends/qt4/GuiImplementation.h b/src/frontends/qt4/GuiImplementation.h index ad1ebc614b..d31437cfa5 100644 --- a/src/frontends/qt4/GuiImplementation.h +++ b/src/frontends/qt4/GuiImplementation.h @@ -15,6 +15,7 @@ #include "frontends/Gui.h" #include "GuiClipboard.h" +#include "GuiSelection.h" #include @@ -38,6 +39,7 @@ public: virtual ~GuiImplementation() {} Clipboard& clipboard(); + Selection& selection(); int newView(unsigned int width, unsigned int height); LyXView& view(int id); @@ -52,6 +54,8 @@ private: /// GuiClipboard clipboard_; /// + GuiSelection selection_; + /// std::map > views_; /// std::map > work_areas_; diff --git a/src/frontends/qt4/GuiSelection.C b/src/frontends/qt4/GuiSelection.C new file mode 100644 index 0000000000..bcade1bd61 --- /dev/null +++ b/src/frontends/qt4/GuiSelection.C @@ -0,0 +1,67 @@ +// -*- C++ -*- +/** + * \file qt4/GuiSelection.C + * 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. + */ + +#include + +#include "GuiSelection.h" +#include "qt_helpers.h" + +#include "debug.h" + +#include +#include +#include + +#include "support/lstrings.h" +using lyx::support::internalLineEnding; +using lyx::support::externalLineEnding; + +using std::endl; +using std::string; + +namespace lyx { +namespace frontend { + +void GuiSelection::haveSelection(bool own) +{ + if (!qApp->clipboard()->supportsSelection()) + return; + + if (own) + qApp->clipboard()->setText(QString(), QClipboard::Selection); + // We don't need to do anything if own = false, as this case is + // handled by QT. +} + + +string const GuiSelection::get() const +{ + QString const str = qApp->clipboard()->text(QClipboard::Selection); + lyxerr[Debug::ACTION] << "GuiSelection::get: " << (const char*) str + << endl; + if (str.isNull()) + return string(); + + return internalLineEnding(fromqstr(str)); +} + + +void GuiSelection::put(string const & str) +{ + lyxerr[Debug::ACTION] << "GuiSelection::put: " << str << endl; + + qApp->clipboard()->setText(toqstr(externalLineEnding(str)), + QClipboard::Selection); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/qt4/GuiSelection.h b/src/frontends/qt4/GuiSelection.h new file mode 100644 index 0000000000..20a104e2a5 --- /dev/null +++ b/src/frontends/qt4/GuiSelection.h @@ -0,0 +1,42 @@ +// -*- C++ -*- +/** + * \file qt4/GuiSelection.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SELECTION_H +#define SELECTION_H + +#include "frontends/Selection.h" + +namespace lyx { +namespace frontend { + +/** + * The Qt4 version of the Selection. + */ +class GuiSelection: public Selection +{ +public: + virtual ~GuiSelection() {} + + /** Selection overloaded methods + */ + //@{ + void haveSelection(bool own); + std::string const get() const; + void put(std::string const & str); + //@} +}; + +} // namespace frontend +} // namespace lyx + +#endif // SELECTION_H diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 54dfa2370a..73d90e2907 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -37,6 +37,7 @@ libqt4_la_SOURCES = \ FileDialog.C \ FontLoader.h FontLoader.C \ GuiClipboard.h GuiClipboard.C \ + GuiSelection.h GuiSelection.C \ GuiImplementation.h GuiImplementation.C \ LyXKeySymFactory.C \ QLMenubar.C QLMenubar.h \ diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index 7b42e5d1db..ed23162557 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -199,6 +199,7 @@ void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd) InsetCollapsable::doDispatch(cur, cmd); break; case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: InsetCollapsable::doDispatch(cur, cmd); if (!params_.inner_box) diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index 94bb336a71..beb2b21357 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -236,6 +236,7 @@ void InsetCharStyle::doDispatch(LCursor & cur, FuncRequest & cmd) InsetText::doDispatch(cur, cmd); break; case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: { InsetCollapsable::doDispatch(cur, cmd); forceParagraphsToDefault(cur); diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 9197bf8055..ed5bf5a44e 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -239,6 +239,7 @@ void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd) break; } case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: { InsetCollapsable::doDispatch(cur, cmd); @@ -380,6 +381,7 @@ bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_QUOTE_INSERT: case LFUN_INSET_MODIFY: case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: status.enabled(true); return true; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d927fe7095..2288ac29c4 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -42,6 +42,7 @@ #include "frontends/LyXView.h" #include "frontends/Clipboard.h" #include "frontends/Painter.h" +#include "frontends/Selection.h" #include "frontends/nullpainter.h" #include @@ -686,8 +687,11 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) cell(cur.idx())->dispatch(cur, cmd); break; + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: { - string const clip = cur.bv().owner()->gui().clipboard().get(); + string const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ? + cur.bv().owner()->gui().clipboard().get() : + cur.bv().owner()->gui().selection().get(); if (clip.empty()) break; // pass to InsertAsciiString, but diff --git a/src/lfuns.h b/src/lfuns.h index aa0473eb23..e98ee0b926 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -367,6 +367,7 @@ enum kb_action { // 280 LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427 LFUN_MATH_BIGDELIM, + LFUN_CLIPBOARD_PASTE, LFUN_LASTACTION // end of the table }; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 273347ea6c..f76a15ff5c 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -52,8 +52,8 @@ #include "frontends/Dialogs.h" #include "frontends/Gui.h" #include "frontends/LyXView.h" -#include "frontends/Clipboard.h" #include "frontends/Painter.h" +#include "frontends/Selection.h" #include "frontends/nullpainter.h" #include @@ -1088,7 +1088,7 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button2) { MathArray ar; - asArray(cur.bv().owner()->gui().clipboard().get(), ar); + asArray(cur.bv().owner()->gui().selection().get(), ar); cur.clearSelection(); editXY(cur, cmd.x, cmd.y); cur.insert(ar); @@ -1121,7 +1121,7 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl; if (cmd.button() == mouse_button::button1) { - //cur.bv().owner()->gui().clipboard().put(cur.grabSelection()); + //cur.bv().owner()->gui().selection().put(cur.grabSelection()); return; } diff --git a/src/text3.C b/src/text3.C index 49d204a3fd..4a494ecd46 100644 --- a/src/text3.C +++ b/src/text3.C @@ -50,6 +50,7 @@ #include "frontends/Gui.h" #include "frontends/LyXView.h" #include "frontends/Clipboard.h" +#include "frontends/Selection.h" #include "insets/insetcommand.h" #include "insets/insetfloatlist.h" @@ -124,7 +125,7 @@ namespace { if (selecting || cur.mark()) cur.setSelection(); if (!cur.selection()) - cur.bv().owner()->gui().clipboard().haveSelection(false); + cur.bv().owner()->gui().selection().haveSelection(false); cur.bv().switchKeyMap(); } @@ -983,7 +984,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; } - case LFUN_PRIMARY_SELECTION_PASTE: { + case LFUN_CLIPBOARD_PASTE: { cur.clearSelection(); string const clip = bv->owner()->gui().clipboard().get(); if (!clip.empty()) { @@ -996,6 +997,19 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; } + case LFUN_PRIMARY_SELECTION_PASTE: { + cur.clearSelection(); + string const clip = bv->owner()->gui().selection().get(); + if (!clip.empty()) { + recordUndo(cur); + if (cmd.argument == "paragraph") + insertStringAsParagraphs(cur, clip); + else + insertStringAsLines(cur, clip); + } + break; + } + case LFUN_QUOTE_INSERT: { lyx::cap::replaceSelection(cur); Paragraph & par = cur.paragraph(); @@ -1045,7 +1059,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cursorEnd(cur); cur.setSelection(); bv->cursor() = cur; - bv->owner()->gui().clipboard().haveSelection(cur.selection()); + bv->owner()->gui().selection().haveSelection(cur.selection()); } break; @@ -1053,7 +1067,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button1) { selectWord(cur, lyx::WHOLE_WORD_STRICT); bv->cursor() = cur; - bv->owner()->gui().clipboard().haveSelection(cur.selection()); + bv->owner()->gui().selection().haveSelection(cur.selection()); } break; @@ -1135,7 +1149,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) // finish selection if (cmd.button() == mouse_button::button1) - bv->owner()->gui().clipboard().haveSelection(cur.selection()); + bv->owner()->gui().selection().haveSelection(cur.selection()); bv->switchKeyMap(); bv->owner()->updateMenubar(); @@ -1156,7 +1170,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) if (lyxrc.auto_region_delete) { if (cur.selection()) cutSelection(cur, false, false); - bv->owner()->gui().clipboard().haveSelection(false); + bv->owner()->gui().selection().haveSelection(false); } cur.clearSelection(); @@ -1869,6 +1883,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_SERVER_GET_FONT: case LFUN_SERVER_GET_LAYOUT: case LFUN_LAYOUT: + case LFUN_CLIPBOARD_PASTE: case LFUN_PRIMARY_SELECTION_PASTE: case LFUN_DATE_INSERT: case LFUN_SELF_INSERT: -- 2.39.5