+ return false;
+}
+#endif
+
+static bool DoLaunchDefaultBrowserHelper(const wxString& urlOrig, int flags)
+{
+ // NOTE: we don't have to care about the wxBROWSER_NOBUSYCURSOR flag
+ // as it was already handled by wxLaunchDefaultBrowser
+
+ wxUnusedVar(flags);
+
+ wxString url(urlOrig), scheme;
+ wxURI uri(url);
+
+ // this check is useful to avoid that wxURI recognizes as scheme parts of
+ // the filename, in case urlOrig is a local filename
+ // (e.g. "C:\\test.txt" when parsed by wxURI reports a scheme == "C")
+ bool hasValidScheme = uri.HasScheme() &&
+ (uri.GetScheme() == "http" || uri.GetScheme() == "file");
+
+#if defined(__WXMSW__)
+
+ // NOTE: when testing wxMSW's wxLaunchDefaultBrowser all possible forms
+ // of the URL/flags should be tested; e.g.:
+ //
+ // for (int i=0; i<2; i++)
+ // {
+ // wxLaunchDefaultBrowser("C:\\test.txt", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("wxwidgets.org", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("file:/C%3A/test.txt", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // wxLaunchDefaultBrowser("http://wxwidgets.org", i==0 ? 0 : wxBROWSER_NEW_WINDOW);
+ // }
+ // (assuming you have a C:\test.txt file)
+
+ if ( !hasValidScheme )
+ {
+ if (wxFileExists(urlOrig) || wxDirExists(urlOrig))
+ {
+ scheme = "file";
+ // do not prepend the file scheme to the URL as ShellExecuteEx() doesn't like it
+ }
+ else
+ {
+ url.Prepend(wxS("http://"));
+ scheme = "http";
+ }
+ }
+ else if ( hasValidScheme )
+ {
+ scheme = uri.GetScheme();
+
+ if ( uri.GetScheme() == "file" )
+ {
+ // TODO: extract URLToFileName() to some always compiled in
+ // function
+#if wxUSE_FILESYSTEM
+ // ShellExecuteEx() doesn't like the "file" scheme when opening local files;
+ // remove it
+ url = wxFileSystem::URLToFileName(url).GetFullPath();
+#endif // wxUSE_FILESYSTEM
+ }
+ }
+
+ if (wxDoLaunchDefaultBrowser(url, scheme, flags))
+ return true;
+ //else: call wxLogSysError
+#else
+ if ( !hasValidScheme )
+ {
+ // set the scheme of url to "http" or "file" if it does not have one
+ if (wxFileExists(urlOrig) || wxDirExists(urlOrig))
+ url.Prepend(wxS("file://"));
+ else
+ url.Prepend(wxS("http://"));
+ }
+
+ if (wxDoLaunchDefaultBrowser(url, flags))
+ return true;
+ //else: call wxLogSysError
+#endif