From 2cca927fe531a757f192003b79a9cecca9ec451e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 15 Jul 2004 22:44:00 +0000 Subject: [PATCH] Fix multibytes character display Fix key repeat git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8404 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/keymap/Keymap.cpp | 31 ++++++++++++++---- src/prefs/keymap/Keymap.h | 3 +- src/prefs/keymap/KeymapWindow.cpp | 52 ++++++++++++++++++++++++++++--- src/prefs/keymap/KeymapWindow.h | 6 ++-- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/prefs/keymap/Keymap.cpp b/src/prefs/keymap/Keymap.cpp index a1d53207c9..e4606131f8 100644 --- a/src/prefs/keymap/Keymap.cpp +++ b/src/prefs/keymap/Keymap.cpp @@ -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; +} diff --git a/src/prefs/keymap/Keymap.h b/src/prefs/keymap/Keymap.h index 1d12109136..4f359e038b 100644 --- a/src/prefs/keymap/Keymap.h +++ b/src/prefs/keymap/Keymap.h @@ -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; diff --git a/src/prefs/keymap/KeymapWindow.cpp b/src/prefs/keymap/KeymapWindow.cpp index f51a8fec69..769c293a16 100644 --- a/src/prefs/keymap/KeymapWindow.cpp +++ b/src/prefs/keymap/KeymapWindow.cpp @@ -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); +}; diff --git a/src/prefs/keymap/KeymapWindow.h b/src/prefs/keymap/KeymapWindow.h index 315cd490cc..ac0d4d4043 100644 --- a/src/prefs/keymap/KeymapWindow.h +++ b/src/prefs/keymap/KeymapWindow.h @@ -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();