haiku/docs/develop/servers/app_server/Layer.htm

390 lines
20 KiB
HTML

<HTML>
<HEAD>
<TITLE>Layer.htm</TITLE>
<style type="text/css">
<!--
.Default {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 12pt}
.OBOS-Function-Def {background-color: rgb(255,255,255); color: rgb(0,0,0); font-family: 'Dutch801 Rm BT'; font-size: 16pt}
.OBOS-Title {background-color: rgb(255,255,255); color: rgb(0,128,0); font-family: 'Dutch801 Rm BT'; font-size: 24pt}
.Text-Background {background-color: rgb(255,255,255)}
.GR-Default {}
.Body {margin: 0px}
.Footer {margin: 0px}
.Header {margin: 0px}
.WP-Default {text-align: left; text-indent: 0px; margin-left: 0px; margin-right: 0px}
-->
</style>
</HEAD>
<BODY BGCOLOR="#ffffff">
<DIV class="sheet" id="Sheet 1">
<P class="Body" style="margin: 0px"><span class="OBOS-Title">Layer class</span><span style="color: rgb(0,0,0); font-size: 24pt"></span></P>
<P class="Body" style="margin: 0px"><BR>
</P>
<P class="Body" style="margin: 0px">The Layer class is responsible for working with invalid regions and serves as the shadow class for BViews.</P>
<P class="Body" style="margin: 0px"><BR>
<HR>
Member Functions</P>
<P class="Body" style="margin: 0px"><BR>
</P>
<TABLE WIDTH=620 HEIGHT=480 BORDER=1 CELLPADDING=1 CELLSPACING=2>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">Layer(BRect frame, const char *name, int32 resize, int32 flags, ServerWindow *win)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">~Layer(void)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">void AddChild(Layer *child, Layer *before=NULL, bool rebuild=true)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">RemoveChild(Layer *child, bool rebuild=true)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void RemoveSelf(bool rebuild=true)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">void Invalidate(BRect r)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void Invalidate(BRegion *region)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">BRect Frame(void)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">BRect Bounds(void)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">void MoveBy(BPoint pt)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void MoveBy(float x, float y)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">void ResizeBy(BPoint pt)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void ResizeBy(float x, float y)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">int32 CountChildren(void)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">bool IsDirty(void)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">BRect ConvertToTop(const BRect &amp;r)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">BRegion ConvertToTop(const BRegion &amp;r)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">BRect ConvertFromTop(const BRect &amp;r)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">BRegion ConvertFromTop(const BRegion &amp;r)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">BRect ConvertToParent(const BRect &amp;r)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">BRegion ConvertToParent(const BRegion &amp;r)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">BRect ConvertFromParent(const BRect &amp;r)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">BRegion ConvertFromParent(const BRegion &amp;r)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">void RebuildRegions(bool recursive=false)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void MakeTopChild(void)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">void MakeBottomChild(void)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=17>
<P class="Body" style="margin: 0px">void RequestDraw(const BRect &amp;r)</P>
</TD>
<TD WIDTH=234 HEIGHT=17>
<P class="Body" style="margin: 0px">Layer *FindLayer(int32 token)</P>
</TD>
</TR>
<TR>
<TD WIDTH=231 HEIGHT=32>
<P class="Body" style="margin: 0px">Layer *GetChildAt(BPoint pt, bool recursive=false)</P>
</TD>
<TD WIDTH=234 HEIGHT=32>
<P class="Body" style="margin: 0px">PortLink *GetLink(void)</P>
</TD>
</TR>
</TABLE>
<P class="Body" style="margin: 0px"><BR>
<BR>
Global Functions</P>
<P class="Body" style="margin: 0px"><BR>
If there are any global functions associated with the class, they are listed here.</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<HR>
</P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">Layer(BRect frame, const char *name, int32 resize, int32 flags, ServerWindow *win)</span></P>
<P class="Body" style="margin: 0px"><BR>
1) acquire a new layer token</P>
<P class="Body" style="margin: 0px">2) validate (and fix, if necessary) parameters and assign to member objects</P>
<P class="Body" style="margin: 0px">3) initalize relation pointers to NULL</P>
<P class="Body" style="margin: 0px">4) set level to -1</P>
<P class="Body" style="margin: 0px">5) set invalid region to NULL</P>
<P class="Body" style="margin: 0px">6) set full and visible regions to bounds</P>
<P class="Body" style="margin: 0px">7) set child count to 0</P>
<P class="Body" style="margin: 0px">8) get ServerWindow's window port and create a PortLink pointed at it</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">~Layer(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is non-NULL, call RemoveSelf()</P>
<P class="Body" style="margin: 0px">2) if topchild is non-NULL, iterate through children and delete them.</P>
<P class="Body" style="margin: 0px">3) delete invalid, full, and visible regions if non-NULL</P>
<P class="Body" style="margin: 0px">4) delete the internal PortLink</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void AddChild(Layer *child, Layer *before=NULL, bool rebuild=true)</span></P>
<P class="Body" style="margin: 0px"><BR>
Function which corresponds to BView::AddChild</P>
<P class="Body" style="margin: 0px"><BR>
1) if child-&gt;parent is non-NULL, spew an error to stderr and return</P>
<P class="Body" style="margin: 0px">2) set child-&gt;parent to this</P>
<P class="Body" style="margin: 0px"><BR>
if before == NULL:</P>
<P class="Body" style="margin: 0px"> A) if topchild is non-NULL, set child-&gt;uppersibling to child</P>
<P class="Body" style="margin: 0px"> B) set child-&gt;lowersibling to topchild</P>
<P class="Body" style="margin: 0px"> C) if topchild is NULL, set bottomchild to child</P>
<P class="Body" style="margin: 0px"> D) set topchild to child</P>
<P class="Body" style="margin: 0px"><BR>
if before != NULL:</P>
<P class="Body" style="margin: 0px"> A) if before-&gt;upper is non-NULL, set child-&gt;upper to before-&gt;upper</P>
<P class="Body" style="margin: 0px"> B) set before-&gt;upper to child</P>
<P class="Body" style="margin: 0px"> C) set child-&gt;lower to before</P>
<P class="Body" style="margin: 0px"> D) if child-&gt;upper is non-NULL, set child-&gt;upper-&gt;lower to child</P>
<P class="Body" style="margin: 0px"> E) increment child's level</P>
<P class="Body" style="margin: 0px">3) increment the child count</P>
<P class="Body" style="margin: 0px">4) if rebuild flag is true, call RebuildRegions</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">RemoveChild(Layer *child, bool rebuild=true)</span></P>
<P class="Body" style="margin: 0px"><BR>
Function which corresponds to BView::RemoveChild</P>
<P class="Body" style="margin: 0px"><BR>
1) if child's parent != this, spew an error to stderr and return</P>
<P class="Body" style="margin: 0px">2) set child's parent to NULL</P>
<P class="Body" style="margin: 0px">3) set child's level to -1</P>
<P class="Body" style="margin: 0px">4) if top child matches child, set top child to child's lower sibling</P>
<P class="Body" style="margin: 0px">5) if bottom child matches child, set bottom child to child's upper sibilng</P>
<P class="Body" style="margin: 0px">6) if child-&gt;uppersibling is non-NULL, set its lowersibling to the child's lowersibling</P>
<P class="Body" style="margin: 0px">7) if child-&gt;lowersibling is non-NULL, set its uppersibling to the child's uppersibling</P>
<P class="Body" style="margin: 0px">8) decrement child count</P>
<P class="Body" style="margin: 0px">9) call RebuildRegions</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void RemoveSelf(bool rebuild=true)</span></P>
<P class="Body" style="margin: 0px"><BR>
Function which corresponds to BView::RemoveSelf</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is NULL, spew an error to stderr and return</P>
<P class="Body" style="margin: 0px">2) call parent-&gt;RemoveChild(this)</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void Invalidate(BRect r)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">void Invalidate(BRegion *region)</span></P>
<P class="Body" style="margin: 0px"><BR>
Marks the area passed to the function as needing to be redrawn</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is NULL, return</P>
<P class="Body" style="margin: 0px">2) if the passed area intersects the layer's frame, add it to the invalid region, creating a new invalid object if necessary.</P>
<P class="Body" style="margin: 0px">3) Iterate through all child layers, calling child-&gt;Invalidate() on the area converted from the parent</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">BRect Frame(void)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BRect Bounds(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Frame() returns the layer's frame in its parent coordinates. Bounds() returns the frame offset to (0,0).</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void MoveBy(BPoint pt)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">void MoveBy(float x, float y)</span></P>
<P class="Body" style="margin: 0px"><BR>
Moves the layer in its parent's coordinate space by the specified amount</P>
<P class="Body" style="margin: 0px"><BR>
1) offset the frame by the specified amount</P>
<P class="Body" style="margin: 0px">2) if parent is non-NULL, call parent-&gt;RebuildRegions()</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void ResizeBy(BPoint pt)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">void ResizeBy(float x, float y)</span></P>
<P class="Body" style="margin: 0px"><BR>
Resizes the layer by the specified amount and all children as appropriate.</P>
<P class="Body" style="margin: 0px"><BR>
1) resize the frame by the specified amount</P>
<P class="Body" style="margin: 0px">2) iterate through all children, checking the resize flags to see whether each should be resized and calling child-&gt;ResizeBy() by the appropriate amount if it is necessary.</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">int32 CountChildren(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Returns the number of children owned directly by the layer - grandchildren not included and some assembly required. Instructions are written in Yiddish.</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">bool IsDirty(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Returns true if the layer needs redrawn (if invalid region is non-NULL).</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">BRect ConvertToTop(const BRect &amp;r)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BRegion ConvertToTop(const BRegion &amp;r)</span></P>
<P class="Body" style="margin: 0px"><BR>
Converts the given data to the coordinates of the root layer in the layer tree.</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is non-NULL, return the data.</P>
<P class="Body" style="margin: 0px">2) if parent is NULL, call this: return (parent-&gt;ConvertToTop( data_offset_by_frame.left_top ) )</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">BRect ConvertFromTop(const BRect &amp;r)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BRegion ConvertFromTop(const BRegion &amp;r)</span></P>
<P class="Body" style="margin: 0px"><BR>
Converts the given data from the coordinates of the root layer in the layer tree.</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is non-NULL, return the layer's frame</P>
<P class="Body" style="margin: 0px">2) if parent is NULL, call this: return (parent-&gt;ConvertFromTop( data_offset_by_frame.left_and_top * -1 ) )</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">BRect ConvertToParent(const BRect &amp;r)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BRegion ConvertToParent(const BRegion &amp;r)</span></P>
<P class="Body" style="margin: 0px"><BR>
Converts the given data to the coordinates of the parent layer</P>
<P class="Body" style="margin: 0px"><BR>
1) return the data offset by the layer's frame's top left point, i.e. frame.LeftTop()</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">BRect ConvertFromParent(const BRect &amp;r)</span></P>
<P class="Body" style="margin: 0px"><span class="OBOS-Function-Def">BRegion ConvertFromParent(const BRegion &amp;r)</span></P>
<P class="Body" style="margin: 0px"><BR>
Converts the given data from the coordinates of the parent layer</P>
<P class="Body" style="margin: 0px"><BR>
1) operates exactly like ConvertToParent, except that the offset values are multiplied by -1</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void RebuildRegions(bool recursive=false)</span></P>
<P class="Body" style="margin: 0px"><BR>
Rebuilds the visible and invalid layers based on the layer hierarchy. Used to update the regions after a call to remove or add a child layer is made or when a layer is hidden or shown.</P>
<P class="Body" style="margin: 0px"><BR>
1) get the frame</P>
<P class="Body" style="margin: 0px">2) set full and visible regions to frame</P>
<P class="Body" style="margin: 0px">3) iterate through each child and exclude its full region from the visible region if the child is visible.</P>
<P class="Body" style="margin: 0px">4) iterate through each lowersibling and exclude its full region from the visible region if the it is visible and it intersects the layer's frame.</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void MakeTopChild(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Makes the layer the top child owned by its parent. Note that the top child is "behind" other children on the screen.</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is NULL, spew an error to stderr and return</P>
<P class="Body" style="margin: 0px">2) if parent's top child equals this, return without doing anything</P>
<P class="Body" style="margin: 0px">3) if lowersibling and uppersibling are both NULL, return without doing anything</P>
<P class="Body" style="margin: 0px">4) save pointer to parent layer to a temporary variable</P>
<P class="Body" style="margin: 0px">5) call RemoveSelf and then the former parent's AddChild</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void MakeBottomChild(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Makes the layer the bottom child owned by its parent. Note that the top child is "in front of" other children on the screen.</P>
<P class="Body" style="margin: 0px"><BR>
1) if parent is NULL, spew an error to stderr and return</P>
<P class="Body" style="margin: 0px">2) if parent's bottom child equals this, return without doing anything</P>
<P class="Body" style="margin: 0px">3) if lowersibling and uppersibling are both NULL, return without doing anything</P>
<P class="Body" style="margin: 0px">4) save pointer to parent layer to a temporary variable</P>
<P class="Body" style="margin: 0px">5) call RemoveSelf() with rebuild set to false</P>
<P class="Body" style="margin: 0px">6) call former parent's AddChild (rebuild is false), setting the before parameter to the former parent's bottomchild</P>
<P class="Body" style="margin: 0px">7) save lowersibling to a temporary variable</P>
<P class="Body" style="margin: 0px">8) call lowersibling-&gt;RemoveSelf() with no rebuild</P>
<P class="Body" style="margin: 0px">9) call the parent's AddChild() with the before set to this and rebuild set to true</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">void RequestDraw(const BRect &amp;r)</span></P>
<P class="Body" style="margin: 0px"><BR>
Requests that the layer be drawn on screen. The rectangle passed is in the layer's own coordinates.</P>
<P class="Body" style="margin: 0px"><BR>
1) if invalid is NULL, return</P>
<P class="Body" style="margin: 0px">2) set the PortLink opcode to B_DRAW</P>
<P class="Body" style="margin: 0px">3) create a BMessage(B_DRAW) and attach all invalid rectangles to it</P>
<P class="Body" style="margin: 0px">4) attach the view token to the message</P>
<P class="Body" style="margin: 0px">4) flatten the message to a buffer, attach it to the PortLink, and Flush() it.</P>
<P class="Body" style="margin: 0px">5) recurse through each child and call its RequestDraw() function if it intersects the child's frame</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">Layer *FindLayer(int32 token)</span></P>
<P class="Body" style="margin: 0px"><BR>
Finds a child layer given an identifying token</P>
<P class="Body" style="margin: 0px"><BR>
1) iterate through children and check tokens. Return a match if found.</P>
<P class="Body" style="margin: 0px">2) iterate through children, calling its FindLayer function, return any non-NULL results</P>
<P class="Body" style="margin: 0px">3) return NULL - we got this far, so there is no match</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">Layer *GetChildAt(BPoint pt, bool recursive=false)</span></P>
<P class="Body" style="margin: 0px"><BR>
Gets the child at a given point. if recursive is true, all layers under the current one in the tree are searched. if the point is contained by the current layer's frame and no child is found, this function returns the current layer. if the point is outside the current layer's frame, it returns NULL</P>
<P class="Body" style="margin: 0px"><BR>
1) if frame does not contain the point, return NULL
</P>
<P class="Body" style="margin: 0px">if recursive is true:</P>
<P class="Body" style="margin: 0px"> A) start at the *bottom* child and iterate upward.</P>
<P class="Body" style="margin: 0px"> B) if the child has children, call the child's GetChildAt with the point converted to the child's coordinate space, returning any non-NULL results</P>
<P class="Body" style="margin: 0px"> C) if the child is hidden, continue to the next iteration</P>
<P class="Body" style="margin: 0px"> D) if the child's frame contains the point, return the child</P>
<P class="Body" style="margin: 0px"> E) if none of the children contain the point, return this</P>
<P class="Body" style="margin: 0px"><BR>
if recursive is false:</P>
<P class="Body" style="margin: 0px"> A) start at the *bottom* child and iterate upward.</P>
<P class="Body" style="margin: 0px"> B) if the child is hidden, continue to the next iteration</P>
<P class="Body" style="margin: 0px"> C) if the child's frame contains the point, return the child</P>
<P class="Body" style="margin: 0px"> D) if none of the children contain the point, return this</P>
<P class="Body" style="margin: 0px"><BR>
<BR>
<span class="OBOS-Function-Def">PortLink *GetLink(void)</span></P>
<P class="Body" style="margin: 0px"><BR>
Returns the layer's internal PortLink object so a message can be sent to the Layer's window.</P>
<DIV class="layer" id="Layer 1">
</DIV>
</DIV>
</BODY>
</HTML>