Listbox negli sheet, quasi funzionanti

git-svn-id: svn://10.65.10.50/trunk@2787 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1996-05-10 09:26:40 +00:00
parent 3043bbda5a
commit 936b537b34
10 changed files with 3169 additions and 3075 deletions

View File

@ -1523,12 +1523,18 @@ void TDropDownList::select_by_initial(char c)
}
}
void TDropDownList::select_by_ofs(int i)
{
i += _selected;
if (i >= 0 && i < _values.items())
select(i);
}
TDropDownList::TDropDownList(XI_OBJ* o, const char* values, int width, bool cell)
: _xi_obj(o), _values(values), _open(FALSE), _xi_lst(NULL), _width(width),
_displayed(FALSE), _in_cell(cell)
_displayed(FALSE), _in_cell(cell), _selected(0)
{}
void TDropDownList::open()
{
if (_open) return;
@ -1633,20 +1639,14 @@ bool TListbox_control::event_handler(XI_OBJ* itf, XI_EVENT* xiev)
case XIE_CHAR_FIELD:
{
const KEY k = xiev_to_key(xiev);
if (is_edit_key(k) && isalnum(k))
if (isalnum(k))
_ddl->select_by_initial(k);
else if (k == K_F9)
_ddl->open();
else if (k == K_RIGHT) // poor man's substitute for down arrow
{
if (selected() < items()-1)
select(selected() + 1);
}
_ddl->select_by_ofs(1);
else if (k == K_LEFT) // poor man's substitute for up arrow
{
if (selected() > 0)
select(selected() - 1);
}
_ddl->select_by_ofs(-1);
xiev->refused = TRUE;
}
break;
@ -1660,16 +1660,6 @@ bool TListbox_control::event_handler(XI_OBJ* itf, XI_EVENT* xiev)
return ok;
}
void TListbox_control::select(int k)
{
_ddl->select(k);
}
int TListbox_control::selected() const
{
return _ddl->selected();
}
void TListbox_control::set_values(const char* val)
{
_values = val;

View File

@ -280,6 +280,7 @@ class TDropDownList : public TObject
const int selected() const { return _selected; }
void select_by_initial(char c);
void select_by_ofs(int n);
void open();
void close();
bool is_open() { return _open; }
@ -310,9 +311,11 @@ protected:
public:
void set_values(const char* c);
int selected() const;
int items() const { return _values.items(); }
void select(int i);
int items() const { return _values.items(); }
void select(int i) { _ddl->select(i); }
void select_by_initial(char c) { _ddl->select_by_initial(c); }
void select_by_ofs(int i) { _ddl->select_by_ofs(i); }
int selected() const { return _ddl->selected(); }
TListbox_control(WINDOW win, short cid,
short left, short top, short width,

View File

@ -225,12 +225,14 @@ HIDDEN int CBuildKey(RecDes *recd, int numkey, RecType recin, char *key, bool b
if (numkey-- <= recd->NKeys)
{
int l = 0;
bool wasbool = FALSE;
for (int i = 0; i < recd->Ky[numkey].NkFields; i++)
{
const KeyDes& kd = recd->Ky[numkey];
const bool upp = kd.FieldSeq[i] > MaxFields;
const int nf = upp ? kd.FieldSeq[i] - MaxFields : kd.FieldSeq[i];
const RecFieldDes& rf = recd->Fd[nf];
const TFieldtypes f = (TFieldtypes) rf.TypeF;
int off, len;
if (kd.FromCh[i] == 255)
@ -248,9 +250,11 @@ HIDDEN int CBuildKey(RecDes *recd, int numkey, RecType recin, char *key, bool b
key[0] = '\0';
return(_iskeylenerr);
}
strncpy((key + l), (recin + off), len);
if (f == _boolfld /* && build_x_cb */)
key[l] = *(recin + off) > ' ' ? 'T' : 'F';
else
strncpy((key + l), (recin + off), len);
const TFieldtypes f = (TFieldtypes) rf.TypeF;
if (recin[off] == '\0')
{
memset(key + l, ' ', len);
@ -270,9 +274,11 @@ HIDDEN int CBuildKey(RecDes *recd, int numkey, RecType recin, char *key, bool b
for (int i = l+len-1; i >= l; i--)
key[i] = toupper(key[i]);
wasbool = f == _boolfld;
l += len;
}
// rtrim
while (l > 0 && key[l-1] == ' ') l--;
key[l] = '\0';
@ -302,7 +308,7 @@ HIDDEN int cisread(isfdptr isfd, TRectype & record, int mode)
do
{
if (rmode>=_isequal && rmode<=_isgteq)
if (rmode>=_isequal && rmode<=_isgteq)
{
err=CBuildKey(isfd->r, isfd->knum, record.string(),key,TRUE);
if (err == NOERR)

View File

@ -3348,7 +3348,7 @@ void TList_field::read_item(TScanner& scanner)
void TList_field::parse_head(TScanner& scanner)
{
_ctl_data._size = scanner.integer();
_ctl_data._size = _size = scanner.integer();
_ctl_data._width = scanner.integer();
if (_ctl_data._width == 0)
_ctl_data._width = _ctl_data._size;
@ -3448,6 +3448,43 @@ void TList_field::add_list()
current(0);
}
const char* TList_field::win2raw(const char* data) const
{
if (*data == '\0') return data;
// fool the compiler to keep const
TToken_string& codes = ((TList_field*)this)->_codes;
TToken_string& value = ((TList_field*)this)->_values;
int pos = value.get_pos(data);
CHECKS(pos >= 0, "Unknown listbox value:", data);
return codes.get(pos);
}
const char* TList_field::raw2win(const char* data) const
{
if (*data == '\0') return data;
// fool the compiler to keep const
TToken_string& codes = ((TList_field*)this)->_codes;
TToken_string& value = ((TList_field*)this)->_values;
int pos = codes.get_pos(data);
CHECKS(pos >= 0, "Unknown listbox code:", data);
return value.get(pos);
}
void TList_field::select_by_ofs(int n)
{
((TListbox_control*)_ctl)->select_by_ofs(n);
_str = _codes.get(current());
}
void TList_field::select_by_initial(char c)
{
((TListbox_control*)_ctl)->select_by_initial(c);
_str = _codes.get(current());
}
// @doc EXTERNAL
// @mfunc Sostituisce alle voci correnti quelle passate come parametri
@ -3478,7 +3515,6 @@ void TList_field::create(WINDOW parent)
add_list();
}
int TList_field::str2curr(const char* data)
{
TString16 str(data);
@ -3511,12 +3547,19 @@ int TList_field::str2curr(const char* data)
}
void TList_field::set_window_data(const char* data)
void TList_field::set(const char* data)
{
const int i = str2curr(data);
current(i);
}
void TList_field::set_window_data(const char* data)
{
CHECK(0,"So' passato da 'sta stronza!!!");
const int i = str2curr(win2raw(data));
current(i);
}
void TList_field::current(int n)
{
((TListbox_control*)_ctl)->select(n);

View File

@ -1104,11 +1104,14 @@ public:
class TList_field : public TEditable_field
// @author:(INTERNAL) Guido
{
word _size;
// @access Private Member
// @cmember Crea una lista con i mesi
void add_list();
// @cmember seleziona all'offset dato dal corrente
void select_by_ofs(int n);
// @access Protected Member
protected:
// @cmember Lista delle voci
@ -1119,11 +1122,11 @@ protected:
// @cmember Ritorna l'identificatore della classe
virtual word class_id() const;
// @cmember Scrive il valore del campo direttamente dalla finestra del controllo
virtual void set_window_data(const char* data);
// @cmember Legge il valore del campo direttamente dalla finestra del controllo
virtual TString& get_window_data();
virtual void set_window_data(const char* data);
// @cmember Crea il controllo
virtual void create(WINDOW parent);
@ -1132,7 +1135,7 @@ protected:
// @cmember Ritorna la voce corrente
virtual int current() const;
// @cmember Trasforma la voce nel corrsipondente valore
// @cmember Trasforma la voce nel corrispondente valore
int str2curr(const char* data);
// @cmember Gestisce la chiamata all'handler del campo
virtual bool on_hit();
@ -1150,18 +1153,46 @@ protected:
// @access Public Member
public:
// @cmember Ritorna la dimensione del buffer associato al campo
virtual word size() const { return _size; }
// @cmember Conversione da formato visuale a valore
virtual const char* win2raw(const char* data) const;
// @cmember Conversione da valore a formato visuale
virtual const char* raw2win(const char* data) const;
// @cmember Scrive il valore del campo direttamente dalla finestra del controllo
virtual void set(const char* data);
// @cmember Ritorna la tokenstring dei valori ammessi
const char* get_values() const { return _values; }
// @cmember Sostituisce alle voci correnti quelle passate come parametri
virtual void replace_items(const char* codes, const char* values);
// @cmember Aggiunge una voce
virtual void add_item(const char* code_value);
// @cmember Elimina la voce con codice <p code>
virtual void delete_item(const char* code);
// @cmember Ritorna il numero di voci presenti
int items() const;
// @cmember Tipo
virtual bool is_kind_of(word cid) const;
// @cmember Seleziona sulla base dell'iniziale
void select_by_initial(char c);
// @cmember Seleziona il prossimo se possibile (no wrap)
void select_next() { select_by_ofs(1); }
// @cmember Seleziona il precedente se possibile (no wrap)
void select_prev() { select_by_ofs(-1); }
// @cmember Costruttore
TList_field(TMask* mask);
virtual ~TList_field() {}
@ -1265,7 +1296,7 @@ protected:
virtual bool on_key(KEY key);
protected:
// @cmember Non fa' nulla
// @cmember Non fa nulla
virtual const char* reformat(const char* data) const;
// @cmember Trasforma <p data> in una riga sola

View File

@ -37,5 +37,6 @@
#define MOV_CODPAG "CODPAG"
#define MOV_INVIATO "INVIATO"
#define MOV_INVIVA "INVIVA"
#define MOV_SCARCON "SCARCON"
#endif

View File

@ -707,7 +707,6 @@ const char* TSpreadsheet::copy_cell2field(XI_OBJ* cell)
}
else
txt = xi_get_text(cell, NULL, -1);
if (_edit_field->is_editable())
{
const TString& val = ((TEditable_field*)_edit_field)->win2raw(txt);
@ -790,8 +789,6 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
xiev->v.cell_request.back_color = DISABLED_BACK_COLOR;
else
if (e->has_query() || e->is_kind_of(CLASS_LIST_FIELD))
// il bottone manda F9 da gestire -- li' vedi se CELL ha il RCT giusto
// per posizione e poi gestisci usando il listfield
{
xiev->v.cell_request.button = TRUE;
xiev->v.cell_request.button_on_focus = TRUE;
@ -1028,20 +1025,19 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
{
_check_enabled = FALSE; // Disable checks
notify_change();
// gestione F9: listbox ok = TRUE e gestione specifica
// MAKE_CELL per beccare la cella
bool ok = TRUE;
if (_edit_field->is_kind_of(CLASS_LIST_FIELD) && k == K_F9)
if (_edit_field->is_kind_of(CLASS_LIST_FIELD) && k == K_F9) // list
{
XI_OBJ cell; XI_MAKE_CELL(&cell, _obj, _cur_row, _cur_col);
// droppagiu'
// droppa giu'
TList_field& lst = (TList_field&)(*_edit_field);
TDropDownList ddl(&cell, lst.get_values(), 0, TRUE);
TDropDownList ddl(&cell, lst.get_values(), lst.size(), TRUE);
ddl.open();
while (ddl.is_open())
do_events();
// sdroppa su
copy_cell2field(); /* ci vuole ma non basta */
}
else // edit_field
{
@ -1097,6 +1093,29 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
refused = TRUE;
beep();
}
else if(_edit_field->is_kind_of(CLASS_LIST_FIELD))
{
XI_OBJ cell;
XI_MAKE_CELL(&cell, _obj, _cur_row, _cur_col);
TList_field& lst = ((TList_field&)*_edit_field);
if (k < 128 && isalnum(k))
{
lst.select_by_initial(k);
xi_set_text(&cell, (char*)lst.raw2win(lst.get()));
}
else if (k == K_RIGHT)
{
lst.select_next();
xi_set_text(&cell, (char*)lst.raw2win(lst.get()));
}
else if (k == K_LEFT)
{
lst.select_prev();
xi_set_text(&cell, (char*)lst.raw2win(lst.get()));
}
refused = TRUE;
}
break;
}
}

View File

@ -654,11 +654,11 @@ word TPrintrow::class_id()
return CLASS_PRINTROW;
}
TPrintrow & TPrintrow::reset ()
TPrintrow& TPrintrow::reset()
{
_row.spaces (sizeof (_attr)); // Azzera testo
_row.spaces (sizeof(_attr)); // Azzera testo
memset (_attr, normalstyle, sizeof (_attr)); // Azzera stile
memset(_attr, normalstyle, sizeof (_attr)); // Azzera stile
_tab.reset(); // Azzera tabulazioni
@ -729,7 +729,7 @@ const char* TPrintrow::row_codified() const
return __tmp_string;
}
TPrintrow & TPrintrow::put(const char *str, int position, int len)
TPrintrow& TPrintrow::put(const char *str, int position, int len)
{
if (len < 1)
len = strlen (str);

View File

@ -7,13 +7,14 @@
#define SLD_SOTTOCONTO "SOTTOCONTO"
#define SLD_FLAGSALINI "FLAGSALINI"
#define SLD_SALDO "SALDO"
#define SLD_PDARESCA "PDARESCA"
#define SLD_PAVERESCA "PAVERESCA"
#define SLD_PDARE "PDARE"
#define SLD_PAVERE "PAVERE"
#define SLD_DATAULMOV "DATAULMOV"
#define SLD_NUMULTMOV "NUMULTMOV"
#define SLD_PAVEREPRO "PAVEREPRO"
#define SLD_PDAREPRO "PDAREPRO"
#define SLD_FLSCA "FLSCA"
#define SLD_FLAGSALFIN "FLAGSALFIN"
#define SLD_SALDOFIN "SALDOFIN"
#endif