-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWIA_SettingsForm.pas
715 lines (620 loc) · 24.4 KB
/
WIA_SettingsForm.pas
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
(******************************************************************************
* FreePascal \ Delphi WIA Implementation *
* *
* FILE: WIA_SettingsForm.pas *
* *
* VERSION: 0.0.2 *
* *
* DESCRIPTION: *
* WIA Property Settings for Device Dialog. *
* *
*******************************************************************************
* *
* (c) 2024 Massimo Magnano *
* *
* See changelog.txt for Change Log *
* *
*******************************************************************************)
unit WIA_SettingsForm;
{$H+}
//{$define UI_Tests}
interface
uses
DelphiCompatibility, Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
ExtCtrls, Buttons, ComCtrls, StdCtrls, Spin,
WIA, WIA_PaperSizes,
ImgList {$ifndef fpc}, ImageList, NumberBox{$endif};
const
//False to display then measurement in Inchs
WIASettings_Unit_cm: Boolean = True; //fucks inch
resourcestring
rsLandscape = 'Landscape';
rsPortrait = 'Portrait';
rsApplyChanges = 'Apply Changes to Item %s of %s';
rsFullsize = 'Full size';
rsCustomsize = 'Custom size';
rsAutosize = 'Auto size';
rsAutotype = 'Auto type';
rsExcCannotGetSourceItem = 'Cannot Get Source Item %d';
rsExcCannotGetCapabilities = 'Cannot Get Capabilities for Source Item %d';
rsErrorSelecting = 'Error Selecting Item %s of %s'#13#10'Try to Select another Source Item';
rsErrorSelectingInt = 'Error Selecting Item [%d] of %s'#13#10'%s'#13#10'Try to Select another Source Item';
type
TInitialItemValues = (initDefault, initParams, initCurrent);
{ TWIASettingsSource }
TInitDefaultValuesEvent = procedure (var ACap: TWIAParamsCapabilities) of object;
TWIASettingsSource = class(TForm)
btContrast0: TSpeedButton;
btContrastD: TSpeedButton;
btResolutionD: TSpeedButton;
btCancel: TBitBtn;
btPaperOrientation: TSpeedButton;
btRefreshUndo: TBitBtn;
btOk: TBitBtn;
btRefreshCurrent: TBitBtn;
btRefreshDefault: TBitBtn;
cbBitDepth: TComboBox;
cbPaperType: TComboBox;
cbDataType: TComboBox;
cbResolution: TComboBox;
cbBackFirst: TCheckBox;
cbUseNativeUI: TCheckBox;
edBrightness: TSpinEdit;
{$ifdef fpc}
edPaperH: TFloatSpinEdit;
edPaperW: TFloatSpinEdit;
{$else}
edPaperH: TNumberBox;
edPaperW: TNumberBox;
{$endif}
edResolution: TSpinEdit;
edContrast: TSpinEdit;
gbPaperAlign: TGroupBox;
gbPaperSize: TGroupBox;
gbFeeder: TGroupBox;
ImgListSource: TImageList;
imgAlign: TImage;
imgListAlign: TImageList;
imgList: TImageList;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
LabelPaperSize: TLabel;
lvSourceItems: TListView;
PageSourceTypes: TPageControl;
Panel1: TPanel;
panelCenter: TPanel;
panelButtons: TPanel;
btBrightness0: TSpeedButton;
btBrightnessD: TSpeedButton;
rbFrontBack: TRadioButton;
rbFrontOnly: TRadioButton;
rbBackOnly: TRadioButton;
tbSource_Scanner: TTabSheet;
trBrightness: TTrackBar;
trHAlign: TTrackBar;
trResolution: TTrackBar;
trContrast: TTrackBar;
trVAlign: TTrackBar;
procedure bt0Click(Sender: TObject);
procedure btDClick(Sender: TObject);
procedure btPaperOrientationClick(Sender: TObject);
procedure cbBackFirstClick(Sender: TObject);
procedure cbPaperTypeChange(Sender: TObject);
procedure cbUseNativeUIChange(Sender: TObject);
procedure edBrightnessChange(Sender: TObject);
procedure edContrastChange(Sender: TObject);
procedure edResolutionChange(Sender: TObject);
procedure lvSourceItemsSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
procedure trBrightnessChange(Sender: TObject);
procedure trContrastChange(Sender: TObject);
procedure trHAlignChange(Sender: TObject);
procedure trResolutionChange(Sender: TObject);
private
WIASource: TWIADevice;
WIAPaperMaxWidth,
WIAPaperMaxHeight,
WIASelectedItemIndex: Integer;
WIACaps: TArrayWIAParamsCapabilities;
WIAParams: TArrayWIAParams;
curCap: TWIAParamsCapabilities;
curParams: TWIAParams;
initItemValues: TInitialItemValues;
OnInitDefaultValues: TInitDefaultValuesEvent;
procedure SelectCurrentItem(AIndex: Integer);
procedure StoreCurrentItemParams;
public
class function Execute(AWIASource: TWIADevice;
var ASelectedItemIndex: Integer;
{ #todo -oMaxM : Possibly Filters for which Items Kinds to Show? How manage AParams without Indexes? }
AInitItemValues: TInitialItemValues;
var AParams: TArrayWIAParams;
AOnInitDefaultValues: TInitDefaultValuesEvent=nil): Boolean;
end;
var
WIASettingsSource: TWIASettingsSource=nil;
implementation
{$ifdef fpc}
{$R *.lfm}
{$else}
{$R *.dfm}
{$endif}
uses WiaDef;
{ TWIASettingsSource }
procedure TWIASettingsSource.trBrightnessChange(Sender: TObject);
begin
edBrightness.Value:=trBrightness.Position;
end;
procedure TWIASettingsSource.edBrightnessChange(Sender: TObject);
begin
trBrightness.Position:=edBrightness.Value;
end;
procedure TWIASettingsSource.cbUseNativeUIChange(Sender: TObject);
begin
PageSourceTypes.Enabled:= not(cbUseNativeUI.Checked);
end;
procedure TWIASettingsSource.bt0Click(Sender: TObject);
begin
Case (TSpeedButton(Sender).Tag) of
1: edBrightness.Value:= 0;
2: edContrast.Value:= 0;
end;
end;
procedure TWIASettingsSource.btDClick(Sender: TObject);
var
i: Integer;
begin
with curCap do
Case (TSpeedButton(Sender).Tag) of
1: edBrightness.Value:= BrightnessDefault;
2: edContrast.Value:= ContrastDefault;
3: begin
if ResolutionRange
then edResolution.Value:= ResolutionDefault
else begin
i:= cbResolution.Items.IndexOf(IntToStr(ResolutionDefault));
if (i > -1) then cbResolution.ItemIndex:= i;
end;
end;
end;
end;
procedure TWIASettingsSource.btPaperOrientationClick(Sender: TObject);
begin
if btPaperOrientation.Down
then begin btPaperOrientation.ImageIndex:= 1; btPaperOrientation.Hint:= rsLandscape; end
else begin btPaperOrientation.ImageIndex:= 0; btPaperOrientation.Hint:= rsPortrait; end;
end;
procedure TWIASettingsSource.cbBackFirstClick(Sender: TObject);
begin
if rbFrontBack.Enabled
then if cbBackFirst.Checked
then rbFrontBack.Checked:= True;
end;
procedure TWIASettingsSource.cbPaperTypeChange(Sender: TObject);
var
selPaperSize: TWIAPaperType;
begin
selPaperSize:= TWIAPaperType(PtrUInt(cbPaperType.Items.Objects[cbPaperType.ItemIndex]));
Case selPaperSize of
wptMAX, wptAUTO: begin
gbPaperAlign.Enabled:= False;
btPaperOrientation.Enabled:= False;
gbPaperSize.Visible:= True;
gbPaperSize.Enabled:= False;
edPaperW.Value:= edPaperW.MaxValue;
edPaperH.Value:= edPaperW.MaxValue;
end;
wptCUSTOM: begin
gbPaperAlign.Enabled:= True;
btPaperOrientation.Enabled:= True;
gbPaperSize.Visible:= True;
edPaperW.Visible:= True;
edPaperH.Visible:= True;
gbPaperSize.Enabled:= True;
edPaperW.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperW);
edPaperH.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperH);
end;
else begin
gbPaperAlign.Enabled:= True;
btPaperOrientation.Enabled:= True;
gbPaperSize.Visible:= False;
edPaperW.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperW);
edPaperH.Value:= THInchToSize(WIASettings_Unit_cm, WIAParams[WIASelectedItemIndex].PaperH);
end;
end;
end;
procedure TWIASettingsSource.edContrastChange(Sender: TObject);
begin
trContrast.Position:=edContrast.Value;
end;
procedure TWIASettingsSource.edResolutionChange(Sender: TObject);
begin
trResolution.Position:= edResolution.Value;
end;
procedure TWIASettingsSource.lvSourceItemsSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
if Selected and (Item.Index <> WIASelectedItemIndex) then
Case MessageDlg(Format(rsApplyChanges, [WIASource.Items[WIASelectedItemIndex]^.Name, WIASource.Name]),
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
mrYes: begin
StoreCurrentItemParams;
SelectCurrentItem(lvSourceItems.ItemIndex);
end;
mrNo: SelectCurrentItem(lvSourceItems.ItemIndex);
end;
end;
procedure TWIASettingsSource.trContrastChange(Sender: TObject);
begin
edContrast.Value:=trContrast.Position;
end;
procedure TWIASettingsSource.trHAlignChange(Sender: TObject);
begin
{$ifdef fpc}
imgAlign.ImageIndex:= (trVAlign.Position*3)+trHAlign.Position;
{$else}
imgListAlign.GetIcon((trVAlign.Position*3)+trHAlign.Position, imgAlign.Picture.Icon);
{$endif}
end;
procedure TWIASettingsSource.trResolutionChange(Sender: TObject);
begin
edResolution.Value:=trResolution.Position;
end;
procedure TWIASettingsSource.SelectCurrentItem(AIndex: Integer);
var
AParams: TWIAParams;
ACap: TWIAParamsCapabilities;
capRet: Boolean;
paperI: TWIAPaperType;
dataI: TWIADataType;
i, cbSelected: Integer;
curItem: PWIAItem;
begin
AParams:= WIAParams[AIndex];
ACap:= WIACaps[AIndex];
curItem:= WIASource.Items[AIndex];
if (curItem <> nil) then
with ACap do
begin
cbUseNativeUI.Checked:= AParams.NativeUI;
PageSourceTypes.Enabled:= not(cbUseNativeUI.Checked) and (curItem^.ItemCategory <> wicAUTO);
//Fill List of Papers
cbPaperType.Clear;
cbSelected :=0;
cbPaperType.Items.AddObject(rsFullsize, TObject(PtrUInt(wptMAX)));
for paperI in PaperTypeSet do
begin
Case paperI of
wptMAX:begin end;
wptCUSTOM: cbPaperType.Items.AddObject(rsCustomsize, TObject(PtrUInt(wptCUSTOM)));
wptAUTO: cbPaperType.Items.AddObject(rsAutosize, TObject(PtrUInt(wptAUTO)));
else begin
if WIASettings_Unit_cm
then cbPaperType.Items.AddObject(PaperSizesWIA[paperI].name+' ('+
THInchToCmStr(PaperSizesWIA[paperI].w)+' x '+
THInchToCmStr(PaperSizesWIA[paperI].h)+' cm)',
TObject(PtrUInt(paperI)))
else cbPaperType.Items.AddObject(PaperSizesWIA[paperI].name+' ('+
THInchToInchStr(PaperSizesWIA[paperI].w)+' x '+
THInchToInchStr(PaperSizesWIA[paperI].h)+' in)',
TObject(PtrUInt(paperI)))
end;
end;
if (paperI = AParams.PaperType) then cbSelected :=cbPaperType.Items.Count-1;
end;
cbPaperType.ItemIndex:=cbSelected;
//Set Landscape/Portrait Button
btPaperOrientation.Down:= (AParams.Rotation in [wrLandscape, wrRot270]);
if btPaperOrientation.Down
then begin btPaperOrientation.ImageIndex:= 1; btPaperOrientation.Hint:= rsLandscape; end
else begin btPaperOrientation.ImageIndex:= 0; btPaperOrientation.Hint:= rsPortrait; end;
//Paper Align
trHAlign.Position:= Integer(AParams.HAlign);
trVAlign.Position:= Integer(AParams.VAlign);
trHAlignChange(nil);
//Set Max,Current Values for Custom Paper Size
edPaperW.MaxValue:= THInchToSize(WIASettings_Unit_cm, PaperSizeMaxWidth);
edPaperH.MaxValue:= THInchToSize(WIASettings_Unit_cm, PaperSizeMaxHeight);
if (curItem^.ItemCategory = wicFEEDER) then
begin
{ #todo 5 -oMaxM : Must be tested in a Duplex Scanner }
gbFeeder.Visible:= True;
(*
if (wdhAdvanced_Duplex in DocHandlingSet)
then begin
//WIA 2 Item structure
rbFrontOnly.Enabled:= True;
rbFrontBack.Enabled:= True;
rbBackOnly.Enabled:= True;
cbBackFirst.Enabled:= True;
end
else begin
rbFrontOnly.Enabled:= (wdhFront_Only in DocHandlingSet);
rbFrontBack.Enabled:= (wdhDuplex in DocHandlingSet);
rbBackOnly.Enabled:= (wdhBack_Only in DocHandlingSet);
cbBackFirst.Enabled:= (wdhBack_First in DocHandlingSet);
end;
*)
rbFrontOnly.Enabled:= (wdhFront_Only in DocHandlingSet);
rbFrontBack.Enabled:= (wdhAdvanced_Duplex in DocHandlingSet) or (wdhDuplex in DocHandlingSet);
rbBackOnly.Enabled:= (wdhBack_Only in DocHandlingSet);
cbBackFirst.Enabled:= (wdhBack_First in DocHandlingSet);
{$ifdef UI_Tests}
rbFrontOnly.Enabled:= True;
rbFrontBack.Enabled:= True;
rbBackOnly.Enabled:= True;
cbBackFirst.Enabled:= True;
{$endif}
rbFrontOnly.Checked:= (wdhFront_Only in AParams.DocHandling);
rbFrontBack.Checked:= (wdhDuplex in AParams.DocHandling) or (wdhAdvanced_Duplex in AParams.DocHandling);
rbBackOnly.Enabled:= (wdhBack_Only in AParams.DocHandling);
cbBackFirst.Enabled:= (wdhBack_First in AParams.DocHandling);
end
else gbFeeder.Visible:= False;
(*
{ #todo 10 -oMaxM : In theory the selectable BitDepths depend on ImageType,
but WIA does not give me an error when I set for example
"Black and White" and BitDepht to 24 bit but I get a damaged Image.
Change automatically from the Form? }
//Fill List of Image Bit Depth
cbBitDepth.Clear;
cbSelected :=0;
for i:=0 to Length(BitDepthArray)-1 do
begin
if (BitDepthArray[i] = 0)
then cbBitDepth.Items.AddObject('Auto', nil)
else cbBitDepth.Items.AddObject(IntToStr(BitDepthArray[i])+' Bit', TObject(PtrUInt(BitDepthArray[i])));
case initItemValues of
initDefault: begin if (BitDepthArray[i] = BitDepthDefault) then cbSelected :=cbBitDepth.Items.Count-1; end;
initParams: begin if (BitDepthArray[i] = AParams.BitDepth) then cbSelected :=cbBitDepth.Items.Count-1; end;
initCurrent: begin if (BitDepthArray[i] = BitDepthCurrent) then cbSelected :=cbBitDepth.Items.Count-1; end;
end;
end;
cbBitDepth.ItemIndex:=cbSelected;
*)
//Fill List of Image Data Type
cbDataType.Clear;
cbSelected :=0;
for dataI in DataTypeSet do
Case dataI of
wdtAUTO: cbDataType.Items.AddObject(rsAutotype, TObject(PtrUInt(wdtAUTO)));
wdtDITHER, wdtCOLOR_DITHER: begin end;
else begin
cbDataType.Items.AddObject(WIADataTypeDescr[dataI], TObject(PtrUInt(dataI)));
if (dataI = AParams.DataType) then cbSelected :=cbDataType.Items.Count-1;
end;
end;
cbDataType.ItemIndex:=cbSelected;
{$ifdef UI_Tests}
ResolutionRange:= True;
{$endif}
if ResolutionRange
then begin
trResolution.Visible:= True; edResolution.Visible:= True;
cbResolution.Visible:= False;
//Set Resolution Range Limit
{$ifdef UI_Tests}
trResolution.Min:= ResolutionArray[0];
trResolution.Max:= ResolutionArray[Length(ResolutionArray)-1];
trResolution.LineSize:= 1;
edResolution.MinValue:= ResolutionArray[0];
edResolution.MaxValue:= ResolutionArray[Length(ResolutionArray)-1];
edResolution.Increment:= 1;
{$else}
trResolution.Min:= ResolutionArray[WIA_RANGE_MIN];
trResolution.Max:= ResolutionArray[WIA_RANGE_MAX];
trResolution.LineSize:= ResolutionArray[WIA_RANGE_STEP];
edResolution.MinValue:= ResolutionArray[WIA_RANGE_MIN];
edResolution.MaxValue:= ResolutionArray[WIA_RANGE_MAX];
edResolution.Increment:= ResolutionArray[WIA_RANGE_STEP];
{$endif}
trResolution.Position:= AParams.Resolution;
edResolution.Value:= AParams.Resolution;
end
else begin
trResolution.Visible:= False; edResolution.Visible:= False;
cbResolution.Visible:= True;
//Fill List of Resolution (Y Resolution=X Resolution)
cbResolution.Clear;
cbSelected :=0;
for i:=0 to Length(ResolutionArray)-1 do
begin
cbResolution.Items.AddObject(IntToStr(ResolutionArray[i]), TObject(PtrUInt(i)));
if (ResolutionArray[i] = AParams.Resolution) then cbSelected :=cbResolution.Items.Count-1;
end;
cbResolution.ItemIndex:=cbSelected;
end;
//Brightness
trBrightness.Min:= BrightnessMin;
trBrightness.Max:= BrightnessMax;
trBrightness.LineSize:= BrightnessStep;
trBrightness.Position:= AParams.Brightness;
edBrightness.MinValue:= BrightnessMin;
edBrightness.MaxValue:= BrightnessMax;
edBrightness.Increment:= BrightnessStep;
edBrightness.Value:= trBrightness.Position;
//Contrast
trContrast.Min:= ContrastMin;
trContrast.Max:= ContrastMax;
trContrast.LineSize:= ContrastStep;
trContrast.Position:= AParams.Contrast;
edContrast.MinValue:= ContrastMin;
edContrast.MaxValue:= ContrastMax;
edContrast.Increment:= ContrastStep;
edContrast.Value:= trContrast.Position;
end;
curParams:= AParams;
curCap:= ACap;
WIASelectedItemIndex:= AIndex;
cbPaperTypeChange(nil);
end;
procedure TWIASettingsSource.StoreCurrentItemParams;
var
curItem: PWIAItem;
begin
curItem:= WIASource.Items[WIASelectedItemIndex];
if (curItem <> nil) then
with curParams do
begin
NativeUI:= cbUseNativeUI.Checked;
if not(NativeUI) then
begin
if (cbPaperType.ItemIndex>-1)
then PaperType:= TWIAPaperType(PtrUInt(cbPaperType.Items.Objects[cbPaperType.ItemIndex]));
if (PaperType = wptCUSTOM) then
begin
PaperW:= SizeToTHInch(WIASettings_Unit_cm, edPaperW.Value);
PaperH:= SizeToTHInch(WIASettings_Unit_cm, edPaperH.Value);
end;
if btPaperOrientation.Down
then Rotation:= wrLandscape
else Rotation:= wrPortrait;
HAlign:= TWIAAlignHorizontal(trHAlign.Position);
VAlign:= TWIAAlignVertical(trVAlign.Position);
if (curItem^.ItemCategory = wicFEEDER) then
begin
{ #todo 5 -oMaxM : Must be tested in a Duplex Scanner }
DocHandling:= [];
if rbFrontOnly.Checked
then DocHandling:= DocHandling+[wdhFront_Only]
else
if rbFrontBack.Checked
then begin
(*//if is A WIA2 structure add wdhAdvanced_Duplex so TWIADevice.Download understand how to work
if (wdhAdvanced_Duplex in WIACaps[WIASelectedItemIndex].DocHandlingSet)
then DocHandling:= DocHandling+[wdhAdvanced_Duplex]
else*) DocHandling:= DocHandling+[wdhDuplex];
if cbBackFirst.Checked then DocHandling:= DocHandling+[wdhBack_First];
end
else
if rbBackOnly.Checked
then DocHandling:= DocHandling+[wdhBack_Only];
end;
(*
if (cbBitDepth.ItemIndex>-1)
then BitDepth:=PtrUInt(cbBitDepth.Items.Objects[cbBitDepth.ItemIndex]);
*)
if (cbDataType.ItemIndex>-1)
then DataType:=TWIADataType(PtrUInt(cbDataType.Items.Objects[cbDataType.ItemIndex]));
if WIACaps[WIASelectedItemIndex].ResolutionRange
then Resolution:= edResolution.Value
else if (cbResolution.ItemIndex > -1)
then Resolution:= curCap.ResolutionArray[PtrUInt(cbResolution.Items.Objects[cbResolution.ItemIndex])];
Contrast:=edContrast.Value;
Brightness:=edBrightness.Value;
end;
end;
WIAParams[WIASelectedItemIndex]:= curParams;
end;
class function TWIASettingsSource.Execute(AWIASource: TWIADevice; var ASelectedItemIndex: Integer;
AInitItemValues: TInitialItemValues; var AParams: TArrayWIAParams;
AOnInitDefaultValues: TInitDefaultValuesEvent): Boolean;
var
i,
itemCount,
lenAParams: Integer;
curListItem: TListItem;
curItem: PWIAItem;
begin
Result:= False;
if (AWIASource = nil) then exit;
if (WIASettingsSource=nil)
then WIASettingsSource :=TWIASettingsSource.Create(nil);
if (WIASettingsSource <> nil) then
with WIASettingsSource do
try
WIASource:= AWIASource;
itemCount:= WIASource.ItemCount;
initItemValues:= AInitItemValues;
OnInitDefaultValues:= AOnInitDefaultValues;
//Do A Copy of Params Array so if the user cancels the Dialog we don't modify the starting array
WIAParams:= Copy(AParams);
//If WiaSource Item Count is greater then our Array enlarge it
lenAParams:= Length(AParams);
if (lenAParams < itemCount)
then SetLength(WIAParams, itemCount);
SetLength(WiaCaps, itemCount);
//Get Capabilities and Fill ListView of Source Items
lvSourceItems.Clear;
for i:=0 to itemCount-1 do
begin
//Get Item[i] Default Values
WIASource.SelectedItemIndex:= i;
curItem:= WIASource.Items[i];
if (curItem = nil)
then raise Exception.Create(Format(rsExcCannotGetSourceItem, [i]));
if not(WIASource.GetParamsCapabilities(WiaCaps[i]))
then raise Exception.Create(Format(rsExcCannotGetCapabilities, [i]));
Case initItemValues of
initDefault: if (curItem^.ItemCategory = wicFEEDER)
then WIAParams[i]:= WIACopyDefaultValues(WiaCaps[i], waHCenter)
else WIAParams[i]:= WIACopyDefaultValues(WiaCaps[i]);
initParams : if (i >= lenAParams) then //if is a new Item then Assign Default Values
begin
if (curItem^.ItemCategory = wicFEEDER)
then WIAParams[i]:= WIACopyDefaultValues(WiaCaps[i], waHCenter)
else WIAParams[i]:= WIACopyDefaultValues(WiaCaps[i]);
end;
initCurrent: if (curItem^.ItemCategory = wicFEEDER)
then WIAParams[i]:= WIACopyCurrentValues(WiaCaps[i], waHCenter)
else WIAParams[i]:= WIACopyCurrentValues(WiaCaps[i]);
end;
curListItem:= lvSourceItems.Items.Add;
curListItem.Caption :=WIASource.Items[i]^.Name;
curListItem.Data:= Pointer(i);
Case curItem^.ItemCategory of
wicFLATBED: curListItem.ImageIndex:= 1;
wicFEEDER,
wicFEEDER_FRONT,
wicFEEDER_BACK: curListItem.ImageIndex:= 2;
wicFILM: curListItem.ImageIndex:= 3;
wicROOT,
wicFOLDER: curListItem.ImageIndex:= 5;
wicBARCODE_READER: curListItem.ImageIndex:= 6;
else curListItem.ImageIndex:= 0;
end;
end;
try
//Select the Initial Item to ASelectedItemIndex
if (ASelectedItemIndex < 0)
then WIASelectedItemIndex:= 0
else WIASelectedItemIndex:= ASelectedItemIndex;
try
WIASource.SelectedItemIndex:= WIASelectedItemIndex;
except
WIASource.SelectedItemIndex:= 0;
end;
WIASelectedItemIndex:= WIASource.SelectedItemIndex;
PageSourceTypes.Enabled:= (WIASource.SelectedItemIntf <> nil);
if (PageSourceTypes.Enabled)
then SelectCurrentItem(WIASelectedItemIndex)
else MessageDlg(Format(rsErrorSelecting, [WIASource.Items[WIASelectedItemIndex]^.Name, WIASource.Name]),
mtError, [mbOk], 0);
except
on E: Exception do
MessageDlg(Format(rsErrorSelectingInt, [WIASelectedItemIndex, WIASource.Name, E.Message]),
mtError, [mbOk], 0);
end;
//cbSourceItem.ItemIndex:= WIASelectedItemIndex;
lvSourceItems.ItemIndex:= WIASelectedItemIndex;
SelectCurrentItem(WIASelectedItemIndex);
Result := (ShowModal=mrOk);
if Result then
begin
ASelectedItemIndex:= WIASelectedItemIndex;
StoreCurrentItemParams;
//Do A Copy of WIAParams to AParams Array and stretch it if needed
if (Length(AParams) < Length(WIAParams)) then SetLength(AParams, Length(WIAParams));
//Move(WIAParams, AParams, Length(AParams));
//AParams:= Copy(WIAParams);
for i:=0 to Length(AParams)-1 do AParams[i]:= WIAParams[i];
end;
finally
WIAParams:= nil;
WIACaps:= nil;
WIASettingsSource.Free; WIASettingsSource:= nil;
end;
end;
end.