From d12de9d60019a17800000ad2fc065187cf73aaca Mon Sep 17 00:00:00 2001 From: angelo Date: Wed, 3 Jan 1996 15:51:25 +0000 Subject: [PATCH] Rif. mod. 96/1. Modifiche effettuate per la gestione e l'anteprima dei profili E.C.: metodi agggiunti: TForm::genera_inmtestazioni, TForm::remove_temp_items, TForm::put_examples, TForm::remove_examples, TForm::set_mode, TPrint_section::set_mode metodi modificati: TForm::reread, TPrint_section::destroy_field, TPrint_section::tab. Corretti inoltre il ricalcolo della larghezza colonna nel caso cambi il font, e sistemato l'offset di stampa. git-svn-id: svn://10.65.10.50/trunk@2382 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/form.cpp | 141 ++++++++++++++++++++++++++++++++++++++++++----- include/form.h | 27 ++++++--- 2 files changed, 146 insertions(+), 22 deletions(-) diff --git a/include/form.cpp b/include/form.cpp index 857da0e01..d5d6e4d1b 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -603,7 +603,6 @@ 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 @@ -881,6 +880,10 @@ bool TForm_item::edit(TMask& m) m.hide(F_PROMPT); m.enable(F_MEMO); m.show(F_MEMO); + m.enable(F_WIDTH); + m.show(F_WIDTH); + m.enable(F_HEIGHT); + m.show(F_HEIGHT); } else { @@ -1122,6 +1125,7 @@ protected: void put_paragraph(const char* s); public: + virtual const int fields() { return _field.items();} virtual const TString& picture() const { return _picture; } virtual void set_picture(const char* p) { _picture = p; } @@ -2015,17 +2019,19 @@ int TPrint_section::tab(int col) // compute column offset _nfld = 0; _tab[0] = 1; + short maxcolreached = 0; for (word i = 0; i < fields(); i++) { if (field(i).shown()) { CHECKD (field(i)._x < MAXCOLUMNS, "Colonna ammessa e non concessa: ", field(i)._x); _tab[field(i)._x] = field(i)._y + 1; // one is for separation + if (field(i)._x > maxcolreached) maxcolreached = field(i)._x; _nfld++; } } // cumulate offsets - for (i = 1; i < _nfld; i++) + for (i = 1; i <= (word)maxcolreached; i++) _tab[i] += _tab[i-1]; } // se manca la colonna, vai a prendere quella immediatamente prima @@ -2571,6 +2577,7 @@ bool TPrint_section::edit(const char* title) TString80 name(m.get(F_FONT)); int size = m.get_int(F_SIZE); + if (size==0) size = form().fontsize(); if (name != form().fontname() || size != form().fontsize()) { if (!form().dirty()) form().set_dirty(); @@ -2595,22 +2602,19 @@ bool TPrint_section::edit(const char* title) for (pagetype pt = odd_page; pt <= last_page; pt = pagetype(pt+1)) { TPrint_section* sec = form().exist(sc, pt); - if (sec != NULL) + if (sec != NULL && !sec->columnwise()) { sec->set_dirty(); for (word i = 0; i < sec->fields() ; i++) { TForm_item& fi = sec->field(i); - short value = sec->columnwise() ? fi.y() : fi.x(); + short value = fi.x(); if (value > 0 && (prm.ratio != 1.0)) { real x_pos; x_pos = value * prm.ratio; x_pos.round(); - if (sec->columnwise()) - fi.y() = (short)x_pos.integer(); - else - fi.x() = (short)x_pos.integer(); + fi.x() = (short)x_pos.integer(); fi.set_dirty(); } } @@ -2921,10 +2925,10 @@ TPrint_section& TForm::section(char s, word pagenum) return section(s, pt); } -bool TForm::reread(char sec, pagetype p) +bool TForm::reread(char sec, pagetype p, bool force) { TPrint_section* s = exist(sec,p); - bool ok = FALSE; + bool ok = force; if (s != NULL) for (word j = 0; j < s->fields(); j++) ok |= s->field(j).dirty(); @@ -3260,7 +3264,7 @@ bool TForm::genera_fincatura(pagetype p, int y1, int y2, int* rows) if (cols[i] != start && cols[i] > 0) { TForm_line* l = new TForm_line(grs); - l->x() = cols[i]-1; + l->x() = cols[i]-1 + body->ofspc(); l->y() = (word)y1; l->id() = -1; l->width() = 1; @@ -3275,11 +3279,12 @@ bool TForm::genera_fincatura(pagetype p, int y1, int y2, int* rows) if (start != 999 && end != 0) { TForm_box* l = new TForm_box(grs); - l->x() = start; + l->x() = start + body->ofspc(); l->y() = (word)y1; l->id() = -1; l->width() = (int)(end + wlast - start + 1); l->height() = (int)(y2 - y1 + 1); + l->set("@B@R"); l->temp() = TRUE; grs->add_field(l); } @@ -3289,7 +3294,7 @@ bool TForm::genera_fincatura(pagetype p, int y1, int y2, int* rows) for (i = 0; rows[i]; i++) { TForm_line* l = new TForm_line(grs); - l->x() = start; + l->x() = start + body->ofspc(); l->y() = (word)rows[i]; l->id() = -1; l->width() = (int)(end + wlast - start + 1); @@ -3302,6 +3307,109 @@ bool TForm::genera_fincatura(pagetype p, int y1, int y2, int* rows) return TRUE; } +bool TForm::genera_intestazioni(pagetype p, short y) +{ + TPrint_section* body = exist('B', p); + if (body == NULL || !body->columnwise()) return FALSE; + + TPrint_section* header = exist('H', p); + if (header == NULL) return FALSE; + + body->reset_tabs(); + const word items = body->fields(); + bool firstcolumn = TRUE; + for (word j=0;jfield(j); + if (!fi.shown()) + continue; + TForm_string* s = new TForm_string(header); + const int x = fi.x() + body->ofspc(); + s->id() = -1; + s->x() = x; + if (firstcolumn) + { + s->x() += 1; + firstcolumn=FALSE; + } + s->y() = y; + s->set_prompt(fi.key()); + s->temp() = TRUE; + header->add_field(s); + } + return TRUE; +} + +void TForm::remove_temp_items(char sec, pagetype p) +{ + TPrint_section* s = exist(sec,p); + if (s!=NULL) + { + const word items = s->fields(); + for (word j=0;jfield(j).temp()) + s->destroy_field(j,FALSE); + } + s->field_array().pack(); + } +} + + +void TForm::put_examples(char sez, pagetype p) +{ + TPrint_section* s = exist(sez,p); + if (s!=NULL) + { + const word items = s->fields(); + for (word i=0;ifield(i); + if (fi.fields()!=0) continue; + if (fi.memo()) + fi.set(fi.memo_info()); + else + if (fi.prompt().empty()) + { + if (fi.class_name() == "DATA") + { + const TDate d(TODAY); + fi.set(d); + } + else + if (fi.class_name() == "NUMERO") + { + fi.set_prompt(fi.example()); + fi.temp() = TRUE; + } + else + fi.set(fi.key()); + } + } + } +} + +void TForm::remove_examples(char sez, pagetype p) +{ + TPrint_section* s = exist(sez,p); + if (s!=NULL) + { + const word items = s->fields(); + for (word i=0;ifield(i); + if (fi.fields()!=0) continue; + if (fi.memo()) + fi.set(""); + else + if (fi.class_name() == "NUMERO" && fi.temp()) + { + fi.set_prompt(""); + fi.temp() = FALSE; + } + } + } +} // Stampa gli items dal from a to // se to < 0 stampa fino alla fine del file @@ -3329,6 +3437,7 @@ bool TForm::print(long from, long to) pr.setheaderhandler(header_handler); // Setta handlers pr.setfooterhandler(footer_handler); + pr.set_offset(_y,_x); if (!pr.is_generic()) { for (pagetype t = odd_page; t <= last_page; t = pagetype(t+1)) @@ -3358,6 +3467,8 @@ bool TForm::print(long from, long to) { pr.formlen(height(odd_page)); } + const bool old_val = pr.isgraphics(); + pr.set_graphics(_background_mode == graphics ? TRUE : FALSE); // Set mode for finkatur & graphics pr.set_char_size(_fontsize); // Set font name and size pr.set_fontname(_fontname); // according to current form const bool was_open = pr.isopen(); @@ -3404,6 +3515,8 @@ bool TForm::print(long from, long to) pr.setheaderhandler(NULL); pr.setfooterhandler(NULL); + pr.set_graphics(old_val); //Reset graphics mode to old value + pr.set_offset(0,0); //Reset global offsets of printer return ok; } @@ -3617,7 +3730,7 @@ void TForm::init() _arrange= TRUE; set_fincatura(printer().get_fincatura()); _dirty= FALSE; - _background_mode = printer().isgraphics() ? graphics : text; + _background_mode = printer().isgraphics() ? graphics : texto; } void TForm::read(const char* name, const char* code, int lev, const char* desc) diff --git a/include/form.h b/include/form.h index d0289a5eb..bf4e77589 100755 --- a/include/form.h +++ b/include/form.h @@ -29,6 +29,7 @@ class TCursor; #endif enum pagetype { odd_page, even_page, first_page, last_page }; +enum bkg_mode { none, texto, graphics } ; pagetype char2page(char); // prototipo della funzione che converte dalla notazione carattere al corrispondente enum pagetype class TForm; @@ -45,9 +46,7 @@ class TForm : public TObject friend class TForm_EC_editor; friend class TPrint_section; - enum bkg_mode - { none, text, graphics } - _background_mode; + bkg_mode _background_mode; TString _name; // Profile name TString _code; // Profile code @@ -133,7 +132,13 @@ public: // verticali, array di posizioni riga con 0 per finire // ritorna FALSE se non c'e' il body per quella pagina bool genera_fincatura(pagetype p, int y1, int y2, int* rows); - + + // Genera le righe di intestazione colonna alla riga indicata, vale per COLUMNWISE + // I form_items di intestazione vengono aggiunti alla sezione header di tipo p con ID -1 + bool genera_intestazioni(pagetype p, short y); + void remove_temp_items(char sec, pagetype p); + void put_examples(char sec, pagetype p); + void remove_examples(char sec, pagetype p); bool print(long from = 0L, long to = -1L); TArray& body() { return _body; } @@ -172,13 +177,16 @@ public: // cambia il formato di tutti i numeri nel form void change_number_format(int w, int dec, const char* p); // Rilegge la sezione specificata - bool reread(char sec, pagetype p); + bool reread(char sec, pagetype p, bool force=FALSE); // editor interface TForm_editor& editor() const; // Notifica l'inizio di stampa dell'ultima pagina void set_last_page(bool lp) { _lastpage = lp; } - + + // Setta il modo di sfondo (fincatura) + void set_mode(bkg_mode b) {_background_mode = b;} + // if code == NULL it's a base form // otherwise it's integrated by a file definition TForm(); @@ -254,7 +262,7 @@ public: TArray& field_array() { return _item; } 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 destroy_field(int n, bool c = TRUE) { _item.destroy(n, c); } void destroy_fields() { _item.destroy(); } void change_field(int n, TForm_item* f); void insert_field(int n, TForm_item* f); @@ -267,6 +275,7 @@ public: // returns 0 if not columnwise; means n. of printable fields word columns() { tab(0); return _nfld; } word height() const { return _height; } + word ofspc() const { return _ofspc; } void offset(int& x, int& y); void set_repeat_count(int x) { _repeat_count = x; } @@ -345,7 +354,9 @@ public: virtual short x() const; virtual short& y() { return _y; } virtual short y() const { return _y; } - + + virtual const int fields() { return 0;} + bool shown() const { return _flag.shown; } bool hidden() const { return !_flag.shown; } bool enabled() const { return _flag.enabled; }