Forum Replies Created
-
AuthorPosts
-
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;
}Thanks Mark, I really appreciate your help on this.
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?
-
AuthorPosts