commit 64e6956af2345973f4a091869d65ec9f7d91f70b
Author: Joshua R. Elsasser <joshua@elsasser.org>
Date: Sat Sep 26 17:38:23 2009 +0000
Fix key events containing ASCII NUL characters, ie: control-space.
diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp
index abc9f53..cc74149 100644
a
|
b
|
KeyboardDevice::_ControlThread()
|
733 | 733 | msg->AddInt32("modifiers", fModifiers); |
734 | 734 | msg->AddData("states", B_UINT8_TYPE, states, 16); |
735 | 735 | if (numBytes > 0) { |
| 736 | BString bytes; |
| 737 | bytes.SetTo('\0', numBytes); |
736 | 738 | for (int i = 0; i < numBytes; i++) { |
737 | 739 | msg->AddInt8("byte", (int8)string[i]); |
| 740 | bytes[i] = string[i]; |
738 | 741 | } |
739 | | msg->AddString("bytes", string); |
| 742 | msg->AddString("bytes", bytes); |
740 | 743 | |
741 | 744 | if (rawNumBytes <= 0) { |
742 | 745 | rawNumBytes = 1; |
diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp
index 3e1bd40..49025bc 100644
a
|
b
|
BMessage::FindString(const char *name, int32 index, BString *string) const
|
2570 | 2570 | if (string == NULL) |
2571 | 2571 | return B_BAD_VALUE; |
2572 | 2572 | |
| 2573 | ssize_t bytes; |
2573 | 2574 | const char *cstr; |
2574 | | status_t error = FindString(name, index, &cstr); |
| 2575 | status_t error = FindData(name, B_STRING_TYPE, index, |
| 2576 | (const void **)&cstr, &bytes); |
2575 | 2577 | if (error < B_OK) |
2576 | 2578 | return error; |
2577 | 2579 | |
2578 | | *string = cstr; |
| 2580 | string->SetTo('\0', bytes - 1); |
| 2581 | while (--bytes > 0) |
| 2582 | (*string)[bytes - 1] = cstr[bytes - 1]; |
2579 | 2583 | return B_OK; |
2580 | 2584 | } |
2581 | 2585 | |
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index e464fb2..d8cd621 100644
a
|
b
|
FrameMoved(origin);
|
1113 | 1113 | // TODO: cannot use "string" here if we support having |
1114 | 1114 | // different font encoding per view (it's supposed to be |
1115 | 1115 | // converted by _HandleKeyDown() one day) |
1116 | | const char* string; |
| 1116 | BString string; |
1117 | 1117 | if (msg->FindString("bytes", &string) == B_OK) |
1118 | | view->KeyDown(string, strlen(string)); |
| 1118 | view->KeyDown(string.String(), string.Length()); |
1119 | 1119 | } else |
1120 | 1120 | target->MessageReceived(msg); |
1121 | 1121 | } |
… |
… |
FrameMoved(origin);
|
1124 | 1124 | |
1125 | 1125 | case B_KEY_UP: |
1126 | 1126 | { |
1127 | | const char* string = NULL; |
| 1127 | BString string; |
1128 | 1128 | msg->FindString("bytes", &string); |
1129 | 1129 | |
1130 | 1130 | // TODO: same as above |
1131 | 1131 | if (BView* view = dynamic_cast<BView*>(target)) |
1132 | | view->KeyUp(string, strlen(string)); |
| 1132 | view->KeyUp(string.String(), string.Length()); |
1133 | 1133 | else |
1134 | 1134 | target->MessageReceived(msg); |
1135 | 1135 | break; |