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