From 9d7cb84959282313373c207a9bc09625f4693d6c Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 22 May 2003 15:25:25 +0000 Subject: [PATCH] Patch level : 2.0 476 Files correlati : xvagaa.dll Ricompilazione Demo : [ ] Commento : Modifiche per Linux git-svn-id: svn://10.65.10.50/trunk@11172 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- xvaga/agasys.cpp | 35 +- xvaga/agasys.h | 2 +- xvaga/oslinux.cpp | 261 ++++++++++ xvaga/oslinux.h | 22 + xvaga/skeylink.h | 7 +- xvaga/wxinc.h | 10 +- xvaga/xvaga.cpp | 1199 ++++++++++++++++++++++++-------------------- xvaga/xvapp.cpp | 4 +- xvaga/xvintern.h | 6 +- xvaga/xvt.h | 34 +- xvaga/xvt_env.h | 2 +- xvaga/xvt_type.h | 496 +++++++++--------- xvaga/xvtextra.cpp | 289 ++++++++--- 13 files changed, 1471 insertions(+), 896 deletions(-) create mode 100755 xvaga/oslinux.cpp create mode 100755 xvaga/oslinux.h diff --git a/xvaga/agasys.cpp b/xvaga/agasys.cpp index 94b3ffe0a..8e9f945d7 100755 --- a/xvaga/agasys.cpp +++ b/xvaga/agasys.cpp @@ -1,7 +1,10 @@ #include "wxinc.h" - #include +#ifdef LINUX +#include "xvt_type.h" +#endif + #include "agasys.h" /////////////////////////////////////////////////////////// @@ -9,7 +12,7 @@ /////////////////////////////////////////////////////////// #include -#include +#include #pragma pack(2) @@ -35,7 +38,7 @@ struct ZipDirectoryFileHeader unsigned short nStartDisk; unsigned short nInternalAttr; unsigned long nExternalAttr; - unsigned long nLocalHeaderOffset; + unsigned long nLocalHeaderOffset; }; struct ZipDirectoryEnd @@ -44,8 +47,8 @@ struct ZipDirectoryEnd unsigned short nStartDisk; unsigned short nDiskEntries; unsigned short nTotalEntries; - unsigned long nSize; - unsigned long nStartOffset; + unsigned long nSize; + unsigned long nStartOffset; unsigned short nCommentLength; }; @@ -102,7 +105,7 @@ bool aga_unzip(const char* zipfile, const char* destdir) strOutFile += '/'; strOutFile += strFileName; - wxString strPath; + wxString strPath; ::wxSplitPath(strOutFile, &strPath, NULL, NULL); if (!::wxDirExists(strPath)) ::wxMkdir(strPath); @@ -168,7 +171,7 @@ static int AddFilesToList(const wxString& strBase, const wxString& strMask, wxSt return n; } -static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, +static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, wxFileOutputStream& fout, wxFileOutputStream& fdir) { if (!wxFileExists(strFile)) @@ -182,7 +185,7 @@ static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, if (!strRelName.IsEmpty()) strRelName += '/'; strRelName += strName; - strRelName += '.'; + strRelName += '.'; strRelName += strExt; const off_t nStartPos = fout.TellO(); // Memorizzo posizione @@ -190,11 +193,11 @@ static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, const unsigned long dwLocalSignature = 0x04034B50; fout.Write(&dwLocalSignature, sizeof(dwLocalSignature)); // Scrivo PK34 ZipLocalFileHeader zlfh; memset(&zlfh, 0, sizeof(zlfh)); - zlfh.nVersionNeeded = 20; // You need at least pkunzip 2.0 - zlfh.nFlags = 0x0002; // Deep Hacking ??? + zlfh.nVersionNeeded = 20; // You need at least pkunzip 2.0 + zlfh.nFlags = 0x0002; // Deep Hacking ??? zlfh.nMethod = 8; // Implode zlfh.nNameLength = strRelName.Length(); - fout.Write(&zlfh, sizeof(zlfh)); // Scrivo header azzerato + fout.Write(&zlfh, sizeof(zlfh)); // Scrivo header azzerato fout.Write((const char*)strRelName, zlfh.nNameLength); // Scrivo nome file const off_t nDataStart = fout.TellO(); // Memorizzo posizione dati compressi @@ -203,14 +206,14 @@ static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, { wxFileInputStream fin(strFile); AgaZlibOutputStream zout(fout); - zout.Write(fin); // Scrivo file compresso + zout.Write(fin); // Scrivo file compresso zlfh.dwUncompressedSize = fin.TellI(); } fout.SeekO(nMagicOffset, wxFromEnd); - zlfh.dwCompressedSize = fout.TellO(); - zlfh.dwCompressedSize -= nDataStart; + zlfh.dwCompressedSize = fout.TellO(); + zlfh.dwCompressedSize -= nDataStart; zlfh.dwCRC = ComputeFileCRC32(strFile); const time_t tMod = ::wxFileModificationTime(strFile); @@ -232,7 +235,7 @@ static void AddFileToZip(const wxString& strPrefix, const wxString& strFile, fout.SeekO(nMagicOffset, wxFromEnd); ZipDirectoryFileHeader zdfh; memset(&zdfh, 0, sizeof(zdfh)); - zdfh.nVersionUsed = zlfh.nVersionNeeded; + zdfh.nVersionUsed = zlfh.nVersionNeeded; memcpy(&zdfh.zlfh, &zlfh, sizeof(zlfh)); zdfh.nLocalHeaderOffset = nStartPos; @@ -304,7 +307,7 @@ bool aga_zip_filelist(const char* filelist, const char* zipfile) ifstream fin(filelist); while (!fin.eof()) { - char name[MAX_PATH]; + char name[_MAX_PATH]; fin.getline(name, sizeof(name)); if (*name) aFiles.Add(name); diff --git a/xvaga/agasys.h b/xvaga/agasys.h index 0053206bf..ad444788c 100755 --- a/xvaga/agasys.h +++ b/xvaga/agasys.h @@ -8,7 +8,7 @@ #define XVTDLL __declspec(dllimport) #endif #else -#define +#define XVTDLL #endif XVTDLL bool aga_unzip(const char* zipfile, const char* destdir); diff --git a/xvaga/oslinux.cpp b/xvaga/oslinux.cpp new file mode 100755 index 000000000..73c4161d4 --- /dev/null +++ b/xvaga/oslinux.cpp @@ -0,0 +1,261 @@ +#include "wxinc.h" +#include "wx/print.h" +#include "wx/printdlg.h" + +#include "xvt.h" +#include "oslinux.h" + +#include "xvt_menu.h" +#include "xvt_help.h" +#include "xvintern.h" +#include +#include +#include + +#include +#include +#include +#include + +wxString OsLinux_File2App(const char* filename) +{ + wxString app; + + SORRY_BOX(); + return app; +} + +int OsLinux_EnumerateFamilies(char** families, int max_count) +{ + wxFontEnumerator ef; + + ef.EnumerateFacenames(); + wxArrayString * fonts = ef.GetFacenames(); + + size_t items = fonts->GetCount(); + size_t i; + + for (i = 0; i < items; i++) + strcpy(families[i], (*fonts)[i].c_str()); + + return items; +} + +int OsLinux_EnumerateSizes(const char* name, long* sizes, short* scalable, int max_count) +{ + int i = 0; + TFontId f; + wxPrinter printer; + wxPostScriptDC dc(printer.GetPrintDialogData().GetPrintData()); + + f.SetFaceName(name); + for (int size = 7; size < 80; size++) + { + f.SetPointSize(size); + if (f.Font((wxDC *) &dc).Ok()) + sizes[i++] = size; + } + + return i; +} + +void OsLinux_PlaceProcessInWindow(unsigned int instance, const char* name, unsigned int parent) +{ + SORRY_BOX(); +} + +void OsLinux_UpdateWindow(unsigned int handle) +{ + SORRY_BOX(); +} + +/////////////////////////////////////////////////////////// +// Hardlock Support +/////////////////////////////////////////////////////////// + +#include "hlapi_c.h" + +bool OsLinux_HL_Login(unsigned short address, const unsigned char* label, const unsigned char* password) +{ + int err = HL_LOGIN(address, LOCAL_DEVICE, (unsigned char*)label, (unsigned char*)password); + return err == STATUS_OK; +} + +bool OsLinux_HL_Logout() +{ + HL_LOGOUT(); + return TRUE; +} + +bool OsLinux_HL_Read(unsigned short reg, unsigned short* data) +{ + int err = HL_READ(reg, data); + return err == STATUS_OK; +} + +bool OsLinux_HL_ReadBlock(unsigned char* data) +{ + int err = HL_READBL(data); + return err == STATUS_OK; +} + +bool OsLinux_HL_Write(unsigned short reg, unsigned short data) +{ + int err = HL_WRITE(reg, data); + return err == STATUS_OK; +} + +bool OsLinux_HL_Crypt(unsigned short* data) // Array di 4 words (8 bytes) +{ + int err = HL_CODE(data, 1); + return err == STATUS_OK; +} + +/////////////////////////////////////////////////////////// +// Eutron Smartlink Support +/////////////////////////////////////////////////////////// + +#include "skeylink.h" + +static KEY_NET _eutron_key; + +static short smartlink(KEY_NET * key) +{ + SKEY_DATA skey; + int i; + + skey.lpt = key->lpt; + skey.command = key->command; + for (i = 0; i < LABEL_LENGTH; i++) + skey.label[i] = key->label[i]; + for (i = 0; i < PASSWORD_LENGTH; i++) + skey.password[i] = key->password[i]; + for (i = 0; i < DATA_LENGTH; i++) + skey.data[i] = key->data[i]; + skey.fail_counter = key->fail_counter; + skey.status = key->status; + for (i = 0; i < EXTENDED_DATA_LENGTH; i++) + skey.ext_data[i] = key->ext_data[i]; + + short retval = clink(&skey); + + key->lpt = skey.lpt; + key->command = skey.command; + for (i = 0; i < LABEL_LENGTH; i++) + key->label[i] = skey.label[i]; + for (i = 0; i < PASSWORD_LENGTH; i++) + key->password[i] = skey.password[i]; + for (i = 0; i < DATA_LENGTH; i++) + key->data[i] = skey.data[i]; + key->fail_counter = skey.fail_counter; + key->status = skey.status; + for (i = 0; i < EXTENDED_DATA_LENGTH; i++) + key->ext_data[i] = skey.ext_data[i]; + return retval; +} + +bool OsLinux_SL_Crypt(unsigned short* data) +{ + _eutron_key.net_command = NET_KEY_ACCESS; + _eutron_key.command = SCRAMBLING_MODE; + memcpy(_eutron_key.data, data, 8); + smartlink(&_eutron_key); + if (_eutron_key.status == ST_OK) + memcpy(data, _eutron_key.data, 8); + return _eutron_key.status == ST_OK; +} + +bool OsLinux_SL_Login(const unsigned char* label, const unsigned char* password) +{ + memset(&_eutron_key, 0, sizeof(KEY_NET)); + _eutron_key.net_command = NET_KEY_OPEN; + _eutron_key.status = ST_HW_FAILURE; // Don't leave ST_OK = 0 here! + memcpy(_eutron_key.label, label, strlen((const char*)label)); + memcpy(_eutron_key.password, password, strlen((const char*)password)); + + smartlink(&_eutron_key); + return _eutron_key.status == ST_OK; +} + +bool OsLinux_SL_Logout() +{ + _eutron_key.net_command = NET_KEY_CLOSE; + _eutron_key.command = 0; + smartlink(&_eutron_key); + return true; +} + +bool OsLinux_SL_ReadBlock(unsigned short reg, unsigned short size, unsigned short* data) +{ + _eutron_key.net_command = NET_KEY_ACCESS; + _eutron_key.command = BLOCK_READING_MODE; + unsigned short* pointer = (unsigned short*)(&_eutron_key.data[0]); + unsigned short* number = (unsigned short*)(&_eutron_key.data[2]); + *pointer = reg; + *number = size; + smartlink(&_eutron_key); + bool ok = _eutron_key.status == ST_OK; + if (ok) + memcpy(data, &_eutron_key.data[4], size*sizeof(unsigned short)); + return ok; +} + +bool OsLinux_SL_WriteBlock(unsigned short reg, unsigned short size, const unsigned short* data) +{ + _eutron_key.net_command = NET_KEY_ACCESS; + _eutron_key.command = BLOCK_WRITING_MODE; + unsigned short* pointer = (unsigned short*)(&_eutron_key.data[0]); + unsigned short* number = (unsigned short*)(&_eutron_key.data[2]); + *pointer = reg; + *number = size; + memcpy(&_eutron_key.data[4], data, size*sizeof(unsigned short)); + smartlink(&_eutron_key); + return _eutron_key.status == ST_OK; +} + +void OsLinux_GetFileSys(const char* path, char * dev, char * dir, char * type) +{ + struct mntent *m; + FILE *f = setmntent("/etc/mnttab", "r"); + + while ((m = getmntent(f)) && strncmp(path, m->mnt_dir, strlen(m->mnt_dir)) != 0); + if (m) + { + if (dev) strcpy(dev, m->mnt_fsname); + if (dir) strcpy(dir, m->mnt_dir); + if (type) strcpy(type, m->mnt_type); + } + else + { + if (dev) *dev = '\0'; + if (dir) *dir = '\0'; + if (type) *type = '\0'; + } + endmntent(f); +} + + +bool OsLinux_IsNetworkDrive(const char * path) +{ + struct statfs buf; + + if (statfs(path, &buf) == -1) + return FALSE; + return (buf.f_type == 0x6969 /*NFS_SUPER_MAGIC */) || + (buf.f_type == 0x517B /*SMB_SUPER_MAGIC)*/); +} + +int64_t OsLinux_GetDiskFreeSpace(const char * path) +{ + struct statfs buf; + int64_t nBytes = 0L; + + if (statfs(path, &buf) != -1) + { + nBytes = buf.f_bsize; + nBytes *= buf.f_bavail; + nBytes *= 1024; + } + + return nBytes; +} diff --git a/xvaga/oslinux.h b/xvaga/oslinux.h new file mode 100755 index 000000000..3f8206d24 --- /dev/null +++ b/xvaga/oslinux.h @@ -0,0 +1,22 @@ +wxString OsLinux_File2App(const char* filename); + +int OsLinux_EnumerateFamilies(char** families, int max_count); +int OsLinux_EnumerateSizes(const char* name, long* sizes, short* scalable, int max_count); + +void OsLinux_PlaceProcessInWindow(unsigned int instance, const char* name, unsigned int parent); +void OsLinux_UpdateWindow(unsigned int handle); + +bool OsLinux_HL_Crypt(unsigned short* data); +bool OsLinux_HL_Login(unsigned short address, const unsigned char* label, const unsigned char* password); +bool OsLinux_HL_Logout() ; +bool OsLinux_HL_Read(unsigned short reg, unsigned short* data); +bool OsLinux_HL_ReadBlock(unsigned char* data); +bool OsLinux_HL_Write(unsigned short reg, unsigned short data); +bool OsLinux_SL_Crypt(unsigned short* data); +bool OsLinux_SL_Login(const unsigned char* label, const unsigned char* password); +bool OsLinux_SL_Logout() ; +bool OsLinux_SL_ReadBlock(unsigned short reg, unsigned short size, unsigned short* data); +bool OsLinux_SL_WriteBlock(unsigned short reg, unsigned short size, const unsigned short* data); +void OsLinux_GetFileSys(const char* path, char * dev, char * dir, char * type); +bool OsLinux_IsNetworkDrive(const char * path); +int64_t OsLinux_GetDiskFreeSpace(const char * path); diff --git a/xvaga/skeylink.h b/xvaga/skeylink.h index 6e79fc035..ec594f4f7 100755 --- a/xvaga/skeylink.h +++ b/xvaga/skeylink.h @@ -131,7 +131,7 @@ typedef struct __SKEY_DATA { #define ST_NET_LOCAL_INIT_ERROR -25 /* Error inizializing the Local protocol */ #define ST_NET_KEY_NOT_MAP -26 /* Not MAP programmed key found when MAP is requested */ -/* +/* Code returned in data[0] after NET_OPEN */ #define NET_TYPE_LOCAL 0 @@ -172,7 +172,12 @@ typedef struct __KEY_NET { Call the driver. Return key->k.status code */ + +#ifdef WIN32 short __cdecl smartlink(KEY_NET*); +#else +int clink(SKEY_DATA *); +#endif #ifdef __cplusplus } diff --git a/xvaga/wxinc.h b/xvaga/wxinc.h index fa6f1109d..9d2925db8 100755 --- a/xvaga/wxinc.h +++ b/xvaga/wxinc.h @@ -2,6 +2,7 @@ #ifndef __WXINC_H__ #define __WXINC_H__ + #ifdef WIN32 #define __WINDOWS__ #define __WXMSW__ @@ -10,9 +11,14 @@ #define WINVER 0x0400 #define STRICT #define WXUSINGDLL 1 +#include +#else +#define _FILE_OFFSET_BITS 64 +#define _LARGE_FILES +#define __WXGTK__ +#define GTK_NO_CHECK_CASTS +#include #endif -#include "wx/wxprec.h" - #endif diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index 11bd4d49c..f0fd0abbe 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -8,7 +8,7 @@ #include "wx/image.h" #include -#include "wx/fs_zip.h" +#include "wx/fs_zip.h" #include "wx/html/helpctrl.h" #include "xvt.h" @@ -19,6 +19,9 @@ #ifdef WIN32 #include "oswin32.h" +#else +#include +#include "oslinux.h" #endif // Funzione interna di utilita' @@ -52,15 +55,13 @@ void assert_box(bool test, int line) } } -#define SORRY_BOX() sorry_box(__LINE__) - -void sorry_box(int line) +void xvt_sys_sorry_box(const char * file,int line) { static wxHashTable sorry; if (sorry.Get(line) == NULL) { sorry.Put(line, &sorry); // Dummy - const wxString strMessage = wxString::Format("Function at line %d not implemented", line); + const wxString strMessage = wxString::Format("Function in file %s at line %d not implemented", file, line); ::wxMessageBox(strMessage); } } @@ -70,13 +71,13 @@ void sorry_box(int line) static bool RectIntersect(const wxRect &rect1, const wxRect &rect2) { if (rect1.GetRight() < rect2.GetLeft()) - return false; + return false; if (rect2.GetRight() < rect1.GetLeft()) - return false; + return false; if (rect1.GetBottom() < rect2.GetTop()) - return false; + return false; if (rect2.GetBottom() < rect1.GetTop()) - return false; + return false; return true; } @@ -144,7 +145,11 @@ wxCursor* GetCursorResource(int rid) wxString strName = ::GetResourceName("Cursor", rid); if (::wxFileExists(strName)) { +#ifdef WIN32 cursor = new wxCursor(strName, wxBITMAP_TYPE_CUR); +#else + cursor = wxSTANDARD_CURSOR; +#endif if (!cursor->Ok()) { delete cursor; @@ -189,14 +194,14 @@ public: WINDOW Owner() const { return _owner; } void Kill(); - TwxCaret() : _visible(false), _owner(NULL_WIN) { } + TwxCaret() : _owner(NULL_WIN), _visible(false) { } virtual ~TwxCaret() { Kill(); } } _TheCaret; -void TwxCaret::Kill() -{ +void TwxCaret::Kill() +{ _owner = NULL_WIN; -} +} void TwxCaret::Show(WINDOW w, bool on) { @@ -254,16 +259,16 @@ TDC::TDC(wxWindow* owner) : _dc(NULL) _owner = owner; memset(&_dct, 0, sizeof(_dct)); - _dct.pen.width = 0; - _dct.pen.pat = PAT_SOLID; - _dct.pen.style = P_SOLID; - _dct.pen.color = COLOR_BLACK; + _dct.pen.width = 0; + _dct.pen.pat = PAT_SOLID; + _dct.pen.style = P_SOLID; + _dct.pen.color = COLOR_BLACK; _dct.brush.pat = PAT_HOLLOW; _dct.brush.color = COLOR_WHITE; _dct.mode = M_COPY; _dct.fore_color = COLOR_BLACK; - _dct.back_color = COLOR_WHITE; - _dct.opaque_text = FALSE; + _dct.back_color = COLOR_WHITE; + _dct.opaque_text = FALSE; _font.SetPointSize(9); // Default font _deltaf = 0; @@ -273,9 +278,9 @@ TDC::TDC(wxWindow* owner) : _dc(NULL) _dirty = -1; // Absolutely force setting } -TDC::~TDC() -{ - KillDC(); +TDC::~TDC() +{ + KillDC(); } void TDC::SetDirty(int d) @@ -299,7 +304,8 @@ static int PatternToStyle(PAT_STYLE pat) case PAT_CROSS: style = wxCROSS_HATCH; break; case PAT_DIAGCROSS: style = wxCROSSDIAG_HATCH; break; case PAT_RUBBER: - case PAT_SPECIAL: style = wxSOLID; SORRY_BOX(); break; + case PAT_SPECIAL: + default: style = wxSOLID; SORRY_BOX(); break; } return style; } @@ -423,7 +429,7 @@ wxDC& TDC::GetDC(bool bPaint) } _dirty = false; - } + } return *_dc; } @@ -440,7 +446,7 @@ void TDC::KillDC() void TDC::SetClippingBox(const RCT* pRct) { #if wxCHECK_VERSION(2,3,0) - if (_dc != NULL) + if (_dc != NULL) _dc->DestroyClippingRegion(); #endif if (pRct) @@ -538,7 +544,7 @@ class TwxWindowBase : public wxWindow { public: TwxWindowBase() { } - TwxWindowBase(wxWindow* parent, int id, const wxString& title, + TwxWindowBase(wxWindow* parent, int id, const wxString& title, wxPoint pos, wxSize size, long style); DECLARE_DYNAMIC_CLASS(TwxWindowBase) @@ -546,7 +552,7 @@ public: IMPLEMENT_DYNAMIC_CLASS(TwxWindowBase, wxWindow) -TwxWindowBase::TwxWindowBase(wxWindow* parent, int id, const wxString& title, +TwxWindowBase::TwxWindowBase(wxWindow* parent, int id, const wxString& title, wxPoint pos, wxSize size, long style) : wxWindow(parent, id, pos, size, style) { @@ -585,13 +591,13 @@ public: void SetMenuTree(const MENU_ITEM* menu); MENU_ITEM* GetMenuTree() const { return m_menu; } - - TwxWindow() : _timer(NULL), _eh(NULL) { } + + TwxWindow() : m_menu(NULL), _type(W_DOC), _eh(NULL), _app_data(0L), _timer(NULL) { } TwxWindow(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); virtual ~TwxWindow(); - + DECLARE_DYNAMIC_CLASS(TwxWindow); DECLARE_EVENT_TABLE(); }; @@ -676,7 +682,7 @@ void TwxWindow::OnChar(wxKeyEvent& event) switch (k) { case WXK_ALT: - case WXK_MENU: + case WXK_MENU: case WXK_NUMPAD0: case WXK_NUMPAD1: case WXK_NUMPAD2: @@ -690,7 +696,7 @@ void TwxWindow::OnChar(wxKeyEvent& event) event.Skip(); return; case WXK_NUMPAD_DECIMAL: // ??? Non arriva mai - case WXK_DECIMAL: // ??? Arriva sia '.' sia WXK_DECIMAL=340 + case WXK_DECIMAL: // ??? Arriva sia '.' sia WXK_DECIMAL=340 k = ','; // Trasformo il punto in virgola bSkipNextDotKey = TRUE; break; @@ -839,10 +845,10 @@ void TwxWindow::OnPaint(wxPaintEvent& event) wxRect rctDamaged = GetUpdateRegion().GetBox(); rct.left = rctDamaged.x; rct.top = rctDamaged.y; - rct.right = rctDamaged.GetRight()+1; + rct.right = rctDamaged.GetRight()+1; rct.bottom = rctDamaged.GetBottom()+1; - TDC& tdc = _dc_map.GetTDC(this); + TDC& tdc = _dc_map.GetTDC(this); tdc.GetDC(true); // Forza la creazione di un wxPaintDC DoXvtEvent(e); tdc.KillDC(); // Distrugge il wxPaintDC @@ -852,9 +858,9 @@ void TwxWindow::OnPaint(wxPaintEvent& event) static SCROLL_CONTROL ConvertScrollToXVT(wxEventType et) { if (et == wxEVT_SCROLL_TOP) - return SC_THUMB; // Meglio di niente + return SC_THUMB; // Meglio di niente if (et == wxEVT_SCROLL_BOTTOM) - return SC_THUMB; // Meglio di niente + return SC_THUMB; // Meglio di niente if (et == wxEVT_SCROLL_LINEUP) return SC_LINE_UP; if (et == wxEVT_SCROLL_LINEDOWN) @@ -944,16 +950,16 @@ void TwxWindow::SetMenuTree(const MENU_ITEM* tree) TwxWindow::TwxWindow(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) - : TwxWindowBase(parent, id, title, pos, size, style), + : TwxWindowBase(parent, id, title, pos, size, style), _timer(NULL), m_menu(NULL), _eh(NULL) -{ +{ _nice_windows.Put((WINDOW)this, this); } TwxWindow::~TwxWindow() { - if (_timer) - delete _timer; + if (_timer) + delete _timer; if (m_menu) { xvt_res_free_menu_tree(m_menu); @@ -1015,13 +1021,13 @@ void TTaskWin::OnPaint() wxRect rctDamaged = GetUpdateRegion().GetBox(); rct.left = rctDamaged.x; rct.top = rctDamaged.y; - rct.right = rctDamaged.GetRight()+1; + rct.right = rctDamaged.GetRight()+1; rct.bottom = rctDamaged.GetBottom()+1; - TDC& dc = _dc_map.GetTDC(this); + TDC& dc = _dc_map.GetTDC(this); dc.GetDC(true); // Forza la creazione di un wxPaintDC _task_win_handler((WINDOW)this, &e); - dc.KillDC(); + dc.KillDC(); } void TTaskWin::OnSize(wxSizeEvent& event) @@ -1053,7 +1059,8 @@ void TTaskWin::SetMenuTree(const MENU_ITEM* tree) pMenu->DoAppend(item); } const int nLast = bar->GetMenuCount()-1; - for (int m = 2; m < nLast; m++) + int m; + for (m = 2; m < nLast; m++) { wxMenu* pMenu = bar->GetMenu(m); if (pMenu->FindItem(tree->child->tag)) @@ -1128,11 +1135,11 @@ TTaskWin::~TTaskWin() /////////////////////////////////////////////////////////// void xvt_app_allow_quit(void) -{ +{ wxTheApp->ExitMainLoop(); // Già lo fa la destroy } -void xvt_app_create(int argc, char **argv, unsigned long flags, +void xvt_app_create(int argc, char **argv, unsigned long flags, EVENT_HANDLER eh, XVT_CONFIG *config) { ::wxInitAllImageHandlers(); @@ -1184,8 +1191,16 @@ void xvt_app_create(int argc, char **argv, unsigned long flags, Menus[2]->Append(M_HELP_HELPONHELP, "&Uso della guida"); Menus[2]->AppendSeparator(); Menus[2]->Append(M_FILE_ABOUT+1, "&Informazioni"); - wxMenuBar* pMenubar = new wxMenuBar(3, Menus, Title); + +#ifdef WIN32 + wxMenuBar* pMenubar = new wxMenuBar(3, Menus, Title); +#else + wxMenuBar* pMenubar = new wxMenuBar(); + + for (int i= 0; i < 3; i++) + pMenubar->Append(Menus[i], Title[i]); ((wxFrame*)_task_win)->SetMenuBar(pMenubar); +#endif _task_win->Show(); if (style & wxMAXIMIZE) @@ -1200,21 +1215,21 @@ void xvt_app_create(int argc, char **argv, unsigned long flags, } void xvt_app_destroy(void) -{ +{ wxTheApp->ExitMainLoop(); _task_win->Destroy(); -} +} DRAW_CTOOLS* xvt_app_get_default_ctools(DRAW_CTOOLS *ct) { XVT_ASSERT(ct != NULL); - TDC dc(NULL); + TDC dc(NULL); memcpy(ct, &dc._dct, sizeof(DRAW_CTOOLS)); return ct; } -void xvt_app_process_pending_events(void) -{ +void xvt_app_process_pending_events(void) +{ if (wxTheApp != NULL) { for (int m = 0; m < 4 && wxTheApp->Pending(); m++) @@ -1228,7 +1243,7 @@ void xvt_app_process_pending_events(void) static DATA_PTR ptrClipboardData = NULL; -char* xvt_cb_alloc_data(long size) +char* xvt_cb_alloc_data(long size) { xvt_cb_free_data(); if (size > 0) @@ -1236,14 +1251,14 @@ char* xvt_cb_alloc_data(long size) return ptrClipboardData; } -BOOLEAN xvt_cb_close(void) -{ +BOOLEAN xvt_cb_close(void) +{ wxTheClipboard->Close(); - return TRUE; -} + return TRUE; +} -void xvt_cb_free_data(void) -{ +void xvt_cb_free_data(void) +{ if (ptrClipboardData != NULL) { xvt_mem_free(ptrClipboardData); @@ -1252,13 +1267,13 @@ void xvt_cb_free_data(void) } char* xvt_cb_get_data(CB_FORMAT cbfmt, char *name, long *sizep) -{ +{ if (xvt_cb_has_format(cbfmt, name)) { wxTextDataObject data; wxTheClipboard->GetData(data); *sizep = data.GetDataSize(); - if (*sizep > 0) + if (*sizep > 0) { xvt_cb_alloc_data(*sizep); memcpy(ptrClipboardData, data.GetText(), *sizep); @@ -1267,59 +1282,59 @@ char* xvt_cb_get_data(CB_FORMAT cbfmt, char *name, long *sizep) } } sizep = 0; - return NULL; + return NULL; } BOOLEAN xvt_cb_has_format(CB_FORMAT fmt, char *name) -{ +{ BOOLEAN ok = fmt == CB_TEXT && wxTheClipboard->IsSupported(wxDF_TEXT); - return ok; + return ok; } -BOOLEAN xvt_cb_open(BOOLEAN writing) -{ +BOOLEAN xvt_cb_open(BOOLEAN writing) +{ wxTheClipboard->Open(); - return TRUE; + return TRUE; } -BOOLEAN xvt_cb_put_data(CB_FORMAT cbfmt, char *name, long size, PICTURE pic) -{ +BOOLEAN xvt_cb_put_data(CB_FORMAT cbfmt, char *name, long size, PICTURE pic) +{ BOOLEAN ok = cbfmt == CB_TEXT && ptrClipboardData != NULL; if (ok) wxTheClipboard->SetData(new wxTextDataObject(ptrClipboardData)); - return ok; + return ok; } /////////////////////////////////////////////////////////// // Controls functions (NOT used) /////////////////////////////////////////////////////////// -void xvt_ctl_check_radio_button(WINDOW Win, WINDOW* Wins, int NbrWindows) +void xvt_ctl_check_radio_button(WINDOW Win, WINDOW* Wins, int NbrWindows) { SORRY_BOX(); } // Ignored -WINDOW xvt_ctl_create_def(WIN_DEF *win_def_p, WINDOW parent_win, long app_data) -{ +WINDOW xvt_ctl_create_def(WIN_DEF *win_def_p, WINDOW parent_win, long app_data) +{ WINDOW win = NULL_WIN; switch (win_def_p->wtype) { - case WC_HSCROLL: /* horizontal scrollbar control */ - case WC_VSCROLL: /* vertical scrollbar control */ + case WC_HSCROLL: /* horizontal scrollbar control */ + case WC_VSCROLL: /* vertical scrollbar control */ { const wxRect rct = NormalizeRCT(&win_def_p->rct); long style = win_def_p->wtype == WC_HSCROLL ? wxSB_HORIZONTAL : wxSB_VERTICAL; - wxScrollBar* sb = new wxScrollBar((wxWindow*)parent_win, - win_def_p->v.ctl.ctrl_id, + wxScrollBar* sb = new wxScrollBar((wxWindow*)parent_win, + win_def_p->v.ctl.ctrl_id, rct.GetPosition(), rct.GetSize(), style); win = (WINDOW)sb; } break; - default: + default: SORRY_BOX(); break; } return win; } -void xvt_ctl_set_checked(WINDOW Win, BOOLEAN Check) +void xvt_ctl_set_checked(WINDOW Win, BOOLEAN Check) { SORRY_BOX(); } // Ignored /////////////////////////////////////////////////////////// @@ -1327,7 +1342,7 @@ void xvt_ctl_set_checked(WINDOW Win, BOOLEAN Check) /////////////////////////////////////////////////////////// void xvt_debug_printf(const char* fmt, ...) -{ +{ #ifndef NDEBUG static FILE* f = NULL; if (f == NULL) @@ -1353,46 +1368,58 @@ BOOLEAN xvt_dongle_hl_crypt(unsigned short* data) // Array di 4 words (8 bytes) { #ifdef WIN32 return OsWin32_HL_Crypt(data); +#else + return OsLinux_HL_Crypt(data); #endif return FALSE; } -BOOLEAN xvt_dongle_hl_login(unsigned short address, const unsigned char* label, const unsigned char* password) +BOOLEAN xvt_dongle_hl_login(unsigned short address, const unsigned char* label, const unsigned char* password) { #ifdef WIN32 return OsWin32_HL_Login(address, label, password); +#else + return OsLinux_HL_Login(address, label, password); #endif return FALSE; } -BOOLEAN xvt_dongle_hl_logout() +BOOLEAN xvt_dongle_hl_logout() { #ifdef WIN32 return OsWin32_HL_Logout(); +#else + return OsLinux_HL_Logout(); #endif return TRUE; } -BOOLEAN xvt_dongle_hl_read(unsigned short reg, unsigned short* data) +BOOLEAN xvt_dongle_hl_read(unsigned short reg, unsigned short* data) { #ifdef WIN32 return OsWin32_HL_Read(reg, data); +#else + return OsLinux_HL_Read(reg, data); #endif return FALSE; } -BOOLEAN xvt_dongle_hl_read_block(unsigned char* data) +BOOLEAN xvt_dongle_hl_read_block(unsigned char* data) { #ifdef WIN32 return OsWin32_HL_ReadBlock(data); +#else + return OsLinux_HL_ReadBlock(data); #endif return FALSE; } -BOOLEAN xvt_dongle_hl_write(unsigned short reg, unsigned short data) +BOOLEAN xvt_dongle_hl_write(unsigned short reg, unsigned short data) { #ifdef WIN32 return OsWin32_HL_Write(reg, data); +#else + return OsLinux_HL_Write(reg, data); #endif return FALSE; } @@ -1401,6 +1428,8 @@ BOOLEAN xvt_dongle_sl_crypt(unsigned short* data) { #ifdef WIN32 return OsWin32_SL_Crypt(data); +#else + return OsLinux_SL_Crypt(data); #endif return FALSE; } @@ -1409,6 +1438,8 @@ BOOLEAN xvt_dongle_sl_login(const unsigned char* label, const unsigned char* pas { #ifdef WIN32 return OsWin32_SL_Login(label, password); +#else + return OsLinux_SL_Login(label, password); #endif return FALSE; } @@ -1417,6 +1448,8 @@ BOOLEAN xvt_dongle_sl_logout() { #ifdef WIN32 return OsWin32_SL_Logout(); +#else + return OsLinux_SL_Logout(); #endif return TRUE; } @@ -1425,6 +1458,8 @@ BOOLEAN xvt_dongle_sl_read_block(unsigned short reg, unsigned short size, unsign { #ifdef WIN32 return OsWin32_SL_ReadBlock(reg, size, data); +#else + return OsLinux_SL_ReadBlock(reg, size, data); #endif return FALSE; } @@ -1433,6 +1468,8 @@ BOOLEAN xvt_dongle_sl_write_block(unsigned short reg, unsigned short size, const { #ifdef WIN32 return OsWin32_SL_WriteBlock(reg, size, data); +#else + return OsLinux_SL_WriteBlock(reg, size, data); #endif return FALSE; } @@ -1444,7 +1481,7 @@ BOOLEAN xvt_dongle_sl_write_block(unsigned short reg, unsigned short size, const static wxString GetMainTitle() { wxString strTitle; - if (_task_win != NULL) + if (_task_win != NULL) { strTitle = _task_win->GetTitle(); const int space = strTitle.Find(" -"); @@ -1481,28 +1518,28 @@ COLOR xvt_dm_post_choose_color(WINDOW win, COLOR xc) return xc; } -ASK_RESPONSE xvt_dm_post_ask(const char* Btn1, const char*Btn2, const char* Btn3, const char* fmt) -{ +ASK_RESPONSE xvt_dm_post_ask(const char* Btn1, const char*Btn2, const char* Btn3, const char* fmt) +{ int nFlags = wxCENTRE | wxICON_QUESTION | wxYES_NO; if (Btn3 == NULL) { - if (stricmp(Btn1, "no") == 0) + if (wxStricmp(Btn1, "no") == 0) nFlags |= wxNO_DEFAULT; } else nFlags |= wxCANCEL; - - int answer = wxMessageBox(fmt, GetMainTitle(), nFlags); + + int answer = wxMessageBox(fmt, GetMainTitle(), nFlags); return answer == wxYES ? RESP_DEFAULT : (answer == wxNO ? RESP_2 : RESP_3); } -void xvt_dm_post_error(const char *fmt) -{ - wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_ERROR); +void xvt_dm_post_error(const char *fmt) +{ + wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_ERROR); } -void xvt_dm_post_fatal_exit(const char *fmt) -{ +void xvt_dm_post_fatal_exit(const char *fmt) +{ wxLogFatalError(fmt); } @@ -1518,7 +1555,7 @@ static wxString MakeFileName(const wxChar* name, const wxChar* ext) return f; } -static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags) +static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags) { wxString path = fsp->dir.path; wxString name = MakeFileName(fsp->name, fsp->type); @@ -1527,7 +1564,7 @@ static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags wxString selectedname = wxFileSelector(msg, path, name, extension , mask, flags); if (selectedname.IsEmpty()) - return FL_CANCEL; + return FL_CANCEL; wxFileName::SplitPath(selectedname, &path, &name, &extension); strcpy(fsp->dir.path, path); @@ -1537,22 +1574,22 @@ static FL_STATUS xvt_dm_post_file_ask(FILE_SPEC *fsp, const char *msg, int flags return FL_OK; } -FL_STATUS xvt_dm_post_file_open(FILE_SPEC *fsp, const char *msg) -{ +FL_STATUS xvt_dm_post_file_open(FILE_SPEC *fsp, const char *msg) +{ const int flags = wxOPEN | wxHIDE_READONLY | wxFILE_MUST_EXIST; return xvt_dm_post_file_ask(fsp, msg, flags); } -FL_STATUS xvt_dm_post_file_save(FILE_SPEC *fsp, const char *msg) -{ +FL_STATUS xvt_dm_post_file_save(FILE_SPEC *fsp, const char *msg) +{ const int flags = wxSAVE | wxHIDE_READONLY; return xvt_dm_post_file_ask(fsp, msg, flags); -} +} -BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD *precp, unsigned long reserved) -{ +BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD *precp, unsigned long reserved) +{ TFontId& font = *(TFontId*)font_id; - wxFontData data; + wxFontData data; data.SetInitialFont(font.Font(NULL)); data.EnableEffects(FALSE); wxFontDialog dlg(_task_win, &data); @@ -1566,30 +1603,30 @@ BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD *precp, un e.v.font.font_id = font_id; _task_win_handler(win, &e); } - return ok; + return ok; } -void xvt_dm_post_message(const char *fmt) -{ - wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_INFORMATION); +void xvt_dm_post_message(const char *fmt) +{ + wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_INFORMATION); } -void xvt_dm_post_note(const char *fmt) -{ - wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_EXCLAMATION); +void xvt_dm_post_note(const char *fmt) +{ + wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_EXCLAMATION); } -char* xvt_dm_post_string_prompt(const char* message, char* response, int response_len) -{ +char* xvt_dm_post_string_prompt(const char* message, char* response, int response_len) +{ XVT_ASSERT(message && response && response_len > 0); SORRY_BOX(); *response = '\0'; - return NULL; + return NULL; } -void xvt_dm_post_warning(const char *fmt) -{ - wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_EXCLAMATION); +void xvt_dm_post_warning(const char *fmt) +{ + wxMessageBox(fmt, GetMainTitle(), wxOK | wxCENTRE | wxICON_EXCLAMATION); } /////////////////////////////////////////////////////////// @@ -1627,11 +1664,11 @@ XVT_HELP_INFO xvt_help_open_helpfile(FILE_SPEC *fs, unsigned long flags) help_info.m_hlp = i == 2; if (!help_info.m_hlp) { - wxFileSystem::AddHandler(new wxZipFSHandler); + wxFileSystem::AddHandler(new wxZipFSHandler); help_info.m_hc.AddBook(strName, true); } return (XVT_HELP_INFO)&help_info; - } + } } } return NULL_HELP_INFO; @@ -1767,26 +1804,26 @@ bool TFontId::IsEqual(const TFontId& rFont) const return true; } -const char* TFontId::FaceName() const -{ +const char* TFontId::FaceName() const +{ if (m_strFace.IsEmpty()) return XVT_FFN_COURIER; - return m_strFace; + return m_strFace; } int TFontId::Family() const { - if (m_strFace.IsEmpty() || m_strFace == XVT_FFN_COURIER) - return wxMODERN; + if (m_strFace.IsEmpty() || m_strFace == XVT_FFN_COURIER) + return wxMODERN; if (m_strFace == XVT_FFN_HELVETICA) - return wxSWISS; + return wxSWISS; if (m_strFace == XVT_FFN_TIMES) return wxROMAN; if (m_strFace == XVT_FFN_FIXED) return wxMODERN; if (m_strFace == XVT_FFN_SYSTEM) - return wxDEFAULT; - return wxROMAN; + return wxDEFAULT; + return wxROMAN; } int TFontId::Style() const @@ -1833,7 +1870,7 @@ wxFont& TFontId::Font(wxDC* dc) const nMin = nScale; nBestSize = nFontSize; } - } + } dPrintScale = nBestSize / 12.0; lastDC = dc; } @@ -1865,8 +1902,8 @@ void TFontId::Copy(const wxFont& rFont) // Drawable windows /////////////////////////////////////////////////////////// -void xvt_dwin_clear(WINDOW win, COLOR col) -{ +void xvt_dwin_clear(WINDOW win, COLOR col) +{ CAST_DC(win, dc); CAST_COLOR(col, brush_color); wxBrush brush(brush_color, wxSOLID); @@ -1874,11 +1911,11 @@ void xvt_dwin_clear(WINDOW win, COLOR col) dc.Clear(); } -void xvt_dwin_draw_arc(WINDOW Win, RCT* r, int sx, int sy, int ex, int ey) +void xvt_dwin_draw_arc(WINDOW Win, RCT* r, int sx, int sy, int ex, int ey) { SORRY_BOX(); } -void xvt_dwin_draw_icon(WINDOW win, int x, int y, int rid) -{ +void xvt_dwin_draw_icon(WINDOW win, int x, int y, int rid) +{ wxIcon* ico = ::GetIconResource(rid); if (ico) { @@ -1887,8 +1924,8 @@ void xvt_dwin_draw_icon(WINDOW win, int x, int y, int rid) } } -void xvt_dwin_draw_image(WINDOW win, XVT_IMAGE image, RCT* dest, RCT* source) -{ +void xvt_dwin_draw_image(WINDOW win, XVT_IMAGE image, RCT* dest, RCT* source) +{ XVT_ASSERT(image != NULL); if (image) @@ -1904,11 +1941,15 @@ void xvt_dwin_draw_image(WINDOW win, XVT_IMAGE image, RCT* dest, RCT* source) else { #ifdef WIN32 - OsWin32_DrawBitmap(bmp.GetHBITMAP(), dc.GetHDC(), + OsWin32_DrawBitmap(bmp.GetHBITMAP(), dc.GetHDC(), dst.x, dst.y, dst.width, dst.height, src.x, src.y, src.width, src.height); #else - SORRY_BOX(); + const wxImage& img = ((const TXVT_IMAGE*)image)->Image(); + wxImage sub = img.GetSubImage(src); + + sub.Rescale(dst.width, dst.height); + dc.DrawBitmap(sub.ConvertToBitmap(), dst.GetPosition()); #endif } } @@ -1918,15 +1959,15 @@ void xvt_dwin_draw_oval(WINDOW Win, RCT* r) { SORRY_BOX(); } void xvt_dwin_draw_pie(WINDOW win, RCT *rctp, int start_x, int start_y, int stop_x, int stop_y) { SORRY_BOX(); } void xvt_dwin_draw_polygon(WINDOW win, PNT *lpnts, int npnts) { SORRY_BOX(); } -void xvt_dwin_draw_rect(WINDOW win, RCT *rctp) -{ +void xvt_dwin_draw_rect(WINDOW win, RCT *rctp) +{ CAST_DC(win, dc); const wxRect rct = NormalizeRCT(rctp); dc.DrawRectangle(rct); } -void xvt_dwin_draw_dotted_rect(WINDOW win, RCT *rctp) -{ +void xvt_dwin_draw_dotted_rect(WINDOW win, RCT *rctp) +{ #ifdef WIN32 CAST_DC(win, dc); OsWin32_DrawDottedRect(dc.GetHDC(), rctp->left, rctp->top, rctp->right, rctp->bottom); @@ -1947,20 +1988,20 @@ void xvt_dwin_draw_dotted_rect(WINDOW win, RCT *rctp) xvt_dwin_set_cbrush(win, &brush); xvt_dwin_draw_rect(win, rctp); - + xvt_dwin_set_draw_ctools(win, &dct); #endif } -void xvt_dwin_draw_set_pos(WINDOW win, PNT pnt) -{ +void xvt_dwin_draw_set_pos(WINDOW win, PNT pnt) +{ CAST_TDC(win, dc); dc._pnt.x = pnt.h; dc._pnt.y = pnt.v; } -void xvt_dwin_draw_text(WINDOW win, int x, int y, const char *s, int len) -{ +void xvt_dwin_draw_text(WINDOW win, int x, int y, const char *s, int len) +{ if (s && *s && len != 0) { /* @@ -1991,29 +2032,29 @@ void xvt_dwin_draw_text(WINDOW win, int x, int y, const char *s, int len) } } -RCT* xvt_dwin_get_clip(WINDOW win, RCT* rct) -{ +RCT* xvt_dwin_get_clip(WINDOW win, RCT* rct) +{ CAST_TDC(win, dc); dc.GetClippingBox(rct); - return rct; + return rct; } -DRAW_CTOOLS* xvt_dwin_get_draw_ctools(WINDOW win, DRAW_CTOOLS *ctoolsp) -{ +DRAW_CTOOLS* xvt_dwin_get_draw_ctools(WINDOW win, DRAW_CTOOLS *ctoolsp) +{ CAST_TDC(win, dc); memcpy(ctoolsp, &dc._dct, sizeof(DRAW_CTOOLS)); - return ctoolsp; + return ctoolsp; } -XVT_FNTID xvt_dwin_get_font(WINDOW win) -{ +XVT_FNTID xvt_dwin_get_font(WINDOW win) +{ CAST_TDC(win, dc); TFontId* pFont = new TFontId(dc._font); return pFont; } -void xvt_dwin_get_font_metrics(WINDOW win, int *leadingp, int *ascentp, int *descentp) -{ +void xvt_dwin_get_font_metrics(WINDOW win, int *leadingp, int *ascentp, int *descentp) +{ CAST_DC(win, dc); const wxString str = "Mq"; int height, desc, lead; @@ -2027,23 +2068,23 @@ void xvt_dwin_get_font_metrics(WINDOW win, int *leadingp, int *ascentp, int *des *descentp = desc; } -long xvt_dwin_get_font_size_mapped(WINDOW win) -{ +long xvt_dwin_get_font_size_mapped(WINDOW win) +{ CAST_WIN(win, dc); const wxFont& font = dc.GetFont(); int height = font.GetPointSize(); return height; -} +} int xvt_dwin_get_text_width(WINDOW win, const char *s, int len) -{ +{ int width = 0, height; - + if (s && *s && len != 0) { CAST_DC(win, dc); wxString str = s; - if (len >= 0) + if (len >= 0) str.Truncate(len); if (str.StartsWith("ABCDEFGH") || str.StartsWith("MMMMMMMM")) { @@ -2053,11 +2094,11 @@ int xvt_dwin_get_text_width(WINDOW win, const char *s, int len) dc.GetTextExtent(str, &width, &height); } - return width; -} + return width; +} -void xvt_dwin_invalidate_rect(WINDOW win, RCT* rctp) -{ +void xvt_dwin_invalidate_rect(WINDOW win, RCT* rctp) +{ CAST_WIN(win, w); CAST_TDC(win, dc); if (rctp) @@ -2071,20 +2112,20 @@ void xvt_dwin_invalidate_rect(WINDOW win, RCT* rctp) } } -BOOLEAN xvt_dwin_is_update_needed(WINDOW win, RCT* rctp) -{ +BOOLEAN xvt_dwin_is_update_needed(WINDOW win, RCT* rctp) +{ if (rctp != NULL) { - CAST_WIN(win, w); + CAST_WIN(win, w); const wxRect rect1 = NormalizeRCT(rctp); const wxRect rect2 = w.GetUpdateRegion().GetBox(); return RectIntersect(rect1, rect2); } - return FALSE; + return FALSE; } -void xvt_dwin_scroll_rect(WINDOW win, RCT *rctp, int dh, int dv) -{ +void xvt_dwin_scroll_rect(WINDOW win, RCT *rctp, int dh, int dv) +{ if (dh != 0 || dv != 0) { CAST_WIN(win, w); @@ -2099,49 +2140,49 @@ void xvt_dwin_scroll_rect(WINDOW win, RCT *rctp, int dh, int dv) } } -void xvt_dwin_set_back_color(WINDOW win, COLOR color) -{ +void xvt_dwin_set_back_color(WINDOW win, COLOR color) +{ CAST_TDC(win, dc); dc._dct.back_color = color; dc.SetDirty(); } -void xvt_dwin_set_cbrush(WINDOW win, CBRUSH* cbrush) -{ +void xvt_dwin_set_cbrush(WINDOW win, CBRUSH* cbrush) +{ CAST_TDC(win, dc); memcpy(&dc._dct.brush, cbrush, sizeof(CBRUSH)); dc.SetDirty(); } -void xvt_dwin_set_clip(WINDOW win, RCT* rctp) -{ +void xvt_dwin_set_clip(WINDOW win, RCT* rctp) +{ CAST_TDC(win, dc); dc.SetClippingBox(rctp); } -void xvt_dwin_set_cpen(WINDOW win, CPEN* cpen) +void xvt_dwin_set_cpen(WINDOW win, CPEN* cpen) { CAST_TDC(win, dc); memcpy(&dc._dct.pen, cpen, sizeof(CPEN)); dc.SetDirty(); } -void xvt_dwin_set_draw_ctools(WINDOW win, DRAW_CTOOLS* xct) -{ +void xvt_dwin_set_draw_ctools(WINDOW win, DRAW_CTOOLS* xct) +{ CAST_TDC(win, dc); memcpy(&dc._dct, xct, sizeof(DRAW_CTOOLS)); dc.SetDirty(); } -void xvt_dwin_set_draw_mode(WINDOW win, DRAW_MODE mode) -{ +void xvt_dwin_set_draw_mode(WINDOW win, DRAW_MODE mode) +{ CAST_TDC(win, dc); dc._dct.mode = mode; dc.SetDirty(); } -void xvt_dwin_set_font(WINDOW win, XVT_FNTID font_id) -{ +void xvt_dwin_set_font(WINDOW win, XVT_FNTID font_id) +{ XVT_ASSERT(font_id != NULL); CAST_TDC(win, dc); const TFontId& font = *(const TFontId*)font_id; @@ -2152,15 +2193,15 @@ void xvt_dwin_set_font(WINDOW win, XVT_FNTID font_id) } } -void xvt_dwin_set_fore_color(WINDOW win, COLOR color) -{ +void xvt_dwin_set_fore_color(WINDOW win, COLOR color) +{ CAST_TDC(win, dc); dc._dct.fore_color = color; dc.SetDirty(); } -void xvt_dwin_set_std_cpen(WINDOW win, long flag) -{ +void xvt_dwin_set_std_cpen(WINDOW win, long flag) +{ CAST_TDC(win, dc); CPEN pen; memset(&pen, 0, sizeof(CPEN)); pen.style = P_SOLID; @@ -2176,8 +2217,8 @@ void xvt_dwin_set_std_cpen(WINDOW win, long flag) xvt_dwin_set_cpen(win, &pen); } -void xvt_dwin_draw_line(WINDOW win, PNT pnt) -{ +void xvt_dwin_draw_line(WINDOW win, PNT pnt) +{ CAST_TDC(win, dc); const wxPoint to(pnt.h, pnt.v); if (dc._pnt != to) @@ -2186,12 +2227,14 @@ void xvt_dwin_draw_line(WINDOW win, PNT pnt) dc._pnt = to; } -void xvt_dwin_update(WINDOW win) -{ +void xvt_dwin_update(WINDOW win) +{ // "sembra" che non serva ad un fico secco, ma FORSE in Windows serve! #ifdef WIN32 CAST_TWIN(win, w); - OsWin32_UpdateWindow(w.GetHWND()); + OsWin32_UpdateWindow(w.GetHWND()); +#else + OsLinux_UpdateWindow(win); #endif } @@ -2199,16 +2242,16 @@ void xvt_dwin_update(WINDOW win) // Debug functions /////////////////////////////////////////////////////////// -XVT_ERRSEV xvt_errmsg_get_sev_id(XVT_ERRMSG err) -{ - return (XVT_ERRSEV)err; +XVT_ERRSEV xvt_errmsg_get_sev_id(XVT_ERRMSG err) +{ + return (XVT_ERRSEV)err; } /////////////////////////////////////////////////////////// // Fonts /////////////////////////////////////////////////////////// -void xvt_font_copy(XVT_FNTID dest_font_id, XVT_FNTID src_font_id, XVT_FONT_ATTR_MASK mask) +void xvt_font_copy(XVT_FNTID dest_font_id, XVT_FNTID src_font_id, XVT_FONT_ATTR_MASK mask) { XVT_ASSERT(dest_font_id && src_font_id && mask == XVT_FA_ALL); TFontId* dst = (TFontId*)dest_font_id; @@ -2216,19 +2259,19 @@ void xvt_font_copy(XVT_FNTID dest_font_id, XVT_FNTID src_font_id, XVT_FONT_ATTR_ *dst = *src; } -XVT_FNTID xvt_font_create(void) -{ +XVT_FNTID xvt_font_create(void) +{ TFontId* pFont = new TFontId; - return (XVT_FNTID)pFont; + return (XVT_FNTID)pFont; } -void xvt_font_deserialize(XVT_FNTID font_id, char *buf) -{ +void xvt_font_deserialize(XVT_FNTID font_id, char *buf) +{ // 01\\Courier\\0\\10\\WIN01/-13/0/0/0/400/0/0/0/0/1/2/1/49/Courier TFontId& font = *(TFontId*)font_id; char* s = strchr(buf, '/'); - if (s == NULL) + if (s == NULL) return; const int nSize = atoi(s+1); if (nSize > 0) @@ -2237,10 +2280,11 @@ void xvt_font_deserialize(XVT_FNTID font_id, char *buf) font.SetPointSize(-nSize * 10 / 13); // Ignore 4 fields - for (int i = 0; i < 4; i++) + int i; + for (i = 0; i < 4; i++) { s = strchr(s+1, '/'); - if (s == NULL) + if (s == NULL) return; } s++; @@ -2249,7 +2293,7 @@ void xvt_font_deserialize(XVT_FNTID font_id, char *buf) font.SetMask(font.Mask() | XVT_FS_BOLD); s = strchr(s, '/'); - if (s == NULL) + if (s == NULL) return; const int nItalic = atoi(s+1); if (nItalic) @@ -2259,7 +2303,7 @@ void xvt_font_deserialize(XVT_FNTID font_id, char *buf) for (i = 0; i < 8; i++) { s = strchr(s+1, '/'); - if (s == NULL) + if (s == NULL) return; } @@ -2267,24 +2311,24 @@ void xvt_font_deserialize(XVT_FNTID font_id, char *buf) font.SetWin(NULL_WIN); } -void xvt_font_destroy(XVT_FNTID font_id) -{ +void xvt_font_destroy(XVT_FNTID font_id) +{ delete (TFontId*)font_id; } -BOOLEAN xvt_font_get_family(XVT_FNTID font_id, char* buf, long max_buf) -{ +BOOLEAN xvt_font_get_family(XVT_FNTID font_id, char* buf, long max_buf) +{ const TFontId& font = *(TFontId*)font_id; - strncpy(buf, font.FaceName(), max_buf); + strncpy(buf, font.FaceName(), max_buf); buf[max_buf-1] = '\0'; - return TRUE; + return TRUE; } -BOOLEAN xvt_font_get_family_mapped(XVT_FNTID font_id, char* buf, long max_buf) +BOOLEAN xvt_font_get_family_mapped(XVT_FNTID font_id, char* buf, long max_buf) { return xvt_font_get_family(font_id, buf, max_buf); } -void xvt_font_get_metrics(XVT_FNTID font_id, int *leadingp, int *ascentp, int *descentp) -{ +void xvt_font_get_metrics(XVT_FNTID font_id, int *leadingp, int *ascentp, int *descentp) +{ const TFontId& font = *(TFontId*)font_id; WINDOW win = font.Win(); if (win == NULL_WIN) @@ -2301,64 +2345,64 @@ void xvt_font_get_metrics(XVT_FNTID font_id, int *leadingp, int *ascentp, int *d *descentp = desc; } -BOOLEAN xvt_font_get_native_desc(XVT_FNTID font_id, char *buf, long max_buf) -{ +BOOLEAN xvt_font_get_native_desc(XVT_FNTID font_id, char *buf, long max_buf) +{ long len = xvt_font_serialize(font_id, buf, max_buf); - return len > 0; + return len > 0; } -long xvt_font_get_size(XVT_FNTID font_id) -{ +long xvt_font_get_size(XVT_FNTID font_id) +{ return ((TFontId*)font_id)->PointSize(); } -XVT_FONT_STYLE_MASK xvt_font_get_style(XVT_FNTID font_id) -{ +XVT_FONT_STYLE_MASK xvt_font_get_style(XVT_FNTID font_id) +{ return ((TFontId*)font_id)->Mask(); } -WINDOW xvt_font_get_win(XVT_FNTID font_id) -{ +WINDOW xvt_font_get_win(XVT_FNTID font_id) +{ return ((TFontId*)font_id)->Win(); } -BOOLEAN xvt_font_is_mapped(XVT_FNTID font_id) -{ +BOOLEAN xvt_font_is_mapped(XVT_FNTID font_id) +{ bool yes = ((TFontId*)font_id)->Win() != NULL_WIN; return yes; } -void xvt_font_map(XVT_FNTID font_id, WINDOW win) -{ +void xvt_font_map(XVT_FNTID font_id, WINDOW win) +{ TFontId* pFont = (TFontId*)font_id; pFont->SetWin(win); } -void xvt_font_map_using_default(XVT_FNTID font_id) -{ +void xvt_font_map_using_default(XVT_FNTID font_id) +{ xvt_font_map(font_id, TASK_WIN); } -void xvt_font_set_family(XVT_FNTID font_id, char* family) -{ +void xvt_font_set_family(XVT_FNTID font_id, char* family) +{ TFontId& font = *(TFontId*)font_id; font.SetFaceName(family); } -void xvt_font_set_size(XVT_FNTID font_id, long size) -{ +void xvt_font_set_size(XVT_FNTID font_id, long size) +{ TFontId& font = *(TFontId*)font_id; font.SetPointSize(size); } -void xvt_font_set_style(XVT_FNTID font_id, XVT_FONT_STYLE_MASK mask) -{ +void xvt_font_set_style(XVT_FNTID font_id, XVT_FONT_STYLE_MASK mask) +{ TFontId& font = *(TFontId*)font_id; font.SetMask(mask); } -long xvt_font_serialize(XVT_FNTID font_id, char *buf, long max_buf) -{ +long xvt_font_serialize(XVT_FNTID font_id, char *buf, long max_buf) +{ // 01\\Courier\\0\\10\\WIN01/-13/0/0/0/400/0/0/0/0/1/2/1/49/Courier TFontId& font = *(TFontId*)font_id; @@ -2373,11 +2417,11 @@ long xvt_font_serialize(XVT_FNTID font_id, char *buf, long max_buf) strncpy(buf, str, max_buf); buf[max_buf-1] = '\0'; - return strlen(buf); + return strlen(buf); } -void xvt_font_unmap(XVT_FNTID font_id) -{ +void xvt_font_unmap(XVT_FNTID font_id) +{ TFontId& font = *(TFontId*)font_id; font.SetWin(NULL_WIN); } @@ -2391,7 +2435,7 @@ BOOLEAN xvt_fsys_build_pathname(char *mbs, const char *volname, const char *dirn #ifdef WIN32 _makepath(mbs, volname, dirname, leafroot, leafext); #else - *msb = '\0'; + *mbs = '\0'; if (dirname && *dirname) strcpy(mbs, dirname); if (leafroot && *leafroot) @@ -2407,7 +2451,6 @@ BOOLEAN xvt_fsys_build_pathname(char *mbs, const char *volname, const char *dirn strcat(mbs, leafext); } #endif - return TRUE; } @@ -2423,15 +2466,15 @@ BOOLEAN xvt_fsys_parse_pathname(const char *mbs, char *volname, char *dirname, c return TRUE; } -BOOLEAN xvt_fsys_convert_dir_to_str(DIRECTORY *dirp, char *path, int sz_path) -{ +BOOLEAN xvt_fsys_convert_dir_to_str(DIRECTORY *dirp, char *path, int sz_path) +{ wxStrncpy(path, dirp->path, sz_path); path[sz_path-1] = '\0'; return TRUE; } -BOOLEAN xvt_fsys_convert_str_to_dir(const char *path, DIRECTORY *dirp) -{ +BOOLEAN xvt_fsys_convert_str_to_dir(const char *path, DIRECTORY *dirp) +{ strcpy(dirp->path, path); return TRUE; } @@ -2441,60 +2484,66 @@ void xvt_fsys_get_default_dir(DIRECTORY *dirp) xvt_fsys_convert_str_to_dir(_startup_dir, dirp); } -BOOLEAN xvt_fsys_get_dir(DIRECTORY *dirp) -{ +BOOLEAN xvt_fsys_get_dir(DIRECTORY *dirp) +{ wxString str = ::wxGetCwd(); return xvt_fsys_convert_str_to_dir(str, dirp); } BOOLEAN xvt_fsys_is_removable_drive(const char* path) -{ +{ #ifdef WIN32 return GetDriveType(path) == DRIVE_REMOVABLE; +#else + char dev[_MAX_PATH]; + + OsLinux_GetFileSys(path, dev, NULL, NULL); + return strncmp(dev, "/dev/fd", 7) == 0; #endif - return FALSE; } BOOLEAN xvt_fsys_is_network_drive(const char* path) { #ifdef WIN32 return GetDriveType(path) == DRIVE_REMOTE; +#else + return OsLinux_IsNetworkDrive(path); #endif - return FALSE; } BOOLEAN xvt_fsys_is_fixed_drive(const char* path) { #ifdef WIN32 return GetDriveType(path) == DRIVE_FIXED; +#else + return !(xvt_fsys_is_network_drive(path) || xvt_fsys_is_removable_drive(path)); #endif - return TRUE; } static unsigned long compute_disk_size(const char* path, bool tot, char unit) { #ifdef WIN32 char drive[_MAX_DRIVE+1]; - _splitpath(path, drive, NULL, NULL, NULL); + xvt_sys_splitpath(path, drive, NULL, NULL, NULL); strcat(drive, "/"); DWORD nSecPerClust, nBytePerSec, nFreeClust, nTotalClust; ::GetDiskFreeSpace(drive, &nSecPerClust, &nBytePerSec, &nFreeClust, &nTotalClust); __int64 nBytes = tot ? nTotalClust : nFreeClust; nBytes *= nSecPerClust; nBytes *= nBytePerSec; -#else - unsigned long nBytes = 1024*1024; - if (!xvt_fsys_is_removable_drive(path)) - nBytes *= 1024; -#endif +#else + int64_t nBytes = OsLinux_GetDiskFreeSpace(path); +#endif + switch (unit) { case 'K': nBytes >>= 10; break; // Kilobytes case 'M': nBytes >>= 20; break; // Megabytes case 'G': nBytes >>= 30; break; // Gigabytes case 'T': nBytes >>= 40; break; // Terabytes - default: break; + default: + break; } const unsigned long nMax = (unsigned long)(~0L); @@ -2523,8 +2572,8 @@ BOOLEAN xvt_fsys_test_disk_free_space(const char* path, unsigned long filesize) // File system /////////////////////////////////////////////////////////// -SLIST xvt_fsys_list_files(char *type, char *pat, BOOLEAN dirs) -{ +SLIST xvt_fsys_list_files(char *type, char *pat, BOOLEAN dirs) +{ SLIST list = xvt_slist_create(); int flags = 0; @@ -2546,23 +2595,23 @@ SLIST xvt_fsys_list_files(char *type, char *pat, BOOLEAN dirs) f = ::wxFindNextFile(); } - return list; + return list; } static wxString _strSavedir; -void xvt_fsys_restore_dir() -{ +void xvt_fsys_restore_dir() +{ ::wxSetWorkingDirectory(_strSavedir); } -void xvt_fsys_save_dir() -{ +void xvt_fsys_save_dir() +{ _strSavedir = ::wxGetCwd(); } -BOOLEAN xvt_fsys_set_dir(DIRECTORY *dirp) -{ +BOOLEAN xvt_fsys_set_dir(DIRECTORY *dirp) +{ return ::wxSetWorkingDirectory(dirp->path); } @@ -2570,20 +2619,20 @@ BOOLEAN xvt_fsys_set_dir(DIRECTORY *dirp) // Images /////////////////////////////////////////////////////////// -XVT_IMAGE xvt_image_create(XVT_IMAGE_FORMAT format, short width, short height, long reserved) -{ +XVT_IMAGE xvt_image_create(XVT_IMAGE_FORMAT format, short width, short height, long reserved) +{ TXVT_IMAGE* i = new TXVT_IMAGE; i->Image().Create(width, height); return (XVT_IMAGE)i; } -void xvt_image_destroy(XVT_IMAGE image) -{ +void xvt_image_destroy(XVT_IMAGE image) +{ delete (TXVT_IMAGE*)image; } -COLOR xvt_image_get_clut(XVT_IMAGE image, short index) -{ +COLOR xvt_image_get_clut(XVT_IMAGE image, short index) +{ XVT_ASSERT(image != NULL); #if wxCHECK_VERSION(2,3,0) if (image) @@ -2598,11 +2647,11 @@ COLOR xvt_image_get_clut(XVT_IMAGE image, short index) } } #endif - return COLOR_BLACK; + return COLOR_BLACK; } -void xvt_image_get_dimensions(XVT_IMAGE image, short *width, short *height) -{ +void xvt_image_get_dimensions(XVT_IMAGE image, short *width, short *height) +{ const wxImage& img = ((const TXVT_IMAGE*)image)->Image(); if (img.Ok()) { @@ -2617,18 +2666,18 @@ void xvt_image_get_dimensions(XVT_IMAGE image, short *width, short *height) } } -XVT_IMAGE_FORMAT xvt_image_get_format(XVT_IMAGE image) -{ +XVT_IMAGE_FORMAT xvt_image_get_format(XVT_IMAGE image) +{ #if wxCHECK_VERSION(2,3,0) const wxImage& img = ((const TXVT_IMAGE*)image)->Image(); - return img.HasPalette() ? XVT_IMAGE_CL8 : XVT_IMAGE_RGB; + return img.HasPalette() ? XVT_IMAGE_CL8 : XVT_IMAGE_RGB; #else return XVT_IMAGE_RGB; #endif } -short xvt_image_get_ncolors(XVT_IMAGE image) -{ +short xvt_image_get_ncolors(XVT_IMAGE image) +{ #if wxCHECK_VERSION(2,3,0) int n = 0; if (image) @@ -2645,7 +2694,7 @@ short xvt_image_get_ncolors(XVT_IMAGE image) } } } - return n; + return n; #else int n = 0; if (image) @@ -2653,12 +2702,12 @@ short xvt_image_get_ncolors(XVT_IMAGE image) wxImage& bmp = ((TXVT_IMAGE*)image)->Image(); n = bmp.CountColours(257); } - return n > 256 ? 0 : n; + return n > 256 ? 0 : n; #endif } -COLOR xvt_image_get_pixel(XVT_IMAGE image, short x, short y) -{ +COLOR xvt_image_get_pixel(XVT_IMAGE image, short x, short y) +{ const wxImage& bmp = ((const TXVT_IMAGE*)image)->Image(); int r = bmp.GetRed(x, y); int g = bmp.GetGreen(x, y); @@ -2666,8 +2715,8 @@ COLOR xvt_image_get_pixel(XVT_IMAGE image, short x, short y) return MAKE_COLOR(r, g, b); } -XVT_IMAGE xvt_image_read(const char* filenamep) -{ +XVT_IMAGE xvt_image_read(const char* filenamep) +{ TXVT_IMAGE* i = NULL; const wxString name = filenamep; if (::wxFileExists(name)) @@ -2683,13 +2732,13 @@ XVT_IMAGE xvt_image_read(const char* filenamep) return (XVT_IMAGE)i; } -XVT_IMAGE xvt_image_read_bmp(const char *filenamep) -{ +XVT_IMAGE xvt_image_read_bmp(const char *filenamep) +{ return xvt_image_read(filenamep); // Very clever! } -void xvt_image_set_clut(XVT_IMAGE image, short index, COLOR color) -{ +void xvt_image_set_clut(XVT_IMAGE image, short index, COLOR color) +{ wxImage& bmp = ((TXVT_IMAGE*)image)->Image(); #if wxCHECK_VERSION(2,3,0) if (bmp.HasPalette()) @@ -2716,26 +2765,26 @@ void xvt_image_set_clut(XVT_IMAGE image, short index, COLOR color) #endif } -void xvt_image_set_ncolors(XVT_IMAGE image, short ncolors) -{ -// SORRY_BOX(); +void xvt_image_set_ncolors(XVT_IMAGE image, short ncolors) +{ +// SORRY_BOX(); } -void xvt_image_set_pixel(XVT_IMAGE image, short x, short y, COLOR color) -{ +void xvt_image_set_pixel(XVT_IMAGE image, short x, short y, COLOR color) +{ wxImage& bmp = ((TXVT_IMAGE*)image)->Image(); CAST_COLOR (color, c); bmp.SetRGB(x, y, c.Red(), c.Green(), c.Blue()); } -void xvt_image_transfer(XVT_IMAGE dstimage, XVT_IMAGE srcimage, RCT *dstrctp, RCT *srcrctp) +void xvt_image_transfer(XVT_IMAGE dstimage, XVT_IMAGE srcimage, RCT *dstrctp, RCT *srcrctp) { wxImage& dst = ((TXVT_IMAGE*)dstimage)->Image(); const wxImage& src = ((const TXVT_IMAGE*)srcimage)->Image(); const wxRect rctDst = NormalizeRCT(dstrctp); - const wxRect rctSrc = NormalizeRCT(srcrctp); + const wxRect rctSrc = NormalizeRCT(srcrctp); - wxImage sub = src.GetSubImage(NormalizeRCT(srcrctp)); + wxImage sub = src.GetSubImage(rctSrc); sub.Rescale(rctDst.width, rctDst.height); if (rctDst.x == 0 && rctDst.y == 0) dst = sub; @@ -2747,22 +2796,22 @@ void xvt_image_transfer(XVT_IMAGE dstimage, XVT_IMAGE srcimage, RCT *dstrctp, RC // Memory management /////////////////////////////////////////////////////////// -DATA_PTR xvt_mem_alloc(size_t size) -{ +DATA_PTR xvt_mem_alloc(size_t size) +{ DATA_PTR ptr = (DATA_PTR)malloc(size); - return ptr; + return ptr; } -void xvt_mem_free(DATA_PTR p) +void xvt_mem_free(DATA_PTR p) { free(p); } -DATA_PTR xvt_mem_realloc(DATA_PTR p, size_t size) +DATA_PTR xvt_mem_realloc(DATA_PTR p, size_t size) { return (DATA_PTR)realloc(p, size); } -DATA_PTR xvt_mem_rep(DATA_PTR dst, DATA_PTR src, unsigned int srclen, long reps) -{ +DATA_PTR xvt_mem_rep(DATA_PTR dst, DATA_PTR src, unsigned int srclen, long reps) +{ XVT_ASSERT(dst != NULL || src != NULL); - + if (srclen == 1) memset(dst, *src, reps); else @@ -2773,8 +2822,8 @@ DATA_PTR xvt_mem_rep(DATA_PTR dst, DATA_PTR src, unsigned int srclen, long reps) return dst; } -DATA_PTR xvt_mem_zalloc(size_t size) -{ +DATA_PTR xvt_mem_zalloc(size_t size) +{ DATA_PTR ptr = xvt_mem_alloc(size); memset(ptr, 0, size); return ptr; @@ -2786,7 +2835,9 @@ DATA_PTR xvt_mem_zalloc(size_t size) int xvt_menu_count(const MENU_ITEM* m) { - for (int n = 0; m[n].tag != 0; n++); + int n; + + for (n = 0; m[n].tag != 0; n++); return n; } @@ -2809,8 +2860,8 @@ MENU_ITEM* xvt_menu_duplicate_tree(const MENU_ITEM* m) return TheMenu; } -MENU_ITEM* xvt_menu_get_tree(WINDOW win) -{ +MENU_ITEM* xvt_menu_get_tree(WINDOW win) +{ MENU_ITEM* m = NULL; if (win == TASK_WIN) { @@ -2825,7 +2876,7 @@ MENU_ITEM* xvt_menu_get_tree(WINDOW win) return m; } -static TranslateMenu(wxMenu* pMenu, TRANSLATE_CALLBACK tc) +static void TranslateMenu(wxMenu* pMenu, TRANSLATE_CALLBACK tc) { wxMenuItemList& list = pMenu->GetMenuItems(); for (unsigned i = 0; i < list.GetCount(); i++) @@ -2856,7 +2907,7 @@ void xvt_menu_translate_tree(WINDOW win, TRANSLATE_CALLBACK tc) const char* ita = pMenuBar->GetLabelTop(m); const char* eng = tc(ita); pMenuBar->SetLabelTop(m, eng); - + wxMenu* pMenu = pMenuBar->GetMenu(m); TranslateMenu(pMenu, tc); } @@ -2864,7 +2915,7 @@ void xvt_menu_translate_tree(WINDOW win, TRANSLATE_CALLBACK tc) } } -void xvt_menu_set_font_sel(WINDOW win, XVT_FNTID font_id) +void xvt_menu_set_font_sel(WINDOW win, XVT_FNTID font_id) { /* Ignored */ } static wxMenuItem* GetXvtMenuItem(WINDOW /* win */, MENU_TAG tag) @@ -2874,28 +2925,28 @@ static wxMenuItem* GetXvtMenuItem(WINDOW /* win */, MENU_TAG tag) return item; } -void xvt_menu_set_item_checked(WINDOW win, MENU_TAG tag, BOOLEAN check) -{ +void xvt_menu_set_item_checked(WINDOW win, MENU_TAG tag, BOOLEAN check) +{ wxMenuItem* item = GetXvtMenuItem(win, tag); if (item) item->Check(check != 0); } -void xvt_menu_set_item_enabled(WINDOW win, MENU_TAG tag, BOOLEAN enable) -{ +void xvt_menu_set_item_enabled(WINDOW win, MENU_TAG tag, BOOLEAN enable) +{ wxMenuItem* item = GetXvtMenuItem(win, tag); if (item) item->Enable(enable != 0); } -void xvt_menu_set_item_title(WINDOW win, MENU_TAG tag, char* text) -{ +void xvt_menu_set_item_title(WINDOW win, MENU_TAG tag, char* text) +{ wxMenuItem* item = GetXvtMenuItem(win, tag); if (item) item->SetText(text); } -void xvt_menu_set_tree(WINDOW win, MENU_ITEM* tree) +void xvt_menu_set_tree(WINDOW win, MENU_ITEM* tree) { if (win == TASK_WIN) { @@ -2909,8 +2960,8 @@ void xvt_menu_set_tree(WINDOW win, MENU_ITEM* tree) } } -void xvt_menu_update(WINDOW win) -{ +void xvt_menu_update(WINDOW win) +{ wxMenuBar* bar = ((TTaskWin*)_task_win)->GetMenuBar(); if (bar) bar->Refresh(); @@ -2942,13 +2993,13 @@ int xvt_rect_get_width(RCT *rctp) return rctp->right - rctp->left; } -BOOLEAN xvt_rect_has_point(RCT *rctp, PNT pnt) -{ +BOOLEAN xvt_rect_has_point(RCT *rctp, PNT pnt) +{ const wxRect rct = NormalizeRCT(rctp); return rct.Inside(pnt.h, pnt.v); } -BOOLEAN xvt_rect_intersect(RCT *drctp, RCT *rctp1, RCT *rctp2) +BOOLEAN xvt_rect_intersect(RCT *drctp, RCT *rctp1, RCT *rctp2) { const wxRect rect1 = NormalizeRCT(rctp1); const wxRect rect2 = NormalizeRCT(rctp2); @@ -2968,8 +3019,8 @@ BOOLEAN xvt_rect_is_empty(const RCT *rct) return rct == NULL || (rct->left==rct->right && rct->top==rct->bottom); } -void xvt_rect_offset(RCT *rctp, short dh, short dv) -{ +void xvt_rect_offset(RCT *rctp, short dh, short dv) +{ XVT_ASSERT(rctp != NULL); rctp->left += dh; rctp->top += dv; @@ -2977,8 +3028,8 @@ void xvt_rect_offset(RCT *rctp, short dh, short dv) rctp->bottom += dv; } -void xvt_rect_set(RCT *rctp, short left, short top, short right, short bottom) -{ +void xvt_rect_set(RCT *rctp, short left, short top, short right, short bottom) +{ XVT_ASSERT(rctp != NULL); rctp->left = left; rctp->top = top; @@ -2986,15 +3037,15 @@ void xvt_rect_set(RCT *rctp, short left, short top, short right, short bottom) rctp->bottom = bottom; } -void xvt_rect_set_empty(RCT *rctp) -{ +void xvt_rect_set_empty(RCT *rctp) +{ XVT_ASSERT(rctp != NULL); rctp->right = rctp->left; rctp->bottom = rctp->top; } -BOOLEAN xvt_rect_set_pos(RCT *rctp, PNT pos) -{ +BOOLEAN xvt_rect_set_pos(RCT *rctp, PNT pos) +{ BOOLEAN ok = rctp != NULL; if (ok) { @@ -3012,8 +3063,8 @@ BOOLEAN xvt_rect_set_pos(RCT *rctp, PNT pos) // Resource management /////////////////////////////////////////////////////////// -void xvt_res_free_menu_tree(MENU_ITEM* tree) -{ +void xvt_res_free_menu_tree(MENU_ITEM* tree) +{ XVT_ASSERT(tree != NULL); if (tree != NULL) { @@ -3028,8 +3079,8 @@ void xvt_res_free_menu_tree(MENU_ITEM* tree) } } -XVT_IMAGE xvt_res_get_image(int rid) -{ +XVT_IMAGE xvt_res_get_image(int rid) +{ const wxString strFileName = ::GetResourceName("Image", rid); const bool ok = !strFileName.IsEmpty(); XVT_ASSERT(ok); @@ -3080,8 +3131,8 @@ static void FillMenuItem(const wxString& strValue, MENU_ITEM* mi) } } -MENU_ITEM* xvt_res_get_menu(int rid) -{ +MENU_ITEM* xvt_res_get_menu(int rid) +{ wxString strName; strName = _startup_dir; strName += "/res/resource.ini"; @@ -3094,7 +3145,7 @@ MENU_ITEM* xvt_res_get_menu(int rid) { wxFileName::SplitPath(wxTheApp->argv[0], NULL, &strName, NULL); strName.MakeUpper(); - strName = wxString::Format("/Menu_%s-%X", strName.Left(3), (rid-1)%16); + strName = wxString::Format("/Menu_%s-%X", (const char *) strName.Left(3), (rid-1)%16); } else strName = wxString::Format("/Menu_%d", rid); @@ -3132,13 +3183,13 @@ MENU_ITEM* xvt_res_get_menu(int rid) return TheMenu; } -char* xvt_res_get_str(int rid, char *s, int sz_s) -{ +char* xvt_res_get_str(int rid, char *s, int sz_s) +{ XVT_ASSERT(s != NULL && sz_s > 0); const wxString str = ::GetResourceName("String", rid); strncpy(s, str, sz_s); s[sz_s-1] = '\0'; - return s; + return s; } /////////////////////////////////////////////////////////// @@ -3148,8 +3199,8 @@ char* xvt_res_get_str(int rid, char *s, int sz_s) #define CAST_SCROLL(win, sb) XVT_ASSERT(win != NULL_WIN); wxScrollBar& sb = *(wxScrollBar*)win; #define CAST_SCROLL_TYPE(t, dir) const int dir = t == HSCROLL ? wxHORIZONTAL : wxVERTICAL; -int xvt_sbar_get_pos(WINDOW win, SCROLL_TYPE t) -{ +int xvt_sbar_get_pos(WINDOW win, SCROLL_TYPE t) +{ if (t == HSCROLL || t == VSCROLL) { CAST_WIN(win, w); @@ -3157,11 +3208,11 @@ int xvt_sbar_get_pos(WINDOW win, SCROLL_TYPE t) return w.GetScrollPos(dir); } CAST_SCROLL(win, sb); - return sb.GetThumbPosition(); -} + return sb.GetThumbPosition(); +} -int xvt_sbar_get_proportion(WINDOW win, SCROLL_TYPE t) -{ +int xvt_sbar_get_proportion(WINDOW win, SCROLL_TYPE t) +{ if (t == HSCROLL || t == VSCROLL) { CAST_WIN(win, w); @@ -3169,11 +3220,11 @@ int xvt_sbar_get_proportion(WINDOW win, SCROLL_TYPE t) return w.GetScrollThumb(dir); } CAST_SCROLL(win, sb); - return sb.GetThumbSize(); -} + return sb.GetThumbSize(); +} -void xvt_sbar_get_range(WINDOW win, SCROLL_TYPE t, int *minp, int *maxp) -{ +void xvt_sbar_get_range(WINDOW win, SCROLL_TYPE t, int *minp, int *maxp) +{ *minp = 0; if (t == HSCROLL || t == VSCROLL) { @@ -3188,8 +3239,8 @@ void xvt_sbar_get_range(WINDOW win, SCROLL_TYPE t, int *minp, int *maxp) } } -void xvt_sbar_set_pos(WINDOW win, SCROLL_TYPE t, int pos) -{ +void xvt_sbar_set_pos(WINDOW win, SCROLL_TYPE t, int pos) +{ if (t == HSCROLL || t == VSCROLL) { CAST_WIN(win, w); @@ -3205,8 +3256,8 @@ void xvt_sbar_set_pos(WINDOW win, SCROLL_TYPE t, int pos) } } -void xvt_sbar_set_proportion(WINDOW win, SCROLL_TYPE t, int proportion) -{ +void xvt_sbar_set_proportion(WINDOW win, SCROLL_TYPE t, int proportion) +{ if (t == HSCROLL || t == VSCROLL) { CAST_WIN(win, w); @@ -3224,8 +3275,8 @@ void xvt_sbar_set_proportion(WINDOW win, SCROLL_TYPE t, int proportion) } } -void xvt_sbar_set_range(WINDOW win, SCROLL_TYPE t, int min, int max) -{ +void xvt_sbar_set_range(WINDOW win, SCROLL_TYPE t, int min, int max) +{ XVT_ASSERT(min == 0); if (t == HSCROLL || t == VSCROLL) { @@ -3249,19 +3300,19 @@ void xvt_sbar_set_range(WINDOW win, SCROLL_TYPE t, int min, int max) // Window manager /////////////////////////////////////////////////////////// -void xvt_scr_beep(void) +void xvt_scr_beep(void) { xvt_sys_beep(0); } -WINDOW xvt_scr_get_focus_topwin(void) -{ - WINDOW win = (WINDOW)_task_win->FindFocus(); +WINDOW xvt_scr_get_focus_topwin(void) +{ + WINDOW win = (WINDOW)_task_win->FindFocus(); return win; } -WINDOW xvt_scr_get_focus_vobj(void) -{ +WINDOW xvt_scr_get_focus_vobj(void) +{ return xvt_scr_get_focus_topwin(); } @@ -3275,8 +3326,8 @@ static void AddWinToList(SLIST list, WINDOW win) } } -SLIST xvt_scr_list_wins() -{ +SLIST xvt_scr_list_wins() +{ SLIST list = xvt_slist_create(); _nice_windows.BeginFind(); for (wxNode *node = _nice_windows.Next(); node; node = _nice_windows.Next()) @@ -3284,16 +3335,16 @@ SLIST xvt_scr_list_wins() WINDOW win = (WINDOW)node->GetData(); AddWinToList(list, win); } - return list; + return list; } void xvt_scr_set_busy_cursor() -{ +{ xvt_win_set_cursor(TASK_WIN, CURSOR_WAIT); } -void xvt_scr_set_focus_vobj(WINDOW win) -{ +void xvt_scr_set_focus_vobj(WINDOW win) +{ CAST_WIN(win, w); w.SetFocus(); } @@ -3318,7 +3369,7 @@ BOOLEAN xvt_slist_add_at_elt(SLIST list, SLIST_ELT e, const char *sx, long data) for (SLIST_ELT i = list->head; i; i = (SLIST_ELT)i->next) { last = i; - if (i == e) + if (i == e) break; } } @@ -3337,13 +3388,13 @@ BOOLEAN xvt_slist_add_at_elt(SLIST list, SLIST_ELT e, const char *sx, long data) return ok; } -int xvt_slist_count(SLIST list) -{ +int xvt_slist_count(SLIST list) +{ XVT_ASSERT(list != NULL); - return list ? list->count : 0; + return list ? list->count : 0; } -SLIST xvt_slist_create() +SLIST xvt_slist_create() { SLIST list = new xvtList; list->head = NULL; @@ -3351,12 +3402,12 @@ SLIST xvt_slist_create() return list; } -void xvt_slist_destroy(SLIST list) -{ +void xvt_slist_destroy(SLIST list) +{ XVT_ASSERT(list != NULL); if (list) { - SLIST_ELT obj = list->head; + SLIST_ELT obj = list->head; while (obj != NULL) { SLIST_ELT tokill = obj; @@ -3368,33 +3419,33 @@ void xvt_slist_destroy(SLIST list) } } -char* xvt_slist_get(SLIST list, SLIST_ELT e, long* datap) -{ +char* xvt_slist_get(SLIST list, SLIST_ELT e, long* datap) +{ XVT_ASSERT(list != NULL); if (e != NULL) { - if (datap != NULL) + if (datap != NULL) *datap = e->data; return e->str; } return NULL; } -long* xvt_slist_get_data(SLIST_ELT elt) -{ - return elt != NULL ? &elt->data : NULL; +long* xvt_slist_get_data(SLIST_ELT elt) +{ + return elt != NULL ? &elt->data : NULL; } -SLIST_ELT xvt_slist_get_first(SLIST list) -{ +SLIST_ELT xvt_slist_get_first(SLIST list) +{ XVT_ASSERT(list != NULL); - return list != NULL ? list->head : NULL; + return list != NULL ? list->head : NULL; } -SLIST_ELT xvt_slist_get_next(SLIST list, SLIST_ELT item) -{ +SLIST_ELT xvt_slist_get_next(SLIST list, SLIST_ELT item) +{ XVT_ASSERT(list != NULL); - return (SLIST_ELT)(item ? item->next : NULL); + return (SLIST_ELT)(item ? item->next : NULL); } /////////////////////////////////////////////////////////// @@ -3413,8 +3464,8 @@ char* xvt_str_duplicate(const char* str) BOOLEAN xvt_str_match(const char *mbs, const char *pat, BOOLEAN case_sensitive) { - wxString text = mbs; - wxString pattern = pat; + wxString text = mbs; + wxString pattern = pat; if (!case_sensitive) { text.MakeUpper(); @@ -3432,7 +3483,7 @@ void xvt_sys_beep(int severity) #ifdef WIN32 OsWin32_Beep(severity); #else - wxBell(); + wxBell(); #endif } @@ -3472,7 +3523,7 @@ long xvt_sys_execute(const char* cmdline, BOOLEAN sync, BOOLEAN iconizetask) ((wxFrame*)_task_win)->Restore(); wxEnableTopLevelWindows(TRUE); _task_win->Raise(); - } + } } else exitcode = wxExecute(cmdline, wxEXEC_ASYNC); @@ -3486,6 +3537,8 @@ long xvt_sys_execute_in_window(const char* cmdline, WINDOW win) #ifdef WIN32 if (inst > 0) OsWin32_PlaceProcessInWindow(inst, "", xvt_vobj_get_attr(ATTR_NATIVE_WINDOW, win)); +#else + OsLinux_PlaceProcessInWindow(inst, "", xvt_vobj_get_attr(ATTR_NATIVE_WINDOW, win)); #endif return inst; } @@ -3513,7 +3566,7 @@ BOOLEAN xvt_sys_dongle_server_is_running() return ok; } -int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, +int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, const char* defval, char* value, int maxsize) { #ifdef WIN32 @@ -3529,7 +3582,7 @@ int xvt_sys_get_profile_string(const char* file, const char* paragraph, const ch wxString val; if (!ini.Read(name, &val)) val = defval; - + len = val.Length(); if (value) { @@ -3541,7 +3594,7 @@ int xvt_sys_get_profile_string(const char* file, const char* paragraph, const ch return len; } -BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, +BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, const char* value) { #ifdef WIN32 @@ -3563,13 +3616,13 @@ BOOLEAN xvt_sys_find_editor(const char* file, char* editor) #ifdef WIN32 const wxString e = OsWin32_File2App(file); +#else + const wxString e = OsLinux_File2App(file); +#endif ok = !e.IsEmpty(); if (ok && editor != NULL) strcpy(editor, e); -#else - SORRY_BOX(); -#endif - + return ok; } @@ -3577,7 +3630,7 @@ unsigned int xvt_sys_load_icon(const char* file) { unsigned int id = 0; wxIcon* icon = NULL; - + wxString str = file; str.MakeLower(); if (str.Find(".ico") > 0) @@ -3592,10 +3645,11 @@ unsigned int xvt_sys_load_icon(const char* file) icon->SetHICON(hicon); } #else - id = ICON_RSRC; // TBI + icon = new wxIcon; +// icon = new wxIcon(wxICON(file)); //verificare #endif } - + if (icon != NULL) { for (id = 60001; ; id++) @@ -3608,7 +3662,11 @@ unsigned int xvt_sys_load_icon(const char* file) } else { +#ifdef WIN32 if (ico->GetHICON() == icon->GetHICON()) // C'e' gia' +#else + if (ico == icon) // C'e' gia' +#endif { delete icon; break; @@ -3616,7 +3674,7 @@ unsigned int xvt_sys_load_icon(const char* file) } } } - + return id; } @@ -3632,13 +3690,13 @@ unsigned long xvt_sys_get_free_memory_kb() return mem / 1024; // Arrotondo per difetto } -int xvt_sys_get_os_version() +int xvt_sys_get_os_version() { int os = 0; int major, minor; switch (::wxGetOsVersion(&major, &minor)) { - case wxGTK: + case wxGTK: os = XVT_WS_LINUX_GTK; break; case wxWIN95: os = minor == 0 ? XVT_WS_WIN_95 : XVT_WS_WIN_98; break; @@ -3664,24 +3722,91 @@ BOOLEAN xvt_sys_test_network_version() return TRUE; } +/////////////////////////////////////////////////////////// +// XVT system calls (added by Alex) +/////////////////////////////////////////////////////////// + +void xvt_sys_searchenv(const char * filename, const char * varname, char * pathname) +{ +#ifdef WIN32 + _searchenv(filename, varname, pathname); +#else + const char * value = getenv(varname); + if (value) + { + char path_list[4096]; + const char * s = path_list; + + strcpy(path_list, value); + do + { + char * s1 = strchr(s, ';'); + + if (s1 != NULL) + *s1 = '\0'; + + char fname[256]; + + strcpy(fname, s); + strcat(fname, filename); + if (wxFileExists(fname)) + strcpy(pathname, s); + if (s1 != NULL) + s = s1 + 1; + } while (s); + + } + else + *pathname = '\0'; +#endif +} + +BOOLEAN xvt_fsys_access(const char *pathname, int mode) +{ +#ifdef WIN32 + return _access(pathname, mode); +#else + return access(pathname, mode); +#endif +} + +BOOLEAN xvt_fsys_file_exists(const char *pathname) +{ + return wxFileExists(pathname); +} + +BOOLEAN xvt_fsys_mkdir(const char *pathname) +{ + return wxMkdir(pathname); +} + +BOOLEAN xvt_fsys_rmdir(const char *pathname) +{ + return wxRmdir(pathname); +} + +BOOLEAN xvt_fsys_removefile(const char *pathname) +{ + return wxRemoveFile(pathname); +} /////////////////////////////////////////////////////////// // Timers /////////////////////////////////////////////////////////// -long xvt_timer_create(WINDOW win, long interval) -{ +long xvt_timer_create(WINDOW win, long interval) +{ CAST_TWIN(win, w); if (w._timer == NULL) { w._timer = new wxTimer(&w, TIMER_ID); w._timer->Start(interval); } - return win; + return win; } -void xvt_timer_destroy(long id) -{ +void xvt_timer_destroy(long id) +{ if (id > 0L) { CAST_TWIN(id, w); @@ -3699,8 +3824,8 @@ void xvt_timer_destroy(long id) // Visual objects /////////////////////////////////////////////////////////// -void xvt_vobj_destroy(WINDOW win) -{ +void xvt_vobj_destroy(WINDOW win) +{ if (win != _print_win) { if (_TheCaret.Owner() == win) @@ -3721,38 +3846,38 @@ long xvt_vobj_get_attr(WINDOW win, long data) case ATTR_APP_CTL_COLORS: { XVT_COLOR_COMPONENT* xcc = (XVT_COLOR_COMPONENT*)xvt_mem_zalloc(sizeof(XVT_COLOR_COMPONENT)*6); - xcc[0].type = XVT_COLOR_FOREGROUND; + xcc[0].type = XVT_COLOR_FOREGROUND; xcc[0].color = MAKE_XVT_COLOR(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNTEXT)); - xcc[1].type = XVT_COLOR_BACKGROUND; + xcc[1].type = XVT_COLOR_BACKGROUND; xcc[1].color = MAKE_XVT_COLOR(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE)); - xcc[2].type = XVT_COLOR_CAPTIONLT; + xcc[2].type = XVT_COLOR_CAPTIONLT; xcc[2].color = MAKE_XVT_COLOR(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_ACTIVECAPTION)); - xcc[3].type = XVT_COLOR_CAPTIONDK; + xcc[3].type = XVT_COLOR_CAPTIONDK; xcc[3].color = MAKE_XVT_COLOR(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_INACTIVECAPTION)); - xcc[4].type = XVT_COLOR_CAPTIONTEXT; + xcc[4].type = XVT_COLOR_CAPTIONTEXT; xcc[4].color = MAKE_XVT_COLOR(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_CAPTIONTEXT)); - xcc[5].type = XVT_COLOR_NULL; + xcc[5].type = XVT_COLOR_NULL; xcc[5].color = 0; ret = (long)xcc; } break; case ATTR_FRAME_WIDTH: - ret = wxSystemSettings::GetSystemMetric(wxSYS_FRAMESIZE_X); + ret = wxSystemSettings::GetSystemMetric(wxSYS_FRAMESIZE_X); break; case ATTR_FRAME_HEIGHT: - ret = wxSystemSettings::GetSystemMetric(wxSYS_FRAMESIZE_Y); + ret = wxSystemSettings::GetSystemMetric(wxSYS_FRAMESIZE_Y); break; case ATTR_MENU_HEIGHT: - ret = wxSystemSettings::GetSystemMetric(wxSYS_MENU_Y); + ret = wxSystemSettings::GetSystemMetric(wxSYS_MENU_Y); break; case ATTR_TITLE_HEIGHT: - ret = wxSystemSettings::GetSystemMetric(wxSYS_CAPTION_Y); + ret = wxSystemSettings::GetSystemMetric(wxSYS_CAPTION_Y); break; case ATTR_CTL_VERT_SBAR_WIDTH: - ret = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); + ret = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); break; - case ATTR_CTL_HORZ_SBAR_HEIGHT: - ret = wxSystemSettings::GetSystemMetric(wxSYS_HSCROLL_Y); + case ATTR_CTL_HORZ_SBAR_HEIGHT: + ret = wxSystemSettings::GetSystemMetric(wxSYS_HSCROLL_Y); break; case ATTR_DISPLAY_TYPE: switch (::wxDisplayDepth()) @@ -3763,50 +3888,58 @@ long xvt_vobj_get_attr(WINDOW win, long data) default: ret = XVT_DISPLAY_DIRECT_COLOR; break; } break; - case ATTR_ERRMSG_HANDLER: - ret = (long)_error_handler; + case ATTR_ERRMSG_HANDLER: + ret = (long)_error_handler; break; case ATTR_NATIVE_GRAPHIC_CONTEXT: if (_nice_windows.Get(win) != NULL) { +#ifdef WIN32 CAST_DC(win, dc); ret = dc.GetHDC(); +#else + SORRY_BOX(); //verificare +#endif } break; - case ATTR_NATIVE_WINDOW: + case ATTR_NATIVE_WINDOW: if (_nice_windows.Get(win) != NULL) { - CAST_WIN(win, w); - ret = w.GetHandle(); - } +#ifdef WIN32 + CAST_WIN(win, w); + ret = w.GetHandle(); +#else + SORRY_BOX(); //verificare +#endif + } break; - case ATTR_SCREEN_HEIGHT: - ret = wxSystemSettings::GetSystemMetric(wxSYS_SCREEN_Y); - break; - case ATTR_SCREEN_WIDTH: - ret = wxSystemSettings::GetSystemMetric(wxSYS_SCREEN_X); - break; - case ATTR_SCREEN_WINDOW: + case ATTR_SCREEN_HEIGHT: + ret = wxSystemSettings::GetSystemMetric(wxSYS_SCREEN_Y); + break; + case ATTR_SCREEN_WIDTH: + ret = wxSystemSettings::GetSystemMetric(wxSYS_SCREEN_X); + break; + case ATTR_SCREEN_WINDOW: ret = NULL_WIN; // Non bellissimo ma per ora... - break; - case ATTR_TASK_WINDOW: - ret = long(_task_win); + break; + case ATTR_TASK_WINDOW: + ret = long(_task_win); break; case ATTR_WIN_INSTANCE: ret = 0; break; - case ATTR_WIN_PM_DRAWABLE_TWIN: - ret = TRUE; + case ATTR_WIN_PM_DRAWABLE_TWIN: + ret = TRUE; break; default: SORRY_BOX(); break; } return ret; } -RCT* xvt_vobj_get_client_rect(WINDOW win, RCT *rctp) -{ +RCT* xvt_vobj_get_client_rect(WINDOW win, RCT *rctp) +{ XVT_ASSERT(rctp != NULL); - int l, h; + int l, h; if (win != NULL_WIN) { if (win == _print_win) @@ -3827,52 +3960,52 @@ RCT* xvt_vobj_get_client_rect(WINDOW win, RCT *rctp) rctp->left = rctp->top = 0; rctp->right = l; rctp->bottom = h; - return rctp; + return rctp; } -long xvt_vobj_get_data(WINDOW win) -{ +long xvt_vobj_get_data(WINDOW win) +{ CAST_TWIN(win, w); return w._app_data; } -RCT* xvt_vobj_get_outer_rect(WINDOW win, RCT *rctp) -{ +RCT* xvt_vobj_get_outer_rect(WINDOW win, RCT *rctp) +{ XVT_ASSERT(rctp != NULL); CAST_WIN(win, w); const wxRect rct = w.GetRect(); rctp->left = rct.x; rctp->top = rct.y; rctp->right = rct.x + rct.width; rctp->bottom = rct.y + rct.height; - return rctp; + return rctp; } -XVT_PALETTE xvt_vobj_get_palet(WINDOW win) +XVT_PALETTE xvt_vobj_get_palet(WINDOW win) { return NULL; } -WINDOW xvt_vobj_get_parent(WINDOW win) -{ +WINDOW xvt_vobj_get_parent(WINDOW win) +{ if (win == TASK_WIN) return NULL_WIN; CAST_WIN(win, w); - return (WINDOW)w.GetParent(); + return (WINDOW)w.GetParent(); } -char* xvt_vobj_get_title(WINDOW win, char *title, int sz_title) -{ +char* xvt_vobj_get_title(WINDOW win, char *title, int sz_title) +{ CAST_WIN(win, w); strncpy(title, w.GetTitle(), sz_title); title[sz_title-1] = '\0'; - return title; + return title; } -WIN_TYPE xvt_vobj_get_type(WINDOW win) -{ - CAST_TWIN(win, w); - return w._type; -} +WIN_TYPE xvt_vobj_get_type(WINDOW win) +{ + CAST_TWIN(win, w); + return w._type; +} -void xvt_vobj_maximize(WINDOW win) +void xvt_vobj_maximize(WINDOW win) { wxFrame* pMain = (wxFrame*)_task_win; if (win != (WINDOW)pMain) @@ -3886,7 +4019,7 @@ void xvt_vobj_maximize(WINDOW win) pMain->Maximize(); } -void xvt_vobj_minimize(WINDOW win) +void xvt_vobj_minimize(WINDOW win) { wxFrame* pMain = (wxFrame*)_task_win; if (win == (WINDOW)pMain) @@ -3895,22 +4028,22 @@ void xvt_vobj_minimize(WINDOW win) SORRY_BOX(); } -void xvt_vobj_move(WINDOW win, RCT *rctp) -{ - CAST_WIN(win, w); +void xvt_vobj_move(WINDOW win, RCT *rctp) +{ + CAST_WIN(win, w); wxRect rct = NormalizeRCT(rctp); w.Move(rct.x, rct.y); w.SetClientSize(rct.width, rct.height); } -void xvt_vobj_raise(WINDOW win) -{ +void xvt_vobj_raise(WINDOW win) +{ CAST_WIN(win, w); w.Raise(); } -void xvt_vobj_set_attr(WINDOW win, long data, long value) -{ +void xvt_vobj_set_attr(WINDOW win, long data, long value) +{ switch(data) { case ATTR_ERRMSG_HANDLER: _error_handler = (XVT_ERRMSG_HANDLER)value; break; @@ -3922,41 +4055,41 @@ void xvt_vobj_set_attr(WINDOW win, long data, long value) } } -void xvt_vobj_set_data(WINDOW win, long AppData) -{ +void xvt_vobj_set_data(WINDOW win, long AppData) +{ CAST_TWIN(win, w); w._app_data = AppData; } -void xvt_vobj_set_enabled(WINDOW win, BOOLEAN enabled) -{ - CAST_WIN(win, w); - w.Enable(enabled != 0); +void xvt_vobj_set_enabled(WINDOW win, BOOLEAN enabled) +{ + CAST_WIN(win, w); + w.Enable(enabled != 0); } -void xvt_vobj_set_palet(WINDOW win, XVT_PALETTE palet) -{ +void xvt_vobj_set_palet(WINDOW win, XVT_PALETTE palet) +{ // Do not implement! } -void xvt_vobj_set_title(WINDOW win, char *title) -{ +void xvt_vobj_set_title(WINDOW win, char *title) +{ CAST_WIN(win, w); w.SetTitle(title); } -void xvt_vobj_set_visible(WINDOW win, BOOLEAN show) -{ - CAST_WIN(win, w); - w.Show(show != 0); +void xvt_vobj_set_visible(WINDOW win, BOOLEAN show) +{ + CAST_WIN(win, w); + w.Show(show != 0); } -void xvt_vobj_translate_points(WINDOW from_win, WINDOW to_win, PNT *pntp, int npnts) -{ +void xvt_vobj_translate_points(WINDOW from_win, WINDOW to_win, PNT *pntp, int npnts) +{ XVT_ASSERT(from_win != NULL_WIN && to_win != NULL_WIN); XVT_ASSERT(pntp != NULL && npnts > 0); - CAST_WIN(from_win, w1); - CAST_WIN(to_win, w2); + CAST_WIN(from_win, w1); + CAST_WIN(to_win, w2); for (int i = 0; i < npnts; i++) { int x = pntp[i].h; @@ -3972,15 +4105,15 @@ void xvt_vobj_translate_points(WINDOW from_win, WINDOW to_win, PNT *pntp, int np // Real windows /////////////////////////////////////////////////////////// -WINDOW xvt_win_create(WIN_TYPE wtype, RCT *rct_p, char *title, int menu_rid, WINDOW parent, long win_flags, EVENT_MASK mask, EVENT_HANDLER eh, long app_data) -{ +WINDOW xvt_win_create(WIN_TYPE wtype, RCT *rct_p, char *title, int menu_rid, WINDOW parent, long win_flags, EVENT_MASK mask, EVENT_HANDLER eh, long app_data) +{ XVT_ASSERT(rct_p != NULL); const wxString caption = title; const wxPoint pos(rct_p->left, rct_p->top); const wxSize size(rct_p->right-rct_p->left, rct_p->bottom-rct_p->top); - long style = wxNO_3D | wxWANTS_CHARS | + long style = wxNO_3D | wxWANTS_CHARS | wxCLIP_CHILDREN | wxCLIP_SIBLINGS | // Clippa per bene wxPOPUP_WINDOW; // Inizialmente invisibile! @@ -3994,13 +4127,13 @@ WINDOW xvt_win_create(WIN_TYPE wtype, RCT *rct_p, char *title, int menu_rid, WIN { case W_DOC: style |= wxBORDER; - if (!caption.IsEmpty()) + if (!caption.IsEmpty()) style |= wxCAPTION | wxSYSTEM_MENU; break; case W_PLAIN: // style |= wxBORDER; // Non attivare MAI il bordo! break; - default: + default: SORRY_BOX(); break; } w = new TwxWindow((wxWindow*)parent, -1, caption, pos, size, style); @@ -4048,18 +4181,18 @@ WINDOW xvt_win_create(WIN_TYPE wtype, RCT *rct_p, char *title, int menu_rid, WIN xvt_app_process_pending_events(); - return (WINDOW)w; + return (WINDOW)w; } -long xvt_win_dispatch_event(WINDOW win, EVENT* event_p) -{ +long xvt_win_dispatch_event(WINDOW win, EVENT* event_p) +{ XVT_ASSERT(event_p != NULL); CAST_TWIN(win, w); - return w._eh(win, event_p); + return w._eh(win, event_p); } -void xvt_win_post_event(WINDOW win, EVENT* event_p) -{ +void xvt_win_post_event(WINDOW win, EVENT* event_p) +{ // Per ora funziona solo con la task window XVT_ASSERT(win == (WINDOW)_task_win && event_p != NULL); @@ -4072,41 +4205,41 @@ void xvt_win_post_event(WINDOW win, EVENT* event_p) wxPostEvent(_task_win, e); } break; - default: - SORRY_BOX(); + default: + SORRY_BOX(); break; } } -void xvt_win_release_pointer(void) +void xvt_win_release_pointer(void) { if (_mouse_trapper != NULL) { // cap SHOULD be equal to _mouse_trapper :-) - wxWindow* cap = _mouse_trapper->GetCapture(); + wxWindow* cap = _mouse_trapper->GetCapture(); if (cap != NULL) cap->ReleaseMouse(); _mouse_trapper = NULL; } } -void xvt_win_set_caret_size(WINDOW win, int width, int height) -{ +void xvt_win_set_caret_size(WINDOW win, int width, int height) +{ _TheCaret.SetSize(width, height); } -void xvt_win_set_caret_pos(WINDOW win, PNT p) -{ +void xvt_win_set_caret_pos(WINDOW win, PNT p) +{ _TheCaret.SetPos(p.h, p.v-1); } -void xvt_win_set_caret_visible(WINDOW win, BOOLEAN on) -{ +void xvt_win_set_caret_visible(WINDOW win, BOOLEAN on) +{ _TheCaret.Show(win, on != 0); } -void xvt_win_set_cursor(WINDOW win, CURSOR cursor) -{ +void xvt_win_set_cursor(WINDOW win, CURSOR cursor) +{ CAST_WIN(win, w); wxCursor* cur = wxSTANDARD_CURSOR; // Dummy initilization switch (cursor) @@ -4119,8 +4252,8 @@ void xvt_win_set_cursor(WINDOW win, CURSOR cursor) w.SetCursor(*cur); } -void xvt_win_set_handler(WINDOW win, EVENT_HANDLER eh) -{ +void xvt_win_set_handler(WINDOW win, EVENT_HANDLER eh) +{ if (win == (WINDOW)_task_win) { _task_win_handler = eh; @@ -4132,8 +4265,8 @@ void xvt_win_set_handler(WINDOW win, EVENT_HANDLER eh) } } -void xvt_win_trap_pointer(WINDOW win) -{ +void xvt_win_trap_pointer(WINDOW win) +{ CAST_WIN(win, w); xvt_win_release_pointer(); w.CaptureMouse(); @@ -4145,7 +4278,7 @@ void xvt_win_trap_pointer(WINDOW win) /////////////////////////////////////////////////////////// static wxString strDefaultStatbarText; - + const char* statbar_set_title(WINDOW win, const char* text) { XVT_ASSERT(win == TASK_WIN); @@ -4165,7 +4298,7 @@ const char* statbar_set_title(WINDOW win, const char* text) w.SetStatusText(text); return text; } - + const char* statbar_set_default_title(WINDOW win, const char *text) { strDefaultStatbarText = text; @@ -4176,10 +4309,10 @@ XVT_FNTID statbar_set_fontid(WINDOW win, XVT_FNTID fontid) { return fontid; // TBI??? } - + XVT_FNTID statbar_get_fontid(WINDOW win, XVT_FNTID fontid) { - return fontid; // TBI??? + return fontid; // VERIFICARE } WINDOW statbar_create(int cid, int left, int top, int right, int bottom, diff --git a/xvaga/xvapp.cpp b/xvaga/xvapp.cpp index c11af1dd1..823290be5 100755 --- a/xvaga/xvapp.cpp +++ b/xvaga/xvapp.cpp @@ -1,6 +1,6 @@ -#include "..\xvaga\wxinc.h" +#include "../xvaga/wxinc.h" -extern int xvt_main(int argc, char** argv); +extern int xvt_main(int argc, char** argv); class TMainApp : public wxApp { diff --git a/xvaga/xvintern.h b/xvaga/xvintern.h index dced72e95..8b1d7fd78 100755 --- a/xvaga/xvintern.h +++ b/xvaga/xvintern.h @@ -37,13 +37,13 @@ public: bool operator==(const TFontId& f) const { return IsEqual(f); } bool operator!=(const TFontId& f) const { return !IsEqual(f); } - TFontId() : m_win(NULL_WIN), m_nSize(0), m_wMask(0) { } + TFontId() : m_nSize(0), m_wMask(0), m_win(NULL_WIN) { } TFontId(const TFontId& f) : m_win(NULL_WIN) { Copy(f); } }; -class TDC : public wxObject +class TDC : public wxObject { - wxWindow* _owner; + wxWindow* _owner; protected: wxDC* _dc; diff --git a/xvaga/xvt.h b/xvaga/xvt.h index 8c20380ef..c6648fce5 100755 --- a/xvaga/xvt.h +++ b/xvaga/xvt.h @@ -2,14 +2,12 @@ #define XVT_INCL_XVT #ifdef XVT_INCL_NATIVE - #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #define WIN32_EXTRA_LEAN #define STRICT #include #endif - #endif #ifdef WIN32 @@ -18,6 +16,7 @@ #else #define XVTDLL __declspec(dllimport) #endif +#include #else #define XVTDLL #endif @@ -25,7 +24,6 @@ #define XVAGA 1 #include -#include #include #include #include @@ -162,6 +160,11 @@ XVTDLL BOOLEAN xvt_fsys_is_removable_drive(const char* path); XVTDLL BOOLEAN xvt_fsys_is_network_drive(const char* path); XVTDLL BOOLEAN xvt_fsys_is_fixed_drive(const char* path); XVTDLL BOOLEAN xvt_fsys_test_disk_free_space(const char* path, unsigned long filesize); +XVTDLL BOOLEAN xvt_fsys_mkdir(const char *pathname); +XVTDLL BOOLEAN xvt_fsys_rmdir(const char *pathname); +XVTDLL BOOLEAN xvt_fsys_removefile(const char *pathname); +XVTDLL BOOLEAN xvt_fsys_access(const char *pathname, int mode); +XVTDLL BOOLEAN xvt_fsys_file_exists(const char *pathname); XVTDLL void xvt_help_close_helpfile(XVT_HELP_INFO hi); XVTDLL XVT_HELP_INFO xvt_help_open_helpfile(FILE_SPEC *fs, unsigned long flags); @@ -255,7 +258,7 @@ XVTDLL void xvt_scr_set_focus_vobj(WINDOW win); XVTDLL BOOLEAN xvt_slist_add_at_elt(SLIST x, SLIST_ELT e, const char *sx, long data); XVTDLL int xvt_slist_count(SLIST x); -XVTDLL SLIST xvt_slist_create(); +XVTDLL SLIST xvt_slist_create(); XVTDLL void xvt_slist_destroy(SLIST list); XVTDLL char* xvt_slist_get(SLIST x, SLIST_ELT e, long *datap); XVTDLL long* xvt_slist_get_data(SLIST_ELT elt); @@ -275,20 +278,20 @@ XVTDLL BOOLEAN xvt_sys_get_user_name(char* name, int maxlen); XVTDLL BOOLEAN xvt_sys_goto_url(const char* url, const char* action); XVTDLL BOOLEAN xvt_sys_dongle_server_is_running(); XVTDLL BOOLEAN xvt_sys_find_editor(const char* file, char* editor); -XVTDLL int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, +XVTDLL int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, const char* defval, char* value, int maxsize); -XVTDLL BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, +XVTDLL BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, const char* value); XVTDLL unsigned long xvt_sys_get_free_memory(); XVTDLL unsigned long xvt_sys_get_free_memory_kb(); -XVTDLL int xvt_sys_get_os_version(); -XVTDLL unsigned int xvt_sys_load_icon(const char* file); -XVTDLL void xvt_sys_sleep(unsigned long msec); -XVTDLL BOOLEAN xvt_sys_test_network_version(); - -XVTDLL long xvt_timer_create(WINDOW win, long interval); -XVTDLL void xvt_timer_destroy(long id); - +XVTDLL int xvt_sys_get_os_version(); +XVTDLL unsigned int xvt_sys_load_icon(const char* file); +XVTDLL void xvt_sys_sleep(unsigned long msec); +XVTDLL BOOLEAN xvt_sys_test_network_version(); +XVTDLL void xvt_sys_searchenv(const char *filename, const char *varname, char *pathname); +XVTDLL void xvt_sys_sorry_box(const char * file, int line); +XVTDLL long xvt_timer_create(WINDOW win, long interval); +XVTDLL void xvt_timer_destroy(long id); XVTDLL void xvt_vobj_destroy(WINDOW win); XVTDLL long xvt_vobj_get_attr(WINDOW win, long data); XVTDLL RCT* xvt_vobj_get_client_rect(WINDOW win, RCT *rctp); @@ -309,7 +312,6 @@ XVTDLL void xvt_vobj_set_palet(WINDOW win, XVT_PALETTE palet); XVTDLL void xvt_vobj_set_title(WINDOW win, char *title); XVTDLL void xvt_vobj_set_visible(WINDOW win, BOOLEAN show); XVTDLL void xvt_vobj_translate_points(WINDOW from_win, WINDOW to_win, PNT *pntp, int npnts); - XVTDLL WINDOW xvt_win_create(WIN_TYPE wtype, RCT *rct_p, char *title, int menu_rid, WINDOW parent_win, long win_flags, EVENT_MASK mask, EVENT_HANDLER eh, long app_data); XVTDLL long xvt_win_dispatch_event(WINDOW win, EVENT* event_p); XVTDLL void xvt_win_post_event(WINDOW win, EVENT* event_p); // Added by XVAGA @@ -325,4 +327,6 @@ XVTDLL void xvt_win_trap_pointer(WINDOW win); } #endif +#define SORRY_BOX() xvt_sys_sorry_box(__FILE__, __LINE__) + #endif diff --git a/xvaga/xvt_env.h b/xvaga/xvt_env.h index 5c990e617..afe88e8b9 100755 --- a/xvaga/xvt_env.h +++ b/xvaga/xvt_env.h @@ -30,4 +30,4 @@ #define ATTR_WIN_PM_TWIN_STARTUP_RCT (ATTR_WIN_BASE + 11) #define ATTR_WIN_PM_TWIN_STARTUP_STYLE (ATTR_WIN_BASE + 12) -#define main xvt_main \ No newline at end of file +#define main xvt_main diff --git a/xvaga/xvt_type.h b/xvaga/xvt_type.h index 6555087f6..960d59847 100755 --- a/xvaga/xvt_type.h +++ b/xvaga/xvt_type.h @@ -1,9 +1,19 @@ +#ifndef BOOLEAN #define BOOLEAN short +#endif #ifndef FALSE #define FALSE 0 #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; @@ -29,11 +39,11 @@ typedef unsigned long XVT_FONT_STYLE_MASK; typedef long PICTURE; typedef void* XVT_IMAGE; -typedef enum { -XVT_IMAGE_NONE, -XVT_IMAGE_CL8, +typedef enum { +XVT_IMAGE_NONE, +XVT_IMAGE_CL8, XVT_IMAGE_RGB, -XVT_IMAGE_MONO, +XVT_IMAGE_MONO, } XVT_IMAGE_FORMAT; #define XVT_FNTID void* @@ -46,19 +56,19 @@ typedef enum e_display_type { XVT_DISPLAY_MONO, /* monochromatic display */ XVT_DISPLAY_GRAY_16, /* 16-entry grayscale */ XVT_DISPLAY_GRAY_256, /* 256-entry grayscale */ - XVT_DISPLAY_COLOR_16, /* 16-entry color */ + XVT_DISPLAY_COLOR_16, /* 16-entry color */ XVT_DISPLAY_COLOR_256, /* 256-entry color */ XVT_DISPLAY_DIRECT_COLOR, /* full color capabilities */ } XVT_DISPLAY_TYPE; -typedef enum { +typedef enum { -XVT_PALETTE_NONE, -XVT_PALETTE_STOCK, -XVT_PALETTE_CURRENT, -XVT_PALETTE_CUBE16, -XVT_PALETTE_CUBE256, -XVT_PALETTE_USER +XVT_PALETTE_NONE, +XVT_PALETTE_STOCK, +XVT_PALETTE_CURRENT, +XVT_PALETTE_CUBE16, +XVT_PALETTE_CUBE256, +XVT_PALETTE_USER } XVT_PALETTE_TYPE; typedef enum { /* response from ask fcn */ @@ -73,34 +83,34 @@ typedef enum { /* result from file open & save dialogs */ FL_OK, /* OK button clicked */ } FL_STATUS; -typedef struct -{ +typedef struct +{ char path[_MAX_DIR]; } DIRECTORY; -typedef struct s_mitem { +typedef struct s_mitem { -MENU_TAG tag; /* menu tag */ -char *text; /* text to appear in menu */ -short mkey; /* mnemonic */ -unsigned enabled: 1; /* enabled? */ -unsigned checked: 1; /* checked? */ -unsigned checkable: 1; /* checkable? */ -unsigned separator: 1; /* separator? */ -struct s_mitem *child; /* pointer to submenu */ +MENU_TAG tag; /* menu tag */ +char *text; /* text to appear in menu */ +short mkey; /* mnemonic */ +unsigned enabled: 1; /* enabled? */ +unsigned checked: 1; /* checked? */ +unsigned checkable: 1; /* checkable? */ +unsigned separator: 1; /* separator? */ +struct s_mitem *child; /* pointer to submenu */ } MENU_ITEM; #define SZ_FNAME _MAX_FNAME -typedef struct { /* file specification */ -DIRECTORY dir; /* directory */ -char type[6]; /* file type/extension */ -char name[_MAX_FNAME]; /* filename */ -char creator[6]; /* file creator */ +typedef struct { /* file specification */ +DIRECTORY dir; /* directory */ +char type[6]; /* file type/extension */ +char name[_MAX_FNAME]; /* filename */ +char creator[6]; /* file creator */ } FILE_SPEC; typedef struct -{ +{ void* pr; } PRINT_RCD; @@ -115,42 +125,42 @@ typedef SLIST_ITEM* SLIST_ELT; typedef struct { SLIST_ELT head; long count; } xvtList; typedef xvtList* SLIST; -typedef enum { /* drawing (transfer) mode */ -M_COPY, -M_OR, -M_XOR, -M_CLEAR, -M_NOT_COPY, -M_NOT_OR, -M_NOT_XOR, -M_NOT_CLEAR +typedef enum { /* drawing (transfer) mode */ +M_COPY, +M_OR, +M_XOR, +M_CLEAR, +M_NOT_COPY, +M_NOT_OR, +M_NOT_XOR, +M_NOT_CLEAR } DRAW_MODE; -typedef enum e_pen_style { /* pen style */ -P_SOLID, /* solid */ -P_DOT, /* dotted line */ -P_DASH /* dashed line */ +typedef enum e_pen_style { /* pen style */ +P_SOLID, /* solid */ +P_DOT, /* dotted line */ +P_DASH /* dashed line */ } PEN_STYLE; -typedef enum { -PAT_NONE, /* no pattern */ -PAT_HOLLOW, /* hollow */ -PAT_SOLID, /* solid fill */ -PAT_HORZ, /* horizontal lines */ -PAT_VERT, /* vertical lines */ -PAT_FDIAG, /* diagonal lines -- top-left to bottom-right */ -PAT_BDIAG, /* diagonal lines -- top-right to bottom-left */ -PAT_CROSS, /* horizontal and vertical crossing lines */ -PAT_DIAGCROSS, /* diagonol crossing lines */ -PAT_RUBBER, /* rubber banding */ -PAT_SPECIAL +typedef enum { +PAT_NONE, /* no pattern */ +PAT_HOLLOW, /* hollow */ +PAT_SOLID, /* solid fill */ +PAT_HORZ, /* horizontal lines */ +PAT_VERT, /* vertical lines */ +PAT_FDIAG, /* diagonal lines -- top-left to bottom-right */ +PAT_BDIAG, /* diagonal lines -- top-right to bottom-left */ +PAT_CROSS, /* horizontal and vertical crossing lines */ +PAT_DIAGCROSS, /* diagonol crossing lines */ +PAT_RUBBER, /* rubber banding */ +PAT_SPECIAL } PAT_STYLE; -typedef struct { /* color pen tool */ -short width; /* width */ -PAT_STYLE pat; /* pattern */ -PEN_STYLE style; /* style */ -COLOR color; /* color */ +typedef struct { /* color pen tool */ +short width; /* width */ +PAT_STYLE pat; /* pattern */ +PEN_STYLE style; /* style */ +COLOR color; /* color */ } CPEN; typedef struct @@ -159,265 +169,265 @@ typedef struct COLOR color; } CBRUSH; -typedef struct { /* color drawing tools */ -CPEN pen; /* color pen */ -CBRUSH brush; /* color brush */ -DRAW_MODE mode; /* drawing mode */ -COLOR fore_color; /* foreground color */ -COLOR back_color; /* background color */ -BOOLEAN opaque_text; /* is text opaque*/ +typedef struct { /* color drawing tools */ +CPEN pen; /* color pen */ +CBRUSH brush; /* color brush */ +DRAW_MODE mode; /* drawing mode */ +COLOR fore_color; /* foreground color */ +COLOR back_color; /* background color */ +BOOLEAN opaque_text; /* is text opaque*/ } DRAW_CTOOLS; -typedef enum { /* scrollbar activity */ -SC_NONE, /* nowhere (ignore) */ -SC_LINE_UP, /* one line up */ -SC_LINE_DOWN, /* one line down */ -SC_PAGE_UP, /* previous page */ -SC_PAGE_DOWN, /* next page */ -SC_THUMB, /* thumb repositioning */ -SC_THUMBTRACK /* thumb tracking */ +typedef enum { /* scrollbar activity */ +SC_NONE, /* nowhere (ignore) */ +SC_LINE_UP, /* one line up */ +SC_LINE_DOWN, /* one line down */ +SC_PAGE_UP, /* previous page */ +SC_PAGE_DOWN, /* next page */ +SC_THUMB, /* thumb repositioning */ +SC_THUMBTRACK /* thumb tracking */ } SCROLL_CONTROL; -typedef enum { /* type of window */ +typedef enum { /* type of window */ -W_NONE, /* marker for end of WIN_DEF array */ -W_DOC, /* document window */ -W_PLAIN, /* window with plain border */ -W_DBL, /* window with double border */ -W_PRINT, /* XVT internal use only */ -W_TASK, /* task window */ -W_SCREEN, /* screen window */ -W_NO_BORDER, /* no border */ -W_PIXMAP, /* pixmap */ -W_MODAL, /* modal window */ -WD_MODAL, /* modal dialog */ -WD_MODELESS, /* modeless dialog */ -WC_PUSHBUTTON, /* button control */ -WC_RADIOBUTTON, /* radio button control */ -WC_CHECKBOX, /* check box control */ -WC_HSCROLL, /* horizontal scrollbar control */ -WC_VSCROLL, /* vertical scrollbar control */ -WC_EDIT, /* edit control */ -WC_TEXT, /* static text control */ -WC_LBOX, /* list box control */ -WC_LISTBUTTON, /* button with list */ +W_NONE, /* marker for end of WIN_DEF array */ +W_DOC, /* document window */ +W_PLAIN, /* window with plain border */ +W_DBL, /* window with double border */ +W_PRINT, /* XVT internal use only */ +W_TASK, /* task window */ +W_SCREEN, /* screen window */ +W_NO_BORDER, /* no border */ +W_PIXMAP, /* pixmap */ +W_MODAL, /* modal window */ +WD_MODAL, /* modal dialog */ +WD_MODELESS, /* modeless dialog */ +WC_PUSHBUTTON, /* button control */ +WC_RADIOBUTTON, /* radio button control */ +WC_CHECKBOX, /* check box control */ +WC_HSCROLL, /* horizontal scrollbar control */ +WC_VSCROLL, /* vertical scrollbar control */ +WC_EDIT, /* edit control */ +WC_TEXT, /* static text control */ +WC_LBOX, /* list box control */ +WC_LISTBUTTON, /* button with list */ -WC_LISTEDIT, /* edit with field list */ -WC_GROUPBOX, /* group box */ -WC_TEXTEDIT, /* text edit object */ -WC_ICON, /* icon control */ +WC_LISTEDIT, /* edit with field list */ +WC_GROUPBOX, /* group box */ +WC_TEXTEDIT, /* text edit object */ +WC_ICON, /* icon control */ WO_TE, /* text edit */ } WIN_TYPE; -typedef enum { -SEV_NONE, +typedef enum { +SEV_NONE, SEV_WARNING, -SEV_ERROR, -SEV_FATAL, +SEV_ERROR, +SEV_FATAL, } XVT_ERRSEV; -typedef enum { /* type of scrollbar */ +typedef enum { /* type of scrollbar */ -HSCROLL, /* horizontal */ -VSCROLL, /* vertical */ -HVSCROLL, /* either */ +HSCROLL, /* horizontal */ +VSCROLL, /* vertical */ +HVSCROLL, /* either */ } SCROLL_TYPE; -typedef struct s_ctlinfo { +typedef struct s_ctlinfo { -WIN_TYPE type; -WINDOW win; -union { +WIN_TYPE type; +WINDOW win; +union { -struct s_scroll { +struct s_scroll { -SCROLL_CONTROL what; -short pos; +SCROLL_CONTROL what; +short pos; -} scroll; -struct s_edit { +} scroll; +struct s_edit { -BOOLEAN focus_change; -BOOLEAN active; +BOOLEAN focus_change; +BOOLEAN active; -} edit; -struct s_lbox { +} edit; +struct s_lbox { -BOOLEAN dbl_click; +BOOLEAN dbl_click; -} lbox; -struct s_listedit { +} lbox; +struct s_listedit { -BOOLEAN focus_change; -BOOLEAN active; +BOOLEAN focus_change; +BOOLEAN active; -} listedit; +} listedit; -} v; +} v; } CONTROL_INFO; -typedef struct s_xvt_color_component { +typedef struct s_xvt_color_component { -XVT_COLOR_TYPE type; /* color component being defined */ -COLOR color; /* RGB color value */ +XVT_COLOR_TYPE type; /* color component being defined */ +COLOR color; /* RGB color value */ } XVT_COLOR_COMPONENT; -typedef struct s_win_def { +typedef struct s_win_def { -WIN_TYPE wtype; /* WC_* or WO_* type */ +WIN_TYPE wtype; /* WC_* or WO_* type */ -RCT rct; -char *text; -UNIT_TYPE units; -XVT_COLOR_COMPONENT * ctlcolors; -union { +RCT rct; +char *text; +UNIT_TYPE units; +XVT_COLOR_COMPONENT * ctlcolors; +union { -struct s_win_def_win { /* WINDOW's */ +struct s_win_def_win { /* WINDOW's */ -short int menu_rid; /* menu resource id */ -MENU_ITEM *menu_p; /* pointer to menu tree */ -long flags; /* WSF_* flags */ -XVT_FNTID ctl_font_id; /* control font id */ +short int menu_rid; /* menu resource id */ +MENU_ITEM *menu_p; /* pointer to menu tree */ +long flags; /* WSF_* flags */ +XVT_FNTID ctl_font_id; /* control font id */ } win; -struct s_win_def_dlg { /* DIALOG's */ +struct s_win_def_dlg { /* DIALOG's */ -long flags; /* WSF_* flags */ -XVT_FNTID ctl_font_id; /* control font id */ +long flags; /* WSF_* flags */ +XVT_FNTID ctl_font_id; /* control font id */ } dlg; -struct s_win_def_ctl { /* CONTROL's */ +struct s_win_def_ctl { /* CONTROL's */ -short int ctrl_id; +short int ctrl_id; -short int icon_id; /* for icons only */ -long flags; /* CTL_* flags */ -XVT_FNTID font_id; /* logical font */ +short int icon_id; /* for icons only */ +long flags; /* CTL_* flags */ +XVT_FNTID font_id; /* logical font */ } ctl; -struct s_win_def_tx { /* text edit objects */ +struct s_win_def_tx { /* text edit objects */ -unsigned short attrib; /* TX_* flags */ -XVT_FNTID font_id; /* logical font */ -short margin; /* right margin */ -short limit; /* max chars */ -short int tx_id; /* text ID */ +unsigned short attrib; /* TX_* flags */ +XVT_FNTID font_id; /* logical font */ +short margin; /* right margin */ +short limit; /* max chars */ +short int tx_id; /* text ID */ -} tx; +} tx; -} v; +} v; } WIN_DEF; -typedef enum { -E_CREATE, /* creation */ -E_DESTROY, /* destruction */ -E_FOCUS, /* window focus gain/loss */ -E_SIZE, /* resize */ -E_UPDATE, /* update */ -E_CLOSE, /* close window request */ -E_MOUSE_DOWN, /* mouse down */ -E_MOUSE_UP, /* mouse up */ -E_MOUSE_MOVE, /* mouse move */ -E_MOUSE_DBL, /* mouse double click */ -E_CHAR, /* character typed */ -E_VSCROLL, /* vert. window scrollbar activity */ -E_HSCROLL, /* horz. window scrollbar activity */ -E_COMMAND, /* menu command */ -E_FONT, /* font menu selection */ -E_CONTROL, /* control activity */ -E_TIMER, /* timer */ -E_QUIT, /* application shutdown request */ -E_HELP, /* help invoked */ -E_USER, /* user defined */ +typedef enum { +E_CREATE, /* creation */ +E_DESTROY, /* destruction */ +E_FOCUS, /* window focus gain/loss */ +E_SIZE, /* resize */ +E_UPDATE, /* update */ +E_CLOSE, /* close window request */ +E_MOUSE_DOWN, /* mouse down */ +E_MOUSE_UP, /* mouse up */ +E_MOUSE_MOVE, /* mouse move */ +E_MOUSE_DBL, /* mouse double click */ +E_CHAR, /* character typed */ +E_VSCROLL, /* vert. window scrollbar activity */ +E_HSCROLL, /* horz. window scrollbar activity */ +E_COMMAND, /* menu command */ +E_FONT, /* font menu selection */ +E_CONTROL, /* control activity */ +E_TIMER, /* timer */ +E_QUIT, /* application shutdown request */ +E_HELP, /* help invoked */ +E_USER, /* user defined */ } EVENT_TYPE; -typedef struct s_event { +typedef struct s_event { -EVENT_TYPE type; -union { +EVENT_TYPE type; +union { -struct s_mouse { +struct s_mouse { -PNT where; -BOOLEAN shift; -BOOLEAN control; -short button; +PNT where; +BOOLEAN shift; +BOOLEAN control; +short button; -} mouse; -struct s_char { +} mouse; +struct s_char { -XVT_WCHAR ch; -BOOLEAN shift; -BOOLEAN control; -BOOLEAN virtual_key; -unsigned long modifiers; +XVT_WCHAR ch; +BOOLEAN shift; +BOOLEAN control; +BOOLEAN virtual_key; +unsigned long modifiers; -} chr; -BOOLEAN active; -BOOLEAN query; -struct s_scroll_info { +} chr; +BOOLEAN active; +BOOLEAN query; +struct s_scroll_info { -SCROLL_CONTROL what; -short pos; +SCROLL_CONTROL what; +short pos; -} scroll; -struct s_cmd { +} scroll; +struct s_cmd { -MENU_TAG tag; -BOOLEAN shift; -BOOLEAN control; +MENU_TAG tag; +BOOLEAN shift; +BOOLEAN control; -} cmd; -struct s_size { +} cmd; +struct s_size { -short height; -short width; +short height; +short width; -} size; -struct s_efont { +} size; +struct s_efont { -XVT_FNTID font_id; +XVT_FNTID font_id; -} font; -struct s_ctl { +} font; +struct s_ctl { -short id; -CONTROL_INFO ci; +short id; +CONTROL_INFO ci; -} ctl; -struct s_update { +} ctl; +struct s_update { -RCT rct; +RCT rct; -} update; -struct s_timer { +} update; +struct s_timer { -long id; +long id; -} timer; -struct s_user { +} timer; +struct s_user { -long id; -void *ptr; +long id; +void *ptr; -} user; -struct s_help { +} user; +struct s_help { -WINDOW obj; -MENU_TAG tag; -XVT_HELP_TID tid; +WINDOW obj; +MENU_TAG tag; +XVT_HELP_TID tid; }help; -} v; +} v; } EVENT; @@ -426,18 +436,18 @@ typedef long (* EVENT_HANDLER) (WINDOW win, EVENT *ep); typedef BOOLEAN (* XVT_ERRMSG_HANDLER) (XVT_ERRMSG err, DATA_PTR context); -typedef enum { /* std. clipboard format */ -CB_TEXT, /* ASCII text */ -CB_PICT, /* encapsulated picture */ -CB_APPL /* app's own (must have name) */ +typedef enum { /* std. clipboard format */ +CB_TEXT, /* ASCII text */ +CB_PICT, /* encapsulated picture */ +CB_APPL /* app's own (must have name) */ } CB_FORMAT; -typedef struct s_xvt_config { +typedef struct s_xvt_config { -short menu_bar_ID; /* task menubar ResID */ -short about_box_ID; /* default aboutbox ResID */ -char *base_appl_name; /* application's "filename" */ -char *appl_name; /* application's name */ -char *taskwin_title; /* title for task window */ +short menu_bar_ID; /* task menubar ResID */ +short about_box_ID; /* default aboutbox ResID */ +char *base_appl_name; /* application's "filename" */ +char *appl_name; /* application's name */ +char *taskwin_title; /* title for task window */ } XVT_CONFIG; diff --git a/xvaga/xvtextra.cpp b/xvaga/xvtextra.cpp index 785aea6f7..8524a21f9 100755 --- a/xvaga/xvtextra.cpp +++ b/xvaga/xvtextra.cpp @@ -3,7 +3,12 @@ #include "wx/printdlg.h" #include "xvt.h" +#ifdef WIN32 #include "oswin32.h" +#else +#include "oslinux.h" +#include +#endif #include "xvintern.h" @@ -31,9 +36,9 @@ void TPRINT_RCD::SetData(void* data, unsigned int nSize) } } -TPRINT_RCD::TPRINT_RCD() : m_size(0) -{ - pr = NULL; +TPRINT_RCD::TPRINT_RCD() : m_size(0) +{ + pr = NULL; memset(m_data, 0, sizeof(m_data)); } @@ -71,7 +76,7 @@ bool TwxPrintOut::OnPrintPage(int pageNum) void TwxPrintOut::InitDC(TPRINT_RCD* prcd) { - wxDC* dc = GetDC(); + wxDC* dc = GetDC(); if (dc != NULL) delete dc; @@ -80,18 +85,22 @@ void TwxPrintOut::InitDC(TPRINT_RCD* prcd) if (m_prcd == NULL) { wxPrinter printer; +#ifdef WIN32 dc = new wxPrinterDC(printer.GetPrintDialogData().GetPrintData()); +#else + dc = new wxPostScriptDC(printer.GetPrintDialogData().GetPrintData()); +#endif } else { wxPrintData data; #ifdef WIN32 data.SetNativeData(OsWin32_ConvertToNativePrinterInfo(prcd->m_data, prcd->m_size)); -#else - data.SetNativeData(prcd->m_data); -#endif data.ConvertFromNative(); dc = new wxPrinterDC(data); +#else + dc = new wxPostScriptDC(prcd->m_data); +#endif } wxSize s = dc->GetPPI(); @@ -104,13 +113,13 @@ void TwxPrintOut::InitDC(TPRINT_RCD* prcd) } TwxPrintOut::TwxPrintOut(TPRINT_RCD* prcd) -{ +{ InitDC(prcd); } TwxPrintOut::~TwxPrintOut() { - wxDC* dc = GetDC(); + wxDC* dc = GetDC(); if (dc != NULL) delete dc; } @@ -127,7 +136,7 @@ wxDC& TPrintDC::GetDC(bool) return TDC::GetDC(false); } -TPrintDC::TPrintDC(wxWindow* owner) : TDC(owner) +TPrintDC::TPrintDC(wxWindow* owner) : TDC(owner) { } TPrintDC::~TPrintDC() @@ -139,8 +148,8 @@ TPrintDC::~TPrintDC() // Printing management :-((((( /////////////////////////////////////////////////////////// -BOOLEAN xvt_app_escape(int esc_code, PRINT_RCD* rcd, long* ph, long* pw, long* pvr, long* phr) -{ +BOOLEAN xvt_app_escape(int esc_code, PRINT_RCD* rcd, long* ph, long* pw, long* pvr, long* phr) +{ *ph = *pw = *pvr = *phr = 0; switch (esc_code) { @@ -163,14 +172,14 @@ BOOLEAN xvt_app_escape(int esc_code, PRINT_RCD* rcd, long* ph, long* pw, long* p return TRUE; } break; - default: + default: break; } return FALSE; } -BOOLEAN xvt_dm_post_page_setup(PRINT_RCD* precp) -{ +BOOLEAN xvt_dm_post_page_setup(PRINT_RCD* precp) +{ wxPageSetupDialog dlg((wxWindow*)TASK_WIN); TPRINT_RCD* rcd = (TPRINT_RCD*)precp; @@ -178,79 +187,83 @@ BOOLEAN xvt_dm_post_page_setup(PRINT_RCD* precp) // pdd.EnablePrinter(false); // Vieta di cambiare stampante wxPrintData& data = pdd.GetPrintData(); -#ifdef WIN32 +#ifdef WIN32 data.SetNativeData(OsWin32_ConvertToNativePrinterInfo(rcd->m_data, rcd->m_size)); -#else - data.SetNativeData(rcd->m_data); -#endif data.ConvertFromNative(); +#endif if (dlg.ShowModal() == wxID_OK) { +#ifdef WIN32 data.ConvertToNative(); void* pHandle = data.GetNativeData(); -#ifdef WIN32 unsigned int nSize = 0; void* ptr = OsWin32_ConvertFromNativePrinterInfo(pHandle, nSize); rcd->SetData(ptr, nSize); delete ptr; #else - rcd->SetData(pHandle, 1024); + rcd->SetData((void *) &data, (unsigned int) sizeof(data)); #endif return TRUE; } - return FALSE; + return FALSE; } -long xvt_fmap_get_family_sizes(PRINT_RCD *precp, char *family, long *size_array, BOOLEAN *scalable, long max_sizes) -{ +long xvt_fmap_get_family_sizes(PRINT_RCD *precp, char *family, long *size_array, BOOLEAN *scalable, long max_sizes) +{ long size = 1; size_array[0] = 13; *scalable = FALSE; -#ifdef WIN32 if (precp != NULL) { +#ifdef WIN32 TwxPrintOut* po = new TwxPrintOut((TPRINT_RCD*)precp); + size = OsWin32_EnumerateSizes(po->GetDC()->GetHDC(), family, size_array, scalable, max_sizes); +#else + size = OsLinux_EnumerateSizes(family, size_array, scalable, max_sizes); +#endif } -#endif - return size; + return size; } -long xvt_fmap_get_families(PRINT_RCD *precp, char **family_array, long max_families) -{ +long xvt_fmap_get_families(PRINT_RCD *precp, char **family_array, long max_families) +{ long size = 1; family_array[0] = xvt_str_duplicate(XVT_FFN_COURIER); -#ifdef WIN32 if (precp != NULL) { +#ifdef WIN32 TwxPrintOut* po = new TwxPrintOut((TPRINT_RCD*)precp); + size = OsWin32_EnumerateFamilies(po->GetDC()->GetHDC(), family_array, max_families); +#else + size = OsLinux_EnumerateFamilies(family_array, max_families); +#endif } -#endif - return size; + return size; } -void xvt_print_close(void) -{ +void xvt_print_close(void) +{ // Nothing to do ? } -BOOLEAN xvt_print_close_page(PRINT_RCD* /*precp*/) -{ +BOOLEAN xvt_print_close_page(PRINT_RCD* /*precp*/) +{ BOOLEAN ok = m_po != NULL; if (ok) m_po->GetDC()->EndPage(); - return ok; + return ok; } -PRINT_RCD* xvt_print_create(int *sizep) -{ +PRINT_RCD* xvt_print_create(int *sizep) +{ TPRINT_RCD* pr = NULL; *sizep = 0; @@ -258,19 +271,26 @@ PRINT_RCD* xvt_print_create(int *sizep) void* data = OsWin32_GetPrinterInfo(*sizep, NULL); if (data != NULL) { - pr = new TPRINT_RCD; + pr = new TPRINT_RCD; pr->SetData(data, *sizep); *sizep += 4; // Spazio per puntatore iniziale delete data; } +#else + wxPrinter printer; + wxPrintData &data = printer.GetPrintDialogData().GetPrintData(); + + data.SetPrinterName(""); //verificare + pr = new TPRINT_RCD; + pr->SetData((void *) &data, (unsigned int) sizeof(data)); #endif return pr; } // Nuova funzione inventata da Aga -PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name) -{ +PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name) +{ TPRINT_RCD* pr = NULL; *sizep = 0; @@ -278,37 +298,45 @@ PRINT_RCD* xvt_print_create_by_name(int* sizep, const char* name) void* data = OsWin32_GetPrinterInfo(*sizep, name); if (data != NULL) { - pr = new TPRINT_RCD; + pr = new TPRINT_RCD; pr->SetData(data, *sizep); *sizep += 4; // Spazio per puntatore iniziale delete data; } +#else + wxPrinter printer; + wxPrintData &data = printer.GetPrintDialogData().GetPrintData(); + wxString PrinterName(name); + + data.SetPrinterName(PrinterName); //verificare + pr = new TPRINT_RCD; + pr->SetData((void *) &data, (unsigned int) sizeof(data)); #endif return pr; } -WINDOW xvt_print_create_win(PRINT_RCD* precp, char* /* title */) -{ +WINDOW xvt_print_create_win(PRINT_RCD* precp, char* /* title */) +{ WINDOW win = NULL_WIN; if (m_po != NULL) { m_po->InitDC((TPRINT_RCD*)precp); m_po->OnBeginPrinting(); m_po->OnBeginDocument(1, 32000); - win = _print_win; + win = _print_win; } return win; } -void xvt_print_destroy(PRINT_RCD *precp) -{ +void xvt_print_destroy(PRINT_RCD *precp) +{ // Nothing to do! } -RCT* xvt_print_get_next_band(void) -{ +RCT* xvt_print_get_next_band(void) +{ static bool yes = false; static RCT rct; yes = !yes; @@ -322,30 +350,31 @@ RCT* xvt_print_get_next_band(void) rct.right = w; rct.bottom = h; - return &rct; + return &rct; } -BOOLEAN xvt_print_is_valid(PRINT_RCD* precp) -{ +BOOLEAN xvt_print_is_valid(PRINT_RCD* precp) +{ BOOLEAN ok = precp != NULL && precp->pr == NULL; if (ok) { #ifdef WIN32 TPRINT_RCD* rcd = (TPRINT_RCD*)precp; ok = OsWin32_CheckPrinterInfo(rcd->m_data, rcd->m_size); +#else + // verificare (c'e' da fare qualcosa ?) #endif } - return ok; + return ok; } -BOOLEAN xvt_print_open(void) -{ - return m_po == NULL; +BOOLEAN xvt_print_open(void) +{ + return m_po == NULL; } -BOOLEAN xvt_print_start_thread(BOOLEAN(*print_fcn)(long), long data) -{ - wxWindow* tw = (wxWindow*)TASK_WIN; +BOOLEAN xvt_print_start_thread(BOOLEAN(*print_fcn)(long), long data) +{ m_po = new TwxPrintOut; print_fcn(data); @@ -357,20 +386,31 @@ BOOLEAN xvt_print_start_thread(BOOLEAN(*print_fcn)(long), long data) return TRUE; } -BOOLEAN xvt_print_open_page(PRINT_RCD* precp) -{ +BOOLEAN xvt_print_open_page(PRINT_RCD* precp) +{ BOOLEAN ok = m_po != NULL; if (ok) { m_po->GetDC()->StartPage(); } - return ok; + return ok; } /////////////////////////////////////////////////////////// // Added by XVAGA /////////////////////////////////////////////////////////// +#ifdef LINUX +static bool is_cups() +{ + static int printer_system = -1; + + if (printer_system < 0) + printer_system = xvt_fsys_file_exists("/etc/cups/printer.conf") ? 1 : 2; + return (printer_system == 1); +} +#endif + SLIST xvt_print_list_devices() { SLIST list = xvt_slist_create(); @@ -381,19 +421,75 @@ SLIST xvt_print_list_devices() for (int i = 0; i < sizeof(buf); i++) if (buf[i] == '\0') { const char* pname = buf+start; - if (*pname == '\0') + if (*pname == '\0') break; xvt_slist_add_at_elt(list, NULL, pname, NULL); start = i+1; } #else - xvt_slist_add_at_elt(list, NULL, "/dev/prn", NULL); // TBI + if (is_cups()) + { + ifstream p("/etc/cups/printer.conf"); // vedere + char line[4096]; + + while (p.getline(line, sizeof(line))) + { + if (line[0] == '<') + { + char * s = strstr(line, "Printer") ; + + if (s != NULL) + { + s += 7; + + while (isspace(*s)) + s++; + + if (*s) + { + char * l = s + strlen(s) - 1; + + while (isspace(*l)) + l--; + *(l + 1) = '\0'; + xvt_slist_add_at_elt(list, NULL, s, 0L); + } + } + } + } + } + else + { + ifstream p("/etc/printcap"); // vedere + char line[4096]; + + while (p.getline(line, sizeof(line))) + { + if (line[0] != '#') + { + const int len = strlen(line); + int i; + + for (i = 0; i < len; i++) + { + const char c = line[i]; + + if (!(isalpha(c) || isdigit(c) || isblank(c))) + break; + } + line[i] = '\0'; + xvt_slist_add_at_elt(list, NULL, line, 0L); + } + } + } + + #endif return list; } BOOLEAN xvt_print_set_default_device(const char* name) -{ +{ BOOLEAN ok = name && *name > ' '; #ifdef WIN32 if (ok) @@ -401,24 +497,59 @@ BOOLEAN xvt_print_set_default_device(const char* name) wxString pdev(name); if (pdev.Find(',') < 0) { - char szDevice[256]; + char szDevice[256]; ::GetProfileString ("devices", pdev, "", szDevice, sizeof(szDevice)); pdev << ',' << szDevice; - } - ok = ::WriteProfileString("windows", "device", pdev) != 0; + } + ok = ::WriteProfileString("windows", "device", pdev) != 0; } -#endif - return ok; -} - -BOOLEAN xvt_print_get_default_device(char* name, int namesize) -{ - bool ok = TRUE; -#ifdef WIN32 - ok = ::GetProfileString ("windows", "device", ",,,", name, namesize) != 0; #else - strcpy(name, "/dev/prn"); + SORRY_BOX(); //verificare #endif return ok; } +BOOLEAN xvt_print_get_default_device(char* name, int namesize) +{ + bool ok = FALSE; +#ifdef WIN32 + ok = ::GetProfileString ("windows", "device", ",,,", name, namesize) != 0; +#else + *name = '\0'; + if (is_cups()) + { + ifstream p("/etc/cups/printer.conf"); // vedere + char line[4096]; + + while (p.getline(line, sizeof(line))) + { + if (line[0] == '<') + { + char * s = strstr(line, "ltPrinter") ; + + if (s != NULL) + { + s += 9; + + while (isspace(*s)) + s++; + + if (*s) + { + char * l = s + strlen(s) - 1; + + while (isspace(*l)) + l--; + *(l + 1) = '\0'; + strcpy(name, s); + } + ok = TRUE; + } + } + } + } +#endif + + return ok; +} +