View Raw SPL
/* viewhtml.spl */

#include 

static urlname  = "";
static urltitle = "";
static urltools = 0x03;

static html_h;
static html_w;


/* display html in a dialog box */
viewhtml(url, title, tools, h, w)
{
        local fname, pathflag, handle, outcnt, compose;

        if (argc < 5)
        {
                if (argc < 4)
                {
                        if (argc < 3)
                        {
                                if (argc < 2)
                                {
                                        if (argc < 1) url = "";
                                        
                                        title = "";
                                }
                                
                                if (isstring(title))
                                {
                                        tools = 0x03;
                                }
                                else
                                {
                                        tools = title;
                                        title = "";
                                }
                        }
                        
                        h = -1;
                }
                
                w = -1;
        }

        if (viewhtml_isurl(url))
        {
                /* use browser */
                gotourl(url);

                return(0);
        }

        html_h = h;
        html_w = w;

        outcnt = outargc;

        pathflag = TRUE;

        if (strlen(title) == 0)
        {
                /* default title to filename */
                (path, urltitle) = dirpath(url, pathflag);
        }
        else
        {
                urltitle = title;
        }

        urltools = tools;

        /* build full path */
        (path, fname) = dirpath(url, pathflag);
        url = path + fname;

        if (isdarkmode())
        {
                url += "?darkmode=1";
        }

        /* set name and display */
        urlname = url;

        /* prevent flicker */
        compose = setconfig("panel_composited", 0);

        /* display */
        handle = _mf("viewhtml.pan");

        setconfig("panel_composited", compose);

        if (outcnt > 0)
        {
                /* return menu handle if requested */
                return(handle);
        }
}


viewhtml_geturl()
{
        return(urlname);
}


viewhtml_title()
{
        return(urltitle);
}


viewhtml_isurl(url)
{
        local status = 0;

        if (strlen(strfind("http://", url)) > 0)
        {
                status = 1;
        }
        else if (strlen(strfind("https://", url)) > 0)
        {
                status = 1;
        }
        else if ("www." == strextract(url, 1, 4))
        {
                status = 1;
        }
        
        return(status);
}


viewhtml_tools()
{
        return(urltools);
}


viewhtml_hw()
{
        local h, w;
        extern _viewhtml_height, _viewhtml_width;

        if (html_h < 0)
        {
                if (isglobal("_viewhtml_height"))
                {
                        h = _viewhtml_height;
                }
                else
                {
                        h = 250;
                }
        }
        else
        {
                h = html_h;
        }

        if (html_w < 0)
        {
                if (isglobal("_viewhtml_width"))
                {
                        w = _viewhtml_width;
                }
                else
                {
                        w = 300;
                }
        }
        else
        {
                w = html_w;
        }
        
        return(h, w);
}