Corretta gestione dei vari modi di uscita da un'applicazione:

Bottone Fine, Menu Fine, Menu Chiudi o ALT-F4


git-svn-id: svn://10.65.10.50/trunk@229 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-09-13 16:43:52 +00:00
parent 5c70586f90
commit 8097b5d8eb
15 changed files with 751 additions and 683 deletions

View File

@ -170,7 +170,7 @@ void TApplication::about() const
{ {
#include <prassi.ver> #include <prassi.ver>
const TFilename n(__argv[0]); const TFilename n(__argv[0]);
message_box("PRASSI Versione Beta %g\nProgramma %s\nLibreria del %s", message_box("PRASSI Versione Beta 1.%g\nProgramma %s\nLibreria del %s",
VERSION, (const char*)n.name(), __DATE__); VERSION, (const char*)n.name(), __DATE__);
} }
@ -196,7 +196,8 @@ long TApplication::handler(WINDOW, EVENT* ep)
switch(mt) switch(mt)
{ {
case M_FILE_QUIT: case M_FILE_QUIT:
stop_run(); if (can_close())
stop_run();
break; break;
case M_FILE_PG_SETUP: case M_FILE_PG_SETUP:
printer().set(); printer().set();
@ -232,10 +233,9 @@ long TApplication::handler(WINDOW, EVENT* ep)
{ {
if (can_close()) if (can_close())
quit_OK(); quit_OK();
else
error_box("Chiudere la finestra attiva prima di terminare il programma");
} }
else stop_run(); else
stop_run();
break; break;
default: default:
break; break;
@ -335,16 +335,11 @@ const char* TApplication::get_module_name() const
return module; return module;
} }
void TApplication::set_title(const char* t)
{ cfg.appl_name = (char*)t; }
const char* TApplication::title() const
{ return cfg.appl_name; }
void TApplication::run(int argc, char* argv[], const char* title) void TApplication::run(int argc, char* argv[], const char* title)
{ {
TFilename base(argv[0]); TFilename base(argv[0]);
base.ext(""); base.lower(); base.ext(""); base.lower();
_title = title;
__argc = argc; __argc = argc;
__argv = (const char**)argv; __argv = (const char**)argv;
@ -364,8 +359,8 @@ void TApplication::run(int argc, char* argv[], const char* title)
TString80 caption; TString80 caption;
caption << "PRASSI S.P.A. - " << get_module_name(); caption << "PRASSI S.P.A. - " << get_module_name();
cfg.base_appl_name = (char*) base.name(); cfg.base_appl_name = (char*)base.name();
cfg.appl_name = (char*) title; cfg.appl_name = (char*)(const char*)_title;
cfg.taskwin_title = (char*)(const char*)caption; cfg.taskwin_title = (char*)(const char*)caption;
cfg.menu_bar_ID = TASK_MENUBAR+addbar; cfg.menu_bar_ID = TASK_MENUBAR+addbar;
cfg.about_box_ID = 0; cfg.about_box_ID = 0;

View File

@ -28,7 +28,7 @@ class TApplication
int __argc; int __argc;
const char** __argv; const char** __argv;
TString _name; TString80 _name, _title;
TPrinter* _printer; TPrinter* _printer;
protected: protected:
@ -67,8 +67,8 @@ public:
const char* argv(int i) const { return __argv[i]; } const char* argv(int i) const { return __argv[i]; }
int argc() const { return __argc; } int argc() const { return __argc; }
void set_title(const char* t); void set_title(const char* t) { _title = t; }
const char* title() const; const char* title() const { return _title; }
void wait_for(const char* name); void wait_for(const char* name);
void wake_up_caller() const; void wake_up_caller() const;

View File

@ -620,13 +620,13 @@ void TPush_button::draw_pressed(bool pressed) const
win_set_fore_color(_hdc, COLOR_WHITE); win_set_fore_color(_hdc, COLOR_WHITE);
win_draw_text(_hdc, _dx+p+1, _dy+p+1, (char*)t, -1); win_draw_text(_hdc, _dx+p+1, _dy+p+1, (char*)t, -1);
if (_accel >= 0) if (_accel >= 0)
win_draw_text(_hdc, _dx+_accel+p+1, _dy+p+1, "_", 1); win_draw_text(_hdc, _dx+_accel+p+1, _dy+p+3, "_", 1);
const COLOR c = disabled() ? DISABLED_COLOR : NORMAL_COLOR; const COLOR c = disabled() ? DISABLED_COLOR : NORMAL_COLOR;
win_set_fore_color(_hdc, c); win_set_fore_color(_hdc, c);
win_draw_text(_hdc, _dx+p, _dy+p, (char*)t, -1); win_draw_text(_hdc, _dx+p, _dy+p, (char*)t, -1);
if (_accel >= 0) if (_accel >= 0)
win_draw_text(_hdc, _dx+_accel+p, _dy+p, "_", 1); win_draw_text(_hdc, _dx+_accel+p, _dy+p+2, "_", 1);
} }
} }

View File

