Ejemplo n.º 1
0
bool LaunchBrowser(const char* url)
{
#ifdef WIN32
  int r =  (int)ShellExecuteA(0, "open", url, "", "", 1);
  return (r > 32);

#else 

#ifdef MACOSX

  CFStringRef strurl =                //CFSTR("http://www.amju.com"); // TODO HACK 
    CFStringCreateWithBytes(
    0, 
    (const unsigned char*)url, 
    strlen(url),
    kCFStringEncodingMacRoman,
    false);

  CFURLRef cfurl = CFURLCreateWithString(0, strurl, 0);
  OSStatus ret = LSOpenCFURLRef(cfurl, 0);

std::cout << "Launch URL: " << CFStringGetCStringPtr(strurl, kCFStringEncodingMacRoman) << "\n";
std::cout << "Launch result: " << ret << "\n";

  // TODO deal with ret
  return true;

#else
  // Not implemented for this platform
  return false;
#endif
#endif

}
Ejemplo n.º 2
0
//--------------------------------------------------------------
bool ofLVOpenProgram(string pathAbsFile)
{
        #ifdef TARGET_OSX
                CFStringRef      cfPathAbsFile = CFStringCreateWithCString(NULL,pathAbsFile.c_str(),CFStringGetSystemEncoding());
                if (cfPathAbsFile != NULL)
                {
                        CFURLRef cfUrl = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,cfPathAbsFile,kCFURLPOSIXPathStyle,false); 
                        if (cfUrl != NULL)
                        {
                                LSOpenCFURLRef(cfUrl, NULL);
                                return true;
                        }
                }

                return false;
        #endif
        
        #ifdef TARGET_WIN32
                // http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx
                HWND hwnd = WindowFromDC(wglGetCurrentDC());
                return ((int)ShellExecute(hwnd, "open", pathAbsFile.c_str(),0,0,SW_SHOWNORMAL))>32;
        #endif

        return false;
}
Ejemplo n.º 3
0
bool ArchHooks_MacOSX::GoToURL( RString sUrl )
{
	CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, (const UInt8*)sUrl.data(),
						 sUrl.length(), kCFStringEncodingUTF8, NULL );
	OSStatus result = LSOpenCFURLRef( url, NULL );

	CFRelease( url );
	return result == 0;
}
Ejemplo n.º 4
0
int Darwin::openURL (const std::string& url, bool) const
{
	CFURLRef cfurl = CFURLCreateWithBytes(nullptr, (const uint8_t *) url.c_str(),
			url.length(), kCFStringEncodingUTF8, nullptr);

	const bool success = LSOpenCFURLRef(cfurl, nullptr) == noErr;
	CFRelease(cfurl);
	return success ? 0 : -1;
}
void SoundCloudCAPI_DefaultAuthenticationOpenAuthURL(SoundCloudCAPI *api)
{
    const char *url;
    CFURLRef cfurl;
    url=SoundCloudCAPI_GetUserAuthorizationURL(api);
    cfurl=CFURLCreateWithBytes(0,(const UInt8*)url,strlen(url),0,0);
    LSOpenCFURLRef(cfurl,0);
    CFRelease(cfurl);
}
void MyLaunchConsoleApp()
{
    CFURLRef pathRef;

    pathRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kMyPathToSystemLog), kCFURLPOSIXPathStyle, false);
    
    if (pathRef) {
        LSOpenCFURLRef(pathRef, NULL);
        CFRelease(pathRef);
    }
}
Ejemplo n.º 7
0
// Open a URL with the user's default web browser.
// Must begin with protocol identifier.
void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url, bool async)
{
	// I'm fairly certain that this is all legitimate under Apple's currently supported APIs.
	
	bool found = false;
	S32 i;
	for (i = 0; i < gURLProtocolWhitelistCount; i++)
	{
		if (escaped_url.find(gURLProtocolWhitelist[i]) != std::string::npos)
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		LL_WARNS() << "spawn_web_browser called for url with protocol not on whitelist: " << escaped_url << LL_ENDL;
		return;
	}

	S32 result = 0;
	CFURLRef urlRef = NULL;

	LL_INFOS() << "Opening URL " << escaped_url << LL_ENDL;

	CFStringRef	stringRef = CFStringCreateWithCString(NULL, escaped_url.c_str(), kCFStringEncodingUTF8);
	if (stringRef)
	{
		// This will succeed if the string is a full URL, including the http://
		// Note that URLs specified this way need to be properly percent-escaped.
		urlRef = CFURLCreateWithString(NULL, stringRef, NULL);

		// Don't use CRURLCreateWithFileSystemPath -- only want valid URLs

		CFRelease(stringRef);
	}

	if (urlRef)
	{
		result = LSOpenCFURLRef(urlRef, NULL);

		if (result != noErr)
		{
			LL_INFOS() << "Error " << result << " on open." << LL_ENDL;
		}

		CFRelease(urlRef);
	}
	else
	{
		LL_INFOS() << "Error: couldn't create URL." << LL_ENDL;
	}
}
Ejemplo n.º 8
0
void WindowMenu::onBringAllToFront()
{
#ifdef Q_WS_MAC
   CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
   if (appUrlRef)
   {
      LSOpenCFURLRef(appUrlRef, NULL);
      CFRelease(appUrlRef);
   }
#endif
}
Ejemplo n.º 9
0
static bool lsOpen(const QUrl &url)
{
    if (!url.isValid() || url.scheme().isEmpty())
        return false;

    QCFType<CFURLRef> cfUrl = CFURLCreateWithString(0, QCFString(QString::fromLatin1(url.toEncoded())), 0);
    if (cfUrl == 0)
        return false;

    const OSStatus err = LSOpenCFURLRef(cfUrl, 0);
    return (err == noErr);
}
Ejemplo n.º 10
0
bool OSystem_MacOSX::displayLogFile() {
	// Use LaunchServices to open the log file, if possible.

	if (_logFilePath.empty())
		return false;

    CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)_logFilePath.c_str(), _logFilePath.size(), false);
    OSStatus err = LSOpenCFURLRef(url, NULL);
    CFRelease(url);

	return err != noErr;
}
Ejemplo n.º 11
0
// ---------------------------------
void USys::openURL( const char* url )
{
	CFStringRef urlString = CFStringCreateWithFormat( NULL, NULL, CFSTR("%s"), url );
	
	if( urlString )
	{
		CFURLRef pathRef = CFURLCreateWithString( NULL, urlString, NULL );
		if( pathRef )
		{
			OSStatus err = LSOpenCFURLRef( pathRef, NULL );
			CFRelease(pathRef);
		}
		CFRelease( urlString );
	}
}
Ejemplo n.º 12
0
bool wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params)
{
    wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault,
                              wxCFStringRef( params.url ), NULL ) );
    OSStatus err = LSOpenCFURLRef( curl , NULL );

    if (err == noErr)
    {
        return true;
    }
    else
    {
        wxLogDebug(wxT("Browser Launch error %d"), (int) err);
        return false;
    }
}
Ejemplo n.º 13
0
static PyObject *Launch_LSOpenCFURLRef(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    OSStatus _err;
    CFURLRef inURL;
    CFURLRef outLaunchedURL;
    if (!PyArg_ParseTuple(_args, "O&",
                          CFURLRefObj_Convert, &inURL))
        return NULL;
    _err = LSOpenCFURLRef(inURL,
                          &outLaunchedURL);
    if (_err != noErr) return PyMac_Error(_err);
    _res = Py_BuildValue("O&",
                         CFURLRefObj_New, outLaunchedURL);
    return _res;
}
Ejemplo n.º 14
0
void openURL(const std::string &url)
{
#ifdef BBGE_BUILD_WINDOWS
	ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#endif
#if defined(BBGE_BUILD_MACOSX)
	CFStringRef str = CFStringCreateWithCString (0, url.c_str(), 0);
	CFURLRef ref = CFURLCreateWithString(kCFAllocatorDefault, str, NULL);
	LSOpenCFURLRef(ref, 0);
	CFRelease(ref);
	CFRelease(str);
#elif BBGE_BUILD_UNIX
	std::string cmd("PATH=$PATH:. xdg-open '");
	cmd += url;
	cmd += "'";
	if (system(cmd.c_str()) != 0)
		debugLog("system(xdg_open '" + url + "') failed");
#endif
}
Ejemplo n.º 15
0
void openUrl(string url)
{
#ifdef _WIN32
	wstring wurl(url.begin(), url.end());
	ShellExecute(NULL, L"open", wurl.c_str(), NULL, NULL, SW_SHOWDEFAULT);
#endif
#ifdef __APPLE__
  	CFURLRef urlref = CFURLCreateWithBytes(NULL, (UInt8*)url.c_str(), url.length(), kCFStringEncodingASCII, NULL);
  	int cnt = 0;
	while (LSOpenCFURLRef(urlref,0) != 0)
	{
		usleep(10000);
		cnt++;
		if (cnt > 100)
			break;
	}
	CFRelease(urlref);
#endif
}
Ejemplo n.º 16
0
bool wxLaunchDefaultApplication(const wxString& document, int flags)
{
    wxUnusedVar(flags);

    wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(document)));
    CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
    wxCFRef<CFURLRef> curl(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
    OSStatus err = LSOpenCFURLRef( curl , NULL );

    if (err == noErr)
    {
        return true;
    }
    else
    {
        wxLogDebug(wxT("Default Application Launch error %d"), (int) err);
        return false;
    }
}
Ejemplo n.º 17
0
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
	// Make sure the method called is "open".
	NPUTF8 *name = npnfuncs->utf8fromidentifier(methodName);
	if(strcmp(name, plugin_method_name_open) == 0) {
		npnfuncs->memfree(name);
		BOOLEAN_TO_NPVARIANT(false, *result);
		// Meke sure the arugment has at least one String parameter.
		if(argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
			// Build CFURL object from the arugment.
			NPString str = NPVARIANT_TO_STRING(args[0]);
			CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)str.UTF8Characters, str.UTF8Length, kCFStringEncodingUTF8, NULL);
			if(url) {
				// Open URL with the default application by Launch Service.
				OSStatus res = LSOpenCFURLRef(url, NULL);
				CFRelease(url);
				BOOLEAN_TO_NPVARIANT(res == noErr, *result);
			}
		}
		return true;
	}
	npnfuncs->memfree(name);
	return false;
}
Ejemplo n.º 18
0
bool OSystem_MacOSX::openUrl(const Common::String &url) {
	CFURLRef urlRef = CFURLCreateWithBytes (NULL, (UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL);
	OSStatus err = LSOpenCFURLRef(urlRef, NULL);
	CFRelease(urlRef);
	return err != noErr;
}
Ejemplo n.º 19
0
gboolean
filemanager_open_directory (const gchar *path)
{
#if defined(G_OS_WIN32)
  /* ShellExecute(...,"explore",...) needs path to be explicitly a directory;
     Otherwise 'explore' will fail if a file exists with a basename matching
     the provided directory path.
     (eg: wireshak-gtk2.exe exists in the same directory as  a wireshark-gtk2
          directory entry).
  */
  gint   ret;
  gchar *xpath;
  xpath = g_strconcat(path,
                      g_str_has_suffix(path, "\\") ? "" : "\\",
                      NULL);
  ret = (gint) ShellExecute (HWND_DESKTOP, _T("explore"), utf_8to16(xpath), NULL, NULL, SW_SHOWNORMAL);
  g_free(xpath);
  return (ret > 32);

#elif defined(HAVE_OS_X_FRAMEWORKS)

  CFStringRef path_CFString;
  CFURLRef path_CFURL;
  OSStatus status;

  path_CFString = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
  if (path_CFString == NULL)
    return (FALSE);
  path_CFURL = CFURLCreateWithFileSystemPath(NULL, path_CFString,
                                             kCFURLPOSIXPathStyle, true);
  CFRelease(path_CFString);
  if (path_CFURL == NULL) {
    /*
     * XXX - does this always mean that that memory allocation failed?
     */
    return (FALSE);
  }
  /*
   * XXX - this is a Launch Services result code, and we should probably
   * display a dialog box if it's not 0, describing what the error was.
   * Then again, we should probably do the same for the ShellExecute call,
   * unless that call itself happens to pop up a dialog box for all errors.
   */
  status = LSOpenCFURLRef(path_CFURL, NULL);
  CFRelease(path_CFURL);
  return (status == 0);

#elif defined(HAVE_XDG_OPEN)

  GError   *error = NULL;
  gchar    *argv[3];
  gboolean  retval;

  g_return_val_if_fail (path != NULL, FALSE);

  argv[0] = "xdg-open";
  argv[1] = (char *)path;	/* Grr - g_spawn_async() shouldn't modify this */
  argv[2] = NULL;

  /*
   * XXX - use g_spawn_on_screen() so the file managaer window shows up on
   * the same screen?
   */
  retval = g_spawn_async (NULL, argv, NULL,
                          G_SPAWN_SEARCH_PATH,
                          NULL, NULL,
                          NULL, &error);

  if (! retval)
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not execute xdg-open: %s\n\n\"%s\"",
          simple_dialog_primary_start(), simple_dialog_primary_end(),
          error->message);
      g_error_free (error);
    }

  return retval;

