Prima versione programma firma digitale

git-svn-id: svn://10.65.10.50/branches/R_10_00@22947 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2014-05-16 12:58:15 +00:00
parent e5d6e2794c
commit 5fda198f65
13 changed files with 3277 additions and 0 deletions

9
fd/ESigner.ini Normal file
View File

@ -0,0 +1,9 @@
[guy]
CER=
PEM=
PFX=Mario_Rossi.pfx
DLL=
URL=
USR=
PWD=
POL=

68
fd/esigner.h Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#ifndef _ESIGNER_DLL
#define _ESIGNER_DLL
#define ESIGNER_USE_SHA1_DIGEST 0
#define ESIGNER_USE_SHA256_DIGEST 1
#define ESIGNER_NO_ERROR 0
#define ESIGNER_TOKEN_OPERATION_ERROR -1
#define ESIGNER_CERT_READ_FAILURE -2
#define ESIGNER_PKEY_READ_FAILURE -3
#define ESIGNER_PFX_PARSE_FAILURE -4
#define ESIGNER_CERT_RETRIEVE_TOKEN_FAILURE -5
#define ESIGNER_FILE_OPENING_ERROR -6
#define ESIGNER_TSA_URI_CONTACT_ERROR -7
#define ESIGNER_TSA_RESPONSE_ERROR -8
#define ESIGNER_TSA_RESPONSE_UNPARSABLE -9
#define ESIGNER_TOKEN_LOGIN_FAILED -10
#define ESIGNER_PKCS11_DLL_NOT_FOUND -11
#define ESIGNER_TOKEN_SLOT_NOT_FOUND -12
#define ESIGNER_OUTPUT_FILE_OPENING_ERROR -13
#define ESIGNER_OUTPUT_FILE_ALREADY_EXISTS_ERROR -14
#define ESIGNER_ERROR_TIMESTAMP_FILE -15
#define ESIGNER_TIMESTAMPING_FILE_OPENING_ERROR -16
#define ESIGNER_FILE_NOT_SIGNED -20
#define ESIGNER_FAKE_P7M -21
#define ESIGNER_SIGNATURE_INVALID -22
#define ESIGNER_CERTIFICATE_REVOKED -23
#define ESIGNER_SIGNED_BUT_TIME_STAMP_ERROR -25
#define ESIGNER_ROOT_CA_CERT_NOT_FOUND -30
#define ESIGNER_CRL_NOT_RETRIEVED -31
#define ESIGNER_CERTIFICATE_REVOKED_BUT_SIGNATURE_VALID -32
#define ESIGNER_CERTIFICATE_SELFSIGNED -33
#define ESIGNER_SIGNER_CERTIFICATE_EXPIRED -34
#define ESIGNER_SIGNER_CERTIFICATE_OUT_OF_TIME_VALIDITY -35
typedef int (PASCAL * ESignerSignProto) (
char *operation,
char *method,
char *inputFile,
char *outputFile,
char *timestampOutputFile,
char *extension,
char *certificateFile,
char *kprivFile,
char *pfxFile,
char *pkcs11Dll,
char *pin_passphrase,
char *directoryTokenCache,
char *indexCertificateOnToken,
char *tsaURI,
char *tsaUsername,
char *tsaPassword,
char *tsaPolicy,
char *tsaCoding,
char *rootCADir
);
typedef int (PASCAL * ESignerVerifyProto) (
char *operation,
char *inputFileName,
char *responseFileName,
char *rootCADir,
char *rootTSADir,
char *resultDescription
);
#endif

702
fd/fd0.cpp Normal file
View File

@ -0,0 +1,702 @@
#include "wxinc.h"
#include "esigner.h"
#include "gtDialog.h"
#include "gtSSA.h"
#include <wx/dialup.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/progdlg.h>
#include <wx/socket.h>
#include <wx/tokenzr.h>
///////////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////////
#define APPFULLNAME wxAppConsole::GetInstance()->GetAppName()
static wxString IniGetString(const char* sec, const char* var, const char* def = "")
{
wxString val;
if (sec && *sec && var && *var)
{
const size_t sz = 256;
char* buf = val.GetWriteBuf(sz);
::GetPrivateProfileString(sec, var, def, buf, sz, "./ESigner.ini");
val.UngetWriteBuf();
}
return val;
}
static long IniGetLong(const char* sec, const char* var, long def = 0)
{
wxString str; if (def != 0) str.Printf("%ld", def);
return wxAtol(IniGetString(sec, var, str));
}
static bool IniSetString(const char* sec, const char* var, const wxString val)
{
if (sec && *sec && var && *var)
{
::WritePrivateProfileString(sec, var, val, "./ESigner.ini");
return true;
}
return false;
}
static bool IniSetLong(const char* sec, const char* var, long val)
{
wxString str; str.Printf("%ld", val);
return IniSetString(sec, var, str);
}
static bool IsOnline()
{
//stoppa il log di wxWidgets per non avere segnalazioni di errori incomprensibili!
const bool bLogEnabled = wxLog::EnableLogging(false);
bool bOnline = false;
wxDialUpManager* dum = wxDialUpManager::Create();
if (dum != NULL)
{
if (dum->IsOk() && dum->IsOnline())
{
wxIPV4address addr;
if (addr.Hostname("www.google.com"))
bOnline = true;
}
delete dum;
}
wxLog::EnableLogging(bLogEnabled);
return bOnline;
}
///////////////////////////////////////////////////////////
// TESignerDlg
///////////////////////////////////////////////////////////
class TEsignerDlg : public gtPropertyDlg
{
wxString m_strUser;
protected:
virtual bool TransferDataToWindow();
virtual bool TransferDataFromWindow();
public:
TEsignerDlg(const wxString& user);
};
bool TEsignerDlg::TransferDataToWindow()
{
bool ok = gtPropertyDlg::TransferDataToWindow();
if (ok)
{
SetProperty("CER", IniGetString(m_strUser, "CER"));
SetProperty("PEM", IniGetString(m_strUser, "PEM"));
SetProperty("PFX", IniGetString(m_strUser, "PFX"));
SetProperty("DLL", IniGetString(m_strUser, "DLL"));
SetProperty("URL", IniGetString(m_strUser, "URL"));
SetProperty("USR", IniGetString(m_strUser, "USR"));
SetProperty("PWD", IniGetString(m_strUser, "PWD"));
SetProperty("POL", IniGetString(m_strUser, "POL"));
SetProperty("DIR_IN", IniGetString(m_strUser, "DIR_IN"));
SetProperty("DIR_OUT", IniGetString(m_strUser, "DIR_OUT"));
SetProperty("DIR_BCK", IniGetString(m_strUser, "DIR_BCK"));
SetProperty("BCK", IniGetLong (m_strUser, "BCK"));
}
return ok;
}
bool TEsignerDlg::TransferDataFromWindow()
{
bool ok = gtPropertyDlg::TransferDataFromWindow();
if (ok)
{
IniSetString(m_strUser, "CER", GetProperty("CER"));
IniSetString(m_strUser, "PEM", GetProperty("PEM"));
IniSetString(m_strUser, "PFX", GetProperty("PFX"));
IniSetString(m_strUser, "DLL", GetProperty("DLL"));
IniSetString(m_strUser, "URL", GetProperty("URL"));
IniSetString(m_strUser, "USR", GetProperty("USR"));
IniSetString(m_strUser, "PWD", GetProperty("PWD"));
IniSetString(m_strUser, "POL", GetProperty("POL"));
IniSetString(m_strUser, "DIR_IN", GetProperty("DIR_IN"));
IniSetString(m_strUser, "DIR_OUT", GetProperty("DIR_OUT"));
IniSetString(m_strUser, "DIR_BCK", GetProperty("DIR_BCK"));
IniSetLong (m_strUser, "BCK", GetProperty("BCK").GetInteger());
}
return ok;
}
TEsignerDlg::TEsignerDlg(const wxString& user)
: gtPropertyDlg(APPFULLNAME, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxSTAY_ON_TOP), m_strUser(user)
{
Init();
AddCategory("Cartelle");
AddPropertyDB("DIR_IN", wxEmptyString, "Input", 0, wxEmptyString, "*.");
AddPropertyDB("DIR_OUT", wxEmptyString, "Output", 0, wxEmptyString, "*.");
AddPropertyDB("DIR_BCK", wxEmptyString, "Backup", 0, wxEmptyString, "*.");
wxArrayString aActions; aActions.Add("Nessuna operazione"); aActions.Add("Elimina file da firmare"); aActions.Add("Backup file da firmare");
AddProperty("BCK", aActions, 0, "Dopo la firma");
AddPage("Avanzate");
AddCategory("Certificati");
AddPropertyDB("CER", wxString(), wxT("File CER"), 0, wxEmptyString, "*.cer");
AddPropertyDB("PEM", wxString(), wxT("File PEM"), 0, wxEmptyString, "*.pem");
AddPropertyDB("PFX", wxString(), wxT("File PFX"), 0, wxEmptyString, "*.pfx");
AddCategory("Token");
AddPropertyDB("DLL", wxString(), wxT("DLL driver"), 0, wxEmptyString, "*.dll");
AddCategory("Marcatura temporale");
const int nFlags = IsOnline() ? 0 : wxTE_READONLY;
AddProperty("URL", wxString(), wxT("URL Autorità"), nFlags);
AddProperty("USR", wxString(), wxT("Utente"), nFlags);
AddProperty("PWD", wxString(), wxT("Password"), nFlags | wxTE_PASSWORD);
AddProperty("POL", wxString(), wxT("Policy"), nFlags);
wxArrayString aCoding; aCoding.Add("binary"); aCoding.Add("text");
AddProperty("ENC", aCoding, aCoding[0], wxT("Coding"), nFlags);
}
///////////////////////////////////////////////////////////
// TSignatureDlg
///////////////////////////////////////////////////////////
class TSignatureDlg : public gtPropertyDlg
{
DECLARE_EVENT_TABLE();
protected:
void OnMore(wxCommandEvent& evt);
virtual bool OnValidateProperty(wxVariant& val);
public:
TSignatureDlg();
};
BEGIN_EVENT_TABLE(TSignatureDlg, gtPropertyDlg)
EVT_BUTTON(wxID_MORE, TSignatureDlg::OnMore)
END_EVENT_TABLE()
bool TSignatureDlg::OnValidateProperty(wxVariant& val)
{
const wxString& name = val.GetName();
if (name == "USR")
{
if (val.GetString().IsEmpty())
return gtError("Occorre specificare un utente");
return true;
}
if (name == "PIN")
{
if (val.GetString().Len() < 2)
return gtError("Occorre specificare un PIN");
return true;
}
return gtPropertyDlg::OnValidateProperty(val);
}
void TSignatureDlg::OnMore(wxCommandEvent& WXUNUSED(evt))
{
wxVariant vUser = GetProperty("USR");
if (OnValidateProperty(vUser))
{
Disable();
TEsignerDlg dlg(vUser.GetString());
dlg.SetParent(this);
dlg.ShowModal();
Enable();
}
}
TSignatureDlg::TSignatureDlg() : gtPropertyDlg(APPFULLNAME)
{
Init();
wxString strUser = wxGetUserId();
AddProperty("USR", strUser, wxT("Utente"));
AddProperty("PIN", wxString(), wxT("PIN"), wxTE_PASSWORD);
const bool aol = IsOnline();
bool mrk = false;
if (aol)
mrk = IniGetString(strUser, "MRK", "0") == "1";
AddProperty("MRK", mrk, "Marcatura temporale", aol ? 0 : wxTE_READONLY);
PrependButton(wxID_MORE, "Opzioni...", wxEmptyString);
}
///////////////////////////////////////////////////////////
// TEsigner
///////////////////////////////////////////////////////////
class TEsigner
{
HMODULE m_hESigner;
ESignerSignProto _SignPDF;
ESignerVerifyProto _VerifyPDF;
wxString m_strUser, m_strPin, m_strDLL, m_strCER, m_strPEM, m_strPFX;
wxString m_strTSAurl, m_strTSAuser, m_strTSApwd, m_strPolicy, m_strTSAcoding;
bool m_bMark;
protected:
bool TestFile(const wxString& strFile) const;
public:
bool Init(bool on);
bool GetPin();
bool Sign(const wxString& strInput, wxString& strOutput, const wxString& strBackup, int mode);
bool Verify(const wxString& strInput);
const wxString& User() const { return m_strUser; }
TEsigner();
~TEsigner();
};
TEsigner::TEsigner() : m_bMark(false), m_hESigner(NULL), _SignPDF(NULL), _VerifyPDF(NULL)
{}
TEsigner::~TEsigner()
{ Init(false); }
bool TEsigner::TestFile(const wxString& strFile) const
{
bool ok = true;
if (!strFile.IsEmpty())
{
ok = wxFileExists(strFile);
if (!ok)
{
wxString msg;
msg << "Impossibile caricare il file " << strFile
<< "\nControllare il paragrafo [" << m_strUser
<< "] nel file ESigner.ini";
gtError(msg);
}
}
return ok;
}
bool TEsigner::GetPin()
{
TSignatureDlg dlg;
if (!m_strUser.IsEmpty())
dlg.SetProperty("USR", m_strUser);
if (dlg.ShowModal() == wxID_OK)
{
m_strUser = dlg.GetString("USR");
m_strPin = dlg.GetString("PIN");
m_bMark = dlg.GetBool("MRK");
IniSetString(m_strUser, "MRK", m_bMark ? "1" : "0");
}
else
return false;
m_strDLL = IniGetString(m_strUser, "DLL");
m_strCER = IniGetString(m_strUser, "CER");
m_strPEM = IniGetString(m_strUser, "PEM");
m_strPFX = IniGetString(m_strUser, "PFX");
if (m_strDLL.IsEmpty() && m_strCER.IsEmpty() && m_strPFX.IsEmpty())
{
TEsignerDlg dlg(m_strUser);
if (dlg.ShowModal() == wxID_OK)
{
m_strDLL = dlg.GetString("DLL");
m_strCER = dlg.GetString("CER");
m_strPEM = dlg.GetString("PEM");
m_strPFX = dlg.GetString("PFX");
}
}
if (m_bMark)
{
m_strTSAurl = IniGetString(m_strUser, "TSA_URL");
m_strTSAuser = IniGetString(m_strUser, "TSA_USR");
m_strTSApwd = IniGetString(m_strUser, "TSA_PWD");
m_strPolicy = IniGetString(m_strUser, "TSA_POL");
m_strTSAcoding = IniGetString(m_strUser, "TSA_ENC", "binary");
if (m_strTSAurl.IsEmpty())
{
wxString msg;
msg << "Mancano i parametri per la marcatura temporale"
<< "\nControllare il paragrafo [" << m_strUser
<< "] del file ESigner.ini";
wxLogWarning(msg);
m_bMark = false;
}
}
return m_strPin.Len() >= 2;
}
bool TEsigner::Init(bool bLoad)
{
bool ok = false;
if (bLoad)
{
if (m_hESigner == NULL)
{
m_hESigner = ::LoadLibrary("esigner.dll");
if (m_hESigner != NULL)
{
_SignPDF = (ESignerSignProto)::GetProcAddress(m_hESigner, "Sign");
_VerifyPDF = (ESignerVerifyProto)::GetProcAddress(m_hESigner, "Verify");
m_strPin.Empty();
GetPin();
}
}
ok = m_hESigner != NULL && _SignPDF != NULL && _VerifyPDF != NULL;
if (!ok)
gtError("Impossibile caricare 'ESigner.dll'");
else
ok = TestFile(m_strDLL) && TestFile(m_strCER) && TestFile(m_strPEM) && TestFile(m_strPFX);
}
else
{
if (m_hESigner != NULL)
{
::FreeLibrary(m_hESigner);
m_hESigner = NULL;
_SignPDF = NULL;
_VerifyPDF = NULL;
m_strPin.Empty();
}
}
return ok;
}
bool TEsigner::Sign(const wxString& strInput, wxString& strOutput, const wxString& strBackup, int mode)
{
if (m_strPin.Len() < 2)
{
if (!Init(true))
return false;
if (!GetPin())
return gtError("PIN non valido");
}
wxString strOperation = "S";
if (m_bMark && !m_strTSAurl.IsEmpty()) // Firma con marcatura temporale
strOperation += "+T"; else
if (wxDirExists(strInput))
strOperation += "+D";
wxString strMethod;
if (!m_strDLL.IsEmpty()) // Token
strMethod = "T"; else
if (!m_strPFX.IsEmpty())
strMethod = "P"; else
if (!m_strCER.IsEmpty())
strMethod = "F";
else
return false;
char* operation = (char*)(const char*)strOperation;
char* method = (char*)(const char*)strMethod;
char* ext = ".p7m";
char* input = (char*)(const char*)strInput;
char* output = (char*)(const char*)strOutput;
char* cer = strMethod == "F" ? (char*)(const char*)m_strCER : NULL;
char* pem = strMethod == "F" ? (char*)(const char*)m_strPEM : NULL;
char* pfx = strMethod == "P" ? (char*)(const char*)m_strPFX : NULL;
char* idx = "0";
char* pin = (char*)(const char*)m_strPin;
char* TSA_output = NULL;
char* TSA_dll = NULL;
char* TSA_url = NULL;
char* TSA_user = NULL;
char* TSA_pwd = NULL;
char* TSA_policy = NULL;
char* TSA_coding = NULL;
char* TSA_rootCA = NULL;
if (strOperation.Find("+T") > 0) // Firma con marcatura temporale
{
TSA_dll = (char*)(const char*)m_strDLL;
TSA_url = (char*)(const char*)m_strTSAurl;
TSA_user = (char*)(const char*)m_strTSAuser;
TSA_pwd = (char*)(const char*)m_strTSApwd;
TSA_policy = (char*)(const char*)m_strPolicy;
TSA_coding = (char*)(const char*)m_strTSAcoding;
}
if (strOperation.Find("+D") > 0)
{
if (strOutput.IsEmpty())
output = input;
}
else
{
ext = strInput.Lower().EndsWith(".pdf") ? ".pdf.p7m" : ".p7m";
if (strOutput.IsEmpty())
strOutput = strInput + ".p7m";
::wxRemoveFile(strOutput); // Altrimenti la fantastica dll s'incazza come una biscia
strOutput = strOutput.BeforeFirst('.');
output = (char*)(const char*)strOutput;
}
int res = _SignPDF(operation, method,
input, output, NULL, ext,
cer, pem, pfx,
TSA_dll, pin, NULL, idx,
TSA_url, TSA_user, TSA_pwd, TSA_policy, TSA_coding, NULL);
if (res > 0) // +D only
{
wxArrayString files;
const size_t p7m = wxDir::GetAllFiles(output, &files, "*.p7m", wxDIR_FILES);
if (p7m > 0)
res = 0;
if (mode == 2)
{
if (strBackup.IsEmpty())
mode = 0;
else
{
if (strBackup.CmpNoCase("Cestino") == 0 || strBackup.CmpNoCase("NULL") == 0 ||
strBackup.CmpNoCase("Basket") == 0 || strBackup.CmpNoCase("Trash") == 0)
mode = 1;
}
if (mode == 2)
wxFileName::Mkdir(strBackup, 0777, wxPATH_MKDIR_FULL);
}
if (res == 0 && mode != 0)
{
files.Clear();
const size_t n = wxDir::GetAllFiles(input, &files, "*.*", wxDIR_FILES);
if (n > 0)
{
wxString msg;
if (mode == 1)
msg << "Eliminazione file in " << strInput;
else
{
wxFileName::Mkdir(strBackup, 0777, wxPATH_MKDIR_FULL);
msg << "Copia file in " << strBackup;
}
wxProgressDialog pd(APPFULLNAME, msg, n);
for (size_t i = 0; i < n; i++)
{
if (!pd.Update(i+1))
break;
wxFileName fout = files[i];
fout.SetPath(strBackup);
bool bRemove = true;
if (mode == 2)
bRemove = wxCopyFile(files[i], fout.GetFullPath());
if (bRemove)
wxRemoveFile(files[i]);
}
}
}
}
if (res == 0)
{
gtMessage("Operazione di firma completata.");
}
else
{
const char* msg = NULL;
switch (res)
{
case -2: msg = "Errore di lettura del certificato"; break;
case -3: msg = "Errore di lettura della chiave privata"; break;
case -4: msg = "Errore di lettura file PFX"; break;
case -5: msg = "Errore recupero certificato da Token"; break;
case -6: msg = "Errore apertura file"; break;
case -7:
case -8:
case -9: msg = "Errore conatatto TSA"; break;
case -10: msg = "Accesso al token fallito"; break;
case -11: msg = "Impossibile trovare dll driver del token"; break;
case -14: msg = "Il file di output esiste già"; break;
case -15:
case -16: msg = "Errore di marctura tmeporale"; break;
default : msg = "Errore di accesso alle operazioni di firma"; break;
}
wxString str;
str.Printf("ESigner.dll errore %d:\n%s", res, msg);
gtError(str);
}
return res == 0;
}
bool TEsigner::Verify(const wxString& strInput)
{
int res = -1;
if (Init(!strInput.IsEmpty()))
{
char file[_MAX_PATH], result[_MAX_PATH];
wxStrncpy(file, strInput, _MAX_PATH);
res = _VerifyPDF("V", file, NULL, NULL, NULL, result);
}
return res == 0;
}
///////////////////////////////////////////////////////////
// TMainDlg
///////////////////////////////////////////////////////////
class TMainDlg : public gtPropertyDlg
{
wxString m_strUser;
DECLARE_EVENT_TABLE();
protected:
virtual bool TransferDataFromWindow();
virtual bool TransferDataToWindow();
public:
TMainDlg(const wxString& strUser);
};
BEGIN_EVENT_TABLE(TMainDlg, gtPropertyDlg)
END_EVENT_TABLE()
bool TMainDlg::TransferDataToWindow()
{
bool ok = gtPropertyDlg::TransferDataToWindow();
if (ok)
{
SetProperty("DIR_IN", IniGetString(m_strUser, "DIR_IN"));
SetProperty("DIR_OUT", IniGetString(m_strUser, "DIR_OUT"));
SetProperty("FILE_IN", IniGetString(m_strUser, "FILE_IN"));
SetProperty("FILE_OUT", IniGetString(m_strUser, "FILE_OUT"));
}
return ok;
}
bool TMainDlg::TransferDataFromWindow()
{
bool ok = gtPropertyDlg::TransferDataFromWindow();
if (ok)
{
IniSetString(m_strUser, "DIR_IN", GetProperty("DIR_IN"));
IniSetString(m_strUser, "DIR_OUT", GetProperty("DIR_OUT"));
/*
IniSetString(m_strUser, "FILE_IN", GetProperty("FILE_IN"));
IniSetString(m_strUser, "FILE_OUT", GetProperty("FILE_OUT"));
*/
}
return ok;
}
TMainDlg::TMainDlg(const wxString& strUser): gtPropertyDlg(APPFULLNAME), m_strUser(strUser)
{
Init();
AddCategory("Cartelle");
AddPropertyDB("DIR_IN", wxEmptyString, "Input", 0, wxEmptyString, "*.");
AddPropertyDB("DIR_OUT", wxEmptyString, "Output", 0, wxEmptyString, "*.");
/*
AddCategory("File");
AddPropertyDB("FILE_IN", wxEmptyString, "Input", 0, wxEmptyString, "*.xml");
AddPropertyDB("FILE_OUT", wxEmptyString, "Output", 0, wxEmptyString, "*.xml");
*/
}
///////////////////////////////////////////////////////////
// TESigner_app
///////////////////////////////////////////////////////////
class TESigner_app : public wxApp
{
TEsigner __TheSigner;
public:
virtual bool OnInit();
virtual int OnExit();
};
IMPLEMENT_APP(TESigner_app)
bool TESigner_app::OnInit()
{
SetAppName("Firma digitale v11.2");
gtInitArtProvider();
if (SSA_Login() != 0)
return gtError("Postazione non abilitata al modulo PA");
const bool done = __TheSigner.Init(true);
if (done)
{
const wxString& usr = __TheSigner.User();
wxString inf, outf;
for (int a = 1; a < __argc; a++)
{
const wxString f = __argv[a];
if (inf.IsEmpty() && (wxFileExists(f) || wxDirExists(f)))
inf = f; else
if (!inf.IsEmpty() && outf.IsEmpty())
{
outf = f;
break;
}
}
if (inf.IsEmpty())
inf = IniGetString(usr, "DIR_IN");
if (outf.IsEmpty())
outf = IniGetString(usr, "DIR_OUT");
if (inf.IsEmpty() && !usr.IsEmpty())
{
TMainDlg dlg(usr);
if (dlg.ShowModal() == wxID_OK)
{
inf = dlg.GetString("DIR_IN");
outf = dlg.GetString("DIR_OUT");
}
}
while (!usr.IsEmpty() && !inf.IsEmpty())
{
const wxString bckd = IniGetString(usr, "DIR_BCK");
const long mode = IniGetLong(usr, "BCK");
__TheSigner.Sign(inf, outf, bckd, mode);
if (__TheSigner.GetPin())
{
inf = IniGetString(usr, "DIR_IN");
outf = IniGetString(usr, "DIR_OUT");
}
else
break;
}
__TheSigner.Init(false);
}
SSA_Logout();
return false;
}
int TESigner_app::OnExit()
{
return wxApp::OnExit();
}

