This patch is a preparation for my long planned Cliboard/Selection split. 
It moves some more stuff from Workarea to Clipboard for qt3 and gtk and 
goes in now, since we already have the same structure in qt4.


Georg

Log:
Move more methods from WorkArea to Clipboard in qt3 and gtk
        * src/frontends/gtk/GWorkArea.[Ch]
        (getClipboard): Move to GuiClipboard.[Ch]
        (putClipboard): ditto

        * src/frontends/gtk/Makefile.am: add GuiClipboard.C

        * src/frontends/gtk/GuiClipboard.C: new file

        * src/frontends/gtk/GuiClipboard.h
        (get, put): only declare

        * src/frontends/qt3/Makefile.am: add GuiClipboard.C

        * src/frontends/qt3/QWorkArea.[Ch]
        (getClipboard): Move to GuiClipboard.[Ch]
        (putClipboard): ditto

        * src/frontends/qt3/GuiClipboard.C: new file

        * src/frontends/qt3/GuiClipboard.h
        (get, put): only declare

        * src/frontends/qt4/GuiClipboard.C: remove unneeded include
        (GuiClipboard::get): adjust debug output
        (GuiClipboard::put): ditto
Index: src/frontends/gtk/GWorkArea.h
===================================================================
--- src/frontends/gtk/GWorkArea.h	(Revision 14376)
+++ src/frontends/gtk/GWorkArea.h	(Arbeitskopie)
@@ -81,10 +81,6 @@ public:
 	virtual void setScrollbarParams(int height, int pos, int line_height);
 	/// a selection exists
 	virtual void haveSelection(bool);
-	///
-	virtual std::string const getClipboard() const;
-	///
-	virtual void putClipboard(std::string const &);
 	void inputCommit(gchar * str);
 private:
 	bool onExpose(GdkEventExpose * event);
Index: src/frontends/gtk/Makefile.am
===================================================================
--- src/frontends/gtk/Makefile.am	(Revision 14376)
+++ src/frontends/gtk/Makefile.am	(Arbeitskopie)
@@ -111,7 +111,7 @@ libgtk_la_SOURCES = \
 	GToolbar.h \
 	GUrl.C \
 	GUrl.h \
-	GuiClipboard.h \
+	GuiClipboard.C GuiClipboard.h \
 	GuiWorkArea.h \
 	GView.C \
 	GView.h \
Index: src/frontends/gtk/GuiClipboard.C
===================================================================
--- src/frontends/gtk/GuiClipboard.C	(Revision 14376)
+++ src/frontends/gtk/GuiClipboard.C	(Arbeitskopie)
@@ -1,10 +1,10 @@
 // -*- C++ -*-
 /**
- * \file qt4/GuiClipboard.C
+ * \file gtk/GuiClipboard.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author John Levon
+ * \author Huang Ying
  * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
@@ -12,20 +12,18 @@
 
 #include <config.h>
 
-#include "GuiClipboard.h"
-#include "qt_helpers.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 "GuiClipboard.h"
 #include "debug.h"
 
-#include <QApplication>
-#include <QClipboard>
-#include <QString>
-
-#include <string>
-
-#include "support/lstrings.h"
-using lyx::support::internalLineEnding;
-using lyx::support::externalLineEnding;
+#include <gtkmm.h>
 
 using std::endl;
 using std::string;
@@ -33,44 +31,27 @@ 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.
-}
-
-
+// ENCODING: Gtk::Clipboard returns UTF-8, we assume that the backend
+// wants ISO-8859-1 and convert it to that.
 string const GuiClipboard::get() const
 {
-	QString str = qApp->clipboard()->text(CLIPBOARD_MODE);
-	lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
-	if (str.isNull())
-		return string();
-
-	return internalLineEnding(fromqstr(str));
+	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
 void GuiClipboard::put(string const & str)
 {
-	lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
-
-	qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE);
+	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
Index: src/frontends/gtk/GuiClipboard.h
===================================================================
--- src/frontends/gtk/GuiClipboard.h	(Revision 14376)
+++ src/frontends/gtk/GuiClipboard.h	(Arbeitskopie)
@@ -40,15 +40,9 @@ public:
 		old_work_area_->haveSelection(own);
 	}
 
-	std::string const get() const
-	{
-		return old_work_area_->getClipboard();
-	}
+	std::string const get() const;
 
-	void put(std::string const & str)
-	{
-		old_work_area_->putClipboard(str);
-	}
+	void put(std::string const & str);
 	//@}
 
 private:
Index: src/frontends/gtk/GWorkArea.C
===================================================================
--- src/frontends/gtk/GWorkArea.C	(Revision 14376)
+++ src/frontends/gtk/GWorkArea.C	(Arbeitskopie)
@@ -519,27 +519,5 @@ void GWorkArea::haveSelection(bool toHav
 	}
 }
 
-
-// ENCODING: Gtk::Clipboard returns UTF-8, we assume that the backend
-// wants ISO-8859-1 and convert it to that.
-string const GWorkArea::getClipboard() const
-{
-	Glib::RefPtr<Gtk::Clipboard> clipboard =
-		Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
-	return Glib::convert_with_fallback(
-		clipboard->wait_for_text(), "ISO-8859-1", "UTF-8");
-}
-
-
-// ENCODING: we assume that the backend passes us ISO-8859-1 and
-// convert from that to UTF-8 before passing to GTK
-void GWorkArea::putClipboard(string const & str)
-{
-	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
Index: src/frontends/qt3/Makefile.am
===================================================================
--- src/frontends/qt3/Makefile.am	(Revision 14376)
+++ src/frontends/qt3/Makefile.am	(Arbeitskopie)
@@ -27,7 +27,7 @@ libqt3_la_SOURCES = \
 	Alert_pimpl.C \
 	Dialogs.C \
 	FileDialog.C \
-	GuiClipboard.h \
+	GuiClipboard.C GuiClipboard.h \
 	GuiImplementation.h \
 	GuiWorkArea.h \
 	LyXKeySymFactory.C \
Index: src/frontends/qt3/QWorkArea.C
===================================================================
--- src/frontends/qt3/QWorkArea.C	(Revision 14376)
+++ src/frontends/qt3/QWorkArea.C	(Arbeitskopie)
@@ -210,23 +210,6 @@ void QWorkArea::haveSelection(bool own)
 }
 
 
-string const QWorkArea::getClipboard() const
-{
-	QApplication::clipboard()->setSelectionMode(true);
-	QString str = QApplication::clipboard()->text();
-	if (str.isNull())
-		return string();
-	return internalLineEnding(fromqstr(str));
-}
-
-
-void QWorkArea::putClipboard(string const & str)
-{
-	QApplication::clipboard()->setSelectionMode(true);
-	QApplication::clipboard()->setText(toqstr(externalLineEnding(str)));
-}
-
-
 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
 {
 	event->accept(QUriDrag::canDecode(event));
Index: src/frontends/qt3/GuiClipboard.C
===================================================================
--- src/frontends/qt3/GuiClipboard.C	(Revision 14376)
+++ src/frontends/qt3/GuiClipboard.C	(Arbeitskopie)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file qt4/GuiClipboard.C
+ * \file qt3/GuiClipboard.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -17,11 +17,9 @@
 
 #include "debug.h"
 
-#include <QApplication>
-#include <QClipboard>
-#include <QString>
-
-#include <string>
+#include <qapplication.h>
+#include <qclipboard.h>
+#include <qstring.h>
 
 #include "support/lstrings.h"
 using lyx::support::internalLineEnding;
@@ -33,32 +31,11 @@ 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);
-	lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
+	QString const str = qApp->clipboard()->text(QClipboard::Selection);
+	lyxerr[Debug::ACTION] << "GuiClipboard::get: " << (const char*) str
+	                      << endl;
 	if (str.isNull())
 		return string();
 
@@ -68,9 +45,10 @@ string const GuiClipboard::get() const
 
 void GuiClipboard::put(string const & str)
 {
-	lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
+	lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl;
 
-	qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE);
+	qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
+	                           QClipboard::Selection);
 }
 
 } // namespace frontend
Index: src/frontends/qt3/QWorkArea.h
===================================================================
--- src/frontends/qt3/QWorkArea.h	(Revision 14376)
+++ src/frontends/qt3/QWorkArea.h	(Arbeitskopie)
@@ -52,10 +52,6 @@ public:
 	/// a selection exists
 	virtual void haveSelection(bool);
 	///
-	virtual std::string const getClipboard() const;
-	///
-	virtual void putClipboard(std::string const &);
-	///
 	virtual void dragEnterEvent(QDragEnterEvent * event);
 	///
 	virtual void dropEvent(QDropEvent* event);
Index: src/frontends/qt3/GuiClipboard.h
===================================================================
--- src/frontends/qt3/GuiClipboard.h	(Revision 14376)
+++ src/frontends/qt3/GuiClipboard.h	(Arbeitskopie)
@@ -19,15 +19,13 @@
 namespace lyx {
 namespace frontend {
 
-typedef QWorkArea FWorkArea;
-
 /**
  * The Qt3 version of the Clipboard.
  */
 class GuiClipboard: public lyx::frontend::Clipboard
 {
 public:
-	GuiClipboard(FWorkArea * work_area)
+	GuiClipboard(QWorkArea * work_area)
 		: old_work_area_(work_area)
 	{
 	}
@@ -42,19 +40,13 @@ public:
 		old_work_area_->haveSelection(own);
 	}
 
-	std::string const get() const
-	{
-		return old_work_area_->getClipboard();
-	}
+	std::string const get() const;
 
-	void put(std::string const & str)
-	{
-		old_work_area_->putClipboard(str);
-	}
+	void put(std::string const & str);
 	//@}
 
 private:
-	FWorkArea * old_work_area_;
+	QWorkArea * old_work_area_;
 };
 
 } // namespace frontend
Index: src/frontends/qt4/GuiClipboard.C
===================================================================
--- src/frontends/qt4/GuiClipboard.C	(Revision 14376)
+++ src/frontends/qt4/GuiClipboard.C	(Arbeitskopie)
@@ -21,8 +21,6 @@
 #include <QClipboard>
 #include <QString>
 
-#include <string>
-
 #include "support/lstrings.h"
 using lyx::support::internalLineEnding;
 using lyx::support::externalLineEnding;
@@ -58,7 +56,8 @@ void GuiClipboard::haveSelection(bool ow
 string const GuiClipboard::get() const
 {
 	QString str = qApp->clipboard()->text(CLIPBOARD_MODE);
-	lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
+	lyxerr[Debug::ACTION] << "GuiClipboard::get: " << (const char*) str
+	                      << endl;
 	if (str.isNull())
 		return string();
 
@@ -68,7 +67,7 @@ string const GuiClipboard::get() const
 
 void GuiClipboard::put(string const & str)
 {
-	lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
+	lyxerr[Debug::ACTION] << "GuiClipboard::put: " << str << endl;
 
 	qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE);
 }

Reply via email to