#elif defined(MUST_LAUNCH_BROWSER_OURSELVES)

  GError    *error = NULL;
  gchar     *browser;
  gchar     *argument;
  gchar     *cmd;
  gchar    **argv;
  gboolean   retval;

  g_return_val_if_fail (path != NULL, FALSE);

  /*  browser = gimp_gimprc_query ("web-browser");*/
  browser = g_strdup(prefs.gui_webbrowser);

  if (browser == NULL || ! strlen (browser))
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "Web browser not specified.\n"
          "Please correct the web browser setting in the Preferences dialog.");
      g_free (browser);
      return FALSE;
    }

  /* conver the path to a URI */
  argument = filename2uri (path);

  /* replace %s with URL */
  if (strstr (browser, "%s"))
    cmd = strreplace (browser, "%s", argument);
  else
    cmd = g_strconcat (browser, " ", argument, NULL);

  g_free (argument);

  /* parse the cmd line */
  if (! g_shell_parse_argv (cmd, NULL, &argv, &error))
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not parse web browser command: \"%s\"%s\n\n\"%s\"\n\n%s",
          simple_dialog_primary_start(), browser, simple_dialog_primary_end(),
          error->message,
          "Please correct the web browser setting in the Preferences dialog.");
      g_error_free (error);
      return FALSE;
    }

  /*
   * XXX - use g_spawn_on_screen() so the browser window shows up on
   * the same screen?
   */
  retval = g_spawn_async (NULL, argv, NULL,
                          G_SPAWN_SEARCH_PATH,
                          NULL, NULL,
                          NULL, &error);

  if (! retval)
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not execute web browser: \"%s\"%s\n\n\"%s\"\n\n%s",
          simple_dialog_primary_start(), browser, simple_dialog_primary_end(),
          error->message,
          "Please correct the web browser setting in the Preferences dialog.");
      g_error_free (error);
    }

  g_free (browser);
  g_free (cmd);
  g_strfreev (argv);

  return retval;
