#include "oohg.ch"
#include "hbclass.ch"
#include "i_windefs.ch"
#include "dSign.ch"

/* TRY / CATCH / FINALLY / END */
#xcommand TRY  => BEGIN SEQUENCE WITH {| oErr | Break( oErr ) }
#xcommand CATCH [<!oErr!>] => RECOVER [USING <oErr>] <-oErr->

MEMVAR oMain, TitleHeight, BorderHeight, BorderWidth, oStat, ;
			oCtrlBox, oWControl, oControlP, aUndo

STATIC  nMilliSeconds := 0, oCopy := {}, lSelecting := .F.	//, aActions := {,}
			
/*
See dSign.ch
#DEFINE aSELECTED		oWin:Cargo[2]
#DEFINE aBox				oWin:Cargo[3]
#DEFINE POSITION			oWin:Cargo[4]
#DEFINE RestofFMG		oWin:Cargo[5]
#DEFINE MODIFIED			oWin:Cargo[6]
*/
// Control Cargo setup is Array(5)
/*#define cTYPE		1
#define GRIDPOS		2
#define lSELECTED	3
#define lMOVED		4
#define TABINDEX		5
*/
//#define MOVING			oWin:Cargo[7]	//aActions[1]
#define ACROSSX		oWin:Cargo[10]
#define ACROSSY		oWin:Cargo[11]
#define ONMENU		oWin:Cargo[12]

Function AddWindow(cName, x, y, w, h, cTitle, aDatas, cAfter)
Local oWin
	DEFAULT aDatas TO WINDOW_DATAS
	DEFAULT cName TO "TEMPLATE"
	DEFAULT cAfter TO ""
	EMPTY(cTitle)

   DECLARE WINDOW cName
   oWin :=  DefineWindow( , ctitle, y, x, w, h, ;
          /*nominimize*/, /*nomaximize*/, /*nosize*/, /*nosysmenu*/, ;
          /*nocaption*/, /*{InitProcedure}*/, {|| wRelease(oWin)} /*{ReleaseProcedure}*/, ;
          /*{MouseDragProcedure}*/, /*{SizeProcedure}*/, /*{ClickProcedure}*/, ;
          /*{MouseMoveProcedure}*/, StrToColor(aDatas[wBACKCOLOR,2]), /*{PaintProcedure}*/, ;
          /*noshow*/, /*topmost*/, /*icon*/, Comillas(aDatas[wFONT,2]), aDatas[wFONTSIZE,2], ;
          /*NotifyIcon*/, /*NotifyIconTooltip*/, /*{NotifyLeftClick}*/, ;
          /*{GotFocusProcedure}*/, /*{LostFocusProcedure}*/, aDatas[wVIRTUALHEIGHT,2], ;
          aDatas[wVIRTUALWIDTH,2], /*{scrollleft}*/, /*{scrollright}*/, /*{scrollup}*/, ;
          /*{scrolldown}*/, /*{hScrollBox}*/, /*{vScrollBox}*/, aDatas[wHELPBUTTON,2], ;
          /*{MaximizeProcedure}*/, /*{MinimizeProcedure}*/, /*cursor*/, ;
          /*noautorelease*/, oMain /*(parent)*/, {|| WCierre(oWin) }/*{interactivecloseprocedure}*/, ;
          /*focused*/, /*break*/, /*grippertext*/, aDatas[wRTL,2], /*main*/, ;
          /*splitchild*/, .T./*child*/, /*modal*/, /*modalsize*/, /*mdi*/, ;
          /*internal*/, /*mdichild*/, /*mdiclient*/, MyForm() /*SubClass*/, ;
          aDatas[wCLIENTAREA,2], /*{RestoreProcedure}*/, {|| NewControl(oWin) }/*{RClickProcedure}*/, ;
          /*{MClickProcedure}*/, /*{DblClickProcedure}*/, ;
          /*{RDblClickProcedure}*/, /*{MDblClickProcedure}*/, /*minwidth*/, ;
          /*maxwidth*/, /*minheight*/, /*maxheight*/, /*{MoveProcedure}*/, ;
          /*backimage*/, /*stretch*/, StrToColor(aDatas[wFONTCOLOR,2]), /*nodwp*/, /*INTERACTIVECLOSE*/ )




/*	DEFINE WINDOW TEMPLATE AT x, y WIDTH w HEIGHT h ;
		TITLE Comillas(aDatas[wTITLE,2]) ;
		OBJ oWin ;
		PARENT (oMain);
		SUBCLASS MyForm ;
		CHILD ;
		FONT aDatas[wFONT,2] ;
		SIZE aDatas[wFONTSIZE,2] ;
		FONTCOLOR aDatas[wFONTCOLOR,2] ;
		BACKCOLOR IsValidColorArray( aDatas[wBACKCOLOR,2] );
		ON INTERACTIVECLOSE WCierre(oWin) ;
		ON RCLICK NewControl(oWin) ;
		ON RELEASE wRelease(oWin)
*/
//		On GOTFOCUS {|| WGotFocus(oWin)} ;
//		oWin:OnRMClick := {|| CURSORCROSS() }

		ON KEY ESCAPE 	ACTION {|| If( wCierre(oWin), oWin:Release(), )}
		ON KEY F6 			ACTION {|| UpdateWControls(oWin)}
		ON KEY DELETE		ACTION DeleteControls(oWin)

//ON KEY F8 ACTION db_Text(oWin:aCtrlsTabIndxs)
		
		ON KEY F5 			ACTION {|| oWin:Redraw(), DrawB(oWin)}
		oWin:SetKey(VK_A,	2,{|| MenuAlign(oWin) })	// 2 es con <CTRL>
		oWin:SetKey(VK_C,	2,{|| oCopy := ACLONE(aSELECTED) })
		oWin:SetKey(VK_D,	2,{|| Duplicar(oWin) })		
		oWin:SetKey(VK_E,	2,{|| MenuSpace(oWin) })	
		oWin:SetKey(VK_F,	2,{|| FontChange(oWin) })	
		oWin:SetKey(VK_V,	2,{|| Duplicar(oWin, .F.) })

		oWin:SetKey(VK_X,	2,{|| UpdateFonts(oWin) })	
		oWin:SetKey(VK_Z,	2,{|| Undo(oWin) })	
		
		oWin:SetKey(VK_DOWN,	0,{|| MoveControl(oWin, 1, 0) })
		oWin:SetKey(VK_UP,		0,{|| MoveControl(oWin,-1, 0) })
		oWin:SetKey(VK_RIGHT,	0,{|| MoveControl(oWin, 0, 1) })
		oWin:SetKey(VK_LEFT,	0,{|| MoveControl(oWin, 0,-1) })

		oWin:SetKey(VK_DOWN,	2,	{|| MoveControl(oWin, 5, 0) })
		oWin:SetKey(VK_UP,		2,	{|| MoveControl(oWin,-5, 0) })
		oWin:SetKey(VK_RIGHT,	2,	{|| MoveControl(oWin, 0, 5) })
		oWin:SetKey(VK_LEFT,	2,	{|| MoveControl(oWin, 0,-5) })

		oWin:SetKey(VK_DOWN,	1,	{|| SizeControl(oWin, 1, 0) })	// 1 es con <ALT>
		oWin:SetKey(VK_UP,		1,	{|| SizeControl(oWin,-1, 0) })
		oWin:SetKey(VK_RIGHT,	1,	{|| SizeControl(oWin, 0, 1) })
		oWin:SetKey(VK_LEFT,	1,	{|| SizeControl(oWin, 0,-1) })


	END WINDOW
	
	oWin:lHasFocus := .F.		// initialize to .F.
	oWin:aDatas := aDatas
	oWin:aEvents := GetDataArray("WINDOW")[2]
	aDatas[NAME,2] := cName

	oWin:cFileName := ""
	oWin:Cargo := ARRAY(12)
	oWin:Cargo[cTYPE] := "WINDOW"
	aSELECTED	:= {}
	aBox			:= {}
	POSITION		:= {,}
	RestofFMG	:= ''
	MODIFIED		:= .F.
	ONGROW		:= .F.
	aFRAME := {,,,}		// For DrawFocusRect
	MOVING := .F.
	ACROSSX := {,,,}
	ACROSSY := {,,,}
	ONMENU := .F.
	oWin:GetDC()			
	
	oWin:cBefore :=  ""
	oWin:cAfter := cAfter
	oWin:lAdjust := .F.
	oCtrlBox:Show()
	oMain:Cargo := oWin
Return oWin

Procedure Undo(oWin)
//	db_Text(aUndo)
	If !EMPTY(aUndo)
//		AEVAL(aUndo, {|a| db_Text("Movin "+a[1]:Name+" to "+hb_DumpVar( {a[3], a[2], a[4] , a[5]},.T.)) })
		AEVAL(aUndo, {|a| a[1]:SizePos( a[3], a[2], a[4] , a[5]) })
		If LEN(aSELECTED) = 0
			aUndo := {}
		Endif
		Invalidate(oWin)									// Remove boxes
		DrawB(oWin)
*		UpdateWControls(oWin)
//		aUndo := {}
	Endif
Return

Procedure MenuAlign(oWin)
Local oMenu	
	If LEN(aSELECTED) > 1
		POSITION := {,}
		DEFINE CONTEXT MENU OF (oWin) OBJ oMenu
			Item "Alinear &Derecha"				ACTION AlignControls(oWin, 1)
			Item "Alinear &Izquierda"			ACTION AlignControls(oWin, 2)
			Item "Alinear Arri&ba"				ACTION AlignControls(oWin, 3)
			Item "Alinear &Abajo"				ACTION AlignControls(oWin, 4)
		END MENU
		oMenu:Activate()
		DO EVENTS
		oMenu:Release()
		oMenu := NIL
	Endif
Return

Procedure MenuSpace(oWin)
Local oMenu	
	If LEN(aSELECTED) > 2
		POSITION := {,}
		DEFINE CONTEXT MENU OF (oWin) OBJ oMenu
			Item "&Vertical"				ACTION SpaceControls(oWin, 1)
			Item "&Horizontal"			ACTION SpaceControls(oWin, 2)
		END MENU
		oMenu:Activate()
		DO EVENTS
		oMenu:Release()
		oMenu := NIL
	Endif
Return

Function WCierre(oWin)
Local nAction
	if MODIFIED
		nAction := MsgYesNoCancel("Save changes to "+oWin:cFileName+"?","Alert")
		If nAction = 0
			Return .F.
		Elseif nAction = 1
			Save(oWin)
		Endif
	Endif
Return .T.

/*
Procedure WGotFocus(oWin)
//oMain:BringToTop()
*     SetWindowPos(oControlP:hWnd, oWin:hWnd, oControlP:Row, oControlP:Col, oControlP:Width, oControlP:Height, 0x0010)

	If !Hb_IsObject(oMain:Cargo) 
*		oMain:Cargo := oWin
		UpdateWControls(oWin)
		SendMessage( oCtrlBox:Control_01:hWnd, BM_SETCHECK, BST_CHECKED, 0 )
	ElseIf oMain:Cargo:hWnd <> oWin:hWnd
*		ReleaseControls(oMain:Cargo)
*		oMain:Cargo := oWin
		UpdateWControls(oWin)
		SendMessage( oCtrlBox:Control_01:hWnd, BM_SETCHECK, BST_CHECKED, 0 )
//		ControlProperties(oWin)
	Endif
Return
*/
*-----------------------------------------------------------------------------*
Procedure WRelease(oWin)
	oControlP:Hide()
	If LEN(_OOHG_FormObjects()) = 5
		If oMain:Cargo:Name == oWin:Name
			oMain:Cargo := NIL
		Endif
		oCtrlBox:Hide()
		oWControl:Hide()
*		oControlP:Hide()
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure WControlData(oWin)
Local o, aTemp, hWnd := oWControl:mControl:hWnd
	For EACH o IN aSELECTED
		aTemp := {o:aDatas[NAME,2], TRANSFORM(o:nRow,"9999"), TRANSFORM(o:nCol,"9999"), TRANSFORM(o:nWidth,"9999"), TRANSFORM(o:nHeight,"9999"), o:Cargo[cTYPE]}
      ListViewSetItem( hWnd, aTemp, o:Cargo[GRIDPOS] )
	Next
Return	

*-----------------------------------------------------------------------------*
Procedure UpdateWControls(oWin)
Local aItems := {}, o, lStat := .F., lTool := .F., j := 1
	For EACH o IN oWin:aControls
		If EMPTY(o:Cargo) .OR. o:Type == "MENU"
			LOOP
		Endif
		o:Cargo[TABINDEX] := hb_EnumIndex()
		o:Cargo[GRIDPOS] := j		// identifica la posición dentro del GRID de Controles
		j ++
		AADD(aItems, {o:aDatas[NAME,2], o:nRow, o:nCol, o:nWidth, o:nHeight, o:Cargo[cTYPE], o:Cargo[GRIDPOS]} )
		If o:Cargo[cTYPE] = "STATUSBAR"
			lStat := .T.
		ElseIf o:Cargo[cTYPE] == "TOOLBAR"
			lTool := .T.
		Endif
	Next
	// Prender o apagar Control de StatusBar en la caja de controles
	SendMessage( oCtrlBox:Control_Statusbar:hWnd, BM_SETCHECK, if( lStat, BST_CHECKED, BST_UNCHECKED ), 0 )
	oCtrlBox:Control_Statusbar:xOldValue := lStat
// Prender o apagar Control de TollBar
	SendMessage( oCtrlBox:Control_Toolbar:hWnd, BM_SETCHECK, if( lTool, BST_CHECKED, BST_UNCHECKED ), 0 )
	oCtrlBox:Control_Toolbar:xOldValue := lTool
	WinControl(aItems)
Return

*-----------------------------------------------------------------------------*
Procedure Duplicar(oWin, lDup)
Local o, NewControl, aControls := {}, x := 0, aCtrls, oTab
DEFAULT lDup TO .T.
	If lDup
		x := 30
		aCtrls := aSELECTED
	Else
		aCtrls := oCopy
	Endif
	If LEN(aCtrls) > 0
		For Each o In aCtrls
			If o:Cargo[cTYPE] == "STATUSBAR" .OR. o:Cargo[cTYPE] == "TOOLBAR" ;
				.OR. o:Cargo[cTYPE] == "PAGE" .OR. o:Cargo[cTYPE] == "TAB"
			ELSE
				NewControl := AddControl(o:Cargo[cTYPE], o:Name, o:nRow+x, o:nCol+x, o:nWidth, o:nHeight, oWin, ACLONE(o:aDatas),,.F.)
				NewControl:aEvents := ACLONE(o:aEvents)
				If lDup			
					If Hb_IsObject(o:Container) .AND.  o:Container:Type == "TABPAGE"			// add control to tab page
						PutControlInTab(o:Container:Container, NewControl)
					Endif
				Elseif LEN(aSELECTED) = 1
					If aSELECTED[1]:Type = "TAB"
						oTab := aSELECTED[1]
						PutControlInTab(oTab, NewControl)
					ElseIf aSELECTED[1]:Type = "TABPAGE"
						oTab := aSELECTED[1]:Container
						PutControlInTab(oTab, NewControl)
					Endif
				Endif					
					
				AADD(aControls, NewControl)
			Endif
		Next
		ReleaseControls(oWin)
		UpdateWControls(oWin)
		AEVAL(aControls, {|o| SelectControl(o, .T.), lSelecting := .F.} )
	Endif
Return				
			
*-----------------------------------------------------------------------------*
Procedure NewControl(oWin)
Local cType, cName, aPt, aPos := {0,0,0,0}, oTab, oCtrl, aDatasAndEvents
	cType := oCtrlBox:Cargo
	If !EMPTY(cType)
		aPt := GetCursorPos()
		GetWindowRect(oWin:hWnd, aPos)
		aPt[ 1 ] -= ( aPos[2] + TitleHeight + Borderheight ) 
		aPt[ 2 ] -= ( aPos[1] + BorderWidth )
		cName := NewControlName(cType, oWin)
		// Check if control is in a tab page
		aDatasAndEvents := GetDataArray(cType)
		If (oTab := InTab(oWin, aPt)) <> NIL
			aPt[1] -= oTab:nRow
			aPt[2] -= oTab:Col
			oCtrl := AddControl(cType, cName, aPt[1], aPt[2],,, oWin, aDatasAndEvents[1],,.T.)
			If oCtrl = NIL
				Return
			Endif
			oTab:AddControl( oCtrl, oTab:Value, aPt[1], aPt[2] )
		Else
			oCtrl := AddControl(cType, cName, aPt[1], aPt[2],,, oWin, aDatasAndEvents[1],,.T.)
			If oCtrl = NIL
				Return
			Endif
		Endif
		oCtrl:aEvents := aDatasAndEvents[2]
		MODIFIED := .T.
// Add control to oWControl		
		UpdateWControls(oWin)
		If cType == "TAB"
			aDatasAndEvents := GetDataArray("PAGE")
			oCtrl := AddControl("PAGE", "Page_1",,,,, oWin, aDatasAndEvents[1])
			oCtrl:aEvents := aDatasAndEvents[2]
			END PAGE
			END TAB
			oCtrlBox:Cargo := cType
		Endif
		SelectControl(oCtrl)
		oCtrl:Redraw()
		If !EMPTY(oCtrl:OnDblClick)
			Eval(oCtrl:OnDblClick)
		Endif
		
	Endif
	oCtrlBox:Cargo := ''		
Return

*-----------------------------------------------------------------------------*
Function NewControlName(cType, oWin)
Local cName, n := 1
	cName := cType+"_"+LTRIM(STR(n))
	WHILE ASCAN(oWin:aControls, {|o| o:Name == UPPER(cName)} ) > 0
		n++
		cName := cType+"_"+LTRIM(STR(n))
	Enddo
Return cName
	
*-----------------------------------------------------------------------------*
Function MouseMove(oWin)
Local aPt, lRet := .F. 
	aPt := GetCursorPos()
	POSITION := aClone(aPt)	//GetCursorPos()
   aPt[ 1 ] -= (GetWindowRow( oWin:hWnd ) + TitleHeight + Borderheight)
   aPt[ 2 ] -= (GetWindowCol( oWin:hWnd ) + BorderWidth)

/*  Draw CrossHair
	DrawFocusRect(oWin:hDC, ACROSSX)	// draws horizontal line
	DrawFocusRect(oWin:hDC, ACROSSY)	// draws vertical line
	ACROSSX := {0, aPt[2], oWin:nHeight, aPt[2]}
	ACROSSY := {aPt[1], 0,  aPt[1], oWin:nWidth }
	DrawFocusRect(oWin:hDC, ACROSSX)	// draws vertical line
	DrawFocusRect(oWin:hDC, ACROSSY)	// draws horizontal line
*/
	oMain:StatusBar:Item(1,"R = "+str(aPt[1],4)+" / C = "+str(aPt[2],4))
	If !MOVING .AND. LEN(aBox) = 4
		lRet := CursorShape(oWin, aPt)	
	Endif
Return lRet  

*-----------------------------------------------------------------------------*
Procedure MouseClick(oWin)
	If !oWin:Active
		Return
	Endif
	IF ONGROW
		mDrag(oWin)
	Else
		ReleaseControls(oWin)
		ControlProperties(oWin)
	Endif
Return

/*-----------------------------------------------------------------------------
Executed when left mouse button is released on the form
Used to select controls with in area selected
------------------------------------------------------------------------------*/
Procedure wLButtonUp(oWin)
Local o, oTab, aCtrls

	If lSelecting .AND. aFRAME[1] <> NIL
//db_Text("Seleccionando controles")
		lSelecting := .F.
		DrawFocusRect(oWin:hDC, aFRAME)
		For EACH o IN oWin:aControls
			If !Hb_IsArray(o:Cargo) .OR. o:Type $ "MENU MESSAGEBAR TOOLBAR" 
				LOOP
			Endif
			// don´t select controls in tabs that are not shown
			If o:Container:ClassName == "TTABPAGE"
				If (o:Container:Container:Value <> o:Container:Position)
					LOOP
				Endif
			Endif
			IF	aFRAME[1] <= o:ContainerRow .and. aFRAME[2] <= o:ContainerCol .and. ;
						aFRAME[3] >= (o:ContainerRow+o:nHeight) .and. ;
						aFRAME[4] >= (o:ContainerCol+o:nWidth)
				SelectControl(o, .T.)
			ENDIF
		NEXT 
		aFRAME := {,,,}
	Endif
	If MOVING		// Actualizar despues de mover controles
		MOVING := .F.
		aCtrls := aSELECTED
*		ReleaseControls(oWin)
		For EACH o IN aCtrls
			// Check to see if control is draged out of a Tab Page
			If Hb_IsObject(o:Container)
				If (o:nRow < 1 .OR. o:nCol < 1)  
					o:nRow := o:nRow + o:Container:ContainerRow
					o:nCol := o:nCol + o:Container:ContainerCol 
					o:Container:Super:DeleteControl(o)
					o:Container := NIL
				ElseIf o:nRow > o:Container:Container:Height .OR. o:nCol > o:Container:Container:Width
//db_Text(	{o:Container:Container:Width, o:Container:Container:Height, o:nRow, o:nCol})
					o:nRow := o:nRow + o:Container:ContainerRow
					o:nCol := o:nCol + o:Container:ContainerCol 
					o:Container:Super:DeleteControl(o)
					o:Container := NIL
				Endif
			Endif
			If !hb_IsObject(o:Container) //.AND. (o:Container:Container:Value <> oTab:Value)
				// Check to see if control is draged in to a Tab Page
				oTab := InTab(oWin, {o:nRow, o:nCol})
//db_Text("OnButtonUp")
				If hb_IsObject(oTab) .AND. oTab:hWnd <> o:hWnd .AND. o:Type <> "TABPAGE" 
					o:nRow := o:ContainerRow - oTab:ContainerRow
					o:nCol := o:ContainerCol - oTab:ContainerCol
					PutControlInTab(oTab, o)
				Endif
			Endif

		Next

*		aEVAL(aCtrls, {|o| SelectControl(o, .T.)})
		UpdateWControls(oMain:Cargo)
		WControlData(oWin)
	Endif

Return

*-----------------------------------------------------------------------------*
Procedure PutControlInTab(oTab, o)
Local i, nIndex
	For i := oTab:Value TO 1 STEP -1
		If LEN(oTab:aPages[i]:aControls) > 0
			nIndex := ATAIL(oTab:aPages[i]:aControls):Cargo[TABINDEX]+1
			Exit
		Endif
	Next
	If nIndex = NIL
		nIndex := oTab:Cargo[TABINDEX]+1
	Endif
	oTab:AddControl( o, oTab:Value, o:nRow, o:nCol )
	TabIndex( o, nIndex)
Return
*-----------------------------------------------------------------------------*

// This function enables point and drag to select controls within rectangle
Procedure Selecting(oWin)
Local aPt := GetCursorPos(), a := {,}
	If POSITION[1] = NIL		// No sé por qué llega a ser NIL
		Return					// pero sucede despues de presentar menu de alinear
	Endif							// y en lugar de seleccionar opcion, se da click en la ventana
	If aFRAME[1] <> NIL 
		lSelecting := .T.
		DrawFocusRect(oWin:hDC, aFRAME)
	Endif

	a[1] := POSITION[1] - (GetWindowRow( oWin:hWnd ) + TitleHeight + Borderheight)
	a[2] := POSITION[2] - (GetWindowCol( oWin:hWnd ) + BorderWidth)
	aPt[1] -= (GetWindowRow( oWin:hWnd ) + TitleHeight + Borderheight)
	aPt[2] -= (GetWindowCol( oWin:hWnd ) + BorderWidth)
	oMain:StatusBar:Item(1,"R = "+str(aPt[1],4)+" / C = "+str(aPt[2],4))
	aFRAME[1] := If(a[1]< aPt[1], a[1], aPt[1])
	aFRAME[2] := If(a[2]< aPt[2], a[2], aPt[2])
	aFRAME[3] := If(a[1]> aPt[1], a[1], aPt[1])
	aFRAME[4] := If(a[2]> aPt[2], a[2], aPt[2])
	DrawFocusRect(oWin:hDC, aFRAME)
Return

