From c7d3458f99869873b72bef52e68eb4076581bf99 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 20 Jun 2006 09:17:19 +0000 Subject: [PATCH] * [qt3, xforms, gtk]/GuiImplementation::newWorkArea: return 0 * qt4/Application.[Ch]: was not merged (GUI API cleanup merge) for an unknown reason * qt4/clipboard.C: ditto git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14153 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/GuiImplementation.h | 1 + src/frontends/qt3/GuiImplementation.h | 1 + src/frontends/qt4/Application.C | 174 +++++++++++++++++++++++ src/frontends/qt4/Application.h | 68 +++++++++ src/frontends/qt4/GuiClipboard.C | 75 ++++++++++ src/frontends/xforms/GuiImplementation.h | 1 + 6 files changed, 320 insertions(+) create mode 100644 src/frontends/qt4/Application.C create mode 100644 src/frontends/qt4/Application.h create mode 100644 src/frontends/qt4/GuiClipboard.C diff --git a/src/frontends/gtk/GuiImplementation.h b/src/frontends/gtk/GuiImplementation.h index 6f603a66d8..6113a803cf 100644 --- a/src/frontends/gtk/GuiImplementation.h +++ b/src/frontends/gtk/GuiImplementation.h @@ -57,6 +57,7 @@ public: work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); clipboard_.reset(new GuiClipboard(old_work_area_.get())); guiCursor().connect(work_area_.get()); + return 0; } lyx::frontend::WorkArea& workArea(int id) diff --git a/src/frontends/qt3/GuiImplementation.h b/src/frontends/qt3/GuiImplementation.h index 199df59f5a..d210d14e43 100644 --- a/src/frontends/qt3/GuiImplementation.h +++ b/src/frontends/qt3/GuiImplementation.h @@ -55,6 +55,7 @@ public: work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); clipboard_.reset(new GuiClipboard(old_work_area_.get())); guiCursor().connect(work_area_.get()); + return 0; } lyx::frontend::WorkArea& workArea(int id) diff --git a/src/frontends/qt4/Application.C b/src/frontends/qt4/Application.C new file mode 100644 index 0000000000..d8b4fdcea8 --- /dev/null +++ b/src/frontends/qt4/Application.C @@ -0,0 +1,174 @@ +/** + * \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 "GuiWorkArea.h" +#include "Application.h" + +#include "qt_helpers.h" +#include "BufferView.h" +#include "debug.h" +#include "support/lstrings.h" + +#include +#include +#include +#include +#include + +#ifdef Q_WS_X11 +#include +#endif + +using lyx::support::subst; + +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), work_area_(NULL) +{ +#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 +} + +void Application::connect(GuiWorkArea * work_area) +{ + 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 (work_area_) + work_area_->view().view()->selectionRequested(); + break; + case SelectionClear: + lyxerr[Debug::GUI] << "Lost selection." << endl; + if (work_area_) + 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); + 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 diff --git a/src/frontends/qt4/Application.h b/src/frontends/qt4/Application.h new file mode 100644 index 0000000000..0d4357286c --- /dev/null +++ b/src/frontends/qt4/Application.h @@ -0,0 +1,68 @@ +/** + * \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 + +/////////////////////////////////////////////////////////////// +// Specific stuff + +#ifdef Q_WS_MACX +#include +#endif +/////////////////////////////////////////////////////////////// + +namespace lyx { +namespace frontend { + +class GuiWorkArea; + +/// 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); + + void connect(GuiWorkArea * work_area); + +private: + /// + GuiWorkArea * work_area_; + +#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 diff --git a/src/frontends/qt4/GuiClipboard.C b/src/frontends/qt4/GuiClipboard.C new file mode 100644 index 0000000000..6f0238a023 --- /dev/null +++ b/src/frontends/qt4/GuiClipboard.C @@ -0,0 +1,75 @@ +// -*- C++ -*- +/** + * \file GuiClipboard.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 "GuiClipboard.h" +#include "qt_helpers.h" + +#include "debug.h" + +#include +#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 { + +#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; + if (str.isNull()) + return string(); + + return internalLineEnding(fromqstr(str)); +} + + +void GuiClipboard::put(string const & str) +{ + lyxerr[Debug::ACTION] << "putClipboard: " << str << endl; + + qApp->clipboard()->setText(toqstr(externalLineEnding(str)), CLIPBOARD_MODE); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/xforms/GuiImplementation.h b/src/frontends/xforms/GuiImplementation.h index 124b7081af..3ecca0bdce 100644 --- a/src/frontends/xforms/GuiImplementation.h +++ b/src/frontends/xforms/GuiImplementation.h @@ -57,6 +57,7 @@ public: work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); clipboard_.reset(new GuiClipboard(old_work_area_.get())); guiCursor().connect(work_area_.get()); + return 0; } lyx::frontend::WorkArea& workArea(int id)