]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/configtool/src/utils.cpp
remove unfinished impl
[wxWidgets.git] / utils / configtool / src / utils.cpp
index 13826439a691d854f4fbbbd7b23f505aa48df9a3..78d6aca247ac19fd7ff9955c38d993f366c66005 100644 (file)
@@ -6,35 +6,41 @@
 // Created:     2002-09-04
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    
+// Licence:
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 // #pragma implementation
 #endif
 
-#include "wx/wx.h"
-#include "wx/image.h"
-#include "wx/notebook.h"
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#include <math.h>
+
+#ifndef WX_PRECOMP
+
 #include "wx/splitter.h"
-#include "wx/wfstream.h"
 #include "wx/datstrm.h"
 #include "wx/file.h"
 #include "wx/listctrl.h"
-#include "wx/tokenzr.h"
 #include "wx/process.h"
-#include "wx/mimetype.h"
 #include "wx/variant.h"
-#include "wx/cshelp.h"
 #include "wx/cmdline.h"
 
-#include <math.h>
-
-#ifdef __WXMSW__
-#include <windows.h>
-#include "wx/msw/winundef.h"
 #endif
 
+#include "wx/wfstream.h"
+#include "wx/cshelp.h"
+#include "wx/image.h"
+#include "wx/imaglist.h"
+#include "wx/tokenzr.h"
+#include "wx/notebook.h"
+#include "wx/mimetype.h"
 #include "utils.h"
 
 // Returns the image type, or -1, determined from the extension.
@@ -45,17 +51,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 +82,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 +100,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 +126,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 +135,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 +161,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,16 +178,16 @@ 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));
         siStartInfo.cb = sizeof(STARTUPINFO);
-        CreateProcess(NULL, szCmdName, NULL, NULL, FALSE, 0, NULL,
+        CreateProcess(NULL, szCmdName, NULL, NULL, false, 0, NULL,
             NULL, &siStartInfo, &piProcInfo );
     }
     if(lRes == ERROR_SUCCESS)
@@ -198,11 +209,11 @@ void apViewHTMLFile(const wxString& url)
     {
         // TODO: some kind of configuration dialog here.
         wxMessageBox(_("Could not determine the command for running the browser."),
-                  wxT("Browsing problem"), wxOK|wxICON_EXCLAMATION);
+                     wxT("Browsing problem"), wxOK|wxICON_EXCLAMATION);
         return ;
     }
 
-    ok = (wxExecute(cmd, FALSE) != 0);
+    ok = (wxExecute(cmd, false) != 0);
 #endif
 }
 
@@ -212,10 +223,12 @@ wxString wxGetTempDir()
 #if defined(__WXMAC__) && !defined(__DARWIN__)
     dir = wxMacFindFolder(  (short) kOnSystemDisk, kTemporaryFolderType, kCreateFolder ) ;
 #else // !Mac
-    dir = wxGetenv(_T("TMP"));
+    wxString dirEnv(wxGetenv(_T("TMP")));
+    dir = dirEnv;
     if ( dir.empty() )
     {
-        dir = wxGetenv(_T("TEMP"));
+        wxString envVar(wxGetenv(_T("TEMP")));
+        dir = envVar;
     }
     
     if ( dir.empty() )
@@ -245,17 +258,14 @@ bool apInvokeAppForFile(const wxString& filename)
         msg.Printf(wxT("Sorry, could not determine what application to invoke for extension %s\nYou may need to edit your MIME types."),
             ext.c_str());
         wxMessageBox(msg, wxT("Application Invocation"), wxICON_EXCLAMATION|wxOK);
-        return FALSE;
+        return false;
     }
 
     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.
@@ -266,14 +276,12 @@ bool apInvokeAppForFile(const wxString& filename)
 
 wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName)
 {
-    wxString str;
-
     // Try appVariableName
     if (!appVariableName.IsEmpty())
     {
-        str = wxGetenv(appVariableName);
-        if (!str.IsEmpty())
-            return str;
+        wxString strVar(wxGetenv(appVariableName.c_str()));
+        if (!strVar.IsEmpty())
+            return strVar;
     }
 
     if (wxIsAbsolutePath(argv0))
@@ -285,9 +293,9 @@ wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxStrin
         if (currentDir.Last() != wxFILE_SEP_PATH)
             currentDir += wxFILE_SEP_PATH;
 
-        str = currentDir + argv0;
-        if (wxFileExists(str))
-            return wxPathOnly(str);
+        currentDir += argv0;
+        if (wxFileExists(currentDir))
+            return wxPathOnly(currentDir);
     }
 
     // OK, it's neither an absolute path nor a relative path.
@@ -295,22 +303,46 @@ wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxStrin
 
     wxPathList pathList;
     pathList.AddEnvList(wxT("PATH"));
-    str = pathList.FindAbsoluteValidPath(argv0);
-    if (!str.IsEmpty())
-        return wxPathOnly(str);
+    wxString strPath = pathList.FindAbsoluteValidPath(argv0);
+    if (!strPath.IsEmpty())
+        return wxPathOnly(strPath);
 
     // Failed
     return wxEmptyString;
 }
 
 // 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__
     wxSize buttonSize(20, 20);
 #else
-    wxSize buttonSize(-1, -1);
+    wxSize buttonSize = wxDefaultSize;
 #endif
     wxButton *contextButton = new wxContextHelpButton( parent, wxID_CONTEXT_HELP,
         wxDefaultPosition, buttonSize);
@@ -381,7 +413,7 @@ void wxIconInfo::SetIconId(int state, bool enabled, int iconId)
 wxIconTable::wxIconTable(wxImageList* imageList)
 {
     m_imageList = imageList;
-    DeleteContents(TRUE);
+    WX_CLEAR_LIST(wxIconTable,*this);
 }
 
 void wxIconTable::AppendInfo(wxIconInfo* info)
@@ -402,12 +434,12 @@ bool wxIconTable::AddInfo(const wxString& name, const wxIcon& icon, int state, b
         Append(info);
     }
     info->SetIconId(state, enabled, m_imageList->Add(icon));
-    return TRUE;
+    return true;
 }
 
 wxIconInfo* wxIconTable::FindInfo(const wxString& name) const
 {
-    wxNode* node = GetFirst();
+    wxObjectList::compatibility_iterator node = GetFirst();
     while (node)
     {
         wxIconInfo* info = (wxIconInfo*) node->GetData();
@@ -430,9 +462,9 @@ bool wxIconTable::SetIconId(const wxString& name, int state, bool enabled, int i
 {
     wxIconInfo* info = FindInfo(name);
     if (!info)
-        return FALSE;
+        return false;
     info->SetIconId(state, enabled, iconId);
-    return TRUE;
+    return true;
 }
 
 // Output stream operators
@@ -450,7 +482,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);
@@ -477,3 +509,36 @@ wxString ctEscapeHTMLCharacters(const wxString& str)
     }
     return s;
 }
+
+// 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) != wxNOT_FOUND);
+
+    wxString left(matchAgainst);
+    bool success = false;
+    int matchTextLen = (int) matchText.Length();
+    while (!success && !matchAgainst.IsEmpty())
+    {
+        int pos = left.Find(matchText);
+        if (pos == wxNOT_FOUND)
+            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;
+}