X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bdc72a22686ac141e9bc4559a1171d017fdcb094..585266618c27ac77a5e5316c03e06ffc514715c9:/src/msw/utils.cpp diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 53db01e6d8..634668dd77 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); } @@ -388,29 +436,14 @@ wxChar *wxGetUserHome(const wxString& user) bool wxDirExists(const wxString& dir) { #if defined(__WIN32__) - WIN32_FIND_DATA fileInfo; + DWORD attribs = GetFileAttributes(dir); + return ((attribs != -1) && (attribs & FILE_ATTRIBUTE_DIRECTORY)); #else // Win16 #ifdef __BORLANDC__ struct ffblk fileInfo; #else struct find_t fileInfo; #endif -#endif // Win32/16 - -#if defined(__WIN32__) - HANDLE h = ::FindFirstFile(dir, &fileInfo); - - if ( h == INVALID_HANDLE_VALUE ) - { - wxLogLastError("FindFirstFile"); - - return FALSE; - } - - ::FindClose(h); - - return (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; -#else // Win16 // In Borland findfirst has a different argument // ordering from _dos_findfirst. But _dos_findfirst // _should_ be ok in both MS and Borland... why not? @@ -454,7 +487,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; } // ---------------------------------------------------------------------------- @@ -543,7 +576,7 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) *majorVsn = info.dwMajorVersion; if (minorVsn) *minorVsn = info.dwMinorVersion; - + switch ( info.dwPlatformId ) { case VER_PLATFORM_WIN32s: @@ -806,10 +839,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) { @@ -857,8 +895,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. @@ -876,7 +912,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__ @@ -893,6 +936,8 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc // get display info // ---------------------------------------------------------------------------- +// See also the wxGetMousePosition in window.cpp +// Deprecated: use wxPoint wxGetMousePosition() instead void wxGetMousePosition( int* x, int* y ) { POINT pt; @@ -926,6 +971,15 @@ void wxDisplaySize(int *width, int *height) if ( height ) *height = GetDeviceCaps(dc, VERTRES); } +void wxDisplaySizeMM(int *width, int *height) +{ + ScreenHDC dc; + + if ( width ) *width = GetDeviceCaps(dc, HORZSIZE); + if ( height ) *height = GetDeviceCaps(dc, VERTSIZE); +} + + // --------------------------------------------------------------------------- // window information functions // --------------------------------------------------------------------------- @@ -992,6 +1046,8 @@ WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) #endif // Win16/32 } +#endif // wxUSE_GUI + #if 0 //------------------------------------------------------------------------ // wild character routines @@ -1149,7 +1205,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) return ((*str == '\0') && (*pattern == '\0')); }; -#endif +#endif // 0 #if 0