Commit b263ff26 authored by Alexandre Julliard's avatar Alexandre Julliard

sane.ds: Use Twain types and status codes in option helpers.

parent ee280d8c
......@@ -35,7 +35,7 @@ TW_UINT16 SANE_ImageInfoGet (pTW_IDENTITY pOrigin,
TW_UINT16 twRC = TWRC_SUCCESS;
pTW_IMAGEINFO pImageInfo = (pTW_IMAGEINFO) pData;
SANE_Status status;
SANE_Int resolution;
int resolution;
TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
......@@ -62,7 +62,7 @@ TW_UINT16 SANE_ImageInfoGet (pTW_IDENTITY pOrigin,
activeDS.sane_param_valid = TRUE;
}
if (sane_option_get_int("resolution", &resolution) == SANE_STATUS_GOOD)
if (sane_option_get_int("resolution", &resolution) == TWCC_SUCCESS)
pImageInfo->XResolution.Whole = pImageInfo->YResolution.Whole = resolution;
else
pImageInfo->XResolution.Whole = pImageInfo->YResolution.Whole = -1;
......@@ -117,23 +117,23 @@ TW_UINT16 SANE_ImageLayoutGet (pTW_IDENTITY pOrigin,
SANE_Fixed tly_current;
SANE_Fixed brx_current;
SANE_Fixed bry_current;
SANE_Status status;
TW_UINT16 rc;
TRACE("DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET\n");
status = sane_option_probe_scan_area("tl-x", &tlx_current, NULL, NULL, NULL, NULL);
if (status == SANE_STATUS_GOOD)
status = sane_option_probe_scan_area("tl-y", &tly_current, NULL, NULL, NULL, NULL);
rc = sane_option_probe_scan_area("tl-x", &tlx_current, NULL, NULL, NULL, NULL);
if (rc == TWCC_SUCCESS)
rc = sane_option_probe_scan_area("tl-y", &tly_current, NULL, NULL, NULL, NULL);
if (status == SANE_STATUS_GOOD)
status = sane_option_probe_scan_area("br-x", &brx_current, NULL, NULL, NULL, NULL);
if (rc == TWCC_SUCCESS)
rc = sane_option_probe_scan_area("br-x", &brx_current, NULL, NULL, NULL, NULL);
if (status == SANE_STATUS_GOOD)
status = sane_option_probe_scan_area("br-y", &bry_current, NULL, NULL, NULL, NULL);
if (rc == TWCC_SUCCESS)
rc = sane_option_probe_scan_area("br-y", &bry_current, NULL, NULL, NULL, NULL);
if (status != SANE_STATUS_GOOD)
if (rc != TWCC_SUCCESS)
{
activeDS.twCC = sane_status_to_twcc(status);
activeDS.twCC = rc;
return TWRC_FAILURE;
}
......@@ -170,17 +170,13 @@ TW_UINT16 SANE_ImageLayoutReset (pTW_IDENTITY pOrigin,
static TW_UINT16 set_one_imagecoord(const char *option_name, TW_FIX32 val, BOOL *changed)
{
double d = val.Whole + ((double) val.Frac / 65536.0);
int set_status = 0;
SANE_Status status;
status = sane_option_set_fixed(option_name, SANE_FIX((d * 254) / 10), &set_status);
if (status != SANE_STATUS_GOOD)
int v = val.Whole * 65536 + val.Frac;
TW_UINT16 rc = sane_option_set_fixed(option_name, MulDiv( v, 254, 10 ), changed);
if (rc != TWCC_SUCCESS)
{
activeDS.twCC = sane_status_to_twcc(status);
activeDS.twCC = rc;
return TWRC_FAILURE;
}
if (set_status & SANE_INFO_INEXACT)
*changed = TRUE;
return TWRC_SUCCESS;
}
......
......@@ -206,18 +206,19 @@ BOOL DoScannerUI(void) DECLSPEC_HIDDEN;
HWND ScanningDialogBox(HWND dialog, LONG progress) DECLSPEC_HIDDEN;
/* Option functions */
SANE_Status sane_option_get_int(const char *option_name, SANE_Int *val) DECLSPEC_HIDDEN;
SANE_Status sane_option_set_int(const char *option_name, SANE_Int val, SANE_Int *status) DECLSPEC_HIDDEN;
SANE_Status sane_option_get_str(const char *option_name, SANE_String val, size_t len, SANE_Int *status) DECLSPEC_HIDDEN;
SANE_Status sane_option_set_str(const char *option_name, SANE_String val, SANE_Int *status) DECLSPEC_HIDDEN;
SANE_Status sane_option_probe_resolution(const char *option_name, SANE_Int *minval, SANE_Int *maxval, SANE_Int *quant) DECLSPEC_HIDDEN;
SANE_Status sane_option_probe_mode(SANE_String_Const **choices, char *current, int current_size) DECLSPEC_HIDDEN;
SANE_Status sane_option_probe_scan_area(const char *option_name, SANE_Fixed *val,
SANE_Unit *unit, SANE_Fixed *min, SANE_Fixed *max, SANE_Fixed *quant) DECLSPEC_HIDDEN;
SANE_Status sane_option_get_bool(const char *option_name, SANE_Bool *val, SANE_Int *status) DECLSPEC_HIDDEN;
SANE_Status sane_option_set_bool(const char *option_name, SANE_Bool val, SANE_Int *status) DECLSPEC_HIDDEN;
SANE_Status sane_option_set_fixed(const char *option_name, SANE_Fixed val, SANE_Int *status) DECLSPEC_HIDDEN;
TW_UINT16 sane_status_to_twcc(SANE_Status rc) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_get_value( int optno, void *val ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_set_value( int optno, void *val, BOOL *reload ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_get_int( const char *option_name, int *val ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_set_int( const char *option_name, int val, BOOL *reload ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_get_str( const char *option_name, char *val, int len ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_set_str( const char *option_name, char *val, BOOL *reload ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_probe_resolution( const char *option_name, int *minval, int *maxval, int *quant) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_probe_mode(const char * const **choices, char *current, int current_size) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_probe_scan_area(const char *option_name, SANE_Fixed *val,
SANE_Unit *unit, SANE_Fixed *min, SANE_Fixed *max, SANE_Fixed *quant) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_get_bool( const char *option_name, BOOL *val ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_set_bool( const char *option_name, BOOL val ) DECLSPEC_HIDDEN;
TW_UINT16 sane_option_set_fixed( const char *option_name, int val, BOOL *reload ) DECLSPEC_HIDDEN;
BOOL convert_sane_res_to_twain(double sane_res, SANE_Unit unit, TW_FIX32 *twain_res, TW_UINT16 twtype) DECLSPEC_HIDDEN;
#endif
......@@ -169,11 +169,9 @@ static int create_item(HDC hdc, const SANE_Option_Descriptor *opt,
}
else if (opt->type == SANE_TYPE_INT)
{
SANE_Int i;
sane_control_option(activeDS.deviceHandle, id-ID_BASE,
SANE_ACTION_GET_VALUE, &i,NULL);
int i;
sane_option_get_value( id - ID_BASE, &i );
sprintf(buffer,"%i",i);
if (opt->constraint_type == SANE_CONSTRAINT_NONE)
......@@ -207,8 +205,7 @@ static int create_item(HDC hdc, const SANE_Option_Descriptor *opt,
i = HeapAlloc(GetProcessHeap(),0,opt->size*sizeof(SANE_Word));
sane_control_option(activeDS.deviceHandle, id-ID_BASE,
SANE_ACTION_GET_VALUE, i, NULL);
sane_option_get_value( id - ID_BASE, i );
dd = SANE_UNFIX(*i);
sprintf(buffer,"%f",dd);
......@@ -251,8 +248,7 @@ static int create_item(HDC hdc, const SANE_Option_Descriptor *opt,
}
leading_len += create_leading_static(hdc, opt->title, &lead_static, y,
id+ID_STATIC_BASE);
sane_control_option(activeDS.deviceHandle, id-ID_BASE,
SANE_ACTION_GET_VALUE, buffer,NULL);
sane_option_get_value( id - ID_BASE, buffer );
title = buffer;
local_len += MultiByteToWideChar(CP_ACP,0,title,-1,NULL,0);
......@@ -366,7 +362,7 @@ static int create_item(HDC hdc, const SANE_Option_Descriptor *opt,
static LPDLGTEMPLATEW create_options_page(HDC hdc, int *from_index,
SANE_Int optcount, BOOL split_tabs)
int optcount, BOOL split_tabs)
{
int i;
INT y = 2;
......@@ -518,8 +514,8 @@ BOOL DoScannerUI(void)
int page_count= 0;
PROPSHEETHEADERW psh;
int index = 1;
SANE_Status rc;
SANE_Int optcount;
TW_UINT16 rc;
int optcount;
UINT psrc;
LPWSTR szCaption;
DWORD len;
......@@ -527,9 +523,8 @@ BOOL DoScannerUI(void)
hdc = GetDC(0);
memset(psp,0,sizeof(psp));
rc = sane_control_option(activeDS.deviceHandle, 0, SANE_ACTION_GET_VALUE,
&optcount, NULL);
if (rc != SANE_STATUS_GOOD)
rc = sane_option_get_value( 0, &optcount );
if (rc != TWCC_SUCCESS)
{
ERR("Unable to read number of options\n");
return FALSE;
......@@ -647,21 +642,18 @@ static void UpdateRelevantEdit(HWND hwnd, const SANE_Option_Descriptor *opt,
static BOOL UpdateSaneScrollOption(
const SANE_Option_Descriptor *opt, int index, DWORD position)
{
SANE_Status rc = SANE_STATUS_GOOD;
SANE_Int result = 0;
BOOL result = FALSE;
if (opt->type == SANE_TYPE_INT)
{
SANE_Int si;
int si;
if (opt->constraint.range->quant)
si = position * opt->constraint.range->quant;
else
si = position;
rc = sane_control_option (activeDS.deviceHandle,index,
SANE_ACTION_SET_VALUE, &si, &result);
sane_option_set_value( index, &si, &result );
}
else if (opt->type == SANE_TYPE_FIXED)
{
......@@ -679,85 +671,23 @@ static BOOL UpdateSaneScrollOption(
*sf = SANE_FIX(dd);
rc = sane_control_option (activeDS.deviceHandle,index,
SANE_ACTION_SET_VALUE, sf, &result);
sane_option_set_value( index, sf, &result );
HeapFree(GetProcessHeap(),0,sf);
}
if(rc == SANE_STATUS_GOOD)
{
if (result & SANE_INFO_RELOAD_OPTIONS ||
result & SANE_INFO_RELOAD_PARAMS || result & SANE_INFO_INEXACT)
return TRUE;
}
return FALSE;
}
static BOOL UpdateSaneBoolOption(int index, BOOL position)
{
SANE_Status rc = SANE_STATUS_GOOD;
SANE_Int result = 0;
SANE_Bool si;
si = position;
rc = sane_control_option (activeDS.deviceHandle,index,
SANE_ACTION_SET_VALUE, &si, &result);
if(rc == SANE_STATUS_GOOD)
{
if (result & SANE_INFO_RELOAD_OPTIONS ||
result & SANE_INFO_RELOAD_PARAMS || result & SANE_INFO_INEXACT)
return TRUE;
}
return FALSE;
}
static BOOL UpdateSaneIntOption(int index, SANE_Int value)
{
SANE_Status rc = SANE_STATUS_GOOD;
SANE_Int result = 0;
rc = sane_control_option (activeDS.deviceHandle,index,
SANE_ACTION_SET_VALUE, &value, &result);
if(rc == SANE_STATUS_GOOD)
{
if (result & SANE_INFO_RELOAD_OPTIONS ||
result & SANE_INFO_RELOAD_PARAMS || result & SANE_INFO_INEXACT)
return TRUE;
}
return FALSE;
}
static BOOL UpdateSaneStringOption(int index, SANE_String value)
{
SANE_Status rc = SANE_STATUS_GOOD;
SANE_Int result = 0;
rc = sane_control_option (activeDS.deviceHandle,index,
SANE_ACTION_SET_VALUE, value, &result);
if(rc == SANE_STATUS_GOOD)
{
if (result & SANE_INFO_RELOAD_OPTIONS ||
result & SANE_INFO_RELOAD_PARAMS || result & SANE_INFO_INEXACT)
return TRUE;
}
return FALSE;
return result;
}
static INT_PTR InitializeDialog(HWND hwnd)
{
SANE_Status rc;
SANE_Int optcount;
TW_UINT16 rc;
int optcount;
HWND control;
int i;
rc = sane_control_option(activeDS.deviceHandle, 0, SANE_ACTION_GET_VALUE,
&optcount, NULL);
if (rc != SANE_STATUS_GOOD)
rc = sane_option_get_value( 0, &optcount );
if (rc != TWCC_SUCCESS)
{
ERR("Unable to read number of options\n");
return FALSE;
......@@ -794,14 +724,13 @@ static INT_PTR InitializeDialog(HWND hwnd)
(LPARAM)opt->constraint.string_list[j]);
j++;
}
sane_control_option(activeDS.deviceHandle, i, SANE_ACTION_GET_VALUE, buffer,NULL);
sane_option_get_value( i, buffer );
SendMessageA(control,CB_SELECTSTRING,0,(LPARAM)buffer);
}
else if (opt->type == SANE_TYPE_BOOL)
{
SANE_Bool b;
sane_control_option(activeDS.deviceHandle, i,
SANE_ACTION_GET_VALUE, &b, NULL);
BOOL b;
sane_option_get_value( i, &b );
if (b)
SendMessageA(control,BM_SETCHECK,BST_CHECKED,0);
......@@ -811,13 +740,13 @@ static INT_PTR InitializeDialog(HWND hwnd)
{
int j, count = opt->constraint.word_list[0];
CHAR buffer[16];
SANE_Int val;
int val;
for (j=1; j<=count; j++)
{
sprintf(buffer, "%d", opt->constraint.word_list[j]);
SendMessageA(control, CB_ADDSTRING, 0, (LPARAM)buffer);
}
sane_control_option(activeDS.deviceHandle, i, SANE_ACTION_GET_VALUE, &val, NULL);
sane_option_get_value( i, &val );
sprintf(buffer, "%d", val);
SendMessageA(control,CB_SELECTSTRING,0,(LPARAM)buffer);
}
......@@ -825,7 +754,7 @@ static INT_PTR InitializeDialog(HWND hwnd)
{
if (opt->type == SANE_TYPE_INT)
{
SANE_Int si;
int si;
int min,max;
min = (SANE_Int)opt->constraint.range->min /
......@@ -838,8 +767,7 @@ static INT_PTR InitializeDialog(HWND hwnd)
SendMessageA(control,SBM_SETRANGE,min,max);
sane_control_option(activeDS.deviceHandle, i,
SANE_ACTION_GET_VALUE, &si,NULL);
sane_option_get_value( i, &si );
if (opt->constraint.range->quant)
si = si / opt->constraint.range->quant;
......@@ -874,8 +802,7 @@ static INT_PTR InitializeDialog(HWND hwnd)
sf = HeapAlloc(GetProcessHeap(),0,opt->size*sizeof(SANE_Word));
sane_control_option(activeDS.deviceHandle, i,
SANE_ACTION_GET_VALUE, sf,NULL);
sane_option_get_value( i, sf );
dd = SANE_UNFIX(*sf);
HeapFree(GetProcessHeap(),0,sf);
......@@ -960,6 +887,7 @@ static void ButtonClicked(HWND hwnd, INT id, HWND control)
{
int index;
const SANE_Option_Descriptor *opt;
BOOL changed = FALSE;
index = id - ID_BASE;
if (index < 0)
......@@ -973,8 +901,8 @@ static void ButtonClicked(HWND hwnd, INT id, HWND control)
if (opt->type == SANE_TYPE_BOOL)
{
BOOL r = SendMessageW(control,BM_GETCHECK,0,0)==BST_CHECKED;
if (UpdateSaneBoolOption(index, r))
InitializeDialog(hwnd);
sane_option_set_value( index, &r, &changed );
if (changed) InitializeDialog(hwnd);
}
}
......@@ -985,6 +913,7 @@ static void ComboChanged(HWND hwnd, INT id, HWND control)
int len;
const SANE_Option_Descriptor *opt;
SANE_String value;
BOOL changed = FALSE;
index = id - ID_BASE;
if (index < 0)
......@@ -1004,14 +933,14 @@ static void ComboChanged(HWND hwnd, INT id, HWND control)
if (opt->type == SANE_TYPE_STRING)
{
if (UpdateSaneStringOption(index, value))
InitializeDialog(hwnd);
sane_option_set_value( index, value, &changed );
}
else if (opt->type == SANE_TYPE_INT)
{
if (UpdateSaneIntOption(index, atoi(value)))
InitializeDialog(hwnd);
int val = atoi( value );
sane_option_set_value( index, &val, &changed );
}
if (changed) InitializeDialog(hwnd);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment