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

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

	*<DefinedPropArrayMethod>
		*m: do_aranjeaza		&& Aranjeaza obiectele din container in functie de nivel.
		*m: nodeclick
		*p: cexplicatie		&& Numele campului care contine explicatia.
		*p: nexplicatie
		*p: nimagine1
		*p: nimagine2
		*p: ntip		&& 0 - nod neterminal, 1 - nod terminal
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		Anchor = 10
		BorderWidth = 0
		cexplicatie = 
		Height = 24
		Name = "element"
		nexplicatie = 0
		nimagine1 = 0
		nimagine2 = 0
		ntip = 0
		Width = 400
		_memberdata = <VFPData>
			<memberdata name="cexplicatie" type="Property" favorites="True"/>
			<memberdata name="nexplicatie" type="Property" favorites="True"/>
			<memberdata name="nimagine1" type="Property" favorites="True"/>
			<memberdata name="nimagine2" type="Property" favorites="True"/>
			<memberdata name="ntip" type="Property" favorites="True"/>
		</VFPData>
	*</PropValue>

	ADD OBJECT 'explicatie' AS _txbase WITH ;
		Anchor = 10, ;
		BackStyle = 0, ;
		BorderStyle = 0, ;
		DisabledBackColor = 255,255,255, ;
		DisabledForeColor = 0,0,0, ;
		Enabled = .F., ;
		FontBold = .T., ;
		Height = 21, ;
		Left = 33, ;
		Name = "explicatie", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		Top = 0, ;
		Width = 375
		*< END OBJECT: ClassLib="..\..\clase\_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'imagine1' AS _image WITH ;
		BackStyle = 0, ;
		Left = 1, ;
		Name = "imagine1", ;
		Top = 2, ;
		Visible = .F., ;
		Width = 17
		*< END OBJECT: ClassLib="..\..\clase\_baza.vcx" BaseClass="image" />

	ADD OBJECT 'imagine2' AS _image WITH ;
		BackStyle = 0, ;
		Left = 18, ;
		Name = "imagine2", ;
		Top = 2, ;
		Width = 17
		*< END OBJECT: ClassLib="..\..\clase\_baza.vcx" BaseClass="image" />

	ADD OBJECT 'nivel' AS _txbase WITH ;
		Alignment = 3, ;
		Anchor = 10, ;
		ControlSource = "nivel", ;
		Enabled = .F., ;
		Height = 21, ;
		Left = 352, ;
		Name = "nivel", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		Top = 0, ;
		Value = 1, ;
		Visible = .F., ;
		Width = 48
		*< END OBJECT: ClassLib="..\..\clase\_tx_base.vcx" BaseClass="textbox" />
	
	PROCEDURE DblClick
		This.nodeClick()
	ENDPROC

	PROCEDURE do_aranjeaza		&& Aranjeaza obiectele din container in functie de nivel.
		lnNivel = This.nivel.Value
		This.imagine1.Left = This.nimagine1 + 15 * lnNivel
		This.imagine2.Left = This.nimagine2 + 15 * lnNivel
		This.explicatie.Left = This.nexplicatie + 15 * lnNivel
		
	ENDPROC

	PROCEDURE Init
		Lparameters tnTip,tcExplicatie
		*!*	tnTip
		*!*	0	-	frunza
		*!*	1	-	inchis
		*!*	2	-	deschis
		Local lnTip
		lnTip = Nvl(tnTip,0)
		With This
			.ntip = lnTip
			.cExplicatie = Iif(Empty(Nvl(tcExplicatie,[])),[explicatie],tcExplicatie)
			Do Case
			Case .ntip = 2
				.imagine1.Picture = [GTV_MINUS.bmp]
				.imagine1.Visible = .T.
				.imagine2.Picture = [GTV_DESCHIS.bmp]
			Case .ntip = 1
				.imagine1.Picture = [GTV_PLUS.bmp]
				.imagine1.Visible = .T.
				.imagine2.Picture = [GTV_INCHIS.bmp]
			Otherwise
				.imagine2.Picture = [GTV_FRUNZA.bmp]
			Endcase
		
			.nimagine1 = .imagine1.Left
			.nimagine2 = .imagine2.Left
			.nexplicatie = .explicatie.Left
		
			.explicatie.ControlSource = .cExplicatie
		Endwith
	ENDPROC

	PROCEDURE nodeclick
		If This.ntip <> 0
			This.Parent.Parent.nodeclick()
		Endif
	ENDPROC

	PROCEDURE explicatie.DblClick
		This.Parent.nodeClick
	ENDPROC

	PROCEDURE imagine1.MouseDown
		Lparameters nButton, nShift, nXCoord, nYCoord
		If nButton=1
			This.Parent.nodeClick
		Endif
	ENDPROC

	PROCEDURE imagine2.DblClick
		This.Parent.nodeClick
	ENDPROC

	PROCEDURE nivel.DblClick
		This.Parent.nodeclick()
		
	ENDPROC

