xref: /haiku/src/apps/icon-o-matic/generic/gui/stateview/ViewState.h (revision 9d6d3fcf5fe8308cd020cecf89dede440346f8c4)
1 /*
2  * Copyright 2006, 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 
14 class BMessage;
15 class Command;
16 class StateView;
17 
18 struct mouse_info {
19 	mouse_info();
20 
21 	uint32				buttons;
22 	BPoint				position;
23 	uint32				transit;
24 	uint32				modifiers;
25 };
26 
27 class 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 
61 	inline	uint32				PressedMouseButtons() const
62 									{ return fMouseInfo->buttons; }
63 
64 	inline	bool				IsFirstButtonDown() const
65 									{ return fMouseInfo->buttons & B_PRIMARY_MOUSE_BUTTON; }
66 	inline	bool				IsSecondButtonDown() const
67 									{ return fMouseInfo->buttons & B_SECONDARY_MOUSE_BUTTON; }
68 	inline	bool				IsThirdButtonDown() const
69 									{ return fMouseInfo->buttons & B_TERTIARY_MOUSE_BUTTON; }
70 
71 	inline	BPoint				MousePos() const
72 									{ return fMouseInfo->position; }
73 
74 	inline	uint32				Modifiers() const
75 									{ return fMouseInfo->modifiers; }
76 
77  protected:
78 			StateView*			fView;
79 
80 			// NOTE: the intention of using a pointer
81 			// to a mouse_info struct is that all
82 			// ViewStates belonging to the same StateView
83 			// should have the same pointer, so that
84 			// they will all be up to date with the same info
85 			const mouse_info*	fMouseInfo;
86 };
87 
88 #endif // VIEW_STATE_H
89