-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing3.html
executable file
·2419 lines (2019 loc) · 74.5 KB
/
listing3.html
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>SampleDS - /Source/SampleDS.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/AppleApplications/index.html">Apple Applications</a> > <a href="../../samplecode/AppleApplications/idxImageCapture-date.html">Image Capture</a> > <A HREF="javascript:location.replace('index.html');">SampleDS</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">SampleDS</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/Source/SampleDS.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Resources/carb.r</option>
<option value="listing2.html">/Resources/vers.r</option>
<option value="listing3.html">/Source/SampleDS.c</option>
<option value="listing4.html">/Source/SampleDS.h</option>
<option value="listing5.html">/TWAIN Helper Glue/TWAcquire.c</option>
<option value="listing6.html">/TWAIN Helper Glue/TWAcquire.h</option>
<option value="listing7.html">/TWAIN Helper Glue/TWDefs.h</option>
<option value="listing8.html">/TWAIN Helper Glue/TWGlue.c</option>
<option value="listing9.html">/TWAIN Helper Glue/TWGlue.h</option>
<option value="listing10.html">/TWAIN Helper Glue/TWSystem.c</option>
<option value="listing11.html">/TWAIN Helper Glue/TWSystem.h</option>
<option value="listing12.html">/TWAIN Helper Glue/TWUtilities.c</option>
<option value="listing13.html">/TWAIN Helper Glue/TWUtilities.h</option></select>
</p>
</form>
<p><strong><a href="SampleDS.zip">Download Sample</a></strong> (“SampleDS.zip”, 156.1K)<BR>
<strong><a href="SampleDS.dmg">Download Sample</a></strong> (“SampleDS.dmg”, 226.4K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: SampleDS.c
Description: Sample Data Source (DS)
Author: Image Capture Engineering
Copyright: © Copyright 2003 Apple Computer, Inc. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under Apple's
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
<1> 6/17/03 WN first file
*/
// ===========================================================================
//
// Example code for TWAIN Data Source.
#include <TWAIN/TWAIN.h>
#include "TWDefs.h"
#include "TWSystem.h"
#include "TWUtilities.h"
#include <QuickTime/QuickTime.h> // for GraphicsImporter
#include <string.h>
#include "SampleDS.h"
#define DEBUGGING 1
static TW_IDENTITY Identity;
static TW_INT16 DSIsAlive=FALSE;
static TW_INT16 gCurrentState=STATE_DSLOADED;
static TW_INT16 gConditionCode = TWCC_SUCCESS;
static TW_STR32 Manufacturer = "\pApple";
static TW_STR32 ProductFamily = "\pApple sample ds";
static TW_STR32 ProductName = "\pSample DS";
static TW_STR32 VersionInfo = "\p1.23";
static PicHandle hPicture=NULL;
static TW_INT16 gTransferReady = FALSE;
static TW_INT16 TWMessage=-1;
static TW_IMAGEINFO ImageInfo;
static TW_IMAGELAYOUT ImageLayout;
static TW_SETUPFILEXFER GlobalSetupFile;
static TW_STR32 FileString="\pClasp.tmp";
static TW_INT16 PixelTypes[]={TWPT_BW,TWPT_GRAY,TWPT_RGB,TWPT_PALETTE};
static TW_INT16 NumPixelTypes=4;
static TW_INT16 CurPixelType=TWPT_RGB;
static TW_INT16 DefPixelType=TWPT_RGB;
static TW_INT32 XResMinValue=50;
static TW_INT32 XResMaxValue=300;
static TW_INT32 XResStepSize=10;
static TW_INT32 XResDefaultValue=300;
static TW_INT32 XResCurrentValue=300;
static TW_INT32 YResNumItems=4;
static TW_INT32 YResCurrentIndex=3;
static TW_INT32 YResDefaultIndex=3;
static TW_FIX32 YResItemList[4]={{50,0},{75,0},{150,0},{300,0}};
static FSSpec gFileSpec = {0, 0, "\p"};
static bool gInfoLoaded = false;
static GWorldPtr gGWorld = nil;
static UInt32 gRowsTransfered = 0;
static TW_INT16 gTransferMode = TWSX_NATIVE;
static PicHandle gPicture = NULL;
static ControlRef gScanButton;
static ControlRef gCancelButton;
static DialogRef gDialog;
static Boolean gDebugInitialized = false;
static CFDictionaryRef gDebugDictionary = NULL;
#define kScanButton 1
#define kCancelButton 2
#define kReturn 0x0D
#define kEnter 0x03
// --------------------------------------------------------------------------------
#pragma mark -
#pragma mark ---------------------- Debugging
// ---------------------------------------------------------------------------
// * DS_LogText
// ---------------------------------------------------------------------------
// Log a string
void DS_LogText ( const char* pFormat, ... )
{
#if ICA_DEBUG
va_list pArg;
char outString[1024];
int len;
va_start(pArg, pFormat);
len = vsnprintf(outString, 1020, pFormat, pArg);
va_end( pArg );
printf(outString);
#endif
}
// ---------------------------------------------------------------------------
// * DS_LogValue
// ---------------------------------------------------------------------------
//
void DS_LogValue (char* label,
char* labelKey,
char* format,
UInt32 value)
{
char key[64];
Boolean found = false;
sprintf(key, format, value);
if (gDebugDictionary)
{
CFStringRef keyRef;
CFStringRef strRef;
CFDictionaryRef dictRef = NULL;
// find the sub-dictionary
keyRef = CFStringCreateWithCString(NULL, labelKey, 0);
if (keyRef)
{
dictRef = (CFDictionaryRef)CFDictionaryGetValue(gDebugDictionary, keyRef);
CFRelease(keyRef);
}
if (dictRef)
{
// find the value
keyRef = CFStringCreateWithCString(NULL, key, 0);
if (keyRef)
{
strRef = (CFStringRef)CFDictionaryGetValue(dictRef, keyRef);
if (strRef)
{
DS_LogText ( "%s [%s] - %s\n", label, key, CFStringGetCStringPtr(strRef,0));
found = true;
}
CFRelease(keyRef);
}
}
}
if (!found)
DS_LogText ( "%s [%s]\n", label, key );
}
// ---------------------------------------------------------------------------
// * DS_LogResult
// ---------------------------------------------------------------------------
// Log errors
void DS_LogResult ( UInt16 result,
UInt16 condition )
{
if ( result != TWRC_SUCCESS
&& result != TWRC_NOTDSEVENT
&& result != TWRC_DSEVENT )
{
DS_LogValue(" result : ", "Result", "%d", result);
if ( condition != TWCC_SUCCESS )
{
DS_LogValue(" Condition : ", "Condition", "%d", condition);
}
DS_LogText ( "\n" );
}
}
// ---------------------------------------------------------------------------
// * DS_LogMessage
// ---------------------------------------------------------------------------
void DS_LogMessage(UInt16 message)
{
DS_LogValue(" message : ", "Messages", "0x%04x", message);
}
// ---------------------------------------------------------------------------
// * DS_LogTriplet
// ---------------------------------------------------------------------------
// Log the triplet passed to DS_Entry().
void DS_LogTriplet ( UInt32 group,
UInt16 attribute,
UInt16 message,
Ptr data )
{
// don't log the event loop triplets
if ( message != MSG_PROCESSEVENT )
{
DS_LogValue(" group : ", "DataGroup", "%d", group);
DS_LogValue(" attribute : ", "Attribute", "0x%04x", attribute);
DS_LogValue(" message : ", "Messages", "0x%04x", message);
if ( attribute == DAT_CAPABILITY )
DS_LogValue("capability : ", "Capabilities", "0x%04x", ((pTW_CAPABILITY) data)->Cap );
DS_LogText ( "\n" );
}
}
// ---------------------------------------------------------------------------
// * DS_DebugInitialize
// ---------------------------------------------------------------------------
//
void DS_DebugInitialize()
{
// write a header of sorts
// Date format: YYYY '-' MM '-' DD ' ' hh ':' mm ':' ss.fff
CFTimeZoneRef tz = CFTimeZoneCopySystem(); // specifically choose system time zone for logs
CFGregorianDate gdate = CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), tz);
CFRelease(tz);
gdate.second = gdate.second + 0.0005;
DS_LogText ( "*****************************************************************\n");
DS_LogText ( "TWAIN mach-o DS Debug Log - %02d:%02d:%06.3f \n", gdate.hour, gdate.minute, gdate.second);
DS_LogText ( "*****************************************************************\n");
// load the gDebugDictionary...
CFURLRef fileURL = NULL;
Boolean status;
CFDataRef resourceData = NULL;
SInt32 errorCode;
CFStringRef errorString = NULL;
CFBundleRef bundle;
bundle = CFBundleGetBundleWithIdentifier ( CFSTR( "com.apple.sampleds" ) );
fileURL = CFBundleCopyResourceURL(bundle, CFSTR("DSDebug"), CFSTR("plist"), NULL);
if (fileURL)
{
status = CFURLCreateDataAndPropertiesFromResource(NULL, fileURL, &resourceData, NULL, NULL, &errorCode);
if (status && resourceData)
{
gDebugDictionary = (CFDictionaryRef)CFPropertyListCreateFromXMLData( NULL, resourceData, kCFPropertyListImmutable, &errorString);
CFRelease(resourceData);
}
CFRelease(fileURL);
}
}
// ---------------------------------------------------------------------------
// * DS_DebugTerminate
// ---------------------------------------------------------------------------
//
void DS_DebugTerminate()
{
DS_LogText ( "--------------------------------------------------------------------------------\n" );
}
#pragma mark -
#pragma mark ---------------------- DS_Entry
// ---------------------------------------------------------------------------
// DS_Entry
// ---------------------------------------------------------------------------
// Entry point for Data Source.
TW_UINT16 DS_Entry ( pTW_IDENTITY pSource,
TW_UINT32 DG,
TW_UINT16 Dat,
TW_UINT16 Msg,
TW_MEMREF pData )
{
TW_INT16 result = TWRC_SUCCESS;
if ( !gDebugInitialized )
{
DS_DebugInitialize();
gDebugInitialized = true;
}
DS_LogTriplet ( DG, Dat, Msg, pData );
if (DSIsAlive == FALSE) /* initialize on first call */
{
Identity.Id =1;
Identity.Version.MajorNum =1;
Identity.Version.MinorNum =9;
Identity.Version.Language =1; /* jjg fill in later */
Identity.Version.Country =01;
pstrcopy((pTW_UINT8)Identity.Version.Info,(pTW_UINT8)VersionInfo);
Identity.ProtocolMajor =1;
Identity.ProtocolMinor =9;
Identity.SupportedGroups =DG_CONTROL|DG_IMAGE;
pstrcopy((pTW_UINT8)Identity.Manufacturer,(pTW_UINT8)Manufacturer);
pstrcopy((pTW_UINT8)Identity.ProductFamily,(pTW_UINT8)ProductFamily);
pstrcopy((pTW_UINT8)Identity.ProductName,(pTW_UINT8)ProductName);
GlobalSetupFile.Format =TWFF_TIFF;
GlobalSetupFile.VRefNum =0;
pstrcopy((pTW_UINT8)GlobalSetupFile.FileName,(pTW_UINT8)FileString);
GetDefaultImageLayout(&ImageLayout);
// init QuickTime
EnterMovies();
DSIsAlive=TRUE;
}
switch (DG)
{
case DG_CONTROL:
result = DS_Control(pSource,Dat,Msg,pData);
break;
case DG_IMAGE:
result = DS_Image(pSource,Dat,Msg,pData);
break;
case DG_AUDIO:
result = TWRC_SUCCESS;
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADPROTOCOL;
break;
}
if (result == TWRC_SUCCESS) /* clear the condition */
{
gConditionCode = TWCC_SUCCESS;
} else
{
DS_LogResult ( result, gConditionCode );
}
return(result);
}
#pragma mark -
#pragma mark ---------------------- Control Data Group
// ---------------------------------------------------------------------------
// DS_Control
// ---------------------------------------------------------------------------
// Process Data Argument types for the DG_CONTROL Data Group.
TW_INT16 DS_Control(pTW_IDENTITY pSource, TW_UINT16 Dat, TW_UINT16 Msg, TW_MEMREF pData)
{
TW_INT16 result = TWRC_SUCCESS;
switch (Dat)
{
case DAT_STATUS:
result = DS_Control_Status(pSource,Msg,(pTW_STATUS)pData);
break;
case DAT_IDENTITY:
result = DS_Control_Identity(pSource,Msg,(pTW_IDENTITY)pData);
break;
case DAT_EVENT:
result = DS_Control_Event(pSource,Msg,(pTW_EVENT)pData);
break;
case DAT_CAPABILITY:
result = DS_Control_Capability(pSource,Msg,(pTW_CAPABILITY)pData);
break;
case DAT_PENDINGXFERS:
result = DS_Control_PendingXfers(pSource,Msg,(pTW_UINT16)pData);
break;
case DAT_SETUPMEMXFER:
result = DS_Control_SetupMemXfer(pSource,Msg,(pTW_SETUPMEMXFER)pData);
break;
/*
case DAT_SETUPFILEXFER:
result = DS_Control_SetupFileXfer(pSource,Msg,(pTW_SETUPFILEXFER)pData);
break;
*/
case DAT_USERINTERFACE:
result = DS_Control_UserInterface(pSource,Msg,(pTW_USERINTERFACE)pData);
break;
case DAT_XFERGROUP:
result = DS_Control_XferGroup(pSource,Msg,(pTW_UINT16)pData);
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADPROTOCOL;
break;
}
return(result);
}
// ---------------------------------------------------------------------------
// DS_Control_Status
// ---------------------------------------------------------------------------
//
TW_INT16 DS_Control_Status ( pTW_IDENTITY pSource, TW_UINT16 Msg, pTW_STATUS pStatus )
{
TW_INT16 result = TWRC_SUCCESS;
switch (Msg)
{
case MSG_GET:
pStatus->ConditionCode = gConditionCode;
pStatus->Reserved=0;
gConditionCode = TWCC_SUCCESS;
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADPROTOCOL;
break;
}
return(result);
}
// ---------------------------------------------------------------------------
// DS_Control_Identity
// ---------------------------------------------------------------------------
//
TW_INT16 DS_Control_Identity ( pTW_IDENTITY pSource, TW_UINT16 Msg, pTW_IDENTITY pIdentity)
{
TW_INT16 result = TWRC_SUCCESS;
switch (Msg)
{
case MSG_GET: /* get the DS's identity */
if (pIdentity!=NULL)
*pIdentity=Identity;
break;
case MSG_OPENDS: /* open the Data source for transfers */
if (gCurrentState==STATE_DSLOADED)
{
if (pIdentity!=NULL) *pIdentity=Identity;
gCurrentState=STATE_DSOPEN;
} else
{
result = TWRC_FAILURE;
gConditionCode = TWCC_SEQERROR;
}
break;
case MSG_CLOSEDS: /* do any house cleaning needed before unload */
if (gCurrentState==STATE_DSOPEN)
{
gCurrentState=STATE_DSLOADED;
} else
{
result = TWRC_FAILURE;
gConditionCode = TWCC_SEQERROR;
}
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADPROTOCOL;
break;
}
return(result);
}
// ---------------------------------------------------------------------------
// DS_Control_Event
// ---------------------------------------------------------------------------
//
TW_INT16 DS_Control_Event ( pTW_IDENTITY pSource, TW_UINT16 Msg, pTW_EVENT pEvent )
{
TW_INT16 result = TWRC_NOTDSEVENT;
pEvent->TWMessage=MSG_NULL;
return result;
switch (Msg)
{
case MSG_PROCESSEVENT: /* Process an event record */
if ((gCurrentState>=STATE_DSENABLED)&&(gCurrentState<=STATE_XFERREADY))
{
WindowRef windowRef;
ControlRef controlRef;
EventRecord * event;
int partCode;
int controlPartCode;
if (pEvent && pEvent->pEvent)
{
event = (EventRecord *)pEvent->pEvent;
switch (event->what)
{
case mouseDown:
DS_LogText("event->what = mouseDown (%08X)\n", event->what);
partCode = FindWindow(event->where, &windowRef);
switch (partCode)
{
case inMenuBar:
break;
case inContent:
SetPortWindowPort ( windowRef );
GlobalToLocal(&event->where);
controlPartCode = FindControl(event->where, windowRef, &controlRef);
switch (controlPartCode)
{
case kControlButtonPart:
if (TrackControl(controlRef, event->where, nil))
{
if (controlRef == gCancelButton)
{
DS_LogText(" cancel button pressed\n");
TWMessage = MSG_CLOSEDSREQ;
} else if (controlRef == gScanButton)
{
DS_LogText(" scan button pressed\n");
gTransferReady = TRUE;
TWMessage = MSG_XFERREADY;
gCurrentState = STATE_XFERREADY;
DS_LogText(" gTransferReady = TRUE\n");
DS_LogText(" TWMessage = MSG_XFERREADY\n");
DS_LogText(" gCurrentState = STATE_XFERREADY\n");
}
}
break;
default:
DS_LogText(" controlPartCode = %d\n", controlPartCode);
break;
}
break;
case inGoAway:
break;
default:
break;
}
break;
case mouseUp:
DS_LogText("event->what = mouseUp (%08X)\n", event->what);
break;
case keyDown:
DS_LogText("event->what = keyDown (%08X)\n", event->what);
break;
case keyUp:
DS_LogText("event->what = keyUp (%08X)\n", event->what);
break;
case autoKey:
DS_LogText("event->what = autoKey (%08X)\n", event->what);
break;
case updateEvt:
DS_LogText("event->what = updateEvt (%08X)\n", event->what);
windowRef = (WindowRef)event->message;
SetPortWindowPort ( windowRef );
BeginUpdate ( windowRef );
DrawControls(windowRef);
EndUpdate ( windowRef );
break;
case diskEvt:
DS_LogText("event->what = diskEvt (%08X)\n", event->what);
break;
case activateEvt:
DS_LogText("event->what = activateEvt (%08X)\n", event->what);
break;
case kHighLevelEvent:
DS_LogText("event->what = kHighLevelEvent (%08X)\n", event->what);
break;
default:
break;
}
}
if (TWMessage == -1)
{
pEvent->TWMessage=MSG_NULL;
} else
{
if (DEBUGGING)
{
switch (TWMessage)
{
case MSG_CLOSEDSREQ:
DS_LogText("DS_Control_Event: MSG_CLOSEDSREQ\n");
break;
case MSG_XFERREADY:
DS_LogText("DS_Control_Event: MSG_XFERREADY\n");
break;
}
}
pEvent->TWMessage=TWMessage;
TWMessage=-1;
}
} else
{
result = TWRC_FAILURE;
gConditionCode = TWCC_SEQERROR;
}
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADPROTOCOL;
break;
}
return(result);
}
// ---------------------------------------------------------------------------
// DS_Control_Capability
// ---------------------------------------------------------------------------
//
TW_INT16 DS_Control_Capability ( pTW_IDENTITY pSource, TW_UINT16 Msg, pTW_CAPABILITY pCapability)
{
TW_INT16 CurrentIndex;
TW_INT16 DefaultIndex;
TW_INT32 TempValue;
TW_INT16 ValueType;
TW_INT16 Count;
TW_INT16 result = TWRC_SUCCESS;
TW_UINT16 TempArray[16];
if ((Msg==MSG_SET)||(Msg==MSG_RESET))
{
if (gCurrentState!=STATE_DSOPEN)
{
result = TWRC_FAILURE;
gConditionCode = TWCC_SEQERROR;
return(result);
}
}
else
{
if (gCurrentState==STATE_DSLOADED)
{
result = TWRC_FAILURE;
gConditionCode = TWCC_SEQERROR;
return(result);
}
}
switch (Msg)
{
case MSG_GET: /* get the current and possible values for a capability */
switch (pCapability->Cap)
{
case CAP_XFERCOUNT:
if (gTransferReady == TRUE)
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)1);
else
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)0);
break;
case CAP_SUPPORTEDCAPS:
{
TW_UINT16 capList[] = {CAP_XFERCOUNT, ICAP_XFERMECH, ICAP_COMPRESSION,
ICAP_PIXELTYPE, ICAP_UNITS, ICAP_XRESOLUTION, ICAP_YRESOLUTION};
SetupArray(pCapability, TWTY_UINT16, 7, (TW_UINT8*) capList);
}
break;
case CAP_UICONTROLLABLE:
SetupOneValue(pCapability,TWTY_BOOL,(TW_INT32) true);
break;
case ICAP_PLANARCHUNKY:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWPC_CHUNKY);
break;
case ICAP_XFERMECH:
{
TW_UINT16 xferList[] = {TWSX_NATIVE, TWSX_MEMORY};
SetupEnumeration(pCapability, TWTY_UINT16, 2,
FindIndex(gTransferMode, xferList, 2),
FindIndex(TWSX_NATIVE, xferList, 2),
(pTW_UINT8) xferList);
}
break;
case ICAP_COMPRESSION:
SetupOneValue(pCapability, TWTY_UINT16, TWCP_NONE);
break;
case ICAP_PIXELTYPE:
SetupEnumeration(pCapability, TWTY_UINT16, NumPixelTypes,
FindIndex(CurPixelType, PixelTypes, NumPixelTypes),
FindIndex(TWPT_RGB, PixelTypes, NumPixelTypes),
(pTW_UINT8) PixelTypes);
break;
case ICAP_PIXELFLAVOR:
SetupOneValue(pCapability, TWTY_UINT16, TWPF_CHOCOLATE);
break;
case ICAP_UNITS:
SetupOneValue(pCapability, TWTY_UINT16, TWUN_PIXELS);
break;
case ICAP_PHYSICALHEIGHT:
case ICAP_PHYSICALWIDTH:
SetupOneValue(pCapability, TWTY_FIX32, 0);
break;
case ICAP_BITORDER:
SetupOneValue(pCapability, TWTY_UINT16, TWBO_MSBFIRST);
break;
case ICAP_XRESOLUTION: /* provided as an example of a range */
SetupRange(pCapability,TWTY_FIX32, XResMinValue, XResMaxValue,
XResStepSize,XResDefaultValue,XResCurrentValue);
break;
case ICAP_YRESOLUTION: /* provided as an example of an enumeration */
SetupEnumeration(pCapability, TWTY_FIX32, YResNumItems,
YResCurrentIndex,YResDefaultIndex,(TW_UINT8 *)YResItemList);
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADCAP;
break;
}
break;
case MSG_GETCURRENT:
switch (pCapability->Cap)
{
case CAP_XFERCOUNT: /* same as get */
if (gTransferReady == TRUE)
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)1);
else
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)0);
break;
case ICAP_PLANARCHUNKY: /* same as get */
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWPC_CHUNKY);
break;
case ICAP_XFERMECH:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32) gTransferMode);
break;
case ICAP_COMPRESSION: /* same as get */
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWCP_NONE);
break;
case ICAP_PIXELTYPE:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)CurPixelType);
break;
case ICAP_PIXELFLAVOR:
SetupOneValue(pCapability, TWTY_UINT16, (TW_INT32) TWPF_CHOCOLATE);
break;
case ICAP_UNITS: /* same as get */
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32) TWUN_PIXELS);
break;
case ICAP_PHYSICALHEIGHT:
case ICAP_PHYSICALWIDTH:
SetupOneValue(pCapability, TWTY_FIX32, (TW_INT32) 0);
break;
case ICAP_BITORDER:
SetupOneValue(pCapability, TWTY_UINT16, (TW_INT32) TWBO_MSBFIRST);
break;
case ICAP_XRESOLUTION: /* provided as an example of a range */
SetupOneValue(pCapability,TWTY_FIX32,XResCurrentValue);
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADCAP;
break;
}
break;
case MSG_GETDEFAULT: /* get the default value for a capability */
switch (pCapability->Cap)
{
case CAP_XFERCOUNT:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)0);
break;
case ICAP_PLANARCHUNKY:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWPC_CHUNKY);
break;
case ICAP_XFERMECH:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWSX_NATIVE);
break;
case ICAP_COMPRESSION:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWCP_NONE);
break;
case ICAP_PIXELTYPE:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWPT_RGB);
break;
case ICAP_PIXELFLAVOR:
SetupOneValue(pCapability, TWTY_UINT16, (TW_INT32) TWPF_CHOCOLATE);
break;
case ICAP_UNITS:
SetupOneValue(pCapability,TWTY_UINT16,(TW_INT32)TWUN_PIXELS);
break;
case ICAP_PHYSICALHEIGHT:
case ICAP_PHYSICALWIDTH:
SetupOneValue(pCapability, TWTY_FIX32, (TW_INT32) 0);
break;
case ICAP_BITORDER:
SetupOneValue(pCapability, TWTY_UINT16, (TW_INT32) TWBO_MSBFIRST);
break;
case ICAP_XRESOLUTION: /* provided as an example of a range */
SetupOneValue(pCapability,TWTY_FIX32,XResDefaultValue);
break;
case ICAP_YRESOLUTION: /* provided as an example of a enumeration */
TempValue=YResItemList[YResDefaultIndex].Whole;
SetupOneValue(pCapability,TWTY_FIX32,(TW_INT32)TempValue);
break;
default:
result = TWRC_FAILURE;
gConditionCode = TWCC_BADCAP;