From b19e702cf59e33ca9ae0aa3081186c83881310dd Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 3 Jun 1997 14:00:29 +0000 Subject: [PATCH] Rifatta completamente la gestione del menu principale git-svn-id: svn://10.65.10.50/trunk@4504 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba0.cpp | 993 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 698 insertions(+), 295 deletions(-) diff --git a/ba/ba0.cpp b/ba/ba0.cpp index 19364ca71..f206aa586 100755 --- a/ba/ba0.cpp +++ b/ba/ba0.cpp @@ -7,11 +7,11 @@ #include #include #include -//#include // TDDE #include #include #include #include +#include #include #include #include @@ -21,8 +21,6 @@ #include "ba0.h" #include "ba0100a.h" - - /////////////////////////////////////////////////////////// // Picture Mask /////////////////////////////////////////////////////////// @@ -318,6 +316,549 @@ bool TColor_mask::azzera_handler(TMask_field& f, KEY k) 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 +{ + TString _last_read; + TSubmenu* _current; + int _item; + TStack _stack; + + TAssoc_array _images; + +public: + void read(const char* name); + const TString& last_read() const { return _last_read; } + + 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(); + + 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 == '<') + { + menu().read(_action); + _action = menu().last_read(); + _type = '['; + if (_action.empty()) + _enabled = FALSE; + } + + if (enabled() && is_program()) + { + 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; + } + _enabled = ext[e] != NULL; + } +} + +bool TMenuitem::enabled() const +{ + bool yes = _enabled; + if (yes) + { + if (is_submenu()) + { + TSubmenu* mnu = menu().find(_action); + yes = mnu && mnu->enabled(); + } + } + return yes; +} + +bool TMenuitem::perform_submenu() const +{ + TSubmenu* mnu = menu().find(_action); + bool ok = mnu != NULL && mnu->enabled(); + if (ok) + { + if (mnu->query_firm()) + ok = main_app().set_firm(); + + if (ok) + { + if (mnu->items() == 1) + { + 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) + ok = main_app().set_firm(); + + if (ok) + { + prefix().set(NULL); // Chiude prefix + const bool maintenance_app = _action.compare("ba1", 3, TRUE) == 0; + TExternal_app a(_action); + a.run(); + 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) +{ +} + +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()) + { + 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('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 +{ + TString caption; + for (int i = 0; i < items(); i++) + { + const TMenuitem& mi = item(i); + if (mi.enabled() && mi.is_program()) + { + caption = item(i).caption(); + caption.upper(); + if (caption.find(str) >= 0) + return i; + } + } + return -1; +} + +bool TSubmenu::perform(int i) +{ + bool ok = i >= 0 && i < items(); + if (ok) + ok = item(i).perform(); + return ok; +} + +void TMenu::read(const char* name) +{ + _last_read.cut(0); + bool first = TRUE; + + TScanner scanner(name); + TString str; + 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) + { + _last_read = str; + first = FALSE; + } + + if (objptr(str) == NULL) + { + TSubmenu* mnu = new TSubmenu(this, str); + mnu->read(scanner); + add(str, mnu); + if (_current == NULL) + { + _current = mnu; + _item = 0; + } + } + else + break; // Menu gia' caricato! + } +} + +bool TMenu::jumpto(TSubmenu* next) +{ + if (next && next->disabled()) + next = NULL; + + if (next) + { + if (next->query_firm()) + { + if (!main_app().set_firm()) + next = NULL; + } + 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); + } + +} + /////////////////////////////////////////////////////////// // Menu application /////////////////////////////////////////////////////////// @@ -325,14 +866,10 @@ bool TColor_mask::azzera_handler(TMask_field& f, KEY k) class TMenu_application : public TApplication { const char* _name; + + TMenu _menu; + TArray _modules; - enum { MAXLEVEL = 512 }; // Non cambiare !! pena di morte . Deve essere < 730 - int _first[MAXLEVEL]; - TArray _menu; // TAG|DESCRIPTION|ACTION - TBit_array _enabled; - TArray _modules, _images; - - int _level, _max; TPicture_mask* _mask; static int _last_button; @@ -350,18 +887,15 @@ protected: void test_temp(); void load_menu(); int do_level(); - int find_menu(const char* s) const; bool check_user(); static bool menu_item_handler(TMask_field&f, KEY k); static bool menu_find_handler(TMask_field&f, KEY k); - bool module_enabled(const char * program) const; - bool module_enabled(int module) const { return has_module(module);} bool choose_colors(); bool choose_editors(); public: - void reload_images(); + void reload_images() { _menu.reload_images(); } TMenu_application(const char* name) : _name(name), _mask(NULL) { } virtual ~TMenu_application() { } @@ -489,112 +1023,11 @@ bool TMenu_application::build_firm_data(long codditta, bool flagcom) return TRUE; } - -bool TMenu_application::module_enabled(const char * program) const -{ - bool found = FALSE; - const int nmod = _modules.items(); - - for (int aut = 0; aut < nmod; aut++) - { - const TString& s = (const TString&) _modules[aut]; - if (isdigit(program[2]) && s.compare(program, 2) == 0) { found = TRUE; break; } - } - return (!found) || has_module(aut); -} - -void TMenu_application::load_menu() -{ - TScanner s(_name); - - _max = -1; - - while (s.line().not_empty()) - { - TToken_string* ts = new TToken_string(s.token()); - int l = ts->get_int(); - - if (l < _max) - { - error_box("Item of level %d while %d was expected)", l, _max); - l = _max; - } - if (l > _max) - { - if (l >= MAXLEVEL) - { - error_box("Too many menu levels: %d", l); - l = _max; - } - _first[++_max] = _menu.items(); - _first[_max = l] = _menu.items(); - } - - _menu.add(ts); - TString80 action(ts->get(2)); - const int last = _menu.items() - 1; - TToken_string list(ts->get(), ','); - - if (atoi(action) > 0 || list.items() > 0) - { - const TString16 mod = list.get(0); - int module = atoi(mod); - - if (module == 0) - { - bool on = TRUE; -// if (mod[0] == 'P') on = user() == "PRASSI"; // Errore MI1639 - _enabled.set(last, on); - } - while(!_enabled[last] && module > 0) - { - if (has_module(module)) - _enabled.set(last); - module = list.get_int(); - } - } - else - { - action.trim(); action.upper(); - const bool on = action != "DISABLED"; - _enabled.set(last, on); - } - // _enabled.set(last, module_enabled(action)); - } - _first[++_max] = _menu.items(); -} - -int TMenu_application::find_menu(const char* s) const -{ - TString str(s); str.upper(); - int found = -1; - TString v(80); - for (int i = 0; i < _menu.items(); i++) - { - if (_enabled[i]) - { - TToken_string& l = (TToken_string&)_menu[i]; - const int m = l.get_int(0); - if (m != _level) - { - v = l.get(); v.upper(); - if (v.find(str) >= 0) - { - found = i; - if (isalpha(l.get_char())) break; - } - } - } - } - return found; -} - bool TMenu_application::menu_item_handler(TMask_field&f, KEY k) { if (k == K_SPACE) { - _last_button = f.dlg(); - _find_button = FALSE; + app()._menu.select(f.dlg()-101); f.set_focusdirty(FALSE); return f.mask().stop_run(K_AUTO_ENTER); } @@ -608,13 +1041,11 @@ bool TMenu_application::menu_find_handler(TMask_field&f, KEY k) { const TString& v = f.get(); if (v.not_empty()) - { - _last_button = app().find_menu(v); - if (_last_button >= 0) + { + if (app()._menu.find_string(v)) { - _find_button = TRUE; f.set_focusdirty(FALSE); - return f.mask().stop_run(K_AUTO_ENTER); + return f.mask().stop_run(K_F9); } else { @@ -626,104 +1057,75 @@ bool TMenu_application::menu_find_handler(TMask_field&f, KEY k) return TRUE; } - -void TMenu_application::reload_images() -{ - for (int id = _images.last(); id >= 0; id--) - { - TImage* i = (TImage*)_images.objptr(id); - if (i) - { - TString16 n; n.format("ba%02d.bmp", id); - i->load(n); - i->convert_transparent_color(MASK_BACK_COLOR); - } - } -} - - int TMenu_application::do_level() { - const int first = _first[_level]; - const int last = _first[_level+1]; - TToken_string& row = (TToken_string&)_menu[first]; - const TString80 head(row.get(1)); + const TSubmenu& curr = _menu.current(); const int width = 78; const int height = 18; const int bwidth = 20; - short id = (short)row.get_int(); - if (_images.objptr(id) == NULL) - { - char* n = format("ba%02d.bmp", id); - if (id > 0 && !fexist(n)) - n = format("ba%02d.bmp", id = 0); - - TImage* image = new TImage(n); - image->convert_transparent_color(MASK_BACK_COLOR); - _images.add(image, id); - } + TImage& image = _menu.image(curr.picture()); - TPicture_mask menu(head, width, height, (TImage&)_images[id]); - _mask = &menu; + TPicture_mask mask(curr.caption(), width, height, image); + _mask = &mask; const int x = width / 2; int y = 1; - for (int i = first+1; i < last; i++, y++) + for (int i = 0; i < curr.items(); i++, y++) { - TToken_string& row = (TToken_string&)_menu[i]; - TString80 item(row.get(1)); - if (isdigit(*row.get())) item << "..."; - menu.add_static(-1, 0, item, x+4, y); + const TMenuitem& item = curr[i]; + TString80 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; - menu.add_button(id, 0, "", x, y, 1, 1, "", BMP_STOPREC); - menu.set_handler(id, menu_item_handler); - if (!_enabled[i]) menu.disable(id); + mask.add_button(id, 0, "", x, y, 1, 1, "", BMP_STOPREC); + mask.set_handler(id, menu_item_handler); + if (item.disabled()) + mask.disable(id); } - menu.add_static(DLG_NULL, 0, "Cerca", 1,-3); - TEdit_field& ef = menu.add_string(DLG_USER, 0, "", -12, -3, 50, "", bwidth+1); + 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); - - TButton_field& bf = menu.add_button(DLG_QUIT, 0, "Fine", first ? -12 : -22, -1, bwidth, 2); - if (first) + + 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 - menu.add_button(DLG_CANCEL, 0, "Menu precedente", -22, -1, bwidth, 2); + mask.add_button(DLG_CANCEL, 0, "Menu precedente", -22, -1, bwidth, 2); } - if (_find_button && _last_button > first) - menu.first_focus(100+_last_button-first); + mask.first_focus(101+_menu.selected()); - _last_button = _find_button = 0; - - const int k = menu.run(); + const int k = mask.run(); _mask = NULL; int m = 0; switch (k) { case K_ESC: - m = -1; + _menu.pop(); + m = -1; break; case K_QUIT: - menu.reset(); + mask.reset(); m = -2; break; + case K_F9: case K_CTRL+'R': m = 0; break; default: - if (_find_button) - m = -1; - else - m = first+_last_button-100; + m = _menu.selected() + 1; // Sempre > 0 break; } return m; @@ -804,9 +1206,15 @@ bool TMenu_application::check_user() { ok = yesno_box("L'utente %s risulta essere gia' collegato\n" "Si desidera continuare ugualmente?", (const char*)utente); - } + } + if (ok) + { user() = utente; + ok = get_serial_number(name()) >= 0; + if (!ok) + error_box("E' stato superato il numero massimo di utenti collegati"); + } } else { @@ -862,11 +1270,11 @@ bool TMenu_application::create() test_temp(); TScanner scanner("prassi.aut"); - for (int aut = 0; scanner.line() != ""; aut++) _modules.add(scanner.token()); - load_menu(); + _menu.read("prassi.men"); + dispatch_e_menu(MENU_ITEM(1)); return TRUE; } @@ -887,119 +1295,14 @@ bool TMenu_application::destroy() bool TMenu_application::main_loop() { - int refarray[256]; - memset(refarray, 0, sizeof(refarray)); - - int i = 0; - - _level = 0; - while (i >= 0) + bool run = TRUE; + while (run) { const int m = do_level(); - if (m >= 0) - { - TToken_string& row = (TToken_string&)_menu[m]; - const TFilename option(row.get(2)); - - if (option.not_empty()) - { - bool ok = TRUE; - const int l = atoi(option); - if (l > 0 && l < MAXLEVEL) - { - const TString16 flags(row.get()); - if (flags.find('F') >= 0) - ok = set_firm(); - if (ok) - { - refarray[i++] = _level; - if (l < _max) _level = l; - } - } - else - { - const TString16 flags(row.get()); - if (flags.find('P') >= 0) - { - TMask mask("ba0100a"); - mask.disable(F_USER); - mask.set(F_USER, "SERVIZIO"); - ok = FALSE; - if (mask.run() == K_ENTER) - { - const TDate oggi(TODAY); - TString16 pwd; pwd << "PRASSI" << (oggi.month() + oggi.day()); - ok = pwd == mask.get(F_PASSWORD); - } - if (!ok) error_box("Password di servizio errata!\nAccesso negato."); - } - - if (ok) - { - const TString16 module(cmd2name(option)); - if (get_firm() == 0 && module.compare("cg", 2, TRUE) == 0) // Chiede ditta se necessario - ok = set_firm(); - } - - if (ok) - { - prefix().set(NULL); // Chiude prefix - TFilename opt_cmd(option); -#if XVT_OS == XVT_OS_WIN - opt_cmd.lower(); -#endif - bool maintenance_app = (opt_cmd == "ba1 -0" || opt_cmd == "ba1"); - TExternal_app a(option); - a.run(); - if (maintenance_app) - { - FILE* fp; - char line1[16],line2[16]; - if (opt_cmd == "ba1") opt_cmd << " -0"; - opt_cmd << " C"; - - while (fexist("conv.his")) - { - fp = fopen("conv.his","r"); - fgets(line1,15,fp); - fclose(fp); - // Ora aspetta... - time_t old_time ; - time( &old_time) ; - while ( time( (time_t *) 0 ) <= old_time ) do_events(); - TExternal_app auto_conv(opt_cmd); - auto_conv.run(); - fp = fopen("conv.his","r"); - if (fp != NULL) - { - fgets(line2,15,fp); - fclose(fp); - } - else strcpy(line2,""); - if (strcmp(line1,line2) == 0) - if (!yesno_box("La conversione non sembra procedere. Continuo?")) - break; - } - } - prefix().set("DEF"); // Aggiorna prefix - } - } - } - } + if (m > 0) + _menu.perform(); else - { - if (m < -1) break; - if (_find_button) - { - TToken_string& row = (TToken_string&)_menu[_last_button]; - _level = row.get_int(0); - } - else - { - _level = (i > 0) ? refarray[--i] : 0; - if (_level == 0) i = 0; - } - } + run = m >= -1; } return FALSE; } @@ -1035,13 +1338,13 @@ HIDDEN bool browse_file_handler(TMask_field& f, KEY k) FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC)); strcpy(fs.type, "EXE"); strcpy(fs.name, f.get()); - strcpy(fs.creator, "ba0"); + strcpy(fs.creator, "PRASSI"); xvt_fsys_get_default_dir(&fs.dir); xvt_fsys_save_dir(); if (xvt_dm_post_file_open(&fs, "Selezione programma") == FL_OK) { TFilename n; - xvt_fsys_convert_dir_to_str(&fs.dir, (char*)(const char*)n, n.size()); + xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(n.size()), n.size()); n.add(fs.name); f.set(n); xvt_fsys_restore_dir(); @@ -1093,6 +1396,85 @@ bool TMenu_application::menu(MENU_TAG mt) 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 = \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) { @@ -1105,9 +1487,30 @@ int main(int argc, char** argv) user() = u; } - const char* menu = (argc < 2) ? "prassi.mnu" : argv[1]; + TFilename menu = (argc < 2) ? "prassi.men" : argv[1]; + TString16 ext = menu.ext(); ext.upper(); + + if (ext == "MEN" && !fexist(menu)) + ext.cut(0); + + if (ext != "MEN") + { + if (ext.empty()) + menu.ext("mnu"); + TFilename newmenu(menu); newmenu.ext("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(menu); ma.run(argc, argv, "Menu Principale"); + exit(0); return TRUE; }