예제 #1
0
    void TextBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::LEFT)
        {
            --mCaretColumn;
            if (mCaretColumn < 0)
            {
                --mCaretRow;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                    mCaretColumn = 0;
                }
                else
                {
                    mCaretColumn = mTextRows[mCaretRow].size();
                }
            }
        }

        else if (key.getValue() == Key::RIGHT)
        {
            ++mCaretColumn;
            if (mCaretColumn > (int)mTextRows[mCaretRow].size())
            {
                ++mCaretRow;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                    if (mCaretRow < 0)
                    {
                        mCaretRow = 0;
                    }

                    mCaretColumn = mTextRows[mCaretRow].size();
                }
                else
                {
                    mCaretColumn = 0;
                }
            }
        }

        else if (key.getValue() == Key::DOWN)
        {
            setCaretRow(mCaretRow + 1);
        }

        else if (key.getValue() == Key::UP)
        {
            setCaretRow(mCaretRow - 1);
        }

        else if (key.getValue() == Key::HOME)
        {
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::END)
        {
            mCaretColumn = mTextRows[mCaretRow].size();
        }

        else if (key.getValue() == Key::ENTER && mEditable)
        {
            mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
                             mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
            mTextRows[mCaretRow].resize(mCaretColumn);
            ++mCaretRow;
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn != 0
                 && mEditable)
        {
			wchar_t c = mTextRows[mCaretRow][mCaretColumn-1];
			if(c < 128) {
				mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
				--mCaretColumn;
			}
			else {
				mTextRows[mCaretRow].erase(mCaretColumn - 3, 3); 
				mCaretColumn -= 3;
			}
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn == 0
                 && mCaretRow != 0
                 && mEditable)
        {
            mCaretColumn = mTextRows[mCaretRow - 1].size();
            mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
            mTextRows.erase(mTextRows.begin() + mCaretRow);
            --mCaretRow;
        }

//         else if (key.getValue() == Key::DELETE
//                  && mCaretColumn < (int)mTextRows[mCaretRow].size()
//                  && mEditable)
		else if (key.getValue() == 1013
			&& mCaretColumn != 0
			&& mEditable)
        {
            mTextRows[mCaretRow].erase(mCaretColumn, 1);
        }

		else if (key.getValue() == 1013
			&& mCaretColumn == (int)mTextRows[mCaretRow].size()
			&& mCaretRow < ((int)mTextRows.size() - 1)
			&& mEditable)
        {
            mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
            mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
        }

        else if(key.getValue() == Key::PAGE_UP)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow -= rowsPerPage;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                }
            }
        }

        else if(key.getValue() == Key::PAGE_DOWN)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow += rowsPerPage;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                }
            }
        }

        else if(key.getValue() == Key::TAB
                && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn, std::string("    "));
            mCaretColumn += 4;
        }

        else if (key.isCharacter()
                 && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn, std::string(1,(char)key.getValue()));
            ++mCaretColumn;
        }

		// ak add ime
		else if (key.isIME())
		{
			char szImeChar[3];

			if (key.getValue() < 128)
			{
				szImeChar[0]=(char)key.getValue();   
				szImeChar[1]='\0';   
			}
			else
			{
				szImeChar[0]=(char)(key.getValue()>>8);   
				szImeChar[1]=(char)key.getValue();
				szImeChar[2]='\0';
			}

			mTextRows[mCaretRow].insert(mCaretColumn, szImeChar);
			++mCaretColumn;
		}
예제 #2
0
void Statistic::getInfo(const Key& key, long& get, long& put) {
    string k = key.toString();
    get = data[k].get;
    put = data[k].put;
}
예제 #3
0
void Statistic::notifyPut(const Key& key) {
    string k = key.toString();
    data[k].put++;
}
예제 #4
0
    void TextBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::Left)
            mText->setCaretPosition(mText->getCaretPosition() - 1);
        
        else if (key.getValue() == Key::Right)
            mText->setCaretPosition(mText->getCaretPosition() + 1);

        else if (key.getValue() == Key::Down)
            mText->setCaretRow(mText->getCaretRow() + 1);

        else if (key.getValue() == Key::Up)
            mText->setCaretRow(mText->getCaretRow() - 1);

        else if (key.getValue() == Key::Home)
            mText->setCaretColumn(0);

        else if (key.getValue() == Key::End)
            mText->setCaretColumn(mText->getNumberOfCharacters(mText->getCaretRow()));

        else if (key.getValue() == Key::Enter && mEditable)
            mText->insert('\n');

        else if (key.getValue() == Key::Backspace && mEditable)
            mText->remove(-1);

        else if (key.getValue() == Key::Delete && mEditable)
            mText->remove(1);

        else if(key.getValue() == Key::PageUp)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mText->setCaretRow(mText->getCaretRow() - rowsPerPage);
            }
        }

        else if(key.getValue() == Key::PageDown)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mText->setCaretRow(mText->getCaretRow() + rowsPerPage);
            }
        }

        else if(key.getValue() == Key::Tab && mEditable)
        {
            mText->insert(' ');
            mText->insert(' ');
            mText->insert(' ');
            mText->insert(' ');
        }

        else if (key.isCharacter() && mEditable)
            mText->insert(key.getValue());

        adjustSize();
        scrollToCaret();

        keyEvent.consume();
    }
