*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="resizer.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS resizer AS control 
 	*< CLASSDATA: Baseclass="control" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Label1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: onresize
		*p: nlastheight
		*p: nlastwidth
	*</DefinedPropArrayMethod>

	*<PropValue>
		BackStyle = 0
		BorderWidth = 0
		Comment = "*:OnResize=RB"
		Height = 14
		Name = "resizer"
		nlastheight = 0
		nlastwidth = 0
		Width = 14
	*</PropValue>

	ADD OBJECT 'Label1' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "o", ;
		FontName = "Marlett", ;
		Height = 14, ;
		Left = 0, ;
		Name = "Label1", ;
		Top = 0, ;
		Width = 14
		*< END OBJECT: BaseClass="label" />
	
	PROCEDURE Init
		*
		* Save the original form size
		*
		THIS.nLastHeight = ThisForm.Height
		THIS.nLastWidth  = ThisForm.Width
		
		IF ThisForm.MinHeight = -1
		   *
		   * Make the design height the minimum if not otherwise specified
		   *
		   ThisForm.MinHeight = ThisForm.Height
		ENDIF
		
		IF ThisForm.MinWidth = -1
		   *
		   * Make the design width the minimum if not otherwise specified
		   *
		   ThisForm.MinWidth = ThisForm.Width
		ENDIF
		
		*
		* Move this control to the right bottom of the form
		*
		THIS.Top  = ThisForm.Height - THIS.Height + 2
		THIS.Left = ThisForm.Width  - This.Width  + 2
		
		*
		* Make sure the border style is resizable
		*
		ThisForm.BorderStyle = 3
		
	ENDPROC

	PROCEDURE onresize
		*
		* Call this method from the Form.Resize event
		*
		LOCAL ARRAY laObjects[1]
		LOCAL lnCount,lnI, loObject, lnDeltaHeight,  lnDeltaWidth
		LOCAL lcOnResize, lcHeight, lcWidth, lnAtPos
		
		*
		* Lock the screen
		*
		ThisForm.LockScreen = .T.
		
		*
		* Calculate the change in height since the last resize
		*
		lnDeltaHeight = ThisForm.Height - THIS.nLastHeight
		lnDeltaWidth  = ThisForm.Width  - THIS.nLastWidth
		
		*
		* Build an array of objects
		*
		lnCount = Obj2Arr(@laObjects, ThisForm)
		
		FOR lnI = 1 TO lnCount
		   *
		   * Get the object
		   *
		   loObject = laObjects[lnI]
		   
		   IF TYPE('loObject.Comment') <> 'C'
		      *
		      * No comment property, skip control
		      LOOP
		   ENDIF
		   
		   lnAtPos = ATCC('*:OnResize=', loObject.Comment)
		   IF lnAtPos = 0
		      *
		      * No On resize specified, skip control
		      *
		      LOOP
		   ENDIF
		   
		   *
		   * Determine the actions to be preformed
		   *
		   lcOnResize = UPPER(PADR(SUBSTR(loObject.Comment, lnAtPos + 11), 2))
		   lcHeight   = RIGHT(lcOnResize, 1)
		   lcWidth    = LEFT(lcOnResize, 1)
		   
		   *
		   * Chanhe the Height/Top of needed
		   DO CASE
		      CASE lcHeight = 'C'
		         *
		         * Center verticaly
		         *
		         loObject.Top    = loObject.Top    + ROUND(lnDeltaHeight / 2, 0)
		         
		      CASE lcHeight = 'B'
		         *
		         * Align with bottom
		         *
		         loObject.Top    = loObject.Top    + lnDeltaHeight
		         
		      CASE lcHeight = 'S'
		         *
		         * Resize object vertically
		         *
		         loObject.Height = loObject.Height + lnDeltaHeight
		   ENDCASE
		   
		   DO CASE
		      CASE lcWidth = 'C'
		         *
		         * Center horizontally
		         *
		         loObject.Left  = loObject.Left  + ROUND(lnDeltaWidth / 2, 0)
		         
		      CASE lcWidth = 'R'
		         *
		         * Align to right site
		         *
		         loObject.Left  = loObject.Left  + lnDeltaWidth
		         
		      CASE lcWidth = 'S'
		         *
		         * Size object horizontally
		         *
		         loObject.Width = loObject.Width + lnDeltaWidth
		   ENDCASE
		ENDFOR
		
		*
		* Remember the current form size
		*
		THIS.nLastHeight = ThisForm.Height
		THIS.nLastWidth  = ThisForm.Width
		
		*
		* Unlock the form to show changes
		*
		ThisForm.LockScreen = .F.
		
	ENDPROC

ENDDEFINE
