]> git.lyx.org Git - features.git/commitdiff
Split clipboard and X selection
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 10 Jul 2006 11:32:25 +0000 (11:32 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 10 Jul 2006 11:32:25 +0000 (11:32 +0000)
* 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

36 files changed:
lib/ui/stdmenus.ui
src/BufferView_pimpl.C
src/CutAndPaste.C
src/LyXAction.C
src/frontends/Clipboard.h
src/frontends/Gui.h
src/frontends/Makefile.am
src/frontends/Selection.h [new file with mode: 0644]
src/frontends/gtk/GuiClipboard.C
src/frontends/gtk/GuiClipboard.h
src/frontends/gtk/GuiImplementation.C
src/frontends/gtk/GuiImplementation.h
src/frontends/gtk/GuiSelection.C [new file with mode: 0644]
src/frontends/gtk/GuiSelection.h [new file with mode: 0644]
src/frontends/gtk/Makefile.am
src/frontends/gtk/ghelpers.C
src/frontends/qt3/GuiClipboard.C
src/frontends/qt3/GuiClipboard.h
src/frontends/qt3/GuiImplementation.h
src/frontends/qt3/GuiSelection.C [new file with mode: 0644]
src/frontends/qt3/GuiSelection.h [new file with mode: 0644]
src/frontends/qt3/Makefile.am
src/frontends/qt4/GuiClipboard.C
src/frontends/qt4/GuiClipboard.h
src/frontends/qt4/GuiImplementation.C
src/frontends/qt4/GuiImplementation.h
src/frontends/qt4/GuiSelection.C [new file with mode: 0644]
src/frontends/qt4/GuiSelection.h [new file with mode: 0644]
src/frontends/qt4/Makefile.am
src/insets/insetbox.C
src/insets/insetcharstyle.C
src/insets/insetert.C
src/insets/insettabular.C
src/lfuns.h
src/mathed/math_nestinset.C
src/text3.C

index c03fcbe1fa19a0831e816f64a9d5f90ca796e294..958abb3ad3fd71246f3fd352dd3cd0bc011f0527 100644 (file)
@@ -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
index ea31aa1c4615c75395d540e904dacffd9b73d2e6..95d85786b47a2fe0ef245df6485545dd28a63489 100644 (file)
 #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);
        }
 }
 
index a418054c952382dbd83f9411f299e62bad8fc234..d88785bb14db1234193a265309107f0abd9134ca 100644 (file)
@@ -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
index 8f52f86a08634d1d216713e1658104346ac5573f..ddef58b000315ac1a3a1ad792891cec235c99386 100644 (file)
@@ -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 },
index ca046429fee49adfca2610cb42c8dcf8590faf8c..d871b114e704d81c205f11fea56d31392ef31e97 100644 (file)
@@ -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;
 };
 
index 76321770486a02d07eeb850e57d79832ffc60d09..0260b1a366a9ac5dd92de0278422eb7f7fa978a0 100644 (file)
@@ -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;
index 2e6d5c5a6dfe3bbc6c81d508fa20a1e305c04d87..b392163b973ace04d6f357988bf052f66d75bddc 100644 (file)
@@ -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 (file)
index 0000000..45ce213
--- /dev/null
@@ -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 <string>
+
+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
index 7aecf524ddba0bb147423f94e78a814c725ea056..60895d462d56b7ce114bbfb27311ac6ba38c42b7 100644 (file)
@@ -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<Gtk::Clipboard> 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<Gtk::Clipboard> clipboard =
-               Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
+               Gtk::Clipboard::get(GDK_SELECTION_CLIPBOARD);
        clipboard->set_text(Glib::convert(str, "UTF-8", "ISO-8859-1"));
 }
 
index 93edbfe321814afa50f0f8e9fe9bd86c45d53729..adb1ec7ed0b3a84a8589365ea53adb0a0c2bcbc8 100644 (file)
@@ -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
index da19b610c5f9ed9b6a02e89c693473839ea20cf9..622aca7fce0da89e02d215dbfcdae97071dcdbe3 100644 (file)
@@ -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();
index a0720d9a3bfb67e0f53b52fc88dffc1d5101cddc..c102bf50e3aae653420633fd62e5de56ff78940c 100644 (file)
@@ -19,6 +19,7 @@
 #include "GWorkArea.h"
 
 #include "GuiClipboard.h"
+#include "GuiSelection.h"
 #include "GuiWorkArea.h"
 
 #include <boost/shared_ptr.hpp>
@@ -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<GuiClipboard> clipboard_;
+       GuiClipboard clipboard_;
+       ///
+       boost::shared_ptr<GuiSelection> selection_;
        ///
        boost::shared_ptr<GuiWorkArea> work_area_;
        ///
