diff --git a/include/form.cpp b/include/form.cpp index eeef1f112..292c10884 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -282,9 +282,9 @@ void TForm_flags::print_on(ostream& out) const if (automagic) s << "A"; if (!enabled) s << "D"; if (!shown) s << "H"; + if (memo) s << "M"; if (finkl) s << "F"; if (finkr) s << "K"; - if (memo) s << "M"; if (s.not_empty()) out << " FLAGS \"" << s << '"' << endl; @@ -496,7 +496,13 @@ bool TForm_item::read_from(const TRectype& prof) TString p(prof.get("PROMPT")); if (p.not_empty()) { - if (p == "_") p.cut(0); + if (p[0] == '\xFE') p.cut(0); + const int l = p.len(); + if (l > 0 && p[l-1] == '\xFF') + { + p[l-1] = ' '; + p << '\0'; + } _prompt = p; changed = TRUE; } @@ -509,33 +515,23 @@ bool TForm_item::read_from(const TRectype& prof) } TToken_string special(prof.get("SPECIAL"),'\n'); - for (i = 0; i < special.items(); i++) + const int sp_items = special.items(); + for (i = 0; i < sp_items; i++) { - if (i == special.items()-1) - { - TToken_string fink(special.get(i)); - _col_head = fink.get(0); - _ofs = fink.get_int(1); - _flag.finkl = fink.get_char(2) == 'X'; - _flag.finkr = fink.get_char(3) == 'X'; - } - else - { - TToken_string sp(special.get(i), '$'); - TString key(sp.get(0)); - TString val(sp.get(1)); + 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"); + 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"); } return TRUE; @@ -549,8 +545,11 @@ 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()); + if (_prompt.empty()) _prompt << '\xFE' << '\0'; + const int l = _prompt.len(); + const char c = _prompt[l-1]; + if (c==' ') _prompt[l-1]='\xFF'; + prof.put("PROMPT", _prompt); prof.put("ATTIVO", shown() ? "X" : " "); // specials: se e' stato cambiato, la tokenstring del valore contiene @@ -574,11 +573,6 @@ void TForm_item::print_on(TRectype& prof) special.add(sp); } } - TString fink; - fink << _col_head << "|"; - fink << _ofs << "|"; fink << (_flag.finkl ? "X" : " ") <<"|"; - fink << (_flag.finkr ? "X" : " "); - special.add(fink); prof.put("SPECIAL", special); } } @@ -595,6 +589,23 @@ void TForm_item::enable( show(on); } +void TForm_item::set_special_value(const char* s, const char* val) +{ + TToken_string& tt = (TToken_string&) _special[s]; + tt.add(val,1); + if (tt.items()==3) tt.add("X"); +} + +const char* TForm_item::get_special_item(const char* s, int n) const +{ + TAssoc_array& sp = (TAssoc_array&)_special; + if (sp.is_key(s)) + { + TToken_string& tt = (TToken_string&) sp[s]; + return tt.get(n); + } else return ""; +} + void TForm_item::string_at(int x, int y, const char* s) { if (shown()) @@ -2320,13 +2331,13 @@ bool TPrint_section::detail_field_handler(TMask_field& f, KEY k) // gna' TForm_item& fi = section.field(field); - msk.enable(F_OPTIONS, fi.special_items() > 0); + msk.enable(F_OPTIONS, fi.special_items() > 3); 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) + if (fi.special_items() > 3) { msk.set_handler(F_OPTIONS, special_field_handler); @@ -3762,7 +3773,7 @@ bool TForm::validate(TForm_item& f, TToken_string&) void TForm::print_on(ostream& out) const { main_app().begin_wait(); - + if (relation()) { out << *relation() << "\nEND" << endl; @@ -3869,6 +3880,7 @@ bool TForm::write_profile() { const char sechar[4] = { 'B', 'F', 'G', 'H' }; + get_compulsory_specials(); TLocalisamfile form(LF_FORM); form.zero(); form.put("TIPOPROF",_name); @@ -4034,6 +4046,7 @@ void TForm::read( if (_code.not_empty()) read_profile(); // read from LF_RFORM file + set_compulsory_specials(); TPrinter& pr = printer(); pr.set_offset(_y,_x); pr.set_char_size(_fontsize); @@ -4043,6 +4056,68 @@ void TForm::read( main_app().end_wait(); } +void TForm::set_compulsory_specials() +{ + const char sechar[3] = { 'B', 'F', 'H' }; + + for (int sn = 0; sn < 3; sn++) + { + const char sc = sechar[sn]; + for (pagetype pt = odd_page; pt <= last_page; pt = pagetype(pt+1)) + { + TPrint_section* sec = exist(sc, pt); + if (sec != NULL) + { + const word fields = sec->fields(); + const bool col_wise = sec->columnwise(); + for (word i = 0; col_wise && i < fields; i++) + { + TForm_item& fi = sec->field(i); + if (fi.special_items()>0) + { + fi.set_col_head(fi.get_special_value("INTESTAZIONE")); + fi.ofs() = (short)atoi(fi.get_special_value("OFFSET")); + TString fnk(fi.get_special_value("FINCATURA")); + fi.set_finkl(fnk[0]!='X'); // !finkl significa fincatura abilitata + fi.set_finkr(fnk[1]!='X'); // !finkr significa fincatura abilitata + } + } + } + } + } +} + +void TForm::get_compulsory_specials() +{ + const char sechar[3] = { 'B', 'F', 'H' }; + + for (int sn = 0; sn < 3; sn++) + { + const char sc = sechar[sn]; + for (pagetype pt = odd_page; pt <= last_page; pt = pagetype(pt+1)) + { + TPrint_section* sec = exist(sc, pt); + if (sec != NULL) + { + const word fields = sec->fields(); + const bool col_wise = sec->columnwise(); + for (word i = 0; col_wise && i < fields; i++) + { + TForm_item& fi = sec->field(i); + if (fi.special_items()>0) + { + fi.set_special_value("INTESTAZIONE", fi.col_head()); + fi.set_special_value("OFFSET", format("%d",fi.ofs())); + TString fnk(fi.finkl()? " " : "X"); + fnk << (fi.finkr() ? " " : "X"); + fi.set_special_value("FINCATURA",fnk); + } + } + } + } + } +} + void TForm::set_fincatura(const char* s) { strncpy(_fink,s,sizeof(_fink)); diff --git a/include/form.h b/include/form.h index 3a0220e92..a822c5626 100755 --- a/include/form.h +++ b/include/form.h @@ -200,6 +200,12 @@ protected: // @cmember Scrive un profilo su file (vedi ) bool write_profile(); + // @cmember Resetta gli specials obbligatori per ogni form_item (header, offset e fincatura) + // per comodita' di utilizzo dei membri _col_head, _ofs, finkl e finkr di TForm_item. + void set_compulsory_specials(); + // @cmember Legge gli specials obbligatori prima di scriverli + void get_compulsory_specials(); + // @cmember Ritorna il numero di pagina correntemente in stampa word page(const TPrinter& p) const; // @cmember Effettua il posizionamento manuale del modulo @@ -633,7 +639,8 @@ protected: // @cmember Stampa una stringa alla posizione indicata void string_at(int x, int y, const char* s); - // @cmember Cerca la stringa

