TWAIN Working Group

Quarterly Newsletter Signup       
  • Home
  • About
    • What’s New?
    • Specification & Tools
    • Self Certification Process
    • TWAIN Features
    • TWAIN Direct
    • Membership
    • News
    • Events
    • Logo Usage
    • TWAIN License
    • Contact Us
  • Scanner User
    • Find Drivers
  • Driver Developer
  • Application Developer
  • Scanner Service Provider
  • TWAIN Forums
  • Resources
    • Find Certified Drivers

gculley

  • Profile
  • Topics Started
  • Replies Created
  • Favorites

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • December 18, 2013 at 5:08 pm in reply to: twain event loop for mac OS X #26044

    gculley
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    Hi Mark,

    I tried the following code with no luck. I never receive any cocoa events of any kind. I also tried GetNextEvent and it also returns no events.

    My code is part of a pluginprocess for the Safari Browser, so I’m wondering if I can even get any events.

    // This method will look for a Mac event to dispatch to the DS.
    S32 TwainSessionMac::ProcessMacEvent()
    {
    NSAutoreleasePool *outerpool = [[NSAutoreleasePool alloc] init];
    NSEvent *cocoaEvent =
    [NSApp
    nextEventMatchingMask:NSAnyEventMask
    untilDate:nil
    inMode:NSDefaultRunLoopMode
    dequeue:YES];

    if (cocoaEvent)
    {
    // Convert to a carbon event
    EventRecord carbonEvent;
    if (!([cocoaEvent eventRef] && ConvertEventRefToEventRecord((EventRef)[cocoaEvent eventRef], &carbonEvent)))
    {
    NSPoint where = cocoaEvent window] convertBaseToScreen:[cocoaEvent locationInWindow;

    carbonEvent.what = nullEvent;
    carbonEvent.message = 0;
    carbonEvent.when = (UInt32)([cocoaEvent timestamp] * 60); // seconds to ticks
    carbonEvent.where.h = (short)where.x;
    carbonEvent.where.v = (short)(NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) – where.y);
    carbonEvent.modifiers = 0; //[self modifiersForEvent:cocoaEvent];
    }

    // send to data source
    TW_EVENT twEvent;
    twEvent.pEvent = (TW_MEMREF)&carbonEvent;
    twEvent.TWMessage = MSG_NULL;
    S32 rc = m_twBase.TWAIN_DS(&CurrentDS(), DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF)&twEvent);
    if( rc < 0 )
    {
    WIC_WARN(g_sessnMacLog, “DataSource operation failed:%d”, rc);
    SetErrorCode(rc);
    return TWRC_FAILURE;
    }
    else if( rc == TWRC_FAILURE )
    {
    TW_UINT16 cc = m_twBase.TWAIN_ConditionCode();
    WIC_WARN(g_sessnMacLog, “DS operation returns error: %d/%d”, rc, cc);
    SetErrorCode(TWSSNEW_FAILURE, cc);
    return TWRC_FAILURE;
    }

    ClearErrorCode();
    if( rc == TWRC_DSEVENT )
    {
    WIC_TRACE(g_sessnMacLog, “DataSource consumes the message”);
    return m_twProc.TwainProc(twEvent.TWMessage);
    }

    [NSApp sendEvent:cocoaEvent];
    [NSApp updateWindows];
    }

    [outerpool release];
    return TWRC_SUCCESS;
    }

    December 17, 2013 at 6:31 pm in reply to: twain event loop for mac OS X #26043

    gculley
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    Thanks Mark, I really appreciate your help on this.

    December 17, 2013 at 6:00 pm in reply to: twain event loop for mac OS X #26041

    gculley
    Participant
    • Topics - 1
    • Replies - 3
    • Total Posts - 4

    Thanks for the reply!

    I have Mac drivers for other Epson scanners that install fine but don’t appear to work with the callback, so I was figuring that I needed to support the old Twain 1.9 event loop for those scanners. This is where it appeared that I needed to use the deprecated Carbon framework to send Carbon events to the datasource.

    Just to be perfectly clear, are you saying that I simply don’t need to support the old-style Mac event loop at all, even for older scanners?

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)

Quick Links

TWAIN Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

Recent Topics

  • TwainDSM is crashing
  • TWAIN_SetCurrentResolution(100)
  • How to detect camera capture button without blocking video going to another app
  • Can I save the scanned image as a PDF?
  • Does TwainDSM.DLL Replace Twain_32.dll
  • Contact Us
Privacy Policy • Copyright © 2019 TWAIN Working Group • by iHwy, Inc.

Log in