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#include <AutoDeleter.h>
25
26
27class Desktop;
28class Window;
29
30
31class DefaultWindowBehaviour : public WindowBehaviour {
32public:
33								DefaultWindowBehaviour(Window* window);
34	virtual						~DefaultWindowBehaviour();
35
36	virtual	bool				MouseDown(BMessage* message, BPoint where,
37									int32 lastHitRegion, int32& clickCount,
38									int32& _hitRegion);
39	virtual	void				MouseUp(BMessage* message, BPoint where);
40	virtual	void				MouseMoved(BMessage *message, BPoint where,
41									bool isFake);
42
43	virtual	void				ModifiersChanged(int32 modifiers);
44
45protected:
46	virtual bool				AlterDeltaForSnap(Window* window, BPoint& delta,
47									bigtime_t now);
48private:
49			enum Action {
50				ACTION_NONE,
51				ACTION_ZOOM,
52				ACTION_CLOSE,
53				ACTION_MINIMIZE,
54				ACTION_TAB,
55				ACTION_DRAG,
56				ACTION_SLIDE_TAB,
57				ACTION_RESIZE,
58				ACTION_RESIZE_BORDER
59			};
60
61			enum {
62				// 1 for the "natural" resize border, -1 for the opposite, so
63				// multiplying the movement delta by that value results in the
64				// size change.
65				LEFT	= -1,
66				TOP		= -1,
67				NONE	= 0,
68				RIGHT	= 1,
69				BOTTOM	= 1
70			};
71
72			struct State;
73			struct MouseTrackingState;
74			struct DragState;
75			struct ResizeState;
76			struct SlideTabState;
77			struct ResizeBorderState;
78			struct DecoratorButtonState;
79			struct ManageWindowState;
80
81			// to keep gcc 2 happy
82			friend struct State;
83			friend struct MouseTrackingState;
84			friend struct DragState;
85			friend struct ResizeState;
86			friend struct SlideTabState;
87			friend struct ResizeBorderState;
88			friend struct DecoratorButtonState;
89			friend struct ManageWindowState;
90
91private:
92			bool				_IsWindowModifier(int32 modifiers) const;
93			Decorator::Region	_RegionFor(const BMessage* message,
94									int32& tab) const;
95
96			void				_SetBorderHighlights(int8 horizontal,
97									int8 vertical, bool active);
98
99			ServerCursor*		_ResizeCursorFor(int8 horizontal,
100									int8 vertical);
101			void				_SetResizeCursor(int8 horizontal,
102									int8 vertical);
103			void				_ResetResizeCursor();
104	static	void				_ComputeResizeDirection(float x, float y,
105									int8& _horizontal, int8& _vertical);
106
107			void				_NextState(State* state);
108
109protected:
110			Window*				fWindow;
111			Desktop*			fDesktop;
112			ObjectDeleter<State>
113								fState;
114			int32				fLastModifiers;
115
116			MagneticBorder		fMagneticBorder;
117};
118
119
120#endif	// DEFAULT_WINDOW_BEHAVIOUR_H
121