Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : TEXTEDIT.HPP

 
Output of file : TEXTEDIT.HPP contained in archive : DOSUIT07.ZIP
/*
* TextEdit - input to a Text item
*/

#ifndef TEXTEDIT_HPP
#define TEXTEDIT_HPP
#ifndef INT_MAX
#include
#endif
#ifndef EDITCTRL_HPP
#include "editctrl.hpp"
#endif

class PopWindow;

/*
An editable text string. The usual range of editing keys is provided
- insert / overtype mode, delete, move by character, word and field
etc. This is also an EditControl, so it has read(), valid() and
write() methods. Note that the write() method overwrites the
original string, which is normally a static or allocated field.
*/
class TextEdit : public Control, public EditControl {
protected:
// Flags to indicate the internal state of a TextEdit.
enum EditFlags {
EFnone = 0,
EFinsert = BIT(0), // insert mode
EFbrowse = BIT(1), // browsing allowed
EFvalid = BIT(2), // string valid
EFchanged = BIT(3), // changed since last validated
EFucase = BIT(4), // Convert all input to upper case
EFlcase = BIT(5) // Convert all input to lower case
};
int offset; // For horizontal scrolling.
int selected; // = 1 if next input char will delete text.

private:
EditFlags eflags;
const char *validation;

public:
TextEdit(char *string,int length,const char *prompt = "",
const char *validchars = "");
/*
Validchars is a string describing the allowable input characters.
An empty validchars means any input character is allowed.
Otherwise, all the characters in validchars are allowed. As a special
case, a range of allowed characters may be represented as (e.g.) "A-Z".
To include the minus sign (-) itself, it must be the first character.
The validchars string is parsed at the start, and input is folded to
upper or lower case if only upper or lower case characters are valid.
*/
~TextEdit();

void setString(const char *string); // Set current string.
const char *string() const { return text; }
int maxlen() const { return textlen; }
const char *validchars() const { return validation; }
void disable() { Control::disable(); EditControl::disable(); }
// Disable the TextEdit, so focus cannot pass to it.
void enable() { Control::enable(); EditControl::enable(); }

virtual coord maxwidth() const;
virtual coord minwidth() const;

virtual void paint(Rectangle r);
virtual int leftclick(MouseEvent& e);
virtual int kbdevent(KeyboardEvent& e);
virtual int setfocus(int tabstop = 1);
virtual void resetfocus();

virtual void move(coord x,coord y);
// Ensure screen cursor follows movement,

//~ Test the status of the TextEdit.
int insmode() const { return ((eflags&EFinsert) != 0); }
int canBrowse() const { return eflags&EFbrowse; }
// True if the user can press cursor down to browse a list of possible
// values (combo box).
int isValid() const { return eflags&EFvalid; }
// True if the current user input is a valid value for the TextEdit.
int hasChanged() const { return eflags&EFchanged; }
// True if the string has been changed since the input focus last
// arrived on the TextEdit.
//~ virtual functions to customise behaviour
void endBrowse(const char *chosen = 0);
// If the TextEdit is a combo box, the virtual function browse is
// called when the user requests the pop-down. It creates a browse List
// containing the pop-down. When the user has finished with the List, it
// should call endBrowse(). It will set chosen to a string containing the
// user's selection, or leave it at the default value of 0 if the user
// decided not to select anything. This is usually done by overriding the
// List's pick() and escape() methods.
virtual char filter(char inchar);
// Filter is called for each character input before placing it in
// the Text. Should return the translated character, or 0 if not valid.
// The default filter ignores control characters.

virtual int validate();
// Validate is called after each single key change to the string.
// The string before the change is found in string(). The string after
// the change is in edittext.
// If it returns 0, the change is not allowed, and the Text

// remains unchanged. pos is also reset to it's original value.
// If it returns 1, the Text is updated from edittext.
// If required, validate may change edittext (e.g. insert filler
// characters, convert to upper case, etc.) before returning.
// The functions inschars() and delchars() assist with this.
// validate may also change pos, if required.

// Return value for TextEdit::complete().
enum Complete { COK, Cchanged, Cinvalid };
virtual Complete complete();
// Complete is called whenever the user has changed the Text, and
// wants to move the focus off the TextEdit. If edittext is valid,
// it should be left unchanged, and completed should return COK.
// If edittext is not valid, it may be changed to a valid value,
// and completed should return Cchanged. The Text will then be updated
// with the new string. Alternatively, complete may return Cinvalid, and
// the text will be marked invalid (preventing write() from updating the
// parameter).

static int defaultMode; // 1 = insert, 0 = overtype.

int valid(); // Calls validate() and complete() if necessary.
// Highlights field if not valid.
// Returns 1 if string is valid, 0 if not.
virtual void read(); // Re-read value from argument string.
virtual int writeback();// Write value to argument string.
virtual VObject *inheritingVObject();

protected:
void toggleInsert() { eflags = EditFlags (eflags ^ EFinsert); }
void insertOn() { setEflag(EFinsert); }
void insertOff() { clearEflag(EFinsert); }
void setBrowsable() { setEflag(EFbrowse); }
// Indicate whether browsing is enabled. A subclass that wishes to
// allow browsing will normally call setBrowsable() in its constructor.
void resetBrowsable() { clearEflag(EFbrowse); }
int testEflag(EditFlags e) const { return (eflags & e); }
void setCase(EditFlags e)
{ eflags = EditFlags (eflags | (e & (EFucase | EFlcase))); }
int pos; // Current cursor position.
char *edittext; // New string after single key edit.

int inschars(int posn,int nchars = 1);// Shift edittext up to make a space.
int delchars(int posn,int nchars = 1);// Delete some chars from edittext.
void updateString() { setString(edittext); }
// Update string from edittext.
virtual VObject *browse();
// Called when the browse key (cursor down) is hit, or the user clicks
// on the down arrow at the end of the TextEdit. browse should return
// some kind of List object. The TextEdit will take care of placing it
// in a PopWindow, displaying it, etc.
private:
void setEflag(EditFlags f) { eflags = EditFlags (eflags | f); }
void clearEflag(EditFlags f) { eflags = EditFlags (eflags & ~f); }
void setValid() { setEflag(EFvalid); unhighlight(); }
void setInvalid() { clearEflag(EFvalid); highlight(); }
void setChanged() { setEflag(EFchanged); }
void setUnchanged() { clearEflag(EFchanged); }
char *parameter; // The string to update on writeback().
PopWindow *browseWindow;
char *text;
int textlen;
protected:
void updateCursor(); // Ensure screen cursor in right place.
void startBrowse(VObject *v); // Pop up a browse window containing v.
};

declare(OCollection,TextEdit);
declare(OIterator,TextEdit);

// A TextEdit that forces its input to upper case.
class UpperEdit : public TextEdit {
public:
UpperEdit(char *string,int length,const char *prompt = "",
const char *validchars = " -`{-~");
};

// A TextEdit that forces its input to lower case.
class LowerEdit : public TextEdit {
public:
LowerEdit(char *string,int length,const char *prompt = "",
const char *validchars = " -@[-~");
};

// A TextEdit that allows input of an unsigned integer.
class UnsignedEdit : public TextEdit {
public:
UnsignedEdit(unsigned &i,const char *prompt = "",
unsigned low = 0, unsigned high = UINT_MAX);
virtual Complete complete();
virtual void read();
virtual int writeback();

private:
unsigned &uparameter;
unsigned lowval, highval;
};

// A TextEdit that allows input of an integer.
class IntEdit : public TextEdit {
public:
IntEdit(int &i,const char *prompt = "",
int low = INT_MIN,int high = INT_MAX);
virtual char filter(char inchar);
virtual int validate();
virtual Complete complete();
virtual void read();
virtual int writeback();

private:
int &iparameter;
int lowval, highval;
};

#endif


  3 Responses to “Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : TEXTEDIT.HPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/