campo-sirio/ba/ba0100.cpp
guy a513f935d2 Patch level : 2.0 470
Files correlati     : ba0.exe ba1.exe ba3.exe ba4.exe
Ricompilazione Demo : [ ]
Commento            :

EP20037
Esempio : Visualizzazione liquidazione, Indico: esercizio =2003, mese
liquidazione =gennaio seleziono la ditta clicco su conferma. Nella
visualizzazione la barra di scorrimento non funziona.


EP20038
Inserendo nel campo "utente" un'utente inesistente  e nel campo "password"
ad.min , entro in campo senza che venga segnalata la non esistenza dell'utente

EP20041
Col mouse seleziono un codice di pagamento già inserito e clicco sul bottone
stampa.A video (come da impostazioni stampante) viene visualizzata la stampa
della condizione di pagamento selezionata.Clicco su stampa, non parte la
stampa su carta. Clicco su fine ritorno nella maschera "stampa condizioni
di pagamento", clicco su fine errore ba3.exe

EP20049
Seleziono un codice valuta inserito con spunta su voce "contro euro"
in tabella valute; la spunta viene riportata anche nella maschera
"Cambi giornalieri". Inserisco la data di oggi nel campo data del group
box valuta e col mouse mi posizono sul campo cambio: la spunta sulla voce
"contro euro" scompare

EP20050
Clicco sul bottone di ricerca e richiamo una ditta memorizzata. Clicco sul
bottone posta errore il campo 203 non nesiste

EP20054
Ho registrato tre anagrafiche. Col mouse.Clicco sul bottone di ricerca e
richiamo la n°2. Clicco sulla freccia singola a sinistra del bottone ricerca
per posizionarmi sull'anagrafica n°1 e viene visualizzato messaggio vuoi
registrare le modifiche?(anche per altre freccie associate al bottone)

EP20055
Col mouse.Clicco su ricerca e richiamo un'anagrafica già presente.Clicco sul
bottone  Nuovo:messaggio registrare le modifiche?

EP20057
clicco sul bottone di ricerca e seleziono un utente già registrato.
I campi vengono compilati, clicco sul bottone nuovo: i campi non vengono
svuotati ma compare messaggio "vuoi registrare dati inseriti?"

EP20058
Ho inserito n utenti. Clicco sul bottone di ricerca e richiamo un utente
già registrato. Clicco sulla freccina singola a sx del botone ricerca
(e anche sulle altre freccie): messaggo "vuoi registrare dati inseriti?"

EP20064
Richiamo una ditta già inserita clicco sul bottone annulla messaggio:
"attività assente si desidera annullare?"

EP20075
Tutte le freccie associate al bottone ricerca non funzionano


git-svn-id: svn://10.65.10.50/trunk@11128 c028cbd2-c16b-5b4b-a496-9718f37d4682
2003-05-14 13:35:51 +00:00

1587 lines
38 KiB
C++
Executable File
Raw Blame History

