| 77 | } |
| 78 | |
| 79 | bool ButtonBase::onProcessMessage(Message* msg) |
| 80 | { |
| 81 | switch (msg->type()) { |
| 82 | |
| 83 | case kFocusEnterMessage: |
| 84 | case kFocusLeaveMessage: |
| 85 | if (isEnabled()) { |
| 86 | if (m_behaviorType == kButtonWidget) { |
| 87 | // Deselect the widget (maybe the user press the key, but |
| 88 | // before release it, changes the focus). |
| 89 | if (isSelected()) |
| 90 | setSelected(false); |
| 91 | } |
| 92 | |
| 93 | // TODO theme specific stuff |
| 94 | invalidate(); |
| 95 | } |
| 96 | break; |
| 97 | |
| 98 | case kKeyDownMessage: { |
| 99 | KeyMessage* keymsg = static_cast<KeyMessage*>(msg); |
| 100 | KeyScancode scancode = keymsg->scancode(); |
| 101 | |
| 102 | // If the button is enabled. |
| 103 | if (isEnabled()) { |
| 104 | bool mnemonicPressed = |
| 105 | (msg->altPressed() && |
| 106 | mnemonicChar() && |
| 107 | mnemonicChar() == she::scancode_to_ascii(scancode)); |
| 108 | |
| 109 | // For kButtonWidget |
| 110 | if (m_behaviorType == kButtonWidget) { |
| 111 | // Has focus and press enter/space |
| 112 | if (hasFocus()) { |
| 113 | if ((scancode == kKeyEnter) || |
| 114 | (scancode == kKeyEnterPad) || |
| 115 | (scancode == kKeySpace)) { |
| 116 | setSelected(true); |
| 117 | return true; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // Check if the user pressed mnemonic. |
| 122 | if (mnemonicPressed) { |
| 123 | setSelected(true); |
| 124 | return true; |
| 125 | } |
| 126 | // Magnetic widget catches ENTERs |
| 127 | else if (isFocusMagnet() && |
| 128 | ((scancode == kKeyEnter) || |
| 129 | (scancode == kKeyEnterPad))) { |
| 130 | manager()->setFocus(this); |
| 131 | |
| 132 | // Dispatch focus movement messages (because the buttons |
| 133 | // process them) |
| 134 | manager()->dispatchMessages(); |
| 135 | |
| 136 | setSelected(true); |
nothing calls this directly
no test coverage detected