From d278ab3fef2b7facaf4815bbb88608447b40f6f0 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Tue, 25 Apr 2023 16:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E6=89=93=E5=BC=80=E5=A4=AA=E5=BF=AB=20?= =?UTF-8?q?=EF=BC=8Cusb=E7=BC=BA=E6=B2=A1=E5=87=86=E5=A4=87=E5=A5=BD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E8=B0=83=E6=95=B4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=9A=84QT=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/scanner.cpp | 92 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/sane/scanner.cpp b/sane/scanner.cpp index c2a130a..93d2838 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -342,9 +342,9 @@ namespace callback // SANE_EVENT_USB_DATA_RECEIVED- void* unused, be NULL, flag - unused, be 0 // SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0 int (*choose_scanner)(const std::vector& devs) = NULL; // blocked. return selected DEVQUE::id or -1 if user cancelled - void (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配置 - void (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, bool with_scan) = NULL; - void (*show_progress_ui)(HWND parent, std::function callback, std::function* notify) = NULL; + int (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配置 + int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, bool with_scan) = NULL; + int (*show_progress_ui)(HWND parent, std::function callback, std::function* notify) = NULL; //std::function ui_result_callback; std::function notify; @@ -701,7 +701,7 @@ void scanner::on_ui_event(int uev, void* sender) if (uev == SANE_EVENT_SCAN_FINISHED || uev == SANE_EVENT_UI_CLOSE_NORMAL || uev == SANE_EVENT_UI_CLOSE_CANCEL) { if (uev == SANE_EVENT_UI_CLOSE_CANCEL) - user_cancel_ = true; + stop(); if (indicator) indicator_.reset(); @@ -2460,25 +2460,25 @@ COM_API_IMPLEMENT(scanner, int, get_scanned_images(DWORD milliseconds)) else Sleep(elapse); - int ev = get_event(); - - count = images_.count(); - if (ev == SANE_EVENT_SCAN_FINISHED) - { - ui_hide(); - break; - } - else if (ev == SANE_EVENT_UI_CLOSE_CANCEL) - { - stop(); - ui_hide(); - break; - } - else if (ev == SANE_EVENT_UI_CLOSE_NORMAL) - { - ui_hide(); - break; - } + //int ev = get_event(); + // + //count = images_.count(); + //if (ev == SANE_EVENT_SCAN_FINISHED) + //{ + // ui_hide(); + // break; + //} + //else if (ev == SANE_EVENT_UI_CLOSE_CANCEL) + //{ + // stop(); + // ui_hide(); + // break; + //} + //else if (ev == SANE_EVENT_UI_CLOSE_NORMAL) + //{ + // ui_hide(); + // break; + //} if (milliseconds != -1) { if (milliseconds <= elapse) @@ -2904,7 +2904,45 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bo { on_ui_event(ev, NULL); }; - callback::show_setting_ui(handle_, parent, &sane_api_, with_scan); + + //auto ui_process = [this](ui_result res) + //{ + // int uev = SANE_EVENT_SCAN_FINISHED; + // switch (res) + // { + // case UI_RESULT_FAILED: + + // break; + // case UI_RESULT_OK: + // break; + // case UI_RESULT_CLOSE_NORMAL: + // uev = SANE_EVENT_UI_CLOSE_NORMAL; + // on_ui_event(uev, (void*)uev); + // break; + // case UI_RESULT_CLOSE_CANCEL: + // uev = SANE_EVENT_UI_CLOSE_CANCEL; + // sane_api_.sane_cancel_api(handle_); + // //on_ui_event(uev, (void*)uev); + // break; + // case UI_RESULT_START_SCAN: + // break; + // default: + // break; + // } + //}; + int res = callback::show_setting_ui(handle_, parent, &sane_api_, true); + if (res == ui_result::UI_RESULT_CLOSE_NORMAL) + { + int ev = SANE_EVENT_UI_CLOSE_NORMAL; + on_ui_event(ev, (void*)ev); + } + else if (res == ui_result::UI_RESULT_START_SCAN) + { + //callback::show_progress_ui(parent, ui_process, &ui_notify); + //start(); + on_ui_event(SANE_EVENT_UI_SCAN_COMMAND, NULL); + } + //on_ui_event(ev, NULL); } else if (cfg_) { @@ -2954,8 +2992,8 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent)) break; case UI_RESULT_CLOSE_CANCEL: uev = SANE_EVENT_UI_CLOSE_CANCEL; - sane_api_.sane_cancel_api(handle_); - //on_ui_event(uev, (void*)uev); + on_ui_event(uev, (void*)uev); + break; case UI_RESULT_START_SCAN: break; @@ -3004,6 +3042,8 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len) else on_ui_event(ev_code, (void*)ev_code); + ui_notify(ev_code, data, 0); + log_info(L"Scanning ...\r\n", 0); } else if (ev_code == SANE_EVENT_IMAGE_OK)