From c163b8e1e7cc8ad78f7ac240b8e64275af42167c Mon Sep 17 00:00:00 2001 From: villa Date: Thu, 14 Dec 1995 10:45:17 +0000 Subject: [PATCH] Megamodifica form editor git-svn-id: svn://10.65.10.50/trunk@2285 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba2.cpp | 4 +- ba/ba2.h | 1 - ba/ba2.url | 32 -- ba/ba2100.cpp | 668 +--------------------------- ba/ba2100b.uml | 6 +- ba/ba2100f.uml | 64 ++- ba/ba2100s.uml | 168 ++++++- ba/ba2500.cpp | 2 - ba/baformed.cpp | 667 ++++++++++++++++++++++++++++ ba/baformed.h | 14 +- ba/bafrm.h | 93 ++++ include/form.cpp | 1099 ++++++++++++++++++++++++++++++++-------------- include/form.h | 185 +++++--- include/mask.cpp | 42 ++ include/mask.h | 4 + 15 files changed, 1911 insertions(+), 1138 deletions(-) create mode 100755 ba/baformed.cpp create mode 100755 ba/bafrm.h diff --git a/ba/ba2.cpp b/ba/ba2.cpp index 1381441ed..5bfb6f683 100755 --- a/ba/ba2.cpp +++ b/ba/ba2.cpp @@ -4,7 +4,7 @@ #include "ba2.h" -#define usage "Error - usage : %s -[0,1,2,3,4]" +#define usage "Error - usage : %s -[0,1,2,3]" int main(int argc, char** argv) { @@ -23,8 +23,6 @@ int main(int argc, char** argv) #endif case 3: rt = ba2400(argc, argv) ; break; - case 4: - rt = ba2500(argc, argv) ; break; default: error_box(usage, argv[0]) ; rt = 1; break; } diff --git a/ba/ba2.h b/ba/ba2.h index d29bb021a..6c46bc821 100755 --- a/ba/ba2.h +++ b/ba/ba2.h @@ -5,7 +5,6 @@ int ba2100(int argc, char* argv[]); int ba2200(int argc, char* argv[]); int ba2300(int argc, char* argv[]); int ba2400(int argc, char* argv[]); -int ba2500(int argc, char* argv[]); #endif // __BA2_H diff --git a/ba/ba2.url b/ba/ba2.url index b333b6136..0c6e99acb 100755 --- a/ba/ba2.url +++ b/ba/ba2.url @@ -74,35 +74,3 @@ MENU BAR_ITEM(1) SUBMENU MENU_FILE "~File" - MENUBAR MENU_BAR(4) - - MENU MENU_BAR(4) - SUBMENU MENU_FILE "~File" - SUBMENU BAR_ITEM(1) "~Dati" - SUBMENU BAR_ITEM(2) "~Testa" - SUBMENU BAR_ITEM(3) "~Corpo" - SUBMENU BAR_ITEM(4) "~Piede" - SUBMENU BAR_ITEM(5) "~Sfondo" - - MENU BAR_ITEM(1) - ITEM MENU_ITEM(11) "~Relazione" - ITEM MENU_ITEM(12) "~Parametri" - ITEM MENU_ITEM(13) "Caratteri ~fincatura" - - MENU BAR_ITEM(2) - ITEM MENU_ITEM(21) "~Normale" - ITEM MENU_ITEM(22) "~Pari" - ITEM MENU_ITEM(23) "~Prima" - ITEM MENU_ITEM(24) "~Ultima" - - MENU BAR_ITEM(3) - ITEM MENU_ITEM(31) "~Normale" - ITEM MENU_ITEM(32) "~Pari" - ITEM MENU_ITEM(33) "~Primo" - ITEM MENU_ITEM(34) "~Ultimo" - - MENU BAR_ITEM(4) - ITEM MENU_ITEM(41) "~Normale" - ITEM MENU_ITEM(42) "~Pari" - ITEM MENU_ITEM(43) "~Primo" - ITEM MENU_ITEM(44) "~Ultimo" diff --git a/ba/ba2100.cpp b/ba/ba2100.cpp index 5279fa033..d6d2304b7 100755 --- a/ba/ba2100.cpp +++ b/ba/ba2100.cpp @@ -1,671 +1,5 @@ +#include "ba2.h" #include "baformed.h" -#include "ba2100.h" -#include -// ----------------------------------------------------------------- -// maschera per le finkature -// ----------------------------------------------------------------- - -#include "ba21fn.h" - -class TFink_mask : public TMask -{ - TToken_string _chars; - - enum pos { // posizioni scatoletta - xl = 1, - xm = 15, - xr = 29, - yt = 1, - ym = 5, - yb = 9, - ofs = 36 - }; - - protected: - - void paint_example(); - - virtual void handler(WINDOW win, EVENT* ep); - static bool char_handler(TMask_field& f, KEY k); - virtual void start_run(); - virtual bool stop_run(KEY k); - virtual PNT log2dev(long x, long y) const; - - public: - - TToken_string& get_chars() { return _chars; } - - TFink_mask(const char* def) : TMask("ba21fn"), _chars(def,',') - { - set_handler(C_TR, char_handler); - set_handler(C_TL, char_handler); - set_handler(C_TM, char_handler); - set_handler(C_BR, char_handler); - set_handler(C_BL, char_handler); - set_handler(C_BM, char_handler); - set_handler(C_CM, char_handler); - set_handler(C_CR, char_handler); - set_handler(C_CL, char_handler); - set_handler(C_HR, char_handler); - set_handler(C_VR, char_handler); - } - virtual ~TFink_mask() {} -}; - -PNT TFink_mask::log2dev(long x, long y) const -{ - PNT p; - p.h = ((short)x+1)*CHARX; - p.v = (short)y*ROWY; - return p; -} - -void TFink_mask::handler(WINDOW win, EVENT* ep) -{ - TMask::handler(win, ep); - if (ep->type == E_UPDATE) - { - // pittura le righette - rect(xl, yt, xr+1, yb+1); - line(xl, ym, xr, ym); - line(xm, yt, xm, yb); - paint_example(); - } -} - -void TFink_mask::paint_example() -{ - // pittura un'immaginetta finculata - // on the right of the mask - TString line(xr); - set_font(XVT_FFN_COURIER); - set_color(MASK_DARK_COLOR,MASK_BACK_COLOR); - set_opaque_text(TRUE); - - for (int i = yt; i <= yb; i++) - { - line.spaces(); - if (i == yt) - { - line.fill(_chars.get_char(9)); - line[xl-1] = _chars.get_char(0); - line[xm-1] = _chars.get_char(1); - line[xr-1] = _chars.get_char(2); - } - else if (i == ym) - { - line.fill(_chars.get_char(9)); - line[xl-1] = _chars.get_char(6); - line[xm-1] = _chars.get_char(7); - line[xr-1] = _chars.get_char(8); - } - else if (i == yb) - { - line.fill(_chars.get_char(9)); - line[xl-1] = _chars.get_char(3); - line[xm-1] = _chars.get_char(4); - line[xr-1] = _chars.get_char(5); - } - else - { - line[xl-1] = _chars.get_char(10); - line[xm-1] = _chars.get_char(10); - line[xr-1] = _chars.get_char(10); - } - stringat(ofs, i, line); - } -} - -void TFink_mask::start_run() -{ - TMask::start_run(); - for (int i = 101; i <= 111; i++) - { - field(i).allow_pipe(); // allowa la pipa, se no son cazzi - field(i).set(_chars.get(i - 101)); - } -} - -bool TFink_mask::stop_run(KEY k) -{ - if (k == K_ENTER) - { - for (int i = 101; i <= 111; i++) - _chars.add(field(i).get(), i-101); - } - return TMask::stop_run(k); -} - -bool TFink_mask::char_handler(TMask_field& f, KEY k) -{ - if (f.focusdirty() && k == K_TAB) - { - TFink_mask& m = (TFink_mask&)f.mask(); - TToken_string& ch = m.get_chars(); - ch.add(f.get(), f.dlg() - 101); - m.paint_example(); - } - return TRUE; -} - - -// ----------------------------------------------------------------- -// form editor -// ----------------------------------------------------------------- - - -TForm_editor::TForm_editor() : _form(NULL), _extra(FALSE), _m(NULL) -{} - -TForm_editor::~TForm_editor() -{} - -bool TForm_editor::create() -{ - TApplication::create(); - - const char* form = NULL; - long code = 0; - - for (int a = 2; a < argc(); a++) - { - if (stricmp(argv(a), "-E") == 0) - { - _extra = TRUE; - continue; - } - - if (form == NULL) - form = argv(a); - else - if (code == 0) - code = atol(argv(a)); - } - - enable_menu_item(M_FILE_PRINT); - if ((form && code) || (form && code == 0 && _extra)) - { - _form = new TForm(form, (code!=0) ? format("%05ld",code) : "", _extra ? 2 : 1); - if (!_extra) dispatch_e_menu(MENU_ITEM(13)); - } - else - dispatch_e_menu(MENU_ITEM(14)); - - _m = new TMask("ba2100b"); - if (form) - { - _m->set(F_BASE, form); - _m->disable(F_BASE); - } - - if (code) _m->set(F_CODE, code); - - return TRUE; -} - -bool TForm_editor::destroy() -{ - if (_form) delete _form; - if (_m) delete _m; - return TApplication::destroy(); -} - - -bool TForm_editor::menu(MENU_TAG tag) -{ - char sec = 'B'; - pagetype pt = odd_page; - bool quit = FALSE; - - switch(tag) - { - case MENU_ITEM(11): - sec = 'R'; pt = odd_page; break; - case MENU_ITEM(12): - sec = 'D'; pt = odd_page; break; - case MENU_ITEM(13): - sec = 'K'; break; - case MENU_ITEM(14): - quit = ask_profile(); - sec = 'B'; pt = odd_page; break; - case MENU_ITEM(15): // formato numeri - sec = 'J'; break; - case MENU_ITEM(16): // formato date - sec = 'Y'; break; - case MENU_ITEM(21): - sec = 'H'; pt = odd_page; break; - case MENU_ITEM(22): - sec = 'H'; pt = even_page; break; - case MENU_ITEM(23): - sec = 'H'; pt = first_page; break; - case MENU_ITEM(24): - sec = 'H'; pt = last_page; break; - case MENU_ITEM(31): - sec = 'B'; pt = odd_page; break; - case MENU_ITEM(32): - sec = 'B'; pt = even_page; break; - case MENU_ITEM(33): - sec = 'B'; pt = first_page; break; - case MENU_ITEM(34): - sec = 'B'; pt = last_page; break; - case MENU_ITEM(41): - sec = 'F'; pt = odd_page; break; - case MENU_ITEM(42): - sec = 'F'; pt = even_page; break; - case MENU_ITEM(43): - sec = 'F'; pt = first_page; break; - case MENU_ITEM(44): - sec = 'F'; pt = last_page; break; - case MENU_ITEM(51): - sec = 'G'; pt = odd_page; break; - case MENU_ITEM(52): - sec = 'G'; pt = even_page; break; - case MENU_ITEM(53): - sec = 'G'; pt = first_page; break; - case MENU_ITEM(54): - sec = 'G'; pt = last_page; break; - default: - break; - } - - if (!quit) edit(sec, pt); - return TRUE; -} - -void TForm_editor::print() -{ - _form->print(); -} - -bool TForm_editor::file_handler(TMask_field& f, KEY k) -{ - bool ok = TRUE; - - if (k == K_TAB && f.dirty()) - { - const char* n = f.get(); - if (*n > ' ') - { - const char* d = prefix().description(n); - if (*d == '\0') ok = error_box("Nome di file o tabella errato"); - f.mask().set(f.dlg()+1, d); - } - } - - return ok; -} - -bool TForm_editor::cod_handler(TMask_field& f, KEY k) -{ - bool ok = TRUE; - - if (k==K_TAB && f.dirty()) - { - TLocalisamfile frm(LF_FORM); - frm.zero(); - frm.put("TIPOPROF",f.mask().get(F_BASE)); - frm.put("CODPROF",f.mask().get(F_CODE)); - if (frm.read() == NOERR) - f.mask().set(F_DESC,frm.get("DESC")); - } - return ok; -} - -bool TForm_editor::edit_fincatura() -{ - TFink_mask m(_form->get_fincatura()); - bool dirty = FALSE; - - if (m.run() == K_ENTER) - { - _form->set_fincatura(m.get_chars()); - dirty = TRUE; - } - return dirty; -} - -bool TForm_editor::date_example(TMask_field& f, KEY k) -{ - if (k == K_TAB && f.focusdirty()) - { - TMask& m = f.mask(); - char format[6]; - format[0] = m.get(F_DFORMAT)[0]; - format[1] = m.get(F_DDAY )[0]; - format[2] = m.get(F_DMONTH )[0]; - format[3] = m.get(F_DYEAR )[0]; - format[4] = m.get(F_DSEP )[0]; - format[5] = '\0'; - - TDate dd(TODAY); - TFormatted_date d(dd); - - d.set_format(format); - m.set(F_DEXAMPLE, d.string()); - } - return TRUE; -} - -bool TForm_editor::edit_formato_numero() -{ - bool dirty = FALSE; - - TMask m("ba21nm"); - if (dirty = (m.run() == K_ENTER)) - { - int w = m.get_int(F_WIDTH); - int d = m.get_int(F_DECIMALS); - TString p(m.get(F_PICTURE)); - - _form->change_number_format(w, d, p); - } - return dirty; - -} - -bool TForm_editor::edit_formato_data() -{ - bool dirty = FALSE; - char format[6] = { "1444-" }; - TMask m("ba21dt"); - - m.set_handler(F_DFORMAT, date_example); - m.set_handler(F_DDAY, date_example); - m.set_handler(F_DMONTH, date_example); - m.set_handler(F_DYEAR, date_example); - m.set_handler(F_DSEP, date_example); - - TDate dd(TODAY); - TFormatted_date d(dd); - d.set_format(format); - - m.set(F_DFORMAT, "1"); - m.set(F_DDAY, "4"); - m.set(F_DMONTH, "4"); - m.set(F_DYEAR, "4"); - m.set(F_DSEP, "-"); - m.set(F_DEXAMPLE, d.string()); - - if (dirty = (m.run() == K_ENTER)) - { - format[0] = m.get(F_DFORMAT)[0]; - format[1] = m.get(F_DDAY )[0]; - format[2] = m.get(F_DMONTH )[0]; - format[3] = m.get(F_DYEAR )[0]; - format[4] = m.get(F_DSEP )[0]; - format[5] = '\0'; - - _form->change_date_format(format); - } - return dirty; - -} - -bool TForm_editor::edit_relation() -{ - TMask m("ba2100r"); - TSheet_field& s = (TSheet_field&)m.field(F_ITEMS); - s.sheet_mask().set_handler(101, file_handler); - - TRelation* & rel = _form->_relation; - TCursor* & cur = _form->_cursor; - - if (rel) - { - s.rows_array() = _form->rel_desc().get_all_desc(); - // Disable meaningless fields for main file - s.disable_cell(0, 2); // Join - s.disable_cell(0, 4); // Alias - } - - if (m.run() != K_ENTER || !m.dirty()) - return FALSE; - - if (rel) - { - delete cur; cur = NULL; - delete rel; rel = NULL; - } - - TToken_string& r = s.row(0); - TString16 name = r.get(0); - - if (name.not_empty()) - { - int logicnum = atoi(name); - - int alias = 0, to = 0, key = r.get_int(3); - TString80 exp = r.get(5); - - rel = (logicnum > 0) ? new TRelation(logicnum) : new TRelation(name); - cur = new TCursor(rel, exp, key); - - for (int i = 1; i < s.items(); i++) - { - TToken_string& r = s.row(i); - name = r.get(0); logicnum = atoi(name); - r.get(); // Skip description - to = name2log(r.get()); // Join - key = r.get_int(); // Key - alias = r.get_int(); // Alias - exp = r.get(); // Expression - - const int l = exp.len(); - for (int j = 0; j < l; j++) - if (exp[j] == ' ') exp[j] = '|'; - - if (logicnum > 0) - rel->add(logicnum, exp, key, to, alias); // join file - else - rel->add(name, exp, key, to, alias); // join table - } - - _form->rel_desc().change_relation(*rel, s.rows_array()); - } - - return TRUE; -} - - -bool TForm_editor::edit(char s, pagetype t) -{ - bool dirty = FALSE; - - 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 - { - TString80 caption; - switch(s) - { - case 'F': - caption << "Piede"; break; - case 'G': - caption << "Sfondo"; break; - case 'H': - caption << "Testa"; break; - default: - caption << "Corpo"; break; - } - - switch(t) - { - case first_page: - caption << " della prima pagina"; break; - case even_page: - caption << " delle pagine pari"; break; - case last_page: - caption << " dell'ultima pagina"; break; - default: - caption << " standard"; break; - } - - dirty = TRUE; - if (!_form->exist(s, t)) - { - const KEY k = yesnocancel_box("La sezione %s non esiste:\n" - "si desidera generare quella standard?", - (const char*)caption); - if (k == K_ESC) - dirty = FALSE; - else - { - TPrint_section* sec = _form->exist(s, t, TRUE); - if (k == K_YES) - { - const TPrint_section* def = _form->exist(s, odd_page); - if (def) *sec = *def; - else dirty = FALSE; - } - } - } - if (dirty) - dirty = _form->section(s, t).edit(caption); - } - - if (dirty && yesno_box("Salvare le modifiche?")) - { - if (_form->code() == "") - { - 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(13)); - return dirty; -} - - -bool TForm_editor::form_config() const -{ - TFilename cnfnam(_form->name()); cnfnam.ext("ini"); - - TString16 cnfpar; - if (_form->code() != "") - cnfpar << _form->code(); - else - cnfpar << "Main"; - - TConfig cnf(cnfnam, cnfpar); - bool ok = FALSE; - - const TFilename maskname(cnf.get("EdMask")); - if (maskname.empty()) - return warning_box("Nessun parametro da configurare"); - - TMask m(maskname); - - // carica campi - for (int i = 0; i < m.fields(); i++) - { - TMask_field& f = m.fld(i); - const TFieldref* fref = f.field(); - if (fref != NULL) - { - const char* fname = fref->name(); - if (fname != NULL) - { - const TString& oldvl = cnf.get(fname); - if (!oldvl.empty()) - f.set(oldvl); - } - } - } - - if (m.run() == K_ENTER && m.dirty()) - { - // aggiusta campi - for (i = 0; i < m.fields(); i++) - { - TMask_field& f = m.fld(i); - if (f.dirty()) - { - const TFieldref* fref = f.field(); - if (fref != NULL) - cnf.set(fref->name(), f.get(), NULL, TRUE); - } - } - ok = TRUE; - } - - return ok; -} - -bool TForm_editor::ask_profile() -{ - - _m->set_handler(F_CODE, cod_handler); - - // choose form from mask - KEY k; - while ((k = _m->run()) != K_QUIT) - { - TString16 fform = _m->get(F_BASE); - TString80 fdesc = _m->get(F_DESC); - long fcode = _m->get_long(F_CODE); - if (!_extra && (fcode == 0 || fform.left(3) == "BOL")) - { - error_box("Non e' possibile modificare i profili standard o i bollettini.") ; - continue; - } - if (k == K_ENTER) - { - if (_form != NULL) delete _form; - _form = new TForm(fform, (fcode!=0) ? format("%05ld",fcode) : "", _extra ? 2 :1, fdesc); - break; - } - else if (k == K_DEL) - { - if (fcode != 0 && yesno_box("Confermare la cancellazione del profilo %05ld", fcode)) - { - TLocalisamfile frm(LF_FORM); - frm.zero(); - frm.put("TIPOPROF", fform); - if (fcode != 0 ) - frm.put("CODPROF", format("%05ld",fcode)); - if (frm.read() == NOERR) - frm.remove(); - TLocalisamfile rfr(LF_RFORM); - rfr.zero(); - rfr.put("TIPOPROF", fform); - rfr.put("CODPROF", format("%05ld",fcode)); - if (rfr.read() == NOERR) - { - for ( ; atol(rfr.get("CODPROF")) == fcode && rfr.get("TIPOPROF") == fform; rfr.next()) - rfr.remove(); - } - _m->set(F_CODE,""); - _m->set(F_BASE,""); - _m->set(F_DESC,""); - } - } - } - if (k == K_QUIT) - { - dispatch_e_menu(M_FILE_QUIT); - return TRUE; - } - - return FALSE; -} int ba2100(int argc, char* argv[]) { diff --git a/ba/ba2100b.uml b/ba/ba2100b.uml index ea6c229d1..8eb54710a 100755 --- a/ba/ba2100b.uml +++ b/ba/ba2100b.uml @@ -1,4 +1,4 @@ -#include "ba2100.h" +#include "bafrm.h" PAGE "Scelta profilo" -1 -1 75 6 @@ -16,7 +16,7 @@ BEGIN OUTPUT F_DESC DESC CHECKTYPE REQUIRED END - + NUMBER F_CODE 5 BEGIN PROMPT 2 2 "Codice profilo " @@ -33,7 +33,7 @@ BEGIN OUTPUT F_CODE CODPROF OUTPUT F_DESC DESC END - + STRING F_DESC 50 BEGIN PROMPT 2 3 "Descrizione " diff --git a/ba/ba2100f.uml b/ba/ba2100f.uml index ac535e690..51461db1a 100755 --- a/ba/ba2100f.uml +++ b/ba/ba2100f.uml @@ -1,20 +1,25 @@ -#include "ba2100.h" +#include "bafrm.h" TOOLBAR "" 0 20 0 2 +BUTTON F_OPTIONS 10 2 +BEGIN +PROMPT -13 -1 "Opzioni" +END + BUTTON DLG_OK 10 2 BEGIN -PROMPT -12 -1 "" +PROMPT -23 -1 "" END BUTTON DLG_CANCEL 10 2 BEGIN -PROMPT -22 -1 "" +PROMPT -33 -1 "" END ENDPAGE -PAGE "CAMPO DI STAMPA" -1 -1 78 20 +PAGE "CAMPO DI STAMPA" -1 -1 78 21 LIST F_CLASS 10 BEGIN @@ -77,6 +82,21 @@ MESSAGE COPY,F_HEIGHT GROUP 7 END +BOOLEAN F_FINKL +BEGIN + PROMPT 40 18 "Fincatura prima" +END + +BOOLEAN F_FINKR +BEGIN + PROMPT 63 18 "Fincatura dopo" +END + +NUMBER F_SPACES 2 +BEGIN + PROMPT 1 18 "N. spazi davanti al campo " +END + STRING F_PICTURE 80 40 BEGIN PROMPT 1 4 "Formato " @@ -167,48 +187,48 @@ END STRING F_FILE1 80 60 BEGIN -PROMPT 2 12 "Archivio " +PROMPT 2 11 "Archivio " HELP "Nome dell'archivio relativo al campo" FLAGS "D" END BUTTON F_BUT_FILE1 2 1 BEGIN -PROMPT 73 12 "*" +PROMPT 73 11 "*" PICTURE 109 GROUP 7 END STRING F_FIELD1 80 60 BEGIN -PROMPT 2 13 "Campo 1 " +PROMPT 2 12 "Campo 1 " HELP "Nome del campo su file" FLAGS "D" END BUTTON F_BUT_FIELD1 2 1 BEGIN -PROMPT 73 13 "*" +PROMPT 73 12 "*" PICTURE 109 GROUP 7 END STRING F_FIELDREF1 20 16 BEGIN -PROMPT 60 14 "" +PROMPT 60 13 "" FLAGS "D" END NUMBER F_FROM1 2 BEGIN -PROMPT 2 14 "Da " +PROMPT 2 13 "Da " FLAGS "U" GROUP 7 END NUMBER F_TO1 2 BEGIN -PROMPT 22 14 "A " +PROMPT 22 13 "A " FLAGS "U" GROUP 7 END @@ -216,56 +236,56 @@ END STRING F_FILE2 60 BEGIN -PROMPT 2 15 "Archivio " +PROMPT 2 14 "Archivio " HELP "Nome dell'archivio relativo al campo" FLAGS "D" END BUTTON F_BUT_FILE2 2 1 BEGIN -PROMPT 73 15 "*" +PROMPT 73 14 "*" PICTURE 109 GROUP 7 END STRING F_FIELD2 60 BEGIN -PROMPT 2 16 "Campo 2 " +PROMPT 2 15 "Campo 2 " HELP "Nome del campo su file" FLAGS "D" END BUTTON F_BUT_FIELD2 2 1 BEGIN -PROMPT 73 16 "*" +PROMPT 73 15 "*" PICTURE 109 GROUP 7 END STRING F_FIELDREF2 16 BEGIN -PROMPT 60 17 "" +PROMPT 60 16 "" FLAGS "D" END NUMBER F_FROM2 2 BEGIN -PROMPT 2 17 "Da " +PROMPT 2 16 "Da " FLAGS "U" GROUP 7 END NUMBER F_TO2 2 BEGIN -PROMPT 22 17 "A " +PROMPT 22 16 "A " FLAGS "U" GROUP 7 END -GROUPBOX DLG_NULL 78 8 -BEGIN -PROMPT 1 11 "Campi su file" -END +//GROUPBOX DLG_NULL 78 8 +//BEGIN +//PROMPT 1 11 "Campi su file" +//END ENDPAGE diff --git a/ba/ba2100s.uml b/ba/ba2100s.uml index bc93fa593..41209fb92 100755 --- a/ba/ba2100s.uml +++ b/ba/ba2100s.uml @@ -1,13 +1,13 @@ -#include "ba2100.h" +#include "bafrm.h" -PAGE "SEZIONE DI STAMPA" -1 -1 34 14 +PAGE "SEZIONE DI STAMPA" -1 -1 78 18 NUMBER F_HEIGHT 3 BEGIN PROMPT 1 1 "Altezza in righe " END -GROUP DLG_NULL -1 10 +GROUP DLG_NULL -1 6 BEGIN PROMPT 0 2 "Dati comuni " END @@ -15,65 +15,85 @@ END NUMBER F_FLEN 3 BEGIN FLAGS "D" -PROMPT 1 3 "Lunghezza foglio " +PROMPT 3 3 "Lunghezza foglio " +END + +STRING F_CTP 1 +BEGIN +PROMPT 40 3 "Carattere posizionamento" +HELP "Carattere da utilizzare per il posizionamento del modulo" END LIST F_FONT 2 16 BEGIN -PROMPT 1 4 "Font " +PROMPT 3 4 "Font " ITEM "Courier New|Courier New" HELP "Font di stampa su video o stampante" END LIST F_SIZE 3 BEGIN -PROMPT 1 5 "Dimensione " +PROMPT 53 4 "Dimensione " ITEM "12|12" HELP "Dimensioni del carattere di stampa" END -STRING F_CTP 1 -BEGIN -PROMPT 1 6 "Carattere di posizionamento " -HELP "Carattere da utilizzare per il posizionamento del modulo" -END TEXT DLG_NULL BEGIN -PROMPT 1 7 "Colonne di posizionamento" +PROMPT 40 5 "Colonne di posizionamento" END NUMBER F_IPX 3 BEGIN -PROMPT 24 7 "" +PROMPT 64 5 "" HELP "Coordinata X di posizionamento iniziale" END NUMBER F_FPX 3 BEGIN -PROMPT 29 7 "" +PROMPT 70 5 "" HELP "Coordinata X di posizionamento finale" END NUMBER F_IPY 3 BEGIN -PROMPT 1 8 "Riga di posizionamento " +PROMPT 3 5 "Riga di posizionamento " HELP "Coordinata Y di posizionamento" END NUMBER F_X 3 BEGIN -PROMPT 1 9 "Spostamento orizzontale " +PROMPT 3 6 "Spostamento orizzontale " END NUMBER F_Y 3 BEGIN -PROMPT 1 10 "Spostamento verticale " +PROMPT 40 6 "Spostamento verticale " +END + +SPREADSHEET F_FIELDS 78 8 +BEGIN + PROMPT 1 8 "" + ITEM "ID@3" + ITEM "Descrizione@40" + ITEM "Intestazione@40" + ITEM "Pr" + ITEM "Y@2" + ITEM "Lun." + ITEM "X@2" + ITEM "Col." + ITEM "Spazi" + ITEM "Finc. sin." + ITEM "Finc. dx." + ITEM "Tipo@10" + ITEM "Formato@45" END -BUTTON DLG_EDIT 10 2 + +BUTTON DLG_OK 10 2 BEGIN -PROMPT -12 -1 "~Edit" +PROMPT -12 -1 "" MESSAGE EXIT,K_ENTER END @@ -83,5 +103,113 @@ PROMPT -22 -1 "" END ENDPAGE - +ENDMASK + + +PAGE "Dettaglio campo" -1 -1 65 15 + +BUTTON 100 10 2 +BEGIN + PROMPT -14 -1 "Dettaglio" +END + +NUMBER 101 3 +BEGIN + PROMPT 1 1 "ID " +END + +STRING 102 40 +BEGIN + PROMPT 1 2 "Descrizione " + FLAGS "G" +END + +STRING 103 40 +BEGIN + PROMPT 1 3 "Intestazione " + FLAGS "G" +END + +BOOLEAN 104 +BEGIN + PROMPT 1 4 "Non Stampare " +END + +NUMBER 105 2 +BEGIN + PROMPT 1 7 "Y " + FLAGS "G" +END + +NUMBER 106 2 +BEGIN + PROMPT 1 6 "Lunghezza " + FLAGS "G" +END + +NUMBER 107 2 +BEGIN + PROMPT 1 5 "X " + FLAGS "G" +END + +NUMBER 108 2 +BEGIN + PROMPT 1 8 "Colonna " + FLAGS "G" +END + +NUMBER 109 2 +BEGIN + PROMPT 1 9 "Spazi inizio " + FLAGS "G" +END + +BOOLEAN 110 +BEGIN + PROMPT 1 10 "Finc. prima " + FLAGS "G" +END + +BOOLEAN 111 +BEGIN + PROMPT 1 10 "Finc. dopo " + FLAGS "G" +END + +LIST 112 10 +BEGIN + PROMPT 1 11 "Tipo " + ITEM "STRINGA|Testo" + ITEM "NUMERO|Numero" + ITEM "DATA|Data" + ITEM "LISTA|Lista" + ITEM "GRUPPO|Gruppo" + ITEM "LINEA|Linea" + ITEM "FIGURA|Figura" +END + +STRING 113 45 +BEGIN + PROMPT 1 10 "Es. formato " +END + +BUTTON DLG_DELREC 10 2 +BEGIN + PROMPT -24 -1 "~Elimina" + MESSAGE EXIT,K_DEL +END + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -34 -1 "" + MESSAGE EXIT,K_ENTER +END + +BUTTON DLG_CANCEL 10 2 +BEGIN + PROMPT -44 -1 "" +END + +ENDPAGE ENDMASK diff --git a/ba/ba2500.cpp b/ba/ba2500.cpp index 517e8e5ac..0c9e0c294 100755 --- a/ba/ba2500.cpp +++ b/ba/ba2500.cpp @@ -1,6 +1,4 @@ #include "baformed.h" -#include "ba2100.h" - class TForm_EC_editor : public TForm_editor { diff --git a/ba/baformed.cpp b/ba/baformed.cpp new file mode 100755 index 000000000..7dbff7a72 --- /dev/null +++ b/ba/baformed.cpp @@ -0,0 +1,667 @@ +#include "baformed.h" +#include +// ----------------------------------------------------------------- +// maschera per le finkature +// ----------------------------------------------------------------- + +#include "ba21fn.h" + +class TFink_mask : public TMask +{ + TToken_string _chars; + + enum pos { // posizioni scatoletta + xl = 1, + xm = 15, + xr = 29, + yt = 1, + ym = 5, + yb = 9, + ofs = 36 + }; + + protected: + + void paint_example(); + + virtual void handler(WINDOW win, EVENT* ep); + static bool char_handler(TMask_field& f, KEY k); + virtual void start_run(); + virtual bool stop_run(KEY k); + virtual PNT log2dev(long x, long y) const; + + public: + + TToken_string& get_chars() { return _chars; } + + TFink_mask(const char* def) : TMask("ba21fn"), _chars(def,',') + { + set_handler(C_TR, char_handler); + set_handler(C_TL, char_handler); + set_handler(C_TM, char_handler); + set_handler(C_BR, char_handler); + set_handler(C_BL, char_handler); + set_handler(C_BM, char_handler); + set_handler(C_CM, char_handler); + set_handler(C_CR, char_handler); + set_handler(C_CL, char_handler); + set_handler(C_HR, char_handler); + set_handler(C_VR, char_handler); + } + virtual ~TFink_mask() {} +}; + +PNT TFink_mask::log2dev(long x, long y) const +{ + PNT p; + p.h = ((short)x+1)*CHARX; + p.v = (short)y*ROWY; + return p; +} + +void TFink_mask::handler(WINDOW win, EVENT* ep) +{ + TMask::handler(win, ep); + if (ep->type == E_UPDATE) + { + // pittura le righette + rect(xl, yt, xr+1, yb+1); + line(xl, ym, xr, ym); + line(xm, yt, xm, yb); + paint_example(); + } +} + +void TFink_mask::paint_example() +{ + // pittura un'immaginetta finculata + // on the right of the mask + TString line(xr); + set_font(XVT_FFN_COURIER); + set_color(MASK_DARK_COLOR,MASK_BACK_COLOR); + set_opaque_text(TRUE); + + for (int i = yt; i <= yb; i++) + { + line.spaces(); + if (i == yt) + { + line.fill(_chars.get_char(9)); + line[xl-1] = _chars.get_char(0); + line[xm-1] = _chars.get_char(1); + line[xr-1] = _chars.get_char(2); + } + else if (i == ym) + { + line.fill(_chars.get_char(9)); + line[xl-1] = _chars.get_char(6); + line[xm-1] = _chars.get_char(7); + line[xr-1] = _chars.get_char(8); + } + else if (i == yb) + { + line.fill(_chars.get_char(9)); + line[xl-1] = _chars.get_char(3); + line[xm-1] = _chars.get_char(4); + line[xr-1] = _chars.get_char(5); + } + else + { + line[xl-1] = _chars.get_char(10); + line[xm-1] = _chars.get_char(10); + line[xr-1] = _chars.get_char(10); + } + stringat(ofs, i, line); + } +} + +void TFink_mask::start_run() +{ + TMask::start_run(); + for (int i = 101; i <= 111; i++) + { + field(i).allow_pipe(); // allowa la pipa, se no son cazzi + field(i).set(_chars.get(i - 101)); + } +} + +bool TFink_mask::stop_run(KEY k) +{ + if (k == K_ENTER) + { + for (int i = 101; i <= 111; i++) + _chars.add(field(i).get(), i-101); + } + return TMask::stop_run(k); +} + +bool TFink_mask::char_handler(TMask_field& f, KEY k) +{ + if (f.focusdirty() && k == K_TAB) + { + TFink_mask& m = (TFink_mask&)f.mask(); + TToken_string& ch = m.get_chars(); + ch.add(f.get(), f.dlg() - 101); + m.paint_example(); + } + return TRUE; +} + + +// ----------------------------------------------------------------- +// form editor +// ----------------------------------------------------------------- + + +TForm_editor::TForm_editor() : _form(NULL), _extra(FALSE), _m(NULL) +{} + +TForm_editor::~TForm_editor() +{} + +bool TForm_editor::create() +{ + TApplication::create(); + + const char* form = NULL; + long code = 0; + + for (int a = 2; a < argc(); a++) + { + if (stricmp(argv(a), "-E") == 0) + { + _extra = TRUE; + continue; + } + + if (form == NULL) + form = argv(a); + else + if (code == 0) + code = atol(argv(a)); + } + + enable_menu_item(M_FILE_PRINT); + if ((form && code) || (form && code == 0 && _extra)) + { + _form = new TForm(form, (code!=0) ? format("%05ld",code) : "", _extra ? 2 : 1); + if (!_extra) dispatch_e_menu(MENU_ITEM(14)); + } + else + dispatch_e_menu(MENU_ITEM(14)); + + _m = new TMask(selection_mask()); + if (form) + { + _m->set(F_BASE, form); + _m->disable(F_BASE); + } + + if (code) _m->set(F_CODE, code); + + return TRUE; +} + +bool TForm_editor::destroy() +{ + if (_form) delete _form; + if (_m) delete _m; + return TApplication::destroy(); +} + + +bool TForm_editor::menu(MENU_TAG tag) +{ + char sec = 'B'; + pagetype pt = odd_page; + bool quit = FALSE; + + switch(tag) + { + case MENU_ITEM(11): + sec = 'R'; pt = odd_page; break; + case MENU_ITEM(12): + sec = 'D'; pt = odd_page; break; + case MENU_ITEM(13): + sec = 'K'; break; + case MENU_ITEM(14): + quit = ask_profile(); + sec = 'B'; pt = odd_page; break; + case MENU_ITEM(15): // formato numeri + sec = 'J'; break; + case MENU_ITEM(16): // formato date + sec = 'Y'; break; + case MENU_ITEM(21): + sec = 'H'; pt = odd_page; break; + case MENU_ITEM(22): + sec = 'H'; pt = even_page; break; + case MENU_ITEM(23): + sec = 'H'; pt = first_page; break; + case MENU_ITEM(24): + sec = 'H'; pt = last_page; break; + case MENU_ITEM(31): + sec = 'B'; pt = odd_page; break; + case MENU_ITEM(32): + sec = 'B'; pt = even_page; break; + case MENU_ITEM(33): + sec = 'B'; pt = first_page; break; + case MENU_ITEM(34): + sec = 'B'; pt = last_page; break; + case MENU_ITEM(41): + sec = 'F'; pt = odd_page; break; + case MENU_ITEM(42): + sec = 'F'; pt = even_page; break; + case MENU_ITEM(43): + sec = 'F'; pt = first_page; break; + case MENU_ITEM(44): + sec = 'F'; pt = last_page; break; + case MENU_ITEM(51): + sec = 'G'; pt = odd_page; break; + case MENU_ITEM(52): + sec = 'G'; pt = even_page; break; + case MENU_ITEM(53): + sec = 'G'; pt = first_page; break; + case MENU_ITEM(54): + sec = 'G'; pt = last_page; break; + default: + break; + } + + if (!quit) edit(sec, pt); + return TRUE; +} + +void TForm_editor::print() +{ + _form->print(); +} + +bool TForm_editor::file_handler(TMask_field& f, KEY k) +{ + bool ok = TRUE; + + if (k == K_TAB && f.dirty()) + { + const char* n = f.get(); + if (*n > ' ') + { + const char* d = prefix().description(n); + if (*d == '\0') ok = error_box("Nome di file o tabella errato"); + f.mask().set(f.dlg()+1, d); + } + } + + return ok; +} + +bool TForm_editor::cod_handler(TMask_field& f, KEY k) +{ + bool ok = TRUE; + + if (k==K_TAB && f.dirty()) + { + TLocalisamfile frm(LF_FORM); + frm.zero(); + frm.put("TIPOPROF",f.mask().get(F_BASE)); + frm.put("CODPROF",f.mask().get(F_CODE)); + if (frm.read() == NOERR) + f.mask().set(F_DESC,frm.get("DESC")); + } + return ok; +} + +bool TForm_editor::edit_fincatura() +{ + TFink_mask m(_form->get_fincatura()); + bool dirty = FALSE; + + if (m.run() == K_ENTER) + { + _form->set_fincatura(m.get_chars()); + dirty = TRUE; + } + return dirty; +} + +bool TForm_editor::date_example(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty()) + { + TMask& m = f.mask(); + char format[6]; + format[0] = m.get(F_DFORMAT)[0]; + format[1] = m.get(F_DDAY )[0]; + format[2] = m.get(F_DMONTH )[0]; + format[3] = m.get(F_DYEAR )[0]; + format[4] = m.get(F_DSEP )[0]; + format[5] = '\0'; + + TDate dd(TODAY); + TFormatted_date d(dd); + + d.set_format(format); + m.set(F_DEXAMPLE, d.string()); + } + return TRUE; +} + +bool TForm_editor::edit_formato_numero() +{ + bool dirty = FALSE; + + TMask m("ba21nm"); + if (dirty = (m.run() == K_ENTER)) + { + int w = m.get_int(F_WIDTH); + int d = m.get_int(F_DECIMALS); + TString p(m.get(F_PICTURE)); + + _form->change_number_format(w, d, p); + } + return dirty; + +} + +bool TForm_editor::edit_formato_data() +{ + bool dirty = FALSE; + char format[6] = { "1444-" }; + TMask m("ba21dt"); + + m.set_handler(F_DFORMAT, date_example); + m.set_handler(F_DDAY, date_example); + m.set_handler(F_DMONTH, date_example); + m.set_handler(F_DYEAR, date_example); + m.set_handler(F_DSEP, date_example); + + TDate dd(TODAY); + TFormatted_date d(dd); + d.set_format(format); + + m.set(F_DFORMAT, "1"); + m.set(F_DDAY, "4"); + m.set(F_DMONTH, "4"); + m.set(F_DYEAR, "4"); + m.set(F_DSEP, "-"); + m.set(F_DEXAMPLE, d.string()); + + if (dirty = (m.run() == K_ENTER)) + { + format[0] = m.get(F_DFORMAT)[0]; + format[1] = m.get(F_DDAY )[0]; + format[2] = m.get(F_DMONTH )[0]; + format[3] = m.get(F_DYEAR )[0]; + format[4] = m.get(F_DSEP )[0]; + format[5] = '\0'; + + _form->change_date_format(format); + } + return dirty; + +} + +bool TForm_editor::edit_relation() +{ + TMask m("ba2100r"); + TSheet_field& s = (TSheet_field&)m.field(F_ITEMS); + s.sheet_mask().set_handler(101, file_handler); + + TRelation* & rel = _form->_relation; + TCursor* & cur = _form->_cursor; + + if (rel) + { + s.rows_array() = _form->rel_desc().get_all_desc(); + // Disable meaningless fields for main file + s.disable_cell(0, 2); // Join + s.disable_cell(0, 4); // Alias + } + + if (m.run() != K_ENTER || !m.dirty()) + return FALSE; + + if (rel) + { + delete cur; cur = NULL; + delete rel; rel = NULL; + } + + TToken_string& r = s.row(0); + TString16 name = r.get(0); + + if (name.not_empty()) + { + int logicnum = atoi(name); + + int alias = 0, to = 0, key = r.get_int(3); + TString80 exp = r.get(5); + + rel = (logicnum > 0) ? new TRelation(logicnum) : new TRelation(name); + cur = new TCursor(rel, exp, key); + + for (int i = 1; i < s.items(); i++) + { + TToken_string& r = s.row(i); + name = r.get(0); logicnum = atoi(name); + r.get(); // Skip description + to = name2log(r.get()); // Join + key = r.get_int(); // Key + alias = r.get_int(); // Alias + exp = r.get(); // Expression + + const int l = exp.len(); + for (int j = 0; j < l; j++) + if (exp[j] == ' ') exp[j] = '|'; + + if (logicnum > 0) + rel->add(logicnum, exp, key, to, alias); // join file + else + rel->add(name, exp, key, to, alias); // join table + } + + _form->rel_desc().change_relation(*rel, s.rows_array()); + } + + return TRUE; +} + + +bool TForm_editor::edit(char s, pagetype t) +{ + bool dirty = FALSE; + + 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 + { + TString80 caption; + switch(s) + { + case 'F': + caption << "Piede"; break; + case 'G': + caption << "Sfondo"; break; + case 'H': + caption << "Testa"; break; + default: + caption << "Corpo"; break; + } + + switch(t) + { + case first_page: + caption << " della prima pagina"; break; + case even_page: + caption << " delle pagine pari"; break; + case last_page: + caption << " dell'ultima pagina"; break; + default: + caption << " standard"; break; + } + + dirty = TRUE; + if (!_form->exist(s, t)) + { + const KEY k = yesnocancel_box("La sezione %s non esiste:\n" + "si desidera generare quella standard?", + (const char*)caption); + if (k == K_ESC) + dirty = FALSE; + else + { + TPrint_section* sec = _form->exist(s, t, TRUE); + if (k == K_YES) + { + const TPrint_section* def = _form->exist(s, odd_page); + if (def) *sec = *def; + else dirty = FALSE; + } + } + } + if (dirty) + dirty = _form->section(s, t).edit(caption); + } + + if (dirty && yesno_box("Salvare le modifiche?")) + { + if (_form->code() == "") + { + 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_editor::form_config() const +{ + TFilename cnfnam(_form->name()); cnfnam.ext("ini"); + + TString16 cnfpar; + if (_form->code() != "") + cnfpar << _form->code(); + else + cnfpar << "Main"; + + TConfig cnf(cnfnam, cnfpar); + bool ok = FALSE; + + const TFilename maskname(cnf.get("EdMask")); + if (maskname.empty()) + return warning_box("Nessun parametro da configurare"); + + TMask m(maskname); + + // carica campi + for (int i = 0; i < m.fields(); i++) + { + TMask_field& f = m.fld(i); + const TFieldref* fref = f.field(); + if (fref != NULL) + { + const char* fname = fref->name(); + if (fname != NULL) + { + const TString& oldvl = cnf.get(fname); + if (!oldvl.empty()) + f.set(oldvl); + } + } + } + + if (m.run() == K_ENTER && m.dirty()) + { + // aggiusta campi + for (i = 0; i < m.fields(); i++) + { + TMask_field& f = m.fld(i); + if (f.dirty()) + { + const TFieldref* fref = f.field(); + if (fref != NULL) + cnf.set(fref->name(), f.get(), NULL, TRUE); + } + } + ok = TRUE; + } + + return ok; +} + +bool TForm_editor::ask_profile() +{ + _m->set_handler(F_CODE, cod_handler); + + // choose form from mask + KEY k; + while ((k = _m->run()) != K_QUIT) + { + TString16 fform = _m->get(F_BASE); + TString80 fdesc = _m->get(F_DESC); + long fcode = _m->get_long(F_CODE); + if (!_extra && (fcode == 0 || fform.left(3) == "BOL")) + { + error_box("Non e' possibile modificare i profili standard o i bollettini.") ; + continue; + } + if (k == K_ENTER) + { + if (_form != NULL) delete _form; + _form = new TForm(fform, (fcode!=0) ? format("%05ld",fcode) : "", _extra ? 2 :1, fdesc); + break; + } + else if (k == K_DEL) + { + if (fcode != 0 && yesno_box("Confermare la cancellazione del profilo %05ld", fcode)) + { + TLocalisamfile frm(LF_FORM); + frm.zero(); + frm.put("TIPOPROF", fform); + if (fcode != 0 ) + frm.put("CODPROF", format("%05ld",fcode)); + if (frm.read() == NOERR) + frm.remove(); + TLocalisamfile rfr(LF_RFORM); + rfr.zero(); + rfr.put("TIPOPROF", fform); + rfr.put("CODPROF", format("%05ld",fcode)); + if (rfr.read() == NOERR) + { + for ( ; atol(rfr.get("CODPROF")) == fcode && rfr.get("TIPOPROF") == fform; rfr.next()) + rfr.remove(); + } + _m->set(F_CODE,""); + _m->set(F_BASE,""); + _m->set(F_DESC,""); + } + } + } + if (k == K_QUIT) + { + dispatch_e_menu(M_FILE_QUIT); + return TRUE; + } + + return FALSE; +} + diff --git a/ba/baformed.h b/ba/baformed.h index 2679b4f50..9a0ada076 100755 --- a/ba/baformed.h +++ b/ba/baformed.h @@ -7,13 +7,19 @@ #include #include +#include "bafrm.h" + class TForm_editor : public TApplication { TForm* _form; TMask* _m; bool _extra; -protected: +protected: + + // maschera usata per selezione profilo (quando non specificato) + virtual const char* selection_mask() const { return "ba2100b"; } + virtual bool create(); virtual bool destroy(); virtual bool menu(MENU_TAG); @@ -25,15 +31,19 @@ protected: bool& extra() { return _extra;} void set_form(TForm * f) { _form = f; } - bool ask_profile(); + virtual bool ask_profile(); bool edit_relation(); bool edit_fincatura(); bool edit_formato_numero(); bool edit_formato_data(); bool edit(char s, pagetype p); bool form_config() const; + TForm& form() { return *_form; } + public: + TForm_editor(); virtual ~TForm_editor(); + }; diff --git a/ba/bafrm.h b/ba/bafrm.h new file mode 100755 index 000000000..cdb072a51 --- /dev/null +++ b/ba/bafrm.h @@ -0,0 +1,93 @@ +// Maschera di edit dei form + +#define F_CLASS 101 +#define F_KEY 102 +#define F_Y 103 +#define F_X 104 +#define F_WIDTH 105 +#define F_HEIGHT 106 +#define F_PROMPT 107 +#define F_HIDDEN 108 +#define F_DISABLED 109 +#define F_AUTOMAGIC 110 +#define F_PICTURE 111 +#define F_ID 112 +#define F_FONT 113 +#define F_SIZE 114 +#define F_FLEN 115 +#define F_CTP 117 +#define F_IPX 118 +#define F_IPY 119 +#define F_FPX 120 +// spreadsheet campi sezione +#define F_FIELDS 121 +#define F_FINKL 122 +#define F_FINKR 123 +#define F_SPACES 124 +#define F_OPTIONS 125 + +#define F_GROUP 130 +#define F_GROUP1 131 +#define F_GROUP2 132 +#define F_GROUP3 133 +#define F_GROUP4 134 +#define F_GROUP5 135 +#define F_GROUP6 136 +#define F_GROUP7 137 +#define F_GROUP8 138 +#define F_GROUP9 139 +#define F_GROUP10 140 +#define F_GROUP11 141 +#define F_GROUP12 142 +#define F_GROUP13 143 +#define F_GROUP14 144 +#define F_GROUP15 145 +#define F_GROUP16 146 +#define F_GROUP17 147 +#define F_GROUP18 148 +#define F_GROUP19 149 +#define F_GROUP20 150 +#define F_GROUP21 151 +#define F_GROUP22 152 +#define F_GROUP23 153 +#define F_GROUP24 154 + +// date format section +#define F_DFORMAT 160 +#define F_DDAY 161 +#define F_DMONTH 162 +#define F_DYEAR 163 +#define F_DSEP 164 +#define F_DEXAMPLE 165 +#define F_FILE 166 + +// file/field references +#define F_FIELDREF1 170 +#define F_FILE1 171 +#define F_BUT_FILE1 172 +#define F_FIELD1 173 +#define F_BUT_FIELD1 174 +#define F_FROM1 175 +#define F_TO1 176 + +#define F_FIELDREF2 180 +#define F_FILE2 181 +#define F_BUT_FILE2 182 +#define F_FIELD2 183 +#define F_BUT_FIELD2 184 +#define F_FROM2 185 +#define F_TO2 186 + +#define F_ITEMS 200 +#define F_DECIMALS 206 +#define F_CAPTION 301 + +// maschera scelta form +#define F_BASE 401 +#define F_CODE 402 +#define F_DESC 403 +#define F_VALUTA 404 + + +// nome base profilo estratto conto +#define BASE_EC_PROFILE "PEC" diff --git a/include/form.cpp b/include/form.cpp index 59a84a287..4abe6998b 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -14,14 +14,31 @@ #include #include -#include "../ba/ba2100.h" +#include "../ba/bafrm.h" + +// per lo sheet di edit campi +HIDDEN const int idt_id = 101; +HIDDEN const int dsc_id = 102; +HIDDEN const int int_id = 103; +HIDDEN const int prn_id = 104; +HIDDEN const int yps_id = 105; +HIDDEN const int len_id = 106; +HIDDEN const int xps_id = 107; +HIDDEN const int col_id = 108; +HIDDEN const int spc_id = 109; +HIDDEN const int fnl_id = 110; +HIDDEN const int fnr_id = 111; +HIDDEN const int typ_id = 112; +HIDDEN const int frm_id = 113; /////////////////////////////////////////////////////////// // Utility functions /////////////////////////////////////////////////////////// // Current form (edit, print) -HIDDEN TForm* _cur_form = NULL; +HIDDEN TForm* _cur_form = NULL; +HIDDEN TPrint_section* _cur_sect = NULL; +HIDDEN TMask* _special_mask = NULL; HIDDEN TForm& form() { @@ -29,6 +46,18 @@ HIDDEN TForm& form() return *_cur_form; } +HIDDEN TPrint_section& section() +{ + CHECK(_cur_sect, "Can't print NULL section"); + return *_cur_sect; +} + +HIDDEN TMask& special_mask() +{ + CHECK(_special_mask, "Can't access NULL mask"); + return *_special_mask; +} + // Translate char to pagetype (visible outside here, no more HIDDEN) pagetype char2page(char c) { @@ -185,8 +214,8 @@ HIDDEN bool dateformat_handler(TMask_field& f, KEY k) TForm_flags::TForm_flags() { - automagic = dirty = FALSE; - shown = enabled = TRUE; + automagic = dirty = finkr = finkl = FALSE; + shown = enabled = TRUE; } // Read from string @@ -202,7 +231,11 @@ bool TForm_flags::update(const char* s) enabled = FALSE; break; case 'H': shown = FALSE; break; - default : + case 'F': + finkl = TRUE; break; + case 'K': + finkr = TRUE; break; + default : error_box("Unknown form item flag '%c'", *s); break; } return TRUE; @@ -218,6 +251,8 @@ void TForm_flags::print_on(ostream& out) const if (automagic) s << "A"; if (!enabled) s << "D"; if (!shown) s << "H"; + if (finkl) s << "F"; + if (finkr) s << "K"; if (s.not_empty()) out << " FLAGS \"" << s << '"' << endl; @@ -230,6 +265,8 @@ void TForm_flags::print_on(TMask& m) m.set(F_DISABLED, enabled ? " " : "X"); m.set(F_HIDDEN, shown ? " " : "X"); m.set(F_AUTOMAGIC, automagic ? "X" : " "); + m.set(F_FINKL, finkl ? " " : "X"); + m.set(F_FINKR, finkr ? " " : "X"); } @@ -240,6 +277,8 @@ void TForm_flags::read_from(const TMask& m) shown = !m.get_bool(F_HIDDEN); enabled = !m.get_bool(F_DISABLED); automagic = m.get_bool(F_AUTOMAGIC); + finkl = !m.get_bool(F_FINKL); + finkr = !m.get_bool(F_FINKL); } /////////////////////////////////////////////////////////// @@ -248,7 +287,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), _effective_height(0), _id(0) +: _section(section), _x(-1), _y(-1), _width(0), _height(0), _id(0), _ofs(0) {} @@ -300,6 +339,24 @@ void TForm_item::print_body(ostream& out) const const TToken_string& m = _message.row(0); if (!m.empty_items()) out << " MESSAGE " << m << endl; + } + + if (_special.items() > 0) + { + TAssoc_array& aa = specials(); + aa.restart(); + + THash_object* op; + + while ((op = aa.get_hashobj()) != NULL) + { + TToken_string& t = (TToken_string&)op->obj(); + TString typ(t.get(0)); + TString val(t.get(1)); + TString des(t.get(2)); + out << " SPECIAL " << typ << " " << op->key() + << " \"" << val << "\" \"" << des << "\"\n"; + } } } @@ -321,17 +378,12 @@ bool TForm_item::parse_item(TScanner& scanner) { TFixed_string m(scanner.line()); m.strip_spaces(); - int n = 0; // All'indice 0 ci sono i messaggi che vanno eseguiti sempre se sono da soli o se il campo non è vuoto se sono in congiunzione con gli EMPTY + int n = 0; if (m.left(5) == "EMPTY") { - n = 1; // All'indice 1 ci sono i messaggi che vanno eseguiti se il campo è vuoto + n = 1; m.ltrim(5); } - else if (m.left(4) == "INIT") - { - n = 2; // All'indice 2 ci sono i messaggi che vanno eseguiti sempre, appena dopo la lettura dal file e prima dell'autoformattazione del campo - m.ltrim(4); - } if (!m.blank()) message(n).add(m); return TRUE; @@ -348,7 +400,18 @@ bool TForm_item::parse_item(TScanner& scanner) _group.set(scanner.line()); return TRUE; } + + if (scanner.key() == "SP") + { + TToken_string val(scanner.pop()); + TString16 var = scanner.pop(); + val.add(scanner.string()); + val.add(scanner.string()); + _special.add(var,val); + return TRUE; + } + yesnofatal_box("Unknown symbol in item '%s': '%s'", (const char*)key(), (const char*)scanner.token()); @@ -363,7 +426,25 @@ bool TForm_item::parse(TScanner& scanner) ok = yesnofatal_box("Missing BEGIN in form item %s", (const char*)key()); while (ok && scanner.popkey() != "EN") - ok = parse_item(scanner); + ok = parse_item(scanner); + + if (section().columnwise()) + { + // look for compulsory SPECIALs and fick them in its cul if absent + if (!_special.is_key("XHEAD")) + _special.add("XHEAD",new TToken_string("NUMERO|0|Spostamento orizzontale intestazione in colonna/2/0")); + if (!_special.is_key("YHEAD")) + _special.add("YHEAD",new TToken_string("NUMERO|-1|Spostamento verticale intestazione in testata /2/0")); + if (!_special.is_key("DHEAD")) + { + TToken_string* tt = new TToken_string(128); + TString k(key()); + tt->add("STRINGA"); + tt->add(k); + tt->add("Intestazione colonna corrispondente/40"); + _special.add("XHEAD",tt); + } + } return ok; } @@ -403,8 +484,28 @@ bool TForm_item::read_from(const TRectype& prof) { _flag.shown = s; changed = TRUE; - } + } + + 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)) + { + 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; } @@ -416,7 +517,32 @@ void TForm_item::print_on(TRectype& prof) prof.put("Y", _y); prof.put("LEN", width()); prof.put("HGT", height()); - prof.put("ATTIVO", shown() ? "X" : " "); + prof.put("ATTIVO", shown() ? "X" : " "); + + // 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(); + + for (int i = 0; i < _special.items(); i++) + { + THash_object* o = _special.get_hashobj(); + + TString key(o->key()); + TToken_string& tt = (TToken_string&)o->obj(); + + if (tt.items() == 4) + { + TToken_string sp(key,'$'); + TString val(tt.get(1)); + sp.add(val); + special.add(sp); + } + } + prof.put("SPECIAL", special); + } } void TForm_item::enable(bool on) @@ -430,6 +556,7 @@ void TForm_item::string_at(int x, int y, const char* s) if (shown()) { section().offset(x, y); + if (section().columnwise()) x += _ofs; TPrintrow& row = section().row(y-1); // Seleziona riga di stampa if (_width > 0 && strlen(s) > (word)_width) // Tronca testo se necessario @@ -573,12 +700,11 @@ bool TForm_item::update() string_at(_x, _y, prompt); } else string_at(_x, _y, _prompt); - _effective_height= 1; // Effective height is one row by default, only paragraph strings can be taller return TRUE; } -void TForm_item::print_on(TToken_string& row) const +void TForm_item::print_on(TToken_string& row) const { row.cut(0); row.add(id()); @@ -593,7 +719,26 @@ void TForm_item::print_on(TToken_string& row) const if (fu > 0) row.add(fu); else row.add(" "); } -} +} + +void TForm_item::print_on_sheet_row(TToken_string& tt) const +{ + TString tmp(80); + tt.add(_id, idt_id - 101); + tt.add(_desc, _section->columnwise() ? int_id - 101 : dsc_id - 101); + tt.add(_x, _section->columnwise() ? col_id - 101 : xps_id - 101); + tt.add(_y, _section->columnwise() ? len_id - 101 : yps_id - 101); + tt.add(class_name(), typ_id - 101); + tt.add(shown() ? "X" : " ", prn_id - 101); + tmp = example(); tt.add(tmp, frm_id - 101); + + if (_section->columnwise()) + { + tt.add(_ofs, spc_id -101); + tt.add(finkl() ? "" : "X", fnl_id -101); + tt.add(finkr() ? "" : "X", fnr_id -101); + } +} void TForm_item::print_on(TMask& m) { @@ -621,6 +766,7 @@ void TForm_item::read_from(const TMask& m) _width = atoi(m.get(F_WIDTH)); _height = atoi(m.get(F_HEIGHT)); _id = atoi(m.get(F_ID)); + _ofs = atoi(m.get(F_SPACES)); _flag.read_from(m); @@ -629,6 +775,21 @@ void TForm_item::read_from(const TMask& m) _group.set(g, m.get_bool(F_GROUP+g)); } +void TForm_item::read_from(TToken_string& s) +{ + _id = s.get_int(idt_id - 101); + _desc = _section->columnwise() ? s.get(int_id - 101) : s.get(dsc_id - 101); + _x = _section->columnwise() ? s.get_int(col_id - 101) : s.get_int(xps_id - 101); + _y = _section->columnwise() ? s.get_int(len_id - 101) : s.get_int(yps_id - 101); + _ofs = s.get_int(spc_id - 101); + _flag.set_enabled(s.get(prn_id - 101) != "X"); + + if (_section->columnwise()) + { + _flag.set_finkl(s.get(fnl_id - 101) != "X"); + _flag.set_finkr(s.get(fnr_id - 101) != "X"); + } +} bool TForm_item::edit(TMask& m) { @@ -674,6 +835,12 @@ void TForm_item::set_picture(const char*) CHECK(0, "Can't set the picture of a generic form item!"); } +short TForm_item::x() const +{ + if (_section == NULL || !_section->columnwise()) + return _x; + return _section->tab(_x-1); +} /////////////////////////////////////////////////////////// // TForm_subsection @@ -756,7 +923,6 @@ bool TForm_subsection::update() } - bool TForm_subsection::edit(TMask& m) { // mask con nome e bottone edit contents / annulla @@ -822,7 +988,7 @@ bool TForm_subsection::edit(TMask& m) } -void TForm_subsection::print_on(ostream& out) const +void TForm_subsection::print_on(ostream& out) const { out << "SEZIONE " << _name << ' ' << _width << ' ' << _height << ' ' << _x << ' ' << _y; @@ -861,7 +1027,7 @@ class TForm_string : public TForm_item protected: virtual const char* class_name() const { return "STRINGA"; } - virtual void print_body(ostream& out) const; + virtual void print_body(ostream& out); virtual void print_on(TMask& m); virtual void read_from(const TMask& m); @@ -869,12 +1035,14 @@ protected: virtual bool read_from(const TRectype& rform); virtual void print_on(TRectype& rform); - virtual void print_on(TToken_string& row) const; + virtual void print_on(TToken_string& row); virtual bool parse_item(TScanner&); virtual bool read(); virtual bool update(); - + virtual const char* example() const; + virtual void apply_format(TString& s, const TString& p) const; + virtual const char* get() const; bool set(const char*); @@ -915,7 +1083,7 @@ bool TForm_string::parse_item(TScanner& scanner) return TForm_item::parse_item(scanner); } -void TForm_string::print_body(ostream& out) const +void TForm_string::print_body(ostream& out) { TForm_item::print_body(out); if (_picture.not_empty()) @@ -938,7 +1106,7 @@ bool TForm_string::read_from(const TRectype& prof) return changed; } -void TForm_string::print_on(TToken_string& row) const +void TForm_string::print_on(TToken_string& row) { TForm_item::print_on(row); if (_field.items() && form().edit_level() > 1) @@ -1038,61 +1206,70 @@ void TForm_string::put_paragraph(const char* s) int i = _prompt.not_empty() ? 1 : 0; for (; (s = p.get()) != NULL && i < height(); i++) string_at(_x, _y+i, s); - _effective_height= i - (_prompt.not_empty() ? 1 : 0); } else string_at(-1, _y, s); } + +void TForm_string::apply_format(TString& s, const TString& p) const +{ + TString tmp(s); + if (!p.blank()) + { + TToken_string delim(4, ','); // Stringa con i due delimitatori + const char* pic = p; // Picture senza delimitatori + + if (pic[0] == '(') // Se ci sono i delimitatori ... + { + const int bra = p.find(')'); + if (bra > 0) // ... cerca la parentesi chiusa + { + delim = p.sub(1, bra); // memorizza delimitatori + pic += bra+1; // toglili dalla picture + } + } + + if (class_name() == "DATA" && s.empty()) + tmp =""; + else + tmp.picture(pic, s); // riempi la stringa col valore pitturato + if (!delim.empty_items()) // Aggiungi delimitatori + { + TString16 d(delim.get(0)); + const int ld = d.len(); + + if (ld > 0) // Se il primo delimitatore e' valido ... + { + for (int spc = 0;s[spc]==' ' ; spc++) ; + if (spc < ld) + { + TString16 spazi; + spazi.spaces(ld - spc); + tmp.insert(spazi,0); + spc = ld; + } + tmp.overwrite(d,spc - ld); + } + d = delim.get(); + if (d.not_empty()) // Se il secondo delimitatore e' valido ... + tmp << d; // ... aggiungilo alla fine + } + s = tmp; + } +} + bool TForm_string::update() { if (read()) { - if (_message.objptr(2) != NULL) do_message(2); // Lancio dei messaggi di inizializzazione (INIT) TString s; TForm_item::update(); if (!picture().blank()) - { - TToken_string delim(4, ','); // Stringa con i due delimitatori - const char* pic = picture(); // Picture senza delimitatori - - if (pic[0] == '(') // Se ci sono i delimitatori ... - { - const int bra = picture().find(')'); - if (bra > 0) // ... cerca la parentesi chiusa - { - delim = picture().sub(1, bra); // memorizza delimitatori - pic += bra+1; // toglili dalla picture - } - } - - if (class_name() == "DATA" && _str.empty()) - s =""; - else - s.picture(pic, get()); // riempi la stringa col valore pitturato - - if (!delim.empty_items()) // Aggiungi delimitatori - { - TString16 d(delim.get(0)); - const int ld = d.len(); - - if (ld > 0) // Se il primo delimitatore e' valido ... - { - for (int spc = 0;s[spc]==' ' ; spc++) ; - if (spc < ld) - { - TString16 spazi; - spazi.spaces(ld - spc); - s.insert(spazi,0); - spc = ld; - } - s.overwrite(d,spc - ld); - } - d = delim.get(); - if (d.not_empty()) // Se il secondo delimitatore e' valido ... - s << d; // ... aggiungilo alla fine - } + { + s = get(); + apply_format(s, picture()); put_paragraph(s); } else @@ -1104,12 +1281,22 @@ bool TForm_string::update() return TRUE; } +const char* TForm_string::example() const +{ + TString prova("Stringa esempio"); + apply_format(prova, picture()); + return strcpy(__tmp_string, prova); +} + + /////////////////////////////////////////////////////////// // TForm_number /////////////////////////////////////////////////////////// class TForm_number : public TForm_string -{ +{ + void apply_format(real& r, TString& s) const; + protected: // TForm_string virtual const char* class_name() const { return "NUMERO"; } virtual bool parse_head(TScanner& scanner); @@ -1122,6 +1309,8 @@ protected: public: void set_decimals(int d) { _height = d; } + virtual const char* example() const; + TForm_number(TPrint_section* section) : TForm_string(section) {} virtual ~TForm_number() {} }; @@ -1141,67 +1330,18 @@ bool TForm_number::update() if (read()) { TForm_item::update(); - real n(get()); n.round(decimals()); - TString s; if (!n.is_zero()) { - if (!picture().blank()) - { - TToken_string delim(4, ','); // Stringa con i due delimitatori - TString pic(picture()); // Picture senza delimitatori - int maxlen = -1; - int at = pic.find('@'); - if (at >= 0) - { - maxlen = atoi(&pic[at+1]); - pic.cut(at); - } - if (pic[0] == '(') // Se ci sono i delimitatori ... - { - const int bra = pic.find(')'); - if (bra > 0) // ... cerca la parentesi chiusa - { - delim = pic.sub(1, bra); // memorizza delimitatori - pic.ltrim(bra + 1); // toglili dalla picture - } - } - - s=n.string(pic); // riempi la stringa col valore pitturato - - if (maxlen >= 0) - s.cut(maxlen); - if (!delim.empty_items()) // Aggiungi delimitatori - { - TString16 d(delim.get(0)); - const int ld = d.len(); - - if (ld > 0) // Se il primo delimitatore e' valido ... - { - for (int spc = 0;s[spc]==' ' ; spc++) ; - if (spc < ld) - { - TString16 spazi; - spazi.spaces(ld - spc); - s.insert(spazi,0); - spc = ld; - } - s.overwrite(d,spc - ld); - } - d = delim.get(); - if (d.not_empty()) // Se il secondo delimitatore e' valido ... - s << d; // ... aggiungilo alla fine - } - put_paragraph(s); - } - else - put_paragraph(n.string()); - do_message(); - } + TString s; + apply_format(n,s); + put_paragraph(s); + do_message(); + } else - { + { const int n = (_message.objptr(1) != NULL ? 1 : 0); do_message(n); } @@ -1210,6 +1350,67 @@ bool TForm_number::update() return TRUE; } +void TForm_number::apply_format(real& n , TString& s) const +{ + if (!picture().blank()) + { + TToken_string delim(4, ','); // Stringa con i due delimitatori + TString pic(picture()); // Picture senza delimitatori + int maxlen = -1; + int at = pic.find('@'); + if (at >= 0) + { + maxlen = atoi(&pic[at+1]); + pic.cut(at); + } + if (pic[0] == '(') // Se ci sono i delimitatori ... + { + const int bra = pic.find(')'); + if (bra > 0) // ... cerca la parentesi chiusa + { + delim = pic.sub(1, bra); // memorizza delimitatori + pic.ltrim(bra + 1); // toglili dalla picture + } + } + + s=n.string(pic); // riempi la stringa col valore pitturato + + if (maxlen >= 0) + s.cut(maxlen); + if (!delim.empty_items()) // Aggiungi delimitatori + { + TString16 d(delim.get(0)); + const int ld = d.len(); + + if (ld > 0) // Se il primo delimitatore e' valido ... + { + for (int spc = 0;s[spc]==' ' ; spc++) ; + if (spc < ld) + { + TString16 spazi; + spazi.spaces(ld - spc); + s.insert(spazi,0); + spc = ld; + } + s.overwrite(d,spc - ld); + } + d = delim.get(); + if (d.not_empty()) // Se il secondo delimitatore e' valido ... + s << d; // ... aggiungilo alla fine + } + } + else s = n.string(); +} + +const char* TForm_number::example() const +{ + real n("123456789120.00"); n.round(2); + TString s; + apply_format(n,s); + return strcpy(__tmp_string, s); +} + + /////////////////////////////////////////////////////////// // TForm_date /////////////////////////////////////////////////////////// @@ -1224,7 +1425,7 @@ protected: virtual bool set(const char*); bool set(const TDate& d); virtual bool parse_item(TScanner& scanner); - virtual void print_body(ostream& out) const; + virtual void print_body(ostream& out); virtual void print_on(TMask& m); virtual void read_from(const TMask& m); @@ -1236,6 +1437,7 @@ public: void set_format(const char* f) { _format = f; } virtual bool edit(TMask& m); + virtual const char* example() const; TForm_date(TPrint_section* section); virtual ~TForm_date() {} }; @@ -1253,7 +1455,7 @@ bool TForm_date::read() return ok; } -void TForm_date::print_body(ostream& out) const +void TForm_date::print_body(ostream& out) { TForm_string::print_body(out); out << " FORMAT \"" << _format << "\"\n"; @@ -1304,8 +1506,9 @@ bool TForm_date::set(const TDate& da) } void TForm_date::print_on(TMask& m) -{ - const TFormatted_date d(TODAY, 0, 0, _format); +{ + const TDate dd(TODAY); + TFormatted_date d(dd); d.set_format(_format); m.set(F_DEXAMPLE, d.string()); m.set(F_DFORMAT, _format.mid(0,1)); @@ -1337,6 +1540,15 @@ bool TForm_date::edit(TMask& m) return TForm_string::edit(m); } +const char* TForm_date::example() const +{ + const TDate dd(TODAY); + TFormatted_date d(dd); d.set_format(_format); + TString s(d.string()); + return strcpy(__tmp_string, s); +} + + /////////////////////////////////////////////////////////// // TForm_list /////////////////////////////////////////////////////////// @@ -1351,7 +1563,7 @@ protected: virtual bool parse_item(TScanner& scanner); virtual void print_on(TMask& m); virtual void read_from(const TMask& m); - virtual void print_body(ostream& out) const; + virtual void print_body(ostream& out); virtual bool update(); public: @@ -1416,7 +1628,7 @@ void TForm_list::read_from(const TMask& m) } } -void TForm_list::print_body(ostream& out) const +void TForm_list::print_body(ostream& out) { TForm_string::print_body(out); @@ -1491,6 +1703,91 @@ public: virtual ~TForm_group() {} }; +/////////////////////////////////////////////////////////// +// TGraphic_section +/////////////////////////////////////////////////////////// + +class TGraphic_section : public TPrint_section +{ + TString _back; + +protected: + TForm_item* parse_item(const TString& s); + bool update(); + +public: + void append(const char* s) { _back << s; } + + TGraphic_section(TForm* f, pagetype pt) : TPrint_section(f, 'G', pt) {} + virtual ~TGraphic_section() {} +}; + +class TForm_picture : public TForm_item +{ +protected: + virtual const char* class_name() const { return "FIGURA"; } + virtual bool update(); + +public: + TForm_picture(TGraphic_section* section) : TForm_item(section) {}; + virtual ~TForm_picture() {} +}; + +class TForm_line : public TForm_item +{ +protected: + virtual const char* class_name() const { return "LINEA"; } + virtual bool update(); + +public: + TForm_line(TGraphic_section* section) : TForm_item(section) {}; + virtual ~TForm_line() {} +}; + +bool TForm_picture::update() +{ + const bool ok = _prompt.not_empty(); + if (ok) + { + TString80 i; + i << "i{" << _prompt << ',' << _x << ',' << _y << ',' + << (_x+width()-1) << ',' << (_y+height()-1) << '}'; + ((TGraphic_section&)section()).append(i); + } + return ok; +} + +bool TForm_line::update() +{ + TString80 i; + const int w = _prompt[0] == '@' ? 3 : 1; + i << 'W' << w << "l{" << _x << ',' << _y << ',' + << (_x+width()-1) << ',' << (_y+height()-1) << '}'; + + ((TGraphic_section&)section()).append(i); + return TRUE; +} + + +TForm_item* TGraphic_section::parse_item(const TString& s) +{ + if (s == "FI") + return new TForm_picture(this); + else if (s == "LI") + return new TForm_line(this); + + error_box("Campo di stampa non ammesso per lo sfondo: %s", (const char*)s); + return NULL; +} + +bool TGraphic_section::update() +{ + _back.cut(0); + const bool ok = TPrint_section::update(); + printer().setbackground(_back); + return ok; +} + /////////////////////////////////////////////////////////// // TPrint_section /////////////////////////////////////////////////////////// @@ -1538,10 +1835,11 @@ HIDDEN bool font_handler(TMask_field& f, KEY key) TMask* TPrint_section::_msk = NULL; + TPrint_section::TPrint_section(TForm* f, char st, pagetype pt, bool sub) : _height(0), _form(f), _sec_type(st), _page_type(pt), _dirty(FALSE), _subsection(sub), _repeat_count(0) -{} +{ _tab[0] = -1; } TPrint_section::~TPrint_section() { @@ -1552,6 +1850,16 @@ TPrint_section::~TPrint_section() } } +void TPrint_section::change_field(int n, TForm_item* f) +{ + _item.add(f,n); +} + +void TPrint_section::insert_field(int n, TForm_item* f) +{ + _item.insert(f,n); +} + const TPrint_section& TPrint_section::copy(const TPrint_section& ps) { _item = ps._item; @@ -1569,10 +1877,42 @@ TPrintrow& TPrint_section::row(int num) } return *pr; } - -void TPrint_section::offset(int& x, int& y) const -{ - if (x >= 0) x += form().offset_x(); + +int TPrint_section::tab(int col) +{ + int ret = -1; + if (_columnwise) + { + if (_tab[0] == -1) + { + // compute column offset + word nfld = 0; + _tab[0] = 1; + for (word i = 0; i < fields(); i++) + { + if (field(i).shown() && field(i).enabled()) + { + CHECKD (field(i)._x < MAXCOLUMNS, "Colonna ammessa e non concessa: ", field(i)._x); + _tab[field(i)._x] = field(i).width() + 1; // one is for separation + nfld++; + } + } + // cumulate offsets + for (i = 1; i < nfld; i++) + _tab[i] += _tab[i-1]; + } + ret = _tab[col]; + } + return ret; +} + +void TPrint_section::offset(int& x, int& y) +{ + if (x >= 0) + { + if (_columnwise) x = tab(x-1); + x += form().offset_x(); + } if (y >= 0) y += form().offset_y() + (_height * _repeat_count); } @@ -1607,6 +1947,14 @@ bool TPrint_section::parse(TScanner& scanner) _height = scanner.integer(); scanner.integer();scanner.integer(); // Eat offset X and Y of Print_section if present + if (scanner.popkey() == "CO") // COLUMNWISE attribute + _columnwise = TRUE; + else + { + _columnwise = FALSE; + scanner.push(); + } + while (scanner.popkey() != "EN") { TForm_item *fi = parse_item(scanner); @@ -1616,7 +1964,8 @@ bool TPrint_section::parse(TScanner& scanner) _item.add(fi); else return FALSE; - } + } + return TRUE; } @@ -1689,11 +2038,235 @@ BOOLEAN XVT_CALLCONV1 wpr (long data) return FALSE; } + +bool TPrint_section::special_field_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE && _special_mask != NULL) + _special_mask->run(); + return TRUE; +} + + +// handlers for section editing +bool TPrint_section::detail_field_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + // to avoid kasinations with recursion + TPrint_section& section = ::section(); + TSheet_field& ms = *f.mask().get_sheet(); + int field = ms.selected(); + TToken_string& tt = ms.row(field); + + TMask msk("ba2100f"); + + msk.set_handler(F_DFORMAT, dateformat_handler); + msk.set_handler(F_DYEAR, dateformat_handler); + msk.set_handler(F_DMONTH, dateformat_handler); + msk.set_handler(F_DDAY, dateformat_handler); + msk.set_handler(F_DSEP, dateformat_handler); + + msk.set_handler(F_BUT_FILE1, but_file_handler); + msk.set_handler(F_BUT_FIELD1, but_field_handler); + msk.set_handler(F_FROM1, from_handler); + msk.set_handler(F_TO1, to_handler); + msk.set_handler(F_BUT_FILE2, but_file_handler); + msk.set_handler(F_BUT_FIELD2, but_field_handler); + msk.set_handler(F_FROM2, from_handler); + msk.set_handler(F_TO2, to_handler); + + // TBI set_mode etc, vedi sotto + + // gna' + TForm_item& fi = section.field(field); + + msk.enable(F_OPTIONS, fi.special_items() > 0); + + // build option mask + if (fi.special_items() > 0) + { + 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"); + + _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_CANCEL, 0, "", -22, -1, 10, 2); + fi.specials().restart(); + + for (int k = 0; k < fi.special_items(); k++) + { + THash_object* ho = fi.specials().get_hashobj(); + TToken_string& tt = (TToken_string&)(ho->obj()); + TString type = tt.get(0); + TString val = tt.get(1); + TToken_string des(tt.get(2),'/'); + TString prompt(des.get(0)); + + if (type == "STRINGA") + { + _special_mask->add_string(101+k, 0, prompt, 1, k+1, des.get_int(1),""); + _special_mask->set(101+k, val); + } + else if (type == "NUMERO") + { + _special_mask->add_number(101+k, 0, prompt, 1, k+1, des.get_int(1),"",des.get_int(2)); + _special_mask->set(101+k, val); + } + else if (type == "LISTA") + { + TToken_string codes(128); + TToken_string value(128); + + for (int jj = 2; jj < des.items(); jj++) + { + CHECK (jj < (des.items() - 1), "AAARGH! LISTA special fatta col CULO!"); + TString t1(des.get(jj++)); + TString t2(des.get(jj)); + codes.add(t1); + value.add(t2); + } + + _special_mask->add_list(101+k, 0, prompt, 1, k+1, des.get_int(1), "", codes, value); + _special_mask->set(101+k, val); + } + else if (type == "BOOLEAN") + { + _special_mask->add_boolean(101+k, 0, prompt, 1, k+1); + _special_mask->set(101+k, val); + } + else if (type == "DATA") + { + _special_mask->add_date(101+k, 0, prompt, 1, k+1); + _special_mask->set(101+k, val); + } + } + } + fi.edit(msk); + + // check specials + if (_special_mask != NULL) + { + if (_special_mask->last_key() == K_ENTER) + { + fi.specials().restart(); + + for (int k = 0; k < fi.special_items(); k++) + { + THash_object* ho = fi.specials().get_hashobj(); + TToken_string& tt = (TToken_string&)(ho->obj()); + TString val = tt.get(1); + TString nvl = _special_mask->get(k + 101); + if (nvl != val) + { + tt.add(nvl, 1); + if (tt.items() == 3) tt.add("X"); + fi.set_dirty(); + } + } + } + + delete _special_mask; + } + + // reset stominchione + fi.print_on_sheet_row(tt); + + ms.force_update(); + + _cur_sect = §ion; + } + return TRUE; +} + +bool TPrint_section::detail_field_notify (TSheet_field& s, int r, KEY k) +{ + TPrint_section& sec = ::section(); + if (k == K_DEL || k == K_INS) + { + if (::form().edit_level() <= 1) + return FALSE; + if (k == K_DEL) + { + // elimina campo + sec.destroy_field(r); + sec.set_dirty(); + } + } + else if (k == (K_INS + K_CTRL)) + { + // new field: set defaults and create field + TForm_string* f = new TForm_string(&sec); + sec.insert_field(r, f); + TToken_string& tt = s.row(r); + f->print_on_sheet_row(tt); + tt.add("Nuovo campo", sec.columnwise() ? int_id : dsc_id); + if (sec.columnwise()) tt.add(r+1, col_id - 101); + s.force_update(); + sec.set_dirty(); + } + else if (k == K_ENTER) + { + // modify field + TForm_item* fld = &sec.field(r); + TToken_string& tt = s.row(r); + + if (sec.columnwise() && ((word)tt.get_int(col_id - 101) <= 0 || + (word)tt.get_int(col_id - 101) > sec.fields())) + { + warning_box("Numero di colonna non accettabile (deve essere da 1 a %u)", sec.fields()); + return FALSE; + } + + // ??? type changed ??? + if (strcmp(tt.get(typ_id - 101), fld->class_name()) != 0) + { + // so'ccazzi: crea nuovo campo del tipo dato e + // copia gli special (e il resto) + TString typ(tt.get(typ_id - 101)); + TForm_item* fff = NULL; + if (typ == "NUMERO") + fff = new TForm_number(&sec); + else if (typ == "STRINGA") + fff = new TForm_string(&sec); + else if (typ == "DATA") + fff = new TForm_date(&sec); + else if (typ == "LISTA") + fff = new TForm_list(&sec); + else if (typ == "GRUPPO") + fff = new TForm_group(&sec); + else if (typ == "LINEA") + fff = new TForm_line((TGraphic_section*)&sec); + else if (typ == "FIGURA") + fff = new TForm_picture((TGraphic_section*)&sec); + + // copia SPECIALS + TAssoc_array& aa = fld->specials(); + TAssoc_array& bb = fff->specials(); + THash_object* oo = NULL; + aa.restart(); + + for (int i = 0; i < aa.items(); i++) + { + oo = aa.get_hashobj(); + bb.add(oo->key(), oo->obj()); + } + sec.change_field(r, fld = fff); + fld->set_dirty(); + } + // modifica valori + fld->read_from(tt); + } + return TRUE; +} + bool TPrint_section::edit(const char* title) { _cur_form = _form; - + _cur_sect = this; + if (!_subsection) { TMask m("ba2100s"); @@ -1706,27 +2279,68 @@ bool TPrint_section::edit(const char* title) m.set(F_IPY, form().ipy()); m.set(F_FPX, form().fpx()); m.set(F_FLEN, printer().formlen()); + + TSheet_field& ms = (TSheet_field&)m.field(F_FIELDS); - { - 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++) + if (_columnwise) { - 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_FONT); - 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()); - } + ms.delete_column(dsc_id); ms.sheet_mask().hide(dsc_id); + ms.delete_column(xps_id); ms.sheet_mask().hide(xps_id); + ms.delete_column(yps_id); ms.sheet_mask().hide(yps_id); + } + else + { + 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); + ms.delete_column(spc_id); ms.sheet_mask().hide(spc_id); + ms.delete_column(fnl_id); ms.sheet_mask().hide(fnl_id); + ms.delete_column(fnr_id); ms.sheet_mask().hide(fnr_id); + } + + ms.enable_column(frm_id - 101, FALSE); + + if (form().edit_level() <= 1) + { + ms.enable_column(idt_id - 101, FALSE); + ms.enable_column(typ_id - 101, FALSE); + } + + // handlers + ms.set_notify(detail_field_notify); + ms.sheet_mask().set_handler(100, detail_field_handler); + + TToken_string tt(128); + + // fill sheet + for (word i = 0; i < fields(); i++) + { + TForm_item& f = field(i); + field(i).print_on_sheet_row(tt); + ms.row(-1) = tt; + } + + { + 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_FONT); + 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()); + } + printer().set_char_size(form().fontsize()); m.set_handler(F_FONT,font_handler); if (m.run() == K_ESC) @@ -1829,88 +2443,10 @@ bool TPrint_section::edit(const char* title) } } - const word flags = 0x08 | (form().edit_level() > 1 ? 0x06 : 0x00); - - TString80 caption("ID@4|Descrizione@40|Riga@R|Col.@R|Non stampare"); - if (form().edit_level() > 1) caption << "|Gr.@R|Campo@16"; - - TArray_sheet a(-1, -1, 0, 0, title, caption, flags); - - for (word i = 0; i < fields(); i++) - { - TToken_string* s = new TToken_string(128); - field(i).print_on(*s); - a.add(s); - } - - KEY k; - while ((k = a.run()) != K_ESC) - { - i = (word)a.selected(); + if (!_dirty) + for (word j = 0; j < fields(); j++) + _dirty |= field(j).dirty(); - if (_msk == NULL && (k == K_ENTER || k == K_INS || k == K_CTRL + 'N')) - { - _msk = new TMask("ba2100f"); - - _msk->set_handler(F_DFORMAT, dateformat_handler); - _msk->set_handler(F_DYEAR, dateformat_handler); - _msk->set_handler(F_DMONTH, dateformat_handler); - _msk->set_handler(F_DDAY, dateformat_handler); - _msk->set_handler(F_DSEP, dateformat_handler); - - _msk->set_handler(F_BUT_FILE1, but_file_handler); - _msk->set_handler(F_BUT_FIELD1, but_field_handler); - _msk->set_handler(F_FROM1, from_handler); - _msk->set_handler(F_TO1, to_handler); - _msk->set_handler(F_BUT_FILE2, but_file_handler); - _msk->set_handler(F_BUT_FIELD2, but_field_handler); - _msk->set_handler(F_FROM2, from_handler); - _msk->set_handler(F_TO2, to_handler); - } - - TForm_string dummy(this); - - switch(k) - { - case K_ENTER: - _msk->set_mode(MODE_MOD); - if (field(i).edit(*_msk)) - { - field(i).print_on(a.row(i)); - _dirty = TRUE; - } - break; - case K_CTRL + 'N': - case K_INS: - _msk->set_mode(MODE_INS); - if (dummy.edit(*_msk)) - { - const TString& c = _msk->get(F_CLASS).left(2); - TForm_item* item = parse_item(c); - if (item != NULL) - { - item->read_from(*_msk); - _item.insert(item, i); - - TToken_string s(128); item->print_on(s); - a.insert(s, i); - _dirty = TRUE; - } - } - break; - case K_DEL: - if (yesno_box("Confermare la cancellazione")) - { - _item.destroy(i, TRUE); - a.destroy(i); - _dirty = TRUE; - } - break; - default: - break; - } - } - set_dirty(_dirty); return _dirty; } @@ -1929,7 +2465,9 @@ void TPrint_section::print_on(ostream& out) const default: out << "ODD"; break; } - out << ' ' << _height << endl << endl; + out << ' ' << _height; + if (_columnwise) out << " COLUMNWISE"; + out << endl << endl; for(word i = 0; i < fields(); i++) out << field(i); } @@ -1945,91 +2483,6 @@ TForm_item& TPrint_section::find_field(short id) const return field(0); } -/////////////////////////////////////////////////////////// -// TGraphic_section -/////////////////////////////////////////////////////////// - -class TGraphic_section : public TPrint_section -{ - TString _back; - -protected: - TForm_item* parse_item(const TString& s); - bool update(); - -public: - void append(const char* s) { _back << s; } - - TGraphic_section(TForm* f, pagetype pt) : TPrint_section(f, 'G', pt) {} - virtual ~TGraphic_section() {} -}; - -class TForm_picture : public TForm_item -{ -protected: - virtual const char* class_name() const { return "FIGURA"; } - virtual bool update(); - -public: - TForm_picture(TGraphic_section* section) : TForm_item(section) {}; - virtual ~TForm_picture() {} -}; - -class TForm_line : public TForm_item -{ -protected: - virtual const char* class_name() const { return "LINEA"; } - virtual bool update(); - -public: - TForm_line(TGraphic_section* section) : TForm_item(section) {}; - virtual ~TForm_line() {} -}; - -bool TForm_picture::update() -{ - const bool ok = _prompt.not_empty(); - if (ok) - { - TString80 i; - i << "i{" << _prompt << ',' << _x << ',' << _y << ',' - << (_x+width()-1) << ',' << (_y+height()-1) << '}'; - ((TGraphic_section&)section()).append(i); - } - return ok; -} - -bool TForm_line::update() -{ - TString80 i; - const int w = _prompt[0] == '@' ? 3 : 1; - i << 'W' << w << "l{" << _x << ',' << _y << ',' - << (_x+width()-1) << ',' << (_y+height()-1) << '}'; - - ((TGraphic_section&)section()).append(i); - return TRUE; -} - - -TForm_item* TGraphic_section::parse_item(const TString& s) -{ - if (s == "FI") - return new TForm_picture(this); - else if (s == "LI") - return new TForm_line(this); - - error_box("Campo di stampa non ammesso per lo sfondo: %s", (const char*)s); - return NULL; -} - -bool TGraphic_section::update() -{ - _back.cut(0); - const bool ok = TPrint_section::update(); - printer().setbackground(_back); - return ok; -} - /////////////////////////////////////////////////////////// // TForm /////////////////////////////////////////////////////////// diff --git a/include/form.h b/include/form.h index 8ae716488..605d53e22 100755 --- a/include/form.h +++ b/include/form.h @@ -24,67 +24,18 @@ class TRelation_description; class TCursor; #endif +#ifndef __ASSOC_H +#include +#endif + enum pagetype { odd_page, even_page, first_page, last_page }; pagetype char2page(char); // prototipo della funzione che converte dalla notazione carattere al corrispondente enum pagetype class TForm; +class TMask_field; +class TSheet_field; class TForm_item; - -class TPrint_section : public TArray -{ - static TMask* _msk; - - word _height; // Altezza della sezione - bool _dirty; // Flag di modifica parametri - - TForm* _form; // Form cui appartiene alla sezione - char _sec_type; // H, B, F, G - pagetype _page_type; // Tipo della pagina - bool _subsection; // e' una sottosezione - - TArray _item; // Lista dei campi da stampare - int _repeat_count; // n. ripetizioni eseguite - - const TPrint_section& copy(const TPrint_section& ps); - -protected: - virtual void print_on(ostream& out) const; - virtual TForm_item* parse_item(const TString& key); - TForm_item* parse_item(TScanner& scanner); - -public: - TPrintrow& row(int num); - TForm& form() const { return *_form; } - - TForm_item& field(int n) const { return (TForm_item&)_item[n]; } - TForm_item& find_field(short id) const; - - word fields() const { return _item.items(); } - word height() const { return _height; } - void offset(int& x, int& y) const; - void set_repeat_count(int x) { _repeat_count = x; } - - virtual bool ok() const { return height() > 0 || fields() > 0; } - - void reset(); - virtual bool update(); - bool parse(TScanner& scanner); - - bool read_from(const TRectype& rec); - void print_on(TRectype& rec); - - bool edit(const char* title); - char section_type() const { return _sec_type; } - pagetype page_type() const { return _page_type; } - - bool dirty() const { return _dirty; } - void set_dirty(bool d = TRUE) { _dirty = d; } - - const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); } - TPrint_section(TForm* parent, char st, pagetype pt, bool subsection = FALSE); - TPrint_section(const TPrint_section& ps) { copy(ps); } - virtual ~TPrint_section(); -}; +class TPrint_section; class TForm : public TObject @@ -181,6 +132,7 @@ public: const TString& code() const { return _code; } bool edit_level() const { return _editlevel; } + void set_edit_level(int n) { _editlevel = n; } void set_description(const char* s) { _desc = s; } virtual TRelation* relation() const { return _relation; } @@ -218,6 +170,8 @@ public: char f_centerright() { return _fink.get_char(8); } char f_horizontal() { return _fink.get_char(9); } char f_vertical() { return _fink.get_char(10); } + // editor interface + TForm_editor& editor() { return (TForm_editor&)main_app(); } // Notifica l'inizio di stampa dell'ultima pagina void set_last_page(bool lp) { _lastpage = lp; } @@ -235,6 +189,8 @@ struct TForm_flags : public TObject bool enabled : 1; bool shown : 1; bool dirty : 1; + bool finkl : 1; + bool finkr : 1; protected: void print_on(ostream& out) const; @@ -242,20 +198,101 @@ protected: public: TForm_flags(); + void set_enabled(bool b) { enabled = b; } + void set_finkl(bool b) { finkl = b; } + void set_finkr(bool b) { finkr = b; } + void print_on(TMask& m); void read_from(const TMask& m); bool update(const char* s); }; +class TPrint_section : public TArray +{ + static TMask* _msk; + enum { MAXCOLUMNS = 32 }; + + word _height; // Altezza della sezione + bool _dirty; // Flag di modifica parametri + bool _columnwise; // Columnwise field specification + + TForm* _form; // Form cui appartiene alla sezione + char _sec_type; // H, B, F, G + pagetype _page_type; // Tipo della pagina + bool _subsection; // e' una sottosezione + + TArray _item; // Lista dei campi da stampare + int _repeat_count; // n. ripetizioni eseguite + + int _tab[MAXCOLUMNS]; // columns offset if columnwise + + const TPrint_section& copy(const TPrint_section& ps); + +protected: + + virtual void print_on(ostream& out) const; + virtual TForm_item* parse_item(const TString& key); + TForm_item* parse_item(TScanner& scanner); + + // handlers for section editing + static bool detail_field_handler(TMask_field&, KEY); + static bool special_field_handler(TMask_field&, KEY); + static bool detail_field_notify (TSheet_field&, int, KEY); + +public: + + TPrintrow& row(int num); + TForm& form() const { return *_form; } + + TForm_item& field(int n) const { return (TForm_item&)_item[n]; } + TForm_item& find_field(short id) const; + void destroy_field(int n) { _item.destroy(n, TRUE); } + void change_field(int n, TForm_item* f); + void insert_field(int n, TForm_item* f); + + word fields() const { return _item.items(); } + word height() const { return _height; } + void offset(int& x, int& y); + void set_repeat_count(int x) { _repeat_count = x; } + + virtual bool ok() const { return height() > 0 || fields() > 0; } + + void reset(); + virtual bool update(); + bool parse(TScanner& scanner); + + bool read_from(const TRectype& rec); + void print_on(TRectype& rec); + + bool edit(const char* title); + char section_type() const { return _sec_type; } + pagetype page_type() const { return _page_type; } + + bool dirty() const { return _dirty; } + void set_dirty(bool d = TRUE) { _dirty = d; } + bool columnwise() const { return _columnwise; } + // ritorna l'offset della colonna corrispondente se columnwise + int tab(int col); + + const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); } + TPrint_section(TForm* parent, char st, pagetype pt, bool subsection = FALSE); + TPrint_section(const TPrint_section& ps) { copy(ps); } + virtual ~TPrint_section(); +}; + class TForm_item : public TObject { + friend class TPrint_section; + TPrint_section* _section; TForm_flags _flag; TBit_array _group; + TAssoc_array _special; -protected: - short _id, _x, _y, _width, _height, _effective_height; +protected: + + short _id, _x, _y, _width, _height, _effective_height, _ofs; TString _prompt; TString _desc; TString_array _message; @@ -273,12 +310,15 @@ protected: void string_at(int x, int y, const char* s); public: + short id() const { return _id; } virtual int width() const { return _width; } virtual void set_width(int w) { _width = w; } virtual int height() const { return _height; } + virtual short& ofs() { return _ofs; } virtual int effective_height() const { return _effective_height; } - virtual short& x() { return _x; } + virtual short& x() { return _x; }; + virtual short x() const; virtual short& y() { return _y; } bool shown() const { return _flag.shown; } @@ -286,20 +326,29 @@ public: bool enabled() const { return _flag.enabled; } bool disabled() const { return !_flag.enabled; } bool automagic() const { return _flag.automagic; } + bool finkl() const { return _flag.finkl; } + bool finkr() const { return _flag.finkr; } virtual bool parse(TScanner&); virtual bool update(); virtual void print_on(TMask& m); - virtual void read_from(const TMask& m); - - virtual bool read_from(const TRectype& rform); virtual void print_on(TRectype& rform); + virtual void print_on_sheet_row(TToken_string& t) const; + + virtual void read_from(const TMask& m); + virtual bool read_from(const TRectype& rform); + virtual void read_from(TToken_string& s); virtual bool edit(TMask& m); virtual const char* get() const { return _prompt; } virtual bool set(const char* s) { _prompt = s; return TRUE; } + + // example() ritorna un esempio del formato corrente + virtual const char* example() const { return ""; } + +// const char* prompt() const { return _prompt; } const TString& prompt() const { return _prompt; } virtual const TString& picture() const; // Da' CHECK @@ -320,9 +369,19 @@ public: void hide() { show(FALSE); } virtual void enable(bool on = TRUE); void disable() { enable(FALSE); } - + + // variabili personalizzate low-level + int special_items() const { return _special.items(); } + TAssoc_array& specials() const { return (TAssoc_array&)_special; } + // high-level + int get_special_names(TString_array& r); + const char* get_special_value(const char*); + const char* get_special_type (const char*); + const char* get_special_description(const char*); + TForm_item(TPrint_section* section); virtual ~TForm_item() {} }; + #endif diff --git a/include/mask.cpp b/include/mask.cpp index fdf6da0d9..50269a9c3 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -1546,6 +1546,48 @@ WINDOW TMask::add_string ( return f->win(); } +// @mfunc Aggiunge runtime un campo lista alla maschera +// +// @rdesc Ritorna l'handle del campo creato +WINDOW TMask::add_list ( + short id, // @parm Numero identificatore del campo da aggiungere + int page, // @parm Pagina nel quale aggiungere il campo + const char* prompt, // @parm Prompt del campo + int x, // @parm Coordinata x (in caratteri) + int y, // @parm Coordinata y (in caratteri) + int dim, // @parm Lunghezza del campo sulla maschera + const char* flags, // @parm Flag di controllo del campo (default "") + const char* codes, // @parm tokenstringa con i codici (NULL def.) + const char* items) // @parm tokenstringa con gli items (NULL def.) + + // @xref + // +{ + TList_field* f = new TList_field(this); + f->construct(id, prompt, x, y, dim, _pagewin[page], flags); + f->replace_items(codes,items); + _field.add(f); + return f->win(); +} + + // @cmember Aggiunge runtime un campo boolean alla maschera +WINDOW TMask::add_boolean ( + short id, // @parm Numero identificatore del campo da aggiungere + int page, // @parm Pagina nel quale aggiungere il campo + const char* prompt, // @parm Prompt del campo + int x, // @parm Coordinata x (in caratteri) + int y, // @parm Coordinata y (in caratteri) + const char* flags) // @parm Flag di controllo del campo (default "") + + // @xref + // +{ + TBoolean_field* f = new TBoolean_field(this); + f->construct(id, prompt, x, y, strlen(prompt), _pagewin[page], flags); + _field.add(f); + return f->win(); +} + // @mfunc Aggiunge runtime un campo zoom alla maschera // // @rdesc Ritorna l'handle del campo creato diff --git a/include/mask.h b/include/mask.h index ca6790027..87051f6c1 100755 --- a/include/mask.h +++ b/include/mask.h @@ -164,12 +164,16 @@ public: WINDOW add_date (short id, int page, const char* prompt, int x, int y, const char* flags = ""); // @cmember Aggiunge runtime un campo bottone alla maschera WINDOW add_button (short id, int page, const char* prompt, int x, int y, int dx = 9, int dy = 1, const char* flags = ""); + // @cmember Aggiunge runtime un campo boolean alla maschera + WINDOW add_boolean (short id, int page, const char* prompt, int x, int y, const char* flags = ""); // @cmember Aggiunge runtime un campo radio button alla maschera WINDOW add_radio(short id, int page, const char* prompt, int x, int y, int dx, const char* codes, const char* items, const char* flags = ""); // @cmember Aggiunge runtime un campo memo alla maschera WINDOW add_memo (short id, int page, const char* prompt, int x, int y, int dx = 78, int dy = 4, const char* flags = ""); // @cmember Aggiunge runtime un campo zoom alla maschera WINDOW add_zoom (short id, int page, const char* prompt, int x, int y, int dim, const char* flags = "", int width = 0); + // @cmember Aggiunge runtime un campo lista alla maschera + WINDOW add_list (short id, int page, const char* prompt, int x, int y, int dim, const char* flags = "", const char* codes = NULL, const char* items = NULL); // @cmember Ritorna il numero di campi della maschera int fields() const