-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStyleUtils.cpp
80 lines (62 loc) · 1.51 KB
/
StyleUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Implementation of ResourceUtils.h
Contains function for loading a resource by name and converting it to a BBitmap.
Distributed as part of the resource editor Style from Realize productionS.
There are absolutely no restrictions on the usage/re-distribution of this file.
Realize productionS
Superior software for a superior OS
*/
#include <be/app/Application.h>
#include <be/app/Roster.h>
#include <be/interface/Bitmap.h>
#include <be/storage/File.h>
#include <be/storage/Resources.h>
#include <string.h>
BBitmap *FetchStyleResource(const char *rcName)
{
int i=0;
int32 id;
const char *name;
size_t length;
type_code type;
const void *data;
// Initialize the file
app_info info;
if (be_app->GetAppInfo(&info)!=B_OK)
return NULL;
entry_ref ref=info.ref;
BFile file(&ref, B_READ_ONLY);
if (file.InitCheck()!=B_OK)
return NULL;
BResources rcFile;
if (rcFile.SetTo(&file)!=B_OK)
return NULL;
// Search for resource
while(true)
if (rcFile.GetResourceInfo(i++, &type, &id, &name, &length))
{
if (strcmp(name, rcName)==0)
{
data=rcFile.LoadResource(type, name, &length);
break;
}
}
else
return NULL;
if (!data)
return NULL;
// Instantiate BBitmap object from resource data
BMessage msg;
if(msg.Unflatten((const char*)data)!=B_OK)
return NULL;
BArchivable *unarchived = instantiate_object(&msg);
if(unarchived)
{
BBitmap *bmp = (BBitmap *)unarchived;
if (bmp)
return bmp;
else
delete unarchived;
}
return NULL;
}