1994-08-26 13:04:28 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <execp.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <utility.h>
|
|
|
|
#include <urldefid.h>
|
|
|
|
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-09-20 12:20:31 +00:00
|
|
|
extern "C"
|
1994-10-03 08:42:51 +00:00
|
|
|
{
|
|
|
|
#include <cpb.h>
|
1994-08-26 13:04:28 +00:00
|
|
|
}
|
1994-10-03 08:42:51 +00:00
|
|
|
#include <dos.h>
|
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
1994-08-26 13:04:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ba0.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Picture Mask
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPicture_mask : public TMask
|
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
static short _id;
|
|
|
|
static PICTURE _picture;
|
1994-08-26 13:04:28 +00:00
|
|
|
|
1994-09-20 12:20:31 +00:00
|
|
|
protected:
|
1994-08-26 13:04:28 +00:00
|
|
|
virtual void handler(WINDOW win, EVENT* ep);
|
1994-09-20 12:20:31 +00:00
|
|
|
void set_picture(short id);
|
1994-08-26 13:04:28 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TPicture_mask(const char* name, int dx, int dy, short picture_id);
|
1994-09-20 12:20:31 +00:00
|
|
|
void reset();
|
1994-08-26 13:04:28 +00:00
|
|
|
};
|
|
|
|
|
1994-09-20 12:20:31 +00:00
|
|
|
short TPicture_mask::_id = 0;
|
|
|
|
PICTURE TPicture_mask::_picture = 0L;
|
|
|
|
|
|
|
|
void TPicture_mask::set_picture(short id)
|
1994-08-26 13:04:28 +00:00
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
if (id != _id)
|
|
|
|
{
|
|
|
|
_id = id;
|
1994-08-26 13:04:28 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-09-20 12:20:31 +00:00
|
|
|
if (_picture) picture_free(_picture);
|
|
|
|
_picture = cpb_picture_load(id);
|
1994-08-26 13:04:28 +00:00
|
|
|
#endif
|
1994-09-20 12:20:31 +00:00
|
|
|
}
|
1994-08-26 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
1994-09-20 12:20:31 +00:00
|
|
|
void TPicture_mask::reset()
|
1994-08-26 13:04:28 +00:00
|
|
|
{
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
if (_picture)
|
1994-09-20 12:20:31 +00:00
|
|
|
{
|
1994-08-26 13:04:28 +00:00
|
|
|
picture_free(_picture);
|
1994-09-20 12:20:31 +00:00
|
|
|
_picture = 0L;
|
|
|
|
_id = 0;
|
|
|
|
}
|
1994-08-26 13:04:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-09-20 12:20:31 +00:00
|
|
|
TPicture_mask::TPicture_mask(const char* name, int dx, int dy, short pic)
|
|
|
|
: TMask(name, 1, dx, dy)
|
|
|
|
{
|
|
|
|
set_picture(pic);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-08-26 13:04:28 +00:00
|
|
|
|
|
|
|
void TPicture_mask::handler(WINDOW win, EVENT* ep)
|
|
|
|
{
|
|
|
|
TMask::handler(win, ep);
|
|
|
|
|
|
|
|
if (ep->type == E_UPDATE)
|
|
|
|
{
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
if (_picture)
|
1994-10-03 08:42:51 +00:00
|
|
|
cpb_win_picture_draw_at(win, _picture, 1, CHARY<<1);
|
1994-08-26 13:04:28 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
const int max = 16;
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
TTemp_window w(win);
|
|
|
|
w.rect(i*2, i, max-i*2, max-i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Menu application
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TMenu_application : public TApplication
|
|
|
|
{
|
|
|
|
const char* _name;
|
|
|
|
|
|
|
|
enum { MAXLEVEL = 1024 };
|
|
|
|
int _first[MAXLEVEL];
|
|
|
|
TArray _menu; // TAG|DESCRIPTION|ACTION
|
|
|
|
|
|
|
|
int _level, _max;
|
|
|
|
|
|
|
|
protected:
|
1994-10-03 08:42:51 +00:00
|
|
|
void test_temp() const;
|
1994-08-26 13:04:28 +00:00
|
|
|
void load_menu();
|
|
|
|
int do_level();
|
1994-09-16 10:43:09 +00:00
|
|
|
virtual bool create();
|
|
|
|
virtual bool menu(MENU_TAG m);
|
1994-08-26 13:04:28 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TMenu_application(const char* name) : _name(name) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static short last_button = 0;
|
|
|
|
|
|
|
|
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 = l] = _menu.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
_menu.add(ts);
|
|
|
|
}
|
|
|
|
_first[++_max] = _menu.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HIDDEN bool menu_item_handler(TMask_field&f, KEY k)
|
|
|
|
{
|
|
|
|
if (k == K_SPACE)
|
|
|
|
{
|
|
|
|
last_button = f.dlg();
|
|
|
|
f.mask().stop_run(K_AUTO_ENTER);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TMenu_application::do_level()
|
|
|
|
{
|
|
|
|
const int first = _first[_level];
|
|
|
|
const int last = _first[_level+1];
|
1994-09-20 12:20:31 +00:00
|
|
|
TToken_string& row = (TToken_string&)_menu[first];
|
|
|
|
const TString80 head(row.get(1));
|
1994-08-26 13:04:28 +00:00
|
|
|
|
|
|
|
const int width = 72;
|
|
|
|
const int heigth = 18;
|
|
|
|
const int bwidth = 20;
|
|
|
|
const int x = width-bwidth-12;
|
1994-09-20 12:20:31 +00:00
|
|
|
const short pic = BA0_PICTURE+(short)row.get_int();
|
|
|
|
TPicture_mask menu(head, width, heigth, pic);
|
1994-08-26 13:04:28 +00:00
|
|
|
|
|
|
|
int y = 1;
|
|
|
|
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-09-20 12:20:31 +00:00
|
|
|
TString16 t(format("#%d", BMP_STOPREC));
|
1994-08-26 13:04:28 +00:00
|
|
|
#else
|
1994-09-20 12:20:31 +00:00
|
|
|
TString16 t;
|
1994-08-26 13:04:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i = first+1; i < last; i++, y++)
|
|
|
|
{
|
|
|
|
TToken_string& row = (TToken_string&)_menu[i];
|
1994-09-20 12:20:31 +00:00
|
|
|
TString80 item(row.get(1));
|
|
|
|
if (isdigit(*row.get())) item << "...";
|
|
|
|
menu.add_static(-1, 0, item, x+4, y);
|
1994-08-26 13:04:28 +00:00
|
|
|
menu.add_button(100+y, 0, t, x, y, 1, 1);
|
|
|
|
menu.set_handler(100+y, menu_item_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
t = first ? "Menu precedente" : "Fine";
|
1994-09-20 12:20:31 +00:00
|
|
|
menu.add_button(first ? DLG_CANCEL : DLG_QUIT, 0, t, -22, -2, bwidth, 2);
|
|
|
|
if (first)
|
|
|
|
menu.add_button(DLG_QUIT, 0, "Fine", -12, -2, bwidth, 2);
|
|
|
|
|
|
|
|
const int k = menu.run();
|
|
|
|
int m = 0;
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case K_ESC:
|
|
|
|
m = -1; break;
|
|
|
|
case K_QUIT:
|
|
|
|
menu.reset();
|
|
|
|
m = -2; break;
|
|
|
|
default:
|
|
|
|
m = first+last_button-100; break;
|
|
|
|
}
|
1994-08-26 13:04:28 +00:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-10-03 08:42:51 +00:00
|
|
|
void TMenu_application::test_temp() const
|
|
|
|
{
|
|
|
|
TFilename name; name.temp();
|
|
|
|
const TString16 ext = name.ext();
|
|
|
|
name.tempdir();
|
|
|
|
name << "/" << "*." << ext;
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
struct _find_t f;
|
|
|
|
if (_dos_findfirst(name, _A_NORMAL, &f) == 0 &&
|
|
|
|
yesno_box("Si desidera cancellare i file temporanei (*.tmp)"))
|
|
|
|
{
|
|
|
|
TFilename dir; dir.tempdir();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
name = dir;
|
|
|
|
name << "/" << f.name;
|
|
|
|
remove(name);
|
|
|
|
} while (_dos_findnext(&f) == 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-09-16 10:43:09 +00:00
|
|
|
|
1994-08-26 13:04:28 +00:00
|
|
|
bool TMenu_application::create()
|
|
|
|
{
|
1994-10-03 08:42:51 +00:00
|
|
|
test_temp();
|
1994-08-26 13:04:28 +00:00
|
|
|
load_menu();
|
1994-09-16 10:43:09 +00:00
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TMenu_application::menu(MENU_TAG)
|
|
|
|
{
|
1994-08-26 13:04:28 +00:00
|
|
|
int refarray[256];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
_level = 0;
|
|
|
|
while (i >= 0)
|
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
const int m = do_level();
|
1994-08-26 13:04:28 +00:00
|
|
|
if (m >= 0)
|
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
TToken_string& row = (TToken_string&)_menu[m];
|
|
|
|
const char* option = row.get(2);
|
1994-08-26 13:04:28 +00:00
|
|
|
if (option && *option)
|
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
const int l = atoi(option);
|
1994-08-26 13:04:28 +00:00
|
|
|
if (l > 0)
|
|
|
|
{
|
1994-09-20 12:20:31 +00:00
|
|
|
const char* flags = row.get();
|
|
|
|
if (flags && strchr(flags, 'F') != NULL)
|
|
|
|
set_firm();
|
1994-08-26 13:04:28 +00:00
|
|
|
refarray[i++] = _level;
|
|
|
|
if (l < _max) _level = l;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TExternal_app a(option);
|
|
|
|
a.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-09-20 12:20:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m < -1) break;
|
|
|
|
_level = (--i >= 0) ? refarray[i] : 0;
|
|
|
|
}
|
1994-08-26 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
1994-09-16 10:43:09 +00:00
|
|
|
return FALSE;
|
1994-08-26 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
const char* menu = (argc < 2) ? "prassi.mnu" : argv[1];
|
|
|
|
TMenu_application ma(menu);
|
1994-09-20 12:20:31 +00:00
|
|
|
ma.run(argc, argv, "Menu Principale");
|
1994-08-26 13:04:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|