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

	*<DefinedPropArrayMethod>
		*p: firstrun		&& Internal
		*p: resizeheight
		*p: resizewidth
	*</DefinedPropArrayMethod>

	HIDDEN firstrun
	*<PropValue>
		BackStyle = 0
		BorderColor = 128,64,0
		BorderWidth = 1
		firstrun = .T.
		Height = 20
		Name = "autoresize"
		resizeheight = (thisform.Height)
		resizewidth = (thisform.Width)
		ToolTipText = "Resizes controls on a form"
		Visible = .F.
		Width = 20
	*</PropValue>
	
	PROCEDURE Error
		LPARAMETERS nError, cMethod, nLine
		
		*--------------------------------------------
		*  Ignore all error from this class
		*--------------------------------------------
		RETURN
		
	ENDPROC

	PROCEDURE Refresh
		*------------------------------------------------------------
		* Description: Auto Resize - resizes all control on form.
		* Parameters:  tObj, Object to resize, default = thisform
		* Return:      n/a
		* Use:         In the Forms Resize event place "thisform.Refresh()"
		*------------------------------------------------------------
		* Id Date        By         Description
		*  1 01/07/2005  GLR	 	Initial Creation v. 1.00.0001
		*  2 01/11/2005  GLR		Free up Tag by move Anchors to ResizeAnchors
		*  3 01/12/2005  GLR        Add option to center control Horz.
		*
		*------------------------------------------------------------
		
		
		*!*	Instructions
		*!*
		*!*	1. Place this control on your form
		*!*	2. In each of the controls you wish to have auto resize, place in the
		*!*	   TAG property a combination of follow letters.
		*!*
		*!*	   T : When the form's height grows, move control down.
		*!*	   L : When the form's width grows, move control to the right
		*!*	   H : When the form's height grows, make the control's height grow too
		*!*	   W : When the form's width grows, make the control's width grow too
		*!*    C : Center the control horizonally.
		*!*
		*!*	3. Place in the Form's Resize event the statement
		*!*
		*!*		THISFORM.Refresh()
		*!*
		*!*	That is all there is to it.
		
		
		LPARAMETERS tObj
		
		IF VARTYPE(tObj) # "O"
			tObj = THISFORM
		ENDIF
		IF TYPE("__Hdiff")="U" AND TYPE("_Wdiff")="U"
			
			*--------------------------------------------
			*  Deactivate screen
			*--------------------------------------------
			Local __LS
			__LS = thisform.LockScreen 
			thisform.LockScreen = .F.
		
			PRIVATE __Hdiff, __Wdiff
		
			*--------------------------------------------
			*  Perset these properties
			*--------------------------------------------
			IF EMPTY(THIS.ResizeHeight) OR EMPTY(THIS.ResizeWidth)
				THIS.ResizeHeight = THISFORM.HEIGHT
				THIS.ResizeWidth  = THISFORM.WIDTH
			ENDIF
		
			*--------------------------------------------
			*  Determine how much has changed by resizing the form.
			*--------------------------------------------
		
			__Hdiff = THISFORM.HEIGHT-THIS.ResizeHeight
			THIS.ResizeHeight = THISFORM.HEIGHT
			__Wdiff = THISFORM.WIDTH-THIS.ResizeWidth
			THIS.ResizeWidth = THISFORM.WIDTH
		
			*--------------------------------------------
			*  If not resized, and not first time through, exit
			*--------------------------------------------
			IF __Hdiff=0 AND __Wdiff=0 AND (NOT THIS.FirstRun)
				RETURN
			ENDIF
			THIS.FirstRun = .F.
		
		ENDIF
		
		
		WITH tObj
		
			*--------------------------------------------
			*  Does the TAG property have Resize information
			*--------------------------------------------
			IF TYPE("tObj.Tag")="C" ;
					AND (NOT EMPTY(.TAG) ) ;
					AND LEN(ALLTRIM(CHRTRAN(.TAG,"TLHW","")))=0
		
				*--------------------------------------------
				*  Free up the Tag property for the application
				*--------------------------------------------
				*!*			tObj.ADDPROPERTY("ResizeAnchors", UPPER(.TAG))
				*!*			.Tag = ""
			ENDIF
		
			*--------------------------------------------
			*  Is there Anchors
			*--------------------------------------------
			*!*		IF PEMSTATUS(tObj,"ResizeAnchors",5)
			*!*			LOCAL lcTLHW
			*!*			lcTLHW = .ResizeAnchors
			IF PEMSTATUS(tObj,"Tag",5)
				LOCAL lcTLHW
				lcTLHW = .TAG
		
				*--------------------------------------------
				*  Resize this control
				*--------------------------------------------
				.TOP = .TOP + 		IIF( "T"$lcTLHW, __Hdiff, 0 )
		
				.LEFT = .LEFT + 	IIF( "L"$lcTLHW, __Wdiff, 0 )
		
				.HEIGHT = .HEIGHT + IIF( "H"$lcTLHW, __Hdiff, 0 )
		
				.WIDTH = .WIDTH + 	IIF( "W"$lcTLHW, __Wdiff, 0 )
		
				*-- Center control horizonally
				.LEFT = IIF( "C"$lcTLHW, (.PARENT.WIDTH - .WIDTH) / 2 , .LEFT )
		
			ENDIF
		
			*--------------------------------------------
			*  If this control has child controls, check them
			*--------------------------------------------
			IF TYPE("tObj.Objects[1]")="O"
		
				FOR EACH lObj IN tObj.OBJECTS
		
					THIS.REFRESH( lObj )
		
				NEXT
		
			ENDIF
		
		ENDWITH
		
		*--------------------------------------------
		*  Reactivate Screen
		*--------------------------------------------
		IF VARTYPE(__LS)="L"
			thisform.LockScreen = __LS
		ENDIF 
		
		RETURN
		
		
	ENDPROC

ENDDEFINE