예제 #5
0
/**
 * @brief This function will be called after the parser exits a value.
 *
 * @param text This variable contains the text stored in the value.
 */
void Driver::exitValue (string const & text)
{
	Key key = parents.top ();
	key.setString (scalarToText (text));
	keys.append (key);
}
예제 #6
0
TEST (test, copy)
{
	// cout << "testing copy meta" << std::endl;

	Key k ("user/metakey", KEY_META, "", "metavalue", KEY_META, "a", "a metavalue", KEY_META, "b", "b metavalue", KEY_META, "c",
	       "c metavalue", KEY_END);
	Key c;

	c.copyMeta (k, "a");

	succeed_if (k.getMeta<const ckdb::Key *> ("a") == c.getMeta<const ckdb::Key *> ("a"), "copy meta did not work");

	c.copyMeta (k, "");

	succeed_if (k.getMeta<const ckdb::Key *> ("") == c.getMeta<const ckdb::Key *> (""), "copy meta did not work");

	k.setMeta<int> ("a", 420);

	succeed_if (k.getMeta<int> ("a") == 420, "could not get value set before");

	c.copyMeta (k, "a");
	succeed_if (c.getMeta<int> ("a") == 420, "could not get value copied before");
	succeed_if (k.getMeta<const ckdb::Key *> ("a") == c.getMeta<const ckdb::Key *> ("a"), "copy meta did not work");

	c.copyMeta (k, "a");
	succeed_if (c.getMeta<int> ("a") == 420, "could not get value copied before (again)");
	succeed_if (k.getMeta<const ckdb::Key *> ("a") == c.getMeta<const ckdb::Key *> ("a"), "copy meta did not work (again)");

	Key d;
	Key meta;

	k.rewindMeta ();
	while ((meta = k.nextMeta ()))
	{
		d.copyMeta (k, meta.getName ());
	}

	succeed_if (d.getMeta<std::string> ("a") == "420", "did not copy metavalue in the loop");
	succeed_if (d.getMeta<const ckdb::Key *> ("a") == d.getMeta<const ckdb::Key *> ("a"), "copy meta did not work in the loop");

	succeed_if (d.getMeta<std::string> ("") == "metavalue", "did not copy metavalue in the loop");
	succeed_if (d.getMeta<const ckdb::Key *> ("") == d.getMeta<const ckdb::Key *> (""), "copy meta did not work in the loop");

	succeed_if (d.getMeta<std::string> ("b") == "b metavalue", "did not copy metavalue in the loop");
	succeed_if (d.getMeta<const ckdb::Key *> ("b") == d.getMeta<const ckdb::Key *> ("b"), "copy meta did not work in the loop");

	succeed_if (d.getMeta<std::string> ("c") == "c metavalue", "did not copy metavalue in the loop");
	succeed_if (d.getMeta<const ckdb::Key *> ("c") == d.getMeta<const ckdb::Key *> ("c"), "copy meta did not work in the loop");
}
예제 #7
0
	constexpr inline bool operator >=(const Key& key1, const Key& key2) noexcept
	{
		return key1.asUint32() >= key2.asUint32();
	}
예제 #8
0
void
IDBCursor::Continue(JSContext* aCx,
                    JS::Handle<JS::Value> aKey,
                    ErrorResult &aRv)
{
  AssertIsOnOwningThread();

  if (!mTransaction->IsOpen()) {
    aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
    return;
  }

  if (!mHaveValue || mContinueCalled) {
    aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
    return;
  }

  Key key;
  aRv = key.SetFromJSVal(aCx, aKey);
  if (aRv.Failed()) {
    return;
  }

  if (!key.IsUnset()) {
    switch (mDirection) {
      case NEXT:
      case NEXT_UNIQUE:
        if (key <= mKey) {
          aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
          return;
        }
        break;

      case PREV:
      case PREV_UNIQUE:
        if (key >= mKey) {
          aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
          return;
        }
        break;

      default:
        MOZ_CRASH("Unknown direction type!");
    }
  }

  mBackgroundActor->SendContinueInternal(ContinueParams(key));

  mContinueCalled = true;

#ifdef IDB_PROFILER_USE_MARKS
  if (mType == Type_ObjectStore || mType == Type_ObjectStoreKey) {
    IDB_PROFILER_MARK("IndexedDB Request %llu: "
                      "database(%s).transaction(%s).objectStore(%s).cursor(%s)."
                      "continue(%s)",
                      "IDBRequest[%llu] MT IDBCursor.continue()",
                      Request()->GetSerialNumber(),
                      IDB_PROFILER_STRING(Transaction()->Database()),
                      IDB_PROFILER_STRING(Transaction()),
                      IDB_PROFILER_STRING(mSourceObjectStore),
                      IDB_PROFILER_STRING(mDirection),
                      key.IsUnset() ? "" : IDB_PROFILER_STRING(key));
  } else {
    IDB_PROFILER_MARK("IndexedDB Request %llu: "
                      "database(%s).transaction(%s).objectStore(%s).index(%s)."
                      "cursor(%s).continue(%s)",
                      "IDBRequest[%llu] MT IDBCursor.continue()",
                      Request()->GetSerialNumber(),
                      IDB_PROFILER_STRING(Transaction()->Database()),
                      IDB_PROFILER_STRING(Transaction()),
                      IDB_PROFILER_STRING(mSourceIndex->ObjectStore()),
                      IDB_PROFILER_STRING(mSourceIndex),
                      IDB_PROFILER_STRING(mDirection),
                      key.IsUnset() ? "" : IDB_PROFILER_STRING(key));
  }
#endif
}
예제 #9
0
bool KeyManager::LoadFromFile(std::string filename){
    std::ifstream stream;
    stream.open(filename);
    if(!stream.is_open())
    {
        return false;
    }
    std::string row;
    std::getline(stream, row, '\n');
    if (*(row.end()-1) == '\r')
    {
        row.erase(row.end()-1);
    }
    if (*(row.begin()) == '\xef')
    {
        for(int i =0; i<3; i++)
        {
            row.erase(row.begin());
        }
    }
    while (!stream.eof())
    {
        
        while(row != "\xa7")
        {
            int x, y;
            std::stringstream ss(row);
            ss >> x >> y;
            
            sf::Color* color = new sf::Color;
            int c;
            ss >> c;
            color->r=c;
            ss >> c;
            color->g=c;
            ss >> c;
            color->b=c;
            
            Key* key = new Key(x, y, m_texture, color);
            m_keys.insert(std::make_pair(key->GetPickUpRadius(), key));
            
            ltbl::Light_Point* glow = new ltbl::Light_Point();
            glow->m_center = Vec2f(key->GetPickUpRadius()->getPosition().x, mp_lightSystem->m_viewAABB.GetDims().y - key->GetPickUpRadius()->getPosition().y);
            glow->m_radius = key->GetPickUpRadius()->getRadius();
            glow->m_size = 1.0f;
            glow->m_color.r = static_cast<float>(color->r) / 255.0f;
            glow->m_color.g = static_cast<float>(color->g) / 255.0f;
            glow->m_color.b = static_cast<float>(color->b) / 255.0f;
            glow->m_intensity = 2.0f;
            glow->m_spreadAngle = ltbl::pifTimes2;
            glow->m_softSpreadAngle = 0.0f;
            glow->CalculateAABB();
            
            mp_lightManager->AddLight(glow, key);
            
            //glow->SetAlwaysUpdate(false);
            
            std::getline(stream, row, '\n');
            if (*(row.end()-1) == '\r')
            {
                row.erase(row.end()-1);
            }
        }
        std::getline(stream, row, '\n');
        if (row == "")
        {
            break;
        }
    }
    return true;
}
예제 #10
0
	size_t HashKey(const Key& key) const
	{
		return key.HashValue();
	}
예제 #11
0
파일: ls.cpp 프로젝트: waht/libelektra
int LsCommand::getDepth (Key const & key)
{
	return std::distance (key.begin (), key.end ());
}
예제 #12
0
    void Tree::insert(const Key &k, TID tid) {
        N *node = nullptr;
        N *nextNode = root;
        N *parentNode = nullptr;
        uint8_t parentKey, nodeKey = 0;
        uint32_t level = 0;

        while (true) {
            parentNode = node;
            parentKey = nodeKey;
            node = nextNode;

            uint32_t nextLevel = level;

            uint8_t nonMatchingKey;
            Prefix remainingPrefix;
            switch (checkPrefixPessimistic(node, k, nextLevel, nonMatchingKey, remainingPrefix,
                                                           this->loadKey)) { // increases level
                case CheckPrefixPessimisticResult::NoMatch: {
                    assert(nextLevel < k.getKeyLen()); //prevent duplicate key
                    // 1) Create new node which will be parent of node, Set common prefix, level to this node
                    auto newNode = new N4(node->getPrefix(), nextLevel - level);

                    // 2)  add node and (tid, *k) as children
                    newNode->insert(k[nextLevel], N::setLeaf(tid));
                    newNode->insert(nonMatchingKey, node);

                    // 3) update parentNode to point to the new node
                    N::change(parentNode, parentKey, newNode);

                    // 4) update prefix of node
                    node->setPrefix(remainingPrefix,
                                    node->getPrefixLength() - ((nextLevel - level) + 1));

                    return;
                }
                case CheckPrefixPessimisticResult::Match:
                    break;
            }
            assert(nextLevel < k.getKeyLen()); //prevent duplicate key
            level = nextLevel;
            nodeKey = k[level];
            nextNode = N::getChild(nodeKey, node);

            if (nextNode == nullptr) {
                N::insertA(node, parentNode, parentKey, nodeKey, N::setLeaf(tid));
                return;
            }
            if (N::isLeaf(nextNode)) {
                Key key;
                loadKey(N::getLeaf(nextNode), key);

                level++;
                assert(level < key.getKeyLen()); //prevent inserting when prefix of key exists already
                uint32_t prefixLength = 0;
                while (key[level + prefixLength] == k[level + prefixLength]) {
                    prefixLength++;
                }

                auto n4 = new N4(&k[level], prefixLength);
                n4->insert(k[level + prefixLength], N::setLeaf(tid));
                n4->insert(key[level + prefixLength], nextNode);
                N::change(node, k[level - 1], n4);
                return;
            }

            level++;
        }
    }
예제 #13
0
void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
{
  // <keyboard><commands><key>
  TiXmlHandle handle(rootElement);
  TiXmlElement* xmlKey = handle
    .FirstChild("commands")
    .FirstChild("key").ToElement();
  while (xmlKey) {
    const char* command_name = xmlKey->Attribute("command");
    const char* command_key = get_shortcut(xmlKey);
    bool removed = bool_attr_is_true(xmlKey, "removed");

    if (command_name) {
      Command* command = CommandsModule::instance()->getCommandByName(command_name);
      if (command) {
        // Read context
        KeyContext keycontext = KeyContext::Any;
        const char* keycontextstr = xmlKey->Attribute("context");
        if (keycontextstr) {
          if (strcmp(keycontextstr, "Selection") == 0)
            keycontext = KeyContext::SelectionTool;
          else if (strcmp(keycontextstr, "Normal") == 0)
            keycontext = KeyContext::Normal;
        }

        // Read params
        Params params;

        TiXmlElement* xmlParam = xmlKey->FirstChildElement("param");
        while (xmlParam) {
          const char* param_name = xmlParam->Attribute("name");
          const char* param_value = xmlParam->Attribute("value");

          if (param_name && param_value)
            params.set(param_name, param_value);

          xmlParam = xmlParam->NextSiblingElement();
        }

        // add the keyboard shortcut to the command
        Key* key = this->command(command_name, params, keycontext);
        if (key && command_key) {
          Accelerator accel(command_key);

          if (!removed) {
            key->add(accel, source);

            // Add the shortcut to the menuitems with this command
            // (this is only visual, the
            // "CustomizedGuiManager::onProcessMessage" is the only
            // one that process keyboard shortcuts)
            if (key->accels().size() == 1) {
              AppMenus::instance()->applyShortcutToMenuitemsWithCommand(
                command, params, key);
            }
          }
          else
            key->disableAccel(accel);
        }
      }
    }

    xmlKey = xmlKey->NextSiblingElement();
  }

  // Load keyboard shortcuts for tools
  // <gui><keyboard><tools><key>
  xmlKey = handle
    .FirstChild("tools")
    .FirstChild("key").ToElement();
  while (xmlKey) {
    const char* tool_id = xmlKey->Attribute("tool");
    const char* tool_key = get_shortcut(xmlKey);
    bool removed = bool_attr_is_true(xmlKey, "removed");

    if (tool_id) {
      tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id);
      if (tool) {
        Key* key = this->tool(tool);
        if (key && tool_key) {
          LOG(" - Shortcut for tool `%s': <%s>\n", tool_id, tool_key);
          Accelerator accel(tool_key);

          if (!removed)
            key->add(accel, source);
          else
            key->disableAccel(accel);
        }
      }
    }
    xmlKey = xmlKey->NextSiblingElement();
  }

  // Load keyboard shortcuts for quicktools
  // <gui><keyboard><quicktools><key>
  xmlKey = handle
    .FirstChild("quicktools")
    .FirstChild("key").ToElement();
  while (xmlKey) {
    const char* tool_id = xmlKey->Attribute("tool");
    const char* tool_key = get_shortcut(xmlKey);
    bool removed = bool_attr_is_true(xmlKey, "removed");

    if (tool_id) {
      tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id);
      if (tool) {
        Key* key = this->quicktool(tool);
        if (key && tool_key) {
          LOG(" - Shortcut for quicktool `%s': <%s>\n", tool_id, tool_key);
          Accelerator accel(tool_key);

          if (!removed)
            key->add(accel, source);
          else
            key->disableAccel(accel);
        }
      }
    }
    xmlKey = xmlKey->NextSiblingElement();
  }

  // Load special keyboard shortcuts for sprite editor customization
  // <gui><keyboard><spriteeditor>
  xmlKey = handle
    .FirstChild("actions")
    .FirstChild("key").ToElement();
  while (xmlKey) {
    const char* tool_action = xmlKey->Attribute("action");
    const char* tool_key = get_shortcut(xmlKey);
    bool removed = bool_attr_is_true(xmlKey, "removed");

    if (tool_action) {
      KeyAction action = base::convert_to<KeyAction, std::string>(tool_action);
      if (action != KeyAction::None) {
        Key* key = this->action(action);
        if (key && tool_key) {
          LOG(" - Shortcut for action '%s': <%s>\n", tool_action, tool_key);
          Accelerator accel(tool_key);

          if (!removed)
            key->add(accel, source);
          else
            key->disableAccel(accel);
        }
      }
    }
    xmlKey = xmlKey->NextSiblingElement();
  }
}
예제 #14
0
// Manager event handler.
bool CustomizedGuiManager::onProcessMessage(Message* msg)
{
  switch (msg->type()) {

    case kCloseDisplayMessage:
      {
        // Execute the "Exit" command.
        Command* command = CommandsModule::instance()->getCommandByName(CommandId::Exit);
        UIContext::instance()->executeCommand(command);
      }
      break;

    case kDropFilesMessage:
      {
        // If the main window is not the current foreground one. We
        // discard the drop-files event.
        if (getForegroundWindow() != App::instance()->getMainWindow())
          break;

        const DropFilesMessage::Files& files = static_cast<DropFilesMessage*>(msg)->files();

        // Open all files
        Command* cmd_open_file =
          CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
        Params params;

        UIContext* ctx = UIContext::instance();

        for (const auto& fn : files) {
          // If the document is already open, select it.
          Document* doc = static_cast<Document*>(ctx->documents().getByFileName(fn));
          if (doc) {
            DocumentView* docView = ctx->getFirstDocumentView(doc);
            if (docView)
              ctx->setActiveView(docView);
            else {
              ASSERT(false);    // Must be some DocumentView available
            }
          }
          // Load the file
          else {
            params.set("filename", fn.c_str());
            ctx->executeCommand(cmd_open_file, params);
          }
        }
      }
      break;

    case kKeyDownMessage: {
#ifdef _DEBUG
      // Left Shift+Ctrl+Q generates a crash (useful to test the anticrash feature)
      if (msg->ctrlPressed() &&
          msg->shiftPressed() &&
          static_cast<KeyMessage*>(msg)->scancode() == kKeyQ) {
        int* p = nullptr;
        *p = 0;
      }
#endif

      // Call base impl to check if there is a foreground window as
      // top level that needs keys. (In this way we just do not
      // process keyboard shortcuts for menus and tools).
      if (Manager::onProcessMessage(msg))
        return true;

      for (const Key* key : *KeyboardShortcuts::instance()) {
        if (key->isPressed(msg)) {
          // Cancel menu-bar loops (to close any popup menu)
          App::instance()->getMainWindow()->getMenuBar()->cancelMenuLoop();

          switch (key->type()) {

            case KeyType::Tool: {
              tools::Tool* current_tool = App::instance()->activeTool();
              tools::Tool* select_this_tool = key->tool();
              tools::ToolBox* toolbox = App::instance()->getToolBox();
              std::vector<tools::Tool*> possibles;

              // Collect all tools with the pressed keyboard-shortcut
              for (tools::Tool* tool : *toolbox) {
                Key* key = KeyboardShortcuts::instance()->tool(tool);
                if (key && key->isPressed(msg))
                  possibles.push_back(tool);
              }

              if (possibles.size() >= 2) {
                bool done = false;

                for (size_t i=0; i<possibles.size(); ++i) {
                  if (possibles[i] != current_tool &&
                      ToolBar::instance()->isToolVisible(possibles[i])) {
                    select_this_tool = possibles[i];
                    done = true;
                    break;
                  }
                }

                if (!done) {
                  for (size_t i=0; i<possibles.size(); ++i) {
                    // If one of the possibilities is the current tool
                    if (possibles[i] == current_tool) {
                      // We select the next tool in the possibilities
                      select_this_tool = possibles[(i+1) % possibles.size()];
                      break;
                    }
                  }
                }
              }

              ToolBar::instance()->selectTool(select_this_tool);
              return true;
            }

            case KeyType::Command: {
              Command* command = key->command();

              // Commands are executed only when the main window is
              // the current window running at foreground.
              for (auto childWidget : children()) {
                Window* child = static_cast<Window*>(childWidget);

                // There are a foreground window executing?
                if (child->isForeground()) {
                  break;
                }
                // Is it the desktop and the top-window=
                else if (child->isDesktop() && child == App::instance()->getMainWindow()) {
                  // OK, so we can execute the command represented
                  // by the pressed-key in the message...
                  UIContext::instance()->executeCommand(
                    command, key->params());
                  return true;
                }
              }
              break;
            }

            case KeyType::Quicktool: {
              // Do nothing, it is used in the editor through the
              // KeyboardShortcuts::getCurrentQuicktool() function.
              break;
            }

          }
          break;
        }
      }
      break;
    }

    case kTimerMessage:
      if (static_cast<TimerMessage*>(msg)->timer() == defered_invalid_timer) {
        invalidateDisplayRegion(defered_invalid_region);
        defered_invalid_region.clear();
        defered_invalid_timer->stop();
      }
      break;

  }

  return Manager::onProcessMessage(msg);
}
예제 #15
0
    void TextField::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::Left)
            mText->setCaretPosition(mText->getCaretPosition() - 1);

        else if (key.getValue() == Key::Right)
            mText->setCaretPosition(mText->getCaretPosition() + 1);

        else if (key.getValue() == Key::Delete && mEditable)
            mText->remove(1);

        else if (key.getValue() == Key::Backspace && mEditable)
            mText->remove(-1);

        else if (key.getValue() == Key::Enter)
            distributeActionEvent();

        else if (key.getValue() == Key::Home)
            mText->setCaretColumn(0);

        else if (key.getValue() == Key::End)
            mText->setCaretColumn(mText->getNumberOfCharacters(0));

        else if (key.isCharacter()
                 && key.getValue() != Key::Tab
                 && mEditable)
            mText->insert(key.getValue());

        if (key.getValue() != Key::Tab)
            keyEvent.consume();

        fixScroll();
    }
