From 5fc07b4f6312e491d577932e4785330d9c471ed3 Mon Sep 17 00:00:00 2001
From: guy <guy@c028cbd2-c16b-5b4b-a496-9718f37d4682>
Date: Wed, 30 Nov 1994 09:04:03 +0000
Subject: [PATCH] Nuovo modo di notificare i cambiamenti dei parametri

git-svn-id: svn://10.65.10.50/trunk@705 c028cbd2-c16b-5b4b-a496-9718f37d4682
---
 include/applicat.cpp | 43 ++++++++++++++++++++++++---------------
 include/applicat.h   | 10 +++++----
 include/confapp.cpp  |  2 --
 include/config.cpp   |  5 ++---
 include/execp.cpp    | 11 +++++++---
 include/isam.cpp     |  8 +++++---
 include/mask.cpp     | 36 ++++++++++++++++++++++++++-------
 include/mask.h       |  1 +
 include/maskfld.cpp  | 18 +++++++++--------
 include/msksheet.cpp | 48 ++++++++++++++++++++++++--------------------
 include/prassi.ver   |  2 +-
 include/relapp.cpp   | 39 +++++++++++++++++++++++++++--------
 include/window.cpp   |  1 -
 13 files changed, 146 insertions(+), 78 deletions(-)

diff --git a/include/applicat.cpp b/include/applicat.cpp
index c1b2a11e0..700097766 100755
--- a/include/applicat.cpp
+++ b/include/applicat.cpp
@@ -247,7 +247,12 @@ long TApplication::handler(WINDOW win, EVENT* ep)
     TBanner banner;
     _create_ok = create();
   }    
-  if (!_create_ok)  
+  if (_create_ok)  
+  {
+    on_firm_change();
+    on_config_change();
+  }  
+  else
     stop_run();
 #if XVT_OS == XVT_OS_SCOUNIX
 else
@@ -272,6 +277,7 @@ else
     break;
   case M_FILE_REVERT:
     config();
+    on_config_change();
     break;
   case (M_FILE+11):
     about();
@@ -614,6 +620,19 @@ bool TApplication::set_firm(long newfirm)
   {
     prefhndl->set_codditta(newfirm);
     _savefirm = 0;
+    
+    WINDOW w = cur_win();
+    if (w != NULL_WIN)       
+    {
+      EVENT e;
+      e.type = E_COMMAND;
+      e.v.cmd.tag = M_FILE_NEW;
+      e.v.cmd.shift = e.v.cmd.control = 0;
+      dispatch_event(w, &e);
+    }  
+
+    on_firm_change();
+    on_config_change();
   }
 
   return TRUE;
@@ -652,12 +671,10 @@ bool TApplication::config()
       }
     }
     
-    
     // run mask
-    disable_menu_item(M_FILE_NEW);
     disable_menu_item(M_FILE_REVERT);
     
-    if (m.run() == K_ENTER)
+    if (m.run() == K_ENTER && m.dirty())
     {
       // aggiusta campi
       for (i = 0; i < m.fields(); i++)
@@ -667,26 +684,20 @@ bool TApplication::config()
         {
           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);
-          }
+            cnf.set(fref->name(), f.get(), 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)
+void TApplication::on_firm_change()
+{}
 
-{ return TRUE; }
+void TApplication::on_config_change()
+{}
diff --git a/include/applicat.h b/include/applicat.h
index b0f4904ac..cfaa43db8 100755
--- a/include/applicat.h
+++ b/include/applicat.h
@@ -16,9 +16,9 @@
 #define MSG_AI "AI"      // message auto_insert          (relapp)
 #define MSG_FS "FS"      // message filtered start (relapp)
 #define MSG_LN "LN"      // message  (printapp -> relapp)