609
fd/fstrcmp.cpp Normal file
View File

@ -0,0 +1,609 @@
/* Functions to make fuzzy comparisons between strings
Copyright (C) 1988-1989, 1992-1993, 1995, 2001-2003 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Derived from GNU diff 2.7, analyze.c et al.
The basic algorithm is described in:
"An O(ND) Difference Algorithm and its Variations", Eugene Myers,
Algorithmica Vol. 1 No. 2, 1986, pp. 251-266;
see especially section 4.2, which describes the variation used below.
The basic algorithm was independently discovered as described in:
"Algorithms for Approximate String Matching", E. Ukkonen,
Information and Control Vol. 64, 1985, pp. 100-118.
Modified to work on strings rather than files
by Peter Miller <pmiller@xxxxxxxxxxx>, October 1995 */
//#include "config.h"
/* Specification. */
#include "fstrcmp.h"
#include <string.h>
#include <limits.h>
#include <stdlib.h>
/*
* Data on one input string being compared.
*/
struct string_data
{
/* The string to be compared. */
const char *data;
/* The length of the string to be compared. */
int data_length;
/* The number of characters inserted or deleted. */
int edit_count;
};
static struct string_data string[2];
#ifdef MINUS_H_FLAG
/* This corresponds to the diff -H flag. With this heuristic, for
strings with a constant small density of changes, the algorithm is
linear in the strings size. This is unlikely in typical uses of
fstrcmp, and so is usually compiled out. Besides, there is no
interface to set it true. */
static int heuristic;
#endif
/* Vector, indexed by diagonal, containing 1 + the X coordinate of the
point furthest along the given diagonal in the forward search of the
edit matrix. */
static int *fdiag;
/* Vector, indexed by diagonal, containing the X coordinate of the point
furthest along the given diagonal in the backward search of the edit
matrix. */
static int *bdiag;
/* Edit scripts longer than this are too expensive to compute. */
static int too_expensive;
/* Snakes bigger than this are considered `big'. */
#define SNAKE_LIMIT 20
struct partition
{
/* Midpoints of this partition. */
int xmid, ymid;
/* Nonzero if low half will be analyzed minimally. */
int lo_minimal;
/* Likewise for high half. */
int hi_minimal;
};
/* NAME
diag - find diagonal path
SYNOPSIS
int diag(int xoff, int xlim, int yoff, int ylim, int minimal,
struct partition *part);
DESCRIPTION
Find the midpoint of the shortest edit script for a specified
portion of the two strings.
Scan from the beginnings of the strings, and simultaneously from
the ends, doing a breadth-first search through the space of
edit-sequence. When the two searches meet, we have found the
midpoint of the shortest edit sequence.
If MINIMAL is nonzero, find the minimal edit script regardless
of expense. Otherwise, if the search is too expensive, use
heuristics to stop the search and report a suboptimal answer.
RETURNS
Set PART->(XMID,YMID) to the midpoint (XMID,YMID). The diagonal
number XMID - YMID equals the number of inserted characters
minus the number of deleted characters (counting only characters
before the midpoint). Return the approximate edit cost; this is
the total number of characters inserted or deleted (counting
only characters before the midpoint), unless a heuristic is used
to terminate the search prematurely.
Set PART->LEFT_MINIMAL to nonzero iff the minimal edit script
for the left half of the partition is known; similarly for
PART->RIGHT_MINIMAL.
CAVEAT
This function assumes that the first characters of the specified
portions of the two strings do not match, and likewise that the
last characters do not match. The caller must trim matching
characters from the beginning and end of the portions it is
going to specify.
If we return the "wrong" partitions, the worst this can do is
cause suboptimal diff output. It cannot cause incorrect diff
output. */
static int
diag (int xoff, int xlim, int yoff, int ylim, int minimal,
struct partition *part)
{
int *const fd = fdiag; /* Give the compiler a chance. */
int *const bd = bdiag; /* Additional help for the compiler. */
const char *const xv = string[0].data; /* Still more help for the
compiler. */
const char *const yv = string[1].data; /* And more and more . . . */
const int dmin = xoff - ylim; /* Minimum valid diagonal. */
const int dmax = xlim - yoff; /* Maximum valid diagonal. */
const int fmid = xoff - yoff; /* Center diagonal of top-down search. */
const int bmid = xlim - ylim; /* Center diagonal of bottom-up search. */
int fmin = fmid;
int fmax = fmid; /* Limits of top-down search. */
int bmin = bmid;
int bmax = bmid; /* Limits of bottom-up search. */
int c; /* Cost. */
int odd = (fmid - bmid) & 1;
/*
* True if southeast corner is on an odd diagonal with respect
* to the northwest.
*/
fd[fmid] = xoff;
bd[bmid] = xlim;
for (c = 1;; ++c)
{
int d; /* Active diagonal. */
int big_snake;
big_snake = 0;
/* Extend the top-down search by an edit step in each diagonal. */
if (fmin > dmin)
fd[--fmin - 1] = -1;
else
++fmin;
if (fmax < dmax)
fd[++fmax + 1] = -1;
else
--fmax;
for (d = fmax; d >= fmin; d -= 2)
{
int x;
int y;
int oldx;
int tlo;
int thi;
tlo = fd[d - 1],
thi = fd[d + 1];
if (tlo >= thi)
x = tlo + 1;
else
x = thi;
oldx = x;
y = x - d;
while (x < xlim && y < ylim && xv[x] == yv[y])
{
++x;
++y;
}
if (x - oldx > SNAKE_LIMIT)
big_snake = 1;
fd[d] = x;
if (odd && bmin <= d && d <= bmax && bd[d] <= x)
{
part->xmid = x;
part->ymid = y;
part->lo_minimal = part->hi_minimal = 1;
return 2 * c - 1;
}
}
/* Similarly extend the bottom-up search. */
if (bmin > dmin)
bd[--bmin - 1] = INT_MAX;
else
++bmin;
if (bmax < dmax)
bd[++bmax + 1] = INT_MAX;
else
--bmax;
for (d = bmax; d >= bmin; d -= 2)
{
int x;
int y;
int oldx;
int tlo;
int thi;
tlo = bd[d - 1],
thi = bd[d + 1];
if (tlo < thi)
x = tlo;
else
x = thi - 1;
oldx = x;
y = x - d;
while (x > xoff && y > yoff && xv[x - 1] == yv[y - 1])
{
--x;
--y;
}
if (oldx - x > SNAKE_LIMIT)
big_snake = 1;
bd[d] = x;
if (!odd && fmin <= d && d <= fmax && x <= fd[d])
{
part->xmid = x;
part->ymid = y;
part->lo_minimal = part->hi_minimal = 1;
return 2 * c;
}
}
if (minimal)
continue;
#ifdef MINUS_H_FLAG
/* Heuristic: check occasionally for a diagonal that has made lots
of progress compared with the edit distance. If we have any
such, find the one that has made the most progress and return
it as if it had succeeded.
With this heuristic, for strings with a constant small density
of changes, the algorithm is linear in the strings size. */
if (c > 200 && big_snake && heuristic)
{
int best;
best = 0;
for (d = fmax; d >= fmin; d -= 2)
{
int dd;
int x;
int y;
int v;
dd = d - fmid;
x = fd[d];
y = x - d;
v = (x - xoff) * 2 - dd;
if (v > 12 * (c + (dd < 0 ? -dd : dd)))
{
if
(
v > best
&&
xoff + SNAKE_LIMIT <= x
&&
x < xlim
&&
yoff + SNAKE_LIMIT <= y
&&
y < ylim
)
{
/* We have a good enough best diagonal; now insist
that it end with a significant snake. */
int k;
for (k = 1; xv[x - k] == yv[y - k]; k++)
{
if (k == SNAKE_LIMIT)
{
best = v;
part->xmid = x;
part->ymid = y;
break;
}
}
}
}
}
if (best > 0)
{
part->lo_minimal = 1;
part->hi_minimal = 0;
return 2 * c - 1;
}
best = 0;
for (d = bmax; d >= bmin; d -= 2)
{
int dd;
int x;
int y;
int v;
dd = d - bmid;
x = bd[d];
y = x - d;
v = (xlim - x) * 2 + dd;
if (v > 12 * (c + (dd < 0 ? -dd : dd)))
{
if (v > best && xoff < x && x <= xlim - SNAKE_LIMIT &&
yoff < y && y <= ylim - SNAKE_LIMIT)
{
/* We have a good enough best diagonal; now insist
that it end with a significant snake. */
int k;
for (k = 0; xv[x + k] == yv[y + k]; k++)
{
if (k == SNAKE_LIMIT - 1)
{
best = v;
part->xmid = x;
part->ymid = y;
break;
}
}
}
}
}
if (best > 0)
{
part->lo_minimal = 0;
part->hi_minimal = 1;
return 2 * c - 1;
}
}
#endif /* MINUS_H_FLAG */
/* Heuristic: if we've gone well beyond the call of duty, give up
and report halfway between our best results so far. */
if (c >= too_expensive)
{
int fxybest;
int fxbest;
int bxybest;
int bxbest;
/* Pacify `gcc -Wall'. */
fxbest = 0;
bxbest = 0;
/* Find forward diagonal that maximizes X + Y. */
fxybest = -1;
for (d = fmax; d >= fmin; d -= 2)
{
int x;
int y;
x = fd[d] < xlim ? fd[d] : xlim;
y = x - d;
if (ylim < y)
{
x = ylim + d;
y = ylim;
}
if (fxybest < x + y)
{
fxybest = x + y;
fxbest = x;
}
}
/* Find backward diagonal that minimizes X + Y. */
bxybest = INT_MAX;
for (d = bmax; d >= bmin; d -= 2)
{
int x;
int y;
x = xoff > bd[d] ? xoff : bd[d];
y = x - d;
if (y < yoff)
{
x = yoff + d;
y = yoff;
}
if (x + y < bxybest)
{
bxybest = x + y;
bxbest = x;
}
}
/* Use the better of the two diagonals. */
if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff))
{
part->xmid = fxbest;
part->ymid = fxybest - fxbest;
part->lo_minimal = 1;
part->hi_minimal = 0;
}
else
{
part->xmid = bxbest;
part->ymid = bxybest - bxbest;
part->lo_minimal = 0;
part->hi_minimal = 1;
}
return 2 * c - 1;
}
}
}
/* NAME
compareseq - find edit sequence
SYNOPSIS
void compareseq(int xoff, int xlim, int yoff, int ylim, int minimal);
DESCRIPTION
Compare in detail contiguous subsequences of the two strings
which are known, as a whole, to match each other.
The subsequence of string 0 is [XOFF, XLIM) and likewise for
string 1.
Note that XLIM, YLIM are exclusive bounds. All character
numbers are origin-0.
If MINIMAL is nonzero, find a minimal difference no matter how
expensive it is. */
static void
compareseq (int xoff, int xlim, int yoff, int ylim, int minimal)
{
const char *const xv = string[0].data; /* Help the compiler. */
const char *const yv = string[1].data;
/* Slide down the bottom initial diagonal. */
while (xoff < xlim && yoff < ylim && xv[xoff] == yv[yoff])
{
++xoff;
++yoff;
}
/* Slide up the top initial diagonal. */
while (xlim > xoff && ylim > yoff && xv[xlim - 1] == yv[ylim - 1])
{
--xlim;
--ylim;
}
/* Handle simple cases. */
if (xoff == xlim)
{
while (yoff < ylim)
{
++string[1].edit_count;
++yoff;
}
}
else if (yoff == ylim)
{
while (xoff < xlim)
{
++string[0].edit_count;
++xoff;
}
}
else
{
int c;
struct partition part;
/* Find a point of correspondence in the middle of the strings. */
c = diag (xoff, xlim, yoff, ylim, minimal, &part);
if (c == 1)
{
#if 0
/* This should be impossible, because it implies that one of
the two subsequences is empty, and that case was handled
above without calling `diag'. Let's verify that this is
true. */
abort ();
#else
/* The two subsequences differ by a single insert or delete;
record it and we are done. */
if (part.xmid - part.ymid < xoff - yoff)
++string[1].edit_count;
else
++string[0].edit_count;
#endif
}
else
{
/* Use the partitions to split this problem into subproblems. */
compareseq (xoff, part.xmid, yoff, part.ymid, part.lo_minimal);
compareseq (part.xmid, xlim, part.ymid, ylim, part.hi_minimal);
}
}
}
/* NAME
fstrcmp - fuzzy string compare
SYNOPSIS
double fstrcmp(const char *, const char *);
DESCRIPTION
The fstrcmp function may be used to compare two string for
similarity. It is very useful in reducing "cascade" or
"secondary" errors in compilers or other situations where
symbol tables occur.
RETURNS
double; 0 if the strings are entirly dissimilar, 1 if the
strings are identical, and a number in between if they are
similar. */
double fstrcmp (const char *string1, const char *string2)
{
static int *fdiag_buf = NULL;
static size_t fdiag_max = 0;
int i;
size_t fdiag_len;
/* set the info for each string. */
string[0].data = string1;
string[0].data_length = strlen (string1);
string[1].data = string2;
string[1].data_length = strlen (string2);
/* short-circuit obvious comparisons */
if (string[0].data_length == 0 && string[1].data_length == 0)
return 1.0;
if (string[0].data_length == 0 || string[1].data_length == 0)
return 0.0;
/* Set TOO_EXPENSIVE to be approximate square root of input size,
bounded below by 256. */
too_expensive = 1;
for (i = string[0].data_length + string[1].data_length; i != 0; i >>= 2)
too_expensive <<= 1;
if (too_expensive < 256)
too_expensive = 256;
/* Because fstrcmp is typically called multiple times, while scanning
symbol tables, etc, attempt to minimize the number of memory
allocations performed. Thus, we use a static buffer for the
diagonal vectors, and never free them. */
fdiag_len = string[0].data_length + string[1].data_length + 3;
if (fdiag_len > fdiag_max)
{
fdiag_max = fdiag_len;
fdiag_buf = (int*)realloc (fdiag_buf, fdiag_max * (2 * sizeof (int)));
}
fdiag = fdiag_buf + string[1].data_length + 1;
bdiag = fdiag + fdiag_len;
/* Now do the main comparison algorithm */
string[0].edit_count = 0;
string[1].edit_count = 0;
compareseq (0, string[0].data_length, 0, string[1].data_length, 0);
/* The result is
((number of chars in common) / (average length of the strings)).
This is admittedly biased towards finding that the strings are
similar, however it does produce meaningful results. */
return ((double) (string[0].data_length + string[1].data_length
- string[1].edit_count - string[0].edit_count)
/ (string[0].data_length + string[1].data_length));
}

