]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/utilscmn.cpp
fix substr() calls broken by r56215 (#10198)
[wxWidgets.git] / src / common / utilscmn.cpp
index 42d60c2c4d931bdace69807fb271a41150782abd..a498ce07e6e33ec206442ae4d917d09c5a7cf77c 100644 (file)
@@ -933,6 +933,49 @@ void wxQsort(void *const pbase, size_t total_elems,
 
 #if wxUSE_GUI
 
+// ----------------------------------------------------------------------------
+// Launch document with default app
+// ----------------------------------------------------------------------------
+
+bool wxLaunchDefaultApplication(const wxString& document, int flags)
+{
+    wxUnusedVar(flags);
+
+#ifdef __WXMAC__
+    static const char * const OPEN_CMD = "/usr/bin/open";
+    if ( wxFileExists(OPEN_CMD) &&
+            wxExecute(wxString(OPEN_CMD) + " " + document) )
+        return true;
+#elif defined(__UNIX__)
+    // Our best best is to use xdg-open from freedesktop.org cross-desktop
+    // compatibility suite xdg-utils
+    // (see http://portland.freedesktop.org/wiki/) -- this is installed on
+    // most modern distributions and may be tweaked by them to handle
+    // distribution specifics.
+    wxString path, xdg_open;
+    if ( wxGetEnv("PATH", &path) &&
+         wxFindFileInPath(&xdg_open, path, "xdg-open") )
+    {
+        if ( wxExecute(xdg_open + " " + document) )
+            return true;
+    }
+#elif defined(__WXMSW__)
+    const INT_PTR result = (INT_PTR)::ShellExecute
+                                      (
+                                        NULL,           // parent window
+                                        _T("open"),
+                                        document.wx_str(),
+                                        NULL,           // parameters
+                                        NULL,           // working directory
+                                        SW_SHOWDEFAULT
+                                      );
+    if ( result > 32 )
+        return true;
+#endif
+
+    return false;
+}
+
 // ----------------------------------------------------------------------------
 // Launch default browser
 // ----------------------------------------------------------------------------
@@ -942,7 +985,7 @@ void wxQsort(void *const pbase, size_t total_elems,
 bool wxCocoaLaunchDefaultBrowser(const wxString& url, int flags);
 #endif
 
-bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
+static bool DoLaunchDefaultBrowser(const wxString& urlOrig, int flags)
 {
     wxUnusedVar(flags);
 
@@ -978,13 +1021,14 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
             wxRegKey keyDDE(key, wxT("DDEExec"));
             if ( keyDDE.Exists() )
             {
-                const wxString ddeTopic = wxRegKey(keyDDE, wxT("topic"));
-
                 // we only know the syntax of WWW_OpenURL DDE request for IE,
                 // optimistically assume that all other browsers are compatible
                 // with it
+                static const wxChar *TOPIC_OPEN_URL = wxT("WWW_OpenURL");
                 wxString ddeCmd;
-                bool ok = ddeTopic == wxT("WWW_OpenURL");
+                wxRegKey keyTopic(keyDDE, wxT("topic"));
+                bool ok = keyTopic.Exists() &&
+                            keyTopic.QueryDefaultValue() == TOPIC_OPEN_URL;
                 if ( ok )
                 {
                     ddeCmd = keyDDE.QueryDefaultValue();
@@ -997,7 +1041,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
                     // in is -1 (meaning "current") by default, replace it with
                     // 0 which means "new" (see KB article 160957)
                     ok = ddeCmd.Replace(wxT("-1"), wxT("0"),
-                                        false /* only first occurence */) == 1;
+                                        false /* only first occurrence */) == 1;
                 }
 
                 if ( ok )
@@ -1013,7 +1057,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
                     wxLogNull noLog;
 
                     const wxString ddeServer = wxRegKey(keyDDE, wxT("application"));
-                    if ( wxExecuteDDE(ddeServer, ddeTopic, ddeCmd) )
+                    if ( wxExecuteDDE(ddeServer, TOPIC_OPEN_URL, ddeCmd) )
                         return true;
 
                     // this is not necessarily an error: maybe browser is
@@ -1031,6 +1075,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
     sei.lpFile = url.c_str();
     sei.lpVerb = _T("open");
     sei.nShow = SW_SHOWNORMAL;
+    sei.fMask = SEE_MASK_FLAG_NO_UI; // we give error message ourselves
 
     ::ShellExecuteEx(&sei);
 
@@ -1150,6 +1195,15 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
     return false;
 }
 
+bool wxLaunchDefaultBrowser(const wxString& url, int flags)
+{
+    if ( flags & wxBROWSER_NOBUSYCURSOR )
+        return DoLaunchDefaultBrowser(url, flags);
+
+    wxBusyCursor bc;
+    return DoLaunchDefaultBrowser(url, flags);
+}
+
 // ----------------------------------------------------------------------------
 // Menu accelerators related functions
 // ----------------------------------------------------------------------------
@@ -1379,7 +1433,7 @@ void wxInfoMessageBox(wxWindow* parent)
     msg.Printf(_T("wxWidgets Library (%s port)\n")
                _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
                _T("Runtime version of toolkit used is %d.%d.%s\n")
-               _T("Copyright (c) 1995-2007 wxWidgets team"),
+               _T("Copyright (c) 1995-2008 wxWidgets team"),
                wxPlatformInfo::Get().GetPortIdName().c_str(),
                wxMAJOR_VERSION,
                wxMINOR_VERSION,
@@ -1466,8 +1520,8 @@ wxString wxGetPasswordFromUser(const wxString& message,
 
 #if wxUSE_COLOURDLG
 
-wxColour wxGetColourFromUser(wxWindow *parent, 
-                             const wxColour& colInit, 
+wxColour wxGetColourFromUser(wxWindow *parent,
+                             const wxColour& colInit,
                              const wxString& caption,
                              wxColourData *ptrData)
 {