*-----------------------------------------------------------------------------*
Procedure DeleteControls(oWin)
	If Len(aSELECTED) > 0
		If MsgYesNo("Borrar controles seleccionados","Alert")
			MODIFIED := .T.
			Invalidate(oWin)
			AEVAL(aSELECTED, {|o| DeleteControl(o) })
			UpdateWindow(oWin:hWnd)
			aSELECTED := {}
			aBox := {}
			UpdateWControls(oWin)
			ControlProperties(oWin)
		Endif
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure DeleteControl(o)
	If o:Cargo[cTYPE] == "PAGE"
		o:Container:DeletePage(o:aDatas[tpPOSITION,2])
	ElseIf o:Cargo[cTYPE] == "TBUTTON"
		CheckSelected(o:Cargo[GRIDPOS], .F.)
		o:Container:DeleteButton(o:Position)
	Else
		CheckSelected(o:Cargo[GRIDPOS], .F.)
		o:Release()
	Endif
Return
		
*-----------------------------------------------------------------------------*
Procedure SelectControl(oo, lAdd, lDelete)
Local oWin := oo:Parent, n
DEFAULT lAdd TO .F.
DEFAULT lDelete TO .F.

	If lSelecting
		Return
	Endif

	lSelecting := .T.
	If LEN(aSELECTED) > 0 .AND. (n:= ASCAN(aSELECTED, {|o| o:Name == oo:Name })) > 0
		If aSELECTED[n]:Cargo[lSELECTED]
			If GetKeyState(VK_SHIFT) < 0 					// Remove from selected if Shift pressed
				oo := aSELECTED[n]
				oo:Cargo[lSELECTED] := .F.					// Set selected to .F.
				Invalidate(oWin)									// Remove boxes
				Hb_aDel(aSELECTED, n, .T.)
				Hb_aDel(aUndo, n, .T.)
				CheckSelected(oo:Cargo[GRIDPOS], .F.)	// Unselect in Controls data grid
				DO EVENTS
				DrawB(oWin)
			Endif
		Endif
	Else
		If GetKeyState(VK_SHIFT) < 0 .OR. lAdd
			Invalidate(oWin)									// Remove boxes
		Else
			ReleaseControls(oWin)						// Release all controls
			aUndo := {}
		Endif
		AADD(aUndo, {oo, oo:nCol, oo:nRow, oo:nWidth, oo:nHeight})
		AADD(aSELECTED, oo)								// Add to selected array
		oo:Cargo[lSELECTED] := .T.
		DrawB(oWin)									// Draw boxes
      ListView_EnsureVisible( oWControl:mControl:hWnd, oo:Cargo[GRIDPOS] )	// Make sure it is visible in Controls Data Grid
	Endif

	If LEN(aSELECTED) = 1
		CheckSelected(oo:Cargo[GRIDPOS], .T.)		// Select in Controls Data grid
		ControlProperties(oo)						// Update properties grid
	Else
		oControlP:P_Control:DeleteAllItems()	// Delete properties grid
		oControlP:E_Control:DeleteAllItems()	// Delete events grid
	Endif

*	If oo:Type = "TOOLBAR"
*		lSelecting := .F.
*	ElseIf !MOVING		// don't do to enable multi control select

*	If !MOVING		// don't do to enable multi control select
*		// This is to avoid initial movement of control and annoing Save massage
*		oMain:Update:Value := 30
*		oMain:Update:OnClick := {|| oMain:Update:Enabled := .F., lSelecting := .F. }
*		oMain:Update:Enabled := .T.
*	Else
*	Endif
	lSelecting := .F.

RETURN

*-----------------------------------------------------------------------------*
Procedure ReleaseControls(oWin)
	Invalidate(oWin)
	AEVAL(aSELECTED, {|o| CheckSelected(o:Cargo[GRIDPOS], .F.), o:Cargo[lSELECTED] := .F. })
*	UpdateWindow(oWin:hWnd)
	aSELECTED := {}
	aBox := {}
Return

*-----------------------------------------------------------------------------*
Procedure SpaceControls(oWin, nSpacing)
Local x, aArray, nSpace, nUsed := 0
	If Hb_IsObject(oWin) .and. LEN(aSELECTED) > 2
		MODIFIED := .T.
		Invalidate(oWin)
		aArray := ACLONE(aSELECTED)
		If nSpacing = 1		// Vertical
			aArray := ASORT(aArray, {|o1, o2| (o1:nRow < o2:nRow) })
			nSpace := (aArray[LEN(aArray)]:nRow+aArray[LEN(aArray)]:nHeight) - aArray[1]:nRow
			AEVAL(aArray, {|o| nUsed += o:nHeight })
			x := INT((nSpace - nUsed) / (LEN(aArray)-1))
			AEVAL(aArray, {|o, n| o:Row := (aArray[n-1]:nRow+aArray[n-1]:nHeight)+x },2, LEN(aArray)-1)
		Else						// Horizontal
			aArray := ASORT(aArray, {|o1, o2| (o1:nCol < o2:nCol) })
			nSpace := (aArray[LEN(aArray)]:nCol+aArray[LEN(aArray)]:nWidth) - aArray[1]:nCol
			AEVAL(aArray, {|o| nUsed += o:nWidth })
			x := INT((nSpace - nUsed) / (LEN(aArray)-1))
			AEVAL(aArray, {|o, n| o:Col := (aArray[n-1]:nCol+aArray[n-1]:nWidth)+x },2, LEN(aArray)-1)
		Endif
		WControlData(oWin)
		DO EVENTS
		DrawB(oWin)
	Endif
Return
	
*-----------------------------------------------------------------------------*
Procedure AlignControls(oWin, nAlign)
Local x
	If Hb_IsObject(oWin) .and. LEN(aSELECTED) > 1
		MODIFIED := .T.
		Invalidate(oWin)
		If nAlign = 1			// Rigth
			x := aSELECTED[1]:nCol+aSELECTED[1]:nWidth
			AEVAL(aSELECTED, {|o| o:Col += x - (o:nCol+o:nWidth) },2)
		ElseIf nAlign = 2		// Left
			x := aSELECTED[1]:nCol
			AEVAL(aSELECTED, {|o| o:Col := x},2)
		ElseIf nAlign = 3		// Up
			x := aSELECTED[1]:nRow
			AEVAL(aSELECTED, {|o| o:Row := x},2)
		Else						// Down
			x := aSELECTED[1]:nRow+aSELECTED[1]:nHeight
			AEVAL(aSELECTED, {|o| o:Row += x - (o:nRow+o:nHeight) },2)
		Endif
		WControlData(oWin)
		DO EVENTS
		DrawB(oWin)
	Endif
Return
	
*-----------------------------------------------------------------------------*
Procedure SizeControl(oWin, y, x)
Local o
	If !EMPTY(aSELECTED)
		MODIFIED := .T.
		Invalidate(oWin)

		For EACH o IN aSELECTED
			If( o:Height > 5 .AND. o:nHeight + y < 5,, o:nHeight += y)
			If( o:Width > 5 .AND. o:nWidth + x < 5,, o:nWidth += x)
			If o:Type <> "TOOLBAR"
				MoveWindow(o:hWnd, o:ContainerCol, o:ContainerRow, o:Width , o:Height)
			Endif
			If o:Type == "SPINNER"
				MoveWindow(o:AuxHandle, o:ContainerCol + o:Width - 15, o:ContainerRow, 15, o:Height , .T. )
			Endif	
		Next
		
		DrawB(oWin)
		WControlData(oWin)
	Endif
Return
   
*-----------------------------------------------------------------------------*
Function MDrag(oWin)
Local aPt := GetCursorPos(), x, y

	If POSITION[1] = NIL; Return .F.; Endif
	x := aPt[2] - POSITION[2]
	y := aPt[1] - POSITION[1]
	If x <> 0 .OR. y <> 0
		oMain:StatusBar:Item(1,;
			"R = "+str(aPt[ 1 ] - (GetWindowRow( oWin:hWnd ) + TitleHeight + Borderheight),4)+;
			" / C = "+str(aPt[ 2 ] - (GetWindowRow( oWin:hWnd ) + TitleHeight + Borderheight),4))

		If lSelecting .OR. LEN(aSELECTED) = 0 //.OR. EMPTY(POSITION[1])
			Return .F.
		Endif

		POSITION := ACLONE(aPt)
		If ONGROW .OR. GetKeyState(VK_MENU) < 0
			SizeControl(oWin, y, x)
			Return .T.
		Endif
		MoveControl(oWin, y, x)
	Endif
		
Return .T.

*-----------------------------------------------------------------------------*
Procedure MoveControl(oWin, y, x)
Local o, cType
	If !EMPTY(aSELECTED)
		MOVING := .T.
		MODIFIED := .T.
		oMain:Update:Value := 100
		If !oMain:Update:lEnabled
			Invalidate(oWin)
			oMain:Update:OnClick := {|| oMain:Update:Enabled := .F., DrawB(oWin), WControlData(oWin) }
			oMain:Update:Enabled := .T.
		Endif
		For EACH o IN aSELECTED
			cType := o:Cargo[cTYPE]

			If o:Type <> "TOOLBAR" .AND. !o:Cargo[lMOVED]
				If cType $ "PAGE" //.OR. cType == "TAB"
					MoveTab(o:Container, x, y)
					o:Container:SizePos(o:ContainerRow, o:ContainerCol)
				ElseIf cType == "TAB"
					MoveTab(o, x, y)
					o:SizePos(o:nRow, o:nCol)
				Else
					o:nRow += y
					o:nCol += x
					MoveWindow(o:hWnd, o:ContainerCol, o:ContainerRow, o:Width , o:Height)
				Endif
				If cType == "SPINNER"
					MoveWindow(o:AuxHandle, o:ContainerCol + o:Width - 15, o:ContainerRow, 15, o:Height , .T. )
				ElseIf cType == "RADIOGROUP"
					o:Repaint()
				Endif
				o:Cargo[lMOVED] := .T.
			Endif
		Next
		AEVAL(aSELECTED, {|o| o:Cargo[lMOVED] := .F. })
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure MoveTab(oTab, x, y)
Local o
	If !oTab:Cargo[lSELECTED] .OR. !oTab:Cargo[lMOVED]
	// Move Tab
		oTab:nRow += y
		oTab:nCol += x
		MoveWindow(oTab:hWnd, oTab:ContainerCol, oTab:ContainerRow, oTab:Width , oTab:Height)
//		oTab:Cargo[lMOVED] := oTab:Cargo[lSELECTED]
	Endif
	// Redraw controls
	FOR EACH o In oTab:aPages[oTab:Value]:aControls
		o:Redraw()
*			MoveWindow( o:hWnd, o:ContainerCol, o:ContainerRow, o:nWidth, o:nHeight )
		 o:Cargo[lMOVED] := o:Cargo[lSELECTED]	// Avoid double movement of controls when moving page
	
		If o:Cargo[cTYPE] == "TAB"
				MoveTab(o)
		ElseIf o:Type == "RADIOGROUP"
			o:Repaint()
		Elseif o:Type == "SPINNER"
*				MoveWindow(o:AuxHandle, o:ContainerCol + o:Width - 15, o:ContainerRow, 15, o:Height , .T. )
		Endif
	Next
	
Return

*-----------------------------------------------------------------------------*
Procedure Invalidate(oWin, lTrue)
DEFAULT lTrue TO .T.
	If LEN(aBox) > 0
		INVALIDATERECT(oWin:hWnd, {aBox[1,2]-1, aBox[1,1]-1,aBox[4,4]+1, aBox[4,3]+1}, lTrue)
		DO EVENTS		// Give it time to erase and refresh
	Endif
	
Return

*-----------------------------------------------------------------------------*
#define BS	4					// 4 number of pixels for box size
#define GROW_NW	1			// Cursor_WSE
#define GROW_SE	2

#define GROW_N		3			// cursor_NS
#define GROW_S		4

#define GROW_E		5			// Cursor_WE
#define GROW_W		6

#define GROW_NE	7			// Cursor_ESW
#define GROW_SW	8			
#define GROW_NONE	0

#DEFINE XC 1
*-----------------------------------------------------------------------------*
// Draw buttons around the control
Procedure DrawB(oWin)
Local o, x,y,w,h, i, hDC := oWin:hDC
Local aSelected := aSELECTED
	x := y := 100000
	w := h := 0
	If HB_IsArray(aSelected)
		For EACH o In aSelected
			x := MIN(x, o:ContainerRow)
			y := MIN(y, o:ContainerCol)
			If o:Type == "RADIOGROUP"
				w := MAX(w, o:ContainerCol+o:GroupWidth())
				h := MAX(h, o:ContainerRow+o:GroupHeight())
			Else
				w := MAX(w, o:ContainerCol+o:nWidth)
				h := MAX(h, o:ContainerRow+o:nHeight)
			Endif
		Next
		aBox := {}
		AADD(aBox, {x-BS, y-BS, x, y})		// upper left
		AADD(aBox, {x-BS, w, x, w+BS})		// upper right
		AADD(aBox, {h, y-BS, h+BS, y})		// lower left
		AADD(aBox, {h, w, h+BS+1, w+BS+1})	// lower right
		For i := 1 to LEN(aBox)-1
			C_Rectangle(hDC, aBox[i,1], aBox[i,2], aBox[i,3], aBox[i,4])					
		next i
		C_Fill(hDC, aBox[i,1], aBox[i,2], aBox[i,3], aBox[i,4])
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure UpdateBox(Self)
Local x, y, nw, nh, oWin := ::Parent	// Middle
	If ::Cargo[1] == "STATUSITEM" .OR. ::Cargo[1] == "TOOLBAR"
		Return
	Endif
	
	x 	:= ::ContainerRow
	y 	:= ::ContainerCol
	nw := If(::Cargo[cTYPE] == "RADIOGROUP", ::GroupWidth(), ::nWidth )
	nh := If(::Cargo[cTYPE] == "RADIOGROUP", ::GroupHeight(), ::nHeight)

	aBox := {}
	AADD(aBox, {x-BS, y-BS, x, y})					// upper left
	AADD(aBox, {x-BS, y+nw, x, y+nw+BS})			// upper right
	AADD(aBox, {x+nh, y-BS, x+nh+BS, y})			// lower left
	AADD(aBox, {x+nh, y+nw, x+nh+BS+1, y+nw+BS+1})	// lower right

	// calculate middle vertical
*	Middle := INT(nh/2 - BS/2)
*	AADD(aBox, {x+Middle, y-BS, x+Middle+BS, y})			// Middle left
*	AADD(aBox, {x+Middle, y+nw, x+Middle+BS, y+nw+BS})	// Middle Right
	
	// calculate middle horizontal
*	Middle := INT(nw/2 - BS/2)
*	AADD(aBox, {x-BS, y+Middle, x, y+Middle+BS})			// Middle Top
*	AADD(aBox, {x+nh, y+Middle, x+nh+BS, y+Middle+BS})	// Middle Bottom
Return

*-----------------------------------------------------------------------------*
Function CursorShape(oWin, aPt)
// aPt[1]	is Row	is y
// aPt[2]	is Col	is x
	If hb_IsNil(aBox) .OR. EMPTY(aBox)
		Return .F.
	Endif

	If aPt[1] >= aBox[4,1]-BS .and. aPt[1] <= aBox[4,3] +BS+1 .AND.;
		aPt[2] >= aBox[4,2]-BS .AND. aPt[2] <= aBox[4,4] +BS+1
		ONGROW := .T.
		CURSORSIZENWSE()
	Else
		ONGROW := .F.
	Endif
										
Return ONGROW

/*
	//set shape of cursor
	IF nx <= BS 										// in left 
		IF ny <= ::aBox[1,4]							// in top 
			nRet := GROW_NW
		ELSEIF ny >= ::aBox[5,2] .and. ny <= ::aBox[5,4]	// in middle
			nRet := GROW_W
		ELSEIF ny >= ::aBox[4,2]					// in bottom
			nRet := GROW_SW
		ENDIF

	ELSEIF nx >= ::aBox[7,1] .and. nx <= ::aBox[7,3]	// in middle
		IF ny <= BS 
			nRet := GROW_N
		ELSEIF ny >= ::aBox[8,2]
			nRet := GROW_S
		ENDIF

	ELSEIF nx >= ::aBox[2,1]					// in right
		IF ny <= BS									// on top
			nRet := GROW_NE
		ELSEIF ny >= ::aBox[6,2] .and. ny <= ::aBox[6,4]
			nRet := GROW_E
		ELSEIF ny >= ::aBox[4,2]
			nRet := GROW_SE
		ENDIF
			
	ENDIF
	
	IF nx < 0 .or. nx > ::nw .or. ny < 0 .or. ny > ::nh
		nRet := GROW_NONE
	ENDIF

	IF nRet > 6
		SetCursor(Cursor_ESW)
	ELSEIF nRet > 4
		SetCursor(Cursor_WE)
	ELSEIF nRet > 2
		SetCursor(Cursor_NS)
	ELSEIF nRet > 0
		SetCursor(Cursor_WSE)
	ELSE
		SetCursor(Cursor)
	ENDIF
	::oParent:Grow := nRet
	
Return nRet
*/

*-----------------------------------------------------------------------------*
Function CheckForControl(oWin) 
LOCAL o, MRow, MCol, oControl, aPt, aPos := {0,0,0,0}
	If MOVING
		Return oControl
	Endif
	aPt := GetCursorPos()   
	GetWindowRect(oWin:hWnd, aPos)
	aPt[ 1 ] -= ( aPos[2] + TitleHeight + Borderheight ) 
	aPt[ 2 ] -= ( aPos[1] + BorderWidth )

	MRow := aPt[1]
   MCol := aPt[2]
   FOR EACH o IN oWin:aControls
		If !Hb_IsArray(o:Cargo) .OR. o:Type == "MENU" .OR. !o:ContainerVisible
			LOOP
		Endif
		If o:TYPE == "RADIOGROUP"
			IF MRow >= o:ContainerRow .AND. MRow <= o:ContainerRow + o:GroupHeight() .AND. ;
				MCol >= o:ContainerCol .AND. MCol <= o:ContainerCol + o:GroupWidth()
				oControl := o
			Endif
		Elseif o:Type == "COMBO"
			// Solo seleccionar la parte visible del combobox
			IF MRow >= o:ContainerRow .AND. MRow <= o:ContainerRow + 26 .AND. ;
				MCol >= o:ContainerCol .AND. MCol <= o:ContainerCol + o:nWidth
				oControl := o
			Endif
		Else
			IF MRow >= o:ContainerRow .AND. MRow <= o:ContainerRow + o:nHeight .AND. ;
				MCol >= o:ContainerCol .AND. MCol <= o:ContainerCol + o:nWidth
				oControl := o
			Endif
		Endif
   NEXT
RETURN oControl

*-----------------------------------------------------------------------------*
// This function checks if position is in a tab
Function InTab(oWin, aPt) 
LOCAL o, oTab
	For EACH o IN oWin:aControls
		If !hb_IsArray(o:Cargo) .OR. o:Type == "MENU"
			LOOP
		Endif
		If o:Cargo[1] == "TAB"
			If o:nRow <= aPt[1] .AND. o:nRow+o:nHeight >= aPt[1] ;
				.AND. o:nCol <= aPt[2] .AND. o:nCol+o:nWidth >= aPt[2]
				oTab := o
				Exit
			Endif
		Endif
	Next
RETURN oTab

*-----------------------------------------------------------------------------*
Procedure Add_Del_StatusBar(oWin)
Local n, aDatasAndEvents	
	If HB_IsObject(oWin)
		n := ASCAN(oWin:aControls, {|o| If(hb_IsString(o:Type) .and. o:Type == "MESSAGEBAR", .T., .F.)})
		If n = 0
			MODIFIED := .T.
			aDatasAndEvents := GetDataArray("STATUSBAR")
			n := AddControl("STATUSBAR","" ,,,,,oWin, aDatasAndEvents[1])
			n:aEvents := aDatasAndEvents[2]
		ElseIf MsgYesNo("Desea quitar el STATUSBAR?", "dSign")
			MODIFIED := .T.
			oWin:aControls[n]:Release()
		Endif
		oWin:Redraw()
		UpdateWControls(oWin)
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure Add_Del_ToolBar(oWin)
Local n, aDatasAndEvents	
	If HB_IsObject(oWin)
		n := ASCAN(oWin:aControls, {|o| If(hb_IsString(o:Type) .and. o:Type == "TOOLBAR", .T., .F.)})
		If n = 0
			MODIFIED := .T.
			aDatasAndEvents := GetDataArray("TOOLBAR")
			n := AddControl("TOOLBAR","ToolBar_1",0,0,90,50,oWin, aDatasAndEvents[1])
			n:aEvents := aDatasAndEvents[2]
		ElseIf MsgYesNo("Desea quitar el TOOLBAR?", "dSign")
			MODIFIED := .T.
			oWin:aControls[n]:Release()
		Endif
		oWin:Redraw()
		UpdateWControls(oWin)
	Endif
Return

*-----------------------------------------------------------------------------*
// Controls
Function AddControl(cType, cName, x, y, w, h, oWin, aDatas, cAfter, lNew)
Local o, xTemp1, xTemp2, xTemp3, cValue 
DEFAULT lNew TO .T.

	// Check control name is not already taken
	If Comillas(cName) == "0" .OR. EMPTY(cName)
		cName := NewControlName(cType, oWin)
	ElseIf ASCAN(oWin:aControls, {|o| o:Name == UPPER(cName) }) > 0
		cName := NewControlName(cType, oWin)
	Endif
*	If cType <> "STATUSBAR" .AND. ASCAN(oWin:aControls, {|o| o:Name == UPPER(cName)} ) > 0
*		cName := NewControlName(cType, oWin)
*	Endif

	cName := UPPER(Comillas(cName))	// ESTO ES NECESARIO
	aDatas[NAME,2] := cName

	cValue := GetaDatas("VALUE", aDatas)
	cValue := If(Empty(cValue) .OR. cValue = NIL, If(!EMPTY(cName), cName,), cValue)

	PutaDatas("FONTCOLOR", StrToColor(GetaDatas("FONTCOLOR",aDatas)), aDatas) 
	PutaDatas("BACKCOLOR", StrToColor(GetaDatas("BACKCOLOR",aDatas)), aDatas) 
	PutaDatas("FONT", Comillas(GetaDatas("FONT", aDatas)), aDatas) 

	DO CASE
   CASE cType == "ACTIVEX"
     o := MyLabel():Define( cName, oWin, y, x, ;
				/*::StrToValueCtrl( ::aProgID[i], "C", cName )*/, w, h, ;
				NIL, NIL, .F., .T., .F., ;
				.F., .F., .F., WHITE, NIL, NIL, NIL, NIL, .F., .F., NIL, .F., .F., NIL )

*      o := TActiveX():Define( cName, oWin, y, x, w, h, ;
*            /*progid*/, /*notabstop*/, /*disabled*/, /*invisible*/ )

   CASE cType == "ANIGIF"
		If lNew
			w := 24
			h := 40
		Endif
      o := TAniGIF():Define( cName, oWin, y, x, /*<filename>*/, w, h, ;
            /*action*/, aDatas[dHELPID,2], /*invisible*/,aDATAS[dWHITEBACKGROUND,2], aDatas[dRTL,2], ;
            aDatas[dBACKCOLOR,2], aDatas[dTOOLTIP,2], /*aDatas[dBORDER,2]*/ .T., aDatas[dCLIENTEDGE,2], /*disabled*/ )

   CASE cType == "ANIMATEBOX"
		// Notes: Tooltip is set on registration
		If lNew
			w := 24
			h := 40
		Endif
      o := MyAnimateBox():Define( cName, oWin, y, x, w, h, ;
            aDatas[dAUTOPLAY,2], aDatas[dCENTER,2], /*transparent*/, /*file*/, /*helpid*/, ;
            /*invisible*/, /*notabstop*/, /*disabled*/, aDatas[dRTL,2], aDATAS[dTOOLTIP,2] )
		aDatas[NAME,2] := cName
		
	CASE cType == "BUTTON"
		// Si el botón lleva imagen y no lleva CAPTION no ponerlo
		If EMPTY(aDatas[dPICTURE,2])
			xTemp1 := IF(EMPTY(aDatas[dCAPTION,2]), cName, Comillas(aDatas[dCAPTION,2]))
		ElseIf lNew
			DEFAULT aDatas[dCAPTION,2] TO cName
			xTemp1 := Comillas(aDatas[dCAPTION,2])
		Endif

     o := MyButton():Define( cName, oWin, y, x, xTemp1, /*action*/,;
				w, h, aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*gotfocus*/, /*lostfocus*/,;
				aDatas[dFLAT,2], 	/*notabstop*/.F., /*helpid*/, /*invisible*/.F., aDatas[dBOLD,2], ;
				aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dRTL,2], aDatas[dNOPREFIX,2], ;
				/*disabled*/.F., /*buffer*/, /*hbitmap*/, If( !EMPTY(aDatas[dPICTURE,2]), GetPicture(aDatas[dPICTURE,2], "ZZZ_AAAOOHG"), NIL), aDatas[dNOLOADTRANSPARENT,2],;
				aDatas[dSTRETCH,2], /*cancel*/.F., aDatas[dIMAGEALIGN,2], aDatas[dMULTILINE,2], ;
				if( aDatas[dOOHGDRAW,2], .T., iif( aDatas[dWINDRAW,2], .F., NIL ) ), ;
				/*::StrToValueCtrl( ::aImageMargin[i], "A", NIL, 4, 0, "N" )*/, /*onmousemove*/, aDatas[dNO3DCOLORS,2], aDatas[dFORCESCALE,2],;
				! aDatas[dDIBSECTION,2], aDatas[dBACKCOLOR,2], aDatas[dNOHOTLIGHT,2], aDatas[dSOLID,2], aDatas[dFONTCOLOR,2], ;
				{aDatas[dTEXTALIGNH,2], aDatas[dTEXTALIGNV,2]}, aDatas[dNOPRINTOVER,2], aDatas[dTEXTMARGIN,2], aDatas[dFITTXT,2], aDatas[dFITIMG,2],;
				aDatas[dIMAGESIZE,2], aDatas[dTRANSPARENT,2], aDatas[dNOFOCUSRECT,2], aDatas[dNOIMAGELIST,2], /*nodestroy*/.F. )

		o:OnDblClick := {|| FastData(o, "CAPTION") }

	CASE cType == "CHECKBOX"
*		If lNew
*			DEFAULT aDatas[dCAPTION,2] TO cName
*		Endif
      o := MyCheckBox():Define( cName, oWin, y, x, Comillas(aDatas[dCAPTION,2]), /*uValue*/, ;
                  aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*bOnChange*/, w, h, NIL, NIL, ;
                  NIL, .F., .F., aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], ;
                  NIL, StrToColor(aDatas[dBACKCOLOR,2]), aDatas[dFONTCOLOR,2], aDatas[dTRANSPARENT,2], aDatas[dAUTOSIZE,2], ;
						aDatas[dRTL,2], .F., aDatas[dTHREESTATE,2], aDatas[dLEFTJUSTIFY,2], ;
						if( aDatas[dOOHGDRAW,2], .T., if( aDatas[dWINDRAW,2], .F., NIL ) ), ;
						/*bkgrnd a implementar*/, aDatas[dNOFOCUSRECT,2] )
		o:OnDblClick := {|| FastData(o, "CAPTION") }

	CASE cType == "CHECKBUTTON"
		xTemp1 := IF(EMPTY(aDatas[dCAPTION,2]), cName, aDatas[dCAPTION,2])
      o := MyCheckButton():Define( cName, oWin, y, x, Comillas(xTemp1), aDatas[dVALUE,2], aDatas[dFONT,2],;
				aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, w, h, /*lostfocus*/, /*gotfocus*/, ;
				/*helpid*/, /*invisible*/.F., /*notabstop*/.F., aDatas[dBOLD,2], aDatas[dITALIC,2], ;
				aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], /*field*/, aDatas[dRTL,2], ;
				if( Empty(aDATAS[dPICTURE,2]), "ZZZ_AAAOOHG", ), /*buffer*/, /*hbitmap*/, aDatas[dNOLOADTRANSPARENT,2], ;
				aDatas[dSTRETCH,2], aDatas[dNO3DCOLORS,2], aDatas[dFORCESCALE,2], ! aDatas[dDIBSECTION,2], ;
				aDatas[dBACKCOLOR,2], /*disabled*/.F., ;
				if( aDatas[dOOHGDRAW,2], .T., if( aDatas[dWINDRAW,2], .F., NIL ) ), ;
				/*::StrToValueCtrl( ::aImageMargin[i], "A", NIL, 4, 0, "N" )*/, /*onmousemove*/, aDatas[dIMAGEALIGN,2], ;
				aDatas[dMULTILINE,2], aDatas[dFLAT,2], aDatas[dNOHOTLIGHT,2], aDatas[dSOLID,2], aDatas[dFONTCOLOR,2], ;
				aDatas[dTEXTALIGNH,2], aDatas[dTEXTALIGNV,2], aDatas[dNOPRINTOVER,2], ;
				/*::StrToValueCtrl( ::aTxtMrgn[i], "A", NIL, 4, 0, "N" )*/, ;
				aDatas[dFITTXT,2], aDatas[dFITIMG,2], aDatas[dIMAGESIZE,2], aDatas[dTRANSPARENT,2], ;
				aDatas[dNOFOCUSRECT,2], aDatas[dNOIMAGELIST,2], /*nodestroy*/.F. )
		o:OnDblClick := {|| FastData(o, "CAPTION") }

	CASE cType == "CHECKLIST"
		If EMPTY(aDatas[dITEMS,2]) .OR. !hb_IsArray(aDatas[dITEMS,2])
			xTemp1 := {cName}
		Else
			xTemp1 := &(aDatas[dITEMS,2])
		Endif
      o := MyCheckList():Define( cName, oWin, y, x, w, h, xTemp1, /*value*/, aDatas[dFONT,2], ;
				aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, /*gotfocus*/, /*lostfocus*/,;
				aDatas[dIMAGE,2], aDatas[dJUSTIFY,2], /*break*/.F., /*helpid*/, aDatas[dBOLD,2],;
				aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dBACKCOLOR,2],;
				aDatas[dFONTCOLOR,2], aDatas[dRTL,2], /*disabled*/.F., /*notabstop*/.F., /*invisible*/.F.,;
				aDatas[dSORT,2], aDatas[dDESCENDING,2], StrToColor( aDatas[dSELECTEDCOLORS,2] ), ;
				/*bffr*/.T., /*click*/ )

	CASE cType == "COMBOBOX"
		If lNew 
			aDatas[dWIDTH,2] := NIL		// default value
			aDatas[dHEIGHT,2] := NIL	// default value
		Elseif h = 0
			aDatas[dHEIGHT,2] := NIL	// default value
		Endif

      o := MyCombo():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dITEMS,2], /*Value*/1, ;
				aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*changeprocedure*/, ;
				aDatas[dHEIGHT,2], /*gotfocus*/,  /*lostfocus*/, /*enter*/, /*helpid*/, ;
				/*invisible*/.F., /*notabstop*/.F., aDatas[dSORT,2], aDatas[dBOLD,2], ;
				aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], /*itemsource*/,;
				/*valuesource*/, /*displayedit*/.F., /*displaychng*/, /*dont know*/.F., ;
				aDatas[dGRIPPERTEXT,2], aDatas[dIMAGE,2], aDatas[dRTL,2], aDatas[dTEXTHEIGHT,2], ;
				/*disabled*/.F., aDatas[dFIRSTITEM,2], aDatas[dFIT,2], aDatas[dBACKCOLOR,2], ;
				aDatas[dFONTCOLOR,2], aDatas[dLISTWIDTH,2], /*listdisplay*/, /*listclose*/,;
				/*imagesource*/, /*itemimagenumber*/, /*delay*/.F., aDatas[dINCREMENTAL,2], ;
				aDatas[dINTEGRALHEIGHT,2], .F., /*sourceorder*/, /*refresh*/, /*nLapse*/, ;
				aDatas[dMAXLENGTH,2], aDatas[dEDITHEIGHT,2], aDatas[dOPTIONSHEIGHT,2], ;
				aDatas[dNOHSCROLL,2], /*noclone*/.F., /*NoTrans*/.F., /*cancel*/, /*lIndex*/, aDatas[dAUTOSIZE,2], Comillas(aDatas[dCUEBANNER,2]) )

		o:OnListDisplay := {|| PostMessage( o:hWnd, CB_SHOWDROPDOWN, 0, 0 ) }

	CASE cType == "DATEPICKER"
		If lNew
			aDatas[dWIDTH,2] := IF(EMPTY(aDatas[dWIDTH,2]), 100, aDatas[dWIDTH,2] )
			aDatas[dHEIGHT,2] := IF(EMPTY(aDatas[dHEIGHT,2]), 24, aDatas[dHEIGHT,2] )
		Endif
      o := MyDatePicker():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2], ;
				/*Value*/, aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, /*lostfocus*/, ;
				/*gotfocus*/, aDatas[dSHOWNONE,2], aDatas[dUPDOWN,2], aDatas[dRIGHTALIGN,2], /*helpid*/,;
				/*invisible*/.F., /*notabstop*/.F., aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2],;
				aDatas[dSTRIKEOUT,2], /*field*/, /*enter*/, aDatas[dRTL,2], /*disabled*/.F., ;
				aDatas[dNOBORDER,2], /*RANGE min*/, /*max*/, aDatas[dFORMAT,2], /*valid*/ )

	CASE cType == "EDITBOX"
		If lNew
			w := NIL
			h := NIL
		Endif
      o := MyEdit():Define( cName, oWin, y, x, w, h, ;
				Comillas(aDatas[dVALUE,2]), aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], ;
				aDatas[dMAXLENGTH,2], /*gotfocus*/, /*change*/, /*lostfocus*/, /*aDatas[dREADONLY,2]*/, ;
				.F., /*helpid*/, /*invisible*/.F., /*notabstop*/.F., ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], /*field*/,;
				aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], aDatas[dNOVSCROLL,2], ;
				aDatas[dNOHSCROLL,2], aDatas[dRTL,2], aDatas[dNOBORDER,2], aDatas[dFOCUSEDPOS,2], ;
				/*hscroll*/, /*vscroll*/, /*disabled*/.F., aDatas[dINSERTTYPE,2] )

	CASE cType == "FRAME"		// OJO Todos los controles son y,x Este es x, y para la posición Row(x), Col(y)
		If lNew
			w := NIL
			h := NIL
			aDatas[dCAPTION][2] := "'"+cName+"'"
		Endif
      o := MyFrame():Define( cName, oWin, x, y, w, h, ;
				Comillas(aDatas[dCAPTION][2]), aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dOPAQUE,2], ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], ;
				aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], aDatas[dTRANSPARENT,2], aDatas[dRTL,2], ;
				/*invisible*/.F., /*disabled*/.F., aDatas[dTOOLTIP,2], aDatas[dEXCLUDEAREA,2] )
		o:OnDblClick := {|| FastData(o, "CAPTION") }
		o:OnRClick := {|| NewControl(oWin)}	// Necesario por que intercepta el click derecho
		
	CASE cType == "GRID" .OR. cType == "XBROWSE" .OR. cType == "BROWSE"
		TRY
			aDatas[dVALUE,2] := VAL(aDatas[dVALUE,2])
		END SEQUENCE

		If VALTYPE(aDatas[dHEADERS,2]) == "A"
			xTemp1 := MAX(1, LEN(aDatas[dHEADERS,2]))
			xTemp2 := Array(1, xTemp1)	// Create empty array for aItems
			Afill(xTemp2[1], " ")
		Else
			xTemp1 := 1
			xTemp2 := {{''}}
		EndIf
*db_Text(hb_dumpvar(aDatas[dHEADERS,2], .T.))
*db_Text(hb_dumpvar(aDatas[dWIDTHS,2], .T.))

		If VALTYPE(aDatas[dINPUTMASK,2]) = "A"
		ElseIf !EMPTY(aDatas[dINPUTMASK,2])
			aDatas[dINPUTMASK,2] := &(aDatas[dINPUTMASK,2])
		Else
			aDatas[dINPUTMASK,2] := Array( LEN(aDatas[dHEADERS][2]) )
		Endif

      o := MyGrid():Define( cName, oWin, y, x, w, h, ;
				If( hb_IsArray(aDatas[dHEADERS,2]), aDatas[dHEADERS,2],{''}),;		//aDatas[dHEADERS][2],
				If( hb_IsArray(aDatas[dWIDTHS,2]), aDatas[dWIDTHS,2],{10}),;		 	//aDatas[dWIDTHS][2], ;
				/*aItems*/ xTemp2, 1, aDatas[dFONT,2], aDatas[dSIZE,2],  aDatas[dTOOLTIP,2], ;
				/*OnChange*/, /*dblclick*/, /*aHeadClick*/, /*gotfocus*/, /*lostfocus*/, ;
				aDatas[dNOLINES,2], /*aImage*/, If( hb_IsArray(aDatas[dJUSTIFY,2]), aDatas[dJUSTIFY,2],), /*break*/.F., /*helpid*/, ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], ;
				/*ownerdata*/.F., /*dispinfo*/, /*itemcount*/,/*edit*/.F., aDatas[dBACKCOLOR,2], ;
				aDatas[dFONTCOLOR,2], /*dynamicbackcolor*/, /*dynamicforecolor*/, aDatas[dINPUTMASK,2],;
				aDatas[dRTL,2], /*inplace*/.F., /*editcontrols*/, /*aReadOnly*/.T., /*aValidFields*/,;
				/*aValidMessages*/, /*editcell*/, /*aWhenFields*/, .F., .F., .F., ! aDatas[dNOHEADERS,2], ;
				/*enter*/, /*aHeaderImages*/, /*aImgAlign*/, /*fullmove*/.F., /*aSelectedColors*/, ;
				/*aEditKeys*/, aDatas[dCHECKBOXES,2], /*checkchange*/, /*bffr*/.F., /*NOFOCUSRECT*/.F., ;
				aDatas[dPAINTLEFTMARGIN,2], /*fixedcols*/.F., /*abortedit*/, /*click*/,/*fixedwidths*/.F.,;
				/*bBefMov*/, /*bAftMov*/, /*bBefSiz*/, /*bAftSiz*/, /*bBefAut*/, /*excel*/.F., ;
				/*buts*/.F., /*delete*/.F., /*onDelete*/, /*bWhenDel*/, /*DelMsg*/, /*nodelmsg*/.F., ;
				/*append*/.F., /*onappend*/, /*nomodal*/.F., /*FIXEDCONTROLS*/.T., /*bheadrclick*/, ;
				/*noclick*/.F., /*norclick*/.F., /*extdbl*/.F., /*silent*/.F., /*alta*/.F., /*noshow*/.F.,;
				/*none*/.F., /*cbe*/.F., /*rclick*/, /*oninsert*/, /*editend*/, /*efv*/.T., /*beforedit*/,;
				/*edtval*/, /*klc*/.F., /*ctt*/.F., /*aDatas[dNOHSCROLL,2]*/, .F./*aDatas[dNOVSCROLL,2]*/,;
				/*beforeins*/, /*aHeadDblClick*/, ;
				If( hb_IsArray(aDatas[dHEADERCOLORS,2]), aDatas[dHEADERCOLORS,2],),/*TIMEOUT*/)
//o:VScrollVisible( .T. )
		o:caColumnBlocks 		:= ASIZE(ParseArray(aDatas[dCOLUMNCONTROLS,2]), xTemp1)
		o:caDynamicBackColor 	:= ASIZE(ParseArray(aDatas[dDYNAMICBACKCOLOR,2]), xTemp1)
		o:caDynamicForeColor 	:= ASIZE(ParseArray(aDatas[dDYNAMICFORECOLOR,2]), xTemp1)
		o:caOnHeadClick 			:= ASIZE(ParseArray(aDatas[dONHEADCLICK,2]), xTemp1)
		o:caOnHeadDblClick 		:= ASIZE(ParseArray(aDatas[dONHEADDBLCLICK,2]), xTemp1)
		o:caHeaderImage 			:= ASIZE(ParseArray(aDatas[dHEADERIMAGES,2]), xTemp1)
		o:caHeaderImageAlign	:= ASIZE(ParseArray(aDatas[dHEADERIMAGESGALIGN,2]), xTemp1)
		o:caWhen						:= if(hb_Isarray(aDatas[dWHEN,2]), aDatas[dWHEN,2], ASIZE(ParseArray(aDatas[dWHEN,2]), xTemp1))
		o:caValid			 		:= ASIZE(ParseArray(aDatas[dVALID,2]), xTemp1)

		If cType == "GRID"
			aDatas[dWORKAREA,2] := ''
		Else	//If cType == "XBROWSE" .or. BROWSE
			o:caDefaultValues := ASIZE(ParseArray(aDatas[dDEFAULTVALUES,2]), xTemp1)
			o:caFields  		:= ASIZE(ParseArray(aDatas[dFIELDS ,2]), xTemp1)
			o:caReplaceField  := ASIZE(ParseArray(aDatas[dREPLACEFIELD,2]), xTemp1)
		Endif

		If hb_IsArray(aDatas[dREADONLY,2])
			o:ReadOnly := aDatas[dREADONLY,2]
		Else
			o:ReadOnly := ARRAY( LEN(o:aHeaders) ) 
			AFILL(o:ReadOnly, .F.)
		ENDIF
		o:bAfterColMove := {|nFrom, nTo| o:ColumnSwap(nFrom, nTo) }
		
   CASE cType == "HOTKEYBOX"
      o := MyHotKeyBox():Define( cName, oWin, y, x, w, h, ;
            Comillas(aDatas[dVALUE,2]), aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2],;
				/*lostfocus*/, /*gotfocus*/, /*change*/, /*enter*/, /*helpid*/, aDatas[dBOLD,2], ;
            aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dBACKCOLOR,2], ;
            aDatas[dFONTCOLOR,2], /*invisible*/, /*notabstop*/, aDatas[dRTL,2], /*disabled*/.F., ;
            aDatas[dNOALT,2] )

	CASE cType == "HYPERLINK"
      o := MyHyperLink():Define( cName, oWin, y, x, Comillas(aDatas[dVALUE,2]), aDatas[dADDRESS,2], ;
				w, h, aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dBOLD,2], aDatas[dBORDER,2], ;
				aDatas[dCLIENTEDGE,2], aDatas[dHSCROLL,2], aDatas[dVSCROLL,2], aDatas[dTRANSPARENT,2],;
				aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], aDatas[dTOOLTIP,2], /*helpid*/, /*invisible*/.F.,;
				aDatas[dITALIC,2], aDatas[dAUTOSIZE,2], aDatas[dHANDCURSOR,2], aDatas[dRTL,2] )
		o:OnDblClick := {|| FastData(o, "VALUE") }
	
	CASE cType == "IMAGE" 
      o := MyImage():Define( cName, oWin, y, x, "IDE_BACKIMG", w, h, /*action*/, ;
				/*helpid*/, /*invisible*/.F., aDatas[dSTRETCH,2], aDatas[dWHITEBACKGROUND,2], ;
				aDatas[dRTL,2], aDatas[dBACKCOLOR,2], /*buffer*/, /*hbitmap*/,;
				! aDatas[dNORESIZE,2], aDatas[dIMAGESIZE,2], ;
				aDatas[dTOOLTIP,2], aDatas[dBORDER,2], aDatas[dCLIENTEDGE,2], aDatas[dNOLOADTRANSPARENT,2], ;
				aDatas[dNO3DCOLORS,2], aDatas[dNODIBSECTION,2], aDatas[dTRANSPARENT,2], aDatas[dEXCLUDEAREA,2], ;
				/*disabled*/.F., /*change*/, /*rclk*/, /*mclk*/, /*dblclk*/, /*rdblclk*/, /*mdblclk*/, ;
				aDatas[dNOCHECKDEPTH,2], /*noredraw*/.F. )
						
		If !EMPTY(aDatas[dPICTURE,2])
			cValue := ALLTRIM(STRTRAN(aDatas[dPICTURE,2], '"', ''))
			cValue := STRTRAN(cValue, "'", '')

			If File(hb_FNameDir(oWin:cFileName)+cValue )
				o:Picture := hb_FNameDir(oWin:cFileName)+cValue
			Endif
		Endif

   CASE cType == "IPADDRESS"
		If lNew
			aDatas[dWIDTH,2] := NIL
			aDatas[dHEIGHT,2] := NIL
		Endif
      o := MyIpAddress():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2],;
				Comillas(aDatas[dVALUE,2]),  aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dBOLD,2],;
				aDatas[dTOOLTIP,2], /*bLostFocus*/, /*bGotFocus*/, /*bChange*/, /*nHelpId*/,;
				/*lInvisible*/.F., /*lNoTabStop*/.F., aDatas[dBOLD,2], aDatas[dITALIC,2], ;
				aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dRTL,2], /*lDisabled*/.F.,;
				aDatas[dFONTCOLOR,2], aDatas[dFONTCOLOR,2] )
		o:OnDblClick := {|| FastData(o, "VALUE") }

	CASE cType == "LABEL"
		If lNew
			aDatas[dVALUE,2] := "'"+cName+"'"
		Endif
		If aDatas[dAUTOSIZE,2]
			w := 20
		Endif

		o := MyLabel():Define( cName, oWin, y, x, ;
				Comillas(aDatas[dVALUE,2]), w, h, aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dBOLD,2], ;
				aDatas[dBORDER,2], aDatas[dCLIENTEDGE,2], aDatas[dHSCROLL,2], aDatas[dVSCROLL,2], ;
				aDatas[dTRANSPARENT,2], aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], /*action*/, ;
				aDatas[dTOOLTIP,2], /*helpid*/, /*invisible*/.F., aDatas[dITALIC,2], aDatas[dUNDERLINE,2], ;
				aDatas[dSTRIKEOUT,2], aDatas[dAUTOSIZE,2], aDatas[dRIGHTALIGN,2], aDatas[dCENTERALIGN,2],;
				aDatas[dRTL,2], aDatas[dNOWORDWRAP,2], aDatas[dNOPREFIX,2], aDatas[dINPUTMASK,2], ;
				/*disabled*/.F., aDatas[dVCENTERALIGN,2] )

		o:OnDblClick := {|| FastData(o, "VALUE")}
		
	CASE cType == "LISTBOX"
		If lNew
			aDatas[dWIDTH,2] := NIL
			aDatas[dHEIGHT,2] := NIL
		Endif
      IF aDatas[dMULTISELECT,2]
         o := MyListMulti():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2],If( HB_IsArray(aDatas[dITEMS,2]), aDatas[dITEMS,2], {}),  /*value*/, ;
					aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, /*dblclick*/, /*gotfocus*/,;
					/*lostfocus*/, .F., /*helpid*/, /*invisible*/.F., /*notabstop*/.F., aDatas[dSORT,2], ;
					aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2],;
					aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], aDatas[dRTL,2], /*disabled*/.F., /*enter*/, ;
					aDatas[dIMAGE,2], aDatas[dTEXTHEIGHT,2], aDatas[dFIT,2], aDatas[dNOVSCROLL,2], ;
					aDatas[dMULTICOLUMN,2], aDatas[dCOLUMNWIDTH,2], aDatas[dMULTITAB,2], aDatas[dTABSWIDTH,2]/*.F.*/, /*dragitems*/.F. )
      ELSE
         o := MyList():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2], If( HB_IsArray(aDatas[dITEMS,2]), aDatas[dITEMS,2], {}), /*value*/, ;
					aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, /*dblclick*/, /*gotfocus*/,;
					/*lostfocus*/, .F., /*helpid*/, /*invisible*/.F., /*notabstop*/.F., aDatas[dSORT,2], ;
					aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2],;
					aDatas[dBACKCOLOR,2], aDatas[dFONTCOLOR,2], aDatas[dRTL,2], /*disabled*/.F., /*enter*/, ;
					aDatas[dIMAGE,2], aDatas[dTEXTHEIGHT,2], aDatas[dFIT,2], aDatas[dNOVSCROLL,2], ;
					aDatas[dMULTICOLUMN,2], aDatas[dCOLUMNWIDTH,2], aDatas[dMULTITAB,2], aDatas[dTABSWIDTH,2]/*.F.*/, /*dragitems*/.F. )
      ENDIF

   CASE cType == "MONTHCALENDAR"
      IF aDatas[dMULTISELECT,2]
         o := MyMultiMonthCal():Define( cName, oWin, y, x, w, h,/*v*/, ;
					aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], ;
					aDatas[dNOTODAY,2], aDatas[dNOTODAYCIRCLE,2], aDatas[dWEEKNUMBERS,2], /*change*/,;
					/*helpid*/, /*invisible*/.F., /*notabsrop*/.F., aDatas[dBOLD,2], ;
					aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dRTL,2],;
					/*Disabled*/.F., aDatas[dFONTCOLOR,2], aDatas[dBACKCOLOR,2], aDatas[dTITLEFONTCOLOR,2],;
					aDatas[dTITLEBACKCOLOR,2], aDatas[dTRAILINGFONTCOLOR,2], aDatas[dBACKGROUNDCOLOR,2],;
					/*viewchg*/, /*gotfocus*/, /*lostfocus*/ )
      ELSE
         o := MyMonthCal():Define( cName, oWin, y, x, w, h, /*v*/,;
					aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], ;
					aDatas[dNOTODAY,2], aDatas[dNOTODAYCIRCLE,2], aDatas[dWEEKNUMBERS,2], /*change*/,;
					/*helpid*/, /*invisible*/.F., /*notabstop*/.F., aDatas[dBOLD,2], ;
					aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dRTL,2], ;
					/*Disabled*/.F., aDatas[dFONTCOLOR,2], aDatas[dBACKCOLOR,2], aDatas[dTITLEFONTCOLOR,2],;
					aDatas[dTITLEBACKCOLOR,2], aDatas[dTRAILINGFONTCOLOR,2], aDatas[dBACKGROUNDCOLOR,2],;
					/*viewchg*/, /*gotfocus*/, /*lostfocus*/ )
      ENDIF

	CASE cType == "PAGE"
      o := _BeginTabPage( Comillas(aDatas[tpCAPTION, 2]), aDatas[tpIMAGE,2], aDatas[tpPOSITION,2], ;
				/*aDatas[NAME,2]*/, /*SubClass*/, aDatas[tpTOOLTIP,2] )
		aDatas[tpPOSITION,2] := o:Position
		
	CASE cType == "PICTURE"		// OJO y x
      o := MyPicture():Define( cName, oWin, y, x, "IDE_BACKIMG", w, h, ;
            /*buffer*/, /*hbitmap*/, aDatas[dSTRETCH,2], aDatas[dFORCESCALE,2], aDatas[dIMAGESIZE,2], ;
            aDatas[dBORDER,2], aDatas[dCLIENTEDGE,2], aDatas[dBACKCOLOR,2], /*action*/,;
				aDatas[dTOOLTIP,2], /*helpid*/, aDatas[dRTL,2], /*invisible*/.F., aDatas[dNOLOADTRANSPARENT,2], ;
				aDatas[dNO3DCOLORS,2], aDatas[dNODIBSECTION,2], aDatas[dTRANSPARENT,2], aDatas[dEXCLUDEAREA,2], /*disabled*/.F. )
	
	CASE cType == "PLAYER"
      o := MyPicture():Define( cName, oWin, y, x, "IDE_PLAYERIMAGE", w, h, ;
            /*buffer*/, /*hbitmap*/, /*STRETCH*/.T., /*FORCESCALE*/, /*IMAGESIZE*/, ;
            /*BORDER*/.T.) //, aDatas[dCLIENTEDGE,2], aDatas[dBACKCOLOR,2], /*action*/,;
