Corretta gestione listbox nelle celle e bottoni della toolbar

git-svn-id: svn://10.65.10.50/trunk@2947 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-05-31 15:07:00 +00:00
parent d1745dd3cd
commit 1d80e8a48c
8 changed files with 4095 additions and 4049 deletions

View File

@ -1009,9 +1009,10 @@ void TButton_control::create(WINDOW win, short cid,
rct.right++;
}
const unsigned long attrib = flags2attr(flags);
if (wc == WC_CHECKBOX)
rct.right += XI_FU_MULTIPLE / 2;
const unsigned long attrib = flags2attr(flags);
XI_OBJ_DEF* def = xi_add_button_def(NULL, cid, &rct, attrib, (char*)t, cid);
CHECKD(def, "Can't create the interface of TButton_control ", cid);
def->v.btn->fore_color = color;
@ -1510,7 +1511,7 @@ void TDropDownList::close()
}
}
void TDropDownList::select(int i, bool force)
bool TDropDownList::select(int i, bool force)
{
if (force || i != _selected)
{
@ -1537,10 +1538,14 @@ void TDropDownList::select(int i, bool force)
XI_OBJ cell; XI_MAKE_CELL(&cell, _xi_lst, r, 0);
xi_set_focus(&cell);
}
}
return TRUE;
}
return FALSE;
}
void TDropDownList::select_by_initial(char c)
bool TDropDownList::select_by_initial(char c)
{
int next = _selected < _values.items() - 1 ? _selected + 1 : 0;
int first = -1;
@ -1550,22 +1555,24 @@ void TDropDownList::select_by_initial(char c)
first = i;
break;
}
if (first == -1) return;
if (first == -1)
return FALSE;
for (i = next; i < _values.items(); i++)
if (toupper(*(_values.get(i))) == toupper(c))
{
select(i);
break;
}
if (i == _values.items() && first > -1)
select(first);
if (i == _values.items() && first >= 0)
i = first;
return select(i);
}
void TDropDownList::select_by_ofs(int i)
bool TDropDownList::select_by_ofs(int i)
{
i += _selected;
if (i >= 0 && i < _values.items())
select(i);
return select(i);
return FALSE;
}
TDropDownList::TDropDownList(XI_OBJ* o, const char* codes, const char* values, int width)

View File