예제 #16
0
void
IDBCursor::Continue(JSContext* aCx,
                    JS::Handle<JS::Value> aKey,
                    ErrorResult &aRv)
{
  AssertIsOnOwningThread();

  if (!mTransaction->IsOpen()) {
    aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
    return;
  }

  if (IsSourceDeleted() || !mHaveValue || mContinueCalled) {
    aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
    return;
  }

  Key key;
  aRv = key.SetFromJSVal(aCx, aKey);
  if (aRv.Failed()) {
    return;
  }

  if (!key.IsUnset()) {
    switch (mDirection) {
      case NEXT:
      case NEXT_UNIQUE:
        if (key <= mKey) {
          aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
          return;
        }
        break;

      case PREV:
      case PREV_UNIQUE:
        if (key >= mKey) {
          aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
          return;
        }
        break;

      default:
        MOZ_CRASH("Unknown direction type!");
    }
  }

  const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
  mRequest->SetLoggingSerialNumber(requestSerialNumber);

  if (mType == Type_ObjectStore || mType == Type_ObjectStoreKey) {
    IDB_LOG_MARK("IndexedDB %s: Child  Transaction[%lld] Request[%llu]: "
                   "database(%s).transaction(%s).objectStore(%s)."
                   "cursor(%s).continue(%s)",
                 "IndexedDB %s: C T[%lld] R[%llu]: IDBCursor.continue()",
                 IDB_LOG_ID_STRING(),
                 mTransaction->LoggingSerialNumber(),
                 requestSerialNumber,
                 IDB_LOG_STRINGIFY(mTransaction->Database()),
                 IDB_LOG_STRINGIFY(mTransaction),
                 IDB_LOG_STRINGIFY(mSourceObjectStore),
                 IDB_LOG_STRINGIFY(mDirection),
                 IDB_LOG_STRINGIFY(key));
  } else {
    IDB_LOG_MARK("IndexedDB %s: Child  Transaction[%lld] Request[%llu]: "
                   "database(%s).transaction(%s).objectStore(%s)."
                   "index(%s).cursor(%s).continue(%s)",
                 "IndexedDB %s: C T[%lld] R[%llu]: IDBCursor.continue()",
                 IDB_LOG_ID_STRING(),
                 mTransaction->LoggingSerialNumber(),
                 requestSerialNumber,
                 IDB_LOG_STRINGIFY(mTransaction->Database()),
                 IDB_LOG_STRINGIFY(mTransaction),
                 IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
                 IDB_LOG_STRINGIFY(mSourceIndex),
                 IDB_LOG_STRINGIFY(mDirection),
                 IDB_LOG_STRINGIFY(key));
  }

  mBackgroundActor->SendContinueInternal(ContinueParams(key));

  mContinueCalled = true;
}
예제 #17
0
int main(int argc, char** argv)
{
	if(argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " listen_port [boostrap_host:port]" << std::endl;
		return EXIT_FAILURE;
	}

	srand(time(NULL));

	DHT* dht = new DHT(NULL, StrToTyp<uint16_t>(argv[1]));

	pf_log.SetLoggedFlags("DESYNCH WARNING ERR INFO DHT", false);
	Scheduler::StartSchedulers(5);

	if(argc > 2)
	{
		Host host = hosts_list.DecodeHost(argv[2]);
		pf_log[W_INFO] << "Connecting to " << host;
		dht->GetChimera()->Join(host);
	}

	std::string s;
	while(std::getline(std::cin, s))
	{
		std::string command_str = stringtok(s, " ");
		Key k;

		if(command_str.length() == 0)
			continue;

		switch(command_str[0])
		{
			case 's':
			case 'S':
				pf_log[W_DHT] << dht->GetStorage()->GetStr();
				break;
			case 'l':
			case 'L':
				pf_log[W_DHT] << dht->GetChimera()->GetRouting()->GetLeafset()->GetStr();
				break;
			case 'r':
			case 'R':
				pf_log[W_DHT] << dht->GetChimera()->GetRouting()->GetRoutingTable()->GetStr();
				break;
			case 'p':
			case 'P':
				k.MakeHash(s);
				pf_log[W_DHT] << "Publish " << s << " with key " << k;
				dht->Publish(k, s);
				break;
			case 'u':
			case 'U':
				k = stringtok(s, " ");
				pf_log[W_DHT] << "Unublish " << s << " with key " << k;
				dht->Unpublish(k, s);
				break;
			case 'g':
			case 'G':
				k = s;
				pf_log[W_DHT] << "Request data with key " << k;
				if(!dht->RequestData(k))
					if(dht->GetStorage()->hasKey(k))
						pf_log[W_DHT] << dht->GetStorage()->getInfo(k)->GetStr();
				break;
			case 'q':
			case 'Q':
				return EXIT_SUCCESS;
			default:
				pf_log[W_ERR] << "Command not recognized.";
		}
	}

	return EXIT_SUCCESS;
}
예제 #18
0
void SpecMountpointReader::processKey (Key const & ck)
{
	Key k (ck);
	k.rewindMeta ();
	Key m;
	while ((m = k.nextMeta ()))
	{
		std::string const & cn = "config/needs";
		if (startsWith (m.getName (), cn))
		{
			Key bKey = m.dup ();
			bKey.setName ("user" + bKey.getName ().substr (cn.length ()));
			backendConfig.append (bKey);
		}
		else if (m.getName () == "infos/plugins")
		{
			bb.addPlugins (parseArguments (m.getString ()));
		}
		else if (m.getName () == "infos/needs")
		{
			bb.needPlugin (m.getString ());
		}
		else if (m.getName () == "infos/recommends")
		{
			bb.recommendPlugin (m.getString ());
		}
		else if (isToBeIgnored (m.getName ()))
		{
		}
		else
		{
			bb.needMetadata (m.getName ());
		}
	}
}
예제 #19
0
TEST (meta, basic)
{
	// cout << "testing metainfo" << endl;
	Key test;

	succeed_if (test.hasMeta ("mode") == false, "has meta?");
	succeed_if (test.getMeta<mode_t> ("mode") == 0, "not properly default constructed");

	test.setMeta<mode_t> ("mode", 0775);
	succeed_if (test.hasMeta ("mode") == true, "has not meta even though set?");

	succeed_if (test.getMeta<mode_t> ("mode") == 0775, "not correct default mode for dir");

	test.setMeta<int> ("myint", 333);
	succeed_if (test.getMeta<int> ("myint") == 333, "could not set other meta");

	test.setMeta<double> ("mydouble", 333.3);
	succeed_if (test.hasMeta ("mydouble"), "no metadata even though it was just set");
	succeed_if (test.getMeta<double> ("mydouble") >= 333.2, "could not set other meta");
	succeed_if (test.getMeta<double> ("mydouble") <= 333.4, "could not set other meta");

	test.delMeta ("mydouble");
	succeed_if (!test.hasMeta ("mydouble"), "metadata there even though it was just deleted");

	test.setMeta<std::string> ("mystr", "str");
	succeed_if (test.getMeta<std::string> ("mystr") == "str", "could not set other meta");

	const ckdb::Key * cmeta = test.getMeta<const ckdb::Key *> ("mystr");
	succeed_if (!strcmp (static_cast<const char *> (ckdb::keyValue (cmeta)), "str"), "could not set other meta");

	const ckdb::Key * nmeta = test.getMeta<const ckdb::Key *> ("not available");
	succeed_if (nmeta == nullptr, "not available metadata did not give a null pointer");

	const Key meta = test.getMeta<const Key> ("mystr");
	succeed_if (meta, "null key");
	succeed_if (meta.getString () == "str", "could not get other meta");

	const Key xmeta = test.getMeta<const Key> ("not available");
	succeed_if (!xmeta, "not a null key");

	const char * str = test.getMeta<const char *> ("mystr");
	succeed_if (!strcmp (str, "str"), "could not get meta as c-string");

	const char * nstr = test.getMeta<const char *> ("not available");
	succeed_if (nstr == nullptr, "did not get null pointer on not available metadata");

	succeed_if (test.getMeta<int> ("not available") == 0, "not default constructed");
	succeed_if (test.getMeta<std::string> ("not available") == "", "not default constructed");

	test.setMeta<std::string> ("wrong", "not an int");

	try
	{
		succeed_if (test.hasMeta ("wrong") == true, "meta is here");
		test.getMeta<int> ("wrong");
		succeed_if (0, "exception did not raise");
	}
	catch (KeyTypeConversion const & e)
	{
		succeed_if (1, "no such metadata");
	}
}
예제 #20
0
bool keyMetaEqual (Key & k1, Key & k2)
{
	if (!k1 || !k2) return false;

	k1.rewindMeta ();
	Key currentMeta;
	while ((currentMeta = k1.nextMeta ()))
	{
		string metaName = currentMeta.getName ();
		if (!k2.hasMeta (metaName)) return false;
		if (currentMeta.getString () != k2.getMeta<string> (metaName)) return false;
	}


	k2.rewindMeta ();
	while ((currentMeta = k2.nextMeta ()))
	{
		string metaName = currentMeta.getName ();
		if (!k1.hasMeta (metaName)) return false;
		if (currentMeta.getString () != k1.getMeta<string> (metaName)) return false;
	}


	return true;
}
예제 #21
0
	inline void Formatter(FormatData& formatData, const Key& key)
	{
		formatData.string.append(key.name());
	}
