From 17dff81c7141e142765b168ab225e5c61475669f Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 1 Jan 1999 16:22:21 +0000 Subject: [PATCH] mac support as stubs added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1303 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/confbase.h | 4 + include/wx/defs.h | 5 + include/wx/filefn.h | 9 ++ include/wx/generic/msgdlgg.h | 2 +- include/wx/msgdlg.h | 2 +- include/wx/socket.h | 5 + include/wx/string.h | 11 +++ include/wx/taskbar.h | 1 + include/wx/wx_cw.h | 50 ++++------ include/wx/wx_cw_d.h | 62 ++++-------- src/common/dynlib.cpp | 29 +++++- src/common/file.cpp | 9 +- src/common/fileconf.cpp | 2 + src/common/filefn.cpp | 114 ++++++++++++++++++++- src/common/ftp.cpp | 4 + src/common/log.cpp | 6 ++ src/common/sckaddr.cpp | 8 ++ src/common/socket.cpp | 185 ++++++++++++++++++++++++++++++----- src/common/timercmn.cpp | 2 + src/common/utilscmn.cpp | 30 ++++++ src/msw/dib.cpp | 2 + src/msw/dibutils.cpp | 2 + src/msw/minifram.cpp | 2 +- src/msw/tbarmsw.cpp | 2 + src/msw/textctrl.cpp | 4 + src/msw/timer.cpp | 2 +- src/msw/utils.cpp | 6 +- src/msw/utilsexc.cpp | 2 + 28 files changed, 458 insertions(+), 104 deletions(-) diff --git a/include/wx/confbase.h b/include/wx/confbase.h index 604e78fe36..3c4773b05a 100644 --- a/include/wx/confbase.h +++ b/include/wx/confbase.h @@ -222,7 +222,11 @@ public: protected: static bool IsImmutable(const wxString& key) + #ifndef __WXMAC__ { return !key.IsEmpty() && key[0u] == wxCONFIG_IMMUTABLE_PREFIX; } + #else + { return !key.IsEmpty() && key[0ul] == wxCONFIG_IMMUTABLE_PREFIX; } + #endif private: // are we doing automatic environment variable expansion? diff --git a/include/wx/defs.h b/include/wx/defs.h index e68ab2cc01..d906f09812 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -306,6 +306,11 @@ WXDLLEXPORT_DATA(extern const bool) wxFalse; #undef except #undef finally #define except(x) catch(...) +#elif defined(__MWERKS__) +#undef try +#undef except +#undef finally +#define except(x) catch(...) #endif // where should i put this? we need to make sure of this as it breaks diff --git a/include/wx/filefn.h b/include/wx/filefn.h index b9c92f21f0..3ce7a54ac2 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -23,7 +23,11 @@ // ---------------------------------------------------------------------------- // define off_t +#ifndef __WXMAC__ #include +#else +typedef long off_t; +#endif #ifdef _MSC_VER #define off_t _off_t @@ -77,6 +81,11 @@ WXDLLEXPORT void wxDos2UnixFilename(char *s); WXDLLEXPORT void wxUnix2DosFilename(char *s); #define Unix2DosFilename wxUnix2DosFilename +#ifdef __WXMAC__ + WXDLLEXPORT void wxMacPathToFSSpec( const char *path , FSSpec *spec ) ; + WXDLLEXPORT void wxMac2UnixFilename(char *s); + WXDLLEXPORT void wxUnix2MacFilename(char *s); +#endif // Strip the extension, in situ WXDLLEXPORT void wxStripExtension(char *buffer); WXDLLEXPORT void wxStripExtension(wxString& buffer); diff --git a/include/wx/generic/msgdlgg.h b/include/wx/generic/msgdlgg.h index 84a58194f8..c9f3778037 100644 --- a/include/wx/generic/msgdlgg.h +++ b/include/wx/generic/msgdlgg.h @@ -40,7 +40,7 @@ public: DECLARE_EVENT_TABLE() }; -#ifndef __WXMSW__ +#if !defined( __WXMSW__ ) && !defined( __WXMAC__) #define wxMessageDialog wxGenericMessageDialog int wxMessageBox(const wxString& message, const wxString& caption = wxMessageBoxCaptionStr, diff --git a/include/wx/msgdlg.h b/include/wx/msgdlg.h index 81aba4972c..e0f80d630c 100644 --- a/include/wx/msgdlg.h +++ b/include/wx/msgdlg.h @@ -10,7 +10,7 @@ #elif defined(__WXQT__) #include "wx/generic/msgdlgg.h" #elif defined(__WXMAC__) -#include "wx/generic/msgdlgg.h" +#include "wx/mac/msgdlg.h" #elif defined(__WXSTUBS__) #include "wx/generic/msgdlgg.h" #endif diff --git a/include/wx/socket.h b/include/wx/socket.h index 49db4403d1..99422550b4 100644 --- a/include/wx/socket.h +++ b/include/wx/socket.h @@ -80,6 +80,9 @@ class WXDLLEXPORT wxSocketHandler; class WXDLLEXPORT wxSocketBase : public wxEvtHandler { DECLARE_CLASS(wxSocketBase) +#ifdef __WXMAC__ +friend void wxMacSocketOnRequestProc(void *refcon , short event) ; +#endif public: enum wxSockFlags { NONE=0, NOWAIT=1, WAITALL=2, SPEED=4 }; @@ -329,6 +332,8 @@ public: typedef void (wxEvtHandler::*wxSocketEventFunction)(wxSocketEvent&); +#define wxEVT_SOCKET wxEVT_FIRST+301 + #define EVT_SOCKET(id, func) { wxEVT_SOCKET, id, 0, \ (wxObjectEventFunction) (wxEventFunction) (wxSocketEventFunction) & func, \ (wxObject *) NULL }, diff --git a/include/wx/string.h b/include/wx/string.h index 9e7a4fe95b..0e8abe5d27 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -22,6 +22,9 @@ * stdarg.h * limits.h */ +#ifdef __WXMAC__ +#include +#endif #include #include #include @@ -93,6 +96,14 @@ inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2) return stricmp(psz1, psz2); #elif defined(__UNIX__) || defined(__GNUWIN32__) return strcasecmp(psz1, psz2); +#elif defined(__MWERKS__) && !defined(_MSC_VER) + register char c1, c2; + do { + c1 = tolower(*psz1++); + c2 = tolower(*psz2++); + } while ( c1 && (c1 == c2) ); + + return c1 - c2; #else // almost all compilers/libraries provide this function (unfortunately under // different names), that's why we don't implement our own which will surely diff --git a/include/wx/taskbar.h b/include/wx/taskbar.h index 1e78999d42..614edbb655 100644 --- a/include/wx/taskbar.h +++ b/include/wx/taskbar.h @@ -8,6 +8,7 @@ #elif defined(__WXGTK__) #elif defined(__WXQT__) #elif defined(__WXMAC__) +#include "wx/mac/taskbar.h" #elif defined(__WXSTUBS__) #include "wx/stubs/taskbar.h" #endif diff --git a/include/wx/wx_cw.h b/include/wx/wx_cw.h index 7702030a3d..c8bf670a26 100644 --- a/include/wx/wx_cw.h +++ b/include/wx/wx_cw.h @@ -11,38 +11,28 @@ #ifndef _WX_CW__ #define _WX_CW__ -#define MSL_USE_PRECOMPILED_HEADERS 1 -#if !defined( __MWERKS__ ) - #error "this file is only for builds with Metrowerks CodeWarrior" -#endif - -#define WX_COMP_INLINE_NO_CLASS // defined if the compiler does not want the classname repeated for inlines within a class definition - -#if (__MWERKS__ < 0x0900) || macintosh - #define __MAC__ - #define __WXMAC__ - #define USE_PRECOMPILED_MAC_HEADERS 1 /*Set to 0 if you don't want to use precompiled MacHeaders*/ - #include - #define WX_PRECOMP -// automatically includes MacHeaders -#elif (__MWERKS__ >= 0x0900) && __INTEL__ - #define __WXMSW__ - #define __WINDOWS__ - #define __WIN95__ - #define STRICT - #define NOMINMAX - #include -#elif __BEOS__ - #include - #include -#else - #error unknown MW compiler +#ifdef __cplusplus + #if __POWERPC__ + #include + #elif __INTEL__ + #include + #elif __CFM68K__ + #include + #else + #include + #endif +#else + #if __POWERPC__ + #include + #elif __INTEL__ + #include + #elif __CFM68K__ + #include + #else + #include + #endif #endif -// in order to avoid problems further down in wxWindows - -char *strdup(const char *s) ; - #endif // _WX_CW__ diff --git a/include/wx/wx_cw_d.h b/include/wx/wx_cw_d.h index 275e130219..f56d8cdc0a 100644 --- a/include/wx/wx_cw_d.h +++ b/include/wx/wx_cw_d.h @@ -12,49 +12,27 @@ #ifndef _WX_CW__ #define _WX_CW__ -#define MSL_USE_PRECOMPILED_HEADERS 1 - -#if !defined( __MWERKS__ ) - #error "this file is only for builds with Metrowerks CodeWarrior" -#endif - -#define WX_COMP_INLINE_NO_CLASS // defined if the compiler does not want the classname repeated for inlines within a class definition - -#if (__MWERKS__ < 0x0900) || macintosh - #define __MAC__ - #define __WXMAC__ - #define USE_PRECOMPILED_MAC_HEADERS 1 /*Set to 0 if you don't want to use precompiled MacHeaders*/ - #include - #define WX_PRECOMP - // automatically includes MacHeaders -#elif (__MWERKS__ >= 0x0900) && __INTEL__ - #define __WXMSW__ - #define __WINDOWS__ - #define __WIN95__ - #define STRICT - #define NOMINMAX - #include -// #include -// #include -#elif __BEOS__ - #include - #include -#else - #error unknown MW compiler -#endif - -#define __WXDEBUG__ -#define USE_DEFINE -// in order to avoid problems further down in wxWindows - -#ifdef __cplusplus -extern "C" -{ -#endif - char *strdup(const char *s) ; - int isascii( int c ) ; #ifdef __cplusplus -} ; + #if __POWERPC__ + #include + #elif __INTEL__ + #include + #elif __CFM68K__ + #include + #else + #include + #endif +#else + #if __POWERPC__ + #include + #elif __INTEL__ + #include + #elif __CFM68K__ + #include + #else + #include + #endif #endif + #endif // _WX_CW__ diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index cab20994b9..6b8bf78e38 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -117,9 +117,20 @@ void *wxLibrary::GetSymbol(const wxString& symbname) { #if defined(__UNIX__) return dlsym(m_handle, WXSTRINGCAST symbname); -#endif -#ifdef __WINDOWS__ +#elif defined( __WINDOWS__ ) return GetProcAddress((HINSTANCE) m_handle, WXSTRINGCAST symbname); +#elif defined( __WXMAC__ ) + Ptr symAddress ; + CFragSymbolClass symClass ; + Str255 symName ; + + strcpy( (char*) symName , symbname ) ; + c2pstr( (char*) symName ) ; + + if ( FindSymbol( (CFragConnectionID) m_handle , symName , &symAddress , &symClass ) == noErr ) + { + return symAddress ; + } #endif return NULL; } @@ -184,6 +195,20 @@ wxLibrary *wxLibraries::LoadLibrary(const wxString& name) #endif if (!handle) return NULL; +#elif defined(__WXMAC__) + FSSpec myFSSpec ; + CFragConnectionID handle ; + Ptr myMainAddr ; + Str255 myErrName ; + + wxMacPathToFSSpec( lib_name , &myFSSpec ) ; + if (GetDiskFragment( &myFSSpec , 0 , kCFragGoesToEOF , "\p" , kPrivateCFragCopy , &handle , &myMainAddr , + myErrName ) != noErr ) + { + p2cstr( myErrName ) ; + wxASSERT_MSG( 1 , (char*)myErrName ) ; + return NULL ; + } #else return NULL; #endif diff --git a/src/common/file.cpp b/src/common/file.cpp index 61e0b07afb..30bc2d13d7 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -56,6 +56,13 @@ #elif (defined(__WXSTUBS__)) // Have to ifdef this for different environments #include +#elif (defined(__WXMAC__)) + int access( const char *path, int mode ) { return 0 ; } + char* mktemp( char * path ) { return path ;} + #include + #include + #define W_OK 2 + #define R_OK 4 #else #error "Please specify the header with file functions declarations." #endif //Win/UNIX @@ -443,7 +450,7 @@ bool wxTempFile::Open(const wxString& strName) // otherwise rename() in Commit() might not work (if the files are on // different partitions for example). Unfortunately, the only standard // (POSIX) temp file creation function tmpnam() can't do it. - #if defined(__UNIX__) || defined(__WXSTUBS__) + #if defined(__UNIX__) || defined(__WXSTUBS__)|| defined( __WXMAC__ ) static const char *szMktempSuffix = "XXXXXX"; m_strTemp << strName << szMktempSuffix; mktemp((char *)m_strTemp.c_str()); // will do because length doesn't change diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 92ca337641..1baee8911e 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -97,6 +97,8 @@ wxString wxFileConfig::GetGlobalDir() strDir = "/etc/"; #elif defined(__WXSTUBS__) wxASSERT_MSG( FALSE, "TODO" ) ; + #elif defined(__WXMAC__) + wxASSERT_MSG( FALSE, "TODO" ) ; #else // Windows char szWinDir[MAX_PATH]; ::GetWindowsDirectory(szWinDir, MAX_PATH); diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index e8d93b2cf5..af885044bd 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -88,6 +88,11 @@ #define _MAXPATHLEN 500 extern char *wxBuffer; +#ifdef __WXMAC__ +extern char gwxMacFileName[] ; +extern char gwxMacFileName2[] ; +extern char gwxMacFileName3[] ; +#endif #if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) @@ -147,7 +152,7 @@ bool wxPathList::Member (const wxString& path) { wxString path2((char *) node->Data ()); if ( -#if defined(__WINDOWS__) || defined(__VMS__) +#if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__) // Case INDEPENDENT path.CompareTo (path2, wxString::ignoreCase) == 0 #else @@ -225,6 +230,13 @@ wxFileExists (const wxString& filename) return FALSE; else return TRUE; +#elif defined(__WXMAC__) + struct stat stbuf; + strcpy( gwxMacFileName , filename ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + if (gwxMacFileName && stat ((char *)(const char *)gwxMacFileName, &stbuf) == 0) + return TRUE; + return FALSE ; #else struct stat stbuf; @@ -738,6 +750,58 @@ wxString wxPathOnly (const wxString& path) // and back again - or we get nasty problems with delimiters. // Also, convert to lower case, since case is significant in UNIX. +#ifdef __WXMAC__ +void +wxMac2UnixFilename (char *s) +{ + if (s) + { + memmove( s+1 , s ,strlen( s ) + 1) ; + if ( *s == ':' ) + *s = '.' ; + else + *s = '/' ; + + while (*s) + { + if (*s == ':') + *s = '/'; + else + *s = wxToLower (*s); // Case INDEPENDENT + s++; + } + } +} + +void +wxUnix2MacFilename (char *s) +{ + if (s) + { + if ( *s == '.' ) + { + // relative path , since it goes on with slash which is translated to a : + memmove( s , s+1 ,strlen( s ) ) ; + } + else if ( *s == '/' ) + { + // absolute path -> on mac just start with the drive name + memmove( s , s+1 ,strlen( s ) ) ; + } + else + { + wxASSERT_MSG( 1 , "unkown path beginning" ) ; + } + while (*s) + { + if (*s == '/' || *s == '\\') + *s = ':'; + + s++ ; + } + } +} +#endif void wxDos2UnixFilename (char *s) { @@ -783,9 +847,22 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil FILE *fp2 = (FILE *) NULL; FILE *fp3 = (FILE *) NULL; // Open the inputs and outputs +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + strcpy( gwxMacFileName3 , outfile) ; + wxUnix2MacFilename( gwxMacFileName3 ) ; + + if ((fp1 = fopen (gwxMacFileName, "rb")) == NULL || + (fp2 = fopen (gwxMacFileName2, "rb")) == NULL || + (fp3 = fopen (gwxMacFileName3, "wb")) == NULL) +#else if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL || (fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL || (fp3 = fopen (outfile, "wb")) == NULL) +#endif { if (fp1) fclose (fp1); @@ -819,9 +896,20 @@ wxCopyFile (const wxString& file1, const wxString& file2) FILE *fd2; int ch; +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + + if ((fd1 = fopen (gwxMacFileName, "rb")) == NULL) + return FALSE; + if ((fd2 = fopen (gwxMacFileName2, "wb")) == NULL) +#else if ((fd1 = fopen (WXSTRINGCAST file1, "rb")) == NULL) return FALSE; if ((fd2 = fopen (WXSTRINGCAST file2, "wb")) == NULL) +#endif { fclose (fd1); return FALSE; @@ -838,9 +926,19 @@ wxCopyFile (const wxString& file1, const wxString& file2) bool wxRenameFile (const wxString& file1, const wxString& file2) { +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + + if (0 == rename (gwxMacFileName, gwxMacFileName2)) + return TRUE; +#else // Normal system call if (0 == rename (WXSTRINGCAST file1, WXSTRINGCAST file2)) return TRUE; +#endif // Try to copy if (wxCopyFile(file1, file2)) { wxRemoveFile(file1); @@ -854,6 +952,10 @@ bool wxRemoveFile(const wxString& file) { #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) int flag = remove(WXSTRINGCAST file); +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , file ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + int flag = unlink(gwxMacFileName); #else int flag = unlink(WXSTRINGCAST file); #endif @@ -866,6 +968,10 @@ bool wxMkdir(const wxString& dir) return FALSE; #elif defined(__VMS__) return FALSE; +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , dir ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + return (mkdir(gwxMacFileName , 0 ) == 0); #elif (defined(__GNUWIN32__) && !defined(__MINGW32__)) || !defined(__WXMSW__) return (mkdir (WXSTRINGCAST dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0); #else @@ -877,6 +983,10 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #ifdef __VMS__ return FALSE; +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , dir ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + return (rmdir(WXSTRINGCAST gwxMacFileName) == 0); #else return (rmdir(WXSTRINGCAST dir) == 0); #endif @@ -1278,7 +1388,7 @@ char *wxGetWorkingDirectory(char *buf, int sz) bool wxSetWorkingDirectory(const wxString& d) { -#ifdef __UNIX__ +#if defined( __UNIX__ ) || defined( __WXMAC__ ) return (chdir(d) == 0); #elif defined(__WINDOWS__) diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp index ee2ac234d5..920e50e2cc 100644 --- a/src/common/ftp.cpp +++ b/src/common/ftp.cpp @@ -23,6 +23,10 @@ #ifndef __MWERKS__ #include #endif +#if defined(__WXMAC__) +#include "/wx/mac/macsock.h" +#endif + #include #include "wx/string.h" #include "wx/utils.h" diff --git a/src/common/log.cpp b/src/common/log.cpp index db45214b9e..f92320b0f8 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -944,6 +944,12 @@ void Trap() DebugBreak(); #elif defined(__WXSTUBS__) // TODO + #elif defined(__WXMAC__) + #if __powerc + Debugger(); + #else + SysBreak(); + #endif #else // Unix raise(SIGTRAP); #endif // Win/Unix diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index d681261969..b61afc01a4 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -33,6 +33,10 @@ #include "wx/defs.h" #include "wx/object.h" +#if defined(__WXMAC__) +#include "/wx/mac/macsock.h" +#endif + #if defined(__WINDOWS__) #include #endif // __WINDOWS__ @@ -121,7 +125,11 @@ bool wxIPV4address::Hostname(const wxString& name) return FALSE; } } else { +#ifdef __WXMAC__ + long len_addr = inet_addr(name.GetData()).s_addr ; +#else long len_addr = inet_addr(name.GetData()); +#endif if (len_addr == -1) return FALSE; m_addr->sin_addr.s_addr = len_addr; diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 82f44c03c5..124df43951 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -15,6 +15,10 @@ // #pragma implementation "socket.cpp" #endif +#ifdef __MWERKS__ +typedef int socklen_t ; +#endif + // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -41,6 +45,33 @@ ///////////////////////////////////////////////////////////////////////////// // System specific headers ///////////////////////////////////////////////////////////////////////////// +#ifdef __WXMAC__ +// in order to avoid problems with our c library and double definitions +#define close closesocket +#define ioctl ioctlsocket + +#include +extern GUSISpinFn GUSISpin; +#define PROCESS_EVENTS() wxMacProcessEvents() +const short kwxMacNetEventsMax = 1000 ; +short wxMacNetEventsTop = 0 ; +short wxMacNetEventsBottom = 0 ; +short wxMacNetEventsEvents[kwxMacNetEventsMax] ; +void *wxMacNetEventsReferences[kwxMacNetEventsMax] ; + +#define FD_READ 1 +#define FD_WRITE 2 +#define FD_CLOSE 4 +#define FD_ACCEPT 8 +#define FD_CONNECT 16 +#define FD_READY 32 + +extern "C" void wxMacSocketHandlerProc( void *refcon , short event ) ; // adds events +extern "C" void wxMacSocketOnRequestProc( void *refcon , short event ) ; // consumes them +extern "C" void GUSISetReference( short sock , short eventmask , void * data ) ; +void wxMacProcessEvents() ; +#endif + #if defined(__WINDOWS__) #include #endif // __WINDOWS__ @@ -129,15 +160,15 @@ #if defined( NEED_WSAFDIsSet ) || defined( _MSC_VER ) int PASCAL FAR __WSAFDIsSet(SOCKET fd, fd_set FAR *set) { - int i = set->fd_count; + int i = set->fd_count; - while (i--) - { - if (set->fd_array[i] == fd) - return 1; - } + while (i--) + { + if (set->fd_array[i] == fd) + return 1; + } - return 0; + return 0; } #endif #endif @@ -218,7 +249,7 @@ public: // --------- wxSocketBase CONSTRUCTOR --------------------------- // -------------------------------------------------------------- wxSocketBase::wxSocketBase(wxSocketBase::wxSockFlags _flags, - wxSocketBase::wxSockType _type) : + wxSocketBase::wxSockType _type) : wxEvtHandler(), m_flags(_flags), m_type(_type), m_connected(FALSE), m_connecting(FALSE), m_fd(INVALID_SOCKET), m_waitflags(0), m_cbk(0), m_cdata(0), m_id(-1), @@ -624,7 +655,7 @@ bool wxSocketBase::WaitForLost(long seconds, long microseconds) #if defined(__WXMOTIF__) || defined(__WXXT__) || defined(__WXGTK__) #if defined(__WXMOTIF__) || defined(__WXXT__) static void wx_socket_read(XtPointer client, int *fid, - XtInputId *WXUNUSED(id)) + XtInputId *WXUNUSED(id)) #define fd *fid #else static void wx_socket_read(gpointer client, gint fd, @@ -668,10 +699,10 @@ static void wx_socket_read(gpointer client, gint fd, #if defined(__WXMOTIF__) || defined(__WXXT__) static void wx_socket_write(XtPointer client, int *WXUNUSED(fid), - XtInputId *WXUNUSED(id)) + XtInputId *WXUNUSED(id)) #else static void wx_socket_write(gpointer client, gint WXUNUSED(fd), - GdkInputCondition WXUNUSED(cond)) + GdkInputCondition WXUNUSED(cond)) #endif { wxSocketBase *sock = (wxSocketBase *)client; @@ -795,7 +826,6 @@ void wxSocketBase::SetupCallbacks() if (m_fd == INVALID_SOCKET || !m_handler || (m_flags & SPEED)) return; - #if defined(__WXMOTIF__) || defined(__WXXT__) if (m_neededreq & (REQ_ACCEPT | REQ_READ | REQ_LOST)) { @@ -894,6 +924,24 @@ void wxSocketBase::SetupCallbacks() if (!m_internal->my_msg) m_internal->my_msg = m_handler->NewMessage(this); WSAAsyncSelect(m_fd, m_handler->GetHWND(), m_internal->my_msg, mask); +#endif +#ifdef __WXMAC__ + short mask = 0; + + if (m_neededreq & REQ_READ) + mask |= FD_READ; + if (m_neededreq & REQ_WRITE) + mask |= FD_WRITE; + if (m_neededreq & REQ_LOST) + mask |= FD_CLOSE; + if (m_neededreq & REQ_ACCEPT) + mask |= FD_ACCEPT; + if (m_neededreq & REQ_CONNECT) + mask |= FD_CONNECT; + + GUSISetReference( m_fd ,mask, this ) ; + unsigned long flag = 1; + ioctl(m_fd, FIONBIO, &flag); #endif m_cbkon = TRUE; m_processing = FALSE; @@ -925,6 +973,20 @@ void wxSocketBase::DestroyCallbacks() #ifdef __WINDOWS__ WSAAsyncSelect(m_fd, m_handler->GetHWND(), 0, 0); #endif +#ifdef __WXMAC__ + GUSISetReference( m_fd , 0 , 0 ) ; + int bottom = wxMacNetEventsBottom ; + while ( wxMacNetEventsTop != bottom ) + { + // set all events that reference this socket to nil + if ( wxMacNetEventsReferences[bottom] == (void*) this ) + wxMacNetEventsReferences[bottom] = NULL ; + bottom++ ; + if ( bottom == kwxMacNetEventsMax ) + bottom = 0 ; + } + SetFlags( m_flags ) ; +#endif } void wxSocketBase::Notify(bool notify) @@ -1173,7 +1235,7 @@ void wxSocketBase::WantSpeedBuffer(char *buffer, size_t nbytes, } void wxSocketBase::WantBuffer(char *buffer, size_t nbytes, - wxRequestEvent evt) + wxRequestEvent evt) { bool buf_timed_out; @@ -1230,7 +1292,7 @@ void wxSocketBase::WantBuffer(char *buffer, size_t nbytes, // -------------------------------------------------------------- wxSocketServer::wxSocketServer(wxSockAddress& addr_man, - wxSockFlags flags) : + wxSockFlags flags) : wxSocketBase(flags, SOCK_SERVER) { m_fd = socket(addr_man.GetFamily(), SOCK_STREAM, 0); @@ -1321,7 +1383,7 @@ void wxSocketServer::OnRequest(wxRequestEvent evt) // --------- wxSocketClient CONSTRUCTOR ------------------------- // -------------------------------------------------------------- wxSocketClient::wxSocketClient(wxSockFlags _flags) : - wxSocketBase(_flags, SOCK_CLIENT) + wxSocketBase(_flags, SOCK_CLIENT) { } @@ -1430,6 +1492,64 @@ static int win_initialized = 0; // -------------------------------------------------------------- // --------- wxSocketHandler CONSTRUCTOR ------------------------ // -------------------------------------------------------------- +#ifdef __WXMAC__ + +extern "C" int updatestatus(int s) ; + +void wxMacSocketOnRequestProc( void *refcon , short event ) +{ + if ( refcon ) + { + wxSocketBase *sock = (wxSocketBase *) refcon ; + + wxSocketBase::wxRequestEvent sk_req; + + int canRead ; + int canWrite ; + int exception ; + + switch (event) { + case FD_READ: + sk_req = wxSocketBase::EVT_READ; + sock->OnRequest(sk_req); + break; + case FD_WRITE: + sk_req = wxSocketBase::EVT_WRITE; + sock->OnRequest(sk_req); + break; + case FD_CLOSE: + sk_req = wxSocketBase::EVT_LOST; + sock->OnRequest(sk_req); + break; + case FD_ACCEPT: + sk_req = wxSocketBase::EVT_ACCEPT; + sock->OnRequest(sk_req); + break; + case FD_CONNECT: + sk_req = wxSocketBase::EVT_CONNECT; + sock->OnRequest(sk_req); + break; + case FD_READY : + break ; + } + updatestatus ( sock->m_fd ) ; + } +} + +void wxMacSocketHandlerProc( void *refcon , short event ) +{ + wxMacNetEventsReferences[wxMacNetEventsTop] = refcon ; + wxMacNetEventsEvents[wxMacNetEventsTop] = event ; + + // clumsy construct in order to never have a incorrect wxMacNetEventsTop (above limits) + + if ( wxMacNetEventsTop + 1 == kwxMacNetEventsMax ) + wxMacNetEventsTop = 0 ; + else + wxMacNetEventsTop++ ; +} + +#endif #ifdef __WINDOWS__ extern char wxPanelClassName[]; @@ -1439,8 +1559,8 @@ LRESULT APIENTRY _EXPORT wxSocketHandlerWndProc(HWND hWnd, UINT message, { if(message==WM_DESTROY) { - ::SetWindowLong(hWnd, GWL_WNDPROC, (LONG) DefWindowProc); - return DefWindowProc(hWnd, message, wParam, lParam); + ::SetWindowLong(hWnd, GWL_WNDPROC, (LONG) DefWindowProc); + return DefWindowProc(hWnd, message, wParam, lParam); } wxSocketHandler *h_sock = (wxSocketHandler *)GetWindowLong(hWnd, GWL_USERDATA); wxNode *node = h_sock->smsg_list->Find(message); @@ -1491,8 +1611,8 @@ wxSocketHandler::wxSocketHandler() } internal = new wxSockHandlerInternal; internal->sockWin = ::CreateWindow(wxPanelClassName, NULL, 0, - 0, 0, 0, 0, NULL, (HMENU) NULL, - wxhInstance, 0); + 0, 0, 0, 0, NULL, (HMENU) NULL, + wxhInstance, 0); // Subclass the window if (!wxSocketSubClassProc) @@ -1592,8 +1712,8 @@ unsigned long wxSocketHandler::Count() const // --------- wxSocketHandler "big" wait functions --------------- // -------------------------------------------------------------- void handler_cbk(wxSocketBase& sock, - wxSocketBase::wxRequestEvent WXUNUSED(flags), - char *cdata) + wxSocketBase::wxRequestEvent WXUNUSED(flags), + char *cdata) { int *a_wait = (int *)cdata; @@ -1662,7 +1782,7 @@ void wxSocketHandler::YieldSock() // --------- wxSocketHandler: create and register the socket ---- // -------------------------------------------------------------- wxSocketServer *wxSocketHandler::CreateServer(wxSockAddress& addr, - wxSocketBase::wxSockFlags flags) + wxSocketBase::wxSockFlags flags) { wxSocketServer *serv = new wxSocketServer(addr, flags); @@ -1715,5 +1835,26 @@ void wxSocketModule::OnExit() wxSocketHandler::master = NULL; } +#ifdef __WXMAC__ +void wxMacProcessSocketEvents() ; +void wxMacProcessEvents() +{ + wxMacProcessSocketEvents() ; + (*GUSISpin)(SP_MISC, 0) ; +} + +void wxMacProcessSocketEvents() +{ + while ( wxMacNetEventsTop != wxMacNetEventsBottom ) + { + // consume event at wxMacNetEventsBottom + wxMacSocketOnRequestProc(wxMacNetEventsReferences[wxMacNetEventsBottom] , wxMacNetEventsEvents[wxMacNetEventsBottom] ) ; + wxMacNetEventsBottom++ ; + if ( wxMacNetEventsBottom == kwxMacNetEventsMax ) + wxMacNetEventsBottom = 0 ; + } +} +#endif + #endif // __WXSTUBS__ diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index f3fdb5b041..ca30cb5be1 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -33,7 +33,9 @@ #endif #include +#ifndef __WXMAC__ #include +#endif #if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)) || defined(__MINGW32__) #include diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index c5e8204954..f516c32e43 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -72,6 +72,36 @@ extern char *wxBuffer; +#ifdef __WXMAC__ +int strcasecmp(const char *str_1, const char *str_2) +{ + register char c1, c2; + do { + c1 = tolower(*str_1++); + c2 = tolower(*str_2++); + } while ( c1 && (c1 == c2) ); + + return c1 - c2; +} + +int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) +{ + + register char c1, c2; + while( maxchar--) + { + c1 = tolower(*str_1++); + c2 = tolower(*str_2++); + + if ( !c1 || c1!=c2 ) + return c1 - c2; + + } ; + + return 0 ; + +} +#endif #ifdef __VMS__ // we have no strI functions under VMS, therefore I have implemented // an inefficient but portable version: convert copies of strings to lowercase diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 4694f6b261..ac6bffe7dd 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -40,7 +40,9 @@ #include #include #include +#ifndef __MWERKS__ #include +#endif #include "wx/msw/dib.h" diff --git a/src/msw/dibutils.cpp b/src/msw/dibutils.cpp index b337129663..5ad72da4f4 100644 --- a/src/msw/dibutils.cpp +++ b/src/msw/dibutils.cpp @@ -32,7 +32,9 @@ #include #if defined(__WIN32__) +#ifndef __MWERKS__ #include // for _fmemcpy() +#endif #define _huge #ifndef hmemcpy #define hmemcpy memcpy diff --git a/src/msw/minifram.cpp b/src/msw/minifram.cpp index c8c1ad14b5..8039c2fd78 100644 --- a/src/msw/minifram.cpp +++ b/src/msw/minifram.cpp @@ -88,7 +88,7 @@ wxMiniFrame::~wxMiniFrame(void) #include -#ifndef __WATCOMC__ +#if !defined( __WATCOMC__ ) && !defined( __MWERKS__ ) #include #endif diff --git a/src/msw/tbarmsw.cpp b/src/msw/tbarmsw.cpp index 99104456ff..aed6d11a74 100644 --- a/src/msw/tbarmsw.cpp +++ b/src/msw/tbarmsw.cpp @@ -30,7 +30,9 @@ #include "malloc.h" #endif +#ifndef __MWERKS__ #include +#endif #include #include "wx/tbarmsw.h" diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 0f5afa110a..13d6c08be1 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -45,7 +45,11 @@ #endif #include +#ifndef __MWERKS__ #include +#else +#include +#endif #if defined(__BORLANDC__) && !defined(__WIN32__) #include #else diff --git a/src/msw/timer.cpp b/src/msw/timer.cpp index 7a12dc3c2d..d655f2805e 100644 --- a/src/msw/timer.cpp +++ b/src/msw/timer.cpp @@ -35,7 +35,7 @@ #include #include -#if !defined(__SC__) && !defined(__GNUWIN32__) +#if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__) #include #endif diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 3a114037d9..6cf42a49ca 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -36,7 +36,9 @@ #ifndef __GNUWIN32__ #include +#ifndef __MWERKS__ #include +#endif #endif //GNUWIN32 #ifdef __GNUWIN32__ @@ -979,7 +981,9 @@ To download dbwin32, see e.g.: http://ftp.digital.com/pub/micro/NT/WinSite/programr/dbwin32.zip */ +#ifndef __MWERKS__ #include +#endif void OutputDebugStringW95(const char* lpOutputString, ...) { @@ -1056,7 +1060,7 @@ void OutputDebugStringW95(const char* lpOutputString, ...) WaitForSingleObject(heventDBWIN, INFINITE); /* write it to the shared memory */ -#ifdef __BORLANDC__ +#if defined( __BORLANDC__ ) || defined( __MWERKS__ ) *((LPDWORD)lpszSharedMem) = getpid(); #else *((LPDWORD)lpszSharedMem) = _getpid(); diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index aae349314d..4140571003 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -34,8 +34,10 @@ #ifndef __GNUWIN32__ #include +#ifndef __MWERKS__ #include #endif +#endif #ifdef __GNUWIN32__ #include -- 2.45.2