(include "sci.sh")
(use "Main")
(use "DColorButton")
(use "n255")
(use "Print")
(use "DIcon")
(use "Obj")
(script 921)



(procedure public (proc921_0 param1)
    (Print:
        addText(rest param1)
        init()
    )
)


(procedure public (proc921_1 param1)
    (Print:
        addTextF(rest param1)
        init()
    )
)


(procedure public (proc921_2 param1 param2 param3 param4)
    (if ((Print:
        font(
            (if (> paramTotal 3)
                param4
            )(else
                gFont
            )
)
        addText(
            (if ((> paramTotal 2) and param3)
                param3
            )(else
                "LOOKUP_ERROR"
            )
)
        addEdit(param1 param2 0 12 param1)
        init()
    )
)
        StrLen(param1)
    )
)


(procedure public (proc921_3 param1 param2)
    (var temp0, temp1, temp2, temp3)
    = temp0 (= temp1 StrLen(param1))
    = temp2 0
    = temp3 0
    (while (< temp3 temp1)
        (if (== StrAt(param1 temp3) 37)
            (switch (StrAt(param1 ++temp3))
                (case 100
                    = temp0 (+ temp0 5)
                )
                (case 120
                    = temp0 (+ temp0 4)
                )
                (case 115
                    = temp0 (+ temp0 StrLen(param2[temp2]))
                )
            )
            ++temp2
        )
        ++temp3
    )
    return ++temp0
)


