2 * Copyright 2009 Jeremy White <jwhite@codeweavers.com> for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
29 static SANE_Status
sane_find_option(SANE_Handle h
, const char *option_name
,
30 const SANE_Option_Descriptor
**opt_p
, int *optno
, SANE_Value_Type type
)
34 const SANE_Option_Descriptor
*opt
;
37 /* Debian, in 32_net_backend_standard_fix.dpatch,
38 * forces a frontend (that's us) to reload options
39 * manually by invoking get_option_descriptor. */
40 opt
= psane_get_option_descriptor(h
, 0);
42 return SANE_STATUS_EOF
;
44 rc
= psane_control_option(h
, 0, SANE_ACTION_GET_VALUE
, &optcount
, NULL
);
45 if (rc
!= SANE_STATUS_GOOD
)
48 for (i
= 1; i
< optcount
; i
++)
50 opt
= psane_get_option_descriptor(h
, i
);
51 if (opt
&& (opt
->name
&& strcmp(opt
->name
, option_name
) == 0) &&
56 return SANE_STATUS_GOOD
;
59 return SANE_STATUS_EOF
;
62 SANE_Status
sane_option_get_int(SANE_Handle h
, const char *option_name
, SANE_Int
*val
)
66 const SANE_Option_Descriptor
*opt
;
68 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
69 if (rc
!= SANE_STATUS_GOOD
)
72 return psane_control_option(h
, optno
, SANE_ACTION_GET_VALUE
, val
, NULL
);
75 SANE_Status
sane_option_set_int(SANE_Handle h
, const char *option_name
, SANE_Int val
, SANE_Int
*status
)
79 const SANE_Option_Descriptor
*opt
;
81 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
82 if (rc
!= SANE_STATUS_GOOD
)
85 return psane_control_option(h
, optno
, SANE_ACTION_SET_VALUE
, (void *) &val
, status
);
88 /* Important: SANE has the side effect of of overwriting val with the returned value */
89 SANE_Status
sane_option_set_str(SANE_Handle h
, const char *option_name
, SANE_String val
, SANE_Int
*status
)
93 const SANE_Option_Descriptor
*opt
;
95 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_STRING
);
96 if (rc
!= SANE_STATUS_GOOD
)
99 return psane_control_option(h
, optno
, SANE_ACTION_SET_VALUE
, (void *) val
, status
);
102 SANE_Status
sane_option_probe_resolution(SANE_Handle h
, const char *option_name
, SANE_Int
*minval
, SANE_Int
*maxval
, SANE_Int
*quant
)
106 const SANE_Option_Descriptor
*opt
;
108 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
109 if (rc
!= SANE_STATUS_GOOD
)
112 if (opt
->constraint_type
!= SANE_CONSTRAINT_RANGE
)
113 return SANE_STATUS_UNSUPPORTED
;
115 *minval
= opt
->constraint
.range
->min
;
116 *maxval
= opt
->constraint
.range
->max
;
117 *quant
= opt
->constraint
.range
->quant
;
122 SANE_Status
sane_option_probe_mode(SANE_Handle h
, SANE_String_Const
**choices
, char *current
, int current_size
)
126 const SANE_Option_Descriptor
*opt
;
127 rc
= sane_find_option(h
, "mode", &opt
, &optno
, SANE_TYPE_STRING
);
128 if (rc
!= SANE_STATUS_GOOD
)
131 if (choices
&& opt
->constraint_type
== SANE_CONSTRAINT_STRING_LIST
)
132 *choices
= (SANE_String_Const
*) opt
->constraint
.string_list
;
134 if (opt
->size
< current_size
)
135 return psane_control_option(h
, optno
, SANE_ACTION_GET_VALUE
, current
, NULL
);
137 return SANE_STATUS_NO_MEM
;