예제 #1
0
void
KeyboardLayoutView::MouseDown(BPoint point)
{
	fClickPoint = point;
	fDragKey = NULL;
	fDropPoint.x = -1;

	Key* key = _KeyAt(point);
	if (key == NULL)
		return;

	int32 buttons = 0;
	if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
		Looper()->CurrentMessage()->FindInt32("buttons", &buttons);

	if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0
		&& (fButtons & B_TERTIARY_MOUSE_BUTTON) == 0) {
		// toggle the "deadness" of dead keys via middle mouse button
		if (fKeymap != NULL) {
			bool isEnabled = false;
			uint8 deadKey
				= fKeymap->DeadKey(key->code, fModifiers, &isEnabled);
			if (deadKey > 0) {
				fKeymap->SetDeadKeyEnabled(key->code, fModifiers, !isEnabled);
				_InvalidateKey(key);
			}
		}
	} else {
		if (fKeymap != NULL && fKeymap->IsModifierKey(key->code)) {
			if (_KeyState(key->code)) {
				uint32 modifier = fKeymap->Modifier(key->code);
				if ((modifier & modifiers()) == 0) {
					_SetKeyState(key->code, false);
					fModifiers &= ~modifier;
					Invalidate();
				}
			} else {
				_SetKeyState(key->code, true);
				fModifiers |= fKeymap->Modifier(key->code);
				Invalidate();
			}

			// TODO: if possible, we could handle the lock keys for real
		} else {
			_SetKeyState(key->code, true);
			_InvalidateKey(key);
		}
	}

	fButtons = buttons;
}
예제 #2
0
void
KeyboardLayoutView::MouseUp(BPoint point)
{
    Key* key = _KeyAt(fClickPoint);

    int32 buttons = 0;
    if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
        Looper()->CurrentMessage()->FindInt32("buttons", &buttons);

    if (key != NULL) {
        if ((fButtons & B_TERTIARY_MOUSE_BUTTON) != 0
                && (buttons & B_TERTIARY_MOUSE_BUTTON) == 0) {
            _SetKeyState(key->code, false);
            _InvalidateKey(key);
            fButtons = buttons;
        } else {
            fButtons = buttons;

            // modifier keys are sticky when used with the mouse
            if (fKeymap != NULL && fKeymap->IsModifierKey(key->code))
                return;

            _SetKeyState(key->code, false);

            if (_HandleDeadKey(key->code, fModifiers) && fDeadKey != 0)
                return;

            _InvalidateKey(key);

            if (fDragKey == NULL && fKeymap != NULL) {
                // Send fake key down message to target
                _SendFakeKeyDown(key);
            }
        }
    }
    fDragKey = NULL;
}