Patch level : nopatch

Files correlati     :
Commento        :

Aggiunto il salvataggio dei valori di un maschera (Alt-S) e il caricamento (Alt-L)
This commit is contained in:
Alessandro Bonazzi 2021-12-13 12:51:17 +01:00
parent 2cd18cbacd
commit eb0249c3c9
2 changed files with 133 additions and 107 deletions

View File

@ -680,7 +680,7 @@ int TMask::id2pos(
TMask_field& TMask::field(short id) const
{
TMask_field* f = find_by_id(id);
if (f == NULL)
if (f == nullptr)
{
if (_mask_num == 0)
yesnofatal_box("Non esiste il campo %d sulla maschera %s", id, (const char*)_source_file);
@ -1042,114 +1042,134 @@ bool TMask::on_key(
return false;
}
switch(key)
{
case K_AUTO_ENTER:
case K_CTRL_ENTER:
case K_QUIT:
case K_ESC:
stop_run(key);
break;
case K_PREV:
if (fld(_focus).on_key(K_TAB))
next_page(-1);
break;
case K_NEXT:
if (fld(_focus).on_key(K_TAB))
next_page(+1);
break;
case K_F1:
{
const char* key = source_file().name_only();
EVENT e; memset(&e, 0, sizeof(e));
e.type = E_HELP;
e.v.help.tag = M_HELP_ONCONTEXT;
e.v.help.obj = win();
e.v.help.tid = (long)key;
switch (key)
{
case K_AUTO_ENTER:
case K_CTRL_ENTER:
case K_QUIT:
case K_ESC:
stop_run(key);
break;
case K_PREV:
if (fld(_focus).on_key(K_TAB))
next_page(-1);
break;
case K_NEXT:
if (fld(_focus).on_key(K_TAB))
next_page(+1);
break;
case K_F1:
{
const char* key = source_file().name_only();
EVENT e; memset(&e, 0, sizeof(e));
e.type = E_HELP;
e.v.help.tag = M_HELP_ONCONTEXT;
e.v.help.obj = win();
e.v.help.tid = (long)key;
TFilename n = "campo";
TString4 module; module.strncpy(key, 2); module.lower();
if (module != "ba")
n.insert(module);
FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(n, &fs);
XVT_HELP_INFO hi = xvt_help_open_helpfile(&fs, 0);
xvt_help_process_event(hi, win(), &e);
}
break;
case K_F12:
TFilename n = "campo";
TString4 module; module.strncpy(key, 2); module.lower();
if (module != "ba")
n.insert(module);
FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(n, &fs);
XVT_HELP_INFO hi = xvt_help_open_helpfile(&fs, 0);
xvt_help_process_event(hi, win(), &e);
}
break;
case K_F12:
send_key(K_F12, focus_field().dlg());
break;
case K_SHIFT+K_F11:
break;
case K_SHIFT + K_F11:
if (is_power_station())
{
_bShowGrid = !_bShowGrid;
xvt_dwin_invalidate_rect(curr_win(), NULL);
}
break;
case K_CTRL+'+':
if (is_running())
{
// Cerco nella pagina corrente il primo spreadsheet a partire dal campo col focus
if (_focus < 0) _focus = 0;
const WINDOW myparent = fld(_focus).parent();
for (int fire = _focus; fire < fields(); fire++)
{
TMask_field& f = fld(fire);
if (f.parent() != myparent)
break;
if (f.is_sheet())
{
{
_bShowGrid = !_bShowGrid;
xvt_dwin_invalidate_rect(curr_win(), NULL);
}
break;
case K_CTRL + '+':
if (is_running())
{
// Cerco nella pagina corrente il primo spreadsheet a partire dal campo col focus
if (_focus < 0) _focus = 0;
const WINDOW myparent = fld(_focus).parent();
for (int fire = _focus; fire < fields(); fire++)
{
TMask_field& f = fld(fire);
if (f.parent() != myparent)
break;
if (f.is_sheet())
{
send_key(key, f.dlg());
break;
}
}
}
break;
/*
case K_CTRL+'-':
if (is_running() && focus_field().is_sheet())
send_key(key, focus_field().dlg());
break;
*/
default:
if (key > K_CTRL)
{
key -= K_CTRL;
if (key >= K_F1 && key <= K_F12)
{
const int page = key - K_F1;
if (page < _pages && fld(_focus).on_key(K_TAB))
show_page(page);
}
else
{
for (int i = fields()-1; i >= 0; i--)
{
TMask_field& f = fld(i);
if (f.is_operable() && !f.is_editable() && f.active())
{
KEY vk = 0;
if (f.is_kind_of(CLASS_BUTTON_FIELD))
{
TButton_field& b = (TButton_field&)f;
vk = b.virtual_key();
} else
if (f.is_kind_of(CLASS_BUTTON_TOOL))
{
TButton_tool& t = (TButton_tool&)f;
vk = t.virtual_key();
}
if (vk > 0 && vk == key)
{
f.on_key(K_SPACE);
break;
}
}
}
}
}
}
}
}
}
break;
/*
case K_CTRL+'-':
if (is_running() && focus_field().is_sheet())
send_key(key, focus_field().dlg());
break;
*/
default:
if (key > K_CTRL)
{
key -= K_CTRL;
if (key >= K_F1 && key <= K_F12)
{
const int page = key - K_F1;
if (page < _pages && fld(_focus).on_key(K_TAB))
show_page(page);
}
else
if (UPCASE(key) == 'S')
{
TFilename fname;
if (fname.input(false))
save(fname);
}
else
if (UPCASE(key) == 'L')
{
TFilename fname;
if (fname.input())
load(fname);
}
else
{
for (int i = fields() - 1; i >= 0; i--)
{
TMask_field& f = fld(i);
if (f.is_operable() && !f.is_editable() && f.active())
{
KEY vk = 0;
if (f.is_kind_of(CLASS_BUTTON_FIELD))
{
TButton_field& b = (TButton_field&)f;
vk = b.virtual_key();
}
else
if (f.is_kind_of(CLASS_BUTTON_TOOL))
{
TButton_tool& t = (TButton_tool&)f;
vk = t.virtual_key();
}
if (vk > 0 && vk == key)
{
f.on_key(K_SPACE);
break;
}
}
}
}
}
}
return true;
}
@ -2511,11 +2531,14 @@ TButton_tool& TMask::add_button_tool(short id, const char* prompt, short bmpup)
//
// @flag true | Se l'operazione e' avvenuta corretamente
// @flag false | Se non si riesce a creare il file di salvataggio
bool TMask::save(
bool TMask::save(const TFilename & fname, // @parm nome del file, se vuoto usa _workfile
bool append) const // @parm Indica se creare il file o appendere (true) le informazioni
// ad uno gia' esistente (false, default).
{
if (fname.full())
((TMask *)this)->set_workfile(fname);
FILE* f = fopen(_workfile, append ? "a" : "w");
if (f == nullptr)
@ -2542,13 +2565,16 @@ bool TMask::save(
//
// @flag true | Se l'operazione e' avvenuta corretamente
// @flag false | Se non si riesce a leggere il file di salvataggio
bool TMask::load(
bool TMask::load(const TFilename & fname, // @parm nome del file, se vuoto usa _workfile
bool reset) // @parm Indica la posizione di lettura del file:
//
// @flag true | Comincia la lettura dell'inizio
// @flag false | Comincia la lettura dalla posizione corrente dell'offset
{
if (fname.full())
((TMask *)this)->set_workfile(fname);
FILE* f = fopen(_workfile, "r");
if (f == nullptr)

View File

@ -449,9 +449,9 @@ public:
void set_workfile(const char* workfile)
{ _workfile = workfile; _lastpos = 0L;}
// @cmember Salva i valori dei campi della maschera sul file di salvataggio
bool save(bool append = false) const;
bool save(const TFilename & fname = EMPTY_STRING, bool append = false) const;
// @cmember Legge i valori dei campi della maschera da file di salvataggio
bool load(bool reset = false);
bool load(const TFilename & fname = EMPTY_STRING, bool reset = false);
// @cmember Copia i valori dei campi dalla maschera <p m>
void copy_values(const TMask &m);