diff --git a/include/wx/list.h b/include/wx/list.h index bfd500d94f..e3c8284fb6 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -37,10 +37,6 @@ #include "wx/object.h" #include "wx/string.h" -// due to circular header dependencies this function has to be declared here -// (normally it's found in utils.h which includes itself list.h...) -extern WXDLLIMPEXP_BASE wxChar* copystring(const wxChar *s); - class WXDLLIMPEXP_BASE wxObjectListNode; typedef wxObjectListNode wxNode; @@ -568,12 +564,10 @@ public: // operations // makes a copy of the string - wxNode *Add(const wxChar *s) - { return (wxNode *)wxStringListBase::Append(copystring(s)); } + wxNode *Add(const wxChar *s); // Append to beginning of list - wxNode *Prepend(const wxChar *s) - { return (wxNode *)wxStringListBase::Insert(copystring(s)); } + wxNode *Prepend(const wxChar *s); bool Delete(const wxChar *s); diff --git a/include/wx/utils.h b/include/wx/utils.h index 0880439f85..8d41542f1e 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -57,7 +57,9 @@ class WXDLLIMPEXP_BASE wxPoint; // ---------------------------------------------------------------------------- // Make a copy of this string using 'new' +#if WXWIN_COMPATIBILITY_2_4 WXDLLIMPEXP_BASE wxChar* copystring(const wxChar *s); +#endif #if WXWIN_COMPATIBILITY_2 // Matches string one within string two regardless of case diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 17fcf47504..8714a27a85 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1988,6 +1988,18 @@ void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, in // File history processor // ---------------------------------------------------------------------------- +static inline wxChar* MYcopystring(const wxString& s) +{ + wxChar* copy = new wxChar[s.length() + 1]; + return wxStrcpy(copy, s.c_str()); +} + +static inline wxChar* MYcopystring(const wxChar* s) +{ + wxChar* copy = new wxChar[wxStrlen(s) + 1]; + return wxStrcpy(copy, s); +} + wxFileHistory::wxFileHistory(size_t maxFiles, wxWindowID idBase) { m_fileMaxFiles = maxFiles; @@ -2058,7 +2070,7 @@ void wxFileHistory::AddFileToHistory(const wxString& file) { m_fileHistory[i] = m_fileHistory[i-1]; } - m_fileHistory[0] = copystring(file); + m_fileHistory[0] = MYcopystring(file); // this is the directory of the last opened file wxString pathCurrent; @@ -2187,7 +2199,7 @@ void wxFileHistory::Load(wxConfigBase& config) wxString historyFile; while ((m_fileHistoryN < m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != wxT(""))) { - m_fileHistory[m_fileHistoryN] = copystring((const wxChar*) historyFile); + m_fileHistory[m_fileHistoryN] = MYcopystring((const wxChar*) historyFile); m_fileHistoryN ++; buf.Printf(wxT("file%d"), (int)m_fileHistoryN+1); historyFile = wxT(""); diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 3e6489ad19..6080ca0308 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -215,6 +215,18 @@ WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ) IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) +static inline wxChar* MYcopystring(const wxString& s) +{ + wxChar* copy = new wxChar[s.length() + 1]; + return wxStrcpy(copy, s.c_str()); +} + +static inline wxChar* MYcopystring(const wxChar* s) +{ + wxChar* copy = new wxChar[wxStrlen(s) + 1]; + return wxStrcpy(copy, s); +} + void wxPathList::Add (const wxString& path) { wxStringList::Add (WXSTRINGCAST path); @@ -239,7 +251,7 @@ void wxPathList::AddEnvList (const wxString& envVariable) wxChar *val = wxGetenv (WXSTRINGCAST envVariable); if (val && *val) { - wxChar *s = copystring (val); + wxChar *s = MYcopystring (val); wxChar *save_ptr, *token = wxStrtok (s, PATH_TOKS, &save_ptr); if (token) @@ -502,9 +514,9 @@ wxChar *wxCopyAbsolutePath(const wxString& filename) wxStrcat(buf, wxT("/")); #endif wxStrcat(buf, wxFileFunctionsBuffer); - return copystring( wxRealPath(buf) ); + return MYcopystring( wxRealPath(buf) ); } - return copystring( wxFileFunctionsBuffer ); + return MYcopystring( wxFileFunctionsBuffer ); } /*- @@ -553,7 +565,7 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) buf[0] = wxT('\0'); if (name == NULL || *name == wxT('\0')) return buf; - nm = copystring(name); // Make a scratch copy + nm = MYcopystring(name); // Make a scratch copy wxChar *nm_tmp = nm; /* Skip leading whitespace and cr */ @@ -1385,7 +1397,7 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) if ( buf ) wxStrcpy(buf, filename); else - buf = copystring(filename); + buf = MYcopystring(filename); return buf; } diff --git a/src/common/list.cpp b/src/common/list.cpp index b9c9e06388..fed64c544f 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -35,7 +35,6 @@ #ifndef WX_PRECOMP #include "wx/defs.h" #include "wx/list.h" - #include "wx/utils.h" // for copystring() (beurk...) #endif // ============================================================================= @@ -572,9 +571,21 @@ void wxObjectListNode::DeleteData() delete (wxObject *)GetData(); } -// ----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // wxStringList -// ----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- + +static inline wxChar* MYcopystring(const wxString& s) +{ + wxChar* copy = new wxChar[s.length() + 1]; + return wxStrcpy(copy, s.c_str()); +} + +static inline wxChar* MYcopystring(const wxChar* s) +{ + wxChar* copy = new wxChar[wxStrlen(s) + 1]; + return wxStrcpy(copy, s); +} IMPLEMENT_DYNAMIC_CLASS(wxStringList, wxObject) @@ -656,7 +667,7 @@ wxChar **wxStringList::ListToArray(bool new_copies) const { wxChar *s = node->GetData(); if ( new_copies ) - string_array[i] = copystring(s); + string_array[i] = MYcopystring(s); else string_array[i] = s; node = node->GetNext(); @@ -709,5 +720,15 @@ void wxStringList::Sort() delete [] array; } +wxNode *wxStringList::Add(const wxChar *s) +{ + return (wxNode *)wxStringListBase::Append(MYcopystring(s)); +} + +wxNode *wxStringList::Prepend(const wxChar *s) +{ + return (wxNode *)wxStringListBase::Insert(MYcopystring(s)); +} + #endif // wxLIST_COMPATIBILITY diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 03deb7925c..4b732fd498 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -557,7 +557,9 @@ wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out) } else { - out = copystring(s); + // MYcopystring - for easier search... + out = new wxChar[s.length() + 1]; + wxStrcpy(out, s.c_str()); } return out;