campo-sirio/sc/sc3100.cpp
angelo ae1ab9ecfd Cambiato il settaggio della fincatura di sfondo in print().
git-svn-id: svn://10.65.10.50/trunk@2417 c028cbd2-c16b-5b4b-a496-9718f37d4682
1996-01-09 18:09:29 +00:00

719 lines
22 KiB
C++
Executable File

#ifndef __PRINTER_H
#include <printer.h>
#endif
#ifndef __PROGIND_H
#include <progind.h>
#endif
#include "../ba/baformed.h"
#include "sc3.h"
#include "sc3100a.h"
#include "sc3100b.h"
#include "sc3100c.h"
#include "sc21pec.h"
/////////////////////////////////////////////////////////////////
// serve per ricalcolare le posizioni //
/////////////////////////////////////////////////////////////////
typedef struct {
char name_1[80]; // Fontname old
char name_2[80]; // Fontname new
int size_1; // size (height) of old font
int size_2; // size (height) of new font
double ratio; // ratio (width_old_font/width_new_font)
} s_data;
class TForm_EC_editor : public TForm_editor
{
s_data _prm;
TMask * _msk; // maschera di selezione sezione
protected:
static bool cpy_handler(TMask_field& f, KEY k);
static bool font_handler(TMask_field& f, KEY k);
static bool code_handler(TMask_field& f, KEY k);
static bool lng_handler(TMask_field& f, KEY k);
static bool ccodes_handler(TMask_field& f, KEY k);
static bool clngs_handler(TMask_field& f, KEY k);
void load_fonts();
void change_pos(char sc, pagetype pt);
bool recalculate_positions(const char* name, int size);
void hook_footer_to_body(TPrint_section* f, TPrint_section* b);
void unhook_footer(TPrint_section* f);
void hide_body_items(TPrint_section* b);
void show_body_items(TPrint_section* b);
void remove_form(TLocalisamfile& frm, TLocalisamfile& rfr,const TString& t,const TString& c);
virtual const char* selection_mask() const { return "sc3100a"; }
virtual bool ask_profile();
virtual bool edit(char s, pagetype p);
virtual void print();
public:
TForm_EC_editor() {_msk = NULL;}
virtual ~TForm_EC_editor() {}
};
inline TForm_EC_editor& app() { return (TForm_EC_editor&) main_app();}
BOOLEAN XVT_CALLCONV1 wprms (long data)
{
s_data* st =(s_data*)data;
WINDOW prwin = xvt_print_create_win(printer().get_printrcd(),"");
long width_old,width_new;
TString spc(100);
spc.fill('m');
xvt_set_font(prwin,st->name_1, XVT_FS_NONE, st->size_1);
width_old = xvt_dwin_get_text_width(prwin,(char*)(const char*)spc, 100);
xvt_set_font(prwin,st->name_2, XVT_FS_NONE, st->size_2);
width_new = xvt_dwin_get_text_width(prwin,(char*)(const char*)spc, 100);
st->ratio = (double)width_old / (double)width_new;
xvt_vobj_destroy(prwin);
return FALSE;
}
bool TForm_EC_editor::ccodes_handler(TMask_field& f, KEY k)
{
TMask& m = f.mask();
if (f.dirty() && m.get(F_CBASE).empty())
m.set(F_CBASE,BASE_EC_PROFILE);
if (k==K_TAB)
{
TString base(m.get(F_CBASE));
TString code(f.get());
code << m.get(F_CCODELS);
TLocalisamfile frm(LF_FORM);
frm.zero();
frm.put("TIPOPROF",base);
frm.put("CODPROF",code);
if (frm.read(_isequal)== NOERR)
m.set(F_CDESCS,frm.get("DESC"));
else
m.reset(F_CDESCS);
}
return TRUE;
}
bool TForm_EC_editor::clngs_handler(TMask_field& f, KEY key)
{
if (key==K_TAB)
{
TMask& m = f.mask();
TString base(m.get(F_CBASE));
TString code(m.get(F_CCODES));
code << f.get();
TLocalisamfile frm(LF_FORM);
frm.zero();
frm.put("TIPOPROF",base);
frm.put("CODPROF",code);
if (frm.read(_isequal)== NOERR)
m.set(F_CDESCS,frm.get("DESC"));
else
m.reset(F_CDESCS);
}
return TRUE;
}
bool TForm_EC_editor::cpy_handler(TMask_field& f, KEY k)
{
if (k==K_SPACE)
{
TLocalisamfile frm(LF_FORM),rfr(LF_RFORM);
TMask mm("sc3100b");
mm.set_handler(F_CCODES,ccodes_handler);
mm.set_handler(F_CCODELS,clngs_handler);
while (mm.run() == K_ENTER) // Prende in input il nome del profilo sorgente
{
long scode = mm.get_long(F_CCODES);
long dcode = mm.get_long(F_CCODED);
char slng = mm.get(F_CCODELS)[0];
char dlng = mm.get(F_CCODELD)[0];
TString form = mm.get(F_CBASE);
TString scod,dcod;
scod.format("%04ld%c",scode,slng); // Codice profilo sorgente
if (scode == 0) scod = "";
dcod.format("%04ld%c",dcode,dlng); // Codice profilo destinazione
frm.zero();
frm.put("TIPOPROF",form);frm.put("CODPROF",dcod);
if (frm.read()==NOERR)
{
error_box("Il profilo specificato come destinazione e' gia' esistente.");
continue;
}
//Effettua la copia dei record.
frm.zero(); frm.put("TIPOPROF",form); // Questo vale per tutti
frm.put("CODPROF",scod); //Profilo sorgente...
if (frm.read()==NOERR)
{
TLocalisamfile rfr_to_write(LF_RFORM);
frm.put("CODPROF",dcod); //Cambia il codice del profilo con quello di destinazione e lo scrive
frm.put("DESC",mm.get(F_CDESCD)); // Mette la descrizione
if (frm.write() != NOERR)
frm.rewrite();
if (frm.status() != NOERR)
{
error_box("Errore %d in scrittura testata profilo.",frm.status());
break;
}
TProgind pi(50,"Copia in corso...",FALSE,FALSE,10);
rfr.zero();rfr.put("TIPOPROF",form);
rfr.put("CODPROF",scod); //Profilo sorgente
rfr.read(_isgteq);
while ( rfr.get("CODPROF") == scod && rfr_to_write.good() && !rfr.eof())
{
rfr_to_write.curr() = rfr.curr();
rfr_to_write.put("CODPROF",dcod); // cambia il codice del profilo con quello di destinazione
if (rfr_to_write.write() != NOERR)
rfr_to_write.rewrite();
rfr.read(_isgreat);
}
pi.cancel();
if (rfr_to_write.status() != NOERR)
{
error_box("Errore %d in scrittura righe profilo.",rfr_to_write.status());
break ;
}
} else
error_box("Non esiste il profilo sorgente specificato.");
}
}
return TRUE;
}
bool TForm_EC_editor::code_handler(TMask_field& f, KEY key)
{
TMask& m = f.mask();
if (f.dirty() && m.get(F_BASE).empty())
m.set(F_BASE,BASE_EC_PROFILE);
if (key==K_TAB)
{
TString base(m.get(F_BASE));
TString code(f.get());
code << m.get(F_CODEL);
TLocalisamfile frm(LF_FORM);
frm.zero();
frm.put("TIPOPROF",base);
frm.put("CODPROF",code);
if (frm.read(_isequal)== NOERR)
m.set(F_DESC,frm.get("DESC"));
else
m.reset(F_DESC);
}
return TRUE;
}
bool TForm_EC_editor::lng_handler(TMask_field& f, KEY key)
{
if (key==K_TAB)
{
TMask& m = f.mask();
TString base(m.get(F_BASE));
TString code(m.get(F_CODE));
code << f.get();
TLocalisamfile frm(LF_FORM);
frm.zero();
frm.put("TIPOPROF",base);
frm.put("CODPROF",code);
if (frm.read(_isequal)== NOERR)
m.set(F_DESC,frm.get("DESC"));
else
m.reset(F_DESC);
}
return TRUE;
}
bool TForm_EC_editor::font_handler(TMask_field& f, KEY key)
{
if (key == K_SPACE)
{
main_app().begin_wait();
const char* family = f.get();
const int MAXSIZES = 16;
long sizes[MAXSIZES];
BOOLEAN scalable;
const int num_sizes = (int)xvt_fmap_get_family_sizes(printer().get_printrcd(),
(char*)family, sizes, &scalable, MAXSIZES);
TToken_string pn1(80), pn2(80);
if (scalable)
{
for (int i = 4; i <= 32; i++)
{
pn1.add(i);
pn2.add(i);
}
}
else
{
if (num_sizes > 0)
{
for (int i = 0; i < num_sizes; i++)
pn1.add(sizes[i]);
}
else pn1.add(printer().get_char_size());
pn2 = pn1;
}
TList_field& lst = (TList_field&)f.mask().field(F_SSIZE);
lst.replace_items(pn1, pn2);
lst.set(format("%d",printer().get_char_size()));
main_app().end_wait();
}
return TRUE;
}
void TForm_EC_editor::load_fonts()
{
const int MAX_FAMILIES = 128;
char* family[MAX_FAMILIES];
const int num_families = (int)xvt_fmap_get_families(printer().get_printrcd(), family, MAX_FAMILIES);
bool font_found = FALSE;
TToken_string pn1(256), pn2(256);
for (int i = 0; i < num_families; i++)
{
pn1.add(family[i]);
pn2.add(family[i]);
if (!font_found)
if (form().fontname() == family[i]) font_found = TRUE;
xvt_mem_free(family[i]);
}
TList_field& lst = (TList_field&)_msk->field(F_SFONT);
lst.replace_items(pn1, pn2);
if (!font_found) warning_box("Il font %s non esiste per la stampante di default.",(const char*) form().fontname());
lst.set(form().fontname());
}
void TForm_EC_editor::change_pos(char sc, pagetype pt)
{
TPrint_section* sec = form().exist(sc, pt);
if (sec != NULL && !sec->columnwise())
{
sec->set_dirty();
for (word i = 0; i < sec->fields() ; i++)
{
TForm_item& fi = sec->field(i);
short value = fi.x();
if (value > 0 && (_prm.ratio != 1.0))
{
real x_pos;
x_pos = value * _prm.ratio;
x_pos.round();
fi.set_x((short)x_pos.integer());
fi.set_dirty();
}
}
}
}
bool TForm_EC_editor::recalculate_positions(const char* name, int size)
{
if (!form().dirty()) form().set_dirty();
_prm.size_1=form().fontsize();
strcpy(_prm.name_1,form().fontname());
_prm.size_2=size;
strcpy(_prm.name_2,name);
_prm.ratio = 1.0;
// Next 3 lines may be changed
xvt_print_open();
xvt_print_start_thread (wprms, (long)&_prm);
xvt_print_close();
form().fontname() = name;
form().fontsize() = size;
const char sechar[4] = { 'B', 'F', 'G', 'H' };
for (int sn = 0; sn < 4 ; sn++)
{
const char sc = sechar[sn];
for (pagetype pt = odd_page; pt <= last_page; pt = pagetype(pt+1))
change_pos(sc,pt);
}
return TRUE;
}
void TForm_EC_editor::hook_footer_to_body(TPrint_section* f, TPrint_section* b)
{
const word items = b->columnwise() ? f->fields() : 0;
const int min_col_id = b->find_first_col();
b->reset_tabs();
for (word i=0;i<items;i++)
{
TForm_item& fi = f->field(i);
if (fi.x()>0 || !fi.shown()) continue;
short id = fi.id();
if (id >= PEC_TSALDO && id <= PEC_TIMPLIRE) id = PEC_DESCR;
TForm_item& fb = b->find_field(id);
if (!fb.shown())
{
fi.hide();
fi.set_x(-1);
} else
{
int x = fb.x()+b->ofspc();
if (id == min_col_id) x++;
fi.set_x(x);
}
fi.ofs() = 999;
}
}
void TForm_EC_editor::unhook_footer(TPrint_section* f)
{
const word items = f->fields();
for (word i=0;i<items;i++)
{
TForm_item& fi = f->field(i);
if (fi.ofs()==999)
{
if (fi.x() == -1) fi.show();
fi.ofs() = 0;
fi.set_x(0);
}
}
}
void TForm_EC_editor::hide_body_items(TPrint_section* b)
{
const word items = b->fields();
for (word i=0;i<items;i++)
{
TForm_item& fi = b->field(i);
if (fi.shown() && fi.prompt().not_empty())
{
fi.hide();
fi.temp() = TRUE;
}
}
}
void TForm_EC_editor::show_body_items(TPrint_section* b)
{
const word items = b->fields();
for (word i=0;i<items;i++)
{
TForm_item& fi = b->field(i);
if (fi.temp())
{
fi.show();
fi.temp() = FALSE;
}
}
}
bool TForm_EC_editor::edit(char s, pagetype p)
{
_msk= new TMask("sc3100c");
TString80 caption;
bool dirty = FALSE;
bool other = FALSE;
KEY k;
if (extra())
{
if (s == 'R')
dirty = edit_relation();
else
if (s == 'D')
form_config();
else
if (s == 'K')
dirty = edit_fincatura();
else
if (s == 'J')
dirty = edit_formato_numero();
else
if (s == 'Y')
dirty = edit_formato_data();
else other = TRUE;
}
if (!extra() || (extra() && other))
{
// Carica i fonts disponibili nel listbox
load_fonts();
printer().set_char_size(form().fontsize()); // Questo settera' il carattere della stampante a quello del form
// Setta l'handler per il listbox dei fonts e per aggiornare i valori dello sfondo
_msk->set_handler(F_SFONT,font_handler);
// carica i dati relativi all'offset
_msk->set(F_SX, form().offset_x());
_msk->set(F_SY, form().offset_y());
TString ctp;
ctp << form().char_to_pos();
_msk->set(F_SCTP, ctp);
_msk->set(F_SIPX, form().ipx());
_msk->set(F_SIPY, form().ipy());
_msk->set(F_FOOT_H,form().exist('F',odd_page)->height());
// carica i dati relativi ai flags (memorizzati in HEADER LAST)
if (form().exist('H', last_page))
{
TForm_item& flags = form().find_field('H',last_page,PEC_FLAGS);
TToken_string tt(flags.prompt());
if (tt.get(0) != NULL)
_msk->set(F_SVALUTA,tt.get(0));
if (tt.get(1) != NULL)
_msk->set(F_FINK,tt.get(1));
if (tt.get(2) != NULL)
_msk->set(F_MAXTOT,tt.get(2));
}
// carica i dati relativi allo sfondo (memorizzati in GRAPHICS ODD)
if (form().exist('G', odd_page))
{
TForm_item& pict = form().find_field('G',odd_page,PEC_PICTURE);
_msk->set(F_BACKGROUND,pict.prompt());
_msk->set(F_BACKWIDTH,pict.width());
_msk->set(F_BACKHEIGHT,pict.height());
_msk->set(F_BACKX,pict.x());
_msk->set(F_BACKY,pict.y());
}
bool font_changed=FALSE;
while (TRUE)
{
bool local_dirty = FALSE;
enable_menu_item(M_FILE_PRINT);
k = _msk->run();
disable_menu_item(M_FILE_PRINT);
if ((_msk->field(F_SFONT).dirty() || _msk->field(F_SSIZE).dirty()))
{
font_changed = TRUE;
TString ff(_msk->get(F_SFONT));
dirty = recalculate_positions(ff, _msk->get_int(F_SSIZE)); // Va bene dirty e non local_dirty
printer().set_char_size(_msk->get_int(F_SSIZE)); // Questo settera' il carattere della stampante a quello del form
}
if (k==K_F3) local_dirty = edit_fincatura();
else if (k==K_F4) local_dirty = edit_formato_data();
else if (k==K_F5) local_dirty = edit_formato_numero();
else if (k!= K_ESC && k!=K_ENTER)
{
if (k==K_F6) { s = 'H'; caption = "Testata"; }
else if (k==K_F7) { s = 'B'; caption = "Corpo"; }
else if (k==K_F8) { s = 'F'; caption = "Piede"; }
local_dirty = TRUE;
if (!form().exist(s, odd_page))
{
const KEY k = yesnocancel_box("La sezione %s non esiste:\n"
"si desidera generarla?",
(const char*)caption);
if (k == K_ESC)
local_dirty = FALSE;
else
{
TPrint_section* sec = form().exist(s, odd_page, TRUE);
if (k == K_YES)
{
const TPrint_section* def = form().exist(s, odd_page);
if (def) *sec = *def;
else local_dirty = FALSE;
}
}
}
if (local_dirty)
{
local_dirty = form().section(s,odd_page).edit(caption);
if (!local_dirty) // E' stato premuto annulla dalla maschera di sezione
if (form().reread(s,odd_page) && font_changed)
//se e' stato cambiato il font allora in _prm ho i dati necessari
// per ricostruire le dimensioni corrette
change_pos(s,odd_page);
}
}
if (local_dirty || _msk->dirty()!=0) dirty=TRUE;
if (k==K_ESC || k==K_ENTER)
break;
} // End of while
} // End if
if (_msk->dirty() != 0 || dirty)
{
form().fontname() = _msk->get(F_SFONT);
form().fontsize() = _msk->get_int(F_SSIZE);
form().offset_x() = _msk->get_int(F_SX);
form().offset_y() = _msk->get_int(F_SY);
form().char_to_pos() = _msk->get(F_SCTP)[0];
form().ipx() = _msk->get_int(F_SIPX);
form().ipy() = _msk->get_int(F_SIPY);
if (form().exist('H', last_page))
{
TForm_item& flags = form().find_field('H',last_page,PEC_FLAGS);
TString s(_msk->get(F_SVALUTA));
s << "|" << _msk->get(F_FINK); s << "|" << _msk->get(F_MAXTOT);
form().section('H',last_page).set_dirty();
flags.set_prompt(s);
flags.set_dirty();
}
if (form().exist('G', odd_page))
{
TForm_item& pict = form().find_field('G',odd_page,PEC_PICTURE);
pict.set_prompt(_msk->get(F_BACKGROUND));
pict.width() = _msk->get_int(F_BACKWIDTH);
pict.height() = _msk->get_int(F_BACKHEIGHT);
pict.set_x(_msk->get_int(F_BACKX));
pict.y() = _msk->get_int(F_BACKY);
form().section('G',odd_page).set_dirty();
pict.set_dirty();
}
form().set_dirty();
if (!dirty) dirty = TRUE;
}
if ((dirty && k==K_ESC && yesno_box("Salvare le modifiche?")) || (dirty && k==K_ENTER))
{ // Se si preme annulla e sono state effettuate modifiche chiede la conferma per salvare
// Se invece si preme conferma e sono state effettuate modifiche non chiede la conferma
if (form().code().empty())
{
TFilename n(form().name()); n.ext("frm");
TFilename bak(n); bak.ext("bak");
rename(n, bak);
ofstream out(n);
form().print_on(out);
}
else
form().write_profile();
}
else
if (k==K_ESC && form()._isnew)
{
TLocalisamfile f(LF_FORM),r(LF_RFORM);
remove_form(f,r,form().name(),form().code());
mask().reset(F_BASE);
mask().reset(F_CODE);
mask().reset(F_CODEL);
mask().reset(F_DESC);
}
if (_msk!=NULL) delete _msk;
_msk = NULL;
if (!extra()) dispatch_e_menu(MENU_ITEM(14));
return dirty;
}
void TForm_EC_editor::print()
{
TPrint_section* g = form().exist('G',odd_page);
TPrint_section* h = form().exist('H',odd_page);
TPrint_section* f = form().exist('F',odd_page);
TPrint_section* b = form().exist('B',odd_page);
bool remove = TRUE;
CHECK(b!=NULL && f!=NULL && h!=NULL,"Una o piu' sezioni non sono presenti");
// Rilegge la sezione grafica, perche' se e' la seconda volta che si
// stampa deve ripristinare la situazione iniziale.
// NB la sezione grafica deve contenere solo sfondo: le linee di fincatura
// qui generate non verranno salvate; analogamente il programma di stampa
// vero e proprio.
if (b->columnwise())
{
bool gen_fink = TRUE;
if (_msk != NULL)
{
TForm_item& pict = g->find_field(PEC_PICTURE);
pict.set_prompt(_msk->get(F_BACKGROUND));
pict.width() = _msk->get_int(F_BACKWIDTH);
pict.height() = _msk->get_int(F_BACKHEIGHT);
pict.set_x(_msk->get_int(F_BACKX));
pict.y() = _msk->get_int(F_BACKY);
form().offset_y() = _msk->get_int(F_SY);
form().offset_x() = _msk->get_int(F_SX);
form().set_mode((bkg_mode)_msk->get_int(F_FINK));
if (form().mode() == none) gen_fink = FALSE;
}
// Schiaffa dentro le stringhe di esempio per ogni campo che non ha prompt o riferimenti sul file
// per i campi memo si copia _memo in _prompt
const int formlen = printer().formlen();
const int h_height = h->height();
int rws[3] = {h_height,formlen-f->height(),0};
if (gen_fink)
form().genera_fincatura(odd_page,h_height-2,formlen,rws);
form().genera_intestazioni(odd_page,h_height-1);
} else
remove = FALSE;
hook_footer_to_body(f,b);
hide_body_items(b);
form().put_examples('H',odd_page);
form().put_examples('F',odd_page);
TForm_editor::print();
form().remove_examples('H',odd_page);
form().remove_examples('F',odd_page);
show_body_items(b);
unhook_footer(f);
if (remove)
{
form().remove_temp_items('G',odd_page);
form().remove_temp_items('H',odd_page);
}
}
void TForm_EC_editor::remove_form(TLocalisamfile& frm, TLocalisamfile& rfr,const TString& t,const TString& c)
{
frm.zero();
frm.put("TIPOPROF", t);
if (c.not_empty())
frm.put("CODPROF", c);
if (frm.read() == NOERR)
frm.remove();
rfr.zero();
rfr.put("TIPOPROF", t);
rfr.put("CODPROF", c);
if (rfr.read(_isgteq) == NOERR)
{
for ( ; rfr.get("CODPROF") == c && rfr.get("TIPOPROF") == t; rfr.next())
rfr.remove();
}
}
bool TForm_EC_editor::ask_profile()
{
KEY k;
mask().set_handler(DLG_COPY,cpy_handler);
mask().set_handler(F_CODE,code_handler);
mask().set_handler(F_CODEL,lng_handler);
disable_menu_item(M_FILE_PRINT);
while ((k = mask().run()) != K_QUIT)
{
TLocalisamfile frm(LF_FORM);
TLocalisamfile rfr(LF_RFORM);
TString fform = mask().get(F_BASE);
TString fdesc = mask().get(F_DESC);
long fcode = mask().get_long(F_CODE);
char flng = mask().get(F_CODEL)[0];
TString cod;
cod.format("%04ld%c",fcode,flng);
if (!extra() && fcode == 0 && flng=='\0')
{
error_box("Non e' possibile modificare il profilo standard.");
continue;
}
if (k == K_ENTER)
{
check_form();
set_form(new TForm(fform, (fcode!=0) ? cod : "", extra() ? 2 :1, fdesc));
form().section_mask() = "sc3100s";
break;
}
else if (k == K_DEL)
{
if (fcode != 0 &&
yesno_box("Confermare la cancellazione del profilo %04ld%c", fcode,flng))
{
TProgind pi(50,"Cancellazione in corso...",FALSE,FALSE,10);
remove_form(frm,rfr,fform,cod);
pi.cancel();
mask().set(F_BASE,"");
mask().set(F_CODE,"");
mask().set(F_CODEL,"");
mask().set(F_DESC,"");
}
}
}
if (k == K_QUIT)
{
dispatch_e_menu(M_FILE_QUIT);
return TRUE;
}
return FALSE;
}
int sc3100(int argc, char** argv)
{
TForm_EC_editor a;
a.run(argc, argv, "Parametrizzazione profili EC");
return 0;
}