1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
34 #include "wx/apptrait.h"
36 #include "wx/msw/private.h" // includes <windows.h>
37 #include "wx/msw/missing.h" // CHARSET_HANGUL
39 #ifdef __GNUWIN32_OLD__
40 // apparently we need to include winsock.h to get WSADATA and other stuff
41 // used in wxGetFullHostName() with the old mingw32 versions
47 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__) && !defined(__WXMICROWIN__)
55 #if defined(__CYGWIN__)
56 #include <sys/unistd.h>
58 #include <sys/cygwin.h> // for cygwin_conv_to_full_win32_path()
61 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
62 // this (3.1 I believe) and how to test for it.
63 // If this works for Borland 4.0 as well, then no worries.
67 // VZ: there is some code using NetXXX() functions to get the full user name:
68 // I don't think it's a good idea because they don't work under Win95 and
69 // seem to return the same as wxGetUserId() under NT. If you really want
70 // to use them, just #define USE_NET_API
77 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
88 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #if wxUSE_ON_FATAL_EXCEPTION
98 static bool gs_handleExceptions
= FALSE
;
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // In the WIN.INI file
106 static const wxChar WX_SECTION
[] = wxT("wxWindows");
107 static const wxChar eUSERNAME
[] = wxT("UserName");
109 // these are only used under Win16
110 #if !defined(__WIN32__) && !defined(__WXMICROWIN__)
111 static const wxChar eHOSTNAME
[] = wxT("HostName");
112 static const wxChar eUSERID
[] = wxT("UserId");
115 // ============================================================================
117 // ============================================================================
119 // ----------------------------------------------------------------------------
120 // get host name and related
121 // ----------------------------------------------------------------------------
123 // Get hostname only (without domain name)
124 bool wxGetHostName(wxChar
*buf
, int maxSize
)
126 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
127 DWORD nSize
= maxSize
;
128 if ( !::GetComputerName(buf
, &nSize
) )
130 wxLogLastError(wxT("GetComputerName"));
138 const wxChar
*default_host
= wxT("noname");
140 if ((sysname
= wxGetenv(wxT("SYSTEM_NAME"))) == NULL
) {
141 GetProfileString(WX_SECTION
, eHOSTNAME
, default_host
, buf
, maxSize
- 1);
143 wxStrncpy(buf
, sysname
, maxSize
- 1);
144 buf
[maxSize
] = wxT('\0');
145 return *buf
? TRUE
: FALSE
;
149 // get full hostname (with domain name if possible)
150 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
152 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && ! (defined(__GNUWIN32__) && !defined(__MINGW32__))
153 // TODO should use GetComputerNameEx() when available
155 // the idea is that if someone had set wxUSE_SOCKETS to 0 the code
156 // shouldn't use winsock.dll (a.k.a. ws2_32.dll) at all so only use this
157 // code if we link with it anyhow
161 if ( WSAStartup(MAKEWORD(1, 1), &wsa
) == 0 )
165 if ( gethostname(bufA
, WXSIZEOF(bufA
)) == 0 )
167 // gethostname() won't usually include the DNS domain name, for
168 // this we need to work a bit more
169 if ( !strchr(bufA
, '.') )
171 struct hostent
*pHostEnt
= gethostbyname(bufA
);
175 // Windows will use DNS internally now
176 pHostEnt
= gethostbyaddr(pHostEnt
->h_addr
, 4, AF_INET
);
181 host
= wxString::FromAscii(pHostEnt
->h_name
);
190 wxStrncpy(buf
, host
, maxSize
);
196 #endif // wxUSE_SOCKETS
200 return wxGetHostName(buf
, maxSize
);
203 // Get user ID e.g. jacs
204 bool wxGetUserId(wxChar
*buf
, int maxSize
)
206 #if defined(__WIN32__) && !defined(__win32s__) && !defined(__WXMICROWIN__)
207 DWORD nSize
= maxSize
;
208 if ( ::GetUserName(buf
, &nSize
) == 0 )
210 // actually, it does happen on Win9x if the user didn't log on
211 DWORD res
= ::GetEnvironmentVariable(wxT("username"), buf
, maxSize
);
220 #else // Win16 or Win32s
222 const wxChar
*default_id
= wxT("anonymous");
224 // Can't assume we have NIS (PC-NFS) or some other ID daemon
226 if ( (user
= wxGetenv(wxT("USER"))) == NULL
&&
227 (user
= wxGetenv(wxT("LOGNAME"))) == NULL
)
229 // Use wxWindows configuration data (comming soon)
230 GetProfileString(WX_SECTION
, eUSERID
, default_id
, buf
, maxSize
- 1);
234 wxStrncpy(buf
, user
, maxSize
- 1);
237 return *buf
? TRUE
: FALSE
;
241 // Get user name e.g. Julian Smart
242 bool wxGetUserName(wxChar
*buf
, int maxSize
)
245 CHAR szUserName
[256];
246 if ( !wxGetUserId(szUserName
, WXSIZEOF(szUserName
)) )
249 // TODO how to get the domain name?
252 // the code is based on the MSDN example (also see KB article Q119670)
253 WCHAR wszUserName
[256]; // Unicode user name
254 WCHAR wszDomain
[256];
257 USER_INFO_2
*ui2
; // User structure
259 // Convert ANSI user name and domain to Unicode
260 MultiByteToWideChar( CP_ACP
, 0, szUserName
, strlen(szUserName
)+1,
261 wszUserName
, WXSIZEOF(wszUserName
) );
262 MultiByteToWideChar( CP_ACP
, 0, szDomain
, strlen(szDomain
)+1,
263 wszDomain
, WXSIZEOF(wszDomain
) );
265 // Get the computer name of a DC for the domain.
266 if ( NetGetDCName( NULL
, wszDomain
, &ComputerName
) != NERR_Success
)
268 wxLogError(wxT("Can not find domain controller"));
273 // Look up the user on the DC
274 NET_API_STATUS status
= NetUserGetInfo( (LPWSTR
)ComputerName
,
275 (LPWSTR
)&wszUserName
,
276 2, // level - we want USER_INFO_2
284 case NERR_InvalidComputer
:
285 wxLogError(wxT("Invalid domain controller name."));
289 case NERR_UserNotFound
:
290 wxLogError(wxT("Invalid user name '%s'."), szUserName
);
295 wxLogSysError(wxT("Can't get information about user"));
300 // Convert the Unicode full name to ANSI
301 WideCharToMultiByte( CP_ACP
, 0, ui2
->usri2_full_name
, -1,
302 buf
, maxSize
, NULL
, NULL
);
307 wxLogError(wxT("Couldn't look up full user name."));
310 #else // !USE_NET_API
311 // Could use NIS, MS-Mail or other site specific programs
312 // Use wxWindows configuration data
313 bool ok
= GetProfileString(WX_SECTION
, eUSERNAME
, wxEmptyString
, buf
, maxSize
- 1) != 0;
316 ok
= wxGetUserId(buf
, maxSize
);
321 wxStrncpy(buf
, wxT("Unknown User"), maxSize
);
328 const wxChar
* wxGetHomeDir(wxString
*pstr
)
330 wxString
& strDir
= *pstr
;
332 #if defined(__UNIX__)
333 const wxChar
*szHome
= wxGetenv("HOME");
334 if ( szHome
== NULL
) {
336 wxLogWarning(_("can't find user's HOME, using current directory."));
342 // add a trailing slash if needed
343 if ( strDir
.Last() != wxT('/') )
347 // Cygwin returns unix type path but that does not work well
348 static wxChar windowsPath
[MAX_PATH
];
349 cygwin_conv_to_full_win32_path(strDir
, windowsPath
);
350 strDir
= windowsPath
;
356 // If we have a valid HOME directory, as is used on many machines that
357 // have unix utilities on them, we should use that.
358 const wxChar
*szHome
= wxGetenv(wxT("HOME"));
360 if ( szHome
!= NULL
)
364 else // no HOME, try HOMEDRIVE/PATH
366 szHome
= wxGetenv(wxT("HOMEDRIVE"));
367 if ( szHome
!= NULL
)
369 szHome
= wxGetenv(wxT("HOMEPATH"));
371 if ( szHome
!= NULL
)
375 // the idea is that under NT these variables have default values
376 // of "%systemdrive%:" and "\\". As we don't want to create our
377 // config files in the root directory of the system drive, we will
378 // create it in our program's dir. However, if the user took care
379 // to set HOMEPATH to something other than "\\", we suppose that he
380 // knows what he is doing and use the supplied value.
381 if ( wxStrcmp(szHome
, wxT("\\")) == 0 )
386 if ( strDir
.empty() )
388 // If we have a valid USERPROFILE directory, as is the case in
389 // Windows NT, 2000 and XP, we should use that as our home directory.
390 szHome
= wxGetenv(wxT("USERPROFILE"));
392 if ( szHome
!= NULL
)
396 if ( !strDir
.empty() )
398 return strDir
.c_str();
400 //else: fall back to the prograrm directory
402 // Win16 has no idea about home, so use the executable directory instead
405 // 260 was taken from windef.h
411 ::GetModuleFileName(::GetModuleHandle(NULL
),
412 strPath
.GetWriteBuf(MAX_PATH
), MAX_PATH
);
413 strPath
.UngetWriteBuf();
415 // extract the dir name
416 wxSplitPath(strPath
, &strDir
, NULL
, NULL
);
420 return strDir
.c_str();
423 wxChar
*wxGetUserHome(const wxString
& WXUNUSED(user
))
425 // VZ: the old code here never worked for user != "" anyhow! Moreover, it
426 // returned sometimes a malloc()'d pointer, sometimes a pointer to a
427 // static buffer and sometimes I don't even know what.
428 static wxString s_home
;
430 return (wxChar
*)wxGetHomeDir(&s_home
);
433 bool wxDirExists(const wxString
& dir
)
435 #ifdef __WXMICROWIN__
436 return wxPathExist(dir
);
437 #elif defined(__WIN32__)
438 DWORD attribs
= GetFileAttributes(dir
);
439 return ((attribs
!= (DWORD
)-1) && (attribs
& FILE_ATTRIBUTE_DIRECTORY
));
442 struct ffblk fileInfo
;
444 struct find_t fileInfo
;
446 // In Borland findfirst has a different argument
447 // ordering from _dos_findfirst. But _dos_findfirst
448 // _should_ be ok in both MS and Borland... why not?
450 return (findfirst(dir
, &fileInfo
, _A_SUBDIR
) == 0 &&
451 (fileInfo
.ff_attrib
& _A_SUBDIR
) != 0);
453 return (_dos_findfirst(dir
, _A_SUBDIR
, &fileInfo
) == 0) &&
454 ((fileInfo
.attrib
& _A_SUBDIR
) != 0);
459 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
464 // old w32api don't have ULARGE_INTEGER
465 #if defined(__WIN32__) && \
466 (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION( 0, 3 ))
467 // GetDiskFreeSpaceEx() is not available under original Win95, check for
469 typedef BOOL (WINAPI
*GetDiskFreeSpaceEx_t
)(LPCTSTR
,
475 pGetDiskFreeSpaceEx
= (GetDiskFreeSpaceEx_t
)::GetProcAddress
477 ::GetModuleHandle(_T("kernel32.dll")),
479 "GetDiskFreeSpaceExW"
481 "GetDiskFreeSpaceExA"
485 if ( pGetDiskFreeSpaceEx
)
487 ULARGE_INTEGER bytesFree
, bytesTotal
;
489 // may pass the path as is, GetDiskFreeSpaceEx() is smart enough
490 if ( !pGetDiskFreeSpaceEx(path
,
495 wxLogLastError(_T("GetDiskFreeSpaceEx"));
500 // ULARGE_INTEGER is a union of a 64 bit value and a struct containing
501 // two 32 bit fields which may be or may be not named - try to make it
502 // compile in all cases
503 #if defined(__BORLANDC__) && !defined(_ANONYMOUS_STRUCT)
510 *pTotal
= wxLongLong(UL(bytesTotal
).HighPart
, UL(bytesTotal
).LowPart
);
515 *pFree
= wxLongLong(UL(bytesFree
).HighPart
, UL(bytesFree
).LowPart
);
521 // there's a problem with drives larger than 2GB, GetDiskFreeSpaceEx()
522 // should be used instead - but if it's not available, fall back on
523 // GetDiskFreeSpace() nevertheless...
525 DWORD lSectorsPerCluster
,
527 lNumberOfFreeClusters
,
528 lTotalNumberOfClusters
;
530 // FIXME: this is wrong, we should extract the root drive from path
531 // instead, but this is the job for wxFileName...
532 if ( !::GetDiskFreeSpace(path
,
535 &lNumberOfFreeClusters
,
536 &lTotalNumberOfClusters
) )
538 wxLogLastError(_T("GetDiskFreeSpace"));
543 wxLongLong lBytesPerCluster
= lSectorsPerCluster
;
544 lBytesPerCluster
*= lBytesPerSector
;
548 *pTotal
= lBytesPerCluster
;
549 *pTotal
*= lTotalNumberOfClusters
;
554 *pFree
= lBytesPerCluster
;
555 *pFree
*= lNumberOfFreeClusters
;
562 // ----------------------------------------------------------------------------
564 // ----------------------------------------------------------------------------
566 bool wxGetEnv(const wxString
& var
, wxString
*value
)
569 const wxChar
* ret
= wxGetenv(var
);
580 // first get the size of the buffer
581 DWORD dwRet
= ::GetEnvironmentVariable(var
, NULL
, 0);
584 // this means that there is no such variable
590 (void)::GetEnvironmentVariable(var
, value
->GetWriteBuf(dwRet
), dwRet
);
591 value
->UngetWriteBuf();
598 bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
600 // some compilers have putenv() or _putenv() or _wputenv() but it's better
601 // to always use Win32 function directly instead of dealing with them
602 #if defined(__WIN32__)
603 if ( !::SetEnvironmentVariable(var
, value
) )
605 wxLogLastError(_T("SetEnvironmentVariable"));
611 #else // no way to set env vars
616 // ----------------------------------------------------------------------------
617 // process management
618 // ----------------------------------------------------------------------------
620 // structure used to pass parameters from wxKill() to wxEnumFindByPidProc()
621 struct wxFindByPidParams
623 wxFindByPidParams() { hwnd
= 0; pid
= 0; }
625 // the HWND used to return the result
628 // the PID we're looking from
631 DECLARE_NO_COPY_CLASS(wxFindByPidParams
)
634 // wxKill helper: EnumWindows() callback which is used to find the first (top
635 // level) window belonging to the given process
636 BOOL CALLBACK
wxEnumFindByPidProc(HWND hwnd
, LPARAM lParam
)
639 (void)::GetWindowThreadProcessId(hwnd
, &pid
);
641 wxFindByPidParams
*params
= (wxFindByPidParams
*)lParam
;
642 if ( pid
== params
->pid
)
644 // remember the window we found
647 // return FALSE to stop the enumeration
651 // continue enumeration
655 int wxKill(long pid
, wxSignal sig
, wxKillError
*krc
)
657 // get the process handle to operate on
658 HANDLE hProcess
= ::OpenProcess(SYNCHRONIZE
|
660 PROCESS_QUERY_INFORMATION
,
661 FALSE
, // not inheritable
663 if ( hProcess
== NULL
)
667 if ( ::GetLastError() == ERROR_ACCESS_DENIED
)
669 *krc
= wxKILL_ACCESS_DENIED
;
673 *krc
= wxKILL_NO_PROCESS
;
684 // kill the process forcefully returning -1 as error code
685 if ( !::TerminateProcess(hProcess
, (UINT
)-1) )
687 wxLogSysError(_("Failed to kill process %d"), pid
);
691 // this is not supposed to happen if we could open the
701 // do nothing, we just want to test for process existence
705 // any other signal means "terminate"
707 wxFindByPidParams params
;
708 params
.pid
= (DWORD
)pid
;
710 // EnumWindows() has nice semantics: it returns 0 if it found
711 // something or if an error occured and non zero if it
712 // enumerated all the window
713 if ( !::EnumWindows(wxEnumFindByPidProc
, (LPARAM
)¶ms
) )
715 // did we find any window?
718 // tell the app to close
720 // NB: this is the harshest way, the app won't have
721 // opportunity to save any files, for example, but
722 // this is probably what we want here. If not we
723 // can also use SendMesageTimeout(WM_CLOSE)
724 if ( !::PostMessage(params
.hwnd
, WM_QUIT
, 0, 0) )
726 wxLogLastError(_T("PostMessage(WM_QUIT)"));
729 else // it was an error then
731 wxLogLastError(_T("EnumWindows"));
736 else // no windows for this PID
753 // as we wait for a short time, we can use just WaitForSingleObject()
754 // and not MsgWaitForMultipleObjects()
755 switch ( ::WaitForSingleObject(hProcess
, 500 /* msec */) )
758 // process terminated
759 if ( !::GetExitCodeProcess(hProcess
, &rc
) )
761 wxLogLastError(_T("GetExitCodeProcess"));
766 wxFAIL_MSG( _T("unexpected WaitForSingleObject() return") );
770 wxLogLastError(_T("WaitForSingleObject"));
785 // just to suppress the warnings about uninitialized variable
789 ::CloseHandle(hProcess
);
791 // the return code is the same as from Unix kill(): 0 if killed
792 // successfully or -1 on error
794 // be careful to interpret rc correctly: for wxSIGNONE we return success if
795 // the process exists, for all the other sig values -- if it doesn't
797 ((sig
== wxSIGNONE
) == (rc
== STILL_ACTIVE
)) )
811 // Execute a program in an Interactive Shell
812 bool wxShell(const wxString
& command
)
814 wxChar
*shell
= wxGetenv(wxT("COMSPEC"));
816 shell
= (wxChar
*) wxT("\\COMMAND.COM");
826 // pass the command to execute to the command processor
827 cmd
.Printf(wxT("%s /c %s"), shell
, command
.c_str());
830 return wxExecute(cmd
, wxEXEC_SYNC
) == 0;
833 // Shutdown or reboot the PC
834 bool wxShutdown(wxShutdownFlags wFlags
)
839 if ( wxGetOsVersion(NULL
, NULL
) == wxWINDOWS_NT
) // if is NT or 2K
841 // Get a token for this process.
843 bOK
= ::OpenProcessToken(GetCurrentProcess(),
844 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
848 TOKEN_PRIVILEGES tkp
;
850 // Get the LUID for the shutdown privilege.
851 ::LookupPrivilegeValue(NULL
, SE_SHUTDOWN_NAME
,
852 &tkp
.Privileges
[0].Luid
);
854 tkp
.PrivilegeCount
= 1; // one privilege to set
855 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
857 // Get the shutdown privilege for this process.
858 ::AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0,
859 (PTOKEN_PRIVILEGES
)NULL
, 0);
861 // Cannot test the return value of AdjustTokenPrivileges.
862 bOK
= ::GetLastError() == ERROR_SUCCESS
;
868 UINT flags
= EWX_SHUTDOWN
| EWX_FORCE
;
871 case wxSHUTDOWN_POWEROFF
:
872 flags
|= EWX_POWEROFF
;
875 case wxSHUTDOWN_REBOOT
:
880 wxFAIL_MSG( _T("unknown wxShutdown() flag") );
884 bOK
= ::ExitWindowsEx(EWX_SHUTDOWN
| EWX_FORCE
| EWX_REBOOT
, 0) != 0;
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
898 long wxGetFreeMemory()
900 #if defined(__WIN32__) && !defined(__BORLANDC__)
901 MEMORYSTATUS memStatus
;
902 memStatus
.dwLength
= sizeof(MEMORYSTATUS
);
903 GlobalMemoryStatus(&memStatus
);
904 return memStatus
.dwAvailPhys
;
906 return (long)GetFreeSpace(0);
910 unsigned long wxGetProcessId()
913 return ::GetCurrentProcessId();
922 ::MessageBeep((UINT
)-1); // default sound
925 wxString
wxGetOsDescription()
933 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
934 if ( ::GetVersionEx(&info
) )
936 switch ( info
.dwPlatformId
)
938 case VER_PLATFORM_WIN32s
:
939 str
= _("Win32s on Windows 3.1");
942 case VER_PLATFORM_WIN32_WINDOWS
:
943 str
.Printf(_("Windows 9%c"),
944 info
.dwMinorVersion
== 0 ? _T('5') : _T('8'));
945 if ( !wxIsEmpty(info
.szCSDVersion
) )
947 str
<< _T(" (") << info
.szCSDVersion
<< _T(')');
951 case VER_PLATFORM_WIN32_NT
:
952 str
.Printf(_T("Windows NT %lu.%lu (build %lu"),
956 if ( !wxIsEmpty(info
.szCSDVersion
) )
958 str
<< _T(", ") << info
.szCSDVersion
;
966 wxFAIL_MSG( _T("GetVersionEx() failed") ); // should never happen
971 return _("Windows 3.1");
975 int wxAppTraits::GetOSVersion(int *verMaj
, int *verMin
)
977 // cache the version info, it's not going to change
979 // NB: this is MT-safe, we may use these static vars from different threads
980 // but as they always have the same value it doesn't matter
981 static int s_ver
= -1,
991 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
992 if ( ::GetVersionEx(&info
) )
994 s_major
= info
.dwMajorVersion
;
995 s_minor
= info
.dwMinorVersion
;
997 switch ( info
.dwPlatformId
)
999 case VER_PLATFORM_WIN32s
:
1003 case VER_PLATFORM_WIN32_WINDOWS
:
1007 case VER_PLATFORM_WIN32_NT
:
1008 s_ver
= wxWINDOWS_NT
;
1022 // ----------------------------------------------------------------------------
1024 // ----------------------------------------------------------------------------
1026 void wxUsleep(unsigned long milliseconds
)
1028 ::Sleep(milliseconds
);
1031 void wxSleep(int nSecs
)
1033 wxUsleep(1000*nSecs
);
1036 // ----------------------------------------------------------------------------
1037 // font encoding <-> Win32 codepage conversion functions
1038 // ----------------------------------------------------------------------------
1040 extern WXDLLIMPEXP_BASE
long wxEncodingToCharset(wxFontEncoding encoding
)
1044 // although this function is supposed to return an exact match, do do
1045 // some mappings here for the most common case of "standard" encoding
1046 case wxFONTENCODING_SYSTEM
:
1047 return DEFAULT_CHARSET
;
1049 case wxFONTENCODING_ISO8859_1
:
1050 case wxFONTENCODING_ISO8859_15
:
1051 case wxFONTENCODING_CP1252
:
1052 return ANSI_CHARSET
;
1054 #if !defined(__WXMICROWIN__)
1055 // The following four fonts are multi-byte charsets
1056 case wxFONTENCODING_CP932
:
1057 return SHIFTJIS_CHARSET
;
1059 case wxFONTENCODING_CP936
:
1060 return GB2312_CHARSET
;
1062 case wxFONTENCODING_CP949
:
1063 return HANGUL_CHARSET
;
1065 case wxFONTENCODING_CP950
:
1066 return CHINESEBIG5_CHARSET
;
1068 // The rest are single byte encodings
1069 case wxFONTENCODING_CP1250
:
1070 return EASTEUROPE_CHARSET
;
1072 case wxFONTENCODING_CP1251
:
1073 return RUSSIAN_CHARSET
;
1075 case wxFONTENCODING_CP1253
:
1076 return GREEK_CHARSET
;
1078 case wxFONTENCODING_CP1254
:
1079 return TURKISH_CHARSET
;
1081 case wxFONTENCODING_CP1255
:
1082 return HEBREW_CHARSET
;
1084 case wxFONTENCODING_CP1256
:
1085 return ARABIC_CHARSET
;
1087 case wxFONTENCODING_CP1257
:
1088 return BALTIC_CHARSET
;
1090 case wxFONTENCODING_CP874
:
1091 return THAI_CHARSET
;
1092 #endif // !__WXMICROWIN__
1094 case wxFONTENCODING_CP437
:
1098 // no way to translate this encoding into a Windows charset
1103 // we have 2 versions of wxCharsetToCodepage(): the old one which directly
1104 // looks up the vlaues in the registry and the new one which is more
1105 // politically correct and has more chances to work on other Windows versions
1106 // as well but the old version is still needed for !wxUSE_FONTMAP case
1109 #include "wx/fontmap.h"
1111 extern WXDLLIMPEXP_BASE
long wxEncodingToCodepage(wxFontEncoding encoding
)
1113 // translate encoding into the Windows CHARSET
1114 long charset
= wxEncodingToCharset(encoding
);
1115 if ( charset
== -1 )
1118 // translate CHARSET to code page
1119 CHARSETINFO csetInfo
;
1120 if ( !::TranslateCharsetInfo((DWORD
*)(DWORD
)charset
,
1124 wxLogLastError(_T("TranslateCharsetInfo(TCI_SRCCHARSET)"));
1129 return csetInfo
.ciACP
;
1132 extern long wxCharsetToCodepage(const wxChar
*name
)
1134 // first get the font encoding for this charset
1138 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(name
, FALSE
);
1139 if ( enc
== wxFONTENCODING_SYSTEM
)
1142 // the use the helper function
1143 return wxEncodingToCodepage(enc
);
1146 #else // !wxUSE_FONTMAP
1148 #include "wx/msw/registry.h"
1150 // this should work if Internet Exploiter is installed
1151 extern long wxCharsetToCodepage(const wxChar
*name
)
1158 wxString
path(wxT("MIME\\Database\\Charset\\"));
1161 // follow the alias loop
1164 wxRegKey
key(wxRegKey::HKCR
, path
+ cn
);
1169 // two cases: either there's an AliasForCharset string,
1170 // or there are Codepage and InternetEncoding dwords.
1171 // The InternetEncoding gives us the actual encoding,
1172 // the Codepage just says which Windows character set to
1173 // use when displaying the data.
1174 if (key
.HasValue(wxT("InternetEncoding")) &&
1175 key
.QueryValue(wxT("InternetEncoding"), &CP
))
1178 // no encoding, see if it's an alias
1179 if (!key
.HasValue(wxT("AliasForCharset")) ||
1180 !key
.QueryValue(wxT("AliasForCharset"), cn
))
1187 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
1189 // ----------------------------------------------------------------------------
1190 // wxApp::OnFatalException() support
1191 // ----------------------------------------------------------------------------
1193 bool wxHandleFatalExceptions(bool doit
)
1195 #if wxUSE_ON_FATAL_EXCEPTION
1196 // assume this can only be called from the main thread
1197 gs_handleExceptions
= doit
;
1201 wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to use this function"));
1208 #if wxUSE_ON_FATAL_EXCEPTION
1210 extern unsigned long wxGlobalSEHandler()
1212 if ( gs_handleExceptions
&& wxTheApp
)
1214 // give the user a chance to do something special about this
1215 wxTheApp
->OnFatalException();
1217 // this will execute our handler and terminate the process
1218 return EXCEPTION_EXECUTE_HANDLER
;
1221 return EXCEPTION_CONTINUE_SEARCH
;
1224 #endif // wxUSE_ON_FATAL_EXCEPTION