Correzioni su TDistrib in modo da gestire al meglio casi limite con totali nulli

git-svn-id: svn://10.65.10.50/branches/R_10_00@22922 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2014-03-07 14:20:06 +00:00
parent de92695865
commit b8d35eb40b
16 changed files with 721 additions and 622 deletions

View File

@ -57,9 +57,7 @@ public:
// @cmember Ritorna il numero di oggetti nel contenitore
virtual long objects( ) const pure;
// @cmember Ritorna true se il contenitore e' vuoto
virtual bool empty() const
{ return objects( ) == 0; }
virtual bool empty() const { return objects( ) == 0; }
// @cmember Cerca il successivo elemento che soddisfa la <t OPERATION_FUNCTION>
virtual void for_each( OPERATION_FUNCTION );

View File

@ -17,11 +17,8 @@
#define XVT_INCL_NATIVE
#include <xvt.h>
#define S4OFF_REPORT
#if XVT_OS == XVT_OS_WIN32
#define S4DLL
#define S4WIN32
#endif
//#define S4DLL
//#define S4WIN32
#include <d4all.h>
#include <codeb.h>

View File

@ -1874,14 +1874,13 @@ void TPushbutton_control::update()
{
XinWindow win = xi_get_window(_obj);
XI_RCT rct; xi_get_rect(_obj, &rct); // = _obj->v.btn->rct;
xi_set_clip(win, &rct);
xi_draw_3d_rect(win, &rct, _obj->v.btn->down, 2, BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
xi_inflate_rect(&rct, -3);
xi_set_clip(win, &rct);
/*if (CAMPI_SCAVATI)
xi_draw_shaded_rect(win, &rct, _obj->v.btn->down, 2, BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
else*/
xi_draw_3d_rect(win, &rct, _obj->v.btn->down, 2, BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
const int bmp = (_bmp_dn > 0 && _obj->v.btn->down) ? _bmp_dn : _bmp_up;
if (bmp > 0)
{
@ -1891,6 +1890,7 @@ void TPushbutton_control::update()
xvt_rect_offset(&dst, 2, 2);
i.draw((WINDOW)win, dst);
}
xi_set_clip(win, NULL);
}
}

View File

@ -945,6 +945,8 @@ bool TForm_subsection::print_body(sec_print_mode showfields)
bool again=TRUE;
while (again && group_expr==_section->eval_expr(*_condexpr,_file_id).as_string())
{
if (printer().frozen())
break;
form().match_result(_file_id);
if (!_bigskip || i==0)
{
@ -3702,9 +3704,8 @@ bool TForm::print(
if ((_char_to_pos != '\0' || ((_ipx +_ipy+_fpx) != 0)) && // Se i parametri di posizionamento sono settati e
(_x != 0 || _y != 0)) // cosi' pure gli offset genera un errore.
{
error_box(TR("Non e' possibile settare contemporaneamente gli offset"
" e i parametri di posizionamento del modulo."));
return FALSE;
return error_box(TR("Non e' possibile settare contemporaneamente gli offset"
" e i parametri di posizionamento del modulo."));
}
TPrinter& pr = printer();
if (_frompage) pr.set_from_page(_frompage);

View File

@ -3410,28 +3410,37 @@ int TRectype::compare_key(
return res;
}
HIDDEN bool fld_empty(const char* s, int len, bool number)
HIDDEN bool fld_empty(const char* s, int len, bool /* number */)
{
if (s && *s)
if (s && *s && len > 0)
{
for (; len; s++, len--)
if (*s != ' ') return false;
for (; len; s++, len--) if (*s != ' ')
return false;
}
return true;
}
HIDDEN int fld_cmp(const char* a, const char* b, int len, bool number)
{
int i;
for (i = 0; i < len && *a == *b; b++, a++, i++);
if (i == len) return 0;
int res = *a - *b;
int res = memcmp(a, b, len);
if (res == 0)
return res;
int i = 0;
if (number) // Aggiunta del 11-02-2014: ignoro spazi e zeri iniziali dei numeri
for (; i < len && (*a==' ' || *a=='0') && (*b==' ' || *b=='0'); b++, a++, i++);
for (; i < len && *a == *b; b++, a++, i++);
if (i == len)
return 0;
res = *a - *b;
if (number)
{
b -= i;
i = 0;
}
return fld_empty(b, len - i, number) ? 0 : res;
}
@ -3615,7 +3624,7 @@ word TRectype::get_word(const char* fieldname) const
real TRectype::get_real(const char* fieldname) const
{
real r(get_str(fieldname));
const real r(get_str(fieldname));
return r;
}

View File

@ -1200,7 +1200,8 @@ bool TPrint_application::print_one (
TPrinter& prn = printer();
if ((_prind && _prind->iscancelled()) || prn.frozen())
if (_cancelled = cancel_hook()) return FALSE;
if (_cancelled = cancel_hook())
return false;
if (!_print_defined)
return TRUE;

View File

@ -1,382 +1,422 @@
#include "xvt.h"
#include "xinclude.h"
#include <colors.h>
#include <diction.h>
#include <progind.h>
#include <controls.h>
#include <reprint.h>
#include <urldefid.h>
int TIndwin::_indwin_count = 0;
word TIndwin::measure_text(TToken_string& s, word& maxlen) const
{
word lines = 0;
FOR_EACH_TOKEN(s, t)
{
const word l = strlen(t);
if (l > maxlen) maxlen = l;
lines++;
}
return lines;
}
// Certified 70%
TIndwin::TIndwin(long tot, const char* txt, bool cancel, bool bar, int div)
: _gauge(NULL_WIN), _can_cancel(cancel), _bar_top(0),
_flags(0x0), _max(tot), _status(0L)
{
TToken_string testo(txt, '\n');
word maxlen = div;
const word lines = measure_text(testo, maxlen);
const int hor = min(maxlen+3, 78);
const int ver = lines+3 + (bar ? 2 : 0);
const int y = _indwin_count == 0 ? 3 : 12;
long flags = WSF_INVISIBLE;
if (_can_cancel)
flags |= WSF_CLOSE;
create(-1, y, hor, ver, TR("Elaborazione in corso"), flags, WD_MODAL);
attach_interface(win(), MASK_BACK_COLOR); // Mette eventuale texture
_bar_top = (lines+1)*ROWY;
set_text(testo);
if (bar)
{
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;
WIN_DEF wd; memset(&wd, 0, sizeof(wd));
wd.wtype = WC_HGAUGE;
get_bar_rct(wd.rct);
wd.ctlcolors = xcc;
_gauge = xvt_ctl_create_def(&wd, win(), tot);
}
open_modal();
_indwin_count++;
setmax(tot);
}
// @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
// (es. inserire degli spazi) quando se ne prevede uno piu' lungo.
{
_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);
}
void TIndwin::setmax(long m)
{
_max = m <= 0 ? 1 : m;
if (_gauge)
xvt_sbar_set_range(_gauge, HVGAUGE, 0, _max);
_start_time = clock();
}
TIndwin::~TIndwin()
{
if (is_open())
close_modal();
_indwin_count--;
}
bool TIndwin::can_be_closed() const
{
const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED);
if (!ok) error_box(TR("Attendere la fine dell'operazione prima di chiudere l'applicazione"));
return ok;
}
KEY TIndwin::check_stop()
{
KEY k = 0;
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
if (is_running())
stop_run(k);
}
return k;
}
void TIndwin::get_bar_rct(RCT& r) const
{
xvt_vobj_get_client_rect(win(), &r);
r.left += CHARX;
r.right -= CHARX;
r.top = _bar_top;
r.bottom = r.top + ROWY;
}
void TIndwin::get_txt_rct(RCT& r) const
{
get_bar_rct(r);
r.bottom = r.top - ROWY/2;
r.top = ROWY/2;
}
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);
}
void TIndwin::update_bar()
{
if (_status >= _max)
{
_status = _max;
_flags |= IND_FINISHED;
}
// Percentuale raggiunta finora
const double prc = (double)_status / (double)_max;
if (prc > 0)
{
const unsigned long elapsed_time = (clock() - _start_time)/CLOCKS_PER_SEC;
const unsigned long total_time = (unsigned long)(elapsed_time / prc + 0.5);
TString16 str_ela, str_res, str_tot;
sec2str(elapsed_time, str_ela);
sec2str(total_time - elapsed_time, str_res);
sec2str(total_time, str_tot);
TString80 n;
n.format("%d%% - %s %s - %s %s - %s %s", int(prc*100.0+0.5),
TR("Trascorso"), str_ela.get_buffer(),
TR("Stimato"), str_tot.get_buffer(),
TR("Residuo"), str_res.get_buffer()
);
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(PROMPT_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
set_font();
xvt_dwin_draw_text(w, b.left, b.bottom-1, n, -1);
}
check_stop();
}
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(PROMPT_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
set_font();
advanced_draw_paragraph(w, _text, r, 'L', 'C', CHARY);
}
void TIndwin::update()
{
//clear(MASK_BACK_COLOR); // Già fatto da xi_interface
if (_gauge != NULL_WIN)
update_bar();
if (!_text.empty())
update_txt();
}
bool TIndwin::setstatus(long l)
{
if (l < 0)
{
NFCHECK("Negative progind status");
l = 0;
}
_status = l > _max ? _max : l;
if (_can_cancel && !xvt_vobj_is_valid(win()))
{
_gauge = NULL_WIN;
on_key(K_ESC);
}
if (_gauge != NULL_WIN)
xvt_sbar_set_pos(_gauge, HVGAUGE, _status);
return !iscancelled();
}
bool TIndwin::on_key(KEY k)
{
if (k == K_ESC && _can_cancel)
{
_flags |= IND_CANCELLED;
check_stop();
}
return true; // Ignora tutti gli altri tasti, senza chiamare TWindow::on_key(k)
}
bool TIndwin::stop_run(KEY k)
{
if (k == K_ESC)
{
if (_can_cancel)
_flags |= IND_CANCELLED;
else
return false;
}
return TWindow::stop_run(k);
}
// TProgind --------------------------------------------------------------
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div), _next_update(0)
{}
bool TProgind::setstatus(long l)
{
const bool ok = TIndwin::setstatus(l);
const clock_t c = clock();
if (ok && c > _next_update)
{
update();
do_events();
_next_update = c+CLOCKS_PER_SEC; // Prossimo aggiornamento tra un secondo
}
return ok;
}
// TTimerind ------------------------------------------------------------
long TTimerind::handler(WINDOW w, EVENT* e)
{
switch(e->type)
{
case E_CREATE:
case E_UPDATE:
if (_timer_id == 0L && _interval > 0)
_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;
}
return TIndwin::handler(w,e);
}
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)
{ }
TTimerind::~TTimerind()
{
if (_timer_id)
xvt_timer_destroy(_timer_id);
}
// C-style binding
// uses static pointer for single instance of TIndwin
static TIndwin* __indwin__p = NULL;
void progind_create(long m, const char* t, bool b, bool c, int n)
{
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
__indwin__p = new TProgind(m,t,b,c,n);
}
bool progind_set_status(long l)
{
return ((TProgind*)__indwin__p)->setstatus(l);
}
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;
}
void timerind_create(long l, const char* title, bool bar, bool cancel,
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;
}
#include "xvt.h"
#include "xinclude.h"
#include <colors.h>
#include <diction.h>
#include <progind.h>
#include <controls.h>
#include <reprint.h>
///////////////////////////////////////////////////////////
// TIndwin
///////////////////////////////////////////////////////////
int TIndwin::_indwin_count = 0;
word TIndwin::measure_text(TToken_string& s, word& maxlen) const
{
word lines = 0;
FOR_EACH_TOKEN(s, t)
{
const word l = strlen(t);
if (l > maxlen) maxlen = l;
lines++;
}
return lines;
}
// Certified 70%
TIndwin::TIndwin(long tot, const char* txt, bool cancel, bool bar, int div)
: _gauge(NULL_WIN), _can_cancel(cancel), _bar_top(0),
_flags(0x0), _max(tot), _status(0L)
{
TToken_string testo(txt, '\n');
word maxlen = div;
const word lines = measure_text(testo, maxlen);
const int hor = min(maxlen+3, 78);
const int ver = lines+3 + (bar ? 2 : 0);
const int y = _indwin_count == 0 ? 3 : 12;
long flags = WSF_INVISIBLE;
if (_can_cancel)
flags |= WSF_CLOSE;
create(-1, y, hor, ver, TR("Elaborazione in corso"), flags, WD_MODAL);
attach_interface(win(), MASK_BACK_COLOR); // Mette eventuale texture
_bar_top = (lines+1)*ROWY;
set_text(testo);
if (bar)
{
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;
WIN_DEF wd; memset(&wd, 0, sizeof(wd));
wd.wtype = WC_HGAUGE;
get_bar_rct(wd.rct);
wd.ctlcolors = xcc;
_gauge = xvt_ctl_create_def(&wd, win(), tot);
}
open_modal();
_indwin_count++;
setmax(tot);
}
// @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
// (es. inserire degli spazi) quando se ne prevede uno piu' lungo.
{
_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);
}
void TIndwin::setmax(long m)
{
_max = m <= 0 ? 1 : m;
if (_gauge)
xvt_sbar_set_range(_gauge, HVGAUGE, 0, _max);
_start_time = clock();
}
TIndwin::~TIndwin()
{
if (is_open())
close_modal();
_indwin_count--;
}
bool TIndwin::can_be_closed() const
{
const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED);
if (!ok) error_box(TR("Attendere la fine dell'operazione prima di chiudere l'applicazione"));
return ok;
}
KEY TIndwin::check_stop()
{
KEY k = 0;
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
if (is_running())
stop_run(k);
}
return k;
}
void TIndwin::get_bar_rct(RCT& r) const
{
xvt_vobj_get_client_rect(win(), &r);
r.left += CHARX;
r.right -= CHARX;
r.top = _bar_top;
r.bottom = r.top + ROWY;
}
void TIndwin::get_txt_rct(RCT& r) const
{
get_bar_rct(r);
r.bottom = r.top - ROWY/2;
r.top = ROWY/2;
}
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);
}
void TIndwin::update_bar()
{
if (_status >= _max)
{
_status = _max;
_flags |= IND_FINISHED;
}
// Percentuale raggiunta finora
const double prc = (double)_status / (double)_max;
if (prc > 0)
{
const unsigned long elapsed_time = (clock() - _start_time)/CLOCKS_PER_SEC;
const unsigned long total_time = (unsigned long)(elapsed_time / prc + 0.5);
TString16 str_ela, str_res, str_tot;
sec2str(elapsed_time, str_ela);
sec2str(total_time - elapsed_time, str_res);
sec2str(total_time, str_tot);
TString80 n;
n.format("%d%% - %s %s - %s %s - %s %s", int(prc*100.0+0.5),
TR("Trascorso"), str_ela.get_buffer(),
TR("Stimato"), str_tot.get_buffer(),
TR("Residuo"), str_res.get_buffer()
);
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(PROMPT_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
set_font();
xvt_dwin_draw_text(w, b.left, b.bottom-1, n, -1);
}
check_stop();
}
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(PROMPT_COLOR, MASK_BACK_COLOR);
set_opaque_text(TRUE);
set_font();
advanced_draw_paragraph(w, _text, r, 'L', 'C', CHARY);
}
void TIndwin::update()
{
//clear(MASK_BACK_COLOR); // Già fatto da xi_interface
if (_gauge != NULL_WIN)
update_bar();
if (!_text.empty())
update_txt();
}
bool TIndwin::setstatus(long l)
{
if (l < 0)
{
NFCHECK("Negative progind status");
l = 0;
}
_status = l > _max ? _max : l;
if (_can_cancel && !xvt_vobj_is_valid(win()))
{
_gauge = NULL_WIN;
on_key(K_ESC);
}
if (_gauge != NULL_WIN)
xvt_sbar_set_pos(_gauge, HVGAUGE, _status);
return !iscancelled();
}
bool TIndwin::on_key(KEY k)
{
if (k == K_ESC && _can_cancel)
{
_flags |= IND_CANCELLED;
check_stop();
}
return true; // Ignora tutti gli altri tasti, senza chiamare TWindow::on_key(k)
}
bool TIndwin::stop_run(KEY k)
{
if (k == K_ESC)
{
if (_can_cancel)
_flags |= IND_CANCELLED;
else
return false;
}
return TWindow::stop_run(k);
}
///////////////////////////////////////////////////////////
// TProgind
///////////////////////////////////////////////////////////
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div), _next_update(0)
{}
bool TProgind::setstatus(long l)
{
const bool ok = TIndwin::setstatus(l);
const clock_t c = clock();
if (ok && c > _next_update)
{
update();
do_events();
_next_update = c+CLOCKS_PER_SEC; // Prossimo aggiornamento tra un secondo
}
return ok;
}
// TTimerind ------------------------------------------------------------
long TTimerind::handler(WINDOW w, EVENT* e)
{
switch(e->type)
{
case E_CREATE:
case E_UPDATE:
if (_timer_id == 0L && _interval > 0)
_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;
}
return TIndwin::handler(w,e);
}
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)
{ }
TTimerind::~TTimerind()
{
if (_timer_id)
xvt_timer_destroy(_timer_id);
}
///////////////////////////////////////////////////////////
// TProgress_monitor
///////////////////////////////////////////////////////////
bool TProgress_monitor::set_status(long n)
{
// Aggiunsto timer iniziale se necessario
if (_status <= 0 && n <= 0)
_start = clock();
// Se sono passati 1 secondi e sono a meno di metà lavoro allora crea la TProgind
if (_pi == NULL && n < _total/2 && (clock() - _start) >= CLOCKS_PER_SEC)
{
_pi = new TProgind(_total, _txt, _cancellable);
_pi->set_start_time(_start);
}
// Aggiorna la TProgind associata, sempre che esista
_status = min(n, _total);
return _pi == NULL || _pi->setstatus(_status);
}
TProgress_monitor::TProgress_monitor(long items, const char* txt, bool cancancel)
: _total(items), _txt(txt), _status(0), _cancellable(cancancel), _pi(NULL), _start(clock())
{
}
TProgress_monitor::~TProgress_monitor()
{
// Distruggi la TProgind o la clessidra, a seconda del caso
if (_pi != NULL)
delete _pi;
}
///////////////////////////////////////////////////////////
// C-style bindings
///////////////////////////////////////////////////////////
// uses static pointer for single instance of TIndwin
static TIndwin* __indwin__p = NULL;
void progind_create(long m, const char* t, bool b, bool c, int n)
{
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
__indwin__p = new TProgind(m,t,b,c,n);
}
bool progind_set_status(long l)
{
return ((TProgind*)__indwin__p)->setstatus(l);
}
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;
}
void timerind_create(long l, const char* title, bool bar, bool cancel,
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;
}

View File

@ -1,180 +1,209 @@
#ifndef __PROGIND_H
#define __PROGIND_H
#ifdef __cplusplus
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __CONTROLS_H
class TControl;
class TField_control;
#endif
// @doc EXTERNAL
// @class TIndwin | Classe base per la gestione delle finestre con le barre di attesa
//
// @base public | TWindow
class TIndwin : public TWindow
// @author:(INTERNAL) Villa
{
// @access:(INTERNAL) Private Member
enum {
// @ccost:(INTERNAL) IND_CANCELLED | 0x01 | Controlla se e' stato premuto il tasto "Annulla"
IND_CANCELLED = 0x01,
// @ccost:(INTERNAL) IND_FINISHED | 0x02 | Controlla se l'operazione e' terminata
IND_FINISHED= 0x02 };
TString_array _text;
short _bar_top;
bool _can_cancel;
// @cmember:(INTERNAL) Movimento della barra e percentuale
WINDOW _gauge;
// @cmember:(INTERNAL) ora inizio elaborazione
unsigned long _start_time;
// @cmember:(INTERNAL) Flag che indica quali operazioni sono state effettuate
byte _flags;
static int _indwin_count;
// @access Protected Member
protected:
// @cmember Massimo valore da ricercare
long _max;
// @cmember Stato corrente dell'esecuzione (settato dell'utente)
long _status;
// @cmember Ritorna il numero di linee necessarie per scrivere il testo nella finestra
word measure_text(TToken_string& t, word& len) const;
// @cmember Calcola il rettangolo della barra di attesa
virtual void get_bar_rct(RCT& r) const;
// @cmember Calcola il rettangolo del testo
virtual void get_txt_rct(RCT& r) const;
// @cmember converte secondi in una stringa nel formato hh:mm:ss
void sec2str(unsigned long ss, TString& str) const;
// @cmember Gestisce gli eventi tasto della finestra
virtual bool on_key(KEY k);
virtual bool stop_run(KEY k);
// @cmember Aggiorna la barra di attesa (chiama update_bar)
virtual void update();
// @cmember Aggiorna la barra di attesa
virtual void update_bar();
virtual void update_txt();
// @cmember Controlla se ha terminato la barra di attesa
KEY check_stop();
// @access Public Member
public:
// @cmember Controlla se e' stato premuto il tasto "Annulla"
bool iscancelled() const { return (_flags & IND_CANCELLED) != 0; }
// @cmember Controlla se e' finito l'operazione
bool isfinished() const { return (_flags & IND_FINISHED) != 0; }
// @cmember Ritorna lo stato dell'operazione (quantita' dell'applicazione gia' fatta)
long status() const { return _status; }
// @cmember Ferma l'operazione (chiude la finestra)
void cancel()
{ _flags |= IND_CANCELLED; do_events(); check_stop(); }
// @cmember Controlla se l'operazione puo' essere chiusa
virtual bool can_be_closed() const;
// @cmember Setta il testo della finestra
void set_text(const char* t);
// @cmember Setta il valore massimo della barra d'attesa
void setmax(long m);
virtual bool setstatus(long l);
// @cmember Costruttore
TIndwin(long max, const char* txt, bool cancel = TRUE, bool bar = TRUE, int div = 60);
// @cmember Distruttore
virtual ~TIndwin();
};
// @doc EXTERNAL
// @class TProgind | Classe per la gestione della barra di attesa di una applicazione
//
// @base public | TIndwin
class TProgind : public TIndwin
// @author:(INTERNAL) Villa
{
clock_t _next_update;
// @access Public Member
public:
// @cmember Setta lo stato della barra d'attesa
virtual bool setstatus(long l);
// @cmember Aggiorna la barra d'attesa aggiungendo l'incremento fatto dell'applicazione
bool addstatus(long l)
{ return setstatus(_status+l); }
// @cmember Costruttore
TProgind(long max, const char* txt = NULL, bool cancel = TRUE, bool bar = TRUE, int div = 60);
// @cmember Distruttore
virtual ~TProgind()
{}
};
// @doc EXTERNAL
// @class TTimerind | Classe per la definizione di una barra d'attesa gestita
// dal tempo e non dallo stato dell'applicazione
//
// @base public | TIndwin
class TTimerind : public TIndwin
// @author:(INTERNAL) Villa
{
// @access:(INTERNAL) Private Member
// @cmember:(INTERNAL) Intervallo di tempo
int _interval;
// @cmember:(INTERNAL) Indice di tempo
long _timer_id;
// @access Protected Member
protected:
// @cmember Gestisce gli eventi della finestra
virtual long handler(WINDOW w, EVENT* e);
// @access Public Member
public:
// @cmember Costruttore
TTimerind(long msec, const char* txt = NULL, bool cancel = TRUE, bool bar = TRUE, int div = 10, int interval = 1000);
// @cmember Distruttore
virtual ~TTimerind();
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Non commentate perche' destinate a sparire
void progind_create(long, const char*, bool, bool, int);
bool progind_set_status(long s);
void progind_cancel();
bool progind_iscancelled();
bool progind_isfinished();
void progind_destroy();
void timerind_create(long, const char*, bool, bool, int, int);
void timerind_cancel();
bool timerind_iscancelled();
bool timerind_isfinished();
void timerind_destroy();
#ifdef __cplusplus
}
#endif
#endif /* __PROGIND_H */
#ifndef __PROGIND_H
#define __PROGIND_H
#ifdef __cplusplus
#ifndef __WINDOW_H
#include <window.h>
#endif
#ifndef __CONTROLS_H
class TControl;
class TField_control;
#endif
// @doc EXTERNAL
// @class TIndwin | Classe base per la gestione delle finestre con le barre di attesa
//
// @base public | TWindow
class TIndwin : public TWindow
// @author:(INTERNAL) Villa
{
// @access:(INTERNAL) Private Member
enum {
// @ccost:(INTERNAL) IND_CANCELLED | 0x01 | Controlla se e' stato premuto il tasto "Annulla"
IND_CANCELLED = 0x01,
// @ccost:(INTERNAL) IND_FINISHED | 0x02 | Controlla se l'operazione e' terminata
IND_FINISHED= 0x02 };
TString_array _text;
short _bar_top;
bool _can_cancel;
// @cmember:(INTERNAL) Movimento della barra e percentuale
WINDOW _gauge;
// @cmember:(INTERNAL) ora inizio elaborazione
clock_t _start_time;
// @cmember:(INTERNAL) Flag che indica quali operazioni sono state effettuate
byte _flags;
static int _indwin_count;
// @access Protected Member
protected:
// @cmember Massimo valore da ricercare
long _max;
// @cmember Stato corrente dell'esecuzione (settato dell'utente)
long _status;
// @cmember Ritorna il numero di linee necessarie per scrivere il testo nella finestra
word measure_text(TToken_string& t, word& len) const;
// @cmember Calcola il rettangolo della barra di attesa
virtual void get_bar_rct(RCT& r) const;
// @cmember Calcola il rettangolo del testo
virtual void get_txt_rct(RCT& r) const;
// @cmember converte secondi in una stringa nel formato hh:mm:ss
void sec2str(unsigned long ss, TString& str) const;
// @cmember Gestisce gli eventi tasto della finestra
virtual bool on_key(KEY k);
virtual bool stop_run(KEY k);
// @cmember Aggiorna la barra di attesa (chiama update_bar)
virtual void update();
// @cmember Aggiorna la barra di attesa
virtual void update_bar();
virtual void update_txt();
// @cmember Controlla se ha terminato la barra di attesa
KEY check_stop();
// @access Public Member
public:
// @cmember Controlla se e' stato premuto il tasto "Annulla"
bool iscancelled() const { return (_flags & IND_CANCELLED) != 0; }
// @cmember Controlla se e' finito l'operazione
bool isfinished() const { return (_flags & IND_FINISHED) != 0; }
// @cmember Ritorna lo stato dell'operazione (quantita' dell'applicazione gia' fatta)
long status() const { return _status; }
// @cmember Ferma l'operazione (chiude la finestra)
void cancel()
{ _flags |= IND_CANCELLED; do_events(); check_stop(); }
// @cmember Controlla se l'operazione puo' essere chiusa
virtual bool can_be_closed() const;
// @cmember Setta il testo della finestra
void set_text(const char* t);
// @cmember Setta il valore massimo della barra d'attesa
void setmax(long m);
virtual bool setstatus(long l);
// @cmember Forza il timer d'inizio (serve solo a TProgress_monitor)
void set_start_time(unsigned long st) { _start_time = st; }
// @cmember Costruttore
TIndwin(long max, const char* txt, bool cancel = TRUE, bool bar = TRUE, int div = 60);
// @cmember Distruttore
virtual ~TIndwin();
};
// @doc EXTERNAL
// @class TProgind | Classe per la gestione della barra di attesa di una applicazione
//
// @base public | TIndwin
class TProgind : public TIndwin
// @author:(INTERNAL) Villa
{
clock_t _next_update;
// @access Public Member
public:
// @cmember Setta lo stato della barra d'attesa
virtual bool setstatus(long l);
// @cmember Aggiorna la barra d'attesa aggiungendo l'incremento fatto dell'applicazione
bool addstatus(long l)
{ return setstatus(_status+l); }
// @cmember Costruttore
TProgind(long max, const char* txt = NULL, bool cancel = TRUE, bool bar = TRUE, int div = 60);
// @cmember Distruttore
virtual ~TProgind()
{}
};
// @doc EXTERNAL
// @class TTimerind | Classe per la definizione di una barra d'attesa gestita
// dal tempo e non dallo stato dell'applicazione
//
// @base public | TIndwin
class TTimerind : public TIndwin
// @author:(INTERNAL) Villa
{
// @access:(INTERNAL) Private Member
// @cmember:(INTERNAL) Intervallo di tempo
int _interval;
// @cmember:(INTERNAL) Indice di tempo
long _timer_id;
// @access Protected Member
protected:
// @cmember Gestisce gli eventi della finestra
virtual long handler(WINDOW w, EVENT* e);
// @access Public Member
public:
// @cmember Costruttore
TTimerind(long msec, const char* txt = NULL, bool cancel = TRUE, bool bar = TRUE, int div = 10, int interval = 1000);
// @cmember Distruttore
virtual ~TTimerind();
};
// @doc EXTERNAL
// @class TProgress_monitor | Classe per gestire intelligentemente clessidra o barra di attesa
//
// @base public | TObject
class TProgress_monitor : public TObject
{
long _total, _status;
TString _txt;
bool _cancellable;
TProgind* _pi;
clock_t _start;
public:
virtual bool set_status(long n);
bool add_status(long i = 1) { return set_status(_status+i); }
// deprecated TProgind compatibility methods
bool setstatus(long n) { return set_status(n); }
bool addstatus(long n) { return add_status(n); }
TProgress_monitor(long items, const char* txt, bool cancellable = true);
~TProgress_monitor();
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Non commentate perche' destinate a sparire
void progind_create(long, const char*, bool, bool, int);
bool progind_set_status(long s);
void progind_cancel();
bool progind_iscancelled();
bool progind_isfinished();
void progind_destroy();
void timerind_create(long, const char*, bool, bool, int, int);
void timerind_cancel();
bool timerind_iscancelled();
bool timerind_isfinished();
void timerind_destroy();
#ifdef __cplusplus
}
#endif
#endif /* __PROGIND_H */

View File

@ -1696,14 +1696,19 @@ real TGeneric_distrib::get ()
{
_ready = true;
CHECK (_current < _slices.items(), "TGeneric_distrib: too many gets");
real & currslice = (real &) _slices[_current++];
const real & currslice = (real &) _slices[_current++];
real r = currslice;
if (_tot != _totslices)
{
if (_tot < 1E9 && currslice < 1E9)
r = (_tot * currslice) / _totslices;
if (currslice != _totslices) // Caso normale
{
if (abs(_tot) < 1E9 && abs(currslice) < 1E9)
r = _tot * currslice / _totslices;
else
r *= (_tot / _totslices);
}
else
r *= (_tot / _totslices);
r = _tot; // Caso limite che risolve (_totslices==0) && (_tot != 0)
}
r.round (_decs);
_tot -= r;

View File

@ -6,6 +6,7 @@
#include <dongle.h>
#include <modaut.h>
#include <progind.h>
#include <recarray.h>
#include <recset.h>
#include <relation.h>
#include <utility.h>
@ -359,7 +360,7 @@ bool TRecordset::save_as_dbf(const char* table, int mode)
char dirname[_MAX_PATH];
char name[_MAX_FNAME];
char ext[_MAX_EXT];
xvt_fsys_parse_pathname (table, volume, dirname, name, ext, NULL);
xvt_fsys_parse_pathname(table, volume, dirname, name, ext, NULL);
const int logicnum = table2logic(name);
@ -384,20 +385,18 @@ bool TRecordset::save_as_dbf(const char* table, int mode)
mode = 0x1;
}
TLocalisamfile* pisam = NULL;
TBaseisamfile* pisam = NULL;
if (logicnum >= LF_USER)
{
if (*dirname)
pisam = new TIsamtempfile(logicnum, table);
else
pisam = new TLocalisamfile(logicnum);
pisam = new TFast_isamfile(logicnum);
}
if (pisam == NULL)
return error_box("Impossibile creare il file %s", table);
TLocalisamfile& isam = *pisam;
TProgind pi(items(), TR("Esportazione in corso..."));
TBaseisamfile& isam = *pisam;
TRectype& rec = isam.curr();
TString_array names;
@ -415,10 +414,12 @@ bool TRecordset::save_as_dbf(const char* table, int mode)
names.add(EMPTY_STRING);
}
TProgress_monitor pi(items(), TR("Esportazione in corso..."), true);
bool ok = true;
for (bool go = move_first(); go; go = move_next())
{
pi.addstatus(1);
if (!pi.add_status())
break;
rec.zero();
FOR_EACH_ARRAY_ROW(names, j, name) if (name->not_empty())
rec.put(*name, get(j).as_string());
@ -985,7 +986,7 @@ const TString& TCursor_parser::line()
{
if (_pushed.not_empty())
return pop();
char* buff = _token.get_buffer(256);
char* buff = _token.get_buffer(512);
_instr.getline(buff, _token.size());
return _token;
}

View File

@ -837,7 +837,7 @@ int TRelation_application::delete_mode()
keep_running = FALSE;
if (tasto == K_DEL && sht.checked() == 0)
{
error_box(TR("Non e' stato selezionato nessun elemento"));
error_box(TR("Non è stato selezionato nessun elemento"));
sht.select(0);
keep_running = TRUE;
}
@ -1216,6 +1216,9 @@ int TRelation_application::rewrite(const TMask& m)
return err;
}
const char* TRelation_application::record_description(const TRelation& r) const
{ return r.file().description(); }
// @doc INTERNAL
// @mfunc Cancella il record corrente
@ -1230,10 +1233,10 @@ bool TRelation_application::relation_remove()
TRelation& r = *get_relation();
r.restore_status();
if (protected_record(r))
return warning_box(TR("Elemento non eliminabile"));
return warning_box(FR("%s non eliminabile"), record_description(r));
if (_curr_transaction == TRANSACTION_DELETE ||
delete_box(FR("Confermare l'eliminazione del record %s"), r.file().description()))
delete_box(FR("Confermare eliminazione %s"), record_description(r)))
{
r.restore_status();
const bool ok = remove();

View File

@ -241,6 +241,8 @@ protected:
virtual void sheet2ini(TSheet_field &sheet,TConfig& ini);
virtual void ini2mask(TConfig& ini, TMask& m, bool query);
virtual bool mask2mail(const TMask& m);
// @cmember Breve descrizione del tipo documento corrente
virtual const char* record_description(const TRelation& r) const;
// @access Public Member
public:

View File

@ -2776,10 +2776,10 @@ void TReport::report2mask(TMask & m) const
}
}
TVariant & string2var(TVariant & v, const TFieldref * r, const TString & val)
TVariant& string2var(TVariant& v, const TFieldref& r, const TString& val)
{
const int from = r->from();
int to = r->to();
const int from = r.from();
int to = r.to();
if (from > 0 || to > 0)
{
@ -2838,7 +2838,7 @@ void TReport::mask2report(const TMask & m)
get_usr_val(name, var);
if (val.empty())
val = is_final ? MAX_STRING : "";
string2var(var, ref, val);
string2var(var, *ref, val);
}
break;
}

