From a77de570a2eb8569a65e3d16e153745ce3d57348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Fri, 28 Jan 2005 18:46:36 +0000 Subject: [PATCH] useful pieces of code git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11107 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/input/BottomlineWindow.cpp | 44 ++++++++++++++++++++++++-- src/servers/input/InputServer.cpp | 37 ++++++++++++++++++++-- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/servers/input/BottomlineWindow.cpp b/src/servers/input/BottomlineWindow.cpp index 37493253e9..b720200251 100644 --- a/src/servers/input/BottomlineWindow.cpp +++ b/src/servers/input/BottomlineWindow.cpp @@ -17,7 +17,7 @@ #include "InputServer.h" BottomlineWindow::BottomlineWindow(const BFont *font) - : BWindow(BRect(0,0,350,20), "", + : BWindow(BRect(0,0,350,16), "", (window_look) 25/*B_FLOATING_WINDOW_LOOK*/, B_FLOATING_ALL_WINDOW_FEEL, B_NOT_V_RESIZABLE | B_NOT_CLOSABLE | @@ -26,11 +26,12 @@ BottomlineWindow::BottomlineWindow(const BFont *font) { BRect textRect = Bounds(); textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(1,1); + textRect.InsetBy(2,2); fTextView = new BTextView(Bounds(), "", textRect, font, NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS); AddChild(fTextView); - fTextView->SetText("coucou"); + fTextView->SetText(""); + fTextView->MakeFocus(true); BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); BPoint pt; @@ -39,6 +40,8 @@ BottomlineWindow::BottomlineWindow(const BFont *font) MoveTo(pt); Show(); + + SERIAL_PRINT(("BottomlineWindow created\n")); } @@ -74,5 +77,40 @@ BottomlineWindow::HandleInputMethodEvent(BMessage *msg, BList *list) CALLED(); PostMessage(msg, fTextView); + + int32 opcode = -1; + const char* string = NULL; + + msg->FindInt32("be:opcode", &opcode); + msg->FindString("be:string", &string); + + SERIAL_PRINT(("IME : %i, %s\n", opcode, string)); + if (opcode != B_INPUT_METHOD_CHANGED) + return; + + bool confirmed = false; + if ((msg->FindBool("be:confirmed", &confirmed) != B_OK) + || !confirmed) + return; + + SERIAL_PRINT(("IME : confirmed\n")); + + if (string != NULL) { + int32 offset = 0; + int32 length = strlen(string); + int32 next_offset = 0; + + while (offset < length) { + for (++next_offset; (string[next_offset] & 0xC0) == 0x80; ++next_offset) + ; + + BMessage *newmsg = new BMessage(B_KEY_DOWN); + newmsg->AddInt32("key", 0); + newmsg->AddInt64("when", system_time()); + newmsg->AddData("bytes", B_STRING_TYPE, string + offset, next_offset - offset); + list->AddItem(newmsg); + offset = next_offset; + } + } } diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 2664e4470c..116ddd5dd0 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -1130,10 +1130,24 @@ InputServer::DispatchEvents(BList *eventList) for ( int32 i = 0; NULL != (event = (BMessage *)fEventsCache.ItemAt(i)); i++ ) { // now we must send each event to the app_server if (event->what == B_INPUT_METHOD_EVENT && !fIMAware) { - if (!fBLWindow) - fBLWindow = new BottomlineWindow(be_bold_font); + SERIAL_PRINT(("IME received\n")); + int32 opcode = -1; + event->FindInt32("be:opcode", &opcode); + BList events; + if (!fBLWindow && opcode == B_INPUT_METHOD_STARTED) { + fBLWindow = new BottomlineWindow(be_plain_font); + } + + if (fBLWindow) { + fBLWindow->HandleInputMethodEvent(event, &events); + + if (!events.IsEmpty()) { + fBLWindow->PostMessage(B_QUIT_REQUESTED); + fBLWindow = NULL; - fBLWindow->HandleInputMethodEvent(event, eventList); + fEventsCache.AddList(&events); + } + } } else { DispatchEvent(event); } @@ -1152,6 +1166,23 @@ int InputServer::DispatchEvent(BMessage *message) { CALLED(); + + switch (message->what) { + case B_KEY_DOWN: + case B_KEY_UP: + case B_UNMAPPED_KEY_UP: + case B_UNMAPPED_KEY_DOWN: { + uint32 modifiers; + ssize_t size; + uint8 *data; + if (message->FindData("states", B_UINT8_TYPE, (const void**)&data, &size) != B_OK) + message->AddData("states", B_UINT8_TYPE, fKey_info.key_states, 16); + if (message->FindInt32("modifiers", (int32*)&modifiers)!=B_OK) + message->AddInt32("modifiers", fKey_info.modifiers); + + break; + } + } // BPortLink is incompatible with R5 one #ifndef COMPILE_FOR_R5