useful pieces of code
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11107 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
#include "InputServer.h"
|
#include "InputServer.h"
|
||||||
|
|
||||||
BottomlineWindow::BottomlineWindow(const BFont *font)
|
BottomlineWindow::BottomlineWindow(const BFont *font)
|
||||||
: BWindow(BRect(0,0,350,20), "",
|
: BWindow(BRect(0,0,350,16), "",
|
||||||
(window_look) 25/*B_FLOATING_WINDOW_LOOK*/,
|
(window_look) 25/*B_FLOATING_WINDOW_LOOK*/,
|
||||||
B_FLOATING_ALL_WINDOW_FEEL,
|
B_FLOATING_ALL_WINDOW_FEEL,
|
||||||
B_NOT_V_RESIZABLE | B_NOT_CLOSABLE |
|
B_NOT_V_RESIZABLE | B_NOT_CLOSABLE |
|
||||||
@@ -26,11 +26,12 @@ BottomlineWindow::BottomlineWindow(const BFont *font)
|
|||||||
{
|
{
|
||||||
BRect textRect = Bounds();
|
BRect textRect = Bounds();
|
||||||
textRect.OffsetTo(B_ORIGIN);
|
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);
|
fTextView = new BTextView(Bounds(), "", textRect, font, NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
|
||||||
AddChild(fTextView);
|
AddChild(fTextView);
|
||||||
|
|
||||||
fTextView->SetText("coucou");
|
fTextView->SetText("");
|
||||||
|
fTextView->MakeFocus(true);
|
||||||
|
|
||||||
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
|
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
|
||||||
BPoint pt;
|
BPoint pt;
|
||||||
@@ -39,6 +40,8 @@ BottomlineWindow::BottomlineWindow(const BFont *font)
|
|||||||
|
|
||||||
MoveTo(pt);
|
MoveTo(pt);
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
|
SERIAL_PRINT(("BottomlineWindow created\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,5 +77,40 @@ BottomlineWindow::HandleInputMethodEvent(BMessage *msg, BList *list)
|
|||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
PostMessage(msg, fTextView);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1130,10 +1130,24 @@ InputServer::DispatchEvents(BList *eventList)
|
|||||||
for ( int32 i = 0; NULL != (event = (BMessage *)fEventsCache.ItemAt(i)); i++ ) {
|
for ( int32 i = 0; NULL != (event = (BMessage *)fEventsCache.ItemAt(i)); i++ ) {
|
||||||
// now we must send each event to the app_server
|
// now we must send each event to the app_server
|
||||||
if (event->what == B_INPUT_METHOD_EVENT && !fIMAware) {
|
if (event->what == B_INPUT_METHOD_EVENT && !fIMAware) {
|
||||||
if (!fBLWindow)
|
SERIAL_PRINT(("IME received\n"));
|
||||||
fBLWindow = new BottomlineWindow(be_bold_font);
|
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 {
|
} else {
|
||||||
DispatchEvent(event);
|
DispatchEvent(event);
|
||||||
}
|
}
|
||||||
@@ -1152,6 +1166,23 @@ int
|
|||||||
InputServer::DispatchEvent(BMessage *message)
|
InputServer::DispatchEvent(BMessage *message)
|
||||||
{
|
{
|
||||||
CALLED();
|
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
|
// BPortLink is incompatible with R5 one
|
||||||
#ifndef COMPILE_FOR_R5
|
#ifndef COMPILE_FOR_R5
|
||||||
|
|||||||
Reference in New Issue
Block a user