/*-*-C-*-
 * FileInfo dialogue for the ResEd shell
 */

#include "resed.h"
#include "main.h"

#include "swicall.h"
#include "wimp.h"
#include "resformat.h"
#include "dbox.h"
#include "registry.h"

#include "class.h"
#include "document.h"
#include "icondefs.h"
#include "fileinfo.h"


static WindowPtr window;


error * fileinfo_load_prototypes ()
{
   ER ( wimp_load_template("FileInfo", &window) );
   ER ( swi (Wimp_CreateWindow,  R1, &window->visarea,
             OUT,  R0, &window->handle,  END) );

   return registry_register_window (window->handle, FileInfo, NULL);
}


/*
 * Open the fileinfo dialogue box.  The filetype and sprite are
 * hardwired into the template.
 */


error * fileinfo_open (DocumentPtr doc, PointPtr position)
{
    char buf[FILENAMELEN];

    ER ( document_recover_document (doc) );

    dbox_setstring (window, I_FILEINFO_MODIFIED, message_lookup(&msgs, doc->modified ? "Yes" : "No"));

    sprintf (buf, "%.*s", doc->namelength, doc->title);
    dbox_setstring (window, I_FILEINFO_FILENAME, buf);

    /* XXX Really we should recover the document data from the CSEs first */
    sprintf (buf, "%d", document_file_size (doc, FALSE));
    dbox_setstring (window, I_FILEINFO_SIZE, buf);

    ER ( swi (Territory_ConvertStandardDateAndTime,
              R0, -1,  R1, doc->timestamp,  R2, buf,  R3, sizeof(buf),  END) );
    dbox_setstring (window, I_FILEINFO_DATE, buf);

    return ( swi (Wimp_CreateSubMenu,  R1, window->handle,  R2, position->x,  R3, position->y,  END) );
}


/*
 * Respond to OPEN_WINDOW_REQUEST.  "win" is the return block
 * from Wimp_Poll and is not a complete window structure.
 */

error * fileinfo_open_window (WindowPtr win)
{
    window->visarea = win->visarea;
    window->scrolloffset = win->scrolloffset;
    window->behind = win->behind;
    return swi (Wimp_OpenWindow, R1, window, END);
}
