X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursesf.cc;h=aaf1202ca94e3c5fb7751ea60aa710bc9ec38a3c;hp=66a6f09eca493fe11484cec1c7d62e0a45168df1;hb=d44d7f381ba0173521cb788ba3adb12e261e5c96;hpb=661078ddbde3ce0f3b06e95642fbb9b5fef7dca1 diff --git a/c++/cursesf.cc b/c++/cursesf.cc index 66a6f09e..aaf1202c 100644 --- a/c++/cursesf.cc +++ b/c++/cursesf.cc @@ -1,6 +1,6 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -28,16 +28,17 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer 1997 * + * Author: Juergen Pfeifer, 1997 * ****************************************************************************/ +#include "internal.h" #include "cursesf.h" #include "cursesapp.h" -#include "internal.h" -MODULE_ID("$Id: cursesf.cc,v 1.7 1998/02/11 12:13:41 tom Exp $") - -NCursesFormField::~NCursesFormField () { +MODULE_ID("$Id: cursesf.cc,v 1.21 2005/08/13 18:09:06 tom Exp $") + +NCursesFormField::~NCursesFormField () +{ if (field) OnError(::free_field (field)); } @@ -46,29 +47,34 @@ NCursesFormField::~NCursesFormField () { * objects. */ FIELD** -NCursesForm::mapFields(NCursesFormField* nfields[]) { +NCursesForm::mapFields(NCursesFormField* nfields[]) +{ int fieldCount = 0,lcv; - - assert(nfields); + FIELD** old_fields; + + assert(nfields != 0); for (lcv=0; nfields[lcv]->field; ++lcv) ++fieldCount; - + FIELD** fields = new FIELD*[fieldCount + 1]; - + for (lcv=0;nfields[lcv]->field;++lcv) { fields[lcv] = nfields[lcv]->field; } fields[lcv] = NULL; - + my_fields = nfields; - - if (form) - delete[] ::form_fields(form); + + if (form && (old_fields = ::form_fields(form))) { + ::set_form_fields(form, static_cast(0)); + delete[] old_fields; + } return fields; } -void NCursesForm::setDefaultAttributes() { +void NCursesForm::setDefaultAttributes() +{ NCursesApplication* S = NCursesApplication::getApplication(); int n = count(); @@ -99,78 +105,81 @@ void NCursesForm::setDefaultAttributes() { void NCursesForm::InitForm(NCursesFormField* nfields[], bool with_frame, - bool autoDelete_Fields) { + bool autoDelete_Fields) +{ int mrows, mcols; - + keypad(TRUE); meta(TRUE); b_framed = with_frame; b_autoDelete = autoDelete_Fields; - form = (FORM*)0; + form = static_cast(0); form = ::new_form(mapFields(nfields)); if (!form) OnError (E_SYSTEM_ERROR); - + UserHook* hook = new UserHook; hook->m_user = NULL; hook->m_back = this; hook->m_owner = form; - ::set_form_userptr(form,(void*)hook); - - ::set_form_init (form, NCursesForm::frm_init); - ::set_form_term (form, NCursesForm::frm_term); - ::set_field_init (form, NCursesForm::fld_init); - ::set_field_term (form, NCursesForm::fld_term); - + ::set_form_userptr(form, reinterpret_cast(hook)); + + ::set_form_init (form, _nc_xx_frm_init); + ::set_form_term (form, _nc_xx_frm_term); + ::set_field_init (form, _nc_xx_fld_init); + ::set_field_term (form, _nc_xx_fld_term); + scale(mrows, mcols); ::set_form_win(form, w); - + if (with_frame) { if ((mrows > height()-2) || (mcols > width()-2)) - OnError(E_NO_ROOM); + OnError(E_NO_ROOM); sub = new NCursesWindow(*this,mrows,mcols,1,1,'r'); ::set_form_sub(form, sub->w); b_sub_owner = TRUE; } else { - sub = (NCursesWindow*)0; + sub = static_cast(0); b_sub_owner = FALSE; } options_on(O_NL_OVERLOAD); setDefaultAttributes(); } -NCursesForm::~NCursesForm() { - UserHook* hook = (UserHook*)::form_userptr(form); +NCursesForm::~NCursesForm() +{ + UserHook* hook = reinterpret_cast(::form_userptr(form)); delete hook; if (b_sub_owner) { delete sub; - ::set_form_sub(form,(WINDOW *)0); + ::set_form_sub(form, static_cast(0)); } if (form) { FIELD** fields = ::form_fields(form); int cnt = count(); - OnError(::set_form_fields(form,(FIELD**)0)); + OnError(::set_form_fields(form, static_cast(0))); if (b_autoDelete) { if (cnt>0) { for (int i=0; i <= cnt; i++) - delete my_fields[i]; + delete my_fields[i]; } delete[] my_fields; } ::free_form(form); // It's essential to do this after free_form() - delete[] fields; + delete[] fields; } } void -NCursesForm::setSubWindow(NCursesWindow& nsub) { +NCursesForm::setSubWindow(NCursesWindow& nsub) +{ if (!isDescendant(nsub)) OnError(E_SYSTEM_ERROR); else { @@ -183,50 +192,59 @@ NCursesForm::setSubWindow(NCursesWindow& nsub) { /* Internal hook functions. They will route the hook * calls to virtual methods of the NCursesForm class, - * so in C++ providing a hook is done simply by + * so in C++ providing a hook is done simply by * implementing a virtual method in a derived class */ void -NCursesForm::frm_init(FORM *f) { - getHook(f)->On_Form_Init(); +_nc_xx_frm_init(FORM *f) +{ + NCursesForm::getHook(f)->On_Form_Init(); } void -NCursesForm::frm_term(FORM *f) { - getHook(f)->On_Form_Termination(); +_nc_xx_frm_term(FORM *f) +{ + NCursesForm::getHook(f)->On_Form_Termination(); } void -NCursesForm::fld_init(FORM *f) { - NCursesForm* F = getHook(f); +_nc_xx_fld_init(FORM *f) +{ + NCursesForm* F = NCursesForm::getHook(f); F->On_Field_Init (*(F->current_field ())); } void -NCursesForm::fld_term(FORM *f) { - NCursesForm* F = getHook(f); +_nc_xx_fld_term(FORM *f) +{ + NCursesForm* F = NCursesForm::getHook(f); F->On_Field_Termination (*(F->current_field ())); } void -NCursesForm::On_Form_Init() { +NCursesForm::On_Form_Init() +{ } void -NCursesForm::On_Form_Termination() { +NCursesForm::On_Form_Termination() +{ } void -NCursesForm::On_Field_Init(NCursesFormField& field) { +NCursesForm::On_Field_Init(NCursesFormField& field) +{ } void -NCursesForm::On_Field_Termination(NCursesFormField& field) { +NCursesForm::On_Field_Termination(NCursesFormField& field) +{ } // call the form driver and do basic error checking. -int -NCursesForm::driver (int c) { +int +NCursesForm::driver (int c) +{ int res = ::form_driver (form, c); switch (res) { case E_OK: @@ -240,22 +258,26 @@ NCursesForm::driver (int c) { return (res); } -void NCursesForm::On_Request_Denied(int c) const { - beep(); +void NCursesForm::On_Request_Denied(int c) const +{ + ::beep(); } -void NCursesForm::On_Invalid_Field(int c) const { - beep(); +void NCursesForm::On_Invalid_Field(int c) const +{ + ::beep(); } -void NCursesForm::On_Unknown_Command(int c) const { - beep(); +void NCursesForm::On_Unknown_Command(int c) const +{ + ::beep(); } static const int CMD_QUIT = MAX_COMMAND + 1; NCursesFormField* -NCursesForm::operator()(void) { +NCursesForm::operator()(void) +{ int drvCmnd; int err; int c; @@ -263,8 +285,8 @@ NCursesForm::operator()(void) { post(); show(); refresh(); - - while (((drvCmnd = virtualize((c=getch()))) != CMD_QUIT)) { + + while (((drvCmnd = virtualize((c=getKey()))) != CMD_QUIT)) { switch((err=driver(drvCmnd))) { case E_REQUEST_DENIED: On_Request_Denied(c); @@ -292,8 +314,9 @@ NCursesForm::operator()(void) { // code c into a form request code. // The default implementation provides a hopefully straightforward // mapping for the most common keystrokes and form requests. -int -NCursesForm::virtualize(int c) { +int +NCursesForm::virtualize(int c) +{ switch(c) { case KEY_HOME : return(REQ_FIRST_FIELD); @@ -315,7 +338,7 @@ NCursesForm::virtualize(int c) { case CTRL('F') : return(REQ_NEXT_FIELD); // Forward case CTRL('B') : return(REQ_PREV_FIELD); // Backward - case CTRL('L') : return(REQ_LEFT_FIELD); // Left + case CTRL('L') : return(REQ_LEFT_FIELD); // Left case CTRL('R') : return(REQ_RIGHT_FIELD); // Right case CTRL('U') : return(REQ_UP_FIELD); // Up case CTRL('D') : return(REQ_DOWN_FIELD); // Down @@ -338,7 +361,7 @@ NCursesForm::virtualize(int c) { case CTRL('N') : return(REQ_NEXT_CHOICE); case CTRL('P') : return(REQ_PREV_CHOICE); - + default: return(c); } @@ -348,76 +371,84 @@ NCursesForm::virtualize(int c) { // User Defined Fieldtypes // ------------------------------------------------------------------------- // -bool UserDefinedFieldType::fcheck(FIELD *f, const void *u) { - NCursesFormField* F = (NCursesFormField*)u; - assert(F); - UserDefinedFieldType* udf = (UserDefinedFieldType*)(F->fieldtype()); - assert(udf); +bool _nc_xx_fld_fcheck(FIELD *f, const void *u) +{ + NCursesFormField* F = reinterpret_cast(const_cast(u)); + assert(F != 0); + UserDefinedFieldType* udf = reinterpret_cast(F->fieldtype()); + assert(udf != 0); return udf->field_check(*F); } -bool UserDefinedFieldType::ccheck(int c, const void *u) { - NCursesFormField* F = (NCursesFormField*)u; - assert(F); - UserDefinedFieldType* udf = - (UserDefinedFieldType*)(F->fieldtype()); - assert(udf); +bool _nc_xx_fld_ccheck(int c, const void *u) +{ + NCursesFormField* F = reinterpret_cast(const_cast(u)); + assert(F != 0); + UserDefinedFieldType* udf = + reinterpret_cast(F->fieldtype()); + assert(udf != 0); return udf->char_check(c); } -void* UserDefinedFieldType::makearg(va_list* va) { +void* _nc_xx_fld_makearg(va_list* va) +{ return va_arg(*va,NCursesFormField*); } FIELDTYPE* UserDefinedFieldType::generic_fieldtype = - ::new_fieldtype(UserDefinedFieldType::fcheck, - UserDefinedFieldType::ccheck); + ::new_fieldtype(_nc_xx_fld_fcheck, + _nc_xx_fld_ccheck); FIELDTYPE* UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice = - ::new_fieldtype(UserDefinedFieldType::fcheck, - UserDefinedFieldType::ccheck); - -bool UserDefinedFieldType_With_Choice::next_choice(FIELD *f, const void *u) { - NCursesFormField* F = (NCursesFormField*)u; - assert(F); - UserDefinedFieldType_With_Choice* udf = - (UserDefinedFieldType_With_Choice*)(F->fieldtype()); - assert(udf); + ::new_fieldtype(_nc_xx_fld_fcheck, + _nc_xx_fld_ccheck); + +bool _nc_xx_next_choice(FIELD *f, const void *u) +{ + NCursesFormField* F = reinterpret_cast(const_cast(u)); + assert(F != 0); + UserDefinedFieldType_With_Choice* udf = + reinterpret_cast(F->fieldtype()); + assert(udf != 0); return udf->next(*F); } -bool UserDefinedFieldType_With_Choice::prev_choice(FIELD *f, const void *u) { - NCursesFormField* F = (NCursesFormField*)u; - assert(F); - UserDefinedFieldType_With_Choice* udf = - (UserDefinedFieldType_With_Choice*)(F->fieldtype()); - assert(udf); +bool _nc_xx_prev_choice(FIELD *f, const void *u) +{ + NCursesFormField* F = reinterpret_cast(const_cast(u)); + assert(F != 0); + UserDefinedFieldType_With_Choice* udf = + reinterpret_cast(F->fieldtype()); + assert(udf != 0); return udf->previous(*F); } -class UDF_Init { +class UDF_Init +{ private: int code; static UDF_Init* I; + public: - UDF_Init() { + UDF_Init() + : code(0) + { code = ::set_fieldtype_arg(UserDefinedFieldType::generic_fieldtype, - UserDefinedFieldType::makearg, + _nc_xx_fld_makearg, NULL, NULL); - if (code==E_OK) + if (code==E_OK) code = ::set_fieldtype_arg (UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice, - UserDefinedFieldType::makearg, + _nc_xx_fld_makearg, NULL, NULL); if (code==E_OK) code = ::set_fieldtype_choice (UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice, - UserDefinedFieldType_With_Choice::next_choice, - UserDefinedFieldType_With_Choice::prev_choice); + _nc_xx_next_choice, + _nc_xx_prev_choice); } }; UDF_Init* UDF_Init::I = new UDF_Init(); -