X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d7463f75f9c170c29b4965d27dccf535ac32cfde..4997d3014cd76b41f2d4036dfd168ad886972f35:/utils/configtool/src/utils.cpp diff --git a/utils/configtool/src/utils.cpp b/utils/configtool/src/utils.cpp index d1bdefb514..8af87a6d8e 100644 --- a/utils/configtool/src/utils.cpp +++ b/utils/configtool/src/utils.cpp @@ -27,6 +27,7 @@ #include "wx/variant.h" #include "wx/cshelp.h" #include "wx/cmdline.h" +#include "wx/imaglist.h" #include @@ -45,17 +46,17 @@ int apDetermineImageType(const wxString& filename) wxSplitPath(filename, & path, & name, & ext); ext.MakeLower(); - if (ext == "jpg" || ext == "jpeg") + if (ext == _T("jpg") || ext == _T("jpeg")) return wxBITMAP_TYPE_JPEG; - else if (ext == "gif") + else if (ext == _T("gif")) return wxBITMAP_TYPE_GIF; - else if (ext == "bmp") + else if (ext == _T("bmp")) return wxBITMAP_TYPE_BMP; - else if (ext == "png") + else if (ext == _T("png")) return wxBITMAP_TYPE_PNG; - else if (ext == "pcx") + else if (ext == _T("pcx")) return wxBITMAP_TYPE_PCX; - else if (ext == "tif" || ext == "tiff") + else if (ext == _T("tif") || ext == _T("tiff")) return wxBITMAP_TYPE_TIF; else return -1; @@ -76,12 +77,9 @@ wxString apColourToHexString(const wxColour& col) // Convert 6-digit hex string to a colour wxColour apHexStringToColour(const wxString& hex) { - unsigned int r = 0; - unsigned int g = 0; - unsigned int b = 0; - r = wxHexToDec(hex.Mid(0, 2)); - g = wxHexToDec(hex.Mid(2, 2)); - b = wxHexToDec(hex.Mid(4, 2)); + unsigned int r = wxHexToDec(hex.Mid(0, 2)); + unsigned int g = wxHexToDec(hex.Mid(2, 2)); + unsigned int b = wxHexToDec(hex.Mid(4, 2)); return wxColour(r, g, b); } @@ -97,6 +95,14 @@ wxString apFontToString(const wxFont& font) return str; } +static inline int StringToInt(const wxString& s) +{ + long tmp; + s.ToLong(&tmp); + + return int(tmp); +} + // Convert a string to a wxFont wxFont apStringToFont(const wxString& str) { @@ -115,7 +121,7 @@ wxFont apStringToFont(const wxString& str) if (i == 0) { - StringToInt(token, & pointSize); + pointSize = StringToInt(token); #if defined(__WXGTK__) || defined(__WXMAC__) if (pointSize < 8) pointSize = 8; @@ -124,13 +130,13 @@ wxFont apStringToFont(const wxString& str) #endif } else if (i == 1) - StringToInt(token, & family); + family = StringToInt(token); else if (i == 2) - StringToInt(token, & style); + style = StringToInt(token); else if (i == 3) - StringToInt(token, & weight); + weight = StringToInt(token); else if (i == 4) - StringToInt(token, & underlined); + underlined = StringToInt(token); else if (i == 5) { facename = token; @@ -150,7 +156,7 @@ wxFont apStringToFont(const wxString& str) int apFindNotebookPage(wxNotebook* notebook, const wxString& name) { int i; - for (i = 0; i < notebook->GetPageCount(); i++) + for (i = 0; i < (int)notebook->GetPageCount(); i++) if (name == notebook->GetPageText(i)) return i; return -1; @@ -167,11 +173,11 @@ void apViewHTMLFile(const wxString& url) TCHAR szCmdName[1024]; DWORD dwType, dw = sizeof(szCmdName); LONG lRes; - lRes = RegOpenKey(HKEY_CLASSES_ROOT, "htmlfile\\shell\\open\\command", &hKey); + lRes = RegOpenKey(HKEY_CLASSES_ROOT, _T("htmlfile\\shell\\open\\command"), &hKey); if(lRes == ERROR_SUCCESS && RegQueryValueEx(hKey,(LPTSTR)NULL, NULL, &dwType, (LPBYTE)szCmdName, &dw) == ERROR_SUCCESS) { - strcat(szCmdName, (const char*) url); + wxStrcat(szCmdName, (const wxChar*) url); PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; memset(&siStartInfo, 0, sizeof(STARTUPINFO)); @@ -249,13 +255,10 @@ bool apInvokeAppForFile(const wxString& filename) } wxString cmd; - bool ok = ft->GetOpenCommand(&cmd, - wxFileType::MessageParameters(filename, _T(""))); + ft->GetOpenCommand(&cmd, wxFileType::MessageParameters(filename, _T(""))); delete ft; - ok = (wxExecute(cmd, FALSE) != 0); - - return ok; + return (wxExecute(cmd, FALSE) != 0); } // Find the absolute path where this application has been run from. @@ -304,7 +307,31 @@ wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxStrin } // Adds a context-sensitive help button, for non-Windows platforms -void apAddContextHelpButton(wxWindow* parent, wxSizer* sizer, int sizerFlags, int sizerBorder) +void apAddContextHelpButton(wxWindow* + #if defined(__WXGTK__) || defined(__WXMAC__) + parent + #else + WXUNUSED(parent) + #endif + , wxSizer* + #if defined(__WXGTK__) || defined(__WXMAC__) + sizer + #else + WXUNUSED(sizer) + #endif + , int + #if defined(__WXGTK__) || defined(__WXMAC__) + sizerFlags + #else + WXUNUSED(sizerFlags) + #endif + , int + #if defined(__WXGTK__) || defined(__WXMAC__) + sizerBorder + #else + WXUNUSED(sizerBorder) + #endif + ) { #if defined(__WXGTK__) || defined(__WXMAC__) #ifdef __WXMAC__ @@ -323,11 +350,13 @@ void apAddContextHelpButton(wxWindow* parent, wxSizer* sizer, int sizerFlags, in #endif contextButton->SetHelpText(_("Invokes context-sensitive help for the clicked-on window.")); +#if 0 if (wxGetApp().UsingTooltips()) { contextButton->SetToolTip(_("Invokes context-sensitive help for the clicked-on window.")); } #endif +#endif } // Get selected wxNotebook page @@ -405,13 +434,13 @@ bool wxIconTable::AddInfo(const wxString& name, const wxIcon& icon, int state, b wxIconInfo* wxIconTable::FindInfo(const wxString& name) const { - wxNode* node = First(); + wxNode* node = GetFirst(); while (node) { - wxIconInfo* info = (wxIconInfo*) node->Data(); + wxIconInfo* info = (wxIconInfo*) node->GetData(); if (info->GetName() == name) return info; - node = node->Next(); + node = node->GetNext(); } return NULL; } @@ -448,7 +477,7 @@ wxOutputStream& operator <<(wxOutputStream& stream, long l) return stream << str; } -wxOutputStream& operator <<(wxOutputStream& stream, const char c) +wxOutputStream& operator <<(wxOutputStream& stream, const wxChar c) { wxString str; str.Printf(_T("%c"), c); @@ -474,4 +503,37 @@ wxString ctEscapeHTMLCharacters(const wxString& str) s += c; } return s; -} \ No newline at end of file +} + +// Match 'matchText' against 'matchAgainst', optionally constraining to +// whole-word only. +bool ctMatchString(const wxString& matchAgainst, const wxString& matchText, bool wholeWordOnly) +{ + // Fast operation if not matching against whole words only + if (!wholeWordOnly) + return (matchAgainst.Find(matchText) != -1); + + wxString left(matchAgainst); + bool success = FALSE; + int matchTextLen = (int) matchText.Length(); + while (!success && !matchAgainst.IsEmpty()) + { + int pos = left.Find(matchText); + if (pos == -1) + return FALSE; + + bool firstCharOK = FALSE; + bool lastCharOK = FALSE; + if (pos == 0 || !wxIsalnum(left[(size_t) (pos-1)])) + firstCharOK = TRUE; + + if (((pos + matchTextLen) == (int) left.Length()) || !wxIsalnum(left[(size_t) (pos + matchTextLen)])) + lastCharOK = TRUE; + + if (firstCharOK && lastCharOK) + success = TRUE; + + left = left.Mid(pos+1); + } + return success; +}