haiku/src/servers/app/WindowLayer.h

316 lines
9.2 KiB
C
Raw Normal View History

/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Author: DarkWyrm <bpmagic@columbus.rr.com>
* Adi Oanca <adioanca@gmail.com>
* Stephan Aßmus <superstippi@gmx.de>
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef WINDOW_LAYER_H
#define WINDOW_LAYER_H
#include "Decorator.h"
#include "ViewLayer.h"
#include "ServerWindow.h"
#include "WindowList.h"
#include <ObjectList.h>
#include <Region.h>
#include <String.h>
class ClientLooper;
class Decorator;
class Desktop;
class DrawingEngine;
class EventDispatcher;
class WindowLayer;
// TODO: move this into a proper place
#define AS_REDRAW 'rdrw'
class WindowLayer {
public:
WindowLayer(const BRect& frame,
const char *name, window_look look,
window_feel feel, uint32 flags,
uint32 workspaces,
::ServerWindow* window,
DrawingEngine* drawingEngine);
virtual ~WindowLayer();
BRect Frame() const { return fFrame; }
const char* Title() const { return fTitle.String(); }
window_anchor& Anchor(int32 index);
WindowLayer* NextWindow(int32 index);
WindowLayer* PreviousWindow(int32 index);
::Desktop* Desktop() const { return fDesktop; }
::Decorator* Decorator() const { return fDecorator; }
::ServerWindow* ServerWindow() const { return fWindow; }
::EventTarget& EventTarget() const { return fWindow->EventTarget(); }
// for convenience, handles window not attached to Desktop
bool ReadLockWindows();
void ReadUnlockWindows();
// setting and getting the "hard" clipping, you need to have
// WriteLock()ed the clipping!
void SetClipping(BRegion* stillAvailableOnScreen);
// you need to have ReadLock()ed the clipping!
inline BRegion& VisibleRegion() { return fVisibleRegion; }
BRegion& VisibleContentRegion();
// TODO: not protected by a lock, but noone should need this anyways
// make private? when used inside WindowLayer, it has the ReadLock()
void GetFullRegion(BRegion* region);
void GetBorderRegion(BRegion* region);
void GetContentRegion(BRegion* region);
void MoveBy(int32 x, int32 y);
void ResizeBy(int32 x, int32 y, BRegion* dirtyRegion);
void ScrollViewBy(ViewLayer* view, int32 dx, int32 dy);
void SetTopLayer(ViewLayer* topLayer);
ViewLayer* ViewAt(const BPoint& where);
virtual bool IsOffscreenWindow() const { return false; }
offscreen bitmaps work, tested on Haiku as well, supports all colorspaces that BBitmap::ImportBits() supports. It uses a fallback for non-B_RGB(A)32 bitmaps. Added support for B_SUB_PIXEL_PRECISION view flags, though it is a bit hacky, since I had to add it to LayerData, even though it is not a true part of stack data. Added Layer::SetFlags() to enforce code path and update fLayerData. Cleaned up DisplayDriverPainter and DisplayDriver API (changed some const BRect& rect to simply BRect rect in order to be able to reuse it in the code), moved Painter.h, the test environment only draws the changed part of the frame buffer again - this causes a lot less CPU overhead, Painter special cases stroke width of 1.0 to use square caps, which is similar to R5 implementation and removes a lot of problems with non-straight line drawing, ServerWindow uses the DisplayDriver from it's WinBorder instead of the one from the Desktop (needed for offscreen windows, which have their own DisplayDriverPainter), it also checks for GetRootLayer() == NULL, because offscreen layers are not attached to a RootLayer, there was a fix for scrolling which worked at least in the test environment, it is now defunced, because Adi moved _CopyBits to Layer... I need to reenable it later, LayerData has no more fEscapementDelta, also fixed fFontAliasing (which was thought to overriding the font flags, and now works as such again), Desktop initialises the menu_info and scroll_bar_info stuff, which makes ScrollBars work actually... hope I didn't forget something. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13448 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-07-05 20:17:16 +04:00
void GetEffectiveDrawingRegion(ViewLayer* layer, BRegion& region);
bool DrawingRegionChanged(ViewLayer* layer) const;
offscreen bitmaps work, tested on Haiku as well, supports all colorspaces that BBitmap::ImportBits() supports. It uses a fallback for non-B_RGB(A)32 bitmaps. Added support for B_SUB_PIXEL_PRECISION view flags, though it is a bit hacky, since I had to add it to LayerData, even though it is not a true part of stack data. Added Layer::SetFlags() to enforce code path and update fLayerData. Cleaned up DisplayDriverPainter and DisplayDriver API (changed some const BRect& rect to simply BRect rect in order to be able to reuse it in the code), moved Painter.h, the test environment only draws the changed part of the frame buffer again - this causes a lot less CPU overhead, Painter special cases stroke width of 1.0 to use square caps, which is similar to R5 implementation and removes a lot of problems with non-straight line drawing, ServerWindow uses the DisplayDriver from it's WinBorder instead of the one from the Desktop (needed for offscreen windows, which have their own DisplayDriverPainter), it also checks for GetRootLayer() == NULL, because offscreen layers are not attached to a RootLayer, there was a fix for scrolling which worked at least in the test environment, it is now defunced, because Adi moved _CopyBits to Layer... I need to reenable it later, LayerData has no more fEscapementDelta, also fixed fFontAliasing (which was thought to overriding the font flags, and now works as such again), Desktop initialises the menu_info and scroll_bar_info stuff, which makes ScrollBars work actually... hope I didn't forget something. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13448 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-07-05 20:17:16 +04:00
// generic version, used by the Desktop
void ProcessDirtyRegion(BRegion& regionOnScreen);
void RedrawDirtyRegion();
offscreen bitmaps work, tested on Haiku as well, supports all colorspaces that BBitmap::ImportBits() supports. It uses a fallback for non-B_RGB(A)32 bitmaps. Added support for B_SUB_PIXEL_PRECISION view flags, though it is a bit hacky, since I had to add it to LayerData, even though it is not a true part of stack data. Added Layer::SetFlags() to enforce code path and update fLayerData. Cleaned up DisplayDriverPainter and DisplayDriver API (changed some const BRect& rect to simply BRect rect in order to be able to reuse it in the code), moved Painter.h, the test environment only draws the changed part of the frame buffer again - this causes a lot less CPU overhead, Painter special cases stroke width of 1.0 to use square caps, which is similar to R5 implementation and removes a lot of problems with non-straight line drawing, ServerWindow uses the DisplayDriver from it's WinBorder instead of the one from the Desktop (needed for offscreen windows, which have their own DisplayDriverPainter), it also checks for GetRootLayer() == NULL, because offscreen layers are not attached to a RootLayer, there was a fix for scrolling which worked at least in the test environment, it is now defunced, because Adi moved _CopyBits to Layer... I need to reenable it later, LayerData has no more fEscapementDelta, also fixed fFontAliasing (which was thought to overriding the font flags, and now works as such again), Desktop initialises the menu_info and scroll_bar_info stuff, which makes ScrollBars work actually... hope I didn't forget something. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13448 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-07-05 20:17:16 +04:00
// can be used from inside classes that don't
// need to know about Desktop (first version uses Desktop)
void MarkDirty(BRegion& regionOnScreen);
// this version does not use the Desktop
void MarkContentDirty(BRegion& regionOnScreen);
// shortcut for invalidating just one view
void InvalidateView(ViewLayer* view, BRegion& layerRegion);
void EnableUpdateRequests();
void DisableUpdateRequests();
void BeginUpdate();
void EndUpdate();
bool NeedsUpdate() const
{ return fUpdateRequested; }
DrawingEngine* GetDrawingEngine() const
{ return fDrawingEngine; }
void CopyContents(BRegion* region,
int32 xOffset, int32 yOffset);
void MouseDown(BMessage* message, BPoint where, int32* _viewToken);
void MouseUp(BMessage* message, BPoint where, int32* _viewToken);
void MouseMoved(BMessage* message, BPoint where, int32* _viewToken);
// some hooks to inform the client window
// TODO: move this to ServerWindow maybe?
void WorkspaceActivated(int32 index, bool active);
void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);
void Activated(bool active);
// changing some properties
void SetTitle(const char* name, BRegion& dirty);
void SetFocus(bool focus);
Have I said input event handling is done? * didn't realize that mouse events always go to the view under the mouse, not only if its the focus window (FFM can really do harm, after all :-)). * removed a TODO from the list: EventDispatcher::Target is now a public class EventTarget, and every ServerWindow has one. * as a result, EventDispatcher no longer manages targets itself, it just maintains a list of them. You no longer set messengers, you only set targets. * customization of the message filters, they no longer inherit from BMessageFilter (but EventFilter). * a message target is no longer set explicetly anywhere, it's only changed in the message filters if needed. * therefore, no more locking mess in the EventDispatcher needed. * this also made the EventDispatcher::fLastFocus stuff superfluous. * moved the RootLayer::MouseEventHandler() into the message filter. * Replaced RootLayer::_ChildAt() with WindowAt(). * WindowLayer now has an idea if it has focus or not, it no longer needs to query the RootLayer for this - maybe we should rename "focus" to "active", though (as far as layers are concerned). * the "_view_token" data is now added from the EventDispatcher, not the (Window)Layer class anymore. * removed Layer::MouseWheelChanged() as we currently don't need it (if the need arises, we can add it back later again) * there is still no mouse moved message sent when opening a window under the cursor, though... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15228 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-29 19:01:41 +03:00
bool IsFocus() const { return fIsFocus; }
void SetHidden(bool hidden);
inline bool IsHidden() const { return fHidden; }
void SetCurrentWorkspace(int32 index)
{ fCurrentWorkspace = index; }
bool IsVisible() const;
// TODO: make this int32 stuff
void SetSizeLimits(int32 minWidth, int32 maxWidth,
int32 minHeight, int32 maxHeight);
void GetSizeLimits(int32* minWidth, int32* maxWidth,
int32* minHeight, int32* maxHeight) const;
// 0.0 -> left .... 1.0 -> right
void SetTabLocation(float location);
float TabLocation() const;
void HighlightDecorator(bool active);
void SetLook(window_look look, BRegion* updateRegion);
void SetFeel(window_feel feel);
void SetFlags(uint32 flags, BRegion* updateRegion);
window_look Look() const { return fLook; }
window_feel Feel() const { return fFeel; }
uint32 Flags() const { return fFlags; }
// window manager stuff
uint32 Workspaces() const { return fWorkspaces; }
void SetWorkspaces(uint32 workspaces)
{ fWorkspaces = workspaces; }
bool OnWorkspace(int32 index) const;
bool SupportsFront();
bool IsModal() const;
bool IsFloating() const;
bool IsNormal() const;
WindowLayer* Frontmost(WindowLayer* first = NULL, int32 workspace = -1);
WindowLayer* Backmost(WindowLayer* first = NULL, int32 workspace = -1);
bool AddToSubset(WindowLayer* window);
void RemoveFromSubset(WindowLayer* window);
bool HasInSubset(WindowLayer* window);
bool SameSubset(WindowLayer* window);
offscreen bitmaps work, tested on Haiku as well, supports all colorspaces that BBitmap::ImportBits() supports. It uses a fallback for non-B_RGB(A)32 bitmaps. Added support for B_SUB_PIXEL_PRECISION view flags, though it is a bit hacky, since I had to add it to LayerData, even though it is not a true part of stack data. Added Layer::SetFlags() to enforce code path and update fLayerData. Cleaned up DisplayDriverPainter and DisplayDriver API (changed some const BRect& rect to simply BRect rect in order to be able to reuse it in the code), moved Painter.h, the test environment only draws the changed part of the frame buffer again - this causes a lot less CPU overhead, Painter special cases stroke width of 1.0 to use square caps, which is similar to R5 implementation and removes a lot of problems with non-straight line drawing, ServerWindow uses the DisplayDriver from it's WinBorder instead of the one from the Desktop (needed for offscreen windows, which have their own DisplayDriverPainter), it also checks for GetRootLayer() == NULL, because offscreen layers are not attached to a RootLayer, there was a fix for scrolling which worked at least in the test environment, it is now defunced, because Adi moved _CopyBits to Layer... I need to reenable it later, LayerData has no more fEscapementDelta, also fixed fFontAliasing (which was thought to overriding the font flags, and now works as such again), Desktop initialises the menu_info and scroll_bar_info stuff, which makes ScrollBars work actually... hope I didn't forget something. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13448 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-07-05 20:17:16 +04:00
static bool IsValidLook(window_look look);
static bool IsValidFeel(window_feel feel);
static bool IsModalFeel(window_feel feel);
static bool IsFloatingFeel(window_feel feel);
static uint32 ValidWindowFlags();
static uint32 ValidWindowFlags(window_feel feel);
protected:
friend class Desktop;
// TODO: for now (list management)
void _ShiftPartOfRegion(BRegion* region, BRegion* regionToShift,
int32 xOffset, int32 yOffset);
// different types of drawing
void _TriggerContentRedraw();
void _DrawBorder();
// handling update sessions
void _MarkContentDirty(BRegion* contentDirtyRegion);
void _SendUpdateMessage();
void _UpdateContentRegion();
click_type _ActionFor(const BMessage* msg) const;
void _ObeySizeLimits();
BString fTitle;
// TODO: no fp rects anywhere
BRect fFrame;
window_anchor fAnchor[kWorkingList + 1];
// one for each desktop, and one working anchor
// the visible region is only recalculated from the
// Desktop thread, when using it, Desktop::ReadLockClipping()
// has to be called
BRegion fVisibleRegion;
BRegion fVisibleContentRegion;
bool fVisibleContentRegionValid;
// our part of the "global" dirty region
// it is calculated from the desktop thread,
// but we can write to it when we read locked
// the clipping, since it is local and the desktop
// thread is blocked
BRegion fDirtyRegion;
// caching local regions
BRegion fBorderRegion;
bool fBorderRegionValid;
BRegion fContentRegion;
bool fContentRegionValid;
BRegion fEffectiveDrawingRegion;
bool fEffectiveDrawingRegionValid;
Have I said input event handling is done? * didn't realize that mouse events always go to the view under the mouse, not only if its the focus window (FFM can really do harm, after all :-)). * removed a TODO from the list: EventDispatcher::Target is now a public class EventTarget, and every ServerWindow has one. * as a result, EventDispatcher no longer manages targets itself, it just maintains a list of them. You no longer set messengers, you only set targets. * customization of the message filters, they no longer inherit from BMessageFilter (but EventFilter). * a message target is no longer set explicetly anywhere, it's only changed in the message filters if needed. * therefore, no more locking mess in the EventDispatcher needed. * this also made the EventDispatcher::fLastFocus stuff superfluous. * moved the RootLayer::MouseEventHandler() into the message filter. * Replaced RootLayer::_ChildAt() with WindowAt(). * WindowLayer now has an idea if it has focus or not, it no longer needs to query the RootLayer for this - maybe we should rename "focus" to "active", though (as far as layers are concerned). * the "_view_token" data is now added from the EventDispatcher, not the (Window)Layer class anymore. * removed Layer::MouseWheelChanged() as we currently don't need it (if the need arises, we can add it back later again) * there is still no mouse moved message sent when opening a window under the cursor, though... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15228 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-29 19:01:41 +03:00
BObjectList<WindowLayer> fSubsets;
// TODO: remove those some day (let the decorator handle that stuff)
bool fIsClosing;
bool fIsMinimizing;
bool fIsZooming;
bool fIsResizing;
bool fIsSlidingTab;
bool fIsDragging;
// bool fBringToFrontOnRelease;
::Decorator* fDecorator;
ViewLayer* fTopLayer;
::ServerWindow* fWindow;
DrawingEngine* fDrawingEngine;
::Desktop* fDesktop;
BPoint fLastMousePosition;
// BPoint fResizingClickOffset;
// The synchronization, which client drawing commands
// belong to the redraw of which dirty region is handled
// through an UpdateSession. When the client has
// been informed that it should redraw stuff, then
// this is the current update session. All new
// redraw requests from the Desktop will go
// into the pending update session.
class UpdateSession {
public:
UpdateSession();
virtual ~UpdateSession();
void Include(BRegion* additionalDirty);
void Exclude(BRegion* dirtyInNextSession);
inline BRegion& DirtyRegion()
{ return fDirtyRegion; }
void MoveBy(int32 x, int32 y);
void SetUsed(bool used);
inline bool IsUsed() const
{ return fInUse; }
UpdateSession& operator=(const UpdateSession& other);
private:
BRegion fDirtyRegion;
bool fInUse;
};
BRegion fDecoratorRegion;
UpdateSession fCurrentUpdateSession;
UpdateSession fPendingUpdateSession;
// these two flags are supposed to ensure a sane
// and consistent update session
bool fUpdateRequested;
bool fInUpdate;
bool fHidden;
bool fIsFocus;
window_look fLook;
window_feel fFeel;
uint32 fFlags;
uint32 fWorkspaces;
int32 fCurrentWorkspace;
int32 fMinWidth;
int32 fMaxWidth;
int32 fMinHeight;
int32 fMaxHeight;
mutable bool fReadLocked;
};
#endif // WINDOW_LAYER_H