ENDDEFINE

DEFINE CLASS gridtreeview AS _grdbase OF "..\..\clase\_grd_base.vcx" 
 	*< CLASSDATA: Baseclass="grid" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	*<DefinedPropArrayMethod>
		*m: do_initializeaza
		*m: dynamic
		*m: nodeclick
		*p: cexplicatie		&& Denumirea campului care contine explicatia.
		*p: cid		&& Denumirea campului care contine id-ul.
		*p: crgbbackcolor
		*p: cseparator		&& Caracterul / caracterele folosite ca separator pentru campul tata.
		*p: ldeschise		&& .T. daca toate ramurile sunt deschise, .F. daca sunt inchise
		*p: nrecno
		*p: _memberdata		&& XML Metadata for customizable properties
	*</DefinedPropArrayMethod>

	*<PropValue>
		AllowHeaderSizing = .F.
		AllowRowSizing = .F.
		cexplicatie = 
		cid = 
		ColumnCount = 1
		crgbbackcolor = 255,255,255
		cseparator = 
		DeleteMark = .F.
		FontName = "Arial Narrow"
		GridLineColor = 128,128,128
		Highlight = .F.
		HighlightStyle = 1
		Name = "gridtreeview"
		nrecno = 0
		RecordMark = .F.
		_memberdata = <VFPData>
			<memberdata name="cexplicatie" type="Property" favorites="True"/>
			<memberdata name="cid" type="Property" favorites="True"/>
			<memberdata name="cseparator" type="Property" favorites="True"/>
		</VFPData>
		Column1.FontName = "Arial Narrow"
		Column1.Name = "ColumnTV"
		Column1.ReadOnly = .T.
		Column1.Sparse = .F.
		Column1.Width = 150
	*</PropValue>

	ADD OBJECT 'ColumnTV.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Header1", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'ColumnTV.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE AfterRowColChange
		Lparameters nColIndex
		If Inlist(This.RowColChange,0,1,3)
			This.nRecno=Recno(This.RecordSource)
			This.Refresh
		Endif
	ENDPROC

	PROCEDURE Destroy
		lcCursor = This.RecordSource
		If Used(lcCursor)
			Select (lcCursor)
			Set Filter To
		Endif
	ENDPROC

	PROCEDURE do_initializeaza
		*!*	daca tlGridSalvat = .F., atunci salvarea se face aici
		*!*	daca tlGridSalvat = .T., atunci salvarea a fost facuta deja, iar tcCursor trebuie sa aiba o valoare
		Lparameters tlGridSalvat,tcCursor
		*!* 	Campuri obligatorii in cursor :
		*!*	id		( in this.cid )
		*!*	cheie	( in this.cexplicatie )
		*!*	nivel
		*!* cale	( toata calea de la primul nod pana la tatal nodului actual separate prin this.cseparator )
		*!*	tip		( 0 = nod , 1 = frunza )
		_Screen.LockScreen = .T.
		If !tlGridSalvat
			lcCursor = This.RecordSource
		Else
			lcCursor = tcCursor
		Endif
		lcColoanaExplicatie = [a.]+This.cexplicatie
		lcSeparator = This.cseparator
		
		If !tlGridSalvat
			save_grid_tag(This)
		Endif
		Select Alltrim(Nvl(a.cale,''))+lcSeparator As crtordine,a.*,Iif(a.tip=1,"X",Iif(This.ldeschise,"D","N")) As deschis,;
			IIF(This.ldeschise,.T.,Iif(a.nivel=1,.T.,.F.)) As vizibil From (lcCursor) a Order By 1 ;
			INTO Cursor (lcCursor) Readwrite
		Select (lcCursor)
		Set Filter To vizibil
		Go Top
		If !tlGridSalvat
			restore_grid_tag(This)
		Endif
		
		With This.columntv
			.DynamicCurrentControl = ["tip"+ALLTRIM(CHRTRAN(]+lcCursor+[.deschis,"DNX","di"))]
			.DynamicBackColor=[this.dynamic()]
		Endwith
		_Screen.LockScreen = .F.
		
	ENDPROC

	PROCEDURE dynamic
		With Evaluate("this.columnTV."+ Evaluate(This.columnTV.DynamicCurrentControl))
			.do_aranjeaza()
			lcRgb = This.Objects(2).DynamicBackColor
		*!*		If Recno(This.RecordSource)=This.nRecno
		*!*			lcRgb = [RGB(]+Alltrim(This.crgbbackcolor)+[)]
		*!*		Else
		*!*			lcRgb = [Rgb(255,255,255)]
		*!*		Endif
		*!*		With .explicatie
		*!*			.BackColor = &lcRgb
		*!*			.Refresh()
		*!*		Endwith
		Endwith
		Return &lcRgb
	ENDPROC

	PROCEDURE Init
		lcCursor = This.RecordSource
		With This.ColumnTv
			If Vartype(.text1)="O"
				.RemoveObject("text1")
			Endif
		
			.AddObject("tip","element",0,This.cexplicatie)
			.AddObject("tipi","element",1,This.cexplicatie)
			.AddObject("tipd","element",2,This.cexplicatie)
		
		Endwith
	ENDPROC

	PROCEDURE nodeclick
		Local lnTip,lcCheie,lnNivel,lnNivelStop,lnNivelPrec, lnNivelMaxim
		lnNivelMaxim = 50
		Dimension laVizibil(lnNivelMaxim)
		lcColoanaID = This.cid
		*!*	lcColoanaCheie = This.cexplicatie
		*!*	lcSeparator = This.cseparator
		lnNivelStop = lnNivelMaxim
		
		Select (This.RecordSource)
		If !Empty(deschis)
			Thisform.LockScreen = .T.
			lnId = &lcColoanaID
		*!*		lcCheie = Lower(Alltrim(cale)+Alltrim(&lcColoanaCheie)+ALLTRIM(lcSeparator)+[*])
			lcCheie = LOWER(ALLTRIM(crtordine)+[*])
			If deschis = "D"
				Replace deschis With "N"
				Replace vizibil With .F. For Like(lcCheie,Lower(cale))
			Else
				Set Filter To
				Replace deschis With "D"
				laVizibil(nivel+1) = .T.
				lnNivelPrec = nivel
				Skip
				Scan Rest For Like(lcCheie,Lower(cale))
					If nivel <= lnNivelStop
						lnNivelStop = lnNivelMaxim
						If lnNivelPrec > nivel
							For i = nivel + 1 To lnNivelPrec
								laVizibil(i) = .F.
							Endfor
						Else
							lnNivelPrec = nivel
						Endif
						Replace vizibil With laVizibil(nivel)
						If Alltrim(deschis) = "D"
							laVizibil(nivel+1) = .T.
						Endif
						If Alltrim(deschis) = "N"
							lnNivelStop = nivel
						Endif
					Endif
				Endscan
			Endif
			Set Filter To vizibil
			Locate For &lcColoanaID = lnId
			This.columnTV.DynamicCurrentControl=This.columnTV.DynamicCurrentControl
			This.Refresh
			Thisform.LockScreen = .F.
		Endif
		Release laVizibil
	ENDPROC

ENDDEFINE