#endif
}
Ejemplo n.º 20
0
gboolean
browser_open_url (const gchar *url)
{
#if defined(G_OS_WIN32)

  return ((gint) ShellExecute (HWND_DESKTOP, _T("open"), utf_8to16(url), NULL, NULL, SW_SHOWNORMAL) > 32);

#elif defined(HAVE_OS_X_FRAMEWORKS)

  CFStringRef url_CFString;
  CFURLRef url_CFURL;
  OSStatus status;

  /*
   * XXX - if URLs passed to "browser_open_url()" contain non-ASCII
   * characters, we'd have to choose an appropriate value from the
   * CFStringEncodings enum.
   */
  url_CFString = CFStringCreateWithCString(NULL, url, kCFStringEncodingASCII);
  if (url_CFString == NULL)
    return (FALSE);
  url_CFURL = CFURLCreateWithString(NULL, url_CFString, NULL);
  CFRelease(url_CFString);
  if (url_CFURL == NULL) {
    /*
     * XXX - this could mean that the url_CFString wasn't a valid URL,
     * or that memory allocation failed.  We can't determine which,
     * except perhaps by providing our own allocator and somehow
     * flagging allocation failures.
     */
    return (FALSE);
  }
  /*
   * XXX - this is a Launch Services result code, and we should probably
   * display a dialog box if it's not 0, describing what the error was.
   * Then again, we should probably do the same for the ShellExecute call,
   * unless that call itself happens to pop up a dialog box for all errors.
   */
  status = LSOpenCFURLRef(url_CFURL, NULL);
  CFRelease(url_CFURL);
  return (status == 0);

#elif defined(HAVE_XDG_OPEN)

  GError   *error = NULL;
  gchar    *argv[3];
  gboolean  retval;

  g_return_val_if_fail (url != NULL, FALSE);

  argv[0] = "xdg-open";
  argv[1] = (char *)url;	/* Grr - g_spawn_async() shouldn't modify this */
  argv[2] = NULL;

  /*
   * XXX - use g_spawn_on_screen() so the browser window shows up on
   * the same screen?
   */
  retval = g_spawn_async (NULL, argv, NULL,
                          G_SPAWN_SEARCH_PATH,
                          NULL, NULL,
                          NULL, &error);

  if (! retval)
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not execute xdg-open: %s\n\n\"%s\"",
          simple_dialog_primary_start(), simple_dialog_primary_end(),
          error->message);
      g_error_free (error);
    }

  return retval;

