Пример #1
0
status_t
AddTranslationItems(BMenu* intoMenu, uint32 fromType)
{

	BTranslatorRoster* use;
	char* translatorTypeName;
	const char* translatorIdName;

	use = BTranslatorRoster::Default();
	translatorIdName = "be:translator";
	translatorTypeName = (char *)"be:type";
	translator_id* ids = NULL;
	int32 count = 0;

	status_t err = use->GetAllTranslators(&ids, &count);
	if (err < B_OK)
		return err;

	for (int tix = 0; tix < count; tix++) {
		const translation_format* formats = NULL;
		int32 num_formats = 0;
		bool ok = false;
		err = use->GetInputFormats(ids[tix], &formats, &num_formats);
		if (err == B_OK)
			for (int iix = 0; iix < num_formats; iix++) {
				if (formats[iix].type == fromType) {
					ok = true;
					break;
				}
			}

		if (!ok)
			continue;

		err = use->GetOutputFormats(ids[tix], &formats, &num_formats);
		if (err == B_OK)
			for (int oix = 0; oix < num_formats; oix++) {
 				if (formats[oix].type != fromType) {
					BMessage* itemmsg;
					itemmsg = new BMessage(msg_translate);
					itemmsg->AddInt32(translatorIdName, ids[tix]);
					itemmsg->AddInt32(translatorTypeName, formats[oix].type);
					intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg));
				}
			}
	}
	delete[] ids;
	return B_OK;
}
Пример #2
0
BMessage *DragonView::_MakeDragMessage( void )
{
	DragonApp *app = dynamic_cast<DragonApp *>( be_app );

	BMessage *msg = new BMessage( B_SIMPLE_DATA );

	// We can handle any image type that's supported by the currently
	// installed Translators.
	//
	// A "real" application would want to add the Translators in order,
	// from best to worst using the quality and capability data in the
	// Translator information structure.  It would also want to make sure
	// that there weren't any duplicate types in the drag message.
	
	BTranslatorRoster *translators = BTranslatorRoster::Default();
	translator_id *all_translators = NULL;
	int32 num_translators = 0;
	
	status_t retval = translators->GetAllTranslators( &all_translators,
													  &num_translators );
	if( retval == B_OK ) {
		// Only add translators that support appropriate inputs/outputs.
		
		for( int32 idx = 0; idx < num_translators; idx++ ) {
			const translation_format *in_formats = NULL;
			int32 num_in = 0;
			
			// Get the list of input formats for this Translator.
			retval = translators->GetInputFormats( all_translators[idx],
												   &in_formats,
												   &num_in );
			if( retval != B_OK ) continue;
			
			// Make sure it supports BBitmap inputs.
			
			for( int32 in = 0; in < num_in; in++ ) {
				if( !strcmp( in_formats[in].MIME, "image/x-be-bitmap" ) ) {
					// Add this translator's output formats to the message.
					
					const translation_format *out_formats = NULL;
					int32 num_out = 0;
					
					retval = translators->GetOutputFormats( all_translators[idx],
															&out_formats,
															&num_out );
					if( retval != B_OK ) break;
					
					for( int32 out = 0; out < num_out; out++ ) {
						// Add every type except "image/x-be-bitmap",
						// which won't be of any use to us.

						if( strcmp( out_formats[out].MIME, "image/x-be-bitmap" ) ) {
							msg->AddString( "be:types", 
											out_formats[out].MIME );
							msg->AddString( "be:filetypes", 
											out_formats[out].MIME );
							msg->AddString( "be:type_descriptions",
											out_formats[out].name );
						}
					}
				}
			}
		}
	}

	// We can also handle raw data.

	msg->AddString( "be:types", B_FILE_MIME_TYPE );
	msg->AddString( "be:filetypes", B_FILE_MIME_TYPE );
	msg->AddString( "be:type_descriptions", 
					app->rsrc_strings->FindString( RSRC_Raw_Data ) );

	// Add the actions that we'll support.  B_LINK_TARGET doesn't make much
	// sense in this context, so we'll leave it out.  B_MOVE_TARGET is a
	// B_COPY_TARGET followed by B_TRASH_TARGET...

	msg->AddInt32( "be:actions", B_COPY_TARGET );
	msg->AddInt32( "be:actions", B_TRASH_TARGET );
	msg->AddInt32( "be:actions", B_MOVE_TARGET );

	// A file name for dropping onto things (like the Tracker) that create
	// files.
	
	msg->AddString( "be:clip_name", "Dropped Bitmap" );

	return msg;
}