1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation "utils.h" // Note: this is done in utilscmn.cpp now.
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/cursor.h"
30 #include "wx/msw/private.h"
38 #if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__)
46 #if defined(__GNUWIN32__) && !defined(__TWIN32__)
47 #include <sys/unistd.h>
53 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
54 // this (3.1 I believe) and how to test for it.
55 // If this works for Borland 4.0 as well, then no worries.
59 // VZ: there is some code using NetXXX() functions to get the full user name:
60 // I don't think it's a good idea because they don't work under Win95 and
61 // seem to return the same as wxGetUserId() under NT. If you really want
62 // to use them, just #define USE_NET_API
69 #if defined(__WIN32__) && !defined(__WXWINE__)
81 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
87 //// BEGIN for console support: VC++ only
90 #include "wx/msw/msvcrt.h"
94 #include "wx/ioswrap.h"
97 // N.B. BC++ doesn't have istream.h, ostream.h
104 /* Need to undef new if including crtdbg.h */
113 # if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
114 # define new new(__FILE__,__LINE__)
119 /// END for console support
121 // In the WIN.INI file
122 static const wxChar WX_SECTION
[] = wxT("wxWindows");
123 static const wxChar eHOSTNAME
[] = wxT("HostName");
124 static const wxChar eUSERID
[] = wxT("UserId");
125 static const wxChar eUSERNAME
[] = wxT("UserName");
127 // For the following functions we SHOULD fill in support
128 // for Windows-NT (which I don't know) as I assume it begin
129 // a POSIX Unix (so claims MS) that it has some special
130 // functions beyond those provided by WinSock
132 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
133 bool wxGetHostName(wxChar
*buf
, int maxSize
)
135 #if defined(__WIN32__) && !defined(__TWIN32__)
136 DWORD nSize
= maxSize
;
137 return (::GetComputerName(buf
, &nSize
) != 0);
140 const wxChar
*default_host
= wxT("noname");
142 if ((sysname
= wxGetenv(wxT("SYSTEM_NAME"))) == NULL
) {
143 GetProfileString(WX_SECTION
, eHOSTNAME
, default_host
, buf
, maxSize
- 1);
145 wxStrncpy(buf
, sysname
, maxSize
- 1);
146 buf
[maxSize
] = wxT('\0');
147 return *buf
? TRUE
: FALSE
;
151 // Get user ID e.g. jacs
152 bool wxGetUserId(wxChar
*buf
, int maxSize
)
154 #if defined(__WIN32__) && !defined(__win32s__) && !defined(__TWIN32__)
155 DWORD nSize
= maxSize
;
156 if ( ::GetUserName(buf
, &nSize
) == 0 )
158 // actually, it does happen on Win9x if the user didn't log on
159 DWORD res
= ::GetEnvironmentVariable(wxT("username"), buf
, maxSize
);
168 #else // Win16 or Win32s
170 const wxChar
*default_id
= wxT("anonymous");
172 // Can't assume we have NIS (PC-NFS) or some other ID daemon
174 if ( (user
= wxGetenv(wxT("USER"))) == NULL
&&
175 (user
= wxGetenv(wxT("LOGNAME"))) == NULL
)
177 // Use wxWindows configuration data (comming soon)
178 GetProfileString(WX_SECTION
, eUSERID
, default_id
, buf
, maxSize
- 1);
182 wxStrncpy(buf
, user
, maxSize
- 1);
185 return *buf
? TRUE
: FALSE
;
189 // Get user name e.g. Julian Smart
190 bool wxGetUserName(wxChar
*buf
, int maxSize
)
192 #if wxUSE_PENWINDOWS && !defined(__WATCOMC__) && !defined(__GNUWIN32__)
193 extern HANDLE g_hPenWin
; // PenWindows Running?
196 // PenWindows Does have a user concept!
197 // Get the current owner of the recognizer
198 GetPrivateProfileString("Current", "User", default_name
, wxBuffer
, maxSize
- 1, "PENWIN.INI");
199 strncpy(buf
, wxBuffer
, maxSize
- 1);
205 CHAR szUserName
[256];
206 if ( !wxGetUserId(szUserName
, WXSIZEOF(szUserName
)) )
209 // TODO how to get the domain name?
212 // the code is based on the MSDN example (also see KB article Q119670)
213 WCHAR wszUserName
[256]; // Unicode user name
214 WCHAR wszDomain
[256];
217 USER_INFO_2
*ui2
; // User structure
219 // Convert ANSI user name and domain to Unicode
220 MultiByteToWideChar( CP_ACP
, 0, szUserName
, strlen(szUserName
)+1,
221 wszUserName
, WXSIZEOF(wszUserName
) );
222 MultiByteToWideChar( CP_ACP
, 0, szDomain
, strlen(szDomain
)+1,
223 wszDomain
, WXSIZEOF(wszDomain
) );
225 // Get the computer name of a DC for the domain.
226 if ( NetGetDCName( NULL
, wszDomain
, &ComputerName
) != NERR_Success
)
228 wxLogError(wxT("Can not find domain controller"));
233 // Look up the user on the DC
234 NET_API_STATUS status
= NetUserGetInfo( (LPWSTR
)ComputerName
,
235 (LPWSTR
)&wszUserName
,
236 2, // level - we want USER_INFO_2
244 case NERR_InvalidComputer
:
245 wxLogError(wxT("Invalid domain controller name."));
249 case NERR_UserNotFound
:
250 wxLogError(wxT("Invalid user name '%s'."), szUserName
);
255 wxLogSysError(wxT("Can't get information about user"));
260 // Convert the Unicode full name to ANSI
261 WideCharToMultiByte( CP_ACP
, 0, ui2
->usri2_full_name
, -1,
262 buf
, maxSize
, NULL
, NULL
);
267 wxLogError(wxT("Couldn't look up full user name."));
270 #else // !USE_NET_API
271 // Could use NIS, MS-Mail or other site specific programs
272 // Use wxWindows configuration data
273 bool ok
= GetProfileString(WX_SECTION
, eUSERNAME
, wxT(""), buf
, maxSize
- 1) != 0;
276 ok
= wxGetUserId(buf
, maxSize
);
281 wxStrncpy(buf
, wxT("Unknown User"), maxSize
);
289 int wxKill(long pid
, int sig
)
295 // Execute a program in an Interactive Shell
298 wxShell(const wxString
& command
)
301 if ((shell
= wxGetenv(wxT("COMSPEC"))) == NULL
)
302 shell
= wxT("\\COMMAND.COM");
305 if (command
!= wxT(""))
306 wxSprintf(tmp
, wxT("%s /c %s"), shell
, WXSTRINGCAST command
);
308 wxStrcpy(tmp
, shell
);
310 return (wxExecute((wxChar
*)tmp
, FALSE
) != 0);
313 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
314 long wxGetFreeMemory()
316 #if defined(__WIN32__) && !defined(__BORLANDC__) && !defined(__TWIN32__)
317 MEMORYSTATUS memStatus
;
318 memStatus
.dwLength
= sizeof(MEMORYSTATUS
);
319 GlobalMemoryStatus(&memStatus
);
320 return memStatus
.dwAvailPhys
;
322 return (long)GetFreeSpace(0);
326 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
327 static bool inTimer
= FALSE
;
328 class wxSleepTimer
: public wxTimer
338 static wxTimer
*wxTheSleepTimer
= NULL
;
340 void wxUsleep(unsigned long milliseconds
)
343 ::Sleep(milliseconds
);
348 wxTheSleepTimer
= new wxSleepTimer
;
350 wxTheSleepTimer
->Start(milliseconds
);
353 if (wxTheApp
->Pending())
354 wxTheApp
->Dispatch();
356 delete wxTheSleepTimer
;
357 wxTheSleepTimer
= NULL
;
361 void wxSleep(int nSecs
)
363 #if 0 // WIN32 hangs app
369 wxTheSleepTimer
= new wxSleepTimer
;
371 wxTheSleepTimer
->Start(nSecs
*1000);
374 if (wxTheApp
->Pending())
375 wxTheApp
->Dispatch();
377 delete wxTheSleepTimer
;
378 wxTheSleepTimer
= NULL
;
382 // Consume all events until no more left
388 // Output a debug mess., in a system dependent fashion.
389 void wxDebugMsg(const wxChar
*fmt
...)
392 static wxChar buffer
[512];
394 if (!wxTheApp
->GetWantDebugOutput())
399 wvsprintf(buffer
,fmt
,ap
) ;
400 OutputDebugString((LPCTSTR
)buffer
) ;
405 // Non-fatal error: pop up message box and (possibly) continue
406 void wxError(const wxString
& msg
, const wxString
& title
)
408 wxSprintf(wxBuffer
, wxT("%s\nContinue?"), WXSTRINGCAST msg
);
409 if (MessageBox(NULL
, (LPCTSTR
)wxBuffer
, (LPCTSTR
)WXSTRINGCAST title
,
410 MB_ICONSTOP
| MB_YESNO
) == IDNO
)
414 // Fatal error: pop up message box and abort
415 void wxFatalError(const wxString
& msg
, const wxString
& title
)
417 wxSprintf(wxBuffer
, wxT("%s: %s"), WXSTRINGCAST title
, WXSTRINGCAST msg
);
418 FatalAppExit(0, (LPCTSTR
)wxBuffer
);
424 // Removed by RD because IHMO syncronous sound is a Bad Thing. MessageBeep
425 // will do a similar thing anyway if there is no sound card...
427 // Beep(1000,1000) ; // 1kHz during 1 sec.
429 MessageBeep((UINT
)-1) ;
433 // Chris Breeze 27/5/98: revised WIN32 code to
434 // detect WindowsNT correctly
435 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
437 extern char *wxOsVersion
;
438 if (majorVsn
) *majorVsn
= 0;
439 if (minorVsn
) *minorVsn
= 0;
441 #if defined(__WIN32__) && !defined(__SC__)
443 memset(&info
, 0, sizeof(OSVERSIONINFO
));
444 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
445 if (GetVersionEx(&info
))
447 if (majorVsn
) *majorVsn
= info
.dwMajorVersion
;
448 if (minorVsn
) *minorVsn
= info
.dwMinorVersion
;
449 switch (info
.dwPlatformId
)
451 case VER_PLATFORM_WIN32s
:
454 case VER_PLATFORM_WIN32_WINDOWS
:
457 case VER_PLATFORM_WIN32_NT
:
462 return wxWINDOWS
; // error if we get here, return generic value
466 # ifdef __WINDOWS_386__
469 # if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS
470 extern HANDLE g_hPenWin
;
471 retValue
= g_hPenWin
? wxPENWINDOWS
: wxWINDOWS
;
474 // @@@@ To be completed. I don't have the manual here...
475 if (majorVsn
) *majorVsn
= 3 ;
476 if (minorVsn
) *minorVsn
= 1 ;
481 // Reading and writing resources (eg WIN.INI, .Xdefaults)
483 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
486 return (WritePrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)value
, (LPCTSTR
)WXSTRINGCAST file
) != 0);
488 return (WriteProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)WXSTRINGCAST value
) != 0);
491 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
494 wxSprintf(buf
, wxT("%.4f"), value
);
495 return wxWriteResource(section
, entry
, buf
, file
);
498 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
501 wxSprintf(buf
, wxT("%ld"), value
);
502 return wxWriteResource(section
, entry
, buf
, file
);
505 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
508 wxSprintf(buf
, wxT("%d"), value
);
509 return wxWriteResource(section
, entry
, buf
, file
);
512 bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
)
514 static const wxChar defunkt
[] = wxT("$$default");
517 int n
= GetPrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
518 (LPTSTR
)wxBuffer
, 1000, (LPCTSTR
)WXSTRINGCAST file
);
519 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
524 int n
= GetProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
525 (LPTSTR
)wxBuffer
, 1000);
526 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
529 if (*value
) delete[] (*value
);
530 *value
= copystring(wxBuffer
);
534 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
537 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
540 *value
= (float)wxStrtod(s
, NULL
);
547 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
550 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
553 *value
= wxStrtol(s
, NULL
, 10);
560 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
563 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
566 *value
= (int)wxStrtol(s
, NULL
, 10);
572 #endif // wxUSE_RESOURCES
574 // ---------------------------------------------------------------------------
575 // helper functions for showing a "busy" cursor
576 // ---------------------------------------------------------------------------
578 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
579 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
580 static int gs_wxBusyCursorCount
= 0;
582 // Set the cursor to the busy cursor for all windows
583 void wxBeginBusyCursor(wxCursor
*cursor
)
585 if ( gs_wxBusyCursorCount
++ == 0 )
587 gs_wxBusyCursor
= (HCURSOR
)cursor
->GetHCURSOR();
588 gs_wxBusyCursorOld
= ::SetCursor(gs_wxBusyCursor
);
590 //else: nothing to do, already set
593 // Restore cursor to normal
594 void wxEndBusyCursor()
596 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
597 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
599 if ( --gs_wxBusyCursorCount
== 0 )
601 ::SetCursor(gs_wxBusyCursorOld
);
603 gs_wxBusyCursorOld
= 0;
607 // TRUE if we're between the above two calls
610 return (gs_wxBusyCursorCount
> 0);
613 // ---------------------------------------------------------------------------
614 const wxChar
* wxGetHomeDir(wxString
*pstr
)
616 wxString
& strDir
= *pstr
;
618 #if defined(__UNIX__) && !defined(__TWIN32__)
619 const wxChar
*szHome
= wxGetenv("HOME");
620 if ( szHome
== NULL
) {
622 wxLogWarning(_("can't find user's HOME, using current directory."));
628 // add a trailing slash if needed
629 if ( strDir
.Last() != wxT('/') )
633 const wxChar
*szHome
= wxGetenv(wxT("HOMEDRIVE"));
634 if ( szHome
!= NULL
)
636 szHome
= wxGetenv(wxT("HOMEPATH"));
637 if ( szHome
!= NULL
) {
640 // the idea is that under NT these variables have default values
641 // of "%systemdrive%:" and "\\". As we don't want to create our
642 // config files in the root directory of the system drive, we will
643 // create it in our program's dir. However, if the user took care
644 // to set HOMEPATH to something other than "\\", we suppose that he
645 // knows what he is doing and use the supplied value.
646 if ( wxStrcmp(szHome
, wxT("\\")) != 0 )
647 return strDir
.c_str();
651 // Win16 has no idea about home, so use the working directory instead
654 // 260 was taken from windef.h
660 ::GetModuleFileName(::GetModuleHandle(NULL
),
661 strPath
.GetWriteBuf(MAX_PATH
), MAX_PATH
);
662 strPath
.UngetWriteBuf();
664 // extract the dir name
665 wxSplitPath(strPath
, &strDir
, NULL
, NULL
);
669 return strDir
.c_str();
673 wxChar
*wxGetUserHome (const wxString
& user
)
676 wxString
user1(user
);
678 if (user1
!= wxT("")) {
680 if (wxGetUserId(tmp
, sizeof(tmp
)/sizeof(char))) {
681 // Guests belong in the temp dir
682 if (wxStricmp(tmp
, wxT("annonymous")) == 0) {
683 if ((home
= wxGetenv(wxT("TMP"))) != NULL
||
684 (home
= wxGetenv(wxT("TMPDIR"))) != NULL
||
685 (home
= wxGetenv(wxT("TEMP"))) != NULL
)
686 return *home
? home
: (wxChar
*)wxT("\\");
688 if (wxStricmp(tmp
, WXSTRINGCAST user1
) == 0)
692 if (user1
== wxT(""))
693 if ((home
= wxGetenv(wxT("HOME"))) != NULL
)
695 wxStrcpy(wxBuffer
, home
);
696 Unix2DosFilename(wxBuffer
);
699 return NULL
; // No home known!
702 // Check whether this window wants to process messages, e.g. Stop button
703 // in long calculations.
704 bool wxCheckForInterrupt(wxWindow
*wnd
)
708 HWND win
= (HWND
) wnd
->GetHWND();
709 while(PeekMessage(&msg
,win
,0,0,PM_REMOVE
)){
710 TranslateMessage(&msg
);
711 DispatchMessage(&msg
);
713 return TRUE
;//*** temporary?
716 wxFAIL_MSG(wxT("wnd==NULL !!!"));
718 return FALSE
;//*** temporary?
722 // MSW only: get user-defined resource from the .res file.
723 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
726 wxChar
*wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
)
729 #if !defined(__WIN32__) || defined(__TWIN32__)
730 HRSRC hResource
= ::FindResource(wxGetInstance(), WXSTRINGCAST resourceName
, WXSTRINGCAST resourceType
);
733 HRSRC hResource
= ::FindResourceW(wxGetInstance(), WXSTRINGCAST resourceName
, WXSTRINGCAST resourceType
);
735 HRSRC hResource
= ::FindResourceA(wxGetInstance(), WXSTRINGCAST resourceName
, WXSTRINGCAST resourceType
);
741 HGLOBAL hData
= ::LoadResource(wxGetInstance(), hResource
);
744 wxChar
*theText
= (wxChar
*)LockResource(hData
);
748 s
= copystring(theText
);
752 UnlockResource(hData
);
756 // GlobalFree(hData);
762 void wxGetMousePosition( int* x
, int* y
)
765 GetCursorPos( & pt
);
770 // Return TRUE if we have a colour display
771 bool wxColourDisplay()
773 HDC dc
= ::GetDC((HWND
) NULL
);
775 int noCols
= GetDeviceCaps(dc
, NUMCOLORS
);
776 if ((noCols
== -1) || (noCols
> 2))
780 ReleaseDC((HWND
) NULL
, dc
);
784 // Returns depth of screen
787 HDC dc
= ::GetDC((HWND
) NULL
);
788 int planes
= GetDeviceCaps(dc
, PLANES
);
789 int bitsPerPixel
= GetDeviceCaps(dc
, BITSPIXEL
);
790 int depth
= planes
*bitsPerPixel
;
791 ReleaseDC((HWND
) NULL
, dc
);
795 // Get size of display
796 void wxDisplaySize(int *width
, int *height
)
798 HDC dc
= ::GetDC((HWND
) NULL
);
799 *width
= GetDeviceCaps(dc
, HORZRES
); *height
= GetDeviceCaps(dc
, VERTRES
);
800 ReleaseDC((HWND
) NULL
, dc
);
803 bool wxDirExists(const wxString
& dir
)
805 /* MATTHEW: [6] Always use same code for Win32, call FindClose */
806 #if defined(__WIN32__)
807 WIN32_FIND_DATA fileInfo
;
810 struct ffblk fileInfo
;
812 struct find_t fileInfo
;
816 #if defined(__WIN32__)
817 HANDLE h
= FindFirstFile((LPTSTR
) WXSTRINGCAST dir
,(LPWIN32_FIND_DATA
)&fileInfo
);
819 if (h
==INVALID_HANDLE_VALUE
)
823 return ((fileInfo
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) == FILE_ATTRIBUTE_DIRECTORY
);
826 // In Borland findfirst has a different argument
827 // ordering from _dos_findfirst. But _dos_findfirst
828 // _should_ be ok in both MS and Borland... why not?
830 return ((findfirst(WXSTRINGCAST dir
, &fileInfo
, _A_SUBDIR
) == 0 && (fileInfo
.ff_attrib
& _A_SUBDIR
) != 0));
832 return (((_dos_findfirst(WXSTRINGCAST dir
, _A_SUBDIR
, &fileInfo
) == 0) && (fileInfo
.attrib
& _A_SUBDIR
)) != 0);
837 // ---------------------------------------------------------------------------
838 // window information functions
839 // ---------------------------------------------------------------------------
841 wxString WXDLLEXPORT
wxGetWindowText(WXHWND hWnd
)
844 int len
= GetWindowTextLength((HWND
)hWnd
) + 1;
845 GetWindowText((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
851 wxString WXDLLEXPORT
wxGetWindowClass(WXHWND hWnd
)
855 int len
= 256; // some starting value
859 // as we've #undefined GetClassName we must now manually choose the
860 // right function to call
873 #endif // Twin32/!Twin32
874 #endif // Unicode/ANSI
876 ((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
881 // the class name might have been truncated, retry with larger
894 WXWORD WXDLLEXPORT
wxGetWindowId(WXHWND hWnd
)
897 return GetWindowWord((HWND
)hWnd
, GWW_ID
);
899 return GetWindowLong((HWND
)hWnd
, GWL_ID
);
904 //------------------------------------------------------------------------
905 // wild character routines
906 //------------------------------------------------------------------------
908 bool wxIsWild( const wxString
& pattern
)
910 wxString tmp
= pattern
;
911 char *pat
= WXSTRINGCAST(tmp
);
914 case '?': case '*': case '[': case '{':
925 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
928 char *pattern
= WXSTRINGCAST(tmp1
);
929 wxString tmp2
= text
;
930 char *str
= WXSTRINGCAST(tmp2
);
933 bool done
= FALSE
, ret_code
, ok
;
934 // Below is for vi fans
935 const char OB
= '{', CB
= '}';
937 // dot_special means '.' only matches '.'
938 if (dot_special
&& *str
== '.' && *pattern
!= *str
)
941 while ((*pattern
!= '\0') && (!done
)
942 && (((*str
=='\0')&&((*pattern
==OB
)||(*pattern
=='*')))||(*str
!='\0'))) {
946 if (*pattern
!= '\0')
953 && (!(ret_code
=wxMatchWild(pattern
, str
++, FALSE
))))
958 while (*pattern
!= '\0')
965 if ((*pattern
== '\0') || (*pattern
== ']')) {
969 if (*pattern
== '\\') {
971 if (*pattern
== '\0') {
976 if (*(pattern
+ 1) == '-') {
979 if (*pattern
== ']') {
983 if (*pattern
== '\\') {
985 if (*pattern
== '\0') {
990 if ((*str
< c
) || (*str
> *pattern
)) {
994 } else if (*pattern
!= *str
) {
999 while ((*pattern
!= ']') && (*pattern
!= '\0')) {
1000 if ((*pattern
== '\\') && (*(pattern
+ 1) != '\0'))
1004 if (*pattern
!= '\0') {
1014 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1017 while (ok
&& (*cp
!= '\0') && (*pattern
!= '\0')
1018 && (*pattern
!= ',') && (*pattern
!= CB
)) {
1019 if (*pattern
== '\\')
1021 ok
= (*pattern
++ == *cp
++);
1023 if (*pattern
== '\0') {
1029 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1030 if (*++pattern
== '\\') {
1031 if (*++pattern
== CB
)
1036 while (*pattern
!=CB
&& *pattern
!=',' && *pattern
!='\0') {
1037 if (*++pattern
== '\\') {
1038 if (*++pattern
== CB
|| *pattern
== ',')
1043 if (*pattern
!= '\0')
1048 if (*str
== *pattern
) {
1055 while (*pattern
== '*')
1057 return ((*str
== '\0') && (*pattern
== '\0'));
1062 #if defined(__WIN95__) && defined(__WXDEBUG__) && wxUSE_DBWIN32
1065 When I started programming with Visual C++ v4.0, I missed one of my favorite
1066 tools -- DBWIN. Finding the code for a simple debug trace utility, DBMON,
1067 on MSDN was a step in the right direction, but it is a console application
1068 and thus has limited features and extensibility. DBWIN32 is my creation
1069 to solve this problem.
1071 The code is essentially a merging of a stripped down version of the DBWIN code
1072 from VC 1.5 and DBMON.C with a few 32 bit changes.
1074 As of version 1.2B, DBWIN32 supports both Win95 and NT. The NT support is
1075 built into the operating system and works just by running DBWIN32. The Win95
1076 team decided not to support this hook, so I have provided code that will do
1077 this for you. See the file WIN95.TXT for instructions on installing this.
1079 If you have questions, problems or suggestions about DBWIN32, I welcome your
1080 feedback and plan to actively maintain the code.
1085 To download dbwin32, see e.g.:
1087 http://ftp.digital.com/pub/micro/NT/WinSite/programr/dbwin32.zip
1090 #if !defined(__MWERKS__) && !defined(__SALFORDC__) && !defined(__TWIN32__)
1091 #include <process.h>
1094 void OutputDebugStringW95(const wxChar
* lpOutputString
, ...)
1096 HANDLE heventDBWIN
; /* DBWIN32 synchronization object */
1097 HANDLE heventData
; /* data passing synch object */
1098 HANDLE hSharedFile
; /* memory mapped file shared data */
1099 LPSTR lpszSharedMem
;
1100 wxChar achBuffer
[500];
1102 /* create the output buffer */
1104 va_start(args
, lpOutputString
);
1105 wxVsprintf(achBuffer
, lpOutputString
, args
);
1109 Do a regular OutputDebugString so that the output is
1110 still seen in the debugger window if it exists.
1112 This ifdef is necessary to avoid infinite recursion
1113 from the inclusion of W95TRACE.H
1116 ::OutputDebugStringW(achBuffer
);
1119 ::OutputDebugString(achBuffer
);
1121 ::OutputDebugStringA(achBuffer
);
1125 /* bail if it's not Win95 */
1127 OSVERSIONINFO VerInfo
;
1128 VerInfo
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
1129 GetVersionEx(&VerInfo
);
1130 if ( VerInfo
.dwPlatformId
!= VER_PLATFORM_WIN32_WINDOWS
)
1134 /* make sure DBWIN is open and waiting */
1135 heventDBWIN
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, wxT("DBWIN_BUFFER_READY"));
1138 //MessageBox(NULL, wxT("DBWIN_BUFFER_READY nonexistent"), NULL, MB_OK);
1142 /* get a handle to the data synch object */
1143 heventData
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, wxT("DBWIN_DATA_READY"));
1146 // MessageBox(NULL, wxT("DBWIN_DATA_READY nonexistent"), NULL, MB_OK);
1147 CloseHandle(heventDBWIN
);
1151 hSharedFile
= CreateFileMapping((HANDLE
)-1, NULL
, PAGE_READWRITE
, 0, 4096, wxT("DBWIN_BUFFER"));
1154 //MessageBox(NULL, wxT("DebugTrace: Unable to create file mapping object DBWIN_BUFFER"), wxT("Error"), MB_OK);
1155 CloseHandle(heventDBWIN
);
1156 CloseHandle(heventData
);
1160 lpszSharedMem
= (LPSTR
)MapViewOfFile(hSharedFile
, FILE_MAP_WRITE
, 0, 0, 512);
1163 //MessageBox(NULL, wxT("DebugTrace: Unable to map shared memory"), wxT("Error"), MB_OK);
1164 CloseHandle(heventDBWIN
);
1165 CloseHandle(heventData
);
1169 /* wait for buffer event */
1170 WaitForSingleObject(heventDBWIN
, INFINITE
);
1172 /* write it to the shared memory */
1173 #if defined( __BORLANDC__ ) || defined( __MWERKS__ ) || defined(__SALFORDC__)
1174 *((LPDWORD
)lpszSharedMem
) = getpid();
1176 *((LPDWORD
)lpszSharedMem
) = _getpid();
1179 wsprintf((LPTSTR
)(lpszSharedMem
+ sizeof(DWORD
)), wxT("%s"), achBuffer
);
1181 /* signal data ready event */
1182 SetEvent(heventData
);
1184 /* clean up handles */
1185 CloseHandle(hSharedFile
);
1186 CloseHandle(heventData
);
1187 CloseHandle(heventDBWIN
);
1198 // maximum mumber of lines the output console should have
1199 static const WORD MAX_CONSOLE_LINES
= 500;
1201 BOOL WINAPI
MyConsoleHandler( DWORD dwCtrlType
) { // control signal type
1206 void wxRedirectIOToConsole()
1210 CONSOLE_SCREEN_BUFFER_INFO coninfo
;
1213 // allocate a console for this app
1216 // set the screen buffer to be big enough to let us scroll text
1217 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
),
1219 coninfo
.dwSize
.Y
= MAX_CONSOLE_LINES
;
1220 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE
),
1223 // redirect unbuffered STDOUT to the console
1224 lStdHandle
= (long)GetStdHandle(STD_OUTPUT_HANDLE
);
1225 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1226 if(hConHandle
<= 0) return;
1227 fp
= _fdopen( hConHandle
, "w" );
1229 setvbuf( stdout
, NULL
, _IONBF
, 0 );
1231 // redirect unbuffered STDIN to the console
1232 lStdHandle
= (long)GetStdHandle(STD_INPUT_HANDLE
);
1233 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1234 if(hConHandle
<= 0) return;
1235 fp
= _fdopen( hConHandle
, "r" );
1237 setvbuf( stdin
, NULL
, _IONBF
, 0 );
1239 // redirect unbuffered STDERR to the console
1240 lStdHandle
= (long)GetStdHandle(STD_ERROR_HANDLE
);
1241 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1242 if(hConHandle
<= 0) return;
1243 fp
= _fdopen( hConHandle
, "w" );
1245 setvbuf( stderr
, NULL
, _IONBF
, 0 );
1247 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
1248 // point to console as well
1249 ios::sync_with_stdio();
1251 SetConsoleCtrlHandler(MyConsoleHandler
, TRUE
);
1255 void wxRedirectIOToConsole()