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
This commit is contained in:
villa 1995-01-09 12:15:24 +00:00
parent 42279d33b5
commit f24bcf1bab
7 changed files with 92 additions and 9 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,7 @@
#include <text.h>
#include <fstream.h>
#include <ctype.h>
#include <applicat.h>
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;

View File

@ -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);

View File

@ -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

View File

@ -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 ()