//				aDatas[dTOOLTIP,2], /*helpid*/, aDatas[dRTL,2], /*invisible*/.F., aDatas[dNOLOADTRANSPARENT,2], ;
//				aDatas[dNO3DCOLORS,2], aDatas[dNODIBSECTION,2], aDatas[dTRANSPARENT,2], aDatas[dEXCLUDEAREA,2], /*disabled*/.F. )

/*      o := MyLabel():Define( cName, oWin, y, x, cName, ;
				w, h, NIL, NIL, .F., .T., .F., ;
				.F., .F., .F., WHITE, NIL, NIL, NIL, NIL, .F., .F., .F., .F., .F., .F., .F., ;
				aDatas[dRTL,2], .F., .F., NIL, .F. )
*/
//      o := MyPlayer():Define( cName, oWin, /*file*/ ,y, x, w, h, ;
//            /*aDatas[dNOAUTOSIZEWINDOW,2]*/, /*aDatas[dNOAUTOSIZEMOVIE,2]*/, /*aDatas[dNOERRORDLG,2]*/, ;
//            aDatas[dNOMENU,2], aDatas[dNOOPEN,2], aDatas[dNOPLAYBAR,2], aDatas[dSHOWALL,2], aDatas[dSHOWMODE,2],;
//				aDatas[dSHOWNAME,2], /*aDatas[dSHOWPOSITION,2]*/,/*helpid*/,/*invisible*/,;
//				/*aDatas[dNOTAPSTOP,2]*/,/*disabled*/,aDatas[dRTL,2])

		
	CASE cType == "PROGRESSBAR"
      o := myProgressBar():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2], ;
				/*nMin*/ 1, /*nMax*/ 10, aDatas[dTOOLTIP,2], aDatas[dVERTICAL,2], ;
				aDatas[dSMOOTH,2], /*HELPID*/, /*INVISIBLE*/, /*VALUE*/, ;
				If(EMPTY(aDatas[dBACKCOLOR,2]),NIL,aDatas[dBACKCOLOR,2]), ;
				aDatas[dFONTCOLOR,2], aDatas[dRTL,2], aDatas[dMARQUEE,2] )
		o:Value := 9
		
   CASE cType == "PROGRESSMETER"
      o := TProgressMeter():Define( cName, oWin, y, x, w, h, /*nMin*/, /*nMax*/, /*Value*/, ;
				aDatas[dTOOLTIP,2], aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dBOLD,2], aDatas[dITALIC,2], ;
				aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dFORECOLOR,2], aDatas[dBACKCOLOR,2],;
				/*action*/, NIL, /*invisible*/.F., aDatas[dRTL,2], aDatas[dCLIENTEDGE,2], /*disabled*/.F. )

	CASE cType == "RADIOGROUP"
		xTemp1 := aDatas[dOPTIONS][2]

		If VALTYPE(xTemp1) <> 'A'
			xTemp1 := {cName,"Opcion2"}
*			aDatas[dOPTIONS][2] := Comillas(aDatas[dOPTIONS][2])
			aDatas[dOPTIONS][2] := aDatas[dOPTIONS][2]
		Endif
		xTemp2 := VAL(aDatas[dSPACING,2])
		xTemp2 := If(xTemp2 = 0, 25, xtemp2)

		xTemp3 := If( !EMPTY( aDatas[dREADONLY,2] ), &( aDatas[dREADONLY,2] ), NIL)
      o := MyRadioGroup():Define( cName, oWin, y, x, xTemp1, /*value*/, ;
				aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, If(w= 0, NIL, w), ;
				xTemp2, /*helpid*/, /*invisible*/.F., /*notabstop*/.F., aDatas[dBOLD,2], ;
				aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dBACKCOLOR,2], ;
				aDatas[dFONTCOLOR,2], aDatas[dTRANSPARENT,2], aDatas[dAUTOSIZE,2], aDatas[dHORIZONTAL,2],;
				/*disabled*/.F., aDatas[dRTL,2], /*::StrToValueCtrl( ::aHeight[i], "N", NIL )*/, ;
				if( aDatas[dOOHGDRAW,2], .T., iif( aDatas[dWINDRAW,2], .F., NIL ) ), ;
				aDatas[dBACKGROUND,2], aDatas[dLEFTJUSTIFY,2], xTemp3, aDatas[dNOFOCUSRECT,2], ;
				aDatas[dLIMIT,2], aDatas[dSHIFT,2] )


   CASE cType == "RICHEDITBOX"
      o := MyRichEditBox():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2],  ;
				cValue, aDatas[dFONT,2], aDatas[dSIZE,2], aDatas[dTOOLTIP,2], aDatas[dMAXLENGTH,2], ;
				/*gotfocus*/, /*change*/, /*lostfocus*/, /*readonly*/.T., /*break*/.F., /*helpid*/,;
				/*invisible*/.F., /*notabstop*/.F., aDatas[dBOLD,2], aDatas[dITALIC,2], ;
				aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], /*field*/, aDatas[dBACKCOLOR,2], ;
				aDatas[dRTL,2], /*disabled*/.F., /*selchange*/, aDatas[dFONTCOLOR,2], aDatas[dNOHIDESEL,2],;
				aDatas[dFOCUSEDPOS,2], aDatas[dNOVSCROLL,2], aDatas[dNOHSCROLL,2], /*file*/, ;
				if( aDatas[dPLAINTEXT,2], aDatas[dFILETYPE,2], NIL ) , /*hscroll*/, /*vscroll*/,;
				/*nInsType*/, /*nVer*/ )

   CASE cType == "SCROLLBAR"
      o := MyScrollBar():Define( cName, oWin, y, x, w, h, ;
						/*Min*/, /*Max*/, /*OnChange*/, /*lineup*/, /*linedown*/, /*pageup*/,;
						/*pagedown*/, /*top*/, /*bottom*/, /*thumb*/, /*track*/, ;
						/*endtrack*/, /*helpid*/, /*invisible*/.F., /*tooltip*/, /*RTL[i]*/, ;
                  if( aDatas[dHORIZONTAL,2], 0, if( aDatas[dVERTICAL,2], 1, NIL ) ), aDatas[dATTACHED,2],;
						/*value*/, /*disabled*/.F., /*lineskip*/, /*pageskip*/, aDatas[dAUTOMOVE,2] )


	CASE cType == "SLIDER"
		If !EMPTY( aDatas[dRANGE,2] )
			xTemp1 := hb_aTokens(aDatas[dRANGE,2], ",")
			xTemp2 := VAL(xTemp1[1])
			xTemp3 := VAL(xTemp1[2])
		Endif
      o := MySlider():Define( cName, oWin, y, x, w, h,  /*nMin*/xTemp2, /*nMax*/xTemp3, ;
				aDatas[dVALUE,2], aDatas[dTOOLTIP,2], /*change*/, aDatas[dVERTICAL,2], aDatas[dNOTICKS,2], ;
				aDatas[dBOTH,2], aDatas[dTOP,2], aDatas[dLEFT,2], /*helpid*/, /*invisible*/.F., ;
				/*notabstop*/.F., aDatas[dBACKCOLOR,2], aDatas[dRTL,2], /*disabled*/.F. )
		
   CASE cType == "SPLITBOX"
      o := MySplitBox(): ;
            Define( oWin, aDatas[dBOTTOM,2], aDatas[dVERTICAL,2] .OR. aDatas[dHORIZONTAL,2], ;
            aDatas[dRTL,2], aDatas[dNOATTACHED,2] )
	
   CASE cType == "SPINNER"
      o := MySpinner():Define( cName, oWin, y, x, aDatas[dWIDTH,2], /*value*/, ;
				aDatas[dFONT,2], aDatas[dSIZE,2], /*nMin*/, /*nMax*/, aDatas[dTOOLTIP,2], /*change*/,;
				/*lostfocus*/, /*gotfocus*/, h, /*helpid*/, /*invisible*/.F., /*notabstop*/.F., ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], ;
				aDatas[dWRAP,2], /*aDatas[dREADONLY,2]*/, aDatas[dINCREMENT,2], aDatas[dBACKCOLOR,2],;
				aDatas[dFONTCOLOR,2], aDatas[dRTL,2], aDatas[dNOBORDER,2], /*disabled*/.F., aDatas[dBOUNDTEXT,2] )

	CASE cType == "STATUSBAR"
		If EMPTY(cName)
			cName := aDatas[NAME,2] := "STATUSBAR"
		Endif
		xTemp1 := IF( EMPTY(aDatas[stMESSAGE,2]), NIL, aDatas[stMESSAGE,2])
      o := MyStatusBar():Define( cName, oWin, 0, 0, 0, 0,  xTemp1, , ;
             aDatas[stFONT,2],  aDatas[stSIZE,2],  aDatas[stTOOLTIP,2],  aDatas[stCLOCK,2],  ;
				 aDatas[stDATE,2],  aDatas[stKEYBOARD,2], NIL, NIL, aDatas[stBOLD,2], aDatas[stITALIC,2],;
				 aDatas[stUNDERLINE,2], aDatas[stSTRIKEOUT,2], aDatas[stTOP,2], aDatas[stNOAUTOADJUST,2],;
				 aDatas[stWIDTH,2], aDatas[stICON,2], aDatas[stSTYLE,2], aDatas[stALIGN,2] )

	CASE cType == "TAB"
		If lNew
			w  := 200
			h := 150
		Endif
      o :=MyTab():Define( cName, oWin, y, x, w, h, {}, {}, /*value*/, ;
				aDatas[dFONT,2],  aDatas[dSIZE,2], aDatas[dTOOLTIP,2], /*change*/, aDatas[dBUTTONS,2],;
				aDatas[dFLAT,2], aDatas[dHOTTRACK,2], aDatas[dVERTICAL,2], /*notabstop*/.F., NIL, ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], {},;
				aDatas[dRTL,2], aDatas[dINTERNALS,2], /*invisible*/.F., /*disabled*/.F., ;
				aDatas[dMULTILINE,2], /*delaymsg*/.F., aDatas[dRIGHT,2], aDatas[dBOTTOM,2],; 
				/*rclick*/, aDatas[dRAGGEDRIGHT,2], aDatas[dFIXEDWIDTHS,2], NIL, /*ITEMSIZE nw*/, ;
				/*ITEMSIZE nh*/, aDatas[dMINWIDTH,2], /*PADDING hor*/, /*PADDING ver*/, NIL, ;
				aDatas[dICONLEFT,2], aDatas[dLABELLEFT,2], aDatas[dRIGHT,2], aDatas[dSCROLLOP,2],;
				/*click*/ )
		o:OnRClick := {|| RMenu(o) }
		o:OnChange := {|| SelectControl(o:aPages[o:Value])}	//Necesary to select page

   CASE cType == "TBUTTON"
		x := Hb_ASCAN(oWin:aControls, {|o| o:Type == "TOOLBAR"} )
		xTemp1 := oWin:aControls[x]
		If lNew
			aDatas[tbbPICTURE,2] := "ZZZ_AAAOOHG"
		Endif
      o := MyToolButton():Define( cName, 0, 0, ;
				Comillas(aDatas[tbbCAPTION,2]),;
				,,, GetPicture(aDatas[tbbPICTURE,2], "ZZZ_AAAOOHG"), ;	//ZZZ_AAAOOHG
            aDatas[tbbTOOLTIP,2],,, .f., aDatas[tbbSEPARATOR,2],;
				aDatas[tbbAUTOSIZE,2], aDatas[tbbCHECK,2], ;
            aDatas[tbbGROUP,2], aDatas[tbbDROPDOWN,2], aDatas[tbbWHOLEDROPDOWN,2], xTemp1 )
		
   CASE cType == "TEXTARRAY"	// OJO invertidos row y col
		If lNew
			w := NIL
			h := NIL
		Endif
      o := TTextArray():Define( cName, oWin, y, x,  w, h, ;
				aDatas[dROWCOUNT,2], aDatas[dCOLCOUNT,2], aDatas[dBORDER,2], aDatas[dCLIENTEDGE,2],;
				aDatas[dFONTCOLOR,2], aDatas[dBACKCOLOR,2], /*action}*/, aDatas[dFONT,2], aDatas[dSIZE,2], ;
				aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], aDatas[dTOOLTIP,2],;
				/*<helpid*/, /*invisible*/.F., aDatas[dRTL,2], /*value*/, /*notabstop*/.F., /*disabled*/.F., ;
            /*gotfocus*/, /*lostfocus*/ )
	
	CASE cType == "TEXTBOX"
		// Picture and InputMask is the same 
		If !EMPTY(aDatas[dPICTURE,2]) .AND. EMPTY(aDatas[dINPUTMASK,2])
			aDatas[dINPUTMASK,2] := Comillas(aDatas[dPICTURE,2])
		Endif
		// Subclassing for TextBox
*	   IF ValType( aDatas[dINPUTMASK,2] ) $ "CM"
			xTemp2 := MyTextPicture()
*		Else
*			xTemp2 := iif( aDatas[dNUMERIC,2], "MyTextNum", "MyText")
*		Endif

//db_Text("Textbox backcolor"+hb_Dumpvar(aDatas[dBACKCOLOR,2]))
      o := DefineTextBox( cName, oWin, y, x, w, h, NIL, aDatas[dFONT,2], ;
				aDatas[dSIZE,2], aDatas[dTOOLTIP,2], aDatas[dMAXLENGTH,2], ;
				aDatas[dUPPERCASE,2], aDatas[dLOWERCASE,2], aDatas[dPASSWORD,2], /*bLostFocus*/, /*bGotFocus*/, ;
				/*bChange*/, /*bEnter*/, aDatas[dRIGHTALIGN,2], /*nHelpId*/, ;
				/*aDatas[dREADONLY,2]*/, aDatas[dBOLD,2], aDatas[dITALIC,2], aDatas[dUNDERLINE,2], ;
				aDatas[dSTRIKEOUT,2], /*FIELD*/, ;
				aDatas[dBACKCOLOR,2], GetSysColor(aDatas[dFONTCOLOR,2]), .F., .F., aDatas[dRTL,2], aDatas[dAUTOSKIP,2], ;
				aDatas[dNOBORDER,2],aDatas[dFOCUSEDPOS,2], ;
				.F., NIL, aDatas[dDATE,2], aDatas[dNUMERIC,2], Comillas(aDatas[dINPUTMASK,2]), ;
				aDatas[dFORMAT,2], /*SUBCLASS*/ xTemp2, NIL, GetPicture(aDatas[dIMAGE,2], 'IDE_OOHG') , ;
				aDatas[dBUTTONWIDTH,2], NIL, NIL, aDatas[dCENTERALIGN,2], ;
				aDatas[dDEFAULTYEAR,2], NIL, aDatas[dINSERTTYPE,2], aDatas[dCTRLSATLEFT,2], /*lNoCntxtMnu*/.F., ;
				/*cTTipB1*/, /*cTTipB2*/, /*cCue*/  )

		If aDatas[dREADONLY,2]
			o:BackColor := GetSysColor(COLOR_3DFACE)
		Endif
		o:OnDblClick := {|| FastData(o, "FIELD")}

   CASE cType == "TIMEPICKER"
		If lNew
			aDatas[dWIDTH,2] := IF(EMPTY(aDatas[dWIDTH,2]), 100, aDatas[dWIDTH,2] )
			aDatas[dHEIGHT,2] := IF(EMPTY(aDatas[dHEIGHT,2]), 24, aDatas[dHEIGHT,2] )
		Endif
      o := MyTimePick():Define( cName, oWin, y, x, aDatas[dWIDTH,2], aDatas[dHEIGHT,2], NIL, aDatas[dFONT,2], ;
				aDatas[dSIZE,2], aDatas[dTOOLTIP,2], NIL, NIL, NIL, aDatas[dSHOWNONE,2], aDatas[dUPDOWN,2], ;
				aDatas[dRIGHTALIGN,2], NIL, .F., .F., aDatas[dBOLD,2], ;
				aDatas[dITALIC,2], aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], NIL, NIL, aDatas[dRTL,2], .F., ;
				aDatas[dNOBORDER,2], aDatas[dFORMAT,2],/*bValid*/ )

   CASE cType == "TIMER"
      o := TLabel():Define( cName, oWin, y, x, cName, 50, 20, ;
                  NIL, NIL, .F., .T., .F., ;
                  .F., .F., .F., WHITE, NIL, .T., aDatas[dTOOLTIP,2], NIL, .F., ;
                  .F., .F., .F., .F., .F., .F., .F., .F., .F., NIL, .F., .F. )

	CASE cType == "TOOLBAR"
		If lNew
			w := 50
			h := 50
			aDatas[tbBORDER,2] := .T.
			aDatas[tbFLAT,2] := .F.
		Endif
      o := MyToolBar():Define( cName, oWin, 0, 0, w, h, aDatas[tbCAPTION,2], ;
            /*aDatas[tbACTION,2]*/, aDatas[tbFONT,2], aDatas[tbSIZE,2], aDatas[tbTOOLTIP,2], aDatas[tbFLAT,2], ;
				aDatas[tbBOTTOM,2], aDatas[tbRIGHTTEXT,2], aDatas[tbBREAK,2], aDatas[tbBOLD,2], aDatas[tbITALIC,2], ;
				aDatas[tbUNDERLINE,2], aDatas[tbSTRIKEOUT,2], aDatas[tbBORDER,2], aDatas[tbRTL,2], aDatas[tbNOTABSTOP,2], ;
				aDatas[tbVERTICAL,2], aDatas[tbOWNTOOLTIP,2], /*aDatas[tbTOOLBARSIZE,2]*/ )
		o:OnRClick := {|| RMenu(o)}
		
	CASE cType == "TREE"
      o := MyTree():Define( cName, oWin, x, y, w, h, NIL /*change*/, ;
				aDatas[dTOOLTIP,2], aDatas[dFONT,2], aDatas[dSIZE,2], /*gotfocus*/, /*lostfocus*/, /*dblclick*/, ;
				.F./*break*/, /*value*/, /*helpid*/, /*aImgNode*/, /*aImgItem*/, aDatas[dNOROOTBUTTON,2], aDatas[dBOLD,2], aDatas[dITALIC,2],;
				aDatas[dUNDERLINE,2], aDatas[dSTRIKEOUT,2], .F. /*itemids*/, aDatas[dRTL,2], /*onenter*/, .F./*lDisabled*/,;
				.F./*invisible*/, .F./*notabstop*/, aDatas[dFONTCOLOR,2], aDatas[dBACKCOLOR,2], .F. /*FULLROWSELECT ??*/, ;
				aDatas[dCHECKBOXES,2], .T. /*EDITLABELS*/, aDatas[dNOHSCROLL,2], aDatas[dNOVSCROLL,2], aDatas[dHOTTRACK,2], aDatas[dNOLINES,2], ;
				aDatas[dNOBUTTONS,2], .T./*lDrag*/, aDatas[dSINGLEEXPAND,2], aDatas[dNOBORDER,2], StrToColor( aDatas[dSELCOLOR,2] ), ;
				.T./*labeledit*/, /*Valid*/, /*checkchange*/, aDatas[dINDENT,2], aDatas[dSELBOLD,2], .T./*lDrop*/, /*aTarget*/, /*ondrop*/,;
				/*lOwnToolTip*/, {|| .T.}/*bExpand*/, {|| .T.} /*bCollapse*/, /*lRedraw*/, /*bExpanded*/, /*bCollapsed*/ )

		If lNew
			o:AddItem( "NODE", ,'New Node', 0 )
		Endif
		
      END TREE
		o:OnMouseMove 	:= {|| SendMessage(oWin:hWnd, WM_MOUSEMOVE)}
		o:DragActive := .F.
		o:OnRClick := {|| RMenu(o)}
		
	OTHERWISE
		If cType == "IMAGECHECKBUTTON" .OR. cType == "IMAGEBUTTON"
			MsgBox( cType+" no existe en realidad dentro de OOHG"+HB_EOL()+;
					"Puede usar un Botton o CheckButton con imagen o "+HB_Eol()+;
					"Puede usar una Imagen con Action ", "dSign")
		Else
			MsgBox("Control "+cType+" aún no implementado","Aviso")
		Endif
		Return NIL
	END CASE

	// Add Name to Tooltip
	If __objHasData( o, "TOOLTIP" ) 
		o:ToolTip := "["+ aDatas[NAME,2] +"]  "+ IF(!HB_IsSTRING(o:ToolTip),"", o:ToolTip)
	Endif
		
	If LEN(aDatas) > 100		// Temporal mientras se asignan aDatas a controles
		aDatas[dWIDTH,2] := ''
		aDatas[dHEIGHT,2] := ''
		If !(cType $ "GRID XBROWSE BROWSE")
			aDatas[dHEADERS,2] := ''
			aDatas[dWIDTHS,2] := ''
			aDatas[dWORKAREA,2] := ''
		Endif
		If cType <> "RADIOGROUP"
			aDatas[dOPTIONS,2] := ""
		Endif

	Endif
	
	// Setup oControl cargo
   x := ASCAN(oWin:aControlsNames, Upper( AllTrim( cName ) ) + Chr( 255 ))
	o:Cargo := {cType, 0, .F., .F., x, .F. }	// Control Type, Position in GRID mControl, lSelected, lMoved, Tab position, lGet}	
	o:cAfter := IF(cAfter = NIL, ""+hb_eol(), cAfter)
	o:aDatas := aDatas
	