@ -1,329 +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 select_by_initial(char c);
void select_by_ofs(int n);
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 select(int i, bool force = FALSE);
void set_values(const char* c, const char* v);
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(); }
void select(int i) { _ddl->select(i); }
void select_by_initial(char c) { _ddl->select_by_initial(c); }
void select_by_ofs(int i) { _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

View File

@ -1080,9 +1080,18 @@ bool TButton_field::on_key(KEY key)
bool ok = TRUE;
if (key == K_SPACE)
{
ok = on_hit();
if (ok && _exit_key > 0 && message(0) == NULL)
mask().stop_run(_exit_key);
if (dlg() != DLG_CANCEL && dlg() != DLG_QUIT)
{
const TMask& m = mask();
if (parent() == m.toolwin())
ok = m.focus_field().on_key(K_TAB);
}
if (ok)
{
ok = on_hit();
if (ok && _exit_key > 0 && !has_message())
mask().stop_run(_exit_key);
}
}
else
ok = TOperable_field::on_key(key);
@ -1719,7 +1728,8 @@ void TBrowse::parse_input(TScanner& scanner)
}
}
else // Field on the mask
{
{
CHECKS(_inp_id.get_pos(s) < 0, "Duplicate input field ", s);
_inp_id.add(s);
if (scanner.popkey() == "SE") _inp_id << '@'; // Special FILTERing field
else scanner.push();
@ -1862,6 +1872,12 @@ const char* TBrowse::get_input_fields() const
return _inp_id;
}
const char* TBrowse::get_input_field_names() const
{
return _inp_fn;
}
const char* TBrowse::get_output_fields() const
{
return _out_id;
@ -3564,16 +3580,20 @@ const char* TList_field::raw2win(const char* data) const
return value.get(pos);
}
void TList_field::select_by_ofs(int n)
bool TList_field::select_by_ofs(int n)
{
((TListbox_control*)_ctl)->select_by_ofs(n);
_str = _codes.get(current());
const bool changed = ((TListbox_control*)_ctl)->select_by_ofs(n);
if (changed)
_str = _codes.get(current());
return changed;
}
void TList_field::select_by_initial(char c)
bool TList_field::select_by_initial(char c)
{
((TListbox_control*)_ctl)->select_by_initial(c);
_str = _codes.get(current());
const bool changed = ((TListbox_control*)_ctl)->select_by_initial(c);
if (changed)
_str = _codes.get(current());
return changed;
}
// @doc EXTERNAL
@ -3588,7 +3608,6 @@ void TList_field::replace_items(
{
_codes = codes;
_values = values;
if (_ctl)
add_list();
}
@ -3633,8 +3652,8 @@ int TList_field::str2curr(const char* data)
if (i < 0)
{
if (items() && str.not_empty())
yesnofatal_box("'%s' non e' un valore valido per il campo %s: %d",
data, prompt(), dlg());
NFCHECK("'%s' non e' un valore valido per il campo %s: %d",
data, prompt(), dlg());
i = 0;
}
return i;
@ -3656,7 +3675,7 @@ void TList_field::set(const char* data)
void TList_field::set_window_data(const char* data)
{
CHECK(0,"So' passato da 'sta stronza!!!");
NFCHECK(0,"So' passato da 'sta stronza!!!");
const int i = str2curr(win2raw(data));
current(i);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,276 +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;
}
const double prc = (double)_status/_max;
RCT r; xvt_vobj_get_client_rect(win(), &r);
r.left = CHARX; r.right -= CHARX;
r.top = (int)_bar;
r.bottom = r.top + 2*CHARY;
RCT b = r;
/*
set_pen(COLOR_BLACK);
const int width = r.right - r.left;
set_brush(COLOR_BLUE);
b.right = b.left + int(width*prc);
xvt_dwin_draw_rect(win(), &b);
set_brush(COLOR_WHITE);
b.left = b.right; b.right = r.right;
xvt_dwin_draw_rect(win(), &b);
set_mode(M_XOR);
xvt_dwin_set_fore_color(win(), COLOR_BLUE);
char n[8]; sprintf(n, "%d%%", int(100*prc));
xvt_dwin_draw_text(win(), r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
set_mode(M_COPY);
*/
WINDOW w = win();
b.right = b.left + int(r.right*prc);
xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
set_brush(COLOR_WHITE);
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;
}

View File

@ -1049,21 +1049,43 @@ TBrowse_sheet::TBrowse_sheet(TCursor* cursor, const char* fields,
}
if (n > 0)
add_tag_button(0, ca, _sel);
TToken_string tids = head;
TToken_string tfns = fields;
TToken_string ids = f->browse()->get_input_fields();
TToken_string fns = f->browse()->get_input_field_names();
short y = 0;
ca = f->browse()->get_input_fields();
for (const char* i = ca.get(0); i; i = ca.get())
for (const char* i = ids.get(0); i; i = ids.get())
{
if (*i != '"' && strchr(i, '@') == NULL)
{
const TMask_field& c = f->mask().field(f->atodlg(i));
if (c.is_editable() && c.active())
{
int pos = ids.get_pos(c.dlg());
CHECK(pos >= 0, "Invalid input field");
TString80 p = fns.get(pos);
pos = tfns.get_pos(p);
if (pos >= 0)
{
p = tids.get(pos);
pos = p.find('@');
if (pos >= 0)
p.cut(pos);
}
else
p.cut(0);
if (p.empty())
{
p = c.prompt();
// Toglie spazi e simboli iniziali dal prompt
for (int a = 0; p[a] && !isalnum(p[a]); a++);
p.ltrim(a);
}
p.left_just(16);
TEditable_field* e = NULL;
TString80 p = c.prompt();
// Toglie spazi e simboli iniziali dal prompt
for (int a = 0; p[a] && !isalnum(p[a]); a++);
p.ltrim(a); p.left_just(16);
switch (c.class_id())
{
case CLASS_EDIT_FIELD:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff