Corretta formattazione

git-svn-id: svn://10.65.10.50/trunk@2948 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-05-31 15:27:42 +00:00
parent 1d80e8a48c
commit 4a4ff4a48f
6 changed files with 4043 additions and 4026 deletions

View File

@ -1,330 +1,330 @@
#ifndef __CONTROLS_H
#define __CONTROLS_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
class TWindow; // __WINDOW_H
class TMask_field; // __MASKFLD_H
#ifndef INCL_XI
#define XI_INTERNAL
#include <xi.h>
#endif
void init_controls();
void free_controls();
XVT_FNTID xvt_default_font(bool bold = FALSE);
WINDOW create_interface(WINDOW parent, short x, short y, short dx, short dy,
const char* caption, TWindow* mask, bool tags);
void attach_interface(WINDOW win, COLOR back = COLOR_WHITE);
short get_focus_id(WINDOW win);
///////////////////////////////////////////////////////////
// Custom control
///////////////////////////////////////////////////////////
// @doc INTERNAL
// @class TControl | Classe per la creazione di controlli
class TControl : public TObject
// @author:(INTERNAL) Guido
// @access:(INTERNAL) Private Member
{
// @access Protected Member
protected:
// @cmember:(INTERNAL) Puntatore al controllo creato
XI_OBJ* _obj;
// @cmember:(INTERNAL) Puntatore al TMask_field eventualmente associato
TMask_field* _fld;
// @cmember Ricava l'interfaccia da una finestra
XI_OBJ* get_interface(WINDOW win = NULL_WIN) const;
// @cmember Cerca un controllo operabile (in avanti o all'indietro)
TControl& find_operable_ctl(bool forward) const;
// @cmember Setta l'identificatore del prossimo controllo per il tasto TAB
void set_tab_cid(short id);
void coord2rct(WINDOW win, short left, short top, short width, short height, RCT& rct) const;
unsigned long flags2attr(const char* flags) const;
void update_tab_cid();
const char* parse_caption(const char* cap, bool& bold, COLOR& color) const;
void change_attrib(unsigned long attr, bool on, XI_OBJ* obj = NULL);
bool notify_key(KEY k);
// @access Public Member
public:
TControl();
virtual ~TControl();
static KEY xiev_to_key(const XI_EVENT* xiev);
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* ep);
bool is_edit_key(KEY k) const;
// @cmember Ritorna l'identificatore assegnato al controllo
short id() const { return _obj->cid; }
WINDOW parent() const;
XI_OBJ_TYPE type() const { return _obj->type; }
// @cmember Ritorna il prompt del controllo
const char* caption() const;
// @cmember Setta il prompt del controllo
virtual void set_caption(const char* c);
// @cmember Abilita/disabilita il controllo
virtual void enable(bool on = TRUE);
void disable() { enable(FALSE); }
// @cmember Mostra/nasconde il controllo
virtual void show(bool on = TRUE);
void hide() { show(FALSE); }
void autoselect(bool on);
// @cmember Forza il focus al controllo
virtual void set_focus() const;
RCT& get_rect(RCT& r) const;
virtual void set_rect(const RCT& r);
bool on_key(KEY k);
};
class TText_control : public TControl
{
public: // TControl
virtual void set_caption(const char* text);
public:
TText_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TText_control() {}
};
class TGroupbox_control : public TText_control
{
XI_OBJ* _rct; // Rettangolo del gruppo
public: // TControl
virtual void show(bool on);
public:
TGroupbox_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TGroupbox_control() {}
};
class TField_control : public TControl
{
protected:
bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
void create(WINDOW win, short cid,
short left, short top,
short width, short height, short maxlen,
const char* flags, const char* text, bool button);
TField_control() {}
public:
// @cmember Mostra o nasconde il bottone associato
void show_button(bool on);
// @cmember Forza il focus al controllo
virtual void set_focus() const;
TField_control(WINDOW win, short cid,
short left, short top,
short width, short maxlen,
const char* flags, const char* text);
virtual ~TField_control() {}
};
class TMultiline_control : public TField_control
{
public:
TMultiline_control(WINDOW win, short cid,
short left, short top,
short width, short height, short maxlen,
const char* flags, const char* text);
virtual ~TMultiline_control() {}
};
class TButton_control : public TControl
{
protected:
void create(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text,
WIN_TYPE wc, XI_OBJ* container);
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* ep);
public:
virtual void set_rect(const RCT& r);
bool checked() const;
void check(bool on = TRUE);
void uncheck() { check(FALSE); }
bool toggle();
XI_BTN_TYPE button_type() const;
XI_OBJ* container() const;
TButton_control() {}
virtual ~TButton_control() {}
};
class TPushbutton_control : public TButton_control
{
short _bmp_up, _bmp_dn;
protected:
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
virtual void update();
void set_bmp(short up, short dn);
TPushbutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text,
short bmp_up = 0, short _bmp_dn = 0);
virtual ~TPushbutton_control() {}
};
class TRadiobutton_control : public TButton_control
{
protected: // TControl
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
virtual void set_focus() const;
protected:
TRadiobutton_control() { } // To be derived
public:
// @cmember Abilita/disabilita il controllo
virtual void enable(bool on = TRUE);
// @cmember Mostra/nasconde il controllo
virtual void show(bool on = TRUE);
byte get_checked() const;
void check_button(byte b);
void show_button(byte b, bool on = TRUE);
void hide_button(byte b) { show_button(b, FALSE); }
TRadiobutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TRadiobutton_control() {}
};
class TTagbutton_control : public TRadiobutton_control
{
protected: // TControl
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
TTagbutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text, int tag);
virtual ~TTagbutton_control() {}
};
class TCheckbox_control : public TButton_control
{
public:
TCheckbox_control(WINDOW win, short cid,
short left, short top, short width,
const char* flags, const char* text);
virtual ~TCheckbox_control() {}
};
class TDropDownList : public TObject
{
XI_OBJ* _obj;
XI_OBJ* _xi_lst;
TToken_string _codes;
TToken_string _values;
int _selected;
int _width;
bool _open;
bool _displayed;
bool _in_cell;
static void ddl_str_eh (XI_OBJ* itf, XI_EVENT* xiev);
public:
const int selected() const { return _selected; }
void open();
void close();
bool is_open() const { return _open; }
bool displayed() const { return _displayed; }
const char* item(int i) { return _values.get(i); }
int items() const { return _values.items(); }
long row2rec(int) const;
int rec2row(long rec) const;
void set_values(const char* c, const char* v);
bool select(int i, bool force = FALSE);
bool select_by_initial(char c);
bool select_by_ofs(int n);
TDropDownList(XI_OBJ* o, const char* codes, const char* values, int wid);
virtual ~TDropDownList() {}
};
class TListbox_control : public TField_control
{
friend class TDropDownList;
TDropDownList* _ddl;
private:
void drop_down();
protected: // TTField_control
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
void set_values(const char* c, const char* v);
int items() const { return _ddl->items(); }
bool select(int i) { return _ddl->select(i); }
bool select_by_initial(char c) { return _ddl->select_by_initial(c); }
bool select_by_ofs(int i) { return _ddl->select_by_ofs(i); }
int selected() const { return _ddl->selected(); }
TListbox_control(WINDOW win, short cid,
short left, short top, short width,
const char* flags, const char* text,
const char* codes, const char* values);
virtual ~TListbox_control();
};
#endif
#ifndef __CONTROLS_H
#define __CONTROLS_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
class TWindow; // __WINDOW_H
class TMask_field; // __MASKFLD_H
#ifndef INCL_XI
#define XI_INTERNAL
#include <xi.h>
#endif
void init_controls();
void free_controls();
XVT_FNTID xvt_default_font(bool bold = FALSE);
WINDOW create_interface(WINDOW parent, short x, short y, short dx, short dy,
const char* caption, TWindow* mask, bool tags);
void attach_interface(WINDOW win, COLOR back = COLOR_WHITE);
short get_focus_id(WINDOW win);
///////////////////////////////////////////////////////////
// Custom control
///////////////////////////////////////////////////////////
// @doc INTERNAL
// @class TControl | Classe per la creazione di controlli
class TControl : public TObject
// @author:(INTERNAL) Guido
// @access:(INTERNAL) Private Member
{
// @access Protected Member
protected:
// @cmember:(INTERNAL) Puntatore al controllo creato
XI_OBJ* _obj;
// @cmember:(INTERNAL) Puntatore al TMask_field eventualmente associato
TMask_field* _fld;
// @cmember Ricava l'interfaccia da una finestra
XI_OBJ* get_interface(WINDOW win = NULL_WIN) const;
// @cmember Cerca un controllo operabile (in avanti o all'indietro)
TControl& find_operable_ctl(bool forward) const;
// @cmember Setta l'identificatore del prossimo controllo per il tasto TAB
void set_tab_cid(short id);
void coord2rct(WINDOW win, short left, short top, short width, short height, RCT& rct) const;
unsigned long flags2attr(const char* flags) const;
void update_tab_cid();
const char* parse_caption(const char* cap, bool& bold, COLOR& color) const;
void change_attrib(unsigned long attr, bool on, XI_OBJ* obj = NULL);
bool notify_key(KEY k);
// @access Public Member
public:
TControl();
virtual ~TControl();
static KEY xiev_to_key(const XI_EVENT* xiev);
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* ep);
bool is_edit_key(KEY k) const;
// @cmember Ritorna l'identificatore assegnato al controllo
short id() const { return _obj->cid; }
WINDOW parent() const;
XI_OBJ_TYPE type() const { return _obj->type; }
// @cmember Ritorna il prompt del controllo
const char* caption() const;
// @cmember Setta il prompt del controllo
virtual void set_caption(const char* c);
// @cmember Abilita/disabilita il controllo
virtual void enable(bool on = TRUE);
void disable() { enable(FALSE); }
// @cmember Mostra/nasconde il controllo
virtual void show(bool on = TRUE);
void hide() { show(FALSE); }
void autoselect(bool on);
// @cmember Forza il focus al controllo
virtual void set_focus() const;
RCT& get_rect(RCT& r) const;
virtual void set_rect(const RCT& r);
bool on_key(KEY k);
};
class TText_control : public TControl
{
public: // TControl
virtual void set_caption(const char* text);
public:
TText_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TText_control() {}
};
class TGroupbox_control : public TText_control
{
XI_OBJ* _rct; // Rettangolo del gruppo
public: // TControl
virtual void show(bool on);
public:
TGroupbox_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TGroupbox_control() {}
};
class TField_control : public TControl
{
protected:
bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
void create(WINDOW win, short cid,
short left, short top,
short width, short height, short maxlen,
const char* flags, const char* text, bool button);
TField_control() {}
public:
// @cmember Mostra o nasconde il bottone associato
void show_button(bool on);
// @cmember Forza il focus al controllo
virtual void set_focus() const;
TField_control(WINDOW win, short cid,
short left, short top,
short width, short maxlen,
const char* flags, const char* text);
virtual ~TField_control() {}
};
class TMultiline_control : public TField_control
{
public:
TMultiline_control(WINDOW win, short cid,
short left, short top,
short width, short height, short maxlen,
const char* flags, const char* text);
virtual ~TMultiline_control() {}
};
class TButton_control : public TControl
{
protected:
void create(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text,
WIN_TYPE wc, XI_OBJ* container);
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* ep);
public:
virtual void set_rect(const RCT& r);
bool checked() const;
void check(bool on = TRUE);
void uncheck() { check(FALSE); }
bool toggle();
XI_BTN_TYPE button_type() const;
XI_OBJ* container() const;
TButton_control() {}
virtual ~TButton_control() {}
};
class TPushbutton_control : public TButton_control
{
short _bmp_up, _bmp_dn;
protected:
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
virtual void update();
void set_bmp(short up, short dn);
TPushbutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text,
short bmp_up = 0, short _bmp_dn = 0);
virtual ~TPushbutton_control() {}
};
class TRadiobutton_control : public TButton_control
{
protected: // TControl
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
virtual void set_focus() const;
protected:
TRadiobutton_control() { } // To be derived
public:
// @cmember Abilita/disabilita il controllo
virtual void enable(bool on = TRUE);
// @cmember Mostra/nasconde il controllo
virtual void show(bool on = TRUE);
byte get_checked() const;
void check_button(byte b);
void show_button(byte b, bool on = TRUE);
void hide_button(byte b) { show_button(b, FALSE); }
TRadiobutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text);
virtual ~TRadiobutton_control() {}
};
class TTagbutton_control : public TRadiobutton_control
{
protected: // TControl
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
TTagbutton_control(WINDOW win, short cid,
short left, short top, short width, short height,
const char* flags, const char* text, int tag);
virtual ~TTagbutton_control() {}
};
class TCheckbox_control : public TButton_control
{
public:
TCheckbox_control(WINDOW win, short cid,
short left, short top, short width,
const char* flags, const char* text);
virtual ~TCheckbox_control() {}
};
class TDropDownList : public TObject
{
XI_OBJ* _obj;
XI_OBJ* _xi_lst;
TToken_string _codes;
TToken_string _values;
int _selected;
int _width;
bool _open;
bool _displayed;
bool _in_cell;
static void ddl_str_eh (XI_OBJ* itf, XI_EVENT* xiev);
public:
const int selected() const { return _selected; }
void open();
void close();
bool is_open() const { return _open; }
bool displayed() const { return _displayed; }
const char* item(int i) { return _values.get(i); }
int items() const { return _values.items(); }
long row2rec(int) const;
int rec2row(long rec) const;
void set_values(const char* c, const char* v);
bool select(int i, bool force = FALSE);
bool select_by_initial(char c);
bool select_by_ofs(int n);
TDropDownList(XI_OBJ* o, const char* codes, const char* values, int wid);
virtual ~TDropDownList() {}
};
class TListbox_control : public TField_control
{
friend class TDropDownList;
TDropDownList* _ddl;
private:
void drop_down();
protected: // TTField_control
virtual bool event_handler(XI_OBJ* itf, XI_EVENT* xiev);
public:
void set_values(const char* c, const char* v);
int items() const { return _ddl->items(); }
bool select(int i) { return _ddl->select(i); }
bool select_by_initial(char c) { return _ddl->select_by_initial(c); }
bool select_by_ofs(int i) { return _ddl->select_by_ofs(i); }
int selected() const { return _ddl->selected(); }
TListbox_control(WINDOW win, short cid,
short left, short top, short width,
const char* flags, const char* text,
const char* codes, const char* values);
virtual ~TListbox_control();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -236,7 +236,7 @@ TSpreadsheet::TSpreadsheet(
:
_mask(maskname, maskno), _notify(NULL),
_cur_row(0), _cur_col(1), _cur_rec(0), _edit_field(NULL), _active(TRUE),
_row_dirty(FALSE), _check_enabled(TRUE),
_row_dirty(FALSE), _cell_dirty(FALSE), _check_enabled(TRUE),
_needs_update(-1)
{
const int NUMBER_WIDTH = 3;
@ -828,7 +828,11 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
break;
case XIE_BUTTON:
if (xiev->v.xi_obj->type == XIT_CELL)
dispatch_e_char(parent(), K_F9);
{
const bool ok = (bool)xi_move_focus(xiev->v.xi_obj);
if (ok)
dispatch_e_char(parent(), K_F9);
}
else
if (xiev->v.xi_obj->type == XIT_LIST)
{
@ -1020,7 +1024,6 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
case K_F9:
if (_edit_field != NULL)
{
/* Guy! */
notify_change();
copy_cell2field();
}
@ -1033,7 +1036,7 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
notify_change();
bool ok = TRUE;
if (_edit_field->is_kind_of(CLASS_LIST_FIELD) && k == K_F9) // list
if (k == K_F9 && _edit_field->is_kind_of(CLASS_LIST_FIELD)) // list
{
XI_OBJ cell; XI_MAKE_CELL(&cell, _obj, _cur_row, _cur_col);
// droppa giu'
@ -1098,22 +1101,28 @@ bool TSpreadsheet::event_handler(XI_OBJ* itf, XI_EVENT *xiev)
{
refused = TRUE;
beep();
}
else if (_edit_field->is_kind_of(CLASS_LIST_FIELD))
} else
if (_edit_field->is_kind_of(CLASS_LIST_FIELD))
{
TList_field& lst = ((TList_field&)*_edit_field);
bool changed = FALSE;
switch (k)
{
case K_RIGHT:
lst.select_next();
changed = lst.select_next();
break;
case K_LEFT:
lst.select_prev();
changed = lst.select_prev();
break;
default:
if (k >= ' ' && k <= 'z')
lst.select_by_initial(k);
changed = lst.select_by_initial(k);
break;
}
if (changed)
{
XI_OBJ cell; XI_MAKE_CELL(&cell, _obj, _cur_row, _cur_col);
xi_set_text(&cell, (char*)(const char*)lst.get());
}
refused = TRUE;
}
@ -1805,9 +1814,17 @@ void TSheet_field::select(int r, bool scrollto)
bool TSheet_field::on_key(KEY k)
{
if (k == K_TAB && !focusdirty() && items() > 0)
{
select(0);
if (k == K_TAB)
{
if (focusdirty())
{
TSpreadsheet* s = (TSpreadsheet*)_ctl;
if (!s->off_cell_handler())
return FALSE;
}
else
if (items() > 0)
select(0);
}
if (k == K_ROWEDIT && items() > 0)

View File

@ -1,260 +1,260 @@
#include <defmask.h>
#include <progind.h>
#include <controls.h>
#include <urldefid.h>
const char* const TITLE_TEXT = "Attesa";
word TIndwin::measure_text(TToken_string& s, word& maxlen) const
{
word lines = 0;
for(const char* t = s.get(0); t; t = s.get())
{
const word l = strlen(t);
if (l > maxlen) maxlen = l;
lines++;
}
return lines;
}
// Certified 70%
TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div)
: _text(NULL), _cancel(NULL), _bar(0),
_status(0L), _max(max), _flags(0x0)
{
if (_max <= 0) _max = 1;
TToken_string testo(txt, '\n');
word maxlen = div;
const word lines = measure_text(testo, maxlen);
int ver = lines+2;
int hor = maxlen+2; if (hor > 78) hor = 78;
if (bar)
{
_bar = ver * CHARY;
ver += 2;
}
ver += cancel ? 2 : 0;
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", "");
testo.replace('\n', '\r');
_text->set_caption(testo);
if (cancel)
{
_cancel = new TPushbutton_control(win(), DLG_CANCEL, -11, -1, 10, 2, "", "Annulla", BMP_CANCEL);
}
open_modal();
do_events();
}
// @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) se se ne prevede uno piu' lungo.
{
_text->set_caption(t);
}
TIndwin::~TIndwin()
{
close_modal();
if (_text) delete _text;
if (_cancel) delete _cancel;
}
bool TIndwin::can_be_closed() const
{
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;
}
KEY TIndwin::check_stop()
{
KEY k = 0;
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
stop_run(k);
}
return k;
}
void TIndwin::update_bar()
{
if (_status >= _max)
{
_status = _max;
_flags |= IND_FINISHED;
}
// Percentuale raggiunta finora
const double prc = (double)_status/_max;
WINDOW w = win();
RCT r; xvt_vobj_get_client_rect(w, &r);
// Rettangolo contenente l'intera barra
r.left = CHARX; r.right -= CHARX;
r.top = (int)_bar;
r.bottom = r.top + 2*CHARY;
RCT b = r;
// Rettangolo in rilievo
b.right = b.left + int((r.right-r.left)*prc);
xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
// Rettangolo scavato
b.left = b.right; b.right = r.right;
xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0);
char n[8]; sprintf(n, "%d%%", int(100*prc));
xvt_dwin_draw_text(w, r.left+r.right/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
check_stop();
}
void TIndwin::update()
{
if (_bar) update_bar();
}
bool TIndwin::on_key(KEY k)
{
if (k == K_ESC && _cancel)
{
_flags |= IND_CANCELLED;
check_stop();
}
return TRUE;
}
void TIndwin::on_button(short id)
{
if (id == DLG_CANCEL)
on_key(K_ESC);
}
// TProgind --------------------------------------------------------------
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div)
{}
// TTimerind ------------------------------------------------------------
long TTimerind::_timer_id = 0L;
void TTimerind::handler(WINDOW w, EVENT* e)
{
switch(e->type)
{
case E_CREATE:
case E_UPDATE:
if (_status == 0L)
_timer_id = xvt_timer_create(w, _interval);
break;
case E_TIMER:
if (e->v.timer.id == _timer_id)
{
_status += _interval;
force_update();
xvt_timer_create(w, _interval);
}
break;
default:
break;
}
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)
{
_interval = i;
_timer_id = 0L;
}
TTimerind::~TTimerind()
{ 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, 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);
}
void progind_set_status(long l)
{
((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, 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 <defmask.h>
#include <progind.h>
#include <controls.h>
#include <urldefid.h>
const char* const TITLE_TEXT = "Attesa";
word TIndwin::measure_text(TToken_string& s, word& maxlen) const
{
word lines = 0;
for(const char* t = s.get(0); t; t = s.get())
{
const word l = strlen(t);
if (l > maxlen) maxlen = l;
lines++;
}
return lines;
}
// Certified 70%
TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div)
: _text(NULL), _cancel(NULL), _bar(0),
_status(0L), _max(max), _flags(0x0)
{
if (_max <= 0) _max = 1;
TToken_string testo(txt, '\n');
word maxlen = div;
const word lines = measure_text(testo, maxlen);
int ver = lines+2;
int hor = maxlen+2; if (hor > 78) hor = 78;
if (bar)
{
_bar = ver * CHARY;
ver += 2;
}
ver += cancel ? 2 : 0;
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", "");
testo.replace('\n', '\r');
_text->set_caption(testo);
if (cancel)
{
_cancel = new TPushbutton_control(win(), DLG_CANCEL, -11, -1, 10, 2, "", "Annulla", BMP_CANCEL);
}
open_modal();
do_events();
}
// @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) se se ne prevede uno piu' lungo.
{
_text->set_caption(t);
}
TIndwin::~TIndwin()
{
close_modal();
if (_text) delete _text;
if (_cancel) delete _cancel;
}
bool TIndwin::can_be_closed() const
{
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;
}
KEY TIndwin::check_stop()
{
KEY k = 0;
if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
stop_run(k);
}
return k;
}
void TIndwin::update_bar()
{
if (_status >= _max)
{
_status = _max;
_flags |= IND_FINISHED;
}
// Percentuale raggiunta finora
const double prc = (double)_status/_max;
WINDOW w = win();
RCT r; xvt_vobj_get_client_rect(w, &r);
// Rettangolo contenente l'intera barra
r.left = CHARX; r.right -= CHARX;
r.top = (int)_bar;
r.bottom = r.top + 2*CHARY;
RCT b = r;
// Rettangolo in rilievo
b.right = b.left + int((r.right-r.left)*prc);
xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
// Rettangolo scavato
b.left = b.right; b.right = r.right;
xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0);
char n[8]; sprintf(n, "%d%%", int(100*prc));
xvt_dwin_draw_text(w, r.left+r.right/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
check_stop();
}
void TIndwin::update()
{
if (_bar) update_bar();
}
bool TIndwin::on_key(KEY k)
{
if (k == K_ESC && _cancel)
{
_flags |= IND_CANCELLED;
check_stop();
}
return TRUE;
}
void TIndwin::on_button(short id)
{
if (id == DLG_CANCEL)
on_key(K_ESC);
}
// TProgind --------------------------------------------------------------
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div)
{}
// TTimerind ------------------------------------------------------------
long TTimerind::_timer_id = 0L;
void TTimerind::handler(WINDOW w, EVENT* e)
{
switch(e->type)
{
case E_CREATE:
case E_UPDATE:
if (_status == 0L)
_timer_id = xvt_timer_create(w, _interval);
break;
case E_TIMER:
if (e->v.timer.id == _timer_id)
{
_status += _interval;
force_update();
xvt_timer_create(w, _interval);
}
break;
default:
break;
}
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)
{
_interval = i;
_timer_id = 0L;
}
TTimerind::~TTimerind()
{ 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, 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);
}
void progind_set_status(long l)
{
((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, 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;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff