View Raw SPL

#define SHOWTEXT_ML 30
#define SHOWTEXT_MC 128

static show_text, show_lines, show_len, show_title, show_handle;


/* display text in a dialog box */
showtext(text, title)
{
        if (argc < 2)
        {
                if (argc < 1)
                {
                        text = "";
                }
                
                title = "";
        }

        text = caststring(text);

        if (strlen(text) > 0)
        {
                show_text  = text;
                show_title = title;

                /* get text height and with in characters */
                (show_lines, show_len) = showtext_numlines(text);
                show_lines++;

                show_lines = min(show_lines, SHOWTEXT_ML);
                show_len   = min(show_len,   SHOWTEXT_MC);

                /* display text in modeless dialog */
                show_handle = _mf("showtext.pan");
        }
}


/* height and width of text in characters */
showtext_numlines(text)
{
        local t, idx, nlines, maxlen;

        /* convert to series */
        t = {text};

        /* number of lines */
        idx    = find(t == charstrs(strescape("\n")));
        nlines = length(idx);

        if (outargc > 1)
        {
                if (nlines > 0)
                {
                        /* longest line length */
                        idx    = extract(idx - delay(idx, 1), 1, length(idx));
                        t      = reshape(t, idx);
                        maxlen = max(collength(t)');
                }
                else
                {
                        maxlen = strlen(text);
                }
                
                return(nlines + 1, maxlen + 2);
        }
        else
        {
                return(nlines + 1);
        }
}


/* menu handle */
showtext_handle()
{
        return(show_handle)
}


/* displayed text */
showtext_text()
{
        return(show_text);
}