#include "TQtClientFilter.h"
#include "TQtRConfig.h"
#include "TQtClientWidget.h"
#include "TGQt.h"
#include "TQtEventQueue.h"
#include "TQUserEvent.h"
#include "TQtLock.h"
#include "TSystem.h"
#include "TStopwatch.h"
#include "qevent.h"
#include <qdatetime.h>
#include <qcursor.h>
#include <qtextcodec.h>
#if QT_VERSION >= 0x40000
#include <QWheelEvent>
#include <QByteArray>
#include <QFocusEvent>
#include <QPaintEvent>
#include <QCloseEvent>
#include <QMoveEvent>
#include <QKeyEvent>
#include <QResizeEvent>
#include <QMouseEvent>
#endif /* QT_VERSION */
#include <cassert>
#include "KeySymbols.h"
#define QTCLOSE_DESTROY_RESPOND 1
ClassImp(TQtClientFilter)
TQtClientWidget *TQtClientFilter::fgPointerGrabber=0;
TQtClientWidget *TQtClientFilter::fgButtonGrabber =0;
TQtClientWidget *TQtClientFilter::fgActiveGrabber =0;
UInt_t TQtClientFilter::fgGrabPointerEventMask = 0;
Bool_t TQtClientFilter::fgGrabPointerOwner = kFALSE;
QCursor *TQtClientFilter::fgGrabPointerCursor = 0;
TQtPointerGrabber *TQtClientFilter::fgGrabber = 0;
static inline UInt_t MapModifierState(Qt::ButtonState qState)
{
UInt_t state = 0;
#if QT_VERSION < 0x40000
if ( qState & Qt::ShiftButton ) state |= kKeyShiftMask;
if ( qState & Qt::ControlButton ) state |= kKeyControlMask;
if ( qState & Qt::AltButton ) state |= kKeyMod1Mask;
#else /* QT_VERSION */
if ( qState & Qt::ShiftModifier ) state |= kKeyShiftMask;
if ( qState & Qt::ControlModifier ) state |= kKeyControlMask;
if ( qState & Qt::AltModifier ) state |= kKeyMod1Mask;
#endif /* QT_VERSION */
if ( qState & Qt::RightButton ) state |= kButton3Mask;
if ( qState & Qt::MidButton ) state |= kButton2Mask;
if ( qState & Qt::LeftButton ) state |= kButton1Mask;
#if QT_VERSION < 0x40000
if ( qState & Qt::MetaButton ) state |= kKeyLockMask;
#else /* QT_VERSION */
if ( qState & Qt::MetaModifier ) state |= kKeyLockMask;
#endif /* QT_VERSION */
return state;
}
static inline void MapEvent( QWheelEvent &qev, Event_t &ev)
{
ev.fX = qev.x();
ev.fY = qev.y();
ev.fXRoot = qev.globalX();
ev.fYRoot = qev.globalY();
if ( qev.delta() > 0 ) {
ev.fCode = kButton4;
ev.fState |= kButton4Mask;
} else {
ev.fCode = kButton5;
ev.fState |= kButton5Mask;
}
ev.fState |= MapModifierState(qev.state());
ev.fUser[0] = TGQt::rootwid(TGQt::wid(ev.fWindow)->childAt(ev.fX,ev.fY)) ;
qev.ignore();
}
Bool_t TQtClientFilter::IsGrabSelected(UInt_t selectEventMask)
{
return fgGrabber ? fgGrabber->IsGrabSelected(selectEventMask) : kFALSE;
}
static inline void MapEvent(QMouseEvent &qev, Event_t &ev)
{
ev.fX = qev.x();
ev.fY = qev.y();
ev.fXRoot = qev.globalX();
ev.fYRoot = qev.globalY();
Qt::ButtonState state = Qt::NoButton;
switch ( state = (qev.type()== QEvent::MouseMove ? qev.state() : qev.button() ) ) {
case Qt::LeftButton:
ev.fCode = kButton1;
break;
case Qt::MidButton:
ev.fCode = kButton2;
break;
case Qt::RightButton:
ev.fCode = kButton3;
break;
default:
if (qev.type() != QEvent::MouseMove) {
fprintf(stderr,"Error ***. Unexpected event. MapEvent(QMouseEvent &qev, Event_t &ev) state = %d\n",state);
return;
}
break;
};
ev.fState |= MapModifierState(qev.state());
if (ev.fCode)
ev.fUser[0] = TGQt::rootwid(TGQt::wid(ev.fWindow)->childAt(ev.fX,ev.fY)) ;
qev.ignore();
}
struct KeyQSymbolMap_t {
Qt::Key fQKeySym;
EKeySym fKeySym;
};
static KeyQSymbolMap_t gKeyQMap[] = {
{Qt::Key_Escape, kKey_Escape},
{Qt::Key_Tab, kKey_Tab},
{Qt::Key_Backtab, kKey_Backtab},
#if QT_VERSION < 0x40000
{Qt::Key_BackSpace, kKey_Backspace},
#else /* QT_VERSION */
{Qt::Key_Backspace, kKey_Backspace},
#endif /* QT_VERSION */
{Qt::Key_Return, kKey_Return},
{Qt::Key_Insert, kKey_Insert},
{Qt::Key_Delete, kKey_Delete},
{Qt::Key_Pause, kKey_Pause},
{Qt::Key_Print, kKey_Print},
{Qt::Key_SysReq, kKey_SysReq},
{Qt::Key_Home, kKey_Home},
{Qt::Key_End, kKey_End},
{Qt::Key_Left, kKey_Left},
{Qt::Key_Up, kKey_Up},
{Qt::Key_Right, kKey_Right},
{Qt::Key_Down, kKey_Down},
#if QT_VERSION < 0x40000
{Qt::Key_Prior, kKey_Prior},
{Qt::Key_Next, kKey_Next},
#else /* QT_VERSION */
{Qt::Key_PageUp, kKey_Prior},
{Qt::Key_PageDown, kKey_Next},
#endif /* QT_VERSION */
{Qt::Key_Shift, kKey_Shift},
{Qt::Key_Control, kKey_Control},
{Qt::Key_Meta, kKey_Meta},
{Qt::Key_Alt, kKey_Alt},
{Qt::Key_CapsLock, kKey_CapsLock},
{Qt::Key_NumLock , kKey_NumLock},
{Qt::Key_ScrollLock, kKey_ScrollLock},
{Qt::Key_Space, kKey_Space},
{Qt::Key_Tab, kKey_Tab},
{Qt::Key_Enter, kKey_Enter},
{Qt::Key_Equal, kKey_Equal},
{Qt::Key_Asterisk, kKey_Asterisk},
{Qt::Key_Plus, kKey_Plus},
{Qt::Key_Comma, kKey_Comma},
{Qt::Key_Minus, kKey_Minus},
{Qt::Key_Period, kKey_Period},
{Qt::Key_Slash, kKey_Slash},
{Qt::Key(0), (EKeySym) 0}
};
static inline UInt_t MapKeySym(const QKeyEvent &qev)
{
UInt_t text = 0;;
Qt::Key key = Qt::Key(qev.key());
for (int i = 0; gKeyQMap[i].fKeySym; i++) {
if (key == gKeyQMap[i].fQKeySym) {
return UInt_t(gKeyQMap[i].fKeySym);
}
}
#if 0
#if QT_VERSION < 0x40000
QCString r = gQt->GetTextDecoder()->fromUnicode(qev.text());
#else /* QT_VERSION */
QByteArray oar = gQt->GetTextDecoder()->fromUnicode(qev.text());
const char *r = oar.constData();
#endif /* QT_VERSION */
qstrncpy((char *)&text, (const char *)r,1);
return text;
#else
text = UInt_t(qev.ascii());
#if QT_VERSION < 0x40000
if ( (qev.state() & Qt::KeyButtonMask) ) {
#else /* QT_VERSION */
if ( (qev.state() & Qt::KeyboardModifierMask) ) {
#endif /* QT_VERSION */
if ( ( Qt::Key_A <= key && key <= Qt::Key_Z) )
#if QT_VERSION < 0x40000
text = (( qev.state() & Qt::ShiftButton )? 'A' : 'a') + (key - Qt::Key_A) ;
#else /* QT_VERSION */
text = (( qev.state() & Qt::ShiftModifier )? 'A' : 'a') + (key - Qt::Key_A) ;
#endif /* QT_VERSION */
else if ( ( Qt::Key_0 <= key && key <= Qt::Key_9) )
text = '0' + (key - Qt::Key_0);
}
return text;
#endif
}
static inline void MapEvent(const QKeyEvent &qev, Event_t &ev)
{
ev.fType = qev.type() == QEvent::KeyPress ? kGKeyPress : kKeyRelease;
ev.fCode = MapKeySym(qev);
ev.fState = MapModifierState(qev.state());
ev.fCount = qev.count();
ev.fUser[0] = TGQt::rootwid(TGQt::wid(ev.fWindow)->childAt(ev.fX,ev.fY)) ;
}
static inline void MapEvent(const QMoveEvent &qev, Event_t &ev)
{
ev.fX = qev.pos().x();
ev.fY = qev.pos().y();
}
static inline void MapEvent(const QResizeEvent &qev, Event_t &ev)
{
ev.fWidth = qev.size().width();
ev.fHeight = qev.size().height();
}
static inline void MapEvent(const QPaintEvent &qev, Event_t &ev)
{
ev.fX = qev.rect().x();
ev.fY = qev.rect().y();
ev.fWidth = qev.rect().width();
ev.fHeight = qev.rect().height();
ev.fCount = 0;
}
static inline void MapEvent(const TQUserEvent &qev, Event_t &ev)
{
qev.getData(ev);
}
TQtClientFilter::~TQtClientFilter()
{
TQtLock lock;
if (fRootEventQueue) {
delete fRootEventQueue;
fRootEventQueue = 0;
}
}
static inline bool IsMouseCursorInside()
{
bool inside = false;
QPoint absPostion = QCursor::pos();
QWidget *currentW = QApplication::widgetAt(absPostion);
if (currentW) {
QRect widgetRect = currentW->geometry();
widgetRect.moveTopLeft(currentW->mapToGlobal(QPoint(0,0)));
inside = widgetRect.contains(absPostion);
}
return inside;
}
#ifdef QTCLOSE_DESTROY_RESPOND
static void SendCloseMessage(Event_t &closeEvent)
{
if (closeEvent.fType != kDestroyNotify) return;
Event_t event = closeEvent;
event.fType = kClientMessage;
event.fFormat = 32;
event.fHandle = gWM_DELETE_WINDOW;
event.fUser[0] = (Long_t) gWM_DELETE_WINDOW;
event.fUser[1] = 0;
event.fUser[2] = 0;
event.fUser[3] = 0;
event.fUser[4] = 0;
gVirtualX->SendEvent(event.fWindow, &event);
}
#endif
void DebugMe() {
}
static inline QWidget *widgetAt(int x, int y)
{
QWidget *w = (TQtClientWidget *)QApplication::widgetAt(x,y);
w = w ? w->childAt(w->mapFromGlobal(QPoint(x, y ) ), TRUE ) : 0;
return w;
}
void TQtClientFilter::AddKeyEvent( const QKeyEvent &keyEvent, TQtClientWidget *frame)
{
if (frame) {
Event_t &event = *new Event_t;
memset( &event,0,sizeof(Event_t));
QPaintDevice *paintDev = (QPaintDevice *)frame;
event.fWindow = TGQt::rootwid(paintDev);
event.fSendEvent = keyEvent.spontaneous();
event.fTime = QTime::currentTime().msec ();
event.fX = frame->x();
event.fY = frame->y();
event.fWidth = frame->width();
event.fHeight = frame->height();
QPoint pointRoot = frame->mapToGlobal(QPoint(0,0));
event.fXRoot = pointRoot.x();
event.fYRoot = pointRoot.y();
MapEvent(keyEvent,event);
fRootEventQueue->enqueue(&event);
}
}
bool TQtClientFilter::SelectGrab(Event_t &event, UInt_t selectEventMask,QMouseEvent &mouse)
{
return fgGrabber ? fgGrabber->SelectGrab(event,selectEventMask, mouse) : kFALSE;
}
bool TQtClientFilter::eventFilter( QObject *qWidget, QEvent *e ){
UInt_t selectEventMask = 0;
Bool_t grabSelectEvent = kFALSE;
static TStopwatch *filterTime = 0;
static int neventProcessed = 0;
neventProcessed ++;
Event_t &event = *new Event_t;
memset( &event,0,sizeof(Event_t));
event.fType = kOtherEvent;
TQtClientWidget *frame = dynamic_cast<TQtClientWidget *>(qWidget);
if (!(frame ) ) {
if (filterTime) filterTime->Stop();
return kFALSE;
}
QPaintDevice *paintDev = (QPaintDevice *)frame;
event.fWindow = TGQt::rootwid(paintDev);
event.fSendEvent = !e->spontaneous();
event.fTime = QTime::currentTime().msec ();
event.fX = frame->x();
event.fY = frame->y();
event.fWidth = frame->width();
event.fHeight = frame->height();
QPoint pointRoot = frame->mapToGlobal(QPoint(0,0));
event.fXRoot = pointRoot.x();
event.fYRoot = pointRoot.y();
QMouseEvent *mouseEvent = 0;
QWheelEvent *wheelEvent = 0;
QKeyEvent *keyEvent = 0;
QFocusEvent *focusEvent = 0;
Bool_t destroyNotify = kFALSE;
switch ( e->type() ) {
case QEvent::Wheel:
event.fType = kButtonPress;
wheelEvent = (QWheelEvent *)e;
MapEvent(*wheelEvent,event);
selectEventMask |= kButtonPressMask;
break;
case QEvent::MouseButtonPress:
event.fType = kButtonPress;
case QEvent::MouseButtonDblClick:
if (e->type()== QEvent::MouseButtonDblClick)
event.fType = kButtonDoubleClick;
mouseEvent = (QMouseEvent *)e;
MapEvent(*mouseEvent,event);
selectEventMask |= kButtonPressMask;
mouseEvent->accept();
if ( !fgGrabber
#if (QT_VERSION >= 0x040000)
&& fButtonGrabList.count(frame) >0
#else
&& fButtonGrabList.findRef(frame) >=0
#endif
&& frame->IsGrabbed(event) )
{
GrabPointer(frame, frame->ButtonEventMask(),0,frame->GrabButtonCursor(), kTRUE,kFALSE);
fgButtonGrabber = frame;
grabSelectEvent = kTRUE;
}
else {
grabSelectEvent = SelectGrab(event,selectEventMask,*mouseEvent);
}
break;
case QEvent::MouseButtonRelease:
event.fType = kButtonRelease;
mouseEvent = (QMouseEvent *)e;
MapEvent(*mouseEvent,event);
selectEventMask |= kButtonReleaseMask;
if (fgButtonGrabber) {
grabSelectEvent = SelectGrab(event,selectEventMask,*mouseEvent);
if ( !(mouseEvent->stateAfter() & Qt::MouseButtonMask)) {
GrabPointer(0, 0, 0, 0, kFALSE);
}
}
else {
grabSelectEvent = SelectGrab(event,selectEventMask,*mouseEvent);
}
break;
case QEvent::MouseMove:
event.fType = kMotionNotify;
mouseEvent = (QMouseEvent *)e;
MapEvent(*mouseEvent,event);
selectEventMask |= kPointerMotionMask;
if ( (mouseEvent->stateAfter() & Qt::MouseButtonMask) )
{ selectEventMask |= kButtonMotionMask; }
grabSelectEvent = SelectGrab(event,selectEventMask,*mouseEvent);
#if 0
{
TQtClientWidget *w = (TQtClientWidget*)TGQt::wid(event.fWindow);
UInt_t eventMask = w->SelectEventMask();
UInt_t pointerMask = w->PointerMask();
}
#endif
break;
case QEvent::KeyPress:
keyEvent = (QKeyEvent *)e;
MapEvent(*keyEvent,event);
selectEventMask |= kKeyPressMask;
((QKeyEvent *)e)->accept();
break;
case QEvent::KeyRelease:
keyEvent = (QKeyEvent *)e;
MapEvent(*keyEvent,event);
selectEventMask |= kKeyReleaseMask;
((QKeyEvent *)e)->accept();
break;
case QEvent::FocusIn:
focusEvent = (QFocusEvent *)e;
event.fCode = kNotifyNormal;
event.fState = 0;
event.fType = kFocusIn;
selectEventMask |= kFocusChangeMask;
break;
case QEvent::FocusOut:
focusEvent = (QFocusEvent *)e;
event.fCode = kNotifyNormal;
event.fState = 0;
event.fType = kFocusOut;
selectEventMask |= kFocusChangeMask;
break;
case QEvent::Enter:
event.fType = kEnterNotify;
selectEventMask |= kEnterWindowMask | kPointerMotionMask ;
grabSelectEvent = IsGrabSelected(selectEventMask);
break;
case QEvent::Leave:
event.fType = kLeaveNotify;
selectEventMask |= kLeaveWindowMask | kPointerMotionMask;
grabSelectEvent = IsGrabSelected(selectEventMask);
if ( fgGrabber )fgGrabber->ActivateGrabbing();
break;
case QEvent::Close:
event.fType = kDestroyNotify;
selectEventMask |= kStructureNotifyMask;
if (fgGrabber && fgGrabber->IsGrabbing(frame) ) {
GrabPointer(0, 0, 0, 0,kFALSE);
}
#ifndef QTCLOSE_DESTROY_RESPOND
if ( e->spontaneous() && frame->DeleteNotify() )
{
frame->SetDeleteNotify(kFALSE);
destroyNotify = kTRUE;
((QCloseEvent *)e)->accept();
}
#else
frame->SetClosing();
if (!e->spontaneous() )
{
if (frame->DeleteNotify() ) {
frame->SetDeleteNotify(kFALSE);
((QCloseEvent *)e)->accept();
SendCloseMessage(event);
}
}
#endif
break;
case QEvent::Destroy:
event.fType = kDestroyNotify;
selectEventMask |= kStructureNotifyMask;
if (fgGrabber && fgGrabber->IsGrabbing(frame) ) {
GrabPointer(0, 0, 0, 0,kFALSE);
}
#ifdef QTCLOSE_DESTROY_RESPOND
SendCloseMessage(event);
#endif
break;
case QEvent::Show:
case QEvent::ShowWindowRequest:
event.fType = kMapNotify;
selectEventMask |= kStructureNotifyMask;
break;
case QEvent::Paint:
event.fType = kExpose;
MapEvent(*(QPaintEvent *)e,event);
selectEventMask |= kExposureMask;
break;
case QEvent::Hide:
event.fType = kUnmapNotify;
selectEventMask |= kStructureNotifyMask;
break;
case QEvent::Resize:
event.fType = kConfigureNotify;
MapEvent(*(QResizeEvent *)e,event);
selectEventMask |= kStructureNotifyMask;
break;
case QEvent::Move:
event.fType = kConfigureNotify;
MapEvent(*(QMoveEvent *)e,event);
selectEventMask |= kStructureNotifyMask;
break;
case QEvent::Clipboard:
event.fType = kSelectionNotify;
#ifdef R__QTX11
event.fType = kSelectionClear;
#endif
selectEventMask |= kStructureNotifyMask;
break;
default:
if ( e->type() >= TQUserEvent::Id()) {
MapEvent(*(TQUserEvent *)e,event);
grabSelectEvent = kTRUE;
if (event.fType != kClientMessage && event.fType != kDestroyNotify)
fprintf(stderr, "** Error ** TQUserEvent: %d %d\n", event.fType, kClientMessage);
else if (event.fType == kDestroyNotify) {
#ifdef QTDEBUG
int nRemoved = fRootEventQueue->RemoveItems(&event);
fprintf(stderr,"kClientMessage kDestroyNotify %p %d events have been removed from the queue\n",event.fWindow,nRemoved );
#endif
}
} else {
delete &event;
if (filterTime) filterTime->Stop();
return kFALSE;
}
break;
};
bool justInit = false;
if (!fRootEventQueue) {
fRootEventQueue = new TQtEventQueue();
justInit = true;
}
#if ROOT_VERSION_CODE >= ROOT_VERSION(9,15,9)
if (event.fType == kExpose ) {
Bool_t keepEvent4Qt =
(((TQtClientWidget*)(TGQt::wid(event.fWindow)))->IsEventSelected(selectEventMask) );
if (filterTime) filterTime->Stop();
delete &event;
return !keepEvent4Qt;
}
#endif
if ( destroyNotify
|| (event.fType == kClientMessage) || (event.fType == kDestroyNotify) ||
(
( (grabSelectEvent && ( mouseEvent || (event.fType == kEnterNotify ) || (event.fType == kLeaveNotify ) ) )
||
( (!fgGrabber || !( mouseEvent || (event.fType == kEnterNotify ) || (event.fType == kLeaveNotify ) ) )
&&
((TQtClientWidget*)(TGQt::wid(event.fWindow)))->IsEventSelected(selectEventMask) ) ) ) )
{
fRootEventQueue->enqueue(&event);
} else {
delete &event;
if (filterTime) filterTime->Stop();
return kFALSE;
}
if (wheelEvent && !wheelEvent->isAccepted () ) return kFALSE;
if (mouseEvent && !mouseEvent->isAccepted () ) return kFALSE;
if (keyEvent && !keyEvent->isAccepted () ) return kFALSE;
if (focusEvent ) return kFALSE;
switch (e->type() ) {
case QEvent::Show:
case QEvent::ShowWindowRequest:
case QEvent::Hide:
case QEvent::Leave:
case QEvent::Enter:
if (filterTime) filterTime->Stop();
return kFALSE;
default: break;
};
return kTRUE;
}
void TQtClientFilter::GrabPointer(TQtClientWidget *grabber, UInt_t evmask, Window_t ,
QCursor *cursor, Bool_t grab, Bool_t owner_events)
{
TQtPointerGrabber *gr = fgGrabber; fgGrabber = 0;
if (gr) {
if (gr->IsGrabbing(fgButtonGrabber)) fgButtonGrabber = 0;
delete gr;
}
if (grab) {
fgGrabber = new TQtPointerGrabber (grabber,evmask,grabber->SelectEventMask()
, cursor, grab, owner_events);
}
}
TQtPointerGrabber::TQtPointerGrabber(TQtClientWidget *grabber, UInt_t evGrabMask
, UInt_t evInputMask, QCursor *cursor
, Bool_t grab, Bool_t owner_events
, QWidget *confine)
{
fIsActive= kFALSE;
SetGrabPointer(grabber,evGrabMask, evInputMask,cursor,grab,owner_events, confine);
}
TQtPointerGrabber::~TQtPointerGrabber()
{
SetGrabPointer(0,0,0,0,kFALSE);
}
void TQtPointerGrabber::ActivateGrabbing(bool on)
{
static int grabCounter = 0;
assert (fPointerGrabber);
QWidget *qtGrabber = QWidget::mouseGrabber();
if (on) {
if (qtGrabber != fPointerGrabber) {
if (qtGrabber) qtGrabber->releaseMouse();
if (fPointerGrabber->isVisible() ) {
if (fGrabPointerCursor) fPointerGrabber->grabMouse(*fGrabPointerCursor);
else fPointerGrabber->grabMouse();
if (!QApplication::hasGlobalMouseTracking () )
QApplication::setGlobalMouseTracking (true);
grabCounter++;
}
}
} else {
if (fIsActive && (qtGrabber != fPointerGrabber)) {
fprintf(stderr," ** Attention ** TQtPointerGrabber::ActivateGrabbing qtGrabber %p == fPointerGrabber %p\n", qtGrabber, fPointerGrabber);
}
if (qtGrabber) qtGrabber->releaseMouse();
if (fGrabPointerCursor) fPointerGrabber->SetCursor();
if (QApplication::hasGlobalMouseTracking () )
QApplication::setGlobalMouseTracking (false);
}
fIsActive = on;
QWidget *grabber = QWidget::mouseGrabber();
#if (QT_VERSION < 0x40000)
assert ( !fPointerGrabber->isVisible() || (fIsActive && (grabber == fPointerGrabber)) || (!fIsActive && !grabber) );
#else
assert ( !fPointerGrabber->isVisible() || (fIsActive) || (!fIsActive && !grabber) );
#endif
}
void TQtPointerGrabber::SetGrabPointer(TQtClientWidget *grabber
, UInt_t evGrabMask, UInt_t evInputMask
, QCursor *cursor, Bool_t grab, Bool_t owner_events
, QWidget *confine)
{
if (grab) {
fPointerGrabber = grabber;
fGrabPointerEventMask = evGrabMask;
fInputPointerEventMask= evInputMask;
fGrabPointerOwner = owner_events;
fGrabPointerCursor = cursor;
fPointerConfine = confine;
fPointerGrabber->setMouseTracking( fGrabPointerEventMask & kPointerMotionMask );
} else {
fPointerGrabber->setMouseTracking( fInputPointerEventMask & kPointerMotionMask );
DisactivateGrabbing();
fPointerGrabber = 0;
fGrabPointerEventMask = 0;
fGrabPointerOwner = kFALSE;
fGrabPointerCursor = 0;
fPointerConfine = 0;
}
}
bool TQtPointerGrabber::SelectGrab(Event_t &event, UInt_t selectEventMask, QMouseEvent &mouse)
{
TQtClientWidget *widget = (TQtClientWidget*)TGQt::wid(event.fWindow);
bool pass2Root = FALSE;
QWidget *grabber = QWidget::mouseGrabber();
TQtClientWidget *pointerGrabber = fPointerGrabber;
if (fIsActive && grabber && (grabber != (QWidget *)pointerGrabber) )
{
DisactivateGrabbing();
grabber = QWidget::mouseGrabber();
}
bool inside = FALSE;
if ( ( inside = IsMouseCursorInside() ) ) {
if ( grabber ) {
if ( fGrabPointerOwner ) {
DisactivateGrabbing();
widget = (TQtClientWidget *)widgetAt(event.fXRoot,event.fYRoot);
if (widget == pointerGrabber) widget = 0;
} else {
ActivateGrabbing();
widget = 0;
}
} else {
if (!fGrabPointerOwner)
{
ActivateGrabbing();
widget = 0;
} else {
DisactivateGrabbing();
if (widget == pointerGrabber) widget = 0;
}
}
} else {
if ( !grabber ) {
ActivateGrabbing();
grabber = pointerGrabber;
} else {
assert (grabber == (QWidget *)pointerGrabber );
}
widget = 0;
}
if (! (fGrabPointerOwner || inside) )
{
mouse.accept();
if ( IsGrabSelected (selectEventMask) ) {
pointerGrabber->GrabEvent(event);
pass2Root = TRUE;
}
} else {
if ( IsGrabSelected (selectEventMask) ) {
if (widget) {
pass2Root = (widget->SelectEventMask() & selectEventMask);
if (!pass2Root) {
TQtClientWidget *parent = (TQtClientWidget *)widget->parentWidget();
while (parent && !(parent->SelectEventMask() & selectEventMask) && (parent != pointerGrabber) )
{ parent = (TQtClientWidget *)parent->parentWidget(); }
if (!parent || parent == pointerGrabber ) widget =0;
else if (parent && (parent != pointerGrabber) ) {
}
}
}
if (!widget) {
pointerGrabber->GrabEvent(event);
pass2Root = TRUE;
mouse.accept();
}
} else if (widget) {
pass2Root = widget->SelectEventMask() & selectEventMask;
}
}
return pass2Root;
}
Bool_t TQtPointerGrabber::IsGrabSelected(UInt_t selectEventMask) const
{ return fGrabPointerEventMask & selectEventMask; }
Last change: Fri Nov 28 17:01:25 2008
Last generated: 2008-11-28 17:01
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.