summaryrefslogtreecommitdiffstats
path: root/src/kernel/qapplication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/qapplication.cpp')
-rw-r--r--src/kernel/qapplication.cpp124
1 files changed, 110 insertions, 14 deletions
diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp
index a552c236c..5b57bd249 100644
--- a/src/kernel/qapplication.cpp
+++ b/src/kernel/qapplication.cpp
@@ -68,6 +68,7 @@
#if defined(QT_THREAD_SUPPORT)
# include "ntqmutex.h"
# include "ntqthread.h"
+# include <private/qthreadinstance_p.h>
#endif // QT_THREAD_SUPPORT
#include <stdlib.h>
@@ -383,7 +384,25 @@ Q_EXPORT TQt::HANDLE tqt_get_application_thread_id()
}
#endif // QT_THREAD_SUPPORT
+#ifndef QT_THREAD_SUPPORT
TQEventLoop *TQApplication::eventloop = 0; // application event loop
+#endif
+
+#ifdef QT_THREAD_SUPPORT
+TQEventLoop* TQApplication::currentEventLoop() {
+ TQThread* thread = TQThread::currentThreadObject();
+ if (thread) {
+ if (thread->d) {
+ return thread->d->eventLoop;
+ }
+ }
+ return NULL;
+}
+#else
+TQEventLoop* TQApplication::currentEventLoop() {
+ return TQApplication::eventloop;
+}
+#endif
#ifndef QT_NO_ACCEL
extern bool tqt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
@@ -516,6 +535,41 @@ TQClipboard *tqt_clipboard = 0; // global clipboard object
#endif
TQWidgetList * tqt_modal_stack=0; // stack of modal widgets
+#ifdef QT_THREAD_SUPPORT
+// thread wrapper for the main() thread
+class TQCoreApplicationThread : public TQThread
+{
+public:
+ inline TQCoreApplicationThread()
+ {
+ TQThreadInstance::setCurrentThread(this);
+
+ // thread should be running and not finished for the lifetime
+ // of the application (even if QCoreApplication goes away)
+ d->running = true;
+ d->finished = false;
+ d->eventLoop = NULL;
+ }
+ inline ~TQCoreApplicationThread()
+ {
+ // avoid warning from TQThread
+ d->running = false;
+ }
+private:
+ inline void run()
+ {
+ // this function should never be called, it is implemented
+ // only so that we can instantiate the object
+ tqFatal("TQCoreApplicationThread: internal error");
+ }
+};
+
+static TQCoreApplicationThread tqt_main_thread;
+static TQThread *mainThread() { return &tqt_main_thread; }
+#else
+static TQThread* mainThread() { return TQThread::currentThread(); }
+#endif
+
// Definitions for posted events
struct TQPostEvent {
TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {}
@@ -818,8 +872,8 @@ void TQApplication::construct( int &argc, char **argv, Type type )
initialize( argc, argv );
if ( tqt_is_gui_used )
tqt_maxWindowRect = desktop()->rect();
- if ( eventloop )
- eventloop->appStartingUp();
+ if ( currentEventLoop() )
+ currentEventLoop()->appStartingUp();
}
/*!
@@ -874,8 +928,8 @@ TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap )
if ( tqt_is_gui_used )
tqt_maxWindowRect = desktop()->rect();
- if ( eventloop )
- eventloop->appStartingUp();
+ if ( currentEventLoop() )
+ currentEventLoop()->appStartingUp();
}
/*!
@@ -916,13 +970,26 @@ TQApplication::TQApplication(Display *dpy, int argc, char **argv,
if ( tqt_is_gui_used )
tqt_maxWindowRect = desktop()->rect();
- if ( eventloop )
- eventloop->appStartingUp();
+ if ( currentEventLoop() )
+ currentEventLoop()->appStartingUp();
}
#endif // Q_WS_X11
+#ifdef QT_THREAD_SUPPORT
+TQThread* TQApplication::guiThread() {
+ return mainThread();
+}
+
+bool TQApplication::isGuiThread() {
+ return (TQThread::currentThreadObject() == guiThread());
+}
+#else
+bool TQApplication::isGuiThread() {
+ return true;
+}
+#endif
void TQApplication::init_precmdline()
{
@@ -1030,8 +1097,8 @@ TQApplication::~TQApplication()
}
#endif
- if ( eventloop )
- eventloop->appClosingDown();
+ if ( currentEventLoop() )
+ currentEventLoop()->appClosingDown();
if ( postRList ) {
TQVFuncList::Iterator it = postRList->begin();
while ( it != postRList->end() ) { // call post routines
@@ -2698,8 +2765,20 @@ bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e)
}
- if (!handled)
+ if (!handled) {
+#if defined(QT_THREAD_SUPPORT)
+ bool locked = TQApplication::tqt_mutex->locked();
+ if (locked) {
+ TQApplication::tqt_mutex->unlock();
+ }
+#endif
consumed = receiver->event( e );
+#if defined(QT_THREAD_SUPPORT)
+ if (locked) {
+ TQApplication::tqt_mutex->lock();
+ }
+#endif
+ }
e->spont = FALSE;
return consumed;
}
@@ -2793,9 +2872,10 @@ void TQApplication::processOneEvent()
*/
TQEventLoop *TQApplication::eventLoop()
{
- if ( !eventloop && !is_app_closing )
+ if ( !currentEventLoop() && !is_app_closing ) {
(void) new TQEventLoop( tqApp, "default event loop" );
- return eventloop;
+ }
+ return currentEventLoop();
}
@@ -3263,8 +3343,23 @@ void TQApplication::postEvent( TQObject *receiver, TQEvent *event )
l->append( pe );
globalPostedEvents->append( pe );
- if (eventloop)
- eventloop->wakeUp();
+#ifdef QT_THREAD_SUPPORT
+ if ( event->type() == TQEvent::MetaCall ) {
+ // Wake up the receiver thread event loop
+ TQThread* thread = receiver->contextThreadObject();
+ if (thread) {
+ if (thread->d) {
+ if (thread->d->eventLoop) {
+ thread->d->eventLoop->wakeUp();
+ }
+ }
+ }
+ return;
+ }
+#endif
+
+ if (currentEventLoop())
+ currentEventLoop()->wakeUp();
}
@@ -3326,7 +3421,8 @@ void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
&& ( receiver == 0 // we send to all receivers
|| receiver == pe->receiver ) // we send to THAT receiver
&& ( event_type == 0 // we send all types
- || event_type == pe->event->type() ) ) { // we send THAT type
+ || event_type == pe->event->type() ) // we send THAT type
+ && ( (!pe->receiver) || (pe->receiver->contextThreadObject() == TQThread::currentThreadObject()) ) ) { // only send if active thread is receiver object owning thread
// first, we diddle the event so that we can deliver
// it, and that noone will try to touch it later.
pe->event->posted = FALSE;