예제 #22
0
w_rc_t key_ranges_map::addPartition(const Key& key, lpid_t& newRoot)
{
    char* keyS = (char*) malloc(key.size());
    key.copy_to(keyS);
    return (_addPartition(keyS, newRoot));
}
예제 #23
0
/**
 * This constructor creates a new driver for the given parent key.
 *
 * @param parent This key specifies the parent of the key set the parser
 *               creates.
 */
Driver::Driver (Key const & parent)
{
	parents.push (parent.dup ());
}
예제 #24
0
KeyQuaero::KeyQuaero(const Key& inKey)
: Key(inKey.tonic(), ModeQuaero(inKey.mode()))
{
}
void InteractiveMergeStrategy::resolveConflict (const MergeTask & task, Key & conflictKey, MergeResult & result)
{
	ConflictOperation ours = getOurConflictOperation (conflictKey);
	ConflictOperation theirs = getTheirConflictOperation (conflictKey);

	outputStream << "merging key " << conflictKey.getName () << endl;
	outputStream << endl;
	outputStream << "======== CONFLICT ========" << endl;
	outputStream << "our operation: " << MergeConflictOperation::getFromTag (ours) << endl;
	outputStream << "their operation: " << MergeConflictOperation::getFromTag (theirs) << endl;
	outputStream << endl;

	Key baseKey = task.base.lookup (rebasePath (conflictKey, task.mergeRoot, task.baseParent));
	Key ourKey = task.ours.lookup (rebasePath (conflictKey, task.mergeRoot, task.ourParent));
	Key theirKey = task.theirs.lookup (rebasePath (conflictKey, task.mergeRoot, task.theirParent));

	outputStream << "======== KEY VALUES ========" << endl;
	outputKeyInfo ("base", baseKey, outputStream);
	outputKeyInfo ("ours", ourKey, outputStream);
	outputKeyInfo ("theirs", theirKey, outputStream);

	outputStream << endl;

	char choice;

	ConflictResolutionSide side;

	bool repeat;
	string input;
	do
	{
		outputStream << "What do you want to do?" << endl;
		outputStream << "Take [o]urs, [t]eirs, [b]ase, [m]erge meta: ";

		repeat = false;
		getline (inputStream, input);

		if (input.size () == 0 || input.size () > 1)
		{
			repeat = true;
			continue;
		}

		choice = input.at (0);

		switch (choice)
		{
		case 'o':
			side = OURS;
			outputStream << "Choose our key" << endl;
			break;
		case 't':
			side = THEIRS;
			outputStream << "Choose their key" << endl;
			break;
		case 'b':
			side = BASE;
			outputStream << "Choose base key" << endl;
			break;
		default:
			repeat = true;
		}
	} while (repeat);

	outputStream << endl;

	OneSideStrategy strategy (side);
	strategy.resolveConflict (task, conflictKey, result);
	outputStream << "Key merged..." << endl;
}
예제 #26
0
inline bool
ShapeHasher::match(const Key k, const Lookup &l)
{
    return k->matches(l);
}
예제 #27
0
void Statistic::notifyGet(const Key& key) {
    string k = key.toString();
    data[k].get++;
}
예제 #28
0
 size_type operator() (const Key& key) const
 {
     return key.hash();
 }
예제 #29
0
 void key_at(size_t id, Key& key) const {
   memcpy(key.data__(), data_ + id * record_len_, key_len_);
   key.clean_msw();
 }
예제 #30
0
/* Throws an exception if "key" is too short to be used. */
void RSA::checkKeyLength(const Key &key)
{
	// Minimum required key length is around 24 bits. (In-house requirement)
	if (key.GetModulus().Length() < 8)
			throw "Error RSA01: Keys must be at least 8 digits long.";
}