MAG Disk (Jun 1990) : source / CheckItemSize.

	       INCLUDE	  "exec/types.i"
	       INCLUDE	  "graphics/rastport.i"
	       INCLUDE	  "graphics/text.i"
	       INCLUDE	  "intuition/intuition.i"
	       INCLUDE	  "PopUpMenu.i"

	       xdef	  @CheckItemSize

	       xref	  @Mystrlen

_LVOIntuiTextLength EQU   -$14a
_LVOTextLength	    EQU   -$36

	       section	  text,code
*********************************************************
* CheckItemSize(SizeSoFar,Item,Contents) -              *
*  find the size needed to include Item in window.	*
*							*
* Input:						*
*   SizeSoFar (A0)  Current size of window.             *
*   Item      (A1)  Item to check.                      *
*   Contents  (D0)  What to fill (ItemFill/SelectFill). *
* Output:						*
*   SizeSoFar	    New size of window			*
*********************************************************
@CheckItemSize:
	       MOVEM.L	  D2-D7/A2-A3/A5-A6,-(SP)

	       MOVEA.L	  A0,A3 	      * A3 = SizeSoFar
	       MOVEA.L	  A1,A2 	      * A2 = Item to check
	       MOVEA.L	  D0,A5 	      * D0 = What to check

* ------------ Anything to check ?
Check:	       MOVE.L	  A5,D0
	       BEQ.W	  Done

	       MOVE.W	  mi_LeftEdge(A2),D3  * D3 = LeftEdge
	       MOVE.W	  mi_TopEdge(A2),D2   * D2 = TopEdge
	       MOVE.W	  D3,D7 	      * D7 = Left
	       MOVE.W	  D2,D6 	      * D6 = Top
	       MOVE.W	  D3,D5
	       MOVE.W	  D2,D4

* ------------ ITEMTEXT or ITEMIMAGE ?
	       MOVEQ.L	  #ITEMTEXT,D0
	       AND.W	  mi_Flags(A2),D0
	       BEQ.B	  ItemImage

* ------------ Add IText position to left and top.
	       ADD.W	  it_LeftEdge(A5),D7
	       ADD.W	  it_TopEdge(A5),D6

* ------------ What font to use ?
	       TST.L	  it_ITextFont(A5)
	       BEQ.B	  DefaultFont

* ------------ Find length of string in pixels.
	       MOVEA.L	  A5,A0
	       MOVEA.L	  _IntuitionBase(A4),A6
	       JSR	  _LVOIntuiTextLength(A6)

* ------------ Add to LeftEdge.
	       ADD.W	  D0,D5 	      * D5 = Right

* ------------ Find hight of string in pixels and add to top.
	       MOVEA.L	  it_ITextFont(A5),A1
	       ADD.W	  ta_YSize(A1),D4     * D4 = Bottom
	       BRA.B	  NextText

* ------------ Find length of string with default font.
DefaultFont:   MOVEA.L	  it_IText(A5),A0
	       JSR	  @Mystrlen(PC)
	       LEA	  _Rp(A4),A1
	       MOVEA.L	  it_IText(A5),A0
	       MOVEA.L	  _GfxBase(A4),A6
	       JSR	  _LVOTextLength(A6)

* ------------ Add to LeftEdge to get rightedge.
	       ADD.W	  D0,D5

* ------------ Find hight of string in pixels and add to top to get bottom.
	       MOVE.W	  _Rp+rp_TxHeight(A4),D4
	       ADD.W	  D6,D4

* ------------ Move to next text.
NextText:      MOVEA.L	  it_NextText(A5),A5
	       BRA.B	  CheckLeft

* ------------ Add Image position to left and top.
ItemImage:     ADD.W	  (A5),D7
	       ADD.W	  ig_TopEdge(A5),D6

* ------------ Add Imgage width and height to right and bottom.
	       ADD.W	  ig_Width(A5),D5
	       ADD.W	  ig_Height(A5),D4

* ------------ Move to next image
	       MOVE.L	  ig_NextImage(A5),A5

* ------------ Find lowest leftedge.
CheckLeft:     CMP.W	  D7,D3 	      * D3 = LeftEdge
	       BGE.B	  1$
	       MOVE.L	  D3,D7
1$:	       CMP.W	  (A3),D7
	       BGE.B	  CheckRight
	       MOVE.W	  D7,(A3)

* ------------ Find Biggest RightEdge
CheckRight:    ADD.W	  mi_Width(A2),D3     * D3 = RightEdge
	       CMP.W	  D5,D3
	       BLE.B	  1$
	       MOVE.L	  D3,D5
* ------------ If item has subitem make room for pointer.
1$:	       TST.L	  mi_SubItem(A2)
	       BEQ.B	  2$
	       ADDQ.W	  #6,D5
* ------------ If screentype is HIRESSCREEN make pointer bigger.
	       TST.W	  _ScreenType(A4)
	       BNE.B	  2$
	       ADDQ.W	  #4,D5
2$:	       CMP.W	  ws_Right(A3),D5
	       BLE.B	  CheckTop
	       MOVE.W	  D5,ws_Right(A3)

* ------------ Find lowest Topedge.
CheckTop:      CMP.W	  D6,D2 	      * D2 = TopEdge
	       BGE.B	  1$
	       MOVE.L	  D2,D6
1$:	       CMP.W	  ws_Top(A3),D6
	       BGE.B	  CheckBottom
	       MOVE.W	  D6,ws_Top(A3)

* ------------ Find biggest bottompos.
CheckBottom:   ADD.W	  mi_Height(A2),D2    * D2 = BottomEdge
	       CMP.W	  D4,D2
	       BLE.B	  1$
	       MOVE.L	  D2,D4
1$:	       CMP.W	  ws_Bottom(A3),D4
	       BLE.B	  2$		      * Size comes before speed.
	       MOVE.W	  D4,ws_Bottom(A3)
2$	       BRA.W	  Check

Done:	       MOVEM.L	  (SP)+,D2-D7/A2-A3/A5-A6
	       RTS

	       section	  __MERGED,bss

	       xref	  _Rp
	       xref	  _ScreenType
	       xref	  _IntuitionBase
	       xref	  _GfxBase

	       END