@ -82,6 +82,16 @@ void TMask::control_handler(EVENT* ep)
} }
return; return;
} }
if (type == WC_LISTBUTTON)
{
if (test_focus_change(win))
{
set_focus_win(win, FALSE);
f->on_key(K_SPACE);
}
return;
}
if (ep->v.ctl.ci.v.edit.focus_change) if (ep->v.ctl.ci.v.edit.focus_change)
{ {
@ -353,6 +363,14 @@ int TMask::first_focus(short id)
return f; return f;
} }
bool TMask::can_be_closed() const
{
bool ok = TRUE;
if (!query_mode() && is_running() && dirty())
ok = yesno_box("Annullare i dati inseriti?");
return ok;
}
void TMask::close() void TMask::close()
{ {
_open = FALSE; _open = FALSE;
@ -528,12 +546,22 @@ TMask_field& TMask::field(short id) const
return fld(pos); return fld(pos);
} }
TEdit_field& TMask::efield(short id) const
{
TMask_field& f = field(id);
CHECKD(f.is_edit(), "Impossibile trattare come editabile il campo ", id);
return (TEdit_field&)f;
}
int TMask::find_field_win(WINDOW win) const int TMask::find_field_win(WINDOW win) const
{ {
if (fld(_focus).win() == win)
return _focus;
const int max = fields(); const int max = fields();
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
if (fld(i).win() == win) return i; if (fld(i).win() == win) return i;
#ifdef DBG #ifdef DBG
yesnofatal_box("Can't find the field given the child window"); yesnofatal_box("Can't find the field given the child window");
#endif #endif

View File

@ -119,7 +119,7 @@ public:
bool check_fields(); bool check_fields();
void get_mask_fields(); // read screen contents void get_mask_fields(); // read screen contents
virtual bool stop_run(KEY key); // called to close the mask virtual bool stop_run(KEY key); // called to close the mask
virtual bool can_be_closed() const;
virtual void open(); virtual void open();
virtual void close(); virtual void close();
@ -128,6 +128,7 @@ public:
int id2pos(short id) const; int id2pos(short id) const;
TMask_field& fld(int i) const { return (TMask_field&)_field[i]; } // Ritorna il campo i-esimo della maschera TMask_field& fld(int i) const { return (TMask_field&)_field[i]; } // Ritorna il campo i-esimo della maschera
TMask_field& field(short id) const; // field with given id TMask_field& field(short id) const; // field with given id
TEdit_field& efield(short id) const; // edit-field with given id
void set(short fld_id, const char* str, bool hit=FALSE); void set(short fld_id, const char* str, bool hit=FALSE);
void set(short fld_id, long num, bool hit=FALSE); void set(short fld_id, long num, bool hit=FALSE);

View File

@ -1,4 +1,4 @@
// $Id: maskfld.cpp,v 1.16 1994-09-09 15:05:23 alex Exp $ // $Id: maskfld.cpp,v 1.17 1994-09-13 16:43:39 guy Exp $
#include <xvt.h> #include <xvt.h>
#include <applicat.h> #include <applicat.h>
@ -1843,9 +1843,10 @@ bool TEdit_field::on_key(KEY key)
switch(key) switch(key)
{ {
case K_TAB: case K_TAB:
if (_validate_func == AUTOEXIT_FUNC || _validate_func == NUMCALC_FUNC || if (_validate_func == AUTOEXIT_FUNC ||
_validate_func == NUMCALC_FUNC ||
_validate_func == STRCALC_FUNC) _validate_func == STRCALC_FUNC)
set_focusdirty(); set_focusdirty(); // Forza validate
if (to_check(K_TAB, TRUE)) if (to_check(K_TAB, TRUE))
{ {
set(get()); set(get());

View File

@ -1 +1 @@
#define VERSION 1.2 #define VERSION 1.1

View File

@ -210,14 +210,24 @@ bool TPrefix::set_codditta(long codditta, bool force)
put(); put();
return TRUE; return TRUE;
} }
else return FALSE; return FALSE;
} }
// Restituisce il nome di una directory dati
// Certified 90%
const char* firm2dir(long codditta) const char* firm2dir(long codditta)
{ {
TFixed_string dir(__tmp_string, 256); TFixed_string dir(__tmp_string, 256);
dir.format("%05lda", codditta); switch (codditta)
{
case -2: // Dati generali campione
case -1: // Dati di studio
dir = ""; break;
case 0: // Dati comuni
dir = "com"; break;
default: // Dati ditta
dir.format("%05lda", codditta); break;
}
dir.insert(__ptprf, 0); dir.insert(__ptprf, 0);
return __tmp_string; return __tmp_string;
} }

View File

@ -1,189 +1,189 @@
#include <printwin.h> #include <printwin.h>
#include <xvtility.h> #include <xvtility.h>
#include <applicat.h> #include <applicat.h>
void TPrintwin::paint_background(long j) void TPrintwin::paint_background(long j)
{ {
_isbackground = _bg->items() > 0 && MainApp()->printer().isgraphics(); _isbackground = _bg->items() > 0 && MainApp()->printer().isgraphics();
if (!_isbackground) return; if (!_isbackground) return;
int rw = (int)(j % _formlen); int rw = (int)(j % _formlen);
TString& rwd = (TString&)(*_bg)[rw]; TString& rwd = (TString&)(*_bg)[rw];
int cnt = 0; char ch; int cnt = 0; char ch;
char curcol = 'n'; char curcol = 'n';
char curpen = 'n'; char curpen = 'n';
char curpat = 'n'; char curpat = 'n';
char curwid = '1'; char curwid = '1';
unsigned int x1, x2; PNT b, e; unsigned int x1, x2; PNT b, e;
while (ch = rwd[cnt++]) while (ch = rwd[cnt++])
{ {
switch(ch) switch(ch)
{ {
case 'v': // verticale intera case 'v': // verticale intera
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2+_hofs; b.h = e.h = x1*_charx+_charx/2+_hofs;
b.v = rw * _chary + _vofs; e.v = rw * _chary + _vofs; b.v = rw * _chary + _vofs; e.v = rw * _chary + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'o': // verticale pezzo sopra case 'o': // verticale pezzo sopra
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2 + _hofs; b.h = e.h = x1*_charx+_charx/2 + _hofs;
b.v = rw * _chary + _vofs; e.v = rw * _chary - _chary/2 + _vofs; b.v = rw * _chary + _vofs; e.v = rw * _chary - _chary/2 + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'u': // verticale pezzo sotto case 'u': // verticale pezzo sotto
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2 + _hofs; b.h = e.h = x1*_charx+_charx/2 + _hofs;
b.v = rw*_chary + _chary/2 + _vofs; e.v = rw * _chary + _vofs; b.v = rw*_chary + _chary/2 + _vofs; e.v = rw * _chary + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'h': // orizzontale intera case 'h': // orizzontale intera
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
x2 = (unsigned char)rwd[cnt++]-1; x2 = (unsigned char)rwd[cnt++]-1;
b.v = e.v = rw*_chary + _chary/2 + _vofs; b.v = e.v = rw*_chary + _chary/2 + _vofs;
b.h = x1*_charx+_hofs; e.h = x2*_charx + _hofs; b.h = x1*_charx+_hofs; e.h = x2*_charx + _hofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'r': // orizzontale scorciata agli estremi case 'r': // orizzontale scorciata agli estremi
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
x2 = (unsigned char)rwd[cnt++]-1; x2 = (unsigned char)rwd[cnt++]-1;
b.v = e.v = rw*_chary + _chary/2 + _vofs; b.v = e.v = rw*_chary + _chary/2 + _vofs;
b.h = x1*_charx+_charx/2 + _hofs; e.h = x2*_charx+_charx/2+_hofs; b.h = x1*_charx+_charx/2 + _hofs; e.h = x2*_charx+_charx/2+_hofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'W': case 'W':
curwid = rwd[cnt++]; curwid = rwd[cnt++];
set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat), set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat),
trans_pen(curpen)); trans_pen(curpen));
break; break;
case 'P': case 'P':
curpen = rwd[cnt++]; curpen = rwd[cnt++];
set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat), set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat),
trans_pen(curpen)); trans_pen(curpen));
break; break;
case 'B': case 'B':
curpat = rwd[cnt++]; curpat = rwd[cnt++];
set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat), set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat),
trans_pen(curpen)); trans_pen(curpen));
break; break;
case 'C': case 'C':
curcol = rwd[cnt++]; curcol = rwd[cnt++];
set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat), set_pen(trans_color(curcol), curwid- '0', trans_brush(curpat),
trans_pen(curpen)); trans_pen(curpen));
break; break;
default: default:
break; break;
} }
} }
// restore default pen // restore default pen
set_pen(COLOR_BLACK); set_pen(COLOR_BLACK);
} }
void TPrintwin::paint_row(long j) void TPrintwin::paint_row(long j)
{ {
const char* cp; int pos = 0; const char* cp; int pos = 0;
int row = (int)(j % _formlen); int row = (int)(j % _formlen);
_txt.read_line(j); _txt.read_line(j);
while(cp = _txt.piece()) while(cp = _txt.piece())
{ {
#if XVT_OS != XVT_OS_SCOUNIX #if XVT_OS != XVT_OS_SCOUNIX
int st = _txt.get_style(); int st = _txt.get_style();
long bg = trans_color(_txt.get_background()); long bg = trans_color(_txt.get_background());
long fg = trans_color(_txt.get_foreground()); long fg = trans_color(_txt.get_foreground());
set_font(FF_FIXED, st & 0x000f, _char_size); set_font(FF_FIXED, st & 0x000f, _char_size);
set_color(fg,bg); set_color(fg,bg);
#else #else
set_color(COLOR_BLACK, COLOR_WHITE); set_color(COLOR_BLACK, COLOR_WHITE);
#endif #endif
win_draw_text(win(), pos*_charx + _hofs, row*_chary + _chary + _vofs - _descent, win_draw_text(win(), pos*_charx + _hofs, row*_chary + _chary + _vofs - _descent,
(char *)cp, -1); (char *)cp, -1);
#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*pos + _hofs; b.v = row*_chary + _chary + _vofs; b.h = _charx*pos + _hofs; b.v = row*_chary + _chary + _vofs;
e.h = _charx*(pos+strlen(cp)) + _hofs; e.v = b.v; e.h = _charx*(pos+strlen(cp)) + _hofs; e.v = b.v;
win_move_to (win(),b); win_move_to (win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
} }
#endif #endif
pos += strlen(cp); pos += strlen(cp);
} }
paint_background(j); paint_background(j);
} }
bool TPrintwin::print_band(int page, RCT& r) bool TPrintwin::print_band(int page, RCT& r)
{ {
int j = page*_formlen; int j = page*_formlen;
int rows = (r.bottom - r.top) / _chary; int rows = (r.bottom - r.top) / _chary;
int top = r.top / _chary; int top = r.top / _chary;
for (int k = top; k < top+rows; k++) for (int k = top; k < top+rows; k++)
{ {
if ((j+k) < _txt.lines() && k < _formlen) if ((j+k) < _txt.lines() && k < _formlen)
paint_row(j+k); paint_row(j+k);
else break; else break;
} }
return j+k < _txt.lines(); return j+k < _txt.lines();
} }
bool TPrintwin::do_print() bool TPrintwin::do_print()
{ {
int page = 0; int page = 0;
RCT* rct; RCT* rct;
bool ok = TRUE; bool ok = TRUE;
while (ok && !_aborted) while (ok && !_aborted)
{ {
_aborted = !(bool)start_page(_printrcd); _aborted = !(bool)start_page(_printrcd);
while (!_aborted && ok && (rct = next_band()) != NULL) while (!_aborted && ok && (rct = next_band()) != NULL)
ok = print_band(page, *rct); ok = print_band(page, *rct);
finish_page(_printrcd); finish_page(_printrcd);
page++; page++;
} }
return !_aborted; return !_aborted;
} }
TPrintwin::~TPrintwin() TPrintwin::~TPrintwin()
{ {
close_print_window(win(), _printrcd); close_print_window(win(), _printrcd);
set_win(NULL_WIN); set_win(NULL_WIN);
} }
TPrintwin::TPrintwin(PRINT_RCD* p, TTextfile& txt, int chsz) : TPrintwin::TPrintwin(PRINT_RCD* p, TTextfile& txt, int chsz) :
_printrcd(p), _aborted(FALSE), _txt(txt), _char_size(chsz) _printrcd(p), _aborted(FALSE), _txt(txt), _char_size(chsz)
{ {
WINDOW w = new_print_window(_printrcd, (char*)MainApp()->title()); WINDOW w = new_print_window(_printrcd, (char*)MainApp()->title());
set_win(w); set_win(w);
if (w != NULL_WIN) if (w != NULL_WIN)
{ {
_bg = MainApp()->printer().getbgdesc(); _bg = MainApp()->printer().getbgdesc();
_isbackground = _bg->items() > 0 && MainApp()->printer().isgraphics(); _isbackground = _bg->items() > 0 && MainApp()->printer().isgraphics();
_formlen = MainApp()->printer().formlen(); _formlen = MainApp()->printer().formlen();
set_font(FF_SYSTEM,0,_char_size); set_font(FF_SYSTEM,0,_char_size);
win_get_font_metrics(win(), &_lead, &_ascent, &_descent); win_get_font_metrics(win(), &_lead, &_ascent, &_descent);
_charx = win_get_text_width(win(), "MM", -1) - win_get_text_width(win(), "M", -1); _charx = win_get_text_width(win(), "MM", -1) - win_get_text_width(win(), "M", -1);
_chary = MainApp()->printer().get_dots_per_line(); _chary = MainApp()->printer().get_dots_per_line();
RCT rct; get_client_rect(win(),&rct); RCT rct; get_client_rect(win(),&rct);
_vofs = MainApp()->printer().get_vert_offset(); _vofs = MainApp()->printer().get_vert_offset();
_hofs = (rct.right - rct.left) % _charx; _hofs = (rct.right - rct.left) % _charx;
} }
else _aborted = TRUE; else _aborted = TRUE;
} }

