1994-08-12 10:52:49 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
#include <colors.h>
|
|
|
|
#include <msksheet.h>
|
|
|
|
#include <relation.h>
|
|
|
|
#include <urldefid.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#define NULL_PAGE 256
|
|
|
|
|
1994-09-01 16:30:57 +00:00
|
|
|
HIDDEN const char* const MASK_EXT = "msk";
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-09-14 07:37:32 +00:00
|
|
|
clock_t clock1, clock2;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TMask methods
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HIDDEN bool moving_focus = FALSE;
|
|
|
|
|
1994-09-01 16:30:57 +00:00
|
|
|
|
|
|
|
bool TMask::test_focus_change(WINDOW next)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
|
|
|
|
TMask_field& prev = fld(_focus);
|
|
|
|
if (prev.win() != next)
|
|
|
|
{
|
|
|
|
if (prev.on_key(K_TAB) == FALSE) // Test if previous field agrees ...
|
|
|
|
{
|
|
|
|
set_focus();
|
1994-09-01 17:03:53 +00:00
|
|
|
prev.set_focusdirty(FALSE);
|
1994-09-01 16:30:57 +00:00
|
|
|
ok = FALSE; // ... sorry, it does not
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
void TMask::control_handler(EVENT* ep)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const WINDOW win = ep->v.ctl.ci.win;
|
|
|
|
const WIN_TYPE type = ep->v.ctl.ci.type;
|
|
|
|
|
|
|
|
TMask_field* f = (TMask_field*)get_app_data(win);
|
|
|
|
CHECK(f != NULL, "Invalid field pointer in control");
|
|
|
|
|
|
|
|
if (type == WC_CHECKBOX)
|
|
|
|
{
|
1994-09-01 16:30:57 +00:00
|
|
|
if (test_focus_change(win))
|
|
|
|
{
|
|
|
|
xvt_check_box(win, !xvt_get_checked_state(win));
|
|
|
|
set_focus_win(win, FALSE);
|
|
|
|
f->on_key(K_SPACE);
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == WC_RADIOBUTTON)
|
|
|
|
{
|
|
|
|
if (moving_focus == FALSE)
|
|
|
|
{
|
1994-09-01 16:30:57 +00:00
|
|
|
if (test_focus_change(win))
|
|
|
|
{
|
|
|
|
((TRadio_field*)f)->check_radiobutton(win);
|
|
|
|
set_focus_win(win, FALSE);
|
|
|
|
f->on_key(K_SPACE);
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
} else moving_focus = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == WC_PUSHBUTTON)
|
|
|
|
{
|
1994-09-01 16:30:57 +00:00
|
|
|
if (test_focus_change(win))
|
|
|
|
{
|
|
|
|
set_focus_win(win, FALSE);
|
|
|
|
f->on_hit();
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
return;
|
|
|
|
}
|
1994-09-13 16:43:52 +00:00
|
|
|
|
|
|
|
if (type == WC_LISTBUTTON)
|
|
|
|
{
|
|
|
|
if (test_focus_change(win))
|
|
|
|
{
|
|
|
|
set_focus_win(win, FALSE);
|
|
|
|
f->on_key(K_SPACE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
|
|
|
|
if (ep->v.ctl.ci.v.edit.focus_change)
|
|
|
|
{
|
|
|
|
if (ep->v.ctl.ci.v.edit.active)
|
1994-09-01 16:30:57 +00:00
|
|
|
{
|
|
|
|
if (test_focus_change(win))
|
1994-09-05 10:58:03 +00:00
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
set_focus_win(win, FALSE);
|
1994-09-05 10:58:03 +00:00
|
|
|
f->set_focusdirty(FALSE);
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Contents of control were changed
|
|
|
|
f->on_key(K_SPACE);
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::handler(WINDOW win, EVENT* ep)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
switch (ep->type)
|
|
|
|
{
|
|
|
|
case E_UPDATE:
|
1994-08-12 10:52:49 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-08-19 10:43:57 +00:00
|
|
|
if (win != toolwin())
|
|
|
|
{
|
|
|
|
clear_window(win, MASK_BACK_COLOR);
|
|
|
|
RCT r; get_client_rect(win, &r);
|
1994-10-03 08:47:32 +00:00
|
|
|
#ifdef __CTL3D__
|
|
|
|
xvt_draw_rect(win, r, COLOR_WHITE, COLOR_GRAY, 1);
|
|
|
|
#else
|
1994-08-19 10:43:57 +00:00
|
|
|
xvt_draw_rect(win, r, COLOR_CYAN, COLOR_GRAY, 1);
|
1994-10-03 08:47:32 +00:00
|
|
|
#endif
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
|
|
|
else clear_window(win, COLOR_GRAY);
|
1994-08-12 10:52:49 +00:00
|
|
|
#else
|
1994-08-19 10:43:57 +00:00
|
|
|
clear_window(win, MASK_BACK_COLOR);
|
1994-08-12 10:52:49 +00:00
|
|
|
#endif
|
1994-08-19 10:43:57 +00:00
|
|
|
update();
|
|
|
|
return;
|
|
|
|
case E_CONTROL:
|
|
|
|
switch(ep->v.ctl.id)
|
|
|
|
{
|
1994-09-01 16:30:57 +00:00
|
|
|
case DLG_OK:
|
|
|
|
if (test_focus_change()) stop_run(K_AUTO_ENTER); break;
|
1994-08-23 13:52:36 +00:00
|
|
|
case DLG_BAR :
|
|
|
|
case DLG_CANCEL :
|
1994-08-26 13:07:24 +00:00
|
|
|
stop_run(K_ESC); break;
|
|
|
|
case DLG_QUIT :
|
|
|
|
stop_run(K_FORCE_CLOSE); break;
|
1994-10-14 19:15:23 +00:00
|
|
|
/*
|
|
|
|
case DLG_NEWREC :
|
|
|
|
if (test_focus_change()) stop_run(K_INS);
|
|
|
|
break;
|
|
|
|
case DLG_DELREC :
|
|
|
|
if (test_focus_change()) stop_run(K_DEL);
|
|
|
|
break;
|
1994-08-23 13:52:36 +00:00
|
|
|
*/
|
1994-09-01 16:30:57 +00:00
|
|
|
case DLG_F9:
|
|
|
|
{
|
|
|
|
WINDOW w = ep->v.ctl.ci.win;
|
1994-11-03 12:46:49 +00:00
|
|
|
TMask_field* f = (TMask_field*)get_app_data(w);
|
|
|
|
w = f->win();
|
1994-09-01 16:30:57 +00:00
|
|
|
if (test_focus_change(w))
|
1994-11-03 12:46:49 +00:00
|
|
|
f->on_key(K_F9); // Attiva ricerca sul campo associato al bottone
|
1994-08-23 13:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
control_handler(ep);
|
|
|
|
break;
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TWindow::handler(win, ep);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::init_mask(int mode)
|
|
|
|
{
|
1994-08-23 13:52:36 +00:00
|
|
|
_sheets = _pages = 0; // Azzera numero pagine e sheets
|
|
|
|
_enabled = 0xffff; // Abilita tutte le pagine
|
1994-10-13 08:04:42 +00:00
|
|
|
_focus = _first_focus = 0; // Nessuno ha il focus
|
|
|
|
_page = -1; // Nessuna pagina corrente
|
1994-08-23 13:52:36 +00:00
|
|
|
_handler = NULL; // Nessun handler utente
|
|
|
|
_mode = mode; // Inizializza modo
|
|
|
|
_exchange = 1.0; // Il cambio per la valuta e' la lira
|
1994-08-19 10:43:57 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= MAX_PAGES; i++)
|
1994-08-23 13:52:36 +00:00
|
|
|
_pagewin[i] = NULL_WIN; // Azzera le finestre delle varie pagine
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMask::TMask(const char* title, int pages, int cols, int rows, int xpos,
|
1994-08-19 10:43:57 +00:00
|
|
|
int ypos, int mode)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
init_mask(mode);
|
|
|
|
for (_pages = 0; _pages < pages; _pages++)
|
1994-10-14 19:15:23 +00:00
|
|
|
_pagewin[_pages] = create(xpos, ypos, cols, rows, title, WSF_CLOSE, WD_MODAL);
|
1994-08-19 10:43:57 +00:00
|
|
|
set_win(NULL_WIN);
|
|
|
|
add_buttons();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::read_mask(const char* name, int mode, int num)
|
|
|
|
{
|
|
|
|
clock1 = clock();
|
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
_source_file = name;
|
|
|
|
_source_file.ext(MASK_EXT);
|
|
|
|
TScanner scanner(_source_file);
|
|
|
|
|
1994-10-11 17:36:33 +00:00
|
|
|
_sheetmask = num > 0;
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
while (scanner.ok())
|
|
|
|
if (scanner.line() == "ENDMASK") break;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_mask(mode);
|
|
|
|
|
|
|
|
const CURSOR old = get_cursor(TASK_WIN);
|
|
|
|
set_cursor(TASK_WIN, CURSOR_WAIT);
|
|
|
|
|
|
|
|
while (scanner.ok() && scanner.popkey() != "EN")
|
|
|
|
{
|
|
|
|
if (scanner.key() == "PA")
|
|
|
|
{
|
|
|
|
CHECKD(_pages < MAX_PAGES, "Maschera con troppe pagine: ", _pages);
|
|
|
|
_pagewin[_pages++] = read_page(scanner, FALSE);
|
|
|
|
} else
|
|
|
|
if (scanner.key() == "TO")
|
|
|
|
{
|
|
|
|
CHECK(toolwin() == NULL_WIN, "La maschera puo' avere una sola TOOLBAR");
|
|
|
|
_pagewin[MAX_PAGES] = read_page(scanner, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_cursor(TASK_WIN, old);
|
|
|
|
|
|
|
|
if (_pages < 1)
|
|
|
|
fatal_box("Impossibile leggere la maschera %s", name);
|
|
|
|
|
|
|
|
add_buttons();
|
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
clock1 = clock()-clock1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::add_buttons()
|
|
|
|
{
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int p = 0; p < _pages; p++)
|
|
|
|
{
|
|
|
|
if (_pages > 1)
|
|
|
|
{
|
|
|
|
const byte flag = (p < _pages-1 ? 0x1 : 0x0) | (p > 0 ? 0x2 : 0x0);
|
|
|
|
xvt_create_control(WC_PUSHBUTTON, 0,0,1,1, "",
|
|
|
|
_pagewin[p], flag, 0, DLG_PAGE);
|
|
|
|
}
|
|
|
|
if (toolwin())
|
|
|
|
xvt_create_control(WC_PUSHBUTTON, 0,0,0,1, "",
|
|
|
|
_pagewin[p], p, _pages, DLG_PAGETAGS);
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
#else
|
1994-08-19 10:43:57 +00:00
|
|
|
if (toolwin())
|
|
|
|
{
|
|
|
|
TString80 t;
|
|
|
|
for (int p = 0; p < _pages; p++)
|
|
|
|
t << ' ' << p+1;
|
|
|
|
t << ' ';
|
|
|
|
for (p = 0; p < _pages; p++)
|
|
|
|
{
|
|
|
|
const int k = p*2;
|
|
|
|
t[k] = '['; t[k+2] = ']';
|
|
|
|
RCT r; set_rect(&r, 0, 0, t.size()*CHARX, CHARY);
|
|
|
|
create_control(WC_TEXT, &r, t, _pagewin[p], 0, 0, DLG_NULL);
|
|
|
|
t[k] = ' ';
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMask::TMask(const char* maskname, int mode, int num)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (maskname && *maskname)
|
|
|
|
read_mask(maskname, mode, num);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMask::~TMask()
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int p = 0; p <= MAX_PAGES; p++)
|
|
|
|
if (_pagewin[p])
|
|
|
|
{
|
|
|
|
close_window(_pagewin[p]);
|
|
|
|
_pagewin[p] = NULL_WIN;
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::open()
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
set_mask_fields();
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
_focus = first_focus(0);
|
|
|
|
if (toolwin() && _focus < 1)
|
|
|
|
_focus = find_first_field(_pagewin[0], +1);
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
if (!_open || _page != 0)
|
|
|
|
{
|
|
|
|
_open = TRUE;
|
1994-10-13 08:04:42 +00:00
|
|
|
if (toolwin())
|
|
|
|
show_window(toolwin(), TRUE);
|
1994-08-19 10:43:57 +00:00
|
|
|
next_page(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_focus();
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMask::first_focus(short id)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
static int tempfirstfocus = 0;
|
|
|
|
|
|
|
|
int f = _first_focus;
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
if (tempfirstfocus)
|
|
|
|
{
|
|
|
|
f = tempfirstfocus;
|
|
|
|
fld(f).set_dirty();
|
|
|
|
}
|
|
|
|
tempfirstfocus = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (id > 0) _first_focus = id2pos(id);
|
|
|
|
else tempfirstfocus = id2pos(-id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
1994-09-13 16:43:52 +00:00
|
|
|
bool TMask::can_be_closed() const
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
if (!query_mode() && is_running() && dirty())
|
|
|
|
ok = yesno_box("Annullare i dati inseriti?");
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
void TMask::close()
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
_open = FALSE;
|
|
|
|
_page = -1;
|
|
|
|
for (int p = 0; p <= MAX_PAGES; p++)
|
|
|
|
if (_pagewin[p]) show_window(_pagewin[p], FALSE);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set_mask_fields() const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
const word id = f.class_id();
|
|
|
|
if (id != CLASS_FIELD && id != CLASS_BUTTON_FIELD)
|
|
|
|
f.set_window_data(f.get_field_data());
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short TMask::dirty() const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
const TMask_field& f = fld(i);
|
|
|
|
const word id = f.class_id();
|
|
|
|
if (f.dirty() && id != CLASS_FIELD && id != CLASS_BUTTON_FIELD && f.active())
|
|
|
|
return f.dlg();
|
|
|
|
}
|
|
|
|
return 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::load_checks() const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (f.has_check())
|
|
|
|
f.check(STARTING_CHECK);
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::enable_page(int page, bool on)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
int first = (page >= 0) ? page : 1;
|
|
|
|
int last = (page >= 0) ? page+1 : _pages;
|
|
|
|
|
|
|
|
for (int p = first; p < last; p++)
|
|
|
|
{
|
|
|
|
const word n = 1 << p;
|
|
|
|
if (on) _enabled |= n;
|
|
|
|
else _enabled &= ~n;
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::page_enabled(int page) const
|
|
|
|
{
|
1994-10-11 17:36:33 +00:00
|
|
|
const unsigned long n = 1 << page;
|
1994-08-12 10:52:49 +00:00
|
|
|
return (_enabled & n) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::start_run()
|
|
|
|
{
|
|
|
|
clock2 = clock();
|
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
load_checks();
|
|
|
|
|
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
1994-09-08 14:26:39 +00:00
|
|
|
if ((f.active() || f.ghost()) &&
|
1994-11-03 12:46:49 +00:00
|
|
|
f.class_id() != CLASS_BUTTON_FIELD && f.dirty() != 3)
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
f.set_dirty(FALSE);
|
|
|
|
f.on_hit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that "nearly" all fields are clean!
|
|
|
|
for (i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (mode() == MODE_QUERY && f.is_edit() && f.in_key(1) &&
|
1994-11-03 12:46:49 +00:00
|
|
|
!f.automagic() && !f.get().empty() || f.dirty() == 3)
|
1994-08-19 10:43:57 +00:00
|
|
|
f.set_dirty(TRUE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.set_dirty(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
clock2 = clock() - clock2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::check_fields()
|
|
|
|
{
|
1994-09-16 16:59:05 +00:00
|
|
|
WINDOW curpage = NULL_WIN; // Page under test
|
1994-10-11 17:36:33 +00:00
|
|
|
|
|
|
|
const bool sheet = is_sheetmask() && !is_open();
|
1994-09-16 16:59:05 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
1994-09-16 16:59:05 +00:00
|
|
|
if (!f.active()) continue; // Don't test inactive fields
|
|
|
|
if (f.parent() != curpage)
|
|
|
|
{
|
|
|
|
const int pa = find_parent_page(f);
|
|
|
|
if (!page_enabled(pa))
|
|
|
|
break; // Page disabled: end of test
|
|
|
|
curpage = f.parent(); // Update current page
|
|
|
|
}
|
1994-10-11 17:36:33 +00:00
|
|
|
|
|
|
|
if (sheet) f.set_dirty(); // Force check in sheets
|
|
|
|
|
1994-09-16 16:59:05 +00:00
|
|
|
if (f.on_key(K_ENTER) == FALSE)
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
if (is_open()) f.set_focus();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::get_mask_fields()
|
|
|
|
{
|
1994-11-03 16:22:03 +00:00
|
|
|
TString256 window_data;
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
1994-11-08 12:48:41 +00:00
|
|
|
|
|
|
|
const int classe = f.class_id();
|
|
|
|
if (classe != CLASS_FIELD && classe != CLASS_BUTTON_FIELD && classe != CLASS_SHEET_FIELD)
|
1994-11-03 16:22:03 +00:00
|
|
|
{
|
|
|
|
window_data = f.get_window_data();
|
|
|
|
if (f.dirty() == TRUE)
|
1994-11-08 12:48:41 +00:00
|
|
|
{
|
|
|
|
const char* fd = f.get_field_data();
|
|
|
|
CHECK(fd, "NULL pointer comparison");
|
|
|
|
if (window_data != fd)
|
|
|
|
f.set_dirty(window_data != fd);
|
|
|
|
}
|
1994-11-03 16:22:03 +00:00
|
|
|
f.set_field_data(window_data);
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TMask::id2pos(short id) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int MAX_FIELDS = 128;
|
|
|
|
static byte positions[MAX_FIELDS]; // 100 <= id < MAX_FIELDS
|
|
|
|
const int max = fields();
|
|
|
|
|
|
|
|
const int j = id-100;
|
|
|
|
int pos = -1;
|
|
|
|
if (j >= 0 && j < MAX_FIELDS) // Try using cache
|
|
|
|
{
|
|
|
|
pos = positions[j];
|
|
|
|
if (pos >= 0 && pos < max)
|
|
|
|
{
|
|
|
|
const TMask_field& f = fld(pos);
|
|
|
|
if (f.dlg() == id) // Mask could have been changed!
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-10-11 17:36:33 +00:00
|
|
|
for (pos = 0; pos < max; pos++) // Standard linear search
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
const TMask_field& f = fld(pos);
|
|
|
|
if (f.dlg() == id)
|
|
|
|
{
|
1994-10-11 17:36:33 +00:00
|
|
|
if (j >= 0 && j < MAX_FIELDS) // Store position for the next time
|
1994-08-19 10:43:57 +00:00
|
|
|
positions[j] = pos;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1; // Not found!
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMask_field& TMask::field(short id) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
int pos = id2pos(id);
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
#ifdef DBG
|
|
|
|
if (pos < 0)
|
|
|
|
{
|
|
|
|
yesnofatal_box("Il campo %d non esiste", id);
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return fld(pos);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
1994-09-13 16:43:52 +00:00
|
|
|
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;
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
|
|
|
|
int TMask::find_field_win(WINDOW win) const
|
|
|
|
{
|
1994-09-13 16:43:52 +00:00
|
|
|
if (fld(_focus).win() == win)
|
|
|
|
return _focus;
|
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
if (fld(i).win() == win) return i;
|
1994-09-13 16:43:52 +00:00
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
#ifdef DBG
|
1994-08-19 10:43:57 +00:00
|
|
|
yesnofatal_box("Can't find the field given the child window");
|
|
|
|
#endif
|
|
|
|
return 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::set_focus_win(WINDOW win, bool force)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
_focus = find_field_win(win);
|
|
|
|
if (force) set_focus();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMask::find_parent_page(const TMask_field& f) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const WINDOW pw = f.parent();
|
|
|
|
for (int p = 0; p < _pages; p++)
|
|
|
|
if (pw == _pagewin[p]) return p;
|
|
|
|
return MAX_PAGES; // Toolbar button
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMask::find_active_field(int first, int dir) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int max = fields()-1;
|
|
|
|
WINDOW w, old = fld(_focus).parent();
|
|
|
|
|
|
|
|
for (int i = first; ; i += dir)
|
|
|
|
{
|
|
|
|
if (i > max) i = 0;
|
|
|
|
else if (i < 0) i = max;
|
1994-09-08 16:24:10 +00:00
|
|
|
if (fld(i).active() && page_enabled(find_parent_page(fld(i))))
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
w = fld(i).parent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w != old)
|
|
|
|
{
|
|
|
|
int p = _page;
|
|
|
|
if (old == toolwin())
|
|
|
|
{
|
|
|
|
if (dir > 0)
|
|
|
|
{ if (++p >= _pages) p = 0; }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dir < 0)
|
|
|
|
{ if (--p < 0) p = _pages-1; }
|
|
|
|
else p = MAX_PAGES;
|
|
|
|
}
|
|
|
|
w = _pagewin[p];
|
|
|
|
i = find_first_field(w, dir);
|
|
|
|
}
|
|
|
|
return i;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set_focus()
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
_focus = find_active_field(_focus, +1);
|
1994-08-26 13:07:24 +00:00
|
|
|
const TMask_field& f = fld(_focus);
|
|
|
|
const int page = find_parent_page(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
if (page != _page && page != MAX_PAGES)
|
|
|
|
{
|
1994-08-26 13:07:24 +00:00
|
|
|
const WINDOW pw = win(); // previous window
|
|
|
|
_page = page; // update page number
|
|
|
|
show_window(win(), TRUE); // show new page
|
1994-08-19 10:43:57 +00:00
|
|
|
if (pw) show_window(pw, FALSE); // hide old page
|
|
|
|
}
|
1994-08-26 13:07:24 +00:00
|
|
|
|
|
|
|
set_front_window(f.win());
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Move the focus to the next (+1) or previous(-1) valid control
|
|
|
|
void TMask::move_focus_field(int d)
|
|
|
|
{
|
1994-09-01 16:30:57 +00:00
|
|
|
if (!test_focus_change())
|
1994-08-19 10:43:57 +00:00
|
|
|
return;
|
1994-09-01 16:30:57 +00:00
|
|
|
|
|
|
|
TMask_field& f = fld(_focus);
|
1994-08-19 10:43:57 +00:00
|
|
|
if (f.class_id() == CLASS_RADIO_FIELD)
|
|
|
|
{
|
|
|
|
TRadio_field& radio = (TRadio_field&)f;
|
|
|
|
moving_focus = TRUE;
|
|
|
|
bool cont = radio.move_focus(d);
|
|
|
|
moving_focus = FALSE;
|
|
|
|
if (!cont) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int focus = find_active_field(_focus+d, d);
|
|
|
|
if (fld(focus).parent() == f.parent() || check_current_page())
|
|
|
|
_focus = focus;
|
|
|
|
|
|
|
|
set_focus();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::stop_run(KEY key)
|
|
|
|
{
|
1994-08-26 13:07:24 +00:00
|
|
|
if (key != K_AUTO_ENTER && key != K_FORCE_CLOSE)
|
1994-08-23 13:52:36 +00:00
|
|
|
{
|
|
|
|
const int last = fields();
|
|
|
|
bool found = FALSE;
|
|
|
|
for (int i = 0; i < last; i++)
|
|
|
|
{
|
|
|
|
const TMask_field& f = fld(i);
|
|
|
|
if (f.class_id() != CLASS_BUTTON_FIELD) continue;
|
|
|
|
const TButton_field& b = (const TButton_field&)f;
|
|
|
|
if (b.exit_key() == key)
|
|
|
|
{
|
|
|
|
if (b.active())
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
#ifdef DBG
|
|
|
|
return error_box("Non e' attivo il bottone associato a %d", key);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
1994-08-26 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
1994-08-26 16:59:18 +00:00
|
|
|
if (key == K_CTRL_ENTER || key == K_AUTO_ENTER) key = K_ENTER; else
|
1994-08-26 13:07:24 +00:00
|
|
|
if (key == K_FORCE_CLOSE) key = K_QUIT;
|
1994-08-23 13:52:36 +00:00
|
|
|
|
1994-10-14 17:59:12 +00:00
|
|
|
if (key != K_ESC && key != K_QUIT && key != K_DEL && key != K_F9)
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
const bool ok = check_fields();
|
|
|
|
if (!ok) return FALSE;
|
|
|
|
}
|
1994-10-03 08:47:32 +00:00
|
|
|
if (is_running()) // Gestisce correttamenete le maschere chiuse
|
|
|
|
get_mask_fields();
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
return TWindow::stop_run(key);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::on_key(KEY key)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (_handler)
|
|
|
|
{
|
|
|
|
bool cont = _handler(*this, key);
|
|
|
|
if (!cont) return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(key)
|
1994-08-23 13:52:36 +00:00
|
|
|
{
|
|
|
|
case K_AUTO_ENTER:
|
|
|
|
case K_CTRL_ENTER:
|
1994-08-19 10:43:57 +00:00
|
|
|
case K_QUIT:
|
|
|
|
case K_ESC:
|
|
|
|
stop_run(key);
|
|
|
|
break;
|
|
|
|
case K_UP:
|
|
|
|
case K_BTAB:
|
|
|
|
case K_SHIFT_TAB:
|
|
|
|
case K_LEFT:
|
|
|
|
move_focus_field(-1);
|
|
|
|
break;
|
|
|
|
case K_DOWN:
|
|
|
|
case K_TAB:
|
|
|
|
case K_RIGHT:
|
|
|
|
case K_ENTER:
|
|
|
|
move_focus_field(+1);
|
|
|
|
break;
|
|
|
|
case K_PREV:
|
|
|
|
next_page(-1);
|
|
|
|
break;
|
|
|
|
case K_NEXT:
|
|
|
|
next_page(+1);
|
|
|
|
break;
|
|
|
|
case K_F11:
|
|
|
|
message_box("Siete fortunati utenti del campo %d della maschera '%s'\n"
|
1994-08-23 13:52:36 +00:00
|
|
|
"caricata nell'incredibile tempo di %ld millisecondi\n"
|
|
|
|
"ed inizializzata mostruosamente in %ld millisecondi\n"
|
|
|
|
"Grazie per la comprensione",
|
1994-08-19 10:43:57 +00:00
|
|
|
fld(_focus).dlg(), (const char*)source_file(), clock1, clock2);
|
1994-10-14 19:15:23 +00:00
|
|
|
set_focus();
|
1994-08-19 10:43:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
1994-08-23 13:52:36 +00:00
|
|
|
if (key > K_CTRL)
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
1994-08-23 13:52:36 +00:00
|
|
|
key -= K_CTRL;
|
1994-08-26 13:07:24 +00:00
|
|
|
if (key >= K_F1 && key <= K_F12)
|
1994-08-23 13:52:36 +00:00
|
|
|
next_page(1000 + key - K_F1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int last = fields();
|
|
|
|
for (int i = 0; i < last; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (f.class_id() != CLASS_BUTTON_FIELD || !f.active()) continue;
|
|
|
|
TButton_field& b = (TButton_field&)f;
|
1994-09-01 16:30:57 +00:00
|
|
|
if (b.virtual_key() == key && test_focus_change())
|
1994-08-23 13:52:36 +00:00
|
|
|
{
|
|
|
|
f.on_key(K_SPACE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
else return fld(_focus).on_key(key);
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMask_field* TMask::parse_field(TScanner& scanner)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (scanner.key() == "ST") return new TEdit_field(this);
|
|
|
|
if (scanner.key() == "NU") return new TReal_field(this);
|
|
|
|
if (scanner.key() == "DA") return new TDate_field(this);
|
|
|
|
if (scanner.key() == "BO") return new TBoolean_field(this);
|
|
|
|
if (scanner.key() == "LI") return new TList_field(this);
|
|
|
|
if (scanner.key() == "BU") return new TButton_field(this);
|
|
|
|
if (scanner.key() == "TE") return new TMask_field(this);
|
|
|
|
if (scanner.key() == "RA") return new TRadio_field(this);
|
|
|
|
if (scanner.key() == "GR") return new TGroup_field(this);
|
|
|
|
if (scanner.key() == "SP")
|
|
|
|
{
|
|
|
|
_sheets++;
|
|
|
|
return new TSheet_field(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WINDOW TMask::read_page(TScanner& scanner, bool toolbar)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
static int tooly;
|
|
|
|
static RCT rect;
|
|
|
|
|
|
|
|
TString80 title(scanner.string());
|
|
|
|
|
|
|
|
RCT r;
|
|
|
|
if (toolwin())
|
|
|
|
{
|
|
|
|
scanner.line();
|
|
|
|
set_rect(&r, 0, 0, 0, tooly);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scanner.rectangle(r);
|
|
|
|
if (toolbar)
|
1994-10-25 16:00:06 +00:00
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
tooly = r.top;
|
1994-10-25 16:00:06 +00:00
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_pages == 0) rect = r;
|
|
|
|
else r = rect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WINDOW w;
|
|
|
|
|
|
|
|
if (toolbar || toolwin())
|
|
|
|
{
|
|
|
|
w = create(0, r.top, 0, r.bottom,
|
|
|
|
title, toolbar ? 0 : WSF_INVISIBLE, W_PLAIN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = create(r.left, r.top, r.right, r.bottom,
|
1994-10-14 19:15:23 +00:00
|
|
|
title, WSF_CLOSE | WSF_INVISIBLE, WD_MODAL);
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (scanner.popkey() != "EN")
|
|
|
|
{
|
|
|
|
TMask_field* f = parse_field(scanner);
|
1994-10-25 16:00:06 +00:00
|
|
|
CHECK(f, "Can't create a control");
|
|
|
|
f->construct(scanner, w);
|
|
|
|
_field.add(f);
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_win(NULL_WIN);
|
|
|
|
return w;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TMask::find_first_field(WINDOW w, int dir) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int last = fields()-1;
|
|
|
|
const int fi = (dir > 0) ? 0 : last;
|
|
|
|
const int la = last-fi;
|
|
|
|
for (int i = fi; i != la; i += dir)
|
|
|
|
{
|
|
|
|
const TMask_field& f = fld(i);
|
|
|
|
if (f.parent() == w && f.active()) break;
|
|
|
|
}
|
|
|
|
return i;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TMask::check_current_page()
|
|
|
|
{
|
1994-10-18 08:16:53 +00:00
|
|
|
if (!test_focus_change())
|
|
|
|
return FALSE;
|
1994-10-03 08:47:32 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
if (sheets() > 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
const int last = fields();
|
|
|
|
const WINDOW page = win();
|
|
|
|
|
|
|
|
for (int i = 0; i < last; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (f.parent() == page && f.active() && f.on_key(K_ENTER) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*/
|
1994-08-19 10:43:57 +00:00
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::next_page(int p)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
const int prev = _page; // Previous page
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
if (p != 0)
|
|
|
|
{
|
|
|
|
if (check_current_page() == FALSE) // New style
|
|
|
|
return;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
const int k = (p < 1000) ? _page+p : p-1000;
|
|
|
|
if (k < 0 || k >= _pages || !page_enabled(k))
|
|
|
|
{
|
|
|
|
beep();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_page = k;
|
|
|
|
} else _page = 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
const WINDOW w = win(); // Current page window
|
|
|
|
if (_page != prev)
|
|
|
|
{
|
|
|
|
show_window(w, TRUE);
|
|
|
|
if (prev >= 0)
|
|
|
|
{
|
|
|
|
show_window(_pagewin[prev], FALSE);
|
|
|
|
_focus = find_first_field(w, +1);
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
set_focus();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::reset(short fld_id)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
|
|
|
for (int f = 0; f < fields(); f++)
|
|
|
|
{
|
|
|
|
TMask_field& c = fld(f);
|
|
|
|
c.reset();
|
|
|
|
c.set_dirty(FALSE);
|
|
|
|
}
|
|
|
|
} else field(fld_id).reset();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::undo(short fld_id)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
|
|
|
for (int f = 0; f < fields(); f++)
|
|
|
|
fld(f).undo();
|
1994-08-12 10:52:49 +00:00
|
|
|
} else field(fld_id).undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const TString& TMask::get(short fld_id) const
|
|
|
|
{
|
|
|
|
return field(fld_id).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
long TMask::get_long(short fld_id) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
return atol(field(fld_id).get());
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::get_bool(short fld_id) const
|
|
|
|
{
|
|
|
|
return field(fld_id).get().not_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set(short fld_id, const char* s, bool hit)
|
|
|
|
{
|
|
|
|
TMask_field& f = field(fld_id);
|
1994-08-19 10:43:57 +00:00
|
|
|
f.set(s);
|
1994-09-01 16:30:57 +00:00
|
|
|
if (hit && (f.active() || f.ghost()))
|
|
|
|
f.on_key(K_TAB);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set(short fld_id, long n, bool hit)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
char s[16];
|
|
|
|
sprintf(s, "%ld", n);
|
|
|
|
set(fld_id, s, hit);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::enable(bool on) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
TWindow::enable(on);
|
|
|
|
if (toolwin() != NULL_WIN)
|
|
|
|
show_window(toolwin(), on);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::enable(short fld_id, bool on)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (f.dlg() > 100) fld(i).enable(on);
|
|
|
|
}
|
|
|
|
} else field(fld_id).enable(on);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::enable_default(short fld_id)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
fld(i).enable_default();
|
|
|
|
} else field(fld_id).enable_default();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte TMask::num_keys() const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
word max = 0;
|
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
{
|
|
|
|
word k = fld(i).last_key();
|
|
|
|
if (k > max) max = k;
|
|
|
|
}
|
|
|
|
return max;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::enable_key(byte key, bool on)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
if (fld(i).in_key(key))
|
|
|
|
{
|
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
fld(i).enable_default();
|
|
|
|
if (!fld(i).showed())
|
|
|
|
fld(i).show_default();
|
|
|
|
}
|
|
|
|
else fld(i).disable();
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
short TMask::get_key_field(byte key, bool first) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
static int last = 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
if (first) last = 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = last; i < fields(); i++)
|
|
|
|
{
|
|
|
|
if (fld(i).in_key(key))
|
|
|
|
{
|
|
|
|
last = i+1;
|
|
|
|
return fld(i).dlg();
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
return -1;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::key_valid(int key) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (short f = 0; f < fields(); f++)
|
|
|
|
{
|
|
|
|
TMask_field& c = fld(f);
|
|
|
|
if (c.in_key(key) && c.required())
|
|
|
|
{
|
1994-10-19 11:44:59 +00:00
|
|
|
const TString & value = c.get();
|
1994-08-19 10:43:57 +00:00
|
|
|
if (c.class_id() == CLASS_REAL_FIELD)
|
|
|
|
{
|
|
|
|
real z(value);
|
|
|
|
if (z.is_zero())
|
|
|
|
{
|
|
|
|
c.reset();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value.empty())
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::show(short fld_id, bool on)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
fld(i).show(on);
|
|
|
|
} else field(fld_id).show(on);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::show_default(short fld_id)
|
|
|
|
{
|
|
|
|
if (fld_id < 1)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
fld(i).show_default();
|
|
|
|
} else field(fld_id).show_default();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::autoload(const TRelation* r)
|
|
|
|
{
|
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
if (f.field())
|
|
|
|
f.autoload(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TMask::autosave(TRelation* r) const
|
|
|
|
{
|
|
|
|
const int max = fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
const TFieldref* fr =f.field();
|
|
|
|
if (fr)
|
|
|
|
{
|
|
|
|
if (f.showed() || *fr->read(r) == '\0')
|
|
|
|
f.autosave(r);
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::send_key(KEY key, short to) const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
if (to == 0)
|
|
|
|
{
|
|
|
|
dispatch_e_char(win(), key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to > 0)
|
|
|
|
{
|
|
|
|
const int pos = id2pos(to);
|
|
|
|
if (pos >= 0)
|
|
|
|
fld(pos).on_key(key);
|
1994-08-12 10:52:49 +00:00
|
|
|
#ifdef DBG
|
1994-08-19 10:43:57 +00:00
|
|
|
else
|
1994-08-29 11:22:14 +00:00
|
|
|
if (mode() != MODE_SEARCH)
|
|
|
|
yesnofatal_box("Can't send key %u to field %d", key, to);
|
1994-08-12 10:52:49 +00:00
|
|
|
#endif
|
1994-08-19 10:43:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1994-10-11 17:36:33 +00:00
|
|
|
const int max = fields();
|
1994-08-19 10:43:57 +00:00
|
|
|
to = -to;
|
1994-10-11 17:36:33 +00:00
|
|
|
for (int i = 0; i < max; i++)
|
1994-08-19 10:43:57 +00:00
|
|
|
{
|
|
|
|
TMask_field& campo = fld(i);
|
|
|
|
if (campo.in_group((int)to))
|
|
|
|
campo.on_key(key);
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set_handler(short fld_id, CONTROL_HANDLER handler)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
field(fld_id).set_handler(handler);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set_handler(MASK_HANDLER handler)
|
|
|
|
{
|
|
|
|
_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aggiunta campi a runclock
|
|
|
|
|
|
|
|
void TMask::add_static (short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, const char* flags)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
TMask_field* f = new TMask_field(this);
|
1994-08-19 10:43:57 +00:00
|
|
|
f->construct(id, prompt, x, y, strlen(prompt), _pagewin[page], flags);
|
1994-08-12 10:52:49 +00:00
|
|
|
_field.add(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::add_string (short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, int dim, const char* flags, int width)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
TEdit_field* f = new TEdit_field(this);
|
1994-08-19 10:43:57 +00:00
|
|
|
f->construct(id, prompt, x, y, dim, _pagewin[page], flags, width);
|
|
|
|
_field.add(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::add_number (short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, int dim, const char* flags, int ndec)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
TReal_field* f = new TReal_field(this);
|
1994-08-19 10:43:57 +00:00
|
|
|
f->construct(id, prompt, x, y, dim, _pagewin[page], flags, ndec);
|
1994-08-12 10:52:49 +00:00
|
|
|
_field.add(f);
|
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
void TMask::add_date (short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, const char* flags)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
TDate_field* f = new TDate_field(this);
|
1994-08-19 10:43:57 +00:00
|
|
|
f->construct(id, prompt, x, y, 10, _pagewin[page], flags);
|
|
|
|
_field.add(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::add_button (short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, int dx, int dy, const char* flags)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
TButton_field* f = new TButton_field(this);
|
|
|
|
f->construct(id, prompt, x, y, dy, _pagewin[page], flags, dx);
|
|
|
|
_field.add(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::add_radio(short id, int page, const char* prompt, int x,
|
1994-08-19 10:43:57 +00:00
|
|
|
int y, int dx, const char* codes, const char* items, const char* flags)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
TRadio_field* f = new TRadio_field(this);
|
|
|
|
f->replace_items(codes, items);
|
|
|
|
f->construct(id, prompt, x, y, dx, _pagewin[page], flags, dx);
|
|
|
|
_field.add(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TMask::save(bool append) const
|
|
|
|
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
FILE* f = fopen((const char *) _workfile, append ? "a" : "w");
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
if (f == NULL)
|
|
|
|
return yesnofatal_box("Non posso aprire %s ", (const char*) _workfile);
|
1994-08-12 10:52:49 +00:00
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
|
|
|
{
|
|
|
|
const short id = fld(i).dlg();
|
|
|
|
if (id >= 100)
|
|
|
|
fprintf(f, "%d|%s\n", id, (const char*) fld(i).get());
|
|
|
|
}
|
|
|
|
fprintf(f, "[EOM]\n");
|
|
|
|
fclose(f);
|
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TMask::load(bool reset)
|
|
|
|
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
FILE* f = fopen((const char *) _workfile, "r");
|
|
|
|
|
|
|
|
if (f == NULL) return FALSE;
|
|
|
|
if (reset) _lastpos = 0;
|
|
|
|
fseek(f, _lastpos, SEEK_SET);
|
|
|
|
TToken_string t(256);
|
|
|
|
char s[256];
|
|
|
|
while (fgets(s, 255, f) != NULL && strncmp(s, "[EOM]", 5) != 0)
|
|
|
|
{
|
|
|
|
if (*s) s[strlen(s) - 1] = '\0';
|
|
|
|
t = s;
|
|
|
|
const short id = t.get_int();
|
|
|
|
if (id >= 100)
|
|
|
|
{
|
|
|
|
const int pos = id2pos(id);
|
|
|
|
if (pos >= 0) fld(pos).set(t.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_lastpos = ftell(f);
|
|
|
|
fclose(f);
|
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* TMask::get_caption() const
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
char* title = &__tmp_string[512];
|
|
|
|
get_title(_pagewin[0], title, 80);
|
|
|
|
return title;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMask::set_caption(const char* c)
|
|
|
|
{
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int p = 0; p < _pages; p++)
|
|
|
|
set_title(_pagewin[p], (char*)c);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-11-07 13:51:11 +00:00
|
|
|
void TMask::set_exchange(bool show_value, const real& n)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
1994-11-07 13:51:11 +00:00
|
|
|
const real nuo = (n.sign() <= 0) ? _exchange : n;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
|
|
|
const CURSOR oldcur = get_cursor(TASK_WIN); // Store current cursor
|
|
|
|
set_cursor(TASK_WIN, CURSOR_WAIT);
|
|
|
|
|
1994-08-19 10:43:57 +00:00
|
|
|
for (int i = 0; i < fields(); i++)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
TMask_field& f = fld(i);
|
|
|
|
const word id = f.class_id();
|
1994-11-07 13:51:11 +00:00
|
|
|
if (id == CLASS_SHEET_FIELD || id == CLASS_REAL_FIELD && f.exchangeable())
|
|
|
|
f.exchange(show_value, nuo);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
1994-08-19 10:43:57 +00:00
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
_exchange = nuo; // Update current exchange
|
|
|
|
|
|
|
|
set_cursor(TASK_WIN, oldcur); // Restore cursor
|
|
|
|
}
|