6
fd/fstrcmp.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __FSTRCMP_H__
#define __FSTRCMP_H__
double fstrcmp(const char *string1, const char *string2);
#endif

407
fd/gtArt.cpp Normal file
View File

@ -0,0 +1,407 @@
#include "wxinc.h"
#include "gtArt.h"
#include <wx/filename.h>
#include <wx/rawbmp.h>
extern wxColor wxAuiStepColour(const wxColor& c, int ialpha);
///////////////////////////////////////////////////////////
// HSLColor
///////////////////////////////////////////////////////////
inline wxColourBase::ChannelType Y601(wxColourBase::ChannelType r,
wxColourBase::ChannelType g,
wxColourBase::ChannelType b)
{ return 0.299*r + 0.587*g + 0.114*b; }
inline wxColourBase::ChannelType Luma(const wxColour& col)
{ return Y601(col.Red(), col.Green(), col.Blue()); }
static wxColourBase::ChannelType ModulatedChannel(wxColourBase::ChannelType c, int val)
{
int k = c;
if (val > 0)
k = (c * (100-val) + 255 * val) / 100;
else
k = c * (100+val) / 100;
if (k < 0) k = 0; else
if (k > 255) k = 255;
return k;
}
// val: -100 = wxBLACK; 0 = Same color; +100 = wxWHITE
wxColour ModulatedColor(const wxColour& col, int val)
{
// return col.ChangeLightness(100 + val);
wxColourBase::ChannelType r = ModulatedChannel(col.Red(), val);
wxColourBase::ChannelType g = ModulatedChannel(col.Green(), val);
wxColourBase::ChannelType b = ModulatedChannel(col.Blue(), val);
return wxColour(r, g, b);
}
inline wxColour GrayedColor(const wxColour& col)
{
const wxColourBase::ChannelType y1 = Luma(col);
return wxColour(y1,y1,y1);
}
wxColour gtContrastingColor(const wxColour& col)
{
const wxColourBase::ChannelType y1 = Luma(col);
return y1 > 128 ? *wxBLACK : *wxWHITE;
}
///////////////////////////////////////////////////////////
// gtToolBarArt
///////////////////////////////////////////////////////////
void gtToolBarArt::DrawBackground(wxDC& dc, wxWindow* window, int orientation, const wxRect &rect)
{
if (!gtAuiManager::DrawBackground(dc, window, orientation, rect))
wxAuiDefaultDockArt::DrawBackground(dc, window, orientation, rect);
}
void gtToolBarArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect)
{ DrawBackground(dc, window, orientation, rect); }
gtToolBarArt::gtToolBarArt()
{
wxColour base, light, dark, text;
if (gtAuiManager::BaseColours(base, light, dark, text))
{
SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, base);
SetColour(wxAUI_DOCKART_SASH_COLOUR, base);
SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_COLOUR, base);
SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_GRADIENT_COLOUR, light);
SetColour(wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR, text);
SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR, dark);
SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR, base);
const wxColourBase::ChannelType g = Luma(dark) > 128 ? 64 : 192;
SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR, wxColour(g,g,g));
SetColour(wxAUI_DOCKART_BORDER_COLOUR, dark);
}
}
///////////////////////////////////////////////////////////
// gtTabArt
///////////////////////////////////////////////////////////
wxAuiTabArt* gtTabArt::Clone()
{
gtTabArt* ta = new gtTabArt;
return ta;
}
gtTabArt::gtTabArt()
{
wxColour base, light, dark, text;
if (gtAuiManager::BaseColours(base, light, dark, text))
{
m_border_pen = wxPen(ModulatedColor(base, 75));
m_base_colour = base;
m_base_colour_pen = wxPen(base);
m_base_colour_brush = wxBrush(base);
}
}
///////////////////////////////////////////////////////////
// gtAuiManager
///////////////////////////////////////////////////////////
bool gtAuiManager::BaseColours(wxColour& base, wxColour& light, wxColour& dark, wxColour& text)
{
const wxSize sz(256,256);
wxBitmap bmp = wxArtProvider::GetBitmap(wxArtID(wxT("Skin")), wxART_OTHER, sz);
if (bmp.IsOk())
{
wxColourBase::ChannelType ldark = 255, llight = 0;
dark = *wxWHITE;
light = *wxBLACK;
wxNativePixelData data(bmp);
const int dim = data.GetHeight();
wxNativePixelData::Iterator p(data);
double r = 0, g = 0, b = 0;
for (int i = 0; i < dim; i++)
{
p.MoveTo(data, i, i);
r += p.Red();
g += p.Green();
b += p.Blue();
const wxColour col(p.Red(), p.Green(), p.Blue());
const wxColourBase::ChannelType lcol = Luma(col);
if (lcol < ldark)
{
dark = col;
ldark = lcol;
}
if (lcol > llight)
{
light = col;
llight = lcol;
}
}
r /= dim; g /= dim; b /= dim;
base = wxColour(r, g, b);
const wxColourBase::ChannelType lbase = Luma(base);
if (lbase - ldark < 40)
dark = ModulatedColor(dark, -(40 - lbase + ldark));
if (llight - lbase < 40)
light = ModulatedColor(light, +(40 - llight + lbase));
text = gtContrastingColor(base);
}
return bmp.IsOk();
}
bool gtAuiManager::DrawBackground(wxDC& dc, wxWindow* WXUNUSED(window),
int WXUNUSED(orientation), const wxRect &rect)
{
const wxBitmap bmp = wxArtProvider::GetBitmap(wxArtID(wxT("Skin")), wxART_OTHER, wxSize(256,256));
if (bmp.IsOk())
{
const wxSize szBm(bmp.GetWidth(), bmp.GetHeight());
for (wxCoord y = rect.y; y < rect.GetBottom(); y += szBm.y)
{
for (wxCoord x = rect.x; x < rect.GetRight(); x += szBm.x)
dc.DrawBitmap(bmp, x, y);
}
}
return bmp.IsOk();
}
gtAuiManager::gtAuiManager()
{
SetArtProvider(new gtToolBarArt);
}
///////////////////////////////////////////////////////////
// plnHolidayAutority
///////////////////////////////////////////////////////////
class gtHolidayAutority : public wxDateTimeWorkDays
{
protected:
virtual bool DoIsHoliday(const wxDateTime& dt) const;
virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart, const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const;
};
bool gtHolidayAutority::DoIsHoliday(const wxDateTime& dt) const
{
const wxDateTime::Month m = dt.GetMonth();
const wxDateTime::wxDateTime_t d = dt.GetDay();
switch (m)
{
case wxDateTime::Jan:
if (d == 1 || d == 6) // Capodanno ed Epifania
return true;
break;
case wxDateTime::Apr:
if (d == 25) // 25 Aprile
return true;
break;
case wxDateTime::May:
if (d == 1)
return true; // I Maggio
break;
case wxDateTime::Jun:
if (d == 2) // Festa della Repubblica
return true;
break;
case wxDateTime::Aug:
if (d == 15) // Ferragosto
return true;
break;
case wxDateTime::Nov:
if (d == 1) // Ognissanti
return true;
break;
case wxDateTime::Dec:
if (d == 8 || d == 25 || d == 26) // Immacolata, Natale e Santo Stefano
return true;
break;
default: break;
}
const wxDateTime::WeekDay wd = dt.GetWeekDay();
if (wd == wxDateTime::Sun || wd == wxDateTime::Sat)
return true;
if (wd == wxDateTime::Mon && (m == wxDateTime::Mar || m == wxDateTime::Apr))
{
const int y = dt.GetYear();
const int correction = y < 2100 ? 0 : 1; // Semplificazione tabella dal 1600 al 2500
int d = (19 * (y%19) + 24) % 30;
d += 22 + ((2*(y%4) + 4*(y%7) + 6*d + 5 + correction) % 7);
int m = 3;
if (d > 31)
{
d -= 31;
m++;
}
const wxDateTime easter(d, wxDateTime::Month(m-1), y);
if (easter == dt - wxDateSpan(0,0,0,1))
return true;
}
return false;
}
size_t gtHolidayAutority::DoGetHolidaysInRange(const wxDateTime& dtStart, const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const
{
for (wxDateTime dt = dtStart; dt <= dtEnd; dt += wxDateSpan(0,0,0,1))
{
if (DoIsHoliday(dt))
holidays.Add(dt);
}
return holidays.GetCount();
}
///////////////////////////////////////////////////////////
// gtArtProvider
///////////////////////////////////////////////////////////
class gtArtProvider : public wxArtProvider
{
wxString m_strSkin;
protected:
wxSize AdjustedSize(const wxArtClient& client, const wxSize& size) const;
virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size);
public:
gtArtProvider();
};
wxSize gtArtProvider::AdjustedSize(const wxArtClient& client, const wxSize& size) const
{
if (size != wxDefaultSize)
return size;
if (client == wxART_MENU)
return wxSize(16,16);
if (client == wxART_TOOLBAR)
return wxSize(48,48);
wxSize sz = wxArtProvider::GetSizeHint(client);
if (sz == wxDefaultSize)
{
if (client == wxART_OTHER)
sz = size;
else
sz.x = sz.y = 32;
}
return sz;
}
wxBitmap gtArtProvider::CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
{
const wxSize sz = AdjustedSize(client, size);
wxString strName = id;
long tool = 0;
bool bOverriding = false;
if (strName.StartsWith(wxT("wxART")))
{
if (id == wxART_FILE_OPEN) tool = wxID_OPEN; else
if (id == wxART_FILE_SAVE) tool = wxID_SAVE; else
if (id == wxART_FILE_SAVE_AS) tool = wxID_SAVEAS; else
if (id == wxART_NEW) tool = wxID_NEW; else
if (id == wxART_HELP) tool = wxID_HELP; else
return wxNullBitmap;
bOverriding = true;
}
else
{
if (strName.CmpNoCase(wxT("Skin"))==0 && !m_strSkin.IsEmpty())
strName = m_strSkin;
}
if (tool > 0 || id.ToLong(&tool))
{
if (client == wxART_TOOLBAR || client == wxART_BUTTON)
strName.Printf(wxT("res/tool_%ld.png"), tool); else
if (client == wxART_OTHER)
strName.Printf(wxT("res/image_%ld.png"), tool);
else
strName.Printf(wxT("res/icon_%ld.png"), tool);
}
else
strName.MakeLower();
if (!strName.EndsWith(wxT(".png")))
strName << wxT(".png");
bool bFound = wxFileName::FileExists(strName);
if (!bFound && !strName.StartsWith(wxT("res/")))
{
strName.Prepend(wxT("res/"));
bFound = wxFileName::FileExists(strName);
}
if (!bFound && !bOverriding && tool > wxID_LOWEST && tool < wxID_HIGHEST)
{
switch (tool)
{
case wxID_OPEN : strName = wxART_FILE_OPEN; break;
case wxID_SAVE : strName = wxART_FILE_SAVE; break;
case wxID_SAVEAS : strName = wxART_FILE_SAVE_AS; break;
case wxID_NEW : strName = wxART_NEW; break;
case wxID_HELP : strName = wxART_HELP; break;
case wxID_PREFERENCES : strName = wxART_HELP_SETTINGS; break;
default : strName = wxEmptyString; break;
}
if (strName.StartsWith(wxT("wxART")))
return wxArtProvider::GetBitmap(strName, client, sz);
}
if (!bFound)
return wxNullBitmap;
wxBitmap bmp;
if (bmp.LoadFile(strName, wxBITMAP_TYPE_ANY))
{
const wxSize szOld(bmp.GetWidth(), bmp.GetHeight());
if (szOld != sz)
{
wxSize szNew = sz;
if (szOld.x >= szOld.y)
szNew.y = sz.x * szOld.y / szOld.x;
else
szNew.x = sz.y * szOld.x / szOld.y;
bmp = wxBitmap(bmp.ConvertToImage().Scale(szNew.x, szNew.y, wxIMAGE_QUALITY_HIGH));
}
}
else
bmp.Create(sz.x, sz.y);
return bmp;
}
gtArtProvider::gtArtProvider()
{
const wxString strSkin = wxT("res/skin.png");
if (wxFileName::FileExists(strSkin))
m_strSkin = strSkin;
}
void gtInitArtProvider()
{
::wxInitAllImageHandlers();
wxArtProvider::Push(new gtArtProvider);
wxDateTimeHolidayAuthority::AddAuthority(new gtHolidayAutority);
}

