ba1600.cpp Nessuna differenza

ba1800.*     Corretta gestione importazioni usando i TWindowed_fields


git-svn-id: svn://10.65.10.50/trunk@6207 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-02-17 11:18:46 +00:00
parent e7719da42f
commit f357843c06
2 changed files with 293 additions and 231 deletions

View File

@ -1,13 +1,13 @@
#include <applicat.h>
#include <browfile.h>
#include <extcdecl.h> #include <extcdecl.h>
#include <applicat.h>
#include <colors.h>
#include <filetext.h> #include <filetext.h>
#include <msksheet.h> #include <msksheet.h>
#include <prefix.h> #include <prefix.h>
#include <relation.h> #include <relation.h>
#include <sheet.h> #include <sheet.h>
#include <utility.h> #include <utility.h>
#include <viswin.h>
#include "ba1800.h" #include "ba1800.h"
@ -113,15 +113,14 @@ public:
virtual ~THandled_mask() { } virtual ~THandled_mask() { }
}; };
#define build_msg() char* _msg = (char*)(const char*)_ctl_data._park;va_list argptr;va_start(argptr,fmt);vsprintf(_msg,fmt,argptr);va_end(argptr)
bool THandled_mask::error_box(const char* fmt, ...) bool THandled_mask::error_box(const char* fmt, ...)
{ {
TString message(1024); TString message(1024);
char* msg = message.get_buffer(); char* msg = message.get_buffer();
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(msg, fmt, argptr); int len = vsprintf(msg, fmt, argptr);
CHECKD(len <= message.size(), "Error message too long: ", len);
va_end(argptr); va_end(argptr);
if (is_sheetmask() && !is_running()) if (is_sheetmask() && !is_running())
@ -240,32 +239,64 @@ THandled_mask::THandled_mask(const char* name, int num)
// TColumnizer_win // TColumnizer_win
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
class TColumnizer_win : public TViswin class TColumnizer_field;
{
// Array delle posizioni di inizio campo
TPointer_array _column;
bool _clickable;
protected: // TViswin class TColumnizer_win : public TField_window
{
enum { RULER_HEIGHT = 2, NUM_WIDTH = 4 };
TString_array _rows; // Righe di testo da stampare
TPointer_array _column; // Array delle posizioni di inizio campo
bool _clickable; // E' possibile cliccare
protected: // TScroll_window
virtual void handler(WINDOW win, EVENT* ep); virtual void handler(WINDOW win, EVENT* ep);
virtual void paint_row(long r); virtual void update();
virtual void paint_column(long c, bool end);
protected: // Internal use protected: // Internal use
int on_column(long col); int on_column(long col);
public: public:
void recalc_layout(int dx, int dy);
bool clickable() const { return _clickable; } bool clickable() const { return _clickable; }
void set_clickable(bool on = TRUE) { _clickable = on; } void set_clickable(bool on = TRUE) { _clickable = on; }
void destroy_rows() { _rows.destroy(); }
void add_row(const char* row) { _rows.add(row); }
void destroy_columns() { _column.destroy(); } void destroy_columns() { _column.destroy(); }
long add_column(long col) { return _column.add_long(col); } long add_column(long col) { return _column.add_long(col); }
long get_column(int index) const { return _column.get_long(index); } long get_column(int index) const { return _column.get_long(index); }
TColumnizer_win(int x, int y, int dx, int dy, WINDOW parent, TBrowsefile_field* field); TColumnizer_win(int x, int y, int dx, int dy, WINDOW parent, TColumnizer_field* field);
virtual ~TColumnizer_win() { } virtual ~TColumnizer_win() { }
}; };
class TColumnizer_field : public TWindowed_field
{
protected: // TWindowed_field
virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent)
{ return new TColumnizer_win(x, y, dx, dy, parent, this); }
protected: // Internal use
TColumnizer_win& col_win() const
{ return (TColumnizer_win&)win(); }
public:
void destroy_rows() { col_win().destroy_rows(); }
void add_row(const char* row) { col_win().add_row(row); }
void recalc_layout(int dx, int dy) const { col_win().recalc_layout(dx, dy); }
int visible_rows() const { return col_win().rows() - 1; }
void destroy_columns() { col_win().destroy_columns(); }
void add_column(long col) { col_win().add_column(col); }
long get_column(int index) const { return col_win().get_column(index); }
TColumnizer_field(THandled_mask* m) : TWindowed_field(m) { }
virtual ~TColumnizer_field() { }
};
int TColumnizer_win::on_column(long col) int TColumnizer_win::on_column(long col)
{ {
int index = -1; int index = -1;
@ -287,16 +318,15 @@ int TColumnizer_win::on_column(long col)
} }
} }
TSheet_field& sf = browsefile_field()->mask().sfield(F_FIELDS); TSheet_field& sf = owner().mask().sfield(F_FIELDS);
switch(action) switch(action)
{ {
case 1: case 1:
index = _column.insert_long(col, i+1); index = _column.insert_long(col, i+1);
sf.insert(index, TRUE, FALSE);
break; break;
case 2: case 2:
_column.destroy(i, TRUE); _column.destroy(i, TRUE);
sf.destroy(i+1, TRUE); index = i;
break; break;
default: default:
break; break;
@ -305,121 +335,136 @@ int TColumnizer_win::on_column(long col)
return index; return index;
} }
void TColumnizer_win::update()
{
const int x = int(origin().x);
const int maxx = x + columns() + 1;
const int y = int(origin().y);
const int maxy = y + rows() + 1;
int i;
TString80 str;
TField_window::update();
set_color(NORMAL_COLOR, NORMAL_BACK_COLOR);
for (i = y; i < maxy-RULER_HEIGHT; i++)
{
TToken_string* row = (TToken_string*)_rows.objptr(i);
if (row)
stringat(NUM_WIDTH, i+RULER_HEIGHT, _rows.row(i));
else
break;
}
set_brush(DISABLED_BACK_COLOR);
bar(x, y, maxx, y+RULER_HEIGHT);
TString points(maxx);
points.fill('.');
for (int n = x+1; n < maxx; n++)
{
if ((n % 5) == 0)
{
if ((n & 0x1) == 0)
{
int len = sprintf(str.get_buffer(), "%d", n);
points.overwrite(str, n - len);
}
else
points.overwrite(":", n-1);
}
}
stringat(NUM_WIDTH, y, points);
bar(x, y, x+NUM_WIDTH, maxy);
for (i = y; i < maxy; i++)
{
str.format("%*d", NUM_WIDTH, i+1);
stringat(x, i+RULER_HEIGHT, str);
}
set_pen(COLOR_BLACK);
int last_column = 0;
for (i = 0; i < _column.items(); i++)
{
const int j = (int)_column.get_long(i);
if (j > x)
{
_pixmap = TRUE;
line((j+NUM_WIDTH)*CHARX, (y+1)*CHARY, (j+NUM_WIDTH)*CHARX, maxy*CHARY);
_pixmap = FALSE;
}
const int available = j-last_column;
int len = sprintf(str.get_buffer(), "%d(%d)", i+1, available);
if (len > available)
{
len = str.find('(');
str.cut(len);
}
if (len <= available)
{
int cx = (j+last_column-len) / 2;
if (cx >= x)
stringat(cx+NUM_WIDTH, y+1, str);
}
last_column = j;
}
_pixmap = TRUE;
line((x+NUM_WIDTH)*CHARX, (y+1)*CHARY, maxx*CHARX, (y+1)*CHARY);
line(x*CHARX, (y+RULER_HEIGHT)*CHARY, maxx*CHARX, (y+RULER_HEIGHT)*CHARY);
line((x+NUM_WIDTH)*CHARX, y*CHARY, (x+NUM_WIDTH)*CHARX, maxy*CHARY);
_pixmap = FALSE;
}
void TColumnizer_win::handler(WINDOW win, EVENT* ep) void TColumnizer_win::handler(WINDOW win, EVENT* ep)
{ {
switch(ep->type) switch(ep->type)
{ {
case E_MOUSE_DOWN: case E_MOUSE_DOWN:
xvt_win_trap_pointer (win);
erase_point();
break;
case E_MOUSE_MOVE:
break;
case E_MOUSE_UP:
TViswin::handler(win, ep);
if (_clickable) if (_clickable)
{ {
on_column(get_point().x); long column = (ep->v.mouse.where.h + CHARX/2) / CHARX;
update(); column += origin().x - NUM_WIDTH;
if (on_column(column) >= 0)
force_update();
} }
break; break;
case E_MOUSE_DBL:
break;
default: default:
TViswin::handler(win, ep); TField_window::handler(win, ep);
break; break;
} }
} }
void TColumnizer_win::paint_column(long j, bool end) void TColumnizer_win::recalc_layout(int dx, int dy)
{ {
TViswin::paint_column(j, end); long maxy = _rows.items() - rows()/2 + 1;
if (j > origin().x) long maxx = dx;
{ if (maxx <= 0)
for (int i = _column.items()-1; i >= 0; i--) maxx = _column.get_long(_column.items()-1) + 70;
{ maxx -= columns()/2 + NUM_WIDTH;
if (_column.get_long(i) == j) if (maxx < 0) maxx = 0;
{ if (maxy < 0) maxy = 0;
autoscroll(TRUE); set_scroll_max(maxx, maxy);
_pixmap = TRUE; update_thumb(0, 0);
set_pen(COLOR_BLACK); force_update();
const int x = tabx((int)j+6);
line(x, taby(1), x, taby((int)lines()+1));
_pixmap = FALSE;
break;
}
}
}
} }
void TColumnizer_win::paint_row(long r) TColumnizer_win::TColumnizer_win(int x, int y, int dx, int dy,
{ WINDOW parent, TColumnizer_field* field)
TViswin::paint_row(r); : TField_window(x, y, dx, dy, parent, field),
autoscroll(TRUE);
_pixmap = TRUE;
set_pen(COLOR_BLACK);
for (int i = _column.items()-1; i >= 0; i--)
{
const int j = (int)_column.get_long(i);
if (j > origin().x)
{
const int x = tabx(j+6);
line(x, taby((int)r+1), x, taby((int)r+2));
}
}
_pixmap = FALSE;
}
TColumnizer_win::TColumnizer_win(int x, int y, int dx, int dy, WINDOW parent, TBrowsefile_field* field)
: TViswin("", "", FALSE, FALSE, FALSE, x, y, dy, dx, TRUE, parent, field),
_clickable(field->enabled()) _clickable(field->enabled())
{ {
set_scroll_max(columns(), rows());
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TColumnizer_field // TColumnizer_field
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
class TColumnizer_field : public TBrowsefile_field
{
protected: // TMask_field
virtual void create(WINDOW parent);
protected: // Internal use
TColumnizer_win& col_win() const { return *(TColumnizer_win*)vis_win(); }
public: // TMask_field
virtual void enable(bool on = TRUE);
public:
void destroy_columns() { col_win().destroy_columns(); }
void add_column(long col) { col_win().add_column(col); }
long get_column(int index) const { return col_win().get_column(index); }
TColumnizer_field(THandled_mask* m);
virtual ~TColumnizer_field() { }
};
void TColumnizer_field::enable(bool on)
{
TBrowsefile_field::enable(on);
col_win().set_clickable(on);
}
void TColumnizer_field::create(WINDOW parent)
{
TColumnizer_win* cw = new TColumnizer_win(_ctl_data._x, _ctl_data._y,
_ctl_data._width, _ctl_data._size,
parent, this);
set_vis_win(cw);
TBrowsefile_field::create(parent);
}
TColumnizer_field::TColumnizer_field(THandled_mask* m)
: TBrowsefile_field(m)
{
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TWizard_mask // TWizard_mask
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -529,7 +574,7 @@ bool TFields_mask::field_handler(TOperable_field& of, TField_event fe)
if (rd) if (rd)
{ {
const char* d = rd->get_field_description(n); const char* d = rd->get_field_description(n);
if (*d) if (d && *d)
set(F_DESCR, d); set(F_DESCR, d);
else else
ok = error_box("Il campo %s non esiste", ok = error_box("Il campo %s non esiste",
@ -642,7 +687,9 @@ bool TWizard_mask::file_open(TFilename& fname) const
void TWizard_mask::load_ini(const TString& ininame) void TWizard_mask::load_ini(const TString& ininame)
{ {
const bool was_frozen = _frozen; TWait_cursor hourglass;
if (!_frozen)
{
_frozen = TRUE; _frozen = TRUE;
TConfig ini(ininame, "MAIN"); TConfig ini(ininame, "MAIN");
@ -656,8 +703,8 @@ void TWizard_mask::load_ini(const TString& ininame)
set(F_RECSEP, ini.get("RECORDSEP").left(4), TRUE); set(F_RECSEP, ini.get("RECORDSEP").left(4), TRUE);
set(F_SKIPLINES, ini.get_int("SKIPLINES")); set(F_SKIPLINES, ini.get_int("SKIPLINES"));
const TString& fldsep = ini.get("FIELDSEP"); const TString16 fldsep = ini.get("FIELDSEP").left(1);
set(F_FIELDSEP, fldsep.left(1), TRUE); set(F_FIELDSEP, fldsep, TRUE);
ini.set_paragraph("RECORD"); ini.set_paragraph("RECORD");
@ -679,7 +726,36 @@ void TWizard_mask::load_ini(const TString& ininame)
} }
} }
_frozen = was_frozen; TRelation_description* rd = rel_desc();
TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS);
TFieldref fr;
for (int i = 0; ini.exist("NAME", i) || ini.exist("POSITION", i); i++)
{
const TString& campo = ini.get("FIELD", NULL, i);
TToken_string& row = fs.row(i);
if (campo.not_empty())
{
fr = campo;
row = fr.name();
if (rd == NULL)
{
int isam = fr.file();
if (isam)
{
set(F_ISAM, isam);
rd = rel_desc();
}
}
if (rd)
row.add(rd->get_field_description(fr.name()));
}
}
fs.force_update();
_frozen = FALSE;
}
} }
void TWizard_mask::save_ini(const TFilename& ininame) const void TWizard_mask::save_ini(const TFilename& ininame) const
@ -746,9 +822,9 @@ bool TWizard_mask::is_aga_file(const TFilename& name) const
bool TWizard_mask::load_aga(const TFilename& name) bool TWizard_mask::load_aga(const TFilename& name)
{ {
TWait_cursor hourglass; TWait_cursor hourglass;
const bool was_frozen = _frozen; if (!_frozen)
{
_frozen = TRUE; _frozen = TRUE;
TSheet_field& sf = sfield(F_FIELDS); TSheet_field& sf = sfield(F_FIELDS);
TScanner aga(name); TScanner aga(name);
TToken_string riga(1024); TToken_string riga(1024);
@ -808,18 +884,15 @@ bool TWizard_mask::load_aga(const TFilename& name)
} }
} }
} }
sf.force_update(); _frozen = FALSE;
}
_frozen = was_frozen;
return TRUE; return TRUE;
} }
void TWizard_mask::file_preview() const void TWizard_mask::file_preview() const
{ {
TWait_cursor hourglass; TWait_cursor hourglass;
const TString& fname = get(F_FILE); if (_frozen)
if (_frozen/* || !fexist(fname) */)
return; return;
const int MAXLINE = 8192; const int MAXLINE = 8192;
@ -829,6 +902,7 @@ void TWizard_mask::file_preview() const
const TString& recsep = get(F_RECSEP); const TString& recsep = get(F_RECSEP);
const TString& fieldsep = get(F_FIELDSEP); const TString& fieldsep = get(F_FIELDSEP);
const TString& fname = get(F_FILE);
int flags = ios::in | ios::nocreate; int flags = ios::in | ios::nocreate;
if (fixedlen) if (fixedlen)
flags |= ios::binary; flags |= ios::binary;
@ -850,10 +924,13 @@ void TWizard_mask::file_preview() const
} }
} }
TString_array righe; TColumnizer_field& cf = (TColumnizer_field&)field(F_COLUMNIZER);
int displines = get_int(F_DISPLINES); int displines = get_int(F_DISPLINES);
if (displines <= 0) displines = 4; if (displines <= 0)
displines = cf.visible_rows();
TString_array righe;
for (int l = 0; l < displines; l++) for (int l = 0; l < displines; l++)
{ {
righe.add(new TToken_string(MAXLINE), l); righe.add(new TToken_string(MAXLINE), l);
@ -879,7 +956,6 @@ void TWizard_mask::file_preview() const
break; break;
} }
TColumnizer_field& cf = (TColumnizer_field&)field(F_COLUMNIZER);
if (fieldsep.blank()) if (fieldsep.blank())
{ {
cf.enable(); cf.enable();
@ -936,26 +1012,13 @@ void TWizard_mask::file_preview() const
} }
} }
cf.vis_win()->destroy_lines(); cf.destroy_rows();
for (l = 0; l < righe.items(); l++) for (l = 0; l < righe.items(); l++)
{ {
TToken_string& riga = righe.row(l); TToken_string& riga = righe.row(l);
riga.replace('|', '¦'); // Grossa crisi coi tubi cf.add_row(riga);
riga.replace('@', '#'); // Grossa crisi con le lumache
if (fixedlen)
{
riga.replace('\n', '¦'); // Grossa crisi con l'a capo
if (reclen > 256) // Grossa crisi con le righe lunghe
riga.cut(256);
} }
else cf.recalc_layout(reclen, righe.items());
{
if (riga.len() > 256) // Grossa crisi con le righe lunghe
riga.cut(256);
}
cf.add_line(riga);
}
cf.goto_pos(0, 0);
} }
TRelation_description* TWizard_mask::rel_desc(int logicnum) TRelation_description* TWizard_mask::rel_desc(int logicnum)

