gdi32: Consider whether the logical font face is vertical when selecting.
[wine/multimedia.git] / dlls / dmscript / dmscript_main.c
blob11f3f97a59f53f5fb0619ceea3695124231b152b
1 /* DirectMusicScript Main
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "dmscript_private.h"
24 #include "rpcproxy.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
28 static HINSTANCE instance;
29 LONG DMSCRIPT_refCount = 0;
31 typedef struct {
32 IClassFactory IClassFactory_iface;
33 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
34 } IClassFactoryImpl;
36 static HRESULT WINAPI create_unimpl_instance(REFIID riid, void **ppv, IUnknown *pUnkOuter)
38 FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
40 return E_NOINTERFACE;
43 /******************************************************************
44 * IClassFactory implementation
46 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
48 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
53 if (ppv == NULL)
54 return E_POINTER;
56 if (IsEqualGUID(&IID_IUnknown, riid))
57 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
58 else if (IsEqualGUID(&IID_IClassFactory, riid))
59 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
60 else {
61 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
62 *ppv = NULL;
63 return E_NOINTERFACE;
66 *ppv = iface;
67 IUnknown_AddRef((IUnknown*)*ppv);
68 return S_OK;
71 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
73 DMSCRIPT_LockModule();
75 return 2; /* non-heap based object */
78 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
80 DMSCRIPT_UnlockModule();
82 return 1; /* non-heap based object */
85 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
86 REFIID riid, void **ppv)
88 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
90 TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
92 return This->fnCreateInstance(riid, ppv, pUnkOuter);
95 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
97 TRACE("(%d)\n", dolock);
99 if (dolock)
100 DMSCRIPT_LockModule();
101 else
102 DMSCRIPT_UnlockModule();
104 return S_OK;
107 static const IClassFactoryVtbl classfactory_vtbl = {
108 ClassFactory_QueryInterface,
109 ClassFactory_AddRef,
110 ClassFactory_Release,
111 ClassFactory_CreateInstance,
112 ClassFactory_LockServer
115 static IClassFactoryImpl ScriptAutoImplSegment_CF = {{&classfactory_vtbl}, create_unimpl_instance};
116 static IClassFactoryImpl ScriptTrack_CF = {{&classfactory_vtbl},
117 DMUSIC_CreateDirectMusicScriptTrack};
118 static IClassFactoryImpl AudioVBScript_CF = {{&classfactory_vtbl}, create_unimpl_instance};
119 static IClassFactoryImpl Script_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicScriptImpl};
120 static IClassFactoryImpl ScriptAutoImplPerformance_CF = {{&classfactory_vtbl},
121 create_unimpl_instance};
122 static IClassFactoryImpl ScriptSourceCodeLoader_CF = {{&classfactory_vtbl}, create_unimpl_instance};
123 static IClassFactoryImpl ScriptAutoImplSegmentState_CF = {{&classfactory_vtbl},
124 create_unimpl_instance};
125 static IClassFactoryImpl ScriptAutoImplAudioPathConfig_CF = {{&classfactory_vtbl},
126 create_unimpl_instance};
127 static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {{&classfactory_vtbl},
128 create_unimpl_instance};
129 static IClassFactoryImpl ScriptAutoImplSong_CF = {{&classfactory_vtbl}, create_unimpl_instance};
131 /******************************************************************
132 * DllMain
136 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
137 if (fdwReason == DLL_PROCESS_ATTACH) {
138 instance = hinstDLL;
139 DisableThreadLibraryCalls(hinstDLL);
140 /* FIXME: Initialisation */
141 } else if (fdwReason == DLL_PROCESS_DETACH) {
142 /* FIXME: Cleanup */
145 return TRUE;
149 /******************************************************************
150 * DllCanUnloadNow (DMSCRIPT.@)
154 HRESULT WINAPI DllCanUnloadNow(void)
156 return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
160 /******************************************************************
161 * DllGetClassObject (DMSCRIPT.@)
165 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
167 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
168 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
169 *ppv = &ScriptAutoImplSegment_CF;
170 IClassFactory_AddRef((IClassFactory*)*ppv);
171 return S_OK;
172 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
173 *ppv = &ScriptTrack_CF;
174 IClassFactory_AddRef((IClassFactory*)*ppv);
175 return S_OK;
176 } else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
177 *ppv = &AudioVBScript_CF;
178 IClassFactory_AddRef((IClassFactory*)*ppv);
179 return S_OK;
180 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
181 *ppv = &Script_CF;
182 IClassFactory_AddRef((IClassFactory*)*ppv);
183 return S_OK;
184 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
185 *ppv = &ScriptAutoImplPerformance_CF;
186 IClassFactory_AddRef((IClassFactory*)*ppv);
187 return S_OK;
188 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
189 *ppv = &ScriptSourceCodeLoader_CF;
190 IClassFactory_AddRef((IClassFactory*)*ppv);
191 return S_OK;
192 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
193 *ppv = &ScriptAutoImplSegmentState_CF;
194 IClassFactory_AddRef((IClassFactory*)*ppv);
195 return S_OK;
196 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
197 *ppv = &ScriptAutoImplAudioPathConfig_CF;
198 IClassFactory_AddRef((IClassFactory*)*ppv);
199 return S_OK;
200 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
201 *ppv = &ScriptAutoImplAudioPath_CF;
202 IClassFactory_AddRef((IClassFactory*)*ppv);
203 return S_OK;
204 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
205 *ppv = &ScriptAutoImplSong_CF;
206 IClassFactory_AddRef((IClassFactory*)*ppv);
207 return S_OK;
210 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
211 return CLASS_E_CLASSNOTAVAILABLE;
215 /***********************************************************************
216 * DllRegisterServer (DMSCRIPT.@)
218 HRESULT WINAPI DllRegisterServer(void)
220 return __wine_register_resources( instance );
223 /***********************************************************************
224 * DllUnregisterServer (DMSCRIPT.@)
226 HRESULT WINAPI DllUnregisterServer(void)
228 return __wine_unregister_resources( instance );
231 /******************************************************************
232 * Helper functions
237 /* FOURCC to string conversion for debug messages */
238 const char *debugstr_fourcc (DWORD fourcc) {
239 if (!fourcc) return "'null'";
240 return wine_dbg_sprintf ("\'%c%c%c%c\'",
241 (char)(fourcc), (char)(fourcc >> 8),
242 (char)(fourcc >> 16), (char)(fourcc >> 24));
245 /* DMUS_VERSION struct to string conversion for debug messages */
246 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
247 if (!version) return "'null'";
248 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
249 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
250 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
253 /* returns name of given GUID */
254 const char *debugstr_dmguid (const GUID *id) {
255 static const guid_info guids[] = {
256 /* CLSIDs */
257 GE(CLSID_AudioVBScript),
258 GE(CLSID_DirectMusic),
259 GE(CLSID_DirectMusicAudioPath),
260 GE(CLSID_DirectMusicAudioPathConfig),
261 GE(CLSID_DirectMusicAuditionTrack),
262 GE(CLSID_DirectMusicBand),
263 GE(CLSID_DirectMusicBandTrack),
264 GE(CLSID_DirectMusicChordMapTrack),
265 GE(CLSID_DirectMusicChordMap),
266 GE(CLSID_DirectMusicChordTrack),
267 GE(CLSID_DirectMusicCollection),
268 GE(CLSID_DirectMusicCommandTrack),
269 GE(CLSID_DirectMusicComposer),
270 GE(CLSID_DirectMusicContainer),
271 GE(CLSID_DirectMusicGraph),
272 GE(CLSID_DirectMusicLoader),
273 GE(CLSID_DirectMusicLyricsTrack),
274 GE(CLSID_DirectMusicMarkerTrack),
275 GE(CLSID_DirectMusicMelodyFormulationTrack),
276 GE(CLSID_DirectMusicMotifTrack),
277 GE(CLSID_DirectMusicMuteTrack),
278 GE(CLSID_DirectMusicParamControlTrack),
279 GE(CLSID_DirectMusicPatternTrack),
280 GE(CLSID_DirectMusicPerformance),
281 GE(CLSID_DirectMusicScript),
282 GE(CLSID_DirectMusicScriptAutoImpSegment),
283 GE(CLSID_DirectMusicScriptAutoImpPerformance),
284 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
285 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
286 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
287 GE(CLSID_DirectMusicScriptAutoImpSong),
288 GE(CLSID_DirectMusicScriptSourceCodeLoader),
289 GE(CLSID_DirectMusicScriptTrack),
290 GE(CLSID_DirectMusicSection),
291 GE(CLSID_DirectMusicSegment),
292 GE(CLSID_DirectMusicSegmentState),
293 GE(CLSID_DirectMusicSegmentTriggerTrack),
294 GE(CLSID_DirectMusicSegTriggerTrack),
295 GE(CLSID_DirectMusicSeqTrack),
296 GE(CLSID_DirectMusicSignPostTrack),
297 GE(CLSID_DirectMusicSong),
298 GE(CLSID_DirectMusicStyle),
299 GE(CLSID_DirectMusicStyleTrack),
300 GE(CLSID_DirectMusicSynth),
301 GE(CLSID_DirectMusicSynthSink),
302 GE(CLSID_DirectMusicSysExTrack),
303 GE(CLSID_DirectMusicTemplate),
304 GE(CLSID_DirectMusicTempoTrack),
305 GE(CLSID_DirectMusicTimeSigTrack),
306 GE(CLSID_DirectMusicWaveTrack),
307 GE(CLSID_DirectSoundWave),
308 /* IIDs */
309 GE(IID_IDirectMusic),
310 GE(IID_IDirectMusic2),
311 GE(IID_IDirectMusic8),
312 GE(IID_IDirectMusicAudioPath),
313 GE(IID_IDirectMusicBand),
314 GE(IID_IDirectMusicBuffer),
315 GE(IID_IDirectMusicChordMap),
316 GE(IID_IDirectMusicCollection),
317 GE(IID_IDirectMusicComposer),
318 GE(IID_IDirectMusicContainer),
319 GE(IID_IDirectMusicDownload),
320 GE(IID_IDirectMusicDownloadedInstrument),
321 GE(IID_IDirectMusicGetLoader),
322 GE(IID_IDirectMusicGraph),
323 GE(IID_IDirectMusicInstrument),
324 GE(IID_IDirectMusicLoader),
325 GE(IID_IDirectMusicLoader8),
326 GE(IID_IDirectMusicObject),
327 GE(IID_IDirectMusicPatternTrack),
328 GE(IID_IDirectMusicPerformance),
329 GE(IID_IDirectMusicPerformance2),
330 GE(IID_IDirectMusicPerformance8),
331 GE(IID_IDirectMusicPort),
332 GE(IID_IDirectMusicPortDownload),
333 GE(IID_IDirectMusicScript),
334 GE(IID_IDirectMusicSegment),
335 GE(IID_IDirectMusicSegment2),
336 GE(IID_IDirectMusicSegment8),
337 GE(IID_IDirectMusicSegmentState),
338 GE(IID_IDirectMusicSegmentState8),
339 GE(IID_IDirectMusicStyle),
340 GE(IID_IDirectMusicStyle8),
341 GE(IID_IDirectMusicSynth),
342 GE(IID_IDirectMusicSynth8),
343 GE(IID_IDirectMusicSynthSink),
344 GE(IID_IDirectMusicThru),
345 GE(IID_IDirectMusicTool),
346 GE(IID_IDirectMusicTool8),
347 GE(IID_IDirectMusicTrack),
348 GE(IID_IDirectMusicTrack8),
349 GE(IID_IUnknown),
350 GE(IID_IPersistStream),
351 GE(IID_IStream),
352 GE(IID_IClassFactory),
353 /* GUIDs */
354 GE(GUID_DirectMusicAllTypes),
355 GE(GUID_NOTIFICATION_CHORD),
356 GE(GUID_NOTIFICATION_COMMAND),
357 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
358 GE(GUID_NOTIFICATION_PERFORMANCE),
359 GE(GUID_NOTIFICATION_RECOMPOSE),
360 GE(GUID_NOTIFICATION_SEGMENT),
361 GE(GUID_BandParam),
362 GE(GUID_ChordParam),
363 GE(GUID_CommandParam),
364 GE(GUID_CommandParam2),
365 GE(GUID_CommandParamNext),
366 GE(GUID_IDirectMusicBand),
367 GE(GUID_IDirectMusicChordMap),
368 GE(GUID_IDirectMusicStyle),
369 GE(GUID_MuteParam),
370 GE(GUID_Play_Marker),
371 GE(GUID_RhythmParam),
372 GE(GUID_TempoParam),
373 GE(GUID_TimeSignature),
374 GE(GUID_Valid_Start_Time),
375 GE(GUID_Clear_All_Bands),
376 GE(GUID_ConnectToDLSCollection),
377 GE(GUID_Disable_Auto_Download),
378 GE(GUID_DisableTempo),
379 GE(GUID_DisableTimeSig),
380 GE(GUID_Download),
381 GE(GUID_DownloadToAudioPath),
382 GE(GUID_Enable_Auto_Download),
383 GE(GUID_EnableTempo),
384 GE(GUID_EnableTimeSig),
385 GE(GUID_IgnoreBankSelectForGM),
386 GE(GUID_SeedVariations),
387 GE(GUID_StandardMIDIFile),
388 GE(GUID_Unload),
389 GE(GUID_UnloadFromAudioPath),
390 GE(GUID_Variations),
391 GE(GUID_PerfMasterTempo),
392 GE(GUID_PerfMasterVolume),
393 GE(GUID_PerfMasterGrooveLevel),
394 GE(GUID_PerfAutoDownload),
395 GE(GUID_DefaultGMCollection),
396 GE(GUID_Synth_Default),
397 GE(GUID_Buffer_Reverb),
398 GE(GUID_Buffer_EnvReverb),
399 GE(GUID_Buffer_Stereo),
400 GE(GUID_Buffer_3D_Dry),
401 GE(GUID_Buffer_Mono),
402 GE(GUID_DMUS_PROP_GM_Hardware),
403 GE(GUID_DMUS_PROP_GS_Capable),
404 GE(GUID_DMUS_PROP_GS_Hardware),
405 GE(GUID_DMUS_PROP_DLS1),
406 GE(GUID_DMUS_PROP_DLS2),
407 GE(GUID_DMUS_PROP_Effects),
408 GE(GUID_DMUS_PROP_INSTRUMENT2),
409 GE(GUID_DMUS_PROP_LegacyCaps),
410 GE(GUID_DMUS_PROP_MemorySize),
411 GE(GUID_DMUS_PROP_SampleMemorySize),
412 GE(GUID_DMUS_PROP_SamplePlaybackRate),
413 GE(GUID_DMUS_PROP_SetSynthSink),
414 GE(GUID_DMUS_PROP_SinkUsesDSound),
415 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
416 GE(GUID_DMUS_PROP_SynthSink_WAVE),
417 GE(GUID_DMUS_PROP_Volume),
418 GE(GUID_DMUS_PROP_WavesReverb),
419 GE(GUID_DMUS_PROP_WriteLatency),
420 GE(GUID_DMUS_PROP_WritePeriod),
421 GE(GUID_DMUS_PROP_XG_Capable),
422 GE(GUID_DMUS_PROP_XG_Hardware)
425 unsigned int i;
427 if (!id) return "(null)";
429 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
430 if (IsEqualGUID(id, guids[i].guid))
431 return guids[i].name;
433 /* if we didn't find it, act like standard debugstr_guid */
434 return debugstr_guid(id);
437 /* generic flag-dumping function */
438 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
439 char buffer[128] = "", *ptr = &buffer[0];
440 unsigned int i;
441 int size = sizeof(buffer);
443 for (i=0; i < num_names; i++)
445 if ((flags & names[i].val) || /* standard flag*/
446 ((!flags) && (!names[i].val))) { /* zero value only */
447 int cnt = snprintf(ptr, size, "%s ", names[i].name);
448 if (cnt < 0 || cnt >= size) break;
449 size -= cnt;
450 ptr += cnt;
454 return wine_dbg_sprintf("%s", buffer);
457 /* dump DMUS_OBJ flags */
458 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
459 static const flag_info flags[] = {
460 FE(DMUS_OBJ_OBJECT),
461 FE(DMUS_OBJ_CLASS),
462 FE(DMUS_OBJ_NAME),
463 FE(DMUS_OBJ_CATEGORY),
464 FE(DMUS_OBJ_FILENAME),
465 FE(DMUS_OBJ_FULLPATH),
466 FE(DMUS_OBJ_URL),
467 FE(DMUS_OBJ_VERSION),
468 FE(DMUS_OBJ_DATE),
469 FE(DMUS_OBJ_LOADED),
470 FE(DMUS_OBJ_MEMORY),
471 FE(DMUS_OBJ_STREAM)
473 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
476 /* dump whole DMUS_OBJECTDESC struct */
477 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
478 if (pDesc) {
479 char buffer[1024] = "", *ptr = &buffer[0];
481 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
482 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
483 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
484 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
485 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
486 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
487 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
488 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
489 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
490 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
491 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
492 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
493 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
495 return wine_dbg_sprintf("%s", buffer);
496 } else {
497 return wine_dbg_sprintf("(NULL)");