/*
    OQDC.C

Methods of OO dialogs of OQUERY.C
Written by DavidW
Started on 5/9/93

*/

#include <oqd.g>
#include <p_date.h>
#include <hwim.h>

#include "oquery.rsg"

#define COMBINS_DIW     1
#define COMBINS_DIM     2
#define COMBINS_FOUND   3

LOCAL_C VOID SetControls(P_DAYSEC *pds)
    {
    P_DATE dt;

    hDlgSetChlist(COMBINS_DIW,p_wkday(pds->day));
    p_dstodt(pds,&dt);
    hDlgSetNcedit(COMBINS_DIM,dt.day+1);
    hDlgSetDtedit(COMBINS_FOUND,pds->day);
    }

#pragma METHOD_CALL

METHOD VOID oqd_combins_dl_dyn_init(PR_DLGBOX *self)
    {
    ULONG sdate;
    P_DAYSEC ds;

    sdate=p_date();
    p_sttods(&sdate,&ds);
    SetControls(&ds);
    }

METHOD INT oqd_combins_dl_key(PR_DLGBOX *self,INT index,INT key)
    {
    P_DAYSEC ds;
    P_DATE dt;
    INT diw;
    INT dim;
    INT diff;
    ULONG reset;
    INT inc;

    if (key==W_KEY_ESCAPE)
        return(WN_KEY_CHANGED);
    diw=hDlgSenseChlist(COMBINS_DIW);
    dim=hDlgSenseNcedit(COMBINS_DIM)-1;
    ds.day=hDlgSenseDtedit(COMBINS_FOUND);
    ds.sec=0;
    reset=ds.day;
    diff=diw-p_wkday(ds.day);
    if (key==W_KEY_RETURN)
        {
        if (diff<=0)
            diff+=7;
        inc=7;
        }
    else
        {
        if (diff>=0)
            diff-=7;
        inc=(-7);
        }
    ds.day+=diff;
    FOREVER
        {
        if (ds.day>93501l)
            {
            hInfoPrint(OQS_NO_FURTHER_MATCHES);
            ds.day=reset;
            break;
            }
        p_dstodt(&ds,&dt);
        if (dt.day==dim)
            break;
        ds.day+=inc;
        }
    SetControls(&ds);
    return(WN_KEY_NO_CHANGE);
    }
