Improved the CHECK_DEF macro to avoid code duplication.
[wine/wine64.git] / dlls / twain / capability.c
blob64b480e48734cf5d597c0cdbe1157e7bda41b088
1 /*
2 * Copyright 2000 Corel Corporation
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.
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.
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
19 #define NONAMELESSUNION
20 #define NONAMELESSSTRUCT
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "twain.h"
29 #include "twain_i.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(twain);
34 TW_UINT16 TWAIN_SaneCapability (activeDS *pSource, pTW_CAPABILITY pCapability,
35 TW_UINT16 action)
37 TW_UINT16 twCC = TWCC_SUCCESS;
39 TRACE("capability=%d action=%d\n", pCapability->Cap, action);
41 switch (pCapability->Cap)
43 case CAP_DEVICEEVENT:
44 case CAP_ALARMS:
45 case CAP_ALARMVOLUME:
46 case ACAP_AUDIOFILEFORMAT:
47 case ACAP_XFERMECH:
48 case ICAP_AUTOMATICBORDERDETECTION:
49 case ICAP_AUTOMATICDESKEW:
50 case ICAP_AUTODISCARDBLANKPAGES:
51 case ICAP_AUTOMATICROTATE:
52 case ICAP_FLIPROTATION:
53 case CAP_AUTOMATICCAPTURE:
54 case CAP_TIMEBEFOREFIRSTCAPTURE:
55 case CAP_TIMEBETWEENCAPTURES:
56 case CAP_AUTOSCAN:
57 case CAP_CLEARBUFFERS:
58 case CAP_MAXBATCHBUFFERS:
59 case ICAP_BARCODEDETECTIONENABLED:
60 case ICAP_SUPPORTEDBARCODETYPES:
61 case ICAP_BARCODEMAXSEARCHPRIORITIES:
62 case ICAP_BARCODESEARCHPRIORITIES:
63 case ICAP_BARCODESEARCHMODE:
64 case ICAP_BARCODEMAXRETRIES:
65 case ICAP_BARCODETIMEOUT:
66 case CAP_EXTENDEDCAPS:
67 case CAP_SUPPORTEDCAPS:
68 case ICAP_FILTER:
69 case ICAP_GAMMA:
70 case ICAP_PLANARCHUNKY:
71 case ICAP_BITORDERCODES:
72 case ICAP_CCITTKFACTOR:
73 case ICAP_COMPRESSION:
74 case ICAP_JPEGPIXELTYPE:
75 /*case ICAP_JPEGQUALITY:*/
76 case ICAP_PIXELFLAVORCODES:
77 case ICAP_TIMEFILL:
78 case CAP_DEVICEONLINE:
79 case CAP_DEVICETIMEDATE:
80 case CAP_SERIALNUMBER:
81 case ICAP_EXPOSURETIME:
82 case ICAP_FLASHUSED2:
83 case ICAP_IMAGEFILTER:
84 case ICAP_LAMPSTATE:
85 case ICAP_LIGHTPATH:
86 case ICAP_NOISEFILTER:
87 case ICAP_OVERSCAN:
88 case ICAP_PHYSICALHEIGHT:
89 case ICAP_PHYSICALWIDTH:
90 case ICAP_UNITS:
91 case ICAP_ZOOMFACTOR:
92 case CAP_PRINTER:
93 case CAP_PRINTERENABLED:
94 case CAP_PRINTERINDEX:
95 case CAP_PRINTERMODE:
96 case CAP_PRINTERSTRING:
97 case CAP_PRINTERSUFFIX:
98 case CAP_AUTHOR:
99 case CAP_CAPTION:
100 case CAP_TIMEDATE:
101 case ICAP_AUTOBRIGHT:
102 case ICAP_BRIGHTNESS:
103 case ICAP_CONTRAST:
104 case ICAP_HIGHLIGHT:
105 case ICAP_ORIENTATION:
106 case ICAP_ROTATION:
107 case ICAP_SHADOW:
108 case ICAP_XSCALING:
109 case ICAP_YSCALING:
110 case ICAP_BITDEPTH:
111 case ICAP_BITDEPTHREDUCTION:
112 case ICAP_BITORDER:
113 case ICAP_CUSTHALFTONE:
114 case ICAP_HALFTONES:
115 case ICAP_PIXELFLAVOR:
116 case ICAP_PIXELTYPE:
117 case ICAP_THRESHOLD:
118 case CAP_LANGUAGE:
119 case ICAP_FRAMES:
120 case ICAP_MAXFRAMES:
121 case ICAP_SUPPORTEDSIZES:
122 case CAP_AUTOFEED:
123 case CAP_CLEARPAGE:
124 case CAP_FEEDERALIGNMENT:
125 case CAP_FEEDERENABLED:
126 case CAP_FEEDERLOADED:
127 case CAP_FEEDERORDER:
128 case CAP_FEEDPAGE:
129 case CAP_PAPERBINDING:
130 case CAP_PAPERDETECTABLE:
131 case CAP_REACQUIREALLOWED:
132 case CAP_REWINDPAGE:
133 case ICAP_PATCHCODEDETECTIONENABLED:
134 case ICAP_SUPPORTEDPATCHCODETYPES:
135 case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
136 case ICAP_PATCHCODESEARCHPRIORITIES:
137 case ICAP_PATCHCODESEARCHMODE:
138 case ICAP_PATCHCODEMAXRETRIES:
139 case ICAP_PATCHCODETIMEOUT:
140 case CAP_BATTERYMINUTES:
141 case CAP_BATTERYPERCENTAGE:
142 case CAP_POWERDOWNTIME:
143 case CAP_POWERSUPPLY:
144 case ICAP_XNATIVERESOLUTION:
145 case ICAP_XRESOLUTION:
146 case ICAP_YNATIVERESOLUTION:
147 case ICAP_YRESOLUTION:
148 twCC = TWCC_CAPUNSUPPORTED;
149 break;
150 case CAP_XFERCOUNT:
151 /* This is a required capability that every source need to
152 support but we havev't implemented yet. */
153 twCC = TWCC_SUCCESS;
154 break;
155 /*case ICAP_COMPRESSION:*/
156 case ICAP_IMAGEFILEFORMAT:
157 case ICAP_TILES:
158 twCC = TWCC_CAPUNSUPPORTED;
159 break;
160 case ICAP_XFERMECH:
161 twCC = TWAIN_ICAPXferMech (pSource, pCapability, action);
162 break;
163 case ICAP_UNDEFINEDIMAGESIZE:
164 case CAP_CAMERAPREVIEWUI:
165 case CAP_ENABLEDSUIONLY:
166 case CAP_INDICATORS:
167 case CAP_UICONTROLLABLE:
168 twCC = TWCC_CAPUNSUPPORTED;
169 break;
170 default:
171 twCC = TWRC_FAILURE;
175 return twCC;
178 static TW_BOOL TWAIN_OneValueSet (pTW_CAPABILITY pCapability, TW_UINT32 value)
180 pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));
182 if (pCapability->hContainer)
184 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
185 pVal->ItemType = TWTY_UINT32;
186 pVal->Item = value;
187 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
188 return TRUE;
190 else
191 return FALSE;
194 static TW_BOOL TWAIN_OneValueGet (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
196 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
198 if (pVal)
200 *pValue = pVal->Item;
201 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
202 return TRUE;
204 else
205 return FALSE;
208 /* ICAP_XFERMECH */
209 TW_UINT16 TWAIN_ICAPXferMech (activeDS *pSource, pTW_CAPABILITY pCapability,
210 TW_UINT16 action)
212 TRACE("ICAP_XFERMECH\n");
214 switch (action)
216 case MSG_GET:
217 if (pCapability->ConType == TWON_ONEVALUE)
219 if (!TWAIN_OneValueSet (pCapability, pSource->capXferMech))
220 return TWCC_LOWMEMORY;
222 break;
223 case MSG_SET:
224 if (pCapability->ConType == TWON_ONEVALUE)
226 TW_UINT32 xfermechtemp = 0;
227 if (!TWAIN_OneValueGet (pCapability, &xfermechtemp))
228 return TWCC_LOWMEMORY;
229 pSource->capXferMech = xfermechtemp;
231 else if (pCapability->ConType == TWON_ENUMERATION)
235 break;
236 case MSG_GETCURRENT:
237 if (!TWAIN_OneValueSet (pCapability, pSource->capXferMech))
238 return TWCC_LOWMEMORY;
239 break;
240 case MSG_GETDEFAULT:
241 if (!TWAIN_OneValueSet (pCapability, TWSX_NATIVE))
242 return TWCC_LOWMEMORY;
243 break;
244 case MSG_RESET:
245 pSource->capXferMech = TWSX_NATIVE;
246 break;
248 return TWCC_SUCCESS;