bool ApplicationLaunch::winEvent(MSG *message, long *result)
{
   if (message->message == WM_COPYDATA)
   {
      COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(message->lParam);
      if (cds->dwData == OPENFILE)
      {
         QString fileName = QString::fromUtf8(
               reinterpret_cast<char*>(cds->lpData),
               cds->cbData);
         openFileRequest(fileName);
         *result = 1;
         return true;
      }
   }
   else if (message->message == wmGetMainWindowHandle())
   {
      if (pMainWindow_)
         *result = reinterpret_cast<LRESULT>(pMainWindow_->winId());
      else
         *result = NULL;
      return true;
   }
   return QWidget::winEvent(message, result);
}
bool ApplicationLaunch::nativeEvent(const QByteArray & eventType,
                                    void * msg,
                                    long * result)
{
   MSG* message = (MSG*)msg;
   if (message->message == WM_COPYDATA)
   {
      COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(message->lParam);
      if (cds->dwData == OPENFILE)
      {
         QString fileName = QString::fromUtf8(
               reinterpret_cast<char*>(cds->lpData),
               cds->cbData);
         openFileRequest(fileName);
         *result = 1;
         return true;
      }
   }
   else if (message->message == wmGetMainWindowHandle())
   {
      if (pMainWindow_)
         *result = reinterpret_cast<LRESULT>((HWND)(pMainWindow_->winId()));
      else
         *result = 0;
      return true;
   }
   return QWidget::nativeEvent(eventType, message, result);
}
bool PHIPrivateApplication::event( QEvent *e )
{
#ifdef Q_OS_MAC
    if ( e->type()==QEvent::FileOpen ) {
        qDebug( "FileOpenEvent" );
        emit openFileRequest( dynamic_cast<QFileOpenEvent*>(e)->file() );
    }
#endif
    return QApplication::event( e );
}
bool PosixApplication::event(QEvent* pEvent)
{
   switch(pEvent->type())
   {
   case QEvent::FileOpen:
   {
      // get filename
      QString filename = static_cast<QFileOpenEvent*>(pEvent)->file();

      if (activationWindow() == NULL)
      {
         // if we don't yet have an activation window then this is a startup
         // request -- save it so DesktopMain can pull it out later
         startupOpenFileRequest_ = filename;
      }
      else
      {
         // otherwise we are already running so this is an apple event
         // targeted at opening a file in an existing instance

         // if this is a project then re-post the request back to
         // another instance using the command line (this is to
         // circumvent the fact that the first RStudio application
         // launched on OSX gets all of the apple events). note that
         // we don't make this code conditional for __APPLE__ because
         // we'd need the same logic if other platforms started posting
         // FileOpen back to existing instances (e.g. via DDE)

         FilePath filePath(filename.toUtf8().constData());
         if (filePath.exists() && filePath.extensionLowerCase() == ".rproj")
         {
            std::vector<std::string> args;
            args.push_back(filePath.absolutePath());
            launchRStudio(args);
         }
         else
         {
            openFileRequest(filename);
         }
      }

      return true;
   }

   default:
      return QtSingleApplication::event(pEvent);
   }
}