1/*
2 * Copyright 2009, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Michael Lotz <mmlr@mlotz.ch>
7 */
8#ifndef REMOTE_VIEW_H
9#define REMOTE_VIEW_H
10
11#include <Cursor.h>
12#include <NetEndpoint.h>
13#include <ObjectList.h>
14#include <View.h>
15
16class BBitmap;
17class NetReceiver;
18class NetSender;
19class StreamingRingBuffer;
20
21struct engine_state;
22
23class RemoteView : public BView {
24public:
25									RemoteView(BRect frame,
26										const char *remoteHost,
27										uint16 remotePort);
28virtual								~RemoteView();
29
30		status_t					InitCheck();
31
32virtual	void						AttachedToWindow();
33
34virtual	void						Draw(BRect updateRect);
35
36virtual	void						MouseMoved(BPoint where, uint32 code,
37										const BMessage *dragMessage);
38virtual	void						MouseDown(BPoint where);
39virtual	void						MouseUp(BPoint where);
40
41virtual	void						KeyDown(const char *bytes, int32 numBytes);
42virtual	void						KeyUp(const char *bytes, int32 numBytes);
43
44virtual	void						MessageReceived(BMessage *message);
45
46private:
47		void						_SendMouseMessage(uint16 code,
48										BPoint where);
49		void						_SendKeyMessage(uint16 code,
50										const char *bytes, int32 numBytes);
51
52static	int							_StateCompareByKey(const uint32 *key,
53										const engine_state *state);
54		engine_state *				_CreateState(uint32 token);
55		void						_DeleteState(uint32 token);
56		engine_state *				_FindState(uint32 token);
57
58static	int32						_DrawEntry(void *data);
59		void						_DrawThread();
60
61		BRect						_BuildInvalidateRect(BPoint *points,
62										int32 pointCount);
63
64		status_t					fInitStatus;
65		bool						fIsConnected;
66
67		StreamingRingBuffer *		fReceiveBuffer;
68		StreamingRingBuffer *		fSendBuffer;
69		BNetEndpoint *				fEndpoint;
70		NetReceiver *				fReceiver;
71		NetSender *					fSender;
72
73		bool						fStopThread;
74		thread_id					fDrawThread;
75
76		BBitmap *					fOffscreenBitmap;
77		BView *						fOffscreen;
78
79		BCursor						fViewCursor;
80		BBitmap *					fCursorBitmap;
81		BRect						fCursorFrame;
82		bool						fCursorVisible;
83
84		BObjectList<engine_state>	fStates;
85};
86
87#endif // REMOTE_VIEW_H
88