Corretta progind

git-svn-id: svn://10.65.10.50/trunk@2789 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-05-10 12:14:42 +00:00
parent ed35f9b3ad
commit 72c832bd15
2 changed files with 3637 additions and 270 deletions

File diff suppressed because it is too large Load Diff

View File

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