From f24bcf1babf1dbb2da6094191a7f85480ba1e656 Mon Sep 17 00:00:00 2001 From: villa Date: Mon, 9 Jan 1995 12:15:24 +0000 Subject: [PATCH] Aggiustato text per replace etc; aggiunto bottone DLG_RECALC con icona git-svn-id: svn://10.65.10.50/trunk@836 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/controls.cpp | 3 ++ include/default.url | 1 + include/defmask.h | 1 + include/text.cpp | 83 ++++++++++++++++++++++++++++++++++++++++---- include/text.h | 5 ++- include/urldefid.h | 2 +- include/viswin.cpp | 6 +++- 7 files changed, 92 insertions(+), 9 deletions(-) diff --git a/include/controls.cpp b/include/controls.cpp index acc47b322..5471efb53 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -657,6 +657,9 @@ TPush_button::TPush_button(short left, short top, short right, short bottom, case DLG_SETPRINT: capt = format("#%d", BMP_SETPRINT); break; + case DLG_RECALC: + capt = format("#%d", BMP_RECALC); + break; default: break; } diff --git a/include/default.url b/include/default.url index 3dbc95b8c..b6ccf32cb 100755 --- a/include/default.url +++ b/include/default.url @@ -95,6 +95,7 @@ ACCEL MENU_FILE "f" ALT BMP_LINK bitmap DISCARDABLE f:\p.due\bmp\link.bmp BMP_PRINT bitmap DISCARDABLE f:\p.due\bmp\print.bmp BMP_SETPRINT bitmap DISCARDABLE f:\p.due\bmp\setprint.bmp + BMP_RECALC bitmap DISCARDABLE f:\p.due\bmp\recalc.bmp $$$ #endif diff --git a/include/defmask.h b/include/defmask.h index 165cc357d..6b57f6d9b 100755 --- a/include/defmask.h +++ b/include/defmask.h @@ -28,6 +28,7 @@ #define DLG_LINK 23 /* TAG del bottone Collega (applicazione) */ #define DLG_PRINT 24 /* TAG del bottone Stampa */ #define DLG_SETPRINT 25 /* TAG del bottone Imposta Stampa */ +#define DLG_RECALC 26 /* TAG del bottone Ricalcola */ #define DLG_USER 100 /* TAG del primo controllo definito dall'utente */ /* @M diff --git a/include/text.cpp b/include/text.cpp index 1ab5c4f11..b7b260887 100755 --- a/include/text.cpp +++ b/include/text.cpp @@ -1,6 +1,7 @@ #include #include #include +#include static char mytmpstr[257]; @@ -54,8 +55,77 @@ style TTextfile::_trans_style (char ch) } } -void TTextfile::_read_page (long n) + +void TTextfile::_save_changes() { + main_app().begin_wait(); + // fa i dovuti replace anche sul disco (solo replace di linee esistenti) + long line = 0l; + + fclose(_index); + remove(_indname); + + TString oldfile(_filename); + _filename.temp("txtf"); + + FILE* newf = fopen(_filename, "a+"); + + if ((_index = fopen(_indname, "w+b")) == NULL || newf == NULL) + { + yesnofatal_box ("Impossibile aprire files temporanei"); + freeze(); + return; + } + + fseek(_instr, 0l, SEEK_SET); + + while (!feof(_instr)) + { + const long l = ftell(newf); + fwrite (&l, sizeof(long), 1, _index); + + if (ferror(_index) || ferror(newf)) + { + error_box ("Errore di scrittura file temporaneo: scrittura interrotta"); + freeze (); + } + + if (fgets(mytmpstr, sizeof(mytmpstr), _instr) == NULL) + break; + + if (line >= _page_start && line <= _page_end) + { + TString& lin = (TString&)(_page[(int)(line - _page_start)]); + if (_dirty_lines[line - _page_start]) + { + strcpy(mytmpstr, lin); + strcat(mytmpstr, "\n"); + } + } + + fprintf(newf, "%s", mytmpstr); + line++; + } + + fflush(_index); + fclose(_instr); + fclose(newf); + remove(oldfile); + rename(_filename, oldfile); + _filename = oldfile; + _instr = fopen(_filename, "a+"); + + main_app().end_wait(); +} + +void TTextfile::_read_page (long n) +{ + if (_dirty_lines.ones() > 0l) + { + _save_changes(); + _dirty_lines.reset(); + } + switch (_direction) { case down: @@ -266,6 +336,7 @@ int TTextfile::replace(long l, const char* txt, int pos, int len) if (cnt == pos) { line.overwrite(txt, cnt+skip); + _dirty_lines.set(l-_page_start); return cnt; } else cnt++; @@ -502,18 +573,18 @@ TTextfile ::TTextfile (const char *file, int pagesize, direction preferred): _page_size (pagesize), _page (pagesize), _filename (file), _lines (0l), _index (NULL), _page_start (0l), _page_end (-1l), _direction (preferred), _dirty (FALSE), _istemp (FALSE), _item (0), _line (256), _cur_line (-1), -_hotspots (4), _accept (TRUE) +_hotspots (4), _accept (TRUE), _dirty_lines(pagesize) { // open file & build index if (file == NULL || *file <= ' ') { - _filename.temp (); + _filename.temp("txtf"); _istemp = TRUE; } _isopen = TRUE; _instr = fopen (_filename, "a+"); - _indname.temp (); + _indname.temp("txti"); _index = fopen (_indname, "w+b"); if (_index == NULL || _instr == NULL) @@ -528,8 +599,8 @@ _hotspots (4), _accept (TRUE) fwrite (&l, sizeof (long), 1, _index); if (ferror(_index) || ferror(_instr)) { - error_box ("Errore di scrittura file temporaneo: scrittura interrotta"); - freeze (); + error_box("Errore di scrittura file temporaneo: scrittura interrotta"); + freeze(); } if (fgets (mytmpstr, sizeof (mytmpstr), _instr) == NULL) break; diff --git a/include/text.h b/include/text.h index ea504647e..409cbe3c0 100755 --- a/include/text.h +++ b/include/text.h @@ -28,6 +28,7 @@ class TTextfile: public TObject enum {DEFAULT_PAGESIZE = 128}; TArray _page; + TBit_array _dirty_lines; long _page_start; long _page_end; long _page_size; @@ -49,8 +50,10 @@ class TTextfile: public TObject bool _accept; void _read_page(long line); - bool _in_page(long l) + bool _in_page(long l) { return l >= _page_start && l < _page_end; } + void _save_changes(); + // void _parse_style(long j); style _trans_style(char c); diff --git a/include/urldefid.h b/include/urldefid.h index 1994c6bf9..5b6c4b1e2 100755 --- a/include/urldefid.h +++ b/include/urldefid.h @@ -42,6 +42,7 @@ #define BMP_EDIT 116 #define BMP_LINK 117 #define BMP_PRINT 118 +#define BMP_RECALC 119 #define BMP_FIRSTREC 121 #define BMP_PREVREC 122 #define BMP_STOPREC 123 @@ -61,7 +62,6 @@ #define BMP_NEWRECDN 155 #define BMP_QUITDN 164 #define BMP_SETPRINT 165 - #endif diff --git a/include/viswin.cpp b/include/viswin.cpp index 1f9614a4e..d3eebb18c 100755 --- a/include/viswin.cpp +++ b/include/viswin.cpp @@ -1939,7 +1939,7 @@ void TViswin::add_line (const char *l) void TViswin::close_print () { _isopen = FALSE; - kill_timer (_wtimer); + if (_showbuts) kill_timer (_wtimer); _need_update = TRUE; if (_toplevel) { @@ -2090,6 +2090,8 @@ TViswin::TViswin(const char *fname, _frozen (FALSE), _brwfld(brwfld), _link_button(-1), _down_dir(TRUE), _showbuts(FALSE), _case_sensitive(FALSE) { + main_app().begin_wait(); + if (title == NULL) title = (fname ? fname : "Anteprima di stampa"); @@ -2215,6 +2217,8 @@ TViswin::TViswin(const char *fname, _txt.set_hotspots(f, b); } _hotspots = &(_txt.hotspots()); + + main_app().end_wait(); } TViswin ::~TViswin ()