;------------------------------------------
; Xgr[
;------------------------------------------

#module

#uselib "user32.dll"
#func CreateWindowEx "CreateWindowExA" int, str, str, int, int, int, int, int, int, int, int, int
#func ScreenToClient "ScreenToClient" int, var


	;------------------------------------------
	; sel_listview
	;
	; p1 : listview id
	;------------------------------------------
	#deffunc sel_listview int p1

	stt = hlist
	hlist = p1
	return


	;------------------------------------------
	; listview
	;
	; p1 : width
	; p2 : height
	; p3 : style
	; p4 : window handle
	;------------------------------------------
	#deffunc listview int p1, int p2, int p3, int p4
	mref stt, 64		; stat

	if p4 : prm = p4 : else : prm = hwnd
	CreateWindowEx $200, "SysListView32", "", (p3 & $FFFF | $8000) | $52000000, ginfo(22), ginfo(23), p1, p2, prm, 0, hinstance, 0
	hlist = stat

	// prm : ex style
	prm = (p3 >> 16) & $FFFF
	if prm : sendmsg hlist, $1036, 0, prm

	mref bmscr, 67 : sendmsg hlist, $30, bmscr(38), 1	; WUItHggꍇ̓RgAEg
	stt = hlist
	return


	;------------------------------------------
	; listadd
	;
	; p1 : item index
	; p2 : item text
	; p3 : subitem
	; p4 : image index
	; p5 : state
	; p6 : lparam
	;------------------------------------------
	#deffunc listadd int p1, str p2, int p3, int p4, int p5, int p6

	text = p2

	// lvitem : LVITEM struct
	// prm    : message code
	lvitem = 9, p1, p3, p5, 0, varptr(text)
	if p3 {
		prm = $1006
	} else {
		lvitem.0 += 6
		lvitem.7 = p4, p6
		prm = $1007
	}
	sendmsg hlist, prm, 0, varptr(lvitem)
	return


	;------------------------------------------
	; listdel
	;
	; p1 : item index
	;------------------------------------------
	#deffunc listdel int p1

	if p1 == -1 : prm = $1009 : else : prm = $1008
	sendmsg hlist, prm, p1, 0
	return


	;------------------------------------------
	; listaddcl
	;
	; p1 : column index
	; p2 : column text
	; p3 : width
	; p4 : format
	;------------------------------------------
	#deffunc listaddcl int p1, str p2, int p3, int p4

	text = p2

	// lvcolumn : LVCOLUMN struct
	lvcolumn = 15, p4, p3, varptr(text), 0, p1
	if p3 == 0 : lvcolumn.2 = 100
	sendmsg hlist, $101B, p1, varptr(lvcolumn)
	return


	;------------------------------------------
	; listdelcl
	;
	; p1 : column index
	;------------------------------------------
	#deffunc listdelcl int p1

	sendmsg hlist, $101C, p1, 0
	return


	;------------------------------------------
	; listsel
	;
	; p1 : item index
	; p2 : flag
	;------------------------------------------
	#deffunc listsel int p1, int p2

	// lvitem : LVITEM struct
	lvitem = 8, p1, 0, p2, -1
	if lvitem.3 == 0 {
		lvitem.3 = 3
	} else {
		if lvitem.3 == -1 : lvitem.3 = 0
	}
	sendmsg hlist, $1006, 0, varptr(lvitem)
	return


	;------------------------------------------
	; listmax
	;
	; p1 : buffer
	; p2 : flag
	;------------------------------------------
	#deffunc listmax var p1, int p2

	// prm : message code
	if p2 : prm = $1028 : else : prm = $1004
	sendmsg hlist, prm, 0, 0
	p1 = stat
	return


	;------------------------------------------
	; listget
	;
	; p1 : buffer
	; p2 : item index
	; p3 : flag
	; p4 : buffer size
	; p5 : subitem
	;------------------------------------------
	#deffunc listget var p1, int p2, int p3, int p4, int p5

	// lvitem : LVITEM struct
	// prm    : message code
	if p3 >= 5 {
		prm = $1005
		if p3 == 5 {
			lvitem = 5, p2, p5, 0, 0, varptr(p1), p4
			if p4 == 0 : lvitem.6 = 64
			if p4 < 0 {
				lvitem.0 = 1
				prm ++
			}
			sendmsg hlist, prm, 0, varptr(lvitem)
			stt = lvitem.8
		} else {
			lvitem = 4, p2
			if p4 {
				lvitem.8 = p1
				prm ++
			}
			sendmsg hlist, prm, 0, varptr(lvitem)
			p1 = lvitem.8
			stt = 0
		}
	}else{

		// prm : flag of search
		prm = 0, $100, $200, $400, $800
		sendmsg hlist, $100C, p2, prm(p3) + p4
		p1 = stat
		stt = 0
	}
	return


	;------------------------------------------
	; listimglist
	;
	; p1 : image list
	; p2 : big(0) or small(1)
	;------------------------------------------
	#deffunc listimglist int p1, int p2

	sendmsg hlist, $1003, p2, p1
	return


	;------------------------------------------
	; listhit
	;
	; p1 : flag
	;------------------------------------------
	#deffunc listhit int p1

	// prm : POINT struct
	prm = ginfo(0), ginfo(1)
	ScreenToClient hlist, prm

	if p1 : prm.2 = p1 : else : prm.2 = 14
	prm.3 = 0
	sendmsg hlist, $1012, 0, varptr(prm)
	return


#global
