Aggiunta funzione fnt_handler, per controllare la larghezza colonna

di una sezione COLUMNWISE.
Aggiunta gestione dei campi memo di un form.
Modificati metodi di lettura/salvataggio di TPrint_section e TForm_item
per gestire il campo memo, il prompt, l'offset iniziale, la fincatura
destra e sinistra.
Corretta la visualizzazione delle informazioni di una sezione COLUMNWISE
Aggiunto il salvataggio su file del membro _ofspc di TPrint_section
Aggiunta la gestione delle descrizioni dell'estratto conto.
Corretto il salvataggio di TDate_iten su file.
Aggiunto il ricalcolo della larghezza colonna nel caso ssi cambi il
font di stampa.


git-svn-id: svn://10.65.10.50/trunk@2342 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1995-12-22 15:57:45 +00:00
parent b6d2c517b1
commit 4e73dfb702

View File

@ -15,6 +15,7 @@
#include <utility.h>
#include "../ba/bafrm.h"
#include "../sc/sc21pec.h"
// per lo sheet di edit campi
HIDDEN const int idt_id = 101;
@ -208,13 +209,31 @@ HIDDEN bool dateformat_handler(TMask_field& f, KEY k)
return TRUE;
}
HIDDEN bool fmt_handler(TMask_field& f, KEY k)
{
if (k==K_ENTER || k==K_TAB)
{
TMask& m = f.mask();
TPrint_section& s = ::section();
if (s.columnwise())
{
const int fmt_len = m.get(F_PICTURE).len(); // length of picture
m.set(F_LENFMT,fmt_len);
m.set(F_NUMCOL,s.fields());
}
else
m.set(F_NUMCOL,999);
}
return TRUE;
}
///////////////////////////////////////////////////////////
// TForm_flags
///////////////////////////////////////////////////////////
TForm_flags::TForm_flags()
{
automagic = dirty = finkr = finkl = FALSE;
automagic = dirty = finkr = finkl = memo = FALSE;
shown = enabled = TRUE;
}
@ -235,6 +254,8 @@ bool TForm_flags::update(const char* s)
finkl = TRUE; break;
case 'K':
finkr = TRUE; break;
case 'M':
memo = TRUE; break;
default :
error_box("Unknown form item flag '%c'", *s); break;
}
@ -253,6 +274,7 @@ void TForm_flags::print_on(ostream& out) const
if (!shown) s << "H";
if (finkl) s << "F";
if (finkr) s << "K";
if (memo) s << "M";
if (s.not_empty())
out << " FLAGS \"" << s << '"' << endl;
@ -288,7 +310,7 @@ void TForm_flags::read_from(const TMask& m)
TForm_item::TForm_item(TPrint_section* section)
: _section(section), _x(-1), _y(-1), _width(0), _height(0), _id(0), _ofs(0),
_temp(FALSE)
_temp(FALSE), _memo("",'\n')
{}
@ -479,7 +501,16 @@ bool TForm_item::read_from(const TRectype& prof)
_height = i;
changed = TRUE;
}
TString p(prof.get("PROMPT"));
if (p.not_empty())
{
if (p == "_") p.cut(0);
_prompt = p;
changed = TRUE;
}
if (_flag.memo)
_memo = prof.get("TESTO");
const bool s = prof.get_bool("ATTIVO");
if (_flag.shown != s)
{
@ -488,23 +519,32 @@ bool TForm_item::read_from(const TRectype& prof)
}
TToken_string special(prof.get("SPECIAL"),'\n');
for (i = 0; i < special.items(); i++)
{
TToken_string sp(special.get(i), '$');
TString key(sp.get(0));
TString val(sp.get(1));
if (!_special.is_key(key))
if (i == special.items()-1)
{
error_box("Variabile speciale non presente nel profilo: %s",
(const char*)key);
continue;
TToken_string fink(special.get(i));
_ofs = fink.get_int(0);
_flag.finkl = fink.get_char(1) == 'X';
_flag.finkr = fink.get_char(2) == 'X';
}
else
{
TToken_string sp(special.get(i), '$');
TString key(sp.get(0));
TString val(sp.get(1));
if (!_special.is_key(key))
{
error_box("Variabile speciale non presente nel profilo: %s",
(const char*)key);
continue;
}
TToken_string& tt = (TToken_string&)_special[key];
tt.add(val,1);
// forza riscrittura su memo
if (tt.items() == 3) tt.add("X");
}
TToken_string& tt = (TToken_string&)_special[key];
tt.add(val,1);
// forza riscrittura su memo
if (tt.items() == 3) tt.add("X");
}
return TRUE;
@ -518,11 +558,14 @@ void TForm_item::print_on(TRectype& prof)
prof.put("Y", _y);
prof.put("LEN", width());
prof.put("HGT", height());
if (prompt().empty()) set_prompt("_");
prof.put("PROMPT", prompt());
prof.put("ATTIVO", shown() ? "X" : " ");
if (_flag.memo)
prof.put("TESTO", _memo);
// specials: se e' stato cambiato, la tokenstring del valore contiene
// una X alla fine (campo 3)
if (_special.items() > 0)
{
TToken_string special(128,'\n');
_special.restart();
@ -542,6 +585,10 @@ void TForm_item::print_on(TRectype& prof)
special.add(sp);
}
}
TString fink(8);
fink << _ofs << "|"; fink << (_flag.finkl ? "X" : " ") <<"|";
fink << (_flag.finkr ? "X" : " ");
special.add(fink);
prof.put("SPECIAL", special);
}
}
@ -747,10 +794,16 @@ void TForm_item::print_on(TMask& m)
m.set(F_ID, id());
m.set(F_KEY, key());
m.set(F_X, _x);
m.set(F_Y, _y);
if (!_section->columnwise())
m.set(F_Y, _y);
m.set(F_PROMPT, _prompt);
m.set(F_WIDTH, _width);
m.set(F_HEIGHT, _height);
if (_section->columnwise())
m.set(F_WIDTH, _y);
else
m.set(F_WIDTH, _width);
m.set(F_HEIGHT, _height);
m.set(F_MEMO, _memo);
m.set(F_SPACES, _ofs);
_flag.print_on(m);
@ -762,12 +815,17 @@ void TForm_item::read_from(const TMask& m)
{
_desc = m.get(F_KEY);
_x = atoi(m.get(F_X));
_y = atoi(m.get(F_Y));
if (!_section->columnwise())
_y = atoi(m.get(F_Y));
_prompt = m.get(F_PROMPT);
_width = atoi(m.get(F_WIDTH));
if (_section->columnwise())
_y = atoi(m.get(F_WIDTH));
else
_width = atoi(m.get(F_WIDTH));
_height = atoi(m.get(F_HEIGHT));
_id = atoi(m.get(F_ID));
_ofs = atoi(m.get(F_SPACES));
_memo = m.get(F_MEMO);
_flag.read_from(m);
@ -795,8 +853,7 @@ void TForm_item::read_from(TToken_string& s)
bool TForm_item::edit(TMask& m)
{
m.enable(F_CLASS, m.insert_mode());
m.enable(F_CLASS, m.insert_mode());
m.reset();
if (m.insert_mode())
@ -816,7 +873,20 @@ bool TForm_item::edit(TMask& m)
m.enable_page(1, godmode);
m.enable(-7, godmode);
m.enable(F_ID, godmode);
m.enable(F_Y,!_section->columnwise());
m.enable(F_WIDTH,_section->columnwise());
if (_flag.memo)
{
m.disable(F_PROMPT);
m.hide(F_PROMPT);
m.enable(F_MEMO);
m.show(F_MEMO);
}
else
{
m.hide(F_MEMO);
m.disable(F_MEMO);
}
const bool dirty = m.run() == K_ENTER;
if (dirty)
{
@ -1056,7 +1126,7 @@ public:
virtual void set_picture(const char* p) { _picture = p; }
virtual bool edit(TMask& m);
TForm_string(TPrint_section* section) : TForm_item(section) {}
TForm_string(TPrint_section* section) : TForm_item(section) { }
virtual ~TForm_string() {}
};
@ -1104,7 +1174,7 @@ bool TForm_string::read_from(const TRectype& prof)
_picture = pict;
changed = TRUE;
}
return changed;
}
@ -1377,7 +1447,7 @@ void TForm_number::apply_format(real& n , TString& s) const
s=n.string(pic); // riempi la stringa col valore pitturato
if (maxlen >= 0)
if (maxlen >= 0 && maxlen < s.size())
s.cut(maxlen);
if (!delim.empty_items()) // Aggiungi delimitatori
{
@ -1489,7 +1559,7 @@ bool TForm_date::read_from(const TRectype& prof)
void TForm_date::print_on(TRectype& prof)
{
TForm_string::read_from(prof);
TForm_string::print_on(prof);
prof.put("DATEFORM", _format);
}
@ -2045,10 +2115,16 @@ bool TPrint_section::read_from(const TRectype& prof)
bool changed = FALSE;
const word h = (word)prof.get_int("HGT");
const word l = (word)prof.get_int("LEN");
if (_height != h)
{
_height = h;
changed = TRUE;
}
if (_ofspc != l)
{
_ofspc = l;
changed = TRUE;
}
return changed;
}
@ -2059,6 +2135,7 @@ void TPrint_section::print_on(TRectype& prof)
prof.put("ID", 0);
prof.put("X", 0);
prof.put("Y", 0);
prof.put("LEN", _ofspc);
prof.put("HGT", _height);
}
@ -2122,13 +2199,16 @@ bool TPrint_section::detail_field_handler(TMask_field& f, KEY k)
msk.set_handler(F_BUT_FIELD2, but_field_handler);
msk.set_handler(F_FROM2, from_handler);
msk.set_handler(F_TO2, to_handler);
msk.set_handler(F_PICTURE,fmt_handler);
// TBI set_mode etc, vedi sotto
// gna'
TForm_item& fi = section.field(field);
msk.enable(F_OPTIONS, fi.special_items() > 0);
msk.enable(F_SPACES, section.columnwise());
msk.enable(F_FINKL, section.columnwise());
msk.enable(F_FINKR, section.columnwise());
// build option mask
if (fi.special_items() > 0)
@ -2216,7 +2296,11 @@ bool TPrint_section::detail_field_handler(TMask_field& f, KEY k)
}
}
delete _special_mask;
if (_special_mask != NULL)
{
delete _special_mask;
_special_mask = NULL;
}
}
// reset stominchione
@ -2314,12 +2398,14 @@ bool TPrint_section::detail_field_notify (TSheet_field& s, int r, KEY k)
bool TPrint_section::edit(const char* title)
{
const bool is_ba_editor = _form->section_mask() == "ba";
bool des_dirty = FALSE;
_cur_form = _form;
_cur_sect = this;
if (!_subsection)
{
TMask m("ba2100s");
TMask m(_form->section_mask());
m.set_caption(title);
m.set(F_HEIGHT, _height);
m.set(F_X, form().offset_x());
@ -2330,11 +2416,25 @@ bool TPrint_section::edit(const char* title)
m.set(F_FPX, form().fpx());
m.set(F_FLEN, printer().formlen());
m.set(F_OFSPC, _ofspc);
// Carica i valori dei campi testo costanti (se non e' il formeditor normale)
if (!is_ba_editor)
{ // Se sta editando il body abilita i primi 4, se sta editando il footer abilita l'ultimo
if (_sec_type == 'B')
m.enable(-2);
if (_sec_type == 'F')
m.enable(-3);
if (_form->exist('H', last_page))
{
m.set(F_DES1,_form->find_field('H',last_page,PEC_SALDO).prompt());
m.set(F_DES2,_form->find_field('H',last_page,PEC_RITENUTE).prompt());
m.set(F_DES3,_form->find_field('H',last_page,PEC_ABBUONI).prompt());
m.set(F_DES4,_form->find_field('H',last_page,PEC_DIFFCAM).prompt());
m.set(F_DES5,_form->find_field('H',last_page,PEC_RIPORTO).prompt());
}
}
// still unused: will need to be shown if section is columnwise; no
// provision for saving yet (should be in form, with a field for each pos)
m.hide(F_OFSPC);
TSheet_field& ms = (TSheet_field&)m.field(F_FIELDS);
if (_columnwise)
@ -2345,6 +2445,7 @@ bool TPrint_section::edit(const char* title)
}
else
{
m.hide(F_OFSPC);
ms.delete_column(int_id); ms.sheet_mask().hide(int_id);
ms.delete_column(len_id); ms.sheet_mask().hide(len_id);
ms.delete_column(col_id); ms.sheet_mask().hide(col_id);
@ -2406,6 +2507,27 @@ bool TPrint_section::edit(const char* title)
if (dirty)
{
// Salva i valori dei campi testo costanti (se non e' il formeditor normale)
if (!is_ba_editor && _form->exist('H', last_page))
{
_form->section('H',last_page).set_dirty();
TForm_item& saldo = _form->find_field('H',last_page,PEC_SALDO);
TForm_item& abbuoni = _form->find_field('H',last_page,PEC_RITENUTE);
TForm_item& diffcam = _form->find_field('H',last_page,PEC_ABBUONI);
TForm_item& ritenute = _form->find_field('H',last_page,PEC_DIFFCAM);
TForm_item& riporto = _form->find_field('H',last_page,PEC_RIPORTO);
saldo.set_prompt(m.get(F_DES1));
saldo.set_dirty();
abbuoni.set_prompt(m.get(F_DES2));
abbuoni.set_dirty();
diffcam.set_prompt(m.get(F_DES3));
diffcam.set_dirty();
ritenute.set_prompt(m.get(F_DES4));
ritenute.set_dirty();
riporto.set_prompt(m.get(F_DES5));
riporto.set_dirty();
des_dirty = TRUE;
}
if (_height != (word)m.get_int(F_HEIGHT) )
{
_height = m.get_int(F_HEIGHT);
@ -2467,12 +2589,16 @@ bool TPrint_section::edit(const char* title)
for (word i = 0; i < sec->fields() ; i++)
{
TForm_item& fi = sec->field(i);
if (fi.x() > 0 && (prm.ratio != 1.0))
short value = sec->columnwise() ? fi.y() : fi.x();
if (value > 0 && (prm.ratio != 1.0))
{
real x_pos;
x_pos = fi.x() * prm.ratio;
x_pos = value * prm.ratio;
x_pos.round();
fi.x() = (short)x_pos.integer();
if (sec->columnwise())
fi.y() = (short)x_pos.integer();
else
fi.x() = (short)x_pos.integer();
fi.set_dirty();
}
}
@ -2483,7 +2609,8 @@ bool TPrint_section::edit(const char* title)
}
}
if ((_dirty || form()._isnew) && yesno_box("Dati generali modificati. Salvare?"))
if (is_ba_editor && (_dirty || form()._isnew) &&
yesno_box("Dati generali modificati. Salvare?"))
{
TLocalisamfile frm(LF_FORM);
frm.zero();
@ -2509,7 +2636,7 @@ bool TPrint_section::edit(const char* title)
_dirty |= field(j).dirty();
set_dirty(_dirty);
return _dirty;
return (_dirty || des_dirty);
}
void TPrint_section::print_on(ostream& out) const
@ -2798,7 +2925,11 @@ bool TForm::ps_change_date_format(TPrint_section& s, const char* f)
ps_change_date_format(ps, f);
}
else if (strcmp(fi.class_name(), "DATA") == 0)
{
((TForm_date&)fi).set_format(f);
if (!s.dirty()) s.set_dirty();
if (!fi.dirty()) fi.set_dirty();
}
}
return TRUE;
}
@ -2819,6 +2950,8 @@ bool TForm::ps_change_number_format(TPrint_section& s, int w, int dec, const cha
fn.width() = w;
fn.set_decimals(dec);
fn.set_picture(p);
if (!s.dirty()) s.set_dirty();
if (!fn.dirty()) fn.set_dirty();
}
}
return TRUE;
@ -3397,6 +3530,7 @@ void TForm::init()
_isnew= FALSE;
_fontname= "Roman 17cpi";
_fontsize= 12;
_section_mask = "ba2100s";
_x= 0;
_y= 0;
_char_to_pos= '\0';