* [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
This commit is contained in:
Abdelrazak Younes 2006-06-20 09:17:19 +00:00
parent d8ae51dbe1
commit c7d3458f99
6 changed files with 320 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 <QApplication>
#include <QEventLoop>
#include <QTranslator>
#include <QTextCodec>
#include <QClipboard>
#ifdef Q_WS_X11
#include <X11/Xlib.h>
#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

View File

@ -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 <QApplication>
///////////////////////////////////////////////////////////////
// Specific stuff
#ifdef Q_WS_MACX
#include <Carbon/Carbon.h>
#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

View File

@ -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 <QApplication>
#include <QClipboard>
#include <QString>
#include <string>
#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

View File

@ -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)