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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
// the glue!
#include <precomp.h>
#include <wasabicfg.h>
#include <bfc/assert.h>
#include "wac.h"
#include <api/service/servicei.h>
#include <api/memmgr/api_memmgr.h>
#ifndef STATIC_COMPONENT
extern WAComponentClient *the;
#ifndef WASABINOMAINAPI
ComponentAPI *api; // we do NOT delete this on shutdown!!!
#endif
OSMODULEHANDLE g_modulehandle;
#endif //STATIC_COMPONENT
WAComponentClient::WAComponentClient(const wchar_t *name) :
CfgItemI(name) {
OSModuleHandle = NULL;
}
const wchar_t *WAComponentClient::getName() {
return cfgitem_getName();
}
#ifdef WASABINOMAINAPI
void WAComponentClient::registerServices(api_service *_serviceapi)
{
serviceApi = _serviceapi;
waServiceFactory *sf = serviceApi->service_getServiceByGuid(applicationApiServiceGuid);
if (sf) applicationApi = reinterpret_cast<api_application*>(sf->getInterface());
#ifdef WASABI_COMPILE_SYSCB
sf = serviceApi->service_getServiceByGuid(syscbApiServiceGuid);
if (sf) sysCallbackApi = reinterpret_cast<api_syscb *>(sf->getInterface());
#endif
sf = serviceApi->service_getServiceByGuid(memMgrApiServiceGuid);
if (sf) memmgrApi = reinterpret_cast<api_memmgr *>(sf->getInterface());
#ifdef WASABI_COMPILE_CONFIG
sf = serviceApi->service_getServiceByGuid(configApiServiceGuid);
if (sf) configApi = reinterpret_cast<api_config *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_IMGLDR
sf = serviceApi->service_getServiceByGuid(imgLdrApiServiceGuid);
if (sf) imgLoaderApi = reinterpret_cast<imgldr_api *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_FONTS
sf = serviceApi->service_getServiceByGuid(fontApiServiceGuid);
if (sf) fontApi = reinterpret_cast<api_font *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_FILEREADER
sf = serviceApi->service_getServiceByGuid(fileReaderApiServiceGuid);
if (sf) fileApi = reinterpret_cast<api_fileReader *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_LOCALES
sf = serviceApi->service_getServiceByGuid(localesApiServiceGuid);
if (sf) localesApi = reinterpret_cast<api_locales *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_TIMERS
sf = serviceApi->service_getServiceByGuid(timerApiServiceGuid);
if (sf) timerApi = reinterpret_cast<timer_api *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_WND
sf = serviceApi->service_getServiceByGuid(wndApiServiceGuid);
if (sf) wndApi = reinterpret_cast<wnd_api *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_WNDMGR
sf = serviceApi->service_getServiceByGuid(wndMgrApiServiceGuid);
if (sf) wndManagerApi = reinterpret_cast<wndmgr_api *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_COMPONENTS
#endif
#ifdef WASABI_COMPILE_METADB
#endif
#ifdef WASABI_COMPILE_SCRIPT
sf = serviceApi->service_getServiceByGuid(makiApiServiceGuid);
if (sf) makiApi = reinterpret_cast<api_maki *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_SKIN
sf = serviceApi->service_getServiceByGuid(skinApiServiceGuid);
if (sf) skinApi = reinterpret_cast<api_skin *>(sf->getInterface());
#endif
#ifdef WASABI_COMPILE_MAKIDEBUG
sf = serviceApi->service_getServiceByGuid(makiDebugApiServiceGuid);
if (sf) debugApi = reinterpret_cast<api_makiDebugger *>(sf->getInterface());
#endif
#else
void WAComponentClient::registerServices(ComponentAPI *_api) {
// save API *
api = _api;
#endif
// propagate name from component to cfgitemi
if (cfgitem_getName() == NULL) CfgItemI::setName(WaComponent::getName());
// register resources
foreach(resources)
resources.getfor()->onRegisterServices();
endfor
// our CfgItem GUID defaults to our component GUID
cfgitem_setGUID(getGUID());
// by default, peg us under "Installed Components" in config
// {99CFD75C-1CA7-49e5-B8C0-7D78AA443C10}
const GUID installed_guid =
{ 0x99cfd75c, 0x1ca7, 0x49e5, { 0xb8, 0xc0, 0x7d, 0x78, 0xaa, 0x44, 0x3c, 0x10 } };
if (cfgitem_getParentGuid() == INVALID_GUID)
setParentGuid(installed_guid);
WASABI_API_CONFIG->config_registerCfgItem(this);
// allow overridden component class to do stuff
onRegisterServices();
}
int WAComponentClient::RegisterServicesSafeModeOk()
{
return 1;
}
void WAComponentClient::deregisterServices() {
foreach(resources)
resources.getfor()->onDeregisterServices();
endfor
WASABI_API_CONFIG->config_deregisterCfgItem(this);
}
CfgItem *WAComponentClient::getCfgInterface(int n) {
if (n == 0) return this;
return NULL;
}
class RegService : public LoadableResource {
public:
RegService(waServiceFactoryI *sf) : factory(sf) {}
virtual void onRegisterServices() {
WASABI_API_SVC->service_register(factory);
}
virtual void onDeregisterServices() {
WASABI_API_SVC->service_deregister(factory);
}
private:
waServiceFactoryI *factory;
};
void WAComponentClient::registerService(waServiceFactoryI* service) {
registerResource(new RegService(service));
}
class SkinPart : public LoadableResource {
public:
SkinPart(const wchar_t *name, int rel) : filename(name), id(-1), relative(rel) {}
void beforeLoadingSkinElements() {
ASSERT(!filename.isempty());
StringW fn(filename);
switch (relative) {
case RSF_RELATIVETOWAC:
fn.prepend(the->getComponentPath());// api->path_getComponentPath());
break;
case RSF_RELATIVETOTHEME: {
wchar_t theme[WA_MAX_PATH]=L"";
WASABI_API_CONFIG->getStringPrivate(L"theme", theme, WA_MAX_PATH, L"default");
StringW path = WASABI_API_APP->path_getAppPath();
path.AppendPath(L"themes");
path.AppendPath(theme);
fn = StringPathCombine(path, fn);
}
break;
}
id = WASABI_API_SKIN->loadSkinFile(fn);
}
virtual void onDeregisterServices() {
if (id >= 0 && WASABI_API_SKIN) WASABI_API_SKIN->unloadSkinPart(id);
id = -1;
}
private:
StringW filename;
int id;
int relative;
};
void WAComponentClient::registerSkinFile(const wchar_t *filename, int relative)
{
registerResource(new SkinPart(filename, relative));
}
void WAComponentClient::registerResource(LoadableResource *res) {
ASSERT(!resources.haveItem(res));
resources.addItem(res);
if (postregisterservices) res->onRegisterServices();
}
void WAComponentClient::internal_onDestroy() {
onDestroy();
foreach(resources)
if (resources.getfor()->deleteOnShutdown()) delete resources.getfor();
endfor
resources.removeAll();
}
int WAComponentClient::internal_onNotify(int cmd, int param1, int param2, int param3, int param4) {
switch (cmd) {
case WAC_NOTIFY_BEFORELOADINGSKINELEMENTS:
foreach(resources)
resources.getfor()->beforeLoadingSkinElements();
endfor
break;
case WAC_NOTIFY_SKINLOADED:
onSkinLoaded();
break;
}
return onNotify(cmd, param1, param2, param3, param4);
}
#ifndef STATIC_COMPONENT
extern "C" {
__declspec(dllexport) UINT WAC_getVersion(void) {
return WA_COMPONENT_VERSION;
}
__declspec(dllexport) int WAC_init(OSMODULEHANDLE moduleHandle) {
the->setOSModuleHandle(moduleHandle);
if (g_modulehandle == NULL) g_modulehandle = moduleHandle;
return TRUE;
}
__declspec(dllexport) WaComponent *WAC_enumComponent(int n) {
return the;
}
} // end extern "C"
#endif
#define CBCLASS WaComponentI
START_DISPATCH;
CB(GETNAME, getName);
CB(GETGUID, getGUID);
#ifndef WASABINOMAINAPI
VCB(REGISTERSERVICES, registerServices);
#else
VCB(REGISTERSERVICES2, registerServices);
#endif
CB(15, RegisterServicesSafeModeOk)
VCB(DEREGISTERSERVICES, deregisterServices);
VCB(ONCREATE, onCreate);
VCB(ONDESTROY, internal_onDestroy);
CB(CREATEWINDOW, createWindow);
CB(ONNOTIFY, internal_onNotify);
CB(ONCOMMAND, onCommand);
CB(GETCFGINTERFACE, getCfgInterface);
VCB(SETOSMODULEHANDLE, setOSModuleHandle);
CB(GETOSMODULEHANDLE, getOSModuleHandle);
VCB(SETPATH, setComponentPath);
CB(GETPATH, getComponentPath);
END_DISPATCH;
#undef CBCLASS
#ifdef WASABINOMAINAPI
api_application *applicationApi = NULL;
api_service *serviceApi = NULL;
api_syscb *sysCallbackApi = NULL;
api_memmgr *memmgrApi = NULL;
#ifdef WASABI_COMPILE_CONFIG
api_config *configApi = NULL;
#endif
#ifdef WASABI_COMPILE_IMGLDR
imgldr_api *imgLoaderApi = NULL;
#endif
#ifdef WASABI_COMPILE_FONTS
api_font *fontApi = NULL;
#endif
#ifdef WASABI_COMPILE_FILEREADER
api_fileReader *fileApi = NULL;
#endif
#ifdef WASABI_COMPILE_LOCALES
api_locales *localesApi = NULL;
#endif
#ifdef WASABI_COMPILE_TIMERS
timer_api *timerApi = NULL;
#endif
#ifdef WASABI_COMPILE_WND
wnd_api *wndApi = NULL;
#endif
#ifdef WASABI_COMPILE_WNDMGR
wndmgr_api *wndManagerApi = NULL;
#endif
#ifdef WASABI_COMPILE_COMPONENTS
#endif
#ifdef WASABI_COMPILE_METADB
#endif
#ifdef WASABI_COMPILE_SCRIPT
api_maki *makiApi = NULL;
#endif
#ifdef WASABI_COMPILE_SKIN
api_skin *skinApi;
#endif
#ifdef WASABI_COMPILE_MAKIDEBUG
api_makiDebugger *debugApi = NULL;
#endif
#ifdef WASABI_COMPILE_MEDIACORE
api_core *coreApi = NULL;
#endif
#endif // ifdef WASABINOMAINAPI
|