ds_ctrl.c 11.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2000 Corel Corporation
 *
 * 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
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18 19
 */

#include <stdlib.h>
20
#include "sane_i.h"
21 22 23 24 25
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(twain);

/* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
26
TW_UINT16 SANE_CapabilityGet (pTW_IDENTITY pOrigin, TW_MEMREF pData)
27 28 29
{
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
30

31
    TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
32

33
    if (activeDS.currentState < 4 || activeDS.currentState > 7)
34 35
    {
        twRC = TWRC_FAILURE;
36
        activeDS.twCC = TWCC_SEQERROR;
37 38 39
    }
    else
    {
40
        twCC = SANE_SaneCapability (pCapability, MSG_GET);
41
        twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
42
        activeDS.twCC = twCC;
43 44 45 46 47 48
    }

    return twRC;
}

/* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
49
TW_UINT16 SANE_CapabilityGetCurrent (pTW_IDENTITY pOrigin, TW_MEMREF pData)
50 51 52 53 54 55
{
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;

    TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");

56
    if (activeDS.currentState < 4 || activeDS.currentState > 7)
57 58
    {
        twRC = TWRC_FAILURE;
59
        activeDS.twCC = TWCC_SEQERROR;
60 61 62
    }
    else
    {
63
        twCC = SANE_SaneCapability (pCapability, MSG_GETCURRENT);
64
        twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
65
        activeDS.twCC = twCC;
66
    }
67 68 69 70 71

    return twRC;
}

/* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
72
TW_UINT16 SANE_CapabilityGetDefault (pTW_IDENTITY pOrigin, TW_MEMREF pData)
73 74 75 76 77 78
{
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;

    TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");

79
    if (activeDS.currentState < 4 || activeDS.currentState > 7)
80 81
    {
        twRC = TWRC_FAILURE;
82
        activeDS.twCC = TWCC_SEQERROR;
83 84 85
    }
    else
    {
86
        twCC = SANE_SaneCapability (pCapability, MSG_GETDEFAULT);
87
        twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
88
        activeDS.twCC = twCC;
89 90 91 92 93 94
    }

    return twRC;
}

/* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
95 96
TW_UINT16 SANE_CapabilityQuerySupport (pTW_IDENTITY pOrigin,
                                        TW_MEMREF pData)
97
{
98 99
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT\n");

    if (activeDS.currentState < 4 || activeDS.currentState > 7)
    {
        twRC = TWRC_FAILURE;
        activeDS.twCC = TWCC_SEQERROR;
    }
    else
    {
        twCC = SANE_SaneCapability (pCapability, MSG_QUERYSUPPORT);
        twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
        activeDS.twCC = twCC;
    }

    return twRC;
116 117 118
}

/* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
119
TW_UINT16 SANE_CapabilityReset (pTW_IDENTITY pOrigin, 
120 121 122 123 124 125 126
                                 TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;

    TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");

127
    if (activeDS.currentState < 4 || activeDS.currentState > 7)
128 129
    {
        twRC = TWRC_FAILURE;
130
        activeDS.twCC = TWCC_SEQERROR;
131 132 133
    }
    else
    {
134
        twCC = SANE_SaneCapability (pCapability, MSG_RESET);
135
        twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
136
        activeDS.twCC = twCC;
137 138 139 140 141 142
    }

    return twRC;
}

/* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
143
TW_UINT16 SANE_CapabilitySet (pTW_IDENTITY pOrigin, 
144 145 146 147 148 149 150
                               TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS, twCC = TWCC_SUCCESS;
    pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;

    TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");

151
    if (activeDS.currentState != 4)
152 153
    {
        twRC = TWRC_FAILURE;
154
        activeDS.twCC = TWCC_SEQERROR;
155 156 157
    }
    else
    {
158
        twCC = SANE_SaneCapability (pCapability, MSG_SET);
159 160 161 162 163 164 165
        if (twCC == TWCC_CHECKSTATUS)
        {
            twCC = TWCC_SUCCESS;
            twRC = TWRC_CHECKSTATUS;
        }
        else
            twRC = (twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
166
        activeDS.twCC = twCC;
167 168 169 170 171
    }
    return twRC;
}

/* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
172
TW_UINT16 SANE_ProcessEvent (pTW_IDENTITY pOrigin, 
173 174
                              TW_MEMREF pData)
{
175
    TW_UINT16 twRC = TWRC_NOTDSEVENT;
176
    pTW_EVENT pEvent = (pTW_EVENT) pData;
177
    MSG *pMsg = pEvent->pEvent;
178

179
    TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT  msg 0x%x, wParam 0x%Ix\n", pMsg->message, pMsg->wParam);
180

181
    activeDS.twCC = TWCC_SUCCESS;
182
    pEvent->TWMessage = MSG_NULL;  /* no message to the application */
