xref: /haiku/src/apps/deskbar/ResourceSet.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30 trademarks of Be Incorporated in the United States and other countries. Other
31 brand product names are registered trademarks or trademarks of their respective
32 holders.
33 All rights reserved.
34 */
35 #ifndef _T_RESOURCE_SET_H
36 #define _T_RESOURCE_SET_H
37 
38 
39 #include <List.h>
40 #include <Locker.h>
41 #include <SupportDefs.h>
42 
43 
44 class BBitmap;
45 class BResources;
46 class BDataIO;
47 class BString;
48 
49 namespace TResourcePrivate {
50 	class TypeItem;
51 	class TypeList;
52 }
53 
54 using namespace TResourcePrivate;
55 
56 const uint32 B_STRING_BLOCK_TYPE = 'SBLK';
57 
58 class TStringBlock {
59 public:
60 	TStringBlock(BDataIO* data);
61 	TStringBlock(const void* block, size_t size);
62 	virtual ~TStringBlock();
63 
64 	const char* String(size_t index) const;
65 
66 private:
67 	size_t PreIndex(char* strings, ssize_t len);
68 	void MakeIndex(const char* strings, ssize_t len, size_t indexLen,
69 		size_t* outIndex);
70 
71 	size_t fNumEntries;
72 	size_t* fIndex;
73 	char* fStrings;
74 	bool fOwnData;
75 };
76 
77 class TResourceSet {
78 public:
79 	TResourceSet();
80 	virtual ~TResourceSet();
81 
82 	status_t AddResources(BResources* resources);
83 	status_t AddDirectory(const char* fullPath);
84 	status_t AddEnvDirectory(const char* envPath,
85 		const char* defaultValue = NULL);
86 
87 	const void* FindResource(type_code type, int32 id, size_t* outSize);
88 	const void* FindResource(type_code type, const char* name, size_t* outSize);
89 
90 	const BBitmap* FindBitmap(type_code type, int32 id);
91 	const BBitmap* FindBitmap(type_code type, const char* name);
92 
93 	const TStringBlock* FindStringBlock(type_code type, int32 id);
94 	const TStringBlock* FindStringBlock(type_code type, const char* name);
95 
96 	const char* FindString(type_code type, int32 id, uint32 index);
97 	const char* FindString(type_code type, const char* name, uint32 index);
98 
99 private:
100 	status_t ExpandString(BString* out, const char* in);
101 	TypeList* FindTypeList(type_code type);
102 
103 	TypeItem* FindItemID(type_code type, int32 id);
104 	TypeItem* FindItemName(type_code type, const char* name);
105 
106 	TypeItem* LoadResource(type_code type, int32 id, const char* name,
107 		TypeList** inoutList = NULL);
108 
109 	BBitmap* ReturnBitmapItem(type_code type, TypeItem* from);
110 	TStringBlock* ReturnStringBlockItem(TypeItem* from);
111 
112 	BLocker fLock;				// access control.
113 	BList fResources;			// containing BResources objects.
114 	BList fDirectories;			// containing BPath objects.
115 	BList fTypes;				// containing TypeList objects.
116 };
117 
118 TResourceSet* AppResSet();
119 
120 
121 #endif	/* _T_RESOURCE_SET_H */
122