48
fd/gtArt.h Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#ifndef __GTART_H__
#define __GTART_H__
#ifndef _WX_ARTPROV_H_
#include <wx/artprov.h>
#endif
#ifndef _WX_AUI_H_
#include <wx/aui/aui.h>
#endif
class gtAuiManager : public wxAuiManager
{
public:
static bool DrawBackground(wxDC& dc, wxWindow* window, int orientation, const wxRect &rect);
static bool BaseColours(wxColour& base, wxColour& light, wxColour& dark, wxColour& text);
gtAuiManager();
};
class gtTabArt : public wxAuiDefaultTabArt
{
protected:
virtual wxAuiTabArt* Clone();
public:
gtTabArt();
};
///////////////////////////////////////////////////////////
// rmstToolBarArt
///////////////////////////////////////////////////////////
class gtToolBarArt : public wxAuiDefaultDockArt
{
protected:
virtual void DrawBackground (wxDC& dc, wxWindow* window, int orientation, const wxRect& rect);
virtual void DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect);
public:
gtToolBarArt();
};
void gtInitArtProvider();
wxColour ModulatedColor(const wxColour& col, int val);
wxColour gtContrastingColor(const wxColour& col);
#endif

1204
fd/gtDialog.cpp Normal file

File diff suppressed because it is too large Load Diff

