From e957ff5b78c8e50114e3b065f585bdb3dfe026ab Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 14 Apr 2004 14:21:12 +0000 Subject: [PATCH] Patch level : 2.1 nopatch Files correlati : ba8.exe Ricompilazione Demo : [ ] Commento : Correzioni sulla generazione query e report git-svn-id: svn://10.65.10.50/trunk@11971 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba8200.cpp | 43 +++++++++++- ba/ba8201.cpp | 43 ++++++++++-- ba/ba8201.h | 3 +- ba/ba8300.cpp | 6 +- ba/ba8302.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++++---- ba/ba8302.h | 1 + ba/ba8303.cpp | 111 ++++++++++++++++++++++++------ ba/ba8303.h | 8 ++- ba/ba8304.cpp | 25 +++---- 9 files changed, 358 insertions(+), 66 deletions(-) diff --git a/ba/ba8200.cpp b/ba/ba8200.cpp index 77fa65941..5a711a2f5 100755 --- a/ba/ba8200.cpp +++ b/ba/ba8200.cpp @@ -292,6 +292,7 @@ class TQuery_mask : public TAutomask TFilename _curr_query;// Nome completo della query in editazione bool _is_dirty; // Maschera cambiata dall'ultimo caricamento + bool _sql_dirty; // Query modificata manualmente protected: virtual void handler(WINDOW win, EVENT* ep); @@ -350,8 +351,10 @@ bool TQuery_mask::add_file_to_tree() TTable_mask msk; const TRelation_node* father = curr_node(); + TString fatherid; if (father != NULL) { + _tree.curr_id(fatherid); msk.set(F_FATHER, father->name()); msk.set(F_FATHER_ALIAS, father->alias()); } @@ -362,6 +365,8 @@ bool TQuery_mask::add_file_to_tree() { TRelation_node* son = new TRelation_node(father, msk.son_logicnum(), msk.get(F_SON_ALIAS)); msk.mask2node(*son); + if (fatherid.not_empty()) + _tree.goto_node(fatherid); _tree.add_son(son); _tree.expand_all(); tfield(F_TABLES).win().force_update(); @@ -380,6 +385,8 @@ bool TQuery_mask::edit_file_in_tree() if (son == NULL) return false; + TString sonid; _tree.curr_id(sonid); + const TRelation_node* father = NULL; if (_tree.goto_father()) father = (const TRelation_node*)_tree.curr_node(); @@ -417,6 +424,17 @@ bool TQuery_mask::edit_file_in_tree() case K_DEL: if (curr_node() != NULL) { + if (yesno_box(TR("Eliminare anche le colonne associate della query?"))) + { + TSheet_field& sheet = sfield(F_SHEET); + FOR_EACH_SHEET_ROW_BACK(sheet, r, row) + { + const TString& id = row->get(0); + if (id == son->id()) + sheet.destroy(r); + } + } + _tree.goto_node(sonid); _tree.kill_node(); _tree.goto_root(); } @@ -670,6 +688,9 @@ void TQuery_mask::sheet2sql() sql << ";"; set(F_SQL, sql, true); + _sql_dirty = false; + TEdit_field& fs = efield(F_SQL); + fs.set_focusdirty(false); // Evita di scatenare eventi inutili } static int select_callback(void* jolly, int argc, char** value, char** field) @@ -937,6 +958,7 @@ void TQuery_mask::global_reset() tf.win().force_update(); } reset(); + _is_dirty = _sql_dirty = false; } // Caica l'intera query @@ -974,7 +996,9 @@ bool TQuery_mask::load_query() { TString str; sql->GetEnclosedText(str); set(F_SQL, str, true); // Aggiorna anche stato bottoni di esportazione - field(F_SQL).set_dirty(false); // Evita falsi allarmi di registrazione + TEdit_field& sf = efield(F_SQL); + sf.set_dirty(false); // Evita falsi allarmi di registrazione + _sql_dirty = !sf.empty(); } _is_dirty = false; // Resetta definitivamente il dirty } @@ -1046,8 +1070,14 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) case F_GENSQL: if (e == fe_button) { - sheet2sql(); next_page(1001); + bool ok = true; + if (_sql_dirty) + ok = yesno_box(TR("Attenzione: la query verra' rigenerata\n" + "annullando eventuali modifiche manuali.\n" + "Si desidera proseguire?")); + if (ok) + sheet2sql(); } break; case F_EDITQUERY: @@ -1058,7 +1088,11 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) if (e == fe_init || e == fe_modify) { enable(-2, !o.empty()); - _is_dirty = e == fe_modify; + if (e == fe_modify) + { + _is_dirty = true; + _sql_dirty = !o.empty(); + } } break; case F_EXPORT_HTML: @@ -1093,6 +1127,7 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { save_if_needed(); global_reset(); + next_page(1000); } break; case DLG_FINDREC: @@ -1103,12 +1138,14 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { get_qry_path(_curr_query); save_query(); + next_page(1000); } break; case DLG_DELREC: if (e == fe_button && jolly == 0) // Elimina della Toolbar { delete_query(); + next_page(1000); return false; // Do not exit! } break; diff --git a/ba/ba8201.cpp b/ba/ba8201.cpp index 5986e6b15..9b99d7ce3 100755 --- a/ba/ba8201.cpp +++ b/ba/ba8201.cpp @@ -74,6 +74,19 @@ void TVariant::set(const long n) _ptr = (void*)n; } +bool TVariant::is_zero() const +{ + switch (_type) + { + case _datefld: return !as_date().ok(); + case _longfld: return _ptr == NULL; + case _realfld: return as_real().is_zero(); + case _alfafld: return as_string().blank(); + default: break; + } + return true; +} + TDate TVariant::as_date() const { if (_type == _datefld) @@ -487,8 +500,16 @@ bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt) const TVariant& TRecordset::get(const char* column_name) const { - if (*column_name == '#' && variables().items() > 0) - return get_var(column_name); + if (*column_name == '#') + { + if (variables().items() > 0) + { + const TVariant& var = get_var(column_name); + if (!var.is_null()) + return var; + } + column_name++; + } for (unsigned int i = 0; i < columns(); i++) { @@ -546,7 +567,7 @@ bool ask_variable(const char* name, TVariant& var) return ok; } -bool TRecordset::ask_variables(bool all) const +bool TRecordset::ask_variables(bool all) { const bool ok = variables().items() > 0; if (ok) // Se ci sono variabili faccio le sostituzioni @@ -554,12 +575,16 @@ bool TRecordset::ask_variables(bool all) const FOR_EACH_ARRAY_ROW(_varnames, i, name) { TVariant var = get_var(*name); - if (var.is_null() || all) // Mi serve assolutamente un valore! + if (var.is_null() || all) { ask_variable(*name, var); - ((TSQL_recordset*)this)->set_var(*name, var); + if (var.is_null()) + var.set(""); // Mi serve assolutamente un valore! + + set_var(*name, var); } } + move_to(-1); } return ok; } @@ -993,7 +1018,7 @@ TSQLite::~TSQLite() void TSQL_recordset::reset() { - _firstrow = _items = 0; + _items = 0; _pagesize = 512; _page.destroy(); _column.destroy(); @@ -1039,7 +1064,8 @@ static int query_get_items(void* jolly, int argc, char** values, char** columns) void TSQL_recordset::parsed_sql_text(TString& sql) const { sql = _sql; - if (ask_variables(false)) // Se ci sono variabili faccio le sostituzioni + const bool vars = ((TSQL_recordset*)this)->ask_variables(false); + if (vars) // Se ci sono variabili faccio le sostituzioni { const TString_array& names = variables(); FOR_EACH_ARRAY_ROW(names, i, name) // Scandisco tutte le variabili @@ -1105,7 +1131,10 @@ bool TSQL_recordset::move_to(TRecnotype n) { _current_row = n; if (n < 0 || n >= items()) + { + _page.destroy(); // Forza rilettura la prossiva volta return false; + } if (n < _firstrow || n >= _firstrow+_page.items()) { diff --git a/ba/ba8201.h b/ba/ba8201.h index 401452aa7..79d31c62c 100755 --- a/ba/ba8201.h +++ b/ba/ba8201.h @@ -37,6 +37,7 @@ public: TFieldtypes type() const { return _type; } bool is_null() const { return _type == _nullfld; } + bool is_zero() const; void set_null(); void set(const char* str); @@ -112,7 +113,7 @@ public: // Absolutely needed methods virtual const TString_array& variables() const { return _varnames; } virtual const TVariant& get_var(const char* name) const; virtual bool set_var(const char* name, const TVariant& var, bool create = false); - bool ask_variables(bool all) const; + bool ask_variables(bool all); virtual const TString& query_text() const; virtual const TVariant& get(const char* column_name) const; diff --git a/ba/ba8300.cpp b/ba/ba8300.cpp index 31e79d562..fb68422b7 100755 --- a/ba/ba8300.cpp +++ b/ba/ba8300.cpp @@ -210,7 +210,7 @@ void TReport_field_mask::vedo_non_vedo() const char type = get(F_TYPE)[0]; const bool is_text = strchr("DNPSTV", type) != NULL; - show(F_HIDE_ZEROES, strchr("NPV", type) != NULL), + show(F_HIDE_ZEROES, strchr("DNPV", type) != NULL), show(F_HALIGN, is_text); show(F_VALIGN, is_text); show(F_TEXT, is_text); @@ -762,6 +762,7 @@ void TReport_mask::add_field() void TReport_mask::edit_field(TReport_field& rf) { + TReport_section& rs = rf.section(); TReport_field_mask m; m.set_field(rf); const KEY key = m.run(); @@ -772,7 +773,6 @@ void TReport_mask::edit_field(TReport_field& rf) break; case K_DEL: { - TReport_section& rs = rf.section(); for (int i = rs.last(); i >= 0; i--) if (rs.objptr(i) == &rf) { rs.destroy(i, true); @@ -785,7 +785,7 @@ void TReport_mask::edit_field(TReport_field& rf) if (key != K_ESC) { _is_dirty = true; - rf.section().sort(); + rs.sort(); update_report(); } } diff --git a/ba/ba8302.cpp b/ba/ba8302.cpp index ffaadf946..70a8f21fb 100755 --- a/ba/ba8302.cpp +++ b/ba/ba8302.cpp @@ -268,6 +268,38 @@ void advanced_draw_rect(TWindow& win, const RCT& r, int border, COLOR fore, COLO } } +void advanced_draw_justified_text(TWindow& win, const char* text, short x, short y, short dx) +{ + TString txt(text); txt.rtrim(); + int spaces = 0; + for (int s = 0; txt[s]; s++) + if (isspace(txt[s])) spaces++; + const int tw = xvt_dwin_get_text_width(win.win(), txt, -1); + if (tw < dx && spaces > 0) + { + txt << ' '; // Aggiunge spazio finale + const double kspc = double(dx - tw) / spaces; + int start = 0; + double kx = x; + for (int i = 0; txt[i]; i++) + { + if (isspace(txt[i])) + { + const bool last_word = txt[i+1] == '\0'; + const TString& parola = txt.sub(start, i + (last_word ? 0 : 1)); + const int lw = xvt_dwin_get_text_width(win.win(), parola, -1); + if (last_word) // ultima parola + kx = x+dx-lw; + xvt_dwin_draw_text(win.win(), int(kx+0.5), y, parola, -1); + kx += lw + kspc; + start = i+1; + } + } + } + else + xvt_dwin_draw_text(win.win(), x, y, text, -1); +} + void advanced_draw_text(TWindow& win, const char* text, const RCT& r, char halign, char valign) { @@ -297,7 +329,10 @@ void advanced_draw_text(TWindow& win, const char* text, const RCT& r, default : y -= descent; break; } - xvt_dwin_draw_text(win.win(), x, y, text, -1); + if (halign == 'J') + advanced_draw_justified_text(win, text, x, y, dx); + else + xvt_dwin_draw_text(win.win(), x, y, text, -1); } static void set_num_attr(TXmlItem& item, const char* attr, long num, short def = 0) @@ -433,17 +468,24 @@ TPoint TReport_section::compute_size() const return TPoint(0,0); TPoint s = _size; - for (int i = 0; i < items(); i++) + if (_size.x <= 0 || _size.y <= 0) // Calcolo automatico necessario { - const TReport_field& rf = field(i); - if (rf.shown()) + for (int i = 0; i < items(); i++) { - const TRectangle& r = rf.get_rect(); - if (r.right() > s.x) - s.x = r.right(); - if (r.bottom() > s.y) - s.y = r.bottom(); + const TReport_field& rf = field(i); + if (rf.shown()) + { + const TRectangle& r = rf.get_rect(); + if (_size.x <= 0 && r.right() > s.x) // Richiesto calcolo larghezza + s.x = r.right(); + if (_size.y <= 0 && r.bottom() > s.y) // Richiesto calcolo altezza + s.y = r.bottom(); + } } + if ((s.x % 100) != 0) // Arrotonda alla colonna successiva + s.x = (s.x / 100 + 1) * 100; + if ((s.y % 100) != 0) // Arrotonda alla riga successiva + s.y = (s.y / 100 + 1) * 100; } return s; } @@ -875,7 +917,26 @@ bool TReport_field::load_field() { const TFieldtypes ft = var_type(); if (ft != _nullfld) - section().report().evaluate(_field, _var, ft); + { + if (_field.starts_with("SELECT ")) + { + TSQL_recordset qry(_field); + TString str; + for (int i = 0; i < qry.items(); i++) + { + if (i > 0) str << '\n'; + for (unsigned int j = 0; j < qry.columns(); j++) + { + if (j > 0) str << ' '; + str << qry.get(j).as_string(); + } + } + _var.set(str); + _var.convert_to(ft); + } + else + section().report().evaluate(_field, _var, ft); + } else _var.set_null(); } @@ -903,12 +964,102 @@ void TReport_field::draw_rect(TWindow& win) const void TReport_field::draw_text(TWindow& win, const char* text) const { - RCT r; win.log2dev(get_rect(), r); + const TRectangle& rct = get_rect(); + RCT r; win.log2dev(rct, r); advanced_draw_rect(win, r, border(), fore_color(), back_color()); xvt_dwin_set_font(win.win(), font().get_xvt_font(win)); win.set_color(fore_color(), back_color()); - advanced_draw_text(win, text, r, _halign, _valign); + + if (rct.height() > 100) + { + const int columns = rct.width() / 100; + int rows = rct.height() / 100; + TParagraph_string str(text, columns); + if (str.items() < rows) + rows = str.items(); + + int ybase = rct.y; + switch (_valign) + { + case 'C': ybase += (rct.height() - rows*100) / 2; break; + case 'B': ybase += rct.height() - rows*100; break; + default : break; + } + char halign = _halign; + char valign = 'T'; + for (int row = 0; row < rows; row++) + { + TRectangle rctline = rct; + rctline.y = ybase+100*row; + rctline.set_height(100); + win.log2dev(rctline, r); + if (halign == 'J' && row == rows-1) + halign = 'L'; + advanced_draw_text(win, str.get(), r, halign, valign); + } + } + else + advanced_draw_text(win, text, r, _halign, _valign); +} + +const TString& TReport_field::formatted_text() const +{ + if (_hide_zeroes && _var.is_zero()) + return EMPTY_STRING; + + switch (_type) + { + case 'D': + { + const TDate d = _var.as_date(); + TString& tmp = get_tmp_string(); + if (_picture.not_empty()) + { + if (_picture.find('#') >= 0) + { + TString8 str; str.format("%02d%02d%04d", d.day(), d.month(), d.year()); + tmp.picture(_picture, str); + } + else + tmp << _picture << ' ' << d; + } + else + tmp = d.string(_rct.width() >= 1000 ? full : brief); + return tmp; + } + break; + case 'N': + { + const real n = _var.as_real(); + TString& tmp = get_tmp_string(); + if (_picture.not_empty()) + tmp = n.string(_picture); + else + tmp = n.stringa(); + return tmp; + } + break; + case 'P': + { + TString& tmp = get_tmp_string(); + TPrice cur(_var.as_real()); + tmp = cur.string(true); + return tmp; + } + break; + case 'V': + { + TString& tmp = get_tmp_string(); + TCurrency cur(_var.as_real()); + tmp = cur.string(true); + return tmp; + } + break; + default: + return _var.as_string(); + } + return EMPTY_STRING; } void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const @@ -1008,7 +1159,10 @@ void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const draw_text(win, _field); } else - draw_text(win, _var.as_string()); + { + const TString& str = formatted_text(); + draw_text(win, str); + } break; } @@ -1199,7 +1353,7 @@ int TReport::find_max_level(char type) const TAssoc_array& ass = (TAssoc_array&)_sections; FOR_EACH_ASSOC_OBJECT(ass, h, k, o) if (k[0] == type1 || k[0] == type2) { - const int l = k[1]-'0'; + const int l = atoi(k+1); if (l > lev) lev = l; } @@ -1305,7 +1459,7 @@ bool TReport::evaluate(const char* expr, TVariant& var, TFieldtypes force_type) if (e.numvar() == 1) { const char* name = e.varname(0); - if (*name == '#' && strcmp(name, expr) == 0) + if (strcmp(name, expr) == 0) { const TFixed_string usr(name); if (get_usr_val(usr, var)) diff --git a/ba/ba8302.h b/ba/ba8302.h index 0ae57a2c8..d5fbc8eae 100755 --- a/ba/ba8302.h +++ b/ba/ba8302.h @@ -229,6 +229,7 @@ protected: virtual int compare(const TSortable& s) const; void copy(const TReport_field& rf); TFieldtypes var_type() const; + const TString& formatted_text() const; public: virtual TObject* dup() const { return new TReport_field(*this); } diff --git a/ba/ba8303.cpp b/ba/ba8303.cpp index b9438e8b5..ffc1afe1d 100755 --- a/ba/ba8303.cpp +++ b/ba/ba8303.cpp @@ -57,6 +57,7 @@ void TPrint_preview_window::update() #define POPUP_LAST 20887 #define POPUP_ZOOMIN 20888 #define POPUP_ZOOMOUT 20889 +#define POPUP_GRID 20890 void TPrint_preview_window::popup_menu(EVENT* ep) { @@ -69,6 +70,9 @@ void TPrint_preview_window::popup_menu(EVENT* ep) menu[4].tag = -1; menu[4].separator = true; menu[5].tag = POPUP_ZOOMIN; menu[5].text = (char*)TR("Zoom +"); menu[5].enabled = _zoom < 300; menu[6].tag = POPUP_ZOOMOUT; menu[6].text = (char*)TR("Zoom -"); menu[6].enabled = _zoom > 75; + menu[7].tag = -1; menu[7].separator = true; + menu[8].tag = POPUP_GRID; menu[8].text = (char*)TR("Griglia"); menu[8].enabled = true; + menu[8].checkable = true; menu[8].checked = _printer->show_preview_grid(); const PNT& p = ep->v.mouse.where; xvt_menu_popup(menu, win(), p, XVT_POPUP_CENTER, 0); @@ -115,6 +119,7 @@ void TPrint_preview_window::handler(WINDOW win, EVENT* ep) break; case POPUP_ZOOMIN : if (_zoom < 300) { _zoom += 25; } break; case POPUP_ZOOMOUT: if (_zoom > 75) { _zoom -= 25; } break; + case POPUP_GRID : _printer->toggle_preview_grid(); break; default:processed = false; break; } if (processed) @@ -140,6 +145,8 @@ bool TPrint_preview_window::on_key(KEY k) case K_RIGHT : dispatch_e_menu(win(), POPUP_NEXT); break; case K_END: case K_LEND : dispatch_e_menu(win(), POPUP_LAST); break; + case 'G' : + case 'g' : dispatch_e_menu(win(), POPUP_GRID); break; default : ok = TField_window::on_key(k); break; }; return ok; @@ -205,6 +212,8 @@ bool TPreview_mask::on_key(KEY k) case K_RIGHT: case K_END : case K_LEND : + case 'G' : + case 'g' : dispatch_e_char(_printer->win(), k); return true; default: @@ -339,16 +348,27 @@ bool TPage_printer::main_loop() TPrinter& p = printer(); _rcd = p.get_printrcd(); if (!xvt_print_is_valid(_rcd)) - return TRUE; // aborted + return false; // aborted WINDOW prwin = xvt_print_create_win(_rcd, (char*)(const char*)form_name()); if (prwin == NULL_WIN) - return TRUE; // aborted + return false; // aborted set_win(prwin); xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr); + if (_pw <= 0 || _ph <= 0) + return error_box(TR("Dimensioni pagina NULLE")); + bool ok = true; + if (_pvr < 150 || _phr < 150) + { + ok = yesno_box(TR("Stampante obsoleta o non adeguatamente configurata:\n" + "Risoluzione %ldx%ld. Continuare ugualmente?"), _phr, _pvr); + if (!ok) + return false; + } + for (word c = 0; c < _copies && ok; c++) { _page = 0; @@ -438,11 +458,11 @@ bool TPage_printer::do_preview() TPrinter& p = printer(); _rcd = p.get_printrcd(); if (!xvt_print_is_valid(_rcd)) - return error_box("Stampante non valida"); + return error_box(TR("Stampante non valida")); xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr); - if (_ph <= 0) - return error_box("Risoluzione stampante NULLA"); + if (_pw <= 0 || _ph <= 0) + return error_box(TR("Dimensioni pagina NULLE")); _preview_mask = new TPreview_mask(this); TPrint_preview_field& pf = (TPrint_preview_field&)_preview_mask->field(DLG_USER); @@ -478,7 +498,8 @@ TPoint TPage_printer::page_res() const return pt; } -TPage_printer::TPage_printer() : _pagefrom(1), _pageto(0), _copies(1), _preview_mask(NULL) +TPage_printer::TPage_printer() + : _pagefrom(1), _pageto(0), _copies(1), _preview_mask(NULL), _draw_grid(true) { _pixmap = true; // Fondamentale!!! } @@ -526,6 +547,32 @@ long TReport_printer::print_section(char type, int level) return h; } +void TReport_printer::draw_preview_page() +{ + clear(COLOR_WHITE); + + if (_draw_grid) + { + const int max = 192; + const int k = 100; + for (int i = 1; i < max; i++) + { + set_pen((i%10) ? MAKE_COLOR(232,232,232) : COLOR_LTGRAY); + line(0, i*k, max*k, i*k); + line(i*k, 0, i*k, max*k); + } + } + + const PNT pag = log2dev(_logical_page_width, _logical_page_height); + hide_pen(); + set_brush(COLOR_GRAY); + RCT rct; + xvt_vobj_get_client_rect(win(), &rct); rct.left = pag.h; + xvt_dwin_draw_rect(win(), &rct); + xvt_vobj_get_client_rect(win(), &rct); rct.top = pag.v; + xvt_dwin_draw_rect(win(), &rct); +} + bool TReport_printer::open_page() { const bool ok = TPage_printer::open_page(); @@ -536,17 +583,7 @@ bool TReport_printer::open_page() _page_break_allowed = false; if (ok && preview_mode()) // Clear page needed - { - clear(COLOR_WHITE); - const int max = 192; - const int k = 100; - for (int i = 1; i < max; i++) - { - set_pen((i%10) ? MAKE_COLOR(232,232,232) : COLOR_LTGRAY); - line(0, i*k, max*k, i*k); - line(i*k, 0, i*k, max*k); - } - } + draw_preview_page(); print_section('B', 0); if (_page == 1) @@ -612,9 +649,14 @@ bool TReport_printer::print_loop() const TPoint siz = page_size(); const TPoint res = page_res(); - const double pollici_pagina = (double)siz.y / (double)res.y; - const double righe_pagina = pollici_pagina * _report.lpi(); + const double pollici_pagina_y = (double)siz.y / (double)res.y; + const double righe_pagina = pollici_pagina_y * _report.lpi(); _logical_page_height = long(righe_pagina*100.0); + + const double pollici_pagina_x = (double)siz.x / (double)res.x; + const double colonne_pagina = pollici_pagina_x * _report.cpi(); + _logical_page_width = long(colonne_pagina*100.0); + const long logical_footer_height = _report.section('F',0).compute_size().y; _logical_foot_pos = _logical_page_height - logical_footer_height; @@ -628,6 +670,7 @@ bool TReport_printer::print_loop() oldgroup.add(EMPTY_STRING, g); } const int max_body = _report.find_max_level('B'); + int last_body_height = 0; _is_last_page = false; open_page(); @@ -655,6 +698,11 @@ bool TReport_printer::print_loop() if (changed) { oldgroup = newgroup; + + if (_delta.x > 0) // Devo tornare a capo! + _delta.y += last_body_height; + _delta.x = 0; + if (rex.current_row() > 0) { for (int g = 2; g <= changed; g++) @@ -666,7 +714,30 @@ bool TReport_printer::print_loop() } for (int b = 1; b <= max_body; b++) - _delta.y += print_section('B', b); + { + const int dy = print_section('B', b); + + int column_delta = 0; + // Cerco di vedere se e' possibile la stampa etichette + if (dy > 0) + { + const int dx = _report.section('B', b).size().x; + // Se dx > 0 ho una sezione a dimensione fissa + if (dx > 0 && _delta.x+2*dx <= _logical_page_width) + { + column_delta = dx; + last_body_height = dy; + } + } + if (column_delta > 0) + _delta.x += column_delta; + else + { + _delta.x = 0; + _delta.y += dy; + last_body_height = 0; // Non servirebbe strettamente + } + } } if (!aborted) { diff --git a/ba/ba8303.h b/ba/ba8303.h index a71939b9b..16cbfbb83 100755 --- a/ba/ba8303.h +++ b/ba/ba8303.h @@ -12,7 +12,7 @@ class TPage_printer : public TWindow protected: word _copies, _pagefrom, _pageto, _page, _lastprinted; - bool _page_is_open; + bool _page_is_open, _draw_grid; TMask* _preview_mask; // owned object TWindow* _preview_window; // referenced object @@ -51,6 +51,9 @@ public: bool print_mode() const { return _preview_mask == NULL; } bool preview_mode() const { return _preview_mask != NULL; } + void toggle_preview_grid() { _draw_grid = !_draw_grid; } + bool show_preview_grid() const { return _draw_grid; } + TPage_printer(); virtual ~TPage_printer(); }; @@ -59,7 +62,7 @@ class TReport_printer : public TPage_printer { TReport& _report; TPoint _delta; - long _logical_page_height; + long _logical_page_height, _logical_page_width; long _logical_foot_pos; bool _is_last_page, _page_break_allowed; @@ -71,6 +74,7 @@ protected: virtual PNT log2dev(long x, long y) const; virtual bool print_loop(); + virtual void draw_preview_page(); virtual bool open_page(); virtual bool close_page(); long print_section(TReport_section& rs); diff --git a/ba/ba8304.cpp b/ba/ba8304.cpp index e511ad50a..134760dbd 100755 --- a/ba/ba8304.cpp +++ b/ba/ba8304.cpp @@ -63,11 +63,11 @@ bool TVariant_stack::push(const real& n) // TAVM_op /////////////////////////////////////////////////////////// -enum AVM_opcode { avm_nop, avm_add , avm_div , avm_dot, - avm_cmp_eq, avm_cmp_gt, avm_cmp_gteq, avm_cmp_lt, avm_cmp_lteq, avm_cmp_noteq, - avm_drop, avm_dup, avm_else, - avm_fetch, avm_if, avm_push, avm_rot, avm_store, - avm_sub, avm_swap, avm_then, avm_usrword }; +enum AVM_opcode { avm_nop, avm_add, avm_div, avm_dot, + avm_cmp_eq, avm_cmp_gt, avm_cmp_gteq, avm_cmp_lt, avm_cmp_lteq, avm_cmp_noteq, + avm_drop, avm_dup, avm_else, + avm_fetch, avm_if, avm_push, avm_rot, avm_store, + avm_sub, avm_swap, avm_then, avm_usrword }; class TAVM_op : public TObject { @@ -222,7 +222,7 @@ bool TAVM::compile(istream& instr, TBytecode& bytecode) TAVM_op& ifop = (TAVM_op&)bytecode[i]; if (ifop.op() == avm_if && ifop.var().is_null()) { - ifop.var() = bytecode.items() - i; + ifop.var() = bytecode.items(); break; } } @@ -242,7 +242,7 @@ bool TAVM::compile(istream& instr, TBytecode& bytecode) TAVM_op& ifop = (TAVM_op&)bytecode[i]; if ((ifop.op() == avm_if || ifop.op() == avm_else) && ifop.var().is_null()) { - ifop.var() = bytecode.last() - i; + ifop.var() = bytecode.items(); break; } } @@ -291,7 +291,6 @@ bool TAVM::execute(const TBytecode& bc, ostream& outstr) for (int ip = 0; ip < bc.items(); ip++) { const TAVM_op& op = *(const TAVM_op*)bc.objptr(ip); - bool jumped_elsewhere = false; switch(op.op()) { case avm_add : @@ -334,8 +333,7 @@ bool TAVM::execute(const TBytecode& bc, ostream& outstr) case avm_drop: _stack.drop(); break; case avm_dup: _stack.push(_stack.peek()); break; case avm_else: - ip += op.var().as_int(); - jumped_elsewhere = true; + ip = op.var().as_int(); break; case avm_fetch: { @@ -352,10 +350,7 @@ bool TAVM::execute(const TBytecode& bc, ostream& outstr) break; case avm_if: if (!_stack.pop().as_bool()) - { - ip += op.var().as_int(); - jumped_elsewhere = true; - } + ip = op.var().as_int(); break; case avm_push: _stack.push(op.var()); break; case avm_rot: _stack.roll(2); break; @@ -439,7 +434,7 @@ bool TAlex_virtual_machine::execute(const TBytecode& bc, TString& outs) bool TAlex_virtual_machine::get_usr_val(const TString& name, TVariant& var) const { - if (name == "#DATE") + if (name == "#TODAY") { const TDate oggi(TODAY); var.set(oggi);