View File

@ -47,14 +47,14 @@ BEGIN
PROMPT 45 3 "Separatore di record " PROMPT 45 3 "Separatore di record "
END END
NUMBER F_RECLEN 6 NUMBER F_RECLEN 5
BEGIN BEGIN
PROMPT 45 3 "Lunghezza " PROMPT 45 3 "Lunghezza "
FLAGFS "U" FLAGFS "U"
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
END END
NUMBER F_SKIPLINES 6 NUMBER F_SKIPLINES 4
BEGIN BEGIN
PROMPT 1 4 "Righe iniziali da ignorare " PROMPT 1 4 "Righe iniziali da ignorare "
FLAGS "U" FLAGS "U"
@ -65,7 +65,7 @@ BEGIN
PROMPT 45 4 "Separatore dei campi " PROMPT 45 4 "Separatore dei campi "
END END
NUMBER F_DISPLINES 6 NUMBER F_DISPLINES 4
BEGIN BEGIN
PROMPT 1 5 "Righe da visualizzare " PROMPT 1 5 "Righe da visualizzare "
FLAGS "U" FLAGS "U"
@ -83,15 +83,14 @@ BEGIN
PROMPT 41 6 "Azzera il file di destinazione" PROMPT 41 6 "Azzera il file di destinazione"
END END
BROWSEFILE F_COLUMNIZER 75 4 BROWSEFILE F_COLUMNIZER 75 5
BEGIN BEGIN
PROMPT 1 6 "" PROMPT 1 6 ""
FLAGS "R"
END END
SPREADSHEET F_FIELDS 78 SPREADSHEET F_FIELDS 78
BEGIN BEGIN
PROMPT 1 13 "" PROMPT 1 15 ""
ITEM "Campo@12" ITEM "Campo@12"
ITEM "Descrizione@50" ITEM "Descrizione@50"
END END
@ -108,7 +107,7 @@ BEGIN
FLAGS "BU" FLAGS "BU"
END END
STRING F_DESCR 70 STRING F_DESCR 70 50
BEGIN BEGIN
PROMPT 1 2 "Descrizione " PROMPT 1 2 "Descrizione "
FLAGS "D" FLAGS "D"