home *** CD-ROM | disk | FTP | other *** search
- /*
- TSTRINP.CPP
- (C) Copyright 1992 Michael Joseph Newton
- All rights reserved.
-
- Definitions for TStringInputLine class.
-
- The TStringInputLine class is derived from Turbo Vision's
- TInputLine class. TStringInputLine is declared in TSTRINP.HPP,
- and defined in TSTRINP.CPP.
-
- This file is hereby released by the author to the public
- domain. Use it as you will.
-
- Author: Michael Joseph Newton
- Date: 01/17/92
- Address: 17874 Marygold Ave. #32
- Bloomington, CA 92316
- Phone: (714) 877-4655
- CompuServe: 70402,531 (as Michael J. Newton)
- RelayNet: ->ECTECH (as Mick Newton)
-
- All questions or comments will be greatly appreciated!
- */
-
- #define Uses_TEvent
- #define Uses_THistory
- #define Uses_THistoryWindow
- #define Uses_TInputLine
- #define Uses_TKeys
- #define Uses_TStreamableClass
- #define Uses_TStreamable
- #define Uses_MsgBox
- #define Uses_ipstream
- #define Uses_opstream
-
- #include <tv.h>
-
- __link(RInputLine)
-
- #if !defined __STRING_H
- #include <string.h>
- #endif
-
- #if !defined __STDLIB_H
- #include <stdlib.h>
- #endif
-
- #if !defined __STRSTREAM_H
- #include <strstream.h>
- #endif
-
- #if !defined __CTYPE_H
- #include <ctype.h>
- #endif
-
- #if !defined __TSTRINP_HPP
- #include "tstrinp.hpp"
- #endif
-
- // TStringInputLine
- /*
- The following is a graphical representation of the defined and
- undefined bits in the 'TStringInputLine::options' data member which
- is inherited from TView via TInputLine.
-
- If bit 10, 'ofMandInput', is set, then TStringInputLine will not
- accept an empty string as input, i.e. the user must enter a minimal
- string.
-
- If bit 11, 'ofUpperCase', is set, then TStringInputLine will convert
- input to uppercase.
-
- If bit 12, 'ofLowerCase', is set, then TStringInputLine will convert
- input to lowercase.
-
- ┌──┬───────────────────────────────────*──caseField = 0xC00
- │ │ ┌───┬────────────────────────────ofCentered = 0x300
- 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- ╔══╤══╤══╤╧═╤╧═╤══╤╧═╤═╧═╦═══╤══╤══╤══╤══╤══╤══╤══╗
- ║ │ │ │ │ │ │ │lsb║msb│ │ │ │ │ │ │ ║
- ╚╤═╧╤═╧╤═╧╤═╧╤═╧╤═╧╤═╧═╤═╩═╤═╧╤═╧╤═╧╤═╧╤═╧╤═╧╤═╧╤═╝
- │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └───ofSelectable = 0x001
- │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──────ofTopSelect = 0x002
- │ │ │ │ │ │ │ │ │ │ │ │ │ └─────────ofFirstClick = 0x004
- │ │ │ │ │ │ │ │ │ │ │ │ └────────────ofFramed = 0x008
- │ │ │ │ │ │ │ │ │ │ │ └───────────────ofPreProcess = 0x010
- │ │ │ │ │ │ │ │ │ │ └──────────────────ofPostProcess = 0x020
- │ │ │ │ │ │ │ │ │ └─────────────────────ofBuffered = 0x040
- │ │ │ │ │ │ │ │ └────────────────────────ofTileable = 0x080
- │ │ │ │ │ │ │ └────────────────────────────ofCenterX = 0x100
- │ │ │ │ │ │ └────────────────────────────────ofCenterY = 0x200
- │ │ │ │ │ └────────────────────────────────*──ofMandInput = 0x400
- │ │ │ │ └───────────────────────────────────*──ofUpperCase = 0x800
- │ │ │ └──────────────────────────────────────*──ofLowerCase = 0x1000
- │ │ └────────────────────────────────────────────Undefined = 0x2000
- │ └───────────────────────────────────────────────Undefined = 0x4000
- └──────────────────────────────────────────────────Undefined = 0x8000
- */
-
- const char * const TStringInputLine::name = "TStringInputLine";
-
-
- TStringInputLine::TStringInputLine(const TRect& bounds, int aMaxLen) :
- TInputLine(bounds, aMaxLen)
- {
- }
-
-
- TStringInputLine::~TStringInputLine()
- // For debugging
- {
- }
-
-
- void TStringInputLine::write(opstream& os)
- {
- TInputLine::write(os);
- }
-
-
- void *TStringInputLine::read(ipstream& is)
- {
- TInputLine::read(is);
- return this;
- }
-
-
- TStreamable *TStringInputLine::build()
- {
- return new TStringInputLine(streamableInit);
- }
-
-
- TStreamableClass RStringInputLine(TStringInputLine::name,
- TStringInputLine::build,
- __DELTA(TStringInputLine));
-
-
- void TStringInputLine::handleEvent(TEvent& event)
- {
- TView::handleEvent(event);
-
- // If neccessary, convert keystroke before THistory grabs it
- if((state & sfSelected) && (event.what == evKeyDown))
- {
- if(options & ofUpperCase) // If uppercase bit set...
- event.keyDown.charScan.charCode =
- toupper(event.keyDown.charScan.charCode);
- else if(options & ofLowerCase) // If lowercase bit set...
- event.keyDown.charScan.charCode =
- tolower(event.keyDown.charScan.charCode);
- }
-
- TInputLine::handleEvent(event);
- }
-
-
- ushort TStringInputLine::dataSize()
- {
- return(strlen(data));
- }
-
-
- void TStringInputLine::getData(void *rec)
- {
- // Convert string if neccessary
- if(options & ofUpperCase)
- strupr(data);
- else if(options & ofLowerCase)
- strlwr(data);
-
- strcpy((char *)rec, data);
- }
-
-
- void TStringInputLine::setData(void *rec)
- {
- strcpy(data, (char *)rec);
-
- // Convert string if neccessary
- if(options & ofUpperCase)
- strupr(data);
- else if(options & ofLowerCase)
- strlwr(data);
-
- selectAll(True);
- }
-
-
- Boolean TStringInputLine::valid(ushort command)
- // Checks TStringInputLine for valid input
- {
- Boolean ok = True;
- char msg[80];
-
- if((command != cmCancel) && (command != cmValid))
- {
- // Invalid if string is empty, and ofMandInput bit is set
- if((strlen(data) == 0) && (options & ofMandInput))
- {
- select();
- strcpy(msg, "\003This field cannot be empty.");
- messageBox(msg, mfError + mfOKButton);
- selectAll(True);
- ok = False;
- }
- }
-
- if(ok)
- return TInputLine::valid(command);
- else
- return False;
- }
-
-
- ushort TStringInputLine::setf(ushort setBits, ushort aField)
- // Clear 'aField' bits and set 'setBits' bits in TView::options word (huh?)
- {
- options &= ~aField; // Unset 'aField' bits
- options |= setBits; // Set 'setBits' bits
- return options; // Return 'options' value
- }
-
-
- ushort TStringInputLine::setf(ushort setBits)
- // Set 'setBits' bits in TView::options word
- {
- options |= setBits; // Set 'setBits' bits
- return options; // Return 'options' value
- }
-
-
- // End of TSTRINP.CPP
-