/* EHBWIN.C */

#include <ehello.g>
#include <ehello.rsg>
#include <hwim.h>

LOCAL_C VOID LaunchDialog(INT class,INT resid,VOID *rbuf)
    {
    DL_DATA dld;

    dld.id=resid;
    dld.rbuf=rbuf;
    dld.pdlg=NULL;
    hLaunchDial(CAT_EHELLO_EHELLO,class,&dld);
    }

#pragma METHOD_CALL

METHOD VOID ehbwin_wn_init(PR_EHBWIN *self)
    {
    W_WINDATA wd;
    IN_EDWIN_X initx;
    struct
        {
        IN_EDWIN e;
        TEXT rest[21];
        } init;

    wd.extent.width=240-50; /* extent calculation presupposes S3 screen */
    wd.extent.height=3+10+5;    /* matches flags set for bwin below */
    wd.extent.tl.x=0;
    wd.extent.tl.y=31;      /* centred vertically */
    p_send5(self,O_WN_CONNECT,NULL,W_WIN_EXTENT,&wd);
    hLoadResBuf(EHSTR_INIT,&init.e.contents[0]);
    init.e.vulen=240-50-3-1-5-1;    /* one extra pixel clearance each end */
    init.e.maxlen=50;
    init.e.flags=IN_EDWIN_VULEN_PIXELS|IN_EDWIN_POSITION_SUPPLIED;
    initx.pos.x=3+1;
    initx.pos.y=3;
    self->ehbwin.edwin=f_newsend(CAT_EHELLO_HWIM,C_EDWIN,O_WN_INIT,
                                                        &init,self,&initx);
    self->win.flags=IN_BWIN_SHADOW_2|IN_BWIN_CUSHION;
    p_send3(self,O_WN_EMPHASISE,TRUE);
    hInitVis(self);
    }

METHOD VOID ehbwin_wn_emphasise(PR_EHBWIN *self,INT flag)
    {
    p_supersend3(self,O_WN_EMPHASISE,flag);
    p_send3(self->ehbwin.edwin,O_WN_EMPHASISE,flag);
    }

METHOD VOID ehbwin_wn_draw(PR_EHBWIN *self)
    {
    p_supersend2(self,O_WN_DRAW);
    p_send2(self->ehbwin.edwin,O_WN_DRAW);
    }

METHOD VOID ehbwin_wn_key(PR_EHBWIN *self,INT keycode,INT mods)
    {
    SE_EDWIN sense;

    if (keycode!=W_KEY_RETURN)
        p_send4(self->ehbwin.edwin,O_WN_KEY,keycode,mods);
    else
        {
        p_send3(self->ehbwin.edwin,O_WN_SENSE,&sense);
        LaunchDialog(C_EHDLG,EHDLG,sense.buf);
        }
    }
