/*******************************************************************
*
* This sample program demonstrates the use of scrollable
* input fields in MagiC 3.
*
*******************************************************************/
#include <aes.h>
#include <tos.h>
#include <string.h>
#include <magx.h>
#include "magxlib.h"
#include "edscroll.h"
#define TLEN 30
int do_dialog (OBJECT *dialog);
void main()
{
OBJECT *adr_dialog;
ULONG crdate;
int is_scroll;
XTED xted;
char tmplt[TLEN+1],txt[TLEN+1];
/* Check whether the system can scrolledit */
/* ------------------------------------------ */
is_scroll = ((0 < get_MagiC_ver(&crdate)) &&
(crdate >= 0x19950829L));
/* Register application with the AES */
/* ----------------------------- */
if (appl_init() < 0)
Pterm(1);
/* Resourcedatei laden */
/* ------------------- */
if (!rsrc_load("edscroll.rsc"))
{
form_alert(1, "[3][ \"EDSCROLL.RSC\"|not found!][Cancel]");
goto err;
}
rsrc_gaddr(0, EDIT, &adr_dialog);
/* Initialize scroll TEDINFO */
/* ----------------------------- */
init_scrlted(adr_dialog+EDITTXT, is_scroll, &xted,
txt, tmplt, TLEN);
strcpy(txt, "Beispiel");
/* Dialog */
/* ------ */
wind_update(BEG_MCTRL);
graf_mouse(ARROW, 0L);
do_dialog(adr_dialog);
wind_update(END_MCTRL);
rsrc_free();
err:
appl_exit();
Pterm0();
}
/****************************************************************
*
* do_dialog
*
****************************************************************/
int do_dialog(OBJECT *dialog)
{
int cx, cy, cw, ch;
int exitbutton;
form_center(dialog, &cx, &cy, &cw, &ch);
form_dial(FMD_START, 0,0,0,0, cx, cy, cw, ch);
objc_draw(dialog, ROOT, MAX_DEPTH, cx, cy, cw, ch);
exitbutton = 0x7f & form_do(dialog, 0);
form_dial(FMD_FINISH, 0,0,0,0,cx, cy, cw, ch);
return(exitbutton);
}
/*******************************************************************
*
* Ascertain MagiC version
* =======================
*
* If <crdate> != NULL, the creation date will be returned
* in the form yyyymmdd. With '<' and '>' one can then
* ascertain directly whether a given function is available
* in the MagiC version in question.
*
* Return value: 0 No MagiC installed
* -1 Still in AUTO folder
* 0x0a0b Version a.b
*
*******************************************************************/
WORD get_MagiC_ver(ULONG *crdate)
{
ULONG *cookie;
AESVARS *av;
cookie = get_cookie('MagX');
if (!cookie)
return(0);
else
{
av = ((MAGX_COOKIE *) (*cookie))->aesvars;
if (!av)
return(-1);
else if (crdate)
{
*crdate = av->date << 16L; /* yyyy0000 */
*crdate |= av->date >> 24L; /* yyyy00dd */
*crdate |= (av->date >> 8L) & 0xff00L; /* yyyymmdd */
return(av->version);
}
}
}
/****************************************************************
*
* Makes an F(BOX)TEXT object scrollable if MagiC is running.
*
* If <is_scroll> is FALSE, only the text field will be converted
* to a user character string.
*
* In the RCS, the text field should be left empty, but the template
* and the validation character string have to be input, as the RCS
* will strike otherwise.
* For scrolling fields a new template has to be created, as the
* one registered in the .RSC file cannot be used since it is too
* short. The template created here consists only of '_' characters,
* since this covers 99.9% of all applications for scrolling objects.
* The length of the validation string is immaterial. i.e. has to be
* at least 1, as the AES automatically duplicates the validation
* string until the length of the text field has been filled.
*
* The maximum length for the input character string is in every case
* (TEDINFO.te_txtlen - 1).
*
****************************************************************/
void init_scrlted(OBJECT *o, WORD is_scroll, XTED *xted,
char *txt, char *tmplt, WORD len)
{
TEDINFO *t;
t = o->ob_spec.tedinfo;
t->te_just = TE_LEFT; /* Important! */
t->te_ptext = txt;
if (is_scroll)
{
memset(tmplt, '_', len); /* New template */
tmplt[len] = '\0';
xted->xte_ptmplt = tmplt;
xted->xte_pvalid = t->te_pvalid;
xted->xte_vislen = t->te_tmplen - 1;
xted->xte_scroll = 0;
t->te_tmplen = len+1;
t->te_ptmplt = NULL;
t->te_pvalid = (void *) xted;
}
t->te_txtlen = t->te_tmplen;
}
See also: About the AES Input fields in MagiC GEM TEDINFO