#include <xinclude.h>
#include <applicat.h>
#include <automask.h>
#include <config.h>
#include <controls.h>
#include <dongle.h>
#include <execp.h>
#include <isam.h>
#include <msksheet.h>
#include <progind.h>
#include <recarray.h>
#include <utility.h>
#include <urldefid.h>
#include <agasys.h>
#include <nditte.h>
#include "ba0.h"
#include "ba0101.h"
#include "ba0102.h"
#include "ba0100a.h"
#include "ba0400a.h"
#define OPTIONS_MENU M_FONT
#define PREFERRED_MENU M_STYLE
#define DLG_TREE 301
#define DLG_LIST 302
#ifdef XVAGA
#define MEN_FILE "bamenu.men"
#else
#define MEN_FILE "baprassi.men"
#endif
///////////////////////////////////////////////////////////
// TMenu_application declaration
///////////////////////////////////////////////////////////
class TMenu_application : public TSkeleton_application
{
const char* _name;
TMenu _menu;
int _tree_view;
TString_array _preferred;
TMask* _mask;
static int _last_button;
static bool _find_button;
protected: // TApplication
virtual bool create();
virtual bool destroy();
virtual bool menu(MENU_TAG m);
virtual long handler(WINDOW win, EVENT* ep);
virtual bool test_assistance_year() const;
protected:
virtual void main_loop();
void test_temp();
void load_menu();
int do_level();
int do_tree();
int do_explore();
bool check_user();
static bool menu_item_handler(TMask_field& f, KEY k);
static bool menu_find_handler(TMask_field& f, KEY k);
static bool tree_handler(TMask_field& f, KEY k);
static bool explore_handler(TMask_field& f, KEY k);
void select_tree_current();
bool choose_colors();
bool choose_editors();
bool choose_study();
void load_preferences();
void save_preferences();
void update_preferred();
void add_to_preferred();
void manage_preferred();
bool test_programs();
bool test_network();
public:
static bool tree_find_handler(TMask_field& f, KEY k);
static bool tree_shrink_handler(TMask_field& f, KEY k);
public:
void reload_images();
TMenu& main_menu() { return _menu; }
TMenu_application(const char* name) : _name(name), _mask(NULL) { }
virtual ~TMenu_application() { }
};
inline TMenu_application& app()
{ return (TMenu_application&)main_app(); }
///////////////////////////////////////////////////////////
// Picture Mask
///////////////////////////////////////////////////////////
class TPicture_mask : public TMask
{
TSubmenu* _submenu;
protected: // TMask
virtual void update();
virtual bool on_key(KEY k);
virtual void on_firm_change();
public:
virtual bool stop_run(KEY key);
void set_current(const TSubmenu& sm);
TPicture_mask(const char* name, int dx, int dy, const TSubmenu& sm, int x = -1, int y = -1);
virtual ~TPicture_mask();
};
bool TPicture_mask::stop_run(KEY key)
{
if (key == K_FORCE_CLOSE)
key = K_QUIT;
return TWindow::stop_run(key);
}
void TPicture_mask::update()
{
TImage& image = _submenu->image();
if (image.ok())
{
int x = 1, y = 1, maxx = 640, maxy = 480; // Default values
RCT client; xvt_vobj_get_client_rect(win(), &client);
if (id2pos(DLG_TREE) >= 0) // TreeView == 1
{
RCT rctree; field(DLG_TREE).get_rect(rctree);
maxx = client.right - rctree.right - 12;
maxy = client.bottom - 4 * ROWY;
const double ratiox = double(maxx) / image.width();
const double ratioy = double(maxy) / image.height();
const double ratio = min(ratiox, ratioy);
maxx = int(ratio * image.width());
maxy = int(ratio * image.height());
x = client.right - maxx - 4;
y = (client.bottom - maxy) / 2;
}
else
{
RCT rctbut; field(101).get_rect(rctbut);
maxx = rctbut.left - CHARX;
maxy = client.bottom - 4 * ROWY;
const double ratiox = double(maxx) / image.width();
const double ratioy = double(maxy) / image.height();
const double ratio = min(ratiox, ratioy);
maxx = int(ratio * image.width());
maxy = int(ratio * image.height());
x = 1;
y = 1;
}
RCT dst;
::xvt_rect_set(&dst, x, y, x+maxx, y+maxy);
if (::xvt_dwin_is_update_needed(win(), &dst))
image.draw(win(), dst);
}
}
bool TPicture_mask::on_key(KEY k)
{
switch (k)
{
case K_F3:
case K_F8:
set(DLG_USER, app().main_menu().last_search_string(), TRUE);
return TRUE;
case K_ENTER:
case K_UP:
case K_DOWN:
case K_LEFT:
case K_RIGHT:
if (focus_field().is_kind_of(CLASS_TREE_FIELD))
{
TTree_field& tf = (TTree_field&)focus_field();
return tf.win().on_key(k);
}
break;
default:
break;
}
return TMask::on_key(k);
}
void TPicture_mask::on_firm_change()
{
force_update();
}
void TPicture_mask::set_current(const TSubmenu& sm)
{
_submenu = (TSubmenu*)&sm;
}
TPicture_mask::TPicture_mask(const char* name, int dx, int dy,
const TSubmenu& submenu, int x, int y)
: TMask(name, 1, dx, dy, x, y), _submenu(NULL)
{
set_current(submenu);
}
TPicture_mask::~TPicture_mask()
{
}
///////////////////////////////////////////////////////////
// Explorer Mask
///////////////////////////////////////////////////////////
class TExplorer_mask : public TMask
{
protected:
virtual bool on_key(KEY k);
public:
TExplorer_mask();
};
bool TExplorer_mask::on_key(KEY k)
{
if (k == K_F3 || k == K_F8)
{
set(DLG_USER, app().main_menu().last_search_string(), TRUE);
return TRUE;
}
return TMask::on_key(k);
}
TExplorer_mask::TExplorer_mask()
: TMask ("", 1, 0, 0, 0, 0)
{
}
///////////////////////////////////////////////////////////
// Color Mask
///////////////////////////////////////////////////////////
class TColor_mask : public TAutomask
{
TAssoc_array _color;
protected: // TMask
virtual void update();
virtual bool stop_run(KEY key) { return TWindow::stop_run(key); }
virtual bool on_field_event(TOperable_field& f, TField_event e, long jolly);
// @cmember Converte le coordinate logiche (caratteri) in coordinate fisiche (pixel)
virtual PNT log2dev(long x, long y) const;
protected:
COLOR get_color_entry(const char* c) const;
void set_color_entry(const char* name, COLOR col);
const char* cid2name(short cid) const;
COLOR cid2color(short cid) const;
public:
void save_colors();
virtual KEY run();
TColor_mask();
virtual ~TColor_mask() { }
};
bool TColor_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
{
const short id = f.dlg();
bool ok = TRUE;
switch (id)
{
case DLG_USER:
if (e == fe_button)
{
for (short bid = 101; bid <= 113; bid++)
{
const char* name = cid2name(bid);
const COLOR color = cid2color(bid);
set_color_entry(name, color);
}
update();
}
break;
case 214:
if (e == fe_button)
{
xvt_dm_post_font_sel(TASK_WIN, xvt_default_font(), NULL, 0);
force_update();
}
break;
default:
if (id >= 101 && id <= 113 && e == fe_button)
{
TColor_mask& m = (TColor_mask&)f.mask();
const char* name = m.cid2name(f.dlg());
COLOR col = m.get_color_entry(name);
col = choose_color(col, m.win());
ok = col != COLOR_INVALID;
if (ok)
{
m.set_color_entry(name, col);
m.stop_run(K_CTRL + 'R');
}
}
break;
}
return ok;
}
TColor_mask::TColor_mask()
: TAutomask("ba0200a")
{
TConfig color(CONFIG_USER, "Colors");
_color = color.list_variables();
set(213, color.get_bool("Campi3D") ? "X" : "");
set(215, color.get_bool("SmallIcons") ? "X" : "");
}
PNT TColor_mask::log2dev(long x, long y) const
{
PNT p = { int(y * XI_FU_MULTIPLE), int(x * XI_FU_MULTIPLE) };
#ifdef XI_R4
XI_OBJ* itf = xi_get_itf((XinWindow)win());
xi_fu_to_pu(itf, (XinPoint*)&p, 1);
#else
XI_OBJ* itf = xi_get_itf(win());
xi_fu_to_pu(itf, &p, 1);
#endif
p.v = int(y * ROWY);
p.h += XI_FU_MULTIPLE / 2;
return p;
}
KEY TColor_mask::run()
{
KEY k = K_CTRL + 'R';
while (k == K_CTRL + 'R')
k = TMask::run();
return k;
}
void TColor_mask::update()
{
COLOR p, b;
const int x = 1;
const int y = 5;
const int w = 33;
const int h = 11;
set_pen(COLOR_BLACK);
set_brush(b = get_color_entry("MaskBack"));
frame(x+0, y+0, x+w, y+h, 0);
set_pen(p = get_color_entry("MaskLight"));
line(x+1, y, x+w-2, y);
line(x+1, y, x+1, y+h-1);
set_pen(p = get_color_entry("MaskDark"));
line(x+1, y+h-1, x+w-2, y+h-1);
line(x+w-2, y+h-1, x+w-2, y);
set_opaque_text(FALSE);
set_pen(p = get_color_entry("Normal"));
set_brush(b = get_color_entry("NormalBack"));
frame(x+3, y+1, x+w-3, y+2, 0);
set_color(p, b);
stringat(x+4, y+1, "Campo normale");
set_pen(p = get_color_entry("Normal")); // Stesso inchiostro del normale
set_brush(b = get_color_entry("RequiredBack"));
frame(x+3, y+3, x+w-3, y+4, 0);
set_color(p, b);
stringat(x+4, y+3, "Campo obbligatorio");
set_pen(p = get_color_entry("Focus"));
set_brush(b = get_color_entry("FocusBack"));
frame(x+3, y+5, x+w-3, y+6, 0);
set_color(p, b);
stringat(x+4, y+5, "Campo attivo");
set_pen(p = get_color_entry("Disabled"));
set_brush(b = get_color_entry("DisabledBack"));
frame(x+3, y+7, x+w-3, y+8, 0);
set_color(p, b);
stringat(x+4, y+7, "Campo disabilitato");
set_pen(p = get_color_entry("ButtonLight"));
set_brush(b = get_color_entry("ButtonBack"));
frame(x+3, y+9, x+w-3, y+10, 0);
set_color(get_color_entry("Normal"), b);
stringat(x+4, y+9, "Bottone normale");
}
void TColor_mask::save_colors()
{
TConfig colors(CONFIG_USER, "Colors");
FOR_EACH_ASSOC_STRING(_color, obj, key, str)
colors.set(key, str);
colors.set("Campi3D", get_bool(213) ? "X" : "");
colors.set("SmallIcons", get_bool(215) ? "X" : "");
}
COLOR TColor_mask::get_color_entry(const char* name) const
{
COLOR c = COLOR_INVALID;
const TObject* s = ((TColor_mask*)this)->_color.objptr(name);
if (s)
{
TToken_string colore(*(TString*)s, ',');
const byte r = (byte)colore.get_int();
const byte g = (byte)colore.get_int();
const byte b = (byte)colore.get_int();
c = RGB2COLOR(r, g, b);
}
return c;
}
void TColor_mask::set_color_entry(const char* name, COLOR col)
{
TString* s = (TString*)_color.objptr(name);
if (s == NULL)
{
s = new TString(15);
_color.add(name, s);
}
s->format("%d,%d,%d", XVT_COLOR_GET_RED(col), XVT_COLOR_GET_GREEN(col), XVT_COLOR_GET_BLUE(col));
}
const char* TColor_mask::cid2name(short cid) const
{
const int colors = 13;
const char* name[colors] = { "MaskBack", "MaskLight", "MaskDark",
"Normal", "NormalBack", "RequiredBack",
"Focus", "FocusBack",
"Disabled", "DisabledBack",
"ButtonBack", "ButtonLight", "ButtonDark"
};
const int i = cid - 101;
CHECK(i >= 0 && i < colors, "Invalid color id");
return name[i];
}
COLOR TColor_mask::cid2color(short cid) const
{
COLOR color[] = { COLOR_LTGRAY, COLOR_WHITE, COLOR_GRAY,
COLOR_BLACK, COLOR_WHITE, blend_colors(COLOR_WHITE, COLOR_YELLOW, 0.60),
COLOR_BLACK, COLOR_YELLOW,
COLOR_DKGRAY, COLOR_LTGRAY,
COLOR_LTGRAY, COLOR_WHITE, COLOR_GRAY };
const int i = cid - 101;
CHECK(i >= 0 && i < 13, "Invalid color id");
return color[i];
}
///////////////////////////////////////////////////////////
// Menu application
///////////////////////////////////////////////////////////
int TMenu_application::_last_button = 0;
bool TMenu_application::_find_button = FALSE;
bool TMenu_application::test_assistance_year() const
{
return TRUE;
}
bool TMenu_application::menu_item_handler(TMask_field&f, KEY k)
{
if (k == K_SPACE)
{
app()._menu.select(f.dlg()-101);
f.set_focusdirty(FALSE);
return f.mask().stop_run(K_AUTO_ENTER);
}
return TRUE;
}
bool TMenu_application::menu_find_handler(TMask_field&f, KEY k)
{
if (k == K_TAB && f.focusdirty())
{
const TString& v = f.get();
if (v.not_empty())
{
TPicture_mask& m = (TPicture_mask&)f.mask();
if (app()._menu.find_string(v))
{
f.set_focusdirty(FALSE);
return f.mask().stop_run(K_F9);
}
else
{
beep();
return FALSE;
}
}
}
return TRUE;
}
int TMenu_application::do_level()
{
const TSubmenu& curr = _menu.current();
const int bwidth = 20;
TPicture_mask mask(curr.caption(), -4, -4, curr);
CHECK(_mask == NULL, "Two masks are better than one?");
_mask = &mask;
const int x = mask.columns() / 2;;
int y = 1;
TString caption;
for (int i = 0; i < curr.items(); i++, y++)
{
const TMenuitem& item = curr[i];
caption = item.caption();
if (item.is_submenu() && caption.right(3) != "...")
caption << "...";
mask.add_static(-1, 0, caption, x+4, y);
const short id = 100+y;
mask.add_button(id, 0, "", x, y, 1, 1, "", BMP_STOPREC);
mask.set_handler(id, menu_item_handler);
if (item.disabled())
mask.disable(id);
}
TEdit_field& ef = mask.add_string(DLG_USER, 0, PR("Cerca "), 1, -3, 50, "", 50);
ef.set_handler(menu_find_handler);
const bool top = _menu.at_top();
TButton_field& bf = mask.add_button(DLG_QUIT, 0, PR("Fine"), -12, -1, bwidth, 2);
if (!top)
mask.add_button(DLG_CANCEL, 0, TR("Menu precedente"), -22, -1, bwidth, 2);
mask.first_focus(101+_menu.selected());
const int k = mask.run();
_mask = NULL;
int m = 0;
switch (k)
{
case K_ESC:
_menu.pop();
m = -1;
break;
case K_QUIT:
mask.reset();
m = -2;
break;
case K_F9:
case K_CTRL+'R':
m = 0;
break;
default:
m = _menu.selected() + 1; // Sempre > 0
break;
}
return m;
}
void TMenu_application::test_temp()
{
TFilename dir; dir.tempdir(); // Directory temporanea
dir.add("*");
TString_array files;
const int count = list_files(dir, files);
if (count > 0 && yesno_box(TR("Cancellare tutti i file temporanei in %s?"), dir.path()))
{
TProgind bar(count, TR("Cancellazione file temporanei"), TRUE, TRUE);
for (int i = count-1; i >= 0; i--)
{
bar.addstatus(1);
if (bar.iscancelled())
break;
const char* e = files.row(i);
::remove(e);
}
}
}
#ifdef DBG
HIDDEN bool pwd_handler(TMask_field& fld, KEY key)
{
if (key == K_F8)
{
TMask& m = fld.mask();
TString16 pwd;
TString16 usr = dongle().administrator(&pwd);
TLocalisamfile users(LF_USER);
users.put("USERNAME", usr);
users.read();
pwd = decode(users.get("PASSWORD"));
m.set(F_USER, usr);
m.set(F_PASSWORD, pwd);
m.stop_run(K_ENTER);
}
return TRUE;
}
#endif
void TMenu_application::reload_images()
{
_menu.reload_images();
}
bool TMenu_application::check_user()
{
// Disabilita le voci di personalizzazione
for (int mi = 2; mi <= 6; mi++)
disable_menu_item(MENU_ITEM(mi));
TString utente(user());
#ifdef _DEMO_
user() = utente = dongle().administrator();
const bool ok = TRUE;
#else
TMask m("ba0100a");
#ifdef DBG
m.set_handler(F_USER, pwd_handler);
m.set_handler(F_PASSWORD, pwd_handler);
#endif
TEdit_field& e = m.efield(F_USER);
e.browse()->set_filter("ISGROUP!=\"X\"");
TString pwd;
bool ok = FALSE;
for (int i = 0 ; i < 3 && !ok; i++)
{
if (utente.not_empty() && utente != dongle().administrator())
{
m.set(F_USER, utente);
m.first_focus(F_PASSWORD);
}
if (m.run() == K_ESC)
break;
utente = m.get(F_USER);
const TString& pass = m.get(F_PASSWORD);
pwd = "";
TLocalisamfile users(LF_USER);
users.put("USERNAME", utente);
if (users.read() == NOERR)
{
pwd = decode(users.get("PASSWORD"));
}
else
{
users.zero();
if (utente == dongle().administrator(&pwd))
{
users.put("USERNAME", utente);
users.put("USERDESC", "Amministratore");
users.put("PASSWORD", encode(pwd));
users.write();
}
else
utente.cut(0);
}
ok = utente.not_empty() && pwd.not_empty() && pwd == pass;
if (ok)
{
ok = !users.get_bool("CONNECTED");
if (!ok)
{
ok = yesno_box("%s\n%s",
TR("L'utente risulta essere gi<67> collegato"),
TR("Si desidera continuare ugualmente?"));
}
if (ok)
{
users.put("USERNAME", dongle().administrator());
users.read();
if (users.get("AUTSTR") == "CONVERTING")
{
TString msg; msg << TR("E' in corso una conversione archivi") << ":\n";
if (utente == dongle().administrator())
{
msg << TR("Si desidera continuare ugualmente?");
ok = yesno_box(msg);
}
else
{
msg << TR("Accesso negato.");
ok = error_box(msg);
}
}
}
if (ok)
{
user() = utente;
dongle().logout();
ok = get_serial_number() >= 0;
if (!ok)
error_box(TR("Probabilmente <20> stato superato il numero massimo di utenti"));
}
}
else
{
error_box(TR("Utente e/o password errata: fare attenzione alle maiuscole"));
m.set(F_PASSWORD,"");
}
if (ok)
{
TLocalisamfile users(LF_USER);
users.put("USERNAME", utente);
users.read(_isequal, _lock);
users.put("CONNECTED", "X");
users.rewrite();
}
}
#endif // _DEMO_
if (ok)
{
if (utente != dongle().administrator())
{
TConfig prawin(CONFIG_INSTALL, "Main");
prawin.set("User", utente);
}
// Abilita le voci di personalizzazione
for (int mi = 2; mi <= 6; mi++)
enable_menu_item(MENU_ITEM(mi));
customize_colors(); // Aggiorna set di colori
reload_images(); // Ritrasparentizza immagini
xvt_dwin_invalidate_rect(TASK_WIN, NULL); // Ridisegna sfondo
load_preferences();
}
return ok;
}
HIDDEN int compare_version(const char* v1, int p1, const char* v2, int p2)
{
TString16 ver1(v1), ver2(v2);
ver1.trim();
if (ver1.len() == 4)
ver1.insert((v1[0] == '9') ? "19" : "20", 0);
ver2.trim();
if (ver2.len() == 4)
ver2.insert((v2[0] == '9') ? "19" : "20", 0);
int res = ver1.compare(ver2, -1, TRUE);
if (res == 0)
res = p1 - p2;
return res;
}
static int get_module_version(TConfig& cfg, void* jolly)
{
const TString& p = cfg.get_paragraph();
if (p.len() == 2)
{
TAssoc_array& map = *(TAssoc_array*)jolly;
TToken_string* tok = new TToken_string(15);
*tok = cfg.get("Versione");
tok->add(cfg.get("Patch"));
map.add(p, tok);
}
return FALSE;
}
bool TMenu_application::test_network()
{
if (!xvt_sys_test_network_version())
return error_box(TR("Il driver di rete VREDIR.VXD contiene un bug riconosciuto da Microsoft.\n"
"Consultare la documentazione sul sito AGA per eliminare questo inconveniente."));
return true;
}
bool TMenu_application::test_programs()
{
TToken_string dangerous;
bool test = FALSE;
bool more = FALSE;
{
TConfig prawin(CONFIG_INSTALL, "Main");
test = prawin.get_bool("TestPrograms");
}
TExternal_app app("ba1 -6");
while (test)
{
TConfig install("install.ini", "Main");
TFilename remote_name = install.get("DiskPath");
remote_name.add("install.ini");
if (remote_name.exist())
{
TProgind pi(3, TR("Controllo aggiornamento programmi"), FALSE, TRUE);
TConfig remote_install(remote_name, "Main");
TAssoc_array my_modules, his_modules;
pi.addstatus(1);
install.for_each_paragraph(get_module_version, &my_modules);
pi.addstatus(1);
remote_install.for_each_paragraph(get_module_version, &his_modules);
pi.addstatus(1);
TScanner scan(AUT_FILE);
for (int module = 0; scan.line().not_empty(); module++)
{
if (dongle().active(module))
{
const TString16 code = scan.token().left(2);
TToken_string* mytok = (TToken_string*)my_modules.objptr(code);
TToken_string* histok = (TToken_string*)his_modules.objptr(code);
const TString16 v1 = mytok ? mytok->get(0) : "";
const int p1 = mytok ? mytok->get_int() : 0;
const TString16 v2 = histok ? histok->get(0) : "";
const int p2 = histok ? histok->get_int() : 0;
if (!v1.blank() && compare_version(v1, p1, v2, p2) < 0)
{
dangerous.add(code);
const TString& name = scan.token().mid(3);
if (!more)
warning_box("ATTENZIONE: Il modulo %s\ndeve essere aggiornato prima di poterlo utilizzare.", (const char*)name);
}
}
}
}
if (more)
break;
if (dangerous.empty() ||
(!more && !yesno_box(TR("Si desidera aggiornare i moduli adesso?"))))
break;
app.run();
more = TRUE; // ricontrolla
}
_menu.set_dangerous_modules(dangerous);
return TRUE;
}
bool TMenu_application::create()
{
if (!test_network())
return FALSE;
#ifdef _DEMO_
{
TMask w(TR("ATTENZIONE"), 1, 68, 12);
w.add_static(DLG_NULL, 0 , PR("@bATTENZIONE") , 30 , 1);
w.add_static(DLG_NULL, 0 , TR("Questo programma <20> in versione dimostrativa.") , 1 , 3);
w.add_static(DLG_NULL, 0 , TR("Non si possono memorizzare date con mese successivo a Marzo.") , 1 , 5);
w.add_static(DLG_NULL, 0 , TR("Il programma funziona circa per due ore ogni giorno.") , 1 , 7);
w.add_static(DLG_NULL, 0 , TR("Il numero di registrazioni <20> stato limitato ad un migliaio.") , 1 , 9);
w.add_button(DLG_OK, 0, "", -11, -1, 10, 2);
w.run();
}
#endif
if (!check_user())
return FALSE;
if (!TApplication::test_assistance_year())
{
TExternal_app app("ba1 -4");
app.run();
}
set_perms();
test_temp();
TWait_cursor hourglass;
if (!test_programs())
return FALSE;
if (!_menu.ok())
{
TWait_cursor hourglass;
TFilename menu = _name;
menu.ext("men");
_menu.read(menu);
TSkeleton_application::create();
}
return TRUE;
}
bool TMenu_application::destroy()
{
TLocalisamfile users(LF_USER);
users.put("USERNAME", user());
int err = users.read(_isequal, _lock);
if (err == NOERR)
{
users.zero("CONNECTED");
users.rewrite();
}
// ba0 / 1 substitute: serve per installare anche i file menu ed installatore che erano in esecuzione
TFilename ba0exfile("ba0.ex_"),ba1exfile("ba1.ex_");
if (ba0exfile.exist()||ba1exfile.exist())
{
TExternal_app ba0epilogue("ba0close.exe");
ba0epilogue.run(TRUE,TRUE,TRUE); // run asynchronous...
}
return TRUE;
}
void TMenu_application::main_loop()
{
bool run = TRUE;
while (run)
{
int m = 0;
switch (_tree_view)
{
case 1: m = do_tree(); break;
case 2: m = do_explore(); break;
default: m = do_level(); break;
}
if (m > 0)
_menu.perform();
else
run = m >= -1;
}
}
bool TMenu_application::choose_colors()
{
disable_menu_item(OPTIONS_MENU);
TColor_mask * cm = new TColor_mask();
if (cm->run() == K_ENTER)
{
cm->save_colors(); // Aggiorna config
customize_colors(); // Aggiorna set di colori
reload_images(); // Aggiorna bitmaps del menu
// Ridisegna sfondo
TTemp_window tw(TASK_WIN);
tw.force_update();
// Provoca chiusura forzata del menu
if (_mask != NULL)
_mask->stop_run(K_CTRL + 'R');
}
enable_menu_item(OPTIONS_MENU);
delete cm;
return TRUE;
}
HIDDEN bool browse_file_handler(TMask_field& f, KEY k)
{
bool ok = TRUE;
if (k == K_F9)
{
FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC));
xvt_fsys_convert_str_to_dir(".", &fs.dir);
strcpy(fs.type, "EXE");
strcpy(fs.name, f.get());
strcpy(fs.creator, "MENU");
DIRECTORY dir;
xvt_fsys_get_dir(&dir);
const int err = xvt_dm_post_file_open(&fs, TR("Selezione programma"));
xvt_fsys_set_dir(&dir);
if (err == FL_OK)
{
TFilename n;
xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(), n.size());
n.add(fs.name);
f.set(n);
}
}
if (k == K_TAB && f.focusdirty())
{
TFilename infile(f.get());
if (infile.not_empty())
{
TFilename outfile;
if (*infile.ext() == '\0')
infile.ext("exe");
if (!infile.search_in_path(outfile))
ok = error_box("Il programma %s non esiste!", (const char*)infile);
}
}
return ok;
}
HIDDEN bool link_notify(TSheet_field& s, int r, KEY k)
{
bool ok = TRUE;
if (k == K_INS)
{
ok = s.items() < 29; // Accetta 29 righe al massimo
}
return ok;
}
bool TMenu_application::choose_editors()
{
disable_menu_item(OPTIONS_MENU);
TConfig link(CONFIG_USER, "Link");
TMask* msk = new TMask("ba0300a");
TMask& m = *msk;
TSheet_field& sheet = m.sfield(201);
sheet.set_notify(link_notify);
TMask& sm = sheet.sheet_mask();
sm.set_handler(102, browse_file_handler);
TAssoc_array& var = (TAssoc_array&)link.list_variables();
FOR_EACH_ASSOC_STRING(var, obj, key, str)
{
TToken_string& row = sheet.row(-1);
if (strlen(key) <= 3)
{
row = key;
row.lower();
row.add(str);
}
}
sheet.rows_array().sort();
if (m.run() == K_ENTER)
{
link.remove_all();
FOR_EACH_SHEET_ROW_BACK(sheet, r, row)
{
TString16 ext = row->get(0);
if (!ext.blank())
{
ext.lower();
TFilename prg = row->get();
link.set(ext, prg);
}
}
}
delete msk;
enable_menu_item(OPTIONS_MENU);
return TRUE;
}
HIDDEN bool study_handler(TMask_field& f, KEY k)
{
bool ok = TRUE;
if (f.to_check(k))
{
TFilename path(f.get());
path.add("com");
path.add("dir.gen");
if (!path.exist())
ok = f.error_box("%s %s", (const char*)f.get(), TR("non e' uno studio valido!"));
}
return ok;
}
bool TMenu_application::choose_study()
{
TMask m(TR("Scelta studio"), 1, 60, 5);
m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
m.add_string(DLG_USER, 0, PR("Studio "), 1, 1, 50);
m.set_handler(DLG_USER, study_handler);
m.set(DLG_USER, prefix().get_studio());
bool ok = m.run() == K_ENTER;
if (ok)
{
destroy();
prefix().set_studio(m.get(DLG_USER));
ok = create();
if (ok)
{
set_firm();
_mask->stop_run(K_F9); // Ricarica maschera
}
else
stop_run(); // Termina applicazione
}
return ok;
}
long TMenu_application::handler(WINDOW win, EVENT* ep)
{
long ret = TApplication::handler(win, ep);
if (ep->type == E_FONT)
{
if (_mask != NULL)
_mask->stop_run(K_CTRL + 'R');
}
return ret;
}
///////////////////////////////////////////////////////////
// Tree view implementation
///////////////////////////////////////////////////////////
bool TMenu_application::tree_handler(TMask_field& f, KEY k)
{
if (k == K_CTRL + K_SPACE)
{
TTree_field& tf = (TTree_field&)f;
TMenu_tree& mt = *(TMenu_tree*)tf.tree();
const TMenuitem& mi = mt.curr_item();
mi.perform();
if (mi.is_submenu() && mt.expanded())
{
TMenu& menu = mt.curr_submenu().menu();
TPicture_mask& pm = (TPicture_mask&)f.mask();
pm.set_current(menu.current());
}
}
return TRUE;
}
void TMenu_application::select_tree_current()
{
TTree_field& tf = _mask->tfield(DLG_TREE);
if (_tree_view == 2)
{
TMenulist_field& mf = (TMenulist_field&)tf.mask().field(DLG_LIST);
TMenu_tree& mt = (TMenu_tree&)*tf.tree();
mf.set_menu(mt);
synchronize_tree_field(tf);
mf.set_focus();
}
else
{
synchronize_tree_field(tf);
tf.set_focus();
}
}
bool TMenu_application::tree_find_handler(TMask_field&f, KEY k)
{
if (k == K_TAB && f.focusdirty() && !f.empty())
{
const TString& v = f.get();
TPicture_mask& m = (TPicture_mask&)f.mask();
TTree_field& tf = (TTree_field&)m.field(DLG_TREE);
TMenu_tree& mt = *(TMenu_tree*)tf.tree();
if (mt.find_string(v))
app().select_tree_current();
else
beep();
}
return TRUE;
}
bool TMenu_application::tree_shrink_handler(TMask_field&f, KEY k)
{
if (k == K_SPACE)
{
TTree_field& tf = f.mask().tfield(DLG_TREE);
TMenu_tree& mt = (TMenu_tree&)*tf.tree();
mt.shrink_all();
mt.goto_root();
app().select_tree_current();
}
return TRUE;
}
bool TMenu_application::explore_handler(TMask_field& f, KEY k)
{
if (k == K_CTRL + K_SPACE)
{
TTree_field& tf = (TTree_field&)f;
TMenu_tree& mt = *(TMenu_tree*)tf.tree();
const TMenuitem& mi = mt.curr_item();
if (mi.perform() && mt.goto_firstson())
{
TMenulist_field& mf = (TMenulist_field&)f.mask().field(DLG_LIST);
mf.set_menu(mt);
}
}
return TRUE;
}
void TMenu_application::update_preferred()
{
MENU_ITEM* mm = xvt_menu_get_tree(TASK_WIN);
for (MENU_ITEM* mi = mm; mi != NULL && mi->tag != 0 && mi->tag != PREFERRED_MENU; mi++);
if (mi == NULL || mi->tag <= 0 || mi->child == NULL)
{
NFCHECK("Can't find Preferiti Menu");
return;
}
int i;
MENU_ITEM* pm = (MENU_ITEM*)xvt_mem_zalloc((_preferred.items()+4)*sizeof(MENU_ITEM));
memcpy(pm, mi->child, 3*sizeof(MENU_ITEM));
for (i = 0; i < 2; i++)
{
const char* src = mi->child[i].text;
pm[i].text = xvt_str_duplicate(src);
}
xvt_res_free_menu_tree(mi->child);
mi->child = pm;
for (i = -1; i < _preferred.items(); i++)
{
MENU_ITEM& m = pm[i+3];
if (i >= 0)
{
m.tag = MENU_ITEM(50+i);
m.enabled = TRUE;
const char* src = _preferred.row(i).get(0);
m.text = xvt_str_duplicate(src);
}
else
{
m.tag = -1;
m.separator = TRUE;
}
}
xvt_menu_set_tree(TASK_WIN, mm);
xvt_menu_update(TASK_WIN);
xvt_res_free_menu_tree(mm);
}
void TMenu_application::load_preferences()
{
TConfig cfg(CONFIG_USER, "ba0");
_tree_view = cfg.get_int("TreeView");
_preferred.destroy();
TToken_string row;
for (int i = 0; ; i++)
{
row = cfg.get("Preferred", NULL, i);
if (row.empty_items())
break;
_preferred.add(row);
}
if (i > 0)
update_preferred();
}
void TMenu_application::save_preferences()
{
TConfig cfg(CONFIG_USER, "ba0");
for (int i = 0; i < _preferred.items(); i++)
cfg.set("Preferred", _preferred.row(i), NULL, TRUE, i);
cfg.set("Preferred", "", NULL, TRUE, i);
cfg.set("TreeView", _tree_view);
}
void TMenu_application::add_to_preferred()
{
const int maxpref = 16;
if (_mask == NULL) // Succede durante il login!
return;
if (_preferred.items() < maxpref)
{
TToken_string tok;
if (_tree_view != 0)
{
TTree_field& tf = _mask->tfield(DLG_TREE);
tf.goto_selected();
tf.tree()->get_description(tok);
TString id; tf.tree()->curr_id(id);
tok.add(id);
}
else
{
const TMask_field& butt = _mask->focus_field();
const int index = butt.dlg() - 101;
if (index >= 0 && index < 16)
{
_menu.select(index);
tok = _menu.curr_item().caption();
tok.add(_menu.current().name());
tok << '.' << index;
}
}
if (!tok.empty())
{
_preferred.add(tok);
update_preferred();
save_preferences();
}
}
else
error_box(TR("Non e' possibile memorizzare piu' di %d preferenze"), maxpref);
}
class TPreferred_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TPreferred_mask() : TAutomask("ba0400a") { }
virtual ~TPreferred_mask() { }
};
bool TPreferred_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_PREF_SHEET:
switch (e)
{
case se_query_add:
return FALSE;
case se_enter:
enable(F_PREF_UP, jolly > 0);
enable(F_PREF_DN, jolly < ((TSheet_field&)o).items()-1);
break;
default:
break;
}
break;
case F_PREF_UP:
if (e == fe_button)
{
TSheet_field& sf = sfield(F_PREF_SHEET);
const int r = sf.selected();
if (r > 0)
{
sf.rows_array().swap(r, r-1);
sf.select(r-1);
sf.force_update();
}
}
break;
case F_PREF_DN:
if (e == fe_button)
{
TSheet_field& sf = sfield(F_PREF_SHEET);
const int r = sf.selected();
if (r < sf.items()-1)
{
sf.rows_array().swap(r, r+1);
sf.select(r+1);
sf.force_update();
}
}
break;
case DLG_DELREC:
if (e == fe_button && jolly == 0) // Main delete button pressed
{
TSheet_field& sf = sfield(F_PREF_SHEET);
const int r = sf.selected();
if (r >= 0)
sf.destroy(r);
return FALSE;
}
break;
default:
break;
}
return TRUE;
}
void TMenu_application::manage_preferred()
{
TPreferred_mask* m = new TPreferred_mask;
m->set(F_PREF_TREE, _tree_view);
TSheet_field& sf = m->sfield(F_PREF_SHEET);
sf.rows_array() = _preferred;
sf.force_update();
if (m->run() == K_ENTER)
{
_preferred = sf.rows_array();
const int old_tv = _tree_view;
_tree_view = m->get_int(F_PREF_TREE);
update_preferred();
save_preferences();
if (_tree_view != old_tv && _mask != NULL)
{
reload_images();
_mask->TWindow::stop_run(K_CTRL + 'R'); // Provoca chiusura forzata del menu
}
}
delete m;
}
int TMenu_application::do_tree()
{
_menu.jumpto_root();
const TSubmenu& curr = _menu.current();
TPicture_mask mask(curr.caption(), 0, 0, curr, 0, 0);
CHECK(_mask == NULL, "Two masks are better than one?");
_mask = &mask;
const int margin = (mask.columns()-80) / 2;
const int twidth = margin + 40;
const int bwidth = (mask.columns() - twidth - 8);
TMenu_tree tree(_menu);
TTree_field& tree_fld = mask.add_tree(DLG_TREE, 0, 0, 0, twidth, -1);
tree_fld.set_tree(&tree);
tree_fld.set_handler(tree_handler);
TMask_field& sf = mask.add_static(DLG_NULL, 0, PR("Cerca"), -2, 0);
TEdit_field& ef = mask.add_string(DLG_USER, 0, "", -2, 1, 50, "", bwidth);
ef.set_handler(tree_find_handler);
TButton_field& mf = mask.add_button(201, 0, PR("Menu Principale"), -1, 2, bwidth, 2);
mf.set_handler(tree_shrink_handler);
TButton_field& bf = mask.add_button(DLG_QUIT, 0, PR("Fine"), -56, -1, bwidth/2, 2);
mask.first_focus(DLG_TREE);
KEY key = mask.run();
_mask = NULL;
return key == K_QUIT ? -2 : 0;
}
int TMenu_application::do_explore()
{
CHECK(_mask == NULL, "Two masks are better than one?");
TExplorer_mask mask;
_mask = &mask;
const int margin = (mask.columns()-80) / 2;
const int tree_width = margin+28; // Usa la met<65> di sinistra
_menu.jumpto_root();
TMenu_tree tree(_menu);
TTree_field& tree_fld = mask.add_tree(DLG_TREE, 0, 0, 0, tree_width, -5);
tree_fld.set_tree(&tree);
tree_fld.set_handler(explore_handler);
tree_fld.hide_leaves(true);
TMenulist_field* mf = new TMenulist_field(&mask);
mf->create(DLG_LIST, tree_width-margin+4, 0, -3, -5);
mask.add_field(mf);
mf->set_menu(tree);
TEdit_field& ef = mask.add_string(DLG_USER, 0, PR("Cerca "), 11, -4, 50);
ef.set_handler(tree_find_handler);
TButton_field& bf = mask.add_button(DLG_QUIT, 0, "", -12, -2, 18, 2);
TButton_field& mp = mask.add_button(201, 0, PR("Menu Principale"), -22, -2, 18, 2);
mp.set_handler(tree_shrink_handler);
mask.first_focus(DLG_LIST);
KEY key = mask.run();
_mask = NULL;
return key == K_QUIT ? -2 : 0;
}
bool TMenu_application::menu(MENU_TAG mt)
{
bool ok = TRUE;
switch (mt)
{
case BAR_ITEM(1): main_loop(); ok = FALSE; break;
case MENU_ITEM(2): choose_colors(); break;
case MENU_ITEM(3): choose_editors(); break;
case MENU_ITEM(4): choose_study(); break;
case MENU_ITEM(5): add_to_preferred(); break;
case MENU_ITEM(6): manage_preferred(); break;
default:
if (mt >= MENU_ITEM(50) && mt < MENU_ITEM(50+_preferred.items()))
{
bool ok = FALSE;
const int index = mt - MENU_ITEM(50);
TToken_string node(_preferred.row(index).get(1), '/');
if (_tree_view != 0)
{
TMenu_tree& met = *(TMenu_tree*)_mask->tfield(DLG_TREE).tree();
ok = node.items() == 1 ? met.find_leaf(node) : met.goto_node(node);
if (ok)
select_tree_current();
}
else
{
TToken_string mi(node.get(-2), '.');
const char* sub = mi.get(0);
TSubmenu* sm = _menu.find(sub);
if (sm && _menu.jumpto(sm))
{
ok = TRUE;
_menu.select(mi.get_int());
_mask->stop_run(K_CTRL + 'R');
}
}
if (!ok) beep();
}
break;
}
return ok;
}
int ba0100(int argc, char** argv)
{
TApplication::check_parameters(argc, argv);
if (user().blank())
{
TConfig prawin(CONFIG_INSTALL, "Main");
TString16 u = prawin.get("User");
if (u.blank())
u = dongle().administrator();
user() = u;
}
TFilename menu = (argc < 2) ? MEN_FILE : argv[1];
if (menu.exist())
{
TMenu_application *ma = new TMenu_application(menu);
ma->run(argc, argv, TR("Menu Principale"));
delete ma;
}
else
error_box(FR("Non esiste il menu %s"), (const char*)menu);
return 0;
}