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