Corretta gestione listbox

git-svn-id: svn://10.65.10.50/trunk@2796 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-05-13 07:31:27 +00:00
parent d15ddcf5f5
commit 74f2ab4b13
8 changed files with 3346 additions and 3315 deletions

View File

@ -1663,8 +1663,11 @@ bool TListbox_control::event_handler(XI_OBJ* itf, XI_EVENT* xiev)
void TListbox_control::set_values(const char* val) void TListbox_control::set_values(const char* val)
{ {
_values = val; _values = val;
_ddl->set_values(val); _ddl->set_values(val);
_ddl->select(selected(), TRUE); if (selected() >= _values.items())
_ddl->select(0, TRUE);
else
_ddl->select(selected(), TRUE);
} }
TListbox_control::TListbox_control(WINDOW win, short cid, TListbox_control::TListbox_control(WINDOW win, short cid,

View File

@ -3326,7 +3326,8 @@ void TReal_field::exchange(bool show_value, const real& nuo)
// List_field // List_field
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TList_field::TList_field(TMask* m) : TEditable_field(m) TList_field::TList_field(TMask* m)
: TEditable_field(m), _size(0)
{ } { }
word TList_field::class_id() const word TList_field::class_id() const
@ -3337,7 +3338,11 @@ void TList_field::read_item(TScanner& scanner)
{ {
TToken_string ts(scanner.string()); TToken_string ts(scanner.string());
_codes.add(ts.get()); _codes.add(ts.get());
_values.add(ts.get());
const char* v = ts.get();
_values.add(v);
CHECKS(strlen(v) <= (word)_ctl_data._width, "List item is too long:", v);
ts = ""; ts = "";
while (scanner.popkey() == "ME") while (scanner.popkey() == "ME")
@ -3348,7 +3353,7 @@ void TList_field::read_item(TScanner& scanner)
void TList_field::parse_head(TScanner& scanner) void TList_field::parse_head(TScanner& scanner)
{ {
_ctl_data._size = _size = scanner.integer(); _ctl_data._size = scanner.integer();
_ctl_data._width = scanner.integer(); _ctl_data._width = scanner.integer();
if (_ctl_data._width == 0) if (_ctl_data._width == 0)
_ctl_data._width = _ctl_data._size; _ctl_data._width = _ctl_data._size;
@ -3451,25 +3456,38 @@ void TList_field::add_list()
const char* TList_field::win2raw(const char* data) const const char* TList_field::win2raw(const char* data) const
{ {
if (*data == '\0') return data;
// fool the compiler to keep const // fool the compiler to keep const
TToken_string& codes = ((TList_field*)this)->_codes; TToken_string& codes = ((TList_field*)this)->_codes;
TToken_string& value = ((TList_field*)this)->_values; TToken_string& value = ((TList_field*)this)->_values;
int pos = value.get_pos(data); _ctl_data._park = data; // data puo' venire da una TToken_string::get
int pos = value.get_pos(_ctl_data._park);
if (pos < 0 && _ctl_data._park.blank())
{
_ctl_data._park = value.get(0);
if (_ctl_data._park.blank())
pos = 0;
}
CHECKS(pos >= 0, "Unknown listbox value:", data); CHECKS(pos >= 0, "Unknown listbox value:", data);
return codes.get(pos); return codes.get(pos);
} }
const char* TList_field::raw2win(const char* data) const const char* TList_field::raw2win(const char* data) const
{ {
if (*data == '\0') return data;
// fool the compiler to keep const // fool the compiler to keep const
TToken_string& codes = ((TList_field*)this)->_codes; TToken_string& codes = ((TList_field*)this)->_codes;
TToken_string& value = ((TList_field*)this)->_values; TToken_string& value = ((TList_field*)this)->_values;
int pos = codes.get_pos(data); _ctl_data._park = data; // data puo' venire da una TToken_string::get
CHECKS(pos >= 0, "Unknown listbox code:", data); int pos = codes.get_pos(_ctl_data._park);
if (pos < 0 && _ctl_data._park.blank())
{
_ctl_data._park = codes.get(0);
if (_ctl_data._park.blank())
pos = 0;
}
CHECKS(pos >= 0, "Unknown listbox code:", (const char*)_ctl_data._park);
return value.get(pos); return value.get(pos);
} }
@ -3508,6 +3526,8 @@ void TList_field::create(WINDOW parent)
const int len = create_prompt(parent, 0, 0); const int len = create_prompt(parent, 0, 0);
_ctl_data._x += len; _ctl_data._x += len;
_size = _ctl_data._width;
_ctl = new TListbox_control(parent, _ctl_data._dlg, _ctl = new TListbox_control(parent, _ctl_data._dlg,
_ctl_data._x, _ctl_data._y, _ctl_data._x, _ctl_data._y,
_ctl_data._width, _ctl_data._width,
@ -3761,7 +3781,7 @@ bool TZoom_field::on_key( KEY key )
get_window_data(); get_window_data();
break; break;
case K_F9: case K_F9:
if (has_query()) if (browse() != NULL)
break; break;
case K_F8: case K_F8:
{ {

View File

@ -217,7 +217,7 @@ public:
virtual bool has_check() const virtual bool has_check() const
{ return FALSE;} { return FALSE;}
// @cmember Controlla se il campo ha una richiesta // @cmember Controlla se il campo ha una richiesta
virtual bool has_query() const virtual bool has_query_button() const
{ return FALSE;} { return FALSE;}
// @cmember Ritorna il campo corrispondente su record // @cmember Ritorna il campo corrispondente su record
virtual const TFieldref* field() const virtual const TFieldref* field() const
@ -929,7 +929,7 @@ public:
// @cmember Controlla se il campo ha un check // @cmember Controlla se il campo ha un check
virtual bool has_check() const; virtual bool has_check() const;
// @cmember Controlla se il campo ha una ricerca // @cmember Controlla se il campo ha una ricerca
virtual bool has_query() const virtual bool has_query_button() const
{ return _browse != NULL;} { return _browse != NULL;}
// @cmember Ritorna TRUE se il campo e' di tipo edit // @cmember Ritorna TRUE se il campo e' di tipo edit
@ -1156,6 +1156,10 @@ public:
// @cmember Ritorna la dimensione del buffer associato al campo // @cmember Ritorna la dimensione del buffer associato al campo
virtual word size() const { return _size; } virtual word size() const { return _size; }
// @cmember Esegue la ricerca. Torna il tasto che ha terminato la ricerca
virtual bool has_query_button() const
{ return TRUE; }
// @cmember Conversione da formato visuale a valore // @cmember Conversione da formato visuale a valore
virtual const char* win2raw(const char* data) const; virtual const char* win2raw(const char* data) const;

View File

@ -277,11 +277,11 @@ TSpreadsheet::TSpreadsheet(
f_width += v+1; f_width += v+1;
} }
testa.cut(at); testa.cut(at);
v = max(at, v+(f->has_query() ? 1 : 0)); v = max(at, v+(f->has_query_button() ? 1 : 0));
} }
else else
{ {
v = max(testa.len(), m+(f->has_query() ? 1 : 0)); v = max(testa.len(), m+(f->has_query_button() ? 1 : 0));
} }
if (v > 69) if (v > 69)
v = 69; v = 69;
@ -788,7 +788,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
if (cell_disabled(rec, col)) if (cell_disabled(rec, col))
xiev->v.cell_request.back_color = DISABLED_BACK_COLOR; xiev->v.cell_request.back_color = DISABLED_BACK_COLOR;
else else
if (e->has_query() || e->is_kind_of(CLASS_LIST_FIELD)) if (e->has_query_button())
{ {
xiev->v.cell_request.button = TRUE; xiev->v.cell_request.button = TRUE;
xiev->v.cell_request.button_on_focus = TRUE; xiev->v.cell_request.button_on_focus = TRUE;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,276 +1,276 @@
#include <defmask.h> #include <defmask.h>
#include <progind.h> #include <progind.h>
#include <controls.h> #include <controls.h>
#include <urldefid.h> #include <urldefid.h>
const char* const TITLE_TEXT = "Attesa"; const char* const TITLE_TEXT = "Attesa";
word TIndwin::measure_text(TToken_string& s, word& maxlen) const word TIndwin::measure_text(TToken_string& s, word& maxlen) const
{ {
word lines = 0; word lines = 0;
for(const char* t = s.get(0); t; t = s.get()) for(const char* t = s.get(0); t; t = s.get())
{ {
const word l = strlen(t); const word l = strlen(t);
if (l > maxlen) maxlen = l; if (l > maxlen) maxlen = l;
lines++; lines++;
} }
return lines; return lines;
} }
// Certified 70% // Certified 70%
TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div) TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div)
: _text(NULL), _cancel(NULL), _bar(0), : _text(NULL), _cancel(NULL), _bar(0),
_status(0L), _max(max), _flags(0x0) _status(0L), _max(max), _flags(0x0)
{ {
if (_max <= 0) _max = 1; if (_max <= 0) _max = 1;
TToken_string testo(txt, '\n'); TToken_string testo(txt, '\n');
word maxlen = div; word maxlen = div;
const word lines = measure_text(testo, maxlen); const word lines = measure_text(testo, maxlen);
int ver = lines+2; int ver = lines+2;
int hor = maxlen+2; if (hor > 78) hor = 78; int hor = maxlen+2; if (hor > 78) hor = 78;
if (bar) if (bar)
{ {
_bar = ver * CHARY; _bar = ver * CHARY;
ver += 2; ver += 2;
} }
ver += cancel ? 2 : 0; ver += cancel ? 2 : 0;
set_win(create_interface(TASK_WIN, -1, -1, hor, ver, TITLE_TEXT, this, FALSE)); set_win(create_interface(TASK_WIN, -1, -1, hor, ver, TITLE_TEXT, this, FALSE));
_text = new TMultiline_control(win(), DLG_NULL, 1, 1, hor-2, lines, 512, "CD", ""); _text = new TMultiline_control(win(), DLG_NULL, 1, 1, hor-2, lines, 512, "CD", "");
testo.replace('\n', '\r'); testo.replace('\n', '\r');
_text->set_caption(testo); _text->set_caption(testo);
if (cancel) if (cancel)
{ {
_cancel = new TPushbutton_control(win(), DLG_CANCEL, -11, -1, 10, 2, "", "Annulla", BMP_CANCEL); _cancel = new TPushbutton_control(win(), DLG_CANCEL, -11, -1, 10, 2, "", "Annulla", BMP_CANCEL);
} }
open_modal(); open_modal();
do_events(); do_events();
} }
// @doc EXTERNAL // @doc EXTERNAL
// @mfunc Setta il testo della finestra // @mfunc Setta il testo della finestra
void TIndwin::set_text( void TIndwin::set_text(
const char* t) // @parm Testo della finestra const char* t) // @parm Testo della finestra
// @comm Si puo' chiamare questa funzione per cambiare il testo, ma // @comm Si puo' chiamare questa funzione per cambiare il testo, ma
// le dimensioni della finestra sono calcolate sul primo testo // le dimensioni della finestra sono calcolate sul primo testo
// passato, quindi occorre dimensionare correttamente il primo passato // passato, quindi occorre dimensionare correttamente il primo passato
// (es. inserire degli spazi) se se ne prevede uno piu' lungo. // (es. inserire degli spazi) se se ne prevede uno piu' lungo.
{ {
_text->set_caption(t); _text->set_caption(t);
} }
TIndwin::~TIndwin() TIndwin::~TIndwin()
{ {
close_modal(); close_modal();
if (_text) delete _text; if (_text) delete _text;
if (_cancel) delete _cancel; if (_cancel) delete _cancel;
} }
bool TIndwin::can_be_closed() const bool TIndwin::can_be_closed() const
{ {
const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED); const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED);
if (!ok) error_box("Attendere la fine dell'operazione prima di chiudere l'applicazione"); if (!ok) error_box("Attendere la fine dell'operazione prima di chiudere l'applicazione");
return ok; return ok;
} }
KEY TIndwin::check_stop() KEY TIndwin::check_stop()
{ {
KEY k = 0; KEY k = 0;
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED)) if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{ {
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC; k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
stop_run(k); stop_run(k);
} }
return k; return k;
} }
void TIndwin::update_bar() void TIndwin::update_bar()
{ {
if (_status >= _max) if (_status >= _max)
{ {
_status = _max; _status = _max;
_flags |= IND_FINISHED; _flags |= IND_FINISHED;
} }
const double prc = (double)_status/_max; const double prc = (double)_status/_max;
RCT r; xvt_vobj_get_client_rect(win(), &r); RCT r; xvt_vobj_get_client_rect(win(), &r);
r.left = CHARX; r.right -= CHARX; r.left = CHARX; r.right -= CHARX;
r.top = (int)_bar; r.top = (int)_bar;
r.bottom = r.top + 2*CHARY; r.bottom = r.top + 2*CHARY;
const int width = r.right - r.left; const int width = r.right - r.left;
RCT b = r; RCT b = r;
set_pen(COLOR_BLACK); set_pen(COLOR_BLACK);
/* /*
set_brush(COLOR_BLUE); set_brush(COLOR_BLUE);
b.right = b.left + int(width*prc); b.right = b.left + int(width*prc);
xvt_dwin_draw_rect(win(), &b); xvt_dwin_draw_rect(win(), &b);
set_brush(COLOR_WHITE); set_brush(COLOR_WHITE);
b.left = b.right; b.right = r.right; b.left = b.right; b.right = r.right;
xvt_dwin_draw_rect(win(), &b); xvt_dwin_draw_rect(win(), &b);
set_mode(M_XOR); set_mode(M_XOR);
xvt_dwin_set_fore_color(win(), COLOR_BLUE); xvt_dwin_set_fore_color(win(), COLOR_BLUE);
char n[8]; sprintf(n, "%d%%", int(100*prc)); char n[8]; sprintf(n, "%d%%", int(100*prc));
xvt_dwin_draw_text(win(), r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1); xvt_dwin_draw_text(win(), r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
set_mode(M_COPY); set_mode(M_COPY);
*/ */
WINDOW w = win(); WINDOW w = win();
b.right = b.left + int(width*prc); b.right = b.left + int(width*prc);
xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0); xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
set_brush(COLOR_WHITE); set_brush(COLOR_WHITE);
b.left = b.right; b.right = r.right; b.left = b.right; b.right = r.right;
xvt_dwin_draw_rect(w, &b); xvt_dwin_draw_rect(w, &b);
char n[8]; sprintf(n, "%d%%", int(100*prc)); char n[8]; sprintf(n, "%d%%", int(100*prc));
xvt_dwin_draw_text(w, r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1); xvt_dwin_draw_text(w, r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
check_stop(); check_stop();
} }
void TIndwin::update() void TIndwin::update()
{ {
if (_bar) update_bar(); if (_bar) update_bar();
} }
bool TIndwin::on_key(KEY k) bool TIndwin::on_key(KEY k)
{ {
if (k == K_ESC && _cancel) if (k == K_ESC && _cancel)
{ {
_flags |= IND_CANCELLED; _flags |= IND_CANCELLED;
check_stop(); check_stop();
} }
return TRUE; return TRUE;
} }
void TIndwin::on_button(short id) void TIndwin::on_button(short id)
{ {
if (id == DLG_CANCEL) if (id == DLG_CANCEL)
on_key(K_ESC); on_key(K_ESC);
} }
// TProgind -------------------------------------------------------------- // TProgind --------------------------------------------------------------
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div) TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div) : TIndwin(max, txt, cancel, bar, div)
{} {}
// TTimerind ------------------------------------------------------------ // TTimerind ------------------------------------------------------------
long TTimerind::_timer_id = 0L; long TTimerind::_timer_id = 0L;
void TTimerind::handler(WINDOW w, EVENT* e) void TTimerind::handler(WINDOW w, EVENT* e)
{ {
switch(e->type) switch(e->type)
{ {
case E_CREATE: case E_CREATE:
case E_UPDATE: case E_UPDATE:
if (_status == 0L) if (_status == 0L)
_timer_id = xvt_timer_create(w, _interval); _timer_id = xvt_timer_create(w, _interval);
break; break;
case E_TIMER: case E_TIMER:
if (e->v.timer.id == _timer_id) if (e->v.timer.id == _timer_id)
{ {
_status += _interval; _status += _interval;
force_update(); force_update();
xvt_timer_create(w, _interval); xvt_timer_create(w, _interval);
} }
break; break;
default: default:
break; break;
} }
TIndwin::handler(w,e); TIndwin::handler(w,e);
} }
TTimerind::TTimerind(long msec, const char* txt, TTimerind::TTimerind(long msec, const char* txt,
bool cancel, bool bar, int div, int i) : bool cancel, bool bar, int div, int i) :
TIndwin(msec, txt, cancel, bar, div) TIndwin(msec, txt, cancel, bar, div)
{ {
_interval = i; _interval = i;
_timer_id = 0L; _timer_id = 0L;
} }
TTimerind::~TTimerind() TTimerind::~TTimerind()
{ xvt_timer_destroy(_timer_id); } { xvt_timer_destroy(_timer_id); }
// C-style binding // C-style binding
// uses static pointer for single instance of TIndwin // uses static pointer for single instance of TIndwin
static TIndwin* __indwin__p = NULL; static TIndwin* __indwin__p = NULL;
void progind_create(long m, char* t, bool b, bool c, int n) void progind_create(long m, char* t, bool b, bool c, int n)
{ {
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator"); CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
__indwin__p = new TProgind(m,t,b,c,n); __indwin__p = new TProgind(m,t,b,c,n);
} }
void progind_set_status(long l) void progind_set_status(long l)
{ {
((TProgind*)__indwin__p)->setstatus(l); ((TProgind*)__indwin__p)->setstatus(l);
} }
void progind_cancel() void progind_cancel()
{ {
__indwin__p->cancel(); __indwin__p->cancel();
} }
bool progind_iscancelled() bool progind_iscancelled()
{ {
return __indwin__p->iscancelled(); return __indwin__p->iscancelled();
} }
bool progind_isfinished() bool progind_isfinished()
{ {
return __indwin__p->isfinished(); return __indwin__p->isfinished();
} }
void progind_destroy() void progind_destroy()
{ {
delete __indwin__p; delete __indwin__p;
__indwin__p = NULL; __indwin__p = NULL;
} }
void timerind_create(long l, char* title, bool bar, bool cancel, void timerind_create(long l, char* title, bool bar, bool cancel,
int divisions, int interval) int divisions, int interval)
{ {
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator"); CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
__indwin__p = new TTimerind(l,title,bar,cancel,divisions,interval); __indwin__p = new TTimerind(l,title,bar,cancel,divisions,interval);
} }
void timerind_cancel() void timerind_cancel()
{ {
__indwin__p->cancel(); __indwin__p->cancel();
} }
bool timerind_iscancelled() bool timerind_iscancelled()
{ {
return __indwin__p->iscancelled(); return __indwin__p->iscancelled();
} }
bool timerind_isfinished() bool timerind_isfinished()
{ {
return __indwin__p->isfinished(); return __indwin__p->isfinished();
} }
void timerind_destroy() void timerind_destroy()
{ {
delete __indwin__p; delete __indwin__p;
__indwin__p = NULL; __indwin__p = NULL;
} }

View File

@ -153,8 +153,12 @@ void TRelation_application::enable_query()
{ {
if (c.in_key(1)) if (c.in_key(1))
c.enable(keyon); c.enable(keyon);
if (c.has_query()) if (c.is_edit())
((TEdit_field&)c).enable_check(query); {
TEdit_field& e = (TEdit_field&)c;
if (e.browse() != NULL)
e.enable_check(query);
}
} }
} }