Fix multibytes character display

Fix key repeat


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8404 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-07-15 22:44:00 +00:00
parent 91c56b1c29
commit 2cca927fe5
4 changed files with 79 additions and 13 deletions

View File

@ -52,7 +52,7 @@ print_key( char *chars, int32 offset )
void
Keymap::GetChars(int32 keyCode, uint32 modifiers, char **chars)
Keymap::GetChars(uint32 keyCode, uint32 modifiers, char **chars, int32 *numBytes)
{
int32 offset = 0;
switch (modifiers & 0xff) {
@ -67,9 +67,9 @@ Keymap::GetChars(int32 keyCode, uint32 modifiers, char **chars)
case B_CONTROL_KEY: offset = fKeys.control_map[keyCode]; break;
}
int size = fChars[offset++];
*numBytes = fChars[offset++];
switch( size ) {
switch( *numBytes ) {
case 0:
// Not mapped
*chars = NULL;
@ -77,9 +77,9 @@ Keymap::GetChars(int32 keyCode, uint32 modifiers, char **chars)
default:
// 1-, 2-, 3-, or 4-byte UTF-8 character
{
char *str = *chars = new char[size + 1];
strncpy(str, &(fChars[offset]), size );
str[size] = 0;
char *str = *chars = new char[*numBytes + 1];
strncpy(str, &(fChars[offset]), *numBytes );
str[*numBytes] = 0;
}
break;
}
@ -140,3 +140,22 @@ Keymap::Load(entry_ref &ref)
return B_OK;
}
bool
Keymap::IsModifierKey(uint32 keyCode)
{
if ((keyCode == fKeys.caps_key)
|| (keyCode == fKeys.num_key)
|| (keyCode == fKeys.left_shift_key)
|| (keyCode == fKeys.right_shift_key)
|| (keyCode == fKeys.left_command_key)
|| (keyCode == fKeys.right_command_key)
|| (keyCode == fKeys.left_control_key)
|| (keyCode == fKeys.right_control_key)
|| (keyCode == fKeys.left_option_key)
|| (keyCode == fKeys.right_option_key)
|| (keyCode == fKeys.menu_key))
return true;
return false;
}

View File

@ -24,7 +24,8 @@ class Keymap
public:
status_t Load(entry_ref &ref);
void DumpKeymap();
void GetChars(int32 keyCode, uint32 modifiers, char **chars);
void GetChars(uint32 keyCode, uint32 modifiers, char **chars, int32 *numBytes);
bool IsModifierKey(uint32 keyCode);
private:
char *fChars;
key_map fKeys;

View File

@ -725,6 +725,7 @@ MapView::AttachedToWindow()
{
SetEventMask(B_KEYBOARD_EVENTS, B_NO_POINTER_HISTORY);
fTextView->SetViewColor(255,255,255);
fTextView->SetStylable(true);
BView::AttachedToWindow();
}
@ -1157,7 +1158,8 @@ MapView::DrawKey(int32 keyCode)
}
char *str;
fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, &str);
int32 numBytes;
fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, &str, &numBytes);
if (str) {
bool hasGlyphs;
fCurrentFont.GetHasGlyphs(str, 1, &hasGlyphs);
@ -1223,13 +1225,29 @@ MapView::MessageReceived(BMessage *msg)
DrawKey(keyCode);
}
}
if (keyCode<0)
for (int8 i=0; i<16; i++) {
uint8 stbits = states[i];
for (int8 j=7; stbits; j--,stbits>>=1)
if (stbits & 1) {
keyCode = i*8 + j;
if (!fCurrentMap->IsModifierKey(keyCode)) {
i = 16;
break;
}
}
}
if (Window()->IsActive() && keyCode >= 0
if (Window()->IsActive()
&& msg->what == B_KEY_DOWN) {
fTextView->MakeFocus();
char *str;
fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, &str);
fTextView->FakeKeyDown(str, 1);
int32 numBytes;
fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, &str, &numBytes);
if (numBytes>0)
fTextView->FakeKeyDown(str, numBytes);
}
}
}
@ -1255,3 +1273,29 @@ MapView::KeyUp(const char* bytes, int32 numBytes)
{
MessageReceived(Window()->CurrentMessage());
}
void
MapView::MouseDown(BPoint point)
{
}
void
MapView::MouseUp(BPoint point)
{
}
void
MapView::MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
{
}
void
MapView::SetFontFamily(const font_family family)
{
fCurrentFont.SetFamilyAndStyle(family, NULL);
fTextView->SetFont(&fCurrentFont);
};

View File

@ -39,7 +39,10 @@ public:
void KeyDown(const char* bytes, int32 numBytes);
void KeyUp(const char* bytes, int32 numBytes);
void MessageReceived(BMessage *msg);
void SetFontFamily(const font_family family) {fCurrentFont.SetFamilyAndStyle(family, NULL); };
void SetFontFamily(const font_family family);
void MouseDown(BPoint point);
void MouseUp(BPoint point);
void MouseMoved(BPoint point, uint32 transit, const BMessage *msg);
private:
key_info fOldKeyInfo;
BRect fKeysRect[128];
@ -70,7 +73,6 @@ protected:
BMenuBar *AddMenuBar();
void AddMaps(BView *placeholderView);
//KeymapListItem* ItemFromEntry( BEntry *entry );
void UseKeymap();
void FillSystemMaps();