View File

@ -1,50 +1,52 @@
#ifndef __PRINTWIN_H #ifndef __PRINTWIN_H
#define __PRINTWIN_H #define __PRINTWIN_H
#ifndef __WINDOW_H #ifndef __WINDOW_H
#include <window.h> #include <window.h>
#endif #endif
#ifndef __ARRAY_H #ifndef __ARRAY_H
#include <array.h> #include <array.h>
#endif #endif
#ifndef __TEXT_H #ifndef __TEXT_H
#include <text.h> #include <text.h>
#endif #endif
class TPrintwin : public TWindow class TPrintwin : public TWindow
{ {
bool _aborted; bool _aborted;
bool _isbackground; bool _isbackground;
PRINT_RCD* _printrcd; PRINT_RCD* _printrcd;
int _formlen; int _formlen;
int _formwidth; int _formwidth;
TArray* _bg; TArray* _bg;
TTextfile& _txt; TTextfile& _txt;
int _lead, _ascent, _descent; int _lead, _ascent, _descent;
int _hofs, _vofs; int _hofs, _vofs;
int _charx, _chary; int _charx, _chary;
int _char_size; int _char_size;
void paint_background(long j); void paint_background(long j);
void paint_row(long j); void paint_row(long j);
bool print_band(int, RCT&); bool print_band(int, RCT&);
public: public:
// check if aborted; also returned by do_print // check if aborted; also returned by do_print
bool aborted() { return _aborted; } bool aborted() const { return _aborted; }
// inhibits background printing
void print_background(bool b) { _isbackground = b; } // inhibits background printing
// starts printing; FALSE if aborted void print_background(bool b) { _isbackground = b; }
bool do_print();
// starts printing; FALSE if aborted
TPrintwin(PRINT_RCD* pr, TTextfile& txt, int chsize = 12); bool do_print();
virtual ~TPrintwin();
}; TPrintwin(PRINT_RCD* pr, TTextfile& txt, int chsize = 12);
virtual ~TPrintwin();
};
#endif
#endif

