]> git.saurik.com Git - wxWidgets.git/blame - src/msw/utils.cpp
no message
[wxWidgets.git] / src / msw / utils.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose: Various utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
743e0a66 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
a3b46648 13// #pragma implementation "utils.h" // Note: this is done in utilscmn.cpp now.
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/setup.h"
25#include "wx/utils.h"
26#include "wx/app.h"
27#include "wx/cursor.h"
743e0a66 28#endif //WX_PRECOMP
2bda0e17
KB
29
30#include "wx/msw/private.h"
31#include "wx/timer.h"
32
33#include <ctype.h>
34
35#ifndef __GNUWIN32__
36#include <direct.h>
37#include <dos.h>
743e0a66 38#endif //GNUWIN32
2bda0e17
KB
39
40#ifdef __GNUWIN32__
41#include <sys/unistd.h>
42#include <sys/stat.h>
43#ifndef __MINGW32__
44#include <std.h>
743e0a66 45#endif //MINGW32
2bda0e17 46
743e0a66
VZ
47#endif //GNUWIN32
48
49#include "wx/log.h"
2bda0e17
KB
50
51#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
52 // this (3.1 I believe) and how to test for it.
53 // If this works for Borland 4.0 as well, then no worries.
54#include <dir.h>
55#endif
56
57#ifdef __WIN32__
58#include <io.h>
59
60#ifndef __GNUWIN32__
61#include <shellapi.h>
62#endif
63#endif
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#ifndef __WATCOMC__
69#if !(defined(_MSC_VER) && (_MSC_VER > 800))
70#include <errno.h>
71#endif
72#endif
73#include <stdarg.h>
74
75// In the WIN.INI file
76static const char WX_SECTION[] = "wxWindows";
77static const char eHOSTNAME[] = "HostName";
78static const char eUSERID[] = "UserId";
79static const char eUSERNAME[] = "UserName";
80
2bda0e17
KB
81// For the following functions we SHOULD fill in support
82// for Windows-NT (which I don't know) as I assume it begin
83// a POSIX Unix (so claims MS) that it has some special
84// functions beyond those provided by WinSock
85
86// Get full hostname (eg. DoDo.BSn-Germany.crg.de)
87bool wxGetHostName(char *buf, int maxSize)
88{
89#ifdef __WIN32__
90 DWORD nSize = maxSize;
91 return (::GetComputerName(buf, &nSize) != 0);
92#else
93 char *sysname;
94 const char *default_host = "noname";
95
96 if ((sysname = getenv("SYSTEM_NAME")) == NULL) {
97 GetProfileString(WX_SECTION, eHOSTNAME, default_host, buf, maxSize - 1);
98 } else
99 strncpy(buf, sysname, maxSize - 1);
100 buf[maxSize] = '\0';
101 return *buf ? TRUE : FALSE;
102#endif
103}
104
105// Get user ID e.g. jacs
106bool wxGetUserId(char *buf, int maxSize)
107{
108#if defined(__WIN32__) && !defined(__win32s__) && 0
109 // Gets the current user's full name according to the MS article PSS ID
110 // Number: Q119670
111 // Seems to be the same as the login name for me?
112 char *UserName = new char[256];
113 char *Domain = new char[256];
114 DWORD maxCharacters = 255;
115 GetUserName( UserName, &maxCharacters );
116 GetComputerName( Domain, &maxCharacters );
117
118 WCHAR wszUserName[256]; // Unicode user name
119 WCHAR wszDomain[256];
120 LPBYTE ComputerName;
121
122 struct _SERVER_INFO_100 *si100; // Server structure
123 struct _USER_INFO_2 *ui; // User structure
124
125 // Convert ASCII user name and domain to Unicode.
126
127 MultiByteToWideChar( CP_ACP, 0, UserName,
128 strlen(UserName)+1, wszUserName, sizeof(wszUserName) );
129 MultiByteToWideChar( CP_ACP, 0, Domain,
130 strlen(Domain)+1, wszDomain, sizeof(wszDomain) );
131
132 // Get the computer name of a DC for the specified domain.
133 // >If you get a link error on this, include netapi32.lib<
134
135 NetGetDCName( NULL, wszDomain, &ComputerName );
136
137 // Look up the user on the DC.
138
139 if(NetUserGetInfo( (LPWSTR) ComputerName,
140 (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui))
141 {
142 printf( "Error getting user information.\n" );
143 return( FALSE );
144 }
145
146 // Convert the Unicode full name to ASCII.
147
148 WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name,
149 -1, buf, 256, NULL, NULL );
150 }
151 return( TRUE );
152/*
153 DWORD nSize = maxSize;
154 return ::GetUserName(buf, &nSize);
155*/
156#else
157 char *user;
158 const char *default_id = "anonymous";
159
160 // Can't assume we have NIS (PC-NFS) or some other ID daemon
161 // So we ...
743e0a66
VZ
162 if ( (user = getenv("USER")) == NULL &&
163 (user = getenv("LOGNAME")) == NULL ) {
2bda0e17
KB
164 // Use wxWindows configuration data (comming soon)
165 GetProfileString(WX_SECTION, eUSERID, default_id, buf, maxSize - 1);
166 } else
167 strncpy(buf, user, maxSize - 1);
168 return *buf ? TRUE : FALSE;
169#endif
170}
171
172// Get user name e.g. Julian Smart
173bool wxGetUserName(char *buf, int maxSize)
174{
175 const char *default_name = "Unknown User";
176#if defined(__WIN32__)
177/*
178 DWORD nSize = maxSize;
179 In VC++ 4.0, results in unresolved symbol __imp__GetUserNameA
180 if (GetUserName(buf, &nSize))
181 return TRUE;
182 else
183*/
184 // Could use NIS, MS-Mail or other site specific programs
185 // Use wxWindows configuration data
186 GetProfileString(WX_SECTION, eUSERNAME, default_name, buf, maxSize - 1);
187 return *buf ? TRUE : FALSE;
188// }
189#else
47d67540 190#if !defined(__WATCOMC__) && !defined(__GNUWIN32__) && wxUSE_PENWINDOWS
81d66cf3
JS
191 extern HANDLE g_hPenWin; // PenWindows Running?
192 if (g_hPenWin)
2bda0e17
KB
193 {
194 // PenWindows Does have a user concept!
195 // Get the current owner of the recognizer
196 GetPrivateProfileString("Current", "User", default_name, wxBuffer, maxSize - 1, "PENWIN.INI");
197 strncpy(buf, wxBuffer, maxSize - 1);
198 }
199 else
200#endif
201 {
202 // Could use NIS, MS-Mail or other site specific programs
203 // Use wxWindows configuration data
204 GetProfileString(WX_SECTION, eUSERNAME, default_name, buf, maxSize - 1);
205 }
206 return *buf ? TRUE : FALSE;
207#endif
208}
209
2bda0e17
KB
210int wxKill(long pid, int sig)
211{
212 return 0;
213}
214
215//
216// Execute a program in an Interactive Shell
217//
218bool
219wxShell(const wxString& command)
220{
221 char *shell;
222 if ((shell = getenv("COMSPEC")) == NULL)
223 shell = "\\COMMAND.COM";
224
225 char tmp[255];
226 if (command != "")
227 sprintf(tmp, "%s /c %s", shell, WXSTRINGCAST command);
228 else
229 strcpy(tmp, shell);
230
231 return (wxExecute((char *)tmp, FALSE) != 0);
232}
233
234// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
235long wxGetFreeMemory(void)
236{
237#if defined(__WIN32__) && !defined(__BORLANDC__)
238 MEMORYSTATUS memStatus;
239 memStatus.dwLength = sizeof(MEMORYSTATUS);
240 GlobalMemoryStatus(&memStatus);
241 return memStatus.dwAvailPhys;
242#else
243 return (long)GetFreeSpace(0);
244#endif
245}
246
247// Sleep for nSecs seconds. Attempt a Windows implementation using timers.
248static bool inTimer = FALSE;
249class wxSleepTimer: public wxTimer
250{
251 public:
252 inline void Notify(void)
253 {
254 inTimer = FALSE;
255 Stop();
256 }
257};
258
259static wxTimer *wxTheSleepTimer = NULL;
260
261void wxSleep(int nSecs)
262{
263#if 0 // WIN32 hangs app
264 Sleep( 1000*nSecs );
265#else
266 if (inTimer)
267 return;
268
269 wxTheSleepTimer = new wxSleepTimer;
270 inTimer = TRUE;
271 wxTheSleepTimer->Start(nSecs*1000);
272 while (inTimer)
273 {
274 if (wxTheApp->Pending())
275 wxTheApp->Dispatch();
276 }
277 delete wxTheSleepTimer;
278 wxTheSleepTimer = NULL;
279#endif
280}
281
282// Consume all events until no more left
283void wxFlushEvents(void)
284{
285// wxYield();
286}
287
288// Output a debug mess., in a system dependent fashion.
289void wxDebugMsg(const char *fmt ...)
290{
291 va_list ap;
292 static char buffer[512];
293
294 if (!wxTheApp->GetWantDebugOutput())
295 return ;
296
297 va_start(ap, fmt);
298
299 wvsprintf(buffer,fmt,ap) ;
300 OutputDebugString((LPCSTR)buffer) ;
301
302 va_end(ap);
303}
304
305// Non-fatal error: pop up message box and (possibly) continue
306void wxError(const wxString& msg, const wxString& title)
307{
308 sprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST msg);
309 if (MessageBox(NULL, (LPCSTR)wxBuffer, (LPCSTR)WXSTRINGCAST title,
310 MB_ICONSTOP | MB_YESNO) == IDNO)
311 wxExit();
312}
313
314// Fatal error: pop up message box and abort
315void wxFatalError(const wxString& msg, const wxString& title)
316{
317 sprintf(wxBuffer, "%s: %s", WXSTRINGCAST title, WXSTRINGCAST msg);
318 FatalAppExit(0, (LPCSTR)wxBuffer);
319}
320
321// Emit a beeeeeep
322void wxBell(void)
323{
324#ifdef __WIN32__
743e0a66 325 Beep(1000,1000) ; // 1kHz during 1 sec.
2bda0e17
KB
326#else
327 MessageBeep(-1) ;
328#endif
329}
330
6f65e337
JS
331// Chris Breeze 27/5/98: revised WIN32 code to
332// detect WindowsNT correctly
2bda0e17
KB
333int wxGetOsVersion(int *majorVsn, int *minorVsn)
334{
335 extern char *wxOsVersion;
6f65e337
JS
336 if (majorVsn) *majorVsn = 0;
337 if (minorVsn) *minorVsn = 0;
338
339#ifdef WIN32
340 OSVERSIONINFO info;
341 memset(&info, 0, sizeof(OSVERSIONINFO));
342 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
343 if (GetVersionEx(&info))
344 {
345 if (majorVsn) *majorVsn = info.dwMajorVersion;
346 if (minorVsn) *minorVsn = info.dwMinorVersion;
347 switch (info.dwPlatformId)
743e0a66
VZ
348 {
349 case VER_PLATFORM_WIN32s:
350 return wxWIN32S;
351 break;
352 case VER_PLATFORM_WIN32_WINDOWS:
353 return wxWIN95;
354 break;
355 case VER_PLATFORM_WIN32_NT:
356 return wxWINDOWS_NT;
357 break;
6f65e337 358 }
743e0a66
VZ
359 }
360 return wxWINDOWS; // error if we get here, return generic value
6f65e337
JS
361#else
362 // Win16 code...
2bda0e17 363 int retValue ;
6f65e337 364# ifdef __WINDOWS_386__
2bda0e17 365 retValue = wxWIN386;
6f65e337 366# else
47d67540 367# if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS
81d66cf3
JS
368 extern HANDLE g_hPenWin;
369 retValue = g_hPenWin ? wxPENWINDOWS : wxWINDOWS ;
6f65e337
JS
370# endif
371# endif
2bda0e17
KB
372 // @@@@ To be completed. I don't have the manual here...
373 if (majorVsn) *majorVsn = 3 ;
374 if (minorVsn) *minorVsn = 1 ;
375 return retValue ;
6f65e337 376#endif
2bda0e17
KB
377}
378
379// Reading and writing resources (eg WIN.INI, .Xdefaults)
47d67540 380#if wxUSE_RESOURCES
2bda0e17
KB
381bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
382{
383 if (file != "")
384 return (WritePrivateProfileString((LPCSTR)WXSTRINGCAST section, (LPCSTR)WXSTRINGCAST entry, (LPCSTR)value, (LPCSTR)WXSTRINGCAST file) != 0);
385 else
386 return (WriteProfileString((LPCSTR)WXSTRINGCAST section, (LPCSTR)WXSTRINGCAST entry, (LPCSTR)WXSTRINGCAST value) != 0);
387}
388
389bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
390{
391 char buf[50];
392 sprintf(buf, "%.4f", value);
393 return wxWriteResource(section, entry, buf, file);
394}
395
396bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
397{
398 char buf[50];
399 sprintf(buf, "%ld", value);
400 return wxWriteResource(section, entry, buf, file);
401}
402
403bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
404{
405 char buf[50];
406 sprintf(buf, "%d", value);
407 return wxWriteResource(section, entry, buf, file);
408}
409
410bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
411{
412 static const char defunkt[] = "$$default";
413 if (file != "")
414 {
415 int n = GetPrivateProfileString((LPCSTR)WXSTRINGCAST section, (LPCSTR)WXSTRINGCAST entry, (LPCSTR)defunkt,
416 (LPSTR)wxBuffer, 1000, (LPCSTR)WXSTRINGCAST file);
417 if (n == 0 || strcmp(wxBuffer, defunkt) == 0)
418 return FALSE;
419 }
420 else
421 {
422 int n = GetProfileString((LPCSTR)WXSTRINGCAST section, (LPCSTR)WXSTRINGCAST entry, (LPCSTR)defunkt,
423 (LPSTR)wxBuffer, 1000);
424 if (n == 0 || strcmp(wxBuffer, defunkt) == 0)
425 return FALSE;
426 }
427 if (*value) delete[] (*value);
428 *value = copystring(wxBuffer);
429 return TRUE;
430 }
431
432bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
433{
434 char *s = NULL;
435 bool succ = wxGetResource(section, entry, (char **)&s, file);
436 if (succ)
437 {
438 *value = (float)strtod(s, NULL);
439 delete[] s;
440 return TRUE;
441 }
442 else return FALSE;
443}
444
445bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
446{
447 char *s = NULL;
448 bool succ = wxGetResource(section, entry, (char **)&s, file);
449 if (succ)
450 {
451 *value = strtol(s, NULL, 10);
452 delete[] s;
453 return TRUE;
454 }
455 else return FALSE;
456}
457
458bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
459{
460 char *s = NULL;
461 bool succ = wxGetResource(section, entry, (char **)&s, file);
462 if (succ)
463 {
464 *value = (int)strtol(s, NULL, 10);
465 delete[] s;
466 return TRUE;
467 }
468 else return FALSE;
469}
47d67540 470#endif // wxUSE_RESOURCES
2bda0e17
KB
471
472// Old cursor
473static HCURSOR wxBusyCursorOld = 0;
474static int wxBusyCursorCount = 0;
475
476// Set the cursor to the busy cursor for all windows
477void wxBeginBusyCursor(wxCursor *cursor)
478{
479 wxBusyCursorCount ++;
480 if (wxBusyCursorCount == 1)
481 {
482 wxBusyCursorOld = ::SetCursor((HCURSOR) cursor->GetHCURSOR());
483 }
484 else
485 {
486 (void)::SetCursor((HCURSOR) cursor->GetHCURSOR());
487 }
488}
489
490// Restore cursor to normal
491void wxEndBusyCursor(void)
492{
493 if (wxBusyCursorCount == 0)
494 return;
495
496 wxBusyCursorCount --;
497 if (wxBusyCursorCount == 0)
498 {
499 ::SetCursor(wxBusyCursorOld);
500 wxBusyCursorOld = 0;
501 }
502}
503
504// TRUE if we're between the above two calls
505bool wxIsBusy(void)
506{
507 return (wxBusyCursorCount > 0);
508}
509
743e0a66
VZ
510const char* WXDLLEXPORT wxGetHomeDir(wxString *pstr)
511{
512 wxString& strDir = *pstr;
513
514 #ifdef __UNIX__
515 const char *szHome = getenv("HOME");
516 if ( szHome == NULL ) {
517 // we're homeless...
518 wxLogWarning(_("can't find user's HOME, using current directory."));
519 strDir = ".";
520 }
521 else
522 strDir = szHome;
523
524 // add a trailing slash if needed
525 if ( strDir.Last() != '/' )
526 strDir << '/';
527 #else // Windows
528 #ifdef __WIN32__
529 const char *szHome = getenv("HOMEDRIVE");
530 if ( szHome != NULL )
531 strDir << szHome;
532 szHome = getenv("HOMEPATH");
533 if ( szHome != NULL ) {
534 strDir << szHome;
535
536 // the idea is that under NT these variables have default values
537 // of "%systemdrive%:" and "\\". As we don't want to create our
538 // config files in the root directory of the system drive, we will
539 // create it in our program's dir. However, if the user took care
540 // to set HOMEPATH to something other than "\\", we suppose that he
541 // knows what he is doing and use the supplied value.
542 if ( strcmp(szHome, "\\") != 0 )
543 return strDir.c_str();
544 }
545
546 #else // Win16
547 // Win16 has no idea about home, so use the working directory instead
548 #endif // WIN16/32
549
550 // 260 was taken from windef.h
551 #ifndef MAX_PATH
552 #define MAX_PATH 260
553 #endif
554
555 wxString strPath;
556 ::GetModuleFileName(::GetModuleHandle(NULL),
557 strPath.GetWriteBuf(MAX_PATH), MAX_PATH);
558 strPath.UngetWriteBuf();
559
560 // extract the dir name
561 wxSplitPath(strPath, &strDir, NULL, NULL);
562
563 #endif // UNIX/Win
564
565 return strDir.c_str();
566}
567
2bda0e17
KB
568// Hack for MS-DOS
569char *wxGetUserHome (const wxString& user)
570{
571 char *home;
572 wxString user1(user);
573
574 if (user1 != "") {
575 char tmp[64];
576 if (wxGetUserId(tmp, sizeof(tmp)/sizeof(char))) {
577 // Guests belong in the temp dir
743e0a66
VZ
578 if (Stricmp(tmp, "annonymous") == 0) {
579 if ((home = getenv("TMP")) != NULL ||
580 (home = getenv("TMPDIR")) != NULL ||
581 (home = getenv("TEMP")) != NULL)
582 return *home ? home : "\\";
2bda0e17 583 }
743e0a66
VZ
584 if (Stricmp(tmp, WXSTRINGCAST user1) == 0)
585 user1 = "";
2bda0e17
KB
586 }
587 }
588 if (user1 == "")
589 if ((home = getenv("HOME")) != NULL)
590 {
591 strcpy(wxBuffer, home);
592 Unix2DosFilename(wxBuffer);
593 return wxBuffer;
594 }
595 return NULL; // No home known!
596}
597
598// Check whether this window wants to process messages, e.g. Stop button
599// in long calculations.
600bool wxCheckForInterrupt(wxWindow *wnd)
601{
743e0a66
VZ
602 if(wnd){
603 MSG msg;
604 HWND win= (HWND) wnd->GetHWND();
605 while(PeekMessage(&msg,win,0,0,PM_REMOVE)){
606 TranslateMessage(&msg);
607 DispatchMessage(&msg);
608 }
609 return TRUE;//*** temporary?
610 }
611 else{
612 wxError("wnd==NULL !!!");
613 return FALSE;//*** temporary?
614 }
2bda0e17
KB
615}
616
617// MSW only: get user-defined resource from the .res file.
618// Returns NULL or newly-allocated memory, so use delete[] to clean up.
619
2049ba38 620#ifdef __WXMSW__
2bda0e17
KB
621char *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType)
622{
623 char *s = NULL;
624#ifndef __WIN32__
625 HRSRC hResource = ::FindResource(wxGetInstance(), WXSTRINGCAST resourceName, WXSTRINGCAST resourceType);
626#else
627#ifdef UNICODE
628 HRSRC hResource = ::FindResourceW(wxGetInstance(), WXSTRINGCAST resourceName, WXSTRINGCAST resourceType);
629#else
630 HRSRC hResource = ::FindResourceA(wxGetInstance(), WXSTRINGCAST resourceName, WXSTRINGCAST resourceType);
631#endif
632#endif
633
634 if (hResource == 0)
635 return NULL;
636 HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
637 if (hData == 0)
638 return NULL;
639 char *theText = (char *)LockResource(hData);
640 if (!theText)
641 return NULL;
642
643 s = copystring(theText);
644
645 // Obsolete in WIN32
646#ifndef __WIN32__
647 UnlockResource(hData);
648#endif
649
650 // No need??
651// GlobalFree(hData);
652
653 return s;
654}
655#endif
656
657void wxGetMousePosition( int* x, int* y )
658{
659 POINT pt;
660 GetCursorPos( & pt );
661 *x = pt.x;
662 *y = pt.y;
663};
664
665// Return TRUE if we have a colour display
666bool wxColourDisplay(void)
667{
668 HDC dc = ::GetDC(NULL);
669 bool flag;
670 int noCols = GetDeviceCaps(dc, NUMCOLORS);
671 if ((noCols == -1) || (noCols > 2))
672 flag = TRUE;
673 else
674 flag = FALSE;
675 ReleaseDC(NULL, dc);
676 return flag;
677}
678
679// Returns depth of screen
680int wxDisplayDepth(void)
681{
682 HDC dc = ::GetDC(NULL);
683 int planes = GetDeviceCaps(dc, PLANES);
684 int bitsPerPixel = GetDeviceCaps(dc, BITSPIXEL);
685 int depth = planes*bitsPerPixel;
686 ReleaseDC(NULL, dc);
687 return depth;
688}
689
690// Get size of display
691void wxDisplaySize(int *width, int *height)
692{
693 HDC dc = ::GetDC(NULL);
694 *width = GetDeviceCaps(dc, HORZRES); *height = GetDeviceCaps(dc, VERTRES);
695 ReleaseDC(NULL, dc);
696}
697
7f555861
JS
698bool wxDirExists(const wxString& dir)
699{
700 /* MATTHEW: [6] Always use same code for Win32, call FindClose */
701#if defined(__WIN32__)
702 WIN32_FIND_DATA fileInfo;
703#else
704#ifdef __BORLANDC__
705 struct ffblk fileInfo;
706#else
707 struct find_t fileInfo;
708#endif
709#endif
710
711#if defined(__WIN32__)
712 HANDLE h = FindFirstFile((LPTSTR) WXSTRINGCAST dir,(LPWIN32_FIND_DATA)&fileInfo);
713
714 if (h==INVALID_HANDLE_VALUE)
715 return FALSE;
716 else {
717 FindClose(h);
718 return ((fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
719 }
720#else
721 // In Borland findfirst has a different argument
722 // ordering from _dos_findfirst. But _dos_findfirst
723 // _should_ be ok in both MS and Borland... why not?
724#ifdef __BORLANDC__
725 return ((findfirst(WXSTRINGCAST dir, &fileInfo, _A_SUBDIR) == 0 && (fileInfo.ff_attrib & _A_SUBDIR) != 0));
726#else
727 return (((_dos_findfirst(WXSTRINGCAST dir, _A_SUBDIR, &fileInfo) == 0) && (fileInfo.attrib & _A_SUBDIR)) != 0);
728#endif
729#endif
730}
731
1c4a764c
VZ
732wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
733{
734 wxString str;
735 int len = GetWindowTextLength((HWND)hWnd) + 1;
736 GetWindowText((HWND)hWnd, str.GetWriteBuf(len), len);
737 str.UngetWriteBuf();
738
739 return str;
740}
741
7f555861
JS
742#if 0
743//------------------------------------------------------------------------
744// wild character routines
745//------------------------------------------------------------------------
746
747bool wxIsWild( const wxString& pattern )
748{
749 wxString tmp = pattern;
750 char *pat = WXSTRINGCAST(tmp);
751 while (*pat) {
752 switch (*pat++) {
753 case '?': case '*': case '[': case '{':
754 return TRUE;
755 case '\\':
756 if (!*pat++)
757 return FALSE;
758 }
759 }
760 return FALSE;
761};
762
763
764bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
765{
766 wxString tmp1 = pat;
767 char *pattern = WXSTRINGCAST(tmp1);
768 wxString tmp2 = text;
769 char *str = WXSTRINGCAST(tmp2);
770 char c;
771 char *cp;
772 bool done = FALSE, ret_code, ok;
773 // Below is for vi fans
774 const char OB = '{', CB = '}';
775
776 // dot_special means '.' only matches '.'
777 if (dot_special && *str == '.' && *pattern != *str)
778 return FALSE;
779
780 while ((*pattern != '\0') && (!done)
781 && (((*str=='\0')&&((*pattern==OB)||(*pattern=='*')))||(*str!='\0'))) {
782 switch (*pattern) {
783 case '\\':
784 pattern++;
785 if (*pattern != '\0')
786 pattern++;
787 break;
788 case '*':
789 pattern++;
790 ret_code = FALSE;
791 while ((*str!='\0')
792 && (!(ret_code=wxMatchWild(pattern, str++, FALSE))))
793 /*loop*/;
794 if (ret_code) {
795 while (*str != '\0')
796 str++;
797 while (*pattern != '\0')
798 pattern++;
799 }
800 break;
801 case '[':
802 pattern++;
803 repeat:
804 if ((*pattern == '\0') || (*pattern == ']')) {
805 done = TRUE;
806 break;
807 }
808 if (*pattern == '\\') {
809 pattern++;
810 if (*pattern == '\0') {
811 done = TRUE;
812 break;
813 }
814 }
815 if (*(pattern + 1) == '-') {
816 c = *pattern;
817 pattern += 2;
818 if (*pattern == ']') {
819 done = TRUE;
820 break;
821 }
822 if (*pattern == '\\') {
823 pattern++;
824 if (*pattern == '\0') {
825 done = TRUE;
826 break;
827 }
828 }
829 if ((*str < c) || (*str > *pattern)) {
830 pattern++;
831 goto repeat;
832 }
833 } else if (*pattern != *str) {
834 pattern++;
835 goto repeat;
836 }
837 pattern++;
838 while ((*pattern != ']') && (*pattern != '\0')) {
839 if ((*pattern == '\\') && (*(pattern + 1) != '\0'))
840 pattern++;
841 pattern++;
842 }
843 if (*pattern != '\0') {
844 pattern++, str++;
845 }
846 break;
847 case '?':
848 pattern++;
849 str++;
850 break;
851 case OB:
852 pattern++;
853 while ((*pattern != CB) && (*pattern != '\0')) {
854 cp = str;
855 ok = TRUE;
856 while (ok && (*cp != '\0') && (*pattern != '\0')
857 && (*pattern != ',') && (*pattern != CB)) {
858 if (*pattern == '\\')
859 pattern++;
860 ok = (*pattern++ == *cp++);
861 }
862 if (*pattern == '\0') {
863 ok = FALSE;
864 done = TRUE;
865 break;
866 } else if (ok) {
867 str = cp;
868 while ((*pattern != CB) && (*pattern != '\0')) {
869 if (*++pattern == '\\') {
870 if (*++pattern == CB)
871 pattern++;
872 }
873 }
874 } else {
875 while (*pattern!=CB && *pattern!=',' && *pattern!='\0') {
876 if (*++pattern == '\\') {
877 if (*++pattern == CB || *pattern == ',')
878 pattern++;
879 }
880 }
881 }
882 if (*pattern != '\0')
883 pattern++;
884 }
885 break;
886 default:
887 if (*str == *pattern) {
888 str++, pattern++;
889 } else {
890 done = TRUE;
891 }
892 }
893 }
894 while (*pattern == '*')
895 pattern++;
896 return ((*str == '\0') && (*pattern == '\0'));
897};
898
899#endif
900