Documentation updates.
[wine] / dlls / twain / capability.c
1 /*
2  * Copyright 2000 Corel Corporation
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "winbase.h"
20 #include "twain.h"
21 #include "twain_i.h"
22 #include "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(twain);
25
26 TW_UINT16 TWAIN_SaneCapability (activeDS *pSource, pTW_CAPABILITY pCapability,
27                                 TW_UINT16 action)
28 {
29     TW_UINT16 twCC = TWCC_SUCCESS;
30
31     TRACE("capability=%d action=%d\n", pCapability->Cap, action);
32
33     switch (pCapability->Cap)
34     {
35         case CAP_DEVICEEVENT:
36         case CAP_ALARMS:
37         case CAP_ALARMVOLUME:
38         case ACAP_AUDIOFILEFORMAT:
39         case ACAP_XFERMECH:
40         case ICAP_AUTOMATICBORDERDETECTION:
41         case ICAP_AUTOMATICDESKEW:
42         case ICAP_AUTODISCARDBLANKPAGES:
43         case ICAP_AUTOMATICROTATE:
44         case ICAP_FLIPROTATION:
45         case CAP_AUTOMATICCAPTURE:
46         case CAP_TIMEBEFOREFIRSTCAPTURE:
47         case CAP_TIMEBETWEENCAPTURES:
48         case CAP_AUTOSCAN:
49         case CAP_CLEARBUFFERS:
50         case CAP_MAXBATCHBUFFERS:
51         case ICAP_BARCODEDETECTIONENABLED:
52         case ICAP_SUPPORTEDBARCODETYPES:
53         case ICAP_BARCODEMAXSEARCHPRIORITIES:
54         case ICAP_BARCODESEARCHPRIORITIES:
55         case ICAP_BARCODESEARCHMODE:
56         case ICAP_BARCODEMAXRETRIES:
57         case ICAP_BARCODETIMEOUT:
58         case CAP_EXTENDEDCAPS:
59         case CAP_SUPPORTEDCAPS:
60         case ICAP_FILTER:
61         case ICAP_GAMMA:
62         case ICAP_PLANARCHUNKY:
63         case ICAP_BITORDERCODES:
64         case ICAP_CCITTKFACTOR:
65         case ICAP_COMPRESSION:
66         case ICAP_JPEGPIXELTYPE:
67         /*case ICAP_JPEGQUALITY:*/
68         case ICAP_PIXELFLAVORCODES:
69         case ICAP_TIMEFILL:
70         case CAP_DEVICEONLINE:
71         case CAP_DEVICETIMEDATE:
72         case CAP_SERIALNUMBER:
73         case ICAP_EXPOSURETIME:
74         case ICAP_FLASHUSED2:
75         case ICAP_IMAGEFILTER:
76         case ICAP_LAMPSTATE:
77         case ICAP_LIGHTPATH:
78         case ICAP_NOISEFILTER:
79         case ICAP_OVERSCAN:
80         case ICAP_PHYSICALHEIGHT:
81         case ICAP_PHYSICALWIDTH:
82         case ICAP_UNITS:
83         case ICAP_ZOOMFACTOR:
84         case CAP_PRINTER:
85         case CAP_PRINTERENABLED:
86         case CAP_PRINTERINDEX:
87         case CAP_PRINTERMODE:
88         case CAP_PRINTERSTRING:
89         case CAP_PRINTERSUFFIX:
90         case CAP_AUTHOR:
91         case CAP_CAPTION:
92         case CAP_TIMEDATE:
93         case ICAP_AUTOBRIGHT:
94         case ICAP_BRIGHTNESS:
95         case ICAP_CONTRAST:
96         case ICAP_HIGHLIGHT:
97         case ICAP_ORIENTATION:
98         case ICAP_ROTATION:
99         case ICAP_SHADOW:
100         case ICAP_XSCALING:
101         case ICAP_YSCALING:
102         case ICAP_BITDEPTH:
103         case ICAP_BITDEPTHREDUCTION:
104         case ICAP_BITORDER:
105         case ICAP_CUSTHALFTONE:
106         case ICAP_HALFTONES:
107         case ICAP_PIXELFLAVOR:
108         case ICAP_PIXELTYPE:
109         case ICAP_THRESHOLD:
110         case CAP_LANGUAGE:
111         case ICAP_FRAMES:
112         case ICAP_MAXFRAMES:
113         case ICAP_SUPPORTEDSIZES:
114         case CAP_AUTOFEED:
115         case CAP_CLEARPAGE:
116         case CAP_FEEDERALIGNMENT:
117         case CAP_FEEDERENABLED:
118         case CAP_FEEDERLOADED:
119         case CAP_FEEDERORDER:
120         case CAP_FEEDPAGE:
121         case CAP_PAPERBINDING:
122         case CAP_PAPERDETECTABLE:
123         case CAP_REACQUIREALLOWED:
124         case CAP_REWINDPAGE:
125         case ICAP_PATCHCODEDETECTIONENABLED:
126         case ICAP_SUPPORTEDPATCHCODETYPES:
127         case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
128         case ICAP_PATCHCODESEARCHPRIORITIES:
129         case ICAP_PATCHCODESEARCHMODE:
130         case ICAP_PATCHCODEMAXRETRIES:
131         case ICAP_PATCHCODETIMEOUT:
132         case CAP_BATTERYMINUTES:
133         case CAP_BATTERYPERCENTAGE:
134         case CAP_POWERDOWNTIME:
135         case CAP_POWERSUPPLY:
136         case ICAP_XNATIVERESOLUTION:
137         case ICAP_XRESOLUTION:
138         case ICAP_YNATIVERESOLUTION:
139         case ICAP_YRESOLUTION:
140             twCC = TWCC_CAPUNSUPPORTED;
141             break;
142         case CAP_XFERCOUNT:
143             /* This is a required capability that every source need to
144                support but we havev't implemented yet. */
145             twCC = TWCC_SUCCESS;
146             break;
147         /*case ICAP_COMPRESSION:*/
148         case ICAP_IMAGEFILEFORMAT:
149         case ICAP_TILES:
150             twCC = TWCC_CAPUNSUPPORTED;
151             break;
152         case ICAP_XFERMECH:
153             twCC = TWAIN_ICAPXferMech (pSource, pCapability, action);
154             break;
155         case ICAP_UNDEFINEDIMAGESIZE:
156         case CAP_CAMERAPREVIEWUI:
157         case CAP_ENABLEDSUIONLY:
158         case CAP_INDICATORS:
159         case CAP_UICONTROLLABLE:
160             twCC = TWCC_CAPUNSUPPORTED;
161             break;
162         default:
163             twCC = TWRC_FAILURE;
164
165     }
166
167     return twCC;
168 }
169
170 TW_BOOL TWAIN_OneValueSet (pTW_CAPABILITY pCapability, TW_UINT32 value)
171 {
172     pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));
173
174     if (pCapability->hContainer)
175     {
176         pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
177         pVal->ItemType = TWTY_UINT32;
178         pVal->Item = value;
179         GlobalUnlock ((HGLOBAL) pCapability->hContainer);
180         return TRUE;
181     }
182     else
183         return FALSE;
184 }
185
186 TW_BOOL TWAIN_OneValueGet (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
187 {
188     pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
189
190     if (pVal)
191     {
192         *pValue = pVal->Item;
193         GlobalUnlock ((HGLOBAL) pCapability->hContainer);
194         return TRUE;
195     }
196     else
197         return FALSE;
198 }
199
200 /* ICAP_XFERMECH */
201 TW_UINT16 TWAIN_ICAPXferMech (activeDS *pSource, pTW_CAPABILITY pCapability,
202                               TW_UINT16 action)
203 {
204     TRACE("ICAP_XFERMECH\n");
205
206     switch (action)
207     {
208         case MSG_GET:
209             if (pCapability->ConType == TWON_ONEVALUE)
210             {
211                 if (!TWAIN_OneValueSet (pCapability, pSource->capXferMech))
212                     return TWCC_LOWMEMORY;
213             }
214             break;
215         case MSG_SET:
216             if (pCapability->ConType == TWON_ONEVALUE)
217             {
218                 TW_UINT32 xfermechtemp;
219                 if (!TWAIN_OneValueGet (pCapability, &xfermechtemp))
220                     return TWCC_LOWMEMORY;
221                 pSource->capXferMech = xfermechtemp;
222             }
223             else if (pCapability->ConType == TWON_ENUMERATION)
224             {
225
226             }
227             break;
228         case MSG_GETCURRENT:
229             if (!TWAIN_OneValueSet (pCapability, pSource->capXferMech))
230                 return TWCC_LOWMEMORY;
231             break;
232         case MSG_GETDEFAULT:
233             if (!TWAIN_OneValueSet (pCapability, TWSX_NATIVE))
234                 return TWCC_LOWMEMORY;
235             break;
236         case MSG_RESET:
237             pSource->capXferMech = TWSX_NATIVE;
238             break;
239     }
240     return TWCC_SUCCESS;
241 }