array.h Tolta riga vuota

assoc.h     Aggiunta macro di iterazione sugli elementi
golem.h     Aggiunta gestione della posta
golem.cpp   Suvvia c'e' la postaa, la posta eletrronicaaa
mailbox.h   Aggiunto vitrtual davanti al distruttore dei TMessage
msksheet.h  Aggiunte macro di iterazione sulle righe
regexp.h    Tolta #define di NULL
strings.cpp Aggiunti metodi a TFilename:
            is_absolute_path, is_relative_path e make_absolute_path
strings.h   Tolta #include <regexp.h> (-1K nel file .mak)


git-svn-id: svn://10.65.10.50/trunk@5626 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1997-11-17 10:28:04 +00:00
parent 80750c5089
commit 42bddb770f
9 changed files with 373 additions and 60 deletions

View File

@ -284,5 +284,4 @@ public:
void set(const char* numbers);
};
#endif

View File

@ -151,4 +151,10 @@ public:
{ destroy(); }
};
#define FOR_EACH_ASSOC_STRING(__ass, __obj, __key, __str) \
const char *__key, *__str; __ass.restart; \
for (THash_object* __obj = __ass.get_hashobj(); \
__obj && (__str = (const TString&)__obj->obj(), __key = __obj->key()); \
__obj = __ass.get_hashobj())
#endif

View File

