Exemplo n.º 1
0
bool
QvisApplication::macEventFilter(EventHandlerCallRef er, EventRef event)
{
    UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
    bool ret = false;

    switch(eclass)
    {
    case kEventClassWindow:
      { // new scope
        //qDebug("macEventFilter: kEventClassWindow");
        WindowRef wid;
        GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL,
                          sizeof(WindowRef), NULL, &wid);
        QWidget *widget = QWidget::find((WId)wid);
        if(widget)
        {
            if(ekind == kEventWindowShown)
            {
                QString mainWindowName(QString("VisIt ") + QString(VISIT_VERSION));
                if(mainWindowName == QString(widget->windowTitle()))
                    emit showApplication();
                //qDebug("ekind = kEventWindowShown");
            }
            else if(ekind == kEventWindowHidden)
            {
                QString mainWindowName(QString("VisIt ") + QString(VISIT_VERSION));
                if(mainWindowName == QString(widget->windowTitle()))
                    emit hideApplication();            
                //qDebug("ekind = kEventWindowHidden");
            }
#ifdef PRINT_CARBON_EVENTS
            else if(ekind == kEventWindowClose)
                qDebug("\tkEventWindowClose");
            else if(ekind == kEventWindowDrawContent)
                qDebug("\tkEventWindowDrawContent");
            else if(ekind == kEventWindowBoundsChanged)
                qDebug("\tkEventWindowBoundsChanged");
#endif
        }        
        break;
      }
    // Trap for other Carbon events.
    case kEventClassApplication:
        if(ekind == kEventAppDeactivated)
        {
            //qDebug("\tkEventAppDeactivated");

            // We're deactivating the application so the next time we activate it
            // via the menu, we need to make it active.
            needToMakeActive = true;
        }
        else if(ekind == kEventAppActivated)
        {
            //qDebug("\tkEventAppActivated");
            needToMakeActive = false;
        }
#ifdef PRINT_CARBON_EVENTS
        else if(ekind == kEventAppQuit)
            qDebug("\tkEventAppQuit");
        else if(ekind == kEventAppLaunchNotification)
            qDebug("\tkEventAppLaunchNotification");
        else if(ekind == kEventAppLaunched)
            qDebug("\tkEventAppLaunched");
        else if(ekind == kEventAppTerminated)
            qDebug("\tkEventAppTerminated");
        else if(ekind == kEventAppFrontSwitched)
            qDebug("\tkEventAppFrontSwitched");
        else if(ekind == kEventAppFocusMenuBar)
            qDebug("\tkEventAppFocusMenuBar");
        else if(ekind == kEventAppFocusNextDocumentWindow)
            qDebug("\tkEventAppFocusNextDocumentWindow");
        else if(ekind == kEventAppFocusNextFloatingWindow)
            qDebug("\tkEventAppFocusNextFloatingWindow");
        else if(ekind == kEventAppFocusToolbar)
            qDebug("\tkEventAppFocusToolbar");
        else if(ekind == kEventAppFocusDrawer)
            qDebug("\tkEventAppFocusDrawer");
        else if(ekind == kEventAppGetDockTileMenu)
            qDebug("\tkEventAppGetDockTileMenu");
        else if(ekind == kEventAppIsEventInInstantMouser)
            qDebug("\tkEventAppIsEventInInstantMouser");
        else if(ekind == kEventAppHidden)
            qDebug("\tkEventAppHidden");
        else if(ekind == kEventAppShown)
            qDebug("\tkEventAppShown");
        else if(ekind == kEventAppSystemUIModeChanged)
            qDebug("\tkEventAppSystemUIModeChanged");
        else if(ekind == kEventAppAvailableWindowBoundsChanged)
            qDebug("\tkEventAppAvailableWindowBoundsChanged");
        else if(ekind == kEventAppActiveWindowChanged)
            qDebug("\tkEventAppActiveWindowChanged");
        break;
    case kEventClassCommand:
        qDebug("kEventClassCommand");
        break;
    case kEventClassControl:
        qDebug("kEventClassControl");
        break;
    case kEventClassKeyboard:
        qDebug("kEventClassKeyboard");
        break;
#endif
    case kEventClassMenu:
#ifdef PRINT_CARBON_EVENTS
        qDebug("kEventClassMenu");
        if(ekind == kEventMenuBeginTracking)
            qDebug("\tkEventMenuBeginTracking");
        else if(ekind == kEventMenuEndTracking)
            qDebug("\tkEventMenuEndTracking");
        else if(ekind == kEventMenuChangeTrackingMode)
            qDebug("\tkEventMenuChangeTrackingMode");
        else if(ekind == kEventMenuClosed)
            qDebug("\tkEventMenuClosed");
        else if(ekind == kEventMenuTargetItem)
            qDebug("\tkEventMenuTargetItem");
        else if(ekind == kEventMenuMatchKey)
            qDebug("\tkEventMenuMatchKey");
        else if(ekind == kEventMenuEnableItems)
            qDebug("\tkEventMenuEnableItems");
        else
#endif
        if(ekind == kEventMenuOpening)
        {
            //qDebug("\tkEventMenuOpening");

            if(needToMakeActive)
            {
                // If we got here then it's from making the menu active after having
                // left the application for the viewer. In this case, we pull some 
                // tricks on Qt to make it execute the AppActivated event before the
                // current event.
                needToMakeActive = false;

                // Inject a Carbon event to make the application active.
                CreateEvent(NULL, kEventClassApplication, kEventAppActivated, GetCurrentEventTime(),
                     NULL, &request_make_app_active);
                PostEventToQueue(GetCurrentEventQueue(), request_make_app_active, kEventPriorityHigh);
                // Inject a directive to exit a sub-event loop that we'll be creating.
                QTimer::singleShot(10, this, SLOT(exitTheLoop()));

                // Start a new event loop to make the app active and then quit
                // the sub-event loop.
                eventLoop = new QEventLoop(0);
                eventLoop->exec();
            }
        }
        break;
#ifdef PRINT_CARBON_EVENTS
    case kEventClassMouse:
        qDebug("kEventClassMouse");
        break;
#endif
    }

    return ret;
}
/*!
    Pop view from view stack. View object is deleted.
*/
void NmApplication::popView()
{
    if (mViewStack && mViewStack->size() > 0) {
        NmBaseView *view = mViewStack->top();    
        if (view) {
            // Get top view id.
            NmUiViewId topViewId = view->nmailViewId();
            
            // Prepare for send animation if returing from editor and message
            // has been sent.
            if (topViewId == NmUiViewMessageEditor && mUiEngine->isSendingMessage()) {
				// If we are coming from message editor with back button.
				// do not prepare the send animation.
				if (!mBackButtonPressed) {
					mEffects->prepareEffect(NmUiEffects::NmEditorSendMessageAnimation);
				}
	        }
            mBackButtonPressed = false;

            // Move the application to background if closing the message list view
            if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) {
                
                // if the application has been started as embedded service,
                // we must close it. Otherwise we cannot return back to the calling application.
                if (!XQServiceUtil::isEmbedded()) {
                    hideApplication();
                    return;
                }
            }

            mViewStack->pop();
            // Call custom exit function.
            view->aboutToExitView();
            // Remove view from stack.
            mMainWindow->removeView(view);
            
            // If we were in editor and sent a message, pop viewer from stack
            // first so we can go straight to mail list.
            if (!mViewStack->isEmpty() && topViewId == NmUiViewMessageEditor &&
                mUiEngine->isSendingMessage() &&
                mViewStack->top()->nmailViewId() == NmUiViewMessageViewer) {
                NmBaseView *tmpView = mViewStack->pop();
                mMainWindow->removeView(tmpView);
                delete tmpView;
                tmpView = NULL;
            }
            
            if (!mViewStack->isEmpty()) {
                // Activate next view in stack.
                NmBaseView *showView = mViewStack->top();
                mMainWindow->addView(showView);
                mMainWindow->setCurrentView(showView);
                // Store activated view id.
                mActiveViewId=showView->nmailViewId();
                // Perform send animation if requested.
                mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
            }
            
            delete view;
            view = NULL;
            
            // If view was started as service, move the app now to the
            // background, unless it was started when the app was already in
            // foreground.
            if (mServiceViewId == topViewId) {
                mServiceViewId = NmUiViewNone;
                NM_COMMENT("NmApplication::popView() : returned from service view.");
                // If started as embedded or while the app was in foreground,
                // do not hide the app.
                if (!XQServiceUtil::isEmbedded() &&
                    !mForegroundService) {
                    XQServiceUtil::toBackground(true);
                }
            }
        }
    }
    
    // If the view stack is now empty quit the app. This happens also when
    // the app has been started as a service.
    if (mViewStack && mViewStack->size() == 0) {
        exitApplication();
    }
}