202b3aea6c
Inserita maschera di avvertimento Disabilitato il cambio ditta git-svn-id: svn://10.65.10.50/trunk@5686 c028cbd2-c16b-5b4b-a496-9718f37d4682
1720 lines
40 KiB
C++
Executable File
1720 lines
40 KiB
C++
Executable File
#define STRICT
|
|
#define XVT_INCL_NATIVE
|
|
|
|
#include <xi.h>
|
|
|
|
#include <applicat.h>
|
|
#include <colors.h>
|
|
#include <config.h>
|
|
#include <execp.h>
|
|
#include <msksheet.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <stack.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
|
|
#include <extcdecl.h> // CGetPrawinName
|
|
|
|
#include <nditte.h>
|
|
|
|
#include "ba0.h"
|
|
#include "ba0100a.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Picture Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPicture_mask : public TMask
|
|
{
|
|
TImage& _image;
|
|
|
|
protected: // TMask
|
|
virtual void update();
|
|
|
|
public:
|
|
virtual bool stop_run(KEY key) { return TWindow::stop_run(key); }
|
|
|
|
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; field(101).get_rect(cli);
|
|
const int topx = cli.left;
|
|
|
|
field(DLG_USER).get_rect(cli);
|
|
const int topy = cli.top;
|
|
|
|
const double ratiox = double(topx) / _image.width();
|
|
const double ratioy = double(topy) / _image.height();
|
|
const double ratio = min(ratiox, ratioy);
|
|
const int maxx = int(ratio * _image.width());
|
|
const int maxy = int(ratio * _image.height());
|
|
|
|
RCT dst; xvt_rect_set(&dst, 1, 1, maxx, maxy);
|
|
|
|
if (xvt_dwin_is_update_needed(win(), &dst))
|
|
_image.draw(win(), dst);
|
|
|
|
xvt_vobj_get_client_rect(win(), &cli);
|
|
cli.bottom--;
|
|
cli.right--;
|
|
xvt_draw_rect(win(), cli, MASK_LIGHT_COLOR, MASK_DARK_COLOR, 1);
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Color Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TColor_mask : public TMask
|
|
{
|
|
TAssoc_array _color;
|
|
|
|
protected: // TMask
|
|
virtual void update();
|
|
virtual bool stop_run(KEY key) { return TWindow::stop_run(key); }
|
|
|
|
// @cmember Converte le coordinate logiche (caratteri) in coordinate fisiche (pixel)
|
|
virtual PNT log2dev(long x, long y) const;
|
|
|
|
protected:
|
|
static bool color_handler(TMask_field& f, KEY k);
|
|
static bool azzera_handler(TMask_field& f, KEY k);
|
|
|
|
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() { }
|
|
};
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
PNT TColor_mask::log2dev(long x, long y) const
|
|
{
|
|
PNT p = { int(y * XI_FU_MULTIPLE), int(x * XI_FU_MULTIPLE) };
|
|
|
|
XI_OBJ* itf = xi_get_itf(win());
|
|
xi_fu_to_pu(itf, &p, 1);
|
|
|
|
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 = 7;
|
|
const int w = 32;
|
|
const int h = 9;
|
|
|
|
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("Focus"));
|
|
set_brush(b = get_color_entry("FocusBack"));
|
|
frame(x+3, y+3, x+w-3, y+4, 0);
|
|
set_color(p, b);
|
|
stringat(x+4, y+3, "Campo attivo");
|
|
|
|
set_pen(p = get_color_entry("Disabled"));
|
|
set_brush(b = get_color_entry("DisabledBack"));
|
|
frame(x+3, y+5, x+w-3, y+6, 0);
|
|
set_color(p, b);
|
|
stringat(x+4, y+5, "Campo disabilitato");
|
|
|
|
set_pen(p = get_color_entry("ButtonLight"));
|
|
set_brush(b = get_color_entry("ButtonBack"));
|
|
frame(x+3, y+7, x+w-3, y+8, 0);
|
|
set_color(get_color_entry("Normal"), b);
|
|
stringat(x+4, y+7, "Bottone normale");
|
|
}
|
|
|
|
void TColor_mask::save_colors()
|
|
{
|
|
TConfig colors(CONFIG_USER, "Colors");
|
|
FOR_EACH_ASSOC_STRING(_color, obj, key, str)
|
|
colors.set(key, str);
|
|
}
|
|
|
|
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(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",
|
|
"ButtonBack", "ButtonLight", "ButtonDark"
|
|
};
|
|
const int i = cid - 101;
|
|
CHECK(i >= 0 && i < 12, "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,
|
|
COLOR_LTGRAY, COLOR_WHITE, COLOR_GRAY};
|
|
|
|
const int i = cid - 101;
|
|
CHECK(i >= 0 && i < 12, "Invalid color id");
|
|
return color[i];
|
|
}
|
|
|
|
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_entry(name);
|
|
col = choose_color(col, m.win());
|
|
ok = col != COLOR_INVALID;
|
|
if (ok)
|
|
{
|
|
m.set_color_entry(name, col);
|
|
XVT_PALETTE wp = xvt_vobj_get_palet(m.win());
|
|
if (wp != NULL)
|
|
{
|
|
XVT_PALETTE up = xvt_palet_create(XVT_PALETTE_USER, 0);
|
|
if (up != NULL)
|
|
{
|
|
const int MAXPAL = 256;
|
|
COLOR color[MAXPAL];
|
|
const int n = xvt_palet_get_colors(wp, color, MAXPAL);
|
|
if (n < MAXPAL) color[n] = col;
|
|
xvt_palet_set_tolerance(up, xvt_palet_get_tolerance(wp));
|
|
xvt_palet_add_colors(up, color, n+1);
|
|
xvt_vobj_set_palet(m.win(), up);
|
|
xvt_palet_destroy(wp);
|
|
}
|
|
}
|
|
m.stop_run(K_CTRL + 'R');
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Menu mamnagement
|
|
///////////////////////////////////////////////////////////
|
|
|
|
static int get_next_string(const char* s, int from, TString& str, char& brace)
|
|
{
|
|
if (from < 0)
|
|
return -1;
|
|
|
|
char closing = '\0';
|
|
int start = 0;
|
|
|
|
for (int i = from; s[i]; i++)
|
|
{
|
|
if (s[i] == closing)
|
|
{
|
|
char* fine = (char*)(s + i);
|
|
const char old = *fine;
|
|
*fine = '\0';
|
|
str = s + start;
|
|
*fine = old;
|
|
return i+1;
|
|
}
|
|
|
|
if (!closing)
|
|
{
|
|
switch(s[i])
|
|
{
|
|
case '\'':
|
|
case '"' : closing = s[i]; break;
|
|
case '<' : closing = '>' ; break;
|
|
case '[' : closing = ']' ; break;
|
|
default : break;
|
|
}
|
|
if (closing)
|
|
{
|
|
start = i+1;
|
|
brace = s[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
class TSubmenu;
|
|
class TMenu;
|
|
|
|
class TMenuitem : public TObject
|
|
{
|
|
TSubmenu* _submenu;
|
|
TString _caption, _action;
|
|
char _type;
|
|
COLOR _color;
|
|
bool _enabled : 1;
|
|
bool _firm : 1;
|
|
bool _password : 1;
|
|
|
|
protected:
|
|
bool perform_submenu() const;
|
|
bool perform_program() const;
|
|
|
|
public:
|
|
virtual bool ok() { return _caption.not_empty(); }
|
|
|
|
const TString& caption() const { return _caption; }
|
|
const TString& action() const { return _action; }
|
|
bool enabled() const;
|
|
bool disabled() const { return !enabled(); }
|
|
|
|
COLOR color() const { return enabled() ? _color : DISABLED_COLOR; }
|
|
|
|
bool is_submenu() const { return _type == '[' && _action.not_empty(); }
|
|
bool is_program() const { return _type != '[' && _action.not_empty(); }
|
|
bool perform() const;
|
|
|
|
TSubmenu& submenu() const { return *_submenu; }
|
|
TMenu& menu() const;
|
|
|
|
void create(const char* t);
|
|
|
|
TMenuitem(TSubmenu* sm);
|
|
virtual ~TMenuitem() { }
|
|
};
|
|
|
|
class TSubmenu : public TObject
|
|
{
|
|
TMenu* _menu;
|
|
TString _name;
|
|
TString _caption;
|
|
TFilename _picture;
|
|
TArray _items;
|
|
bool _enabled : 1;
|
|
bool _firm : 1;
|
|
|
|
public:
|
|
void read(TScanner& scanner);
|
|
|
|
TMenu& menu() const { return *_menu; }
|
|
int find_string(const char* str) const;
|
|
|
|
TMenuitem& item(int i) { return (TMenuitem&)_items[i]; }
|
|
const TMenuitem& item(int i) const { return (const TMenuitem&)_items[i]; }
|
|
const TMenuitem& operator[](int i) const { return item(i); }
|
|
|
|
const TString& name() const { return _name; }
|
|
const TString& caption() const { return _caption; }
|
|
const TString& picture() const { return _picture; }
|
|
int items() const { return _items.items(); }
|
|
|
|
bool query_firm() const { return _firm; }
|
|
bool enabled() const { return _enabled; }
|
|
bool disabled() const { return !enabled(); }
|
|
|
|
bool perform(int i);
|
|
|
|
TSubmenu(TMenu* menu, const char* name);
|
|
virtual ~TSubmenu() { }
|
|
};
|
|
|
|
class TMenu : public TAssoc_array
|
|
{
|
|
TSubmenu* _current;
|
|
int _item;
|
|
TStack _stack;
|
|
|
|
TAssoc_array _images;
|
|
|
|
TAssoc_array _modules;
|
|
|
|
public: // TObject
|
|
virtual bool ok() const { return _current != NULL; }
|
|
|
|
public:
|
|
bool read(const char* name); // First call
|
|
bool read(const char* name, TString& root);
|
|
|
|
TSubmenu& current() const { return *_current; }
|
|
TSubmenu* find(const char* name) const { return (TSubmenu*)objptr(name); }
|
|
bool jumpto(TSubmenu *next);
|
|
|
|
TSubmenu& pop();
|
|
bool at_top() const { return _stack.count() == 0; }
|
|
|
|
void select(int i) { _item = i; }
|
|
int selected() const { return _item; }
|
|
|
|
bool perform();
|
|
TSubmenu* find_string(const char* str);
|
|
|
|
TImage& image(const char* name);
|
|
void reload_images();
|
|
|
|
bool has_module(const char* mod);
|
|
|
|
TMenu() : _current(NULL), _item(0) { }
|
|
TMenu(const char* name) { read(name); }
|
|
virtual ~TMenu() { }
|
|
};
|
|
|
|
TMenuitem::TMenuitem(TSubmenu* sm)
|
|
: _submenu(sm),
|
|
_enabled(TRUE), _firm(FALSE), _password(FALSE),
|
|
_color(NORMAL_COLOR)
|
|
{ }
|
|
|
|
TMenu& TMenuitem::menu() const
|
|
{ return _submenu->menu(); }
|
|
|
|
void TMenuitem::create(const char* t)
|
|
{
|
|
TString16 flags;
|
|
char brace;
|
|
int start = 0;
|
|
start = get_next_string(t, start, _caption, brace);
|
|
start = get_next_string(t, start, _action, _type);
|
|
start = get_next_string(t, start, flags, brace);
|
|
|
|
for (int i = flags.len()-1; i >= 0; i--)
|
|
{
|
|
switch(toupper(flags[i]))
|
|
{
|
|
case 'D': _enabled = FALSE; break;
|
|
case 'F': _firm = TRUE; break;
|
|
case 'P': _password = TRUE; break;
|
|
default : break;
|
|
}
|
|
}
|
|
|
|
if (_type == '<')
|
|
{
|
|
if (_action.find('.') < 0)
|
|
_action << ".men";
|
|
menu().read(_action, _action);
|
|
_type = '[';
|
|
if (_action.empty())
|
|
_enabled = FALSE;
|
|
}
|
|
|
|
if (_enabled && is_program())
|
|
_enabled = menu().has_module(_action);
|
|
}
|
|
|
|
bool TMenuitem::enabled() const
|
|
{
|
|
bool yes = _enabled;
|
|
if (yes)
|
|
{
|
|
if (is_submenu())
|
|
{
|
|
TSubmenu* mnu = menu().find(_action);
|
|
yes = mnu && mnu->enabled();
|
|
}
|
|
else
|
|
{
|
|
const int endname = _action.find(' ');
|
|
TFilename name(endname > 0 ? _action.left(endname) : _action);
|
|
const char* ext[] = { "exe", "pif", "com", "bat", NULL };
|
|
for (int e = 0; ext[e]; e++)
|
|
{
|
|
name.ext(ext[e]);
|
|
if (fexist(name))
|
|
break;
|
|
}
|
|
yes = ext[e] != NULL;
|
|
if (!yes)
|
|
((TMenuitem*)this)->_enabled = FALSE;
|
|
}
|
|
}
|
|
return yes;
|
|
}
|
|
|
|
bool TMenuitem::perform_submenu() const
|
|
{
|
|
TSubmenu* mnu = menu().find(_action);
|
|
bool ok = mnu != NULL && mnu->enabled();
|
|
if (ok)
|
|
{
|
|
/* Cristina 6/11/97
|
|
if (mnu->items() == 1)
|
|
{
|
|
if (mnu->query_firm())
|
|
ok = main_app().set_firm();
|
|
if (ok)
|
|
{
|
|
const TMenuitem& mi = mnu->item(0);
|
|
ok = mi.enabled() && mi.perform();
|
|
}
|
|
}
|
|
else
|
|
*/
|
|
menu().jumpto(mnu);
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TMenuitem::perform_program() const
|
|
{
|
|
bool ok = TRUE;
|
|
|
|
if (_password)
|
|
{
|
|
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 (_firm && main_app().get_firm() == 0)
|
|
#ifdef _DEMO_
|
|
ok = main_app().set_firm(1);
|
|
#else
|
|
ok = main_app().set_firm();
|
|
#endif
|
|
|
|
if (ok)
|
|
{
|
|
prefix().set(NULL); // Chiude prefix
|
|
const bool maintenance_app = _action.compare("ba1", 3, TRUE) == 0;
|
|
TExternal_app a(_action);
|
|
a.run(FALSE,3);
|
|
if (maintenance_app)
|
|
{
|
|
char line1[16],line2[16];
|
|
|
|
while (fexist("conv.his"))
|
|
{
|
|
FILE* 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("ba1 -0 -C");
|
|
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
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TMenuitem::perform() const
|
|
{
|
|
bool ok = enabled();
|
|
if (ok)
|
|
{
|
|
if (is_submenu())
|
|
ok = perform_submenu();
|
|
else
|
|
ok = perform_program();
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
TSubmenu::TSubmenu(TMenu* menu, const char* name)
|
|
: _menu(menu), _name(name), _enabled(TRUE), _firm(FALSE), _items(12)
|
|
{
|
|
}
|
|
|
|
void TSubmenu::read(TScanner& scanner)
|
|
{
|
|
while (scanner.ok())
|
|
{
|
|
TString& line = scanner.line();
|
|
if (line.empty())
|
|
break;
|
|
if (line[0] == '[')
|
|
{
|
|
scanner.push();
|
|
break;
|
|
}
|
|
|
|
char brace;
|
|
if (line.compare("Caption", 7, TRUE) == 0)
|
|
get_next_string(line, 8, _caption, brace); else
|
|
if (line.compare("Module", 6, TRUE) == 0)
|
|
{
|
|
const int equal = line.find('=');
|
|
if (equal > 0)
|
|
{
|
|
bool disable = TRUE;
|
|
TToken_string mod(line.mid(equal+1, -1), ',');
|
|
// for (const char* cod = mod.get(0); cod; cod = mod.get())
|
|
FOR_EACH_TOKEN(mod, cod)
|
|
{
|
|
const int code = atoi(cod);
|
|
if (code == 0 || main_app().has_module(code))
|
|
{
|
|
disable = FALSE;
|
|
break;
|
|
}
|
|
}
|
|
if (disable)
|
|
_enabled = FALSE;
|
|
}
|
|
} else
|
|
if (line.compare("Picture", 7, TRUE) == 0)
|
|
get_next_string(line, 8, _picture, brace); else
|
|
if (line.compare("Flags", 5, TRUE) == 0)
|
|
{
|
|
TString16 flags;
|
|
get_next_string(line, 6, flags, brace);
|
|
if (flags.find('D') >= 0)
|
|
_enabled = FALSE;
|
|
if (flags.find('F') >= 0)
|
|
_firm = TRUE;
|
|
} else
|
|
if (line.compare("Item", 4, TRUE) == 0)
|
|
{
|
|
TMenuitem* item = new TMenuitem(this);
|
|
_items.add(item);
|
|
item->create(line);
|
|
}
|
|
}
|
|
}
|
|
|
|
int TSubmenu::find_string(const char* str) const
|
|
{
|
|
bool found = FALSE;
|
|
|
|
TString caption;
|
|
caption = _caption; caption.upper();
|
|
if (caption.find(str) >= 0)
|
|
found = TRUE;
|
|
|
|
for (int i = 0; i < items(); i++)
|
|
{
|
|
const TMenuitem& mi = item(i);
|
|
caption = item(i).caption();
|
|
caption.upper();
|
|
const bool match = caption.find(str) >= 0;
|
|
found = match && mi.is_program() && mi.enabled();
|
|
if (found)
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
bool TSubmenu::perform(int i)
|
|
{
|
|
bool ok = i >= 0 && i < items();
|
|
if (ok)
|
|
ok = item(i).perform();
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu::read(const char* name, TString& root)
|
|
{
|
|
TString str(255);
|
|
bool first = TRUE;
|
|
|
|
TScanner scanner(name);
|
|
while (scanner.ok())
|
|
{
|
|
const TString& line = first ? scanner.line() : scanner.pop();
|
|
if (line.empty())
|
|
break;
|
|
|
|
char brace = '[';
|
|
get_next_string(line, 0, str, brace);
|
|
|
|
if (first)
|
|
{
|
|
root = str;
|
|
first = FALSE;
|
|
}
|
|
|
|
if (objptr(str) == NULL)
|
|
{
|
|
TSubmenu* mnu = new TSubmenu(this, str);
|
|
mnu->read(scanner);
|
|
add(str, mnu);
|
|
}
|
|
else
|
|
break; // Menu gia' caricato!
|
|
}
|
|
|
|
return first == FALSE;
|
|
}
|
|
|
|
bool TMenu::read(const char* name)
|
|
{
|
|
TString root(50);
|
|
bool ok = read(name, root);
|
|
if (ok && _current == NULL)
|
|
{
|
|
_current = find(root);
|
|
_item = 0;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu::jumpto(TSubmenu* next)
|
|
{
|
|
if (next && next->disabled())
|
|
next = NULL;
|
|
|
|
if (next)
|
|
{
|
|
if (next->query_firm())
|
|
{
|
|
#ifdef _DEMO_
|
|
main_app().set_firm(1);
|
|
#else
|
|
if (!main_app().set_firm())
|
|
next = NULL;
|
|
#endif
|
|
}
|
|
if (next)
|
|
{
|
|
if (_stack.count() >= 32)
|
|
_stack.destroy_base();
|
|
_stack.push(_current->name());
|
|
_current = next;
|
|
_item = 0;
|
|
}
|
|
}
|
|
|
|
return next != NULL;
|
|
}
|
|
|
|
TSubmenu& TMenu::pop()
|
|
{
|
|
TSubmenu* sm = _current;
|
|
if (!at_top())
|
|
{
|
|
TString& name = (TString&)_stack.pop();
|
|
sm = (TSubmenu*)objptr(name);
|
|
}
|
|
if (sm)
|
|
{
|
|
_current = sm;
|
|
_item = 0;
|
|
}
|
|
return *sm;
|
|
}
|
|
|
|
TSubmenu* TMenu::find_string(const char* str)
|
|
{
|
|
TString upstr(str);
|
|
upstr.upper();
|
|
|
|
restart();
|
|
for (TSubmenu* sm = (TSubmenu*)get(); sm; sm = (TSubmenu*)get())
|
|
{
|
|
if (sm != _current && sm->enabled())
|
|
{
|
|
int item = sm->find_string(upstr);
|
|
if (item >= 0)
|
|
{
|
|
jumpto(sm);
|
|
_item = item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return sm;
|
|
}
|
|
|
|
bool TMenu::perform()
|
|
{
|
|
bool ok = _current != NULL;
|
|
if (ok)
|
|
ok = _current->perform(_item);
|
|
return ok;
|
|
}
|
|
|
|
TImage& TMenu::image(const char* name)
|
|
{
|
|
TImage* image = (TImage*)_images.objptr(name);
|
|
if (image == NULL)
|
|
{
|
|
if (fexist(name))
|
|
{
|
|
image = new TImage(name);
|
|
image->convert_transparent_color(MASK_BACK_COLOR);
|
|
_images.add(name, image);
|
|
}
|
|
else
|
|
image = (TImage*)_images.objptr("ba00.bmp");
|
|
}
|
|
CHECK(image, "No images");
|
|
return *image;
|
|
}
|
|
|
|
void TMenu::reload_images()
|
|
{
|
|
_images.restart();
|
|
for (THash_object* h = _images.get_hashobj(); h; h = _images.get_hashobj())
|
|
{
|
|
const char* name = h->key();
|
|
TImage& i = (TImage&)h->obj();
|
|
i.load(name);
|
|
i.convert_transparent_color(MASK_BACK_COLOR);
|
|
}
|
|
}
|
|
|
|
bool TMenu::has_module(const char* mod)
|
|
{
|
|
TString16 key;
|
|
|
|
if (_modules.items() == 0)
|
|
{
|
|
TScanner scanner("prassi.aut");
|
|
TString16 val;
|
|
for (int aut = 0; scanner.line() != ""; aut++)
|
|
{
|
|
key.strncpy(scanner.token(), 2);
|
|
key.lower();
|
|
val.format("%d", aut);
|
|
_modules.add(key, val);
|
|
}
|
|
}
|
|
|
|
key.strncpy(mod, 2);
|
|
key.lower();
|
|
|
|
int module = 0;
|
|
TString* cod = (TString*)_modules.objptr(key);
|
|
if (cod) module = atoi(*cod);
|
|
return main_app().has_module(module);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Menu application
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TMenu_application : public TApplication
|
|
{
|
|
const char* _name;
|
|
|
|
TMenu _menu;
|
|
|
|
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);
|
|
virtual long handler(WINDOW win, EVENT* ep);
|
|
|
|
protected:
|
|
bool main_loop();
|
|
void test_temp();
|
|
void load_menu();
|
|
int do_level();
|
|
bool check_user();
|
|
static bool menu_item_handler(TMask_field&f, KEY k);
|
|
static bool menu_find_handler(TMask_field&f, KEY k);
|
|
|
|
bool choose_colors();
|
|
bool choose_editors();
|
|
bool choose_study();
|
|
|
|
public:
|
|
void reload_images() { _menu.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::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())
|
|
{
|
|
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 width = 78;
|
|
const int height = 18;
|
|
const int bwidth = 20;
|
|
|
|
TImage& image = _menu.image(curr.picture());
|
|
|
|
TPicture_mask mask(curr.caption(), width, height, image);
|
|
_mask = &mask;
|
|
|
|
const int x = width / 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.find("...") < 0)
|
|
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);
|
|
}
|
|
|
|
mask.add_static(DLG_NULL, 0, "Cerca", 1,-3);
|
|
TEdit_field& ef = mask.add_string(DLG_USER, 0, "", -12, -3, 50, "", bwidth+1);
|
|
ef.set_handler(menu_find_handler);
|
|
|
|
const bool top = _menu.at_top();
|
|
TButton_field& bf = mask.add_button(DLG_QUIT, 0, "Fine", top ? -22 : -12, -1, bwidth, 2);
|
|
if (!top)
|
|
{
|
|
RCT e_rct; ef.get_rect(e_rct); // Rettangolo cerca
|
|
RCT b_rct; bf.get_rect(b_rct); // Rettangolo bottone
|
|
b_rct.left = e_rct.left-2; // Aggiusta rettangolo
|
|
b_rct.right = e_rct.right+2;
|
|
bf.set_rect(b_rct); // Modifica bottone
|
|
mask.add_button(DLG_CANCEL, 0, "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("Cancellare %d file temporane%c in %s?",
|
|
count, (count > 1) ? 'i' : 'o', dir.path()))
|
|
{
|
|
TProgind bar(count, "Cancellazione file temporanei", TRUE, TRUE);
|
|
for (int i = count-1; i >= 0; i--)
|
|
{
|
|
if (bar.iscancelled()) break;
|
|
const char* e = files.row(i);
|
|
::remove(e);
|
|
bar.addstatus(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef DBG
|
|
|
|
HIDDEN bool pwd_handler(TMask_field& fld, KEY key)
|
|
{
|
|
if (key == K_F8)
|
|
{
|
|
TMask& m = fld.mask();
|
|
m.set(F_USER, "PRASSI");
|
|
m.set(F_PASSWORD, "pr.assi");
|
|
m.stop_run(K_ENTER);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
#endif
|
|
|
|
bool TMenu_application::check_user()
|
|
{
|
|
TMask m("ba0100a");
|
|
#ifdef DBG
|
|
m.set_handler(F_USER, pwd_handler);
|
|
m.set_handler(F_PASSWORD, pwd_handler);
|
|
#endif
|
|
|
|
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);
|
|
}
|
|
|
|
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)
|
|
{
|
|
users.put("USERNAME", "PRASSI");
|
|
users.read(_isequal);
|
|
if (users.get("AUTSTR") == "CONVERTING")
|
|
{
|
|
TString msg = "E' in corso una conversione archivi:\n";
|
|
if (utente == "PRASSI")
|
|
{
|
|
msg << "Si desidera continuare ugualmente?";
|
|
ok = yesno_box(msg);
|
|
}
|
|
else
|
|
{
|
|
msg << "Accesso negato.";
|
|
ok = error_box(msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ok)
|
|
{
|
|
user() = utente;
|
|
ok = get_serial_number(name()) >= 0;
|
|
if (!ok)
|
|
error_box("E' stato superato il numero massimo di utenti collegati");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
error_box("Utente e/o password errata:\nfare attenzione alle maiuscole");
|
|
m.set(F_PASSWORD,"");
|
|
}
|
|
|
|
if (err == NOERR)
|
|
{
|
|
if (ok)
|
|
{
|
|
users.put("USERNAME", utente);
|
|
users.read(_isequal, _lock);
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
if (ok && utente != "PRASSI")
|
|
WritePrivateProfileString("Main", "User", utente, CGetPrawinName());
|
|
#endif
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu_application::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
#ifdef _DEMO_
|
|
{
|
|
TMask w("Attenzione", 1, 80, 14);
|
|
|
|
w.add_static(DLG_NULL, 0 ,"@bAttenzione" , 35 , 1);
|
|
w.add_static(DLG_NULL, 0 ,"@bQuesto programma e' in versione dimostrativa." , 1 , 3);
|
|
w.add_static(DLG_NULL, 0 ,"@bNon si possono memorizzare date posteriori al 1992" , 1 , 5);
|
|
w.add_static(DLG_NULL, 0 ,"@bcon mese successivo a Marzo." , 1 , 7);
|
|
w.add_static(DLG_NULL, 0 ,"@bIl programma funziona per due ore ogni giorno." , 1 , 9);
|
|
w.add_static(DLG_NULL, 0 ,"@bIl numero di registrazioni e' stato limitato a circa 1000." , 1 , 11);
|
|
w.add_button(DLG_OK, 0, "", -11, -1, 10, 2);
|
|
w.run();
|
|
}
|
|
#endif
|
|
|
|
if (!check_user())
|
|
return FALSE;
|
|
|
|
set_perms();
|
|
test_temp();
|
|
|
|
TWait_cursor hourglass;
|
|
|
|
if (!_menu.ok())
|
|
{
|
|
TFilename menu = (argc() < 2) ? "baprassi" : argv(1);
|
|
menu.ext("men");
|
|
_menu.read(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()
|
|
{
|
|
bool run = TRUE;
|
|
while (run)
|
|
{
|
|
const int m = do_level();
|
|
if (m > 0)
|
|
_menu.perform();
|
|
else
|
|
run = m >= -1;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_application::choose_colors()
|
|
{
|
|
disable_menu_item(M_FONT);
|
|
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(M_FONT);
|
|
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, "ba0");
|
|
|
|
DIRECTORY dir;
|
|
xvt_fsys_get_dir(&dir);
|
|
const int err = xvt_dm_post_file_open(&fs, "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(M_FONT);
|
|
|
|
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(M_FONT);
|
|
|
|
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 (!fexist(path))
|
|
ok = f.error_box("La directory %s non e' uno studio valido!",
|
|
(const char*)f.get());
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu_application::choose_study()
|
|
{
|
|
TMask m("Scelta studio", 1, 60, 6);
|
|
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, "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)
|
|
{
|
|
_mask->close_modal();
|
|
do_events();
|
|
destroy();
|
|
prefix().set_studio(m.get(DLG_USER));
|
|
create();
|
|
}
|
|
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;
|
|
}
|
|
|
|
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;
|
|
case MENU_ITEM(3): choose_editors(); break;
|
|
case MENU_ITEM(4): choose_study(); break;
|
|
default: break;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
HIDDEN bool convert(const char* menuname)
|
|
{
|
|
TString tag(_MAX_FNAME);
|
|
_splitpath(menuname, NULL, NULL, tag.get_buffer(_MAX_FNAME), NULL);
|
|
tag.upper();
|
|
|
|
TFilename outname = tag; outname.ext("men");
|
|
FILE* out = fopen(outname, "w");
|
|
if (out == NULL)
|
|
{
|
|
error_box("Can't write output file %s", (const char*)outname);
|
|
return FALSE;
|
|
}
|
|
|
|
TToken_string line;
|
|
TString256 tmp;
|
|
|
|
int lastid = -1;
|
|
int lastitem = 0;
|
|
|
|
TScanner mnu(menuname);
|
|
while (mnu.ok())
|
|
{
|
|
line = mnu.line();
|
|
if (line.empty())
|
|
break;
|
|
|
|
int menuid = line.get_int(0);
|
|
if (menuid != lastid)
|
|
{
|
|
if (lastid >= 0)
|
|
fputc('\n', out);
|
|
fprintf(out, "[%s_%03d]\n", (const char*)tag, menuid);
|
|
fprintf(out, "Caption = \"%s\"\n", line.get());
|
|
fprintf(out, "Picture = <ba%02d.bmp>\n", line.get_int());
|
|
fprintf(out, "Module = %d\n", line.get_int());
|
|
fputs("Flags = \"\"\n", out);
|
|
|
|
lastid = menuid;
|
|
lastitem = 0;
|
|
}
|
|
else
|
|
{
|
|
tmp.format("Item_%02d = \"%s\", ", ++lastitem, line.get());
|
|
TString256 action = line.get();
|
|
int jump = atoi(action);
|
|
if (jump > 0 && jump < 730)
|
|
{
|
|
action.format("[%s_%03d]", (const char*)tag, jump);
|
|
tmp << action;
|
|
}
|
|
else
|
|
{
|
|
if (action == "DISABLED")
|
|
action.cut(0);
|
|
|
|
tmp << '\"' << action << "\", \"";
|
|
|
|
if (action.empty())
|
|
tmp << 'D';
|
|
|
|
if (action.compare("cg", 2, TRUE) == 0)
|
|
tmp << 'F';
|
|
|
|
const char* mod = line.get(); // Eventuale 'P'assword
|
|
if (mod && *mod == 'P')
|
|
tmp << 'P';
|
|
|
|
tmp << '\"';
|
|
}
|
|
tmp << '\n';
|
|
fputs(tmp, out);
|
|
}
|
|
}
|
|
|
|
fclose(out);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TApplication::check_parameters(argc, argv);
|
|
|
|
if (user().blank())
|
|
{
|
|
char u[16];
|
|
GetPrivateProfileString("Main", "User", "PRASSI", u, sizeof(u), CGetPrawinName());
|
|
user() = u;
|
|
}
|
|
|
|
TFilename menu = (argc < 2) ? "baprassi.men" : argv[1];
|
|
TString ext = menu.ext(); ext.lower();
|
|
|
|
if (ext == "men" && !fexist(menu))
|
|
ext.cut(0);
|
|
|
|
if (ext != "men")
|
|
{
|
|
if (ext.empty())
|
|
menu.ext("mnu");
|
|
TFilename newmenu(menu);
|
|
newmenu.ext("men");
|
|
if (newmenu == "prassi.men")
|
|
newmenu == "baprassi.men";
|
|
if (fexist(menu) && !fexist(newmenu))
|
|
convert(menu);
|
|
menu = newmenu;
|
|
}
|
|
|
|
if (!fexist(menu))
|
|
{
|
|
error_box("Non esiste il menu %s", (const char*)menu);
|
|
exit(1);
|
|
}
|
|
|
|
TMenu_application* ma = new TMenu_application(menu);
|
|
ma->run(argc, argv, "Menu Principale");
|
|
delete ma;
|
|
|
|
exit(0);
|
|
return TRUE;
|
|
}
|