227 lines
4.3 KiB
C++
Executable File
227 lines
4.3 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <execp.h>
|
|
#include <mask.h>
|
|
#include <scanner.h>
|
|
#include <strings.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
extern "C" {
|
|
#include <cpb.h>
|
|
}
|
|
#endif
|
|
|
|
#include "ba0.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Picture Mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPicture_mask : public TMask
|
|
{
|
|
PICTURE _picture;
|
|
|
|
virtual void handler(WINDOW win, EVENT* ep);
|
|
|
|
public:
|
|
TPicture_mask(const char* name, int dx, int dy, short picture_id);
|
|
~TPicture_mask();
|
|
};
|
|
|
|
TPicture_mask::TPicture_mask(const char* name, int dx, int dy,
|
|
short picture_id)
|
|
: TMask(name, 1, dx, dy), _picture(0L)
|
|
{
|
|
#if XVT_OS == XVT_OS_WIN
|
|
_picture = cpb_picture_load(picture_id);
|
|
#endif
|
|
}
|
|
|
|
TPicture_mask::~TPicture_mask()
|
|
{
|
|
#if XVT_OS == XVT_OS_WIN
|
|
if (_picture)
|
|
picture_free(_picture);
|
|
#endif
|
|
}
|
|
|
|
|
|
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)
|
|
cpb_win_picture_draw_at(win, _picture, 1, 1);
|
|
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:
|
|
void load_menu();
|
|
int do_level();
|
|
bool create();
|
|
|
|
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];
|
|
const char* head = ((TToken_string&)_menu[first]).get(1);
|
|
|
|
const int width = 72;
|
|
const int heigth = 18;
|
|
const int bwidth = 20;
|
|
const int x = width-bwidth-12;
|
|
|
|
TPicture_mask menu(head, width, heigth, BA0_PICTURE);
|
|
|
|
int y = 1;
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
TString t(format("#%d", BMP_STOPREC));
|
|
#else
|
|
TString t;
|
|
#endif
|
|
|
|
TString item(32);
|
|
for (int i = first+1; i < last; i++, y++)
|
|
{
|
|
TToken_string& row = (TToken_string&)_menu[i];
|
|
item = row.get(1);
|
|
menu.add_button(100+y, 0, t, x, y, 1, 1);
|
|
menu.set_handler(100+y, menu_item_handler);
|
|
menu.add_static(-1, 0, item, x+4, y);
|
|
}
|
|
|
|
t = first ? "Menu precedente" : "Fine";
|
|
const short id = first ? DLG_CANCEL : DLG_QUIT;
|
|
menu.add_button(id, 0, t, x, heigth-2, bwidth, 2);
|
|
|
|
menu.run();
|
|
int k = menu.last_key();
|
|
int m =(k == K_QUIT || k == K_ESC) ? -1 : first+last_button-100;
|
|
return m;
|
|
}
|
|
|
|
|
|
bool TMenu_application::create()
|
|
{
|
|
load_menu();
|
|
int refarray[256];
|
|
int i = 0;
|
|
|
|
_level = 0;
|
|
while (i >= 0)
|
|
{
|
|
int m = do_level();
|
|
if (m >= 0)
|
|
{
|
|
const char* option = ((TToken_string&)_menu[m]).get(2);
|
|
if (option && *option)
|
|
{
|
|
int l = atoi(option);
|
|
if (l > 0)
|
|
{
|
|
const char* flags = ((TToken_string&)_menu[m]).get(3);
|
|
|
|
if (flags && strchr(flags, 'F') != NULL) set_firm();
|
|
refarray[i++] = _level;
|
|
if (l < _max) _level = l;
|
|
}
|
|
else
|
|
{
|
|
TExternal_app a(option);
|
|
a.run();
|
|
}
|
|
}
|
|
}
|
|
else _level = (--i >= 0) ? refarray[i] : 0;
|
|
}
|
|
|
|
stop_run();
|
|
return TRUE;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
const char* menu = (argc < 2) ? "prassi.mnu" : argv[1];
|
|
TMenu_application ma(menu);
|
|
ma.run(argc, argv, "PRASSI");
|
|
return TRUE;
|
|
}
|