From ae7c61c788fae641dfa1e501f547897ba5e1a1b5 Mon Sep 17 00:00:00 2001
From: Alessandro Bonazzi <alexbonazzi5652@gmail.com>
Date: Thu, 24 Sep 2020 07:09:05 +0200
Subject: [PATCH] Patch level         : 12.0 998 Files correlati     :
 xvaga.dll Commento            :

Aggiunte funzioni per verificare e scaricare un URL
Aggiunto supporto per finestre principali non a pieno schermo.
 bisogna specificare nel paragrafo main di campo.ini MaxDim= "dimX"x"dimY esempio MaxDim=1024x768
---
 src/xvaga/wxinc.h    |  12 +++--
 src/xvaga/xvaga.cpp  | 106 +++++++++++++++++++++++++++++++++++++++++--
 src/xvaga/xvt.h      |   3 ++
 src/xvaga/xvt_type.h |   8 ++++
 4 files changed, 121 insertions(+), 8 deletions(-)

diff --git a/src/xvaga/wxinc.h b/src/xvaga/wxinc.h
index 4f575f950..c0fd60d92 100755
--- a/src/xvaga/wxinc.h
+++ b/src/xvaga/wxinc.h
@@ -10,8 +10,14 @@
 #define WINVER 0x0500
 #define STRICT
 #define WXUSINGDLL 1
+#include <wx/wxprec.h>
+#else
+#define _FILE_OFFSET_BITS 64
+#define _LARGE_FILES
+#define __WXGTK__
+#define GTK_NO_CHECK_CASTS
+#define _IODBC
+#include <wx/wx.h>
 #endif
 
-#include <wx/wxprec.h>
-
-#endif
\ No newline at end of file
+#endif
diff --git a/src/xvaga/xvaga.cpp b/src/xvaga/xvaga.cpp
index 26d67ab71..bfd8e8378 100755
--- a/src/xvaga/xvaga.cpp
+++ b/src/xvaga/xvaga.cpp
@@ -141,6 +141,46 @@ void xvt_app_create(int WXUNUSED(argc), char** WXUNUSED(argv), unsigned long WXU
     if ((szWin.y - szCli.y) > 2) // Sposto la finestra in modo da coprire il menu del padre
       _startup_rect.top -= xvt_vobj_get_attr(NULL_WIN, ATTR_MENU_HEIGHT);   
   }
+	else
+	{
+		char xmax[50];
+
+		xvt_sys_get_profile_string(xvt_fsys_get_campo_ini(), "Main", "MaxDim", "MAX", xmax, sizeof(xmax));
+
+		if (strcmp(xmax, "MAX") != 0)
+		{
+			char * ymax =  strchr(xmax, 'x');
+
+			if (ymax == NULL)
+				ymax = strchr(xmax, 'X');
+			if (ymax != NULL)
+			{
+				*ymax++ = '\0';
+
+				const wxRect rect = wxGetClientDisplayRect();
+				int x = atoi(xmax);
+				int y = atoi(ymax);
+
+				if (x >= 1024 && y >= 768)
+				{
+					pos = rect.GetPosition();
+					size = rect.GetSize();
+
+					pos.x += (size.x - x) / 2;
+					pos.y += (size.y - y) / 2;
+					size.x = x;
+					size.y = y;
+				}
+				else
+				{
+					pos.x = 0;
+					pos.y = 0;
+					size.x = 0;
+					size.y = 0;
+				}
+			}
+		}
+	}
 #endif
   
   if (_startup_rect.right > _startup_rect.left)