diff --git a/src/frontends/gtk/GuiSelection.C b/src/frontends/gtk/GuiSelection.C
new file mode 100644 (file)
index 0000000..cae4af7
--- /dev/null
@@ -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 <config.h>
+
+// 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 <gtkmm.h>
+
+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<Gtk::Clipboard> 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<Gtk::Clipboard> 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 (file)
index 0000000..4d62ad8
--- /dev/null
@@ -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
index 04d6ca53687e40862ec2ca626a1f9eb32538c545..7351f5798a94081662736c33c0786803b6d0b3d2 100644 (file)
@@ -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 \
index 4dd0db5944dae2ed54072ea73d89e01805829f8f..dd4ab6560f84a462e0fbbf14d4234fa3f22795aa 100644 (file)
@@ -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;
index 0961dedd5b8aa449c2e2de10e6d0fa5ffd250272..c91b788670233fa3cf2b4701b659d3ac46ace89b 100644 (file)
@@ -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
index 89de0470343c79f5e189d0709d9a67f5d030d5d1..47f14f9c07087f166fdb68548f73e084e03bea3f 100644 (file)
@@ -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
index 28aa612ec602376924d0120fb40640fc57bf2502..d74def1331b19f0a38704ba41f166098f85f519d 100644 (file)
@@ -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<GuiClipboard> clipboard_;
+       GuiClipboard clipboard_;
+       ///
+       boost::shared_ptr<GuiSelection> selection_;
        ///
        boost::shared_ptr<GuiWorkArea> work_area_;
        ///
diff --git a/src/frontends/qt3/GuiSelection.C b/src/frontends/qt3/GuiSelection.C
new file mode 100644 (file)
index 0000000..4e10bad
--- /dev/null
@@ -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 <config.h>
+
+#include "GuiSelection.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <qapplication.h>
+#include <qclipboard.h>
+#include <qstring.h>
+
+#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 (file)
index 0000000..3f1c136
--- /dev/null
@@ -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
index 42af82c82b4aafdd3e98d4417dfea2a74e550811..ce4048ad148053643e2e3257d2276ba74e1a14df 100644 (file)
@@ -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 \
index 6e951a4f45d14d73f25ae18554d8f15686b8c3da..d518f1a3c45008410b15250d5a258a617beb2f75 100644 (file)
@@ -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
index e821b2a4d6ffd31c701d9cef6293107a3a6697e2..8ccd709d608cac1e93b025b96b230dcdd125bfb2 100644 (file)
@@ -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);
        //@}
index ee720bf6596de585933a5ff805e3e3340160f5e3..b31375c80c46a0179338f63a8863c6174016c52a 100644 (file)
@@ -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_;
index ad1ebc614b0ec5af316634306cdd77adb5bd0b6e..d31437cfa59617dbafd4b00133a06d56540b7511 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "frontends/Gui.h"
 #include "GuiClipboard.h"
+#include "GuiSelection.h"
 
 #include <boost/shared_ptr.hpp>
 
@@ -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<int, boost::shared_ptr<GuiView> > views_;
        ///
        std::map<int, boost::shared_ptr<GuiWorkArea> > work_areas_;
diff --git a/src/frontends/qt4/GuiSelection.C b/src/frontends/qt4/GuiSelection.C
new file mode 100644 (file)
index 0000000..bcade1b
--- /dev/null
@@ -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 <config.h>
+
+#include "GuiSelection.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QApplication>
+#include <QClipboard>
+#include <QString>
+
+#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 (file)
index 0000000..20a104e
--- /dev/null
@@ -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
index 54dfa2370aec0eb0aa28b82123515c421e574d67..73d90e2907f14e4fe3169ee5a83fe02e0ace4178 100644 (file)
@@ -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 \
index 7b42e5d1dbe55be1955c859d3a4ce33fd3e49368..ed231625578cb527944354bd70b8f2fe50877daa 100644 (file)
@@ -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)
index 94bb336a7184c33a6b9ccf5d9944943a253b10f7..beb2b2135783a6b40bef08838ede874235af1b15 100644 (file)
@@ -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);
index 9197bf805581b7496c813fc4cdd9bd0392ec8c4a..ed5bf5a44ea1b98ea4c9d0c272cbaa8ef1257054 100644 (file)
@@ -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;
index d927fe70957675f62a417e6235ac192a5486b4bb..2288ac29c43736bcb1b9d13db4cacda938ca208f 100644 (file)
@@ -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 <sstream>
@@ -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
index aa0473eb2315b27e375ed2db13139983f2042e7a..e98ee0b926a0d8f39075ed98e169c29f2e825f80 100644 (file)
@@ -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
 };
index 273347ea6c77a52dc85cb41940e033ba940a4204..f76a15ff5c9764b587da06dec88cef96450a4728 100644 (file)
@@ -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 <sstream>
@@ -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;
        }
 
index 49d204a3fd8614844e80faa8d9ca4c1c4fddff32..4a494ecd466867590e8a0f0eb46833f58adf02bf 100644 (file)
@@ -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: