Abdelrazak Younes wrote:
And yet another one updated from latest SVN that contained some qt4
changes.
And the patch...
Index: src/BufferView.C
===================================================================
--- src/BufferView.C (revision 14001)
+++ src/BufferView.C (working copy)
@@ -42,6 +42,7 @@
#include "frontends/Dialogs.h"
#include "frontends/LyXView.h"
#include "frontends/screen.h"
+#include "frontends/Clipboard.h"
#include "frontends/WorkArea.h"
#include "insets/insetcommand.h" // ChangeRefs
@@ -212,7 +213,7 @@
string const BufferView::getClipboard() const
{
- return pimpl_->workarea().getClipboard();
+ return pimpl_->clipboard().getClipboard();
}
@@ -338,7 +339,7 @@
void BufferView::haveSelection(bool sel)
{
- pimpl_->workarea().haveSelection(sel);
+ pimpl_->clipboard().haveSelection(sel);
}
Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C (revision 14001)
+++ src/BufferView_pimpl.C (working copy)
@@ -64,6 +64,7 @@
#include "frontends/LyXView.h"
#include "frontends/LyXScreenFactory.h"
#include "frontends/screen.h"
+#include "frontends/Clipboard.h"
#include "frontends/WorkArea.h"
#include "frontends/WorkAreaFactory.h"
@@ -143,6 +144,7 @@
xsel_cache_.set = false;
workarea_.reset(WorkAreaFactory::create(*owner_, width, height));
+ clipboard_.reset(WorkAreaFactory::getClipboard());
screen_.reset(LyXScreenFactory::create(workarea()));
// Setup the signals
@@ -320,6 +322,12 @@
}
+Clipboard & BufferView::Pimpl::clipboard() const
+{
+ return *clipboard_.get();
+}
+
+
LyXScreen & BufferView::Pimpl::screen() const
{
return *screen_.get();
@@ -618,7 +626,7 @@
xsel_cache_.set = cur.selection();
sel = cur.selectionAsString(false);
if (!sel.empty())
- workarea().putClipboard(sel);
+ clipboard().putClipboard(sel);
}
}
@@ -873,7 +881,7 @@
void BufferView::Pimpl::stuffClipboard(string const & content) const
{
- workarea().putClipboard(content);
+ clipboard().putClipboard(content);
}
Index: src/BufferView_pimpl.h
===================================================================
--- src/BufferView_pimpl.h (revision 14001)
+++ src/BufferView_pimpl.h (working copy)
@@ -39,6 +39,7 @@
class LyXKeySym;
class LyXView;
class WorkArea;
+class Clipboard;
class LyXScreen;
class FuncRequest;
class FuncStatus;
@@ -152,6 +153,8 @@
boost::scoped_ptr<LyXScreen> screen_;
///
boost::scoped_ptr<WorkArea> workarea_;
+ ///
+ boost::scoped_ptr<Clipboard> clipboard_;
/// Estimated average par height for scrollbar
int wh_;
///
@@ -181,6 +184,8 @@
void menuInsertLyXFile(std::string const & filen);
/// our workarea
WorkArea & workarea() const;
+ /// our clipboard
+ Clipboard & clipboard() const;
/// this is used to handle XSelection events in the right manner
struct {
CursorSlice cursor;
Index: src/frontends/Clipboard.h
===================================================================
--- src/frontends/Clipboard.h (revision 0)
+++ src/frontends/Clipboard.h (revision 0)
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+/**
+ * \file Clipboard.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CLIPBOARD_H
+#define CLIPBOARD_H
+
+#include <string>
+
+/**
+ * The Clipboard class manages the clipboard.
+ */
+class Clipboard
+{
+public:
+ virtual ~Clipboard() {}
+
+ /// a selection exists
+ virtual void haveSelection(bool) = 0;
+ /// get the X clipboard contents
+ virtual std::string const getClipboard() const = 0;
+ /// fill the clipboard
+ virtual void putClipboard(std::string const &) = 0;
+};
+
+#endif // CLIPBOARD_H
Property changes on: src\frontends\Clipboard.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/gtk/GWorkArea.C
===================================================================
--- src/frontends/gtk/GWorkArea.C (revision 14001)
+++ src/frontends/gtk/GWorkArea.C (working copy)
@@ -504,7 +504,7 @@
}
-void GWorkArea::haveSelection(bool toHave) const
+void GWorkArea::haveSelection(bool toHave)
{
if (toHave) {
Glib::RefPtr<Gtk::Clipboard> clipboard =
@@ -533,7 +533,7 @@
// 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) const
+void GWorkArea::putClipboard(string const & str)
{
Glib::RefPtr<Gtk::Clipboard> clipboard =
Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
Index: src/frontends/gtk/GWorkArea.h
===================================================================
--- src/frontends/gtk/GWorkArea.h (revision 14001)
+++ src/frontends/gtk/GWorkArea.h (working copy)
@@ -15,6 +15,7 @@
#include "GPainter.h"
#include "frontends/WorkArea.h"
+#include "frontends/Clipboard.h"
#include <gtkmm.h>
#include <gtk/gtk.h>
@@ -55,7 +56,7 @@
};
-class GWorkArea : public WorkArea, public sigc::trackable {
+class GWorkArea : public WorkArea, public Clipboard, public sigc::trackable {
public:
GWorkArea(LyXView & owner, int width, int height);
~GWorkArea();
@@ -80,11 +81,11 @@
virtual void setScrollbarParams(int height, int pos, int line_height);
/// a selection exists
- virtual void haveSelection(bool) const;
+ virtual void haveSelection(bool);
///
virtual std::string const getClipboard() const;
///
- virtual void putClipboard(std::string const &) const;
+ virtual void putClipboard(std::string const &);
void inputCommit(gchar * str);
private:
bool onExpose(GdkEventExpose * event);
Index: src/frontends/gtk/WorkAreaFactory.C
===================================================================
--- src/frontends/gtk/WorkAreaFactory.C (revision 14001)
+++ src/frontends/gtk/WorkAreaFactory.C (working copy)
@@ -27,11 +27,20 @@
namespace WorkAreaFactory {
+static GWorkArea * work_area_ = 0;
WorkArea * create(LyXView & owner, int w, int h)
{
- return new lyx::frontend::GWorkArea(owner, w, h);
+ work_area_ = new lyx::frontend::GWorkArea(owner, w, h);
+ return work_area_;
}
+/**
+The call to this method must be done after the WorkArea creation.
+*/
+Clipboard * getClipboard()
+{
+ return work_area_;
+}
}
Index: src/frontends/Makefile.am
===================================================================
--- src/frontends/Makefile.am (revision 14001)
+++ src/frontends/Makefile.am (working copy)
@@ -31,6 +31,7 @@
Timeout.h \
Toolbars.C \
Toolbars.h \
+ Clipboard.h \
WorkArea.h \
WorkAreaFactory.h \
font_metrics.h \
Index: src/frontends/qt3/QWorkArea.C
===================================================================
--- src/frontends/qt3/QWorkArea.C (revision 14001)
+++ src/frontends/qt3/QWorkArea.C (working copy)
@@ -184,7 +184,7 @@
}
#endif // Q_WS_MACX
-void QWorkArea::haveSelection(bool own) const
+void QWorkArea::haveSelection(bool own)
{
wa_ptr = const_cast<QWorkArea*>(this);
@@ -215,7 +215,7 @@
}
-void QWorkArea::putClipboard(string const & str) const
+void QWorkArea::putClipboard(string const & str)
{
QApplication::clipboard()->setSelectionMode(true);
#ifdef Q_OS_MAC
Index: src/frontends/qt3/QWorkArea.h
===================================================================
--- src/frontends/qt3/QWorkArea.h (revision 14001)
+++ src/frontends/qt3/QWorkArea.h (working copy)
@@ -13,7 +13,8 @@
#ifndef QWORKAREA_H
#define QWORKAREA_H
-#include "WorkArea.h"
+#include "frontends/WorkArea.h"
+#include "frontends/Clipboard.h"
#include "QLPainter.h"
#include "QContentPane.h"
@@ -31,7 +32,7 @@
* It consists of a content pane widget, and a scrollbar.
* Hopefully soon we can just use QScrollView ...
*/
-class QWorkArea : public WorkArea, public QWidget {
+class QWorkArea : public WorkArea, public Clipboard, public QWidget {
public:
friend class QContentPane;
@@ -48,11 +49,11 @@
virtual void setScrollbarParams(int height, int pos, int line_height);
/// a selection exists
- virtual void haveSelection(bool) const;
+ virtual void haveSelection(bool);
///
virtual std::string const getClipboard() const;
///
- virtual void putClipboard(std::string const &) const;
+ virtual void putClipboard(std::string const &);
///
virtual void dragEnterEvent(QDragEnterEvent * event);
///
Index: src/frontends/qt3/WorkAreaFactory.C
===================================================================
--- src/frontends/qt3/WorkAreaFactory.C (revision 14001)
+++ src/frontends/qt3/WorkAreaFactory.C (working copy)
@@ -15,9 +15,21 @@
namespace WorkAreaFactory {
+
+static QWorkArea * work_area_ = 0;
+
WorkArea * create(LyXView & owner, int w, int h)
{
- return new QWorkArea(owner, w, h);
+ work_area_ = new lyx::frontend::QWorkArea(owner, w, h);
+ return work_area_;
}
+/**
+The call to this method must be done after the WorkArea creation.
+*/
+Clipboard * getClipboard()
+{
+ return work_area_;
+}
+
} // namespace WorkAreaFactory
Index: src/frontends/qt4/Application.C
===================================================================
--- src/frontends/qt4/Application.C (revision 0)
+++ src/frontends/qt4/Application.C (revision 0)
@@ -0,0 +1,193 @@
+/**
+ * \file qt4/Application.C
+ * 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.
+ */
+
+#include "Application.h"
+#include "qt_helpers.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "support/lstrings.h"
+
+#include <QApplication>
+#include <QEventLoop>
+#include <QTranslator>
+#include <QTextCodec>
+#include <QClipboard>
+
+using lyx::support::subst;
+
+using std::map;
+using std::vector;
+using std::string;
+using std::endl;
+
+///////////////////////////////////////////////////////////////
+// You can find other X11 and MACX specific stuff
+// at the end of this file...
+///////////////////////////////////////////////////////////////
+
+namespace lyx {
+namespace frontend {
+
+Application::Application(int & argc, char ** argv)
+ : QApplication(argc, argv), clipboard_(this)
+{
+#ifdef Q_WS_X11
+ // doubleClickInterval() is 400 ms on X11 witch is just too long.
+ // On Windows and Mac OS X, the operating system's value is used.
+ // On Microsoft Windows, calling this function sets the double
+ // click interval for all applications. So we don't!
+ QApplication::setDoubleClickInterval(300);
+#endif
+
+#ifdef Q_WS_MACX
+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+ NewAEEventHandlerUPP(handleOpenDocuments),
+ 0, false);
+#endif
+}
+
+
+Application::~Application()
+{
+ size_t end = work_areas_.size();
+ for (size_t i = 0; i < end; ++i)
+ delete work_areas_[i];
+}
+
+
+QWorkArea * Application::newWorkArea(LyXView & owner, int w, int h)
+{
+ current_work_area_ = new QWorkArea(owner, w, h);
+ work_areas_.push_back(current_work_area_);
+ lyxerr[Debug::GUI]
+ << "current_work_area_ " << current_work_area_
+ << " work_areas_.size() " << work_areas_.size()
+ << endl;
+
+ return current_work_area_;
+}
+
+
+void Application::setCurrent(QWorkArea * const work_area_)
+{
+ // FIXME put some verification here.
+ current_work_area_ = work_area_;
+}
+
+
+////////////////////////////////////////////////////////////////////////
+// X11 specific stuff goes here...
+#ifdef Q_WS_X11
+bool Application::x11EventFilter(XEvent * xev)
+{
+ switch (xev->type) {
+ case SelectionRequest:
+ lyxerr[Debug::GUI] << "X requested selection." << endl;
+ if (current_work_area_)
+ current_work_area_->view().view()->selectionRequested();
+ break;
+ case SelectionClear:
+ lyxerr[Debug::GUI] << "Lost selection." << endl;
+ if (current_work_area_)
+ current_work_area_->view().view()->selectionLost();
+ break;
+ }
+ return false;
+}
+#endif
+
+
+////////////////////////////////////////////////////////////////////////
+// Mac OSX specific stuff goes here...
+
+#ifdef Q_WS_MACX
+namespace{
+OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
+ {
+ DescType returnedType;
+ Size actualSize;
+ OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
+ typeWildCard, &returnedType, nil, 0,
+ &actualSize);
+ switch (err) {
+ case errAEDescNotFound:
+ return noErr;
+ case noErr:
+ return errAEEventNotHandled;
+ default:
+ return err;
+ }
+ }
+} // namespace
+
+OSErr Application::handleOpenDocuments(const AppleEvent* inEvent,
+
AppleEvent* /*reply*/, long /*refCon*/)
+{
+ QString s_arg;
+ AEDescList documentList;
+ OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
+ &documentList);
+ if (err != noErr)
+ return err;
+
+ err = checkAppleEventForMissingParams(*inEvent);
+ if (err == noErr) {
+ long documentCount;
+ err = AECountItems(&documentList, &documentCount);
+ for (long documentIndex = 1;
+ err == noErr && documentIndex <= documentCount;
+ documentIndex++) {
+ DescType returnedType;
+ Size actualSize;
+ AEKeyword keyword;
+ FSRef ref;
+ char qstr_buf[1024];
+ err = AESizeOfNthItem(&documentList, documentIndex,
+ &returnedType, &actualSize);
+ if (err == noErr) {
+ err = AEGetNthPtr(&documentList, documentIndex,
+ typeFSRef, &keyword,
+ &returnedType, (Ptr)&ref,
+ sizeof(FSRef), &actualSize);
+ if (err == noErr) {
+ FSRefMakePath(&ref, (UInt8*)qstr_buf,
+ 1024);
+ s_arg=QString::fromUtf8(qstr_buf);
+
current_work_area_->view().view()->workAreaDispatch(
+ FuncRequest(LFUN_FILE_OPEN,
+ fromqstr(s_arg)));
+ break;
+ }
+ }
+ } // for ...
+ }
+ AEDisposeDesc(&documentList);
+
+ return err;
+}
+
+bool Application::macEventFilter(EventRef event)
+{
+ if (GetEventClass(event) == kEventClassAppleEvent) {
+ EventRecord eventrec;
+ ConvertEventRefToEventRecord(event, &eventrec);
+ AEProcessAppleEvent(&eventrec);
+
+ return false;
+ }
+ return false;
+}
+
+#endif // Q_WS_MACX
+
+} // namespace frontend
+} // namespace lyx
Property changes on: src\frontends\qt4\Application.C
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/qt4/Application.h
===================================================================
--- src/frontends/qt4/Application.h (revision 0)
+++ src/frontends/qt4/Application.h (revision 0)
@@ -0,0 +1,90 @@
+/**
+ * \file qt4/Application.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 LYX_APPLICATION_H
+#define LYX_APPLICATION_H
+
+#include "QWorkArea.h"
+#include "LyxClipboard.h"
+
+#include <QApplication>
+
+///////////////////////////////////////////////////////////////
+// Specific stuff
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
+
+#ifdef Q_WS_MACX
+#include <Carbon/Carbon.h>
+#endif
+///////////////////////////////////////////////////////////////
+
+namespace lyx {
+namespace frontend {
+
+/// The Qt main application class
+/**
+There should be only one instance of this class. No Qt object
+initialisation should be done before the instanciation of this class.
+
+\todo The work areas handling could be moved to a base virtual class
+comon to all frontends.
+*/
+class Application : public QApplication
+{
+public:
+ Application(int & argc, char ** argv);
+ ~Application();
+
+ /// Create a new WorkArea.
+ QWorkArea * newWorkArea(LyXView & owner, int w, int h);
+
+ /// Delete a new WorkArea.
+ //void deleteWorkArea(QWorkArea *);
+
+ /// Set the work area that has the current focus.
+ void setCurrent(QWorkArea * const);
+
+ Clipboard * lyxClipboard() { return &clipboard_; }
+
+private:
+ /// WorkArea container.
+ /**
+ \todo A map or a list would probably be better...
+ */
+ std::vector<QWorkArea *> work_areas_;
+
+ /// The work area that has the focus.
+ QWorkArea * current_work_area_;
+
+ LyxClipboard clipboard_;
+
+#ifdef Q_WS_X11
+public:
+ bool x11EventFilter (XEvent * ev);
+#endif
+
+#ifdef Q_WS_MACX
+public:
+ bool macEventFilter(EventRef event);
+private:
+// static OSStatus handleOpenDocuments(
+ static pascal OSErr handleOpenDocuments(
+ const AppleEvent* inEvent, AppleEvent*, long);
+#endif
+}; // Application
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // LYX_APPLICATION_H
Property changes on: src\frontends\qt4\Application.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/qt4/lyx_gui.C
===================================================================
--- src/frontends/qt4/lyx_gui.C (revision 14001)
+++ src/frontends/qt4/lyx_gui.C (working copy)
@@ -46,11 +46,8 @@
#include "QLImage.h"
#include "qt_helpers.h"
#include "socket_callback.h"
+#include "Application.h"
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#endif
-
#include <QApplication>
#include <QEventLoop>
#include <QTranslator>
@@ -60,6 +57,7 @@
using lyx::support::package;
using lyx::frontend::QtView;
+using lyx::frontend::Application;
namespace os = lyx::support::os;
@@ -73,9 +71,6 @@
using std::vector;
using std::string;
-
-extern BufferList bufferlist;
-
namespace {
int getDPI()
@@ -95,59 +90,9 @@
// in QLyXKeySym.C
extern void initEncodings();
-#ifdef Q_WS_X11
-extern bool lyxX11EventFilter(XEvent * xev);
-#endif
-
-#ifdef Q_WS_MACX
-extern bool macEventFilter(EventRef event);
-extern pascal OSErr
-handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
- long /*refCon*/);
-#endif
-
-class LQApplication : public QApplication
-{
-public:
- LQApplication(int & argc, char ** argv);
-#ifdef Q_WS_X11
- bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
-#endif
-#ifdef Q_WS_MACX
- bool macEventFilter(EventRef event);
-#endif
-};
-
-
-LQApplication::LQApplication(int & argc, char ** argv)
- : QApplication(argc, argv)
-{
-#ifdef Q_WS_MACX
- AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
- NewAEEventHandlerUPP(handleOpenDocuments),
- 0, false);
-#endif
-}
-
-
-#ifdef Q_WS_MACX
-bool LQApplication::macEventFilter(EventRef event)
-{
- if (GetEventClass(event) == kEventClassAppleEvent) {
- EventRecord eventrec;
- ConvertEventRefToEventRecord(event, &eventrec);
- AEProcessAppleEvent(&eventrec);
-
- return false;
- }
- return false;
-}
-#endif
-
-
namespace {
-LQApplication * app = 0;
+Application * app = 0;
}
@@ -181,9 +126,9 @@
FontLoader::initFontPath();
#ifdef Q_WS_WIN
- static QApplication win_app(argc, argv);
+ static Application win_app(argc, argv);
#else
- app = new LQApplication(argc, argv);
+ app = new Application(argc, argv);
#endif
// install translation file for Qt built-in dialogs
Index: src/frontends/qt4/LyxClipboard.C
===================================================================
--- src/frontends/qt4/LyxClipboard.C (revision 0)
+++ src/frontends/qt4/LyxClipboard.C (revision 0)
@@ -0,0 +1,112 @@
+// -*- C++ -*-
+/**
+ * \file LyxClipboard.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 "LyxClipboard.h"
+#include "Application.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QClipboard>
+#include <QString>
+
+#include <string>
+
+#include "support/lstrings.h"
+using lyx::support::subst;
+
+using std::endl;
+using std::string;
+
+namespace {
+
+string toClipboardStr(string const & str)
+{
+#ifdef Q_WS_MACX
+ // The MAC clipboard uses \r for lineendings, and we use \n
+ return subst(str, '\n', '\r');
+#endif
+
+ return str;
+/*
+#ifdef Q_WS_WIN
+ // Windows clipboard uses \r\n for lineendings, and we use \n
+ return subst(str, '\n', '\r\n');
+#endif
+*/
+}
+
+
+string fromClipboardStr(string const & str)
+{
+#ifdef Q_WS_MACX
+ // The MAC clipboard uses \r for lineendings, and we use \n
+ return subst(str, '\r', '\n');
+#endif
+
+ return str;
+/*
+#ifdef Q_WS_WIN
+ // Windows clipboard uses \r\n for lineendings, and we use \n
+ return subst(str, '\r\n', '\n');
+#endif
+*/
+}
+
+} // namespace anon
+
+
+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 LyxClipboard::haveSelection(bool own)
+{
+ if (!owner_->clipboard()->supportsSelection())
+ return;
+
+ if (own) {
+ owner_->clipboard()->setText(QString(), CLIPBOARD_MODE);
+ }
+ // We don't need to do anything if own = false, as this case is
+ // handled by QT.
+}
+
+
+string const LyxClipboard::getClipboard() const
+{
+ QString str = owner_->clipboard()->text(CLIPBOARD_MODE);
+ lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
+ if (str.isNull())
+ return string();
+
+ return fromClipboardStr(fromqstr(str));
+}
+
+
+void LyxClipboard::putClipboard(string const & str)
+{
+ lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
+
+ owner_->clipboard()->setText(toqstr(toClipboardStr(str)),
CLIPBOARD_MODE);
+}
+
+} // namespace frontend
+} // namespace lyx
Property changes on: src\frontends\qt4\LyxClipboard.C
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/qt4/LyxClipboard.h
===================================================================
--- src/frontends/qt4/LyxClipboard.h (revision 0)
+++ src/frontends/qt4/LyxClipboard.h (revision 0)
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+/**
+ * \file LyxClipboard.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 LYX_CLIPBOARD_H
+#define LYX_CLIPBOARD_H
+
+#include "frontends/Clipboard.h"
+
+namespace lyx {
+namespace frontend {
+
+class Application;
+
+/**
+ * The Qt4 version of the Clipboard.
+ */
+class LyxClipboard: public Clipboard
+{
+public:
+ LyxClipboard(Application * owner): owner_(owner) {}
+
+ virtual ~LyxClipboard() {}
+
+ /** ClipBoard overloaded methods
+ */
+ //@{
+ void haveSelection(bool own);
+ std::string const getClipboard() const;
+ void putClipboard(std::string const & str);
+ //@}
+
+private:
+ Application * owner_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // LYX_CLIPBOARD_H
Property changes on: src\frontends\qt4\LyxClipboard.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/qt4/LyXScreenFactory.C
===================================================================
--- src/frontends/qt4/LyXScreenFactory.C (revision 14001)
+++ src/frontends/qt4/LyXScreenFactory.C (working copy)
@@ -18,7 +18,7 @@
LyXScreen * create(WorkArea & owner)
{
- return &(static_cast<QWorkArea &>(owner));
+ return &(static_cast<lyx::frontend::QWorkArea &>(owner));
}
} // namespace LyXScreenFactory
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am (revision 14001)
+++ src/frontends/qt4/Makefile.am (working copy)
@@ -85,6 +85,8 @@
QtLyXView.h \
WorkAreaFactory.C \
checkedwidgets.C checkedwidgets.h \
+ LyxClipboard.C LyxClipboard.h \
+ Application.C Application.h \
lyx_gui.C \
lcolorcache.h lcolorcache.C \
panelstack.h panelstack.C \
Index: src/frontends/qt4/QLPainter.C
===================================================================
--- src/frontends/qt4/QLPainter.C (revision 14001)
+++ src/frontends/qt4/QLPainter.C (working copy)
@@ -33,6 +33,8 @@
using std::endl;
using std::string;
+namespace lyx {
+namespace frontend {
QLPainter::~QLPainter()
{
@@ -261,3 +263,6 @@
QPainter qp(qwa_->paintDevice());
qp.drawImage(x, y, image);
}
+
+} // namespace frontend
+} // namespace lyx
Index: src/frontends/qt4/QLPainter.h
===================================================================
--- src/frontends/qt4/QLPainter.h (revision 14001)
+++ src/frontends/qt4/QLPainter.h (working copy)
@@ -23,6 +23,10 @@
class QString;
class QPixmap;
class QImage;
+
+namespace lyx {
+namespace frontend {
+
class QWorkArea;
/**
@@ -149,4 +153,7 @@
QWorkArea * qwa_;
};
+} // namespace frontend
+} // namespace lyx
+
#endif // QLPAINTER_H
Index: src/frontends/qt4/QWorkArea.C
===================================================================
--- src/frontends/qt4/QWorkArea.C (revision 14001)
+++ src/frontends/qt4/QWorkArea.C (working copy)
@@ -20,14 +20,13 @@
#include "lcolorcache.h"
#include "qt_helpers.h"
+#include "Application.h"
#include "BufferView.h"
#include "debug.h"
#include "funcrequest.h"
#include "LColor.h"
#include "support/os.h"
-#include <QApplication>
-#include <QClipboard>
#include <QLayout>
#include <QMainWindow>
#include <QMimeData>
@@ -39,22 +38,6 @@
#include <boost/bind.hpp>
-///////////////////////////////////////////////////////////////
-// Specific stuff
-#ifdef Q_WS_X11
-#include <X11/Xlib.h>
-#endif
-
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#include <support/lstrings.h>
-using lyx::support::subst;
-#endif
-
-// You can find other qt-immodule, X11 and MACX specific stuff
-// at the end of this file...
-///////////////////////////////////////////////////////////////
-
using std::endl;
using std::string;
@@ -62,8 +45,6 @@
namespace {
-QWorkArea * wa_ptr = 0;
-
/// return the LyX key state from Qt's
key_modifier::state q_key_state(Qt::ButtonState state)
{
@@ -114,6 +95,9 @@
} // namespace anon
+namespace lyx {
+namespace frontend {
+
// This is a 'heartbeat' generating synthetic mouse move events when the
// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
SyntheticMouseEvent::SyntheticMouseEvent()
@@ -187,17 +171,6 @@
setInputMethodEnabled(true);
#endif
-#ifdef Q_WS_X11
- // doubleClickInterval() is 400 ms on X11 witch is just too long.
- // On Windows and Mac OS X, the operating system's value is used.
- // On Microsoft Windows, calling this function sets the double
- // click interval for all applications. So we don't!
- QApplication::setDoubleClickInterval(300);
-#endif
-
-#ifdef Q_WS_MACX
- wa_ptr = this;
-#endif
}
QWorkArea::~QWorkArea()
@@ -231,50 +204,6 @@
}
-void QWorkArea::haveSelection(bool own) const
-{
- /// \todo ask X11 and MAC devels why this wa_ptr is useful.
- wa_ptr = const_cast<QWorkArea*>(this);
-
- if (!QApplication::clipboard()->supportsSelection())
- return;
-
- if (own) {
- QApplication::clipboard()->setText(QString(),
QClipboard::Selection);
- }
- // We don't need to do anything if own = false, as this case is
- // handled by QT.
-}
-
-
-string const QWorkArea::getClipboard() const
-{
- QString str = QApplication::clipboard()->text(QClipboard::Selection);
- lyxerr[Debug::ACTION] << "getClipboard: " << (const char*) str << endl;
- if (str.isNull())
- return string();
-#ifdef Q_WS_MACX
- // The MAC clipboard uses \r for lineendings, and we use \n
- return subst(fromqstr(str), '\r', '\n');
-#else
- return fromqstr(str);
-#endif
-}
-
-
-void QWorkArea::putClipboard(string const & str) const
-{
-#ifdef Q_WS_MACX
- // The MAC clipboard uses \r for lineendings, and we use \n
- QApplication::clipboard()->setText(toqstr(subst(str, '\n', '\r')),
- QClipboard::Selection);
-#else
- QApplication::clipboard()->setText(toqstr(str), QClipboard::Selection);
-#endif
- lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
-}
-
-
void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
{
if (event->mimeData()->hasUrls())
@@ -282,7 +211,6 @@
/// \todo Ask lyx-devel is this is enough:
/// if (event->mimeData()->hasFormat("text/plain"))
/// event->acceptProposedAction();
-
}
@@ -394,7 +322,7 @@
{
// Wheel rotation by one notch results in a delta() of 120 (see
// documentation of QWheelEvent)
- int const lines = QApplication::wheelScrollLines() * e->delta() / 120;
+ int const lines = qApp->wheelScrollLines() * e->delta() / 120;
verticalScrollBar()->setValue(verticalScrollBar()->value() -
lines * verticalScrollBar()->lineStep());
adjustViewWithScrollBar();
@@ -419,6 +347,7 @@
}
}
+
void QWorkArea::keyPressEvent(QKeyEvent * e)
{
lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
@@ -513,6 +442,7 @@
*/
}
+
void QWorkArea::update(int x, int y, int w, int h)
{
//screen_device_.fromImage(paint_device_);
@@ -522,6 +452,7 @@
viewport()->update(x, y, w, h);
}
+
void QWorkArea::paintEvent(QPaintEvent * e)
{
/*
@@ -554,6 +485,7 @@
return paint_device_.copy(x, y, w, h);
}
+
void QWorkArea::drawScreen(int x, int y, QPixmap pixmap)
{
QPainter q(&paint_device_);
@@ -674,97 +606,7 @@
}
#endif
+} // namespace frontend
+} // namespace lyx
-////////////////////////////////////////////////////////////////////////
-// X11 specific stuff goes here...
-
-#ifdef Q_WS_X11
-bool lyxX11EventFilter(XEvent * xev)
-{
- switch (xev->type) {
- case SelectionRequest:
- lyxerr[Debug::GUI] << "X requested selection." << endl;
- if (wa_ptr)
- wa_ptr->view().view()->selectionRequested();
- break;
- case SelectionClear:
- lyxerr[Debug::GUI] << "Lost selection." << endl;
- if (wa_ptr)
- wa_ptr->view().view()->selectionLost();
- break;
- }
- return false;
-}
-#endif
-
-
-////////////////////////////////////////////////////////////////////////
-// Mac OSX specific stuff goes here...
-
-#ifdef Q_WS_MACX
-namespace{
-OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
- typeWildCard, &returnedType, nil, 0,
- &actualSize);
- switch (err) {
- case errAEDescNotFound:
- return noErr;
- case noErr:
- return errAEEventNotHandled;
- default:
- return err;
- }
- }
-}
-
-pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
- AppleEvent* /*reply*/, long /*refCon*/)
-{
- QString s_arg;
- AEDescList documentList;
- OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
- &documentList);
- if (err != noErr)
- return err;
-
- err = checkAppleEventForMissingParams(*inEvent);
- if (err == noErr) {
- long documentCount;
- err = AECountItems(&documentList, &documentCount);
- for (long documentIndex = 1;
- err == noErr && documentIndex <= documentCount;
- documentIndex++) {
- DescType returnedType;
- Size actualSize;
- AEKeyword keyword;
- FSRef ref;
- char qstr_buf[1024];
- err = AESizeOfNthItem(&documentList, documentIndex,
- &returnedType, &actualSize);
- if (err == noErr) {
- err = AEGetNthPtr(&documentList, documentIndex,
- typeFSRef, &keyword,
- &returnedType, (Ptr)&ref,
- sizeof(FSRef), &actualSize);
- if (err == noErr) {
- FSRefMakePath(&ref, (UInt8*)qstr_buf,
- 1024);
- s_arg=QString::fromUtf8(qstr_buf);
- wa_ptr->view().view()->workAreaDispatch(
- FuncRequest(LFUN_FILE_OPEN,
- fromqstr(s_arg)));
- break;
- }
- }
- } // for ...
- }
- AEDisposeDesc(&documentList);
- return err;
-}
-#endif // Q_WS_MACX
-
#include "QWorkArea_moc.cpp"
Index: src/frontends/qt4/QWorkArea.h
===================================================================
--- src/frontends/qt4/QWorkArea.h (revision 14001)
+++ src/frontends/qt4/QWorkArea.h (working copy)
@@ -22,7 +22,8 @@
#undef emit
#endif
-#include "WorkArea.h"
+#include "frontends/WorkArea.h"
+#include "frontends/Clipboard.h"
#include "QLPainter.h"
#include "LyXView.h"
#include "screen.h"
@@ -49,6 +50,9 @@
class QDropEvent;
class QMouseEvent;
+namespace lyx {
+namespace frontend {
+
/// for emulating triple click
class double_click {
public:
@@ -70,7 +74,6 @@
state(e->button()), active(true) {}
};
-
/** Qt only emits mouse events when the mouse is being moved, but
* we want to generate 'pseudo' mouse events when the mouse button is
* pressed and the mouse cursor is below the bottom, or above the top
@@ -96,7 +99,8 @@
* Qt-specific implementation of the work area
* (buffer view GUI)
*/
-class QWorkArea : public QAbstractScrollArea, public WorkArea, public
LyXScreen {
+class QWorkArea
+ : public QAbstractScrollArea, public WorkArea, public LyXScreen {
Q_OBJECT
@@ -113,16 +117,7 @@
///
virtual void setScrollbarParams(int height, int pos, int line_height);
- /// a selection exists
- virtual void haveSelection(bool) const;
-
///
- virtual std::string const getClipboard() const;
-
- ///
- virtual void putClipboard(std::string const &) const;
-
- ///
virtual void dragEnterEvent(QDragEnterEvent * event);
///
@@ -184,7 +179,7 @@
#if USE_INPUT_METHODS
protected:
/// IM events
- void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
+ void inputMethodEvent(QInputMethodEvent * e);
#endif
public slots:
@@ -259,4 +254,7 @@
Cursor_Shape cursor_shape_;
};
+} // namespace frontend
+} // namespace lyx
+
#endif // QWORKAREA_H
Index: src/frontends/qt4/WorkAreaFactory.C
===================================================================
--- src/frontends/qt4/WorkAreaFactory.C (revision 14001)
+++ src/frontends/qt4/WorkAreaFactory.C (working copy)
@@ -11,13 +11,25 @@
#include <config.h>
#include "frontends/WorkAreaFactory.h"
-#include "QWorkArea.h"
+#include "Application.h"
+using lyx::frontend::Application;
+
namespace WorkAreaFactory {
WorkArea * create(LyXView & owner, int w, int h)
{
- return new QWorkArea(owner, w, h);
+ Application * theApp = static_cast<Application *> qApp;
+
+ return theApp->newWorkArea(owner, w, h);
}
+
+Clipboard * getClipboard()
+{
+ Application * theApp = static_cast<Application *> qApp;
+
+ return theApp->lyxClipboard();
+}
+
} // namespace WorkAreaFactory
Index: src/frontends/WorkArea.h
===================================================================
--- src/frontends/WorkArea.h (revision 14001)
+++ src/frontends/WorkArea.h (working copy)
@@ -50,14 +50,6 @@
* @param line_height the line-scroll amount, in pixels
*/
virtual void setScrollbarParams(int height, int pos, int line_height) =
0;
-
- // FIXME: this is an odd place to have it, but xforms needs it here ...
- /// a selection exists
- virtual void haveSelection(bool) const = 0;
- /// get the X clipboard contents
- virtual std::string const getClipboard() const = 0;
- /// fill the clipboard
- virtual void putClipboard(std::string const &) const = 0;
};
#endif // WORKAREA_H
Index: src/frontends/WorkAreaFactory.h
===================================================================
--- src/frontends/WorkAreaFactory.h (revision 14001)
+++ src/frontends/WorkAreaFactory.h (working copy)
@@ -14,6 +14,7 @@
class WorkArea;
class LyXView;
+class Clipboard;
namespace WorkAreaFactory {
/**
@@ -21,6 +22,11 @@
* a toolkit-specific instance.
*/
WorkArea * create(LyXView & owner, int w, int h);
+
+ /**
+ * Get the toolkit-specific clipboard instance.
+ */
+ Clipboard * getClipboard();
}
#endif // WORKAREA_FACTORY_H
Index: src/frontends/xforms/WorkAreaFactory.C
===================================================================
--- src/frontends/xforms/WorkAreaFactory.C (revision 14001)
+++ src/frontends/xforms/WorkAreaFactory.C (working copy)
@@ -16,9 +16,20 @@
namespace WorkAreaFactory {
+static XWorkArea * work_area_ = 0;
+
WorkArea * create(LyXView & owner, int w, int h)
{
- return new lyx::frontend::XWorkArea(owner, w, h);
+ work_area_ = new lyx::frontend::XWorkArea(owner, w, h);
+ return work_area_;
}
+/**
+The call to this method must be done after the WorkArea creation.
+*/
+Clipboard * getClipboard()
+{
+ return work_area_;
}
+
+}
Index: src/frontends/xforms/XWorkArea.C
===================================================================
--- src/frontends/xforms/XWorkArea.C (revision 14001)
+++ src/frontends/xforms/XWorkArea.C (working copy)
@@ -613,7 +613,7 @@
}
-void XWorkArea::haveSelection(bool yes) const
+void XWorkArea::haveSelection(bool yes)
{
Window const owner = yes ? FL_ObjWin(work_area) : None;
XSetSelectionOwner(fl_get_display(), XA_PRIMARY, owner, CurrentTime);
@@ -642,7 +642,7 @@
}
-void XWorkArea::putClipboard(string const & s) const
+void XWorkArea::putClipboard(string const & s)
{
static string hold;
hold = s;
Index: src/frontends/xforms/XWorkArea.h
===================================================================
--- src/frontends/xforms/XWorkArea.h (revision 14001)
+++ src/frontends/xforms/XWorkArea.h (working copy)
@@ -14,6 +14,7 @@
#define XWORKAREA_H
#include "frontends/WorkArea.h"
+#include "frontends/Clipboard.h"
#include "XPainter.h"
#include "LayoutEngine.h"
@@ -25,7 +26,7 @@
namespace lyx {
namespace frontend {
-class XWorkArea : public WorkArea {
+class XWorkArea : public WorkArea, public Clipboard {
public:
///
XWorkArea(LyXView & owner, int width, int height);
@@ -56,11 +57,11 @@
/// xforms callback from scrollbar
void scroll_cb();
/// a selection exists
- virtual void haveSelection(bool) const;
+ virtual void haveSelection(bool);
///
virtual std::string const getClipboard() const;
///
- virtual void putClipboard(std::string const &) const;
+ virtual void putClipboard(std::string const &);
/// handles SelectionRequest X Event, to fill the clipboard
int event_cb(XEvent * xev);