#elif defined(MUST_LAUNCH_BROWSER_OURSELVES)

  GError    *error = NULL;
  gchar     *browser;
  gchar     *argument;
  gchar     *cmd;
  gchar    **argv;
  gboolean   retval;

  g_return_val_if_fail (url != NULL, FALSE);

  /*  browser = gimp_gimprc_query ("web-browser");*/
  browser = g_strdup(prefs.gui_webbrowser);

  if (browser == NULL || ! strlen (browser))
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "Web browser not specified.\n"
          "Please correct the web browser setting in the Preferences dialog.");
      g_free (browser);
      return FALSE;
    }

  /* quote the url since it might contains special chars */
  argument = g_shell_quote (url);

  /* replace %s with URL */
  if (strstr (browser, "%s"))
    cmd = strreplace (browser, "%s", argument);
  else
    cmd = g_strconcat (browser, " ", argument, NULL);

  g_free (argument);

  /* parse the cmd line */
  if (! g_shell_parse_argv (cmd, NULL, &argv, &error))
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not parse web browser command: \"%s\"%s\n\n\"%s\"\n\n%s",
          simple_dialog_primary_start(), browser, simple_dialog_primary_end(),
          error->message,
          "Please correct the web browser setting in the Preferences dialog.");
      g_error_free (error);
      return FALSE;
    }

  /*
   * XXX - use g_spawn_on_screen() so the browser window shows up on
   * the same screen?
   */
  retval = g_spawn_async (NULL, argv, NULL,
                          G_SPAWN_SEARCH_PATH,
                          NULL, NULL,
                          NULL, &error);

  if (! retval)
    {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
          "%sCould not execute web browser: \"%s\"%s\n\n\"%s\"\n\n%s",
          simple_dialog_primary_start(), browser, simple_dialog_primary_end(),
          error->message,
          "Please correct the web browser setting in the Preferences dialog.");
      g_error_free (error);
    }

  g_free (browser);
  g_free (cmd);
  g_strfreev (argv);

  return retval;
