Migliorata esportazione in Excel di stampe vecchio stile

git-svn-id: svn://10.65.10.50/branches/R_10_00@22980 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2014-07-30 12:57:55 +00:00
parent f7b3d60860
commit 3de99221c0
13 changed files with 168 additions and 111 deletions

View File

@ -6,6 +6,7 @@
#define ANG_NATGIU "NATGIU" #define ANG_NATGIU "NATGIU"
#define ANG_STATOSOC "STATOSOC" #define ANG_STATOSOC "STATOSOC"
#define ANG_SITSOC "SITSOC" #define ANG_SITSOC "SITSOC"
#define ANG_CAPSOC "CAPSOC"
#endif #endif

View File

@ -1,18 +1,14 @@
#ifndef __APPLICATION_H #ifndef __APPLICATION_H
#define __APPLICATION_H #define __APPLICATION_H
#ifndef INCL_XVTH #ifndef __DICTION_H
#include <xvt.h> #include <diction.h>
#endif #endif
#ifndef __ASSOC_H #ifndef __ASSOC_H
#include <assoc.h> #include <assoc.h>
#endif #endif
#ifndef __DICTION_H
#include <diction.h>
#endif
#define MSG_AI "AI" // message auto_insert (relapp) #define MSG_AI "AI" // message auto_insert (relapp)
#define MSG_FS "FS" // message filtered start (relapp) #define MSG_FS "FS" // message filtered start (relapp)
#define MSG_LN "LN" // message link (printapp -> relapp) #define MSG_LN "LN" // message link (printapp -> relapp)

View File

@ -94,6 +94,8 @@
#define DOC_CIG "CIG" #define DOC_CIG "CIG"
#define DOC_CONTSEP "CONTSEP" #define DOC_CONTSEP "CONTSEP"
#define DOC_NOLEGGIO "NOLEGGIO" #define DOC_NOLEGGIO "NOLEGGIO"
#define DOC_MODPAG "MODPAG"
#define DOC_CONTRATTO "CONTRATTO"
#define DOC_PAF "PAF" #define DOC_PAF "PAF"
// Virtuali // Virtuali

View File

@ -1,3 +1,6 @@
// Disble annoying vsprintf warnings
#define _CRT_SECURE_NO_WARNINGS
#include <about.h> #include <about.h>
#include <automask.h> #include <automask.h>
#include <colors.h> #include <colors.h>
@ -31,6 +34,7 @@ HIDDEN void smart_trim(
) )
{ {
/*
switch (mode) switch (mode)
{ {
case 1: s.ltrim(); break; case 1: s.ltrim(); break;
@ -38,6 +42,9 @@ HIDDEN void smart_trim(
case 3: s.trim(); break; case 3: s.trim(); break;
default: break; default: break;
} }
*/
if (mode & 2) s.rtrim();
if (mode & 1) s.ltrim();
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -56,7 +63,7 @@ TMask_field::TField_Flags::TField_Flags()
roman = read_only = false; roman = read_only = false;
firm = ghost = false; firm = ghost = false;
password = false; password = false;
trim = 3; trim = 0x3;
pipeallowed = false; pipeallowed = false;
user = false; user = false;
} }
@ -407,7 +414,8 @@ void TMask_field::construct(TScanner& scanner, WINDOW parent)
long mod = _modules->last_one(); long mod = _modules->last_one();
for (; mod > BAAUT; mod--) for (; mod > BAAUT; mod--)
{ {
if (in_module(mod) && main_app().has_module(mod)) const word m = (word)mod;
if (in_module(m) && main_app().has_module(m))
break; break;
} }
if (mod <= 0) if (mod <= 0)
@ -3090,8 +3098,31 @@ void TReal_field::create(WINDOW w)
TMask_field::set(prefix().get_codditta()); TMask_field::set(prefix().get_codditta());
} }
else else
if (automagic()) if (automagic() && size() == 4 && decimals() == 0)
TMask_field::set(TDate(TODAY).year()); {
const TDate oggi(TODAY);
int anno = oggi.year(); // Anno solare o ...
if (has_query_button() && browse() != NULL && browse()->cursor() != NULL)
{
TCursor& cur = *browse()->cursor();
const TRectype& esc = cur.curr();
if (esc.num() == LF_TAB) // ... codice esercizio?
{
const TRecnotype ne = cur.items();
for (cur = ne-1; cur.ok(); --cur)
{
const TDate dataini = esc.get("D0");
const TDate datafin = esc.get("D1");
if (oggi >= dataini && oggi <= datafin)
{
anno = esc.get_int("CODTAB");
break;
}
}
}
}
TMask_field::set(anno);
}
} }
bool TReal_field::parse_item(TScanner& scanner) bool TReal_field::parse_item(TScanner& scanner)
@ -3642,8 +3673,7 @@ void TList_field::add_list()
} }
for (int i = 1; i <= 12; i++) for (int i = 1; i <= 12; i++)
{ {
char num[4]; sprintf(num, "%02d", i); _codes.add(format("%02d", i));
_codes.add(num);
_values.add(itom(i)); _values.add(itom(i));
} }

