2 * Copyright 2001-2011, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
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>
17 #include "RegionPool.h"
18 #include "ServerWindow.h"
20 #include "WindowList.h"
22 #include <ObjectList.h>
23 #include <Referenceable.h>
31 typedef BObjectList
<Window
> StackWindows
;
34 class WindowStack
: public BReferenceable
{
36 WindowStack(::Decorator
* decorator
);
39 void SetDecorator(::Decorator
* decorator
);
40 ::Decorator
* Decorator();
42 const StackWindows
& WindowList() const { return fWindowList
; }
43 const StackWindows
& LayerOrder() const { return fWindowLayerOrder
; }
45 Window
* TopLayerWindow() const;
48 Window
* WindowAt(int32 index
);
49 bool AddWindow(Window
* window
,
51 bool RemoveWindow(Window
* window
);
53 bool MoveToTopLayer(Window
* window
);
54 bool Move(int32 from
, int32 to
);
56 ::Decorator
* fDecorator
;
58 StackWindows fWindowList
;
59 StackWindows fWindowLayerOrder
;
72 class EventDispatcher
;
74 class WindowBehaviour
;
77 // TODO: move this into a proper place
78 #define AS_REDRAW 'rdrw'
81 UPDATE_REQUEST
= 0x01,
88 Window(const BRect
& frame
, const char *name
,
89 window_look look
, window_feel feel
,
90 uint32 flags
, uint32 workspaces
,
91 ::ServerWindow
* window
,
92 DrawingEngine
* drawingEngine
);
95 status_t
InitCheck() const;
97 BRect
Frame() const { return fFrame
; }
98 const char* Title() const { return fTitle
.String(); }
100 window_anchor
& Anchor(int32 index
);
101 Window
* NextWindow(int32 index
) const;
102 Window
* PreviousWindow(int32 index
) const;
104 ::Desktop
* Desktop() const { return fDesktop
; }
105 ::Decorator
* Decorator() const;
106 ::ServerWindow
* ServerWindow() const { return fWindow
; }
107 ::EventTarget
& EventTarget() const
108 { return fWindow
->EventTarget(); }
112 void SetScreen(const ::Screen
* screen
);
113 const ::Screen
* Screen() const;
115 // setting and getting the "hard" clipping, you need to have
116 // WriteLock()ed the clipping!
117 void SetClipping(BRegion
* stillAvailableOnScreen
);
118 // you need to have ReadLock()ed the clipping!
119 inline BRegion
& VisibleRegion() { return fVisibleRegion
; }
120 BRegion
& VisibleContentRegion();
122 // TODO: not protected by a lock, but noone should need this anyways
123 // make private? when used inside Window, it has the ReadLock()
124 void GetFullRegion(BRegion
* region
);
125 void GetBorderRegion(BRegion
* region
);
126 void GetContentRegion(BRegion
* region
);
128 void MoveBy(int32 x
, int32 y
, bool moveStack
= true);
129 void ResizeBy(int32 x
, int32 y
,
130 BRegion
* dirtyRegion
,
131 bool resizeStack
= true);
133 void ScrollViewBy(View
* view
, int32 dx
, int32 dy
);
135 void SetTopView(View
* topView
);
136 View
* TopView() const { return fTopView
; }
137 View
* ViewAt(const BPoint
& where
);
139 virtual bool IsOffscreenWindow() const { return false; }
141 void GetEffectiveDrawingRegion(View
* view
,
143 bool DrawingRegionChanged(View
* view
) const;
145 // generic version, used by the Desktop
146 void ProcessDirtyRegion(BRegion
& regionOnScreen
);
147 void RedrawDirtyRegion();
149 // can be used from inside classes that don't
150 // need to know about Desktop (first version uses Desktop)
151 void MarkDirty(BRegion
& regionOnScreen
);
152 // these versions do not use the Desktop
153 void MarkContentDirty(BRegion
& regionOnScreen
);
154 void MarkContentDirtyAsync(BRegion
& regionOnScreen
);
155 // shortcut for invalidating just one view
156 void InvalidateView(View
* view
, BRegion
& viewRegion
);
158 void DisableUpdateRequests();
159 void EnableUpdateRequests();
161 void BeginUpdate(BPrivate::PortLink
& link
);
163 bool InUpdate() const
164 { return fInUpdate
; }
166 bool NeedsUpdate() const
167 { return fUpdateRequested
; }
169 DrawingEngine
* GetDrawingEngine() const
170 { return fDrawingEngine
; }
172 // managing a region pool
173 ::RegionPool
* RegionPool()
174 { return &fRegionPool
; }
175 inline BRegion
* GetRegion()
176 { return fRegionPool
.GetRegion(); }
177 inline BRegion
* GetRegion(const BRegion
& copy
)
178 { return fRegionPool
.GetRegion(copy
); }
179 inline void RecycleRegion(BRegion
* region
)
180 { fRegionPool
.Recycle(region
); }
182 void CopyContents(BRegion
* region
,
183 int32 xOffset
, int32 yOffset
);
185 void MouseDown(BMessage
* message
, BPoint where
,
186 const ClickTarget
& lastClickTarget
,
188 ClickTarget
& _clickTarget
);
189 void MouseUp(BMessage
* message
, BPoint where
,
191 void MouseMoved(BMessage
* message
, BPoint where
,
192 int32
* _viewToken
, bool isLatestMouseMoved
,
195 void ModifiersChanged(int32 modifiers
);
197 // some hooks to inform the client window
198 // TODO: move this to ServerWindow maybe?
199 void WorkspaceActivated(int32 index
, bool active
);
200 void WorkspacesChanged(uint32 oldWorkspaces
,
201 uint32 newWorkspaces
);
202 void Activated(bool active
);
204 // changing some properties
205 void SetTitle(const char* name
, BRegion
& dirty
);
207 void SetFocus(bool focus
);
208 bool IsFocus() const { return fIsFocus
; }
210 void SetHidden(bool hidden
);
211 inline bool IsHidden() const { return fHidden
; }
213 void SetShowLevel(int32 showLevel
);
214 inline int32
ShowLevel() const { return fShowLevel
; }
216 void SetMinimized(bool minimized
);
217 inline bool IsMinimized() const { return fMinimized
; }
219 void SetCurrentWorkspace(int32 index
)
220 { fCurrentWorkspace
= index
; }
221 int32
CurrentWorkspace() const
222 { return fCurrentWorkspace
; }
223 bool IsVisible() const;
225 bool IsDragging() const;
226 bool IsResizing() const;
228 void SetSizeLimits(int32 minWidth
, int32 maxWidth
,
229 int32 minHeight
, int32 maxHeight
);
231 void GetSizeLimits(int32
* minWidth
, int32
* maxWidth
,
232 int32
* minHeight
, int32
* maxHeight
) const;
234 // 0.0 -> left .... 1.0 -> right
235 bool SetTabLocation(float location
, bool isShifting
,
237 float TabLocation() const;
239 bool SetDecoratorSettings(const BMessage
& settings
,
241 bool GetDecoratorSettings(BMessage
* settings
);
243 void HighlightDecorator(bool active
);
245 void FontsChanged(BRegion
* updateRegion
);
246 void ColorsChanged(BRegion
* updateRegion
);
248 void SetLook(window_look look
,
249 BRegion
* updateRegion
);
250 void SetFeel(window_feel feel
);
251 void SetFlags(uint32 flags
, BRegion
* updateRegion
);
253 window_look
Look() const { return fLook
; }
254 window_feel
Feel() const { return fFeel
; }
255 uint32
Flags() const { return fFlags
; }
257 // window manager stuff
258 uint32
Workspaces() const { return fWorkspaces
; }
259 void SetWorkspaces(uint32 workspaces
)
260 { fWorkspaces
= workspaces
; }
261 bool InWorkspace(int32 index
) const;
263 bool SupportsFront();
265 bool IsModal() const;
266 bool IsFloating() const;
267 bool IsNormal() const;
269 bool HasModal() const;
271 Window
* Frontmost(Window
* first
= NULL
,
272 int32 workspace
= -1);
273 Window
* Backmost(Window
* first
= NULL
,
274 int32 workspace
= -1);
276 bool AddToSubset(Window
* window
);
277 void RemoveFromSubset(Window
* window
);
278 bool HasInSubset(const Window
* window
) const;
279 bool SameSubset(Window
* window
);
280 uint32
SubsetWorkspaces() const;
281 bool InSubsetWorkspace(int32 index
) const;
283 bool HasWorkspacesViews() const
284 { return fWorkspacesViewCount
!= 0; }
285 void AddWorkspacesView()
286 { fWorkspacesViewCount
++; }
287 void RemoveWorkspacesView()
288 { fWorkspacesViewCount
--; }
289 void FindWorkspacesViews(
290 BObjectList
<WorkspacesView
>& list
) const;
292 static bool IsValidLook(window_look look
);
293 static bool IsValidFeel(window_feel feel
);
294 static bool IsModalFeel(window_feel feel
);
295 static bool IsFloatingFeel(window_feel feel
);
297 static uint32
ValidWindowFlags();
298 static uint32
ValidWindowFlags(window_feel feel
);
300 // Window stack methods.
301 WindowStack
* GetWindowStack();
303 bool DetachFromWindowStack(
304 bool ownStackNeeded
= true);
305 bool AddWindowToStack(Window
* window
);
306 Window
* StackedWindowAt(const BPoint
& where
);
307 Window
* TopLayerStackWindow();
309 int32
PositionInStack() const;
310 bool MoveToTopStackLayer();
311 bool MoveToStackPosition(int32 index
,
314 void _ShiftPartOfRegion(BRegion
* region
,
315 BRegion
* regionToShift
, int32 xOffset
,
318 // different types of drawing
319 void _TriggerContentRedraw(BRegion
& dirty
);
322 // handling update sessions
323 void _TransferToUpdateSession(
324 BRegion
* contentDirtyRegion
);
325 void _SendUpdateMessage();
327 void _UpdateContentRegion();
329 void _ObeySizeLimits();
330 void _PropagatePosition();
333 // TODO: no fp rects anywhere
335 const ::Screen
* fScreen
;
337 window_anchor fAnchor
[kListCount
];
339 // the visible region is only recalculated from the
340 // Desktop thread, when using it, Desktop::ReadLockClipping()
343 BRegion fVisibleRegion
;
344 BRegion fVisibleContentRegion
;
345 // our part of the "global" dirty region
346 // it is calculated from the desktop thread,
347 // but we can write to it when we read locked
348 // the clipping, since it is local and the desktop
350 BRegion fDirtyRegion
;
353 // caching local regions
354 BRegion fContentRegion
;
355 BRegion fEffectiveDrawingRegion
;
357 bool fVisibleContentRegionValid
: 1;
358 bool fContentRegionValid
: 1;
359 bool fEffectiveDrawingRegionValid
: 1;
361 ::RegionPool fRegionPool
;
363 BObjectList
<Window
> fSubsets
;
365 WindowBehaviour
* fWindowBehaviour
;
367 ::ServerWindow
* fWindow
;
368 DrawingEngine
* fDrawingEngine
;
371 // The synchronization, which client drawing commands
372 // belong to the redraw of which dirty region is handled
373 // through an UpdateSession. When the client has
374 // been informed that it should redraw stuff, then
375 // this is the current update session. All new
376 // redraw requests from the Desktop will go
377 // into the pending update session.
378 class UpdateSession
{
381 virtual ~UpdateSession();
383 void Include(BRegion
* additionalDirty
);
384 void Exclude(BRegion
* dirtyInNextSession
);
386 inline BRegion
& DirtyRegion()
387 { return fDirtyRegion
; }
389 void MoveBy(int32 x
, int32 y
);
391 void SetUsed(bool used
);
392 inline bool IsUsed() const
395 void AddCause(uint8 cause
);
396 inline bool IsExpose() const
397 { return fCause
& UPDATE_EXPOSE
; }
398 inline bool IsRequest() const
399 { return fCause
& UPDATE_REQUEST
; }
402 BRegion fDirtyRegion
;
407 UpdateSession fUpdateSessions
[2];
408 UpdateSession
* fCurrentUpdateSession
;
409 UpdateSession
* fPendingUpdateSession
;
410 // these two flags are supposed to ensure a sane
411 // and consistent update session
412 bool fUpdateRequested
: 1;
414 bool fUpdatesEnabled
: 1;
423 uint32 fOriginalFlags
;
426 int32 fCurrentWorkspace
;
433 int32 fWorkspacesViewCount
;
435 friend class DecorManager
;
438 WindowStack
* _InitWindowStack();
440 BReference
<WindowStack
> fCurrentStack
;