X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0500b3ee1255cc71624bc58b83d0d954b2d45e..ed8fad817a4c951b0a3c07b8a086a874dc435591:/src/msw/utils.cpp diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 56413e0523..e32d27860f 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -36,6 +36,17 @@ #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" @@ -61,10 +72,6 @@ #include #endif -#if defined(__WIN32__) && !defined(__TWIN32__) - #include // we use socket functions in wxGetFullHostName() -#endif - // VZ: there is some code using NetXXX() functions to get the full user name: // I don't think it's a good idea because they don't work under Win95 and // seem to return the same as wxGetUserId() under NT. If you really want @@ -120,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 @@ -156,7 +163,7 @@ bool wxGetHostName(wxChar *buf, int maxSize) DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { - wxLogLastError("GetComputerName"); + wxLogLastError(wxT("GetComputerName")); return FALSE; } @@ -178,7 +185,7 @@ bool wxGetHostName(wxChar *buf, int maxSize) // get full hostname (with domain name if possible) bool wxGetFullHostName(wxChar *buf, int maxSize) { -#if defined(__WIN32__) && !defined(__TWIN32__) +#if defined(__WIN32__) && !defined(__TWIN32__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) // TODO should use GetComputerNameEx() when available WSADATA wsa; if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) @@ -416,7 +423,7 @@ const wxChar* wxGetHomeDir(wxString *pstr) return strDir.c_str(); } -wxChar *wxGetUserHome(const wxString& user) +wxChar *wxGetUserHome(const wxString& WXUNUSED(user)) { // VZ: the old code here never worked for user != "" anyhow! Moreover, it // returned sometimes a malloc()'d pointer, sometimes a pointer to a @@ -429,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 != (DWORD)-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? @@ -465,11 +457,52 @@ bool wxDirExists(const wxString& dir) #endif // Win32/16 } +// ---------------------------------------------------------------------------- +// env vars +// ---------------------------------------------------------------------------- + +bool wxGetEnv(const wxString& var, wxString *value) +{ + // first get the size of the buffer + DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0); + if ( !dwRet ) + { + // this means that there is no such variable + return FALSE; + } + + if ( value ) + { + (void)::GetEnvironmentVariable(var, value->GetWriteBuf(dwRet), dwRet); + value->UngetWriteBuf(); + } + + return TRUE; +} + +bool wxSetEnv(const wxString& var, const wxChar *value) +{ + // some compilers have putenv() or _putenv() or _wputenv() but it's better + // to always use Win32 function directly instead of dealing with them +#if defined(__WIN32__) + if ( !::SetEnvironmentVariable(var, value) ) + { + wxLogLastError(_T("SetEnvironmentVariable")); + + return FALSE; + } + + return TRUE; +#else // no way to set env vars + return FALSE; +#endif +} + // ---------------------------------------------------------------------------- // process management // ---------------------------------------------------------------------------- -int wxKill(long pid, int sig) +int wxKill(long WXUNUSED(pid), int WXUNUSED(sig)) { // TODO use SendMessage(WM_QUIT) and TerminateProcess() if needed @@ -540,7 +573,7 @@ wxString wxGetOsDescription() case VER_PLATFORM_WIN32_WINDOWS: str.Printf(_("Windows 9%c"), - info.dwMinorVersion == 0 ? _T('5') : _T('9')); + info.dwMinorVersion == 0 ? _T('5') : _T('8')); if ( !wxIsEmpty(info.szCSDVersion) ) { str << _T(" (") << info.szCSDVersion << _T(')'); @@ -903,8 +936,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. @@ -946,6 +977,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; @@ -957,10 +990,22 @@ void wxGetMousePosition( int* x, int* y ) // Return TRUE if we have a colour display bool wxColourDisplay() { - ScreenHDC dc; - int noCols = GetDeviceCaps(dc, NUMCOLORS); + // this function is called from wxDC ctor so it is called a *lot* of times + // hence we optimize it a bit but doign the check only once + // + // this should be MT safe as only the GUI thread (holding the GUI mutex) + // can call us + static int s_isColour = -1; + + if ( s_isColour == -1 ) + { + ScreenHDC dc; + int noCols = ::GetDeviceCaps(dc, NUMCOLORS); + + s_isColour = (noCols == -1) || (noCols > 2); + } - return (noCols == -1) || (noCols > 2); + return s_isColour != 0; } // Returns depth of screen @@ -979,6 +1024,27 @@ 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); +} + +void wxClientDisplayRect(int *x, int *y, int *width, int *height) +{ + // Determine the desktop dimensions minus the taskbar and any other + // special decorations... + RECT r; + SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); + if (x) *x = r.left; + if (y) *y = r.top; + if (width) *width = r.right - r.left; + if (height) *height = r.bottom - r.top; +} + + // --------------------------------------------------------------------------- // window information functions // --------------------------------------------------------------------------- @@ -1039,12 +1105,14 @@ wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd) WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) { #ifndef __WIN32__ - return GetWindowWord((HWND)hWnd, GWW_ID); + return (WXWORD)GetWindowWord((HWND)hWnd, GWW_ID); #else // Win32 - return GetWindowLong((HWND)hWnd, GWL_ID); + return (WXWORD)GetWindowLong((HWND)hWnd, GWL_ID); #endif // Win16/32 } +#endif // wxUSE_GUI + #if 0 //------------------------------------------------------------------------ // wild character routines @@ -1202,7 +1270,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) return ((*str == '\0') && (*pattern == '\0')); }; -#endif +#endif // 0 #if 0