tra gli item e ne ritorna l'

-esimo elemnto (NON IMPLEMENTATA) + // @cmember Cerca nella definizione della variabile

e ne ritorna + // l'

-esimo elemento (0=tipo, 1=valore, 2=descrizione) const char* get_special_item(const char* s, int n) const; // @access Public Member @@ -820,18 +827,18 @@ public: TAssoc_array& specials() const { return (TAssoc_array&)_special; } - // @cmember NON IMPLEMENTATA + // @cmember Riempie il TString_array

passato per reference con i nomi delle variabili int get_special_names(TString_array& r); - // @cmember Ritorna il secondo elemento dell'item corrispondente alla stringa

- // (chiama che NON E' IMPLEMENTATA) + // @cmember Ritorna il valore dello special corrispondente al nome

+ // (chiama ) const char* get_special_value(const char* s) const { return get_special_item(s, 1); } - // @cmember Ritorna il primo elemento dell'item corrispondente alla stringa

- // (chiama che NON E' IMPLEMENTATA) + // @cmember Ritorna il tipo dello special corrispondente al nome

+ // (chiama ) const char* get_special_type (const char* s) const { return get_special_item(s, 0); } - // @cmember Ritorna il terzo elemento dell'item corrispondente alla stringa

- // (chiama che NON E' IMPLEMENTATA) + // @cmember Ritorna la descrizione dello special corrispondente al nome

+ // (chiama ) const char* get_special_desc (const char* s) const { return get_special_item(s, 2); }