183 184

    if (activeDS.currentState < 5 || activeDS.currentState > 7)
185
    {
186 187
        twRC = TWRC_FAILURE;
        activeDS.twCC = TWCC_SEQERROR;
188 189 190 191 192 193
    }

    return twRC;
}

/* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
194
TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin, 
195 196 197 198 199 200 201
                                     TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS;
    pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;

    TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");

202
    if (activeDS.currentState != 6 && activeDS.currentState != 7)
203 204
    {
        twRC = TWRC_FAILURE;
205
        activeDS.twCC = TWCC_SEQERROR;
206 207 208
    }
    else
    {
209 210
        pPendingXfers->Count = -1;
        activeDS.currentState = 6;
211
        if (SANE_CALL( start_device, NULL ))
212
        {
213 214 215 216
            pPendingXfers->Count = 0;
            activeDS.currentState = 5;
            /* Notify the application that it can close the data source */
            SANE_Notify(MSG_CLOSEDSREQ);
217 218
        }
        twRC = TWRC_SUCCESS;
219
        activeDS.twCC = TWCC_SUCCESS;
220 221 222 223 224 225
    }

    return twRC;
}

/* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
226
TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin, 
227 228 229 230 231 232 233
                                 TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS;
    pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;

    TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");

234
    if (activeDS.currentState < 4 || activeDS.currentState > 7)
235 236
    {
        twRC = TWRC_FAILURE;
237
        activeDS.twCC = TWCC_SEQERROR;
238 239 240
    }
    else
    {
241
        pPendingXfers->Count = -1;
242 243
        if (SANE_CALL( start_device, NULL ))
            pPendingXfers->Count = 0;
244
        twRC = TWRC_SUCCESS;
245
        activeDS.twCC = TWCC_SUCCESS;
246 247 248 249 250 251
    }

    return twRC;
}

/* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
252
TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin, 
253 254 255 256 257 258 259
                                   TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS;
    pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;

    TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");

260
    if (activeDS.currentState != 6)
261 262
    {
        twRC = TWRC_FAILURE;
263
        activeDS.twCC = TWCC_SEQERROR;
264 265 266 267
    }
    else
    {
        pPendingXfers->Count = 0;
268
        activeDS.currentState = 5;
269
        twRC = TWRC_SUCCESS;
270
        activeDS.twCC = TWCC_SUCCESS;
271
        SANE_CALL( cancel_device, NULL );
272 273 274 275 276 277
    }

    return twRC;
}

/* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
278
TW_UINT16 SANE_SetupMemXferGet (pTW_IDENTITY pOrigin, 
279 280
                                  TW_MEMREF pData)
{
281 282 283
    pTW_SETUPMEMXFER  pSetupMemXfer = (pTW_SETUPMEMXFER)pData;

    TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
284
    if (activeDS.frame_params.bytes_per_line)
285
    {
286 287 288
        pSetupMemXfer->MinBufSize = activeDS.frame_params.bytes_per_line;
        pSetupMemXfer->MaxBufSize = activeDS.frame_params.bytes_per_line * 8;
        pSetupMemXfer->Preferred = activeDS.frame_params.bytes_per_line * 2;
289 290 291 292 293 294 295 296 297 298
    }
    else
    {
        /* Guessing */
        pSetupMemXfer->MinBufSize = 2000;
        pSetupMemXfer->MaxBufSize = 8000;
        pSetupMemXfer->Preferred = 4000;
    }

    return TWRC_SUCCESS;