118
fd/gtDialog.h Normal file
View File

@ -0,0 +1,118 @@
#pragma once
#ifndef __GTDIALOG_H__
#define __GTDIALOG_H__
class wxAuiNotebook;
class wxCalendarEvent;
class wxDateEvent;
#ifndef _WX_HASHMAP_H_
#include <wx/hashmap.h>
#endif
#ifndef __GTART_H__
#include "gtart.h"
#endif
class gtBaseDlg : public wxDialog
{
DECLARE_DYNAMIC_CLASS(gtBaseDlg);
DECLARE_EVENT_TABLE();
wxString m_msg;
wxColour m_rgbTheme;
protected:
gtBaseDlg() { wxASSERT(false); }
virtual void CreateControls(wxSizer& WXUNUSED(sizer)) { wxASSERT(false); }
virtual void OnIdle(wxIdleEvent& evt);
bool Init();
gtBaseDlg(const wxString& title, int nFlags = wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP);
const wxColour& ThemeColour() const { return m_rgbTheme; }
public:
wxButton* PrependButton(wxWindowID id, wxString strLabel, wxArtID art);
bool gtError(const wxString msg);
};
class gtPropertyDlg : public gtBaseDlg
{
DECLARE_DYNAMIC_CLASS(gtPropertyDlg);
wxAuiNotebook* m_pNoteBook;
WX_DECLARE_STRING_HASH_MAP(wxWindow*, gtPropertyCtrls);
gtPropertyCtrls m_hControls;
protected:
gtPropertyDlg() : m_pNoteBook(NULL) { }
wxWindow* FindControl(const char* strName) const;
wxPanel* GetCurrPanel();
virtual void CreateControls(wxSizer& sizer);
virtual bool TransferDataToWindow();
virtual bool TransferDataFromWindow();
void AddLabel(const wxString& strLabel);
void OnTextChanged(wxFocusEvent& evt);
void OnCheckChanged(wxCommandEvent& evt);
void OnComboChanged(wxCommandEvent& evt);
void OnRadioBoxChanged(wxCommandEvent& evt);
void OnDateChanged(wxCalendarEvent& evt);
void OnDatePickChanged(wxDateEvent& evt);
public:
virtual void AddPage(const wxString& strLabel);
virtual void AddCategory(const wxString& strLabel);
virtual void AddProperty(const char* strName, const wxString& strValue, const wxString& strLabel = wxEmptyString,
long flags = 0, const wxString& strHint = wxEmptyString);
virtual void AddProperty(const char* strName, int nValue, const wxString& strLabel = wxEmptyString,
long flags = 0, const wxString& strHint = wxEmptyString);
virtual void AddProperty(const char* strName, double nValue, const wxString& strLabel = wxEmptyString,
long flags = 0, const wxString& strHint = wxEmptyString);
virtual void AddProperty(const char* strName, bool bValue, const wxString& strLabel = wxEmptyString, long flags = 0);
virtual void AddProperty(const char* strName, const wxArrayString& aValues, int nValue = 0,
const wxString& strLabel = wxEmptyString, long flags = 0);
virtual void AddProperty(const char* strName, const wxArrayString& aValues, const wxString& strValue = wxEmptyString,
const wxString& strLabel = wxEmptyString, long flags = 0);
virtual void AddProperty(const char* strName, const wxDateTime& dt, const wxString& strLabel, long flags = 0);
virtual void OnSqlPressed(wxCommandEvent& evt);
virtual void AddPropertyDB(const char* strName, const wxString& strValue, const wxString& strLabel,
long flags = 0, const wxString& strHint = wxEmptyString, const char* strTable = NULL);
virtual bool SetProperty(const char* strName, const wxVariant& var);
virtual wxVariant GetProperty(const char* strName) const;
wxString GetString(const char* strName) const;
int GetInt(const char* strName) const;
double GetDouble(const char* strName) const;
bool GetBool(const char* strName) const;
wxDateTime GetDate(const char* strName) const;
virtual bool IsPropertyEnabled(const wxString& name) const;
virtual bool EnableProperty(const wxString& name, bool on = true);
bool DisableProperty(const wxString& name) { return EnableProperty(name, false); }
virtual bool IsPropertyShown(const wxString& name) const;
virtual bool ShowProperty(const wxString& name, bool on = true);
bool HideProperty(const wxString& name) { return ShowProperty(name, false); }
virtual bool OnDecodeProperty(wxVariant& var);
virtual bool OnValidateProperty(wxVariant& val);
virtual bool OnPropertyChanged(const wxVariant& val);
virtual bool SaveDefault() const;
virtual bool LoadDefault();
virtual int ShowModal();
gtPropertyDlg(const wxString& strTitle, int flags = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxSTAY_ON_TOP);
};
bool gtMessage(const wxString str);
bool gtWarning(const wxString str);
bool gtError(const wxString str);
bool gtAsk(const wxString str);
bool TryToUpdateFile(const wxString& strFile);
bool TryToRemoveFile(wxString& strFile);
#endif

