📄 ecutils.cpp
字号:
if(int(hInst)<=32/*sei.hInstApp==0*/) { wxString str; switch(int(hInst)) { case 0 : str=wxT("The operating system is out of memory or resources. ");break; case ERROR_FILE_NOT_FOUND : str=wxT("The specified file was not found. ");break; case ERROR_PATH_NOT_FOUND : str=wxT("The specified path was not found. ");break; case ERROR_BAD_FORMAT : str=wxT("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). ");break; case SE_ERR_ACCESSDENIED : str=wxT("The operating system denied access to the specified file. ");break; case SE_ERR_ASSOCINCOMPLETE : str=wxT("The filename association is incomplete or invalid. ");break; case SE_ERR_DDEBUSY : str=wxT("The DDE transaction could not be completed because other DDE transactions were being processed. ");break; case SE_ERR_DDEFAIL : str=wxT("The DDE transaction failed. ");break; case SE_ERR_DDETIMEOUT : str=wxT("The DDE transaction could not be completed because the request timed out. ");break; case SE_ERR_DLLNOTFOUND : str=wxT("The specified dynamic-link library was not found. ");break; //case SE_ERR_FNF : str=wxT("The specified file was not found. ");break; case SE_ERR_NOASSOC : str=wxT("There is no application associated with the given filename extension. ");break; case SE_ERR_OOM : str=wxT("There was not enough memory to complete the operation. ");break; //case SE_ERR_PNF : str=wxT("The specified path was not found. ");break; case SE_ERR_SHARE : str=wxT("A sharing violation occurred. ");break; default: str=wxT("An unexpected error occurred");break; } MessageBoxF(wxT("Failed to open document %s using %s.\r\n%s"),strFileName,szExe,str); } else { rc=true; } } } return rc;}#endifvoid ecUtils::UnicodeToCStr(const wxChar* str,char *&psz){ int nLength=1 + wxStrlen(str); psz=new char[nLength];#ifdef _UNICODE WideCharToMultiByte(CP_ACP, 0, str, -1, psz, nLength, NULL, NULL);#else strcpy(psz,str);#endif}std::string ecUtils::UnicodeToStdStr(const wxChar* str){ std::string stdstr; char *psz; UnicodeToCStr(str,psz); stdstr=std::string(psz); delete psz; return stdstr;}// ecUtils::StripExtraWhitespace() returns a modified version of// a string in which each sequence of whitespace characters is// replaced by a single spacestatic bool ecIsSpace(wxChar ch){ return (ch == wxT(' ') || ch == wxT('\r') || ch == wxT('\n') || ch == wxT('\t'));}wxString ecUtils::StripExtraWhitespace (const wxString & strInput){ wxString strOutput; wxChar* o=strOutput.GetWriteBuf(1+strInput.Len()); for(const wxChar* c=strInput.GetData();*c;c++){ if(ecIsSpace(*c)){ *o++=wxT(' '); if (ecIsSpace(c[1])){ for(c=c+2; ecIsSpace(*c);c++); c--; } } else { *o++=*c; } } *o=0; strOutput.UngetWriteBuf(); strOutput.Trim(TRUE); strOutput.Trim(FALSE); return strOutput;#if 0 wxString strOutput; LPTSTR o=strOutput.GetBuffer(1+strInput.GetLength()); for(LPCTSTR c=strInput;*c;c++){ if(_istspace(*c)){ *o++=_TCHAR(' '); if (_istspace(c[1])){ for(c=c+2;_istspace(*c);c++); c--; } } else { *o++=*c; } } *o=0; strOutput.ReleaseBuffer(); strOutput.TrimLeft(); strOutput.TrimRight(); return strOutput;#endif}#if 0ecFileName ecUtils::WPath(const std::string &str){ // Convert a path as read from cdl into host format // Change / to \ throughout ecFileName strPath(str.c_str()); strPath.Replace (_TCHAR('/'), _TCHAR('\\')); return strPath;}// Copy file helper function.// This makes sure the destination file is only touched as necessary.// It is written using Posix calls lest it should be more broadly applicable.bool ecUtils::CopyFile(LPCTSTR pszSource,LPCTSTR pszDest){ // Compare the files. First set rc to the result of the comparison (true if the same) bool rc=false; struct _stat s1,s2; if(-1!=_tstat(pszSource,&s1) && -1!=_tstat(pszDest,&s2) && s1.st_size==s2.st_size){ // Files both exist and are of equal size FILE *f1=_tfopen(pszSource,wxT("rb")); if(f1){ FILE *f2=_tfopen(pszDest,wxT("rb")); if(f2){ int nSize1,nSize2; rc=true; do{ char buf1[4096],buf2[4096]; nSize1=fread(buf1,1,sizeof buf1,f1); nSize2=fread(buf2,1,sizeof buf2,f2); if(nSize1!=nSize2 || 0!=memcmp(buf1,buf2,nSize1)){ rc=false; break; } } while (nSize1>0); fclose(f2); } fclose(f1); } } if(rc){ // Files are identical } else { rc=TRUE==::CopyFile(pszSource,pszDest,FALSE); if(rc){ } else { MessageBoxF(wxT("Failed to copy '%s' to '%s' - %s"),pszSource,pszDest,GetLastErrorMessageString()); } } return rc;}#endif/* * wxStringToStringMap * * Stores string values keyed by strings */void wxStringToStringMap::Set(const wxString& key, const wxString& value){ wxString oldValue; if (Find(key, oldValue)) Remove(key); m_hashTable.Put(key, (wxObject*) new wxString(value));}bool wxStringToStringMap::Remove(const wxString& key){ wxString* str = (wxString*) m_hashTable.Delete(key); if (str) { delete str; return TRUE; } else return FALSE;}bool wxStringToStringMap::Find(const wxString& key, wxString& value){ wxString* str = (wxString*) m_hashTable.Get(key); if (str) { value = * str; return TRUE; } else return FALSE;}void wxStringToStringMap::Clear(){ m_hashTable.BeginFind(); wxNode* node; while ((node = m_hashTable.Next())) { wxString* str = (wxString*) node->Data(); delete str; }}void wxStringToStringMap::BeginFind(){ m_hashTable.BeginFind();}bool wxStringToStringMap::Next(wxString& key, wxString& value){ wxNode* node = m_hashTable.Next(); if (node) { value = * (wxString*) node->Data(); return TRUE; } else return FALSE;}// Is str a member of arr?bool wxArrayStringIsMember(const wxArrayString& arr, const wxString& str){ size_t i; for (i = (size_t) 0; i < arr.GetCount(); i++) if (arr[i] == str) return TRUE; return FALSE;}// Eliminate .. and .wxString wxGetRealPath(const wxString& path){ wxChar* p = new wxChar[path.Len() + 1]; wxStrcpy(p, (const wxChar*) path); wxRealPath(p); wxString str(p); delete[] p; return str;}// A version of the above but prepending 'cwd' (current path) first// if 'path' is relativewxString wxGetRealPath(const wxString& cwd, const wxString& path){ wxString path1(path); if (!wxIsAbsolutePath(path)) { path1 = cwd; if (path1.Last() != wxFILE_SEP_PATH) path1 += wxFILE_SEP_PATH; path1 += path; } return wxGetRealPath(path1);}// Find the absolute path where this application has been run from.// argv0 is wxTheApp->argv[0]// cwd is the current working directory (at startup)// appVariableName is the name of a variable containing the directory for this app, e.g.// MYAPPDIR. This is checked first.wxString wxFindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName){ wxString str; // Try appVariableName if (!appVariableName.IsEmpty()) { str = wxGetenv(appVariableName); if (!str.IsEmpty()) return str; } if (wxIsAbsolutePath(argv0)) return wxPathOnly(argv0); else { // Is it a relative path? wxString currentDir(cwd); if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH; str = currentDir + argv0; if (wxFileExists(str)) return wxPathOnly(str); } // OK, it's neither an absolute path nor a relative path. // Search PATH. wxPathList pathList; pathList.AddEnvList(wxT("PATH")); str = pathList.FindAbsoluteValidPath(argv0); if (!str.IsEmpty()) return wxPathOnly(str); // Failed return wxEmptyString;}// Make a path name with no separators, out of a full pathname,// e.g. opt_ecos_ecos-1.4.5 out of /opt/ecos/ecos-1.4.5wxString ecMakeNameFromPath(const wxString& path){ wxString p(path); p.Replace(wxT("/"), wxT("_")); p.Replace(wxT("\\"), wxT("_")); p.Replace(wxT(":"), wxT("_")); return p;}// Find the text of the list control item at the given columnwxString wxListCtrlGetItemTextColumn(wxListCtrl& listCtrl, long item, int col){ wxListItem listItem; listItem.m_mask = wxLIST_MASK_TEXT; listItem.m_itemId = item; listItem.m_col = col; if (listCtrl.GetItem(listItem)) return listItem.m_text; else return wxEmptyString;}// Select the given itemvoid wxListCtrlSelectItem(wxListCtrl& listCtrl, long sel, bool deselectOthers){ long n = listCtrl.GetItemCount(); long i; if (deselectOthers) { for (i = 0; i < n; i++) { if (listCtrl.GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) { listCtrl.SetItemState(i, wxLIST_STATE_SELECTED, 0); } } } listCtrl.SetItemState(sel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);}// Find the selectionlong wxListCtrlGetSelection(wxListCtrl& listCtrl){ long n = listCtrl.GetItemCount(); long i; for (i = 0; i < n; i++) { if (listCtrl.GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) { return i; } } return -1;}// Find which column the cursor is onint wxListCtrlFindColumn(wxListCtrl& listCtrl, int noCols, int x){ int col = 0; // Find which column we're on int width = 0; int i; for (i = 0; i < noCols; i++) { width += listCtrl.GetColumnWidth(i); if (x <= width) { col = i; break; } } return col;}// Utility functionvoid wxRefreshControls(wxWindow* win){ wxNode *node = win->GetChildren().First(); while (node) { wxWindow* win = (wxWindow*) node->Data(); win->Refresh(); node = node->Next(); }}wxOutputStream& operator <<(wxOutputStream& stream, const wxString& s){ stream.Write(s, s.Length());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -