X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e6feb95a79834836e88143b15d9f424ebe79621..2fe212b0336512aac9eace69fab09ce856b0bf4b:/src/msw/utils.cpp diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index dea7aeb352..d34d0ede3e 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -31,9 +31,11 @@ #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/app.h" - #include "wx/cursor.h" #include "wx/intl.h" #include "wx/log.h" +#if wxUSE_GUI + #include "wx/cursor.h" +#endif #endif //WX_PRECOMP // In some mingws there is a missing extern "C" int the winsock header, @@ -41,7 +43,7 @@ // #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__)) +#if defined(__WIN32__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) extern "C" { #include // we use socket functions in wxGetFullHostName() } @@ -51,7 +53,7 @@ extern "C" { #include "wx/timer.h" -#if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__) +#if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__) && !defined(__WXMICROWIN__) #include #ifndef __MWERKS__ @@ -80,7 +82,7 @@ extern "C" { #include #endif // USE_NET_API -#if defined(__WIN32__) && !defined(__WXWINE__) +#if defined(__WIN32__) && !defined(__WXWINE__) && !defined(__WXMICROWIN__) #include #ifndef __GNUWIN32__ @@ -131,11 +133,13 @@ static const wxChar WX_SECTION[] = wxT("wxWindows"); static const wxChar eUSERNAME[] = wxT("UserName"); // these are only used under Win16 -#ifndef __WIN32__ +#if !defined(__WIN32__) && !defined(__WXMICROWIN__) static const wxChar eHOSTNAME[] = wxT("HostName"); static const wxChar eUSERID[] = wxT("UserId"); #endif // !Win32 +#ifndef __WXMICROWIN__ + // ============================================================================ // implementation // ============================================================================ @@ -147,7 +151,7 @@ static const wxChar eUSERID[] = wxT("UserId"); // Get hostname only (without domain name) bool wxGetHostName(wxChar *buf, int maxSize) { -#if defined(__WIN32__) && !defined(__TWIN32__) +#if defined(__WIN32__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__) DWORD nSize = maxSize; if ( !::GetComputerName(buf, &nSize) ) { @@ -173,7 +177,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__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) +#if defined(__WIN32__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__)) // TODO should use GetComputerNameEx() when available WSADATA wsa; if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) @@ -218,7 +222,7 @@ bool wxGetFullHostName(wxChar *buf, int maxSize) // Get user ID e.g. jacs bool wxGetUserId(wxChar *buf, int maxSize) { -#if defined(__WIN32__) && !defined(__win32s__) && !defined(__TWIN32__) +#if defined(__WIN32__) && !defined(__win32s__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__) DWORD nSize = maxSize; if ( ::GetUserName(buf, &nSize) == 0 ) { @@ -423,7 +427,9 @@ wxChar *wxGetUserHome(const wxString& WXUNUSED(user)) bool wxDirExists(const wxString& dir) { -#if defined(__WIN32__) +#ifdef __WXMICROWIN__ + return wxPathExist(dir); +#elif defined(__WIN32__) DWORD attribs = GetFileAttributes(dir); return ((attribs != (DWORD)-1) && (attribs & FILE_ATTRIBUTE_DIRECTORY)); #else // Win16 @@ -445,6 +451,99 @@ bool wxDirExists(const wxString& dir) #endif // Win32/16 } +bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) +{ + if ( path.empty() ) + return FALSE; + +#ifdef __WIN32__ + // GetDiskFreeSpaceEx() is not available under original Win95, check for + // it + typedef BOOL (*GetDiskFreeSpaceEx_t)(LPCTSTR, + PULARGE_INTEGER, + PULARGE_INTEGER, + PULARGE_INTEGER); + + GetDiskFreeSpaceEx_t + pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress + ( + ::GetModuleHandle(_T("kernel32.dll")), +#if wxUSE_UNICODE + "GetDiskFreeSpaceExW" +#else + "GetDiskFreeSpaceExA" +#endif + ); + + if ( pGetDiskFreeSpaceEx ) + { + ULARGE_INTEGER bytesFree, bytesTotal; + + // may pass the path as is, GetDiskFreeSpaceEx() is smart enough + if ( !pGetDiskFreeSpaceEx(path, + &bytesFree, + &bytesTotal, + NULL) ) + { + wxLogLastError(_T("GetDiskFreeSpaceEx")); + + return FALSE; + } + + if ( pTotal ) + { + *pTotal = wxLongLong(bytesTotal.HighPart, bytesTotal.LowPart); + } + + if ( pFree ) + { + *pFree = wxLongLong(bytesFree.HighPart, bytesFree.LowPart); + } + } + else +#endif // Win32 + { + // there's a problem with drives larger than 2GB, GetDiskFreeSpaceEx() + // should be used instead - but if it's not available, fall back on + // GetDiskFreeSpace() nevertheless... + + DWORD lSectorsPerCluster, + lBytesPerSector, + lNumberOfFreeClusters, + lTotalNumberOfClusters; + + // FIXME: this is wrong, we should extract the root drive from path + // instead, but this is the job for wxFileName... + if ( !::GetDiskFreeSpace(path, + &lSectorsPerCluster, + &lBytesPerSector, + &lNumberOfFreeClusters, + &lTotalNumberOfClusters) ) + { + wxLogLastError(_T("GetDiskFreeSpace")); + + return FALSE; + } + + wxLongLong lBytesPerCluster = lSectorsPerCluster; + lBytesPerCluster *= lBytesPerSector; + + if ( pTotal ) + { + *pTotal = lBytesPerCluster; + *pTotal *= lTotalNumberOfClusters; + } + + if ( pFree ) + { + *pFree = lBytesPerCluster; + *pFree *= lNumberOfFreeClusters; + } + } + + return TRUE; +} + // ---------------------------------------------------------------------------- // env vars // ---------------------------------------------------------------------------- @@ -926,6 +1025,8 @@ void wxSleep(int nSecs) } #endif // wxUSE_GUI/!wxUSE_GUI +#endif + // __WXMICROWIN__ // ---------------------------------------------------------------------------- // deprecated (in favour of wxLog) log functions @@ -934,6 +1035,7 @@ void wxSleep(int nSecs) #if wxUSE_GUI // Output a debug mess., in a system dependent fashion. +#ifndef __WXMICROWIN__ void wxDebugMsg(const wxChar *fmt ...) { va_list ap; @@ -965,6 +1067,7 @@ void wxFatalError(const wxString& msg, const wxString& title) wxSprintf(wxBuffer, wxT("%s: %s"), WXSTRINGCAST title, WXSTRINGCAST msg); FatalAppExit(0, (LPCTSTR)wxBuffer); } +#endif // __WXMICROWIN__ // ---------------------------------------------------------------------------- // functions to work with .INI files @@ -1091,7 +1194,9 @@ void wxBeginBusyCursor(wxCursor *cursor) if ( gs_wxBusyCursorCount++ == 0 ) { gs_wxBusyCursor = (HCURSOR)cursor->GetHCURSOR(); +#ifndef __WXMICROWIN__ gs_wxBusyCursorOld = ::SetCursor(gs_wxBusyCursor); +#endif } //else: nothing to do, already set } @@ -1104,8 +1209,9 @@ void wxEndBusyCursor() if ( --gs_wxBusyCursorCount == 0 ) { +#ifndef __WXMICROWIN__ ::SetCursor(gs_wxBusyCursorOld); - +#endif gs_wxBusyCursorOld = 0; } } @@ -1135,6 +1241,7 @@ bool wxCheckForInterrupt(wxWindow *wnd) // MSW only: get user-defined resource from the .res file. // Returns NULL or newly-allocated memory, so use delete[] to clean up. +#ifndef __WXMICROWIN__ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType) { HRSRC hResource = ::FindResource(wxGetInstance(), resourceName, resourceType); @@ -1168,6 +1275,7 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc return s; } +#endif // ---------------------------------------------------------------------------- // get display info @@ -1186,6 +1294,10 @@ void wxGetMousePosition( int* x, int* y ) // Return TRUE if we have a colour display bool wxColourDisplay() { +#ifdef __WXMICROWIN__ + // MICROWIN_TODO + return TRUE; +#else // 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 // @@ -1202,6 +1314,7 @@ bool wxColourDisplay() } return s_isColour != 0; +#endif } // Returns depth of screen @@ -1214,23 +1327,37 @@ int wxDisplayDepth() // Get size of display void wxDisplaySize(int *width, int *height) { +#ifdef __WXMICROWIN__ + RECT rect; + HWND hWnd = GetDesktopWindow(); + ::GetWindowRect(hWnd, & rect); + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; +#else ScreenHDC dc; if ( width ) *width = GetDeviceCaps(dc, HORZRES); if ( height ) *height = GetDeviceCaps(dc, VERTRES); +#endif } void wxDisplaySizeMM(int *width, int *height) { +#ifdef __WXMICROWIN__ + // MICROWIN_TODO + *width = 0; * height = 0; +#else ScreenHDC dc; if ( width ) *width = GetDeviceCaps(dc, HORZSIZE); if ( height ) *height = GetDeviceCaps(dc, VERTSIZE); +#endif } void wxClientDisplayRect(int *x, int *y, int *width, int *height) { -#ifdef __WIN16__ +#if defined(__WIN16__) || defined(__WXMICROWIN__) *x = 0; *y = 0; wxDisplaySize(width, height); #else @@ -1263,6 +1390,10 @@ wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd) wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd) { +#ifdef __WXMICROWIN__ + // MICROWIN_TODO + return wxEmptyString; +#else wxString str; int len = 256; // some starting value @@ -1302,6 +1433,7 @@ wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd) } return str; +#endif } WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) @@ -1576,4 +1708,13 @@ void wxRedirectIOToConsole() } #endif +#ifdef __WXMICROWIN__ +int wxGetOsVersion(int *majorVsn, int *minorVsn) +{ + // MICROWIN_TODO + if (majorVsn) *majorVsn = 0; + if (minorVsn) *minorVsn = 0; + return wxUNIX; +} +#endif