1
2#ifndef DESKTOP_H
3#define DESKTOP_H
4
5#include <List.h>
6#include <Region.h>
7#include <View.h>
8#include <Window.h>
9
10#define SHOW_GLOBAL_DIRTY_REGION 0
11#define SHOW_WINDOW_CONTENT_DIRTY_REGION 0
12
13#define MULTI_LOCKER 1
14
15#if MULTI_LOCKER
16#  include "MultiLocker.h"
17#else
18#  include <Locker.h>
19#endif
20
21class DrawingEngine;
22class DrawView;
23class WindowLayer;
24class ViewLayer;
25
26enum {
27	MSG_ADD_WINDOW		= 'addw',
28	MSG_DRAW			= 'draw',
29
30	MSG_MARK_CLEAN		= 'mcln',
31
32	MSG_QUIT			= 'quit',
33};
34
35class Desktop : public BLooper {
36 public:
37								Desktop(DrawView* drawView,
38										DrawingEngine* engine);
39	virtual						~Desktop();
40
41			// functions for the DrawView
42			void				MouseDown(BPoint where, uint32 buttons,
43										  int32 clicks);
44			void				MouseUp(BPoint where);
45			void				MouseMoved(BPoint where, uint32 code,
46										   const BMessage* dragMessage);
47
48	virtual	void				MessageReceived(BMessage* message);
49
50			void				SetMasterClipping(BRegion* clipping);
51			void				SetOffset(int32 x, int32 y);
52
53			bool				AddWindow(WindowLayer* window);
54			bool				RemoveWindow(WindowLayer* window);
55			int32				IndexOf(WindowLayer* window) const;
56			int32				CountWindows() const;
57			bool				HasWindow(WindowLayer* window) const;
58
59			WindowLayer*		WindowAt(int32 index) const;
60			WindowLayer*		WindowAtFast(int32 index) const;
61			WindowLayer*		WindowAt(const BPoint& where) const;
62			WindowLayer*		TopWindow() const;
63			WindowLayer*		BottomWindow() const;
64
65			// doing something with the windows
66			void				MoveWindowBy(WindowLayer* window, int32 x, int32 y);
67			void				ResizeWindowBy(WindowLayer* window, int32 x, int32 y);
68
69			void				ShowWindow(WindowLayer* window);
70			void				HideWindow(WindowLayer* window);
71			void				SetWindowHidden(WindowLayer* window, bool hidden);
72
73			void				BringToFront(WindowLayer* window);
74			void				SendToBack(WindowLayer* window);
75
76			void				SetFocusWindow(WindowLayer* window);
77
78#if MULTI_LOCKER
79			bool				ReadLockClipping() { return fClippingLock.ReadLock(); }
80			void				ReadUnlockClipping() { fClippingLock.ReadUnlock(); }
81
82			bool				LockClipping() { return fClippingLock.WriteLock(); }
83			void				UnlockClipping() { fClippingLock.WriteUnlock(); }
84#else // BLocker
85			bool				ReadLockClipping() { return fClippingLock.Lock(); }
86			void				ReadUnlockClipping() { fClippingLock.Unlock(); }
87
88			bool				LockClipping() { return fClippingLock.Lock(); }
89			void				UnlockClipping() { fClippingLock.Unlock(); }
90#endif
91
92			void				MarkDirty(BRegion* region);
93
94			DrawingEngine*		GetDrawingEngine() const
95									{ return fDrawingEngine; }
96
97			BRegion&			BackgroundRegion()
98									{ return fBackgroundRegion; }
99
100			void				WindowDied(WindowLayer* window);
101
102private:
103			void				_RebuildClippingForAllWindows(BRegion* stillAvailableOnScreen);
104			void				_TriggerWindowRedrawing(BRegion* newDirtyRegion);
105			void				_SetBackground(BRegion* background);
106
107			bool				fTracking;
108			BPoint				fLastMousePos;
109			WindowLayer*		fClickedWindow;
110			ViewLayer*			fScrollingView;
111			bool				fResizing;
112			bigtime_t			fClickTime;
113			bool				fIs2ndButton;
114
115#if MULTI_LOCKER
116			MultiLocker			fClippingLock;
117#else
118			BLocker				fClippingLock;
119#endif
120			BRegion				fBackgroundRegion;
121
122			BRegion				fMasterClipping;
123			int32				fXOffset;
124			int32				fYOffset;
125
126			DrawView*			fDrawView;
127			DrawingEngine*		fDrawingEngine;
128
129			BList				fWindows;
130
131			bool				fFocusFollowsMouse;
132			WindowLayer*		fFocusWindow;
133};
134
135#endif // DESKTOP_H
136
137