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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,260 +1,260 @@
#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;
} }
// Percentuale raggiunta finora // Percentuale raggiunta finora
const double prc = (double)_status/_max; const double prc = (double)_status/_max;
WINDOW w = win(); WINDOW w = win();
RCT r; xvt_vobj_get_client_rect(w, &r); RCT r; xvt_vobj_get_client_rect(w, &r);
// Rettangolo contenente l'intera barra // Rettangolo contenente l'intera barra
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;
RCT b = r; RCT b = r;
// Rettangolo in rilievo // Rettangolo in rilievo
b.right = b.left + int((r.right-r.left)*prc); b.right = b.left + int((r.right-r.left)*prc);
xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0); xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
// Rettangolo scavato // Rettangolo scavato
b.left = b.right; b.right = r.right; b.left = b.right; b.right = r.right;
xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0); xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0);
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+r.right/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1); xvt_dwin_draw_text(w, r.left+r.right/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;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff