Qt 4.8
Functions | Variables
qeventdispatcher_mac.mm File Reference
#include "qplatformdefs.h"
#include "private/qt_mac_p.h"
#include "qeventdispatcher_mac_p.h"
#include "qapplication.h"
#include "qevent.h"
#include "qdialog.h"
#include "qhash.h"
#include "qsocketnotifier.h"
#include "private/qwidget_p.h"
#include "private/qthread_p.h"
#include "private/qapplication_p.h"
#include <private/qcocoaapplication_mac_p.h>
#include "private/qt_cocoa_helpers_mac_p.h"
#include "qmutex.h"

Go to the source code of this file.

Functions

static CFRunLoopRef mainRunLoop ()
 
static void processPostedEvents (QEventDispatcherMacPrivate *const d, const bool blockSendPostedEvents)
 
MacTimerInfoqt_event_get_timer (EventRef)
 
void qt_event_request_select (QEventDispatcherMac *)
 
void qt_event_request_timer (MacTimerInfo *)
 
void qt_event_request_updates ()
 
CFRunLoopSourceRef qt_mac_add_socket_to_runloop (const CFSocketRef socket)
 
bool qt_mac_is_macsheet (const QWidget *)
 
void qt_mac_remove_socket_from_runloop (const CFSocketRef socket, CFRunLoopSourceRef runloop)
 
static bool qt_mac_send_event (QEventLoop::ProcessEventsFlags, OSEventRef event, OSWindowRef pt)
 
void qt_mac_socket_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef, const void *, void *info)
 
static void qt_mac_waitForMoreEvents ()
 
OSWindowRef qt_mac_window_for (const QWidget *)
 
bool qt_sendSpontaneousEvent (QObject *, QEvent *)
 

Variables

bool qt_is_gui_used
 

Function Documentation

◆ mainRunLoop()

static CFRunLoopRef mainRunLoop ( )
inlinestatic

Definition at line 111 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::interrupt(), QEventDispatcherMac::QEventDispatcherMac(), qt_mac_add_socket_to_runloop(), qt_mac_remove_socket_from_runloop(), QEventDispatcherMac::registerTimer(), QEventDispatcherMac::wakeUp(), and QEventDispatcherMac::~QEventDispatcherMac().

112 {
113 #ifndef QT_MAC_USE_COCOA
114  return reinterpret_cast<CFRunLoopRef>(const_cast<void *>(GetCFRunLoopFromEventLoop(GetMainEventLoop())));
115 #else
116  return CFRunLoopGetMain();
117 #endif
118 }

◆ processPostedEvents()

static void processPostedEvents ( QEventDispatcherMacPrivate *const  d,
const bool  blockSendPostedEvents 
)
inlinestatic

Definition at line 1035 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMacPrivate::firstLoopEntry(), and QEventDispatcherMacPrivate::postedEventsSourcePerformCallback().

1036 {
1037  if (blockSendPostedEvents) {
1038  // We're told to not send posted events (because the event dispatcher
1039  // is currently working on setting up the correct session to run). But
1040  // we still need to make sure that we don't fall asleep until pending events
1041  // are sendt, so we just signal this need, and return:
1042  CFRunLoopSourceSignal(d->postedEventsSource);
1043  return;
1044  }
1045 
1046 #ifdef QT_MAC_USE_COCOA
1047  if (d->cleanupModalSessionsNeeded)
1048  d->cleanupModalSessions();
1049 #endif
1050 
1051  if (d->interrupt) {
1052 #ifdef QT_MAC_USE_COCOA
1053  if (d->currentExecIsNSAppRun) {
1054  // The event dispatcher has been interrupted. But since
1055  // [NSApplication run] is running the event loop, we
1056  // delayed stopping it until now (to let cocoa process
1057  // pending cocoa events first).
1058  if (d->currentModalSessionCached)
1059  d->temporarilyStopAllModalSessions();
1060  [NSApp stop:NSApp];
1061  d->cancelWaitForMoreEvents();
1062  }
1063 #endif
1064  return;
1065  }
1066 
1067  if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) {
1068  d->lastSerial = d->serialNumber;
1070  }
1071 }
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
bool canWait
Definition: qthread_p.h:267
QThreadData * threadData
Definition: qobject_p.h:195

◆ qt_event_get_timer()

MacTimerInfo* qt_event_get_timer ( EventRef  )

◆ qt_event_request_select()

void qt_event_request_select ( QEventDispatcherMac )

◆ qt_event_request_timer()

void qt_event_request_timer ( MacTimerInfo )

◆ qt_event_request_updates()

void qt_event_request_updates ( )

◆ qt_mac_add_socket_to_runloop()

CFRunLoopSourceRef qt_mac_add_socket_to_runloop ( const CFSocketRef  socket)

Definition at line 290 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::registerSocketNotifier().

291 {
292  CFRunLoopSourceRef loopSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0);
293  if (!loopSource)
294  return 0;
295 
296  CFRunLoopAddSource(mainRunLoop(), loopSource, kCFRunLoopCommonModes);
297  return loopSource;
298 }
static CFRunLoopRef mainRunLoop()

◆ qt_mac_is_macsheet()

bool qt_mac_is_macsheet ( const QWidget )

Definition at line 295 of file qwidget_mac.mm.

Referenced by QWidgetPrivate::hide_sys(), make_win_eventUPP(), qt_mac_unregister_widget(), and QWidgetPrivate::show_sys().

296 {
297  if (!w)
298  return false;
299 
300  Qt::WindowModality modality = w->windowModality();
301  if (modality == Qt::ApplicationModal)
302  return false;
303  return w->parentWidget() && (modality == Qt::WindowModal || w->windowType() == Qt::Sheet);
304 }
WindowModality
Definition: qnamespace.h:1683

◆ qt_mac_remove_socket_from_runloop()

void qt_mac_remove_socket_from_runloop ( const CFSocketRef  socket,
CFRunLoopSourceRef  runloop 
)

Definition at line 303 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::unregisterSocketNotifier(), and QEventDispatcherMac::~QEventDispatcherMac().

