1/*
2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan Aßmus <superstippi@gmx.de>
7 */
8
9#ifndef VIEW_STATE_H
10#define VIEW_STATE_H
11
12#include <View.h>
13
14class BMessage;
15class Command;
16class StateView;
17
18struct mouse_info {
19	mouse_info();
20
21	uint32				buttons;
22	BPoint				position;
23	uint32				transit;
24	uint32				modifiers;
25};
26
27class ViewState {
28 public:
29								ViewState(StateView* view);
30								ViewState(const ViewState& other);
31	virtual						~ViewState();
32
33	// ViewState interface
34	virtual	void				Init();
35	virtual	void				Cleanup();
36
37	virtual	void				Draw(BView* into, BRect updateRect);
38	virtual	bool				MessageReceived(BMessage* message,
39												Command** _command);
40
41	// mouse tracking
42	virtual	void				MouseDown(BPoint where,
43										  uint32 buttons,
44										  uint32 clicks);
45
46	virtual	void				MouseMoved(BPoint where,
47										   uint32 transit,
48										   const BMessage* dragMessage);
49	virtual	Command*			MouseUp();
50
51	// modifiers
52	virtual	void				ModifiersChanged(uint32 modifiers);
53
54	// TODO: mouse wheel
55	virtual	bool				HandleKeyDown(uint32 key, uint32 modifiers,
56											  Command** _command);
57	virtual	bool				HandleKeyUp(uint32 key, uint32 modifiers,
58											Command** _command);
59
60	virtual	bool				UpdateCursor();
61
62
63	inline	uint32				PressedMouseButtons() const
64									{ return fMouseInfo->buttons; }
65
66	inline	bool				IsFirstButtonDown() const
67									{ return fMouseInfo->buttons & B_PRIMARY_MOUSE_BUTTON; }
68	inline	bool				IsSecondButtonDown() const
69									{ return fMouseInfo->buttons & B_SECONDARY_MOUSE_BUTTON; }
70	inline	bool				IsThirdButtonDown() const
71									{ return fMouseInfo->buttons & B_TERTIARY_MOUSE_BUTTON; }
72
73	inline	BPoint				MousePos() const
74									{ return fMouseInfo->position; }
75
76	inline	uint32				Modifiers() const
77									{ return fMouseInfo->modifiers; }
78
79 protected:
80			StateView*			fView;
81
82			// NOTE: the intention of using a pointer
83			// to a mouse_info struct is that all
84			// ViewStates belonging to the same StateView
85			// should have the same pointer, so that
86			// they will all be up to date with the same info
87			const mouse_info*	fMouseInfo;
88};
89
90#endif // VIEW_STATE_H
91