2008-04-19 19:31:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-04-19 19:31:50 +04:00
|
|
|
|
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include <qapplication.h>
|
2008-04-19 19:35:04 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2008-04-23 11:04:55 +04:00
|
|
|
#include <qabstracteventdispatcher.h>
|
2012-05-03 14:22:58 +04:00
|
|
|
#include <qthread.h>
|
2008-04-23 00:05:03 +04:00
|
|
|
|
|
|
|
#include "prenv.h"
|
2010-04-23 03:29:18 +04:00
|
|
|
#include "nsQAppInstance.h"
|
2008-04-19 19:31:50 +04:00
|
|
|
|
2008-04-20 12:16:40 +04:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#include "prlog.h"
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 19:37:51 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo *gWidgetLog = nsnull;
|
|
|
|
PRLogModuleInfo *gWidgetFocusLog = nsnull;
|
|
|
|
PRLogModuleInfo *gWidgetIMLog = nsnull;
|
|
|
|
PRLogModuleInfo *gWidgetDrawLog = nsnull;
|
|
|
|
#endif
|
|
|
|
|
2008-04-22 16:20:42 +04:00
|
|
|
static int sPokeEvent;
|
2008-04-19 19:31:50 +04:00
|
|
|
|
|
|
|
nsAppShell::~nsAppShell()
|
|
|
|
{
|
2010-04-23 03:29:18 +04:00
|
|
|
nsQAppInstance::Release();
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAppShell::Init()
|
|
|
|
{
|
2008-04-19 19:37:51 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gWidgetLog)
|
|
|
|
gWidgetLog = PR_NewLogModule("Widget");
|
|
|
|
if (!gWidgetFocusLog)
|
|
|
|
gWidgetFocusLog = PR_NewLogModule("WidgetFocus");
|
|
|
|
if (!gWidgetIMLog)
|
|
|
|
gWidgetIMLog = PR_NewLogModule("WidgetIM");
|
|
|
|
if (!gWidgetDrawLog)
|
|
|
|
gWidgetDrawLog = PR_NewLogModule("WidgetDraw");
|
|
|
|
#endif
|
2008-04-22 17:51:40 +04:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
|
2008-04-22 16:20:42 +04:00
|
|
|
sPokeEvent = QEvent::registerEventType();
|
2008-04-23 11:04:55 +04:00
|
|
|
#else
|
|
|
|
sPokeEvent = QEvent::User+5000;
|
2008-04-22 17:51:40 +04:00
|
|
|
#endif
|
2010-01-29 09:50:44 +03:00
|
|
|
|
2010-05-16 01:46:18 +04:00
|
|
|
nsQAppInstance::AddRef();
|
|
|
|
|
2008-04-19 19:31:50 +04:00
|
|
|
return nsBaseAppShell::Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAppShell::ScheduleNativeEventCallback()
|
|
|
|
{
|
2008-04-22 16:20:42 +04:00
|
|
|
QCoreApplication::postEvent(this,
|
|
|
|
new QEvent((QEvent::Type) sPokeEvent));
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
|
|
|
|
2008-04-23 00:05:03 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
2008-04-19 19:31:50 +04:00
|
|
|
{
|
2010-01-29 09:50:44 +03:00
|
|
|
QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
|
|
|
|
|
|
|
|
if (mayWait)
|
|
|
|
flags |= QEventLoop::WaitForMoreEvents;
|
|
|
|
|
2012-05-03 14:22:58 +04:00
|
|
|
QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread());
|
2010-01-29 09:50:44 +03:00
|
|
|
if (!dispatcher)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-04-20 12:16:40 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return dispatcher->processEvents(flags) ? true : false;
|
2008-04-19 19:31:50 +04:00
|
|
|
}
|
2008-04-22 16:20:42 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsAppShell::event (QEvent *e)
|
|
|
|
{
|
|
|
|
if (e->type() == sPokeEvent) {
|
|
|
|
NativeEventCallback();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|