winspool: Update the default settings when deleting the default printer.
[wine] / dlls / wineqtdecoder / qtdatahandler.c
1 /*
2  * QuickTime Data Handler
3  *
4  * Copyright 2011 Aric Stewart for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #define ULONG CoreFoundation_ULONG
24 #define HRESULT CoreFoundation_HRESULT
25
26 #define LoadResource __carbon_LoadResource
27 #define CompareString __carbon_CompareString
28 #define GetCurrentThread __carbon_GetCurrentThread
29 #define GetCurrentProcess __carbon_GetCurrentProcess
30 #define AnimatePalette __carbon_AnimatePalette
31 #define EqualRgn __carbon_EqualRgn
32 #define FillRgn __carbon_FillRgn
33 #define FrameRgn __carbon_FrameRgn
34 #define GetPixel __carbon_GetPixel
35 #define InvertRgn __carbon_InvertRgn
36 #define LineTo __carbon_LineTo
37 #define OffsetRgn __carbon_OffsetRgn
38 #define PaintRgn __carbon_PaintRgn
39 #define Polygon __carbon_Polygon
40 #define ResizePalette __carbon_ResizePalette
41 #define SetRectRgn __carbon_SetRectRgn
42
43 #define CheckMenuItem __carbon_CheckMenuItem
44 #define DeleteMenu __carbon_DeleteMenu
45 #define DrawMenuBar __carbon_DrawMenuBar
46 #define EnableMenuItem __carbon_EnableMenuItem
47 #define EqualRect __carbon_EqualRect
48 #define FillRect __carbon_FillRect
49 #define FrameRect __carbon_FrameRect
50 #define GetCursor __carbon_GetCursor
51 #define GetMenu __carbon_GetMenu
52 #define InvertRect __carbon_InvertRect
53 #define IsWindowVisible __carbon_IsWindowVisible
54 #define MoveWindow __carbon_MoveWindow
55 #define OffsetRect __carbon_OffsetRect
56 #define PtInRect __carbon_PtInRect
57 #define SetCursor __carbon_SetCursor
58 #define SetRect __carbon_SetRect
59 #define ShowCursor __carbon_ShowCursor
60 #define ShowWindow __carbon_ShowWindow
61 #define UnionRect __carbon_UnionRect
62
63 #include <QuickTime/QuickTimeComponents.h>
64
65 #undef LoadResource
66 #undef CompareString
67 #undef GetCurrentThread
68 #undef _CDECL
69 #undef DPRINTF
70 #undef GetCurrentProcess
71 #undef AnimatePalette
72 #undef EqualRgn
73 #undef FillRgn
74 #undef FrameRgn
75 #undef GetPixel
76 #undef InvertRgn
77 #undef LineTo
78 #undef OffsetRgn
79 #undef PaintRgn
80 #undef Polygon
81 #undef ResizePalette
82 #undef SetRectRgn
83 #undef CheckMenuItem
84 #undef DeleteMenu
85 #undef DrawMenuBar
86 #undef EnableMenuItem
87 #undef EqualRect
88 #undef FillRect
89 #undef FrameRect
90 #undef GetCursor
91 #undef GetMenu
92 #undef InvertRect
93 #undef IsWindowVisible
94 #undef MoveWindow
95 #undef OffsetRect
96 #undef PtInRect
97 #undef SetCursor
98 #undef SetRect
99 #undef ShowCursor
100 #undef ShowWindow
101 #undef UnionRect
102
103 #undef ULONG
104 #undef HRESULT
105 #undef DPRINTF
106 #undef STDMETHODCALLTYPE
107
108 #include <assert.h>
109 #include <stdio.h>
110 #include <stdarg.h>
111
112 #define NONAMELESSSTRUCT
113 #define NONAMELESSUNION
114 #define COBJMACROS
115
116 #include "windef.h"
117 #include "winbase.h"
118 #include "wtypes.h"
119 #include "winuser.h"
120 #include "dshow.h"
121
122 #include <assert.h>
123
124 #include "wine/unicode.h"
125 #include "wine/debug.h"
126
127 #include "qtprivate.h"
128
129 WINE_DEFAULT_DEBUG_CHANNEL(qtdatahandler);
130
131 static ComponentDescription myType =
132 {
133     'dhlr',
134     'WINE',
135     'WINE',
136     0,
137     0
138 };
139
140 typedef struct DHData
141 {
142     WineDataRefRecord dataRef;
143
144    Ptr AsyncPtr;
145    long AsyncRefCon;
146    DataHCompletionUPP AsyncCompletionRtn;
147 } DHData;
148
149 static pascal ComponentResult myComponentRoutineProc ( ComponentParameters *
150 cp, Handle componentStorage);
151
152 void RegisterWineDataHandler( void )
153 {
154     ComponentRoutineUPP MyComponentRoutineUPP;
155
156     MyComponentRoutineUPP = NewComponentRoutineUPP(&myComponentRoutineProc);
157     RegisterComponent( &myType , MyComponentRoutineUPP, 0, NULL, NULL, NULL);
158 }
159
160 static pascal ComponentResult myDataHCanUseDataRef ( DataHandler dh,
161                                        Handle dataRef,
162                                        long *useFlags
163 )
164 {
165     WineDataRefRecord *record = (WineDataRefRecord*)(*dataRef);
166     TRACE("%p %p %p\n",dh,dataRef,useFlags);
167     if (record->pReader == NULL)
168         return badComponentSelector;
169     *useFlags = kDataHCanRead;
170     return noErr;
171 }
172
173 static pascal ComponentResult myDataHSetDataRef ( DataHandler dh, Handle dataRef)
174 {
175     Handle storage = GetComponentInstanceStorage(dh);
176     DHData *data = (DHData*)*storage;
177     WineDataRefRecord* newRef = (WineDataRefRecord*)(*dataRef);
178     TRACE("\n");
179     if (newRef->pReader != data->dataRef.pReader)
180         IAsyncReader_AddRef(newRef->pReader);
181     data->dataRef = *newRef;
182     return noErr;
183 }
184
185 static pascal ComponentResult myDataHGetAvailableFileSize ( DataHandler dh,
186                                                    long *fileSize)
187 {
188     Handle storage = GetComponentInstanceStorage(dh);
189     DHData *data = (DHData*)*storage;
190     LONGLONG total;
191     LONGLONG avaliable;
192
193     TRACE("%p\n",dh);
194
195     IAsyncReader_Length(data->dataRef.pReader,&total,&avaliable);
196     *fileSize = avaliable;
197     return noErr;
198 }
199
200 static pascal ComponentResult myDataHGetFileSize ( DataHandler dh, long *fileSize)
201 {
202     Handle storage = GetComponentInstanceStorage(dh);
203     DHData *data = (DHData*)*storage;
204     LONGLONG total;
205     LONGLONG avaliable;
206
207     TRACE("%p\n",dh);
208
209     IAsyncReader_Length(data->dataRef.pReader,&total,&avaliable);
210     *fileSize = total;
211     return noErr;
212 }
213
214 static pascal ComponentResult myDataHScheduleData ( DataHandler dh,
215                                              Ptr PlaceToPutDataPtr,
216                                              long FileOffset,
217                                              long DataSize,
218                                              long RefCon,
219                                              DataHSchedulePtr scheduleRec,
220                                              DataHCompletionUPP CompletionRtn)
221 {
222     Handle storage = GetComponentInstanceStorage(dh);
223     DHData *data = (DHData*)*storage;
224     HRESULT hr;
225     LONGLONG offset = FileOffset;
226     BYTE* buffer = (BYTE*)PlaceToPutDataPtr;
227
228     TRACE("%p %p %li %li %li %p %p\n",dh, PlaceToPutDataPtr, FileOffset, DataSize, RefCon, scheduleRec, CompletionRtn);
229
230     hr = IAsyncReader_SyncRead(data->dataRef.pReader, offset, DataSize, buffer);
231     TRACE("result %x\n",hr);
232     if (CompletionRtn)
233     {
234         if (data->AsyncCompletionRtn)
235             InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
236
237         data->AsyncPtr = PlaceToPutDataPtr;
238         data->AsyncRefCon = RefCon;
239         data->AsyncCompletionRtn = CompletionRtn;
240     }
241
242     return noErr;
243 }
244
245 static pascal ComponentResult myDataHFinishData (DataHandler dh, Ptr PlaceToPutDataPtr, Boolean Cancel)
246 {
247     Handle storage = GetComponentInstanceStorage(dh);
248     DHData *data = (DHData*)*storage;
249     if (!data->AsyncCompletionRtn)
250         return noErr;
251     if (!PlaceToPutDataPtr || PlaceToPutDataPtr == data->AsyncPtr)
252     {
253         if (!Cancel)
254             InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
255         data->AsyncPtr = NULL;
256         data->AsyncRefCon = 0;
257         data->AsyncCompletionRtn = NULL;
258     }
259     return noErr;
260 }
261
262 static pascal ComponentResult myDataHGetData ( DataHandler dh,
263                                         Handle h,
264                                         long hOffset,
265                                         long offset,
266                                         long size)
267 {
268     Handle storage = GetComponentInstanceStorage(dh);
269     DHData *data = (DHData*)*storage;
270     BYTE *target = (BYTE*)*h;
271     LONGLONG off = offset;
272     HRESULT hr;
273
274     TRACE("%p %p %li %li %li\n",dh, h, hOffset, offset, size);
275     hr = IAsyncReader_SyncRead(data->dataRef.pReader, off, size, target+hOffset);
276     TRACE("result %x\n",hr);
277
278     return noErr;
279 }
280
281 static pascal ComponentResult myDataHCompareDataRef ( DataHandler dh,
282                                                Handle dataRef, Boolean *equal)
283 {
284     WineDataRefRecord *ptr1;
285     Handle storage = GetComponentInstanceStorage(dh);
286     DHData *data = (DHData*)*storage;
287     TRACE("\n");
288
289     ptr1 = (WineDataRefRecord*)dataRef;
290
291     *equal = (ptr1->pReader == data->dataRef.pReader);
292     return noErr;
293 }
294
295 static pascal ComponentResult myDataHGetDataRef ( DataHandler dh, Handle *dataRef)
296 {
297     Handle storage = GetComponentInstanceStorage(dh);
298     TRACE("\n");
299     *dataRef = storage;
300     HandToHand(dataRef);
301     return noErr;
302 }
303
304 static pascal ComponentResult myDataHGetScheduleAheadTime ( DataHandler dh,
305                                                        long *millisecs)
306 {
307     TRACE("\n");
308     *millisecs = 1000;
309     return noErr;
310 }
311
312 static pascal ComponentResult myDataHGetInfoFlags ( DataHandler dh, UInt32 *flags)
313 {
314     TRACE("\n");
315     *flags = 0;
316     return noErr;
317 }
318
319 static pascal ComponentResult myDataHGetFileTypeOrdering ( DataHandler dh,
320                            DataHFileTypeOrderingHandle *orderingListHandle)
321 {
322     OSType orderlist[1] = {kDataHFileTypeExtension};
323     TRACE("\n");
324     PtrToHand( &orderlist, (Handle*)orderingListHandle, sizeof(OSType));
325     return noErr;
326 }
327
328 typedef struct {
329     const CFStringRef fname;
330     const int sig_length;
331     const BYTE sig[10];
332 } signature;
333
334 static const signature stream_sigs[] = {
335     {CFSTR("video.asf"),4,{0x30,0x26,0xb2,0x75}},
336     {CFSTR("video.mov"),8,{0x00,0x00,0x00,0x14,0x66,0x74,0x79,0x70}},
337     {CFSTR("video.mp4"),8,{0x00,0x00,0x00,0x18,0x66,0x74,0x79,0x70}},
338     {CFSTR("video.m4v"),8,{0x00,0x00,0x00,0x1c,0x66,0x74,0x79,0x70}},
339     {CFSTR("video.flv"),4,{0x46,0x4C,0x56,0x01}},
340     {CFSTR("video.mpg"),3,{0x00,0x00,0x01}},
341     {CFSTR("avideo.rm"),4,{0x2E,0x52,0x4D,0x46}}
342 };
343
344 static pascal ComponentResult myDataHGetFileName ( DataHandler dh, Str255 str)
345 {
346     Handle storage = GetComponentInstanceStorage(dh);
347     DHData *data = (DHData*)*storage;
348     TRACE("%p %s\n",str,debugstr_guid(&data->dataRef.streamSubtype));
349
350     /* Todo Expand this list */
351     if (IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1Video) ||
352         IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1System))
353         CFStringGetPascalString(CFSTR("video.mpg"),str,256,kCFStringEncodingMacRoman);
354     else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Asf))
355         CFStringGetPascalString(CFSTR("video.asf"),str,256,kCFStringEncodingMacRoman);
356     else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Avi))
357         CFStringGetPascalString(CFSTR("video.avi"),str,256,kCFStringEncodingMacRoman);
358     else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_QTMovie))
359         CFStringGetPascalString(CFSTR("video.mov"),str,256,kCFStringEncodingMacRoman);
360     else
361     {
362         BYTE header[10] = {0,0,0,0,0,0,0,0,0,0};
363         int i;
364         IAsyncReader_SyncRead(data->dataRef.pReader, 0, 8, header);
365
366         for (i=0; i < sizeof(stream_sigs)/sizeof(signature); i++)
367             if (memcmp(header, stream_sigs[i].sig, stream_sigs[i].sig_length)==0)
368             {
369                 CFStringGetPascalString(stream_sigs[i].fname,str,256,kCFStringEncodingMacRoman);
370                 return noErr;
371             }
372
373         return badComponentSelector;
374     }
375
376     return noErr;
377 }
378
379 static pascal ComponentResult myDataHOpenForRead(DataHandler dh)
380 {
381     TRACE("\n");
382     return noErr;
383 }
384
385 static pascal ComponentResult myDataHTask(DataHandler dh)
386 {
387     Handle storage = GetComponentInstanceStorage(dh);
388     DHData *data = (DHData*)*storage;
389
390     if (data->AsyncCompletionRtn)
391     {
392         TRACE("Sending Completion\n");
393         InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
394         data->AsyncPtr = NULL;
395         data->AsyncRefCon = 0;
396         data->AsyncCompletionRtn = NULL;
397     }
398     return noErr;
399 }
400
401 static pascal ComponentResult myDataHPlaybackHints(DataHandler dh, long flags,
402                 unsigned long minFileOffset, unsigned long maxFileOffset,
403                 long bytesPerSecond)
404 {
405     TRACE("%lu %lu %li\n",minFileOffset, maxFileOffset, bytesPerSecond);
406     return noErr;
407 }
408
409 static pascal ComponentResult myDataHGetFileSize64(DataHandler dh, wide * fileSize)
410 {
411     Handle storage = GetComponentInstanceStorage(dh);
412     DHData *data = (DHData*)*storage;
413     LONGLONG total;
414     LONGLONG avaliable;
415     SInt64 total64;
416
417     TRACE("%p\n",dh);
418
419     IAsyncReader_Length(data->dataRef.pReader,&total,&avaliable);
420     total64 = total;
421     *fileSize = SInt64ToWide(total64);
422     return noErr;
423 }
424
425 static pascal ComponentResult myDataHGetAvailableFileSize64(DataHandler dh, wide * fileSize)
426 {
427     Handle storage = GetComponentInstanceStorage(dh);
428     DHData *data = (DHData*)*storage;
429     LONGLONG total;
430     LONGLONG avaliable;
431     SInt64 total64;
432
433     TRACE("%p\n",dh);
434
435     IAsyncReader_Length(data->dataRef.pReader,&total,&avaliable);
436     total64 = avaliable;
437     *fileSize = SInt64ToWide(total64);
438     return noErr;
439 }
440
441 static pascal ComponentResult myDataHScheduleData64( DataHandler dh,
442                                           Ptr PlaceToPutDataPtr,
443                                           const wide * FileOffset,
444                                           long DataSize,
445                                           long RefCon,
446                                           DataHSchedulePtr scheduleRec,
447                                           DataHCompletionUPP CompletionRtn)
448 {
449     Handle storage = GetComponentInstanceStorage(dh);
450     DHData *data = (DHData*)*storage;
451     HRESULT hr;
452     SInt64 fileOffset64 = WideToSInt64(*FileOffset);
453     LONGLONG offset = fileOffset64;
454     BYTE* buffer = (BYTE*)PlaceToPutDataPtr;
455
456     TRACE("%p %p %lli %li %li %p %p\n",dh, PlaceToPutDataPtr, offset, DataSize, RefCon, scheduleRec, CompletionRtn);
457
458     hr = IAsyncReader_SyncRead(data->dataRef.pReader, offset, DataSize, buffer);
459     TRACE("result %x\n",hr);
460     if (CompletionRtn)
461     {
462         if (data->AsyncCompletionRtn)
463             InvokeDataHCompletionUPP(data->AsyncPtr, data->AsyncRefCon, noErr, data->AsyncCompletionRtn);
464
465         data->AsyncPtr = PlaceToPutDataPtr;
466         data->AsyncRefCon = RefCon;
467         data->AsyncCompletionRtn = CompletionRtn;
468     }
469
470     return noErr;
471 }
472
473 static const struct { LPVOID proc; ProcInfoType type;} componentFunctions[] =
474 {
475     {NULL, 0}, /* 0 */
476     {NULL, 0}, /* 1 */
477     {myDataHGetData,  kPascalStackBased
478             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
479             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
480             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
481             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
482             | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
483             | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
484 }, /* kDataHGetDataSelect                        */
485     {NULL, 0}, /* kDataHPutDataSelect                        */
486     {NULL, 0}, /* kDataHFlushDataSelect                      */
487     {NULL, 0}, /* kDataHOpenForWriteSelect                   */
488     {NULL, 0}, /* kDataHCloseForWriteSelect                  */
489     {NULL, 0}, /* 7 */
490     {myDataHOpenForRead, kPascalStackBased
491             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
492             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
493 }, /* kDataHOpenForReadSelect
494 */
495     {NULL, 0}, /* kDataHCloseForReadSelect                   */
496     {myDataHSetDataRef,  kPascalStackBased
497             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
498             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
499             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
500 }, /* kDataHSetDataRefSelect                     */
501     {myDataHGetDataRef,  kPascalStackBased
502             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
503             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
504             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
505 }, /* kDataHGetDataRefSelect                     */
506     {myDataHCompareDataRef,  kPascalStackBased
507             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
508             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
509             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
510             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean*)))
511 }, /* kDataHCompareDataRefSelect                 */
512     {myDataHTask, kPascalStackBased
513             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
514             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
515 }, /* kDataHTaskSelect                           */
516     {myDataHScheduleData,  kPascalStackBased
517             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
518             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
519             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
520             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))
521             | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
522             | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
523             | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DataHSchedulePtr)))
524             | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(DataHCompletionUPP)))
525 }, /* kDataHScheduleDataSelect                   */
526     {myDataHFinishData, kPascalStackBased
527             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
528             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
529             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
530             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean)))
531 }, /* kDataHFinishDataSelect                     */
532     {NULL, 0}, /* kDataHFlushCacheSelect       0x10              */
533     {NULL, 0}, /* kDataHResolveDataRefSelect                 */
534     {myDataHGetFileSize,  kPascalStackBased
535             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
536             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
537             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
538 }, /* kDataHGetFileSizeSelect                    */
539     {myDataHCanUseDataRef,  kPascalStackBased
540             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
541             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
542             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
543             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long*)))
544 }, /* kDataHCanUseDataRefSelect                  */
545     {NULL, 0}, /* kDataHGetVolumeListSelect                  */
546     {NULL, 0}, /* kDataHWriteSelect                          */
547     {NULL, 0}, /* kDataHPreextendSelect                      */
548     {NULL, 0}, /* kDataHSetFileSizeSelect                    */
549     {NULL, 0}, /* kDataHGetFreeSpaceSelect                   */
550     {NULL, 0}, /* kDataHCreateFileSelect                     */
551     {NULL, 0}, /* kDataHGetPreferredBlockSizeSelect          */
552     {NULL, 0}, /* kDataHGetDeviceIndexSelect                 */
553     {NULL, 0}, /* kDataHIsStreamingDataHandlerSelect         */
554     {NULL, 0}, /* kDataHGetDataInBufferSelect                */
555     {myDataHGetScheduleAheadTime,  kPascalStackBased
556             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
557             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
558             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
559 }, /* kDataHGetScheduleAheadTimeSelect           */
560 /* End of Required List */
561     {NULL, 0}, /* kDataHSetCacheSizeLimitSelect              */
562     {NULL, 0}, /* kDataHGetCacheSizeLimitSelect       0x20   */
563     {NULL, 0}, /* kDataHGetMovieSelect                       */
564     {NULL, 0}, /* kDataHAddMovieSelect                       */
565     {NULL, 0}, /* kDataHUpdateMovieSelect                    */
566     {NULL, 0}, /* kDataHDoesBufferSelect                     */
567     {myDataHGetFileName,  kPascalStackBased
568             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
569             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
570             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Str255*)))
571 }, /* kDataHGetFileNameSelect                    */
572     {myDataHGetAvailableFileSize,   kPascalStackBased
573             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
574             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
575             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long*)))
576 }, /* kDataHGetAvailableFileSizeSelect           */
577     {NULL, 0}, /* kDataHGetMacOSFileTypeSelect               */
578     {NULL, 0}, /* kDataHGetMIMETypeSelect                    */
579     {NULL, 0}, /* kDataHSetDataRefWithAnchorSelect           */
580     {NULL, 0}, /* kDataHGetDataRefWithAnchorSelect           */
581     {NULL, 0}, /* kDataHSetMacOSFileTypeSelect               */
582     {NULL, 0}, /* kDataHSetTimeBaseSelect                    */
583     {myDataHGetInfoFlags,  kPascalStackBased
584             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
585             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
586             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(UInt32*)))
587 }, /* kDataHGetInfoFlagsSelect                   */
588     {myDataHScheduleData64, kPascalStackBased
589             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
590             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
591             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
592             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(wide*)))
593             | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
594             | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
595             | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DataHSchedulePtr)))
596             | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(DataHCompletionUPP)))
597 }, /* kDataHScheduleData64Select                 */
598     {NULL, 0}, /* kDataHWrite64Select                        */
599     {myDataHGetFileSize64, kPascalStackBased
600             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
601             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
602             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(wide*)))
603 }, /* kDataHGetFileSize64Select     0x30         */
604     {NULL, 0}, /* kDataHPreextend64Select                    */
605     {NULL, 0}, /* kDataHSetFileSize64Select                  */
606     {NULL, 0}, /* kDataHGetFreeSpace64Select                 */
607     {NULL, 0}, /* kDataHAppend64Select                       */
608     {NULL, 0}, /* kDataHReadAsyncSelect                      */
609     {NULL, 0}, /* kDataHPollReadSelect                       */
610     {NULL, 0}, /* kDataHGetDataAvailabilitySelect            */
611     {NULL, 0}, /* 0x0038 */
612     {NULL, 0}, /* 0x0039 */
613     {NULL, 0}, /* kDataHGetFileSizeAsyncSelect               */
614     {NULL, 0}, /* kDataHGetDataRefAsTypeSelect               */
615     {NULL, 0}, /* kDataHSetDataRefExtensionSelect            */
616     {NULL, 0}, /* kDataHGetDataRefExtensionSelect            */
617     {NULL, 0}, /* kDataHGetMovieWithFlagsSelect              */
618     {NULL, 0}, /* 0x3F */
619     {myDataHGetFileTypeOrdering, kPascalStackBased
620             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
621             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
622             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DataHFileTypeOrderingHandle*)))
623 }, /* kDataHGetFileTypeOrderingSelect  0x40      */
624     {NULL, 0}, /* kDataHCreateFileWithFlagsSelect            */
625     {NULL, 0}, /* kDataHGetMIMETypeAsyncSelect               */
626     {NULL, 0}, /* kDataHGetInfoSelect                        */
627     {NULL, 0}, /* kDataHSetIdleManagerSelect                 */
628     {NULL, 0}, /* kDataHDeleteFileSelect                     */
629     {NULL, 0}, /* kDataHSetMovieUsageFlagsSelect             */
630     {NULL, 0}, /* kDataHUseTemporaryDataRefSelect            */
631     {NULL, 0}, /* kDataHGetTemporaryDataRefCapabilitiesSelect */
632     {NULL, 0}, /* kDataHRenameFileSelect                     */
633     {NULL, 0}, /* 0x4A */
634     {NULL, 0}, /* 0x4B */
635     {NULL, 0}, /* 0x4C */
636     {NULL, 0}, /* 0x4D */
637     {myDataHGetAvailableFileSize64, kPascalStackBased
638             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
639             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
640             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(wide*)))
641 }, /* kDataHGetAvailableFileSize64Select         */
642     {NULL, 0}, /* kDataHGetDataAvailability64Select          */
643 };
644
645 static const struct { LPVOID proc; ProcInfoType type;} componentFunctions_2[] =
646 {
647     {myDataHPlaybackHints, kPascalStackBased
648             | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
649             | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DataHandler)))
650             | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
651             | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned long)))
652             | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(unsigned long)))
653             | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
654 }, /* kDataHPlaybackHintsSelect     0x103 */
655     {NULL, 0}, /* kDataHPlaybackHints64Select   0x10E */
656     {NULL, 0}, /* kDataHGetDataRateSelect       0x110 */
657     {NULL, 0}, /* kDataHSetTimeHintsSelect      0x111 */
658 };
659
660 /* Component Functions */
661
662 static pascal ComponentResult myComponentOpen(ComponentInstance ci, ComponentInstance self)
663 {
664     DHData myData;
665     Handle storage;
666
667     ZeroMemory(&myData,sizeof(DHData));
668     PtrToHand( &myData, &storage, sizeof(DHData));
669     SetComponentInstanceStorage(self,storage);
670
671     return noErr;
672 }
673
674 static pascal ComponentResult myComponentClose(ComponentInstance ci, ComponentInstance self)
675 {
676     Handle storage = GetComponentInstanceStorage(self);
677     DHData *data;
678     if (storage)
679     {
680         data = (DHData*)*storage;
681         if (data && data->dataRef.pReader != NULL)
682             IAsyncReader_Release(data->dataRef.pReader);
683         DisposeHandle(storage);
684         SetComponentInstanceStorage(self,NULL);
685     }
686     return noErr;
687 }
688
689 static pascal ComponentResult myComponentCanDo(ComponentInstance ci, SInt16 ftnNumber)
690 {
691     TRACE("test 0x%x\n",ftnNumber);
692     if (ftnNumber <= kComponentOpenSelect && ftnNumber >= kComponentCanDoSelect)
693         return TRUE;
694     if (ftnNumber == kDataHPlaybackHintsSelect)
695         return TRUE;
696     if (ftnNumber > kDataHGetDataAvailability64Select)
697         return FALSE;
698     TRACE("impl? %i\n",(componentFunctions[ftnNumber].proc != NULL));
699     return (componentFunctions[ftnNumber].proc != NULL);
700 }
701
702 /* Main Proc */
703
704 static ComponentResult callOurFunction(LPVOID proc, ProcInfoType type, ComponentParameters * cp)
705 {
706     ComponentRoutineUPP myUUP;
707     ComponentResult result;
708
709     myUUP = NewComponentFunctionUPP(proc, type);
710     result = CallComponentFunction(cp, myUUP);
711     DisposeComponentFunctionUPP(myUUP);
712     return result;
713 }
714
715 static pascal ComponentResult myComponentRoutineProc ( ComponentParameters * cp,
716                                          Handle componentStorage)
717 {
718     switch (cp->what)
719     {
720         case kComponentOpenSelect:
721             return callOurFunction(myComponentOpen, uppCallComponentOpenProcInfo,  cp);
722         case kComponentCloseSelect:
723             return callOurFunction(myComponentClose, uppCallComponentOpenProcInfo,  cp);
724         case kComponentCanDoSelect:
725             return callOurFunction(myComponentCanDo, uppCallComponentCanDoProcInfo,  cp);
726         case kDataHPlaybackHintsSelect:
727             return callOurFunction(componentFunctions_2[0].proc, componentFunctions_2[0].type, cp);
728     }
729
730     if (cp->what > 0 && cp->what <=kDataHGetDataAvailability64Select && componentFunctions[cp->what].proc)
731         return callOurFunction(componentFunctions[cp->what].proc, componentFunctions[cp->what].type, cp);
732
733     FIXME("unhandled select 0x%x\n",cp->what);
734     return badComponentSelector;
735 }