2002-03-21 03:58:39 +01:00
|
|
|
/*
|
|
|
|
* TWAIN32 functions
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-03-21 03:58:39 +01:00
|
|
|
* Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
|
2006-05-08 20:05:42 +02:00
|
|
|
* Copyright 2006 Marcus Meissner
|
2002-03-21 03:58:39 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-21 03:58:39 +01:00
|
|
|
*/
|
|
|
|
|
2004-09-13 20:06:46 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-03-21 03:58:39 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "twain.h"
|
|
|
|
#include "twain_i.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(twain);
|
|
|
|
|
2017-11-16 23:07:15 +01:00
|
|
|
extern HINSTANCE DSM_hinstance;
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstance, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
TRACE("%p,%x,%p\n", hinstance, reason, reserved);
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hinstance);
|
|
|
|
DSM_hinstance = hinstance;
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
/* A helper function that looks up a destination identity in the active
|
|
|
|
source list */
|
2007-11-07 22:11:07 +01:00
|
|
|
static activeDS *TWAIN_LookupSource (const TW_IDENTITY *pDest)
|
2006-05-08 20:05:42 +02:00
|
|
|
{
|
|
|
|
activeDS *pSource;
|
|
|
|
|
|
|
|
for (pSource = activeSources; pSource; pSource = pSource->next)
|
|
|
|
if (pSource->identity.Id == pDest->Id)
|
|
|
|
break;
|
|
|
|
return pSource;
|
|
|
|
}
|
|
|
|
|
2008-12-02 15:25:52 +01:00
|
|
|
static TW_UINT16 TWAIN_SourceManagerHandler (
|
2002-03-21 03:58:39 +01:00
|
|
|
pTW_IDENTITY pOrigin,
|
|
|
|
TW_UINT16 DAT,
|
|
|
|
TW_UINT16 MSG,
|
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
|
|
|
|
switch (DAT)
|
|
|
|
{
|
|
|
|
case DAT_IDENTITY:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_CLOSEDS:
|
|
|
|
twRC = TWAIN_CloseDS (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_GETDEFAULT:
|
|
|
|
twRC = TWAIN_IdentityGetDefault (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_GETFIRST:
|
|
|
|
twRC = TWAIN_IdentityGetFirst (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_GETNEXT:
|
|
|
|
twRC = TWAIN_IdentityGetNext (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_OPENDS:
|
|
|
|
twRC = TWAIN_OpenDS (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_USERSELECT:
|
|
|
|
twRC = TWAIN_UserSelect (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unrecognized operation triplet */
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
WARN("unrecognized operation triplet\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_PARENT:
|
|
|
|
switch (MSG)
|
|
|
|
{
|
|
|
|
case MSG_CLOSEDSM:
|
|
|
|
twRC = TWAIN_CloseDSM (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_OPENDSM:
|
|
|
|
twRC = TWAIN_OpenDSM (pOrigin, pData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unrecognized operation triplet */
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
WARN("unrecognized operation triplet\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2002-03-21 03:58:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DAT_STATUS:
|
2006-05-08 20:05:42 +02:00
|
|
|
if (MSG == MSG_GET) {
|
2002-03-21 03:58:39 +01:00
|
|
|
twRC = TWAIN_GetDSMStatus (pOrigin, pData);
|
2006-05-08 20:05:42 +02:00
|
|
|
} else {
|
2002-03-21 03:58:39 +01:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
WARN("unrecognized operation triplet\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
WARN("unrecognized operation triplet\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Main entry point for the TWAIN library */
|
|
|
|
TW_UINT16 WINAPI
|
|
|
|
DSM_Entry (pTW_IDENTITY pOrigin,
|
|
|
|
pTW_IDENTITY pDest,
|
|
|
|
TW_UINT32 DG,
|
|
|
|
TW_UINT16 DAT,
|
|
|
|
TW_UINT16 MSG,
|
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
|
|
|
|
|
2009-01-06 00:09:48 +01:00
|
|
|
TRACE("(DG=%d DAT=%d MSG=%d)\n", DG, DAT, MSG);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2017-10-20 21:16:26 +02:00
|
|
|
if (DG == DG_CONTROL && DAT == DAT_NULL)
|
|
|
|
{
|
|
|
|
activeDS *pSource = TWAIN_LookupSource (pOrigin);
|
|
|
|
if (!pSource)
|
|
|
|
{
|
|
|
|
ERR("No source associated with pSource %p\n", pDest);
|
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TWAIN_ControlNull (pOrigin, pDest, pSource, MSG, pData);
|
|
|
|
}
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
if (pDest)
|
|
|
|
{
|
|
|
|
activeDS *pSource = TWAIN_LookupSource (pDest);
|
|
|
|
/* This operation's destination is a source */
|
|
|
|
|
|
|
|
if (!pSource) {
|
|
|
|
ERR("No source associated with pDest %p\n", pDest);
|
|
|
|
DSM_twCC = TWCC_BADDEST;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
2017-10-20 21:16:26 +02:00
|
|
|
|
|
|
|
if (DG == DG_CONTROL && DAT == DAT_EVENT && MSG == MSG_PROCESSEVENT)
|
|
|
|
{
|
|
|
|
twRC = TWAIN_ProcessEvent(pOrigin, pSource, pData);
|
|
|
|
if (twRC == TWRC_DSEVENT)
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DG == DG_CONTROL && DAT == DAT_USERINTERFACE &&
|
|
|
|
(MSG == MSG_ENABLEDS || MSG == MSG_ENABLEDSUIONLY) &&
|
|
|
|
pData != NULL)
|
|
|
|
{
|
|
|
|
pSource->ui_window = ((TW_USERINTERFACE*)pData)->hParent;
|
|
|
|
}
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
DSM_twCC = TWCC_SUCCESS;
|
2009-01-06 00:09:48 +01:00
|
|
|
TRACE("Forwarding %d/%d/%d/%p to DS.\n", DG, DAT, MSG, pData);
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = pSource->dsEntry(pOrigin, DG, DAT, MSG, pData);
|
|
|
|
TRACE("return value is %d\n", twRC);
|
|
|
|
return twRC;
|
|
|
|
}
|
2002-03-21 03:58:39 +01:00
|
|
|
switch (DG)
|
|
|
|
{
|
|
|
|
case DG_CONTROL:
|
2006-05-08 20:05:42 +02:00
|
|
|
twRC = TWAIN_SourceManagerHandler (pOrigin, DAT, MSG, pData);
|
2002-03-21 03:58:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-01-06 00:09:48 +01:00
|
|
|
FIXME("The DSM does not handle DG %d\n", DG);
|
2002-03-21 03:58:39 +01:00
|
|
|
DSM_twCC = TWCC_BADPROTOCOL;
|
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
return twRC;
|
|
|
|
}
|