View File

@ -2332,7 +2332,7 @@ bool TPrinter::is_landscape() const
class TTab_info : public TObject class TTab_info : public TObject
{ {
int _start, _end; int _start, _end, _col;
public: public:
int intersection(int s, int e) const; int intersection(int s, int e) const;
@ -2340,11 +2340,14 @@ public:
void set_start(int s) { _start = s; } void set_start(int s) { _start = s; }
void set_end(int e) { _end = e; } void set_end(int e) { _end = e; }
void set(int s, int e) { _start = s; _end = e; } void set_column(int c) { _col = c; }
void set(int s, int e) { _start = s; _end = e; _col = -1; }
int start() const { return _start; } int start() const { return _start; }
int end() const { return _end; } int end() const { return _end; }
int width() const { return _end - _start + 1; } int width() const { return _end - _start + 1; }
int column() const { return _col; }
bool operator==(const TTab_info& ti) const { return _start == ti.start() && _end == ti.end(); } bool operator==(const TTab_info& ti) const { return _start == ti.start() && _end == ti.end(); }
bool operator!=(const TTab_info& ti) const { return _start != ti.start() || _end != ti.end(); }
TTab_info(int s, int e) { set(s, e); } TTab_info(int s, int e) { set(s, e); }
}; };
@ -2378,82 +2381,52 @@ void TTabulator::split(int s0, int e0, int s1, int e1)
return; return;
} }
add(min(s0,s1), max(e0,e1)); add(min(s0,s1), max(e0,e1));
/*
int a[4] = { s0, e0, s1, e1 };
int i, j;
for (i = 0; i < 3; i++)
{
for (j = i+1; j < 4; j++)
{
if (a[i] > a[j])
{ const int tmp = a[i]; a[i] = a[j]; a[j] = tmp; }
}
}
int t = 3;
for (i = 0; i < t; i++)
{
j = i+1;
if (abs(a[i]-a[j]) <= 1)
{
if (i < 2)
a[i] = a[j] = min(a[i],a[j]);
else
a[i] = a[j] = max(a[i],a[j]);
t--;
for (j = i+1; j <= t; j++)
a[j] = a[j+1];
}
}
if (t > 0)
{
a[t-1]++;
for (i = 0; i < t; i++)
add(a[i], a[i+1]-1);
}
*/
} }
int TTabulator::find_column(int column, int width) const bool TTabulator::find_column(int column, int width, int &idx, int& col) const
{ {
int start = column; int start = column;
int end = column + width - 1; int end = column + width - 1;
int inter = 0;
int index = -1, inter = 0; idx = col = -1;
FOR_EACH_ARRAY_ITEM(_tab, t, obj) FOR_EACH_ARRAY_ITEM(_tab, t, obj)
{ {
TTab_info& ti = *(TTab_info*)obj; const TTab_info& ti = *(TTab_info*)obj;
const int i = ti.intersection(start, end); const int i = ti.intersection(start, end);
if (i > inter) if (i > inter)
{ {
inter = i; inter = i;
index = t; idx = t;
col = ti.column();
} }
} }
return index; return idx >= 0;
} }
static int tab_compare(const TObject** o0, const TObject** o1) static int tab_compare(const TObject** o0, const TObject** o1)
{ {
const TTab_info& t0 = *(TTab_info*)*o0; const TTab_info& t0 = *(TTab_info*)*o0;
const TTab_info& t1 = *(TTab_info*)*o1; const TTab_info& t1 = *(TTab_info*)*o1;
return t0.start() - t1.start(); int d = t0.start() - t1.start();
if (d == 0)
d = t0.end() - t1.end();
return d;
} }
void TTabulator::add_field(int column, int width) void TTabulator::add_field(int column, int width)
{ {
int start = column; int start = column;
int end = column + width - 1; int end = column + width - 1;
int index = find_column(column, width); int idx, col;
if (index >= 0) if (find_column(column, width, idx, col))
{ {
const TTab_info& ti = (const TTab_info&)_tab[index]; const TTab_info& ti = (const TTab_info&)_tab[idx];
if (ti.intersection(start, end) < width) if (ti.intersection(start, end) < width)
{ {
split(start, end, ti.start(), ti.end()); split(start, end, ti.start(), ti.end());
_tab.destroy(index, true); _tab.destroy(idx, true);
} }
} }
else else
@ -2484,19 +2457,36 @@ void TTabulator::sort()
_tab.destroy(i); _tab.destroy(i);
else else
{ {
if (t1.start() - t0.end() >= 8) const int gap = t1.start() - t0.end();
if (gap > 0)
{ {
_tab.insert(new TTab_info(t0.end()+1, t1.start()-1), i); if (gap >= 8)
} {
else _tab.insert(new TTab_info(t0.end()+1, t1.start()-1), i);
{ }
const int center = (t0.end() + t1.start())/2; else
t0.set_end(center); {
t1.set_start(center+1); const int center = (t0.end() + t1.start())/2;
t0.set_end(center);
t1.set_start(center+1);
}
} }
} }
} }
} }
int col = 0;
for (int i = 0; i < _tab.items(); i++)
{
TTab_info& ti = (TTab_info&)_tab[i];
if (i > 0)
{
const TTab_info& tj = (const TTab_info&)_tab[i-1];
if (ti.start() > tj.start())
col++;
}
ti.set_column(col);
}
} }

View File

@ -782,7 +782,7 @@ protected:
public: public:
void add_field(int column, int width); void add_field(int column, int width);
void sort(); void sort();
int find_column(int column, int width) const; bool find_column(int column, int width, int &idx, int& col) const;
bool empty() const; bool empty() const;
}; };

View File

@ -327,7 +327,7 @@ TTimerind::~TTimerind()
bool TProgress_monitor::set_status(long n) bool TProgress_monitor::set_status(long n)
{ {
// Aggiunsto timer iniziale se necessario // Aggiunsto timer iniziale se necessario
if (_status <= 0 && n <= 0) if (_status <= 0L && n <= 0L)
_start = clock(); _start = clock();
// Se sono passati 1 secondi e sono a meno di metà lavoro allora crea la TProgind // Se sono passati 1 secondi e sono a meno di metà lavoro allora crea la TProgind
@ -349,6 +349,17 @@ void TProgress_monitor::set_text(const char* msg)
_pi->set_text(_txt); _pi->set_text(_txt);
} }
void TProgress_monitor::set_max(long tot)
{
if (tot != _total)
{
_total = tot;
if (_pi != NULL)
_pi->setmax(tot);
set_status(_status = 0L); // Forza aggiornamento timer e barra
}
}
TProgress_monitor::TProgress_monitor(long items, const char* txt, bool cancancel) TProgress_monitor::TProgress_monitor(long items, const char* txt, bool cancancel)
: _total(items), _txt(txt), _status(0), _cancellable(cancancel), _pi(NULL), _start(clock()) : _total(items), _txt(txt), _status(0), _cancellable(cancancel), _pi(NULL), _start(clock())
{ {

View File

@ -173,6 +173,7 @@ class TProgress_monitor : public TObject
public: public:
virtual bool set_status(long n); virtual bool set_status(long n);
void set_max(long tot);
bool add_status(long i = 1) { return set_status(_status+i); } bool add_status(long i = 1) { return set_status(_status+i); }
void set_text(const char* msg); void set_text(const char* msg);

View File

@ -1282,22 +1282,21 @@ const char *real::ita2eng (const char *s)
__string = tmp.get_buffer(strlen(s)); __string = tmp.get_buffer(strlen(s));
int j = 0; int j = 0;
if (s) for (int i = 0; s[i]; i++)
for (int i = 0; s[i]; i++) {
switch (s[i])
{ {
switch (s[i]) case ' ':
{ case '.':
case ' ': break;
case '.': case ',':
break; __string[j++] = '.';
case ',': break;
__string[j++] = '.'; default:
break; __string[j++] = s[i];
default: break;
__string[j++] = s[i];
break;
}
} }
}
__string[j] = '\0'; __string[j] = '\0';
} }
return __string; return __string;
@ -1310,9 +1309,9 @@ bool real::is_null(const char *s)
{ {
for (const char* n = s; *n; n++) for (const char* n = s; *n; n++)
{ {
if (strchr("123456789", *n) != NULL) if (*n >= '1' && *n <= '9')
{ {
z = FALSE; z = false;
break; break;
} }
if (strchr(" ,-.0", *n) == NULL) if (strchr(" ,-.0", *n) == NULL)
@ -1331,7 +1330,7 @@ bool real::is_natural (const char *s)
s++; // Remove leading spaces before s++; // Remove leading spaces before
if (*s) if (*s)
{ {
while (isdigit(*s)) while (*s >= '0' && *s <= '9') // isdigit may fail on non ASCII characters
s++; s++;
ok = *s == '\0'; ok = *s == '\0';
} }

View File

@ -400,7 +400,7 @@ bool TRelation_application::autonum(
k = get_next_key(); k = get_next_key();
#ifdef DBG #ifdef DBG
if (k.full()) if (k.full())
NFCHECK("'const char* get_next_key()' is deprecated: implement 'bool get_next_key(TToken_string&)'"); xvt_dm_popup_warning("'const char* get_next_key()' is deprecated: implement 'bool get_next_key(TToken_string&)'");
#endif #endif
} }

View File

@ -1827,8 +1827,8 @@ bool TBook::export_excel(TFilename& fname, bool signature)
break; break;
if (do_export && str.full()) if (do_export && str.full())
{ {
const int pos = tab.find_column(col, wid); int idx, pos;
if (pos >= 0) if (tab.find_column(col, wid, idx, pos))
{ {
TToken_string* line = (TToken_string*)page.objptr(row); TToken_string* line = (TToken_string*)page.objptr(row);
if (line == NULL) if (line == NULL)

View File

@ -838,13 +838,16 @@ void TTextfile::write(
static int str_type(TString& str) static int str_type(TString& str)
{ {
str.trim(); str.trim();
if (str.empty())
return 0;
bool is_string = false; bool is_string = false;
bool is_number = str.full(); bool is_number = true;
for (int i=0; str[i]; i++) for (int i=0; str[i]; i++)
{ {
if (isalnum(str[i])) const char c = str[i];
if (c < '\0' || isalnum(c))
is_string = true; is_string = true;
if (strchr("0123456789,.", str[i]) == NULL) if (strchr("0123456789,.", c) == NULL)
is_number = false; is_number = false;
} }
if (is_number) if (is_number)
@ -859,29 +862,48 @@ static int str_type(TString& str)
bool TTextfile::write_xls(const TFilename& xls) bool TTextfile::write_xls(const TFilename& xls)
{ {
const int headerlen = printer().headersize(); int headerlen = printer().headersize();
const int footerlen = printer().footersize(); const int footerlen = printer().footersize();
const int pagelen = printer().formlen(); const int pagelen = printer().formlen();
TString str; TString str;
TTabulator tab; int tabstart = 1;
for (long j = headerlen; j < _lines && j < pagelen; j++) int tabstop = pagelen - footerlen;
if (_lines < tabstop) tabstop = _lines;
if (headerlen <= 0) // Cerca di capire l'inizio della testata
{ {
const int row = j % pagelen; for (long j = 1; j < 12 && j < tabstop; j++)
if (row >= headerlen && row < pagelen-footerlen)
{ {
read_line(j); read_line(j);
int x = 0; str = piece(); str.trim();
for (const char* cp = piece(); cp; cp = piece()) if (str.len() >= 64 && (str.starts_with("________") || str.starts_with("--------") || str.starts_with("========")))
{ {
str = cp; if (tabstart <= 1)
const int len = str.len(); tabstart = j+1;
if (str.full() && str_type(str) > 0) else
tab.add_field(x, len); {
x += len; tabstop = j;
headerlen = j;
}
} }
} }
} }
TTabulator tab;
for (long j = tabstart; j < tabstop; j++)
{
read_line(j);
int x = 0;
for (const char* cp = piece(); cp; cp = piece())
{
str = cp;
const int len = str.len();
if (str_type(str) > 0)
tab.add_field(x, len);
x += len;
}
}
tab.sort(); tab.sort();
TToken_string riga(256, '\t'); TToken_string riga(256, '\t');
@ -904,9 +926,14 @@ bool TTextfile::write_xls(const TFilename& xls)
const int st = str_type(str); const int st = str_type(str);
if (st > 0) if (st > 0)
{ {
const int pos = tab.find_column(x, len); int idx, pos;
if (pos >= 0) if (tab.find_column(x, len, idx, pos))
{
const char* old = riga.get(pos);
if (old && *old)
str.insert(old);
riga.add(str, pos); riga.add(str, pos);
}
} }
x += len; x += len;
} }

View File

@ -561,9 +561,9 @@ long daytime()
} }
// DON'T cache this bool because hostname can be local or server // DON'T cache this bool because hostname can be local or server
static bool is_aga_station(const char* hostname) static bool is_sirio_station(const char* hostname)
{ {
const char* const ranger[] = { "BATMOBILE", "KIRK", "KLINGON", "MOBILE", "PCTRUFFELLI", "SPOCK", NULL }; const char* const ranger[] = { "NBKCORRADIW81", "KIRK", "KLINGON", "MOBILE", "PCTRUFFELLI", "SPOCK", NULL };
for (int i = 0; ranger[i]; i++) for (int i = 0; ranger[i]; i++)
if (xvt_str_compare_ignoring_case(hostname, ranger[i]) == 0) if (xvt_str_compare_ignoring_case(hostname, ranger[i]) == 0)
return true; return true;
@ -577,8 +577,8 @@ bool is_power_station()
{ {
const TDongle& d = dongle(); const TDongle& d = dongle();
if ((d.local() && (d.number() == 0 || d.number()==1045)) || if ((d.local() && (d.number() == 0 || d.number()==1045)) ||
(d.network() && is_aga_station(d.server_name()))) (d.network() && is_sirio_station(d.server_name())))
ps = is_aga_station(get_hostname()); ps = is_sirio_station(get_hostname());
else else
ps = FALSE; ps = FALSE;
} }