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

View File

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

View File

@ -466,6 +466,8 @@ protected:
// @cmember Crea un nuovo <c TForm_item> ritornandone un puntatore (chiama <mf TForm_item::parse_item>) // @cmember Crea un nuovo <c TForm_item> ritornandone un puntatore (chiama <mf TForm_item::parse_item>)
TForm_item* parse_item(TScanner& scanner); 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> // @cmember Handler del bottone per editare in modo dettagliato un <c TForm_item>
static bool detail_field_handler(TMask_field&, KEY); static bool detail_field_handler(TMask_field&, KEY);
// @cmember Handler del bottone per editare gli specials di un <c TForm_item> // @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) // l'<p n>-esimo elemento (0=tipo, 1=valore, 2=descrizione)
const char* get_special_item(const char* s, int n) const; const char* get_special_item(const char* s, int n) const;
// @cmember Crea un item (TForm_date, TForm_list...) e ne restituisce il puntatore // @cmember Copia tutti i membri dell'oggetto base in fi. Viene chiamata dalla <mf TForm_item::dup>
// TForm_item. Va ridefinita per ogni classe derivata da TForm_item. void copy_to_form_item(TForm_item* fi) const;
// 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;
// @access Public Member // @access Public Member
public: public: