1/*
2 * Copyright 2004-2005, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		J��r��me Duval
7 */
8
9
10#include "BottomlineWindow.h"
11#include "WindowPrivate.h"
12
13#include <String.h>
14#include <TextView.h>
15
16
17BottomlineWindow::BottomlineWindow()
18	: BWindow(BRect(0, 0, 350, 16), "",
19		kLeftTitledWindowLook,
20		B_FLOATING_ALL_WINDOW_FEEL,
21		B_NOT_V_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
22			| B_AVOID_FOCUS | B_WILL_ACCEPT_FIRST_CLICK)
23{
24	BRect textRect = Bounds();
25	textRect.OffsetTo(B_ORIGIN);
26	textRect.InsetBy(2,2);
27	fTextView = new BTextView(Bounds(), "", textRect, be_plain_font,
28		NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
29	AddChild(fTextView);
30
31	fTextView->SetText("");
32
33	BRect   screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
34	BPoint pt;
35	pt.x = 100;
36	pt.y = screenFrame.Height()*2/3 - Bounds().Height()/2;
37
38	MoveTo(pt);
39	Show();
40
41	SERIAL_PRINT(("BottomlineWindow created\n"));
42}
43
44
45BottomlineWindow::~BottomlineWindow()
46{
47
48
49}
50
51
52void
53BottomlineWindow::MessageReceived(BMessage *msg)
54{
55	switch(msg->what)
56	{
57		default:
58			BWindow::MessageReceived(msg);
59			break;
60	}
61}
62
63
64bool
65BottomlineWindow::QuitRequested()
66{
67	return true;
68}
69
70
71void
72BottomlineWindow::HandleInputMethodEvent(BMessage* event, EventList& newEvents)
73{
74	CALLED();
75
76	PostMessage(event, fTextView);
77
78	const char* string;
79	bool confirmed;
80	int32 opcode;
81	if (event->FindInt32("be:opcode", &opcode) != B_OK
82		|| opcode != B_INPUT_METHOD_CHANGED
83		|| event->FindBool("be:confirmed", &confirmed) != B_OK
84		|| !confirmed
85		|| event->FindString("be:string", &string) != B_OK)
86		return;
87
88	SERIAL_PRINT(("IME : %" B_PRId32 ", %s\n", opcode, string));
89	SERIAL_PRINT(("IME : confirmed\n"));
90
91	int32 length = strlen(string);
92	int32 offset = 0;
93	int32 nextOffset = 0;
94
95	while (offset < length) {
96		// this is supposed to go to the next UTF-8 character
97		for (++nextOffset; (string[nextOffset] & 0xC0) == 0x80; ++nextOffset)
98			;
99
100		BMessage *newEvent = new BMessage(B_KEY_DOWN);
101		if (newEvent != NULL) {
102			newEvent->AddInt32("key", 0);
103			newEvent->AddInt64("when", system_time());
104			BString bytes(string + offset, nextOffset - offset);
105			newEvent->AddString("bytes", bytes);
106			newEvent->AddInt32("raw_char", 0xa);
107			newEvents.AddItem(newEvent);
108		}
109
110		offset = nextOffset;
111	}
112}
113
114