View File

@ -612,7 +612,6 @@ public:
virtual bool set_recordset(const TString& sql);
virtual bool set_recordset(TRecordset* sql);
virtual TRecordset* recordset() const { return _recordset; }
bool evaluate_atom(const char* atom, TVariant& var);
bool evaluate(const char* expr, TVariant& var, TFieldtypes force_type);
const TString& prescript() const;

View File

@ -2737,20 +2737,34 @@ void TReport_book::add_doc(const TString& name)
TReport* eminem = new TReport;
if (eminem->load(name))
{
TReport* rep = _report; // Salvo variabile globale
if (rep->use_mask())
TFilename msk = _report->filename().name();
msk.ext("msk");
if (_report->use_mask() && msk.custom_path())
{
TFilename msk = rep->filename().name();
msk.ext("msk");
if (msk.custom_path())
TMask m(msk);
_report->report2mask(m);
eminem->mask2report(m);
}
else
{
TRecordset* mainset = _report->recordset();
TRecordset* recset = eminem->recordset();
if (mainset && recset)
{
TMask m(msk);
rep->report2mask(m);
eminem->mask2report(m);
const TString_array& vars = mainset->variables();
FOR_EACH_ARRAY_ROW(vars, i, name)
recset->set_var(*name, mainset->get_var(*name));
if (main_app().name().starts_with("ve1"))
{
recset->set_var("#PROVV", mainset->get("PROVV"));
recset->set_var("#ANNO", mainset->get("ANNO"));
recset->set_var("#CODNUM", mainset->get("CODNUM"));
recset->set_var("#NDOC", mainset->get("NDOC"));
}
}
}
TReport* rep = _report; // Salvo variabile globale
add(*eminem, true);
_report = rep; // Ripristino variabile globale
}

View File

@ -67,7 +67,7 @@ TString & TVariable_field::get() const
{
if (_in_get)
fatal_box("Recursive get in %s", (const char *) _name);
((TVariable_field *) this)->_in_get = TRUE;
((TVariable_field *) this)->_in_get = true;
if (_e)
{
CHECK(_rec, "NULL Record pointer with an expression");
@ -80,8 +80,8 @@ TString & TVariable_field::get() const
CHECK(_rec, "NULL Record pointer with a function");
v = _getfunc(*_rec);
}
((TVariable_field *) this)->_in_get = FALSE;
((TVariable_field *) this)->set_clean();
((TVariable_field*) this)->_in_get = false;
((TVariable_field*) this)->set_clean();
}
return v;
}