544 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			544 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <stdlib.h>
 | 
						|
 | 
						|
#include <xvt.h>
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <config.h>
 | 
						|
#include <extcdecl.h>
 | 
						|
#include <modaut.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <prefix.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <urldefid.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include <bagn002.h>
 | 
						|
 | 
						|
HIDDEN XVT_CONFIG cfg;
 | 
						|
HIDDEN TApplication* application = NULL;
 | 
						|
HIDDEN long savefirm = 0;
 | 
						|
 | 
						|
TApplication* MainApp()
 | 
						|
{
 | 
						|
  CHECK(application, "NULL application!");
 | 
						|
  return application;
 | 
						|
}
 | 
						|
 | 
						|
bool xvt_running() { return application != NULL; }
 | 
						|
 | 
						|
HIDDEN long backdrop_eh( WINDOW  win, EVENT* ep)
 | 
						|
{
 | 
						|
#if XVTWS == WMWS
 | 
						|
  clear_window( win, COLOR_BLUE );
 | 
						|
#else
 | 
						|
  clear_window( win, COLOR_GRAY );
 | 
						|
  /*
 | 
						|
     const RCT&  rct = ep->v.update.rct;
 | 
						|
     bool even = FALSE;
 | 
						|
     for (int y = 0; y < rct.bottom; y += 96)
 | 
						|
     {
 | 
						|
     const int sx = even ? 96 : 0;
 | 
						|
     for (int x = sx; x < rct.right; x += 192)
 | 
						|
     if (
 | 
						|
     (y+64) > rct.top && y < rct.bottom &&
 | 
						|
     (x+64) > rct.left && x < rct.right
 | 
						|
     ) win_draw_icon(win, x, y, ICON_RSRC);
 | 
						|
     even = !even;
 | 
						|
     }
 | 
						|
     */
 | 
						|
#endif
 | 
						|
 | 
						|
  return 0L;
 | 
						|
}
 | 
						|
 | 
						|
HIDDEN void create_backdrop( void )
 | 
						|
{
 | 
						|
#if XVTWS == WMWS
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MENU,     COLOR_BLACK, COLOR_WHITE);
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DIALOG,   COLOR_BLUE,  COLOR_WHITE);
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_WINDOW,   COLOR_RED,  COLOR_WHITE);
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_CONTROL,  COLOR_BLACK, COLOR_WHITE);
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_DISABLED, COLOR_GRAY,  COLOR_WHITE);
 | 
						|
  xvt_escape(XVT_ESC_CH_COLOR, XVT_CH_CLR_MNEMONIC, COLOR_RED,   COLOR_WHITE);
 | 
						|
 | 
						|
  RCT rct;
 | 
						|
  get_client_rect( SCREEN_WIN, &rct );
 | 
						|
  create_window(W_PLAIN, &rct, (char*) "BACKDROP", 0, TASK_WIN,
 | 
						|
                WSF_NO_MENUBAR | WSF_CH_BACKDROP , EM_UPDATE,
 | 
						|
                backdrop_eh, 0L );
 | 
						|
#else
 | 
						|
  xvt_create_statbar();
 | 
						|
  xvt_statbar_set("");
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
#if XVT_OS == XVT_OS_WIN
 | 
						|
 | 
						|
#include <windows.h>
 | 
						|
 | 
						|
const word WM_WAKEUP = RegisterWindowMessage("WAKEUP");
 | 
						|
DWORD waiting_for = 0;
 | 
						|
 | 
						|
BOOLEAN waiting_event_hook(HWND, WORD msg, WORD,
 | 
						|
                           DWORD lparam, long far* ret)
 | 
						|
{
 | 
						|
  if (msg == WM_WAKEUP)
 | 
						|
  {
 | 
						|
    if( lparam == waiting_for || lparam == 0)
 | 
						|
    {
 | 
						|
      waiting_for = 0L;
 | 
						|
      TTemp_window tw(TASK_WIN);
 | 
						|
      tw.maximize();
 | 
						|
    }
 | 
						|
    *ret = 0;
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
HIDDEN DWORD name2id(const char* name)
 | 
						|
{
 | 
						|
  waiting_for = 0L;
 | 
						|
  for (int i = 0; i < 5 && name[i] > ' '; i++)
 | 
						|
  {
 | 
						|
    waiting_for <<= 6;
 | 
						|
    waiting_for |= toupper(name[i]) - '0';
 | 
						|
  }
 | 
						|
  return waiting_for;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::wait_for(const char* command)
 | 
						|
{
 | 
						|
  TTemp_window tw(TASK_WIN);
 | 
						|
  tw.iconize();
 | 
						|
  name2id(cmd2name(command));
 | 
						|
  set_value(TASK_WIN, ATTR_EVENT_HOOK, (long)waiting_event_hook);
 | 
						|
  while (waiting_for) do_events();
 | 
						|
 | 
						|
  ///////////////////////////////////////////////////////////
 | 
						|
    // It seems necessary to restore these things
 | 
						|
    ///////////////////////////////////////////////////////////
 | 
						|
      customize_controls(TRUE);
 | 
						|
  xvt_statbar_refresh();
 | 
						|
}
 | 
						|
 | 
						|
void TApplication::wake_up_caller() const
 | 
						|
{
 | 
						|
  name2id(name());
 | 
						|
  SendMessage(-1, WM_WAKEUP, 0, waiting_for);
 | 
						|
}
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
 | 
						|
void TApplication::print()
 | 
						|
{
 | 
						|
#ifdef DBG
 | 
						|
  error_box("Non saprei bene cosa stampare!");
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
long TApplication::task_eh(WINDOW win, EVENT *ep)
 | 
						|
{
 | 
						|
  switch (ep->type)
 | 
						|
  {
 | 
						|
  case E_CREATE:
 | 
						|
    create_backdrop();
 | 
						|
#if defined(DBG) && XVT_OS == XVT_OS_SCOUNIX
 | 
						|
    message_box("Attach to process %d ...", getpid());
 | 
						|
#endif
 | 
						|
    do_events();
 | 
						|
    break;
 | 
						|
#if XVT_OS == XVT_OS_WIN
 | 
						|
  case E_UPDATE:
 | 
						|
    backdrop_eh(win, ep);
 | 
						|
    break;
 | 
						|
#endif
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
 | 
						|
  return application->handler(win, ep);
 | 
						|
}
 | 
						|
 | 
						|
void TApplication::about() const
 | 
						|
{                                               
 | 
						|
#include <prassi.ver>             
 | 
						|
  const TFilename n(__argv[0]);
 | 
						|
  message_box("PRASSI Versione %g\nProgramma %s\nLibreria del %s", 
 | 
						|
              VERSION, (const char*)n.name(), __DATE__);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
long TApplication::handler(WINDOW, EVENT* ep)
 | 
						|
{
 | 
						|
  switch (ep->type)
 | 
						|
  {
 | 
						|
  case E_CREATE:
 | 
						|
    if (create() == FALSE)
 | 
						|
      stop_run();
 | 
						|
    break;
 | 
						|
  case E_CHAR:
 | 
						|
  {
 | 
						|
#ifdef DBG
 | 
						|
    KEY k = e_char_to_key(ep);
 | 
						|
#endif      
 | 
						|
  }
 | 
						|
    break;
 | 
						|
  case E_COMMAND:
 | 
						|
  {
 | 
						|
    MENU_TAG mt = ep->v.cmd.tag;
 | 
						|
    switch(mt)
 | 
						|
    {
 | 
						|
    case M_FILE_QUIT:
 | 
						|
      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_REVERT:
 | 
						|
      config();
 | 
						|
      break;
 | 
						|
    case (M_FILE+11)    :
 | 
						|
      about();
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      if (mt >= BAR_ITEM(1))
 | 
						|
      {
 | 
						|
        if(!menu(mt))
 | 
						|
          stop_run();
 | 
						|
      }   
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
    break;
 | 
						|
  case E_CLOSE:
 | 
						|
    if (can_close())
 | 
						|
      stop_run();
 | 
						|
    break;
 | 
						|
  case E_QUIT:
 | 
						|
    if (ep->v.query) 
 | 
						|
    {
 | 
						|
      if (can_close())
 | 
						|
        quit_OK();
 | 
						|
      else
 | 
						|
        error_box("Chiudere la finestra attiva prima di terminare il programma");
 | 
						|
    } 
 | 
						|
    else stop_run();
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return 0L;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::stop_run()
 | 
						|
{
 | 
						|
  if (savefirm) prefhndl->set_codditta(savefirm);
 | 
						|
  terminate();
 | 
						|
  //#if XVT_OS == XVT_OS_WIN
 | 
						|
  //      xvt_escape(XVT_ESC_WIN_TERMINATE);
 | 
						|
  //#else
 | 
						|
  xvt_terminate();
 | 
						|
  //#endif
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TApplication::TApplication() : _printer(NULL)
 | 
						|
{
 | 
						|
  init_global_vars();
 | 
						|
  _bar = TASK_MENUBAR;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TApplication::~TApplication()
 | 
						|
{}
 | 
						|
 | 
						|
 | 
						|
TPrinter* TApplication::set_printer(TPrinter* p)
 | 
						|
{
 | 
						|
  TPrinter*  printer = _printer;
 | 
						|
  _printer = p;
 | 
						|
  return printer;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TPrinter& TApplication::printer()
 | 
						|
{
 | 
						|
  if (_printer  == NULL) _printer = new TPrinter;
 | 
						|
  return *_printer;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TApplication::create()
 | 
						|
{
 | 
						|
  // include_progind();  // TBC da eliminare quando il linker diventa furbo
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TApplication::destroy()
 | 
						|
{
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::terminate()
 | 
						|
{
 | 
						|
#if XVT_OS == XVT_OS_WIN
 | 
						|
  wake_up_caller();       // Manda il segnale di risveglio al chiamante
 | 
						|
#endif
 | 
						|
 | 
						|
  close_all_dialogs();
 | 
						|
  application->destroy(); // Distruzione files e maschere
 | 
						|
  do_events();
 | 
						|
 | 
						|
  if (_printer)   // Distruzione dell'eventuale stampante
 | 
						|
  {
 | 
						|
    if (printer().isopen())
 | 
						|
      printer().close();
 | 
						|
    delete _printer;
 | 
						|
    _printer = NULL;
 | 
						|
  }
 | 
						|
 | 
						|
  free_global_vars();     // Distruzione variabili globali
 | 
						|
 | 
						|
  customize_controls(FALSE);      // Rilascio eventuali DLL
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
const char* TApplication::get_module_name() const
 | 
						|
{
 | 
						|
  TScanner scanner("prassi.aut");
 | 
						|
 | 
						|
  bool ok = FALSE;
 | 
						|
  for (int aut = 0; scanner.line() != ""; aut++)
 | 
						|
    if (strncmp(scanner.token(), _name, 2) == 0) { ok = TRUE; break; }
 | 
						|
 | 
						|
  const char* module = scanner.token().mid(3);
 | 
						|
  if (ok) ok = has_module(aut);
 | 
						|
 | 
						|
  if (!ok)
 | 
						|
    fatal_box("Il modulo '%s' non e' autorizzato", module);
 | 
						|
 | 
						|
  return module;
 | 
						|
}
 | 
						|
 | 
						|
void TApplication::set_title(const char* t)
 | 
						|
{ cfg.appl_name = (char*)t; }
 | 
						|
 | 
						|
const char* TApplication::title() const
 | 
						|
{ return cfg.appl_name; }
 | 
						|
 | 
						|
void TApplication::run(int argc, char* argv[], const char* title)
 | 
						|
{
 | 
						|
  TFilename base(argv[0]);
 | 
						|
  base.ext(""); base.lower();
 | 
						|
 | 
						|
  __argc = argc;
 | 
						|
  __argv = (const char**)argv;
 | 
						|
 | 
						|
  int addbar;
 | 
						|
  if (argc > 1)
 | 
						|
  {
 | 
						|
    addbar = atoi(argv[1]+1);
 | 
						|
    _name = cmd2name(argv[0], argv[1]);
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    addbar = 0;
 | 
						|
    _name = cmd2name(argv[0]);
 | 
						|
  }
 | 
						|
 | 
						|
  TString80 caption;
 | 
						|
  caption << "PRASSI S.P.A. - " << get_module_name();
 | 
						|
 | 
						|
  cfg.base_appl_name = (char*) base.name();
 | 
						|
  cfg.appl_name      = (char*) title;
 | 
						|
  cfg.taskwin_title  = (char*)(const char*)caption;
 | 
						|
  cfg.menu_bar_ID    = TASK_MENUBAR+addbar;
 | 
						|
  cfg.about_box_ID   = 0;
 | 
						|
 | 
						|
  customize_controls(TRUE);
 | 
						|
 | 
						|
  application = this;
 | 
						|
  xvt_system(argc, argv, 0L, task_eh, &cfg);
 | 
						|
}
 | 
						|
 | 
						|
void TApplication::check_menu_item(MENU_TAG item)
 | 
						|
{
 | 
						|
  win_menu_check(TASK_WIN, item, TRUE);
 | 
						|
  win_update_menu_bar(TASK_WIN);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::uncheck_menu_item(MENU_TAG item)
 | 
						|
{
 | 
						|
  win_menu_check(TASK_WIN, item, FALSE);
 | 
						|
  win_update_menu_bar(TASK_WIN);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::enable_menu_item(MENU_TAG item, bool on)
 | 
						|
{
 | 
						|
  win_menu_enable(TASK_WIN, item, on);
 | 
						|
  win_update_menu_bar(TASK_WIN);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TApplication::dispatch_e_menu(MENU_TAG item)
 | 
						|
 | 
						|
{
 | 
						|
#if XVT_OS == XVT_OS_WIN
 | 
						|
  HWND w = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW);
 | 
						|
  PostMessage(w, WM_COMMAND, item, 0L);
 | 
						|
#else
 | 
						|
  EVENT e;
 | 
						|
  e.type = E_COMMAND;
 | 
						|
  e.v.cmd.tag = item;
 | 
						|
  e.v.cmd.shift = e.v.cmd.control = 0;
 | 
						|
  dispatch_event(TASK_WIN, &e);
 | 
						|
#endif  
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TApplication::has_module(int module) const
 | 
						|
{
 | 
						|
  return (bool)CGetAut(module);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
long TApplication::get_firm() const
 | 
						|
{
 | 
						|
  return prefhndl->get_codditta();
 | 
						|
}
 | 
						|
 | 
						|
const char* TApplication::get_firm_dir() const
 | 
						|
{
 | 
						|
  return format("%s%s", __ptprf, prefhndl->name());
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TApplication::set_firm(long newfirm)
 | 
						|
{
 | 
						|
  disable_menu_item(M_FILE_NEW);
 | 
						|
  const long oldfirm = get_firm();
 | 
						|
 | 
						|
  if (newfirm < 1)
 | 
						|
  {
 | 
						|
    TMask mask("bagn002");
 | 
						|
 | 
						|
    mask.send_key(K_CTRL+K_SHIFT+(extended_firm() ? 's' : 'h'), -2);
 | 
						|
    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)
 | 
						|
      {
 | 
						|
        if (savefirm == 0) savefirm = oldfirm;
 | 
						|
        prefhndl->set(tipodir == 1 ? "com" : "");
 | 
						|
        return TRUE;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  if (newfirm == oldfirm || newfirm < 1)
 | 
						|
    return FALSE;
 | 
						|
 | 
						|
  if (prefhndl->test(newfirm))
 | 
						|
  {
 | 
						|
    prefhndl->set_codditta(newfirm);
 | 
						|
    savefirm = 0;
 | 
						|
  }
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TApplication::config()
 | 
						|
  // gestisce le voci di configurazione
 | 
						|
  // le si passa il file in cui cercare il proprio
 | 
						|
  // paragrafo (comunque relativo alla ditta)
 | 
						|
  // se non c'e', viene creato copiando il default
 | 
						|
  // la variabile EdMask di quel paragrafo specifica
 | 
						|
  // la maschera da usare
 | 
						|
{
 | 
						|
  TConfig cnf(CONFIG_DITTA);
 | 
						|
  bool ok = FALSE;
 | 
						|
  
 | 
						|
  TString80 maskname(cnf.get("EdMask"));
 | 
						|
  if (!maskname.empty())
 | 
						|
  {
 | 
						|
    TMask m(maskname);
 | 
						|
    
 | 
						|
    // carica campi
 | 
						|
    for (int i = 0; i < m.fields(); i++)
 | 
						|
    {
 | 
						|
      TMask_field& f = m.fld(i);
 | 
						|
      const TFieldref* fref = f.field();
 | 
						|
      if (fref != NULL)
 | 
						|
      {
 | 
						|
        const char* fname = fref->name();
 | 
						|
        if (fname != NULL)
 | 
						|
        {
 | 
						|
          TString& oldvl = cnf.get(fname);
 | 
						|
          if (!oldvl.empty())
 | 
						|
            f.set(oldvl);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    
 | 
						|
    
 | 
						|
    // run mask
 | 
						|
    disable_menu_item(M_FILE_NEW);
 | 
						|
    disable_menu_item(M_FILE_REVERT);
 | 
						|
    
 | 
						|
    if (m.run() == K_ENTER)
 | 
						|
    {
 | 
						|
      // aggiusta campi
 | 
						|
      for (i = 0; i < m.fields(); i++)
 | 
						|
      {
 | 
						|
        TMask_field& f = m.fld(i);
 | 
						|
        if (f.dirty())
 | 
						|
        {
 | 
						|
          const TFieldref* fref = f.field();
 | 
						|
          if (fref != NULL)
 | 
						|
          {
 | 
						|
            const char* fname = fref->name();
 | 
						|
            const char* value = f.get();
 | 
						|
            const char* oldvl = cnf.get(fname);
 | 
						|
            if (change_config(fname,oldvl,value))
 | 
						|
              cnf.set(fname, value, NULL, TRUE);
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
      ok = TRUE;
 | 
						|
    }
 | 
						|
    else  ok = FALSE;
 | 
						|
    enable_menu_item(M_FILE_NEW);
 | 
						|
    enable_menu_item(M_FILE_REVERT);
 | 
						|
    return ok;
 | 
						|
  }
 | 
						|
  return warning_box("Nessun parametro da configurare");
 | 
						|
}
 | 
						|
 | 
						|
bool TApplication::change_config(const char* var, const char* oldv,
 | 
						|
                                 const char* newv)
 | 
						|
 | 
						|
{ return TRUE; }
 |