Fix wxCocoa's wxLaunchDefaultBrowser in the 2.8 branch.
Roughly equivalent to trunk 45892 (NOTE: CVS) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48184 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
20
include/wx/private/browserhack28.h
Normal file
20
include/wx/private/browserhack28.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/private/browserhack28.h
|
||||||
|
// Purpose: Allows GUI library to override base wxLaunchDefaultBrowser.
|
||||||
|
// Author: David Elliott
|
||||||
|
// Modified by:
|
||||||
|
// Created: 2007-08-19
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) David Elliott
|
||||||
|
// Licence: wxWidgets licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_PRIVATE_BROWSERHACK28_H_
|
||||||
|
#define _WX_PRIVATE_BROWSERHACK28_H_
|
||||||
|
|
||||||
|
typedef bool (*wxLaunchDefaultBrowserImpl_t)(const wxString& url, int flags);
|
||||||
|
|
||||||
|
// Function the GUI library can call to provide a better implementation
|
||||||
|
WXDLLIMPEXP_BASE void wxSetLaunchDefaultBrowserImpl(wxLaunchDefaultBrowserImpl_t newImpl);
|
||||||
|
|
||||||
|
#endif //ndef _WX_PRIVATE_BROWSERHACK28_H_
|
@@ -27,6 +27,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "wx/cocoa/string.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSURL.h>
|
||||||
|
#import <AppKit/NSWorkspace.h>
|
||||||
|
|
||||||
void wxDisplaySize(int *width, int *height)
|
void wxDisplaySize(int *width, int *height)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
@@ -92,6 +97,28 @@ void wxBell()
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "wx/private/browserhack28.h"
|
||||||
|
|
||||||
|
// Private helper method for wxLaunchDefaultBrowser
|
||||||
|
static bool wxCocoaLaunchDefaultBrowser(const wxString& url, int flags)
|
||||||
|
{
|
||||||
|
// NOTE: We ignore the flags
|
||||||
|
return [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:wxNSStringWithWxString(url)]] != NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For this to work the linker (particularly the static one) must link in this object file and the C++
|
||||||
|
// runtime must call the static initializer. It is basically guaranteed that the linker won't throw us
|
||||||
|
// away because some of the wxGUIAppTraits virtual methods are implemented in this file.
|
||||||
|
static class DoFixLaunchDefaultBrowser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DoFixLaunchDefaultBrowser()
|
||||||
|
{
|
||||||
|
// Tell the base library we can launch a default browser better.
|
||||||
|
wxSetLaunchDefaultBrowserImpl(&wxCocoaLaunchDefaultBrowser);
|
||||||
|
}
|
||||||
|
} s_launchDefaultBrowserFixer;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// DFE: These aren't even implemented by wxGTK, and no wxWidgets code calls
|
// DFE: These aren't even implemented by wxGTK, and no wxWidgets code calls
|
||||||
// them. If someone needs them, then they'll get a link error
|
// them. If someone needs them, then they'll get a link error
|
||||||
|
@@ -725,22 +725,22 @@ long wxExecute(const wxString& command,
|
|||||||
// Launch default browser
|
// Launch default browser
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
|
#include "wx/private/browserhack28.h"
|
||||||
{
|
|
||||||
wxUnusedVar(flags);
|
|
||||||
|
|
||||||
// set the scheme of url to http if it does not have one
|
static bool wxLaunchDefaultBrowserBaseImpl(const wxString& url, int flags);
|
||||||
// RR: This doesn't work if the url is just a local path
|
|
||||||
wxString url(urlOrig);
|
// Use wxLaunchDefaultBrowserBaseImpl by default
|
||||||
wxURI uri(url);
|
static wxLaunchDefaultBrowserImpl_t s_launchBrowserImpl = &wxLaunchDefaultBrowserBaseImpl;
|
||||||
if ( !uri.HasScheme() )
|
|
||||||
|
// Function the GUI library can call to provide a better implementation
|
||||||
|
WXDLLIMPEXP_BASE void wxSetLaunchDefaultBrowserImpl(wxLaunchDefaultBrowserImpl_t newImpl)
|
||||||
{
|
{
|
||||||
if (wxFileExists(urlOrig))
|
s_launchBrowserImpl = newImpl!=NULL ? newImpl : &wxLaunchDefaultBrowserBaseImpl;
|
||||||
url.Prepend( wxT("file://") );
|
|
||||||
else
|
|
||||||
url.Prepend(wxT("http://"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool wxLaunchDefaultBrowserBaseImpl(const wxString& url, int flags)
|
||||||
|
{
|
||||||
|
wxUnusedVar(flags);
|
||||||
|
|
||||||
#if defined(__WXMSW__)
|
#if defined(__WXMSW__)
|
||||||
|
|
||||||
@@ -923,6 +923,25 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
|
|||||||
wxLogError(_T("No default application configured for HTML files."));
|
wxLogError(_T("No default application configured for HTML files."));
|
||||||
|
|
||||||
#endif // !wxUSE_MIMETYPE && !__WXMSW__
|
#endif // !wxUSE_MIMETYPE && !__WXMSW__
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
|
||||||
|
{
|
||||||
|
// set the scheme of url to http if it does not have one
|
||||||
|
// RR: This doesn't work if the url is just a local path
|
||||||
|
wxString url(urlOrig);
|
||||||
|
wxURI uri(url);
|
||||||
|
if ( !uri.HasScheme() )
|
||||||
|
{
|
||||||
|
if (wxFileExists(urlOrig))
|
||||||
|
url.Prepend( wxT("file://") );
|
||||||
|
else
|
||||||
|
url.Prepend(wxT("http://"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(s_launchBrowserImpl(url, flags))
|
||||||
|
return true;
|
||||||
|
|
||||||
wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
|
wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
|
||||||
url.c_str());
|
url.c_str());
|
||||||
|
@@ -65,6 +65,7 @@
|
|||||||
*wxMenuItemBase*GetLabelText*;
|
*wxMenuItemBase*GetLabelText*;
|
||||||
*wxMenuItem*GetItemLabel*;
|
*wxMenuItem*GetItemLabel*;
|
||||||
*wxMetafileDC*DoGetTextExtent*;
|
*wxMetafileDC*DoGetTextExtent*;
|
||||||
|
*wxSetLaunchDefaultBrowserImpl*;
|
||||||
*wxWindowMSW*GetThemedBorderStyle*;
|
*wxWindowMSW*GetThemedBorderStyle*;
|
||||||
*wxWizard*GetBitmap*;
|
*wxWizard*GetBitmap*;
|
||||||
*wxWizard*SetBitmap*;
|
*wxWizard*SetBitmap*;
|
||||||
|
Reference in New Issue
Block a user