% Written by Josh Siegel
% Demo of brets scroll item code

systemdict begin
    /watchme {
        systemdict /watched currentprocess put
    } def
    /stopwatch {
        systemdict /watched undef
    } def
end

/oldsta () store

/gork {
    /arr [] store
    /str () store

    systemdict /watched known {
        watched /OperandStack get
        {
            dup type cvlit /nametype eq {
                255 string cvs (/) exch append
            } {
                255 string cvs
            } ifelse

            dup [ exch ] arr exch append /arr exch store
            str append /str exch store

            pause
        } forall
        oldsta str eq not {
            /oldsta str store
            arr /setdata foo1 send
        } if
    } if
} def

/xsize 0 def
/ysize 0 def

/main_win framebuffer /new DefaultWindow send def

{ 
    /IconImage /galaxy def % Give it an icon
    100 500 500 400 reshape % Give it a size
    /PaintClient {
		gsave
			can setcanvas initmatrix clippath pathbbox
			/ysize exch store
			/xsize exch store
			{ 0 0 xsize ysize reshape } foo1 send
        	item_array paintitems
		grestore
    } def
} main_win send

/can
main_win /ClientCanvas get
def

/foo1 can {
%    ItemValue (%\n) printf
} /new ScrollDataItem send def
{
    /AllowMultipleSelect? false def
    /HScrollbar? false def
    /BufferColor .9 .9 .9 rgbcolor def
    /ItemTextColor 0 0 1 rgbcolor def
    /ItemHighLightColor .7 .7 .7 rgbcolor def
    50 50 200 200 reshape
    /ItemLabel (Stack) def
    /ItemLabelFont /Times-Bold findfont 24 scalefont def
    /ItemLabelColor 1 0 0 rgbcolor def
    /ShowItemSeperators true def
	[] setdata
} foo1 send

/item_array [foo1] def
/item_manager item_array forkitems def

/map main_win send

/watcher
{
    {
% Wait till somebody wants to be watched

        {
            systemdict /watched known
            {
                exit
            } if
            .0166 sleep
        } loop

% watch them

        {
            .0166 sleep
            systemdict /watched known not {
                exit
            } if
            watched /State get /zombie eq {
                stopwatch
            } {
                gork
            } ifelse
        } loop
    } loop
} fork
def