@ -1,5 +1,6 @@
#define STRICT
#define XVT_INCL_NATIVE
#include <controls.h>
#include <execp.h>
#include <golem.h>
@ -9,6 +10,7 @@
#include <urldefid.h>
#include <utility.h>
#include <mapi.h>
#include <shellapi.h>
#include "bagn006.h"
@ -91,7 +93,10 @@ HIDDEN bool internet_address(const char* filename)
HIDDEN word file2icon(const char* filename)
{
TFilename key;
word icon = 0;
int icon_number = 0;
TString ext(_MAX_EXT);
if (*filename == '.' && strlen(filename) < _MAX_EXT)
@ -100,13 +105,10 @@ HIDDEN word file2icon(const char* filename)
{
if (internet_address(filename))
ext = ".htm";
else
else
_splitpath(filename, NULL, NULL, NULL, ext.get_buffer());
}
ext.lower();
int icon_number = 0;
TFilename key;
if (ext != ".exe")
{
@ -131,22 +133,39 @@ HIDDEN word file2icon(const char* filename)
}
else
key = filename;
if (fexist(key))
// Toglie eventuali parametri sulla riga si comando
const int space_pos = key.find(' ');
if (space_pos > 0) key.cut(space_pos);
HINSTANCE hInst = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
HICON hicon = ExtractIcon(hInst, key, icon_number);
if (hicon == NULL && icon_number != 0)
hicon = ExtractIcon(hInst, key, 0);
if (hicon != NULL)
{
HINSTANCE hInst = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
HICON hicon = ExtractIcon(hInst, key, icon_number);
if (hicon == NULL)
ExtractIcon(hInst, key, 0);
if (hicon == NULL)
warning_box("Impossibile accedere alll'icona del programma %s", key.get_buffer());
DWORD dwicon = DWORD((DWORD*)hicon);
icon = LOWORD(dwicon);
}
}
return icon;
}
HIDDEN word mail2icon()
{
word icon = 0;
TFilename key;
if (get_reg_key(HKEY_CLASSES_ROOT, "msgfile\\shell\\open\\command", key) == ERROR_SUCCESS)
{
const int space = key.find(' ');
if (space) key.cut(space);
icon = file2icon(key);
}
if (icon == 0)
icon = file2icon(".mmf");
return icon;
}
bool goto_url(const char* url)
{
TFilename app(url);
@ -342,19 +361,24 @@ bool TGolem_mask::ole_handler(TMask_field& f, KEY k)
sheet.check_row(selected);
TString16 ext = f.prompt();
if (ext[0] != '.')
ext.insert(".", 0);
TFilename file;
file.temp(NULL, ext);
sm.set(S_FILE, file);
ofstream out(file);
sheet.row(selected) = file;
sheet.force_update();
TFilename app; file2app(ext, app);
app << ' ' << file;
WinExec(app, SW_SHOWNORMAL);
if (ext == "mailto")
{
TMail_message msg("");
msg.send();
}
else
{
TFilename file;
file.temp(NULL, ext);
sm.set(S_FILE, file);
ofstream out(file);
sheet.row(selected) = file;
sheet.force_update();
TFilename app; file2app(ext, app);
app << ' ' << file;
WinExec(app, SW_SHOWNORMAL);
}
}
return TRUE;
}
@ -376,25 +400,52 @@ TGolem_mask::TGolem_mask()
TConfig ini(CONFIG_USER, "Link");
TString_array list;
const int items = ini.list_variables(list);
ini.list_variables(list);
// Elimina la posta se c'e'
const int mmf_pos = list.find("mailto");
if (mmf_pos >= 0) list.destroy(mmf_pos);
// Ordina alfabeticamente
list.sort();
const int ITEMS_PER_ROW = 15;
const int MAX_ITEMS = ITEMS_PER_ROW * 2 - 1;
for (int i = 0; i < items && i < MAX_ITEMS; i++)
{
TString16 ext = list.row(i);
const int x = (i < ITEMS_PER_ROW ? i*5 : (i-ITEMS_PER_ROW)*5) + 1;
const int y = i < ITEMS_PER_ROW ? 0 : 2;
TButton_field& btn = add_button(301+i, 0, ext, x, y, 3, 2);
btn.set_handler(ole_handler);
const int MAX_ITEMS = ITEMS_PER_ROW * 2;
// Aggiungi la posta se attiva
if (GetProfileInt("Mail", "MAPI", 0))
{
const int items = list.items();
const int mmf_pos = (items >= MAX_ITEMS) ? MAX_ITEMS-1 : -1;
list.add("mailto", mmf_pos);
}
int i = 0;
FOR_EACH_ARRAY_ROW(list, r, row)
{
TString16 ext = *row;
word icon;
if (ext[0] != '.')
if (ext == "mailto")
{
icon = mail2icon();
}
else
{
ext.insert(".", 0);
word icon = file2icon(ext);
icon = file2icon(ext);
}
if (icon)
{
const int x = (i < ITEMS_PER_ROW ? i*5 : (i-ITEMS_PER_ROW)*5) + 1;
const int y = i < ITEMS_PER_ROW ? 0 : 2;
TButton_field& btn = add_button(301+i, 0, ext, x, y, 3, 2);
btn.set_handler(ole_handler);
btn.set_icon(icon);
else
btn.set_bmp(BMP_OLE, 0);
i++;
if (i > MAX_ITEMS)
break;
}
}
}
@ -534,7 +585,8 @@ bool TGolem_field::on_key(KEY key)
if (roman())
{
tmp.separator('\n');
for (const char* row = tmp.get(0); row; row = tmp.get())
// for (const char* row = tmp.get(0); row; row = tmp.get())
FOR_EACH_TOKEN(tmp, row)
{
if (*row > ' ')
sheet.row(-1) = row;
@ -542,11 +594,12 @@ bool TGolem_field::on_key(KEY key)
if (msk->run() == K_ENTER)
{
tmp.cut(0);
for (int r = 0; r < sheet.items(); r++)
// for (int r = 0; r < sheet.items(); r++)
FOR_EACH_SHEET_ROW(sheet, r, row)
{
TToken_string& row = sheet.row(r);
if (row[0] > ' ')
tmp.add(row);
// TToken_string& row = sheet.row(r);
if ((*row)[0] > ' ')
tmp.add(*row);
}
set(tmp);
}
@ -579,10 +632,188 @@ TGolem_field::~TGolem_field()
{ }
///////////////////////////////////////////////////////////
// Obsolete DDE management
// Mail message
///////////////////////////////////////////////////////////
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
#ifdef _WIN32
const char* const szMAPIDLL = "MAPI32.DLL";
#else
const char* const szMAPIDLL = "MAPI.DLL";
#endif
static HINSTANCE _hlibMAPI = NULL;
LPMAPILOGON lpfnMAPILogon = NULL;
LPMAPILOGOFF lpfnMAPILogoff = NULL;
LPMAPISENDMAIL lpfnMAPISendMail = NULL;
LPMAPISENDDOCUMENTS lpfnMAPISendDocuments = NULL;
LPMAPIFINDNEXT lpfnMAPIFindNext = NULL;
LPMAPIREADMAIL lpfnMAPIReadMail = NULL;
LPMAPISAVEMAIL lpfnMAPISaveMail = NULL;
LPMAPIDELETEMAIL lpfnMAPIDeleteMail = NULL;
LPMAPIFREEBUFFER lpfnMAPIFreeBuffer = NULL;
LPMAPIADDRESS lpfnMAPIAddress = NULL;
LPMAPIDETAILS lpfnMAPIDetails = NULL;
LPMAPIRESOLVENAME lpfnMAPIResolveName = NULL;
bool TMail_message::load_mapi(void)
{
if (_hlibMAPI) // Check in already loaded
return TRUE;
// Check if MAPI is installed on the system
BOOL MAPI_installed = GetProfileInt("Mail", "MAPI", 0);
if(!MAPI_installed)
return FALSE;
UINT fuError = SetErrorMode(SEM_NOOPENFILEERRORBOX);
_hlibMAPI = LoadLibrary(szMAPIDLL);
SetErrorMode(fuError);
DWORD* err = (DWORD*)_hlibMAPI;
if ((DWORD)err < 32)
return FALSE;
if (!(lpfnMAPILogon = (LPMAPILOGON) GetProcAddress (_hlibMAPI, "MAPILogon")))
return FALSE;
if (!(lpfnMAPILogoff = (LPMAPILOGOFF) GetProcAddress (_hlibMAPI, "MAPILogoff")))
return FALSE;
if (!(lpfnMAPISendMail = (LPMAPISENDMAIL) GetProcAddress (_hlibMAPI, "MAPISendMail")))
return FALSE;
if (!(lpfnMAPISendDocuments = (LPMAPISENDDOCUMENTS) GetProcAddress (_hlibMAPI, "MAPISendDocuments")))
return FALSE;
if (!(lpfnMAPIFindNext = (LPMAPIFINDNEXT) GetProcAddress (_hlibMAPI, "MAPIFindNext")))
return FALSE;
if (!(lpfnMAPIReadMail = (LPMAPIREADMAIL) GetProcAddress (_hlibMAPI, "MAPIReadMail")))
return FALSE;
if (!(lpfnMAPISaveMail = (LPMAPISAVEMAIL) GetProcAddress (_hlibMAPI, "MAPISaveMail")))
return FALSE;
if (!(lpfnMAPIDeleteMail = (LPMAPIDELETEMAIL) GetProcAddress (_hlibMAPI, "MAPIDeleteMail")))
return FALSE;
if (!(lpfnMAPIFreeBuffer = (LPMAPIFREEBUFFER) GetProcAddress (_hlibMAPI, "MAPIFreeBuffer")))
return FALSE;
if (!(lpfnMAPIAddress = (LPMAPIADDRESS) GetProcAddress (_hlibMAPI, "MAPIAddress")))
return FALSE;
if (!(lpfnMAPIDetails = (LPMAPIDETAILS) GetProcAddress (_hlibMAPI, "MAPIDetails")))
return FALSE;
if (!(lpfnMAPIResolveName = (LPMAPIRESOLVENAME) GetProcAddress (_hlibMAPI, "MAPIResolveName")))
return FALSE;
return TRUE;
}
void TMail_message::unload_mapi()
{
if (_hlibMAPI)
{
FreeLibrary(_hlibMAPI);
_hlibMAPI = NULL;
}
}
bool TMail_message::send()
{
TWait_cursor hourglass;
bool ok = load_mapi();
if (!ok)
return error_box("Impossibile inizializzare MAPI");
LHANDLE lhSession = 0;
ULONG err = lpfnMAPILogon(0L, "", "",
MAPI_LOGON_UI | MAPI_USE_DEFAULT,
0L, &lhSession);
if (err == SUCCESS_SUCCESS)
{
const int MAX_RECIPIENTS = _recipients.items() + _copy_recipients.items() + 1;
MapiRecipDesc* msgRecipient = new MapiRecipDesc[MAX_RECIPIENTS];
memset(msgRecipient, 0, MAX_RECIPIENTS*sizeof(MapiRecipDesc));
int nr = 0;
if (_sender.not_empty())
{
msgRecipient[nr].ulRecipClass = MAPI_ORIG;
msgRecipient[nr++].lpszName = _sender.get_buffer();
}
FOR_EACH_ARRAY_ROW(_recipients, rec, recipient)
{
msgRecipient[nr].ulRecipClass = MAPI_TO;
msgRecipient[nr++].lpszName = recipient->get_buffer();
}
FOR_EACH_ARRAY_ROW(_copy_recipients, cc_rec, cc_recipient)
{
msgRecipient[nr].ulRecipClass = MAPI_CC;
msgRecipient[nr++].lpszName = cc_recipient->get_buffer();
}
const int MAX_ATTACHMENTS = _attachments.items() + 1;
MapiFileDesc* msgAttachment = new MapiFileDesc[MAX_ATTACHMENTS];
memset(msgAttachment, 0, MAX_ATTACHMENTS*sizeof(MapiFileDesc));
int na = 0;
FOR_EACH_ARRAY_ROW(_attachments, att, attachment)
{
TString80 tmp; tmp.spaces(32);
*this << '\n' << tmp;
msgAttachment[na].nPosition = len()-1;
msgAttachment[na++].lpszPathName = attachment->get_buffer();
}
MapiMessage msgSend;
memset(&msgSend, 0, sizeof(MapiMessage));
msgSend.lpszNoteText = get_buffer();
msgSend.lpszSubject = _subject.get_buffer();
msgSend.nRecipCount = nr;
msgSend.lpRecips = msgRecipient;
msgSend.nFileCount = na;
msgSend.lpFiles = msgAttachment;
err = lpfnMAPISendMail(lhSession, 0, &msgSend, MAPI_DIALOG, 0L);
delete msgRecipient;
delete msgAttachment;
err = lpfnMAPILogoff(lhSession, 0L, 0L, 0L);
}
else
ok = error_box("Impossibile collegarsi a MAPI");
unload_mapi();
return ok;
}
bool TMail_message::add_recipient_ex(const char* recipient, int type)
{
TFilename rec(recipient);
rec.trim();
bool ok = rec.not_empty();
if (ok) switch(type)
{
case 1:
_copy_recipients.add(rec);
break;
case 2:
if (rec.is_relative_path())
rec.make_absolute_path();
ok = fexist(rec);
if (ok)
_attachments.add(rec);
break;
default:
_recipients.add(rec);
break;
}
return ok;
}
TMail_message::TMail_message(const char* recipient, const char* subject,
const char* text, const char* sender)
: TString(text), _subject(subject), _sender(sender)
{
add_recipient(recipient);
}
///////////////////////////////////////////////////////////
// Obsolete DDE management
///////////////////////////////////////////////////////////
#include <dde.h>
@ -626,7 +857,8 @@ HIDDEN BOOLEAN hook(HWND hwnd,
if (ok && !query_topics)
{
ok = FALSE;
for (const char* topo = topics.get(0); topo; topo = topics.get())
// for (const char* topo = topics.get(0); topo; topo = topics.get())
FOR_EACH_TOKEN(topics, topo)
{
if (t.compare(topo, -1, TRUE) == 0)
{
@ -795,4 +1027,3 @@ void TDDE::terminate()
}
}
#endif

View File

@ -8,6 +8,35 @@
bool goto_url(const char* url);
bool print_url(const char* url);
class TMail_message : public TString
{
TString_array _recipients, _copy_recipients, _attachments;
TString _subject;
TString _sender;
protected:
bool load_mapi();
void unload_mapi();
bool add_recipient_ex(const char* recipient, int type);
public:
bool add_recipient(const char* address) { return add_recipient_ex(address, 0); }
void set_subject(const char* subject) { _subject = subject; _subject.trim(); }
bool add_copy_recipient(const char* address) { return add_recipient_ex(address, 1); }
bool attach(const char* filename) { return add_recipient_ex(filename, 2); }
void set_sender(const char* address) { _sender = address; _sender.trim(); }
TString& operator = (const char* msg) { set(msg); return *this; }
TString& operator = (const TString& msg) { set(msg); return *this; }
bool send();
TMail_message(const char* recipient, const char* subject = NULL,
const char* text = NULL, const char* sender = NULL);
virtual ~TMail_message() { }
};
// @doc EXTERNAL
// @class TDDE | Classe per la gestione del DDE

View File

@ -83,6 +83,7 @@ public:
// @cmember Costruttore
TMessage(const char* to, const char* sub, const char* text, const char* from = NULL);
virtual ~TMessage() { }
};
// @class TMailbox | Classe per controllare i messaggi ricevuti da una applicazione

View File

@ -231,4 +231,10 @@ public:
virtual ~TSheet_field();
};
#define FOR_EACH_SHEET_ROW(__sheet, __r, __riga) \
FOR_EACH_ARRAY_ROW(__sheet.rows_array(), __r, __riga)
#define FOR_EACH_SHEET_ROW_BACK(__sheet, __r, __riga) \
FOR_EACH_ARRAY_ROW_BACK(__sheet.rows_array(), __r, __riga)
#endif

View File

@ -5,10 +5,6 @@
#include <stdtypes.h>
#endif
#ifndef NULL
#include <stddef.h>
#endif
// Composizione delle regular expression:
// -------------------------------------
// - '*' sostituisce una qualunque sottostringa (0 o più caratteri)

View File

@ -1,4 +1,5 @@
#include <ctype.h>
#include <direct.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
@ -8,6 +9,7 @@
#include <strstream.h>
#endif
#include <regexp.h>
#include <strings.h>
#include <prefix.h>
#include <utility.h>
@ -393,6 +395,12 @@ int TString::find(const char* s, int from) const
return p ? int(p - _str) : -1;
}
bool TString::match(const char* pat) const
{
return ::match(pat, _str);
}
int TString::replace(char find_char, char replace_char)
{
const int l = len();
@ -1217,6 +1225,26 @@ const TFilename& TFilename::temp(
}
bool TFilename::is_absolute_path() const
{
const char* s = _str;
if (isalpha(*s) && s[1] == ':')
s += 2;
return *s == '/' || *s == '\\';
}
const TFilename& TFilename::make_absolute_path()
{
if (is_relative_path())
{
const TString saved(*this);
getcwd(get_buffer(), size());
add(saved);
}
return *this;
}
///////////////////////////////////////////////////////////
// Token string
///////////////////////////////////////////////////////////

View File

@ -9,11 +9,6 @@
#include <array.h>
#endif
#ifndef __REGEXP_H
#include <regexp.h>
#endif
// @doc EXTERNAL
// @class Classe per la definizione della stringhe
@ -256,8 +251,7 @@ public:
bool operator <=(const TString & s) const
{ return strcmp(_str, s._str) <= 0; }
// @cmember Confronta usando le regular expression
bool match(const char* pat) const
{ return ::match(pat, _str); }
bool match(const char* pat) const;
// @cmember Compara due stringhe (o i primi max caratteri)
int compare(const char* s, int max = -1, bool ignorecase = FALSE) const;
};
@ -415,6 +409,13 @@ public:
// @cmember Concatena un nome di file ad una directory
TFilename& add(const char* n);
// @cmember Controlla se si tratta di un path assoluto
bool is_absolute_path() const;
// @cmember Controlla se si tratta di un path relativo
bool is_relative_path() const { return !is_absolute_path(); }
// @cmember Trasforma un path da relativo ad assoluto
const TFilename& make_absolute_path();
// @cmember Ritorna il nome del file
const char* name() const;
@ -504,6 +505,9 @@ public:
bool empty_items() const;
};
#define FOR_EACH_TOKEN(__tok, __str) \
for (const char* __str = __tok.get(0); __str; __str = __tok.get())
///////////////////////////////////////////////////////////
// DES Paragraph
///////////////////////////////////////////////////////////
@ -590,6 +594,18 @@ public:
{}
};
#define FOR_EACH_ARRAY_ROW(__arr, __r, __riga) \
TToken_string* __riga; \
for (int __r = __arr.first(); \
__riga = (TToken_string*)__arr.objptr(__r); \
__r = __arr.succ(__r))
#define FOR_EACH_ARRAY_ROW_BACK(__arr, __r, __riga) \
TToken_string* __riga; \
for (int __r = __arr.last(); \
__riga = (TToken_string*)__arr.objptr(__r); \
__r = __arr.pred(__r))
const char SLASH =
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
'\\';
@ -598,3 +614,4 @@ const char SLASH =
#endif
#endif