-#define CHK_ALL -1                       // all authorization checks
-#define CHK_DONGLE 0             // dongle authorization checks
-#define CHK_USER 1                       // user authorization checks
+#define CHK_ALL -1       // all authorization checks
+#define CHK_DONGLE 0     // dongle authorization checks
+#define CHK_USER 1       // user authorization checks
 
 class TApplication
 {
@@ -49,7 +49,9 @@ protected:
   virtual bool destroy();       // Rimuove l'applicazione
   virtual void print();
 
-  virtual bool change_config(const char* var, const char* oldv, const char* newv);
+  virtual void on_config_change();
+  virtual void on_firm_change();
+
   void set_user(const char * user) { _user = user; }
 
   void terminate();
diff --git a/include/confapp.cpp b/include/confapp.cpp
index c748992ff..4719cd747 100755
--- a/include/confapp.cpp
+++ b/include/confapp.cpp
@@ -2,9 +2,7 @@
 #include <urldefid.h>
 #include <utility.h>
 #include <mask.h>
-#include <maskfld.h>
 #include <relation.h>
-#include <xvtility.h>
 
 bool TConfig_application::create()
 {
diff --git a/include/config.cpp b/include/config.cpp
index 5d22a93d4..40fa6114f 100755
--- a/include/config.cpp
+++ b/include/config.cpp
@@ -94,9 +94,8 @@ void TConfig::_write_file()
 
   out.close(); in.close();
   TFilename bak(_file); bak.ext("bak");
-  rename(_file,bak);
-  fcopy(temp,_file);
-  remove(temp);
+  rename(_file, bak);
+  rename(temp, _file);
 }
 
 
diff --git a/include/execp.cpp b/include/execp.cpp
index 68298d3b9..977ca0c08 100755
--- a/include/execp.cpp
+++ b/include/execp.cpp
@@ -47,9 +47,14 @@ bool TExternal_app::can_run() const
 int TExternal_app::run(bool async, bool iconized)
 {
   TString256 path(_path);
-  if (iconized)
-    path << " -icon"; 
-  path << " -u" << main_app().user();
+  
+  if (!async)
+  {
+    if (iconized)
+      path << " -icon"; 
+    path << " -u" << main_app().user();
+  }
+  
   _error = 0;
   _exitcode =  0;
 
diff --git a/include/isam.cpp b/include/isam.cpp
index 74479e142..addafe05e 100755
--- a/include/isam.cpp
+++ b/include/isam.cpp
@@ -1329,17 +1329,19 @@ void TBaseisamfile::recover()
 
   fn = fn.name();
 #ifndef FOXPRO
-  if (yesno_box("La dimensione dell' archivio %s e' errata. Cerco di recuperarlo?", (const char *) fn))
+  if (yesno_box("La dimensione dell'archivio %s e' errata. Cerco di recuperarlo?", (const char *)fn))
   {
     TDir d;
     TString mess(80);
 
     mess.format("Ricostruzione archivio %s : I Fase", (const char*) fn);
     TProgind p(nitems ? nitems : 1, mess, TRUE, TRUE, 70);
-    d.get(num(), _lock, _nordir, _sysdirop);
+    
+    const TDirtype dir = (fh->ft == 0) ? _nordir : _comdir; 
+    d.get(num(), _lock, dir, _sysdirop);
     d.eod() = fh->d->EOD = nitems;
     d.eox() = fh->d->EOX = nitems;
-    d.put(num(), _nordir, _sysdirop);
+    d.put(num(), dir, _sysdirop);
     for (TRecnotype r = 1; r <= nitems; r++)
     {
       p.addstatus(1);
diff --git a/include/mask.cpp b/include/mask.cpp
index 8331da09a..9608f0fd8 100755
--- a/include/mask.cpp
+++ b/include/mask.cpp
@@ -131,6 +131,10 @@ void TMask::handler(WINDOW win, EVENT* ep)
 #endif
     update();
     return;
+  case E_COMMAND:
+    if (ep->v.cmd.tag == M_FILE_NEW)
+      on_firm_change();
+    break;  
   case E_CONTROL:
     switch(ep->v.ctl.id)
     {
@@ -201,6 +205,7 @@ void TMask::read_mask(const char* name, int num, int max)
   TScanner scanner(_source_file);
 
   _sheetmask = num > 0;
+  
   for (int i = 0; i < num; i++)
   {
     while (scanner.ok())
@@ -1040,7 +1045,6 @@ byte TMask::num_keys() const
   return max;
 }
 
-
 void TMask::enable_key(byte key, bool on)
 {
   for (int i = 0; i < fields(); i++)
@@ -1101,9 +1105,10 @@ bool TMask::key_valid(int key) const
 
 void TMask::show(short fld_id, bool on)
 {
-  if (fld_id < 1)
-  {
-    for (int i = 0; i < fields(); i++)
+  if (fld_id <= 0)
+  {        
+    const int gr = -fld_id;
+    for (int i = 0; i < fields(); i++) if (fld(i).in_group(gr)) 
       fld(i).show(on);
   } else field(fld_id).show(on);
 }
@@ -1111,7 +1116,7 @@ void TMask::show(short fld_id, bool on)
 
 void TMask::show_default(short fld_id)
 {
-  if (fld_id < 1)
+  if (fld_id <= 0)
   {
     for (int i = 0; i < fields(); i++)
       fld(i).show_default();
@@ -1146,6 +1151,23 @@ void TMask::autosave(TRelation* r) const
   }
 }
 
+void TMask::on_firm_change()
+{
+  TString16 firm; firm << main_app().get_firm();
+  
+  for (int i = 0; i < fields(); i++)
+  {
+    TMask_field& f = fld(i);
+    if (f._flags.firm)
+    {
+      f.set(firm);
+      f.check(STARTING_CHECK);
+      f.on_hit();
+    }  
+  }  
+}
+
+
 void TMask::send_key(KEY key, short to, TMask_field* from)
 {
   if (to == 0)
@@ -1178,11 +1200,11 @@ void TMask::send_key(KEY key, short to, TMask_field* from)
   else
   {
     const int max = fields();
-    to = -to;
+    const int gr = -to;
     for (int i = 0; i < max; i++)
     {
       TMask_field& campo = fld(i);
-      if (campo.in_group((int)to))
+      if (campo.in_group(gr))
         campo.on_key(key);
     }
   }
diff --git a/include/mask.h b/include/mask.h
index 57687d217..a3be95324 100755
--- a/include/mask.h
+++ b/include/mask.h
@@ -147,6 +147,7 @@ public:
   int focus_field() const { return _focus;}
 
   virtual bool on_key(KEY key);
+  void on_firm_change();
   
   void enable(short fld_id, bool on = TRUE);               // Abilita un campo
   void disable(short fld_id) { enable(fld_id, FALSE); }
diff --git a/include/maskfld.cpp b/include/maskfld.cpp
index fab9b5d7b..ed1105978 100755
--- a/include/maskfld.cpp
+++ b/include/maskfld.cpp
@@ -1,4 +1,4 @@
-//      $Id: maskfld.cpp,v 1.54 1994-11-29 17:34:25 alex Exp $
+//      $Id: maskfld.cpp,v 1.55 1994-11-30 09:03:49 guy Exp $
 #include <xvt.h>
 
 #include <applicat.h>
@@ -1515,10 +1515,6 @@ bool TBrowse::check(CheckTime t)
   if (_secondary == TRUE && t != RUNNING_CHECK)
     return TRUE;
 
-  //    if (_checked && t == FINAL_CHECK)
-  //      return TRUE;
-  //    _checked = TRUE;
-
   if (_fld->check_type() != CHECK_NONE)
   {
     const TMaskmode mode = (TMaskmode)field().mask().mode();
@@ -2400,13 +2396,19 @@ bool TDate_field::on_key(KEY key)
           changed = TRUE;
         }
         else
-          if (data == "ULTIMO")
+          if (data == "NATALE")
           {
-            gstring.overwrite("31-12", 0);
+            gstring.overwrite("25-12", 0);
             changed = TRUE;
           }
           else
-            if (data == "OGGI") changed = TRUE;
+            if (data == "ULTIMO")
+            {
+              gstring.overwrite("31-12", 0);
+              changed = TRUE;
+            }
+            else
+              if (data == "OGGI") changed = TRUE;
         if (changed) data = gstring;
       }
 
diff --git a/include/msksheet.cpp b/include/msksheet.cpp
index c30a6e693..458de2f88 100755
--- a/include/msksheet.cpp
+++ b/include/msksheet.cpp
@@ -18,6 +18,8 @@ const short FIRST_FIELD = 101;
 
 class TSpreadsheet : public TWindow
 {
+  friend class TSheet_field;
+
   enum { ITF_CID = 0, LIST_CID = 1 };
 
   TArray _str;                // Array di TToken_strings
@@ -70,7 +72,7 @@ public:
   bool cell_disabled(int row, int column) const;
 
   TMask& sheet_mask() { return _mask; }
-  TMask& mask();
+  TMask& mask() const;
   
   void mask2str(int n);
   void str2mask(int n);
@@ -251,7 +253,7 @@ TSpreadsheet::TSpreadsheet(short x, short y, short dx, short dy,
 }
 
 TSpreadsheet::~TSpreadsheet() 
-{ 
+{                    
   set_win(NULL_WIN); 
 }             
 
@@ -322,7 +324,6 @@ void TSpreadsheet::update_rec(int rec)
 
 void TSpreadsheet::set_focus_cell(int riga, int colonna)
 {                 
-  _firstfocus = FALSE;
   set_front_window(win());    // It seems necessary to make xi_set_focus work properly
   const int r = rec2row(riga);
   XI_OBJ cell;     
@@ -551,7 +552,7 @@ break;
 {
   _check_enabled = FALSE;                 // Avoid recursion!
   str2mask(_cur_row);                     // It shouldn't have to be necessary
-  bool ok = _mask.check_fields();
+  bool ok = sheet_mask().check_fields();
   if (ok) 
   { 
     mask2str(_cur_row);               
@@ -710,23 +711,23 @@ break;
 void TSpreadsheet::enable(bool on)
 {
   const dword old = xi_get_attrib(_list);
-  const dword att = on ? (old & ~XI_ATR_NAVIGATE) : (old | XI_ATR_NAVIGATE);
+  dword att = on ? (old & ~XI_ATR_NAVIGATE) : (old | XI_ATR_NAVIGATE);
   if (old != att) 
   {
     int num;
     XI_OBJ** columns = xi_get_member_list(_list, &num);
     
     xi_move_focus(_itf);                  // Set focus to interface
+    att = on ? (att | XI_ATR_TABWRAP) : (att & ~XI_ATR_TABWRAP);
     xi_set_attrib(_list, att);        
     
-    att = on ? (att | XI_ATR_TABWRAP) : (att & ~XI_ATR_TABWRAP);
     for (int col = 1; col < num; col++)
     {
       XI_OBJ* column = columns[col];
-      dword attr = xi_get_attrib(column);
-      if (on) attr &= ~XI_ATR_READONLY;
-      else    attr |= XI_ATR_READONLY;
-      xi_set_attrib(column, attr);          // Set new attributes
+      att = xi_get_attrib(column);
+      if (on) att &= ~XI_ATR_READONLY;
+      else    att |= XI_ATR_READONLY;
+      xi_set_attrib(column, att);          // Set new attributes
     }  
   }  
 }
@@ -852,7 +853,7 @@ bool TSpreadsheet::on_key(KEY k)
 // Metodi di TSpreadsheet comuni a tutte le piattaforme
 ///////////////////////////////////////////////////////////
 
-TMask& TSpreadsheet::mask()
+TMask& TSpreadsheet::mask() const
 {
   TMask* m = (TMask*)get_app_data(parent());
   return *m;
@@ -873,12 +874,12 @@ void TSpreadsheet::mask2str(int riga)
   r.cut(0);
   for (short id = FIRST_FIELD; ; id++)
   {                                 
-    int pos = _mask.id2pos(id);
+    int pos = sheet_mask().id2pos(id);
     if (pos < 0) break;
     
-    for(int dlg = id; pos >= 0; pos = _mask.id2pos(dlg += 100))
+    for(int dlg = id; pos >= 0; pos = sheet_mask().id2pos(dlg += 100))
     {
-      const TMask_field& f = _mask.fld(pos);
+      const TMask_field& f = sheet_mask().fld(pos);
       if (f.showed())
       {
         r.add(f.get());
@@ -968,7 +969,7 @@ void TSpreadsheet::str2mask(int riga)
 {
   if (riga == items())
   {
-    _mask.reset();
+    sheet_mask().reset();
     mask2str(riga);
     return;
   }
@@ -978,7 +979,7 @@ void TSpreadsheet::str2mask(int riga)
   TString80 val;  
   for (short id = FIRST_FIELD; ; id++)
   {
-    int pos = _mask.id2pos(id);
+    int pos = sheet_mask().id2pos(id);
     if (pos < 0) break;
 
     val = r.get(); // Value to set
@@ -986,7 +987,7 @@ void TSpreadsheet::str2mask(int riga)
     int rid = id;
     while (pos >= 0)
     {
-      TMask_field& f = _mask.fld(pos);
+      TMask_field& f = sheet_mask().fld(pos);
       f.set(val);
       f.enable(!cell_disabled(riga, id-FIRST_FIELD));
 
@@ -1001,14 +1002,14 @@ void TSpreadsheet::str2mask(int riga)
         f.set_dirty(FALSE);
       }
       else
-        _mask.first_focus(-rid);
+        sheet_mask().first_focus(-rid);
       
       rid += 100;
-      pos = _mask.id2pos(rid);
+      pos = sheet_mask().id2pos(rid);
     }
   }
 
-  _mask.set_caption(format("Riga %d", riga+1));
+  sheet_mask().set_caption(format("Riga %d", riga+1));
 }
 
 
@@ -1032,7 +1033,7 @@ KEY TSpreadsheet::edit(int n, KEY tasto)
   const int olditems = items();
   str2mask(n);
 
-  const KEY k = _mask.run();
+  const KEY k = sheet_mask().run();
 
   if (k == K_ENTER)
   {
@@ -1185,8 +1186,11 @@ void TSheet_field::set_notify(SPREADSHEET_NOTIFY n)
 void TSheet_field::highlight() const
 {
 #if XVT_OS == XVT_OS_WIN
-  if (items())
+  if (_sheet->_firstfocus && items())
+  {
+    _sheet->_firstfocus = FALSE;
     _sheet->set_focus_cell(0, 1);
+  }  
 #else 
   TMask_field::highlight();
 #endif
diff --git a/include/prassi.ver b/include/prassi.ver
index 2b2f55dd9..422744e78 100755
--- a/include/prassi.ver
+++ b/include/prassi.ver
@@ -1 +1 @@
-#define VERSION 1.16
+#define VERSION 1.17
diff --git a/include/relapp.cpp b/include/relapp.cpp
index 31c434e1a..9087a91df 100755
--- a/include/relapp.cpp
+++ b/include/relapp.cpp
@@ -1,4 +1,4 @@
-//      $Id: relapp.cpp,v 1.34 1994-11-24 14:01:16 guy Exp $        
+//      $Id: relapp.cpp,v 1.35 1994-11-30 09:04:01 guy Exp $        
 #include <mailbox.h>
 #include <sheet.h>
 #include <urldefid.h>
@@ -7,11 +7,35 @@
 #include <xvtility.h>
 
 #if XVT_OS == XVT_OS_WIN
-extern "C" {
-#include <statbar.h>
-}
+#include <windows.h>
+#include <toolhelp.h>
 #endif
 
+HIDDEN bool can_change_firm()
+{   
+#ifndef DBG
+  static bool can = 2;
+  if (can == 2)
+  {
+#if XVT_OS == XVT_OS_WIN
+    HTASK ct = GetCurrentTask();
+    TASKENTRY te;
+    te.dwSize = sizeof(TASKENTRY);
+    TaskFindHandle(&te, ct);
+    TaskFindHandle(&te, te.hTaskParent);
+    can = strcmp(te.szModule, "BA0") == 0;
+#else
+    can = TRUE;  
+#endif  
+  }
+  return can;
+#else           /* DBG */
+  return TRUE;  
+#endif  
+}
+
+
+
 ///////////////////////////////////////////////////////////
 // Array delle chiavi della maschera di ricerca
 ///////////////////////////////////////////////////////////
@@ -709,11 +733,11 @@ bool TRelation_application::main_loop()
     // Seleziona il cursore a freccia
     set_cursor(TASK_WIN, CURSOR_ARROW);
 
+    const bool change = _mask->query_mode() && can_change_firm();
     // Dis/abilita cambio ditta
-    enable_menu_item(M_FILE_NEW, _mask->query_mode());
-
+    enable_menu_item(M_FILE_NEW, change);
     // Dis/abilita cambio parametri
-    enable_menu_item(M_FILE_REVERT, _mask->query_mode());
+    enable_menu_item(M_FILE_REVERT, change);
 
     k = _mask->run();
 
@@ -820,7 +844,6 @@ bool TRelation_application::main_loop()
   return k != K_QUIT;
 }
 
-
 bool TRelation_application::filter()
 {
   TMailbox mail;
diff --git a/include/window.cpp b/include/window.cpp
index 618ea34af..8b437f01f 100755
--- a/include/window.cpp
+++ b/include/window.cpp
@@ -154,7 +154,6 @@ void TWindow_manager::unreg(const TWindow* m)
   }     
 }
 
-
 void close_all_dialogs()
 {
   WinManager.destroy();