;Menu Test PlugIn

	incdir	Include:
	include	exec/initializers.i
	include	scalos_class.i
	include	scalos_macros.i
	include iconobject.i


Startlib:
	moveq	#0,d0
	rts

RomTag:
	dc.w	$4afc		;RT_MATCHWORD
	dc.l	RomTag		;RT_MATCHTAG
	dc.l	endep		;RT_ENDSKIP
	dc.b	$80		;RT_FLAGS
	dc.b	39		;RT_VERSION
	dc.b	9		;RT_TYPE
	dc.b	0		;RT_PRI
	dc.l	libname		;RT_NAME
	dc.l	idstring	;RT_IDSTRING
	dc.l	init		;RT_INIT

libname:
	dc.b	'sorted_cleanup.plugin',0
	even
idstring:
	dc.b	'$VER: sorted_cleanup.plugin 39.1 (28-05-97)',10
	dc.b	'(c)1997 by ALiENDESiGN',0
	cnop	0,4
init:
	dc.l	34			;BaseSize
	dc.l	functable
	dc.l	datatable
	dc.l	InitRoutine

functable:
	dc.l	Open
	dc.l	Close
	dc.l	Expunge
	dc.l	Startlib
	dc.l	menufunction

	dc.l	-1

datatable:
	INITBYTE	8,9			;LN_TYPE,NT_LIBRARY
	INITLONG	10,libname		;LN_NAME,LibName
	INITBYTE	14,3			;LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
	INITWORD	20,39			;LIB_VERSION,VERSION
	INITWORD	22,0			;LIB_REVISION,REVISION
	INITLONG	24,idstring		;LIB_IDSTRING,IDString
	dc.l	0


InitRoutine:
	movem.l	d0-a6,-(sp)
	move.l	a0,seglist
	move.l	4.w,a6
	lea	scaname(pc),a1
	moveq	#39,d0
	jsr	-552(a6)		;OpenLibrary
	move.l	d0,scabase
	beq.s	.openerror
	lea	utilname(pc),a1
	moveq	#39,d0
	jsr	-552(a6)		;OpenLibrary
	move.l	d0,utilbase
	lea	intname(pc),a1
	moveq	#39,d0
	jsr	-552(a6)		;OpenLibrary
	move.l	d0,intbase

	movem.l	(sp)+,d0-a6
	rts
.openerror:
	movem.l	(sp)+,d0-a6
	moveq	#0,d0
	rts

Open:					; ( libptr:a6, version:d0 )
	addq.w	#1,32(a6)		; LIB_OPENCNT
	bclr	#3,14(a6)		; LIB_FLAGS
	move.l	a6,d0
	rts

Close:					; ( libptr:a6 )
	subq.w	#1,32(a6)		; LIB_OPENCNT
	bne.s	.nooneopen
	btst	#3,14(a6)		; LIB_FLAGS
	beq.s	.nooneopen
	bsr.s	Expunge
.nooneopen:
	moveq	#0,d0
	rts

Expunge:				; ( libptr: a6 )
	tst.w	32(a6)
	beq.s	.nooneopen2
	bset	#3,14(a6)
	moveq	#0,d0
	rts

.nooneopen2:
	movem.l	d2/a4/a5/a6,-(sp)
	move.l	seglist(pc),d2
	move.l	a6,a4
	move.l	4.w,a6
	move.l	a4,a1
	jsr	-252(a6)		;Remove
	moveq	#0,d0
	move.l	a4,a1
	move.w	16(a4),d0		;LIB_NEGSIZE
	sub.w	d0,a1
	add.w	18(a4),d0		;LIB_POSSIZE
	jsr	-210(a6)		;FreeMem

	move.l	scabase(pc),a1
	jsr	-414(a6)		;CloseLibrary
	move.l	utilbase(pc),a1
	jsr	-414(a6)		;CloseLibrary

	move.l	d2,d0
	movem.l	(sp)+,d2/a4/a5/a6
	rts

;----------------------------- GetClass Info --------------------------------

;Input: A0 = WindowTask, A1 = IconNode or NULL
;Ouput: none
menufunction:
	movem.l	d1-a6,-(a7)
	move.l	a0,a5

	move.l	4.w,a6
	move.l	iconsem(a5),a0
	jsr	-564(a6)			;ObtainSemaphore
	move.l	lateiconlist(a5),a2
	move.l	scabase(pc),a6
.loop:
	cmp.w	#0,a2
	beq.s	.loopend
	lea	lateiconlist(a5),a0
	lea	iconlist(a5),a1
	move.l	a2,d0
	move.l	(a2),a2
	jsr	-90(a6)				;sca_MoveNode
	bra.s	.loop