Return o

*-----------------------------------------------------------------------------*
// OJO Se debe destruir este menú ANTES de crear o borrar controles
// de lo contrario quedan mal los indices de TABINDEX
Procedure RMenu(o)
Local oMenu, oWin := oMain:Cargo
	POSITION := {,}		// Avoids control movement if clicked outside of menu
	If o:Cargo[cTYPE] == "TAB"
		DEFINE CONTEXT MENU OF (oWin) OBJ oMenu
			ITEM "&Add Page"	ACTION {|| AddTabPage(o), o:Value := LEN(o:aPages) }
			ITEM "&Delete Page"	ACTION {|| If( MsgYesNo( "This will delete all controls on this page."+CRLF+;
																			 "             Continue?", o:aPages[o:Value]:Caption), ;
															o:DeletePage(o:Value),)  }
		END MENU
	ELSEIf o:Cargo[cTYPE] == "TOOLBAR" 
		DEFINE CONTEXT MENU OF (oWin) OBJ oMenu
			ITEM "&Agregar Button"	ACTION {|| oCtrlBox:Cargo := "TBUTTON", NewControl(oWin)}
		END MENU

	ELSEIf o:Cargo[cTYPE] == "TREE"
		DEFINE CONTEXT MENU OF (oWin) OBJ oMenu
			ITEM "Value"	ACTION {||  o:Value := 0}
			ITEM "Add &Node"	ACTION {|| o:AddItem( "NODE", ,'New Node', o:Value ), o:Refresh()}
			ITEM "Add &Tree Item"	ACTION {|| o:AddItem( "TREEITEM",,'New Item', o:Value ), o:Refresh()}
			ITEM "&Delete"	ACTION {|| o:DeleteItem(o:Value)}
		END MENU
	Endif

	If hb_isObject(oMenu)
		oMenu:Activate()
		// Do events before releasing menu
		Do events
		oMenu:Release()
	Endif
Return //oMenu

/************************************************************************************
SubClassing
************************************************************************************/
Function MyEvents( hWnd, nMsg, wParam, lParam )		// Control events
Local Self := qSelf(), oCtrl, oWin := Self:Parent, nRet
//Local Hi_wParam := HIWORD( wParam  )

If ::Type == "TREE"
//	db_Text(::DebugMessageName(nMsg))
Endif
	IF nMsg = WM_LBUTTONDOWN
		If ONGROW
			Return 0
		Endif
		nRet := ::Super:Events( hWnd, nMsg, wParam, lParam )
		If ::Type $ "FRAME" .AND. hb_IsObject( oCtrl := CheckForControl(::Parent))
			SelectControl( oCtrl )
		ElseIf ::Type == "RADIOITEM"
			SelectControl(::Container)
		Else
			SelectControl(Self)
		Endif
*		If ::Type == "TREE"
*			Return ::Super:Events( hWnd, nMsg, wParam, lParam )
*		Else
*			Return 0 
*		Endif
		Return nRet

	ElseIF nMsg = WM_LBUTTONUP
		nRet := ::Super:Events( hWnd, nMsg, wParam, lParam )
		wLButtonUp(oWin)
		Return nRet

	ElseIF nMsg = WM_MOUSEMOVE
		If wParam = MK_LBUTTON
			If !mDrag(oWin)
				// if we are not draging controls we are making a selection box
				Selecting(oWin)	//, aPt[1], aPt[2])
			Endif
			Return 0
		ElseIf MouseMove(oWin)
			Return 0
		Endif

	ElseIf nMsg == WM_RBUTTONDOWN

	ElseIf nMsg == WM_RBUTTONUP
		If hb_IsBlock(::OnRClick)
			EVAL(::OnRClick, Self)
		Endif
		Return 0

	ElseIf nMsg = WM_LBUTTONDBLCLK
		If ::Type $ "FRAME" .AND. hb_IsObject( oCtrl := CheckForControl(::Parent))
			If Hb_IsBlock(oCtrl:OnDblClick)
				EVAL(oCtrl:OnDblClick, oCtrl)
			Endif
		ElseIf hb_IsBlock(::OnDblClick)
			EVAL(::OnDblClick, Self)
		Endif
		Return 1
	Endif
Return ::Super:Events( hWnd, nMsg, wParam, lParam )

*-----------------------------------------------------------------------------*
CLASS MyForm FROM TForm
	METHOD Events(hWnd, nMsg, wParam, lParam)
END CLASS

METHOD Events(hWnd, nMsg, wParam, lParam) CLASS MyForM
Local oWin := Self, oCtrl	//, aChildWindows	//, nRet

	If nMsg = WM_SETFOCUS
		If Hb_IsObject(oMain:Cargo) .AND. oMain:Cargo:hWnd <> oWin:hWnd
			oMain:Cargo := oWin
			UpdateWControls(oWin)
		Endif

	ElseIf nMsg = WM_LBUTTONDOWN
		If ONGROW
			
		ElseIf hb_IsObject( oCtrl := CheckForControl(oWin))
			SelectControl( oCtrl )
		Else 
			MouseClick(Self)
		Endif
		Return 0

	ElseIf nMsg = WM_LBUTTONUP //.AND. MOVING
		wLButtonUp( Self)
		Return 0

	ElseIF nMsg = WM_MOUSEMOVE
		If wParam = MK_LBUTTON
			If !mDrag(oWin)
				Selecting(Self)
			Endif
		Else
			MouseMove(Self)
		Endif
		Return 0

   elseif nMsg == WM_MOVE
   elseif nMsg == WM_SIZE
*		If MsgYesNo("Desea establecer nuevas coordenadas a la ventana?")
			
	ElseIf nMsg = WM_ACTIVATE
*		If LoWord(wParam) = 2	//WM_CLICKACTIVE
*			If Hb_IsObject(oMain:Cargo) .AND. oMain:Cargo:hWnd <> oWin:hWnd
*				oMain:Cargo := oWin
*				UpdateWControls(oWin)
*			Endif
*		Endif

	Elseif nMsg == WM_RBUTTONUP
	db_text("oWin RButton")
	Endif
Return ::Super:Events( hWnd, nMsg, wParam, lParam )

*-----------------------------------------------------------------------------*
CLASS MyAnimateBox FROM TAnimateBox
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyButton FROM TBUTTON
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyCheckButton FROM TBUTTONCheck
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyCheckList FROM TCheckList
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyCombo FROM TCombo
	MESSAGE Events EXTERN MyEvents
	METHOD SetTransparency	BLOCK { |Self| ::Enabled := .F.  } 
	METHOD RemoveTransparency	BLOCK { |Self| ::Enabled := .T.  } 
ENDCLASS
//GetWindow( ::hWnd, GW_CHILD )
*-----------------------------------------------------------------------------*
CLASS MyCheckBox FROM TCheckbox
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyCombobox FROM TCombo
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyDatePicker FROM TDatePick
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyEdit FROM TEdit
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyFrame FROM TFrame
	MESSAGE Events EXTERN MyEvents
ENDCLASS


*-----------------------------------------------------------------------------*
CLASS MyGrid FROM TGrid
//   DATA lUpdateAll                INIT .F.	// From Browse
	// From Grid
*   DATA caHeadColor					INIT {}
*   DATA caHeadBkColor				INIT {}
   DATA caOnHeadClick				INIT {}
   DATA caOnHeadDblClick			INIT {}
   DATA caHeaderImage				INIT {}
   DATA caHeaderImageAlign		INIT {}
   DATA caDynamicBackColor		INIT {}
   DATA caDynamicForeColor		INIT {}
	// From xBrowse
   DATA caColumnBlocks			INIT {}
   DATA caDefaultValues			INIT {}
   DATA caFields						INIT {}
   DATA caReplaceField			INIT {}
   DATA caWhen						INIT {}
   DATA caValid						INIT {}
	
	METHOD AddColumn(nColumn, ...)
	METHOD DeleteColumn(nColIndex, lNoDelete)
	METHOD ColumnSwap(nFrom, nTo)
	METHOD MyUpdate
	MESSAGE Events EXTERN MyEvents
ENDCLASS


METHOD Procedure AddColumn(nColumn, ...) CLASS MyGrid
	::Super:AddColumn(nColumn, ...)
*	hb_aIns(::caHeadColor, 			nColumn, , .T.)
*	hb_aIns(::caHeadBkColor,	 		nColumn, , .T.)
	hb_aIns(::caOnHeadClick, 		nColumn, , .T.)
	hb_aIns(::caOnHeadDblClick, 	nColumn, , .T.)
	hb_aIns(::caHeaderImage, 		nColumn, , .T.)
	hb_aIns(::caHeaderImageAlign, 	nColumn, , .T.)
	hb_aIns(::caDynamicBackColor, 	nColumn, , .T.)
	hb_aIns(::caDynamicForeColor, 	nColumn, , .T.)
	hb_aIns(::caColumnBlocks, 		nColumn, , .T.)
//	If ::TYPE <> "GRID"
*	If ::Cargo[1] == "XBROWSE" .OR. ::Cargo[1] == "BROWSE"
		hb_aIns(::caDefaultValues, 	nColumn, , .T.)
		hb_aIns(::caFields,				nColumn, , .T.)
		hb_aIns(::caReplaceField,	nColumn, , .T.)
*	Endif
	hb_aIns(::caWhen, 					nColumn, , .T.)
	hb_aIns(::caValid, 					nColumn, , .T.)
*	::ReadOnly[nColumn] := .F.
Return

METHOD Procedure DeleteColumn(nColIndex, lNoDelete) CLASS MyGrid
	::Super:DeleteColumn(nColIndex, lNoDelete)
*	Hb_aDel(::caHeadColor, 				nColIndex, .T.)
*	Hb_aDel(::caHeadBkColor, 			nColIndex, .T.)
	Hb_aDel(::caOnHeadClick, 			nColIndex, .T.)
	Hb_aDel(::caOnHeadDblClick, 		nColIndex, .T.)
	Hb_aDel(::caHeaderImage, 			nColIndex, .T.)
	Hb_aDel(::caHeaderImageAlign, 	nColIndex, .T.)
	Hb_aDel(::caDynamicBackColor, 	nColIndex, .T.)
	Hb_aDel(::caDynamicForeColor, 	nColIndex, .T.)
	Hb_aDel(::caColumnBlocks, 			nColIndex, .T.)
*	If ::TYPE <> "GRID"
		Hb_aDel(::caDefaultValues, 	nColIndex, .T.)
		Hb_aDel(::caFields, 				nColIndex, .T.)
		Hb_aDel(::caReplaceField, 		nColIndex, .T.)
*	Endif
	Hb_aDel(::caWhen, 					nColIndex, .T.)
	Hb_aDel(::caValid, 					nColIndex, .T.)
Return

METHOD Function ColumnSwap(nFrom, nTo) CLASS MyGrid
//msgbox(hb_Dumpvar({nFrom, nTo}, .t.))
	If nTo <> nFrom .AND. (nTo >= 1 .OR. nTo <= LEN(::aHeaders))
		If nTo < nFrom
		::AddColumn( nTo, ::aHeaders[nFrom], ::aWidths[nFrom], ::aJust[nFrom], /*uForeColor*/, /*uBackColor*/, ;
							/*lNoDelete*/, ::Picture[nFrom], /*uEditControl*/, /*uHeadClick*/, /*uValid*/, ;
							/*uValidMessage, uWhen, nHeaderImage, nHeaderImageAlign, ;
							uReadonly, cColType, uHeadDblClick*/ )
			nFrom +=1
		Else
		::AddColumn( ++nTo, ::aHeaders[nFrom], ::aWidths[nFrom], ::aJust[nFrom], /*uForeColor*/, /*uBackColor*/, ;
							/*lNoDelete*/, ::Picture[nFrom], /*uEditControl*/, /*uHeadClick*/, /*uValid*/, ;
							/*uValidMessage, uWhen, nHeaderImage, nHeaderImageAlign, ;
							uReadonly, cColType, uHeadDblClick*/ )
			
		Endif
		Swap(::caColumnBlocks, 		nFrom, nTo)
		Swap(::caDefaultValues, 		nFrom, nTo)
		Swap(::caDynamicBackColor, 	nFrom, nTo)
		Swap(::caDynamicForeColor, 	nFrom, nTo)
		Swap(::caFields,					nFrom, nTo)
*		Swap(::caHeadColor,		 		nFrom, nTo)
*		Swap(::aHeaderColors,		 	nFrom, nTo)
//msgbox(hb_dumpvar(LEN(::caHeadBKColor)))
*		Swap(::caHeadBKColor,	 		nFrom, nTo)
		Swap(::caOnHeadClick, 		nFrom, nTo)
		Swap(::caOnHeadDblClick, 	nFrom, nTo)
		Swap(::caValid, 					nFrom, nTo)
		Swap(::caWhen, 					nFrom, nTo)

		Swap(::aHeaderImage, 			nFrom, nTo)
		Swap(::caHeaderImage, 		nFrom, nTo)
		Swap(::caHeaderImageAlign, 	nFrom, nTo)
*		Swap(::aHeaders, 				nFrom, nTo)
*		Swap(::Picture, 					nFrom, nTo)
*		Swap(::aJust, 					nFrom, nTo)
		Swap(::ReadOnly, 				nFrom, nTo)
		Swap(::caReplaceField, 		nFrom, nTo)
*		Swap(::aWidths, 					nFrom, nTo)
		Swap(::ColType, 					nFrom, nTo)

		Swap(::aHeadClick, 				nFrom, nTo)
		Swap(::aHeadDblClick, 		nFrom, nTo)
*		If ::Cargo[1] == "XBROWSE" .OR. ::Cargo[1] == "BROWSE"
*		Endif
		::DeleteColumn( nFrom )

		ControlProperties(Self)
	Endif
						
Return .F.	


METHOD Procedure MyUpdate(what, nIndex, xToWhat) CLASS MyGrid
Local cData
	If nIndex > 0 .and. nIndex <= LEN(::aHeaders)
		cData := __ObjSendMsg(Self, what)
		cData[nIndex] := xToWhat
		If what == "aWidhts"
			LISTVIEW_SETCOLUMNWIDTH(::hWnd, nIndex-1, VAL(xToWhat))
		ElseIf what == "aJust"
			SETGRIDCOLUMNJUSTIFY(::hWnd, nIndex, VAL(xToWhat))
		Endif
	Endif
Return	

*-----------------------------------------------------------------------------*
CLASS MyHotKeyBox FROM THotKeyBox
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyHyperlink FROM THyperlink
	Data Address
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyImage FROM TImage
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyIpAddress FROM TIpAddress
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyLabel FROM TLabel
// Labels will only send the first WM_LBUTTONDOWN when transparent
*	Data nTransparent INIT 255
	MESSAGE Events EXTERN MyEvents
	MESSAGE SetTransparency() INLINE ::Super:SetTransparency(170)
*	MESSAGE RemoveTransparency	INLINE ::SetTransparency(::nTransparent)
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyList FROM TList
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyListMulti FROM TListMulti
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyMonthCal FROM TMonthCal
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyMultiMonthCal FROM TMonthCalMulti
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyPicture FROM TPicture
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyPlayer FROM TPlayer
	MESSAGE Events INLINE tone(2000,2)	//EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyProgressBar FROM TProgressBar
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyRadioGroup FROM TRadioGroup
	MESSAGE Events EXTERN MyEvents
	METHOD SetTransparency(n)		
	METHOD RemoveTransparency()	BLOCK {|Self| aEVAL(::aOptions, {|o| o:RemoveTransparency()})}
ENDCLASS

METHOD SetTransparency(n)
	AEVAL(::aOptions, {|o| o:SetTransparency(n)})
Return NIL
*-----------------------------------------------------------------------------*
CLASS MyRichEditBox FROM TEditRich
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyScrollbar FROM TSCROLLBAR
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MySlider FROM TSLIDER
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MySplitBox FROM TSplitBox
	Data MyItems	INIT {}
	METHOD AddControl(o)   INLINE AADD(::MyItems, o), ::Super:AddControl(o)
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MySpinner FROM TSpinner
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyStatusBar FROM TMessageBar
	Data MyItems		INIT {}
	METHOD MyAddItem( aItems )
	METHOD Update
	METHOD Delete(n) INLINE If(n>0 .AND. n <= LEN(::MyItems), (hb_aDel(::MyItems, n, .T.), .T.), .F.)
//	METHOD Item			BLOCK  {|Self, nItem, cValue| ::aItems[nItem, 1] := cValue, ::Super:Item(nItem, cValue) }
	METHOD Events(hWnd, nMsg, wParam, lParam)	
ENDCLASS

METHOD EVENTS(hWnd, nMsg, wParam, lParam) CLASS MyStatusBar
	IF nMsg = WM_LBUTTONDOWN
		ReleaseControls(::Parent)
		SelectControl(Self)
	
	ElseIf nMsg == WM_RBUTTONUP
		If HB_IsBlock(::OnRClick)
			EVAL(::OnRClick, Self)
		Endif
	Endif
Return ::Super:Events( hWnd, nMsg, wParam, lParam )

METHOD Procedure MyAddItem( aItems ) CLASS MyStatusBar
	IF LEN(aItems) <> 8
//		aItems := {"",,,"","","",, .F. }	//Caption, Width, action, ToolTip, icon, Style, Align, lDefault
		ASIZE(aItems, 8)
	Endif
	DEFAULT aItems[1] TO ''
	DEFAULT aItems[4] TO ''
	DEFAULT aItems[5] TO ''
	DEFAULT aItems[6] TO ''
	DEFAULT aItems[8] TO .F.
	If aItems[1] = "CLOCK"
//		SetClock( Width, ToolTip, action, lAmPm, icon, cstyl, cAlign )
		::Super:SetClock( aItems[2], aItems[4], /*uAction*/, /*lAmPm*/, aItems[5], aItems[6], aItems[7] )				
*		::aDatas[stCLOCK] := .T.
	ElseIf aItems[1] = "KEYBOARD"
//		SetKeybrd( nSize, cToolTip, uAction, icon, cstyl, cAlign )
		::Super:SetKeybrd( aItems[2], aItems[4], /*uAction*/, aItems[5], aItems[6], aItems[7] )
*		::aDatas[stKEYBOARD] := .T.
	ElseIf aItems[1] = "DATE"
//		SetDate( Width, ToolTip, action, icon, cstyl, cAlign )
		::Super:SetDate( Dtoc( Date() ), aItems[2], aItems[4], /*uAction*/, aItems[5], aItems[6], aItems[7] )
*		::aDatas[stDATE] := .T.
	Else
		::Super:AddItem( 	aItems[1],;
								aItems[2],;	// WIDTH
								/*aItems[3]*/,;	// Action
								aItems[4],;	// Tooltip
								aItems[5],;	// Icon
								aItems[6],;	// Style
								aItems[7],;	// Align
								aItems[8])	// lDefault
	Endif
	AADD(::MyItems, ACLONE(aItems))
Return 

METHOD Update(nItem, nValue, xValue) CLASS MyStatusBar
Local xOldValue, lRet := .F.
	If nItem > 0 .and. nItem <= LEN(::MyItems)
		xOldValue := ::MyItems[nItem, nValue]
		::MyItems[nItem, nValue] := xValue
		lRet := (xOldValue <> xValue)
		If lRet 
			If nValue = 1;     ::Item(nItem, xValue)
			ElseIf nValue = 2; ::ItemWidth(nItem, xValue)
			ElseIf nValue = 3
			ElseIf nValue = 4
			ElseIf nValue = 5; ::ItemToolTip(nItem, xValue)
			ElseIf nValue = 7; ::Item( nItem, ::MyItems[nItem,1], xValue )
			Else
				RecreateControl(Self)
			Endif
		Endif
	Endif
Return lRet

*-----------------------------------------------------------------------------*
CLASS MyTab FROM TTabMulti
	METHOD Events( hWnd, nMsg, wParam, lParam )
*	METHOD Events_Notify( wParam, lParam)	
	METHOD RemoveTransparency	BLOCK { |Self| ::Super:RemoveTransparency(), ::Refresh()  } 
ENDCLASS

METHOD Events( hWnd, nMsg, wParam, lParam ) CLASS MyTab
// never gets here
Return ::Super:Events( hWnd, nMsg, wParam, lParam )
/*
METHOD Events_Notify( wParam, lParam)	CLASS MyTab
LOCAL nNotify := GetNotifyCode( lParam )
	   IF nNotify == TCN_SELCHANGE
tone(2000,3)
Endif
Return ::Super:Events_Notify( wParam, lParam )
*/
*-----------------------------------------------------------------------------*
/*CLASS MyTabPage FROM TTabPage
*	METHOD CAPTION(cCaption) INLINE  ::Container:Caption(::Container:Value, cCaption)
*	MESSAGE Events EXTERN MyEvents
ENDCLASS

Procedure MyTabPage(o)
	__objModMethod(o, "CAPTION", {|...| db_Text(hb_dumpvar(hb_aParams()))})	//::Container:Caption(::Container:Value, cCaption)})
Return
*/
*-----------------------------------------------------------------------------*
CLASS MyText FROM TText
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyTextPicture FROM TTextPicture
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyTextNum FROM TTextNum
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyTimePick FROM TTimePick
	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyToolbar FROM TToolbar
	METHOD Events //EXTERN MyEvents
	METHOD DeleteButton( nButtonIndex ) 
	METHOD Events_Command( wParam  )
ENDCLASS

METHOD Events(hWnd, nMsg, wParam, lParam) CLASS MyToolBar
	If nMsg = WM_LBUTTONDOWN
		ReleaseControls(::Parent)
		SelectControl( Self )
	Endif
Return ::Super:Events(hWnd, nMsg, wParam, lParam)

METHOD DeleteButton( nButtonIndex ) CLASS MyToolBar
Local lRet := .F.
	If ::Super:DeleteButton( nButtonIndex )
		lRet := .T.
		AEVAL(::aControls, {|o| o:Position --}, nButtonIndex)
	Endif
Return lRet	

METHOD Events_Command( wParam  ) CLASS MyToolbar

   Local Hi_wParam := HIWORD( wParam  )
   Local oControl

   If Hi_wParam == BN_CLICKED
      oControl := GetControlObjectById( LOWORD( wParam  ), ::Parent:hWnd )
		ReleaseControls(::Parent)
		SelectControl( oControl )
      Return 1
   EndIf

   Return ::Super:Events_Command( wParam  )

*-----------------------------------------------------------------------------*
CLASS MyToolButton FROM TToolButton
*	MESSAGE Events EXTERN MyEvents
ENDCLASS

*-----------------------------------------------------------------------------*
CLASS MyTree FROM TTree
	Data aNode			INIT {}
	Data aBefore		INIT {}
	Data aAsignId		INIT {}
	Data aBold			INIT {}
	Data aChecked		INIT {}
	Data aId				INIT {}
	Data aImages		INIT {}
	Data aText			INIT {}
	Data aEndNode		INIT {}
	Data aAfter			INIT {}
	
	MESSAGE Events EXTERN MyEvents
*	METHOD Events_Notify BLOCK {|| .F.}
	METHOD AddItem( cType, cAfter, text, aImage, Id, lChecked, lReadOnly, lBold, lDisabled, lNoDrag, lAssignID )
	METHOD EndNode	
ENDCLASS

METHOD PROCEDURE AddItem( cType, cAfter, text, aImage, Id, lChecked, lReadOnly, lBold, lDisabled, lNoDrag, lAssignID ) CLASS MyTree
	AADD(::aAsignId, lAssignID)
	AADD(::aBold, lBold)
	AADD(::aChecked, lChecked)
	AADD(::aId, id)
	AADD(::aImages, aImage)
	AADD(::aText, text)
	AADD(::aBefore, cAfter)
	AADD(::aEndNode, .F.)
	AADD(::aAfter, )
	If cType == "NODE"
		_DefineTreeNode( text, aImage, Id, lChecked, lReadOnly, lBold, lDisabled, lNoDrag, lAssignID )
		AADD(::aNode, .T.)
	Else
		_DefineTreeItem( text, aImage, Id, lChecked, lReadOnly, lBold, lDisabled, lNoDrag, lAssignID )
		AADD(::aNode, .F.)
	Endif
