99ecbb0f01
git-svn-id: svn://10.65.10.50/trunk@3255 c028cbd2-c16b-5b4b-a496-9718f37d4682
1010 lines
24 KiB
C++
Executable File
1010 lines
24 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <colors.h>
|
|
#include <config.h>
|
|
#include <execp.h>
|
|
#include <golem.h>
|
|
#include <mask.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
#define STRICT
|
|
#include <windows.h>
|
|
#include <commdlg.h>
|
|
#endif
|
|
|
|
#include <nditte.h>
|
|
|
|
#include "ba0.h"
|
|
#include "ba0100a.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Picture Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPicture_mask : public TMask
|
|
{
|
|
TImage& _image;
|
|
|
|
protected: // TMask
|
|
virtual void update();
|
|
|
|
public:
|
|
TPicture_mask(const char* name, int dx, int dy, TImage& image);
|
|
virtual ~TPicture_mask() {}
|
|
};
|
|
|
|
TPicture_mask::TPicture_mask(const char* name, int dx, int dy, TImage& image)
|
|
: TMask(name, 1, dx, dy), _image(image)
|
|
{
|
|
if (_image.ok())
|
|
_image.set_palette(win());
|
|
}
|
|
|
|
void TPicture_mask::update()
|
|
{
|
|
if (_image.ok())
|
|
{
|
|
RCT cli; fld(1).get_rect(cli);
|
|
const short maxx = cli.left;
|
|
const short maxy = short((long)maxx*_image.height()/_image.width());
|
|
RCT dst; xvt_rect_set(&dst, 1, 1, maxx, maxy);
|
|
|
|
if (xvt_dwin_is_update_needed(win(), &dst))
|
|
_image.draw(win(), dst);
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Color Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TColor_mask : public TMask
|
|
{
|
|
TAssoc_array _color;
|
|
|
|
protected: // TMask
|
|
virtual void update();
|
|
static bool color_handler(TMask_field& f, KEY k);
|
|
static bool azzera_handler(TMask_field& f, KEY k);
|
|
|
|
COLOR get_color(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();
|
|
|
|
TColor_mask();
|
|
virtual ~TColor_mask() { }
|
|
};
|
|
|
|
TColor_mask::TColor_mask()
|
|
: TMask("ba0200a")
|
|
{
|
|
TConfig color(CONFIG_USER, "Colors");
|
|
_color = color.list_variables();
|
|
|
|
for (int f = fields()-1; f >= 0; f--)
|
|
{
|
|
TMask_field& mf = fld(f);
|
|
if (mf.is_kind_of(CLASS_BUTTON_FIELD))
|
|
{
|
|
if (mf.dlg() > DLG_USER)
|
|
mf.set_handler(color_handler);
|
|
else
|
|
if (mf.dlg() == DLG_USER)
|
|
mf.set_handler(azzera_handler);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TColor_mask::save_colors()
|
|
{
|
|
TConfig colors(CONFIG_USER, "Colors");
|
|
_color.restart();
|
|
for (THash_object* h = _color.get_hashobj(); h; h = _color.get_hashobj())
|
|
{
|
|
const TString& k = h->key();
|
|
const TString& s = (const TString&)h->obj();
|
|
colors.set(k, s);
|
|
}
|
|
}
|
|
|
|
COLOR TColor_mask::get_color(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(16);
|
|
_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 char* name[] = { "MaskBack", "MaskLight", "MaskDark",
|
|
"Normal", "NormalBack",
|
|
"Focus", "FocusBack",
|
|
"Disabled", "DisabledBack" };
|
|
const int i = cid - 101;
|
|
CHECK(i >= 0 && i < 9, "Invalid color id");
|
|
return name[i];
|
|
}
|
|
|
|
COLOR TColor_mask::cid2color(short cid) const
|
|
{
|
|
COLOR color[] = { COLOR_DKCYAN, COLOR_CYAN, COLOR_GRAY,
|
|
COLOR_BLACK, COLOR_WHITE,
|
|
COLOR_BLACK, COLOR_CYAN,
|
|
COLOR_GRAY, COLOR_DKCYAN };
|
|
|
|
const int i = cid - 101;
|
|
CHECK(i >= 0 && i < 9, "Invalid color id");
|
|
return color[i];
|
|
}
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
inline COLORREF COLOR2RGB(COLOR c)
|
|
{
|
|
return RGB(XVT_COLOR_GET_RED(c), XVT_COLOR_GET_GREEN(c), XVT_COLOR_GET_BLUE(c));
|
|
}
|
|
|
|
#endif
|
|
|
|
bool TColor_mask::color_handler(TMask_field& f, KEY k)
|
|
{
|
|
bool ok = TRUE;
|
|
|
|
if (k == K_SPACE)
|
|
{
|
|
TColor_mask& m = (TColor_mask&)f.mask();
|
|
const char* name = m.cid2name(f.dlg());
|
|
COLOR col = m.get_color(name);
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
CHOOSECOLOR cc;
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
HWND hwnd = (HWND)xvt_vobj_get_attr(m.win(), ATTR_NATIVE_WINDOW);
|
|
HDC hdc = GetDC(hwnd);
|
|
|
|
PALETTEENTRY* pe = NULL;
|
|
int max_entries = 0;
|
|
if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
|
|
{
|
|
max_entries = GetDeviceCaps(hdc, SIZEPALETTE);
|
|
pe = new PALETTEENTRY[max_entries];
|
|
GetSystemPaletteEntries(hdc, 0, max_entries, pe);
|
|
}
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
unsigned long custom_colors[16];
|
|
for (int c = 0; c < 16; c++)
|
|
{
|
|
if (pe)
|
|
{
|
|
const PALETTEENTRY& e = pe[c < 8 ? c : max_entries - 16 + c];
|
|
custom_colors[c] = RGB(e.peRed, e.peGreen, e.peBlue);
|
|
}
|
|
else
|
|
{
|
|
const byte val = (c & 0x8) ? 255 : 127;
|
|
const byte red = (c & 0x1) ? val : 0;
|
|
const byte green = (c & 0x2) ? val : 0;
|
|
const byte blue = (c & 0x4) ? val : 0;
|
|
custom_colors[c] = RGB(red, green, blue);
|
|
}
|
|
}
|
|
if (pe)
|
|
{
|
|
delete pe;
|
|
pe = NULL;
|
|
}
|
|
|
|
cc.lStructSize = sizeof(cc);
|
|
cc.hwndOwner = hwnd;
|
|
cc.rgbResult = COLOR2RGB(col);
|
|
cc.lpCustColors = custom_colors;
|
|
cc.Flags = CC_RGBINIT;
|
|
|
|
ok = ChooseColor(&cc) != 0;
|
|
col = RGB2COLOR(GetRValue(cc.rgbResult), GetGValue(cc.rgbResult), GetBValue(cc.rgbResult));
|
|
#endif
|
|
|
|
if (ok)
|
|
{
|
|
m.set_color_entry(name, col);
|
|
m.force_update();
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TColor_mask::azzera_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TColor_mask& cm = (TColor_mask&)f.mask();
|
|
for (int i = cm.fields()-1; i >= 0; i--)
|
|
{
|
|
TMask_field& mf = cm.fld(i);
|
|
if (mf.dlg() > DLG_USER && mf.is_kind_of(CLASS_BUTTON_FIELD))
|
|
{
|
|
const char* name = cm.cid2name(mf.dlg());
|
|
const COLOR color = cm.cid2color(mf.dlg());
|
|
cm.set_color_entry(name, color);
|
|
}
|
|
}
|
|
cm.update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void TColor_mask::update()
|
|
{
|
|
COLOR p, b;
|
|
|
|
set_pen(COLOR_BLACK);
|
|
set_brush(b = get_color("MaskBack"));
|
|
frame(1, 10, 33, 19, 0);
|
|
|
|
set_pen(p = get_color("MaskLight"));
|
|
line(2, 10, 31, 10);
|
|
line(2, 10, 2, 18);
|
|
|
|
set_pen(p = get_color("MaskDark"));
|
|
line( 2, 18, 31, 18);
|
|
line(31, 18, 31, 10);
|
|
|
|
set_opaque_text(FALSE);
|
|
set_pen(p = COLOR_BLACK);
|
|
set_brush(b = get_color("NormalBack"));
|
|
frame(4, 12, 30, 13, 0);
|
|
set_color(get_color("Normal"), b);
|
|
stringat(5, 12, "Campo normale");
|
|
|
|
set_pen(p = get_color("Focus"));
|
|
set_brush(b = get_color("FocusBack"));
|
|
frame(4, 14, 30, 15, 0);
|
|
set_color(p, b);
|
|
stringat(5, 14, "Campo attivo");
|
|
|
|
set_pen(p = COLOR_BLACK);
|
|
set_brush(b = get_color("DisabledBack"));
|
|
frame(4, 16, 30, 17, 0);
|
|
set_color(get_color("Disabled"), b);
|
|
stringat(5, 16, "Campo disabilitato");
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Menu application
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TMenu_application : public TApplication
|
|
{
|
|
const char* _name;
|
|
|
|
enum { MAXLEVEL = 512 }; // Non cambiare !! pena di morte . Deve essere < 730
|
|
int _first[MAXLEVEL];
|
|
TArray _menu; // TAG|DESCRIPTION|ACTION
|
|
TBit_array _enabled;
|
|
TArray _modules, _images;
|
|
|
|
int _level, _max;
|
|
TPicture_mask* _mask;
|
|
|
|
static int _last_button;
|
|
static bool _find_button;
|
|
|
|
protected: // TApplication
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual bool menu(MENU_TAG m);
|
|
virtual bool build_firm_data(long cod, bool flagcom = FALSE);
|
|
|
|
protected:
|
|
bool main_loop();
|
|
void test_temp();
|
|
void load_menu();
|
|
int do_level();
|
|
int find_menu(const char* s) const;
|
|
bool check_user();
|
|
static bool menu_item_handler(TMask_field&f, KEY k);
|
|
static bool menu_find_handler(TMask_field&f, KEY k);
|
|
bool module_enabled(const char * program) const;
|
|
bool module_enabled(int module) const { return has_module(module);}
|
|
|
|
bool choose_colors();
|
|
|
|
public:
|
|
void reload_images();
|
|
|
|
TMenu_application(const char* name) : _name(name), _mask(NULL) { }
|
|
virtual ~TMenu_application() { }
|
|
};
|
|
|
|
int TMenu_application::_last_button = 0;
|
|
bool TMenu_application::_find_button = FALSE;
|
|
|
|
inline TMenu_application& app()
|
|
{ return (TMenu_application&)main_app(); }
|
|
|
|
|
|
bool TMenu_application::build_firm_data(long codditta, bool flagcom)
|
|
{
|
|
const char * const ndir = "/dir.gen";
|
|
const char * const ntrc = "/trc.gen";
|
|
TFilename s(firm2dir(codditta)); s << ndir;
|
|
bool exist = fexist(s);
|
|
|
|
if (!exist)
|
|
{
|
|
s = s.path(); s.rtrim(1); s << ntrc;
|
|
exist = fexist(s);
|
|
}
|
|
if (exist)
|
|
return message_box("Direttorio dati danneggiato, impossibile attivare la ditta %ld", codditta);
|
|
if (!yesno_box("Gli archivi della ditta %ld non esistono: si desidera generarli?", codditta))
|
|
return FALSE;
|
|
|
|
TLocalisamfile ditte(LF_NDITTE);
|
|
ditte.zero();
|
|
ditte.put(NDT_CODDITTA,codditta);
|
|
if (ditte.read(_isequal,_testandlock) == _islocked)
|
|
{
|
|
message_box("Archivi della ditta %ld in fase di creazione da parte di un altro utente.",codditta);
|
|
return FALSE;
|
|
}
|
|
|
|
set_autoload_new_files(yesno_box("Si desidera precaricare gli archivi standard"));
|
|
s = s.path(); s.rtrim(1);
|
|
|
|
if (!fexist(s) && !make_dir(s))
|
|
return error_box("Impossibile creare il direttorio della ditta %ld (%s)",
|
|
codditta, (const char*)s);
|
|
|
|
s << ndir;
|
|
if (!fcopy(&ndir[1], s))
|
|
return error_box("Impossibile copiare il file %s della ditta %ld",
|
|
&ndir[1], codditta);
|
|
s = s.path(); s << ntrc;
|
|
if (!fcopy(&ntrc[1], s))
|
|
return error_box("Impossibile copiare il file %s della ditta %ld",
|
|
ntrc, codditta);
|
|
|
|
TDir dir, dir1;
|
|
TTrec rec;
|
|
|
|
prefix().set("");
|
|
dir1.get(LF_DIR, _nolock, _nordir, _sysdirop);
|
|
const long maxeod0 = dir1.eod();
|
|
|
|
prefix().set_codditta(codditta);
|
|
dir.get(LF_DIR, _nolock, _nordir, _sysdirop);
|
|
if (dir.eod() == 0)
|
|
{
|
|
dir1.eod() = 1L;
|
|
dir1.put(LF_DIR, _nordir, _sysdirop);
|
|
dir.get(LF_DIR, _nolock, _nordir, _sysdirop);
|
|
}
|
|
const long maxeod1 = dir.eod();
|
|
|
|
if (maxeod0 > maxeod1)
|
|
{
|
|
dir.get(LF_DIR, _nolock, _nordir, _sysdirop);
|
|
dir.eod() = maxeod0;
|
|
dir.put(LF_DIR, _nordir, _sysdirop);
|
|
rec.zero();
|
|
}
|
|
TString mess("Generazione archivi della ditta "); mess << codditta;
|
|
TProgind p(maxeod0 ? maxeod0 : 1, mess, FALSE, TRUE, 70);
|
|
|
|
for (int i = LF_DIR + 1; i <= maxeod0; i++)
|
|
{
|
|
p.addstatus(1);
|
|
prefix().set("");
|
|
dir.get(i, _nolock, _nordir, _sysdirop);
|
|
rec.get(i);
|
|
bool create_now = dir.is_active();
|
|
|
|
prefix().set_codditta(codditta);
|
|
dir.put(i, _nordir, _sysdirop);
|
|
rec.put(i);
|
|
const char* name = dir.name();
|
|
dir.flags() = 0L;
|
|
create_now = create_now && (flagcom ? dir.is_com() : dir.is_firm());
|
|
|
|
if (dir.is_valid() && create_now)
|
|
{
|
|
TSystemisamfile f(i);
|
|
f.build(30);
|
|
}
|
|
else
|
|
{
|
|
dir.put(i, _nordir, _sysdirop);
|
|
rec.put(i);
|
|
}
|
|
}
|
|
|
|
TConfig c(CONFIG_STUDIO, "cg");
|
|
|
|
if (c.get_bool("StiReg"))
|
|
{
|
|
TTable reg("REG");
|
|
for (reg.first(_lock); reg.good(); reg.next(_lock))
|
|
{
|
|
reg.put("B9", "X");
|
|
reg.rewrite();
|
|
}
|
|
}
|
|
ditte.reread(_unlock);
|
|
|
|
set_firm(codditta);
|
|
set_autoload_new_files(TRUE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TMenu_application::module_enabled(const char * program) const
|
|
{
|
|
bool found = FALSE;
|
|
const int nmod = _modules.items();
|
|
|
|
for (int aut = 0; aut < nmod; aut++)
|
|
{
|
|
const TString& s = (const TString&) _modules[aut];
|
|
if (isdigit(program[2]) && s.compare(program, 2) == 0) { found = TRUE; break; }
|
|
}
|
|
return (!found) || has_module(aut);
|
|
}
|
|
|
|
void TMenu_application::load_menu()
|
|
{
|
|
TScanner s(_name);
|
|
|
|
_max = -1;
|
|
|
|
while (s.line().not_empty())
|
|
{
|
|
TToken_string* ts = new TToken_string(s.token());
|
|
int l = ts->get_int();
|
|
|
|
if (l < _max)
|
|
{
|
|
error_box("Item of level %d while %d was expected)", l, _max);
|
|
l = _max;
|
|
}
|
|
if (l > _max)
|
|
{
|
|
if (l >= MAXLEVEL)
|
|
{
|
|
error_box("Too many menu levels: %d", l);
|
|
l = _max;
|
|
}
|
|
_first[++_max] = _menu.items();
|
|
_first[_max = l] = _menu.items();
|
|
}
|
|
|
|
_menu.add(ts);
|
|
const TString80 action(ts->get(2));
|
|
const int last = _menu.items() - 1;
|
|
|
|
if (atoi(action) > 0)
|
|
{
|
|
TToken_string list(ts->get(), ',');
|
|
const TString& mod = list.get();
|
|
int module = atoi(mod);
|
|
|
|
if (module == 0)
|
|
{
|
|
bool on = TRUE;
|
|
if (mod[0] == 'P')
|
|
on = user() == "PRASSI";
|
|
_enabled.set(last, on);
|
|
}
|
|
while(!_enabled[last] && module > 0)
|
|
{
|
|
if (has_module(module))
|
|
_enabled.set(last);
|
|
module = list.get_int();
|
|
}
|
|
}
|
|
else
|
|
_enabled.set(last, TRUE);
|
|
// _enabled.set(last, module_enabled(action));
|
|
}
|
|
_first[++_max] = _menu.items();
|
|
}
|
|
|
|
int TMenu_application::find_menu(const char* s) const
|
|
{
|
|
TString str(s); str.upper();
|
|
int found = -1;
|
|
|
|
for (int i = 0; i < _menu.items(); i++)
|
|
{
|
|
if (_enabled[i])
|
|
{
|
|
TToken_string& l = (TToken_string&)_menu[i];
|
|
const int m = l.get_int(0);
|
|
if (m != _level)
|
|
{
|
|
TString v(l.get()); v.upper();
|
|
|
|
if (v.find(str) >= 0)
|
|
{
|
|
found = i;
|
|
if (isalpha(l.get_char())) break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
bool TMenu_application::menu_item_handler(TMask_field&f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
_last_button = f.dlg();
|
|
_find_button = FALSE;
|
|
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())
|
|
{
|
|
_last_button = app().find_menu(v);
|
|
if (_last_button >= 0)
|
|
{
|
|
_find_button = TRUE;
|
|
f.set_focusdirty(FALSE);
|
|
return f.mask().stop_run(K_AUTO_ENTER);
|
|
}
|
|
else
|
|
{
|
|
beep();
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void TMenu_application::reload_images()
|
|
{
|
|
for (int id = _images.last(); id >= 0; id--)
|
|
{
|
|
TImage* i = (TImage*)_images.objptr(id);
|
|
if (i)
|
|
{
|
|
TString n(16); n.format("ba%02d.bmp", id);
|
|
i->load(n);
|
|
i->convert_transparent_color(MASK_BACK_COLOR);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int TMenu_application::do_level()
|
|
{
|
|
const int first = _first[_level];
|
|
const int last = _first[_level+1];
|
|
TToken_string& row = (TToken_string&)_menu[first];
|
|
const TString80 head(row.get(1));
|
|
|
|
const int width = 78;
|
|
const int height = 18;
|
|
const int bwidth = 20;
|
|
short id = (short)row.get_int();
|
|
|
|
if (_images.objptr(id) == NULL)
|
|
{
|
|
char* n = format("ba%02d.bmp", id);
|
|
if (id > 0 && !fexist(n))
|
|
n = format("ba%02d.bmp", id = 0);
|
|
|
|
TImage* image = new TImage(n);
|
|
image->convert_transparent_color(MASK_BACK_COLOR);
|
|
_images.add(image, id);
|
|
}
|
|
|
|
TPicture_mask menu(head, width, height, (TImage&)_images[id]);
|
|
_mask = &menu;
|
|
|
|
const int x = width / 2;
|
|
int y = 1;
|
|
|
|
for (int i = first+1; i < last; i++, y++)
|
|
{
|
|
TToken_string& row = (TToken_string&)_menu[i];
|
|
TString80 item(row.get(1));
|
|
if (isdigit(*row.get())) item << "...";
|
|
menu.add_static(-1, 0, item, x+4, y);
|
|
const short id = 100+y;
|
|
menu.add_button(id, 0, "", x, y, 1, 1, "", BMP_STOPREC);
|
|
menu.set_handler(id, menu_item_handler);
|
|
if (!_enabled[i]) menu.disable(id);
|
|
}
|
|
menu.add_static(-1, 0, "Cerca", 1,-3);
|
|
menu.add_string(DLG_USER, 0, "", -12, -3, 50, "", bwidth+1);
|
|
menu.set_handler(DLG_USER, menu_find_handler);
|
|
|
|
menu.add_button(first ? DLG_CANCEL : DLG_QUIT, 0,
|
|
first ? "Menu precedente" : "Fine", -22, -1, bwidth, 2);
|
|
if (first)
|
|
menu.add_button(DLG_QUIT, 0, "Fine", -12, -1, bwidth, 2);
|
|
|
|
if (_find_button && _last_button > first)
|
|
menu.first_focus(100+_last_button-first);
|
|
|
|
_last_button = _find_button = 0;
|
|
|
|
const int k = menu.run();
|
|
_mask = NULL;
|
|
|
|
int m = 0;
|
|
switch (k)
|
|
{
|
|
case K_ESC:
|
|
m = -1;
|
|
break;
|
|
case K_QUIT:
|
|
menu.reset();
|
|
m = -2;
|
|
break;
|
|
default:
|
|
if (_find_button)
|
|
m = -1;
|
|
else
|
|
m = first+_last_button-100;
|
|
break;
|
|
}
|
|
return m;
|
|
}
|
|
|
|
|
|
void TMenu_application::test_temp()
|
|
{
|
|
begin_wait();
|
|
|
|
TFilename dir; dir.tempdir(); // Directory temporanea
|
|
dir << '/' << '*';
|
|
TToken_string files(dir);
|
|
const int count = list_files(files);
|
|
|
|
end_wait();
|
|
|
|
if (count > 0 && yesno_box("Cancellare %d file temporane%c in %s?",
|
|
count, (count > 1) ? 'i' : 'o', dir.path()))
|
|
{
|
|
TProgind bar(count, "Cancellazione file temporanei", TRUE, TRUE);
|
|
for (const char* e = files.get(0); e; e = files.get())
|
|
{
|
|
if (bar.iscancelled()) break;
|
|
remove(e);
|
|
bar.addstatus(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TMenu_application::check_user()
|
|
{
|
|
TMask m("ba0100a");
|
|
TLocalisamfile users(LF_USER);
|
|
TString utente(user()), pwd;
|
|
|
|
bool ok = FALSE;
|
|
for (int i = 0 ; i < 3 && !ok; i++)
|
|
{
|
|
if (utente.not_empty() && utente != "PRASSI")
|
|
{
|
|
m.set(F_USER, utente);
|
|
m.first_focus(F_PASSWORD);
|
|
}
|
|
|
|
if (m.run() == K_ESC)
|
|
break;
|
|
|
|
utente = m.get(F_USER);
|
|
users.zero();
|
|
users.put("USERNAME", utente);
|
|
|
|
pwd = "";
|
|
|
|
int err = users.read(_isequal, _lock);
|
|
if (err == NOERR)
|
|
{
|
|
pwd = decode(users.get("PASSWORD"));
|
|
}
|
|
else
|
|
if (utente == "PRASSI")
|
|
{
|
|
pwd = "pr.assi";
|
|
users.zero();
|
|
users.put("USERNAME", utente);
|
|
users.put("USERDESC", utente);
|
|
users.put("PASSWORD", encode(pwd));
|
|
users.write();
|
|
err = users.read(_isequal, _lock);
|
|
}
|
|
|
|
ok = utente.not_empty() && pwd.not_empty() && pwd == m.get(F_PASSWORD);
|
|
|
|
if (ok)
|
|
{
|
|
ok = !users.get_bool("CONNECTED");
|
|
if (!ok)
|
|
{
|
|
ok = yesno_box("L'utente %s risulta essere gia' collegato\n"
|
|
"Si desidera continuare ugualmente?", (const char*)utente);
|
|
}
|
|
if (ok)
|
|
user() = utente;
|
|
}
|
|
else
|
|
{
|
|
error_box("Utente e/o password errata:\nfare attenzione alle maiuscole");
|
|
m.set(F_PASSWORD,"");
|
|
}
|
|
|
|
if (err == NOERR)
|
|
{
|
|
if (ok)
|
|
{
|
|
users.put("CONNECTED", "X");
|
|
users.rewrite();
|
|
|
|
enable_menu_item(M_FONT);
|
|
|
|
customize_colors(); // Aggiorna set di colori
|
|
xvt_dwin_invalidate_rect(TASK_WIN, NULL); // Ridisegna sfondo
|
|
}
|
|
else
|
|
users.read(_isequal, _unlock);
|
|
}
|
|
}
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
if (ok && utente != "PRASSI")
|
|
{
|
|
TDDE dde;
|
|
if (dde.initiate("PROGMAN", "PROGMAN"))
|
|
{
|
|
dde.execute("[ReplaceItem(PR.A.S.S.I.)]");
|
|
TString cmd(80);
|
|
cmd << "[AddItem(" << argv(0) << " /u" << utente << ",PR.A.S.S.I.)]";
|
|
dde.execute(cmd);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu_application::create()
|
|
{
|
|
TApplication::create();
|
|
if (!check_user()) return FALSE;
|
|
set_perms();
|
|
test_temp();
|
|
|
|
TScanner scanner("prassi.aut");
|
|
|
|
for (int aut = 0; scanner.line() != ""; aut++)
|
|
_modules.add(scanner.token());
|
|
|
|
load_menu();
|
|
dispatch_e_menu(MENU_ITEM(1));
|
|
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();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMenu_application::main_loop()
|
|
{
|
|
int refarray[256];
|
|
memset(refarray, 0, sizeof(refarray));
|
|
|
|
int i = 0;
|
|
|
|
_level = 0;
|
|
while (i >= 0)
|
|
{
|
|
const int m = do_level();
|
|
if (m >= 0)
|
|
{
|
|
TToken_string& row = (TToken_string&)_menu[m];
|
|
const TFilename option(row.get(2));
|
|
|
|
if (option.not_empty())
|
|
{
|
|
bool ok = TRUE;
|
|
const int l = atoi(option);
|
|
if (l > 0 && l < MAXLEVEL)
|
|
{
|
|
const TString16 flags(row.get());
|
|
if (flags.find('F') >= 0)
|
|
ok = set_firm();
|
|
if (ok)
|
|
{
|
|
refarray[i++] = _level;
|
|
if (l < _max) _level = l;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TString16 flags(row.get());
|
|
if (flags.find('P') >= 0)
|
|
{
|
|
TMask mask("ba0100a");
|
|
mask.disable(F_USER);
|
|
mask.set(F_USER, "SERVIZIO");
|
|
ok = FALSE;
|
|
if (mask.run() == K_ENTER)
|
|
{
|
|
const TDate oggi(TODAY);
|
|
TString16 pwd; pwd << "PRASSI" << (oggi.month() + oggi.day());
|
|
ok = pwd == mask.get(F_PASSWORD);
|
|
}
|
|
if (!ok) error_box("Password di servizio errata!\nAccesso negato.");
|
|
}
|
|
if (ok)
|
|
{
|
|
const TString16 module(cmd2name(option));
|
|
if (get_firm() == 0 && module.compare("cg", 2, TRUE) == 0) // Chiede ditta se necessario
|
|
set_firm();
|
|
prefix().set(NULL); // Chiude prefix
|
|
TFilename opt_cmd(option);
|
|
#if XVT_OS == XVT_OS_WIN
|
|
opt_cmd.lower();
|
|
#endif
|
|
bool maintenance_app = (opt_cmd == "ba1 -0" || opt_cmd == "ba1");
|
|
TExternal_app a(option);
|
|
a.run();
|
|
if (maintenance_app)
|
|
{
|
|
FILE* fp;
|
|
char line1[16],line2[16];
|
|
if (opt_cmd == "ba1") opt_cmd << " -0";
|
|
opt_cmd << " C";
|
|
|
|
while (fexist("conv.his"))
|
|
{
|
|
fp = fopen("conv.his","r");
|
|
fgets(line1,15,fp);
|
|
fclose(fp);
|
|
// Ora aspetta...
|
|
time_t old_time ;
|
|
time( &old_time) ;
|
|
while ( time( (time_t *) 0 ) <= old_time ) do_events();
|
|
TExternal_app auto_conv(opt_cmd);
|
|
auto_conv.run();
|
|
fp = fopen("conv.his","r");
|
|
if (fp != NULL)
|
|
{
|
|
fgets(line2,15,fp);
|
|
fclose(fp);
|
|
}
|
|
else strcpy(line2,"");
|
|
if (strcmp(line1,line2) == 0)
|
|
if (!yesno_box("La conversione non sembra procedere. Continuo?"))
|
|
break;
|
|
}
|
|
}
|
|
prefix().set("DEF"); // Aggiorna prefix
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m < -1) break;
|
|
if (_find_button)
|
|
{
|
|
TToken_string& row = (TToken_string&)_menu[_last_button];
|
|
_level = row.get_int(0);
|
|
}
|
|
else
|
|
{
|
|
_level = (i > 0) ? refarray[--i] : 0;
|
|
if (_level == 0) i = 0;
|
|
}
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_application::choose_colors()
|
|
{
|
|
TColor_mask cm;
|
|
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)
|
|
{
|
|
_last_button = 100;
|
|
_mask->stop_run(K_AUTO_ENTER);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMenu_application::menu(MENU_TAG mt)
|
|
{
|
|
bool ok = TRUE;
|
|
switch (mt)
|
|
{
|
|
case MENU_ITEM(1): ok = main_loop(); break;
|
|
case MENU_ITEM(2): choose_colors(); break;
|
|
default: break;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TApplication::check_parameters(argc, argv);
|
|
const char* menu = (argc < 2) ? "prassi.mnu" : argv[1];
|
|
|
|
TMenu_application ma(menu);
|
|
ma.run(argc, argv, "Menu Principale");
|
|
return TRUE;
|
|
}
|