]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/utils.cpp
compilation fix
[wxWidgets.git] / src / msw / utils.cpp
index bc79244d0b09473ff872ecc8d131c66a6be5f862..3850a53d1040f9c9a74e73e029c4b25a37a02f62 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/apptrait.h"
 
 #include "wx/msw/private.h"     // includes <windows.h>
+#include "wx/msw/missing.h"     // CHARSET_HANGUL
 
 #ifdef __GNUWIN32_OLD__
     // apparently we need to include winsock.h to get WSADATA and other stuff
     #endif
 #endif
 
+// ----------------------------------------------------------------------------
+// module globals
+// ----------------------------------------------------------------------------
+
+#if wxUSE_ON_FATAL_EXCEPTION
+    static bool gs_handleExceptions = FALSE;
+#endif
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -232,99 +241,86 @@ bool wxGetUserId(wxChar *buf, int maxSize)
 // 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, wxEmptyString, 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;
 }
@@ -1041,7 +1037,7 @@ void wxSleep(int nSecs)
 // font encoding <-> Win32 codepage conversion functions
 // ----------------------------------------------------------------------------
 
-extern long wxEncodingToCharset(wxFontEncoding encoding)
+extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding)
 {
     switch ( encoding )
     {
@@ -1097,10 +1093,11 @@ extern long wxEncodingToCharset(wxFontEncoding 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
@@ -1111,7 +1108,7 @@ extern long wxEncodingToCharset(wxFontEncoding encoding)
 
 #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);
@@ -1189,3 +1186,40 @@ extern long wxCharsetToCodepage(const wxChar *name)
 
 #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
+