1 /* 2 * Copyright (c) 2001-2015, 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 * Axel Dörfler, axeld@pinc-software.de 9 * Stephan Aßmus <superstippi@gmx.de> 10 * Marcus Overhagen <marcus@overhagen.de> 11 * Adrien Destugues <pulkomandy@pulkomandy.tk> 12 * Julian Harnath <julian.harnath@rwth-aachen.de> 13 * Joseph Groover <looncraz@looncraz.net> 14 */ 15 #ifndef VIEW_H 16 #define VIEW_H 17 18 19 #include "Canvas.h" 20 #include "IntRect.h" 21 22 #include <AutoDeleter.h> 23 #include <GraphicsDefs.h> 24 #include <InterfaceDefs.h> 25 #include <ObjectList.h> 26 #include <Region.h> 27 #include <Referenceable.h> 28 #include <String.h> 29 30 class BList; 31 class BMessage; 32 33 namespace BPrivate { 34 class PortLink; 35 }; 36 37 class DrawingEngine; 38 class Overlay; 39 class Window; 40 class ServerBitmap; 41 class ServerCursor; 42 class ServerPicture; 43 class BGradient; 44 45 class View: public Canvas { 46 public: 47 View(IntRect frame, IntPoint scrollingOffset, 48 const char* name, int32 token, 49 uint32 resizeMode, uint32 flags); 50 virtual ~View(); 51 52 int32 Token() const 53 { return fToken; } 54 55 IntRect Frame() const 56 { return fFrame; } 57 virtual IntRect Bounds() const; 58 59 void SetResizeMode(uint32 resizeMode) 60 { fResizeMode = resizeMode; } 61 62 void SetName(const char* string); 63 const char* Name() const 64 { return fName.String(); } 65 66 void SetFlags(uint32 flags); 67 uint32 Flags() const 68 { return fFlags; } 69 70 inline IntPoint ScrollingOffset() const 71 { return fScrollingOffset; } 72 73 // converts the given frame up the view hierarchy and 74 // clips to each views bounds 75 void ConvertToVisibleInTopView(IntRect* bounds) const; 76 77 virtual void AttachedToWindow(::Window* window); 78 virtual void DetachedFromWindow(); 79 ::Window* Window() const { return fWindow; } 80 81 // Shorthands for opaque Window access 82 DrawingEngine* GetDrawingEngine() const; 83 ServerPicture* GetPicture(int32 token) const; 84 void ResyncDrawState(); 85 void UpdateCurrentDrawingRegion(); 86 87 // tree stuff 88 void AddChild(View* view); 89 bool RemoveChild(View* view); 90 91 inline bool HasParent(View* candidate) const 92 { 93 return fParent == candidate 94 || (fParent != NULL 95 && fParent->HasParent(candidate)); 96 } 97 98 inline View* Parent() const 99 { return fParent; } 100 101 inline View* FirstChild() const 102 { return fFirstChild; } 103 inline View* LastChild() const 104 { return fLastChild; } 105 inline View* PreviousSibling() const 106 { return fPreviousSibling; } 107 inline View* NextSibling() const 108 { return fNextSibling; } 109 110 View* TopView(); 111 112 uint32 CountChildren(bool deep = false) const; 113 void CollectTokensForChildren(BList* tokenMap) const; 114 void FindViews(uint32 flags, BObjectList<View>& list, 115 int32& left); 116 117 bool HasView(View* view); 118 View* ViewAt(const BPoint& where); 119 120 public: 121 void MoveBy(int32 dx, int32 dy, 122 BRegion* dirtyRegion); 123 124 void ResizeBy(int32 dx, int32 dy, 125 BRegion* dirtyRegion); 126 127 void ScrollBy(int32 dx, int32 dy, 128 BRegion* dirtyRegion); 129 130 void ParentResized(int32 dx, int32 dy, 131 BRegion* dirtyRegion); 132 133 void CopyBits(IntRect src, IntRect dst, 134 BRegion& windowContentClipping); 135 136 const BRegion& LocalClipping() const { return fLocalClipping; } 137 138 const rgb_color& ViewColor() const 139 { return fViewColor; } 140 void SetViewColor(const rgb_color& color) 141 { fViewColor = color; } 142 143 void ColorUpdated(color_which which, rgb_color color); 144 void SetViewUIColor(color_which which, float tint); 145 color_which ViewUIColor(float* tint); 146 147 ServerBitmap* ViewBitmap() const 148 { return fViewBitmap; } 149 void SetViewBitmap(ServerBitmap* bitmap, 150 IntRect sourceRect, IntRect destRect, 151 int32 resizingMode, int32 options); 152 153 void PushState(); 154 void PopState(); 155 156 void SetEventMask(uint32 eventMask, uint32 options); 157 uint32 EventMask() const 158 { return fEventMask; } 159 uint32 EventOptions() const 160 { return fEventOptions; } 161 162 void SetCursor(ServerCursor* cursor); 163 ServerCursor* Cursor() const { return fCursor; } 164 165 void SetPicture(ServerPicture* picture); 166 ServerPicture* Picture() const 167 { return fPicture; } 168 169 void BlendAllLayers(); 170 171 // for background clearing 172 virtual void Draw(DrawingEngine* drawingEngine, 173 const BRegion* effectiveClipping, 174 const BRegion* windowContentClipping, 175 bool deep = false); 176 177 virtual void MouseDown(BMessage* message, BPoint where); 178 virtual void MouseUp(BMessage* message, BPoint where); 179 virtual void MouseMoved(BMessage* message, BPoint where); 180 181 void SetHidden(bool hidden); 182 bool IsHidden() const; 183 184 // takes into account parent views hidden status 185 bool IsVisible() const 186 { return fVisible; } 187 // update visible status for this view and all children 188 // according to the parents visibility 189 void UpdateVisibleDeep(bool parentVisible); 190 191 void UpdateOverlay(); 192 193 void MarkBackgroundDirty(); 194 bool IsBackgroundDirty() const 195 { return fBackgroundDirty; } 196 197 bool IsDesktopBackground() const 198 { return fIsDesktopBackground; } 199 200 void AddTokensForViewsInRegion(BPrivate::PortLink& link, 201 BRegion& region, 202 BRegion* windowContentClipping); 203 204 // clipping 205 void RebuildClipping(bool deep); 206 BRegion& ScreenAndUserClipping( 207 const BRegion* windowContentClipping, 208 bool force = false) const; 209 void InvalidateScreenClipping(); 210 inline bool IsScreenClippingValid() const 211 { 212 return fScreenClippingValid 213 && (!fUserClipping.IsSet() 214 || (fUserClipping.IsSet() 215 && fScreenAndUserClipping.IsSet())); 216 } 217 218 // debugging 219 void PrintToStream() const; 220 #if 0 221 bool MarkAt(DrawingEngine* engine, const BPoint& where, 222 int32 level = 0); 223 #endif 224 225 protected: 226 virtual void _LocalToScreenTransform( 227 SimpleTransform& transform) const; 228 virtual void _ScreenToLocalTransform( 229 SimpleTransform& transform) const; 230 231 BRegion& _ScreenClipping(const BRegion* windowContentClipping, 232 bool force = false) const; 233 void _MoveScreenClipping(int32 x, int32 y, 234 bool deep); 235 Overlay* _Overlay() const; 236 void _UpdateOverlayView() const; 237 238 BString fName; 239 int32 fToken; 240 // area within parent coordinate space 241 IntRect fFrame; 242 // offset of the local area (bounds) 243 IntPoint fScrollingOffset; 244 245 rgb_color fViewColor; 246 color_which fWhichViewColor; 247 float fWhichViewColorTint; 248 BReference<ServerBitmap> 249 fViewBitmap; 250 IntRect fBitmapSource; 251 IntRect fBitmapDestination; 252 int32 fBitmapResizingMode; 253 int32 fBitmapOptions; 254 255 uint32 fResizeMode; 256 uint32 fFlags; 257 bool fHidden : 1; 258 bool fVisible : 1; 259 bool fBackgroundDirty : 1; 260 bool fIsDesktopBackground : 1; 261 262 uint32 fEventMask; 263 uint32 fEventOptions; 264 265 ::Window* fWindow; 266 View* fParent; 267 268 View* fFirstChild; 269 View* fPreviousSibling; 270 View* fNextSibling; 271 View* fLastChild; 272 273 BReference<ServerCursor> 274 fCursor; 275 BReference<ServerPicture> 276 fPicture; 277 278 // clipping 279 BRegion fLocalClipping; 280 281 mutable BRegion fScreenClipping; 282 mutable bool fScreenClippingValid; 283 284 ObjectDeleter<BRegion> 285 fUserClipping; 286 mutable ObjectDeleter<BRegion> 287 fScreenAndUserClipping; 288 }; 289 290 #endif // VIEW_H 291