.loopend:
	move.l	iconlist(a5),lateiconlist(a5)
	clr.l	iconlist(a5)
	lea	lateiconlist(a5),a0
	lea	comparename(pc),a1
	moveq	#-1,d0
	jsr	-36(a6)				;sca_SortNodes
	
	move.l	4.w,a6
	move.l	iconsem(a5),a0
	jsr	-570(a6)			;ReleaseSemaphore

	clr.l	xoffset(a5)
	move.l	iconstartinfo(a5),a0
	move.l	xoffset(a5),startinfo\.xoffset(a0)

	DoMethod	mainobject(a5),#SCCM_IconWin_Redraw,#0	;Clear the background

	DoMethod	mainobject(a5),#SCCM_IconWin_CleanUp

	DoMethod	mainobject(a5),#SCCM_IconWin_SetVirtSize,#3

	movem.l	(a7)+,d1-a6
	rts
	
comparename:
	dc.l	0,0
	dc.l	comparenamefunc
	dc.l	0,0

comparenamefunc:
	move.l	a6,-(a7)
	tst.l	intbase
	beq.s	.noint
	move.l	a1,-(a7)
	clr.l	-(a7)
	move.l	#IDTA_Type,d0
	move.l	iconnode\.icon(a1),a0
	move.l	a7,a1
	move.l	intbase(pc),a6
	jsr	-654(a6)			;GetAttr
	clr.l	-(a7)
	move.l	#IDTA_Type,d0
	move.l	iconnode\.icon(a2),a0
	move.l	a7,a1
	jsr	-654(a6)			;GetAttr
	move.l	(a7)+,d0
	move.l	(a7)+,d1
	cmp.l	#2,d0				;Drawer ?
	beq.s	.firstdir
	cmp.l	#2,d1				;Drawer ?
	bne.s	.files
	bra.s	.greater
.firstdir:
	cmp.l	#2,d1				;Drawer ?
	bne.s	.smaller
.files:	move.l	(a7)+,a1
.noint:	move.l	iconnode\.name(a2),a0
	move.l	iconnode\.name(a1),a1
	move.l	utilbase(pc),a6
	jsr	-162(a6)			;Stricmp
	move.l	(a7)+,a6
	rts
.greater:
	moveq	#1,d0
	bra.s	.end
.smaller:
	moveq	#-1,d0
.end:	addq.w	#4,a7
	move.l	(a7)+,a6
	rts


;--------------------------- DoMethod --------------------------------------

_DoMethod:			;Standard-Function !! DON'T REMOVE !!
	movem.l	d1/a0-a2/a6,-(a7)
	move.l	(a1)+,a2
	cmp.w	#0,a2
	beq.s	.do
	move.l	-4(a2),a0
	move.l	8(a0),a6
	jsr	(a6)
	movem.l	(a7)+,d1/a0-a2/a6
	rts
.do:	moveq	#0,d0
	movem.l	(a7)+,d1/a0-a2/a6
	rts

;----------------------------------------------------------------------------

	RSRESET				;BaseMem
			rs.b	36
xoffset:		rs.w	1		;virtuell x-offset
yoffset:		rs.w	1		;virtuell y-offset
mainobject:		rs.l	1		;IconWindow Object
winobject:		rs.l	1		;Window Object
iconwin:		rs.l	1		;the window of the icons
iconlist:		rs.l	1		;current list of all icons (IconNode)
lateiconlist:		rs.l	1		;for position rerender (IconNode)
iconsem:		rs.l	1		;Semaphore for Iconlist
iconport:		rs.l	1		;Windows MsgPort
winsem:			rs.l	1		;avoid window from closing
iconstartinfo:		rs.l	1		;WindowNode for this window

	RSRESET				;IconNode
iconnode:	rs.l	2		;next and previous node
.icon:		rs.l	1		;IconObject
.name:		rs.l	1		;Pointer to the name (same as DTA_NAME)
.devilist:	rs.l	1		;DevList node
.lock:		rs.l	1		;Dirlock for Backdrops
.iconlist:	rs.l	1		;Linked icons
.flags:		rs.w	1		;Flags
.userdata:	rs.w	1		;One word Userdata

	RSRESET				;StartInfo
startinfo:	rs.l	2		;next and previous node
.task:		rs.l	1		;Window Task
.lock:		rs.l	1		;CurrentDir Lock
.window:	rs.l	1		;Storebuffer for Window
.msgport:	rs.l	1		;MessagePort
.left:		rs.w	1		;Window Sizes
.top:		rs.w	1
.width:		rs.w	1
.height:	rs.w	1
.xoffset:	rs.w	1		;virual position
.yoffset:	rs.w	1
.pattern:	rs.l	1		;Pointer to Pattern node
.basemem:	rs.l	1		;ONLY ACCESS USING THE RIGHT SEMAPHORE!
.name:		rs.l	1		;Directory Name
.title:		rs.l	1		;Title-Pattern
.classname:	rs.l	1		;Scalos-Class name
.class:		rs.l	1		;BOOPSI-Class if classname is NULL
.flags:		rs.w	1
.patternnum:	rs.w	1		;Number of Pattern
.viewmodes:	rs.b	1		;DrawerData ViewMode
.type:		rs.b	1		;WindowType

;----------------------------------------------------------------------------

seglist:	dc.l	0
scabase:	dc.l	0
utilbase:	dc.l	0
intbase:	dc.l	0

scaname:	dc.b	'scalos.library',0
utilname:	dc.b	'utility.library',0
intname:	dc.b	'intuition.library',0

endep:

