home *** CD-ROM | disk | FTP | other *** search
- /*
- FIELDS.CPP
-
- Written by: ing E.A.B. Schlösser, The Netherlands
- CIS 100016,2263
-
- Again a new Turbo Vision class.
-
- When using a dialog screen, you create the dialog screen with it's
- fields for data entry. When done you must define a data-struct
- that matches your dialog screen. To me this does not seem 'right'.
- I created an InputField class that updates your variables linked
- to the input field when pressing enter.
- Only create the dialog screen, put labels and input fields and
- you are done.
- Additionally the class inhibits using alpha keys in numeric fields !
-
- Only part that I do not like: A pointer to the TDialog window must be
- provided as an argument. Currently you should use
- TDialog *pd;
-
- TRect r( 1, 1, 77, 46 );
- pd=new TDialog(r,"Enter geometry data");
-
- if (pd)
- {
- wing.Dubbel=stabilo.Dubbel=2;
- kielvlak.Dubbel=0;
- kielvlak.alpha=kielvlak.b0=0.0;
-
- pd->insert(new TButton(TRect(60,42,68,44),"~O~K",cmOK,bfNormal));
-
- pd->PutText(2,1,"Model name:");
- new InputField(pd,25,1,24,naam);
- .
- .
- .
-
- I would like to use:
- pd->insert(InputField(25,1,24,naam));
-
- Who can help ?
-
- */
- #pragma hdrfile "fields.sym"
-
- #define Uses_TEvent
- #define Uses_TKeys
-
-
- #include <tv.h>
-
- #include "fields.hpp"
-
- #include <ctype.h>
- #include <stdio.h>
-
- #pragma hdrstop
-
- InputField::InputField(TDialog *pd, int x, int y, int w, float *data):
- TInputLine(TRect(x,y,x+w+3,y+1),w+1)
- {
- char tmp[20];
- sprintf(tmp,"%f",*data);
- setData(tmp);
- pd->insert(this);
- ptrData=data;
- dataType=0;
- }
-
- InputField::InputField(TDialog *pd, int x, int y, int w, char *data):
- TInputLine(TRect(x,y,x+w+3,y+1),w+1)
- {
- setData(data);
- pd->insert(this);
- ptrData=data;
- dataType=4;
- }
-
- InputField::~InputField(void)
- {
- }
-
- int InputField::Validate(void)
- {
- char tmpstr[50];
- float tmpflt;
-
- TInputLine::getData(tmpstr);
-
- switch(dataType)
- {
- case 0: // float
- if (1==sscanf(tmpstr,"%f",&tmpflt))
- {
- *(float *)ptrData=tmpflt;
- return 1;
- }
- break;
-
- case 4: // string
- strcpy((char *)ptrData,tmpstr);
- return 1;
-
- }
- return 0;
- }
-
- void InputField::handleEvent(TEvent& event)
- {
- ushort Kcode;
- uchar Ccode;
- // uchar Scode;
-
- if (event.what==evKeyDown)
- {
- Kcode=event.keyDown.keyCode; // full two byte key code
- Ccode=event.keyDown.charScan.charCode; // lower byte
- // Scode=event.keyDown.charScan.scanCode; // upper byte
- if (Kcode==kbEnter)
- {
- if (Validate()) event.keyDown.keyCode=kbTab;
- }
- else
- {
- if ( (dataType<4) && (isalpha(Ccode))) clearEvent(event);
- }
- }
- TInputLine::handleEvent(event);
- }
-