UPLOAD - DOSUIT07.ZIP - EDITCTRL.HPP

 
Output of file : EDITCTRL.HPP contained in archive : DOSUIT07.ZIP

// Controls which edit a value
#ifndef EDITCTRL_HPP
#define EDITCTRL_HPP
#ifndef BUTTON_HPP
#include "button.hpp"
#endif

/*
The basic class for all VObjects that allow the user to update a
value (e.g. TextEdit, CheckButton).
To create a new class based on EditControl, you only need to
override the virtual methods read, valid and writeback. The main
value of deriving classes from EditControl is that they can then all
be connected to CloseEditButtons, ApplyEditButtons and
ResetEditButtons, giving automatic control of a user dialog.
*/
class EditControl {
public:
EditControl();
virtual int valid(); // Check if Control is valid.
virtual void read(); // Re-read value from variable.
int write() // Validate and write variable.
{ return valid() ? writeback() : 0; }
virtual int writeback(); // Write value (validity already checked).
virtual VObject *inheritingVObject() = 0;
void enable(int on = 1);
void disable() { enable(0); }

protected:
friend class EditCluster;
VObject *linkedPrompt; // Follows enabled/disabled status.
};
declare(GCollection,EditControl);
declare(GIterator,EditControl);

/*
This is an internal class, used to group a whole list of EditControls
to be treated as a single EditControl, so that they can be read and
written together.
*/
class EditControlList : public EditControl, public GCollection(EditControl) {
public:
EditControlList(EditControl *e);
EditControlList(EditControl **e);
EditControlList(const GCollection(EditControl)& e);
virtual int valid();
virtual void read();
virtual int writeback();
virtual VObject *inheritingVObject() = 0;
};

/*
A CloseButton which will validate and write one or more EditControls
before closing the containing Window. If any of the EditControls
contains invalid data, the Window will not be closed.
*/
class CloseEditButton : public CloseButton {
public:
CloseEditButton(EditControl *e,const char *n = "O.K.",
Keys hotkey = Knone,Command *cmd = 0,
ButtonDefault makedefault = Default);
CloseEditButton(EditControl *e,Command *cmd,
ButtonDefault makedefault = Default,const char *n = "O.K.");
virtual int doit();
private:
EditControl *editctrl;
};

/*
An ActiveButton that calls the read methods for all the
EditControl's it is connected with. ResetEditButton's are usually
used for the "Undo" button in a dialog, which will restore the
original values, discarding any edits, but without closing the
dialog box.
*/
class ResetEditButton : public ActiveButton {
public:
ResetEditButton(EditControl *e,const char *n = "Reset",
Keys hotkey = Knone,Command *cmd = 0);
virtual int doit();
private:
EditControl *editctrl;
};

/*
An ActiveButton that calls the valid and write methods for all the
EditControl's it is connected with. If any of the valid methods fail,
then no writing is performed. ApplyEditButton's are usually used for
the "Apply" button in a dialog, which will update the values being
set by the dialog, but without closing the dialog box.
*/
class ApplyEditButton : public ActiveButton {
public:
ApplyEditButton(EditControl *e,const char *n = "Apply",
Keys hotkey = Knone,Command *cmd = 0);
virtual int doit();
private:
EditControl *editctrl;
};

#endif