Return

METHOD PROCEDURE EndNode(cBefore) CLASS MyTree
	If ATAIL(::aEndNode)
		AADD(::aEndNode, .T.)
		AADD(::aBefore, cBefore)
	Else
		::aEndNode[LEN(::aEndNode)] := .T.
		::aAfter[LEN(::aEndNode)] := cBefore
	Endif
Return


/************************************************************************************
End SubClassing
************************************************************************************/
Procedure FontChange(oWin)
Local aFont, oCtrl, n
	If !EMPTY(aSELECTED)
		oCtrl := aSELECTED[1]
	Else
		oCtrl := oWin
	Endif
	If oCtrl:Type $ "SLIDER"
		Return
	Endif
// GetFont( cInitFontName, nInitFontSize, lBold, lItalic, anInitColor, lUnderLine, lStrikeOut, nCharset )
	aFont := GetFont(oCtrl:cFontName, oCtrl:nFontSize, oCtrl:Bold, oCtrl:Italic, ;
			oCtrl:FontColor, oCtrl:Underline, oCtrl:StrikeOut, oCtrl:FntCharset)
  If !EMPTY(aFont[1])
		If oCtrl:Cargo[1] == "WINDOW"
			oCtrl:ParentDefaults(aFont[1], aFont[2], aFont[5])
			PutaDatas("FONT", aFont[1], oCtrl:aDatas)
			PutaDatas("SIZE", aFont[2], oCtrl:aDatas)
*			PutaDatas("BOLD", aFont[3], oCtrl:aDatas)
*			PutaDatas("ITALIC", aFont[4], oCtrl:aDatas)
			PutaDatas("FONTCOLOR", aFont[5], oCtrl:aDatas)
*			PutaDatas("UNDERLINE", aFont[6], oCtrl:aDatas)
*			PutaDatas("STRIKEOUT", aFont[7], oCtrl:aDatas)
			oCtrl:ParentDefaults( aFont[1], aFont[2], aFont[5])
			UpdateFonts(oCtrl)
		Else
			For n := 1 TO LEN(aSELECTED)
				oCtrl := aSELECTED[n]
				oCtrl:SetFont( aFont[1], aFont[2], aFont[3], aFont[4], aFont[6], aFont[7] )
				oCtrl:FontColor := aFont[5]
				PutaDatas("FONT", aFont[1], oCtrl:aDatas)
				PutaDatas("SIZE", aFont[2], oCtrl:aDatas)
				PutaDatas("BOLD", aFont[3], oCtrl:aDatas)
				PutaDatas("ITALIC", aFont[4], oCtrl:aDatas)
				PutaDatas("FONTCOLOR", aFont[5], oCtrl:aDatas)
				If oCtrl:Type $ "HYPERLINK"
				Else
					PutaDatas("UNDERLINE", aFont[6], oCtrl:aDatas)
					PutaDatas("STRIKEOUT", aFont[7], oCtrl:aDatas)
				Endif
	//			PutaDatas("nCharSet", aFont[8], oCtrl:aDatas)
			Next
		Endif
	Endif
Return

Procedure UpdateFonts(oWin)
Local oCtrl
	For Each oCtrl IN oMain:Cargo:aControls
		If __OBJHASDATA(oCtrl, "CFONTNAME") .AND. __OBJHASDATA(oCtrl, "aDatas") ;
			.AND. LEN(oCtrl:aDatas) > dFONT //.AND. EMPTY(oCtrl:aDatas[dFONT,2]) 


				oCtrl:FontColor := IF( EMPTY(oCtrl:aDatas[dFONTCOLOR,2]), oWin:FontColor, oCtrl:FontColor)
				oCtrl:SetFont( If( EMPTY(oCtrl:aDatas[dFONT,2]), oWin:cFontName,),;
									If( EMPTY(oCtrl:aDatas[dSIZE,2]), oWin:nFontSize,),;
									oCtrl:Bold, oCtrl:Italic, ;
									oCtrl:Underline, oCtrl:Strikeout,oCtrl:FntAngle, ;
									oCtrl:FntCharset, oCtrl:FntWidth, ;
									oCtrl:FntOrientation, oCtrl:FntAdvancedGM)
		Endif
	Next
Return


*-----------------------------------------------------------------------------*
Function ValidControlProperty(oCtrl, n, uValue)
Local lRet := .T., aDatas := oCtrl:aDatas
	If n = NAME
		If " " $ uValue
			MsgStop("Control Name can'nt have spaces", "dSign")
			lRet := .F.
		ElseIf LEN(uValue) = 0 .AND. oCtrl:Cargo[cTYPE] == "WINDOW"
			uValue := "TEMPLATE"
		Else
			uValue := UPPER(uValue)
		Endif
	Endif
	If  oCtrl:Cargo[cTYPE] == "FRAME" .AND. aDatas[dOPAQUE,2] .AND. aDatas[dTRANSPARENT,2]
		lRet := .F.
		MsgStop("OPAQUE and TRANSPARENT clauses can not be used simultaneously", "dSign")
	Endif
	If  oCtrl:Cargo[cTYPE] == "TEXTBOX"
		If aDatas[dNUMERIC,2] .AND. aDatas[dDATE,2]
			lRet := .F.
			MsgStop("TEXTBOX cant´nt be NUMERIC and DATE simultaneously", "dSign")
		Endif
	Endif
	If  oCtrl:Cargo[cTYPE] == "COMBOBOX"
		If aDatas[dSORT,2] .AND. aDatas[dDELAYEDLOAD,2]
			lRet := .F.
			MsgStop("COMBOBOX cant´nt be SORT and DELAYEDLOAD simultaneously", "dSign")
		Endif
	Endif
Return lRet

*-----------------------------------------------------------------------------*
Procedure ChangeProperty(o, n, uValue)
Local aDatas := o:aDatas, oWin, Type := o:Cargo[cTYPE], nPos, oTab, oPage
	o:aDatas[n,2] := uValue                          // Save value in Control:aDatas
	If Type == "WINDOW"
		oWin := o
	Else
		oWin := o:Parent
	Endif
*	If o:Type == "TOOLBUTTON"
*		If n = NAME .OR. n <> tbbSUBCLASS 
*		ElseIf n = tbbPICTURE
*			__objSendMsg( o, aDatas[n,1], aDatas[n,2] )
*		Else
*			RecreateControl(o)
*		Endif
	MODIFIED := .T.
	If Type == "PAGE"
		If o:aDatas[n,3] = 0
			
		Elseif n = tpCAPTION
//db_Text({aDatas[n,1], aDatas[n,2]})
//			__objSendMsg( o, aDatas[n,1], aDatas[n,2] )
			o:Container:Caption( o:Container:Value, o:aDatas[n,2])
		ElseIf n = tpPOSITION
			oTab := o:Container
			nPos := oTab:Value
			uValue := VAL(uValue)
//db_Text(hb_dumpvar({uValue,o:Container:aPages}))
			If uValue <= LEN(oTab:aPages) .AND. uValue <> nPos
				oPage := oTab:aPages[nPos]
				AEVAL(oTab:aPages, {|x, y| oTab:HidePage(y), x})
				hb_aDel(oTab:aPages, nPos, .T.)
				hb_aIns(oTab:aPages, uValue, oPage, .T.)
				AEVAL(oTab:aPages, {|x, y| oTab:ShowPage(y),x:aDatas[tpPOSITION,2] := y})
			Endif
			oTab:Value := uValue
			oTab:Refresh()
		Endif
	Else	// Actualizar control con valor capturado
		If n = dOOHGDRAW
			PutaDatas("OOHGDRAW", (uValue = "OOHGDRAW"), aDatas)
			PutaDatas("WINDRAW", (uValue = "WINDRAW"), aDatas)
		Endif
		// If uppercase, set lowercase to .F. and viceversa
		If n = dUPPERCASE .AND. uValue 
			aDatas[dLOWERCASE,2] := .F.
		Endif
		If n = dLOWERCASE .AND. uValue
			aDatas[dUPPERCASE,2] := .F.
		Endif
		
		If LEN(aDatas[n]) > 2
			// This is for parameters that may be arrays
			If aDatas[n,1] $ "ITEMS OPTIONS"
				If LEFT(aDatas[n,2],1) = '{' .AND. LEFT(aDatas[n,2],2) <> "{|"
					// Make it Array
					aDatas[n,2] := &(aDatas[n,2])
				ElseIf o:Type == "RADIOGROUP"
					aDatas[n,3] := 2
				Endif
			Endif
			// Changing style does not work when label is on tabpage. Must recreate control
*			If aDatas[n,1] == "TRANSPARENT"
*				ChangeControlStyle(o, WS_EX_TRANSPARENT, aDatas[n,2])
*				automsgbox(aDatas[n,2])
*			Endif
			If aDatas[n,3] = 1			// Direct asign
				If aDatas[n,1] $ "BOLD SIZE ITALIC UNDERLINE STRIKEOUT"
					If Type == "WINDOW"		// change all control none defined fonts 
						o:ParentDefaults( aDatas[wFONT,2], aDatas[wFONTSIZE,2], aDatas[wFONTCOLOR,2])
						UpdateFonts(o)
					Else
						__ObjSendMsg(o, "FONT"+aDatas[n,1], aDatas[n,2])
					Endif

				ElseIf Type == "WINDOWS" .AND. n = wTITLE
					o:aDatas[wTITLE,2] := uValue
					o:Title := uValue +  "     ("+oWin:cFileName+")"

				ElseIf Type == "COMBOBOX" .AND. n = dMAXLENGTH
					o:aDatas[dDISPLAYEDIT,2] := .T.
					o:aDatas[dMAXLENGTH,2] := uValue
					
*				ElseIf Type == "FRAME" .AND. n = dOPAQUE .OR. n = dTRANSPARENT
*					RecreateControl(o)

				ElseIf aDatas[n,1] == "TOOLTIP"
					__ObjSendMsg(o, aDatas[n,1], "["+ aDatas[NAME,2] +"]  "+aDatas[n,2])

				ElseIf aDatas[n,1] == "INPUTMASK" .and. Type == "TEXTBOX"
					o:Picture( aDatas[n,2], )

				ElseIf aDatas[n,1] == "INPUTMASK" .and. Type == "LABEL"
					o:Picture :=  aDatas[n,2]

				ElseIf Type == "HYPERLINK" .and. aDatas[n,1] == "VALUE"
					__ObjSendMsg(o, "CAPTION", Comillas(aDatas[n,2]))

				ElseIf aDatas[n,1] $ "VALUE CAPTION"
					If Type $ "GRID BROWSE XBROWSE"
						__ObjSendMsg(o, aDatas[n,1], aDatas[n,2])
					Else	
						__ObjSendMsg(o, aDatas[n,1], Comillas(aDatas[n,2]))
					Endif
				ElseIf aDatas[n,1] == "HEADERCOLORS"
					If hb_At("|", aDatas[n,2]) = 0	// not codeblock
						If LEFT(aDatas[n,2],1) = "{"	// array
							aDatas[n,2] := &(aDatas[n,2])
						Else
							aDatas[n,2] := StrToColor(aDatas[n,2])
						Endif
						IF HB_ISARRAY( aDatas[n,2] )
							ASize( aDatas[n,2], Len( o:aHeaders ) )
							o:aHeaderColors := aDatas[n,2]
							o:ReDraw()
						Endif
					Endif

				ElseIf hb_IsChar(aDatas[n,2])
					__ObjSendMsg(o, aDatas[n,1], Comillas(aDatas[n,2]))
				Else
					__ObjSendMsg(o, aDatas[n,1], aDatas[n,2])
				Endif

			ElseIf aDatas[n,3] = 2	// Recreate control
				RecreateControl(o)

*			ElseIf aDatas[n,1] $ "VALUE"	// Can be string or numeric or logical (checkbox)
*				IF VALTYPE(__ObjSendMsg(o, aDatas[n,1])) = "N" .AND. TYPE(aDatas[n,2]) == "N"
*					aDatas[n,2] := VAL(aDatas[n,2])
*				Endif
			Endif
		Else
			RecreateControl(o)
		Endif
*		WControlData(oWin)

		If aDatas[n,1] == "NAME" .AND. Type <> "WINDOW"
			UpdateWControls(oWin)
			o:ToolTip := "["+ o:aDatas[NAME,2] +"]  "+ IF(HB_IsSTRING(o:aDatas[dTOOLTIP,2]),o:aDatas[dTOOLTIP,2],"")
		Endif
	Endif

Return

*-----------------------------------------------------------------------------*
Procedure ChangeControlStyle(o, nStyle, lValue)
	SetWindowStyle( o:hWnd, If(lValue, nStyle, -nStyle) ) 
Return

*-----------------------------------------------------------------------------*
Procedure RecreateControl( o )
Local nPos, NewControl, oWin := o:Parent, oParent
Local cType, cName, x, y, w, h, aDatas, cBefore, cAfter, aItems := {}, i, aEvents
/*Local hWnd := GetFocus()	// should return the control that is in use
Local LastControl := GetControlObjectByHandle(hWnd), nValue
//db_Text(LastControl:Type)
	If LastControl:Type == "GRID"
		nValue := LastControl:Value
	Endif
*/
//Local nComboValue
	MODIFIED := .T.
	
	nPos := o:Cargo[TABINDEX]
	If nPos <> 0
		ReleaseControls(oWin)

		If o:Type == "TOOLBAR" .OR. o:Type == "TOOLBUTTON"
			Recreate_Tool(oWin, nPos)
*			Return
		ElseIf o:Cargo[cTYPE] == "TAB"
			Recreate_TAB(o)
		Else
			// Copy important information
			aDatas := ACLONE(o:aDatas)
			aEvents := ACLONE(o:aEvents)
			cBefore := o:cBefore
			cAfter  := o:cAfter
			
			o:lVisible := .F.					// Make invisible ???
			cType := o:Cargo[cTYPE]
			cName := aDatas[NAME,2]
			x 		:= o:nRow
			y 		:= o:nCol
			w 		:= o:nWidth
			h 		:= o:nHeight

			If o:Container:ClassName == "TTABPAGE"
				oParent := o:Container
			ElseIf o:Cargo[cTYPE] == "STATUSBAR"
				aItems := ACLONE(o:myItems)
			Endif
			o:Release()
			DO EVENTS
			NewControl := AddControl(cType, cName, x, y, w, h, oWin, aDatas, cAfter, .F.)
			If HB_IsObject(oParent)
				oParent:AddControl(NewControl, x, y)
			Endif

			// Add important information  -> aDatas and cBefore are set on AddControl()
			NewControl:aEvents := aEvents
			NewControl:cBefore := cBefore
			
			If NewControl:Cargo[cTYPE] == "STATUSBAR"
				// Recreate ITEMS
				For i := 1 TO LEN(aItems)
					NewControl:MyAddItem( aItems[i] )	// lDefault
				Next
				_EndMessageBar()
			Endif
DO EVENTS
			
			// Set control in previous order   NOTE: Could use Method TabIndex
			TabIndex(NewControl, nPos)
*			UpdateWControls(oWin)
		// Need to reset aSELECTED with new object
DO EVENTS
//			SelectControl(NewControl)
		Endif

		// Reposition on last control
/*		LastControl:SetFocus()
		If !EMPTY(nValue)
			LastControl:Value := nValue
		Endif
*/			
		oWin:Redraw()
		UpdateWControls(oWin)
		SelectControl(oWin:aControls[oWin:aCtrlsTabIndxs[nPos]])
	Endif
Return

Procedure Recreate_TAB(o)
Local aPagesData := {}, aPagescBefore := {}, aPagesCargo := {}
Local aControlsData := {}, aControlsEvents := {}, aControlscBefore := {}, aControlsCargo := {}, aControlsXYWH := {}
Local aDatas, aEvents, cBefore, aCtrlDatas, aXYWH
Local oPage, oCtrl, oParent, Cargo, i, x	//, oWin := o:Parent

	For EACH oPage IN o:aPages 
		AADD(aPagesData, ACLONE(oPage:aDatas))
		AADD(aPagescBefore, ACLONE(oPage:cBefore))
		AADD(aPagesCargo, ACLONE(oPage:Cargo))
		i := hb_EnumIndex()
		AADD(aControlsData, {})
		AADD(aControlsEvents, {})
		AADD(aControlscBefore, {})
		AADD(aControlsCargo, {})
		AADD(aControlsXYWH, {})
		FOR EACH oCtrl In oPage:aControls
			AADD( aControlsData[i], ACLONE( oCtrl:aDatas) )
			AADD( aControlsEvents[i], ACLONE( oCtrl:aEvents ) )
			AADD( aControlscBefore[i], ACLONE( oCtrl:cBefore ) )
			AADD( aControlsCargo[i], ACLONE( oCtrl:Cargo ) )
			AADD( aControlsXYWH[i], {oCtrl:nRow, oCtrl:nCol, oCtrl:nWidth, oCtrl:nHeight} )
		Next
	Next

	oParent	:= o:Parent		// This could be another container (tab, splitwindow)??? investigate!!!
	aDatas 	:= ACLONE(o:aDatas)
	aEvents 	:= ACLONE(o:aEvents)
	Cargo		:= ACLONE(o:Cargo)
	cBefore	:= o:cBefore
	aXYWH    := {o:nRow, o:nCol, o:nWidth, o:nHeight}
	o:Release()
	DO EVENTS

	//Recreate TAB
	o := AddControl(Cargo[cTYPE], aDatas[NAME,2], aXYWH[1], aXYWH[2], aXYWH[3], aXYWH[4], oParent, aDatas, cBefore, .F.)
	DO EVENTS
	o:aEvents := aEvents
	// Set TAB in previous order  
	TabIndex(o, Cargo[TABINDEX])
	
	For EACH aDatas IN aPagesData
		i := HB_EnumIndex()
		//Recreate PAGE
		o := AddControl(aPagesCargo[i][cTYPE], aDatas[NAME,2], , , , , oParent, aDatas, aPagescBefore[i], .F.)
		DO EVENTS
		// No events for pages
		// Set TAB in previous order
*		TabIndex(o, aPagesCargo[i][TABINDEX])

		For EACH aCtrlDatas IN aControlsData[i]
			x := HB_EnumIndex()
			//Recreate Control
			o := AddControl(aControlsCargo[i][x][cTYPE], aCtrlDatas[NAME,2], aControlsXYWH[i,x,1], aControlsXYWH[i][x,2], aControlsXYWH[i][x,3], aControlsXYWH[i][x,4], oParent, aCtrlDatas, aControlscBefore[i][x], .F.)
			o:aEvents := aControlsEvents[i][x]
			o:cBefore := aControlscBefore[i][x]
			// Set TAB in previous order  
			TabIndex(o, aControlsCargo[i][x][TABINDEX])
		Next
		END PAGE
	Next
	END TAB
*	UpdateWControls(oWin)
*	SelectControl(oWin:aControls[Cargo[TABINDEX]])
Return
			
Procedure Recreate_Tool(oWin, nPos)
Local o := oWin:aControls[nPos], aControls
Local cName, aDatas, aEvents, cBefore, oParent, NewControl, nPosition, cAfter

	If o:Type == "TOOLBAR"
		oParent := o
	Else
		oParent := o:Container
	Endif
	// Recreate everything
	aDatas   := ACLONE(oParent:aDatas)
	aEvents  := ACLONE(oParent:aEvents)
	cName    := aDatas[NAME,2]
	cBefore  := oParent:cBefore
	cAfter	:= o:cAfter
	aControls := ACLONE(oParent:aControls)
	nPosition := oParent:Cargo[TABINDEX]
	DeleteControl(oParent)
	oParent := AddControl("TOOLBAR", cName, /*x*/,/*y*/, oParent:nButtonWidth, oParent:nButtonHeight, oWin, aDatas, cAfter, .T.)
	TabIndex(oParent, nPosition)
	oParent:aEvents := aEvents
	oParent:cBefore := cBefore

	For EACH o IN aControls
		aEvents    := ACLONE(o:aEvents)
		nPosition  := o:Cargo[TABINDEX]
*		NewControl := AddControl("TBUTTON", o:Name, /*x*/,/*y*/,o:nWidth, o:nHeight, oWin, o:aDatas, o:cAfter, .T.)
		NewControl := AddControl("TBUTTON", o:Name, /*x*/,/*y*/, , , oWin, o:aDatas, o:cAfter, .T.)
		NewControl:aEvents := aEvents
		NewControl:cBefore := o:cBefore
		TabIndex(NewControl, nPosition)
	Next

// Need to reset aSELECTED with new object
	_EndToolBar( .T. )
*	UpdateWControls(oWin)
*	oWin:Redraw()
*	SelectControl( oWin:aControls[nPos])		//Reset aSELECTED with new control

Return
*-----------------------------------------------------------------------------*
Procedure ControlProperties(o)
Local cType, aItems := {}, aItem, gItems, aEvents := {}  
Local lValid := .T., aDatas := o:aDatas, i, aNames, uValue, lMemo 

	If !HB_IsArray(o:Cargo)
		Return
	Endif
	If oControlP:Cargo == o		// Selected control is already displayed
		Return
	Endif
	oControlP:iW:OnLostFocus := NIL
	oControlP:ComboHeaders:OnChange    := {|| .T. }		// Set to do nothing so it won´t triger before loaded
	oControlP:ComboHeaders:OnLostFocus := {|| .T. }	// Set to do nothing so it won´t triger before loaded
	If HB_IsObject(oControlP:Cargo) .AND. oControlP:Cargo:Cargo[1] = o:Cargo[1]
*		If oControlP:Cargo:hWnd == o:hWnd
*			Return
*		Endif
	Else
		oControlP:pTabs:HidePage(4)
		oControlP:pTabs:HidePage(5)
*		oControlP:pTabs:HidePage(6)
	Endif

	cType := o:Cargo[cTYPE]
	If !oControlP:Visible()
		oControlP:Show()
		SetFocus(oMain:Cargo:hWnd)
	Endif
	If cType == "ACTIVEX"
		aNames := {NAME, dOBJ,;
		dDISABLED, ;
		dHEIGHT, ;
		dWIDTH, ;
		dINVISIBLE, ;
		dNOTABSTOP,;
		dPROGID, ;
		dSUBCLASS}
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
	
	ElseIf cType == "ANIMATEBOX"
		aNames := {NAME, dOBJ, dAUTOPLAY, dCENTER, dDISABLED, dFILE, dHELPID, dINVISIBLE, dNOTABSTOP,;
						dRTL, dSUBCLASS, dTOOLTIP, dTRANSPARENT}
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
	
	ElseIf cType == "ANIGIF"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;      
      dBORDER,;			
      dCLIENTEDGE,;	
		dDISABLED,;		
      dFILE,;			
		dHELPID,;			
		dINVISIBLE,;		
		dRTL,;				
		dSUBCLASS,;		
		dTOOLTIP,;		
      dWHITEBACKGROUND }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])      	

	ElseIf cType == "BUTTON"
		aNames := {NAME, dOBJ,;
			dBACKCOLOR      		,;
			dBUFFER      			,;
			dCANCEL      			,;
			dCAPTION      		,;
			dDIBSECTION      	,;
			dDISABLED      		,;
			dFITIMG      			,;
			dFLAT      				,;	
			dFITTXT     			,;
			dFORCESCALE      	,;
			dHBITMAP      		,;
			dHELPID      			,;
			dIMAGEALIGN      	,;
			dIMAGEMARGIN      	,;
			dIMAGESIZE      		,;
			dINVISIBLE      		,;
			dMULTILINE      		,;
			dNO3DCOLORS      	,;
			dNODESTROY      		,;
			dNOFOCUSRECT      	,;
			dNOHOTLIGHT      	,;
			dNOIMAGELIST      	,;
			dNOLOADTRANSPARENT ,;
			dNOPREFIX      		,;
			dNOPRINTOVER      	,;
			dNOTABSTOP      		,;
			dOOHGDRAW     		,;
			dPICTURE      		,;
			dRTL      				,;
			dSOLID      			,;
			dSTRETCH      		,;
			dSUBCLASS      		,;
			dTEXTALIGNH     	 	,;
			dTEXTALIGNV      	,;
			dTEXTMARGIN      	,;
			dTOOLTIP      		,;
			dTRANSPARENT      	}
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
	
		AADD(aEvents, aDatas[dACTION])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		AADD(aEvents, aDatas[dONMOUSEMOVE])      	
		
	ElseIf cType == "CHECKBUTTON"
		aNames := {NAME, dOBJ,;
			dBUFFER,;      			
			dCAPTION,;             
			dDIBSECTION,;             
			dDISABLED,;             
			dFIELD,;             
			dFITIMG,;             
			dFITTXT,;             
			dFLAT,;             
			dFORCESCALE,;             
			dHBITMAP,;             
			dHELPID,;             
			dIMAGEALIGN,;             
			dIMAGESIZE,;             
			dINVISIBLE,;             
			dMULTILINE,;             
			dNO3DCOLORS,;             
			dNOFOCUSRECT,;             
			dNOHOTLIGHT,;             
			dNOIMAGELIST,;             
			dNOLOADTRANSPARENT,;             
			dNOPRINTOVER,;             
			dNOTABSTOP,;             
			dOOHGDRAW     			,;
			dPICTURE,;             
			dRTL,;             
			dSOLID,;             
			dSTRETCH,;             
			dSUBCLASS,;             
			dTEXTALIGNH,;             
			dTEXTALIGNV,;             
			dTEXTMARGIN,;             
			dTOOLTIP,;             
			dTRANSPARENT,;             
			dVALUE }             
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
	
		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		AADD(aEvents, aDatas[dONMOUSEMOVE])      	

	ElseIf cType == "CHECKBOX"
		aNames := {NAME, dOBJ,;
			dAUTOSIZE,;
			dBACKCOLOR,;
			dBACKGROUND,;          
			dCAPTION,;             
			dDISABLED,;            
			dFIELD,;               
			dHELPID,;              
			dINVISIBLE,;           
			dLEFTJUSTIFY,;           
			dNOFOCUSRECT,;         
			dNOTABSTOP,;           
			dOOHGDRAW     			,;
			dRTL,;                 
			dSUBCLASS,;            
			dTHREESTATE,;          
			dTOOLTIP,;             
			dTRANSPARENT,;         
			dVALUE }              

		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		
	ElseIf cType == "CHECKBUTTON"
		aNames := {NAME, dOBJ,;
			dBACKCOLOR,;
			dBUFFER,;
			dCAPTION,;
			dDIBSECTION,;
			dDISABLED,;
			dFIELD,;
			dFITIMG,;
			dFITTXT,;
			dFLAT,;
			dFORCESCALE,;
			dHBITMAP,;
			dHELPID,;
			dIMAGEALIGN,;
			dIMAGEMARGIN,;
			dIMAGESIZE,;
			dINVISIBLE,;
			dMULTILINE,;		
			dNO3DCOLORS,;
			dNOFOCUSRECT,;
			dNOHOTLIGHT,;
			dNOIMAGELIST,;
			dNOLOADTRANSPARENT,;
			dNOPRINTOVER,;
			dNOTABSTOP,;
			dOOHGDRAW     			,;
			dPICTURE,;
			dSOLID,;
			dSTRETCH,;
			dSTRIKEOUT,;	
			dSUBCLASS,;
			dRTL,; 
			dTEXTALIGNH,;
			dTEXTALIGNV,;
			dTEXTMARGIN,;
			dTOOLTIP,;
			dTRANSPARENT,;
			dVALUE }

		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		AADD(aEvents, aDatas[dONMOUSEMOVE])      	

	ElseIf cType == "CHECKLIST"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBREAK,;               
		dDESCENDING,;          
		dDISABLED,;            
		dHELPID,;              
		dIMAGE,;               
		dINVISIBLE,;           
		dITEMS,;               
		dJUSTIFY,;             
		dNOTABSTOP,;           
		dRTL,;                 
		dSELECTEDCOLORS,;      
		dSINGLEBUFFER,;        
		dSORT,;                
		dSUBCLASS,;            
		dTOOLTIP,;             
		dVALUE }              
	
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])      	
		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	

	ElseIf cType == "COMBOBOX"
		aNames := {NAME, dOBJ,;
		dAUTOSIZE,;
		dBACKCOLOR,;
		dBREAK,;               
		dCUEBANNER,;               
		dDELAYEDLOAD,; 
		dDISABLED,;
		dDISPLAYEDIT,;         
		dEDITHEIGHT,;          
		dFIRSTITEM,;           
		dFIT,;                 
		dGRIPPERTEXT,;         
		dHELPID,;              
		dIMAGE,;               
		dIMAGESOURCE,;         
		dINCREMENTAL,;         
		dINDEXISVALUE,;         
		dINTEGRALHEIGHT,;      
		dINVISIBLE,;           
		dITEMIMAGENUMBER,;     
		dITEMS,;               
		dITEMSOURCE,;
		dLISTWIDTH,;           
		dMAXLENGTH,;           
		dNOTABSTOP,;
		dNOLOADTRANSPARENT,;
		dOPTIONSHEIGHT,;       
		dREFRESH,;             
		dRTL,;                 
		dSEARCHLAPSE,;         
		dSORT,;                
		dSOURCEORDER,;         
		dSUBCLASS,;            
		dTEXTHEIGHT,;          
		dTOOLTIP,;             
		dVALUE,;               
		dVALUESOURCE }       
		
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONDISPLAYCHANGE])      	
		AADD(aEvents, aDatas[dONENTER])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLISTCLOSE])      	
		AADD(aEvents, aDatas[dONLISTDISPLAY])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		AADD(aEvents, aDatas[dONREFRESH])      	

	ElseIf cType == "DATEPICKER"
		aNames := {NAME, dOBJ,;
		dDATEFORMAT,;          
		dDISABLED,;            
		dFIELD,;               
		dHELPID,;              
		dINVISIBLE,;           
		dNOBORDER,;            
		dNOTABSTOP,;           
		dRANGE,;               
		dRTL,;                 
		dSHOWNONE,;            
		dSUBCLASS,;            
		dTOOLTIP,;             
		dUPDOWN,;              
		dVALID,;               
		dVALUE }           
		
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONENTER])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	

	ElseIf cType == "EDITBOX"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBREAK,;               
		dDISABLED,;            
		dFIELD,;               
		dFOCUSEDPOS,; 
		dHELPID,;
		dINSERTTYPE,;          
		dINVISIBLE,;	
		dMAXLENGTH,;           
		dNOBORDER,;            
		dNOHSCROLL,;           
		dNOTABSTOP,;           
		dNOVSCROLL,;           
		dREADONLY,;            
		dRTL,;   
		dSUBCLASS,;            
		dTOOLTIP,;
		dVALUE }            
		
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])      	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONHSCROLL])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		AADD(aEvents, aDatas[dONVSCROLL])      	

	ElseIf cType == "FRAME"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;	
		dCAPTION,;	
		dDISABLED,;	
		dEXCLUDEAREA,;	
		dINVISIBLE,;	
		dOPAQUE,;
		dRTL,;	
		dTRANSPARENT,;	
		dSUBCLASS,;	
		dTOOLTIP }

		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

	ElseIf cType == "GRID" .OR. cType == "BROWSE" .OR. cType == "XBROWSE"
		aNames := {NAME, dOBJ,;
		dAPPEND,;              
		dBACKCOLOR,;               
		dBREAK,;               
		dCELLTOOLTIP,;         
		dCHECKBOXES,;          
;//		dCOLUMNCONTROLS,;      
		dDELETE,;              
		dDELETEMSG,;           
		dDELETEWHEN,;          
		dDISABLED,;            
		dDYNAMICBACKCOLOR,;    
		dDYNAMICFORECOLOR,;    
		dEDIT,;                
		dEDITCELLVALUE,;       
		dEDITFIRSTVISIBLE,;    
		dEDITKEYS,;            
		dEDITLIKEEXCEL,;			
		dENABLEALTA,;          
		dEXTDBLCLICK,;         
		dFIXEDCOLS,;           
		dFIXEDCONTROLS,;       
		dFIXEDWIDTHS,;         
		dFOCUSRECT,;
		dHEADERCOLORS,;
		dHELPID,;              
		dIMAGE,;               
		dINPLACE,;             
		dINVISIBLE,;           
		dKEYSLIKECLIPPER,;     
		dMULTISELECT,;         
		dNAVIGATEBYCELL,;      
		dNODELETEMSG,;           
		dNOHEADERS,;           
		dNOHSCROLL,;           
		dNOLINES,;             
		dNOMODALEDIT,;         
		dNOSHOWALWAYS,;        
		dNOTABSTOP,;           
		dNOVSCROLL,;           
		dPAINTLEFTMARGIN,;     
		dRTL,;                 
		dSELECTEDCOLORS,;		
		dSILENT,;        
		dSINGLEBUFFER,;        
		dSUBCLASS,;            
		dTIMEOUT, ;
		dTOOLTIP,;             
		dUSEBUTTONS,;          
		dVALID,;               
		dVALIDMESSAGES,;       
		dVALUE }               

		If cType == "GRID"
			AEVAL( {;
				dCHANGEBEFOREEDIT,;  	 // Not in xBrowse 
				dITEMCOUNT,;         	// Not in Browse  or xbrowse
				dITEMS,;             	// not in browse or xbrowse
				dNOCLICKONCHECKBOX,; 	// not in browse or xbrowse
				dNONEUNSELS,;     		// not in xbrowse     
				dNORCLICKONCHECKBOX,;	// not in browse or xbrowse
				dVIRTUAL },;    			// not in browse or xbrowse     
				{|a| AADD(aNames, a)} )
		ElseIf cType == "BROWSE"
			AEVAL( {;
				dCOLUMNINFO,;      	// Not in Grid
				dDEFAULTVALUES,;  	// Not in Grid    
				dDESCENDING,;     	// Not in Grid     
;//				dDISABLEALTA,;     // not in grid This is the same as ENABLEALTA ??? 
;//				dFIELDS,;			// Not in grid	
				dFIXEDBLOCKS,;			// not in grid	
				dLOCK,;     			// not in grid
				dRECCOUNT,;    		// not in grid        
				dREFRESH,;      		// not in grif      
;//				dREPLACEFIELD,;    // not in grid        
				dSYNCHRONIZED,;  		// not in grid      
				dUPDATEALL,;    		// not in grid    
				dUPDATECOLORS,;  		// not in grid
				dWORKAREA,;
				dNEWATROW },;   		// not in grid		
				{|a| AADD(aNames, a)} )
		Else	// xBrowse
			AEVAL( {;
				dCOLUMNINFO,;      	// not in grid
				dDEFAULTVALUES,;   	// not in grid
				dDESCENDING,;     	// not in grid  
;//				dDISABLEALTA,;    // not in grid This is the same as ENABLEALTA ???
;//				dFIELDS,;			// not in grid
				dFIXEDBLOCKS,;			// not in grid	
				dFULLMOVE,;      		// not in grid
				dRECCOUNT,;   			// not in grid
;//				dREPLACEFIELD,;  	// not in grid    
				dUPDATECOLORS,;  		// not in grid
				dWORKAREA },;   		// not in grid
				{|a| AADD(aNames, a)} )
		Endif
		aSort(aNames)

		
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])      	
		AADD(aEvents, aDatas[dAFTERCOLMOVE])      	
		AADD(aEvents, aDatas[dAFTERCOLSIZE])      	
		AADD(aEvents, aDatas[dBEFOREAUTOFIT])      	
		AADD(aEvents, aDatas[dBEFORECOLMOVE])      	
		AADD(aEvents, aDatas[dBEFORECOLSIZE])      	
		AADD(aEvents, aDatas[dONABORTEDIT])      	
		AADD(aEvents, aDatas[dONAPPEND])      	
		AADD(aEvents, aDatas[dONBEFOREEDITCELL])      	
		If cType == "GRID"
			AADD(aEvents, aDatas[dONBEFOREINSERT])  // not in browse    	
		Endif
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONCHECKCHANGE])  	
		AADD(aEvents, aDatas[dONDBLCLICK])  	
		AADD(aEvents, aDatas[dONDELETE])  	
		AADD(aEvents, aDatas[dONEDITCELL])  	
		AADD(aEvents, aDatas[dONEDITCELLEND])  	
		AADD(aEvents, aDatas[dONENTER])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONHEADCLICK])     // columns in grid 	
		AADD(aEvents, aDatas[dONHEADDBLCLICK])  // columns in grid    	
		AADD(aEvents, aDatas[dONHEADRCLICK])      	
		If cType == "GRID"
			AADD(aEvents, aDatas[dONINSERT])      // not in browse	
		Endif
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		If cType == "GRID"
			AADD(aEvents, aDatas[dONQUERYDATA])    // not in browse  
		Endif
		AADD(aEvents, aDatas[dONRCLICK])      	

		If VALTYPE(o:aDatas[dHEADERS,2]) == 'A'
//			oControlP:ComboHeaders:Value := 0	// Reset combo
			oControlP:ComboHeaders:DeleteAllItems()	// Reset combo

			oControlP:ComboHeaders:OnChange    := {|| UpdateColumns(oControlP:ComboHeaders, o) }
			oControlP:ComboHeaders:OnLostFocus := {|| ChangeColumnHeader(oControlP)}
			oControlP:ComboHeaders:Rows        := o:aHeaders
			oControlP:ComboHeaders:Value       := 1
			oControlP:bAddColumn:OnClick       := {|| GridAddColumn(o) }
			oControlP:bDelColumn:OnClick       := {|| GridDelColumn(o) }
			oControlP:pTabs:ShowPage(5)
	*		oControlP:pTabs:ShowPage(6)
		Else
			oControlP:pTabs:HidePage(5)
		Endif

	ElseIf cType == "HOTKEYBOX"
		aNames := {NAME, dOBJ,;
      dBACKCOLOR,;
      dDISABLED,;
      dHELPID,;
      dINVISIBLE,;
      dNOALT,;
      dNOTABSTOP,;
      dRTL,;
      dSUBCLASS,;
      dTOOLTIP,;
      dVALUE }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	
		AADD(aEvents, aDatas[dONENTER])  	
 
	ElseIf cType == "HYPERLINK"
		aNames := {NAME, dOBJ,;
		dADDRESS,; 
		dAUTOSIZE,;
		dBACKCOLOR,;
		dBORDER,; 
		dCLIENTEDGE,;
		dHANDCURSOR,; 
		dHELPID,; 
		dHSCROLL,; 
		dINVISIBLE,;
		dNOVSCROLL,;
		dRTL,; 
		dSUBCLASS,; 
		dTOOLTIP,; 
		dTRANSPARENT,; 
		dVALUE,; 
		dVSCROLL }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

	ElseIf cType == "IMAGE"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBORDER,;					
		dBUFFER,;              
		dCLIENTEDGE,;				
		dDISABLED,;            
		dEXCLUDEAREA,;			
		dHBITMAP,;             
		dHELPID,;					
		dIMAGESIZE,;           
		dINVISIBLE,;				
		dNO3DCOLORS,;          
		dNOCHECKDEPTH,;			
		dNODIBSECTION,;        
		dNOLOADTRANSPARENT,;	
		dNOPARENTREDRAW,;      
		dNORESIZE,;				
		dPICTURE,;             
		dRTL,;						
		dSTRETCH,;             
		dSUBCLASS,;				
		dTOOLTIP,;             
		dTRANSPARENT,;			
		dWHITEBACKGROUND }

		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])  	
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONDBLCLICK])  	
		AADD(aEvents, aDatas[dONMCLICK])  	
		AADD(aEvents, aDatas[dONMDBLCLICK])  	
		AADD(aEvents, aDatas[dONRCLICK])  	
		AADD(aEvents, aDatas[dONRDBLCLICK])  	

	ElseIf cType == "IPADDRESS"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dDISABLED,;
		dHELPID,;					
		dINVISIBLE,;
		dNOTABSTOP,;
		dRTL,;
		dSTRETCH,;
		dSUBCLASS,;				
		dTOOLTIP,; 
		dVALUE }           

		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])      	
		AADD(aEvents, aDatas[dONLOSTFOCUS])      	
		
	ElseIf cType == "LABEL"
*		AEVAL(aDatas, {|a| AADD(aItems, {a[1],a[2]}) })
*		aEvents := o:aEvents
		aNames := {NAME, dOBJ,;
			dAUTOSIZE     	,;
			dBACKCOLOR      	,;
			dBORDER       		,;
			dCENTERALIGN  	,;
			dCLIENTEDGE   	,;
			dDISABLED     	,;
			dHELPID       		,;
			dHSCROLL      		,;
			dINPUTMASK    	,;
			dINVISIBLE    	,;
			dNOPREFIX     	,;
			dNOWORDWRAP     	,;
			dRIGHTALIGN   	,;
			dRTL          		,;
			dSUBCLASS     	,;
			dTOOLTIP      		,;
			dTRANSPARENT  	,;
			dVALUE        		,;
			dVCENTERALIGN   	,;
			dVSCROLL      		}
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])  	
		AADD(aEvents, aDatas[dONDBLCLICK])  	
		
	ElseIf cType == "LISTBOX"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBREAK,;
		dCOLUMNWIDTH, ;
		dDISABLED,;
		dDRAGITEMS,;
		dFIT,;
		dHELPID,;
		dIMAGE,;
		dINVISIBLE,;
		dITEMS,;
		dMULTICOLUMN,;
		dMULTISELECT,;
		dMULTITAB,;
		dNOTABSTOP,;
		dNOVSCROLL,;
		dRTL,;
		dSORT,;
		dSUBCLASS,;
		dTABSWIDTH,;
		dTEXTHEIGHT,;
		dTOOLTIP,;
		dVALUE }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONDBLCLICK])  	
		AADD(aEvents, aDatas[dONENTER])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	

	ElseIf cType == "MONTHCALENDAR"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBACKGROUNDCOLOR,;
		dDISABLED,;
		dHELPID,;
		dINVISIBLE,;
		dMULTISELECT,;
		dNOTABSTOP,;
		dNOTODAY,;
		dNOTODAYCIRCLE,;
		dRTL,;
		dSUBCLASS,;
		dTITLEBACKCOLOR,;
		dTITLEFONTCOLOR,;
		dTRAILINGFONTCOLOR,;
		dTOOLTIP,;
		dVALUE,;
		dWEEKNUMBERS }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	
		AADD(aEvents, aDatas[dONVIEWCHANGE])  	

   ElseIf cType == "PAGE"
		AEVAL(aDatas, {|a| AADD(aItems, {a[1],a[2]}) })
		
	ElseIf cType == "PICTURE"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBORDER,;
		dBUFFER,;
		dCLIENTEDGE,;
		dDISABLED,;
		dEXCLUDEAREA,;
		dFORCESCALE,;
		dHBITMAP,;
		dHELPID,;
		dIMAGESIZE,;
		dINVISIBLE,;
		dNO3DCOLORS,;
		dNODIBSECTION,;
		dNOLOADTRANSPARENT,;
		dPICTURE,;
		dRTL,;
		dSTRETCH,;
		dSUBCLASS,;
		dTOOLTIP,;
		dTRANSPARENT }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])  	

	ElseIf cType == "PLAYER"
		aNames := {NAME, dOBJ,;
		dDISABLED,;
		dFILE,;
		dHELPID,;
		dINVISIBLE,;
		dNOAUTOSIZEMOVIE,;
		dNOAUTOSIZEWINDOW,;
		dNOERRORDLG,;
		dNOMENU,;
		dNOOPEN,;
		dNOPLAYBAR,;
		dNOTABSTOP,;
		dRTL,;
		dSHOWALL,;
		dSHOWMODE,;
		dSHOWNAME,;
		dSHOWPOSITION,;
		dSUBCLASS }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

	ElseIf cType == "PROGRESSBAR"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR 	 ,;
;//		dFORECOLOR	 ,;
		dHELPID		 ,;
		dINVISIBLE 	 ,;
		dMARQUEE 	 ,;
		dRANGE       ,;
		dRTL 			 ,;
		dSMOOTH 		 ,;
		dSUBCLASS    ,;
		dTOOLTIP     ,;
		dVALUE       ,;
		dVERTICAL 	 }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		aEvents := o:aEvents

	ElseIf cType == "PROGRESSMETER"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR 	,;
		dCLIENTEDGE	,;
		dDISABLED	,;
;//		dFORECOLOR	,;
		dHELPID		,;
		dINVISIBLE 	,;
		dRANGE      ,;
		dRTL			,;
		dSUBCLASS   ,;
		dTOOLTIP    ,;
		dVALUE       }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])  	

	ElseIf cType == "RADIOGROUP"
		aNames := {NAME, dOBJ,;
		dAUTOSIZE,;
		dBACKCOLOR,;
		dBACKGROUND,;
		dDISABLED,;
		dHELPID,;
		dHEIGHT,;
		dHORIZONTAL,;
		dINVISIBLE,;
		dLEFTJUSTIFY,;
		dLIMIT,;
		dNOFOCUSRECT,;
		dNOTABSTOP,;
		dOPTIONS,;
		dOOHGDRAW     			,;
		dREADONLY,;
		dRTL,;
		dSHIFT,;
		dSPACING,;
		dSUBCLASS,;
		dTOOLTIP,;
		dTRANSPARENT,;
		dVALUE,;
		dWIDTH }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, o:aDatas[dONCHANGE])  	

	ElseIf cType == "RICHEDITBOX"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBREAK,;
		dDISABLED,;
		dFIELD,;
		dFILE,;
		dFILETYPE,;
		dFOCUSEDPOS,;
		dHELPID,;
		dINSERTTYPE,;
		dINVISIBLE,;
		dMAXLENGTH,;
		dNOHIDESEL,;
		dNOHSCROLL,;
		dNOTABSTOP,;
		dNOVSCROLL,;
		dPLAINTEXT,;
		dREADONLY,;
		dRTL,;
		dSUBCLASS,;
		dTOOLTIP,;
		dVALUE,;
		dVERSION }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONHSCROLL])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	
		AADD(aEvents, aDatas[dONSELCHANGE])  	
		AADD(aEvents, aDatas[dONVSCROLL])  	

	ElseIf cType == "STATUSBAR"
		aEval(aDatas, {|a| AADD(aItems, {a[1],a[2]})} )
		aEvents := o:aEvents
		oControlP:ComboItems:OnChange 	:= NIL
		oControlP:ComboItems:DeleteAllItems()
		oControlP:iW:OnLostFocus 			:= {|| o:Update(oControlP:ComboItems:Value, stiWIDTH, oControlP:iW:Value) }
		oControlP:iIcon:OnLostFocus 		:= {|| o:Update(oControlP:ComboItems:Value, stiICON, oControlP:iIcon:Value) }
		oControlP:iToolTip:OnLostFocus 	:= {|| o:Update(oControlP:ComboItems:Value, stiTOOLTIP, oControlP:iToolTip:Value) }
		oControlP:iAction:OnLostFocus 	:= {|| o:Update(oControlP:ComboItems:Value, stiACTION, oControlP:iAction:Value) }
		oControlP:iStyle:OnChange 			:= {|| o:Update(oControlP:ComboItems:Value, stiSTYLE, oControlP:iStyle:DisplayValue) } //, RecreateControl(o),) } 
		oControlP:iAlign:OnChange 			:= {|| o:Update(oControlP:ComboItems:Value, stiALIGN, oControlP:iAlign:DisplayValue) } 

		oControlP:bMas:OnClick := {|| o:MyAddItem({"New Item"}), RecreateControl(o), oControlP:ComboItems:Value := LEN(o:MyItems) }
		oControlP:bDel:OnClick := {|n| n := oControlP:ComboItems:Value, o:Delete(n), RecreateControl(o) }
		
		aItem := {}
		for i=1 to LEN(o:MyItems)
