Exemple #1
0
BBitmap * BitmapUtils::LoadFromResource(int32 id)
{
	BArchivable *archivable;
	BResources resources;
	BMessage message;
	const void *data;
	BBitmap *bitmap;
	app_info info;
	BFile file;
	size_t len;

	if (be_app->GetAppInfo(&info) != B_OK) return NULL;
	if (file.SetTo(&(info.ref), B_READ_ONLY) != B_OK) return NULL;
	if (resources.SetTo(&file, false) != B_OK) return NULL;
	data = resources.LoadResource('BBMP', id, &len);
	if (data == NULL || len <= 0) return NULL;
	if (message.Unflatten((const char *)data) != B_OK) return NULL;
	archivable = BBitmap::Instantiate(&message);
	if (archivable == NULL) return NULL;
	bitmap = dynamic_cast<BBitmap*>(archivable);
	if (bitmap == NULL) {
		delete archivable;
		return NULL;
	}
	return bitmap;
}
Exemple #2
0
BBitmap*
MediaAlert::InitIcon()
{
	// The alert icons are in the app_server resources
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
			BResources resources;
			if (resources.SetTo(&file) == B_OK) {
				// Which icon are we trying to load?
				const char* iconName = "warn";

				// Load the raw icon data
				size_t size;
				const void* rawIcon =
					resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size);

				if (rawIcon != NULL) {
					// Now build the bitmap
					icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
					if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
							icon) != B_OK) {
						delete icon;
						return NULL;
					}
				}
			}
		}
	}

	return icon;
}
Exemple #3
0
// ---------------------------------------------------------------
// GetBitmap
//
// Returns a BBitmap object for the bitmap resource identified by
// the type type with the resource id, id. 
// The user has to delete this object.
//
// Preconditions:
//
// Parameters: type, the type of resource to be loaded
//             id, the id for the resource to be loaded
//             roster, BTranslatorRoster used to do the translation
//
// Postconditions:
//
// Returns: NULL, if the resource couldn't be loaded or couldn't
//                be translated to a BBitmap
//          BBitmap * to the bitmap identified by type and id
// ---------------------------------------------------------------
BBitmap *
BTranslationUtils::GetBitmap(uint32 type, int32 id, BTranslatorRoster *roster)
{
	BResources *pResources = BApplication::AppResources();
		// Remember: pResources must not be freed because
		// it belongs to the application
	if (pResources == NULL || pResources->HasResource(type, id) == false)
		return NULL;
	
	// Load the bitmap resource from the application file 
	// pRawData should be NULL if the resource is an
	// unknown type or not available
	size_t bitmapSize = 0;
	const void *kpRawData = pResources->LoadResource(type, id, &bitmapSize);
	if (kpRawData == NULL || bitmapSize == 0)
		return NULL;
	
	BMemoryIO memio(kpRawData, bitmapSize);
		// Put the pointer to the raw image data into a BMemoryIO object
		// so that it can be used with BTranslatorRoster->Translate() in
		// the GetBitmap(BPositionIO *, BTranslatorRoster *) function
	
	return GetBitmap(&memio, roster);
		// Translate the data in memio using the BTranslatorRoster roster
}
Exemple #4
0
BBitmap*
AlertView::InitIcon()
{
	// This is how BAlert gets to its icon
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BResources resources;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& resources.SetTo(&file) == B_OK) {
			size_t size;
			const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
				"warn", &size);
			if (data) {
				icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
				if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
						!= B_OK) {
					delete icon;
					icon = NULL;
				}
			}
		}
	}

	return icon;
}
Exemple #5
0
/*static*/ void
BApplication::_InitAppResources()
{
	entry_ref ref;
	bool found = false;

	// App is already running. Get its entry ref with
	// GetAppInfo()
	app_info appInfo;
	if (be_app && be_app->GetAppInfo(&appInfo) == B_OK) {
		ref = appInfo.ref;
		found = true;
	} else {
		// Run() hasn't been called yet
		found = BPrivate::get_app_ref(&ref) == B_OK;
	}

	if (!found)
		return;

	BFile file(&ref, B_READ_ONLY);
	if (file.InitCheck() != B_OK)
		return;

	BResources* resources = new (std::nothrow) BResources(&file, false);
	if (resources == NULL || resources->InitCheck() != B_OK) {
		delete resources;
		return;
	}

	sAppResources = resources;
}
void
CamStatusView::AttachedToWindow()
{
	if (fController->LockLooper()) {
		fController->StartWatching(this, kMsgControllerCaptureStarted);
		fController->StartWatching(this, kMsgControllerCaptureStopped);
		fController->StartWatching(this, kMsgControllerCapturePaused);
		fController->StartWatching(this, kMsgControllerCaptureResumed);
		fController->StartWatching(this, kMsgControllerEncodeStarted);
		fController->StartWatching(this, kMsgControllerEncodeProgress);
		fController->StartWatching(this, kMsgControllerEncodeFinished);
		fController->UnlockLooper();
	}
	
	if (Parent())
		SetViewColor(Parent()->ViewColor());
	
	BResources* resources = be_app->AppResources();
	size_t size;
	const void* buffer = resources->LoadResource('VICN', "record_icon", &size);
	if (buffer != NULL)
		BIconUtils::GetVectorIcon((uint8*)buffer, size, fRecordingBitmap);
	buffer = resources->LoadResource('VICN', "pause_icon", &size);
	if (buffer != NULL)
		BIconUtils::GetVectorIcon((uint8*)buffer, size, fPauseBitmap);
	
	fBitmapView->SetBitmap(NULL);
}
Exemple #7
0
int32
Project::UpdateAttributes(void)
{
	BResources res;
	
	BPath path(fPath.GetFolder());
	path.Append(GetTargetName());
	
	BFile file(path.Path(), B_READ_WRITE);
	if (file.InitCheck() != B_OK)
		return B_BAD_VALUE;
	
	if (res.SetTo(&file) != B_OK)
		return B_ERROR;
	
	ResourceToAttribute(file,res,'MIMS',"BEOS:APP_SIG");
	ResourceToAttribute(file,res,'MIMS',"BEOS:TYPE");
	ResourceToAttribute(file,res,'MSGG',"BEOS:FILE_TYPES");
	ResourceToAttribute(file,res,'APPV',"BEOS:APP_VERSION");
	ResourceToAttribute(file,res,'APPF',"BEOS:APP_FLAGS");
	ResourceToAttribute(file,res,'ICON',"BEOS:L:STD_ICON");
	ResourceToAttribute(file,res,'MICN',"BEOS:M:STD_ICON");
	ResourceToAttribute(file,res,'VICN',"BEOS:ICON");
	
	return B_OK;
}
Exemple #8
0
bool
ResourceToAttribute(BFile &file, BResources &res,type_code code, const char *name)
{
	if (!name)
		return false;
	
	int32 id;
	size_t length;
	if (res.GetResourceInfo(code,name,&id,&length))
	{
		const void *buffer = res.LoadResource(code,name,&length);
		if (!buffer)
		{
			STRACE(2,("Resource %s exists, but couldn't be loaded\n",name));
			return false;
		}
		file.WriteAttr(name,code,0,buffer,length);
		STRACE(2,("Successfully wrote attribute %s\n",name));
		return true;
	}
	else
	{
		STRACE(2,("Resource %s doesn't exist\n",name));
	}
	return false;
}
Exemple #9
0
status_t
DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	if (res == B_OK) {
		res = rsrc.AddResource(B_MESSAGE_TYPE, BLocaleRoster::kEmbeddedCatResId,
			mallocIO.Buffer(), mallocIO.BufferLength(), "embedded catalog");
	}

	return res;
}
status_t
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);

	if (res == B_OK) {
		res = rsrc.AddResource('CADA', mangledLanguage,
			mallocIO.Buffer(), mallocIO.BufferLength(),
			BString(fLanguageName));
	}

	return res;
}
Exemple #11
0
void 
MyApp	::	ReadyToRun(	void) 
{
	BResources * appResources = AppResources();
	size_t len;
	char * str = (char *)appResources->FindResource('CSTR', "aResource", &len);
	printf("%s\n", str);
	free (str);
	PostMessage(B_QUIT_REQUESTED);
}//end
Exemple #12
0
status_t TaskFS::SetUpMimeTyp(void)
{
	status_t err;
	//set the MimeType
	BMimeType mime(TASK_MIMETYPE);
	//later do better check
	bool valid = mime.IsInstalled();
	if (!valid) {
		mime.Install();
		mime.SetShortDescription(B_TRANSLATE_CONTEXT("Tasks",
			"Short mimetype description"));
		mime.SetLongDescription(B_TRANSLATE_CONTEXT("Tasks",
			"Long mimetype description"));
		//get the icon from our Ressources
		BResources* res = BApplication::AppResources();
		if (res != NULL){
			size_t size;
			const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, "TASK_ICON", &size);
			if (data!=NULL)
				mime.SetIcon(reinterpret_cast<const uint8*>(data), size);
		}
		mime.SetPreferredApp(APP_SIG);

		// add default task fields to meta-mime type
		BMessage fields;
		for (int32 i = 0; sDefaultAttributes[i].attribute; i++) {
			fields.AddString("attr:public_name", sDefaultAttributes[i].name);
			fields.AddString("attr:name", sDefaultAttributes[i].attribute);
			fields.AddInt32("attr:type", sDefaultAttributes[i].type);
			fields.AddString("attr:display_as", sDefaultAttributes[i].displayAs);
			fields.AddBool("attr:viewable", sDefaultAttributes[i].isPublic);
			fields.AddBool("attr:editable", sDefaultAttributes[i].editable);
			fields.AddInt32("attr:width", sDefaultAttributes[i].width);
			fields.AddInt32("attr:alignment", B_ALIGN_LEFT);
			fields.AddBool("attr:extra", false);
		}
		mime.SetAttrInfo(&fields);
			// create indices on all volumes for the found attributes.
		int32 count = 8;
		BVolumeRoster volumeRoster;
		BVolume volume;
		while (volumeRoster.GetNextVolume(&volume) == B_OK) {
			for (int32 i = 0; i < count; i++) {
				if (sDefaultAttributes[i].isPublic == true)
					fs_create_index(volume.Device(), sDefaultAttributes[i].attribute,
						sDefaultAttributes[i].type, 0);
			}
		}
	}
	else
		err = B_OK;
	return err;
}
Exemple #13
0
BBitmap* LoadVectorIcon(const char* name, int32 size)
{
	BResources* res = BApplication::AppResources();
	size_t length = 0;
	const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, name, &length);
	BBitmap* dest = new BBitmap(BRect(0, 0, size, size), B_RGBA32);
	if (data != NULL &&
		BIconUtils::GetVectorIcon((uint8*)data, length, dest) == B_OK)
		return dest;
	delete dest;
	return NULL;
}
void
ConfigWindow::MakeHowToView()
{
	BResources *resources = BApplication::AppResources();
	if (resources)
	{
		size_t length;
		char *buffer = (char *)resources->FindResource('ICON',101,&length);
		if (buffer)
		{
			BBitmap *bitmap = new BBitmap(BRect(0,0,63,63),B_CMAP8);
			if (bitmap && bitmap->InitCheck() == B_OK)
			{
				// copy and enlarge a 32x32 8-bit bitmap
				char *bits = (char *)bitmap->Bits();
				for (int32 i = 0,j = -64;i < length;i++)
				{
					if ((i % 32) == 0)
						j += 64;

					char *b = bits + (i << 1) + j;
					b[0] = b[1] = b[64] = b[65] = buffer[i];
				}
				fConfigView->AddChild(new BitmapView(bitmap));
			}
			else
				delete bitmap;
		}
	}

	BRect rect = fConfigView->Bounds();
	BTextView *text = new BTextView(rect,NULL,rect,B_FOLLOW_NONE,B_WILL_DRAW);
	text->SetViewColor(fConfigView->Parent()->ViewColor());
	text->SetAlignment(B_ALIGN_CENTER);
	text->SetText(
		MDR_DIALECT_CHOICE ("\n\nCreate a new account using the \"Add\" button.\n\n"
		"Delete accounts (or only the inbound/outbound) by using the \"Remove\" button on the selected item.\n\n"
		"Select an item in the list to edit its configuration.",
		"\n\nアカウントの新規作成は\"追加\"ボタンを\n使います。"
		"\n\nアカウント自体またはアカウントの\n送受信設定を削除するには\n項目を選択して\"削除\"ボタンを使います。"
		"\n\nアカウント内容の変更は、\nマウスで項目をクリックしてください。"));
	rect = text->Bounds();
	text->ResizeTo(rect.Width(),text->TextHeight(0,42));
	text->SetTextRect(rect);

	text->MakeEditable(false);
	text->MakeSelectable(false);

	fConfigView->AddChild(text);
	
	static_cast<CenterContainer *>(fConfigView)->Layout();
}
Exemple #15
0
// read_boot_code_data
static uint8 *
read_boot_code_data(const char* programPath)
{
	// open our executable
	BFile executableFile;
	status_t error = executableFile.SetTo(programPath, B_READ_ONLY);
	if (error != B_OK) {
		fprintf(stderr, "Error: Failed to open my executable file (\"%s\": "
			"%s\n", programPath, strerror(error));
		exit(1);
	}

	uint8 *bootCodeData = new uint8[kBootCodeSize];

	// open our resources
	BResources resources;
	error = resources.SetTo(&executableFile);
	const void *resourceData = NULL;
	if (error == B_OK) {
		// read the boot block from the resources
		size_t resourceSize;
		resourceData = resources.LoadResource(B_RAW_TYPE, 666, &resourceSize);

		if (resourceData && resourceSize != (size_t)kBootCodeSize) {
			resourceData = NULL;
			printf("Warning: Something is fishy with my resources! The boot "
				"code doesn't have the correct size. Trying the attribute "
				"instead ...\n");
		}
	}

	if (resourceData) {
		// found boot data in the resources
		memcpy(bootCodeData, resourceData, kBootCodeSize);
	} else {
		// no boot data in the resources; try the attribute
		ssize_t bytesRead = executableFile.ReadAttr("BootCode", B_RAW_TYPE,
			0, bootCodeData, kBootCodeSize);
		if (bytesRead < 0) {
			fprintf(stderr, "Error: Failed to read boot code from resources "
				"or attribute.\n");
			exit(1);
		}
		if (bytesRead != kBootCodeSize) {
			fprintf(stderr, "Error: Failed to read boot code from resources, "
				"and the boot code in the attribute has the wrong size!\n");
			exit(1);
		}
	}

	return bootCodeData;
}
Exemple #16
0
BBitmap *LoadMiniIcon(int32 id) {
	BResources *res = BApplication::AppResources();
	if (res != NULL) {
		size_t length;
		const void *bits = res->LoadResource(miniIcon, id, &length);
		if ((bits != NULL) && (length == B_MINI_ICON * B_MINI_ICON)) {
			BRect rect(0, 0, B_MINI_ICON-1, B_MINI_ICON-1);
			BBitmap *bitmap = new BBitmap(rect, B_CMAP8);
			bitmap->SetBits(bits, B_MINI_ICON * B_MINI_ICON, 0, B_CMAP8);
			return bitmap;
		}
	}
	return NULL;
}
Exemple #17
0
BBitmap *LoadLargeIcon(const char *name) {
	BResources *res = BApplication::AppResources();
	if (res != NULL) {
		size_t length;
		const void *bits = res->LoadResource(icon, name, &length);
		if ((bits != NULL) && (length == B_LARGE_ICON * B_LARGE_ICON)) {
			BRect rect(0, 0, B_LARGE_ICON-1, B_LARGE_ICON-1);
			BBitmap *bitmap = new BBitmap(rect, B_CMAP8);
			bitmap->SetBits(bits, B_LARGE_ICON * B_LARGE_ICON, 0, B_CMAP8);
			return bitmap;
		}
	}
	return NULL;
}
Exemple #18
0
BBitmap *getIconFromResources(const char *icon_resname) {
	BBitmap *bmp = NULL;
	BResources *res = be_app->AppResources();
	if (res->HasResource('BBMP',icon_resname)) {
		printf("has resource bitmap [%s]\n",icon_resname);
		BMessage msg;
		size_t len;
		char *buf;
		buf = (char *)res->LoadResource('BBMP', icon_resname, &len);
//					printf("loaded,len=%i\n",len);
		msg.Unflatten(buf);
		bmp = new BBitmap(&msg);
	}
	return bmp;
}
BBitmap*
BrowserToolbar::_RetrieveBitmap(const char *name)
{
	BResources *resource = BApplication::AppResources();
	size_t size = 0;

	const void *data = resource->LoadResource('TBBM', name, &size);
	if (!data)
		return NULL;

	BBitmap *bitmap = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32);
	if (BIconUtils::GetVectorIcon((const uint8 *)data, size, bitmap) != B_OK)
		return NULL;

	return bitmap;
}
DeviceWatcher::DeviceWatcher()
	: BLooper("MIDI devices watcher"),
	fDeviceEndpointsMap(), fVectorIconData(NULL), fVectorIconDataSize(0),
	fLargeIcon(NULL), fMiniIcon(NULL)
{
	// Load midi endpoint vector icon data
	app_info info;
	be_app->GetAppInfo(&info);
	BFile file(&info.ref, B_READ_ONLY);

	BResources resources;
	if (resources.SetTo(&file) == B_OK) {
		size_t dataSize;
		// Load MIDI port endpoint vector icon
		const uint8* data = (const uint8*)resources.LoadResource(
			B_VECTOR_ICON_TYPE,	"endpoint_vector_icon", &dataSize);

		if (data != NULL && dataSize > 0)
			fVectorIconData = new(std::nothrow) uint8[dataSize];

		if (fVectorIconData) {
			// data is own by resources local object: copy its content for
			// later use
			memcpy(fVectorIconData, data, dataSize);
			fVectorIconDataSize = dataSize;
		}
	}

	// Render 32x32 and 16x16 B_CMAP8 icons for R5 compatibility
	if (fVectorIconData != NULL) {
		fLargeIcon = new(std::nothrow) BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
		fMiniIcon  = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), B_CMAP8);

		if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
			fLargeIcon) != B_OK) {
			delete fLargeIcon;
			fLargeIcon = NULL;
		}
		if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
			fMiniIcon) != B_OK) {
			delete fMiniIcon;
			fMiniIcon = NULL;
		}
	}

	Start();
}
Exemple #21
0
BBitmap *LoadBitmap(const char *name, uint32 type_code) {
	if (type_code == B_TRANSLATOR_BITMAP) {
		return BTranslationUtils::GetBitmap(type_code, name);
	} else {
		BResources *res = BApplication::AppResources();
		if (res != NULL) {
			size_t length;
			const void *bits = res->LoadResource(type_code, name, &length);
			BMessage m;
			if (bits && B_OK == m.Unflatten((char*)bits)) {
				BBitmap* bitmap = (BBitmap*)BBitmap::Instantiate(&m);
				return bitmap;
			}
		}
		return NULL;
	}
}
Exemple #22
0
status_t
XColorsTable::_LoadXColorsTable()
{
	BResources* res = BApplication::AppResources();
	if (res == NULL)
		return B_ERROR;

	size_t size = 0;
	fTable = (_XColorEntry*)res->LoadResource(B_RAW_TYPE, "XColorsTable", &size);
	if (fTable == NULL || size < sizeof(_XColorEntry)) {
		fTable = NULL;
		return B_ENTRY_NOT_FOUND;
	}

	fCount = size / sizeof(_XColorEntry);
	return B_OK;
}
Exemple #23
0
bool
ResourceData::SetFromResource(const int32 &index, BResources &res)
{
	char *name;
	if (!res.GetResourceInfo(index, (type_code*)&fType, &fID,
							(const char **)&name, &fLength)) {
		*this = ResourceData();
		return false;
	}
	fName = name;
	fTypeString = MakeTypeString(fType);
	fIDString = "";
	fIDString << fID;
	fAttr = false;
	char *data = (char *)res.LoadResource(fType,fID,&fLength);
	SetData(data,fLength);
	
	return true;
}
Exemple #24
0
BResources*
CayaResources()
{
	image_info info;
	if (our_image(info) != B_OK)
		return NULL;

	BFile file(info.name, B_READ_ONLY);
	if (file.InitCheck() != B_OK)
		return NULL;

	BResources* res = new BResources(&file);
	if (res->InitCheck() != B_OK) {
		delete res;
		return NULL;
	}

	return res;
}
Exemple #25
0
status_t
BLocaleRoster::GetFlagIconForLanguage(BBitmap* flagIcon,
	const char* languageCode)
{
	if (languageCode == NULL || languageCode[0] == '\0'
		|| languageCode[1] == '\0')
		return B_BAD_VALUE;

	BAutolock lock(fData->fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	BResources* resources;
	status_t status = fData->GetResources(&resources);
	if (status != B_OK)
		return status;

	// Normalize the language code: first two letters, lowercase

	char normalizedCode[3];
	normalizedCode[0] = tolower(languageCode[0]);
	normalizedCode[1] = tolower(languageCode[1]);
	normalizedCode[2] = '\0';

	size_t size;
	const void* buffer = resources->LoadResource(B_VECTOR_ICON_TYPE,
		normalizedCode, &size);
	if (buffer != NULL && size != 0) {
		return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer),
			size, flagIcon);
	}

	// There is no language flag, try to get the default country's flag for
	// the language instead.

	BLanguage language(languageCode);
	const char* countryCode = country_code_for_language(language);
	if (countryCode == NULL)
		return B_NAME_NOT_FOUND;

	return GetFlagIconForCountry(flagIcon, countryCode);
}
void
IconView::ShowIconHeap(bool show)
{
	if (show == (fHeapIcon != NULL))
		return;

	if (show) {
		BResources* resources = be_app->AppResources();
		if (resources != NULL) {
			const void* data = NULL;
			size_t size;
			data = resources->LoadResource('VICN', "icon heap", &size);
			if (data != NULL) {
				// got vector icon data
				fHeapIcon = Icon::AllocateBitmap(B_LARGE_ICON, B_RGBA32);
				if (BIconUtils::GetVectorIcon((const uint8*)data,
						size, fHeapIcon) != B_OK) {
					// bad data
					delete fHeapIcon;
					fHeapIcon = NULL;
					data = NULL;
				}
			}
			if (data == NULL) {
				// no vector icon or failed to get bitmap
				// try bitmap icon
				data = resources->LoadResource(B_LARGE_ICON_TYPE, "icon heap",
					NULL);
				if (data != NULL) {
					fHeapIcon = Icon::AllocateBitmap(B_LARGE_ICON, B_CMAP8);
					if (fHeapIcon != NULL) {
						memcpy(fHeapIcon->Bits(), data,
							fHeapIcon->BitsLength());
					}
				}
			}
		}
	} else {
		delete fHeapIcon;
		fHeapIcon = NULL;
	}
}
Exemple #27
0
BBitmap*
SharedBitmap::_CreateBitmapFromResource(int32 size) const
{
	BResources resources;
	status_t status = get_app_resources(resources);
	if (status != B_OK)
		return NULL;

	size_t dataSize;
	const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID,
		&dataSize);
	if (data != NULL)
		return _LoadIconFromBuffer(data, dataSize, size);

	data = resources.LoadResource(B_MESSAGE_TYPE, fResourceID, &dataSize);
	if (data != NULL)
		return _LoadBitmapFromBuffer(data, dataSize);

	return NULL;
}
Exemple #28
0
static void
close_output_file()
{
	if (rdef_err == B_OK || (flags & RDEF_MERGE_RESOURCES) != 0)
		rsrc.Sync();
	else
		entry.Remove();  // throw away output file

	file.Unset();
	entry.Unset();
}
Exemple #29
0
BBitmap*
PrinterItem::_LoadVectorIcon(const char* resourceName, float iconSize)
{
	size_t dataSize;
	BResources* resources = BApplication::AppResources();
	const void* data = resources->LoadResource(B_VECTOR_ICON_TYPE,
		resourceName, &dataSize);

	if (data != NULL){
		BBitmap *iconBitmap = new BBitmap(BRect(0, 0, iconSize - 1,
			iconSize - 1), 0, B_RGBA32);
		if (BIconUtils::GetVectorIcon(
				reinterpret_cast<const uint8*>(data),
				dataSize, iconBitmap) == B_OK)
			return iconBitmap;
		else
			delete iconBitmap;
	};
	return NULL;
}
Exemple #30
0
BBitmap *GetCicnFromResource(const char *theResource)
{	
	// Get application info
	app_info info;
	
	be_app->GetAppInfo(&info);
	BFile file(&info.ref, O_RDONLY);	
	if (file.InitCheck())
		return NULL;
	
	size_t 		size;
	cicn 		*icon;
	
	BResources res; 
	status_t err; 
	if ( (err = res.SetTo(&file)) != B_NO_ERROR ) 
		return NULL;
		
	icon = (cicn *)res.FindResource('cicn', theResource, &size);
	if (!icon)			
		return NULL;
			
	// 	Swap bytes if needed.  We do this because the resources are currently
	// 	built on Macintosh BeOS
	if (B_HOST_IS_LENDIAN)
	{
		status_t retVal;
		retVal = swap_data(B_INT16_TYPE, &icon->width, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);		
		retVal = swap_data(B_INT16_TYPE, &icon->height, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);
	}
	
	// Get cicn bounding rect
	BRect bounds(0, 0, icon->width-1, icon->height-1);
		
	// Load bitmap
	BBitmap *bitmap = new BBitmap(bounds, B_COLOR_8_BIT);
	ASSERT(bitmap);
	bitmap->SetBits(&icon->data, size - sizeof(int16)*2, 0, B_COLOR_8_BIT);
	
	return (bitmap);	
}