#endif
}
Ejemplo n.º 21
0
void open_web_link(const char * url)
{
#ifdef OSX
	CFURLRef newurl = CFURLCreateWithString(kCFAllocatorDefault,CFStringCreateWithCStringNoCopy(NULL,url,kCFStringEncodingMacRoman, NULL),NULL);
	LSOpenCFURLRef(newurl,NULL);
	CFRelease(newurl);
#else
	// browser name can override the windows default, and if not defined in Linux, don't error
	if(*browser_name){
#ifndef WINDOWS
		static int have_set_signal = 0;
#ifdef SOUND_FORK_BUGFIX
		int sound_on_copy = sound_on;
		int music_on_copy = music_on;
#endif

		/* we're not interested in the exit status of the child so
		   set SA_NOCLDWAIT to stop it becoming a zombie if we don't wait() */
		if (!have_set_signal)
		{
			struct sigaction act;
			memset(&act, 0, sizeof(act));
			act.sa_handler = SIG_DFL;
			act.sa_flags = SA_NOCLDWAIT;
			sigaction(SIGCHLD, &act, NULL);
			have_set_signal = 1;
		}

#ifdef SOUND_FORK_BUGFIX
		if (sound_on_copy)
			toggle_sounds(&sound_on);
		if (music_on_copy)
			toggle_music(&music_on);
#endif

		if (fork() == 0){
			execlp(browser_name, browser_name, url, NULL);
			// in case the exec errors
			_exit(1);
		}

#ifdef SOUND_FORK_BUGFIX
		if (sound_on_copy)
			toggle_sounds(&sound_on);
		if (music_on_copy)
			toggle_music(&music_on);
#endif

#else
		// make a copy of the url string as it may be freed by the caller
		// will be freed as the only_call_from_open_web_link__go_to_url() exits
		char *cp_url = malloc(strlen(url)+1);
		safe_strncpy(cp_url, url, strlen(url)+1);

		// windows needs to spawn it in its own thread
		SDL_CreateThread(only_call_from_open_web_link__go_to_url, cp_url);
	} else {
		ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNOACTIVATE); //this returns an int we could check for errors, but that's mainly when you use shellexecute for local files
#endif  //_WIN32
	}
