/* Written by Leif November 1993 */

#include <p_std.h>
#include <p_date.h>
#include <epoc.h>
#include <hwim.h>
#include <time.g>
#include <dat.g>
#include <dat.rsg>

GLREF_D PR_WSERV * const w_ws;
GLREF_D PR_APPMAN * const w_am;

#pragma METHOD_CALL

METHOD VOID datwin_wn_draw(PR_DATWIN *self)
    {
    TEXT buf[LN_TIME_DATE_STR];
    G_FONT_INFO fontinfo;
    W_WINDATA windata;
    P_RECT r;

    p_supersend2(self,O_WN_DRAW);
    wInquireWindow(self->win.id,&windata);
    gFontInfo(WS_FONT_SYSTEM,0,&fontinfo);
    r.tl.x=2;
    r.br.x=windata.extent.width-2;
    r.tl.y=(windata.extent.height-fontinfo.height)>>1;
    r.br.y=r.tl.y+fontinfo.height;
    f_leave(p_send4(self->datwin.time,O_TO_SENSE,SENSE_TIME_DATESTR,&buf[0]));
    gPrintBoxText(&r,fontinfo.ascent,G_TEXT_ALIGN_CENTRE,0,&buf[0],p_slen(&buf[0]));
    }

METHOD VOID datwin_wn_dodraw(PR_DATWIN *self)
    {
    gCreateTempGC0(self->win.id);
    datwin_wn_draw(self);
    gFreeTempGC();
    wFlush();
    }

METHOD VOID datwin_wn_init(PR_DATWIN *self,PR_WIN *par,UINT fields,W_WINDATA *pwd)
    {
    p_supersend5(self,O_WN_CONNECT,par,fields,pwd);
    p_send3(self,O_WN_VISIBLE,WV_INITVIS);
    p_send3(self,O_WN_EMPHASISE,TRUE);
    self->datwin.time=f_newsend(CAT_DAT_OLIB,C_TIME,O_TO_SET_FORMAT,NULL,NULL);
    p_send4(self->datwin.time,O_TO_SET,SET_TIME_NOW,NULL);
    datwin_wn_dodraw(self);
    }

