Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:43

0001 // * This makes emacs happy -*-Mode: C++;-*-
0002 // vile:cppmode
0003 /****************************************************************************
0004  * Copyright 2019-2021,2022 Thomas E. Dickey                                *
0005  * Copyright 1998-2012,2014 Free Software Foundation, Inc.                  *
0006  *                                                                          *
0007  * Permission is hereby granted, free of charge, to any person obtaining a  *
0008  * copy of this software and associated documentation files (the            *
0009  * "Software"), to deal in the Software without restriction, including      *
0010  * without limitation the rights to use, copy, modify, merge, publish,      *
0011  * distribute, distribute with modifications, sublicense, and/or sell       *
0012  * copies of the Software, and to permit persons to whom the Software is    *
0013  * furnished to do so, subject to the following conditions:                 *
0014  *                                                                          *
0015  * The above copyright notice and this permission notice shall be included  *
0016  * in all copies or substantial portions of the Software.                   *
0017  *                                                                          *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
0019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
0020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
0021  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
0022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
0023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
0024  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
0025  *                                                                          *
0026  * Except as contained in this notice, the name(s) of the above copyright   *
0027  * holders shall not be used in advertising or otherwise to promote the     *
0028  * sale, use or other dealings in this Software without prior written       *
0029  * authorization.                                                           *
0030  ****************************************************************************/
0031 
0032 /****************************************************************************
0033  *   Author: Juergen Pfeifer, 1997                                          *
0034  ****************************************************************************/
0035 
0036 // $Id: cursesf.h,v 1.39 2022/08/20 20:52:15 tom Exp $
0037 
0038 #ifndef NCURSES_CURSESF_H_incl
0039 #define NCURSES_CURSESF_H_incl 1
0040 
0041 #include <ncursesw/cursesp.h>
0042 
0043 #ifndef __EXT_QNX
0044 #include <string.h>
0045 #endif
0046 
0047 extern "C" {
0048 #  include <ncursesw/form.h>
0049 }
0050 //
0051 // -------------------------------------------------------------------------
0052 // The abstract base class for builtin and user defined Fieldtypes.
0053 // -------------------------------------------------------------------------
0054 //
0055 class NCURSES_CXX_IMPEXP NCursesFormField; // forward declaration
0056 
0057 // Class to represent builtin field types as well as C++ written new
0058 // fieldtypes (see classes UserDefineFieldType...
0059 class NCURSES_CXX_IMPEXP NCursesFieldType
0060 {
0061   friend class NCursesFormField;
0062 
0063 protected:
0064   FIELDTYPE* fieldtype;
0065 
0066   inline void OnError(int err) const THROW2(NCursesException const, NCursesFormException) {
0067     if (err!=E_OK)
0068       THROW(new NCursesFormException (err));
0069   }
0070 
0071   NCursesFieldType(FIELDTYPE *f) : fieldtype(f) {
0072   }
0073 
0074   virtual ~NCursesFieldType() {}
0075 
0076   // Set the fields f fieldtype to this one.
0077   virtual void set(NCursesFormField& f) = 0;
0078 
0079 public:
0080   NCursesFieldType()
0081     : fieldtype(STATIC_CAST(FIELDTYPE*)(0))
0082   {
0083   }
0084 
0085   NCursesFieldType& operator=(const NCursesFieldType& rhs)
0086   {
0087     if (this != &rhs) {
0088       *this = rhs;
0089     }
0090     return *this;
0091   }
0092 
0093   NCursesFieldType(const NCursesFieldType& rhs)
0094     : fieldtype(rhs.fieldtype)
0095   {
0096   }
0097 
0098 };
0099 
0100 //
0101 // -------------------------------------------------------------------------
0102 // The class representing a forms field, wrapping the lowlevel FIELD struct
0103 // -------------------------------------------------------------------------
0104 //
0105 class NCURSES_CXX_IMPEXP NCursesFormField
0106 {
0107   friend class NCursesForm;
0108 
0109 protected:
0110   FIELD *field;          // lowlevel structure
0111   NCursesFieldType* ftype;   // Associated field type
0112 
0113   // Error handler
0114   inline void OnError (int err) const THROW2(NCursesException const, NCursesFormException) {
0115     if (err != E_OK)
0116       THROW(new NCursesFormException (err));
0117   }
0118 
0119 public:
0120   // Create a 'Null' field. Can be used to delimit a field list
0121   NCursesFormField()
0122     : field(STATIC_CAST(FIELD*)(0)),
0123       ftype(STATIC_CAST(NCursesFieldType*)(0))
0124   {
0125   }
0126 
0127   // Create a new field
0128   NCursesFormField (int rows,
0129             int ncols,
0130             int first_row = 0,
0131             int first_col = 0,
0132             int offscreen_rows = 0,
0133             int additional_buffers = 0)
0134     : field(0),
0135       ftype(STATIC_CAST(NCursesFieldType*)(0))
0136   {
0137       field = ::new_field(rows, ncols, first_row, first_col,
0138               offscreen_rows, additional_buffers);
0139       if (!field)
0140     OnError(errno);
0141   }
0142 
0143   NCursesFormField& operator=(const NCursesFormField& rhs)
0144   {
0145     if (this != &rhs) {
0146       *this = rhs;
0147     }
0148     return *this;
0149   }
0150 
0151   NCursesFormField(const NCursesFormField& rhs)
0152     : field(rhs.field), ftype(rhs.ftype)
0153   {
0154   }
0155 
0156   virtual ~NCursesFormField () THROWS(NCursesException);
0157 
0158   // Duplicate the field at a new position
0159   inline NCursesFormField* dup(int first_row, int first_col)
0160   {
0161     NCursesFormField* f = new NCursesFormField();
0162     if (!f)
0163       OnError(E_SYSTEM_ERROR);
0164     else {
0165       f->ftype = ftype;
0166       f->field = ::dup_field(field,first_row,first_col);
0167       if (!f->field)
0168     OnError(errno);
0169     }
0170     return f;
0171   }
0172 
0173   // Link the field to a new location
0174   inline NCursesFormField* link(int first_row, int first_col) {
0175     NCursesFormField* f = new NCursesFormField();
0176     if (!f)
0177       OnError(E_SYSTEM_ERROR);
0178     else {
0179       f->ftype = ftype;
0180       f->field = ::link_field(field,first_row,first_col);
0181       if (!f->field)
0182     OnError(errno);
0183     }
0184     return f;
0185   }
0186 
0187   // Get the lowlevel field representation
0188   inline FIELD* get_field() const {
0189     return field;
0190   }
0191 
0192   // Retrieve info about the field
0193   inline void info(int& rows, int& ncols,
0194            int& first_row, int& first_col,
0195            int& offscreen_rows, int& additional_buffers) const {
0196     OnError(::field_info(field, &rows, &ncols,
0197              &first_row, &first_col,
0198              &offscreen_rows, &additional_buffers));
0199   }
0200 
0201   // Retrieve info about the fields dynamic properties.
0202   inline void dynamic_info(int& dynamic_rows, int& dynamic_cols,
0203                int& max_growth) const {
0204     OnError(::dynamic_field_info(field, &dynamic_rows, &dynamic_cols,
0205                  &max_growth));
0206   }
0207 
0208   // For a dynamic field you may set the maximum growth limit.
0209   // A zero means unlimited growth.
0210   inline void set_maximum_growth(int growth = 0) {
0211     OnError(::set_max_field(field,growth));
0212   }
0213 
0214   // Move the field to a new position
0215   inline void move(int row, int col) {
0216     OnError(::move_field(field,row,col));
0217   }
0218 
0219   // Mark the field to start a new page
0220   inline void new_page(bool pageFlag = FALSE) {
0221     OnError(::set_new_page(field,pageFlag));
0222   }
0223 
0224   // Retrieve whether or not the field starts a new page.
0225   inline bool is_new_page() const {
0226     return ::new_page(field);
0227   }
0228 
0229   // Set the justification for the field
0230   inline void set_justification(int just) {
0231     OnError(::set_field_just(field,just));
0232   }
0233 
0234   // Retrieve the fields justification
0235   inline int justification() const {
0236     return ::field_just(field);
0237   }
0238   // Set the foreground attribute for the field
0239   inline void set_foreground(chtype foreground) {
0240     OnError(::set_field_fore(field,foreground));
0241   }
0242 
0243   // Retrieve the fields foreground attribute
0244   inline chtype fore() const {
0245     return ::field_fore(field);
0246   }
0247 
0248   // Set the background attribute for the field
0249   inline void set_background(chtype background) {
0250     OnError(::set_field_back(field,background));
0251   }
0252 
0253   // Retrieve the fields background attribute
0254   inline chtype back() const {
0255     return ::field_back(field);
0256   }
0257 
0258   // Set the padding character for the field
0259   inline void set_pad_character(int padding) {
0260     OnError(::set_field_pad(field, padding));
0261   }
0262 
0263   // Retrieve the fields padding character
0264   inline int pad() const {
0265     return ::field_pad(field);
0266   }
0267 
0268   // Switch on the fields options
0269   inline void options_on (Field_Options opts) {
0270     OnError (::field_opts_on (field, opts));
0271   }
0272 
0273   // Switch off the fields options
0274   inline void options_off (Field_Options opts) {
0275     OnError (::field_opts_off (field, opts));
0276   }
0277 
0278   // Retrieve the fields options
0279   inline Field_Options options () const {
0280     return ::field_opts (field);
0281   }
0282 
0283   // Set the fields options
0284   inline void set_options (Field_Options opts) {
0285     OnError (::set_field_opts (field, opts));
0286   }
0287 
0288   // Mark the field as changed
0289   inline void set_changed(bool changeFlag = TRUE) {
0290     OnError(::set_field_status(field,changeFlag));
0291   }
0292 
0293   // Test whether or not the field is marked as changed
0294   inline bool changed() const {
0295     return ::field_status(field);
0296   }
0297 
0298   // Return the index of the field in the field array of a form
0299   // or -1 if the field is not associated to a form
0300   inline int (index)() const {
0301     return ::field_index(field);
0302   }
0303 
0304   // Store a value in a fields buffer. The default buffer is nr. 0
0305   inline void set_value(const char *val, int buffer = 0) {
0306     OnError(::set_field_buffer(field,buffer,val));
0307   }
0308 
0309   // Retrieve the value of a fields buffer. The default buffer is nr. 0
0310   inline char* value(int buffer = 0) const {
0311     return ::field_buffer(field,buffer);
0312   }
0313 
0314   // Set the validation type of the field.
0315   inline void set_fieldtype(NCursesFieldType& f) {
0316     ftype = &f;
0317     f.set(*this); // A good friend may do that...
0318   }
0319 
0320   // Retrieve the validation type of the field.
0321   inline NCursesFieldType* fieldtype() const {
0322     return ftype;
0323   }
0324 
0325 };
0326 
0327   // This are the built-in hook functions in this C++ binding. In C++ we use
0328   // virtual member functions (see below On_..._Init and On_..._Termination)
0329   // to provide this functionality in an object oriented manner.
0330 extern "C" {
0331   void _nc_xx_frm_init(FORM *);
0332   void _nc_xx_frm_term(FORM *);
0333   void _nc_xx_fld_init(FORM *);
0334   void _nc_xx_fld_term(FORM *);
0335 }
0336 
0337 //
0338 // -------------------------------------------------------------------------
0339 // The class representing a form, wrapping the lowlevel FORM struct
0340 // -------------------------------------------------------------------------
0341 //
0342 class NCURSES_CXX_IMPEXP NCursesForm : public NCursesPanel
0343 {
0344 protected:
0345   FORM* form;  // the lowlevel structure
0346 
0347 private:
0348   NCursesWindow* sub;   // the subwindow object
0349   bool b_sub_owner;     // is this our own subwindow?
0350   bool b_framed;    // has the form a border?
0351   bool b_autoDelete;    // Delete fields when deleting form?
0352 
0353   NCursesFormField** my_fields; // The array of fields for this form
0354 
0355   // This structure is used for the form's user data field to link the
0356   // FORM* to the C++ object and to provide extra space for a user pointer.
0357   typedef struct {
0358     void*          m_user;      // the pointer for the user's data
0359     const NCursesForm* m_back;      // backward pointer to C++ object
0360     const FORM*        m_owner;
0361   } UserHook;
0362 
0363   // Get the backward pointer to the C++ object from a FORM
0364   static inline NCursesForm* getHook(const FORM *f) {
0365     UserHook* hook = reinterpret_cast<UserHook*>(::form_userptr(f));
0366     assert(hook != 0 && hook->m_owner==f);
0367     return const_cast<NCursesForm*>(hook->m_back);
0368   }
0369 
0370   friend void _nc_xx_frm_init(FORM *);
0371   friend void _nc_xx_frm_term(FORM *);
0372   friend void _nc_xx_fld_init(FORM *);
0373   friend void _nc_xx_fld_term(FORM *);
0374 
0375   // Calculate FIELD* array for the menu
0376   FIELD** mapFields(NCursesFormField* nfields[]);
0377 
0378 protected:
0379   // internal routines
0380   inline void set_user(void *user) {
0381     UserHook* uptr = reinterpret_cast<UserHook*>(::form_userptr (form));
0382     assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==form);
0383     uptr->m_user = user;
0384   }
0385 
0386   inline void *get_user() {
0387     UserHook* uptr = reinterpret_cast<UserHook*>(::form_userptr (form));
0388     assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==form);
0389     return uptr->m_user;
0390   }
0391 
0392   void InitForm (NCursesFormField* Fields[],
0393          bool with_frame,
0394          bool autoDeleteFields);
0395 
0396   inline void OnError (int err) const THROW2(NCursesException const, NCursesFormException) {
0397     if (err != E_OK)
0398       THROW(new NCursesFormException (err));
0399   }
0400 
0401   // this wraps the form_driver call.
0402   virtual int driver (int c) ;
0403 
0404   // 'Internal' constructor, builds an object without association to a
0405   // field array.
0406   NCursesForm( int  nlines,
0407            int  ncols,
0408            int  begin_y = 0,
0409            int  begin_x = 0)
0410     : NCursesPanel(nlines, ncols, begin_y, begin_x),
0411       form (STATIC_CAST(FORM*)(0)),
0412       sub(0),
0413       b_sub_owner(0),
0414       b_framed(0),
0415       b_autoDelete(0),
0416       my_fields(0)
0417   {
0418   }
0419 
0420 public:
0421   // Create form for the default panel.
0422   NCursesForm (NCursesFormField* Fields[],
0423            bool with_frame=FALSE,         // reserve space for a frame?
0424            bool autoDelete_Fields=FALSE)  // do automatic cleanup?
0425     : NCursesPanel(),
0426       form(0),
0427       sub(0),
0428       b_sub_owner(0),
0429       b_framed(0),
0430       b_autoDelete(0),
0431       my_fields(0)
0432   {
0433     InitForm(Fields, with_frame, autoDelete_Fields);
0434   }
0435 
0436   // Create a form in a panel with the given position and size.
0437   NCursesForm (NCursesFormField* Fields[],
0438            int  nlines,
0439            int  ncols,
0440            int  begin_y,
0441            int  begin_x,
0442            bool with_frame=FALSE,        // reserve space for a frame?
0443            bool autoDelete_Fields=FALSE) // do automatic cleanup?
0444     : NCursesPanel(nlines, ncols, begin_y, begin_x),
0445       form(0),
0446       sub(0),
0447       b_sub_owner(0),
0448       b_framed(0),
0449       b_autoDelete(0),
0450       my_fields(0)
0451   {
0452       InitForm(Fields, with_frame, autoDelete_Fields);
0453   }
0454 
0455   NCursesForm& operator=(const NCursesForm& rhs)
0456   {
0457     if (this != &rhs) {
0458       *this = rhs;
0459       NCursesPanel::operator=(rhs);
0460     }
0461     return *this;
0462   }
0463 
0464   NCursesForm(const NCursesForm& rhs)
0465     : NCursesPanel(rhs),
0466       form(rhs.form),
0467       sub(rhs.sub),
0468       b_sub_owner(rhs.b_sub_owner),
0469       b_framed(rhs.b_framed),
0470       b_autoDelete(rhs.b_autoDelete),
0471       my_fields(rhs.my_fields)
0472   {
0473   }
0474 
0475   virtual ~NCursesForm() THROWS(NCursesException);
0476 
0477   // Set the default attributes for the form
0478   virtual void setDefaultAttributes();
0479 
0480   // Retrieve current field of the form.
0481   inline NCursesFormField* current_field() const {
0482     return my_fields[::field_index(::current_field(form))];
0483   }
0484 
0485   // Set the forms subwindow
0486   void setSubWindow(NCursesWindow& sub);
0487 
0488   // Set these fields for the form
0489   inline void setFields(NCursesFormField* Fields[]) {
0490     OnError(::set_form_fields(form,mapFields(Fields)));
0491   }
0492 
0493   // Remove the form from the screen
0494   inline void unpost (void) {
0495     OnError (::unpost_form (form));
0496   }
0497 
0498   // Post the form to the screen if flag is true, unpost it otherwise
0499   inline void post(bool flag = TRUE) {
0500     OnError (flag ? ::post_form(form) : ::unpost_form (form));
0501   }
0502 
0503   // Decorations
0504   inline void frame(const char *title=NULL, const char* btitle=NULL) NCURSES_OVERRIDE {
0505     if (b_framed)
0506       NCursesPanel::frame(title,btitle);
0507     else
0508       OnError(E_SYSTEM_ERROR);
0509   }
0510 
0511   inline void boldframe(const char *title=NULL, const char* btitle=NULL) NCURSES_OVERRIDE {
0512     if (b_framed)
0513       NCursesPanel::boldframe(title,btitle);
0514     else
0515       OnError(E_SYSTEM_ERROR);
0516   }
0517 
0518   inline void label(const char *topLabel, const char *bottomLabel) NCURSES_OVERRIDE {
0519     if (b_framed)
0520       NCursesPanel::label(topLabel,bottomLabel);
0521     else
0522       OnError(E_SYSTEM_ERROR);
0523   }
0524 
0525   // -----
0526   // Hooks
0527   // -----
0528 
0529   // Called after the form gets repositioned in its window.
0530   // This is especially true if the form is posted.
0531   virtual void On_Form_Init();
0532 
0533   // Called before the form gets repositioned in its window.
0534   // This is especially true if the form is unposted.
0535   virtual void On_Form_Termination();
0536 
0537   // Called after the field became the current field
0538   virtual void On_Field_Init(NCursesFormField& field);
0539 
0540   // Called before this field is left as current field.
0541   virtual void On_Field_Termination(NCursesFormField& field);
0542 
0543   // Calculate required window size for the form.
0544   void scale(int& rows, int& ncols) const {
0545     OnError(::scale_form(form,&rows,&ncols));
0546   }
0547 
0548   // Retrieve number of fields in the form.
0549   int count() const {
0550     return ::field_count(form);
0551   }
0552 
0553   // Make the page the current page of the form.
0554   void set_page(int pageNum) {
0555     OnError(::set_form_page(form, pageNum));
0556   }
0557 
0558   // Retrieve current page number
0559   int page() const {
0560     return ::form_page(form);
0561   }
0562 
0563   // Switch on the forms options
0564   inline void options_on (Form_Options opts) {
0565     OnError (::form_opts_on (form, opts));
0566   }
0567 
0568   // Switch off the forms options
0569   inline void options_off (Form_Options opts) {
0570     OnError (::form_opts_off (form, opts));
0571   }
0572 
0573   // Retrieve the forms options
0574   inline Form_Options options () const {
0575     return ::form_opts (form);
0576   }
0577 
0578   // Set the forms options
0579   inline void set_options (Form_Options opts) {
0580     OnError (::set_form_opts (form, opts));
0581   }
0582 
0583   // Are there more data in the current field after the data shown
0584   inline bool data_ahead() const {
0585     return ::data_ahead(form);
0586   }
0587 
0588   // Are there more data in the current field before the data shown
0589   inline bool data_behind() const {
0590     return ::data_behind(form);
0591   }
0592 
0593   // Position the cursor to the current field
0594   inline void position_cursor () {
0595     OnError (::pos_form_cursor (form));
0596   }
0597   // Set the current field
0598   inline void set_current(NCursesFormField& F) {
0599     OnError (::set_current_field(form, F.field));
0600   }
0601 
0602   // Provide a default key virtualization. Translate the keyboard
0603   // code c into a form request code.
0604   // The default implementation provides a hopefully straightforward
0605   // mapping for the most common keystrokes and form requests.
0606   virtual int virtualize(int c);
0607 
0608   // Operators
0609   inline NCursesFormField* operator[](int i) const {
0610     if ( (i < 0) || (i >= ::field_count (form)) )
0611       OnError (E_BAD_ARGUMENT);
0612     return my_fields[i];
0613   }
0614 
0615   // Perform the menu's operation
0616   // Return the field where you left the form.
0617   virtual NCursesFormField* operator()(void);
0618 
0619   // Exception handlers. The default is a Beep.
0620   virtual void On_Request_Denied(int c) const;
0621   virtual void On_Invalid_Field(int c) const;
0622   virtual void On_Unknown_Command(int c) const;
0623 
0624 };
0625 
0626 //
0627 // -------------------------------------------------------------------------
0628 // This is the typical C++ typesafe way to allow to attach
0629 // user data to a field of a form. Its assumed that the user
0630 // data belongs to some class T. Use T as template argument
0631 // to create a UserField.
0632 // -------------------------------------------------------------------------
0633 template<class T> class NCURSES_CXX_IMPEXP NCursesUserField : public NCursesFormField
0634 {
0635 public:
0636   NCursesUserField (int rows,
0637             int ncols,
0638             int first_row = 0,
0639             int first_col = 0,
0640             const T* p_UserData = STATIC_CAST(T*)(0),
0641             int offscreen_rows = 0,
0642             int additional_buffers = 0)
0643     : NCursesFormField (rows, ncols,
0644             first_row, first_col,
0645             offscreen_rows, additional_buffers) {
0646       if (field)
0647     OnError(::set_field_userptr(field, STATIC_CAST(void *)(p_UserData)));
0648   }
0649 
0650   virtual ~NCursesUserField() THROWS(NCursesException) {};
0651 
0652   inline const T* UserData (void) const {
0653     return reinterpret_cast<const T*>(::field_userptr (field));
0654   }
0655 
0656   inline virtual void setUserData(const T* p_UserData) {
0657     if (field)
0658       OnError (::set_field_userptr (field, STATIC_CAST(void *)(p_UserData)));
0659   }
0660 };
0661 //
0662 // -------------------------------------------------------------------------
0663 // The same mechanism is used to attach user data to a form
0664 // -------------------------------------------------------------------------
0665 //
0666 template<class T> class NCURSES_CXX_IMPEXP NCursesUserForm : public NCursesForm
0667 {
0668 protected:
0669   // 'Internal' constructor, builds an object without association to a
0670   // field array.
0671   NCursesUserForm( int  nlines,
0672            int  ncols,
0673            int  begin_y = 0,
0674            int  begin_x = 0,
0675            const T* p_UserData = STATIC_CAST(T*)(0))
0676     : NCursesForm(nlines,ncols,begin_y,begin_x) {
0677       if (form)
0678     set_user (const_cast<void *>(reinterpret_cast<const void*>
0679                      (p_UserData)));
0680   }
0681 
0682 public:
0683   NCursesUserForm (NCursesFormField* Fields[],
0684            const T* p_UserData = STATIC_CAST(T*)(0),
0685            bool with_frame=FALSE,
0686            bool autoDelete_Fields=FALSE)
0687     : NCursesForm (Fields, with_frame, autoDelete_Fields) {
0688       if (form)
0689     set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
0690   };
0691 
0692   NCursesUserForm (NCursesFormField* Fields[],
0693            int nlines,
0694            int ncols,
0695            int begin_y = 0,
0696            int begin_x = 0,
0697            const T* p_UserData = STATIC_CAST(T*)(0),
0698            bool with_frame=FALSE,
0699            bool autoDelete_Fields=FALSE)
0700     : NCursesForm (Fields, nlines, ncols, begin_y, begin_x,
0701            with_frame, autoDelete_Fields) {
0702       if (form)
0703     set_user (const_cast<void *>(reinterpret_cast<const void*>
0704                      (p_UserData)));
0705   };
0706 
0707   virtual ~NCursesUserForm() THROWS(NCursesException) {
0708   };
0709 
0710   inline T* UserData (void) {
0711     return reinterpret_cast<T*>(get_user ());
0712   };
0713 
0714   inline virtual void setUserData (const T* p_UserData) {
0715     if (form)
0716       set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
0717   }
0718 
0719 };
0720 //
0721 // -------------------------------------------------------------------------
0722 // Builtin Fieldtypes
0723 // -------------------------------------------------------------------------
0724 //
0725 class NCURSES_CXX_IMPEXP Alpha_Field : public NCursesFieldType
0726 {
0727 private:
0728   int min_field_width;
0729 
0730   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0731     OnError(::set_field_type(f.get_field(),fieldtype,min_field_width));
0732   }
0733 
0734 public:
0735   explicit Alpha_Field(int width)
0736     : NCursesFieldType(TYPE_ALPHA),
0737       min_field_width(width) {
0738   }
0739 };
0740 
0741 class NCURSES_CXX_IMPEXP Alphanumeric_Field : public NCursesFieldType
0742 {
0743 private:
0744   int min_field_width;
0745 
0746   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0747     OnError(::set_field_type(f.get_field(),fieldtype,min_field_width));
0748   }
0749 
0750 public:
0751   explicit Alphanumeric_Field(int width)
0752     : NCursesFieldType(TYPE_ALNUM),
0753       min_field_width(width) {
0754   }
0755 };
0756 
0757 class NCURSES_CXX_IMPEXP Integer_Field : public NCursesFieldType
0758 {
0759 private:
0760   int precision;
0761   long lower_limit, upper_limit;
0762 
0763   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0764     OnError(::set_field_type(f.get_field(),fieldtype,
0765                  precision,lower_limit,upper_limit));
0766   }
0767 
0768 public:
0769   Integer_Field(int prec, long low=0L, long high=0L)
0770     : NCursesFieldType(TYPE_INTEGER),
0771       precision(prec), lower_limit(low), upper_limit(high) {
0772   }
0773 };
0774 
0775 class NCURSES_CXX_IMPEXP Numeric_Field : public NCursesFieldType
0776 {
0777 private:
0778   int precision;
0779   double lower_limit, upper_limit;
0780 
0781   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0782     OnError(::set_field_type(f.get_field(),fieldtype,
0783                  precision,lower_limit,upper_limit));
0784   }
0785 
0786 public:
0787   Numeric_Field(int prec, double low=0.0, double high=0.0)
0788     : NCursesFieldType(TYPE_NUMERIC),
0789       precision(prec), lower_limit(low), upper_limit(high) {
0790   }
0791 };
0792 
0793 class NCURSES_CXX_IMPEXP Regular_Expression_Field : public NCursesFieldType
0794 {
0795 private:
0796   char* regex;
0797 
0798   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0799     OnError(::set_field_type(f.get_field(),fieldtype,regex));
0800   }
0801 
0802   void copy_regex(const char *source)
0803   {
0804     regex = new char[1 + ::strlen(source)];
0805     (::strcpy)(regex, source);
0806   }
0807 
0808 public:
0809   explicit Regular_Expression_Field(const char *expr)
0810     : NCursesFieldType(TYPE_REGEXP),
0811       regex(NULL)
0812   {
0813     copy_regex(expr);
0814   }
0815 
0816   Regular_Expression_Field& operator=(const Regular_Expression_Field& rhs)
0817   {
0818     if (this != &rhs) {
0819       *this = rhs;
0820       copy_regex(rhs.regex);
0821       NCursesFieldType::operator=(rhs);
0822     }
0823     return *this;
0824   }
0825 
0826   Regular_Expression_Field(const Regular_Expression_Field& rhs)
0827     : NCursesFieldType(rhs),
0828       regex(NULL)
0829   {
0830     copy_regex(rhs.regex);
0831   }
0832 
0833   ~Regular_Expression_Field() {
0834     delete[] regex;
0835   }
0836 };
0837 
0838 class NCURSES_CXX_IMPEXP Enumeration_Field : public NCursesFieldType
0839 {
0840 private:
0841   const char** list;
0842   int case_sensitive;
0843   int non_unique_matches;
0844 
0845   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0846     OnError(::set_field_type(f.get_field(),fieldtype,
0847                  list,case_sensitive,non_unique_matches));
0848   }
0849 public:
0850   Enumeration_Field(const char* enums[],
0851             bool case_sens=FALSE,
0852             bool non_unique=FALSE)
0853     : NCursesFieldType(TYPE_ENUM),
0854       list(enums),
0855       case_sensitive(case_sens ? -1 : 0),
0856       non_unique_matches(non_unique ? -1 : 0) {
0857   }
0858 
0859   Enumeration_Field& operator=(const Enumeration_Field& rhs)
0860   {
0861     if (this != &rhs) {
0862       *this = rhs;
0863       NCursesFieldType::operator=(rhs);
0864     }
0865     return *this;
0866   }
0867 
0868   Enumeration_Field(const Enumeration_Field& rhs)
0869     : NCursesFieldType(rhs),
0870       list(rhs.list),
0871       case_sensitive(rhs.case_sensitive),
0872       non_unique_matches(rhs.non_unique_matches)
0873   {
0874   }
0875 };
0876 
0877 class NCURSES_CXX_IMPEXP IPV4_Address_Field : public NCursesFieldType
0878 {
0879 private:
0880   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0881     OnError(::set_field_type(f.get_field(),fieldtype));
0882   }
0883 
0884 public:
0885   IPV4_Address_Field() : NCursesFieldType(TYPE_IPV4) {
0886   }
0887 };
0888 
0889 extern "C" {
0890   bool _nc_xx_fld_fcheck(FIELD *, const void*);
0891   bool _nc_xx_fld_ccheck(int c, const void *);
0892   void* _nc_xx_fld_makearg(va_list*);
0893 }
0894 
0895 //
0896 // -------------------------------------------------------------------------
0897 // Abstract base class for User-Defined Fieldtypes
0898 // -------------------------------------------------------------------------
0899 //
0900 class NCURSES_CXX_IMPEXP UserDefinedFieldType : public NCursesFieldType
0901 {
0902   friend class UDF_Init; // Internal helper to set up statics
0903 private:
0904   // For all C++ defined fieldtypes we need only one generic lowlevel
0905   // FIELDTYPE* element.
0906   static FIELDTYPE* generic_fieldtype;
0907 
0908 protected:
0909   // This are the functions required by the low level libforms functions
0910   // to construct a fieldtype.
0911   friend bool _nc_xx_fld_fcheck(FIELD *, const void*);
0912   friend bool _nc_xx_fld_ccheck(int c, const void *);
0913   friend void* _nc_xx_fld_makearg(va_list*);
0914 
0915   void set(NCursesFormField& f) NCURSES_OVERRIDE {
0916     OnError(::set_field_type(f.get_field(),fieldtype,&f));
0917   }
0918 
0919 protected:
0920   // Redefine this function to do a field validation. The argument
0921   // is a reference to the field you should validate.
0922   virtual bool field_check(NCursesFormField& f) = 0;
0923 
0924   // Redefine this function to do a character validation. The argument
0925   // is the character to be validated.
0926   virtual bool char_check (int c) = 0;
0927 
0928 public:
0929   UserDefinedFieldType();
0930 };
0931 
0932 extern "C" {
0933   bool _nc_xx_next_choice(FIELD*, const void *);
0934   bool _nc_xx_prev_choice(FIELD*, const void *);
0935 }
0936 
0937 //
0938 // -------------------------------------------------------------------------
0939 // Abstract base class for User-Defined Fieldtypes with Choice functions
0940 // -------------------------------------------------------------------------
0941 //
0942 class NCURSES_CXX_IMPEXP UserDefinedFieldType_With_Choice : public UserDefinedFieldType
0943 {
0944   friend class UDF_Init; // Internal helper to set up statics
0945 private:
0946   // For all C++ defined fieldtypes with choice functions we need only one
0947   // generic lowlevel FIELDTYPE* element.
0948   static FIELDTYPE* generic_fieldtype_with_choice;
0949 
0950   // This are the functions required by the low level libforms functions
0951   // to construct a fieldtype with choice functions.
0952   friend bool _nc_xx_next_choice(FIELD*, const void *);
0953   friend bool _nc_xx_prev_choice(FIELD*, const void *);
0954 
0955 protected:
0956   // Redefine this function to do the retrieval of the next choice value.
0957   // The argument is a reference to the field tobe examined.
0958   virtual bool next    (NCursesFormField& f) = 0;
0959 
0960   // Redefine this function to do the retrieval of the previous choice value.
0961   // The argument is a reference to the field tobe examined.
0962   virtual bool previous(NCursesFormField& f) = 0;
0963 
0964 public:
0965   UserDefinedFieldType_With_Choice();
0966 };
0967 
0968 #endif /* NCURSES_CURSESF_H_incl */