#endif // OSX
}
Ejemplo n.º 22
0
//-----------------------------------------------------------------------------
//	CustomToolbarItemHandler
//-----------------------------------------------------------------------------
//	This is where the magic happens. This is your method reception desk. When
//	your object is created, etc. or receives events, this is where we take the
//	events and call specific functions to do the work.
//
static pascal OSStatus
CustomToolbarItemHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{
	OSStatus			result = eventNotHandledErr;
	CustomToolbarItem*	object = (CustomToolbarItem*)inUserData;

	switch ( GetEventClass( inEvent ) )
	{
		case kEventClassHIObject:
			switch ( GetEventKind( inEvent ) )
			{
				case kEventHIObjectConstruct:
					{
						HIObjectRef			toolbarItem;
						CustomToolbarItem*	item;
						
						GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL,
								sizeof( HIObjectRef ), NULL, &toolbarItem );
						
						result = ConstructCustomToolbarItem( toolbarItem, &item );
						
						if ( result == noErr )
							SetEventParameter( inEvent, kEventParamHIObjectInstance, 'void', sizeof( void * ), &item );
					}
					break;

				case kEventHIObjectInitialize:
					if ( CallNextEventHandler( inCallRef, inEvent ) == noErr )
						result = InitializeCustomToolbarItem( object, inEvent );
					break;
				
				case kEventHIObjectDestruct:
					DestructCustomToolbarItem( object );
					result = noErr;
					break;
			}
			break;
		
		case kEventClassToolbarItem:
			switch ( GetEventKind( inEvent ) )
			{
				case kEventToolbarItemGetPersistentData:
					{
						CFTypeRef		data;
						
						data = CreateCustomToolbarItemPersistentData( object );
						if ( data )
						{
							SetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef,
								sizeof( CFTypeRef ), &data );
							result = noErr;
						}
					}
					break;
		
				case kEventToolbarItemPerformAction:
					if ( object->url )
						result = LSOpenCFURLRef( object->url, NULL );
					else
						result = noErr;
					break;
			}
			break;
	}
	
	return result;
}
Ejemplo n.º 23
0
static OSErr OpenDocEventHandler(const AppleEvent *theAppleEvent,
                                 AppleEvent *reply,
                                 long handlerRefcon) {

    char** argv  = NULL;
    int no;
    AEDesc fileListDesc = {'NULL', NULL};
    long numFiles;
    long actualSize;
    long index;
    OSErr err;
    DescType actualType;
    AEKeyword actualKeyword;
    FSSpec aFile;
    FSRef theFile;
    UInt8 fullPath[MAXPATHLEN];
    bool openWithWebStart = true;
    CFURLRef jnlpLocation = NULL;

    // Load up our list of file descriptors
    err = AEGetKeyDesc(theAppleEvent, keyDirectObject, typeAEList, &fileListDesc);

    if(err) {
        AEDisposeDesc(&fileListDesc);
        fprintf(stderr, "Error getting key desc\n");
        return err;
    }

    // How many files do we have to deal with?
    err = AECountItems(&fileListDesc, &numFiles);

    if(err) {
        AEDisposeDesc(&fileListDesc);
        fprintf(stderr, "Error counting items\n");
        return err;
    }

    // Iterate through all of the files, and try to send them through the JNLP java code.
    for(index = 1; index <= numFiles; index++) {

        err = AEGetNthPtr(&fileListDesc, index, typeFSS, &actualKeyword,
                          &actualType, (Ptr)&aFile, sizeof(aFile), &actualSize);

        if(err) {
            AEDisposeDesc(&fileListDesc);
            fprintf(stderr, "Error getting file pointer\n");
            return err;
        }

        // Mac stuff to turn the file representation we get into a workable pathname
        FSpMakeFSRef(&aFile, &theFile);
        FSRefMakePath(&theFile, fullPath, sizeof(fullPath));

        // See if we have an application for this JNLP file.  If so, use that instead.
        jnlpLocation = FindJnlpURLInFile(fullPath);

        if (jnlpLocation != NULL) {
            CFURLRef applicationURL = FindJNLPApplicationPackage(jnlpLocation);

            if (applicationURL != NULL) {
                OSStatus result = LSOpenCFURLRef(applicationURL, NULL);

                if (result == noErr) {
                    openWithWebStart = false;
                }
            }

            CFRelease(jnlpLocation);
        }

        if (openWithWebStart) {
            // Three arguments -- app name, file to open, and null.
            argv = (char**)malloc(sizeof(char*) * 3);
            no = 0;
            argv[no++] = GetWebStartAppName();
            argv[no++] = fullPath;
            argv[no] = NULL;

            // Call into our main app.
            main(no, argv);
        }

        openWithWebStart = TRUE;
    }

    QuitApplicationEventLoop();
    return noErr;
}