xref: /haiku/src/apps/icon-o-matic/generic/gui/stateview/StateView.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
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 STATE_VIEW_H
10 #define STATE_VIEW_H
11 
12 #include <View.h>
13 
14 #include "ViewState.h"
15 
16 class BMessageFilter;
17 class Command;
18 class CommandStack;
19 class RWLocker;
20 
21 class StateView : public BView {
22  public:
23 								StateView(BRect frame, const char* name,
24 										  uint32 resizingMode, uint32 flags);
25 	virtual						~StateView();
26 
27 	// BView interface
28 	virtual	void				AttachedToWindow();
29 	virtual	void				DetachedFromWindow();
30 	virtual	void				Draw(BRect updateRect);
31 	virtual	void				MessageReceived(BMessage* message);
32 
33 	virtual	void				MouseDown(BPoint where);
34 	virtual	void				MouseMoved(BPoint where, uint32 transit,
35 										   const BMessage* dragMessage);
36 	virtual	void				MouseUp(BPoint where);
37 
38 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
39 	virtual	void				KeyUp(const char* bytes, int32 numBytes);
40 
41 	// StateView interface
42 			void				SetState(ViewState* state);
43 			void				UpdateStateCursor();
44 
45 			void				Draw(BView* into, BRect updateRect);
46 
47 	virtual	bool				MouseWheelChanged(BPoint where,
48 												  float x, float y);
49 
50 			bool				HandleKeyDown(uint32 key, uint32 modifiers);
51 			bool				HandleKeyUp(uint32 key, uint32 modifiers);
52 
53 			const mouse_info*	MouseInfo() const
54 									{ return &fMouseInfo; }
55 
56 	virtual	void				FilterMouse(BPoint* where) const;
57 
58 	virtual	ViewState*			StateForDragMessage(const BMessage* message);
59 
60 			void				SetLocker(RWLocker* locker);
61 			RWLocker*			Locker() const
62 									{ return fLocker; }
63 
64 			void				SetCommandStack(::CommandStack* stack);
65 			::CommandStack*		CommandStack() const
66 									{ return fCommandStack; }
67 
68 			void				SetUpdateTarget(BHandler* target,
69 												uint32 command);
70 
71 			void				SetCatchAllEvents(bool catchAll);
72 
73 			status_t			Perform(Command* command);
74 
75  protected:
76 	virtual	bool				_HandleKeyDown(uint32 key, uint32 modifiers);
77 	virtual	bool				_HandleKeyUp(uint32 key, uint32 modifiers);
78 
79 			void				_InstallEventFilter();
80 			void				_RemoveEventFilter();
81 
82 			void				_TriggerUpdate();
83 
84 			ViewState*			fCurrentState;
85 			ViewState*			fDropAnticipatingState;
86 				// the drop anticipation state is some
87 				// kind of "temporary" state that is
88 				// used on top of the current state (it
89 				// doesn't replace it)
90 			mouse_info			fMouseInfo;
91 
92 			::CommandStack*		fCommandStack;
93 			RWLocker*			fLocker;
94 
95 			BMessageFilter*		fEventFilter;
96 			bool				fCatchAllEvents;
97 
98 			BHandler*			fUpdateTarget;
99 			uint32				fUpdateCommand;
100 };
101 
102 #endif // STATE_VIEW_H
103