1Layer class 2########### 3 4The Layer class is responsible for working with invalid regions and 5serves as the shadow class for BViews. 6 7Member Functions 8================ 9 10Layer(BRect frame, const char \*name, int32 resize, int32 flags, ServerWindow \*win) 11------------------------------------------------------------------------------------ 12 13 141. acquire a new layer token 152. validate (and fix, if necessary) parameters and assign to member objects 163. initalize relation pointers to NULL 174. set level to -1 185. set invalid region to NULL 196. set full and visible regions to bounds 207. set child count to 0 218. get ServerWindow's window port and create a PortLink pointed at it 22 23 24~Layer(void) 25------------ 26 271. if parent is non-NULL, call RemoveSelf() 282. if topchild is non-NULL, iterate through children and delete them. 293. delete invalid, full, and visible regions if non-NULL 304. delete the internal PortLink 31 32 33void AddChild(Layer \*child, Layer \*before=NULL, bool rebuild=true) 34-------------------------------------------------------------------- 35 36Function which corresponds to BView::AddChild 37 38 391) if child->parent is non-NULL, spew an error to stderr and return 402) set child->parent to this 41 42 a) if before == NULL: 43 44 A) if topchild is non-NULL, set child->uppersibling to child 45 B) set child->lowersibling to topchild 46 C) if topchild is NULL, set bottomchild to child 47 D) set topchild to child 48 49 b) if before != NULL: 50 51 A) if before->upper is non-NULL, set child->upper to before->upper 52 B) set before->upper to child 53 C) set child->lower to before 54 D) if child->upper is non-NULL, set child->upper->lower to child 55 E) increment child's level 56 573) increment the child count 584) if rebuild flag is true, call RebuildRegions 59 60 61RemoveChild(Layer \*child, bool rebuild=true) 62--------------------------------------------- 63 64Function which corresponds to BView::RemoveChild 65 66 671. if child's parent != this, spew an error to stderr and return 682. set child's parent to NULL 693. set child's level to -1 704. if top child matches child, set top child to child's lower sibling 715. if bottom child matches child, set bottom child to child's upper sibilng 726. if child->uppersibling is non-NULL, set its lowersibling to the child's lowersibling 737. if child->lowersibling is non-NULL, set its uppersibling to the child's uppersibling 748. decrement child count 759. call RebuildRegions 76 77void RemoveSelf(bool rebuild=true) 78---------------------------------- 79 80Function which corresponds to BView::RemoveSelf 81 82 831. if parent is NULL, spew an error to stderr and return 842. call parent->RemoveChild(this) 85 86void Invalidate(BRect r) 87------------------------ 88 89void Invalidate(BRegion \*region) 90--------------------------------- 91 92 93Marks the area passed to the function as needing to be redrawn 94 951) if parent is NULL, return 962) if the passed area intersects the layer's frame, add it to the 97 invalid region, creating a new invalid object if necessary. 983) Iterate through all child layers, calling child->Invalidate() on the 99 area converted from the parent 100 101BRect Frame(void), BRect Bounds(void) 102------------------------------------- 103 104Frame() returns the layer's frame in its parent coordinates. Bounds() 105returns the frame offset to (0,0). 106 107void MoveBy(BPoint pt), void MoveBy(float x, float y) 108----------------------------------------------------- 109 110Moves the layer in its parent's coordinate space by the specified 111amount 112 1131. offset the frame by the specified amount 1142. if parent is non-NULL, call parent->RebuildRegions() 115 116void ResizeBy(BPoint pt), void ResizeBy(float x, float y) 117--------------------------------------------------------- 118 119Resizes the layer by the specified amount and all children as 120appropriate. 121 1221) resize the frame by the specified amount 1232) iterate through all children, checking the resize flags to see 124 whether each should be resized and calling child->ResizeBy() by the 125 appropriate amount if it is necessary. 126 127int32 CountChildren(void) 128------------------------- 129 130Returns the number of children owned directly by the layer - 131grandchildren not included and some assembly required. Instructions 132are written in Yiddish. 133 134 135bool IsDirty(void) 136------------------ 137 138Returns true if the layer needs redrawn (if invalid region is 139non-NULL). 140 141 142BRect ConvertToTop(const BRect &r), BRegion ConvertToTop(const BRegion &r) 143-------------------------------------------------------------------------- 144 145 146Converts the given data to the coordinates of the root layer in the 147layer tree. 148 149 1501) if parent is non-NULL, return the data. 1512) if parent is NULL, call this: return (parent->ConvertToTop( 152 data_offset_by_frame.left_top ) ) 153 154BRect ConvertFromTop(const BRect &r), BRegion ConvertFromTop(const BRegion &r) 155------------------------------------------------------------------------------ 156 157Converts the given data from the coordinates of the root layer in the 158layer tree. 159 1601. if parent is non-NULL, return the layer's frame 1612. if parent is NULL, call this: return (parent->ConvertFromTop( 162 data_offset_by_frame.left_and_top \* -1 ) ) 163 164BRect ConvertToParent(const BRect &r), BRegion ConvertToParent(const BRegion &r) 165 166Converts the given data to the coordinates of the parent layer 167 1681. return the data offset by the layer's frame's top left point, i.e. 169 frame.LeftTop() 170 171BRect ConvertFromParent(const BRect &r), BRegion ConvertFromParent(const BRegion &r) 172------------------------------------------------------------------------------------ 173 174Converts the given data from the coordinates of the parent layer 175 1761. operates exactly like ConvertToParent, except that the offset 177 values are multiplied by -1 178 179void RebuildRegions(bool recursive=false) 180----------------------------------------- 181 182Rebuilds the visible and invalid layers based on the layer hierarchy. 183Used to update the regions after a call to remove or add a child layer 184is made or when a layer is hidden or shown. 185 186 1871. get the frame 1882. set full and visible regions to frame 1893. iterate through each child and exclude its full region from the 190 visible region if the child is visible. 1914. iterate through each lowersibling and exclude its full region from 192 the visible region if the it is visible and it intersects the layer's 193 frame. 194 195void MakeTopChild(void) 196----------------------- 197 198Makes the layer the top child owned by its parent. Note that the top 199child is "behind" other children on the screen. 200 201 2021. if parent is NULL, spew an error to stderr and return 2032. if parent's top child equals this, return without doing anything 2043. if lowersibling and uppersibling are both NULL, return without doing anything 2054. save pointer to parent layer to a temporary variable 2065. call RemoveSelf and then the former parent's AddChild 207 208void MakeBottomChild(void) 209-------------------------- 210 211Makes the layer the bottom child owned by its parent. Note that the 212top child is "in front of" other children on the screen. 213 2141. if parent is NULL, spew an error to stderr and return 2152. if parent's bottom child equals this, return without doing anything 2163. if lowersibling and uppersibling are both NULL, return without doing anything 2174. save pointer to parent layer to a temporary variable 2185. call RemoveSelf() with rebuild set to false 2196. call former parent's AddChild (rebuild is false), setting the before 220 parameter to the former parent's bottomchild 2217. save lowersibling to a temporary variable 2228. call lowersibling->RemoveSelf() with no rebuild 2239. call the parent's AddChild() with the before set to this and rebuild set to true 224 225void RequestDraw(const BRect &r) 226-------------------------------- 227 228Requests that the layer be drawn on screen. The rectangle passed is in 229the layer's own coordinates. 230 2311. if invalid is NULL, return 2322. set the PortLink opcode to B_DRAW 2333. create a BMessage(B_DRAW) and attach all invalid rectangles to it 2344. attach the view token to the message 2355. flatten the message to a buffer, attach it to the PortLink, and Flush() it. 2366. recurse through each child and call its RequestDraw() function if it 237 intersects the child's frame 238 239Layer \*FindLayer(int32 token) 240------------------------------ 241 242Finds a child layer given an identifying token 243 244 2451. iterate through children and check tokens. Return a match if found. 2462. iterate through children, calling its FindLayer function, return any non-NULL results 2473. return NULL - we got this far, so there is no match 248 249Layer \*GetChildAt(BPoint pt, bool recursive=false) 250--------------------------------------------------- 251 252Gets the child at a given point. if recursive is true, all layers 253under the current one in the tree are searched. if the point is 254contained by the current layer's frame and no child is found, this 255function returns the current layer. if the point is outside the 256current layer's frame, it returns NULL 257 258 2591. if frame does not contain the point, return NULL 260 261if recursive is true: 262 263A. start at the \*bottom\* child and iterate upward. 264B. if the child has children, call the child's GetChildAt with the point 265 converted to the child's coordinate space, returning any non-NULL 266 results 267C. if the child is hidden, continue to the next iteration 268D. if the child's frame contains the point, return the child 269E. if none of the children contain the point, return this 270 271if recursive is false: 272 273A. start at the \*bottom\* child and iterate upward. 274B. if the child is hidden, continue to the next iteration 275C. if the child's frame contains the point, return the child 276D. if none of the children contain the point, return this 277 278PortLink \*GetLink(void) 279------------------------ 280 281Returns the layer's internal PortLink object so a message can be sent 282to the Layer's window. 283 284