From bb631844eff403767db1e01ac6d1b3da5aac7cba Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 15 May 2003 08:09:47 +0000 Subject: [PATCH] Patch level : 2.0 nopatch Files correlati : stampe Ricompilazione Demo : [ ] Commento : Aggiunta finestra di conferma prima di ogni stampa su carta: e' possibile anche impostare le pagine ed il numero di copie desiderate Corretta nei form la stampa di testi su piu' righe con prompt sulla prima git-svn-id: svn://10.65.10.50/trunk@11132 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/controls.cpp | 2 +- include/form.cpp | 25 +++-------- include/printer.cpp | 75 ++++++++++++++++++++++++-------- include/printwin.cpp | 100 +++++++++++++++++++------------------------ include/printwin.h | 2 +- include/text.cpp | 10 ----- include/text.h | 6 +-- 7 files changed, 113 insertions(+), 107 deletions(-) diff --git a/include/controls.cpp b/include/controls.cpp index aaf79cc36..9aac689cb 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -32,7 +32,7 @@ COLOR DISABLED_COLOR = COLOR_DKGRAY; COLOR DISABLED_BACK_COLOR = MASK_BACK_COLOR; COLOR FOCUS_COLOR = NORMAL_COLOR; COLOR FOCUS_BACK_COLOR = COLOR_YELLOW; -COLOR REQUIRED_BACK_COLOR = MAKE_COLOR(255,255,216); +COLOR REQUIRED_BACK_COLOR = MAKE_COLOR(255,255,156); bool CAMPI_SCAVATI = TRUE; bool AUTOSELECT = FALSE; diff --git a/include/form.cpp b/include/form.cpp index 27f9a3c4c..331e507eb 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -1074,28 +1074,15 @@ void TForm_string::put_paragraph(const char* s) if (h > 1) { - /* - const int w = width(); - TParagraph_string p(s, w); - int i = _prompt.not_empty() ? 1 : 0; - for (; (s = p.get()) != NULL && i < h; i++) + TString lines; + if (_prompt.not_empty()) + lines = _prompt; + lines << s; + TParagraph_string p(lines, width()); + for (int i=0; (s = p.get()) != NULL && i < h; i++) string_at(x(), _y+i, s); _effective_height = i; - */ - const int w = width(); - int plen=_prompt.len(); - TString prompt(plen,'-'); - TParagraph_string p(prompt << s, w); -#ifdef DBG - if (plen>0 && *s) - NFCHECK("Nei form la stampa di un item su pił righe con prompt ora non pone pił il prompt isolato sulla prima riga ma allinea a sinistra del prompt "); -#endif - for (int i=0; (s = p.get()) != NULL && i < h; i++) - { - string_at(x()+plen, _y+i, s+plen); - } - _effective_height = i; TForm_subsection *subsec= section().subsection_above(); if (subsec) { diff --git a/include/printer.cpp b/include/printer.cpp index ff5f25038..6784d8e1c 100755 --- a/include/printer.cpp +++ b/include/printer.cpp @@ -11,6 +11,7 @@ #include #include +#include HIDDEN TPrinter* _printer = NULL; @@ -189,23 +190,59 @@ void TPrint_intersector::clear() } /////////////////////////////////////////////////////////// -// PrDesc +// TPrint_txt_info /////////////////////////////////////////////////////////// -struct PrDesc +struct TPrint_txt_info { - TTextfile *_txt; - TPrinter * _p; -} PrintWhat; + TTextfile* _txt; + word _copies; + word _pagefrom; + word _pageto; + + bool edit(); + TPrint_txt_info(TTextfile& txt); +}; + +bool TPrint_txt_info::edit() +{ + TPrinter& p = printer(); + TMask msk("bagn003"); + msk.set(F_PRINTER, p.printername()); + msk.set(F_FONT, p.fontname()); + msk.set(F_SIZE, p.get_char_size()); + msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : ""); + msk.set(F_FROMPAGE, _pagefrom); + msk.set(F_TOPAGE, _pageto); + msk.set(F_COPIES, _copies); + bool ok = msk.run() == K_ENTER; + if (ok) + { + _copies = msk.get_int(F_COPIES); + _pagefrom = msk.get_int(F_FROMPAGE); + _pageto = msk.get_int(F_TOPAGE); + } + return ok; +} + +TPrint_txt_info::TPrint_txt_info(TTextfile& txt) + : _txt(&txt), _copies(1), _pagefrom(1), _pageto(0) +{ + const word ps = txt.page_size(); + const long li = txt.lines(); + _pageto = (li+ps-1) / ps; +} BOOLEAN TPrinter::start_print(long data) { - const PrDesc *pd = (PrDesc *) data; + const TPrint_txt_info *pd = (TPrint_txt_info *) data; TTextfile& txt = *(pd->_txt); - const int vofs = pd->_p->get_line_offset(); - const int hofs = pd->_p->get_column_offset(); + TPrinter& stampante = printer(); + + const int vofs = stampante.get_line_offset(); + const int hofs = stampante.get_column_offset(); - if (pd->_p->is_generic() && (vofs != 0 || hofs != 0)) + if (stampante.is_generic() && (vofs != 0 || hofs != 0)) { TTextfile new_txt; TString s(256); @@ -214,7 +251,7 @@ BOOLEAN TPrinter::start_print(long data) for (long row = (vofs < 0 ? -vofs : 0); row < last_row; row++) { - const int pagelen = pd->_p->formlen(); + const int pagelen = stampante.formlen(); const int page_row = (int) (out_row % pagelen); if (vofs > 0 && page_row == 0) @@ -248,14 +285,14 @@ BOOLEAN TPrinter::start_print(long data) out_row++; } TPrintwin pw(new_txt); - pw.do_print(); + pw.do_print(pd->_pagefrom, pd->_pageto, pd->_copies); return pw.aborted(); } else { TPrintwin pw(txt); if (pw.win() != NULL_WIN) - pw.do_print(); + pw.do_print(pd->_pagefrom, pd->_pageto, pd->_copies); return pw.aborted(); } } @@ -1032,7 +1069,7 @@ void TPrinter::read_configuration( if (iniptr == NULL) iniptr = new TConfig(CONFIG_USER, "Printer"); - const int what = iniptr->get_int("Type", NULL, -1, 0); // Tipo stampante + const int what = iniptr->get_int("Type", NULL, -1, 4); // Tipo stampante _prname = iniptr->get("Name", NULL, -1, _defPrinter); // Nome stampante corrente _printerfile = iniptr->get("File", NULL, -1, ""); // File di stampa _fontname = iniptr->get("Font", NULL, -1, XVT_FFN_FIXED); // Nome del font @@ -1692,11 +1729,13 @@ void TPrinter::print_txt(TTextfile& txt) { if (txt.lines() > 0) { - PrintWhat._txt = &txt; - PrintWhat._p = this; - xvt_print_open(); - xvt_print_start_thread(start_print, (long) (&PrintWhat)); - xvt_print_close(); + TPrint_txt_info what(txt); + if (what.edit()) + { + xvt_print_open(); + xvt_print_start_thread(start_print, long(&what)); + xvt_print_close(); + } /* if (is_generic()) os_spool_row("\n"); // Force flushing on Generic printer diff --git a/include/printwin.cpp b/include/printwin.cpp index 23dae4ab8..cd79ae998 100755 --- a/include/printwin.cpp +++ b/include/printwin.cpp @@ -5,31 +5,21 @@ HIDDEN int LEN_SPACES(WINDOW win, int x) { - HIDDEN long w = 0L; + HIDDEN int w = 0L; + + const int columns = 132; if (x < 0) { - x = 80; + x = columns; w = 0L; - } + } if (w == 0L) { - TString256 spc; spc.fill('m', 132); - w = xvt_dwin_get_text_width(win, spc.get_buffer(), 132); + TString256 spc; spc.fill('m', columns); + w = xvt_dwin_get_text_width(win, spc.get_buffer(), columns); } - const int k = int((w*x) / 132); - -#if defined(DBG) && !defined(XVAGA) - static bool error_on = TRUE; - if (error_on) - { - TString256 spc; spc.fill('m', x); - const int k1 = xvt_dwin_get_text_width(win, spc.get_buffer(), x); - if (k != k1) - error_on = error_box("Maguire disagrees: %d != %d", k, k1); - } -#endif - - return k; + const int tab = w * x / columns; + return tab; } void TPrintwin::paint_background(long j) @@ -293,7 +283,7 @@ void TPrintwin::paint_row(long j) // // @rdesc Ritorna se e' riuscito a stampare in una unica pagina bool TPrintwin::print_band( - int page, // @parm Numero della pagina in cui stampare + int page, // @parm Numero della pagina da stampare const RCT& r) // @parm Parte di finestra da stampare // @comm Di solito viene disegnata l'intera pagina, ma la cosa dipende dal driver di stampa @@ -303,32 +293,22 @@ bool TPrintwin::print_band( // const int offset = printer().get_line_offset(); // const bool generic = _chary == 1; - const long j = ((long)page) * _formlen; + const long first_row = (long)page * _formlen; const int rows = (r.bottom - r.top) / _chary; const int top = r.top / _chary; + const long lines = _txt.lines() + _frlc; for (int k = top; k < top+rows; k++) { - long row = j + k; - - if (row < _txt.lines() + _frlc && k < _formlen) + const long row = first_row + k; + if (row < lines && k < _formlen) paint_row(row); else break; } - return (j + k < _txt.lines() + _frlc); + return (first_row + k < lines); } -#ifdef XVAGA -TPrintwin* _curr_print = NULL; - -bool print_callback(int page, const RCT& rct) -{ - return _curr_print->print_band(page-1, rct); -} - -#endif - // @doc INTERNAL // @mfunc Inizia la stampa @@ -337,32 +317,42 @@ bool print_callback(int page, const RCT& rct) // // @flag TRUE | La stampa e' andata a buon fine // @flag FALSE | La stampa e' stata interrotta -bool TPrintwin::do_print() +bool TPrintwin::do_print(word page_from, word page_to, word copies) // @comm Quando possibile parte un processo concorrente (dipende dal sistema operativo) -{ +{ + CHECKD(page_from > 0, "Invalid page start ", page_from); + CHECKD(copies > 0, "Invalid number of copies ", copies); + _frlc = 0; _blank_lines_to_print = 0; - bool finished = FALSE; - for (int page = 0; !finished && !_aborted; page++) + for (word c = 0; c < copies && !_aborted; c++) { - _aborted = xvt_print_open_page(_printrcd) == 0; - if (!_aborted) + bool finished = FALSE; + for (word page = page_from-1; !finished && !_aborted; page++) { - for (const RCT* rct = xvt_print_get_next_band(); rct != NULL; rct = xvt_print_get_next_band()) - { - set_font(XVT_FFN_SYSTEM, XVT_FS_NONE, _char_size); // ??? - set_font(printer().fontname(), XVT_FS_NONE, _char_size); - LEN_SPACES(win(), -1); // Resetta bene le dimensioni font - if (!print_band(page, *rct)) - { - finished = TRUE; - break; - } - } - _aborted = xvt_print_close_page(_printrcd) == 0; - } - } + if (page_to >= page_from && page >= page_to) + break; + + _aborted = xvt_print_open_page(_printrcd) == 0; + if (!_aborted) + { + for (const RCT* rct = xvt_print_get_next_band(); rct != NULL; rct = xvt_print_get_next_band()) + { + set_font(XVT_FFN_SYSTEM, XVT_FS_NONE, _char_size); // ??? + set_font(printer().fontname(), XVT_FS_NONE, _char_size); + LEN_SPACES(win(), -1); // Resetta bene le dimensioni font + if (!print_band(page, *rct)) + { + finished = TRUE; + while (xvt_print_get_next_band()); // Esce dalla lista delle bande + break; + } + } + _aborted = xvt_print_close_page(_printrcd) == 0; + } + } + } return !_aborted; } diff --git a/include/printwin.h b/include/printwin.h index 05621d8e6..3fc1b0d08 100755 --- a/include/printwin.h +++ b/include/printwin.h @@ -85,7 +85,7 @@ public: { return _aborted; } // @cmember Inizia la stampa (Ritorna FALSE se viene interrotta) - bool do_print(); + bool do_print(word page_from, word page_to, word copies); // @cmember Costruttore TPrintwin(TTextfile& txt); diff --git a/include/text.cpp b/include/text.cpp index 699840f58..8957f98e8 100755 --- a/include/text.cpp +++ b/include/text.cpp @@ -910,16 +910,6 @@ TTextfile ::TTextfile (const char *file, int pagesize, direction preferred, } if (fgets (TEXT_TMP, TEXT_TMP_SIZE, _instr) == NULL) break; - // if (TEXT_TMP[strlen(TEXT_TMP)-1] == '\n') - // TEXT_TMP[strlen(TEXT_TMP)-1] = '\0'; - // if ((_lines) < (_page_start + _page_size)) - // { - // TString *ll = new TString (TEXT_TMP); - // _page.add(ll); - // _page_end++; - - // TBI process links - // } _lines++; } } diff --git a/include/text.h b/include/text.h index 146e62c12..92be557b7 100755 --- a/include/text.h +++ b/include/text.h @@ -59,7 +59,7 @@ class TTextfile: public TObject // @cmember:(INTERNAL) Fine della pagina in coordinate testo long _page_end; // @cmember:(INTERNAL) Numero di righe di

- long _page_size; + word _page_size; // @cmember:(INTERNAL) Numero totale delle linee di testo long _lines; // @cmember:(INTERNAL) Numero della linea corrente @@ -123,8 +123,8 @@ public: // @cmember Ritorna se sono state effettuate delle modifiche bool changed() const { return _dirty; } - - + // @cmember Ritorna il numero di righe per pagina + word page_size() const { return _page_size; } // @cmember Ritorna la stringa di caratteri senza formattazione const char* line(long row, long column = 0, int howmuch = -1);