2003-05-13 15:12:54 +00:00
|
|
|
#include "xvt.h"
|
|
|
|
#include "xinclude.h"
|
|
|
|
|
1997-10-08 10:46:39 +00:00
|
|
|
#include <colors.h>
|
2002-10-24 10:47:49 +00:00
|
|
|
#include <diction.h>
|
1996-05-31 15:27:42 +00:00
|
|
|
#include <progind.h>
|
|
|
|
#include <controls.h>
|
2008-10-02 15:57:06 +00:00
|
|
|
#include <reprint.h>
|
1996-05-31 15:27:42 +00:00
|
|
|
#include <urldefid.h>
|
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
int TIndwin::_indwin_count = 0;
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
word TIndwin::measure_text(TToken_string& s, word& maxlen) const
|
|
|
|
{
|
|
|
|
word lines = 0;
|
2008-10-08 08:49:04 +00:00
|
|
|
FOR_EACH_TOKEN(s, t)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
|
|
|
const word l = strlen(t);
|
|
|
|
if (l > maxlen) maxlen = l;
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Certified 70%
|
2003-12-19 08:15:17 +00:00
|
|
|
TIndwin::TIndwin(long tot, const char* txt, bool cancel, bool bar, int div)
|
2008-10-02 15:57:06 +00:00
|
|
|
: _gauge(NULL_WIN), _can_cancel(cancel), _bar_top(0),
|
2007-04-06 14:46:40 +00:00
|
|
|
_flags(0x0), _max(tot), _status(0L)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
|
|
|
TToken_string testo(txt, '\n');
|
|
|
|
word maxlen = div;
|
|
|
|
const word lines = measure_text(testo, maxlen);
|
2004-03-12 14:39:04 +00:00
|
|
|
|
2003-02-25 15:22:52 +00:00
|
|
|
const int hor = min(maxlen+3, 78);
|
2008-10-02 15:57:06 +00:00
|
|
|
const int ver = lines+3 + (bar ? 2 : 0);
|
2003-12-03 09:41:16 +00:00
|
|
|
const int y = _indwin_count == 0 ? 3 : 12;
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2008-10-02 15:57:06 +00:00
|
|
|
long flags = WSF_INVISIBLE;
|
|
|
|
if (_can_cancel)
|
|
|
|
flags |= WSF_CLOSE;
|
|
|
|
create(-1, y, hor, ver, TR("Elaborazione in corso"), flags, WD_MODAL);
|
|
|
|
|
|
|
|
_bar_top = (lines+1)*ROWY;
|
1996-05-31 15:27:42 +00:00
|
|
|
|
1998-03-30 13:50:30 +00:00
|
|
|
set_text(testo);
|
2004-03-12 14:39:04 +00:00
|
|
|
|
1996-08-30 14:30:08 +00:00
|
|
|
if (bar)
|
2004-03-12 14:39:04 +00:00
|
|
|
{
|
2008-10-08 08:49:04 +00:00
|
|
|
XVT_COLOR_COMPONENT xcc[4];
|
|
|
|
memset(xcc, 0, sizeof(xcc));
|
|
|
|
xcc[0].type = XVT_COLOR_BACKGROUND;
|
|
|
|
xcc[0].color = MASK_BACK_COLOR;
|
|
|
|
xcc[1].type = XVT_COLOR_BLEND;
|
|
|
|
xcc[1].color = BTN_LIGHT_COLOR;
|
|
|
|
xcc[2].type = XVT_COLOR_BORDER;
|
|
|
|
xcc[2].color = BTN_DARK_COLOR;
|
|
|
|
|
2007-04-06 14:46:40 +00:00
|
|
|
WIN_DEF wd; memset(&wd, 0, sizeof(wd));
|
|
|
|
wd.wtype = WC_HGAUGE;
|
2008-10-02 15:57:06 +00:00
|
|
|
get_bar_rct(wd.rct);
|
2008-10-08 08:49:04 +00:00
|
|
|
wd.ctlcolors = xcc;
|
2007-04-06 14:46:40 +00:00
|
|
|
_gauge = xvt_ctl_create_def(&wd, win(), tot);
|
1996-08-30 14:30:08 +00:00
|
|
|
}
|
2008-10-02 15:57:06 +00:00
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
open_modal();
|
2003-02-25 15:22:52 +00:00
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
_indwin_count++;
|
2003-12-19 08:15:17 +00:00
|
|
|
setmax(tot);
|
2004-03-12 14:39:04 +00:00
|
|
|
}
|
1996-05-31 15:27:42 +00:00
|
|
|
|
|
|
|
// @doc EXTERNAL
|
|
|
|
|
|
|
|
// @mfunc Setta il testo della finestra
|
|
|
|
void TIndwin::set_text(
|
|
|
|
const char* t) // @parm Testo della finestra
|
|
|
|
|
|
|
|
// @comm Si puo' chiamare questa funzione per cambiare il testo, ma
|
|
|
|
// le dimensioni della finestra sono calcolate sul primo testo
|
|
|
|
// passato, quindi occorre dimensionare correttamente il primo passato
|
1998-03-30 13:50:30 +00:00
|
|
|
// (es. inserire degli spazi) quando se ne prevede uno piu' lungo.
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
2008-10-02 15:57:06 +00:00
|
|
|
_text.destroy();
|
|
|
|
TToken_string txt(t, '\n');
|
|
|
|
FOR_EACH_TOKEN(txt, tok)
|
|
|
|
_text.add(tok);
|
|
|
|
|
|
|
|
RCT r; get_txt_rct(r);
|
|
|
|
xvt_dwin_invalidate_rect(win(), &r);
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
2003-12-19 08:15:17 +00:00
|
|
|
void TIndwin::setmax(long m)
|
|
|
|
{
|
|
|
|
_max = m <= 0 ? 1 : m;
|
2007-04-06 14:46:40 +00:00
|
|
|
if (_gauge)
|
|
|
|
xvt_sbar_set_range(_gauge, HVGAUGE, 0, _max);
|
2003-12-19 08:15:17 +00:00
|
|
|
_start_time = clock();
|
|
|
|
}
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
TIndwin::~TIndwin()
|
1996-08-26 15:59:07 +00:00
|
|
|
{
|
|
|
|
if (is_open())
|
|
|
|
close_modal();
|
2003-11-10 15:01:49 +00:00
|
|
|
_indwin_count--;
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TIndwin::can_be_closed() const
|
|
|
|
{
|
|
|
|
const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED);
|
2002-10-24 10:47:49 +00:00
|
|
|
if (!ok) error_box(TR("Attendere la fine dell'operazione prima di chiudere l'applicazione"));
|
1996-05-31 15:27:42 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
KEY TIndwin::check_stop()
|
|
|
|
{
|
|
|
|
KEY k = 0;
|
|
|
|
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
|
|
|
|
{
|
|
|
|
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
|
2008-10-02 15:57:06 +00:00
|
|
|
if (is_running())
|
|
|
|
stop_run(k);
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2008-10-02 15:57:06 +00:00
|
|
|
void TIndwin::get_bar_rct(RCT& r) const
|
1998-03-30 13:50:30 +00:00
|
|
|
{
|
|
|
|
xvt_vobj_get_client_rect(win(), &r);
|
|
|
|
r.left += CHARX;
|
|
|
|
r.right -= CHARX;
|
2008-10-02 15:57:06 +00:00
|
|
|
r.top = _bar_top;
|
2003-05-12 13:52:48 +00:00
|
|
|
r.bottom = r.top + ROWY;
|
2008-10-02 15:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TIndwin::get_txt_rct(RCT& r) const
|
|
|
|
{
|
|
|
|
get_bar_rct(r);
|
|
|
|
r.bottom = r.top - ROWY/2;
|
|
|
|
r.top = ROWY/2;
|
1998-03-30 13:50:30 +00:00
|
|
|
}
|
|
|
|
|
2007-04-02 08:41:03 +00:00
|
|
|
void TIndwin::sec2str(unsigned long ss, TString& str) const
|
|
|
|
{
|
|
|
|
const unsigned long hh = ss / 3600;
|
|
|
|
ss -= hh*3600;
|
|
|
|
const unsigned long mm = ss / 60;
|
|
|
|
ss -= mm *60;
|
|
|
|
str.format("%02ld:%02ld:%02ld", hh, mm, ss);
|
|
|
|
}
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
void TIndwin::update_bar()
|
|
|
|
{
|
|
|
|
if (_status >= _max)
|
|
|
|
{
|
|
|
|
_status = _max;
|
|
|
|
_flags |= IND_FINISHED;
|
|
|
|
}
|
2007-04-06 14:46:40 +00:00
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
// Percentuale raggiunta finora
|
2003-02-25 15:22:52 +00:00
|
|
|
const double prc = (double)_status / (double)_max;
|
2007-04-06 14:46:40 +00:00
|
|
|
if (prc > 0)
|
1997-12-24 14:26:25 +00:00
|
|
|
{
|
2007-04-06 14:46:40 +00:00
|
|
|
const unsigned long elapsed_time = (clock() - _start_time)/CLOCKS_PER_SEC;
|
|
|
|
const unsigned long total_time = (unsigned long)(elapsed_time / prc + 0.5);
|
2008-09-19 15:35:09 +00:00
|
|
|
TString16 str_ela, str_res, str_tot;
|
|
|
|
sec2str(elapsed_time, str_ela);
|
2007-04-06 14:46:40 +00:00
|
|
|
sec2str(total_time - elapsed_time, str_res);
|
|
|
|
sec2str(total_time, str_tot);
|
|
|
|
|
|
|
|
TString80 n;
|
2008-09-19 15:35:09 +00:00
|
|
|
n.format("%d%% - %s %s - %s %s - %s %s", int(prc*100.0+0.5),
|
2009-01-22 12:00:23 +00:00
|
|
|
TR("Trascorso"), str_ela.get_buffer(),
|
|
|
|
TR("Stimato"), str_tot.get_buffer(),
|
|
|
|
TR("Residuo"), str_res.get_buffer()
|
2008-09-19 15:35:09 +00:00
|
|
|
);
|
2007-04-06 14:46:40 +00:00
|
|
|
RCT b; get_bar_rct(b);
|
|
|
|
b.top = b.bottom+2; b.bottom = b.top + CHARY;
|
|
|
|
|
|
|
|
WINDOW w = win();
|
|
|
|
CBRUSH brush; brush.pat = PAT_SOLID; brush.color = MASK_BACK_COLOR;
|
|
|
|
xvt_dwin_set_cbrush(w, &brush);
|
|
|
|
xvt_dwin_set_std_cpen(w, TL_PEN_HOLLOW);
|
|
|
|
xvt_dwin_draw_rect(w, &b);
|
|
|
|
xvt_dwin_set_clip(w, NULL);
|
|
|
|
set_color(NORMAL_COLOR, MASK_BACK_COLOR);
|
|
|
|
set_opaque_text(TRUE);
|
|
|
|
set_font();
|
|
|
|
xvt_dwin_draw_text(w, b.left, b.bottom-1, n, -1);
|
1997-12-24 14:26:25 +00:00
|
|
|
}
|
1996-05-31 15:27:42 +00:00
|
|
|
check_stop();
|
|
|
|
}
|
|
|
|
|
2008-10-07 09:02:41 +00:00
|
|
|
void TIndwin::update_txt()
|
|
|
|
{
|
|
|
|
RCT r; get_txt_rct(r);
|
|
|
|
|
|
|
|
WINDOW w = win();
|
|
|
|
CBRUSH brush; brush.pat = PAT_SOLID; brush.color = MASK_BACK_COLOR;
|
|
|
|
xvt_dwin_set_cbrush(w, &brush);
|
|
|
|
xvt_dwin_set_std_cpen(w, TL_PEN_HOLLOW);
|
|
|
|
xvt_dwin_draw_rect(w, &r);
|
|
|
|
xvt_dwin_set_clip(w, NULL);
|
|
|
|
set_color(NORMAL_COLOR, MASK_BACK_COLOR);
|
|
|
|
set_opaque_text(TRUE);
|
|
|
|
set_font();
|
2009-03-06 12:11:03 +00:00
|
|
|
advanced_draw_paragraph(w, _text, r, 'L', 'C', CHARY);
|
2008-10-07 09:02:41 +00:00
|
|
|
}
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
void TIndwin::update()
|
|
|
|
{
|
2008-10-02 15:57:06 +00:00
|
|
|
clear(MASK_BACK_COLOR);
|
|
|
|
|
2007-04-06 14:46:40 +00:00
|
|
|
if (_gauge != NULL_WIN)
|
1998-11-03 10:27:35 +00:00
|
|
|
update_bar();
|
2008-10-02 15:57:06 +00:00
|
|
|
|
|
|
|
if (!_text.empty())
|
2008-10-07 09:02:41 +00:00
|
|
|
update_txt();
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-06 14:46:40 +00:00
|
|
|
bool TIndwin::setstatus(long l)
|
|
|
|
{
|
|
|
|
if (l < 0)
|
|
|
|
{
|
|
|
|
NFCHECK("Negative progind status");
|
|
|
|
l = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_status = l > _max ? _max : l;
|
|
|
|
|
|
|
|
if (_gauge != NULL_WIN)
|
|
|
|
xvt_sbar_set_pos(_gauge, HVGAUGE, _status);
|
|
|
|
|
|
|
|
return !iscancelled();
|
|
|
|
}
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
bool TIndwin::on_key(KEY k)
|
|
|
|
{
|
2008-10-02 15:57:06 +00:00
|
|
|
if (k == K_ESC && _can_cancel)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
|
|
|
_flags |= IND_CANCELLED;
|
|
|
|
check_stop();
|
|
|
|
}
|
2008-10-02 15:57:06 +00:00
|
|
|
return true; // Ignora tutti gli altri tasti, senza chiamare TWindow::on_key(k)
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 15:57:06 +00:00
|
|
|
bool TIndwin::stop_run(KEY k)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
2008-10-02 15:57:06 +00:00
|
|
|
if (k == K_ESC)
|
|
|
|
{
|
|
|
|
if (_can_cancel)
|
|
|
|
_flags |= IND_CANCELLED;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return TWindow::stop_run(k);
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TProgind --------------------------------------------------------------
|
|
|
|
|
|
|
|
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
|
2007-03-06 16:37:44 +00:00
|
|
|
: TIndwin(max, txt, cancel, bar, div), _next_update(0)
|
1996-05-31 15:27:42 +00:00
|
|
|
{}
|
|
|
|
|
1998-03-30 13:50:30 +00:00
|
|
|
bool TProgind::setstatus(long l)
|
1996-12-02 11:01:06 +00:00
|
|
|
{
|
2007-04-06 14:46:40 +00:00
|
|
|
const bool ok = TIndwin::setstatus(l);
|
|
|
|
|
|
|
|
if (ok && clock() > _next_update)
|
1996-12-02 11:01:06 +00:00
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
update();
|
2007-03-06 16:37:44 +00:00
|
|
|
do_events();
|
|
|
|
_next_update = clock()+CLOCKS_PER_SEC; // Prossimo aggiornamento tra un secondo
|
|
|
|
}
|
|
|
|
|
2007-04-06 14:46:40 +00:00
|
|
|
return ok;
|
1996-12-02 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
1996-05-31 15:27:42 +00:00
|
|
|
// TTimerind ------------------------------------------------------------
|
|
|
|
|
|
|
|
void TTimerind::handler(WINDOW w, EVENT* e)
|
|
|
|
{
|
|
|
|
switch(e->type)
|
|
|
|
{
|
|
|
|
case E_CREATE:
|
|
|
|
case E_UPDATE:
|
2009-05-27 13:23:41 +00:00
|
|
|
if (_timer_id == 0L && _interval > 0)
|
1996-05-31 15:27:42 +00:00
|
|
|
_timer_id = xvt_timer_create(w, _interval);
|
|
|
|
break;
|
|
|
|
case E_TIMER:
|
|
|
|
if (e->v.timer.id == _timer_id)
|
|
|
|
{
|
|
|
|
_status += _interval;
|
|
|
|
force_update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TIndwin::handler(w,e);
|
|
|
|
}
|
|
|
|
|
2009-05-27 13:23:41 +00:00
|
|
|
TTimerind::TTimerind(long msec, const char* txt, bool cancel, bool bar, int div, int i)
|
|
|
|
: TIndwin(msec, txt, cancel, bar, div), _timer_id(0), _interval(i)
|
|
|
|
{ }
|
1996-05-31 15:27:42 +00:00
|
|
|
|
|
|
|
TTimerind::~TTimerind()
|
2003-05-15 09:51:23 +00:00
|
|
|
{
|
2009-05-27 13:23:41 +00:00
|
|
|
if (_timer_id)
|
2003-05-15 09:51:23 +00:00
|
|
|
xvt_timer_destroy(_timer_id);
|
|
|
|
}
|
1996-05-31 15:27:42 +00:00
|
|
|
|
|
|
|
// C-style binding
|
|
|
|
// uses static pointer for single instance of TIndwin
|
|
|
|
|
|
|
|
static TIndwin* __indwin__p = NULL;
|
|
|
|
|
1997-12-02 13:21:19 +00:00
|
|
|
void progind_create(long m, const char* t, bool b, bool c, int n)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
|
|
|
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
|
|
|
|
__indwin__p = new TProgind(m,t,b,c,n);
|
|
|
|
}
|
|
|
|
|
2008-12-10 16:52:43 +00:00
|
|
|
bool progind_set_status(long l)
|
1996-05-31 15:27:42 +00:00
|
|
|
{
|
2008-12-10 16:52:43 +00:00
|
|
|
return ((TProgind*)__indwin__p)->setstatus(l);
|
1996-05-31 15:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void progind_cancel()
|
|
|
|
{
|
|
|
|
__indwin__p->cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool progind_iscancelled()
|
|
|
|
{
|
|
|
|
return __indwin__p->iscancelled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool progind_isfinished()
|
|
|
|
{
|
|
|
|
return __indwin__p->isfinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void progind_destroy()
|
|
|
|
{
|
|
|
|
delete __indwin__p;
|
|
|
|
__indwin__p = NULL;
|
|
|
|
}
|
|
|
|
|
1997-12-02 13:21:19 +00:00
|
|
|
void timerind_create(long l, const char* title, bool bar, bool cancel,
|
1996-05-31 15:27:42 +00:00
|
|
|
int divisions, int interval)
|
|
|
|
{
|
|
|
|
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
|
|
|
|
__indwin__p = new TTimerind(l,title,bar,cancel,divisions,interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void timerind_cancel()
|
|
|
|
{
|
|
|
|
__indwin__p->cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool timerind_iscancelled()
|
|
|
|
{
|
|
|
|
return __indwin__p->iscancelled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool timerind_isfinished()
|
|
|
|
{
|
|
|
|
return __indwin__p->isfinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void timerind_destroy()
|
|
|
|
{
|
|
|
|
delete __indwin__p;
|
|
|
|
__indwin__p = NULL;
|
|
|
|
}
|
2002-12-18 10:56:10 +00:00
|
|
|
|