#pragma implementation #include #include #include #include #include "internal.h" #include "dialog.h" #include "fcombo.h" #include "dialog.m" #include "../diajava/proto.h" PUBLIC ELM_STR::ELM_STR( const char *_value, const char *_shown, const char *_verbose) { value = strdup(_value); shown = strdup(_shown); verbose = strdup(_verbose); } PUBLIC ELM_STR::~ELM_STR() { free (value); free (shown); free (verbose); } PUBLIC ELM_STR *LIST_STR::getitem(int no) const { return (ELM_STR*)ARRAY::getitem(no); } /* Get the "significative" value associate of one item of the choice list */ PUBLIC const char *LIST_STR::getshown(int no) const { const char *ret = ""; ELM_STR *e = getitem(no); if (e != NULL){ ret = e->shown; } return ret; } /* #Specification: FIELD_COMBO / principle The FIELD_COMBO class is a string editor with an assist hot key. When triggered a list of string is displayed and the user is allowed to pick a value from there. The value (if selected) will replace the input buffer. */ # PUBLIC FIELD_COMBO::FIELD_COMBO( const char *_prompt, SSTRING &_str, int maxsiz) : FIELD_STRING_HELP (_prompt,_str,maxsiz) { opts = new LIST_STR; listvalueonly = 0; } /* #Specification: FIELD_LIST / principle The FIELD_LIST class is a selector editor with an assist hot key. When triggered a list of string is displayed and the user is allowed to pick a value from there. The value (if selected) will replace the input buffer. The use may either use the input buffer to type the value or use the list, but the input has to come from the list. */ # PUBLIC FIELD_LIST::FIELD_LIST( const char *_prompt, SSTRING &_str) : FIELD_COMBO (_prompt,_str,30) { listvalueonly = 1; } PUBLIC FIELD_COMBO::~FIELD_COMBO() { delete opts; } /* Add one string option to the combo box pick list */ PUBLIC void FIELD_COMBO::addopt(const char *str) { opts->add (new ELM_STR(str,str,"")); } /* Add several string options to the combo box pick list */ PUBLIC void FIELD_COMBO::addopts(const SSTRINGS &lst) { int n = lst.getnb(); for (int i=0; iget()); } } /* Add one string option to the combo box pick list. This time there is two string. The strings will be show in the pick list like this value verbose */ PUBLIC void FIELD_COMBO::addopt(const char *value, const char *verbose) { opts->add (new ELM_STR(value,value,verbose)); } PUBLIC void FIELD_LIST::addopt(const char *value, const char *verbose) { FIELD_COMBO::addopt(value,verbose); } PUBLIC void FIELD_LIST::addopt(const char *str) { FIELD_COMBO::addopt(str); } /* Add one string option with translation to the combo box pick list. This time there is two string. The strings will be show in the pick list like this value verbose */ PUBLIC void FIELD_LIST::addopt( const char *value, // Real value we want in the edit variable const char *shown, // Value presented to the user const char *verbose) // Description of the value { if (strcmp(buf,value)==0) strcpy (buf,shown); opts->add (new ELM_STR(value,shown,verbose)); } /* Add several string options to the combo box pick list */ PUBLIC void FIELD_COMBO::addopts(const SSTRING_KEYS &lst) { int n = lst.getnb(); for (int i=0; iget(),k->getobjval()); } } PROTECTED void FIELD_COMBO::assist(WINDOW *dialog) { int nbopt = opts->getnb(); DIALOG dia; int nof = 0; for (int i=0; igetitem(i); const char *val = elm->shown; dia.new_menuitem (val,elm->verbose); if (strcmp(buf,val)==0) nof = i; } MENU_STATUS ret = dia.editmenu (MSG_U(T_HELPLIST,"Help list") ,MSG_U(I_HELPLIST,"Pick one value") ,help_nil ,nof,0); touchwin(stdscr); touchwin(dialog); if (ret == MENU_OK && nof >=0 && nof < nbopt){ strcpy (buf,opts->getshown(nof)); draw(dialog,0,0,0); } } PUBLIC void FIELD_COMBO::html_draw(int nof) { char key[100]; format_htmlkey (key,nof); html_printf ("%s",prompt); if (readonly){ html_printf ("%s\n",buf); }else{ if (!listvalueonly){ html_defvar ("text",key,buf,"size=30 maxlength=256"); } html_defvarcur (key,backup.get()); int n = opts->getnb(); if (n > 0){ char sel_key[100]; sprintf (sel_key,"SELECT_%s",key); html_defselect (sel_key); if (!listvalueonly) html_printf ("