(class Print of Obj
    (properties
        dialog 0
        window 0
        title 0
        mode 0
        font -1
        width 0
        x -1
        y -1
        ticks 0
        caller 0
        retValue 0
        modeless 0
        first 0
        saveCursor 0
    )

    (method (init theCaller param2)
        = caller 0
        (if (paramTotal)
            = caller theCaller
        )
        (if (> paramTotal 1)
            (self:addText(rest param2))
        )
        (if (not modeless)
            (if (not IsObject(global92))
                = global92 (send ((EventHandler:new())):name("prints"))
            )
            (send global92:add(self))
        )
        (self:showSelf())
    )


    (method (doit)
        (send dialog:eachElementDo(57))
    )


    (method (dispose)
        (if (global92 and (send global92:contains(self)))
            (send global92:delete(self))
            (if ((send global92:isEmpty()))
                (send global92:dispose())
                = global92 0
            )
        )
        (if (title)
            Memory(3 title)
        )
        = width (= mode (= title (= first (= saveCursor (= window 0)))))
        = x (= y -1)
        = modeless 0
        (send gSounds:pause(0))
        (super:dispose())
    )


    (method (showSelf)
        (var theFirst, temp1, temp2, temp3, temp4)
        (if (saveCursor)
            (send gSQ5:setCursor(999))
        )
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (send dialog:
            window(
                (if (window)
                )(else
                    gSq5Win
                )
)
            name("PODialog")
            caller(self)
        )
        (send dialog:
            text(title)
            time(ticks)
            setSize()
        )
        (send dialog:center())
        = temp3 
            (if (== x -1)
                (send dialog:nsLeft)
            )(else
                x
            )
        (send dialog:moveTo(temp3 (= temp4 
                (if (== y -1)
                    (send dialog:nsTop)
                )(else
                    y
                )
)))
        = temp1 GetPort()
        (send dialog:open(
            (if (title)
                4
            )(else
                0
            )
 15))
        return 
            (if (modeless)
                = global41 GetPort()
                SetPort(temp1)
                = gDialog dialog
            )(else
                (send gSounds:pause(1))
                (if (not = theFirst first)
                    (if ((= theFirst (send dialog:firstTrue(191 1))) and not (send dialog:firstTrue(191 2)))
                        (send theFirst:state((| (send theFirst:state) $0002)))
                    )
                )(else
                    (if (not IsObject(theFirst))
                        = theFirst (send dialog:at(theFirst))
                    )
                )
                = retValue (send dialog:doit(theFirst))
                SetPort(temp1)
                (if (== retValue -1)
                    = retValue 0
                )(else
                    (if (IsObject(retValue) and (send retValue:isKindOf(DButton)))
                        = retValue (send retValue:value)
                    )(else
                        (if (not (send dialog:theItem))
                            = retValue 1
                        )
                    )
                )
                (if (saveCursor)
                    (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor)))
                )
                (send dialog:dispose())
                return retValue
            )
    )


    (method (addButton param1 param2)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8)
        (asm
            pToa    dialog
            not     
            bnt     code_0158
            pushi   #new
            pushi   0
            class   Dialog
            send    4
            aTop    dialog
code_0158:  pTos    font
            ldi     65535
            eq?     
            bnt     code_0163
            lag     gFont
            aTop    font
code_0163:  lsp     paramTotal
            ldi     4
            gt?     
            bnt     code_01f6
            ldi     0
            lapi    param2
            sat     temp0
            ldi     1
            lapi    param2
            sat     temp1
            ldi     2
            lapi    param2
            sat     temp2
            ldi     3
            lapi    param2
            bnt     code_0189
            ldi     3
            lapi    param2
            jmp     code_018b
code_0189:  ldi     1
code_018b:  sat     temp3
            ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lag     gModNum
            sat     temp6
            lsp     paramTotal
            ldi     5
            gt?     
            bnt     code_01c0
            ldi     4
            lapi    param2
            sat     temp4
            lsp     paramTotal
            ldi     6
            gt?     
            bnt     code_01c0
            ldi     5
            lapi    param2
            sat     temp5
            lsp     paramTotal
            ldi     7
            gt?     
            bnt     code_01c0
            ldi     6
            lapi    param2
            sat     temp6
code_01c0:  pushi   6
            pushi   2
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            callk   GetMessage, 12
            sat     temp8
            bnt     code_0235
            pushi   2
            pushi   1
            push    
            callk   Memory, 4
            sat     temp7
            pushi   7
            pushi   0
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            push    
            callk   GetMessage, 14
            not     
            bnt     code_0235
            ldi     0
            sat     temp7
            jmp     code_0235
code_01f6:  ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lsp     paramTotal
            ldi     2
            gt?     
            bnt     code_0218
            ldi     1
            lapi    param2
            sat     temp4
            lsp     paramTotal
            ldi     3
            gt?     
            bnt     code_0218
            ldi     2
            lapi    param2
            sat     temp5
code_0218:  pushi   2
            pushi   1
            pushi   1
            ldi     0
            lspi    param2
            callk   StrLen, 2
            push    
            ldi     1
            add     
            push    
            callk   Memory, 4
            sat     temp7
            pushi   2
            push    
            ldi     0
            lspi    param2
            callk   StrCpy, 4
code_0235:  lat     temp7
            bnt     code_0273
            pushi   118
            pushi   1
            pushi   #value
            pushi   1
            lsp     param1
            pushi   30
            pushi   1
            pTos    font
            pushi   23
            pushi   1
            push    
            pushi   186
            pushi   0
            pushi   188
            pushi   2
            pushi   4
            lat     temp4
            add     
            push    
            pushi   4
            lat     temp5
            add     
            push    
            pushi   117
            pushi   0
            pushi   #new
            pushi   0
            class   DButton
            send    4
            send    34
            push    
            pushi   186
            pushi   0
            pToa    dialog
            send    10
code_0273:  ret     
        )
    )


    (method (addColorButton param1 param2)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12, temp13, temp14)
        (asm
            pToa    dialog
            not     
            bnt     code_0284
            pushi   #new
            pushi   0
            class   Dialog
            send    4
            aTop    dialog
code_0284:  pTos    font
            ldi     65535
            eq?     
            bnt     code_028f
            lag     gFont
            aTop    font
code_028f:  ldi     0
            sat     temp9
            ldi     15
            sat     temp11
            ldi     31
            sat     temp13
            ldi     5
            sat     temp10
            ldi     5
            sat     temp12
            ldi     5
            sat     temp14
            pushi   1
            ldi     0
            lspi    param2
            callk   Abs, 2
            push    
            ldi     1000
            lt?     
            bnt     code_0395
            ldi     0
            lapi    param2
            sat     temp0
            ldi     1
            lapi    param2
            sat     temp1
            ldi     2
            lapi    param2
            sat     temp2
            ldi     3
            lapi    param2
            bnt     code_02d5
            ldi     3
            lapi    param2
            jmp     code_02d7
code_02d5:  ldi     1
code_02d7:  sat     temp3
            ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lag     gModNum
            sat     temp6
            lsp     paramTotal
            ldi     5
            gt?     
            bnt     code_035c
            ldi     4
            lapi    param2
            sat     temp4
            lsp     paramTotal
            ldi     6
            gt?     
            bnt     code_035c
            ldi     5
            lapi    param2
            sat     temp5
            lsp     paramTotal
            ldi     7
            gt?     
            bnt     code_035c
            ldi     6
            lapi    param2
            sat     temp6
            lsp     paramTotal
            ldi     8
            gt?     
            bnt     code_035c
            ldi     7
            lapi    param2
            sat     temp9
            lsp     paramTotal
            ldi     9
            gt?     
            bnt     code_035c
            ldi     8
            lapi    param2
            sat     temp11
            lsp     paramTotal
            ldi     10
            gt?     
            bnt     code_035c
            ldi     9
            lapi    param2
            sat     temp13
            lsp     paramTotal
            ldi     11
            gt?     
            bnt     code_035c
            ldi     10
            lapi    param2
            sat     temp10
            lsp     paramTotal
            ldi     12
            gt?     
            bnt     code_035c
            ldi     11
            lapi    param2
            sat     temp12
            lsp     paramTotal
            ldi     13
            gt?     
            bnt     code_035c
            ldi     12
            lapi    param2
            sat     temp14
code_035c:  pushi   6
            pushi   2
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            callk   GetMessage, 12
            sat     temp8
            bnt     code_0423
            pushi   2
            pushi   1
            push    
            callk   Memory, 4
            sat     temp7
            pushi   7
            pushi   0
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            push    
            callk   GetMessage, 14
            not     
            bnt     code_0423
            ldi     0
            sat     temp7
            jmp     code_0423
code_0395:  ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lsp     paramTotal
            ldi     2
            gt?     
            bnt     code_0406
            ldi     1
            lapi    param2
            sat     temp4
            lsp     paramTotal
            ldi     3
            gt?     
            bnt     code_0406
            ldi     2
            lapi    param2
            sat     temp5
            lsp     paramTotal
            ldi     4
            gt?     
            bnt     code_0406
            ldi     3
            lapi    param2
            sat     temp9
            lsp     paramTotal
            ldi     5
            gt?     
            bnt     code_0406
            ldi     4
            lapi    param2
            sat     temp11
            lsp     paramTotal
            ldi     6
            gt?     
            bnt     code_0406
            ldi     5
            lapi    param2
            sat     temp13
            lsp     paramTotal
            ldi     7
            gt?     
            bnt     code_0406
            ldi     6
            lapi    param2
            sat     temp10
            lsp     paramTotal
            ldi     8
            gt?     
            bnt     code_0406
            ldi     7
            lapi    param2
            sat     temp12
            lsp     paramTotal
            ldi     9
            gt?     
            bnt     code_0406
            ldi     8
            lapi    param2
            sat     temp14
code_0406:  pushi   2
            pushi   1
            pushi   1
            ldi     0
            lspi    param2
            callk   StrLen, 2
            push    
            ldi     1
            add     
            push    
            callk   Memory, 4
            sat     temp7
            pushi   2
            push    
            ldi     0
            lspi    param2
            callk   StrCpy, 4
code_0423:  lat     temp7
            bnt     code_048d
            pushi   118
            pushi   1
            pushi   #value
            pushi   1
            lsp     param1
            pushi   30
            pushi   1
            pTos    font
            pushi   23
            pushi   1
            push    
            pushi   27
            pushi   1
            pTos    mode
            pushi   625
            pushi   1
            lst     temp9
            pushi   626
            pushi   1
            lst     temp10
            pushi   629
            pushi   1
            lst     temp13
            pushi   630
            pushi   1
            lst     temp14
            pushi   627
            pushi   1
            lst     temp11
            pushi   628
            pushi   1
            lst     temp12
            pushi   186
            pushi   1
            pTos    width
            pushi   188
            pushi   2
            pushi   4
            lat     temp4
            add     
            push    
            pushi   4
            lat     temp5
            add     
            push    
            pushi   117
            pushi   0
            pushi   #new
            pushi   0
            class   DColorButton
            send    4
            send    78
            push    
            pushi   186
            pushi   0
            pToa    dialog
            send    10
code_048d:  ret     
        )
    )


    (method (addEdit param1 param2 param3 param4 param5)
        (var temp0, temp1)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        StrCpy(param1 
            (if (> paramTotal 4)
                param5
            )(else
                "LOOKUP_ERROR"
            )
)
        (if (> paramTotal 2)
            = temp0 param3
            (if (> paramTotal 3)
                = temp1 param4
            )
        )
        (send dialog:
            add((send ((DEdit:new())):
                    text(param1)
                    max(param2)
                    setSize()
                    moveTo(+ temp0 4 + temp1 4)
                    yourself()
                )
)
            setSize()
        )
    )


    (method (addIcon param1 param2 param3 param4 param5)
        (var temp0, temp1)
        (if (not dialog)
            = dialog (Dialog:new())
        )
        (if (> paramTotal 3)
            = temp0 param4
            = temp1 param5
        )(else
            = temp0 (= temp1 0)
        )
        (if (IsObject(param1))
            (send dialog:
                add((send param1:
                        setSize()
                        moveTo(+ temp0 4 + temp1 4)
                        yourself()
                    )
)
                setSize()
            )
        )(else
            (send dialog:
                add((send ((DIcon:new())):
                        view(param1)
                        loop(param2)
                        cel(param3)
                        setSize()
                        moveTo(+ temp0 4 + temp1 4)
                        yourself()
                    )
)
                setSize()
            )
        )
    )


    (method (addText param1)
        (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8)
        (asm
            pToa    dialog
            not     
            bnt     code_05a3
            pushi   #new
            pushi   0
            class   Dialog
            send    4
            aTop    dialog
code_05a3:  pTos    font
            ldi     65535
            eq?     
            bnt     code_05ae
            lag     gFont
            aTop    font
code_05ae:  lsp     paramTotal
            ldi     3
            gt?     
            bnt     code_067c
            ldi     0
            lapi    param1
            sat     temp0
            ldi     1
            lapi    param1
            sat     temp1
            ldi     2
            lapi    param1
            sat     temp2
            ldi     3
            lapi    param1
            bnt     code_05d4
            ldi     3
            lapi    param1
            jmp     code_05d6
code_05d4:  ldi     1
code_05d6:  sat     temp3
            ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lag     gModNum
            sat     temp6
            lsp     paramTotal
            ldi     5
            ge?     
            bnt     code_060b
            ldi     4
            lapi    param1
            sat     temp4
            lsp     paramTotal
            ldi     6
            ge?     
            bnt     code_060b
            ldi     5
            lapi    param1
            sat     temp5
            lsp     paramTotal
            ldi     7
            ge?     
            bnt     code_060b
            ldi     6
            lapi    param1
            sat     temp6
code_060b:  pushi   6
            pushi   2
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            callk   GetMessage, 12
            sat     temp8
            bnt     code_06f8
            pushi   2
            pushi   1
            push    
            callk   Memory, 4
            sat     temp7
            pushi   7
            pushi   0
            lst     temp6
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            push    
            callk   GetMessage, 14
            bnt     code_06f8
            pushi   118
            pushi   1
            pushi   #text
            pushi   1
            lst     temp7
            pushi   30
            pushi   1
            pTos    font
            pushi   27
            pushi   1
            pTos    mode
            pushi   186
            pushi   1
            pTos    width
            pushi   188
            pushi   2
            pushi   4
            lat     temp4
            add     
            push    
            pushi   4
            lat     temp5
            add     
            push    
            pushi   117
            pushi   0
            pushi   #new
            pushi   0
            class   DText
            send    4
            send    36
            push    
            pushi   186
            pushi   0
            pToa    dialog
            send    10
            jmp     code_06f8
code_067c:  ldi     0
            sat     temp4
            ldi     0
            sat     temp5
            lsp     paramTotal
            ldi     2
            ge?     
            bnt     code_069e
            ldi     1
            lapi    param1
            sat     temp4
            lsp     paramTotal
            ldi     3
            ge?     
            bnt     code_069e
            ldi     2
            lapi    param1
            sat     temp5
code_069e:  pushi   2
            pushi   1
            pushi   1
            ldi     0
            lspi    param1
            callk   StrLen, 2
            push    
            ldi     1
            add     
            push    
            callk   Memory, 4
            sat     temp7
            pushi   2
            push    
            ldi     0
            lspi    param1
            callk   StrCpy, 4
            pushi   118
            pushi   1
            pushi   #text
            pushi   1
            lst     temp7
            pushi   30
            pushi   1
            pTos    font
            pushi   27
            pushi   1
            pTos    mode
            pushi   186
            pushi   1
            pTos    width
            pushi   188
            pushi   2
            pushi   4
            lat     temp4
            add     
            push    
            pushi   4
            lat     temp5
            add     
            push    
            pushi   117
            pushi   0
            pushi   #new
            pushi   0
            class   DText
            send    4
            send    36
            push    
            pushi   186
            pushi   0
            pToa    dialog
            send    10
code_06f8:  ret     
        )
    )


    (method (addTextF param1)
        (var temp0, temp1)
        Format(= temp1 Memory(1 (= temp0 proc921_3(rest))) rest)
        (self:addText(temp1))
        Memory(3 temp1)
    )


    (method (addTitle param1)
        (var temp0, temp1, temp2, temp3, temp4, temp5)
        (asm
            lsp     paramTotal
            ldi     1
            gt?     
            bnt     code_077b
            ldi     0
            lapi    param1
            sat     temp0
            ldi     1
            lapi    param1
            sat     temp1
            ldi     2
            lapi    param1
            sat     temp2
            ldi     3
            lapi    param1
            sat     temp3
            ldi     4
            lapi    param1
            sat     temp4
            pushi   6
            pushi   2
            push    
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            callk   GetMessage, 12
            sat     temp5
            bnt     code_0799
            pushi   2
            pushi   1
            push    
            callk   Memory, 4
            aTop    title
            pushi   7
            pushi   0
            lst     temp4
            lst     temp0
            lst     temp1
            lst     temp2
            lst     temp3
            pTos    title
            callk   GetMessage, 14
            jmp     code_0799
code_077b:  pushi   2
            pushi   1
            pushi   1
            ldi     0
            lspi    param1
            callk   StrLen, 2
            push    
            ldi     1
            add     
            push    
            callk   Memory, 4
            aTop    title
            pushi   2
            pTos    title
            ldi     0
            lspi    param1
            callk   StrCpy, 4
code_0799:  ret     
        )
    )


    (method (posn theX theY)
        = x theX
        = y theY
    )


    (method (handleEvent pEvent)
        (if ((send dialog:handleEvent(pEvent)))
            (send dialog:dispose())
        )
    )


    (method (cue)
        (var theCaller)
        = theCaller caller
        = dialog 0
        (if (window)
            (send window:dispose())
        )
        (self:dispose())
        (if (theCaller)
            (send theCaller:cue())
        )
    )

)
