From a8bf36a4137faf17208f66689c6fe0401b3b0f5c Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 26 Jun 2006 17:18:28 +0000 Subject: [PATCH] GUI API Cleanup step 2: merge of the "younes" branch. What's missing git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14234 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Application.C | 175 +++++++++++++++++++++++++++++++ src/frontends/qt4/Application.h | 87 +++++++++++++++ src/frontends/qt4/GuiClipboard.C | 75 +++++++++++++ 3 files changed, 337 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/qt4/Application.C b/src/frontends/qt4/Application.C new file mode 100644 index 0000000000..51e2380a5d --- /dev/null +++ b/src/frontends/qt4/Application.C @@ -0,0 +1,175 @@ +/** + * \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), buffer_view_(0) +{ +#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::setBufferView(BufferView * buffer_view) +{ + buffer_view_ = buffer_view; +} + + +//////////////////////////////////////////////////////////////////////// +// 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 (buffer_view_) + buffer_view_->selectionRequested(); + break; + case SelectionClear: + lyxerr[Debug::GUI] << "Lost selection." << endl; + if (buffer_view_) + buffer_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); +// buffer_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..a176342766 --- /dev/null +++ b/src/frontends/qt4/Application.h @@ -0,0 +1,87 @@ +/** + * \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 "GuiImplementation.h" +#include "FontLoader.h" + +#include + +/////////////////////////////////////////////////////////////// +// Specific stuff + +#ifdef Q_WS_MACX +#include +#endif +/////////////////////////////////////////////////////////////// + +class BufferView; + +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); + + // + Gui & gui() { return gui_; } + /// + FontLoader & fontLoader() { return font_loader_; } + /// + void setBufferView(BufferView * buffer_view); + +private: + /// + BufferView * buffer_view_; + + /// + GuiImplementation gui_; + + /// + FontLoader font_loader_; + +#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 + +extern lyx::frontend::Application * theApp; + + +#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 -- 2.39.2