View File

@ -1,261 +1,267 @@
// $Id: progind.cpp,v 1.1.1.1 1994-08-12 10:52:04 alex Exp $ // $Id: progind.cpp,v 1.2 1994-09-13 16:43:46 guy Exp $
#include <defmask.h> #include <defmask.h>
#include <progind.h> #include <progind.h>
const char* const CANCEL_TEXT = "Annulla"; const char* const CANCEL_TEXT = "Annulla";
const char* const TITLE_TEXT = "Attesa"; const char* const TITLE_TEXT = "Attesa";
// Certified 70% // Certified 70%
TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div) TIndwin::TIndwin(long max, const char* txt, bool cancel, bool bar, int div)
{ {
_cancel = _bar = _text = NULL_WIN; _cancel = _bar = _text = NULL_WIN;
_status = 0l; _status = 0l;
_max = max; _max = max;
if (_max <= 0) _max = 1; if (_max <= 0) _max = 1;
_flags = 0x0; _flags = 0x0;
word maxlen = div, lines; word maxlen = div, lines;
measure_text(txt, maxlen, lines); measure_text(txt, maxlen, lines);
int ver = lines+3; int ver = lines+3;
int hor = maxlen+2; if (hor > 78) hor = 78; int hor = maxlen+2; if (hor > 78) hor = 78;
if (bar) if (bar)
{ {
_bar = ver * CHARY; _bar = ver * CHARY;
ver += 3; ver += 3;
} }
ver += cancel ? 3 : 0; ver += cancel ? 3 : 0;
create(-1, -1, hor, ver, TITLE_TEXT); create(-1, -1, hor, ver, TITLE_TEXT);
RCT r; r.left = CHARX; r.top = CHARY; r.right = CHARX*(hor-2); r.bottom = r.top + lines*CHARY+4; RCT r; r.left = CHARX; r.top = CHARY; r.right = CHARX*(hor-2); r.bottom = r.top + lines*CHARY+4;
_text = create_control(WC_TEXT, &r, (char*)txt, win(), CTL_FLAG_CENTER_JUST, 0l, DLG_NULL); _text = create_control(WC_TEXT, &r, (char*)txt, win(), CTL_FLAG_CENTER_JUST, 0l, DLG_NULL);
if (cancel) if (cancel)
_cancel = xvt_create_control(WC_PUSHBUTTON, -11, -1, 9, 2, _cancel = xvt_create_control(WC_PUSHBUTTON, -11, -1, 9, 2,
CANCEL_TEXT, win(), 0, 0l, DLG_CANCEL); CANCEL_TEXT, win(), 0, 0l, DLG_CANCEL);
open_modal(); open_modal();
do_events(); do_events();
} }
void TIndwin::set_text(const char* t) void TIndwin::set_text(const char* t)
{ {
set_title(_text, (char*)t); set_title(_text, (char*)t);
} }
TIndwin::~TIndwin() TIndwin::~TIndwin()
{ close_modal(); } { close_modal(); }
void TIndwin::measure_text(const char* txt, word& maxlen, word& lines) const void TIndwin::measure_text(const char* txt, word& maxlen, word& lines) const
{ {
TToken_string s(txt, '\n'); TToken_string s(txt, '\n');
lines = 0; lines = 0;
for(const char* t = s.get(0); t; t = s.get()) for(const char* t = s.get(0); t; t = s.get())
{ {
const word l = strlen(t); const word l = strlen(t);
if (l > maxlen) maxlen = l; if (l > maxlen) maxlen = l;
lines++; lines++;
} }
} }
bool TIndwin::can_be_closed() const
KEY TIndwin::check_stop() {
{ const bool ok = (_flags & IND_FINISHED) || (_flags & IND_CANCELLED);
KEY k = 0; if (!ok) error_box("Attendere la fine dell'operazione prima di chiudere l'applicazione");
if (_flags & IND_FINISHED || _flags & IND_CANCELLED) return ok;
{ }
k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
stop_run(k); KEY TIndwin::check_stop()
} {
return k; KEY k = 0;
} if ((_flags & IND_FINISHED) || (_flags & IND_CANCELLED))
{
void TIndwin::update_bar() k = (_flags & IND_FINISHED) ? K_ENTER : K_ESC;
{ stop_run(k);
if (_status >= _max) }
{ return k;
_status = _max; }
_flags |= IND_FINISHED;
} void TIndwin::update_bar()
{
const double prc = (double)_status/_max; if (_status >= _max)
{
RCT r; get_client_rect(win(), &r); _status = _max;
r.left = CHARX; r.right -= CHARX; _flags |= IND_FINISHED;
r.top = (int)_bar; }
r.bottom = r.top + 3*CHARY;
#if XVT_OS == XVT_OS_WIN const double prc = (double)_status/_max;
r.top += 6;
r.bottom -= 6; RCT r; get_client_rect(win(), &r);
#endif r.left = CHARX; r.right -= CHARX;
const int width = r.right - r.left; r.top = (int)_bar;
r.bottom = r.top + 3*CHARY;
RCT b = r; #if XVT_OS == XVT_OS_WIN
set_brush(COLOR_BLUE); r.top += 6;
b.right = b.left + int(width*prc); r.bottom -= 6;
win_draw_rect(win(), &b); #endif
const int width = r.right - r.left;
set_brush(COLOR_WHITE);
b.left = b.right; b.right = r.right; RCT b = r;
win_draw_rect(win(), &b); set_brush(COLOR_BLUE);
b.right = b.left + int(width*prc);
set_mode(M_XOR); win_draw_rect(win(), &b);
win_set_fore_color(win(), COLOR_BLUE);
char n[8]; sprintf(n, "%d%%", int(100*prc)); set_brush(COLOR_WHITE);
win_draw_text(win(), r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1); b.left = b.right; b.right = r.right;
set_mode(M_COPY); win_draw_rect(win(), &b);
check_stop(); set_mode(M_XOR);
} win_set_fore_color(win(), COLOR_BLUE);
char n[8]; sprintf(n, "%d%%", int(100*prc));
void TIndwin::update() win_draw_text(win(), r.left+width/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
{ set_mode(M_COPY);
if (_bar) update_bar();
} check_stop();
}
void TIndwin::handler(WINDOW w, EVENT* e) void TIndwin::update()
{ {
switch(e->type) if (_bar) update_bar();
{ }
case E_UPDATE:
clear_window(w, COLOR_WHITE);
update(); void TIndwin::handler(WINDOW w, EVENT* e)
return; {
case E_CONTROL: switch(e->type)
if (e->v.ctl.id == DLG_CANCEL) {
dispatch_e_char(w, K_ESC); case E_UPDATE:
break; clear_window(w, COLOR_WHITE);
case E_CHAR: update();
// allowed only if cancel button is there return;
if (e->v.chr.ch == K_ESC) case E_CONTROL:
{ if (e->v.ctl.id == DLG_CANCEL)
if (_cancel) dispatch_e_char(w, K_ESC);
{ break;
_flags |= IND_CANCELLED; case E_CHAR:
check_stop(); // allowed only if cancel button is there
} if (e->v.chr.ch == K_ESC)
else return; {
} if (_cancel)
break; {
default: _flags |= IND_CANCELLED;
break; check_stop();
} }
TWindow::handler(w,e); else return;
} }
break;
default:
// TProgind -------------------------------------------------------------- break;
}
TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div) TWindow::handler(w,e);
: TIndwin(max, txt, cancel, bar, div) }
{}
// TTimerind ------------------------------------------------------------ // TProgind --------------------------------------------------------------
long TTimerind::_timer_id = 0L; TProgind::TProgind(long max, const char* txt, bool cancel, bool bar, int div)
: TIndwin(max, txt, cancel, bar, div)
void TTimerind::handler(WINDOW w, EVENT* e) {}
{
switch(e->type) // TTimerind ------------------------------------------------------------
{
case E_CREATE: long TTimerind::_timer_id = 0L;
case E_UPDATE:
if (_status == 0L) void TTimerind::handler(WINDOW w, EVENT* e)
_timer_id = set_timer(w, _interval); {
break; switch(e->type)
case E_TIMER: {
if (e->v.timer.id == _timer_id) case E_CREATE:
{ case E_UPDATE:
_status += _interval; if (_status == 0L)
force_update(); _timer_id = set_timer(w, _interval);
set_timer(w, _interval); break;
} case E_TIMER:
break; if (e->v.timer.id == _timer_id)
default: {
break; _status += _interval;
} force_update();
TIndwin::handler(w,e); set_timer(w, _interval);
} }
break;
TTimerind::TTimerind(long msec, const char* txt, default:
bool cancel, bool bar, int div, int i) : break;
TIndwin(msec, txt, cancel, bar, div) }
{ TIndwin::handler(w,e);
_interval = i; }
_timer_id = 0L;
} TTimerind::TTimerind(long msec, const char* txt,
bool cancel, bool bar, int div, int i) :
TTimerind::~TTimerind() TIndwin(msec, txt, cancel, bar, div)
{ kill_timer(_timer_id); } {
_interval = i;
// C-style binding _timer_id = 0L;
// uses static pointer for single instance of TIndwin }
static TIndwin* __indwin__p = NULL; TTimerind::~TTimerind()
{ kill_timer(_timer_id); }
void progind_create(long m, char* t, bool b, bool c, int n)
{ // C-style binding
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator"); // uses static pointer for single instance of TIndwin
__indwin__p = new TProgind(m,t,b,c,n);
} static TIndwin* __indwin__p = NULL;
void progind_set_status(long l) void progind_create(long m, char* t, bool b, bool c, int n)
{ {
((TProgind*)__indwin__p)->setstatus(l); CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
} __indwin__p = new TProgind(m,t,b,c,n);
}
void progind_cancel()
{ void progind_set_status(long l)
__indwin__p->cancel(); {
} ((TProgind*)__indwin__p)->setstatus(l);
}
bool progind_iscancelled()
{ void progind_cancel()
return __indwin__p->iscancelled(); {
} __indwin__p->cancel();
}
bool progind_isfinished()
{ bool progind_iscancelled()
return __indwin__p->isfinished(); {
} return __indwin__p->iscancelled();
}
void progind_destroy()
{ bool progind_isfinished()
delete __indwin__p; {
__indwin__p = NULL; return __indwin__p->isfinished();
} }
void timerind_create(long l, char* title, bool bar, bool cancel, void progind_destroy()
int divisions, int interval) {
{ delete __indwin__p;
CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator"); __indwin__p = NULL;
__indwin__p = new TTimerind(l,title,bar,cancel,divisions,interval); }
}
void timerind_create(long l, char* title, bool bar, bool cancel,
void timerind_cancel() int divisions, int interval)
{ {
__indwin__p->cancel(); CHECK(__indwin__p == NULL, "Cannot have more than one progress indicator");
} __indwin__p = new TTimerind(l,title,bar,cancel,divisions,interval);
}
bool timerind_iscancelled()
{ void timerind_cancel()
return __indwin__p->iscancelled(); {
} __indwin__p->cancel();
}
bool timerind_isfinished()
{ bool timerind_iscancelled()
return __indwin__p->isfinished(); {
} return __indwin__p->iscancelled();
}
void timerind_destroy()
{ bool timerind_isfinished()
delete __indwin__p; {
__indwin__p = NULL; return __indwin__p->isfinished();
} }
void timerind_destroy()
{
delete __indwin__p;
__indwin__p = NULL;
}

View File

@ -1,143 +1,145 @@
/* $Id: progind.h,v 1.1.1.1 1994-08-12 10:52:04 alex Exp $ */ /* $Id: progind.h,v 1.2 1994-09-13 16:43:47 guy Exp $ */
/* @N /* @N
progind.h progind.h
program status and timer boxes program status and timer boxes
fv 20/8/93 fv 20/8/93
works for both C and C++ works for both C and C++
@END @END
*/ */
#ifdef __cplusplus #ifdef __cplusplus
#ifndef __PROGIND_H #ifndef __PROGIND_H
#define __PROGIND_H #define __PROGIND_H
#ifndef __WINDOW_H #ifndef __WINDOW_H
#include <window.h> #include <window.h>
#endif #endif
#ifndef __STRINGS_H #ifndef __STRINGS_H
#include <strings.h> #include <strings.h>
#endif #endif
/* /*
@C @C
class TIndwin : public TWindow class TIndwin : public TWindow
@END @END
*/ */
class TIndwin : public TWindow class TIndwin : public TWindow
{ {
/* @DPRIV */ /* @DPRIV */
enum { IND_CANCELLED = 0x01, IND_FINISHED= 0x02 }; enum { IND_CANCELLED = 0x01, IND_FINISHED= 0x02 };
WINDOW _text; // Static text WINDOW _text; // Static text
WINDOW _cancel; // CANCEL button WINDOW _cancel; // CANCEL button
WINDOW _bar; // Moving bar and percentage WINDOW _bar; // Moving bar and percentage
byte _flags; byte _flags;
/* @END */ /* @END */
protected: protected:
/* @FPROT */ /* @FPROT */
long _max; // maximum value to reach long _max; // maximum value to reach
long _status; // current status (set by user) long _status; // current status (set by user)
void draw_window(); void draw_window();
void measure_text(const char* t, word& len, word& lin) const; void measure_text(const char* t, word& len, word& lin) const;
virtual void handler(WINDOW w, EVENT* e); virtual void handler(WINDOW w, EVENT* e);
virtual void update(); virtual void update();
void update_bar(); void update_bar();
KEY check_stop(); KEY check_stop();
public: public:
/* @FPUB */ /* @FPUB */
bool iscancelled() const { return _flags & IND_CANCELLED; } bool iscancelled() const { return _flags & IND_CANCELLED; }
bool isfinished() const { return _flags & IND_FINISHED; } bool isfinished() const { return _flags & IND_FINISHED; }
long status() const { return _status; } long status() const { return _status; }
void cancel() { _flags |= IND_CANCELLED; check_stop(); } void cancel() { _flags |= IND_CANCELLED; check_stop(); }
/* @END */
virtual bool can_be_closed() const;
/* @LONGDES /* @END */
si puo' chiamare settext() per cambiare il testo, ma
le dimensioni della finestra sono calcolate sul primo /* @LONGDES
passato, quindi occorre dare spazi se se ne prevede si puo' chiamare settext() per cambiare il testo, ma
uno piu' lungo le dimensioni della finestra sono calcolate sul primo
@END */ passato, quindi occorre dare spazi se se ne prevede
void set_text(const char* t); uno piu' lungo
@END */
/* FPUB */ void set_text(const char* t);
TIndwin(long max, const char* txt, bool cancel = TRUE, bool bar = TRUE, int div = 16);
virtual ~TIndwin(); /* FPUB */
}; TIndwin(long max, const char* txt, bool cancel = TRUE, bool bar = TRUE, int div = 16);
virtual ~TIndwin();
/* };
@C
class TProgind : public TIndwin /*
@END @C
*/ class TProgind : public TIndwin
@END
class TProgind : public TIndwin */
{
public: class TProgind : public TIndwin
/* @FPUB */ {
void setmax(long m) { _max = m; } public:
void setstatus(long l) { _status = l; update_bar(); do_events(); } /* @FPUB */
void addstatus(long l) { setstatus(_status+l); } void setmax(long m) { _max = m; }
TProgind(long max, const char* txt = NULL, bool cancel = TRUE, void setstatus(long l) { _status = l; update_bar(); do_events(); }
bool bar = TRUE, int div = 10); void addstatus(long l) { setstatus(_status+l); }
virtual ~TProgind() {} TProgind(long max, const char* txt = NULL, bool cancel = TRUE,
}; bool bar = TRUE, int div = 10);
virtual ~TProgind() {}
/* };
@C
class TTimerind : public TIndwin /*
@END @C
*/ class TTimerind : public TIndwin
@END
class TTimerind : public TIndwin */
{
/* @DPRIV */ class TTimerind : public TIndwin
int _interval; {
static long _timer_id; /* @DPRIV */
int _interval;
protected: static long _timer_id;
/* @FPROT */
virtual void handler(WINDOW w, EVENT* e); protected:
/* @FPROT */
public: virtual void handler(WINDOW w, EVENT* e);
/* @FPUB */
TTimerind(long msec, const char* txt = NULL, bool cancel = TRUE, public:
bool bar = TRUE, int div = 10, int interval = 1000); /* @FPUB */
virtual ~TTimerind(); TTimerind(long msec, const char* txt = NULL, bool cancel = TRUE,
}; bool bar = TRUE, int div = 10, int interval = 1000);
virtual ~TTimerind();
};
/* @DPRIV */
/* extern TIndwin* __indwin__p; */
/* @DPRIV */
/* @FPUB */ /* extern TIndwin* __indwin__p; */
#endif
/* @FPUB */
#ifdef __cplusplus #endif
extern "C" {
#endif #ifdef __cplusplus
extern "C" {
void progind_create(long, char*, bool, bool, int); #endif
void progind_set_status(long);
void progind_cancel(); void progind_create(long, char*, bool, bool, int);
bool progind_iscancelled(); void progind_set_status(long);
bool progind_isfinished(); void progind_cancel();
void progind_destroy(); bool progind_iscancelled();
void timerind_create(long, char*, bool, bool, int, int); bool progind_isfinished();
void timerind_cancel(); void progind_destroy();
bool timerind_iscancelled(); void timerind_create(long, char*, bool, bool, int, int);
bool timerind_isfinished(); void timerind_cancel();
void timerind_destroy(); bool timerind_iscancelled();
bool timerind_isfinished();
#ifdef __cplusplus void timerind_destroy();
}
#endif #ifdef __cplusplus
}
#endif /* __PROGIND_H */ #endif
#endif /* __PROGIND_H */

View File

@ -1,4 +1,4 @@
// $Id: relapp.cpp,v 1.7 1994-09-02 15:16:50 alex Exp $ // $Id: relapp.cpp,v 1.8 1994-09-13 16:43:48 guy Exp $
#include <mailbox.h> #include <mailbox.h>
#include <sheet.h> #include <sheet.h>
#include <urldefid.h> #include <urldefid.h>
@ -482,7 +482,7 @@ bool TRelation_application::test_key(byte k, bool err)
if (err) if (err)
{ {
_mask->first_focus(-c.dlg()); _mask->first_focus(-c.dlg());
error_box("Manca un valore indispensabile"); error_box("Manca un valore indispensabile per la ricerca");
} }
return FALSE; return FALSE;
} }
@ -494,7 +494,7 @@ bool TRelation_application::test_key(byte k, bool err)
if (k == 1 && !onereq && !onefill) if (k == 1 && !onereq && !onefill)
{ {
if (err) if (err)
error_box("Manca un valore indispensabile"); error_box("Manca un valore indispensabile per la ricerca");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;

View File

@ -40,7 +40,7 @@ public:
TWindow* cur_win() const { return (_current < 0) ? NULL : _window[_current]; } // Ritorna il puntatore alla finestra corrente TWindow* cur_win() const { return (_current < 0) ? NULL : _window[_current]; } // Ritorna il puntatore alla finestra corrente
void destroy(); void destroy();
bool can_close() const { return _current < 1; } bool can_close() const;
} WinManager; } WinManager;
@ -58,6 +58,15 @@ void TWindow_manager::destroy()
} }
} }
bool TWindow_manager::can_close() const
{
bool ok = TRUE;
if (_current >= 0)
ok = cur_win()->can_be_closed();
return ok;
}
// Dis/abilitazione del menu principale // Dis/abilitazione del menu principale
HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on) HIDDEN void xvt_menu_enable(MENU_ITEM* m, bool on)
{ {
@ -107,10 +116,15 @@ void TWindow_manager::reg(TWindow* m)
switch (_current) switch (_current)
{ {
case 0 : menu_enable(FALSE); break; case 0 :
case 1 : win_menu_enable(TASK_WIN, M_FILE_QUIT, FALSE); menu_enable(FALSE);
default: _window[_current-1]->disable(); break; break;
} case 1 :
win_menu_enable(TASK_WIN, M_FILE_QUIT, _current < 1);
break;
default:
_window[_current-1]->disable(); break;
}
_window[_current] = m; _window[_current] = m;
} }
@ -121,20 +135,22 @@ void TWindow_manager::unreg(const TWindow* m)
#ifdef DBG #ifdef DBG
if (m != cur_win()) if (m != cur_win())
{ {
error_box("You can unregister the current window only"); yesnofatal_box("You can unregister the current window only");
return; return;
} }
#endif #endif
_current--; _current--;
if (_current < 0) if (_current <= 0)
{
menu_enable(TRUE); menu_enable(TRUE);
win_menu_enable(TASK_WIN, M_FILE_QUIT, TRUE);
}
else else
{ {
if (_current == 0)
win_menu_enable(TASK_WIN, M_FILE_QUIT, TRUE);
cur_win()->enable(); cur_win()->enable();
win_menu_enable(TASK_WIN, M_FILE_QUIT, FALSE);
} }
} }
@ -185,7 +201,7 @@ WINDOW TWindow::create(short x, short y, short dx, short dy,
{ {
flags |= WSF_NO_MENUBAR; flags |= WSF_NO_MENUBAR;
if (parent == NULL_WIN) parent = TASK_WIN; if (parent == NULL_WIN) parent = TASK_WIN;
if (parent == TASK_WIN) flags |= WSF_INVISIBLE; if (parent == TASK_WIN) flags |= WSF_INVISIBLE;
_win = xvt_create_window( _win = xvt_create_window(
@ -241,7 +257,6 @@ void TWindow::close()
void TWindow::close_modal() void TWindow::close_modal()
{ {
WinManager.unreg(this); WinManager.unreg(this);
close(); close();
_open = FALSE; _open = FALSE;
} }
@ -253,6 +268,13 @@ bool TWindow::stop_run(KEY key)
return TRUE; return TRUE;
} }
bool TWindow::can_be_closed() const
{
const bool ok = !is_modal();
if (!ok)
error_box("Chiudere la finestra attiva prima di uscire dal programma");
return ok;
}
KEY TWindow::run() KEY TWindow::run()
{ {

View File

@ -104,6 +104,7 @@ public:
virtual void open(); // Mostra la finestra virtual void open(); // Mostra la finestra
virtual void close(); // Nasconde la finestra virtual void close(); // Nasconde la finestra
virtual bool can_be_closed() const; // Puo' essere chiusa brutalmente?
void iconize() const; void iconize() const;
void maximize() const; void maximize() const;