4b004eff90
Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la verione 98.01.04 sul main trunk git-svn-id: svn://10.65.10.50/trunk@6984 c028cbd2-c16b-5b4b-a496-9718f37d4682
2140 lines
48 KiB
C++
Executable File
2140 lines
48 KiB
C++
Executable File
#include <xinclude.h>
|
|
|
|
#include <applicat.h>
|
|
#include <colors.h>
|
|
#include <config.h>
|
|
#include <dongle.h>
|
|
#include <execp.h>
|
|
#include <isam.h>
|
|
#include <msksheet.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <stack.h>
|
|
#include <tree.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
|
|
#include <nditte.h>
|
|
|
|
#include "ba0.h"
|
|
#include "ba0100a.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TPriority_image
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TTimed_image : public TImage
|
|
{
|
|
clock_t _last_time;
|
|
|
|
public:
|
|
clock_t touch() { return _last_time = clock(); }
|
|
clock_t last_time() const { return _last_time; }
|
|
|
|
TTimed_image(const char* name) : TImage(name) { touch(); }
|
|
virtual ~TTimed_image() { }
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Picture Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPicture_mask : public TMask
|
|
{
|
|
TImage* _image;
|
|
|
|
static TString _last_string;
|
|
|
|
protected: // TMask
|
|
virtual void update();
|
|
virtual bool on_key(KEY k);
|
|
|
|
public:
|
|
virtual bool stop_run(KEY key);
|
|
|
|
void set_last_search_string(const char* str) { _last_string = str; }
|
|
void set_image(TImage* image);
|
|
|
|
TPicture_mask(const char* name, int dx, int dy, TImage* image, int x = -1, int y = -1);
|
|
virtual ~TPicture_mask() {}
|
|
};
|
|
|
|
TString TPicture_mask::_last_string;
|
|
|
|
TPicture_mask::TPicture_mask(const char* name, int dx, int dy,
|
|
TImage* image, int x, int y)
|
|
: TMask(name, 1, dx, dy, x, y)
|
|
{
|
|
set_image(image);
|
|
}
|
|
|
|
void TPicture_mask::set_image(TImage* image)
|
|
{
|
|
if (image && image->ok())
|
|
{
|
|
_image = image;
|
|
_image->set_palette(win());
|
|
}
|
|
else
|
|
_image = NULL;
|
|
}
|
|
|
|
bool TPicture_mask::stop_run(KEY key)
|
|
{
|
|
if (key == K_FORCE_CLOSE)
|
|
key = K_QUIT;
|
|
return TWindow::stop_run(key);
|
|
}
|
|
|
|
void TPicture_mask::update()
|
|
{
|
|
if (_image && _image->ok())
|
|
{
|
|
RCT cli;
|
|
field(DLG_USER).get_rect(cli);
|
|
int vy = cli.top;
|
|
|
|
const TMask_field& fld = field(101);
|
|
fld.get_rect(cli);
|
|
int vx = cli.left;
|
|
if (fld.class_id() == CLASS_TREE_FIELD)
|
|
{
|
|
vx = -cli.right;
|
|
::xvt_vobj_get_client_rect(win(), &cli);
|
|
vx += cli.right - CHARX;
|
|
vy = cli.bottom;
|
|
}
|
|
|
|
const double ratiox = double(vx) / _image->width();
|
|
const double ratioy = double(vy) / _image->height();
|
|
const double ratio = min(ratiox, ratioy);
|
|
const int maxx = int(ratio * _image->width());
|
|
const int maxy = int(ratio * _image->height());
|
|
int x = 1;
|
|
int y = 1;
|
|
if (fld.class_id() == CLASS_TREE_FIELD)
|
|
{
|
|
x = cli.right - maxx + 1;
|
|
y = (cli.bottom - maxy) / 2;
|
|
}
|
|
|
|
RCT dst;
|
|
::xvt_rect_set(&dst, x, y, x+maxx-1, y+maxy-1);
|
|
|
|
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, _last_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);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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();
|
|
set(113, color.get_bool("Campi3D"));
|
|
|
|
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());
|
|
#ifdef XI_R4
|
|
xi_fu_to_pu(itf, (XinPoint*)&p, 1);
|
|
#else
|
|
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 = 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);
|
|
colors.set("Campi3D", get_bool(113) ? "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 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_LTGRAY, COLOR_WHITE, COLOR_GRAY,
|
|
COLOR_BLACK, COLOR_WHITE,
|
|
COLOR_BLACK, COLOR_YELLOW,
|
|
COLOR_DKGRAY, COLOR_LTGRAY,
|
|
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;
|
|
bool _reloadmenu : 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;
|
|
|
|
TFilename _default_bmp;
|
|
TString _default_menu;
|
|
|
|
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);
|
|
bool jumpto_root();
|
|
|
|
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), _reloadmenu(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;
|
|
case 'R': _reloadmenu = 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 };
|
|
yes = FALSE;
|
|
for (int e = 0; ext[e]; e++)
|
|
{
|
|
name.ext(ext[e]);
|
|
if (name.exist())
|
|
{
|
|
yes = TRUE;
|
|
break;
|
|
}
|
|
|
|
}
|
|
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_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;
|
|
bool ok = read(name, root);
|
|
if (ok && _current == NULL)
|
|
{
|
|
_default_menu = root;
|
|
_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_
|
|
if (!main_app().set_firm(1))
|
|
next = NULL;
|
|
#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;
|
|
}
|
|
|
|
bool TMenu::jumpto_root()
|
|
{
|
|
TSubmenu* sm = find(_default_menu);
|
|
return jumpto(sm);
|
|
}
|
|
|
|
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)
|
|
{
|
|
TTimed_image* image = (TTimed_image*)_images.objptr(name);
|
|
if (image == NULL)
|
|
{
|
|
if (fexist(name))
|
|
{
|
|
if (_images.items() == 0)
|
|
_default_bmp = name; // Store default bitmap name
|
|
|
|
image = new TTimed_image(name);
|
|
image->convert_transparent_color(MASK_BACK_COLOR);
|
|
_images.add(name, image);
|
|
}
|
|
else
|
|
{
|
|
image = (TTimed_image*)_images.objptr(_default_bmp);
|
|
if (image == NULL)
|
|
fatal_box("Impossibile trovare l'immagine %s", (const char*)_default_bmp);
|
|
}
|
|
|
|
if (_images.items() > 3)
|
|
{
|
|
TString worst_bmp;
|
|
clock_t worst_time = image->touch(); // Impedisco di cancellare la prossima
|
|
_images.restart();
|
|
for (THash_object* o = _images.get_hashobj(); o; o = _images.get_hashobj())
|
|
{
|
|
if (o->key() != _default_bmp)
|
|
{
|
|
TTimed_image& i = (TTimed_image&)o->obj();
|
|
if (i.last_time() < worst_time)
|
|
{
|
|
worst_time = i.last_time();
|
|
worst_bmp = o->key();
|
|
}
|
|
}
|
|
}
|
|
_images.remove(worst_bmp);
|
|
}
|
|
}
|
|
image->touch();
|
|
return *image;
|
|
}
|
|
|
|
void TMenu::reload_images()
|
|
{
|
|
_images.restart();
|
|
for (THash_object* h = _images.get_hashobj(); h; h = _images.get_hashobj())
|
|
{
|
|
const TString& 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;
|
|
bool _tree_view;
|
|
|
|
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 long handler(WINDOW win, EVENT* ep);
|
|
|
|
protected:
|
|
bool main_loop();
|
|
void test_temp();
|
|
void load_menu();
|
|
int do_level();
|
|
int do_tree();
|
|
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 tree_find_handler(TMask_field& f, KEY k);
|
|
static bool tree_shrink_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::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();
|
|
m.set_last_search_string(v);
|
|
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);
|
|
CHECK(_mask == NULL, "Two masks are better than one?");
|
|
_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.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);
|
|
}
|
|
|
|
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;
|
|
dongle().logout();
|
|
ok = get_serial_number() >= 0;
|
|
if (!ok)
|
|
error_box("Probabilmente e' stato superato il numero massimo di utenti");
|
|
}
|
|
}
|
|
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
|
|
reload_images(); // Ritrasparentizza immagini
|
|
xvt_dwin_invalidate_rect(TASK_WIN, NULL); // Ridisegna sfondo
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ok)
|
|
{
|
|
if (utente != "PRASSI")
|
|
{
|
|
TConfig prawin(CONFIG_INSTALL, "Main");
|
|
prawin.set("User", utente);
|
|
}
|
|
|
|
TConfig userini(CONFIG_USER, "ba0");
|
|
_tree_view = userini.get_bool("TreeView");
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TMenu_application::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
#ifdef _DEMO_
|
|
{
|
|
TMask w("Attenzione", 1, 78, 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
|
|
|
|
#ifndef _DEMO_
|
|
if (!check_user())
|
|
return FALSE;
|
|
#else
|
|
enable_menu_item(M_FONT);
|
|
#endif
|
|
|
|
set_perms();
|
|
test_temp();
|
|
|
|
if (!_menu.ok())
|
|
{
|
|
TWait_cursor hourglass;
|
|
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 = _tree_view ? do_tree() : 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 (!path.exist())
|
|
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, 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, "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)
|
|
_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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TMenu_tree
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TMenu_tree : public TBidirectional_tree
|
|
{
|
|
TMenu* _menu;
|
|
const TSubmenu* _submenu;
|
|
int _menuitem;
|
|
|
|
TString _root_id, _curr_id;
|
|
|
|
protected: // TTree
|
|
virtual void node2id(const TObject* node, TString& id) const;
|
|
|
|
public: // TTree
|
|
virtual bool goto_root();
|
|
virtual bool goto_firstson();
|
|
virtual bool goto_rbrother();
|
|
virtual bool goto_node(const TString &id);
|
|
virtual bool has_son() const;
|
|
virtual bool has_rbrother() const;
|
|
virtual TObject* curr_node() const;
|
|
|
|
virtual bool has_root() const;
|
|
virtual bool has_father() const;
|
|
virtual bool has_lbrother() const;
|
|
virtual bool goto_father();
|
|
virtual bool goto_lbrother();
|
|
|
|
virtual void curr_id(TString& id) const { id = _curr_id; }
|
|
virtual bool get_description(TString& desc) const;
|
|
virtual TImage* image(bool selected) const;
|
|
|
|
public:
|
|
const TSubmenu& curr_submenu() const;
|
|
const TMenuitem& curr_item() const;
|
|
bool find_string(const TString& str);
|
|
|
|
TMenu_tree(TMenu& menu);
|
|
virtual ~TMenu_tree() { }
|
|
};
|
|
|
|
const TSubmenu& TMenu_tree::curr_submenu() const
|
|
{
|
|
CHECKS(_submenu, "NULL submenu ", (const char*)_curr_id);
|
|
return *_submenu;
|
|
}
|
|
|
|
const TMenuitem& TMenu_tree::curr_item() const
|
|
{
|
|
const TSubmenu& sm = curr_submenu();
|
|
CHECKD(_menuitem >= 0 && _menuitem < sm.items(), "Invalid submenu item ", _menuitem);
|
|
return sm.item(_menuitem);
|
|
}
|
|
|
|
struct TFind_string_data
|
|
{
|
|
TString _str;
|
|
TString _ignore;
|
|
};
|
|
|
|
HIDDEN bool find_string_callback(TTree& tree, void* jolly, word flags)
|
|
{
|
|
if (flags == SCAN_PRE_ORDER)
|
|
{
|
|
TMenu_tree& mt = (TMenu_tree&)tree;
|
|
TFind_string_data& data = *(TFind_string_data*)jolly;
|
|
|
|
const TSubmenu& sm = mt.curr_submenu();
|
|
if (sm.name() == data._ignore)
|
|
return FALSE;
|
|
|
|
TString desc; mt.get_description(desc);
|
|
desc.upper();
|
|
if (desc.find(data._str) >= 0)
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
struct TFind_node_data
|
|
{
|
|
TString _id;
|
|
long _count;
|
|
};
|
|
|
|
HIDDEN bool find_node_callback(TTree& tree, void* jolly, word flags)
|
|
{
|
|
if (flags == SCAN_PRE_ORDER)
|
|
{
|
|
TFind_node_data& data = *(TFind_node_data*)jolly;
|
|
data._count++;
|
|
TString id; tree.curr_id(id);
|
|
if (id == data._id)
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_tree::find_string(const TString& str)
|
|
{
|
|
static TFind_string_data data;
|
|
data._str = str; data._str.upper();
|
|
|
|
goto_root();
|
|
bool ok = scan_depth_first(find_string_callback, &data,
|
|
SCAN_PRE_ORDER);
|
|
if (ok)
|
|
data._ignore = curr_submenu().name();
|
|
else
|
|
data._ignore.cut(0);
|
|
|
|
return ok;
|
|
}
|
|
|
|
void TMenu_tree::node2id(const TObject* node, TString& id) const
|
|
{
|
|
TString* str = (TString*)node;
|
|
id = *str;
|
|
}
|
|
|
|
bool TMenu_tree::goto_root()
|
|
{
|
|
TSubmenu* sm = _menu->find(_root_id);
|
|
if (sm)
|
|
{
|
|
_curr_id = _root_id;
|
|
_curr_id << ".0";
|
|
_submenu = sm;
|
|
_menuitem = 0;
|
|
}
|
|
return sm != NULL;
|
|
}
|
|
|
|
bool TMenu_tree::goto_firstson()
|
|
{
|
|
const TMenuitem& mi = curr_item();
|
|
if (mi.is_submenu())
|
|
{
|
|
const TSubmenu* sm = _menu->find(mi.action());
|
|
if (sm && sm->items() > 0)
|
|
{
|
|
_curr_id << '/' << mi.action() << ".0";
|
|
_submenu = sm;
|
|
_menuitem = 0;
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_tree::goto_rbrother()
|
|
{
|
|
if (_menuitem < _submenu->items()-1)
|
|
{
|
|
const int dot = _curr_id.rfind('.');
|
|
_curr_id.cut(dot+1);
|
|
_curr_id << (++_menuitem);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_tree::goto_node(const TString &id)
|
|
{
|
|
const int dot = id.rfind('.');
|
|
_menuitem = atoi(id.mid(dot+1));
|
|
_curr_id = id.left(dot);
|
|
const int slash = _curr_id.rfind('/');
|
|
|
|
_curr_id = _curr_id.mid(slash+1);
|
|
_submenu = _menu->find(_curr_id);
|
|
_curr_id = id;
|
|
|
|
return _submenu != NULL;
|
|
}
|
|
|
|
bool TMenu_tree::has_son() const
|
|
{
|
|
const TMenuitem& mi = curr_item();
|
|
return mi.is_submenu();
|
|
}
|
|
|
|
bool TMenu_tree::has_rbrother() const
|
|
{
|
|
return _menuitem < _submenu->items()-1;
|
|
}
|
|
|
|
bool TMenu_tree::has_root() const
|
|
{
|
|
return _root_id.not_empty();
|
|
}
|
|
|
|
bool TMenu_tree::has_father() const
|
|
{
|
|
return _curr_id.find('/') > 0;
|
|
}
|
|
|
|
bool TMenu_tree::has_lbrother() const
|
|
{
|
|
return _menuitem > 0;
|
|
}
|
|
|
|
bool TMenu_tree::goto_father()
|
|
{
|
|
const int slash = _curr_id.rfind('/');
|
|
if (slash > 0)
|
|
{
|
|
const TString id = _curr_id.left(slash);
|
|
return goto_node(id);
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TMenu_tree::goto_lbrother()
|
|
{
|
|
if (_menuitem > 0)
|
|
{
|
|
const int dot = _curr_id.rfind('.');
|
|
_curr_id.cut(dot+1);
|
|
_curr_id << (--_menuitem);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
TObject* TMenu_tree::curr_node() const
|
|
{
|
|
return &((TMenu_tree*)this)->_curr_id;
|
|
}
|
|
|
|
bool TMenu_tree::get_description(TString& desc) const
|
|
{
|
|
const TMenuitem& mi = curr_item();
|
|
desc = mi.caption();
|
|
return desc.not_empty();
|
|
}
|
|
|
|
TImage* TMenu_tree::image(bool selected) const
|
|
{
|
|
const TMenuitem& mi = curr_item();
|
|
if (mi.disabled())
|
|
return get_res_image(BMP_STOP);
|
|
return TTree::image(selected);
|
|
}
|
|
|
|
TMenu_tree::TMenu_tree(TMenu& menu)
|
|
: _menu(&menu), _curr_id(128, '/')
|
|
{
|
|
_root_id = _menu->current().name();
|
|
goto_root();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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();
|
|
TImage& image = menu.image(menu.current().picture());
|
|
TPicture_mask& pm = (TPicture_mask&)f.mask();
|
|
pm.set_image(&image);
|
|
pm.force_update();
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
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();
|
|
m.set_last_search_string(v);
|
|
|
|
TTree_field& tf = (TTree_field&)m.field(101);
|
|
TMenu_tree& mt = *(TMenu_tree*)tf.tree();
|
|
if (mt.find_string(v))
|
|
{
|
|
tf.select_current();
|
|
|
|
TString id; mt.curr_id(id);
|
|
do { mt.expand(); } while (mt.goto_father());
|
|
|
|
TFind_node_data data;
|
|
data._id = id;
|
|
data._count = 0;
|
|
mt.goto_root();
|
|
mt.scan_depth_first(find_node_callback, &data,
|
|
SCAN_PRE_ORDER | SCAN_IGNORING_UNEXPANDED);
|
|
|
|
TField_window& win = tf.win();
|
|
const TPoint& range = win.range();
|
|
if (data._count > range.y)
|
|
win.set_scroll_max(win.columns(), data._count+win.rows());
|
|
|
|
const int dot = id.rfind('.');
|
|
const int pos = atoi(id.mid(dot+1));
|
|
|
|
win.update_thumb(-1, data._count-pos-2);
|
|
win.force_update();
|
|
tf.set_focus();
|
|
}
|
|
else
|
|
beep();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMenu_application::tree_shrink_handler(TMask_field&f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TTree_field& tf = (TTree_field&)f.mask().field(101);
|
|
TMenu_tree& mt = *(TMenu_tree*)tf.tree();
|
|
mt.shrink_all();
|
|
mt.goto_root();
|
|
tf.select_current();
|
|
tf.win().update_thumb(0,0);
|
|
tf.win().force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
HIDDEN void left_align_field(TMask_field& fld, int x)
|
|
{
|
|
RCT rct;
|
|
fld.get_rect(rct);
|
|
rct.left = x;
|
|
fld.set_rect(rct);
|
|
}
|
|
|
|
int TMenu_application::do_tree()
|
|
{
|
|
_menu.jumpto_root();
|
|
const TSubmenu& curr = _menu.current();
|
|
|
|
TImage& image = _menu.image(curr.picture());
|
|
TPicture_mask mask(curr.caption(), 0, 0, &image, 0, 0);
|
|
CHECK(_mask == NULL, "Two masks are better than one?");
|
|
_mask = &mask;
|
|
|
|
TMenu_tree tree(_menu);
|
|
TTree_field& tree_fld = mask.add_tree(101, 0, 0, 0, 60, -1);
|
|
tree_fld.set_tree(&tree);
|
|
tree_fld.set_handler(tree_handler);
|
|
RCT rct; tree_fld.get_rect(rct);
|
|
const int x = rct.right + CHARX;
|
|
const int bwidth = 20;
|
|
|
|
TMask_field& sf = mask.add_static(DLG_NULL, 0, "Cerca", -1, 0);
|
|
left_align_field(sf, x);
|
|
|
|
TEdit_field& ef = mask.add_string(DLG_USER, 0, "", -2, 1, 50, "", bwidth);
|
|
ef.set_handler(tree_find_handler);
|
|
left_align_field(ef, x);
|
|
|
|
TButton_field& mf = mask.add_button(102, 0, "Menu principale", -1, 2, bwidth, 2);
|
|
mf.set_handler(tree_shrink_handler);
|
|
left_align_field(mf, x);
|
|
|
|
TButton_field& bf = mask.add_button(DLG_QUIT, 0, "Fine", -1, -1, bwidth, 2);
|
|
left_align_field(bf, x);
|
|
|
|
mask.first_focus(101);
|
|
KEY key = mask.run();
|
|
_mask = NULL;
|
|
|
|
return key == K_QUIT ? -2 : 0;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Main program
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TApplication::check_parameters(argc, argv);
|
|
|
|
if (user().blank())
|
|
{
|
|
TConfig prawin(CONFIG_INSTALL, "Main");
|
|
user() = prawin.get("User");
|
|
}
|
|
|
|
TFilename menu = (argc < 2) ? "baprassi.men" : argv[1];
|
|
TString ext = menu.ext(); ext.lower();
|
|
|
|
if (ext == "men" && !menu.exist())
|
|
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 (menu.exist() && !newmenu.exist())
|
|
convert(menu);
|
|
menu = newmenu;
|
|
}
|
|
|
|
if (!menu.exist())
|
|
{
|
|
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;
|
|
}
|