1/*
2 * Copyright 2001-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
4 *
5 * Authors:
6 *		DarkWyrm <bpmagic@columbus.rr.com>
7 *		Adi Oanca <adioanca@gmail.com>
8 *		Stephan Aßmus <superstippi@gmx.de>
9 *		Axel Dörfler <axeld@pinc-software.de>
10 *		Brecht Machiels <brecht@mos6581.org>
11 *		Clemens Zeidler <haiku@clemens-zeidler.de>
12 *		Ingo Weinhold <ingo_weinhold@gmx.de>
13 */
14#ifndef DEFAULT_WINDOW_BEHAVIOUR_H
15#define DEFAULT_WINDOW_BEHAVIOUR_H
16
17
18#include "WindowBehaviour.h"
19
20#include "Decorator.h"
21#include "MagneticBorder.h"
22#include "ServerCursor.h"
23
24
25class Desktop;
26class Window;
27
28
29class DefaultWindowBehaviour : public WindowBehaviour {
30public:
31								DefaultWindowBehaviour(Window* window);
32	virtual						~DefaultWindowBehaviour();
33
34	virtual	bool				MouseDown(BMessage* message, BPoint where,
35									int32 lastHitRegion, int32& clickCount,
36									int32& _hitRegion);
37	virtual	void				MouseUp(BMessage* message, BPoint where);
38	virtual	void				MouseMoved(BMessage *message, BPoint where,
39									bool isFake);
40
41	virtual	void				ModifiersChanged(int32 modifiers);
42
43protected:
44	virtual bool				AlterDeltaForSnap(Window* window, BPoint& delta,
45									bigtime_t now);
46private:
47			enum Action {
48				ACTION_NONE,
49				ACTION_ZOOM,
50				ACTION_CLOSE,
51				ACTION_MINIMIZE,
52				ACTION_TAB,
53				ACTION_DRAG,
54				ACTION_SLIDE_TAB,
55				ACTION_RESIZE,
56				ACTION_RESIZE_BORDER
57			};
58
59			enum {
60				// 1 for the "natural" resize border, -1 for the opposite, so
61				// multiplying the movement delta by that value results in the
62				// size change.
63				LEFT	= -1,
64				TOP		= -1,
65				NONE	= 0,
66				RIGHT	= 1,
67				BOTTOM	= 1
68			};
69
70			struct State;
71			struct MouseTrackingState;
72			struct DragState;
73			struct ResizeState;
74			struct SlideTabState;
75			struct ResizeBorderState;
76			struct DecoratorButtonState;
77			struct ManageWindowState;
78
79			// to keep gcc 2 happy
80			friend struct State;
81			friend struct MouseTrackingState;
82			friend struct DragState;
83			friend struct ResizeState;
84			friend struct SlideTabState;
85			friend struct ResizeBorderState;
86			friend struct DecoratorButtonState;
87			friend struct ManageWindowState;
88
89private:
90			bool				_IsWindowModifier(int32 modifiers) const;
91			Decorator::Region	_RegionFor(const BMessage* message,
92									int32& tab) const;
93
94			void				_SetBorderHighlights(int8 horizontal,
95									int8 vertical, bool active);
96
97			ServerCursor*		_ResizeCursorFor(int8 horizontal,
98									int8 vertical);
99			void				_SetResizeCursor(int8 horizontal,
100									int8 vertical);
101			void				_ResetResizeCursor();
102	static	void				_ComputeResizeDirection(float x, float y,
103									int8& _horizontal, int8& _vertical);
104
105			void				_NextState(State* state);
106
107protected:
108			Window*				fWindow;
109			Desktop*			fDesktop;
110			State*				fState;
111			int32				fLastModifiers;
112
113			MagneticBorder		fMagneticBorder;
114};
115
116
117#endif	// DEFAULT_WINDOW_BEHAVIOUR_H
118