#include "wx/log.h"
#endif //WX_PRECOMP
+#include "wx/apptrait.h"
+
#include "wx/msw/private.h" // includes <windows.h>
#ifdef __GNUWIN32_OLD__
#endif
#endif
+// ----------------------------------------------------------------------------
+// module globals
+// ----------------------------------------------------------------------------
+
+#if wxUSE_ON_FATAL_EXCEPTION
+ static bool gs_handleExceptions = FALSE;
+#endif
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// Get user name e.g. Julian Smart
bool wxGetUserName(wxChar *buf, int maxSize)
{
-#if wxUSE_PENWINDOWS && !defined(__WATCOMC__) && !defined(__GNUWIN32__)
- extern HANDLE g_hPenWin; // PenWindows Running?
- if (g_hPenWin)
- {
- // PenWindows Does have a user concept!
- // Get the current owner of the recognizer
- GetPrivateProfileString("Current", "User", default_name, wxBuffer, maxSize - 1, "PENWIN.INI");
- strncpy(buf, wxBuffer, maxSize - 1);
- }
- else
-#endif
- {
#ifdef USE_NET_API
- CHAR szUserName[256];
- if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) )
- return FALSE;
+ CHAR szUserName[256];
+ if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) )
+ return FALSE;
- // TODO how to get the domain name?
- CHAR *szDomain = "";
+ // TODO how to get the domain name?
+ CHAR *szDomain = "";
- // the code is based on the MSDN example (also see KB article Q119670)
- WCHAR wszUserName[256]; // Unicode user name
- WCHAR wszDomain[256];
- LPBYTE ComputerName;
+ // the code is based on the MSDN example (also see KB article Q119670)
+ WCHAR wszUserName[256]; // Unicode user name
+ WCHAR wszDomain[256];
+ LPBYTE ComputerName;
- USER_INFO_2 *ui2; // User structure
+ USER_INFO_2 *ui2; // User structure
- // Convert ANSI user name and domain to Unicode
- MultiByteToWideChar( CP_ACP, 0, szUserName, strlen(szUserName)+1,
- wszUserName, WXSIZEOF(wszUserName) );
- MultiByteToWideChar( CP_ACP, 0, szDomain, strlen(szDomain)+1,
- wszDomain, WXSIZEOF(wszDomain) );
+ // Convert ANSI user name and domain to Unicode
+ MultiByteToWideChar( CP_ACP, 0, szUserName, strlen(szUserName)+1,
+ wszUserName, WXSIZEOF(wszUserName) );
+ MultiByteToWideChar( CP_ACP, 0, szDomain, strlen(szDomain)+1,
+ wszDomain, WXSIZEOF(wszDomain) );
- // Get the computer name of a DC for the domain.
- if ( NetGetDCName( NULL, wszDomain, &ComputerName ) != NERR_Success )
- {
- wxLogError(wxT("Can not find domain controller"));
+ // Get the computer name of a DC for the domain.
+ if ( NetGetDCName( NULL, wszDomain, &ComputerName ) != NERR_Success )
+ {
+ wxLogError(wxT("Can not find domain controller"));
- goto error;
- }
+ goto error;
+ }
- // Look up the user on the DC
- NET_API_STATUS status = NetUserGetInfo( (LPWSTR)ComputerName,
- (LPWSTR)&wszUserName,
- 2, // level - we want USER_INFO_2
- (LPBYTE *) &ui2 );
- switch ( status )
- {
- case NERR_Success:
- // ok
- break;
+ // Look up the user on the DC
+ NET_API_STATUS status = NetUserGetInfo( (LPWSTR)ComputerName,
+ (LPWSTR)&wszUserName,
+ 2, // level - we want USER_INFO_2
+ (LPBYTE *) &ui2 );
+ switch ( status )
+ {
+ case NERR_Success:
+ // ok
+ break;
- case NERR_InvalidComputer:
- wxLogError(wxT("Invalid domain controller name."));
+ case NERR_InvalidComputer:
+ wxLogError(wxT("Invalid domain controller name."));
- goto error;
+ goto error;
- case NERR_UserNotFound:
- wxLogError(wxT("Invalid user name '%s'."), szUserName);
+ case NERR_UserNotFound:
+ wxLogError(wxT("Invalid user name '%s'."), szUserName);
- goto error;
+ goto error;
- default:
- wxLogSysError(wxT("Can't get information about user"));
+ default:
+ wxLogSysError(wxT("Can't get information about user"));
- goto error;
- }
+ goto error;
+ }
- // Convert the Unicode full name to ANSI
- WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1,
- buf, maxSize, NULL, NULL );
+ // Convert the Unicode full name to ANSI
+ WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1,
+ buf, maxSize, NULL, NULL );
- return TRUE;
+ return TRUE;
error:
- wxLogError(wxT("Couldn't look up full user name."));
+ wxLogError(wxT("Couldn't look up full user name."));
- return FALSE;
+ return FALSE;
#else // !USE_NET_API
- // Could use NIS, MS-Mail or other site specific programs
- // Use wxWindows configuration data
- bool ok = GetProfileString(WX_SECTION, eUSERNAME, wxT(""), buf, maxSize - 1) != 0;
- if ( !ok )
- {
- ok = wxGetUserId(buf, maxSize);
- }
+ // Could use NIS, MS-Mail or other site specific programs
+ // Use wxWindows configuration data
+ bool ok = GetProfileString(WX_SECTION, eUSERNAME, wxT(""), buf, maxSize - 1) != 0;
+ if ( !ok )
+ {
+ ok = wxGetUserId(buf, maxSize);
+ }
- if ( !ok )
- {
- wxStrncpy(buf, wxT("Unknown User"), maxSize);
- }
-#endif // Win32/16
+ if ( !ok )
+ {
+ wxStrncpy(buf, wxT("Unknown User"), maxSize);
}
+#endif // Win32/16
return TRUE;
}
#endif // Win32/16
}
-int wxGetOsVersion(int *majorVsn, int *minorVsn)
+int wxAppTraits::GetOSVersion(int *verMaj, int *verMin)
{
-#if defined(__WIN32__)
- static int ver = -1, major = -1, minor = -1;
+ // cache the version info, it's not going to change
+ //
+ // NB: this is MT-safe, we may use these static vars from different threads
+ // but as they always have the same value it doesn't matter
+ static int s_ver = -1,
+ s_major = -1,
+ s_minor = -1;
- if ( ver == -1 )
+ if ( s_ver == -1 )
{
OSVERSIONINFO info;
wxZeroMemory(info);
- ver = wxWINDOWS;
+ s_ver = wxWINDOWS;
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if ( ::GetVersionEx(&info) )
{
- major = info.dwMajorVersion;
- minor = info.dwMinorVersion;
+ s_major = info.dwMajorVersion;
+ s_minor = info.dwMinorVersion;
switch ( info.dwPlatformId )
{
case VER_PLATFORM_WIN32s:
- ver = wxWIN32S;
+ s_ver = wxWIN32S;
break;
case VER_PLATFORM_WIN32_WINDOWS:
- ver = wxWIN95;
+ s_ver = wxWIN95;
break;
case VER_PLATFORM_WIN32_NT:
- ver = wxWINDOWS_NT;
+ s_ver = wxWINDOWS_NT;
break;
}
}
}
- if (majorVsn && major != -1)
- *majorVsn = major;
- if (minorVsn && minor != -1)
- *minorVsn = minor;
-
- return ver;
-#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;
+ if ( verMaj )
+ *verMaj = s_major;
+ if ( verMin )
+ *verMin = s_minor;
- return retValue;
-#endif
+ return s_ver;
}
// ----------------------------------------------------------------------------
// font encoding <-> Win32 codepage conversion functions
// ----------------------------------------------------------------------------
-extern long wxEncodingToCharset(wxFontEncoding encoding)
+extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding)
{
switch ( encoding )
{
case wxFONTENCODING_CP437:
return OEM_CHARSET;
- }
- // no way to translate this encoding into a Windows charset
- return -1;
+ default:
+ // no way to translate this encoding into a Windows charset
+ return -1;
+ }
}
// we have 2 versions of wxCharsetToCodepage(): the old one which directly
#include "wx/fontmap.h"
-extern long wxEncodingToCodepage(wxFontEncoding encoding)
+extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding)
{
// translate encoding into the Windows CHARSET
long charset = wxEncodingToCharset(encoding);
#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
+// ----------------------------------------------------------------------------
+// wxApp::OnFatalException() support
+// ----------------------------------------------------------------------------
+
+bool wxHandleFatalExceptions(bool doit)
+{
+#if wxUSE_ON_FATAL_EXCEPTION
+ // assume this can only be called from the main thread
+ gs_handleExceptions = doit;
+
+ return TRUE;
+#else
+ wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to use this function"));
+
+ (void)doit;
+ return FALSE;
+#endif
+}
+
+#if wxUSE_ON_FATAL_EXCEPTION
+
+extern unsigned long wxGlobalSEHandler()
+{
+ if ( gs_handleExceptions && wxTheApp )
+ {
+ // give the user a chance to do something special about this
+ wxTheApp->OnFatalException();
+
+ // this will execute our handler and terminate the process
+ return EXCEPTION_EXECUTE_HANDLER;
+ }
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+#endif // wxUSE_ON_FATAL_EXCEPTION
+