*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (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 afficherniveau AS container 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	*<DefinedPropArrayMethod>
		*m: afficherniveau
		*p: ogrid
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderWidth = 0
		Height = 14
		Name = "afficherniveau"
		Width = 43
	*</PropValue>

	ADD OBJECT 'CmdN0' AS commandbutton WITH ;
		Caption = "0", ;
		FontSize = 8, ;
		Height = 14, ;
		Left = 0, ;
		Name = "CmdN0", ;
		Top = 0, ;
		Width = 13
		*< END OBJECT: BaseClass="commandbutton" />

	ADD OBJECT 'CmdN1' AS commandbutton WITH ;
		Caption = "1", ;
		FontSize = 8, ;
		Height = 14, ;
		Left = 15, ;
		Name = "CmdN1", ;
		Top = 0, ;
		Width = 13
		*< END OBJECT: BaseClass="commandbutton" />

	ADD OBJECT 'CmdN2' AS commandbutton WITH ;
		Caption = "2", ;
		FontSize = 8, ;
		Height = 14, ;
		Left = 30, ;
		Name = "CmdN2", ;
		Top = 0, ;
		Width = 13
		*< END OBJECT: BaseClass="commandbutton" />
	
	PROCEDURE afficherniveau
		LPARAMETERS nNiveau
		UPDATE (This.oGrid.recordSource) ;
			SET visible=(niveau<=nNiveau),;
				expanded=IIF(niveau<nNiveau AND expanded="N","O",IIF(niveau=nNiveau AND expanded="O","N",expanded))
		GO top
		This.oGrid.refresh
		This.oGrid.setFocus
	ENDPROC

	PROCEDURE Init
		FOR EACH oCtrl IN thisform.Controls
			IF LOWER(oCtrl.class) = "gridtreeview"
				this.oGrid = oCtrl
				exit
			ENDIF
		ENDFOR
		
	ENDPROC

	PROCEDURE CmdN0.Click
		This.parent.AfficherNiveau(0)
	ENDPROC

	PROCEDURE CmdN1.Click
		This.parent.AfficherNiveau(1)
	ENDPROC

	PROCEDURE CmdN2.Click
		This.parent.AfficherNiveau(2)
	ENDPROC

ENDDEFINE

DEFINE CLASS gridtreeview AS grid 
 	*< CLASSDATA: Baseclass="grid" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	#INCLUDE "gridtreeview.h"
	*<DefinedPropArrayMethod>
		*m: dynamic
		*m: nodeclick
		*p: niveau0
		*p: niveau1
		*p: niveau2
		*p: nrecno
	*</DefinedPropArrayMethod>

	*<PropValue>
		AllowHeaderSizing = .F.
		AllowRowSizing = .F.
		ColumnCount = 1
		DeleteMark = .F.
		GridLineColor = 128,128,128
		GridLines = 3
		Height = 345
		Highlight = .F.
		HighlightRow = .F.
		Name = "gridtreeview"
		nrecno = 0
		Panel = 1
		RecordMark = .F.
		RowHeight = 20
		ScrollBars = 2
		Width = 383
		Column1.ControlSource = ""
		Column1.Name = "ColumnTV"
		Column1.ReadOnly = .T.
		Column1.Sparse = .F.
		Column1.Visible = .T.
		Column1.Width = 135
	*</PropValue>

	ADD OBJECT 'ColumnTV.HeaderTV' AS header WITH ;
		Caption = "Clé", ;
		Name = "HeaderTV"
		*< END OBJECT: BaseClass="header" />
	
	PROCEDURE AfterRowColChange
		LPARAMETERS nColIndex
		this.nRecno=Recno(this.RecordSource)
		thisform.lockScreen= .T.
		this.columntv.Refresh
		thisform.lockScreen= .f.
		
	ENDPROC

	PROCEDURE Destroy
		SELECT (this.RecordSource)
		SET FILTER to
		
	ENDPROC

	PROCEDURE dynamic
		WITH Evaluate("this.columnTV."+ Evaluate(this.columnTV.dynamicCurrentControl)+".text1")
			IF Recno(this.RecordSource)=this.nRecno
				.disabledBackColor=Rgb(10,36,106)
				.DisabledForeColor=Rgb(255,255,255)
			ELSE
				.disabledBackColor=Rgb(255,255,255)
				.resetToDefault("DisabledForeColor")
			ENDIF
		ENDWITH
		RETURN Rgb(255,255,255)
		
	ENDPROC

	PROCEDURE Init
		thisform.lockScreen = .t.
		
		SELECT (this.recordsource)
		SET FILTER TO visible
		GO top
		
		WITH this.columnTV
		
			IF VARTYPE(.text1)="O"
				.RemoveObject("text1")
			ENDIF
			SET CLASSLIB TO (_GridTreeViewVCX) additive
			
			.AddObject("niveau0","niveau")
			.AddObject("niveau0p","niveau")
			.AddObject("niveau0m","niveau")
			
			.AddObject("niveau1","niveau1")
			.AddObject("niveau1p","niveau1")
			.AddObject("niveau1m","niveau1")
			
			.AddObject("niveau2","niveau2")
				
			CLEAR CLASSLIB _GridTreeViewVCX
			
			STORE JUSTPATH(_GridTreeViewVCX)+"\leaf.bmp" ;
				TO 	.niveau0.image.picture, ;
					.niveau1.image.picture ,;
					.niveau2.image.picture
			STORE JUSTPATH(_GridTreeViewVCX)+"\open.bmp" ;
				TO 	.niveau0m.image.picture, ;
					.niveau1m.image.picture 
			STORE JUSTPATH(_GridTreeViewVCX)+"\closed.bmp" ;
				TO 	.niveau0p.image.picture, ;
					.niveau1p.image.picture 
				
			STORE JUSTPATH(_GridTreeViewVCX)+"\minus.bmp" ;
				TO 	.niveau0m.plusMoins.picture, ;
					.niveau1m.plusMoins.picture	
			STORE JUSTPATH(_GridTreeViewVCX)+"\plus.bmp" ;
				TO  .niveau0p.plusMoins.picture, ;
					.niveau1p.plusMoins.picture 
				
			STORE .t. ;
				TO 	.niveau0m.plusMoins.visible, ;
					.niveau0p.plusMoins.visible ,;
			        .niveau1m.plusMoins.visible, ;
			       	.niveau1p.plusMoins.visible
		
			.DynamicCurrentControl = ["Niveau"+str(]+.parent.RecordSource+[.niveau,1)+chrtran(]+.parent.RecordSource+[.expanded,"ON ","mp")]
			.DynamicBackColor=[this.dynamic()]
		ENDWITH
		
		thisform.lockScreen = .f.
		
		
	ENDPROC

	PROCEDURE nodeclick
		LOCAL niveau, cExpanded, key
		
		SELECT (this.recordSource)
		cExpanded = ALLTRIM(expanded)
		IF NOT EMPTY(expanded)
			thisform.LockScreen = .T.
			m.key = EVALUATE(KEY())
			IF expanded="O"
				replace expanded WITH "N"
				SKIP 
				REPLACE visible WITH .f. while LIKE(TRIM(m.key) + '*', EVALUATE(KEY()))
			ELSE
				SET FILTER TO 
				replace expanded WITH "O"
				m.niveau = niveau
				SKIP
				SCAN REST WHILE LIKE(TRIM(m.key) + '*', EVALUATE(KEY()))
					IF niveau = m.niveau + 1
						replace visible with .t.
						cExpanded = Expanded
					ELSE
						IF m.cExpanded="O"
							replace visible with .t.
						ENDIF
					ENDIF
				ENDSCAN
			ENDIF
			SEEK m.key
			SET FILTER TO visible
			This.columnTV.dynamicCurrentControl=This.columnTV.dynamicCurrentControl
			this.refresh
			thisform.LockScreen = .f.
		ENDIF
		
	ENDPROC

ENDDEFINE

DEFINE CLASS niveau AS container 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	*<PropValue>
		BackStyle = 0
		BorderWidth = 0
		Height = 24
		Name = "niveau"
		Width = 361
	*</PropValue>

	ADD OBJECT 'Image' AS image WITH ;
		Height = 17, ;
		Left = 18, ;
		Name = "Image", ;
		Top = 2, ;
		Width = 17
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'PlusMoins' AS image WITH ;
		Height = 17, ;
		Left = 1, ;
		Name = "PlusMoins", ;
		Top = 2, ;
		Visible = .F., ;
		Width = 17
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'Text1' AS textbox WITH ;
		BackStyle = 1, ;
		BorderStyle = 0, ;
		DisabledBackColor = 255,255,255, ;
		DisabledForeColor = 0,0,0, ;
		Enabled = .F., ;
		FontBold = .T., ;
		Height = 21, ;
		Left = 33, ;
		Name = "Text1", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		Top = 0, ;
		Width = 327
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE DblClick
		this.parent.parent.nodeClick
	ENDPROC

	PROCEDURE Image.DblClick
		this.parent.parent.parent.nodeClick
	ENDPROC

	PROCEDURE PlusMoins.MouseDown
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		IF nButton=1
			this.parent.parent.parent.nodeClick
		ENDIF
	ENDPROC

	PROCEDURE Text1.DblClick
		this.parent.parent.parent.nodeClick
	ENDPROC

	PROCEDURE Text1.Init
		this.controlSource = this.parent.parent.parent.niveau0
	ENDPROC

ENDDEFINE

DEFINE CLASS niveau1 AS niveau OF "gridtreeview.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	*<PropValue>
		Height = 21
		Name = "niveau1"
		Text1.FontBold = .F.
		Text1.Height = 20
		Text1.Left = 58
		Text1.Name = "Text1"
		Text1.Top = 0
		Text1.Width = 301
		Text1.ZOrderSet = 0
		Image.Height = 17
		Image.Left = 42
		Image.Name = "Image"
		Image.Top = 2
		Image.Width = 15
		PlusMoins.Left = 26
		PlusMoins.Name = "PlusMoins"
		PlusMoins.Top = 2
	*</PropValue>

	ADD OBJECT 'LineV' AS line WITH ;
		BorderColor = 128,128,128, ;
		BorderWidth = 3, ;
		Height = 27, ;
		Left = 8, ;
		Name = "LineV", ;
		Top = -2, ;
		Width = 0, ;
		ZOrderSet = 1
		*< END OBJECT: BaseClass="line" />
	
	PROCEDURE Text1.Init
		this.controlSource = this.parent.parent.parent.niveau1
	ENDPROC

ENDDEFINE

DEFINE CLASS niveau2 AS niveau1 OF "gridtreeview.vcx" 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

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

	*<PropValue>
		Height = 21
		Name = "niveau2"
		Text1.DisabledForeColor = 128,128,128
		Text1.FontBold = .T.
		Text1.ForeColor = 128,128,128
		Text1.Height = 20
		Text1.Left = 80
		Text1.Name = "Text1"
		Text1.Top = 0
		Text1.Width = 268
		Text1.ZOrderSet = 0
		LINEV.Name = "LINEV"
		LINEV.ZOrderSet = 1
		Image.Left = 64
		Image.Name = "Image"
		Image.Top = 2
		PlusMoins.Left = 48
		PlusMoins.Name = "PlusMoins"
		PlusMoins.Top = 2
	*</PropValue>

	ADD OBJECT 'Line2V' AS line WITH ;
		BorderColor = 192,192,192, ;
		BorderWidth = 3, ;
		Height = 20, ;
		Left = 33, ;
		Name = "Line2V", ;
		Top = 0, ;
		Width = 0, ;
		ZOrderSet = 2
		*< END OBJECT: BaseClass="line" />
	
	PROCEDURE Text1.Init
		this.controlSource = this.parent.parent.parent.niveau2
	ENDPROC

ENDDEFINE
