Correzione errore MI1087 (Variazione della descrizione di un profilo

esistente). Resa piu' snella la TForm_item::dup() (eliminata la
TForm_item::make_new_item()). Corretta la gestione della modifica del
font per i profili base (deleghe).


git-svn-id: svn://10.65.10.50/trunk@2854 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1996-05-20 13:07:32 +00:00
parent 8b6603b9cc
commit fd1396a30b
2 changed files with 130 additions and 112 deletions

@ -327,16 +327,8 @@ TForm_item::TForm_item(TPrint_section* section)
_temp(FALSE)
{}
TForm_item* TForm_item::make_new_item() const
void TForm_item::copy_to_form_item(TForm_item* fi) const
{
return new TForm_item(_section);
}
TForm_item* TForm_item::copy_to_form_item() const
{
TForm_item* fi = make_new_item();
fi->_flag = _flag; fi->_group = _group;
// come copiarlo facendo una cosa orrenda...
fi->_special.destroy();
@ -360,12 +352,12 @@ TForm_item* TForm_item::copy_to_form_item() const
for (k = 0; k < items; k++)
fi->_message.add(_message.row(k),k);
// fi->_message = _message; sarebbe utile avere un "operator =" per i TString_array
return fi;
}
TObject* TForm_item::dup() const
{
TForm_item * fi = copy_to_form_item();
TForm_item * fi = new TForm_item(_section);
copy_to_form_item(fi);
return fi;
}
@ -995,7 +987,6 @@ class TForm_subsection : public TForm_item
protected:
virtual void print_on(ostream& out) const;
virtual TForm_item* make_new_item() const;
public:
virtual TObject* dup() const;
virtual bool parse(TScanner& s);
@ -1023,14 +1014,10 @@ TForm_subsection::TForm_subsection(TPrint_section* s, const char* nm) :
TForm_item(s), _ssec(&(s->form()), s->section_type(), s->page_type(), TRUE), _file_id(-1), _name(nm)
{}
TForm_item* TForm_subsection::make_new_item() const
TObject* TForm_subsection::dup() const
{
return (TForm_item*) new TForm_subsection(_section);
}
TObject * TForm_subsection::dup() const
{
TForm_subsection* fs = (TForm_subsection*) copy_to_form_item();
TForm_subsection* fs = new TForm_subsection(_section);
copy_to_form_item(fs);
fs->_ssec = _ssec;
fs->_name = _name;
fs->_file_id = _file_id;
@ -1180,7 +1167,6 @@ class TForm_string : public TForm_item
TToken_string _memo;
protected:
virtual TForm_item* make_new_item() const;
virtual const char* class_name() const { return "STRINGA"; }
virtual void print_body(ostream& out);
@ -1221,14 +1207,10 @@ TForm_string::TForm_string(TPrint_section* section)
: TForm_item(section), _memo("",'\n')
{}
TForm_item* TForm_string::make_new_item() const
TObject* TForm_string::dup() const
{
return (TForm_item*) new TForm_string(_section);
}
TObject * TForm_string::dup() const
{
TForm_string* fs = (TForm_string*) copy_to_form_item();
TForm_string* fs = new TForm_string(_section);
copy_to_form_item(fs);
fs->_str = _str;
fs->_picture = _picture;
fs->_field = _field;
@ -1505,6 +1487,7 @@ protected:
public:
virtual TObject* dup() const;
void set_decimals(int d) { _height = d; }
virtual const char* example() const;
virtual void set_picture(const char* p);
@ -1518,6 +1501,12 @@ bool TForm_number::parse_head(TScanner& scanner)
return TForm_item::parse_head(scanner);
}
TObject* TForm_number::dup() const
{
TForm_number *fn = new TForm_number(_section);
copy_to_form_item(fn);
return fn;
}
void TForm_number::put_paragraph(const char* s)
{
@ -1639,7 +1628,6 @@ class TForm_date : public TForm_string
TString16 _format;
protected:
virtual TForm_item* make_new_item() const;
virtual const char* class_name() const { return "DATA"; }
virtual bool read();
virtual bool set(const char*);
@ -1668,14 +1656,10 @@ TForm_date::TForm_date(TPrint_section* section)
: TForm_string(section), _format("1444-")
{}
TForm_item* TForm_date::make_new_item() const
TObject* TForm_date::dup() const
{
return (TForm_item*) new TForm_date(_section);
}
TObject * TForm_date::dup() const
{
TForm_date* fd = (TForm_date*) copy_to_form_item();
TForm_date* fd = new TForm_date(_section);
copy_to_form_item(fd);
fd->_format = _format;
return fd;
}
@ -1792,7 +1776,6 @@ class TForm_list : public TForm_string
TToken_string _values;
protected:
virtual TForm_item* make_new_item() const;
virtual const char* class_name() const { return "LISTA"; }
virtual bool parse_item(TScanner& scanner);
virtual void print_on(TMask& m);
@ -1810,14 +1793,10 @@ TForm_list::TForm_list(TPrint_section* section)
: TForm_string(section)
{}
TForm_item* TForm_list::make_new_item() const
TObject* TForm_list::dup() const
{
return (TForm_item*) new TForm_list(_section);
}
TObject * TForm_list::dup() const
{
TForm_list* fl = (TForm_list*) copy_to_form_item();
TForm_list* fl = new TForm_list(_section);
copy_to_form_item(fl);
fl->_codes = _codes;
fl->_values = _values;
return fl;
@ -2118,7 +2097,7 @@ HIDDEN bool font_handler(TMask_field& f, KEY key)
lst.set(format("%d",printer().get_char_size()));
main_app().end_wait();
}
}
return TRUE;
}
@ -2384,13 +2363,80 @@ bool TPrint_section::special_field_handler(TMask_field& f, KEY k)
_special_mask->run();
return TRUE;
}
void TPrint_section::repos_fields(const char* name, int size)
{
TPrint_section& ps = ::section();
if (ps.form().fontname() != name ||
ps.form().fontsize() != size)
{
if (!ps.form().dirty()) ps.form().set_dirty();
ps.set_dirty();
if (yesno_box("E' stato cambiato il font o la dimensione del carattere\ndevo aggiornare le coordinate dei campi"))
{
s_data prm;
prm.size_1=ps.form().fontsize();
strcpy(prm.name_1,ps.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 (wpr, (long)&prm);
xvt_print_close();
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 = ps.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();
}
}
}
}
}
}
ps.form().fontname() = name;
ps.form().fontsize() = size;
// Aggiorna lo spreadsheet
TSheet_field& ms = (TSheet_field&)ps._msk->field(F_FIELDS);
TToken_string tt(128);
const word flds = ps.fields();
for (word i = 0; i < flds; i++)
{
TForm_item& f = ps.field(i);
ps.field(i).print_on_sheet_row(tt);
ms.row(i) = tt;
}
}
}
// handlers for section editing
bool TPrint_section::detail_field_handler(TMask_field& f, KEY k)
{
if (k == K_SPACE)
{
{
TString80 name(_msk->get(F_FONT));
int size = _msk->get_int(F_SIZE);
repos_fields(name, size);
bool consider_sheet_mask = FALSE;
if (f.mask().is_running()) // Se la maschera di editing dello sheet e' running
consider_sheet_mask = TRUE; // allora deve tener conto anche di essa per l'I/O
@ -2456,8 +2502,8 @@ bool TPrint_section::detail_field_handler(TMask_field& f, KEY k)
{
msk.set_handler(F_OPTIONS, special_field_handler);
CHECK(fi.special_items() < 18, "Ostia, quanti special! Non ho nessuna voglia di "
" farti una maschera a piu' pagine per sta cagata. Ripensaci e riprova");
CHECK(fi.special_items() < 18, "Quanti special! Non ho nessuna voglia di "
" farti una maschera a piu' pagine. Ripensaci e riprova");
_special_mask = new TMask("Variabili personalizzate", 1, 78, fi.special_items() + 3);
_special_mask->add_button(DLG_OK, 0, "", -12, -1, 10, 2);
@ -2490,7 +2536,7 @@ bool TPrint_section::detail_field_handler(TMask_field& f, KEY k)
for (int jj = 2; jj < des.items(); jj++)
{
CHECK (jj < (des.items() - 1), "AAARGH! 'Sta LISTA special e' fatta col CULO!");
CHECK (jj < (des.items() - 1), "AAARGH! 'Sta LISTA special e' fatta male");
TString t1(des.get(jj++));
TString t2(des.get(jj));
codes.add(t1);
@ -2659,7 +2705,16 @@ bool TPrint_section::detail_field_notify (TSheet_field& s, int r, KEY k)
}
// modifica valori
fld->read_from(tt);
}
else
if (k == K_SPACE)
{
TString80 name(s.mask().get(F_FONT));
int size = s.mask().get_int(F_SIZE);
repos_fields(name,size);
s.force_update();
}
return TRUE;
}
@ -2681,6 +2736,7 @@ bool TPrint_section::edit(
if (!_subsection)
{
TMask m(_form->section_mask());
_msk = &m;
m.set_caption(title);
m.set(F_HEIGHT, _height);
m.set(F_OFSPC, _ofspc);
@ -2730,9 +2786,10 @@ bool TPrint_section::edit(
if (_form->edit_level()<=1) ms.sheet_mask().disable(DLG_DELREC);
TToken_string tt(128);
const word flds = fields();
// fill sheet
for (word i = 0; i < fields(); i++)
for (word i = 0; i < flds; i++)
{
TForm_item& f = field(i);
field(i).print_on_sheet_row(tt);
@ -2783,11 +2840,15 @@ bool TPrint_section::edit(
if (i==items && !ok) error_box("Selezionare almeno una colonna stampabile.");
if (ok) break;
}
_msk = NULL;
if (!ok) return FALSE;
}
else
if (m.run() == K_ESC)
{
_msk = NULL;
return FALSE;
}
bool dirty = m.dirty() != 0;
@ -2831,57 +2892,12 @@ bool TPrint_section::edit(
}
TString80 name(m.get(F_FONT));
int size = m.get_int(F_SIZE);
if (name != form().fontname() || size != form().fontsize())
{
if (!form().dirty()) form().set_dirty();
_dirty = TRUE;
if (font_found && yesno_box("E' stato cambiato il font o la dimensione del carattere\ndevo aggiornale le coordinate dei campi"))
{
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 (wpr, (long)&prm);
xvt_print_close();
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->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();
}
}
}
}
}
}
form().fontname() = name;
form().fontsize() = size;
}
int size = m.get_int(F_SIZE);
repos_fields(name,size);
} else // controlli se l'editor non e' quello base
nstd_dirty = _form->post_edit_checks(m,_cur_sect);
}
_msk = NULL;
}
if (is_ba_editor && (_dirty || form()._isnew) &&
@ -4163,7 +4179,7 @@ void TForm::read(
forms.put("TIPOPROF", _name);
forms.put("CODPROF", _code);
_isnew = forms.read() != NOERR;
_isnew = forms.read() == _iskeynotfound;
if (_isnew)
{
// create new form
@ -4181,7 +4197,17 @@ void TForm::read(
forms.put("GRID", _fink);
forms.write();
}
else _desc = forms.get("DESC");
else
if (forms.status() == NOERR)
{
_desc = forms.get("DESC");
if (_desc != desc && desc != "") // Controlla se la descrizione e' diversa, in questo caso l'aggiorna
{
forms.reread(_lock);
forms.put("DESC",desc);
forms.rewrite();
}
}
}
// read base form

@ -466,6 +466,8 @@ protected:
// @cmember Crea un nuovo <c TForm_item> ritornandone un puntatore (chiama <mf TForm_item::parse_item>)
TForm_item* parse_item(TScanner& scanner);
// @cmember Procedura che effettua il ricalcolo delle coordinate di <c TForm_item> nel caso il font sia cambiato
static void repos_fields(const char* name, int size);
// @cmember Handler del bottone per editare in modo dettagliato un <c TForm_item>
static bool detail_field_handler(TMask_field&, KEY);
// @cmember Handler del bottone per editare gli specials di un <c TForm_item>
@ -659,18 +661,8 @@ protected:
// l'<p n>-esimo elemento (0=tipo, 1=valore, 2=descrizione)
const char* get_special_item(const char* s, int n) const;
// @cmember Crea un item (TForm_date, TForm_list...) e ne restituisce il puntatore
// TForm_item. Va ridefinita per ogni classe derivata da TForm_item.
// N.B. il membro _section deve rimanere protected, altrimenti le varie
// make_new_item() non potranno essere compilate.
virtual TForm_item* make_new_item() const;
// @cmember Restituisce un puntatore a TForm_item, nel quale sono copiati tutti
// i membri del presente oggetto. Viene chiamata dalla <mf TForm_item::dup>
// All'interno di questa funzione vi e' una discriminazione sul tipo di classe
// affinche' possa creare un opportuno item (data, lista, numero, stringa...).
// E' ovvio che per tali ultimi casi e' necessario un cast. Chiama la <mf TForm_item::make_new_item>
// per creare un nuovo item.
TForm_item* copy_to_form_item() const;
// @cmember Copia tutti i membri dell'oggetto base in fi. Viene chiamata dalla <mf TForm_item::dup>
void copy_to_form_item(TForm_item* fi) const;
// @access Public Member
public: