code_twain/sane/ui.cpp

77 lines
1.5 KiB
C++
Raw Permalink Normal View History

2022-05-03 08:54:08 +00:00
#include "pch.h"
#include "ui.h"
#include "huagaotwain.h" // for sane_invoker::load_dll
twain_ui::twain_ui(const wchar_t* path) : path_(path), dll_(NULL)
, show_(NULL), hide_(NULL), event_(NULL), hui_(NULL)
, good_(false)
{
good_ = load();
}
twain_ui::~twain_ui()
{
if (hui_ && hide_)
hide_(hui_);
if (dll_)
FreeLibrary(dll_);
}
bool twain_ui::load()
{
std::wstring dll(path_ + L"\\huagaoui.dll");
sane_invoker::load_dll(dll.c_str(), &dll_);
if (!dll_)
return false;
show_ = (ui_show_api)GetProcAddress(dll_, "ui_show");
hide_ = (ui_hide_api)GetProcAddress(dll_, "ui_hide");
event_ = (handle_event_api)GetProcAddress(dll_, "handle_event");
return show_ && hide_ && event_;
}
void twain_ui::show_main_ui(LPSANEAPI api)
{
type_ = UITYPE::UI_MAIN;
if (show_)
hui_ = show_(UITYPE::UI_MAIN, api);
}
void twain_ui::show_setting_ui(LPSANEAPI api, bool with_scan)
{
if (show_)
{
type_ = with_scan ? UITYPE::UI_SETTING_AND_SCAN : UITYPE::UI_SETTING;
hui_ = show_(type_, api);
}
}
void twain_ui::show_progress_ui(LPSANEAPI api)
{
type_ = UITYPE::UI_PROGRESS;
if (show_)
hui_ = show_(UITYPE::UI_PROGRESS, api);
}
void twain_ui::hide_ui(void)
{
if (hui_ && hide_)
hide_(hui_);
hui_ = NULL;
}
void twain_ui::handle_sane_event(int sane_ev, void* data, unsigned int* len)
{
if (event_)
event_((SANE_Event)sane_ev, data, len);
}
bool twain_ui::is_ok(void)
{
return good_;
}
bool twain_ui::is_progress_ui_showing(void)
{
return type_ == UITYPE::UI_PROGRESS;
}