xref: /haiku/src/servers/app/stackandtile/StackAndTile.h (revision 7a74a5df454197933bc6e80a542102362ee98703)
1 /*
2  * Copyright 2010, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Clemens Zeidler <haiku@clemens-zeidler.de>
7  */
8 #ifndef STACK_AND_TILE_H
9 #define STACK_AND_TILE_H
10 
11 
12 #include <map>
13 
14 #include <Message.h>
15 #include <MessageFilter.h>
16 
17 #include "DesktopListener.h"
18 #include "ObjectList.h"
19 #include "WindowList.h"
20 
21 
22 //#define DEBUG_STACK_AND_TILE
23 
24 #ifdef DEBUG_STACK_AND_TILE
25 #	define STRACE_SAT(x...) debug_printf("SAT: "x)
26 #else
27 #	define STRACE_SAT(x...) ;
28 #endif
29 
30 
31 class SATGroup;
32 class SATWindow;
33 class Window;
34 class WindowArea;
35 
36 
37 typedef std::map<Window*, SATWindow*> SATWindowMap;
38 
39 
40 class StackAndTile : public DesktopListener {
41 public:
42 								StackAndTile();
43 	virtual						~StackAndTile();
44 
45 	virtual int32				Identifier();
46 
47 	// DesktopListener hooks
48 	virtual void				ListenerRegistered(Desktop* desktop);
49 	virtual	void				ListenerUnregistered();
50 
51 	virtual bool				HandleMessage(Window* sender,
52 									BPrivate::LinkReceiver& link,
53 									BPrivate::LinkSender& reply);
54 
55 	virtual void				WindowAdded(Window* window);
56 	virtual void				WindowRemoved(Window* window);
57 
58 	virtual bool				KeyPressed(uint32 what, int32 key,
59 									int32 modifiers);
60 	virtual void				MouseEvent(BMessage* message) {}
61 	virtual void				MouseDown(Window* window, BMessage* message,
62 									const BPoint& where);
63 	virtual void				MouseUp(Window* window, BMessage* message,
64 									const BPoint& where);
65 	virtual void				MouseMoved(Window* window, BMessage* message,
66 									const BPoint& where) {}
67 
68 	virtual void				WindowMoved(Window* window);
69 	virtual void				WindowResized(Window* window);
70 	virtual void				WindowActitvated(Window* window);
71 	virtual void				WindowSentBehind(Window* window,
72 									Window* behindOf);
73 	virtual void				WindowWorkspacesChanged(Window* window,
74 									uint32 workspaces);
75 	virtual void				WindowHidden(Window* window, bool fromMinimize);
76 	virtual void				WindowMinimized(Window* window, bool minimize);
77 
78 	virtual void				WindowTabLocationChanged(Window* window,
79 									float location, bool isShifting);
80 	virtual void				SizeLimitsChanged(Window* window,
81 									int32 minWidth, int32 maxWidth,
82 									int32 minHeight, int32 maxHeight);
83 	virtual void				WindowLookChanged(Window* window,
84 									window_look look);
85 	virtual void				WindowFeelChanged(Window* window,
86 									window_feel feel);
87 
88 	virtual bool				SetDecoratorSettings(Window* window,
89 									const BMessage& settings);
90 	virtual void				GetDecoratorSettings(Window* window,
91 									BMessage& settings);
92 
93 			bool				SATKeyPressed()
94 									{ return fSATKeyPressed; }
95 
96 		SATWindow*				GetSATWindow(Window* window);
97 		SATWindow*				FindSATWindow(uint64 id);
98 
99 private:
100 			void				_StartSAT();
101 			void				_StopSAT();
102 			void				_ActivateWindow(SATWindow* window);
103 			bool				_HandleMessage(BPrivate::LinkReceiver& link,
104 									BPrivate::LinkSender& reply);
105 
106 			Desktop*			fDesktop;
107 
108 			bool				fSATKeyPressed;
109 
110 			SATWindowMap		fSATWindowMap;
111 			BObjectList<SATWindow>	fGrouplessWindows;
112 
113 			SATWindow*			fCurrentSATWindow;
114 };
115 
116 
117 class GroupIterator {
118 public:
119 								GroupIterator(StackAndTile* sat,
120 									Desktop* desktop);
121 
122 			void				RewindToFront();
123 			SATGroup*			NextGroup();
124 
125 private:
126 			StackAndTile*		fStackAndTile;
127 			Desktop*			fDesktop;
128 			Window*				fCurrentWindow;
129 			SATGroup*			fCurrentGroup;
130 };
131 
132 
133 class WindowIterator {
134 public:
135 								WindowIterator(SATGroup* group,
136 									bool reverseLayerOrder = false);
137 
138 			void				Rewind();
139 			/*! Iterates over all areas in the group and return the windows in
140 			the areas. Within one area the windows are ordered by their layer
141 			position. If reverseLayerOrder is false the bottommost window comes
142 			first. */
143 			SATWindow*			NextWindow();
144 
145 
146 private:
147 			SATWindow*			_ReverseNextWindow();
148 			void				_ReverseRewind();
149 
150 			SATGroup*			fGroup;
151 			bool				fReverseLayerOrder;
152 
153 			WindowArea*			fCurrentArea;
154 			int32				fAreaIndex;
155 			int32				fWindowIndex;
156 };
157 
158 
159 class SATSnappingBehaviour {
160 public:
161 	virtual						~SATSnappingBehaviour();
162 
163 	/*! Find all window candidates which possibly can join the group. Found
164 	candidates are marked here visual. */
165 	virtual bool				FindSnappingCandidates(SATGroup* group) = 0;
166 	/*! Join all candidates found in FindSnappingCandidates to the group.
167 	Previously visually mark should be removed here. \return true if
168 	integration has been succeed. */
169 	virtual bool				JoinCandidates() = 0;
170 	/*! Update the window tab values, solve the layout and move all windows in
171 	the group accordantly. */
172 	virtual void				RemovedFromArea(WindowArea* area) {}
173 	virtual void				WindowLookChanged(window_look look) {}
174 };
175 
176 
177 typedef BObjectList<SATSnappingBehaviour> SATSnappingBehaviourList;
178 
179 
180 #endif
181