/* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */ TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin, TW_MEMREF pData) { TW_UINT16 twRC = TWRC_SUCCESS; pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData; TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n"); if (activeDS.currentState != 4) { twRC = TWRC_FAILURE; activeDS.twCC = TWCC_SEQERROR; WARN("sequence error %d\n", activeDS.currentState); } else { activeDS.hwndOwner = pUserInterface->hParent; if (! activeDS.windowMessage) activeDS.windowMessage = RegisterWindowMessageA("SANE.DS ACTIVITY MESSAGE"); if (pUserInterface->ShowUI) { BOOL rc; activeDS.currentState = 5; /* Transitions to state 5 */ rc = DoScannerUI(); pUserInterface->ModalUI = TRUE; if (!rc) { if (activeDS.windowMessage) PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0); } #ifdef SONAME_LIBSANE else { psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param); activeDS.sane_param_valid = TRUE; } #endif } else { /* no UI will be displayed, so source is ready to transfer data */ activeDS.currentState = 6; /* Transitions to state 6 directly */ if (activeDS.windowMessage) PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_XFERREADY, 0); } twRC = TWRC_SUCCESS; activeDS.twCC = TWCC_SUCCESS; } return twRC; }
/* ICAP_PIXELTYPE */ static TW_UINT16 SANE_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action) { TW_UINT16 twCC = TWCC_BADCAP; #ifdef SONAME_LIBSANE TW_UINT32 possible_values[3]; int possible_value_count; TW_UINT32 val; SANE_Status rc; SANE_Int status; SANE_String_Const *choices; char current_mode[64]; TW_UINT16 current_pixeltype = TWPT_BW; SANE_Char mode[64]; TRACE("ICAP_PIXELTYPE\n"); rc = sane_option_probe_mode(activeDS.deviceHandle, &choices, current_mode, sizeof(current_mode)); if (rc != SANE_STATUS_GOOD) { ERR("Unable to retrieve mode from sane, ICAP_PIXELTYPE unsupported\n"); return twCC; } sane_mode_to_pixeltype(current_mode, ¤t_pixeltype); /* Sane does not support a concept of a default mode, so we simply cache * the first mode we find */ if (! activeDS.PixelTypeSet) { activeDS.PixelTypeSet = TRUE; activeDS.defaultPixelType = current_pixeltype; } switch (action) { case MSG_QUERYSUPPORT: twCC = set_onevalue(pCapability, TWTY_INT32, TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET ); break; case MSG_GET: for (possible_value_count = 0; choices && *choices && possible_value_count < 3; choices++) { TW_UINT16 pix; if (sane_mode_to_pixeltype(*choices, &pix)) possible_values[possible_value_count++] = pix; } twCC = msg_get_enum(pCapability, possible_values, possible_value_count, TWTY_UINT16, current_pixeltype, activeDS.defaultPixelType); break; case MSG_SET: twCC = msg_set(pCapability, &val); if (twCC == TWCC_SUCCESS) { TRACE("Setting pixeltype to %d\n", val); if (! pixeltype_to_sane_mode(val, mode, sizeof(mode))) return TWCC_BADVALUE; status = 0; rc = sane_option_set_str(activeDS.deviceHandle, "mode", mode, &status); /* Some SANE devices use 'Grayscale' instead of the standard 'Gray' */ if (rc == SANE_STATUS_INVAL && strcmp(mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { strcpy(mode, "Grayscale"); rc = sane_option_set_str(activeDS.deviceHandle, "mode", mode, &status); } if (rc != SANE_STATUS_GOOD) return sane_status_to_twcc(rc); if (status & SANE_INFO_RELOAD_PARAMS) psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param); } break; case MSG_GETDEFAULT: twCC = set_onevalue(pCapability, TWTY_UINT16, activeDS.defaultPixelType); break; case MSG_RESET: current_pixeltype = activeDS.defaultPixelType; if (! pixeltype_to_sane_mode(current_pixeltype, mode, sizeof(mode))) return TWCC_BADVALUE; status = 0; rc = sane_option_set_str(activeDS.deviceHandle, "mode", mode, &status); /* Some SANE devices use 'Grayscale' instead of the standard 'Gray' */ if (rc == SANE_STATUS_INVAL && strcmp(mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { strcpy(mode, "Grayscale"); rc = sane_option_set_str(activeDS.deviceHandle, "mode", mode, &status); } if (rc != SANE_STATUS_GOOD) return sane_status_to_twcc(rc); if (status & SANE_INFO_RELOAD_PARAMS) psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param); /* .. fall through intentional .. */ case MSG_GETCURRENT: twCC = set_onevalue(pCapability, TWTY_UINT16, current_pixeltype); TRACE("Returning current pixeltype of %d\n", current_pixeltype); break; } #endif return twCC; }