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