299 300 301
}

/* DG_CONTROL/DAT_STATUS/MSG_GET */
302
TW_UINT16 SANE_GetDSStatus (pTW_IDENTITY pOrigin, 
303 304 305 306 307
                             TW_MEMREF pData)
{
    pTW_STATUS pSourceStatus = (pTW_STATUS) pData;

    TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
308 309 310 311
    pSourceStatus->ConditionCode = activeDS.twCC;
    /* Reset the condition code */
    activeDS.twCC = TWCC_SUCCESS;
    return TWRC_SUCCESS;
312 313 314
}

/* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
315 316
TW_UINT16 SANE_DisableDSUserInterface (pTW_IDENTITY pOrigin,
                                        TW_MEMREF pData)
317 318 319 320 321
{
    TW_UINT16 twRC = TWRC_SUCCESS;

    TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");

322
    if (activeDS.currentState != 5)
323 324
    {
        twRC = TWRC_FAILURE;
325
        activeDS.twCC = TWCC_SEQERROR;
326 327 328
    }
    else
    {
329
        activeDS.currentState = 4;
330
        twRC = TWRC_SUCCESS;
331
        activeDS.twCC = TWCC_SUCCESS;
332 333 334 335 336 337
    }

    return twRC;
}

/* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
338 339
TW_UINT16 SANE_EnableDSUserInterface (pTW_IDENTITY pOrigin,
                                       TW_MEMREF pData)
340 341 342
{
    TW_UINT16 twRC = TWRC_SUCCESS;
    pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
343

344
    TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
345

346
    if (activeDS.currentState != 4)
347 348
    {
        twRC = TWRC_FAILURE;
349
        activeDS.twCC = TWCC_SEQERROR;
350
	WARN("sequence error %d\n", activeDS.currentState);
351 352 353
    }
    else
    {
354
        activeDS.hwndOwner = pUserInterface->hParent;
355 356
        if (pUserInterface->ShowUI)
        {
357
            BOOL rc;
358 359
            activeDS.currentState = 5; /* Transitions to state 5 */
            rc = DoScannerUI();
360
            pUserInterface->ModalUI = TRUE;
361 362
            if (!rc)
            {
363
                SANE_Notify(MSG_CLOSEDSREQ);
364 365 366
            }
            else
            {
367
                get_sane_params( &activeDS.frame_params );
368
            }
369 370 371 372
        }
        else
        {
            /* no UI will be displayed, so source is ready to transfer data */
373
            activeDS.currentState = 6; /* Transitions to state 6 directly */
374
            SANE_Notify(MSG_XFERREADY);
375
        }
376

377
        twRC = TWRC_SUCCESS;
378
        activeDS.twCC = TWCC_SUCCESS;
379 380 381 382 383 384
    }

    return twRC;
}

/* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
385
TW_UINT16 SANE_EnableDSUIOnly (pTW_IDENTITY pOrigin, 
386 387 388 389 390 391
                                TW_MEMREF pData)
{
    TW_UINT16 twRC = TWRC_SUCCESS;

    TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");

392
    if (activeDS.currentState != 4)
393 394
    {
        twRC = TWRC_FAILURE;
395
        activeDS.twCC = TWCC_SEQERROR;
396 397 398
    }
    else
    {
399
        activeDS.currentState = 5;
400
        twRC = TWRC_SUCCESS;
401
        activeDS.twCC = TWCC_SUCCESS;
402 403 404 405 406 407
    }

    return twRC;
}

/* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
408
TW_UINT16 SANE_XferGroupGet (pTW_IDENTITY pOrigin, 
409 410 411 412 413 414 415 416
                              TW_MEMREF pData)
{
    FIXME ("stub!\n");

    return TWRC_FAILURE;
}

/* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
417
TW_UINT16 SANE_XferGroupSet (pTW_IDENTITY pOrigin, 
418 419 420 421 422 423
                                  TW_MEMREF pData)
{
    FIXME ("stub!\n");

    return TWRC_FAILURE;
}