#include #include #include #include #include #include #include #include #include #include #include #include #include #include // Maschera scelta ditta #include /////////////////////////////////////////////////////////// // Finestra informazioni /////////////////////////////////////////////////////////// class TInfo_mask : public TMask { int _row, _col; public: void add_row(const char* prompt, const char* value); void add_row(const char* prompt, unsigned long value); TInfo_mask(); }; void TInfo_mask::add_row(const char* prompt, const char* value) { const int MASK_WIDTH = 78; const int MASK_WIDTH2 = MASK_WIDTH/2; const int PROMPT_WIDTH = 12; TString val(value); val.trim(); const int len = val.len(); const int estim_len = 120 * (PROMPT_WIDTH + len) / 100; if (_col + estim_len > MASK_WIDTH) { _row++; _col = 1; } TString16 pr(prompt); pr.left_just(PROMPT_WIDTH); const short id = 101 + _row*10 + (_col > 1); TEdit_field& e = add_string(id, 0, pr, _col, _row, len, "", len > 50 ? 50 : len); e.set(value); if (_col == 1) _col = (estim_len+2 >= MASK_WIDTH2) ? MASK_WIDTH : MASK_WIDTH2; else _col = MASK_WIDTH; } void TInfo_mask::add_row(const char* prompt, unsigned long value) { TString8 str; str.format("%lu", value); add_row(prompt, str); } TInfo_mask::TInfo_mask() : TMask("Informazioni", 1, 72, 11, -1, -1), _row(0), _col(1) { const word ser_no = dongle().number(); int year, release, tag, patch; TString16 versione = "2003.02"; TString16 strpatch = "01.001"; if (main_app().get_version_info(year, release, tag, patch)) { versione.format("%d.%02d", year, release); strpatch.format("%02d.%03d", tag, patch); } TString arg; for (int a = 0; a < main_app().argc(); a++) arg << main_app().argv(a) << ' '; arg.trim(); arg.lower(); TConfig campoini(CONFIG_INSTALL, "Main"); TConfig userini(CONFIG_GUI, "Printer"); TString prot; switch (dongle().hardware()) { case 1: prot = "Hardlock"; break; case 2: prot = "Eutron"; break; case 3: prot = campoini.get("Dongle", "Server"); break; default: prot = TR("Nessuna"); break; } add_row(TR("Versione"), versione); add_row(TR("Patch"), strpatch); add_row(TR("N. di serie"), ser_no); add_row(TR("Protezione"), prot); add_row(TR("Programma"), arg); add_row(TR("Utente"), user()); add_row(TR("Config"), CGetCampoIni()); add_row(TR("Studio"), firm2dir(-1)); add_row(TR("Ditta"), campoini.get("Firm", "Main")); if (prefix_valid()) add_row(TR("Valuta"), TCurrency::get_firm_val()); add_row(TR("Stampante"), userini.get("Name", "Printer")); add_row(TR("Mb su disco"), xvt_fsys_get_disk_free_space(firm2dir(-1), 'M')); add_button(DLG_OK, 0, "", -11, -1, 10, 2); } /////////////////////////////////////////////////////////// // Metodi di accesso globali all'applicazione corrente /////////////////////////////////////////////////////////// HIDDEN TApplication* _application = NULL; // @doc EXTERNAL // @func Ritorna l'applicazione in corso // // @rdesc Ritorna il reference all'applicazione in corso TApplication& main_app() { CHECK(_application, "NULL application!"); return *_application; } // @doc INTERNAL // Ritorna il nome della ditta che vende il programma attuale HIDDEN const char* producer_name(TString& firm) { TConfig ini("install.ini", "Main"); firm = ini.get("Producer"); if (firm.not_empty()) { const char* p = decode(firm); for (const char* c = p; *c; c++) { if (*c > '\0' && *c < ' ') // Hand crafted string? { p = NULL; break; } } firm = p; } if (firm.empty()) { ignore_xvt_errors(TRUE); char* p = firm.get_buffer(80); xvt_res_get_str(STR_FIRMNAME, p, firm.size()); ignore_xvt_errors(FALSE); } if (firm.empty()) firm = "Campo"; return firm; } /////////////////////////////////////////////////////////// // Gestione dello sfondo della finestra principale /////////////////////////////////////////////////////////// HIDDEN long backdrop_eh(WINDOW win, EVENT* ep) { const XVT_DISPLAY_TYPE type = (XVT_DISPLAY_TYPE)xvt_vobj_get_attr(win, ATTR_DISPLAY_TYPE); if (ADVANCED_GRAPHICS && type == XVT_DISPLAY_DIRECT_COLOR) { const int step = 6; RCT r; xvt_vobj_get_client_rect(win, &r); const int bot = r.bottom; xvt_dwin_set_std_cpen(win, TL_PEN_HOLLOW); CBRUSH brush = { PAT_SOLID, COLOR_BLACK }; for (int y = 0; y < bot; y += step) { brush.color = blend_colors(MASK_DARK_COLOR, MASK_LIGHT_COLOR, double(y) / double(bot)); xvt_dwin_set_cbrush(win, &brush); r.top = y; r.bottom = y+step; xvt_dwin_draw_rect(win, &r); } } else xvt_dwin_clear(win, MASK_DARK_COLOR); return 0L; } HIDDEN void create_backdrop(void) { xvt_create_statbar(); xvt_statbar_set(""); } /////////////////////////////////////////////////////////// // Gestione del banner iniziale /////////////////////////////////////////////////////////// class TBanner : public TWindow { bool _updated; protected: virtual void handler(WINDOW win, EVENT* ep); public: bool updated() const { return _updated;} TBanner(); virtual ~TBanner(); }; TBanner::TBanner() { create(-1, 1, 76, 4, "BANNER", WSF_NONE, W_PLAIN); hide_brush(); open(); _updated = false; } TBanner::~TBanner() { if (is_open()) close(); } void TBanner::handler(WINDOW win, EVENT* ep) { if (ep->type == E_UPDATE) { _updated = true; const int BIGY = 3*CHARY/2; RCT r; xvt_vobj_get_client_rect(win, &r); clear(COLOR_LTGRAY); set_color(COLOR_WHITE, COLOR_LTGRAY); set_font(XVT_FFN_TIMES, XVT_FS_BOLD | XVT_FS_ITALIC, BIGY); char* t = (char*)(const char*)main_app().title(); int w = xvt_dwin_get_text_width(win, t, -1); int a; xvt_dwin_get_font_metrics(win, NULL, &a, NULL); int x = (r.right-w)>>1, y = (r.bottom+a)>>1 ; xvt_dwin_draw_text(win, x+1, y+1, t, -1); set_color(COLOR_BLACK, COLOR_LTGRAY); xvt_dwin_draw_text(win, x, y, t, -1); set_font(XVT_FFN_TIMES); TString spa; t = (char*)producer_name(spa); w = xvt_dwin_get_text_width(win, t, -1); x = (r.right-r.left-w)>>1; y = BIGY; xvt_dwin_draw_text(win, x, y, t, -1); r.left += 5; r.right -= 4; r.top += 5; r.bottom -= 4; set_pen(COLOR_WHITE); xvt_dwin_draw_rect(win, &r); xvt_rect_offset(&r, -1, -1); set_pen(COLOR_BLACK); xvt_dwin_draw_rect(win, &r); xvt_dwin_draw_icon(win, CHARX<<1, CHARX<<1, ICON_RSRC); } else TWindow::handler(win, ep); } long TApplication::task_eh(WINDOW win, EVENT *ep) { switch (ep->type) { case E_CREATE: if (_application->pre_create()) { #ifdef _DEMO_ { const TString16 dname(encode("DATA")); const TString16 hname(encode("ORA")); TConfig c(CONFIG_INSTALL, "Main"); TDate data(decode(c.get(dname))); TDate oggi(TODAY); real remaining_time(decode(c.get(hname))); main_app()._start_time = time(NULL); if (data < oggi) { data = oggi; c.set(dname, encode(data)); c.set(hname, encode("120.00")); } else if (data == oggi) { if (remaining_time <= ZERO) exit(0); } else exit(0); } #endif // Setta il vero menu principale se diverso dal default const int meno = _application->argc() > 1 ? atoi(_application->argv(1)+1) : 0; ignore_xvt_errors(TRUE); MENU_ITEM* menu = xvt_res_get_menu(MENU_BAR(meno)); ignore_xvt_errors(FALSE); if (menu) { xvt_menu_set_tree(win, menu); xvt_res_free_menu_tree(menu); } if (dictionary_active()) xvt_menu_translate_tree(win, dictionary_translate_menu_item); // Setta la caption della task window TString cap; TString firm; cap << _application->get_module_name() << " - " << producer_name(firm); TTemp_window tw(win); tw.set_caption(cap); // Carica colori e font customize_controls(TRUE); // Crea il banner iniziale create_backdrop(); do_events(); // strateggicca non scancellare } break; case E_UPDATE: backdrop_eh(win, ep); break; default: break; } return _application->handler(win, ep); } void TApplication::dispatch_e_menu(MENU_TAG tag) { // ::dispatch_e_menu(TASK_WIN, tag); EVENT e; memset(&e, 0, sizeof(e)); e.type = E_COMMAND; e.v.cmd.tag = tag; xvt_win_post_event(TASK_WIN, &e); } long TApplication::handler(WINDOW win, EVENT* ep) { switch (ep->type) { case E_CREATE: { TBanner banner; while (!banner.updated()) { xvt_sys_sleep(10); do_events(); } _create_ok = create(); } if (_create_ok) { on_firm_change(); on_config_change(); return 1; } else stop_run(); break; case E_COMMAND: switch(ep->v.cmd.tag) { case M_FILE_QUIT: if (can_close()) stop_run(); break; case M_FILE_PG_SETUP: printer().set(); break; case M_FILE_PRINT: print(); break; case M_FILE_NEW: set_firm(); break; case (M_FILE_ABOUT+1): about(); break; case M_HELP_CONTENTS: case M_HELP_SEARCH: case M_HELP_HELPONHELP: { TFilename n = "campo"; TString16 module = name(); module.cut(2); if (module != "ba") n.insert(module); FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC)); strcpy(fs.name, n); XVT_HELP_INFO hi = xvt_help_open_helpfile(&fs, 0); xvt_help_process_event(hi, win, ep); } break; default: if (ep->v.cmd.tag > MAX_MENU_TAG) { WINDOW w = cur_win(); if (w != NULL_WIN && w != win) dispatch_event(w, *ep, TRUE); } else { if (ep->v.cmd.tag >= BAR_ITEM(1)) { if(!menu(ep->v.cmd.tag)) stop_run(); } } break; } break; case E_CLOSE: if (can_close()) stop_run(); else return 1; // Divieto! break; case E_QUIT: if (ep->v.query) { if (can_close()) xvt_app_allow_quit(); } else stop_run(); break; default: break; } return 0L; } void TApplication::stop_run() { if (_savefirm) prefix().set_codditta(_savefirm); #ifdef _DEMO_ { const TString16 hname(encode("ORA")); TConfig c(CONFIG_INSTALL, "Main"); real remaining_time(decode(c.get(hname))); if (name() != "ba0100") { time_t wt = time(NULL); int delay = (int) (wt - _start_time); if (delay < 0) remaining_time = ZERO; else remaining_time -= (delay / 60.0); c.set(hname, encode(remaining_time.string())); } else message_box(TR("Questo e' un programma dimostrativo.\nOggi rimangono %s minuti di utilizzo."), remaining_time.string(3, 0)); } #endif terminate(); xvt_app_destroy(); } bool TApplication::add_menu(TString_array& menu, MENU_TAG id) { TTemp_window tw(TASK_WIN); return tw.add_menu(menu,id,TRUE); } bool TApplication::remove_menu(MENU_TAG id) { TTemp_window tw(TASK_WIN); return tw.remove_menu(id); } TApplication::TApplication() : _god_vars(NULL),_savefirm(0), _running(FALSE), _create_ok(FALSE) { } TApplication::~TApplication() { if (_god_vars != NULL) delete _god_vars; } bool TApplication::create() { return TRUE; } bool TApplication::destroy() { return TRUE; } void TApplication::terminate() { close_all_dialogs(); if (_create_ok) destroy(); // Distruzione files e maschere do_events(); if (use_files()) { _used_files.destroy(); free_global_vars(); // Distruzione variabili globali } printer_destroy(); dictionary_close(); xvt_help_close_helpfile(NULL_HELP_INFO); customize_controls(FALSE); // Rilascio eventuali DLL } const char* TApplication::get_module_name() const { TString& module = ((TApplication*)this)->_module_name; // Fool the compiler if (module.empty()) { TScanner scanner(AUT_FILE); bool ok = FALSE; int aut; for (aut = 0; scanner.line() != ""; aut++) if (strncmp(scanner.token(), _name, 2) == 0) { ok = TRUE; break; } module = scanner.token().mid(3); if (ok && check_autorization()) ok = has_module(aut); if (!ok) { if (module.empty()) module = "Tools"; TToken_string em(extra_modules()); if (!em.empty_items()) { if (em != "*") { FOR_EACH_TOKEN(em, cod) { if (has_module(atoi(cod))) { ok = TRUE; break; } } } else ok = TRUE; } if (!ok) { error_box(TR("Il modulo '%s' non e' autorizzato per l'utente %s"), (const char*)module, ((const char*)user())); module.cut(0); } } } return module; } void TApplication::set_perms() { _user_aut.set(0, TRUE); // Attiva la BASE TString& utente = user(); if (utente.not_empty()) { if (utente == ::dongle().administrator()) { for (int i = 1 ; i < ENDAUT; i++) _user_aut.set(i); } else { int err = _iskeynotfound; if (use_files()) { TLocalisamfile users(LF_USER); users.zero(); users.put("USERNAME", utente); err = users.read(); if (err == NOERR) { const TString& aut = users.get("AUTSTR"); if (aut.blank()) { for (int i = 1 ; i < ENDAUT; i++) _user_aut.reset(i); } else { for (int i = aut.len()-1; i > 0; i--) _user_aut.set(i, aut[i] == 'X'); } } } if (err != NOERR && utente == "GUEST") { for (int i = 1 ; i < ENDAUT; i++) _user_aut.set(i); } } } } // @doc EXTERNAL // @mfunc Legge il parametro /uUTENTE e lo toglie dalla lista void TApplication::check_parameters( int & argc, // @parm Numero del parametro da controllare char* argv[]) // @parm Array di paramentri da passare all'applicazione // @comm Nel caso si identifichi che il paramentro

sia il nome dell'utente // si setta la variabile col nome dell'utente, altrimenti l'utente diventa PRASSI, // e si diminuisce di uno il numero di argomenti da passare. { if (argc > 1) { TString u(argv[argc-1]); u.upper(); if (u.compare("-u", 2, TRUE) == 0 || u.compare("/u", 2, TRUE) == 0) { user() = u.mid(2); argc--; } } } bool TApplication::test_assistance_year() const { #ifndef _DEMO_ const int dongle_year = dongle().year_assist(); int app_year, dum1, dum2, dum3; bool ok = TApplication::get_version_info(app_year, dum1, dum2, dum3); if (ok) ok = app_year <= dongle_year; return ok; #else return TRUE; #endif // _DEMO_ } // @doc EXTERNAL // @mfunc Fa partire l'applicazione void TApplication::run( int argc, // @parm Numero deglia argomenti da passara all'applicazione char* argv[], // @parm Argomenti da passare all'applicazione const char* title) // @parm Titolo dell'applicazione // @comm E' in questa fase che si controlla se esiste la chiave e' attaccata { CHECK(_application == NULL, "Sorry, multitasking not implemented"); // Devo metterla qui per far funzionare la TDongle::network_login _application = this; TFilename base(argv[0]); base.ext(""); base.lower(); _title = title; if (user().empty()) check_parameters(argc, argv); _argc_ = argc; _argv_ = (const char**)argv; if (argc > 1 && argv[1][0] == '-') { _name = cmd2name(argv[0], argv[1]); } else { _name = cmd2name(argv[0]); } if (use_files()) init_global_vars(); else CGetPref(); const int sn = get_serial_number(); if (sn < 0) { error_box(TR("Probabilmente non e' inserita la chiave di protezione\noppure mancano i relativi driver.")); return; } if (!test_assistance_year()) { error_box(TR("Probabilmente e' necessario attivare il contratto di assistenza per l'anno in corso")); return; } set_perms(); const char* mod = get_module_name(); if (mod == NULL || *mod == '\0') return; XVT_CONFIG cfg; cfg.menu_bar_ID = TASK_MENUBAR; cfg.about_box_ID = 0; cfg.base_appl_name = (char*)base.name(); cfg.appl_name = (char*)title; cfg.taskwin_title = "CAMPO"; set_xvt_hooks(); _running = TRUE; xvt_app_create(argc, argv, 0L, task_eh, &cfg); } bool TApplication::get_version_info(int& year, int& release, int& tag, int& patch) { const char* const VERSIONANDPATCH = "Don't cry for me Argentina.2002.02.00.000.2004"; TToken_string vep(VERSIONANDPATCH, '.'); year = vep.get_int(1); release = vep.get_int(); tag = vep.get_int(); patch = vep.get_int(); int checksum = vep.get_int(); bool valid = year >= 2002 && release > 0 && tag >= 0 && patch >= 0 && checksum == (year + release + tag + patch); return valid; } // About box: risposta alla opzione Informazioni del menu File void TApplication::about() const { TInfo_mask info; info.run(); } // Risposta alla selezione Stampa del menu File void TApplication::print() { #ifdef DBG NFCHECK("Non saprei bene cosa stampare!"); #endif } void TApplication::check_menu_item(MENU_TAG item) { xvt_menu_set_item_checked(TASK_WIN, item, TRUE); xvt_menu_update(TASK_WIN); } void TApplication::uncheck_menu_item(MENU_TAG item) { xvt_menu_set_item_checked(TASK_WIN, item, FALSE); xvt_menu_update(TASK_WIN); } // @doc EXTERNAL // @mfunc Permette di abilitare/disabilitare una voce di menu' void TApplication::enable_menu_item( MENU_TAG item, // @parm Voce del menu' da abilitare/disabilitare bool on) // @parm Operazione da svolgere sulla voce del menu': // // @flag TRUE | Viene abilitata la voce del menu' // @flag FALSE | Viene disabilitata la voce del menu' { xvt_menu_set_item_enabled(TASK_WIN, item, on); xvt_menu_update(TASK_WIN); } bool TApplication::has_module(int module, int checktype) const { bool ok = TRUE; #ifndef _DEMO_ // Ignora i bit di attivazione della chiave programmatori (sempre attivati) if (get_serial_number() == 0) checktype = CHK_USER; if (checktype == CHK_ALL || checktype == CHK_DONGLE) ok = dongle().active(module); #endif // Testa bit di attivazione dell'utente if (ok && (checktype == CHK_ALL || checktype == CHK_USER)) ok = _user_aut[module]; return ok; } long TApplication::get_firm() const { return prefix().get_codditta(); } const char* TApplication::get_firm_dir() const { return format("%s%s", __ptprf, prefix().name()); } bool TApplication::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(TR("Direttorio dati danneggiato, impossibile attivare la ditta %ld"), codditta); if (!yesno_box(TR("Gli archivi della ditta %ld non esistono: si desidera generarli?"), codditta)) return FALSE; TLocalisamfile ditte(LF_NDITTE); ditte.zero(); ditte.put("CODDITTA",codditta); if (ditte.read(_isequal,_testandlock) == _islocked) { message_box(TR("Archivi della ditta %ld in fase di creazione da parte di un altro utente."),codditta); return FALSE; } set_autoload_new_files(yesno_box(TR("Si desidera precaricare gli archivi standard"))); s = s.path(); s.rtrim(1); if (!fexist(s) && !make_dir(s)) return error_box(TR("Impossibile creare il direttorio della ditta %ld (%s)"), codditta, (const char*)s); s << ndir; if (!fcopy(&ndir[1], s)) return error_box(TR("Impossibile copiare il file %s della ditta %ld"), &ndir[1], codditta); s = s.path(); s << ntrc; if (!fcopy(&ntrc[1], s)) return error_box(TR("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(TR("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 TApplication::set_firm(long newfirm) { const long oldfirm = get_firm(); const bool interactive = newfirm <= 0; #ifndef _DEMO_ if (interactive) { TMask mask("bagn002"); TFilename pp(__ptprf); pp.cut(pp.len()-1); mask.set(F_PATHPREF, pp); mask.show(-2, extended_firm()); disable_menu_item(M_FILE_NEW); const KEY k = mask.run(); enable_menu_item(M_FILE_NEW); if (k == K_ENTER) { newfirm = mask.get_long(F_CODDITTA); const int tipodir = mask.get_int(F_TIPO); if (tipodir == 0 && !prefix().exist(newfirm) && !prefix().build_firm_data(newfirm)) return FALSE; if (tipodir > 0) { if (_savefirm == 0) _savefirm = oldfirm; // E' necessario ricordare la ditta ... prefix().set(tipodir == 1 ? "com" : ""); // ... se si setta il prefix a com return TRUE; } } } #endif if (interactive) { if (newfirm <= 0) return newfirm > 0; } else { if (newfirm == oldfirm || newfirm <= 0) return newfirm > 0; } if (prefix().test(newfirm)) { prefix().set_codditta(newfirm); _savefirm = 0; WINDOW w = cur_win(); if (w != NULL_WIN) { TWindow * win = (TWindow *) xvt_vobj_get_data(w); win->on_firm_change(); } on_firm_change(); on_config_change(); } return TRUE; } // @doc EXTERNAL // @mfunc Controlla se al programma corrente e' concesso cambiare ditta da menu. // // @rdesc Ritorna i seguenti valori: // // @flag TRUE | Se e' abilitata la voce di menu' per il cambio della ditta // @flag FALSE | Se non e' possibile cambiare ditta da menu' bool TApplication::firm_change_enabled() const // @comm Praticamente controlla se e' stato lanciato da ba0 o dal program manager { #ifdef _DEMO_ return false; #else return true; #endif } void TApplication::on_firm_change() {} void TApplication::on_config_change() {} void TApplication::open_files(int logicnum, ...) { va_list marker; va_start(marker, logicnum); while (logicnum > 0 && logicnum < 1000) { if (_used_files.objptr(logicnum) == NULL) _used_files.add(new TLocalisamfile(logicnum), logicnum); logicnum = va_arg(marker, int); } } /////////////////////////////////////////////////////////// // The Skeleton application! /////////////////////////////////////////////////////////// bool TSkeleton_application::create() { dispatch_e_menu(BAR_ITEM(1)); return TApplication::create(); } bool TSkeleton_application::menu(MENU_TAG tag) { if (tag == BAR_ITEM(1)) main_loop(); return FALSE; }