int SurveyToolImplementation::handleObjectMenuSelect(CreatureObject* player, byte selectedID) {
	PlayerObject* playerObject = player->getPlayerObject();

	if(isASubChildOf(player)) {
		if (!playerObject->hasAbility("survey")) {
			player->sendSystemMessage("@error_message:insufficient_skill");
			return 0;
		}

		if (selectedID == 20) { // use object

			if(getRange(player) == 0) {
				sendRangeSui(player);
				return 0;
			}

			Locker locker(_this.getReferenceUnsafeStaticCast());

			ManagedReference<SurveySession*> session = player->getActiveSession(SessionFacadeType::SURVEY).castTo<SurveySession*>();
			if(session == NULL) {
				session = new SurveySession(player);
				session->initializeSession(_this.getReferenceUnsafeStaticCast());
			}

			session->setOpenSurveyTool(_this.getReferenceUnsafeStaticCast());

			ManagedReference<ResourceManager*> resourceManager = cast<ResourceManager*>(server->getZoneServer()->getResourceManager());
			if(resourceManager == NULL) {
				error("null resource manager");
				return 0;
			}
			resourceManager->sendResourceListForSurvey(player, getToolType(), getSurveyType());

			return 0;
		}

		if (selectedID == 133) { // Set Tool Range

			sendRangeSui(player);

			return 0;
		}
	}

	return TangibleObjectImplementation::handleObjectMenuSelect(player, selectedID);
}
mir::EventUPtr mia::Lexicon::translate(droidinput::InputEvent const* android_event)
{
    switch(android_event->getType())
    {
        case AINPUT_EVENT_TYPE_KEY:
        {
            auto kev = static_cast<const droidinput::KeyEvent*>(android_event);
            return mev::make_event(MirInputDeviceId(android_event->getDeviceId()),
                                   kev->getEventTime(),
                                   kev->getMac(),
                                   mia::mir_keyboard_action_from_android(kev->getAction(), kev->getRepeatCount()),
                                   kev->getKeyCode(),
                                   kev->getScanCode(),
                                   mia::mir_modifiers_from_android(kev->getMetaState()));
        }
        case AINPUT_EVENT_TYPE_MOTION:
        {
            if (mia::android_source_id_is_pointer_device(android_event->getSource()))
            {
                auto mev = static_cast<const droidinput::MotionEvent*>(android_event);
                return mev::make_event(MirInputDeviceId(android_event->getDeviceId()),
                                       mev->getEventTime(),
                                       mev->getMac(),
                                       mia::mir_modifiers_from_android(mev->getMetaState()),
                                       mia::mir_pointer_action_from_masked_android(mev->getAction() & AMOTION_EVENT_ACTION_MASK),
                                       mia::mir_pointer_buttons_from_android(mev->getButtonState()),
                                       mev->getX(0), mev->getY(0),
                                       mev->getRawAxisValue(AMOTION_EVENT_AXIS_HSCROLL, 0),
                                       mev->getRawAxisValue(AMOTION_EVENT_AXIS_VSCROLL, 0),
                                       mev->getRawAxisValue(AMOTION_EVENT_AXIS_RX, 0),
                                       mev->getRawAxisValue(AMOTION_EVENT_AXIS_RY, 0));
            }
            else
            {
                auto mev = static_cast<const droidinput::MotionEvent*>(android_event);
                auto ev = mev::make_event(MirInputDeviceId(android_event->getDeviceId()),
                                          mev->getEventTime(),
                                          mev->getMac(),
                                          mia::mir_modifiers_from_android(mev->getMetaState()));
                auto action = mev->getAction();
                size_t index_with_action = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
                auto masked_action = action & AMOTION_EVENT_ACTION_MASK;
                for (unsigned i = 0; i < mev->getPointerCount(); i++)
                {
                    auto action = (i == index_with_action) ? mia::mir_touch_action_from_masked_android(masked_action) :
                        mir_touch_action_change;
                    mev::add_touch(*ev, mev->getPointerId(i), action, mia::mir_tool_type_from_android(mev->getToolType(i)),
                        mev->getX(i), mev->getY(i),
                        mev->getPressure(i), mev->getTouchMajor(i),
			mev->getTouchMinor(i), mev->getSize(i));
                }
                return ev;
            }
        }
    default:
        BOOST_THROW_EXCEPTION(std::logic_error("Invalid android event"));
    }
}
示例#3
0
文件: samsa.c 项目: dacut/juliet
int main (int argc, char **argv, char **envp)
{
#if defined(WIN32)
    PROCESS_INFORMATION procInfo;
    STARTUPINFO startInfo;
#endif
    int myArgvCount = argc;
    int moreArgvCount = /* -cp <classpath> */ 2 + /* <tool-class> */ 1 + /* NULL */ 1;
    char **myArgv = (char **) malloc(sizeof(char*) * (myArgvCount + moreArgvCount));    
    char *toolName = NULL;
    char *cmd_line = NULL;
    int size, i, j;
    int cmd_len = 0;
    int exit_code = -1;
    int newIndex = 0;
    char *root = NULL;
    char *fullExePath = NULL;
    TOOLDATA *pToolData = (TOOLDATA *) malloc(sizeof(TOOLDATA));
    
    int isJavaw = 0;
    int toolType = 0; /* 0 = JRE tool, 1 = JDK tool, 2 = JRE tool in jdk/bin */

    /*
     *  get the root and the construct invocation path for exe
     *  and the full paths to jars.  This way, we can be called 
     *  from anywhere
     */    
    root = getRoot(argv[0]);

//    printf("root = %s\n", root);
    
    if (!root) { 
        fprintf(stderr, "Unable to find JRE/JDK Root");
        return 2;
    }
        
    /* 
     * if we can't figure out what tool we are, just bail
     */    
    toolName = cleanToolName(argv[0]);

//    printf("tool name = %s\n", toolName);
    
    if (toolName == NULL) { 
        fprintf(stderr, "Unknown tool name %s\n", argv[0]);
        return 1;
    }
    
    isJavaw = strcmp(toolName, "javaw") == 0;

    toolType = getToolType(root, toolName);
    if (toolType == -1) {
        fprintf(stderr, "Unable to determine type (JDK/JRE) of tool\n");
        return 1;
    }
      
    /*
     *  get the 'tool data' - right now, this is just the jars
     *  specificly needed by this tool
     */
    pToolData = getToolData(toolName, root, toolType);
       
    if (pToolData == NULL) { 
        return 2;
    }
    
    fullExePath = (char *) malloc(strlen(root) + strlen(JDK_WEXE_POSTFIX) + 1);
    
    strcpy(fullExePath, root);
    
    /* 
     * If we're javaw then we need to javaw to command line
     */
    if (isJavaw) {
        strcat(fullExePath, toolType ? JDK_WEXE_POSTFIX : JRE_WEXE_POSTFIX);
    } else {
        strcat(fullExePath, toolType ? JDK_EXE_POSTFIX : JRE_EXE_POSTFIX);
    }
    
    /*
     *  we're invoking java with the following 
     *    -cp toolpath  clasname .......
     */
    myArgv[newIndex++] = fullExePath;
    
    /*
     *  if we're not java or javaw, put the tools on cp, figure out the tool class to invoke...
     */
    if (strcmp(toolName, "java") && !isJavaw) {
        char *classpath;
        char *buffer;

        myArgvCount = argc + moreArgvCount;
        
        // hangle non-empty -J<flag> options
        for (i = 1; i < argc; i++) { 
            if (argv[i] != NULL && argv[i][0] == '-' && argv[i][1] == 'J' && argv[i][2] != '\0') {
                myArgv[newIndex++] = argv[i] + 2;
            }
        }

        size = strlen(root) * pToolData->numJars +
                   strlen(CLASSPATH_SEP) * (pToolData->numJars - 1) + 1;

        for (i = 0; i < pToolData->numJars; i++) { 
            size += strlen(pToolData->jarList[i]);
        }
                    
        classpath = (char *) malloc(size * sizeof(char));

        strcpy(classpath, root);
        strcat(classpath, pToolData->jarList[0]);

        for (i = 1; i < pToolData->numJars; i++) { 
            strcat(classpath, CLASSPATH_SEP);
            strcat(classpath, root);
            strcat(classpath, pToolData->jarList[i]);
        }
 
        myArgv[newIndex++] = "-cp";
        myArgv[newIndex++] = classpath;

        buffer =
          (char *) malloc(strlen(toolType==1 ? JDK_CLASS_PREFIX : JRE_CLASS_PREFIX)
                          + strlen(toolName) + strlen(CLASS_POSTFIX) + 1);
    
        strcpy(buffer, toolType==1 ? JDK_CLASS_PREFIX : JRE_CLASS_PREFIX);
        strcat(buffer, toolName);
        strcat(buffer, CLASS_POSTFIX);
        
        myArgv[newIndex++] = buffer;

        // copy remaining arguments (skipping -J options)
        for (i = 1; i < argc; i++) {
            if (argv[i] != NULL && argv[i][0] == '-' && argv[i][1] == 'J') continue;
            myArgv[newIndex++] = argv[i];
        }

    } else {
        
        // for 'java' wrappper copy all arguments without changes
        for (i = 1; i < argc; i++) {
            myArgv[newIndex++] = argv[i];
        }

    }
    
    myArgv[newIndex] = NULL;

//    for (i=0; i < myArgvCount; i++) { 
//        printf(" %d = %s\n", i, myArgv[i]);
//    }

    free(toolName);
        
    /*
     * now simply execv() the java app w/ the new params
     */ 
     
#if defined(WIN32)

    /*
     * win32 - CreateProcess() needs a cmd line string
     *   - double quote all arguments to avoid breaking spaces
     *   - prepend existing double quotes with '\'
     */
     
    // determine required memory size for command line arguments
    size = 0;
    for (i=1; i < myArgvCount; i++) {
        if (myArgv[i] != NULL) {
            int arg_len = strlen(myArgv[i]);
            size += /* space */ 1 + /* quotes */ 2 + arg_len;
            for (j = 0; j < arg_len; j++) {
                 if (myArgv[i][j] == '\"') size++;
            }
        }
    }
    
    // allocate memory for whole command line
    cmd_line = (char *) malloc(strlen(fullExePath) + /* quotes */ 2 + /* arguments */ size + /* NULL */ 1);
    
    if (cmd_line == NULL) { 
        fprintf(stderr, "Unable to allocate memory for tool command line %s\n", argv[0]);
        return 4;
    }
    
    // copy quoted exe path
    sprintf(cmd_line, "\"%s\"", fullExePath);
    cmd_len = strlen(cmd_line);
        
    // copy quoted arguments and prepend existing double quotes with '\'
    for (i=1; i < myArgvCount; i++) {
        if (myArgv[i] != NULL) {
            int arg_len = strlen(myArgv[i]);
            cmd_line[cmd_len++] = ' ';  // space delimiter
            cmd_line[cmd_len++] = '\"'; // starting quote
            for (j = 0; j < arg_len; j++) {
                char ch = myArgv[i][j];
                if (ch == '\"') {
                    cmd_line[cmd_len++] = '\\';
                }  
                cmd_line[cmd_len++] = ch;
            }
            cmd_line[cmd_len++] = '\"'; // ending quote
        }
    }
    cmd_line[cmd_len] = '\0';
    
    // create child process
    memset(&procInfo, 0, sizeof(PROCESS_INFORMATION));
    memset(&startInfo, 0, sizeof(STARTUPINFO));
    startInfo.cb = sizeof(STARTUPINFO);
        
    if (!CreateProcess(NULL, cmd_line, NULL, NULL,
                    TRUE, 0, NULL, NULL, &startInfo, &procInfo)) { 

        fprintf(stderr, "Error creating process : %d\n", GetLastError());
        free(cmd_line);
        return exit_code;
    }

    free(cmd_line);

    // wait for child process to finish
    if (!isJavaw && WAIT_FAILED == WaitForSingleObject(procInfo.hProcess, INFINITE)) {

        fprintf(stderr, "Error waiting for process : %d\n", GetLastError());

        // terminate child process before exiting
        if (!TerminateProcess(procInfo.hProcess, -1)) {
            fprintf(stderr, "Error terminating process : %d\n", GetLastError());
        }

    } 
    else {

        // get exit code of the finished child process
        DWORD res = 0;
        if (GetExitCodeProcess(procInfo.hProcess, &res)) {
            exit_code = (int)res;
        }
        else {
            fprintf(stderr, "Error getting process exit code : %d\n", GetLastError());
        } 

    }

    // close child process handles
    CloseHandle(procInfo.hProcess);
    CloseHandle(procInfo.hThread);

    return exit_code;

#else    

    /*
     * linux - use execv() to replace current process
     */
     
    exit_code = execv(fullExePath, myArgv);

    // execv returns here only in case of error
    perror("Error creating process");
    return exit_code;

#endif

}
示例#4
0
QString TTool::updateEnabled() {
  // Disable every tool during playback
  if (m_application->getCurrentFrame()->isPlaying())
    return (enable(false), QString());

  // Release Generic tools at once
  int toolType   = getToolType();
  int targetType = getTargetType();

  if (toolType == TTool::GenericTool) return (enable(true), QString());

  // Retrieve vars and view modes
  TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();

  int rowIndex       = m_application->getCurrentFrame()->getFrame();
  int columnIndex    = m_application->getCurrentColumn()->getColumnIndex();
  TXshColumn *column = (columnIndex >= 0) ? xsh->getColumn(columnIndex) : 0;

  TXshLevel *xl       = m_application->getCurrentLevel()->getLevel();
  TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0;
  int levelType       = sl ? sl->getType() : NO_XSHLEVEL;

  TStageObject *obj =
      xsh->getStageObject(TStageObjectId::ColumnId(columnIndex));
  bool spline = m_application->getCurrentObject()->isSpline();

  bool filmstrip = m_application->getCurrentFrame()->isEditingLevel();

  /*-- MultiLayerStylePickerONのときは、現状に関わらず使用可能 --*/
  if (m_name == T_StylePicker &&
      Preferences::instance()->isMultiLayerStylePickerEnabled())
    return (enable(true), QString());

  // Check against unplaced columns (not in filmstrip mode)
  if (column && !filmstrip) {
    if (column->isLocked())
      return (enable(false), QObject::tr("The current column is locked."));

    else if (!column->isCamstandVisible())
      return (enable(false), QObject::tr("The current column is hidden."));

    else if (column->getSoundColumn())
      return (enable(false),
              QObject::tr("It is not possible to edit the audio column."));

    else if (column->getSoundTextColumn())
      return (
          enable(false),
          QObject::tr(
              "Note columns can only be edited in the xsheet or timeline."));

    if (toolType == TTool::ColumnTool) {
      // Check column target
      if (column->getLevelColumn() && !(targetType & LevelColumns))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Level column."));

      if (column->getMeshColumn() && !(targetType & MeshColumns))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Mesh column."));
    }
  }

  // Check column tools
  if (toolType == TTool::ColumnTool) {
    if (filmstrip)
      return (
          enable(false),
          QObject::tr("The current tool cannot be used in Level Strip mode."));

    if ((!column || column->isEmpty()) && !(targetType & TTool::EmptyTarget))
      return (enable(false), QString());
  }

  // Check LevelRead & LevelWrite tools
  if (toolType & TTool::LevelTool) {
    // Check against splines
    if (spline) {
      return (targetType & Splines)
                 ? (enable(true), QString())
                 : (enable(false), QObject::tr("The current tool cannot be "
                                               "used to edit a motion path."));
    }

    // Check against empty levels
    if (!xl)
      return (targetType & EmptyTarget) ? (enable(true), QString())
                                        : (enable(false), QString());

    // Check against simple-level-edness
    if (!sl)
      return (enable(false),
              QObject::tr("The current level is not editable."));  // Does it
                                                                   // happen at
                                                                   // all btw?

    // Check against level types
    {
      if ((levelType == PLI_XSHLEVEL) && !(targetType & VectorImage))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Vector Level."));

      if ((levelType == TZP_XSHLEVEL) && !(targetType & ToonzImage))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Toonz Level."));

      if ((levelType == OVL_XSHLEVEL) && !(targetType & RasterImage))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Raster Level."));

      if ((levelType == MESH_XSHLEVEL) && !(targetType & MeshImage))
        return (
            enable(false),
            QObject::tr("The current tool cannot be used on a Mesh Level."));
    }

    // Check against impossibly traceable movements on the column
    if ((levelType & LEVELCOLUMN_XSHLEVEL) && !filmstrip) {
      // Test for Mesh-deformed levels
      const TStageObjectId &parentId = obj->getParent();
      if (parentId.isColumn() && obj->getParentHandle()[0] != 'H') {
        TXshSimpleLevel *parentSl =
            xsh->getCell(rowIndex, parentId.getIndex()).getSimpleLevel();
        if (parentSl && parentSl->getType() == MESH_XSHLEVEL)
          return (
              enable(false),
              QObject::tr(
                  "The current tool cannot be used on a mesh-deformed level"));
      }
    }

    // Check TTool::ImageType tools
    if (toolType == TTool::LevelWriteTool) {
      // Check level against read-only status
      if (sl->isReadOnly()) {
        const std::set<TFrameId> &editableFrames = sl->getEditableRange();
        TFrameId currentFid                      = getCurrentFid();

        if (editableFrames.find(currentFid) == editableFrames.end())
          return (
              enable(false),
              QObject::tr(
                  "The current frame is locked: any editing is forbidden."));
      }

      // Check level type write support
      if (sl->getPath().getType() ==
              "psd" ||  // We don't have the API to write psd files
          sl->is16BitChannelLevel() ||  // Inherited by previous implementation.
                                        // Could be fixed?
          sl->getProperties()->getBpp() ==
              1)  // Black & White images. Again, could be fixed?

        return (enable(false),
                QObject::tr("The current level is not editable."));
    }
  }

  return (enable(true), QString());
}