X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b568d04ffa191f9e3b643ca33526094eca0ba304..6342bd1ab36c1957684c00d408d09fba65d33db6:/src/msw/utils.cpp?ds=sidebyside diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index d2a2872995..14346f1413 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: mse/utils.cpp +// Name: msw/utils.cpp // Purpose: Various utilities // Author: Julian Smart // Modified by: @@ -32,12 +32,24 @@ #include "wx/utils.h" #include "wx/app.h" #include "wx/cursor.h" + #include "wx/intl.h" + #include "wx/log.h" #endif //WX_PRECOMP +// In some mingws there is a missing extern "C" int the winsock header, +// so we put it here just to be safe. Note that this must appear _before_ +// #include "wx/msw/private.h" which itself includes , as this +// one in turn includes unless we define WIN32_LEAN_AND_MEAN. +// +#if defined(__WIN32__) && !defined(__TWIN32__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) +extern "C" { + #include // we use socket functions in wxGetFullHostName() +} +#endif + #include "wx/msw/private.h" // includes #include "wx/timer.h" -#include "wx/intl.h" #include @@ -54,8 +66,6 @@ #include #endif //GNUWIN32 -#include "wx/log.h" - #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs // this (3.1 I believe) and how to test for it. // If this works for Borland 4.0 as well, then no worries. @@ -117,7 +127,7 @@ #endif # if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS -# define new new(__FILE__,__LINE__) +# define new new(__TFILE__,__LINE__) # endif #endif @@ -146,16 +156,14 @@ static const wxChar eUSERID[] = wxT("UserId"); // get host name and related // ---------------------------------------------------------------------------- -// Get full hostname (eg. DoDo.BSn-Germany.crg.de) +// Get hostname only (without domain name) bool wxGetHostName(wxChar *buf, int maxSize) { #if defined(__WIN32__) && !defined(__TWIN32__) - // TODO should use GetComputerNameEx() when available - DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { - wxLogLastError("GetComputerName"); + wxLogLastError(wxT("GetComputerName")); return FALSE; } @@ -174,8 +182,48 @@ bool wxGetHostName(wxChar *buf, int maxSize) #endif } +// get full hostname (with domain name if possible) bool wxGetFullHostName(wxChar *buf, int maxSize) { +#if defined(__WIN32__) && !defined(__TWIN32__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) + // TODO should use GetComputerNameEx() when available + WSADATA wsa; + if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) + { + wxString host; + char bufA[256]; + if ( gethostname(bufA, WXSIZEOF(bufA)) == 0 ) + { + // gethostname() won't usually include the DNS domain name, for + // this we need to work a bit more + if ( !strchr(bufA, '.') ) + { + struct hostent *pHostEnt = gethostbyname(bufA); + + if ( pHostEnt ) + { + // Windows will use DNS internally now + pHostEnt = gethostbyaddr(pHostEnt->h_addr, 4, PF_INET); + } + + if ( pHostEnt ) + { + host = pHostEnt->h_name; + } + } + } + + WSACleanup(); + + if ( !!host ) + { + wxStrncpy(buf, host, maxSize); + + return TRUE; + } + } +#endif // Win32 + return wxGetHostName(buf, maxSize); } @@ -402,7 +450,7 @@ bool wxDirExists(const wxString& dir) if ( h == INVALID_HANDLE_VALUE ) { - wxLogLastError("FindFirstFile"); + wxLogLastError(wxT("FindFirstFile")); return FALSE; } @@ -454,7 +502,7 @@ bool wxShell(const wxString& command) cmd.Printf(wxT("%s /c %s"), shell, command.c_str()); } - return wxExecute(cmd, FALSE) != 0; + return wxExecute(cmd, TRUE /* sync */) != 0; } // ---------------------------------------------------------------------------- @@ -480,50 +528,101 @@ void wxBell() ::MessageBeep((UINT)-1); // default sound } -// Chris Breeze 27/5/98: revised WIN32 code to -// detect WindowsNT correctly -int wxGetOsVersion(int *majorVsn, int *minorVsn) +wxString wxGetOsDescription() { - if (majorVsn) *majorVsn = 0; - if (minorVsn) *minorVsn = 0; +#ifdef __WIN32__ + wxString str; + + OSVERSIONINFO info; + wxZeroMemory(info); + + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if ( ::GetVersionEx(&info) ) + { + switch ( info.dwPlatformId ) + { + case VER_PLATFORM_WIN32s: + str = _("Win32s on Windows 3.1"); + break; + + case VER_PLATFORM_WIN32_WINDOWS: + str.Printf(_("Windows 9%c"), + info.dwMinorVersion == 0 ? _T('5') : _T('9')); + if ( !wxIsEmpty(info.szCSDVersion) ) + { + str << _T(" (") << info.szCSDVersion << _T(')'); + } + break; + + case VER_PLATFORM_WIN32_NT: + str.Printf(_T("Windows NT %lu.%lu (build %lu"), + info.dwMajorVersion, + info.dwMinorVersion, + info.dwBuildNumber); + if ( !wxIsEmpty(info.szCSDVersion) ) + { + str << _T(", ") << info.szCSDVersion; + } + str << _T(')'); + break; + } + } + else + { + wxFAIL_MSG( _T("GetVersionEx() failed") ); // should never happen + } + + return str; +#else // Win16 + return _("Windows 3.1"); +#endif // Win32/16 +} +int wxGetOsVersion(int *majorVsn, int *minorVsn) +{ #if defined(__WIN32__) && !defined(__SC__) - OSVERSIONINFO info; - memset(&info, 0, sizeof(OSVERSIONINFO)); - info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (GetVersionEx(&info)) - { - if (majorVsn) *majorVsn = info.dwMajorVersion; - if (minorVsn) *minorVsn = info.dwMinorVersion; - switch (info.dwPlatformId) - { - case VER_PLATFORM_WIN32s: - return wxWIN32S; - break; - case VER_PLATFORM_WIN32_WINDOWS: - return wxWIN95; - break; - case VER_PLATFORM_WIN32_NT: - return wxWINDOWS_NT; - break; - } - } - return wxWINDOWS; // error if we get here, return generic value -#else - // Win16 code... - int retValue = 0; -# ifdef __WINDOWS_386__ - retValue = wxWIN386; -# else -# if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS - extern HANDLE g_hPenWin; - retValue = g_hPenWin ? wxPENWINDOWS : wxWINDOWS ; -# endif -# endif - // @@@@ To be completed. I don't have the manual here... - if (majorVsn) *majorVsn = 3 ; - if (minorVsn) *minorVsn = 1 ; - return retValue ; + OSVERSIONINFO info; + wxZeroMemory(info); + + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if ( ::GetVersionEx(&info) ) + { + if (majorVsn) + *majorVsn = info.dwMajorVersion; + if (minorVsn) + *minorVsn = info.dwMinorVersion; + + switch ( info.dwPlatformId ) + { + case VER_PLATFORM_WIN32s: + return wxWIN32S; + + case VER_PLATFORM_WIN32_WINDOWS: + return wxWIN95; + + case VER_PLATFORM_WIN32_NT: + return wxWINDOWS_NT; + } + } + + return wxWINDOWS; // error if we get here, return generic value +#else // Win16 + int retValue = wxWINDOWS; + #ifdef __WINDOWS_386__ + retValue = wxWIN386; + #else + #if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS + extern HANDLE g_hPenWin; + retValue = g_hPenWin ? wxPENWINDOWS : wxWINDOWS; + #endif + #endif + + if (majorVsn) + *majorVsn = 3; + if (minorVsn) + *minorVsn = 1; + + return retValue; #endif } @@ -755,10 +854,15 @@ bool wxGetResource(const wxString& section, const wxString& entry, int *value, c // helper functions for showing a "busy" cursor // --------------------------------------------------------------------------- -HCURSOR gs_wxBusyCursor = 0; // new, busy cursor -HCURSOR gs_wxBusyCursorOld = 0; // old cursor +static HCURSOR gs_wxBusyCursor = 0; // new, busy cursor +static HCURSOR gs_wxBusyCursorOld = 0; // old cursor static int gs_wxBusyCursorCount = 0; +extern HCURSOR wxGetCurrentBusyCursor() +{ + return gs_wxBusyCursor; +} + // Set the cursor to the busy cursor for all windows void wxBeginBusyCursor(wxCursor *cursor) { @@ -806,8 +910,6 @@ bool wxCheckForInterrupt(wxWindow *wnd) return TRUE; } -#endif // wxUSE_GUI - // MSW only: get user-defined resource from the .res file. // Returns NULL or newly-allocated memory, so use delete[] to clean up. @@ -825,7 +927,14 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc if ( !theText ) return NULL; - wxChar *s = copystring(theText); + // Not all compilers put a zero at the end of the resource (e.g. BC++ doesn't). + // so we need to find the length of the resource. + int len = ::SizeofResource(wxGetInstance(), hResource); + wxChar *s = new wxChar[len+1]; + wxStrncpy(s,theText,len); + s[len]=0; + + // wxChar *s = copystring(theText); // Obsolete in WIN32 #ifndef __WIN32__ @@ -941,6 +1050,8 @@ WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) #endif // Win16/32 } +#endif // wxUSE_GUI + #if 0 //------------------------------------------------------------------------ // wild character routines @@ -1098,7 +1209,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) return ((*str == '\0') && (*pattern == '\0')); }; -#endif +#endif // 0 #if 0