@@ -153,11 +193,16 @@ void xvt_app_create(int WXUNUSED(argc), char** WXUNUSED(argv), unsigned long WXU
   else
   {
 #ifdef __WXMSW__
-		style |= wxMAXIMIZE;
+    if (size.x <= 0 || size.y <= 0)
+			style |= wxMAXIMIZE;
+		else
+			style &= ~wxMAXIMIZE;
 #else
 	  style &= ~wxMAXIMIZE;
-    const wxRect rect = wxGetClientDisplayRect();
-    pos = rect.GetPosition();
+		
+		const wxRect rect = wxGetClientDisplayRect();
+    
+		pos = rect.GetPosition();
     size = rect.GetSize();
 #endif
   }
@@ -1487,7 +1532,16 @@ BOOLEAN xvt_fsys_parse_pathname(const char* mbs, char* volname, char* dirname, c
   if (dirname) strcpy(dirname, path);
   if (leafroot) strcpy(leafroot, file);
   if (leafext) strcpy(leafext, ext);
-  if (leafvers) strcpy(leafvers, "");  // TBI put here last change date/time?
+  if (leafvers)
+  {
+    wxFileName name(mbs);
+    wxDateTime t;
+    wxString strTime;
+
+    name.GetTimes(nullptr, &t, nullptr);
+    strTime = t.Format(wxDefaultDateTimeFormat);
+    strcpy(leafvers, strTime);
+  }
   return true;
  }
 
@@ -1755,9 +1809,27 @@ long xvt_fsys_file_attr(const char* path, long attr)
         ret = sz.GetHi() != 0 ? INT_MAX : sz.GetLo();
       }
       break;
+    case XVT_FILE_ATTR_ATIME:
+      {
+        wxFileName name(path);
+        wxDateTime t;
+
+        name.GetTimes(&t, nullptr, nullptr);
+        ret = t.GetTicks();
+      }
+      break;
     case XVT_FILE_ATTR_MTIME:
       ret = ::wxFileModificationTime(path);
       break;
+    case XVT_FILE_ATTR_CTIME:
+    {
+      wxFileName name(path);
+      wxDateTime t;
+
+      name.GetTimes(nullptr, nullptr, &t);
+      ret = t.GetTicks();
+    }
+      break;
     default: break;
     }
   }
@@ -4689,8 +4761,32 @@ BOOLEAN statbar_destroy(WINDOW win)
     pStatusBar->Destroy();
   }
   return pStatusBar != NULL;
+}
 
-  
+BOOLEAN xvt_url_valid(const char * url)
+{
+  if (url && *url)
+  {
+    wxURL u(url);
+
+    return u.IsOk();
+  }
+  return FALSE;
+}
+
+BOOLEAN xvt_url_get(const char * url, const char * path, const char *outfile)
+{
+  if (xvt_url_valid(url))
+  {
+    wxURL u(url);
+    wxInputStream * in = u.GetInputStream();
+    wxString file(outfile);
+    wxFileOutputStream out(file);
+
+    in->Read(out);
+    return TRUE;
+  }
+  return FALSE;
 }
 
 
diff --git a/src/xvaga/xvt.h b/src/xvaga/xvt.h
index e53973748..10ee5d588 100755
--- a/src/xvaga/xvt.h
+++ b/src/xvaga/xvt.h
@@ -558,6 +558,9 @@ XVTDLL void              xvt_treelist_set_node_images(WINDOW win, XVT_TREEVIEW_N
 XVTDLL void              xvt_treelist_set_node_string(WINDOW win, XVT_TREEVIEW_NODE node, const char* text);
 XVTDLL void              xvt_treelist_suspend(WINDOW win);
 
+XVTDLL BOOLEAN           xvt_url_valid(const char * url);
+XVTDLL BOOLEAN           xvt_url_get(const char * url, const char * path, const char * outfile);
+
 // Send email using normal methods
 XVTDLL BOOLEAN  xvt_mail_send(const char* to, const char* cc, const char* ccn,
                               const char* subject, const char* msg, const char* attach, short flags); // 0x1=UI; 0x2=Receipt
diff --git a/src/xvaga/xvt_type.h b/src/xvaga/xvt_type.h
index 38d5f0933..db3d9f36f 100755
--- a/src/xvaga/xvt_type.h
+++ b/src/xvaga/xvt_type.h
@@ -6,6 +6,14 @@
 #define TRUE 1
 #endif
 
+#ifdef LINUX
+#define _MAX_PATH 512
+#define _MAX_EXT 6
+#define _MAX_DRIVE 6
+#define _MAX_DIR 512
+#define _MAX_FNAME 512
+#endif
+
 typedef unsigned long WINDOW;
 typedef unsigned int UNIT_TYPE;
 typedef unsigned long ULONG;