// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
const wxChar *wxFatalErrorStr = wxT("wxWindows Fatal Error");
#endif // WXWIN_COMPATIBILITY_2_2
-// ----------------------------------------------------------------------------
-// function protoypes
-// ----------------------------------------------------------------------------
-
// ============================================================================
// implementation
// ============================================================================
-// ----------------------------------------------------------------------------
-// string functions
-// ----------------------------------------------------------------------------
-
-#if defined(__WXMAC__) && !defined(__DARWIN__)
-int strcasecmp(const char *str_1, const char *str_2)
-{
- register char c1, c2;
- do {
- c1 = tolower(*str_1++);
- c2 = tolower(*str_2++);
- } while ( c1 && (c1 == c2) );
-
- return c1 - c2;
-}
-
-int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
-{
-
- register char c1, c2;
- while( maxchar--)
- {
- c1 = tolower(*str_1++);
- c2 = tolower(*str_2++);
-
- if ( !c1 || c1!=c2 )
- return c1 - c2;
-
- } ;
-
- return 0 ;
-
-}
-#endif // __WXMAC__ && !__DARWIN__
-
-#if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
-// we have no strI functions under VMS, therefore I have implemented
-// an inefficient but portable version: convert copies of strings to lowercase
-// and then use the normal comparison
-static void myLowerString(char *s)
-{
- while(*s){
- if(isalpha(*s)) *s = (char)tolower(*s);
- s++;
- }
-}
-
-int strcasecmp(const char *str_1, const char *str_2)
-{
- char *temp1 = new char[strlen(str_1)+1];
- char *temp2 = new char[strlen(str_2)+1];
- strcpy(temp1,str_1);
- strcpy(temp2,str_2);
- myLowerString(temp1);
- myLowerString(temp2);
-
- int result = wxStrcmp(temp1,temp2);
- delete[] temp1;
- delete[] temp2;
-
- return(result);
-}
-
-int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
-{
- char *temp1 = new char[strlen(str_1)+1];
- char *temp2 = new char[strlen(str_2)+1];
- strcpy(temp1,str_1);
- strcpy(temp2,str_2);
- myLowerString(temp1);
- myLowerString(temp2);
-
- int result = strncmp(temp1,temp2,maxchar);
- delete[] temp1;
- delete[] temp2;
-
- return(result);
-}
-#endif // __VMS__
-
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) && !defined(__WXWINE__)
-
-#ifndef __GNUWIN32__
-#ifndef __MWERKS__
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#else
-#define strcasecmp _stricmp
-#define strncasecmp _strnicmp
-#endif
-#endif
-
-#else
-
-#ifdef __EMX__
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
-// This declaration is missing in SunOS!
-// (Yes, I know it is NOT ANSI-C but its in BSD libc)
-#if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
-extern "C"
-{
- int strcasecmp (const char *, const char *);
- int strncasecmp (const char *, const char *, size_t);
-}
-#endif
-#endif /* __WXMSW__ */
-
-#ifdef __WXPM__
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
-#ifdef __WATCOMC__
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
wxChar *
copystring (const wxChar *s)
{
wxCurrentId = id + 1;
}
+// ----------------------------------------------------------------------------
+// String <-> Number conversions (deprecated)
+// ----------------------------------------------------------------------------
+
+#if WXWIN_COMPATIBILITY_2_4
+
+WXDLLEXPORT_DATA(const wxChar *) wxFloatToStringStr = wxT("%.2f");
+WXDLLEXPORT_DATA(const wxChar *) wxDoubleToStringStr = wxT("%.2f");
+
void
StringToFloat (const wxChar *s, float *number)
{
return buf;
}
+#endif // WXWIN_COMPATIBILITY_2_4
+
// Array used in DecToHex conversion routine.
static wxChar hexArray[] = wxT("0123456789ABCDEF");
return wxString(buf);
}
-// Match a string INDEPENDENT OF CASE
+#if WXWIN_COMPATIBILITY_2
bool
-StringMatch (const char *str1, const char *str2, bool subString, bool exact)
+StringMatch (const wxChar *str1, const wxChar *str2, bool subString, bool exact)
{
if (str1 == NULL || str2 == NULL)
return FALSE;
if (subString)
{
- int len1 = strlen (str1);
- int len2 = strlen (str2);
+ int len1 = wxStrlen (str1);
+ int len2 = wxStrlen (str2);
int i;
// Search for str1 in str2
// Slow .... but acceptable for short strings
for (i = 0; i <= len2 - len1; i++)
{
- if (strncasecmp (str1, str2 + i, len1) == 0)
+ if (wxStrnicmp (str1, str2 + i, len1) == 0)
return TRUE;
}
}
else if (exact)
{
- if (strcasecmp (str1, str2) == 0)
+ if (wxStricmp (str1, str2) == 0)
return TRUE;
}
else
{
- int len1 = strlen (str1);
- int len2 = strlen (str2);
+ int len1 = wxStrlen (str1);
+ int len2 = wxStrlen (str2);
- if (strncasecmp (str1, str2, wxMin (len1, len2)) == 0)
+ if (wxStrnicmp (str1, str2, wxMin (len1, len2)) == 0)
return TRUE;
}
return FALSE;
}
+#endif
// Return the current date/time
// [volatile]
wxString wxNow()
{
- time_t now = time((time_t *) NULL);
- char *date = ctime(&now);
- date[24] = '\0';
- return wxString(date);
+ time_t now = time((time_t *) NULL);
+ char *date = ctime(&now);
+ date[24] = '\0';
+ return wxString::FromAscii(date);
}
#if wxUSE_GUI
if (frame->GetToolBar())
extraChildren.Append(frame->GetToolBar());
- wxNode* node = extraChildren.First();
+ wxNode* node = extraChildren.GetFirst();
while (node)
{
- wxWindow* child = (wxWindow*) node->Data();
+ wxWindow* child = (wxWindow*) node->GetData();
wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
if (foundWin)
return foundWin;
}
*/
- wxNode* node = win->GetChildren().Last();
+ wxWindowList::Node *node = win->GetChildren().GetLast();
while (node)
{
- wxWindow* child = (wxWindow*) node->Data();
+ wxWindow* child = node->GetData();
wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
if (foundWin)
return foundWin;
- node = node->Previous();
+ node = node->GetPrevious();
}
wxPoint pos = win->GetPosition();
// Go backwards through the list since windows
// on top are likely to have been appended most
// recently.
- wxNode* node = wxTopLevelWindows.Last();
+ wxWindowList::Node *node = wxTopLevelWindows.GetLast();
while (node)
{
- wxWindow* win = (wxWindow*) node->Data();
+ wxWindow* win = node->GetData();
wxWindow* found = wxFindWindowAtPoint(win, pt);
if (found)
return found;
- node = node->Previous();
+ node = node->GetPrevious();
}
return NULL;
}
// missing C RTL functions (FIXME shouldn't be here at all)
// ----------------------------------------------------------------------------
-#ifdef __MWERKS__
-#if __MSL__ < 0x7000
+#if defined( __MWERKS__ ) && !defined(__MACH__)
char *strdup(const char *s)
{
return strcpy( (char*) malloc( strlen( s ) + 1 ) , s ) ;
}
-#endif
int isascii( int c )
{
return ( c >= 0 && c < 128 ) ;
// Yield to other apps/messages and disable user input to all windows except
// the given one
-bool wxSafeYield(wxWindow *win)
+bool wxSafeYield(wxWindow *win, bool onlyIfNeeded)
{
wxWindowDisabler wd(win);
- bool rc = wxYield();
+ bool rc;
+ if (onlyIfNeeded)
+ rc = wxYieldIfNeeded();
+ else
+ rc = wxYield();
return rc;
}
const wxChar *wxGetInstallPrefix()
{
wxString prefix;
-
+
if ( wxGetEnv(wxT("WXPREFIX"), &prefix) )
return prefix.c_str();
-
+
#ifdef wxINSTALL_PREFIX
return wxT(wxINSTALL_PREFIX);
-#else
+#else
return wxT("");
#endif
}
// wxExecute
// ----------------------------------------------------------------------------
+// wxDoExecuteWithCapture() helper: reads an entire stream into one array
+//
+// returns TRUE if ok, FALSE if error
+#if wxUSE_STREAMS
+static bool ReadAll(wxInputStream *is, wxArrayString& output)
+{
+ wxCHECK_MSG( is, FALSE, _T("NULL stream in wxExecute()?") );
+
+ // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
+ is->Reset();
+
+ wxTextInputStream tis(*is);
+
+ bool cont = TRUE;
+ while ( cont )
+ {
+ wxString line = tis.ReadLine();
+ if ( is->Eof() )
+ break;
+
+ if ( !*is )
+ {
+ cont = FALSE;
+ }
+ else
+ {
+ output.Add(line);
+ }
+ }
+
+ return cont;
+}
+#endif // wxUSE_STREAMS
+
// this is a private function because it hasn't a clean interface: the first
// array is passed by reference, the second by pointer - instead we have 2
// public versions of wxExecute() below
#if wxUSE_STREAMS
if ( rc != -1 )
{
- wxInputStream* is = process->GetInputStream();
- wxCHECK_MSG( is, -1, _T("if wxExecute() succeded, stream can't be NULL") );
- wxTextInputStream tis(*is);
+ if ( !ReadAll(process->GetInputStream(), output) )
+ rc = -1;
- wxTextInputStream *tes = NULL;
- wxInputStream *es = NULL;
if ( error )
{
- es = process->GetErrorStream();
-
- wxCHECK_MSG( es, -1, _T("stderr can't be NULL") );
-
- tes = new wxTextInputStream(*es);
- }
-
- bool cont;
- do
- {
- cont = FALSE;
-
- if ( !is->Eof() && is->IsOk() )
- {
- wxString line = tis.ReadLine();
- if ( is->LastError() )
- break;
-
- cont = TRUE;
-
- output.Add(line);
- }
-
- if ( error && !es->Eof() && es->IsOk() )
- {
- wxString line = tes->ReadLine();
- if ( es->LastError() )
- break;
-
- cont = TRUE;
-
- error->Add(line);
- }
+ if ( !ReadAll(process->GetErrorStream(), *error) )
+ rc = -1;
}
- while ( cont );
- delete tes;
}
#endif // wxUSE_STREAMS