示例#1
0
    void FocusHandler::checkHotKey(const KeyInput &keyInput)
    {
        int keyin = keyInput.getKey().getValue();

        for (int i = 0; i < (int)mWidgets.size(); ++i)
        {
            int hotKey = mWidgets[i]->getHotKey();

            if (hotKey == 0)
            {
                continue;
            }

            if ((isascii(keyin) && tolower(keyin) == hotKey) || keyin == hotKey)
            {
                if (keyInput.getType() == KeyInput::PRESS)
                {
                    mWidgets[i]->hotKeyPress();
                    if (mWidgets[i]->isFocusable())
                    {
                        this->requestFocus(mWidgets[i]);
                    }
                }
                else
                {
                    mWidgets[i]->hotKeyRelease();
                }
                break;
            }
        }
    }
示例#2
0
文件: widget.cpp 项目: AMDmi3/Wyrmgus
    bool Widget::_keyInputMessage(const KeyInput& keyInput)
    {
        if (mFocusHandler == NULL)
        {
            //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
            assert(!"No focushandler set (did you add the widget to the gui?).");
        }

        if (!mEnabled || (mFocusHandler->getModalFocused() != NULL &&
                          !hasModalFocus()))
        {
            return false;
        }

        KeyListenerIterator iter;
        bool keyProcessed = false;

        switch(keyInput.getType())
        {
          case KeyInput::PRESS:
              for (iter = mKeyListeners.begin(); iter != mKeyListeners.end(); ++iter)
              {
                  if ((*iter)->keyPress(keyInput.getKey()))
                  {
                      keyProcessed = true;
                  }
              }
              break;

          case KeyInput::RELEASE:
              for (iter = mKeyListeners.begin(); iter != mKeyListeners.end(); ++iter)
              {
                  if ((*iter)->keyRelease(keyInput.getKey()))
                  {
                      keyProcessed = true;
                  }
              }
              break;
        }

        return keyProcessed;
    }
示例#3
0
文件: gui.cpp 项目: doveiya/isilme
    void Gui::handleKeyInput()
    {
        while (!mInput->isKeyQueueEmpty())
        {
            KeyInput keyInput = mInput->dequeueKeyInput();

            // Save modifiers state
            mShiftPressed = keyInput.isShiftPressed();
            mMetaPressed = keyInput.isMetaPressed();
            mControlPressed = keyInput.isControlPressed();
            mAltPressed = keyInput.isAltPressed();

            KeyEvent keyEventToGlobalKeyListeners(WidgetPtr(),
                                                  mShiftPressed,
                                                  mControlPressed,
                                                  mAltPressed,
                                                  mMetaPressed,
                                                  keyInput.getType(),
                                                  keyInput.isNumericPad(),
                                                  keyInput.getKey());

            distributeKeyEventToGlobalKeyListeners(keyEventToGlobalKeyListeners);

            // If a global key listener consumes the event it will not be
            // sent further to the source of the event.
            if (keyEventToGlobalKeyListeners.isConsumed())
            {
                continue;
            }

            bool keyEventConsumed = false;
            
            // Send key inputs to the focused widgets
            if (mFocusHandler->GetFocused() != NULL)
            {
                KeyEvent keyEvent(GetKeyEventSource(),
                                  mShiftPressed,
                                  mControlPressed,
                                  mAltPressed,
                                  mMetaPressed,
                                  keyInput.getType(),
                                  keyInput.isNumericPad(),
                                  keyInput.getKey());
                

                if (!mFocusHandler->GetFocused()->IsFocusable())
                {
                    mFocusHandler->FocusNone();
                }
                else
                {                    
                    distributeKeyEvent(keyEvent);                    
                }

                keyEventConsumed = keyEvent.isConsumed();
            }

            // If the key event hasn't been consumed and
            // tabbing is enable check for tab press and
            // change focus.
            if (!keyEventConsumed
                && mTabbing
                && keyInput.getKey().getValue() == Key::TAB
                && keyInput.getType() == KeyInput::PRESSED)
            {
                if (keyInput.isShiftPressed())
                {
                    mFocusHandler->TabPrevious();
                }
                else
                {
                    mFocusHandler->TabNext();
                }
            }                           
                
        } // end while
    }