98
fd/gtSSA.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "wxinc.h"
#include "gtSSA.h"
#include "../ssa/h/ssadll.h"
#include "../ssa/h/ssaerr.h"
#include <wx/filename.h>
class SSA_dongle : public wxObject
{
int m_nSerial;
wxString m_strUserID;
wxString m_strProduct, m_strModule;
protected:
const wxString& UserID();
int Login(const char* product, const char* module);
public:
int Login();
int Logout();
SSA_dongle() : m_nSerial(SSA_UTENTE_NON_LOGGATO) {}
} __SSA;
const wxString& SSA_dongle::UserID()
{
if (m_strUserID.IsEmpty())
{
const unsigned long sess = ::WTSGetActiveConsoleSessionId(); // Unknown modern way!
const wxString strUser = ::wxGetUserId();
const wxString strHost = ::wxGetHostName();
m_strUserID.Printf("%s@%s:%lu", (const char*)strUser, (const char*)strHost, sess);
}
return m_strUserID;
}
int SSA_dongle::Login(const char* product, const char* module)
{
if (!m_strProduct.IsEmpty())
Logout();
int err = SSA_Login(UserID(), product);
if (err == 0)
{
m_strProduct = product;
m_nSerial = SSA_NumeroSerie(product);
}
if (err == 0)
{
wxString m = module; m.MakeLower();
err = SSA_ApriModulo(UserID(), m);
if (err == SSA_MOD_NOTFOUND)
{
m.MakeUpper();
err = SSA_ApriModulo(UserID(), m);
}
if (err == 0)
m_strModule = m;
}
return err;
}
int SSA_dongle::Login()
{
const char* product = "CAMPO";
const char* module = "pa";
if (!wxFileName::FileExists("campo.ini"))
product = "WEBGATE";
return Login(product, module);
}
int SSA_dongle::Logout()
{
int err = 0;
if (!m_strModule.IsEmpty())
{
err = SSA_ChiudiModulo(UserID(), m_strModule);
if (err == 0)
m_strModule.Empty();
}
if (!m_strProduct.IsEmpty())
{
err = SSA_Logout(UserID(), m_strProduct);
if (err == 0)
{
m_nSerial = SSA_UTENTE_NON_LOGGATO;
m_strProduct.Empty();
m_strModule.Empty();
}
}
return err;
}
int SSA_Login() { return __SSA.Login(); }
int SSA_Logout() { return __SSA.Logout(); }

8
fd/gtSSA.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#ifndef __GT_SSA_H
#define __GT_SSA_H
int SSA_Login();
int SSA_Logout();
#endif

BIN
fd/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB