* Now handles dead keys via the mouse as well.
* Added _InvalidateKey() variant. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29699 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6b9767aa8a
commit
be09c2a190
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "Keymap.h"
|
#include "Keymap.h"
|
||||||
@ -24,7 +25,8 @@ KeyboardLayoutView::KeyboardLayoutView(const char* name)
|
|||||||
fKeymap(NULL),
|
fKeymap(NULL),
|
||||||
fModifiers(0),
|
fModifiers(0),
|
||||||
fDeadKey(0),
|
fDeadKey(0),
|
||||||
fIsDragging(false)
|
fIsDragging(false),
|
||||||
|
fDropTarget(NULL)
|
||||||
{
|
{
|
||||||
fLayout = new KeyboardLayout;
|
fLayout = new KeyboardLayout;
|
||||||
memset(fKeyState, 0, sizeof(fKeyState));
|
memset(fKeyState, 0, sizeof(fKeyState));
|
||||||
@ -98,15 +100,12 @@ KeyboardLayoutView::FrameResized(float width, float height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
BSize
|
BSize
|
||||||
KeyboardLayoutView::MinSize()
|
KeyboardLayoutView::MinSize()
|
||||||
{
|
{
|
||||||
// TODO!
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(), BSize(100, 50));
|
||||||
BSize size(100, 100);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardLayoutView::KeyDown(const char* bytes, int32 numBytes)
|
KeyboardLayoutView::KeyDown(const char* bytes, int32 numBytes)
|
||||||
@ -131,7 +130,7 @@ KeyboardLayoutView::MouseDown(BPoint point)
|
|||||||
Key* key = _KeyAt(point);
|
Key* key = _KeyAt(point);
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
fKeyState[key->code / 8] |= (1 << (7 - (key->code & 7)));
|
fKeyState[key->code / 8] |= (1 << (7 - (key->code & 7)));
|
||||||
_InvalidateKey(key->code);
|
_InvalidateKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,10 +138,17 @@ KeyboardLayoutView::MouseDown(BPoint point)
|
|||||||
void
|
void
|
||||||
KeyboardLayoutView::MouseUp(BPoint point)
|
KeyboardLayoutView::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
|
fDropTarget = NULL;
|
||||||
|
|
||||||
Key* key = _KeyAt(fClickPoint);
|
Key* key = _KeyAt(fClickPoint);
|
||||||
if (key != NULL) {
|
if (key != NULL) {
|
||||||
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
|
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
|
||||||
_InvalidateKey(key->code);
|
|
||||||
|
if (fKeymap != NULL && _HandleDeadKey(key->code, fModifiers)
|
||||||
|
&& fDeadKey != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_InvalidateKey(key);
|
||||||
|
|
||||||
if (!fIsDragging && fKeymap != NULL) {
|
if (!fIsDragging && fKeymap != NULL) {
|
||||||
// Send fake key down message to target
|
// Send fake key down message to target
|
||||||
@ -183,17 +189,11 @@ KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (dragMessage != NULL) {
|
if (dragMessage != NULL) {
|
||||||
#if 0
|
_InvalidateKey(fDropTarget);
|
||||||
// TODO: check if we support this message!
|
|
||||||
Key* key = _KeyAt(point);
|
|
||||||
if (key == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: have a mouse key state, and a current drag key!
|
fDropTarget = _KeyAt(point);
|
||||||
memset(fKeyState, 0, sizeof(fKeyState));
|
if (fDropTarget != NULL)
|
||||||
fKeyState[key->code / 8] = (1 << (7 - (key->code & 7)));
|
_InvalidateKey(fDropTarget);
|
||||||
_InvalidateKey(key->code);
|
|
||||||
#endif
|
|
||||||
} else if (!fIsDragging && (fabs(point.x - fClickPoint.x) > 4
|
} else if (!fIsDragging && (fabs(point.x - fClickPoint.x) > 4
|
||||||
|| fabs(point.y - fClickPoint.y) > 4)) {
|
|| fabs(point.y - fClickPoint.y) > 4)) {
|
||||||
// start dragging
|
// start dragging
|
||||||
@ -243,7 +243,7 @@ KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
|
|||||||
fIsDragging = true;
|
fIsDragging = true;
|
||||||
|
|
||||||
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
|
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
|
||||||
_InvalidateKey(key->code);
|
_InvalidateKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,6 +264,8 @@ void
|
|||||||
KeyboardLayoutView::MessageReceived(BMessage* message)
|
KeyboardLayoutView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
if (message->WasDropped()) {
|
if (message->WasDropped()) {
|
||||||
|
fDropTarget = NULL;
|
||||||
|
|
||||||
Key* key = _KeyAt(ConvertFromScreen(message->DropPoint()));
|
Key* key = _KeyAt(ConvertFromScreen(message->DropPoint()));
|
||||||
if (key != NULL && fKeymap != NULL) {
|
if (key != NULL && fKeymap != NULL) {
|
||||||
const char* data;
|
const char* data;
|
||||||
@ -276,9 +278,8 @@ KeyboardLayoutView::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
fKeymap->SetKey(key->code, fModifiers, fDeadKey,
|
fKeymap->SetKey(key->code, fModifiers, fDeadKey,
|
||||||
(const char*)data, size);
|
(const char*)data, size);
|
||||||
_InvalidateKey(key->code);
|
_InvalidateKey(key);
|
||||||
} else
|
}
|
||||||
message->PrintToStream();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,6 +525,9 @@ KeyboardLayoutView::_IsKeyPressed(int32 code)
|
|||||||
if (code >= 16 * 8)
|
if (code >= 16 * 8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (fDropTarget != NULL && fDropTarget->code == code)
|
||||||
|
return true;
|
||||||
|
|
||||||
return (fKeyState[code / 8] & (1 << (7 - (code & 7)))) != 0;
|
return (fKeyState[code / 8] & (1 << (7 - (code & 7)))) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,12 +550,41 @@ KeyboardLayoutView::_KeyForCode(int32 code)
|
|||||||
void
|
void
|
||||||
KeyboardLayoutView::_InvalidateKey(int32 code)
|
KeyboardLayoutView::_InvalidateKey(int32 code)
|
||||||
{
|
{
|
||||||
Key* key = _KeyForCode(code);
|
_InvalidateKey(_KeyForCode(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeyboardLayoutView::_InvalidateKey(Key* key)
|
||||||
|
{
|
||||||
if (key != NULL)
|
if (key != NULL)
|
||||||
Invalidate(_FrameFor(key));
|
Invalidate(_FrameFor(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! Updates the fDeadKey member, and invalidates the view if needed.
|
||||||
|
fKeymap must be valid when calling this method.
|
||||||
|
|
||||||
|
\return true if the view has been invalidated.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
KeyboardLayoutView::_HandleDeadKey(int32 key, int32 modifiers)
|
||||||
|
{
|
||||||
|
int32 deadKey = fKeymap->IsDeadKey(key, modifiers);
|
||||||
|
if (fDeadKey != deadKey) {
|
||||||
|
Invalidate();
|
||||||
|
fDeadKey = deadKey;
|
||||||
|
return true;
|
||||||
|
} else if (fDeadKey != 0) {
|
||||||
|
Invalidate();
|
||||||
|
fDeadKey = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardLayoutView::_KeyChanged(BMessage* message)
|
KeyboardLayoutView::_KeyChanged(BMessage* message)
|
||||||
{
|
{
|
||||||
@ -568,16 +601,8 @@ KeyboardLayoutView::_KeyChanged(BMessage* message)
|
|||||||
bool checkSingle = true;
|
bool checkSingle = true;
|
||||||
|
|
||||||
if (message->what == B_KEY_DOWN || message->what == B_UNMAPPED_KEY_DOWN) {
|
if (message->what == B_KEY_DOWN || message->what == B_UNMAPPED_KEY_DOWN) {
|
||||||
int32 deadKey = fKeymap->IsDeadKey(key, fModifiers);
|
if (_HandleDeadKey(key, fModifiers))
|
||||||
if (fDeadKey != deadKey) {
|
|
||||||
Invalidate();
|
|
||||||
fDeadKey = deadKey;
|
|
||||||
checkSingle = false;
|
checkSingle = false;
|
||||||
} else if (fDeadKey != 0) {
|
|
||||||
Invalidate();
|
|
||||||
fDeadKey = 0;
|
|
||||||
checkSingle = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32 i = 0; i < 16; i++) {
|
for (int32 i = 0; i < 16; i++) {
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
// virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
|
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
virtual void KeyUp(const char* bytes, int32 numBytes);
|
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||||
@ -64,6 +64,8 @@ private:
|
|||||||
bool _IsKeyPressed(int32 code);
|
bool _IsKeyPressed(int32 code);
|
||||||
Key* _KeyForCode(int32 code);
|
Key* _KeyForCode(int32 code);
|
||||||
void _InvalidateKey(int32 code);
|
void _InvalidateKey(int32 code);
|
||||||
|
void _InvalidateKey(Key* key);
|
||||||
|
bool _HandleDeadKey(int32 key, int32 modifiers);
|
||||||
void _KeyChanged(BMessage* message);
|
void _KeyChanged(BMessage* message);
|
||||||
Key* _KeyAt(BPoint point);
|
Key* _KeyAt(BPoint point);
|
||||||
BRect _FrameFor(Key* key);
|
BRect _FrameFor(Key* key);
|
||||||
@ -79,6 +81,7 @@ private:
|
|||||||
|
|
||||||
BPoint fClickPoint;
|
BPoint fClickPoint;
|
||||||
bool fIsDragging;
|
bool fIsDragging;
|
||||||
|
Key* fDropTarget;
|
||||||
|
|
||||||
BFont fFont;
|
BFont fFont;
|
||||||
BFont fSpecialFont;
|
BFont fSpecialFont;
|
||||||
|
Loading…
Reference in New Issue
Block a user