X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7007fcfced6e51c61295b987f7edddbc2b7f699e..884470b12ee25b20796bfef11a9bfa5fb1e1511c:/src/common/utilscmn.cpp?ds=sidebyside diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 349d6f04a0..1488ca866c 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -26,15 +26,21 @@ #include "wx/window.h" #include "wx/menu.h" #include "wx/frame.h" +#include "wx/msgdlg.h" +#include "wx/textdlg.h" #endif -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include +#include #else #include +#include +# ifdef _MSC_VER + using namespace std; +# endif #endif -#include #include #include #include @@ -45,8 +51,14 @@ #endif #endif #include +#ifndef __MWERKS__ #include #include +#endif + +#ifdef __SALFORDC__ +#include +#endif // Pattern matching code. // Yes, this path is deliberate (for Borland compilation) @@ -56,7 +68,7 @@ #include "../common/glob.inc" #endif -#ifdef __WINDOWS__ +#ifdef __WXMSW__ #include "windows.h" #endif @@ -64,6 +76,36 @@ extern char *wxBuffer; +#ifdef __WXMAC__ +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 #ifdef __VMS__ // we have no strI functions under VMS, therefore I have implemented // an inefficient but portable version: convert copies of strings to lowercase @@ -112,8 +154,13 @@ int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) #ifdef __WINDOWS__ #ifndef __GNUWIN32__ +#ifndef __MWERKS__ #define strcasecmp stricmp #define strncasecmp strnicmp +#else +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#endif #endif #ifdef _MSC_VER @@ -134,7 +181,7 @@ extern "C" int strncasecmp (const char *, const char *, size_t); } #endif -#endif /* __WINDOWS__ */ +#endif /* __WXMSW__ */ char * @@ -172,14 +219,14 @@ void StringToFloat (char *s, float *number) { if (s && *s && number) - *number = (float) strtod (s, NULL); + *number = (float) strtod (s, (char **) NULL); } void StringToDouble (char *s, double *number) { if (s && *s && number) - *number = strtod (s, NULL); + *number = strtod (s, (char **) NULL); } char * @@ -205,14 +252,14 @@ void StringToInt (char *s, int *number) { if (s && *s && number) - *number = (int) strtol (s, NULL, 10); + *number = (int) strtol (s, (char **) NULL, 10); } void StringToLong (char *s, long *number) { if (s && *s && number) - *number = strtol (s, NULL, 10); + *number = strtol (s, (char **) NULL, 10); } char * @@ -238,19 +285,19 @@ static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A' 'C', 'D', 'E', 'F' }; // Convert 2-digit hex number to decimal -int wxHexToDec(char *buf) +int wxHexToDec(const wxString& buf) { int firstDigit, secondDigit; - if (buf[0] >= 'A') - firstDigit = buf[0] - 'A' + 10; + if (buf.GetChar(0) >= 'A') + firstDigit = buf.GetChar(0) - 'A' + 10; else - firstDigit = buf[0] - '0'; + firstDigit = buf.GetChar(0) - '0'; - if (buf[1] >= 'A') - secondDigit = buf[1] - 'A' + 10; + if (buf.GetChar(1) >= 'A') + secondDigit = buf.GetChar(1) - 'A' + 10; else - secondDigit = buf[1] - '0'; + secondDigit = buf.GetChar(1) - '0'; return firstDigit * 16 + secondDigit; } @@ -265,6 +312,14 @@ void wxDecToHex(int dec, char *buf) buf[2] = 0; } +// Convert decimal integer to 2-character hex string +wxString wxDecToHex(int dec) +{ + char buf[3]; + wxDecToHex(dec, buf); + return wxString(buf); +} + // Match a string INDEPENDENT OF CASE bool StringMatch (char *str1, char *str2, bool subString, bool exact) @@ -309,7 +364,7 @@ StringMatch (char *str1, char *str2, bool subString, bool exact) // [volatile] wxString wxNow( void ) { - time_t now = time(NULL); + time_t now = time((time_t *) NULL); char *date = ctime(&now); date[24] = '\0'; return wxString(date); @@ -344,7 +399,7 @@ wxGetEmailAddress (char *address, int maxSize) char *wxStripMenuCodes (char *in, char *out) { if (!in) - return NULL; + return (char *) NULL; if (!out) out = copystring(in); @@ -376,6 +431,14 @@ char *wxStripMenuCodes (char *in, char *out) return tmpOut; } +wxString wxStripMenuCodes(const wxString& str) +{ + char *buf = new char[str.Length() + 1]; + wxStripMenuCodes((char*) (const char*) str, buf); + wxString str1(buf); + delete[] buf; + return str1; +} /* * Window search functions @@ -408,7 +471,7 @@ wxFindWindowByLabel (const wxString& title, wxWindow * parent) } // for() } - return NULL; + return (wxWindow *) NULL; } // Recursive @@ -423,7 +486,7 @@ wxFindWindowByLabel1 (const wxString& title, wxWindow * parent) if (parent) { - for (wxNode * node = parent->GetChildren()->First (); node; node = node->Next ()) + for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ()) { wxWindow *win = (wxWindow *) node->Data (); wxWindow *retwin = wxFindWindowByLabel1 (title, win); @@ -433,7 +496,7 @@ wxFindWindowByLabel1 (const wxString& title, wxWindow * parent) } - return NULL; // Not found + return (wxWindow *) NULL; // Not found } @@ -479,7 +542,7 @@ wxFindWindowByName1 (const wxString& title, wxWindow * parent) if (parent) { - for (wxNode * node = parent->GetChildren()->First (); node; node = node->Next ()) + for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ()) { wxWindow *win = (wxWindow *) node->Data (); wxWindow *retwin = wxFindWindowByName1 (title, win); @@ -489,7 +552,7 @@ wxFindWindowByName1 (const wxString& title, wxWindow * parent) } - return NULL; // Not found + return (wxWindow *) NULL; // Not found } @@ -503,50 +566,6 @@ wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& i return menuBar->FindMenuItem (menuString, itemString); } -/* - * wxDebugStreamBuf - */ -#if !defined(_WINDLL) - -wxDebugStreamBuf::wxDebugStreamBuf(void) -{ - if (allocate()) setp(base(),ebuf()); -} - -int wxDebugStreamBuf::overflow(int WXUNUSED(i)) -{ - int len = pptr() - pbase(); - char *txt = new char[len+1]; - strncpy(txt, pbase(), len); - txt[len] = '\0'; -#ifdef __WINDOWS__ - OutputDebugString((LPCSTR)txt); -#else - fprintf(stderr, txt); -#endif - setp(pbase(), epptr()); - delete[] txt; - return EOF; -} - -int wxDebugStreamBuf::sync(void) -{ - int len = pptr() - pbase(); - char *txt = new char[len+1]; - strncpy(txt, pbase(), len); - txt[len] = '\0'; -#ifdef __WINDOWS__ - OutputDebugString((LPCSTR)txt); -#else - fprintf(stderr, txt); -#endif - setp(pbase(), epptr()); - delete[] txt; - return 0; -} - -#endif - /* On Fri, 21 Jul 1995, Paul Craven wrote: @@ -740,3 +759,93 @@ whereami(name) #endif +/* + * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp + * since otherwise the generic code may be pulled in unnecessarily. + */ + +int wxMessageBox(const wxString& message, const wxString& caption, long style, + wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) ) +{ + wxMessageDialog dialog(parent, message, caption, style); + + int ans = dialog.ShowModal(); + switch ( ans ) + { + case wxID_OK: + return wxOK; + break; + case wxID_YES: + return wxYES; + break; + case wxID_NO: + return wxNO; + break; + default: + case wxID_CANCEL: + return wxCANCEL; + break; + } + return ans; +} + +wxString wxGetTextFromUser(const wxString& message, const wxString& caption, + const wxString& defaultValue, wxWindow *parent, + int x, int y, bool WXUNUSED(centre) ) +{ + wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y)); + if (dialog.ShowModal() == wxID_OK) + return dialog.GetValue(); + else + return wxString(""); +} + +#ifdef __MWERKS__ +char *strdup(const char *s) +{ + return strcpy( (char*) malloc( strlen( s ) + 1 ) , s ) ; +} + +int isascii( int c ) +{ + return ( c >= 0 && c < 128 ) ; +} +#endif + +// Overloaded functions, taking a wxString +bool wxGetHostName(wxString& name) +{ + bool success = wxGetHostName(wxBuffer, 500); + if (success) + { + name = wxBuffer; + return TRUE; + } + else + return FALSE; +} + +bool wxGetUserId(wxString& buf) +{ + bool success = wxGetUserId(wxBuffer, 500); + if (success) + { + buf = wxBuffer; + return TRUE; + } + else + return FALSE; +} + +bool wxGetUserName(wxString& buf) +{ + bool success = wxGetUserName(wxBuffer, 500); + if (success) + { + buf = wxBuffer; + return TRUE; + } + else + return FALSE; +} +