1995-12-18 15:37:20 +00:00
|
|
|
#ifndef __PRINTER_H
|
|
|
|
#include <printer.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../ba/baformed.h"
|
|
|
|
#include "sc3.h"
|
|
|
|
#include "sc3100a.h"
|
|
|
|
#include "sc3100b.h"
|
|
|
|
#include "sc3100c.h"
|
|
|
|
#include "sc21pec.h"
|
|
|
|
|
|
|
|
class TForm_EC_editor : public TForm_editor
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
static bool cpy_handler(TMask_field& f, KEY k);
|
|
|
|
static bool font_handler(TMask_field& f, KEY k);
|
|
|
|
void load_fonts(TMask& m);
|
|
|
|
bool recalculate_positions(const char* name, int size);
|
|
|
|
virtual const char* selection_mask() const { return "sc3100a"; }
|
|
|
|
virtual bool ask_profile();
|
|
|
|
virtual bool edit(char s, pagetype p);
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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::cpy_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
if (k==K_SPACE)
|
|
|
|
{
|
|
|
|
TLocalisamfile frm(LF_FORM),rfr(LF_RFORM);
|
|
|
|
TMask mm("sc3100b");
|
|
|
|
if (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.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
//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());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (rfr_to_write.status() != NOERR)
|
|
|
|
{
|
|
|
|
error_box("Errore %d in scrittura righe profilo.",rfr_to_write.status());
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error_box("Non esiste il profilo sorgente specificato.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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(TMask& m)
|
|
|
|
{
|
|
|
|
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&)m.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());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_EC_editor::recalculate_positions(const char* name, int size)
|
|
|
|
{
|
|
|
|
if (!form().dirty()) form().set_dirty();
|
|
|
|
s_data prm;
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
TPrint_section* sec = form().exist(sc, pt);
|
|
|
|
if (sec != NULL)
|
|
|
|
{
|
|
|
|
sec->set_dirty();
|
|
|
|
for (word i = 0; i < sec->fields() ; i++)
|
|
|
|
{
|
|
|
|
TForm_item& fi = sec->field(i);
|
1995-12-22 16:20:42 +00:00
|
|
|
short value = sec->columnwise() ? fi.y() : fi.x();
|
|
|
|
if (value > 0 && (prm.ratio != 1.0))
|
1995-12-18 15:37:20 +00:00
|
|
|
{
|
|
|
|
real x_pos;
|
1995-12-22 16:20:42 +00:00
|
|
|
x_pos = value * prm.ratio;
|
1995-12-18 15:37:20 +00:00
|
|
|
x_pos.round();
|
1995-12-22 16:20:42 +00:00
|
|
|
if (sec->columnwise())
|
|
|
|
fi.y() = (short)x_pos.integer();
|
|
|
|
else
|
|
|
|
fi.x() = (short)x_pos.integer();
|
1995-12-18 15:37:20 +00:00
|
|
|
fi.set_dirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_EC_editor::edit(char s, pagetype p)
|
|
|
|
{
|
|
|
|
TMask m("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(m);
|
|
|
|
printer().set_char_size(form().fontsize()); // Questo settera' il carattere della stampante a quello del form
|
|
|
|
// Setta l'handler per il listbox dei fonts
|
|
|
|
m.set_handler(F_SFONT,font_handler);
|
|
|
|
// carica i dati relativi all'offset
|
|
|
|
m.set(F_SX, form().offset_x());
|
|
|
|
m.set(F_SY, form().offset_y());
|
|
|
|
TString ctp;
|
|
|
|
ctp << form().char_to_pos();
|
|
|
|
m.set(F_SCTP, ctp);
|
|
|
|
m.set(F_SIPX, form().ipx());
|
|
|
|
m.set(F_SIPY, form().ipy());
|
|
|
|
// carica i dati relativi ai flags (memorizzati in HEADER LAST)
|
|
|
|
if (form().exist('H', last_page))
|
|
|
|
{
|
1995-12-22 16:20:42 +00:00
|
|
|
TForm_item& flags = form().find_field('H',last_page,PEC_FLAGS);
|
1995-12-18 15:37:20 +00:00
|
|
|
TToken_string tt(flags.prompt());
|
|
|
|
if (tt.get(0) != NULL)
|
|
|
|
m.set(F_SVALUTA,tt.get(0));
|
|
|
|
if (tt.get(1) != NULL)
|
|
|
|
m.set(F_FINK,tt.get(1));
|
|
|
|
}
|
|
|
|
// carica i dati relativi allo sfondo (memorizzati in GRAPHICS ODD)
|
|
|
|
if (form().exist('G', odd_page))
|
|
|
|
{
|
1995-12-22 16:20:42 +00:00
|
|
|
TForm_item& pict = form().find_field('G',odd_page,PEC_PICTURE);
|
1995-12-18 15:37:20 +00:00
|
|
|
m.set(F_BACKGROUND,pict.prompt());
|
|
|
|
m.set(F_BACKWIDTH,pict.width());
|
|
|
|
m.set(F_BACKHEIGHT,pict.height());
|
|
|
|
m.set(F_BACKX,pict.x());
|
|
|
|
m.set(F_BACKY,pict.y());
|
|
|
|
}
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
bool local_dirty = FALSE;
|
|
|
|
k = m.run();
|
|
|
|
if ((m.field(F_SFONT).dirty() || m.field(F_SSIZE).dirty()))
|
|
|
|
{
|
|
|
|
TString ff(m.get(F_SFONT));
|
|
|
|
dirty = recalculate_positions(ff, m.get_int(F_SSIZE)); // Va bene dirty e non local_dirty
|
|
|
|
printer().set_char_size(m.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)
|
|
|
|
{
|
1995-12-22 16:20:42 +00:00
|
|
|
if (k==K_F6) { s = 'H'; caption = "Testata"; }
|
1995-12-18 15:37:20 +00:00
|
|
|
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);
|
|
|
|
}
|
1995-12-22 16:20:42 +00:00
|
|
|
if (local_dirty || m.dirty()!=0) dirty=TRUE;
|
1995-12-18 15:37:20 +00:00
|
|
|
if (k==K_ESC || k==K_ENTER)
|
|
|
|
break;
|
|
|
|
} // End of while
|
|
|
|
} // End if
|
|
|
|
|
1995-12-22 16:20:42 +00:00
|
|
|
if (m.dirty() != 0 || dirty)
|
1995-12-18 15:37:20 +00:00
|
|
|
{
|
|
|
|
form().fontname() = m.get(F_SFONT);
|
|
|
|
form().fontsize() = m.get_int(F_SSIZE);
|
|
|
|
form().offset_x() = m.get_int(F_SX);
|
|
|
|
form().offset_y() = m.get_int(F_SY);
|
|
|
|
form().char_to_pos() = m.get(F_SCTP)[0];
|
|
|
|
form().ipx() = m.get_int(F_SIPX);
|
|
|
|
form().ipy() = m.get_int(F_SIPY);
|
|
|
|
if (form().exist('H', last_page))
|
|
|
|
{
|
1995-12-22 16:20:42 +00:00
|
|
|
TForm_item& flags = form().find_field('H',last_page,PEC_FLAGS);
|
1995-12-18 15:37:20 +00:00
|
|
|
TString s(m.get(F_SVALUTA));
|
|
|
|
s << "|" << m.get(F_FINK);
|
|
|
|
form().section('H',last_page).set_dirty();
|
|
|
|
flags.set_prompt(s);
|
|
|
|
flags.set_dirty();
|
|
|
|
}
|
|
|
|
if (form().exist('G', odd_page))
|
|
|
|
{
|
1995-12-22 16:20:42 +00:00
|
|
|
TForm_item& pict = form().find_field('G',odd_page,PEC_PICTURE);
|
1995-12-18 15:37:20 +00:00
|
|
|
pict.set_prompt(m.get(F_BACKGROUND));
|
|
|
|
pict.width() = m.get_int(F_BACKWIDTH);
|
|
|
|
pict.height() = m.get_int(F_BACKHEIGHT);
|
|
|
|
pict.x() = m.get_int(F_BACKX);
|
|
|
|
pict.y() = m.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
|
1995-12-22 16:20:42 +00:00
|
|
|
if (form().code().empty())
|
1995-12-18 15:37:20 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
if (!extra()) dispatch_e_menu(MENU_ITEM(14));
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TForm_EC_editor::ask_profile()
|
|
|
|
{
|
|
|
|
KEY k;
|
|
|
|
mask().set_handler(DLG_COPY,cpy_handler);
|
|
|
|
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();
|
1995-12-22 16:20:42 +00:00
|
|
|
set_form(new TForm(fform, (fcode!=0) ? cod : "", extra() ? 2 :1, fdesc));
|
|
|
|
form().section_mask() = "sc3100s";
|
1995-12-18 15:37:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (k == K_DEL)
|
|
|
|
{
|
|
|
|
if (fcode != 0 &&
|
|
|
|
yesno_box("Confermare la cancellazione del profilo %04ld%c", fcode,flng))
|
|
|
|
{
|
|
|
|
frm.zero();
|
|
|
|
frm.put("TIPOPROF", fform);
|
|
|
|
if (fcode != 0 )
|
|
|
|
frm.put("CODPROF", cod);
|
|
|
|
if (frm.read() == NOERR)
|
|
|
|
frm.remove();
|
|
|
|
rfr.zero();
|
|
|
|
rfr.put("TIPOPROF", fform);
|
|
|
|
rfr.put("CODPROF", cod);
|
|
|
|
if (rfr.read(_isgteq) == NOERR)
|
|
|
|
{
|
|
|
|
for ( ; rfr.get("CODPROF") == cod && rfr.get("TIPOPROF") == fform; rfr.next())
|
|
|
|
rfr.remove();
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|