home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_form.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  7.4 KB  |  250 lines

  1. /*
  2.  * File:     wx_form.h
  3.  * Purpose:  Declaration of the wxForm object and related functions, for
  4.  *           creating forms with constrained user-editable items.
  5.  *
  6.  *                       wxWindows 1.40
  7.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  8.  *                   The University of Edinburgh
  9.  *
  10.  *                     Author: Julian Smart
  11.  *                       Date: 18-4-93
  12.  *
  13.  * Permission to use, copy, modify, and distribute this software and its
  14.  * documentation for any purpose is hereby granted without fee, provided
  15.  * that the above copyright notice, author statement and this permission
  16.  * notice appear in all copies of this software and related documentation.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  19.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  20.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  21.  *
  22.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  23.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  24.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  25.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  26.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  27.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  */
  29.  
  30. #ifndef wx_formh
  31. #define wx_formh
  32.  
  33. #include "common.h"
  34. #include "wx_item.h"
  35.  
  36. // Data types
  37. #define wxFORM_SHORT           1
  38. #define wxFORM_LONG            2
  39. #define wxFORM_STRING          3
  40. #define wxFORM_BOOL            4
  41. #define wxFORM_FLOAT           5
  42. #define wxFORM_LIST_OF_LONGS   6
  43. #define wxFORM_LIST_OF_STRINGS 7
  44.  
  45. // Editor types
  46. #define wxFORM_DEFAULT       1  // Use whatever is most suitable
  47. #define wxFORM_SINGLE_LIST   2
  48. #define wxFORM_MULTI_LIST    3
  49. #define wxFORM_CHOICE        4
  50. #define wxFORM_CHECKBOX      5
  51. #define wxFORM_TEXT          6
  52. #define wxFORM_MULTITEXT     8
  53. #define wxFORM_SLIDER        9
  54. #define wxFORM_MESSAGE       10
  55. #define wxFORM_NEWLINE       11
  56. #define wxFORM_BUTTON        12
  57. #define wxFORM_DUMB_MESSAGE  13
  58.  
  59. // Editable or not editable
  60. #define wxFORM_EDITABLE      1
  61. #define wxFORM_NOT_EDITABLE  0
  62.  
  63. // Constraint types
  64. #define wxFORM_CONSTRAINT_ONE_OF    1
  65. #define wxFORM_CONSTRAINT_RANGE     2
  66. #define wxFORM_CONSTRAINT_FUNCTION  3
  67. #define wxFORM_CONSTRAINT_IS_INT    4
  68. #define wxFORM_CONSTRAINT_IS_STRING 5
  69. #define wxFORM_CONSTRAINT_IS_REAL   6
  70. #define wxFORM_CONSTRAINT_IS_BOOL   7
  71.  
  72. // Returns FALSE if constraint violated, print error to msg_buffer.
  73. // Cast value to POINTER to appropriate value.
  74. typedef Bool (*wxConstraintFunction) (int type, char *value, char *label, char *msg_buffer);
  75.  
  76. // Edits a value with a user-supplied editor, placing result in
  77. // variable pointed to by value.
  78. typedef Bool (*wxEditFunction) (int type, char *current_value, char *variable);
  79.  
  80. class wxRealRange: public wxObject
  81. {
  82.  public:
  83.   float lo;
  84.   float hi;
  85.   wxRealRange(float lo, float hi);
  86. };
  87.  
  88. class wxFormItemConstraint: public wxObject
  89. {
  90.  public:
  91.   int Type;
  92.  
  93.   union
  94.   {
  95.     wxList *OneOf; // List of strings or longs
  96.     wxConstraintFunction ConstraintFunc;
  97.     wxRealRange *Range;
  98.   } Constraint;
  99.  
  100.   wxFormItemConstraint(int type);
  101.   ~wxFormItemConstraint(void);
  102. };
  103.  
  104. // A form item contains information about the C++ variable
  105. // containing the data, the type, the constraints, error messages, help
  106. // information.
  107. class wxForm;
  108. class wxFormItem: public wxObject
  109. {
  110.  public:
  111.   long Id;
  112.   int Type;
  113.   int ItemType;
  114.   int Width;
  115.   int Height;
  116.   wxForm *Form;
  117.   wxItem *PanelItem;
  118.   wxList *Constraints;
  119.   wxEditFunction CustomEditor;
  120.   char *HelpString;
  121.   char *Label;
  122.   wxFunction ButtonFunc;
  123.  
  124.   // Temporary value before user clicks Ok on form
  125.   union
  126.   {
  127.     float FloatValue;
  128.     long LongIntValue;
  129.     int ShortIntValue;
  130.     char *StringValue;
  131.     Bool BoolValue;
  132.     wxList *ListValue;
  133.     wxFunction ButtonFunction;
  134.   } Value;
  135.  
  136.   // Pointer to (for example) some C++ object member
  137.   union
  138.   {
  139.     float *FloatValuePtr;
  140.     long *LongIntValuePtr;
  141.     int *ShortIntValuePtr;
  142.     char **StringValuePtr;
  143.     Bool *BoolValuePtr;
  144.     wxList **ListValuePtr;
  145.   } ValuePtr;
  146.  
  147.    wxFormItem(int type, int item_type);
  148.    ~wxFormItem(void);
  149.  
  150.    void MakePanelItem(wxPanel *panel);
  151.  
  152.    // Checking functions
  153.    Bool CheckLongValue(long val);
  154.    Bool CheckBoolValue(Bool val);
  155.    Bool CheckStringValue(char *val);
  156.    Bool CheckFloatValue(float val);
  157.  
  158.    // Set C++ variable to currently edited value(s) if doesn't
  159.    // violate any constraint. Returns TRUE if successful.
  160.    Bool UpdateValue(void);
  161.  
  162.    // Display current C++ variable value
  163.    void RevertValue(void);
  164. };
  165.  
  166. // A form is independent from an actual panel or dialog,
  167. // but can be associated with one
  168. class wxForm: public wxObject
  169. {
  170.  public:
  171.   wxList FormItems;
  172.   wxPanel *wx_form_panel;
  173.   Bool wx_editable;
  174.   wxForm(void);
  175.   ~wxForm(void);
  176.   void Add(wxFormItem *item, long id = -1);
  177.   wxNode *FindItem(long id);
  178.   Bool Set(long id, wxFormItem *item);
  179.   Bool Delete(long id);
  180.   void AssociatePanel(wxPanel *panel);
  181.   void DisassociatePanel(void);
  182.   Bool UpdateValues(void);
  183.   void RevertValues(void);
  184.   inline void SetEditable(Bool editable)
  185.     { wx_editable = editable; }
  186.   inline Bool IsEditable(void)
  187.     { return wx_editable; }
  188.  
  189.   // Default behaviour for OnOk/OnCancel - delete form and panel/dialog box
  190.   virtual void OnOk(void);
  191.   virtual void OnCancel(void);
  192.   virtual void OnRevert(void);
  193.   virtual void OnUpdate(void);
  194. };
  195.  
  196. // Functions for making wxFormItems
  197. wxFormItem *wxMakeFormButton(char *label, wxFunction fun);
  198.  
  199. wxFormItem *wxMakeFormMessage(char *label);
  200.  
  201. wxFormItem *wxMakeFormNewLine(void);
  202.  
  203. wxFormItem *wxMakeFormLong(char *label, long *var,
  204.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  205.   char *help_string = NULL, wxEditFunction editor = NULL,
  206.   int width = -1, int height = -1);
  207.  
  208. wxFormItem *wxMakeFormShort(char *label, int *var,
  209.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  210.   char *help_string = NULL, wxEditFunction editor = NULL,
  211.   int width = -1, int height = -1);
  212.  
  213. wxFormItem *wxMakeFormFloat(char *label, float *var,
  214.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  215.   char *help_string = NULL, wxEditFunction editor = NULL,
  216.   int width = -1, int height = -1);
  217.  
  218. wxFormItem *wxMakeFormBool(char *label, Bool *var,
  219.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  220.   char *help_string = NULL, wxEditFunction editor = NULL,
  221.   int width = -1, int height = -1);
  222.  
  223. wxFormItem *wxMakeFormString(char *label, char **var,
  224.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  225.   char *help_string = NULL, wxEditFunction editor = NULL,
  226.   int width = -1, int height = -1);
  227.  
  228. /* NOT IMPLEMENTED
  229. // List of strings
  230. wxFormItem *wxMakeFormStringList(char *label, wxList **var,
  231.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  232.   char *help_string = NULL, wxEditFunction editor = NULL,
  233.   int width = -1, int height = -1);
  234.  
  235. // List of longs
  236. wxFormItem *wxMakeFormLongList(char *label, wxList **var,
  237.   int item_type = wxFORM_DEFAULT, wxList *constraints = NULL,
  238.   char *help_string = NULL, wxEditFunction editor = NULL,
  239.   int width = -1, int height = -1);
  240. */
  241.  
  242. // Functions for making wxFormItemConstraints
  243. wxFormItemConstraint *wxMakeConstraintStrings(wxList *list);
  244. wxFormItemConstraint *wxMakeConstraintStrings(char *first ...);
  245. // wxFormItemConstraint *wxMakeConstraintLongs(wxList *list);
  246. wxFormItemConstraint *wxMakeConstraintFunction(wxConstraintFunction func);
  247. wxFormItemConstraint *wxMakeConstraintRange(float lo, float hi);
  248.  
  249. #endif // wx_formh
  250.