304 {
305  Q_ASSERT(runloop);
306  CFRunLoopRemoveSource(mainRunLoop(), runloop, kCFRunLoopCommonModes);
307  CFSocketDisableCallBacks(socket, kCFSocketReadCallBack);
308  CFSocketDisableCallBacks(socket, kCFSocketWriteCallBack);
309  CFRunLoopSourceInvalidate(runloop);
310 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static CFRunLoopRef mainRunLoop()

◆ qt_mac_send_event()

static bool qt_mac_send_event ( QEventLoop::ProcessEventsFlags  ,
OSEventRef  event,
OSWindowRef  pt 
)
static

Definition at line 454 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::processEvents().

455 {
456 #ifndef QT_MAC_USE_COCOA
457  if(pt && SendEventToWindow(event, pt) != eventNotHandledErr)
458  return true;
459  return !SendEventToEventTarget(event, GetEventDispatcherTarget());
460 #else // QT_MAC_USE_COCOA
461  if (pt)
462  [pt sendEvent:event];
463  else
464  [NSApp sendEvent:event];
465  return true;
466 #endif
467 }
EventRef event

◆ qt_mac_socket_callback()

void qt_mac_socket_callback ( CFSocketRef  s,
CFSocketCallBackType  callbackType,
CFDataRef  ,
const void *  ,
void *  info 
)

Definition at line 265 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::registerSocketNotifier().

266  {
267  QEventDispatcherMacPrivate *const eventDispatcher
268  = static_cast<QEventDispatcherMacPrivate *>(info);
269  int nativeSocket = CFSocketGetNative(s);
270  MacSocketInfo *socketInfo = eventDispatcher->macSockets.value(nativeSocket);
271  QEvent notifierEvent(QEvent::SockAct);
272 
273  // There is a race condition that happen where we disable the notifier and
274  // the kernel still has a notification to pass on. We then get this
275  // notification after we've successfully disabled the CFSocket, but our Qt
276  // notifier is now gone. The upshot is we have to check the notifier
277  // everytime.
278  if (callbackType == kCFSocketReadCallBack) {
279  if (socketInfo->readNotifier)
280  QApplication::sendEvent(socketInfo->readNotifier, &notifierEvent);
281  } else if (callbackType == kCFSocketWriteCallBack) {
282  if (socketInfo->writeNotifier)
283  QApplication::sendEvent(socketInfo->writeNotifier, &notifierEvent);
284  }
285 }
static mach_timebase_info_data_t info
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ qt_mac_waitForMoreEvents()

static void qt_mac_waitForMoreEvents ( )
inlinestatic

Definition at line 515 of file qeventdispatcher_mac.mm.

Referenced by QEventDispatcherMac::processEvents().

516 {
517 #ifndef QT_MAC_USE_COCOA
518  while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, true) == kCFRunLoopRunTimedOut) ;
519 #else
520  // If no event exist in the cocoa event que, wait
521  // (and free up cpu time) until at least one event occur.
522  // This implementation is a bit on the edge, but seems to
523  // work fine:
524  NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
525  untilDate:[NSDate distantFuture]
526  inMode:NSDefaultRunLoopMode
527  dequeue:YES];
528  if (event)
529  [NSApp postEvent:event atStart:YES];
530 #endif
531 }
EventRef event

◆ qt_mac_window_for()

OSWindowRef qt_mac_window_for ( const QWidget )

Definition at line 484 of file qwidget_mac.mm.

Referenced by QEventDispatcherMac::flush().

485 {
486  if (OSViewRef hiview = qt_mac_effectiveview_for(w)) {
488  if (window)
489  return window;
490 
491  if (qt_isGenuineQWidget(hiview)) {
492  // This is a workaround for NSToolbar. When a widget is hidden
493  // by clicking the toolbar button, Cocoa reparents the widgets
494  // to another window (but Qt doesn't know about it).
495  // When we start showing them, it reparents back,
496  // but at this point it's window is nil, but the window it's being brought
497  // into (the Qt one) is for sure created.
498  // This stops the hierarchy moving under our feet.
499  QWidget *toplevel = w->window();
500  if (toplevel != w) {
501  hiview = qt_mac_nativeview_for(toplevel);
502  if (OSWindowRef w = qt_mac_window_for(hiview))
503  return w;
504  }
505 
506  toplevel->d_func()->createWindow_sys();
507  // Reget the hiview since "create window" could potentially move the view (I guess).
508  hiview = qt_mac_nativeview_for(toplevel);
509  return qt_mac_window_for(hiview);
510  }
511  }
512  return 0;
513 }
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view)
Definition: qwidget_mac.mm:453
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
static bool qt_isGenuineQWidget(OSViewRef ref)
Definition: qwidget_mac.mm:464
WindowRef OSWindowRef
Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w)
Definition: qwidget_mac.mm:419
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
HIViewRef OSViewRef
Q_GUI_EXPORT OSViewRef qt_mac_effectiveview_for(const QWidget *w)
Definition: qwidget_mac.mm:424

◆ qt_sendSpontaneousEvent()

bool qt_sendSpontaneousEvent ( QObject ,
QEvent  
)

Definition at line 5779 of file qapplication.cpp.

Referenced by QEventDispatcherMacPrivate::activateTimer().

5780 {
5782 }
EventRef event
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)

Variable Documentation

◆ qt_is_gui_used

bool qt_is_gui_used

Definition at line 492 of file qapplication.cpp.

Referenced by QEventDispatcherMac::hasPendingEvents().