Aggiunto controllo BROWSEFILE alle mask (che e' una viswin) e handlers

del caso


git-svn-id: svn://10.65.10.50/trunk@708 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1994-12-01 14:49:44 +00:00
parent acea285fff
commit b04fedfea8
7 changed files with 416 additions and 213 deletions

View File

@ -5,22 +5,58 @@
#include <mask.h> #include <mask.h>
#endif #endif
class TViswin; class TViswin;
// viene chiamato sia al semplice passaggio del cursore sul testo
// (con doubleclick = FALSE) o alla pressione di tasti o balle per
// collegare (doubleclick = TRUE)
// se non ritorna NULL, il testo usato per linkare viene sostituito
// dal testo ritornato
typedef const char* (*MASK_LINKHANDLER)(TMask&, int, const char*, bool doubleclick);
class TBrowsefile_field : public TMask_field class TBrowsefile_field : public TMask_field
{ {
TViswin* _viswin; friend class TViswin;
TViswin* _viswin;
MASK_LINKHANDLER _lh;
TArray _links;
TArray _background;
bool _m_link;
protected: protected:
virtual word class_id() const; virtual word class_id() const;
virtual void parse_head(TScanner& scanner); virtual void parse_head(TScanner& scanner);
virtual bool parse_item(TScanner& scanner);
virtual void create(WINDOW parent); virtual void create(WINDOW parent);
public: public:
TViswin* vis_win() const { return _viswin; } TViswin* vis_win() const { return _viswin; }
void add_line(const char* l);
void set_text(const char* file);
// TBI posiziona su riga e colonna passate
void goto_pos(long r, long c);
void goto_top();
void goto_end();
void close();
// link processor
void set_link_handler(MASK_LINKHANDLER lh) { _lh = lh; }
MASK_LINKHANDLER get_link_handler() { return _lh; }
TArray& links() { return _links; }
void set_multiple_link(bool on) { _m_link = on; }
bool is_multiple_link() { return _m_link; }
int find_link(const char* descr);
int enable_link (const char* descr, char fg, char bg = 'w');
void disable_link(char fg, char bg = 'w');
void disable_links() { _links.destroy(); }
// print background
void set_background(const char* bg);
TArray* get_bg_desc() { return &_background; }
TBrowsefile_field(TMask* m); TBrowsefile_field(TMask* m);
virtual ~TBrowsefile_field(); virtual ~TBrowsefile_field();
}; };

View File

@ -100,7 +100,7 @@ void TPrinter::set_win_formlen ()
} }
#endif #endif
void TPrinter::_parse_background () void TPrinter::parse_background(const char* bg_desc, TArray& background)
{ {
char op; char op;
int x1, x2, y1, y2; int x1, x2, y1, y2;
@ -110,7 +110,7 @@ void TPrinter::_parse_background ()
char ch; char ch;
int cnt = 0; int cnt = 0;
while ((ch = _bg_desc[cnt++]) != '\0') while ((ch = bg_desc[cnt++]) != '\0')
{ {
op = ch; op = ch;
tt = ""; tt = "";
@ -131,10 +131,10 @@ void TPrinter::_parse_background ()
case 'r': // round box case 'r': // round box
cnt++; cnt++;
read_int (_bg_desc, x1, cnt); read_int (bg_desc, x1, cnt);
read_int (_bg_desc, y1, cnt); read_int (bg_desc, y1, cnt);
read_int (_bg_desc, x2, cnt); read_int (bg_desc, x2, cnt);
read_int (_bg_desc, y2, cnt); read_int (bg_desc, y2, cnt);
cnt++; cnt++;
tt << op; tt << op;
tt.add (x1 - 1); tt.add (x1 - 1);
@ -145,11 +145,11 @@ void TPrinter::_parse_background ()
case 't': // text case 't': // text
cnt++; cnt++;
read_int (_bg_desc, x1, cnt); read_int (bg_desc, x1, cnt);
read_int (_bg_desc, y1, cnt); read_int (bg_desc, y1, cnt);
cnt++; cnt++;
txt = ""; txt = "";
while ((ch = _bg_desc[cnt++]) != '}') while ((ch = bg_desc[cnt++]) != '}')
txt << ch; txt << ch;
tt << op; tt << op;
tt.add (x1 - 1); tt.add (x1 - 1);
@ -165,7 +165,7 @@ void TPrinter::_parse_background ()
case 'C': // set pen color case 'C': // set pen color
tt << op; tt << op;
bf[0] = _bg_desc[cnt++]; bf[0] = bg_desc[cnt++];
tt.add (bf); tt.add (bf);
break; break;
default: default:
@ -187,10 +187,10 @@ void TPrinter::_parse_background ()
for (int l = 0; l < _formlen; l++) for (int l = 0; l < _formlen; l++)
{ {
TString *rwd = (TString *) _background.objptr (l); TString *rwd = (TString *) background.objptr (l);
if (rwd == NULL) if (rwd == NULL)
{ {
_background.add (rwd = new TString, l); background.add (rwd = new TString, l);
if (curcol != 'n') if (curcol != 'n')
(*rwd) << 'C' << curcol; (*rwd) << 'C' << curcol;
if (curpat != 'n') if (curpat != 'n')
@ -283,10 +283,10 @@ void TPrinter::_parse_background ()
void TPrinter::setbackground(const char *b) void TPrinter::setbackground(const char *b)
{ {
_background.destroy (); _background.destroy();
_bg_desc = b; _bg_desc = b;
if (b != NULL) if (b != NULL)
_parse_background (); parse_background(_bg_desc, _background);
} }
bool printers_on_key(TMask_field & f, KEY key); bool printers_on_key(TMask_field & f, KEY key);

View File

@ -170,7 +170,6 @@ class TPrinter : public TObject
int _horz_offset; int _horz_offset;
int _dots_per_line; int _dots_per_line;
void _parse_background();
void _get_windows_printer_names(TToken_string& t); void _get_windows_printer_names(TToken_string& t);
bool _multiple_copies; bool _multiple_copies;
bool _export_header; bool _export_header;
@ -205,6 +204,11 @@ public:
void set_to_page (word to) { _topage = to; } void set_to_page (word to) { _topage = to; }
void set_hwff (bool hwff) { _hwformfeed = hwff; } void set_hwff (bool hwff) { _hwformfeed = hwff; }
// resa pubblica per farsi usare dagli altri
// la stampante e' un servizio, se non si fa usare
// che servizio e'?
void parse_background(const char* bgdesc, TArray& bg);
int descriptions() int descriptions()
{ return _printers.items(); } { return _printers.items(); }
const PrinterDef& get_description(word i) const const PrinterDef& get_description(word i) const

View File

@ -1,4 +1,4 @@
/* $Id: progind.h,v 1.3 1994-11-11 18:04:25 guy Exp $ */ /* $Id: progind.h,v 1.4 1994-12-01 14:49:33 villa Exp $ */
/* @N /* @N
progind.h progind.h
@ -53,10 +53,10 @@ protected:
public: public:
/* @FPUB */ /* @FPUB */
bool iscancelled() const { return _flags & IND_CANCELLED; } bool iscancelled() const { do_events(); return _flags & IND_CANCELLED; }
bool isfinished() const { return _flags & IND_FINISHED; } bool isfinished() const { do_events(); return _flags & IND_FINISHED; }
long status() const { return _status; } long status() const { do_events(); return _status; }
void cancel() { _flags |= IND_CANCELLED; check_stop(); } void cancel() { _flags |= IND_CANCELLED; do_events(); check_stop(); }
virtual bool can_be_closed() const; virtual bool can_be_closed() const;
/* @END */ /* @END */

View File

@ -353,7 +353,7 @@ bool TTextfile::append (const char *l)
void TTextfile::close () void TTextfile::close ()
{ {
CHECK (_isopen, "Attempt operation on closed file"); CHECK (_isopen,"Attempt operation on closed file");
fclose (_instr); fclose (_instr);
fclose (_index); fclose (_index);
_instr = _index = NULL; _instr = _index = NULL;
@ -443,6 +443,7 @@ _hotspots (4), _accept (TRUE)
_filename.temp (); _filename.temp ();
_istemp = TRUE; _istemp = TRUE;
} }
_isopen = TRUE;
_instr = fopen (_filename, "a+"); _instr = fopen (_filename, "a+");
_indname.temp (); _indname.temp ();
@ -453,20 +454,30 @@ _hotspots (4), _accept (TRUE)
yesnofatal_box ("Impossibile aprire files temporanei"); yesnofatal_box ("Impossibile aprire files temporanei");
freeze (); freeze ();
} }
if (file != NULL) if (!_istemp)
while (!feof (_instr)) while (!feof(_instr))
{ {
const long l = ftell (_instr); const long l = ftell (_instr);
fwrite (&l, sizeof (long), 1, _index); fwrite (&l, sizeof (long), 1, _index);
if (ferror (_index) || ferror (_instr)) if (ferror(_index) || ferror(_instr))
{ {
error_box ("Errore di scrittura file temporaneo: scrittura interrotta"); error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
freeze (); freeze ();
} }
fgets (mytmpstr, sizeof (mytmpstr), _instr); if (fgets (mytmpstr, sizeof (mytmpstr), _instr) == NULL)
break;
if (mytmpstr[strlen(mytmpstr)-1] == '\n')
mytmpstr[strlen(mytmpstr)-1] = '\0';
if ((_lines) < (_page_start + _page_size))
{
TString *ll = new TString (mytmpstr);
_page.add(ll);
_page_end++;
// TBI process links
}
_lines++; _lines++;
} }
_isopen = TRUE;
} }
TTextfile::~TTextfile () TTextfile::~TTextfile ()

View File

@ -9,6 +9,7 @@
#include <utility.h> #include <utility.h>
#include <viswin.h> #include <viswin.h>
#include <xvtility.h> #include <xvtility.h>
#include <colors.h>
#ifndef __PRINTER_H #ifndef __PRINTER_H
typedef void (*LINKHANDLER) (int, const char *); typedef void (*LINKHANDLER) (int, const char *);
@ -21,13 +22,11 @@ extern "C"
} }
#endif #endif
#define BUTTONROW_SIZE 3 #define BUTTONROW_SIZE (_toplevel ? 3 : 0)
#define W_X1 (origin().x+5) #define X_OFFSET (_rulers ? 6 : 1)
#define W_Y1 (origin().y+1) #define Y_OFFSET (_rulers ? 1 : 0)
#define W_X2 (origin().x+columns()) #define TEXTROWS (rows() - Y_OFFSET - BUTTONROW_SIZE)
#define W_Y2 (origin().y+rows()+1-BUTTONROW_SIZE) #define TEXTCOLUMNS (columns() - X_OFFSET)
#define TEXTROWS (rows() - 1 - BUTTONROW_SIZE)
#define TEXTCOLUMNS (columns() - 6)
#define DLG_QUIT_TITLE "Fine" #define DLG_QUIT_TITLE "Fine"
#define DLG_EDIT_TITLE "~Edit" #define DLG_EDIT_TITLE "~Edit"
@ -35,8 +34,8 @@ extern "C"
#define DLG_PRINT_TITLE "~Stampa" #define DLG_PRINT_TITLE "~Stampa"
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
#define BACKGROUND MASK_BACK_COLOR #define BACKGROUND (_toplevel ? MASK_BACK_COLOR : COLOR_GRAY)
#define FOREGROUND COLOR_BLACK #define FOREGROUND (_toplevel ? COLOR_BLACK : COLOR_WHITE)
#else #else
#define BACKGROUND COLOR_BLACK #define BACKGROUND COLOR_BLACK
#define FOREGROUND COLOR_WHITE #define FOREGROUND COLOR_WHITE
@ -64,39 +63,47 @@ void TViswin::exec_link()
{ {
if (_linkID != -1) if (_linkID != -1)
{ {
LINKHANDLER pl = main_app().printer().getlinkhandler(); if (!_toplevel)
if (pl)
pl(_linkID, _multiple ? (const char*)_multiple_link : (const char*)_linktxt);
// dai opzione per rifare la stampa se e' arrivato un messaggio
// dall'applicazione chiamata
// schiaffa indi il tutto in una funzione
TMailbox m;
if (m.next_s(MSG_LN) != NULL)
{ {
if (yesno_box("Si desidera riaggiornare la stampa?")) // link da browsefile_field
MASK_LINKHANDLER pl = _brwfld->_lh;
if (pl != NULL)
pl(_brwfld->mask(), _linkID,
_multiple ? (const char*)_multiple_link : (const char*)_linktxt, TRUE);
}
else
{
LINKHANDLER pl = main_app().printer().getlinkhandler();
if (pl)
pl(_linkID, _multiple ? (const char*)_multiple_link :
(const char*)_linktxt);
// dai opzione per rifare la stampa se e' arrivato un messaggio
// dall'applicazione chiamata
// schiaffa indi il tutto in una funzione
TMailbox m;
if (m.next_s(MSG_LN) != NULL)
{ {
((TPrint_application&)main_app()).repeat_print(); if (yesno_box("Si desidera riaggiornare la stampa?"))
{
((TPrint_application&)main_app()).repeat_print();
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
xvt_statbar_refresh (); xvt_statbar_refresh ();
#endif #endif
stop_run(K_ENTER); stop_run(K_ENTER);
} }
} }
} // _toplevel
set_focus(); set_focus();
check_link(); check_link();
_need_update = TRUE; _need_update = TRUE;
force_update(); force_update();
do_events(); do_events();
check_link (&_point); check_link (&_point);
} } // linkID != -1
else else beep();
beep();
} }
void TViswin::display_link (long y, long x1, long x2, const char *d) void TViswin::display_link (long y, long x1, long x2, const char *d)
{ {
if (!_link_displayed) if (!_link_displayed)
@ -104,8 +111,7 @@ void TViswin::display_link (long y, long x1, long x2, const char *d)
paint_link (y, x1, x2); paint_link (y, x1, x2);
_link_displayed = TRUE; _link_displayed = TRUE;
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
xvt_statbar_set (d); xvt_statbar_set(d);
xvt_statbar_refresh ();
#endif #endif
xvt_enable_control (_link_button, TRUE); xvt_enable_control (_link_button, TRUE);
} }
@ -129,7 +135,8 @@ void TViswin::erase_link (long y, long x1, long x2)
void TViswin::paint_link (long y, long x1, long x2) void TViswin::paint_link (long y, long x1, long x2)
{ {
if (adjust_box (x1, x2, y)) if (adjust_box (x1, x2, y))
invert_bar ((int) (x1 + 6l), (int) (y + 1l), (int) (x2 + 6l), (int) (y + 2l)); invert_bar ((int)(x1 + (long)X_OFFSET), (int)(y + (long)Y_OFFSET),
(int)(x2 + (long)X_OFFSET), (int)(y + (long)Y_OFFSET+1l));
} }
bool TViswin::adjust_box (long &x1, long &x2, long y) bool TViswin::adjust_box (long &x1, long &x2, long y)
@ -235,6 +242,16 @@ bool TViswin::check_link (TPoint * p)
y = py; y = py;
strcpy (descr, pdescr); strcpy (descr, pdescr);
display_link (y, x1, x2, descr); display_link (y, x1, x2, descr);
if (!_toplevel)
{
// chiama l'handler per maschere con FALSE come terzo parametro
MASK_LINKHANDLER pl = _brwfld->_lh;
if (pl != NULL)
pl(_brwfld->mask(), _linkID,
_multiple ? (const char*)_multiple_link : (const char*)_linktxt, FALSE);
}
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -242,7 +259,7 @@ bool TViswin::check_link (TPoint * p)
bool TViswin::in_text (const TPoint & p) const bool TViswin::in_text (const TPoint & p) const
{ {
if (p.x > 5 && p.x < columns () && p.y > 0 && p.y < (rows () - 3)) if (p.x > 5 && p.x < columns () && p.y > 0 && p.y < (rows () - BUTTONROW_SIZE))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -301,13 +318,15 @@ void TViswin::shift_screen (scroll dir)
{ {
case up: case up:
case down: case down:
set_rect (&r, 0, CHARY + 2, (int) (CHARX * (_textcolumns + 6)), (int) (CHARY * (_textrows + 1))); set_rect (&r, 0, (CHARY*Y_OFFSET) + 2, (int) (CHARX * (_textcolumns + X_OFFSET)),
(int)(CHARY * (_textrows + Y_OFFSET)));
win_scroll_rect (win (), &r, 0, dir == down ? CHARY : -CHARY); win_scroll_rect (win (), &r, 0, dir == down ? CHARY : -CHARY);
paint_row (dir == up ? origin ().y + _textrows - 1 : origin ().y); paint_row (dir == up ? origin ().y + _textrows - 1 : origin ().y);
break; break;
case left: case left:
case right: case right:
set_rect (&r, CHARX * 6, 0, (int) (CHARX * (_textcolumns + 6) + 2), (int) (CHARY * (_textrows + 1) - 2)); set_rect (&r, CHARX * X_OFFSET, 0, (int) (CHARX * (_textcolumns + X_OFFSET) + 2),
(int) (CHARY * (_textrows + 1) - 2));
win_scroll_rect (win (), &r, dir == right ? CHARX : -CHARX, 0); win_scroll_rect (win (), &r, dir == right ? CHARX : -CHARX, 0);
paint_column (dir == left ? origin ().x + _textcolumns - 1 : origin ().x, paint_column (dir == left ? origin ().x + _textcolumns - 1 : origin ().x,
dir == left); dir == left);
@ -340,7 +359,10 @@ WINDOW TViswin::add_button (short id, const char *caption)
} }
void TViswin::repos_buttons () void TViswin::repos_buttons ()
{ {
if (!_toplevel) return;
for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++) for (int buttons = 0; _button[buttons] != NULL_WIN; buttons++)
if (buttons == MAXBUT - 1) if (buttons == MAXBUT - 1)
{ {
@ -353,8 +375,8 @@ void TViswin::repos_buttons ()
autoscroll (FALSE); autoscroll (FALSE);
set_mode (M_COPY); set_mode (M_COPY);
set_brush (MASK_BACK_COLOR); set_brush (BACKGROUND);
bar (5, rows () - 3, columns () + 1, rows () + 1); bar (5, rows () - BUTTONROW_SIZE, columns () + 1, rows () + 1);
autoscroll (TRUE); autoscroll (TRUE);
RCT wr; RCT wr;
@ -403,7 +425,7 @@ void TViswin::paint_screen ()
PNT b, e; PNT b, e;
b.h = CHARX * 5; b.h = CHARX * 5;
b.v = (CHARY * (int) (j + 1l - origin ().y)) - 2; b.v = (CHARY * (int) (j + (long)Y_OFFSET - origin ().y)) - 2;
e.h = CHARX * columns (); e.h = CHARX * columns ();
e.v = b.v; e.v = b.v;
win_move_to (win (), b); win_move_to (win (), b);
@ -414,7 +436,8 @@ void TViswin::paint_screen ()
win_move_to (win (), b); win_move_to (win (), b);
win_draw_line (win (), e); win_draw_line (win (), e);
set_brush (COLOR_DKGRAY); set_brush (COLOR_DKGRAY);
bar (5, (int) (j + 1l - origin ().y), (int) columns (), (int) (rows () - 3l)); bar (5, (int)(j+(long)Y_OFFSET-origin().y),(int)columns(),
(int)(rows()-(long)BUTTONROW_SIZE));
autoscroll (TRUE); autoscroll (TRUE);
break; break;
#endif #endif
@ -427,7 +450,7 @@ void TViswin::paint_background (long j, int row)
if (!_isbackground) if (!_isbackground)
return; return;
int rw = (int) (j % (long) _formlen); int rw = (int) (j % (long) _formlen);
TString & rwd = (TString &) (*_bg)[rw]; TString & rwd = (TString &)(*_bg)[rw];
int cnt = 0; int cnt = 0;
char ch; char ch;
@ -444,7 +467,7 @@ void TViswin::paint_background (long j, int row)
{ {
case 'v': // verticale intera case 'v': // verticale intera
x1 = (unsigned char) rwd[cnt++] + 5; x1 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
b.h = e.h = x1 * CHARX + CHARX / 2; b.h = e.h = x1 * CHARX + CHARX / 2;
b.v = row * CHARY; b.v = row * CHARY;
e.v = (row + 1) * CHARY; e.v = (row + 1) * CHARY;
@ -453,7 +476,7 @@ void TViswin::paint_background (long j, int row)
break; break;
case 'o': // verticale pezzo sopra case 'o': // verticale pezzo sopra
x1 = (unsigned char) rwd[cnt++] + 5; x1 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
b.h = e.h = x1 * CHARX + CHARX / 2; b.h = e.h = x1 * CHARX + CHARX / 2;
b.v = row * CHARY; b.v = row * CHARY;
e.v = (row + 1) * CHARY - CHARY / 2; e.v = (row + 1) * CHARY - CHARY / 2;
@ -462,7 +485,7 @@ void TViswin::paint_background (long j, int row)
break; break;
case 'u': // verticale pezzo sotto case 'u': // verticale pezzo sotto
x1 = (unsigned char) rwd[cnt++] + 5; x1 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
b.h = e.h = x1 * CHARX + CHARX / 2; b.h = e.h = x1 * CHARX + CHARX / 2;
b.v = row * CHARY + CHARY / 2; b.v = row * CHARY + CHARY / 2;
e.v = (row + 1) * CHARY; e.v = (row + 1) * CHARY;
@ -471,8 +494,8 @@ void TViswin::paint_background (long j, int row)
break; break;
case 'h': // orizzontale intera case 'h': // orizzontale intera
x1 = (unsigned char) rwd[cnt++] + 5; x1 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
x2 = (unsigned char) rwd[cnt++] + 5; x2 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
b.v = e.v = row * CHARY + CHARY / 2; b.v = e.v = row * CHARY + CHARY / 2;
b.h = x1 * CHARX; b.h = x1 * CHARX;
e.h = (x2 + 1) * CHARX; e.h = (x2 + 1) * CHARX;
@ -481,8 +504,8 @@ void TViswin::paint_background (long j, int row)
break; break;
case 'r': // orizzontale scorciata agli estremi case 'r': // orizzontale scorciata agli estremi
x1 = (unsigned char) rwd[cnt++] + 5; x1 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
x2 = (unsigned char) rwd[cnt++] + 5; x2 = (unsigned char) rwd[cnt++] + (X_OFFSET -1);
b.v = e.v = row * CHARY + CHARY / 2; b.v = e.v = row * CHARY + CHARY / 2;
b.h = x1 * CHARX + CHARX / 2; b.h = x1 * CHARX + CHARX / 2;
e.h = x2 * CHARX + CHARX / 2; e.h = x2 * CHARX + CHARX / 2;
@ -524,28 +547,32 @@ void TViswin::paint_row (long j)
TPoint p1, p2; TPoint p1, p2;
if (need_paint_sel (FALSE)) if (need_paint_sel (FALSE))
adjust_selection (p1, p2); adjust_selection (p1, p2);
int row = (int) (j + 1l - y); int row = (int) (j + (long)Y_OFFSET - y);
static char fill[] = " " static char fill[] = " "
" "; " ";
autoscroll (FALSE); autoscroll(FALSE);
set_font (FF_FIXED, 0); set_font(FF_FIXED, 0);
set_mode (M_COPY); set_mode(M_COPY);
set_opaque_text (TRUE); set_opaque_text(TRUE);
set_color (FOREGROUND, BACKGROUND); if (_rulers)
printat (0, row, "%05ld", j + 1); {
set_color(FOREGROUND, BACKGROUND);
set_brush(BACKGROUND);
printat(0, row, "%05ld", j + 1);
}
if (_scrolling) if (_scrolling)
{ {
hide_pen (); hide_pen ();
set_brush (COLOR_WHITE); set_brush (COLOR_WHITE);
RCT r; RCT r;
r.top = row * CHARY; r.top = row * CHARY;
r.left = CHARX * 5, r.left = CHARX * (X_OFFSET -1),
r.bottom = r.top + CHARY + 2; r.bottom = r.top + CHARY + 2;
r.right = CHARX * 255; r.right = CHARX * 255;
win_draw_rect (win (), &r); win_draw_rect (win (), &r);
} }
const char *cp; const char *cp;
int pos = 0; int pos = 0;
_txt.read_line (j, origin ().x); _txt.read_line (j, origin ().x);
while (cp = _txt.piece ()) while (cp = _txt.piece ())
{ {
@ -559,17 +586,17 @@ void TViswin::paint_row (long j)
#else #else
set_color (COLOR_BLACK, COLOR_WHITE); set_color (COLOR_BLACK, COLOR_WHITE);
#endif #endif
printat (6 + pos, row, "%s", cp); printat (X_OFFSET + pos, row, "%s", cp);
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
if (st & underlined) if (st & underlined)
{ {
PNT b, e; PNT b, e;
set_pen (COLOR_BLACK); set_pen (COLOR_BLACK);
b.h = CHARX * (6 + pos); b.h = CHARX*(X_OFFSET + pos);
b.v = (row + 1) * CHARY; b.v = (row+Y_OFFSET) * CHARY;
e.h = CHARX * (6 + pos + strlen (cp)); e.h = CHARX*(X_OFFSET + pos + strlen (cp));
e.v = (row + 1) * CHARY; e.v = (row+Y_OFFSET)*CHARY;
win_move_to (win (), b); win_move_to (win (), b);
win_draw_line (win (), e); win_draw_line (win (), e);
} }
@ -579,21 +606,21 @@ void TViswin::paint_row (long j)
if (_scrolling && (pos < _textcolumns)) if (_scrolling && (pos < _textcolumns))
{ {
set_color (COLOR_BLACK, COLOR_WHITE); set_color (COLOR_BLACK, COLOR_WHITE);
printat (6 + pos, row, "%s", fill); printat (X_OFFSET + pos, row, "%s", fill);
} }
#if XVT_OS == XVT_OS_WIN // paint page limits #if XVT_OS == XVT_OS_WIN // paint page limits
if ((j % _formlen) == (_formlen - 1)) // last row if ((j % _formlen) == (_formlen - 1) && _toplevel) // last row
{ {
PNT b, e; PNT b, e;
b.h = CHARX * 5; b.h = CHARX * (X_OFFSET -1);
b.v = (row + 1) * CHARY - 1; b.v = (row + Y_OFFSET) * CHARY - 1;
e.h = CHARX * 132; e.h = CHARX * 132;
e.v = (row + 1) * CHARY - 1; e.v = (row + Y_OFFSET) * CHARY - 1;
set_pen (COLOR_LTGRAY, 2, PAT_SOLID, P_DASH); set_pen (COLOR_LTGRAY, 2, PAT_SOLID, P_DASH);
win_move_to (win (), b); win_move_to (win(), b);
win_draw_line (win (), e); win_draw_line (win(), e);
} }
#endif #endif
paint_background (j, row); paint_background (j, row);
@ -621,8 +648,8 @@ void TViswin::paint_column (long j, bool end)
long fg = trans_color (_txt.get_foreground ((int) j)); long fg = trans_color (_txt.get_foreground ((int) j));
set_color (fg, bg); set_color (fg, bg);
#endif #endif
int col = end ? (int) (_textcolumns + 5) : 6; int col = end ? (int) (_textcolumns + X_OFFSET -1) : X_OFFSET;
printat (col, (int) l + 1, "%c", printat (col, (int) l + Y_OFFSET, "%c",
(unsigned int) j < strlen (c) ? c[(int) j] : ' '); (unsigned int) j < strlen (c) ? c[(int) j] : ' ');
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
if ((st & underlined) && strlen (c) > (word) j) if ((st & underlined) && strlen (c) > (word) j)
@ -648,8 +675,8 @@ void TViswin::draw_crossbars ()
{ {
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
if (_cross.v > CHARY && _cross.v < (rows () - 3) * CHARY && if (_cross.v > CHARY && _cross.v < (rows () - BUTTONROW_SIZE) * CHARY &&
_cross.h > CHARX * 5 && _cross.h < columns () * CHARX) _cross.h > CHARX * (X_OFFSET - 1) && _cross.h < columns () * CHARX)
{ {
set_pen (COLOR_BLACK); set_pen (COLOR_BLACK);
set_mode (M_XOR); set_mode (M_XOR);
@ -658,12 +685,12 @@ void TViswin::draw_crossbars ()
autoscroll (FALSE); autoscroll (FALSE);
b1.h = _cross.h; b1.h = _cross.h;
b1.v = CHARY; b1.v = CHARY * Y_OFFSET;
e1.h = _cross.h; e1.h = _cross.h;
e1.v = ((rows () - 3) * CHARY); e1.v = ((rows() - BUTTONROW_SIZE + (_rulers ? 0 : 1)) * CHARY);
b2.h = CHARX * 5; b2.h = CHARX * (X_OFFSET -1);
b2.v = _cross.v; b2.v = _cross.v;
e2.h = CHARX * columns (); e2.h = CHARX * columns();
e2.v = _cross.v; e2.v = _cross.v;
win_move_to (win (), b1); win_move_to (win (), b1);
win_draw_line (win (), e1); win_draw_line (win (), e1);
@ -710,19 +737,25 @@ void TViswin::paint_point (bool erase)
if (_isbar) if (_isbar)
{ {
invert_bar (6, (int) (_point.y - origin ().y + 1l), invert_bar (X_OFFSET, (int)(_point.y - origin().y + (long)Y_OFFSET),
(int) columns (), (int) (_point.y - origin ().y + 2l)); (int)columns(), (int) (_point.y - origin().y + (long)Y_OFFSET + 1l));
invert_bar ((int) (_point.x - origin ().x + 6l), 1, invert_bar ((int)(_point.x - origin().x + (long)X_OFFSET), Y_OFFSET,
(int) (_point.x - origin ().x + 7l), (int) (rows () - 3l)); (int)(_point.x - origin().x + (long)X_OFFSET + 1l),
(int)(rows() - (long)BUTTONROW_SIZE));
} }
else else
{ {
invert_bar ((int) (_point.x - origin ().x + 6l), (int) (_point.y - origin ().y + 1l), invert_bar ((int) (_point.x - origin ().x + (long)X_OFFSET),
(int) (_point.x - origin ().x + 7l), (int) (_point.y - origin ().y + 2l)); (int) (_point.y - origin ().y + (long)Y_OFFSET),
invert_bar (0, (int) (_point.y - origin ().y + 1l), 5, (int) (_point.x - origin ().x + (long)X_OFFSET + 1l),
(int) (_point.y - origin ().y + 2l)); (int) (_point.y - origin ().y + (long)Y_OFFSET + 1l));
invert_bar ((int) (_point.x - origin ().x + 6l), 0, if (_rulers)
(int) (_point.x - origin ().x + 7l), 1); {
invert_bar (0, (int) (_point.y - origin ().y + (long)Y_OFFSET), (X_OFFSET -1),
(int) (_point.y - origin ().y + (long)Y_OFFSET + 1l));
invert_bar ((int) (_point.x - origin ().x + (long)X_OFFSET), 0,
(int) (_point.x - origin ().x + (long)X_OFFSET + 1l), 1);
}
} }
autoscroll (TRUE); autoscroll (TRUE);
wasbar = _isbar; wasbar = _isbar;
@ -730,7 +763,9 @@ void TViswin::paint_point (bool erase)
// draw screen header // draw screen header
void TViswin::paint_header () void TViswin::paint_header ()
{ {
if (!_rulers)
return;
set_mode (M_COPY); set_mode (M_COPY);
set_opaque_text (TRUE); set_opaque_text (TRUE);
set_color (FOREGROUND, BACKGROUND); set_color (FOREGROUND, BACKGROUND);
@ -744,7 +779,7 @@ void TViswin::paint_header ()
} }
autoscroll (FALSE); autoscroll (FALSE);
set_color (COLOR_WHITE, BACKGROUND); set_color (COLOR_WHITE, BACKGROUND);
printat (0, 0, "P.%3ld ", ((origin ().y) / _formlen) + 1l); printat (0, 0, "P.%3ld ", ((origin().y) / _formlen) + 1l);
autoscroll (TRUE); autoscroll (TRUE);
} }
@ -757,12 +792,12 @@ void TViswin::paint_selection ()
for (long l = p1.y; l <= p2.y; l++) for (long l = p1.y; l <= p2.y; l++)
{ {
int top, left, right; int top, left, right;
top = (int) (l - origin ().y + 1); top = (int) (l - origin().y + 1);
if (top > 0 && top <= _textrows) if (top > 0 && top <= _textrows)
{ {
left = p1.y == l ? (int) (p1.x - origin ().x + 6l) : 6; left = p1.y == l ? (int)(p1.x-origin().x + (long)X_OFFSET) : X_OFFSET;
right = p2.y == l ? (int) (p2.x - origin ().x + 6l) : right = p2.y == l ? (int)(p2.x-origin().x + (long)X_OFFSET) :
(int) (_textcolumns + 6l); (int)(_textcolumns + (long)X_OFFSET);
autoscroll (FALSE); autoscroll (FALSE);
invert_bar (left, top, right, top + 1); invert_bar (left, top, right, top + 1);
autoscroll (TRUE); autoscroll (TRUE);
@ -771,7 +806,7 @@ void TViswin::paint_selection ()
} }
void TViswin::paint_waitbar (bool xor) void TViswin::paint_waitbar (bool xor)
{ {
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
static int pic; static int pic;
#endif #endif
@ -779,20 +814,20 @@ void TViswin::paint_waitbar (bool xor)
if (xor) if (xor)
{ {
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
cpb_win_picture_draw_at (win (), _picture[pic], 4, 4 + (int) (rows () - 3l) * CHARY); cpb_win_picture_draw_at(win(),_picture[pic],4,4+(int)(rows()-(long)BUTTONROW_SIZE)*CHARY);
if (pic == 3) if (pic == 3)
pic = 0; pic = 0;
else else
pic++; pic++;
#else #else
invert_bar (3, rows () - 2, 4, rows () - 1); invert_bar (3, rows() - 2, 4, rows() - 1);
#endif #endif
} }
else else
{ {
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
cpb_win_picture_draw_at (win (), _picture[pic], 4, cpb_win_picture_draw_at (win (), _picture[pic], 4,
4 + (int) (rows () - 3l) * CHARY); 4 + (int) (rows () - (long)BUTTONROW_SIZE) * CHARY);
if (pic == 3) if (pic == 3)
pic = 0; pic = 0;
else else
@ -812,26 +847,38 @@ void TViswin::update ()
erase_point (); erase_point ();
autoscroll (FALSE); autoscroll (FALSE);
set_mode (M_COPY); set_mode (M_COPY);
set_brush (MASK_BACK_COLOR); if (_toplevel)
bar (5, rows () - 3, columns () + 1, rows () + 1); {
set_brush (BACKGROUND);
bar ((X_OFFSET-1), rows()-BUTTONROW_SIZE, columns()+1, rows() + 1);
}
if (_need_update) if (_need_update)
{ {
if (_isselection) if (_isselection)
erase_selection (); erase_selection ();
clear (COLOR_WHITE); clear (COLOR_WHITE);
set_mode (M_COPY); set_mode (M_COPY);
set_brush (MASK_BACK_COLOR); set_brush (BACKGROUND);
autoscroll (FALSE); autoscroll (FALSE);
bar (0, 0, columns () + 1, 1); if (_rulers)
bar (0, 0, 5, rows () + 1); {
bar (5, rows () - 3, columns () + 1, rows () + 1); bar (0, 0, columns() + 1, 1);
if (_isopen) bar (0, 0, 5, rows() + 1);
// RCT r1, r2;
// r1.top = 0; r1.left = 0; r1.bottom = CHARY; r1.right = (columns() + 1)*CHARX;
// r2.top = 0; r2.left = 0; r2.bottom = (rows()+1)*CHARY; r2.right = 5*CHARX;
// xvt_draw_rect(win(), r1, COLOR_WHITE, COLOR_GRAY, 2);
// xvt_draw_rect(win(), r2, COLOR_WHITE, COLOR_GRAY, 2);
}
if (_toplevel)
bar ((X_OFFSET -1), rows()-BUTTONROW_SIZE, columns() + 1, rows() + 1);
if (_toplevel && _isopen)
paint_waitbar (FALSE); paint_waitbar (FALSE);
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
else if (parent() == TASK_WIN) else if (_toplevel)
cpb_win_picture_draw_at (win(), _modpic, 4, cpb_win_picture_draw_at (win(), _modpic, 4,
4 + (int) (rows () - 3l) * CHARY); 4 + (int) (rows () - (long)BUTTONROW_SIZE) * CHARY);
#endif #endif
autoscroll (TRUE); autoscroll (TRUE);
paint_header (); paint_header ();
@ -932,7 +979,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
} }
else if (ep->v.timer.id == _wtimer) else if (ep->v.timer.id == _wtimer)
{ {
paint_waitbar (); if (_toplevel) paint_waitbar ();
kill_timer (_wtimer); kill_timer (_wtimer);
if (_isopen) if (_isopen)
_wtimer = set_timer (win, 150l); _wtimer = set_timer (win, 150l);
@ -960,8 +1007,8 @@ void TViswin::handler (WINDOW win, EVENT * ep)
erase_point (); erase_point ();
_sel_start = ep->v.mouse.where; _sel_start = ep->v.mouse.where;
_sel_start.x += (origin ().x - 6); _sel_start.x += (origin ().x - X_OFFSET);
_sel_start.y += (origin ().y - 1); _sel_start.y += (origin ().y - Y_OFFSET);
_sel_end = _sel_start; _sel_end = _sel_start;
_selecting = TRUE; _selecting = TRUE;
} }
@ -982,8 +1029,8 @@ void TViswin::handler (WINDOW win, EVENT * ep)
{ {
p = ep->v.mouse.where; p = ep->v.mouse.where;
if (_isopen && (p.x >= 4 && p.x) <= 6 && if (_isopen && (p.x >= 4 && p.x) <= X_OFFSET &&
(p.y >= (int) rows () - 3 && p.y <= (int) rows () - 1)) (p.y >= (int)rows () - BUTTONROW_SIZE && p.y <= (int)rows() - Y_OFFSET))
{ {
abort_print (); abort_print ();
ignore = TRUE; ignore = TRUE;
@ -995,8 +1042,8 @@ void TViswin::handler (WINDOW win, EVENT * ep)
break; break;
} }
// confirm selection & store // confirm selection & store
p.x += (origin ().x - 6); p.x += (origin ().x - X_OFFSET);
p.y += (origin ().y - 1); p.y += (origin ().y - Y_OFFSET);
if (_sel_start == p) if (_sel_start == p)
{ {
@ -1099,7 +1146,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
if (_iscross) if (_iscross)
display_crossbar (); display_crossbar ();
} }
else if (p.x <= 5l) else if (p.x <= (long)(X_OFFSET - 1))
{ {
if (_isselection) if (_isselection)
erase_selection (); erase_selection ();
@ -1111,7 +1158,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
if (_iscross) if (_iscross)
display_crossbar (); display_crossbar ();
} }
else if (p.x >= _textcolumns + 6) else if (p.x >= _textcolumns + X_OFFSET)
{ {
if (_isselection) if (_isselection)
erase_selection (); erase_selection ();
@ -1127,8 +1174,8 @@ void TViswin::handler (WINDOW win, EVENT * ep)
{ {
if (in_text (p)) if (in_text (p))
{ {
p.x += (origin ().x - 6); p.x += (origin ().x - X_OFFSET);
p.y += (origin ().y - 1); p.y += (origin ().y - Y_OFFSET);
_point = p; _point = p;
if (_point.y >= _txt.lines ()) if (_point.y >= _txt.lines ())
_point.y = _txt.lines () - 1l; _point.y = _txt.lines () - 1l;
@ -1186,7 +1233,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
{ {
kdiff = (int) (_point.y - origin ().y); kdiff = (int) (_point.y - origin ().y);
new_origin = origin ().y > _textrows ? new_origin = origin ().y > _textrows ?
origin ().y - _textrows + 1l : 0; origin().y - _textrows + 1l : 0;
_point.y = new_origin + kdiff; _point.y = new_origin + kdiff;
check_link (); check_link ();
update_thumb (origin ().x, new_origin); update_thumb (origin ().x, new_origin);
@ -1208,10 +1255,10 @@ void TViswin::handler (WINDOW win, EVENT * ep)
{ {
kdiff = (int) (_point.x - origin ().x); kdiff = (int) (_point.x - origin ().x);
new_origin = origin ().x > _textcolumns ? new_origin = origin ().x > _textcolumns ?
origin ().x - _textcolumns + 1 : 0; origin().x - _textcolumns + 1 : 0;
_point.x = new_origin + kdiff; _point.x = new_origin + kdiff;
check_link (); check_link ();
update_thumb(new_origin, _point.y); update_thumb(new_origin, origin().y);
_need_update = TRUE; _need_update = TRUE;
update (); // AAAARGH! update (); // AAAARGH!
@ -1235,7 +1282,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
if (need_paint_sel ()) if (need_paint_sel ())
erase_selection (); erase_selection ();
check_link (); check_link ();
update_thumb (origin ().x, origin ().y - 1l); update_thumb (origin().x, origin().y - 1l);
_need_scroll = down; _need_scroll = down;
} }
else else
@ -1252,7 +1299,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
if (need_paint_sel (FALSE)) if (need_paint_sel (FALSE))
erase_selection (); erase_selection ();
check_link (); check_link ();
update_thumb (origin ().x - 1l, origin ().y); update_thumb (origin().x - 1l, origin().y);
_point.x--; _point.x--;
_need_scroll = right; _need_scroll = right;
} }
@ -1266,7 +1313,7 @@ void TViswin::handler (WINDOW win, EVENT * ep)
case SC_PAGE_DOWN: case SC_PAGE_DOWN:
if (ep->type == E_VSCROLL) if (ep->type == E_VSCROLL)
{ {
if ((origin ().y + _textrows) < _txt.lines ()) if ((origin().y + _textrows) < _txt.lines())
{ {
kdiff = (int) (_point.y - origin ().y); kdiff = (int) (_point.y - origin ().y);
new_origin = (_txt.lines () - origin ().y) > new_origin = (_txt.lines () - origin ().y) >
@ -1289,14 +1336,14 @@ void TViswin::handler (WINDOW win, EVENT * ep)
} }
else else
{ {
if ((origin ().x + _textcolumns) < 256) if ((origin().x + _textcolumns) < 256)
{ {
kdiff = (int) (_point.x - origin ().x); kdiff = (int) (_point.x - origin ().x);
new_origin = (256 - origin ().x) > _textcolumns ? new_origin = (256 - origin ().x) > _textcolumns ?
origin ().x + _textcolumns - 1 : 256 - _textcolumns; origin ().x + _textcolumns - 1 : 256 - _textcolumns;
_point.x = new_origin + kdiff; _point.x = new_origin + kdiff;
check_link (); check_link ();
update_thumb (new_origin, origin ().y); update_thumb (new_origin, origin().y);
_need_update = TRUE; _need_update = TRUE;
update (); // AAAARGH! update (); // AAAARGH!
@ -1469,7 +1516,9 @@ bool TViswin::on_key (KEY key)
{ {
erase_selection (); erase_selection ();
_isselection = FALSE; _isselection = FALSE;
} }
if (_toplevel)
exec_link();
break; break;
case K_TAB: case K_TAB:
if (_curbut == (_buttons - 1)) if (_curbut == (_buttons - 1))
@ -1645,7 +1694,7 @@ bool TViswin::on_key (KEY key)
case K_DOWN: case K_DOWN:
case K_SHIFT_DOWN: case K_SHIFT_DOWN:
_need_update = FALSE; _need_update = FALSE;
if (_point.y < (_txt.lines () - 1)) if (_point.y < (_txt.lines() - 1))
{ {
if (key == K_SHIFT_DOWN) if (key == K_SHIFT_DOWN)
{ {
@ -1657,12 +1706,12 @@ bool TViswin::on_key (KEY key)
_selecting = TRUE; _selecting = TRUE;
} }
} }
if (_point.y == origin ().y + _textrows - 1) if (_point.y == origin().y + _textrows - 1)
{ {
if (need_paint_sel ()) if (need_paint_sel())
erase_selection (); erase_selection();
// check_link(); // check_link();
update_thumb (origin ().x, (++_point.y) - _textrows + 1); update_thumb (origin().x, (++_point.y) - _textrows + 1);
_need_scroll = up; _need_scroll = up;
} }
else else
@ -1791,7 +1840,7 @@ void TViswin::add_line (const char *l)
_txt.append (l); _txt.append (l);
EVENT ev; EVENT ev;
ev.type = E_USER; ev.type = E_USER;
ev.v.user.id = (_txt.lines () - origin ().y) <= _textrows ? ev.v.user.id = (_txt.lines() - origin().y) <= _textrows ?
E_ADDLINE_ONSCREEN : E_ADDLINE; E_ADDLINE_ONSCREEN : E_ADDLINE;
dispatch_event (win (), &ev); dispatch_event (win (), &ev);
do_events (); do_events ();
@ -1810,20 +1859,23 @@ TViswin ::TViswin (const char *fname,
const char *title, const char *title,
bool editbutton, bool editbutton,
bool printbutton, bool printbutton,
bool linkbutton, bool linkbutton,
int height, int x, int y,
WINDOW parent): int height, int width,
bool rulers,
WINDOW parent,
TBrowsefile_field* brwfld):
_filename (fname), _txt (fname, BUFFERSIZE), _islink (linkbutton), _isedit (editbutton), _filename (fname), _txt (fname, BUFFERSIZE), _islink (linkbutton), _isedit (editbutton),
_isprint (printbutton), _isbar (FALSE), _istimer (FALSE), _iscross (FALSE), _isprint (printbutton), _isbar (FALSE), _istimer (FALSE), _iscross (FALSE),
_isselection (FALSE), _sel_displayed (FALSE), _cross_displayed (FALSE), _isselection (FALSE), _sel_displayed (FALSE), _cross_displayed (FALSE),
_link_displayed (FALSE), _point_displayed (FALSE), _selecting (FALSE), _link_displayed (FALSE), _point_displayed (FALSE), _selecting (FALSE),
_scrolling (FALSE), _selflag (FALSE), _need_update (TRUE), _need_scroll (none), _scrolling (FALSE), _selflag (FALSE), _need_update (TRUE), _need_scroll (none),
_multiple (FALSE), _multiple (FALSE), _rulers(rulers),
_frozen (FALSE) _frozen (FALSE), _brwfld(brwfld)
{ {
if (title == NULL) if (title == NULL)
title = (fname ? fname : "Anteprima di stampa"); title = (fname ? fname : "Anteprima di stampa");
_isopen = fname == NULL || *fname <= ' '; _isopen = fname == NULL || *fname <= ' ';
if (_isopen) if (_isopen)
_filename = _txt.name (); _filename = _txt.name ();
@ -1834,18 +1886,20 @@ TViswin ::TViswin (const char *fname,
if (parent == NULL_WIN) if (parent == NULL_WIN)
parent = TASK_WIN; parent = TASK_WIN;
bool toplevel = parent == TASK_WIN; _toplevel = parent == TASK_WIN;
const int larg = 76; const int larg = 76;
const int alt = 20; const int alt = 20;
RCT r;
get_client_rect (parent, &r);
int maxlarg = r.right / CHARX - 6; // Calculates max window width
int maxalt = height == 0 ? (r.bottom / CHARY - 6) : height; RCT r;
if (larg > maxlarg)
get_client_rect (parent, &r);
int maxlarg = width == 0 ? (r.right / CHARX - 6) : width;
int maxalt = height == 0 ? (r.bottom / CHARY - 6) : height;
if (_toplevel && larg > maxlarg)
maxlarg = larg; maxlarg = larg;
if (alt > maxalt) if (_toplevel && alt > maxalt)
maxalt = alt; maxalt = alt;
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
@ -1855,20 +1909,22 @@ TViswin ::TViswin (const char *fname,
#endif #endif
long flags = WSF_HSCROLL | WSF_VSCROLL; long flags = WSF_HSCROLL | WSF_VSCROLL;
if (toplevel) if (_toplevel)
{ {
flags |= (WSF_CLOSE | WSF_SIZE); flags |= (WSF_CLOSE | WSF_SIZE);
} }
WIN_TYPE rt = toplevel ? W_DOC : W_PLAIN; WIN_TYPE rt = _toplevel ? W_DOC : W_PLAIN;
create (x, y, maxlarg, maxalt, title, flags, rt, parent);
create (-1, parent == TASK_WIN ? -1 : 0, maxlarg, maxalt, title, flags, rt, parent);
set_opaque_text (TRUE); set_opaque_text (TRUE);
set_font (FF_FIXED); set_font (FF_FIXED);
if (toplevel) if (_txt.lines() > 0l)
set_scroll_max (MAXLEN - 1, _txt.lines () <= _textrows ?
_txt.lines () : _txt.lines () - _textrows);
if (_toplevel)
{ {
add_button (DLG_QUIT, DLG_QUIT_TITLE); add_button (DLG_QUIT, DLG_QUIT_TITLE);
_buttons = 1; _buttons = 1;
@ -1908,11 +1964,12 @@ TViswin ::TViswin (const char *fname,
_textcolumns = TEXTCOLUMNS; _textcolumns = TEXTCOLUMNS;
autoscroll (TRUE); autoscroll (TRUE);
_links = &(main_app().printer ().links ()); _links = _toplevel ? &(main_app().printer().links()) : &(_brwfld->_links);
_multiple = main_app().printer ().ismultiplelink (); _multiple = _toplevel ? (main_app().printer ().ismultiplelink()) :
_bg = main_app().printer ().getbgdesc (); (_brwfld->is_multiple_link());
_bg = _toplevel ? main_app().printer().getbgdesc() : _brwfld->get_bg_desc();
_isbackground = _bg->items () > 0; _isbackground = _bg->items () > 0;
_formlen = main_app().printer ().formlen (); _formlen = _toplevel ? main_app().printer().formlen() : maxalt;
for (i = 0; i < _links->items (); i++) for (i = 0; i < _links->items (); i++)
{ {
@ -1920,7 +1977,7 @@ TViswin ::TViswin (const char *fname,
char f = *(t.get (1)); char f = *(t.get (1));
char b = *(t.get (2)); char b = *(t.get (2));
t.restart (); t.restart ();
_txt.set_hotspots (f, b); _txt.set_hotspots(f, b);
} }
_hotspots = &(_txt.hotspots ()); _hotspots = &(_txt.hotspots ());
} }
@ -1939,7 +1996,7 @@ TViswin ::~TViswin ()
// Certified 100% // Certified 100%
TBrowsefile_field::TBrowsefile_field(TMask* m) TBrowsefile_field::TBrowsefile_field(TMask* m)
: TMask_field(m), _viswin(NULL) : TMask_field(m), _viswin(NULL), _m_link(FALSE), _background(36), _lh(NULL)
{} {}
// Certified 100% // Certified 100%
@ -1957,28 +2014,109 @@ TBrowsefile_field::~TBrowsefile_field()
void TBrowsefile_field::parse_head(TScanner& scanner) void TBrowsefile_field::parse_head(TScanner& scanner)
{ {
_width = scanner.integer();
_size = scanner.integer(); _size = scanner.integer();
} }
// Certified 100%
bool TBrowsefile_field::parse_item(TScanner& scanner)
{
if (scanner.key() == "FI")
{
_prompt = scanner.string();
return TRUE;
}
return TMask_field::parse_item(scanner);
}
// Certified 100% // Certified 100%
void TBrowsefile_field::create(WINDOW parent) void TBrowsefile_field::create(WINDOW parent)
{ {
const TMask& m = mask(); const TMask& m = mask();
_viswin = new TViswin(_prompt, _prompt, FALSE, FALSE, FALSE, _size, parent); _viswin = new TViswin(_prompt, _prompt, FALSE, FALSE, FALSE, _x, _y,
_size, _width, _flags.rightjust ? TRUE : FALSE, parent, this);
_win = _viswin->win(); _win = _viswin->win();
enable_window(_win, enabled()); enable_window(_win, enabled());
show_window(_win, showed()); show_window(_win, showed());
} }
void TBrowsefile_field::set_text(const char* file)
{
FILE* instr = fopen(file,"r");
if (instr == NULL)
error_box("File non trovato: %s", file);
while (!feof(instr))
{
if (fgets(__tmp_string, sizeof (__tmp_string), instr) == NULL)
break;
if (__tmp_string[strlen(__tmp_string)-1] == '\n')
__tmp_string[strlen(__tmp_string)-1] = '\0';
add_line(__tmp_string);
}
fclose(instr);
}
int TBrowsefile_field::find_link(const char* descr)
{
for (int i = 0; i < _links.items(); i++)
{
TToken_string& tt = (TToken_string&)_links[i];
const TFixed_string d(tt.get(0));
if (d == descr)
return i;
}
return -1;
}
int TBrowsefile_field::enable_link(const char *descr, char fg, char bg)
{
int lnk = find_link(descr);
if (lnk < 0)
{
TToken_string *tt = new TToken_string(30);
char b[2] = { '\0', '\0' };
tt->add(descr);
b[0] = fg;
tt->add(b);
b[0] = bg;
tt->add(b);
lnk = _links.add(tt);
}
return lnk;
}
void TBrowsefile_field::disable_link(char fg, char bg)
{
for (int i = 0; i < _links.items (); i++)
{
TToken_string & t = (TToken_string&)_links[i];
const char f = *(t.get(1));
const char b = *(t.get());
if (f == fg && b == bg)
{
_links.remove(i, TRUE);
break;
}
}
}
void TBrowsefile_field::set_background(const char* bg)
{
main_app().printer().parse_background(bg,_background);
}
void TBrowsefile_field::add_line(const char* l)
{
_viswin->add_line(l);
}
void TBrowsefile_field::close()
{
_viswin->close_print();
}
void TBrowsefile_field::goto_pos(long r, long c)
{
}
void TBrowsefile_field::goto_top()
{
dispatch_e_char(_viswin->win(), K_END);
}
void TBrowsefile_field::goto_end()
{
dispatch_e_char(_viswin->win(), K_HOME);
}

View File

@ -18,8 +18,12 @@
#include <text.h> #include <text.h>
#endif #endif
class TBrowsefile_field;
class TViswin : public TScroll_window class TViswin : public TScroll_window
{ {
friend class TBrowsefile_field;
enum { MAXBUT = 4, MAXLEN = 256, BUFFERSIZE = 256, MAXPIC=4}; enum { MAXBUT = 4, MAXLEN = 256, BUFFERSIZE = 256, MAXPIC=4};
enum scroll { none, up, down, left, right }; enum scroll { none, up, down, left, right };
@ -77,6 +81,11 @@ class TViswin : public TScroll_window
TArray* _bg; TArray* _bg;
bool _isbackground; bool _isbackground;
bool _frozen; bool _frozen;
bool _toplevel;
bool _rulers;
// viene istanziato soltanto se e' usata come controllo BROWSEFILE
TBrowsefile_field* _brwfld;
protected: protected:
@ -132,13 +141,18 @@ public:
void add_line(const char* l); void add_line(const char* l);
TViswin (const char* fname = NULL, TViswin (const char* fname = NULL,
const char* title = NULL, const char* title = NULL,
bool editbutton = TRUE, bool editbutton = TRUE,
bool printbutton = TRUE, bool printbutton = TRUE,
bool linkbutton = TRUE, bool linkbutton = TRUE,
int height = 0, int x = -1,
WINDOW parent = NULL_WIN); int y = -1,
int height = 0,
int width = 0,
bool rulers = TRUE,
WINDOW parent = NULL_WIN,
TBrowsefile_field* = NULL);
virtual ~TViswin (); virtual ~TViswin ();
}; };