*			oControlP:ComboItems:AddItem(o:aItems[i,1])		// This does'nt work
			AADD(aItem, o:MyItems[i,1])
		next
		oControlP:ComboItems:Rows := aItem
		oControlP:ComboItems:OnChange 	:= {|| GetStatValues(o)}
		oControlP:ComboItems:Value := 1
		oControlP:ComboItems:Cargo := oControlp:ComboItems:Value
		oControlP:ComboItems:OnLostFocus := {|| ChangeStatusCaption(oControlP)}
		oControlP:pTabs:ShowPage(4)
		GetStatValues(o)	// Initialize
		
	ElseIf cType == "SLIDER"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBOTH,;
		dDISABLED,;
		dHELPID,;
		dINVISIBLE,;
		dLEFT,;
		dNOTABSTOP,;
		dNOTICKS,;
		dRANGE,;
		dRTL,;
		dSUBCLASS,;
		dTOOLTIP,;
		dTOP,;
		dVALUE,;
		dVERTICAL }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
		
		AADD(aEvents, aDatas[dONCHANGE])  	

	ElseIf cType == "SPINNER"
		aNames := {NAME, dOBJ,;
		dBACKCOLOR,;
		dBOUNDTEXT,;
		dDISABLED,;
		dHELPID,;
		dINCREMENT,;
		dINVISIBLE,;
		dNOBORDER,;
		dNOTABSTOP,;
		dRANGE,;
		dREADONLY,;
		dRTL,;
		dSUBCLASS,;
		dTOOLTIP,;
		dVALUE,;
		dWRAP }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
		
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	

	ElseIf cType == "SCROLLBAR"
		aNames := {NAME, dOBJ,;
		dATTACHED,;
		dAUTOMOVE,;
		dDISABLED,;
		dHELPID,;
		dHORIZONTAL,;
		dINVISIBLE,;
		dLINESKIP,;
		dPAGESKIP,;
		dRANGE,;
		dREADONLY,;
		dRTL,;
		dSUBCLASS,;
		dTOOLTIP,;
		dVALUE,; 
		dVERTICAL }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
		
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONLINEUP])  	
		AADD(aEvents, aDatas[dONLINEDOWN])  	
		AADD(aEvents, aDatas[dONPAGEUP])  	
		AADD(aEvents, aDatas[dONPAGEDOWN])  	
		AADD(aEvents, aDatas[dONTOP])  	
		AADD(aEvents, aDatas[dONBOTTOM])  	
		AADD(aEvents, aDatas[dONTHUMB])  	
		AADD(aEvents, aDatas[dONTRACK])  	
		AADD(aEvents, aDatas[dONENDTRACK])  	

	ElseIf cType == "TAB"
		aNames := {NAME, dOBJ,;
		dBOTTOM,;
		dBUTTONS,;
		dDELAYMSGS,;
		dDISABLED,;
		dFIXEDWIDTHS,;	// OJO ESTO ES SIN LA S
		dFLAT,;
		dHOTTRACK,;
		dICONLEFT,;
		dINTERNALS,;
		dINVISIBLE,;
		dITEMSIZE,;
		dLABELLEFT,;
		dMINWIDTH,;
		dMULTILINE,;
		dNOTABSTOP,;
		dPADDING,;
		dRAGGEDRIGHT,;
;//		dRIGHT,;
		dRIGHT,;
		dRTL,;
		dSCROLLOP,;
		dSUBCLASS,;
		dTOOLTIP,;
		dVALUE,;
		dVERTICAL }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])  	
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONRCLICK])  	

	ElseIf cType == "TEXTARRAY"
		aNames := {NAME, dOBJ,;
      dBACKCOLOR,;
      dBORDER,;
      dDISABLED,;
      dCOLCOUNT,;
      dCLIENTEDGE,;
      dHELPID, ;
      dINVISIBLE, ;
      dNOTABSTOP,;
      dROWCOUNT, ;
      dRTL ,;
      dSUBCLASS ,;
      dTOOLTIP ,;
      dVALUE }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

 		AADD(aEvents, aDatas[dACTION])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	
		
	ElseIf cType == "TEXTBOX"
		aNames := {NAME, dOBJ,;
		dAUTOSKIP,;
		dBACKCOLOR,;
		dBUTTONWIDTH,;
		dCENTERALIGN,;
		dCTRLSATLEFT,;
		dDATE,;
		dDEFAULTYEAR,;
		dDISABLED,;
		dFIELD,;
		dFOCUSEDPOS,;
		dFORMAT,;
		dHELPID,;
		dIMAGE,;
		dINPUTMASK,;
		dINSERTTYPE,;
		dINVISIBLE,;
		dLOWERCASE,;
		dMAXLENGTH,;
		dNOBORDER,;
		dNOCONTEXTMENU,;
		dNOTABSTOP,;
		dNUMERIC,;
		dPASSWORD,;
		dREADONLY,;
		dRIGHTALIGN,;
		dRTL,;
		dSUBCLASS,;
		dTOOLTIP,;
		dUPPERCASE,;
		dVALID,;
		dVALUE,;
		dWHEN }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])
		AADD(aEvents, aDatas[dACTION2])
		AADD(aEvents, aDatas[dONCHANGE])
		AADD(aEvents, aDatas[dONENTER])
		AADD(aEvents, aDatas[dONGOTFOCUS])
		AADD(aEvents, aDatas[dONLOSTFOCUS])
		AADD(aEvents, aDatas[dONTEXTFILLED])
	
	ElseIf cType == "TIMER"
		aNames := {NAME, dOBJ,;
		dDISABLED,;
		dINTERVAL,;
		dONCE,;
		dSUBCLASS }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dACTION])

	ElseIf cType == "TIMEPICKER"
		aNames := {NAME, dOBJ,;
		dDISABLED,;
		dFIELD,;
		dHELPID,;
		dINVISIBLE,;
		dNOBORDER,;
		dNOTABSTOP,;
		dRIGHTALIGN,;
		dRTL,;
		dSHOWNONE,;
		dSUBCLASS,;
		dTIMEFORMAT,;
		dTOOLTIP,;
		dUPDOWN,;
		dVALID,;
		dVALUE }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONENTER])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	

   ElseIf cType == "TOOLBAR"
		AEVAL(aDatas, {|a| AADD(aItems, {a[1],a[2]}) })

/*		aNames := {NAME, dOBJ,;
			dBOLD	        ,;
			dBORDER       ,;
			dBOTTOM		  ,;
			dBREAK        ,;
			dBUTTONSIZE   ,;
			dCAPTION      ,;	
			dFLAT      	  ,;
			dFONT     	  ,;
			dITALIC 	     ,;
			dNOTABSTOP    ,;
			dOWNTOOLTIP   ,;
			dRIGHTTEXT	  ,;
			dRTL          ,;
			dSIZE   		  ,;
			dSTRIKEOUT    ,;
			dSUBCLASS     ,;
			dTOOLBARSIZE  ,;
			dTOOLTIP      ,;
			dUNDERLINE    ,;
			dVERTICAL	  }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
*/			
 		
	ElseIf cType == "TREE"
		aNames := {NAME, dOBJ,;
			dBACKCOLOR,;
			dBREAK,;
			dCHECKBOXES,;
			dDISABLED,;
			dEDITLABELS,;
			dENABLEDRAG,;
			dENABLEDROP,;
			dFULLROWSELECT,;
			dHELPID,;
			dHOTTRACKING,;
			dINDENT,;
			dINVISIBLE,;
			dITEMIDS,;
			dITEMIMAGES,;
			dNOBORDER,;
			dNOBUTTONS,;
			dNODEIMAGES,;
			dNOHSCROLL,;
			dNOLINES,;
			dNOROOTBUTTON,;
			dNOSCROLL,;
			dNOTABSTOP,;
			dOWNTOOLTIP,;
			dRTL,;
			dSELBOLD,;
			dSELCOLOR,;
			dSINGLEEXPAND,;
			dSUBCLASS,;
			dTARGET,;
			dTOOLTIP,;
			dVALID,;
			dVALUE }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })
	
		AADD(aEvents, aDatas[dONCHANGE])  	
		AADD(aEvents, aDatas[dONCHECKCHANGE])  	
		AADD(aEvents, aDatas[dONCOLLAPSE])  	
		AADD(aEvents, aDatas[dONDBLCLICK])  	
		AADD(aEvents, aDatas[dONDROP])  	
		AADD(aEvents, aDatas[dONENTER])  	
		AADD(aEvents, aDatas[dONEXPAND])  	
		AADD(aEvents, aDatas[dONGOTFOCUS])  	
		AADD(aEvents, aDatas[dONLABELEDIT])  	
		AADD(aEvents, aDatas[dONLOSTFOCUS])  	

   ElseIf cType == "TBUTTON"
		AEVAL(aDatas, {|a| AADD(aItems, {a[1],a[2]}) })
		aEvents := o:aEvents
/*		aNames := {NAME, dOBJ,;
		dAUTOSIZE            ,;
		dCAPTION             ,;
		dCHECK               ,;
		dDROPDOWN            ,;
		dGROUP               ,;
		dPICTURE             ,;
		dSEPARATOR           ,;
		dSUBCLASS            ,;
		dTOOLTIP             ,;
		dWHOLEDROPDOWN       }
		AEVAL(aNames, {|a| AADD(aItems, {aDatas[a,1], aDatas[a,2]} ) })

		AADD(aEvents, aDatas[dONCLICK])  	
*/		
	ElseIf cType == "WINDOW"
		aDatas[wWIDTH,2] := o:WIDTH
		aDatas[wHEIGHT,2] := o:HEIGHT
		AEVAL(aDatas, {|a| AADD(aItems, {a[1], a[2]}) })
		aEvents := o:aEvents
		
	Else
		lValid := .F.
		oControlP:Title := "Control "+cType
		oControlP:P_Control:DeleteAllItems()
		oControlP:E_Control:DeleteAllItems()
	Endif
	
	If lValid
		// Properties
		oControlP:Title := o:Cargo[1]+"   "+aDatas[NAME,2]
		oControlP:P_Control:Cargo := ACLONE(aItems)
		gItems := ACLONE(aItems)
		WITH OBJECT oControlP:P_Control
			FOR EACH aItem IN gItems
	*			uValue := aItem[2]
				lMemo := .F.
				If aItem[1] == "OOHGDRAW"
					uValue := {"","OOHGDRAW", "WINDRAW"}
					aItem[2] := If(aItem[2], "OOHGDRAW", If(aDatas[dWINDRAW,2], "WINDRAW", ""))
				ElseIf aItem[1] == "IMAGEALIGN"
					uValue := {" ","LEFT", "RIGHT", "TOP", "BOTTOM", "CENTER"}
				ElseIf aItem[1] == "TEXTALIGNH"
					uValue := {" ","LEFT", "RIGHT", "CENTER"}
				ElseIf aItem[1] == "TEXTALIGNV"
					uValue := {" ","TOP", "BOTTOM", "VCENTER"}
				ElseIf aItem[1] == "INTERACTIVECLOSE"
					uValue := {" ", "OFF", "ON", "QUERY"}
*				ElseIf aItem[1] == "ITEMS"
*					aItem[2] := ArrayToString(aItem[2], .T.)
*					lMemo := .T.
				ElseIf aItem[1] $ "HEADERCOLORS VALIDMESSAGES SELECTEDCOLORS EDITKEYS TOOLTIP"  
					lMemo := .T.
				Endif
				AADD(:Cargo[hb_EnumIndex()], My_GridControlObjectByType( Hb_QWith(), aItem[2], uValue, lMemo ) )
				aItem[2] := xToString(aItem[2])
*				If LEFT(aItem[2],1) = "'" .OR. LEFT(aItem[2],1) = '"'
*					aItem[2] := SUBSTR(aItem[2], 2, LEN(aItem[2])-2)
*				Endif
				uValue := ''
			Next
*			:DeleteAllItems()
			:aItems := gItems
		End With
		// Events
		oControlP:E_Control:Cargo := ACLONE(aEvents)
		oControlP:E_Control:aItems := ACLONE(aEvents)

		// Create edit controls for Events
		oControlP:E_Control:lFixedControls := .T.

		oControlP:Cargo := o
		oControlP:Redraw()
	Endif
Return	


/*************************************************************************************
StatusBar programing
**************************************************************************************/
Procedure GetStatValues(o)
Local i := oControlP:ComboItems:Value
//ComboGetCursel( oControlP:ComboItems:hWnd )	//
	If i > 0 .AND. i <= LEN(o:MyItems)
//		ComboItem( oControlP:ComboItems, i, oControlP:ComboItems:DisplayValue )
		If !oControlP:ComboItems:Enabled
			oControlP:ComboItems:Enabled := .T.
			oControlP:iW:Enabled := .T.
			oControlP:iToolTip:Enabled := .T.
			oControlP:iIcon:Enabled := .T.
			oControlP:iStyle:Enabled := .T.
			oControlP:iAlign:Enabled := .T.
			oControlP:iAction:Enabled := .T.
		Endif

		oControlP:ComboItems:Cargo := i	// Keeps Combo value to change caption of statusitem
		oControlP:iW:Value 			:= If(o:MyItems[i,2]=NIL, 0, o:MyItems[i,2])
		oControlP:iToolTip:Value 	:= o:MyItems[i,4]
		oControlP:iIcon:Value 		:= o:MyItems[i,5]
		oControlP:iStyle:Value 		:= o:MyItems[i,6]
		oControlP:iAlign:Value 		:= o:MyItems[i,7]
		oControlP:iAction:Value 	:= o:MyItems[i,3]
	Else
*		oControlP:ComboItems:Cargo := 0
		oControlP:iW:Value 			:= 0
		oControlP:iToolTip:Value 	:= ""
		oControlP:iIcon:Value 		:= ""
		oControlP:iStyle:Value 		:= 1
		oControlP:iAlign:Value 		:= 1
		oControlP:iAction:Value 	:= ''

		oControlP:ComboItems:Enabled := .F.
		oControlP:iW:Enabled := .F.
		oControlP:iToolTip:Enabled := .F.
		oControlP:iIcon:Enabled := .F.
		oControlP:iStyle:Enabled := .F.
		oControlP:iAlign:Enabled := .F.
		oControlP:iAction:Enabled := .F.

	Endif
Return

*-----------------------------------------------------------------------------*
Procedure ChangeStatusCaption()
Local oCombo := oControlP:ComboItems, cText
	If oCombo:Cargo > 0
		cText := oCombo:Cargo
		ComboItem(oCombo, cText, oCombo:DisplayValue)
		oControlP:Cargo:Update(cText, 1, oCombo:DisplayValue)
	Endif
Return
/*************************************************************************************
End StatusBar programing
**************************************************************************************/

/*************************************************************************************
Tab Page programing
**************************************************************************************/
Procedure AddTabPage(o)
Local aDatas := GetDataArray("PAGE")[1], NewPage
	aDatas[NAME,2] := NewControlName("PAGE", oMain:Cargo)
	aDatas[tpCAPTION,2] := "New Page"
	NewPage := o:AddPage( , "New Page", /*cImage*/, /*aControls*/, /*bMnemonic*/, /*cName*/, /*oSubClass*/, /*uToolTip*/ )
	NewPage:Cargo := {"PAGE",0,.F.,.F.}
	NewPage:aDatas := aDatas
	NewPage:aEvents := {}
	o:Value := NewPage:Position
	o:Refresh()
	PageName(NewPage)
Return

Procedure PageName(oPage)
	FastData(oPage, "CAPTION")
Return

/*************************************************************************************
End Tabe Page programing
**************************************************************************************/

/*
Column Control
DynamicBackColor
DynamicForeColor
EditCellValue
Header
Header Images
Header Image Align
Input Mask
Justify
ReadOnly
Valid
ValidMessageds
When
Widths

OnBeforeEditCell
OnEditCell
OnCellEnd
OnHeadDblClick
OnHeadClick
*/
/*************************************************************************************
GRID, XBROWSE, BROWSE column properties and events programing
**************************************************************************************/
Procedure UpdateColumns(oCombo, oGrid)
Local aItems := {}, aEvents := {}, i := oCombo:Value, aItem
Local oGridColumns := oControlP:Column_P

	If i> 0
		oGridColumns:Cargo := {}
		AADD(aItems, {"Column Control", IsNull(oGrid:caColumnBlocks[i],''), "caColumnBlocks",;
				My_GridControlObjectByType(oGridColumns, IsNull(oGrid:caColumnBlocks[i],''), ,.T. )})	//oGrid:aColumns
		
		If oGrid:Cargo[1] == "XBROWSE" .OR. oGrid:Cargo[1] == "BROWSE"
			AADD(aItems, {"DefaultValue", 	oGrid:caDefaultValues[i], "caDefaultValues",;	// aReplaceField
			My_GridControlObjectByType( oGridColumns, oGrid:caDefaultValues[i] ) })
		Endif

		AADD(aItems, {"Dynamic Back Color", IsNull(oGrid:caDynamicBackColor[i],''), "caDynamicBackColor", ;	
			My_GridControlObjectByType(oGridColumns, IsNull(oGrid:caDynamicBackColor[i],'') ) })

		AADD(aItems, {"Dynamic Fore Color", IsNull(oGrid:caDynamicForeColor[i],''), "caDynamicForeColor", ;	
			My_GridControlObjectByType(oGridColumns, IsNull(oGrid:caDynamicForeColor[i],'')) })

		If oGrid:Cargo[1] == "XBROWSE" .OR. oGrid:Cargo[1] == "BROWSE"
			AADD(aItems, {"Fields", 			oGrid:caFields[i], "caFields", ;	// Field
				My_GridControlObjectByType(oGridColumns, oGrid:caFields[i]) })
		Endif

		AADD(aItems, {"Header Images", 		oGrid:aHeaderImage[i], "caHeaderImage", ;	
				My_GridControlObjectByType(oGridColumns, oGrid:aHeaderImage[i]) })

		AADD(aItems, {"Header Images Align", oGrid:aHeaderImageAlign[i], "caHeaderImageAlign", ;	
				My_GridControlObjectByType(oGridColumns, oGrid:aHeaderImageAlign[i]) })

		AADD(aItems, {"Input Mask", 			IsNull(oGrid:Picture[i],''), "Picture", ;	
				My_GridControlObjectByType(oGridColumns, IsNull(oGrid:Picture[i],'')) })

		AADD(aItems, {"Justify", 				oGrid:aJust[i], "aJust", ;	
				My_GridControlObjectByType(oGridColumns, oGrid:aJust[i], {{"LEFT", "RIGHT", "CENTER"},{0,1,2}}) })
		
		AADD(aItems, {"ReadOnly", 				oGrid:ReadOnly[i], "ReadOnly", ;	
				My_GridControlObjectByType(oGridColumns, oGrid:ReadOnly[i]) })

		If oGrid:Cargo[1] == "XBROWSE" .OR. oGrid:Cargo[1] == "BROWSE"
			AADD(aItems, {"ReplaceField", 	oGrid:caReplaceField[i], "caReplaceField", ;	// aReplaceField
				My_GridControlObjectByType(oGridColumns, oGrid:caReplaceField[i]) })
		Endif

		AADD(aItems, {"Valid", 					IsNull(oGrid:caValid[i],''), "caValid", ;	//oGrid:aColumns
				My_GridControlObjectByType(oGridColumns, IsNull(oGrid:caValid[i],''),,.T.) })

		AADD(aItems, {"When", 					IsNull(oGrid:caWhen[i],''), "caWhen", ; 
				My_GridControlObjectByType(oGridColumns, IsNull(oGrid:caWhen[i],''),,.T.) })

		AADD(aItems, {"Width", 					oGrid:aWidths[i], "aWidths", ;	
				My_GridControlObjectByType(oGridColumns, oGrid:aWidths[i]) })

		oControlP:Column_P:Cargo := ACLONE(aItems)

		aItem := {}
		AEVAL(aItems, {|a| AADD(aItem, {a[1], xToString(a[2]) }) })
		oControlP:Column_P:DeleteAllItems()
		oControlP:Column_P:aItems := aItem
		AADD(aEvents, {"OnHeadClick", oGrid:caOnHeadClick[i]})     // columns in grid 	
		AADD(aEvents, {"OnHeadDBLClick", oGrid:caOnHeadDblClick[i]})  // columns in grid    	
		oControlP:Column_E:aItems := aEvents
		oControlP:pTabs:Refresh()
		
	Else
		oControlP:Column_P:aItems := aItems
		oControlP:Column_E:aItems := aEvents
	Endif
	oCombo:Cargo := i
Return

*-----------------------------------------------------------------------------*
Procedure ChangeColumnProperties(oGrid, n, uValue)
Local i := oControlP:ComboHeaders:Value
	If i < 1 .OR. i > LEN(oGrid:aHeaders)
		Return
	Endif
	
	If oGrid:Cargo[1] == "GRID"
		DO CASE
		CASE n = 1	// Column Control
			oGrid:caColumnBlocks[i] := uValue
		CASE n = 2	// Dynamic Back Color
			oGrid:caDynamicBackColor[i] := uValue
		CASE n = 3 // Dynamic Fore Color
			oGrid:aDynamicForeColor[i] := uValue
		CASE n = 4	// Header Images
			oGrid:aHeaderImage[i] := uValue
		CASE n = 5
			oGrid:aHeaderImageAlign[i] := uValue
		CASE n = 6
			oGrid:Picture[i] := uValue
		CASE n = 7
			oGrid:aJust[i] := VAL(uValue)
			SETGRIDCOLUMNJUSTIFY(oGrid:hWnd, i, VAL(uValue))
		CASE n = 8 
			oGrid:ReadOnly[i] := uValue 
		CASE n = 9 
			oGrid:caValid[i] := uValue
		CASE n = 10 
			oGrid:caWhen[i] := uValue
		CASE n = 11
			oGrid:aWidths[i] := uValue
			LISTVIEW_SETCOLUMNWIDTH(oGrid:hWnd, i-1, uValue)
		END CASE
	Else	// xBrowse & Browse
		DO CASE
		CASE n = 1	
			oGrid:caColumnBlocks[i] := uValue
		CASE n = 2	// Default Vañues
			oGrid:caDefaultValues[i] := uValue
		CASE n = 3	// Dynamic Back Color
			oGrid:caDynamicBackColor[i] := uValue
		CASE n = 4
			oGrid:caDynamicForeColor[i] := uValue
		CASE n = 5
			oGrid:caFields[i] := uValue
		CASE n = 6
			oGrid:caHeaderImage[i] := uValue
		CASE n = 7
			oGrid:caHeaderImageAlign[i] := uValue
		CASE n = 8
			oGrid:Picture[i] := uValue
		CASE n = 9
			oGrid:aJust[i] := uValue
			SETGRIDCOLUMNJUSTIFY(oGrid:hWnd, i, uValue)
		CASE n = 10 
			oGrid:ReadOnly[i] := uValue
		CASE n = 11 
			oGrid:caReplaceField[i] := uValue
		CASE n = 12 
			oGrid:caValid[i] := uValue
		CASE n = 13 
			oGrid:caWhen[i] := uValue
		CASE n = 14
			oGrid:aWidths[i] := uValue
			LISTVIEW_SETCOLUMNWIDTH(oGrid:hWnd, i-1, uValue)
		END CASE
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure ChangeColumnHeader()
Local oCombo := oControlP:ComboHeaders, oGrid
	If oCombo:Cargo > 0
		oGrid := oControlP:Cargo
		oGrid:Header(oCombo:Cargo, oCombo:DisplayValue)
		oCombo:Item(oCombo:Cargo, oCombo:DisplayValue)
		oCombo:Value := oCombo:Cargo
	Endif
Return

*-----------------------------------------------------------------------------*
Procedure GridAddColumn(oGrid)
Local nColumn := oControlP:ComboHeaders:Value+1
	oGrid:AddColumn( nColumn, "New Column", 50)
	oControlP:ComboHeaders:Rows := oGrid:aHeaders
	DO EVENTS
	oGrid:ReadOnly[nColumn] := .F.
	oControlP:ComboHeaders:Cargo := nColumn
	oControlP:ComboHeaders:Value := nColumn
Return

*-----------------------------------------------------------------------------*
Procedure GridDelColumn(oGrid)
Local nCol := oControlP:ComboHeaders:Value
	If nCol > 0 .and. nCol <= LEN(oGrid:aHeaders)
		oGrid:DeleteColumn( nCol, /*lNoDelete*/ )
		oControlP:ComboHeaders:Rows := oGrid:aHeaders
		oControlP:ComboHeaders:Value := 1
		oControlP:ComboHeaders:Cargo := oControlP:ComboHeaders:Value
		UpdateColumns(oControlP:ComboHeaders, oGrid)
	Endif
Return
