1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <string.h> 28cdf0e10cSrcweir #include <math.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #if defined( WNT ) 31cdf0e10cSrcweir #include <tools/svwin.h> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #ifdef OS2 34cdf0e10cSrcweir #include <svpm.h> 35cdf0e10cSrcweir #endif // OS2 36cdf0e10cSrcweir #include <vos/module.hxx> 37cdf0e10cSrcweir #include <tools/stream.hxx> 38cdf0e10cSrcweir #include <vcl/svapp.hxx> 39cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 40cdf0e10cSrcweir #include <vcl/sysdata.hxx> 41cdf0e10cSrcweir #include "twain.hxx" 42cdf0e10cSrcweir 43cdf0e10cSrcweir // ----------- 44cdf0e10cSrcweir // - Defines - 45cdf0e10cSrcweir // ----------- 46cdf0e10cSrcweir 47cdf0e10cSrcweir #define PFUNC (*pDSM) 48cdf0e10cSrcweir #define FIXTODOUBLE( nFix ) ((double)nFix.Whole+(double)nFix.Frac/65536.) 49cdf0e10cSrcweir #define FIXTOLONG( nFix ) ((long)floor(FIXTODOUBLE(nFix)+0.5)) 50cdf0e10cSrcweir 51cdf0e10cSrcweir #if defined WNT 52cdf0e10cSrcweir #define TWAIN_LIBNAME "TWAIN_32.DLL" 53cdf0e10cSrcweir #define TWAIN_FUNCNAME "DSM_Entry" 54cdf0e10cSrcweir #elif defined OS2 55cdf0e10cSrcweir #define TWAIN_LIBNAME "twain" 56cdf0e10cSrcweir #define TWAIN_FUNCNAME "DSM_ENTRY" 57cdf0e10cSrcweir #endif 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ----------- 60cdf0e10cSrcweir // - Statics - 61cdf0e10cSrcweir // ----------- 62cdf0e10cSrcweir 63cdf0e10cSrcweir static ImpTwain* pImpTwainInstance = NULL; 64cdf0e10cSrcweir 65cdf0e10cSrcweir // --------- 66cdf0e10cSrcweir // - Procs - 67cdf0e10cSrcweir // --------- 68cdf0e10cSrcweir 69cdf0e10cSrcweir #ifdef OS2 70cdf0e10cSrcweir 71cdf0e10cSrcweir #define PTWAINMSG QMSG* 72cdf0e10cSrcweir 73cdf0e10cSrcweir MRESULT EXPENTRY TwainWndProc( HWND hWnd, ULONG nMsg, MPARAM nParam1, MPARAM nParam2 ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir return (MRESULT) TRUE; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir 79cdf0e10cSrcweir #else // OS2 80cdf0e10cSrcweir 81cdf0e10cSrcweir #define PTWAINMSG MSG* 82cdf0e10cSrcweir 83cdf0e10cSrcweir // ------------------------------------------------------------------------- 84cdf0e10cSrcweir 85cdf0e10cSrcweir LRESULT CALLBACK TwainWndProc( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return DefWindowProc( hWnd, nMsg, nPar1, nPar2 ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir // ------------------------------------------------------------------------- 91cdf0e10cSrcweir 92cdf0e10cSrcweir LRESULT CALLBACK TwainMsgProc( int nCode, WPARAM wParam, LPARAM lParam ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir MSG* pMsg = (MSG*) lParam; 95cdf0e10cSrcweir 96cdf0e10cSrcweir if( ( nCode < 0 ) || 97cdf0e10cSrcweir ( pImpTwainInstance->hTwainWnd != pMsg->hwnd ) || 98cdf0e10cSrcweir !pImpTwainInstance->ImplHandleMsg( (void*) lParam ) ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir return CallNextHookEx( pImpTwainInstance->hTwainHook, nCode, wParam, lParam ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir else 103cdf0e10cSrcweir { 104cdf0e10cSrcweir pMsg->message = WM_USER; 105cdf0e10cSrcweir pMsg->lParam = 0; 106cdf0e10cSrcweir 107cdf0e10cSrcweir return 0; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir #endif // OS2 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ------------ 114cdf0e10cSrcweir // - ImpTwain - 115cdf0e10cSrcweir // ------------ 116cdf0e10cSrcweir 117cdf0e10cSrcweir ImpTwain::ImpTwain( const Link& rNotifyLink ) : 118cdf0e10cSrcweir aNotifyLink ( rNotifyLink ), 119cdf0e10cSrcweir pDSM ( NULL ), 120cdf0e10cSrcweir pMod ( NULL ), 121cdf0e10cSrcweir hTwainWnd ( 0 ), 122cdf0e10cSrcweir hTwainHook ( 0 ), 123cdf0e10cSrcweir nCurState ( 1 ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir pImpTwainInstance = this; 126cdf0e10cSrcweir 127cdf0e10cSrcweir aAppIdent.Id = 0; 128cdf0e10cSrcweir aAppIdent.Version.MajorNum = 1; 129cdf0e10cSrcweir aAppIdent.Version.MinorNum = 0; 130cdf0e10cSrcweir aAppIdent.Version.Language = TWLG_USA; 131cdf0e10cSrcweir aAppIdent.Version.Country = TWCY_USA; 132cdf0e10cSrcweir aAppIdent.ProtocolMajor = TWON_PROTOCOLMAJOR; 133cdf0e10cSrcweir aAppIdent.ProtocolMinor = TWON_PROTOCOLMINOR; 134cdf0e10cSrcweir aAppIdent.SupportedGroups = DG_IMAGE | DG_CONTROL; 135cdf0e10cSrcweir strcpy( aAppIdent.Version.Info, "6.0" ); 136cdf0e10cSrcweir strcpy( aAppIdent.Manufacturer, "Sun Microsystems"); 137cdf0e10cSrcweir strcpy( aAppIdent.ProductFamily,"Office"); 138cdf0e10cSrcweir strcpy( aAppIdent.ProductName, "Office"); 139cdf0e10cSrcweir 140cdf0e10cSrcweir #ifdef OS2 141cdf0e10cSrcweir 142cdf0e10cSrcweir hAB = Sysdepen::GethAB(); 143cdf0e10cSrcweir ImplFallback( TWAIN_EVENT_QUIT ); 144cdf0e10cSrcweir // hTwainWnd = WinCreateWindow( HWND_DESKTOP, WC_FRAME, "dummy", 0, 0, 0, 0, 0, HWND_DESKTOP, HWND_BOTTOM, 0, 0, 0 ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir #else 147cdf0e10cSrcweir 148cdf0e10cSrcweir HWND hParentWnd = HWND_DESKTOP; 149cdf0e10cSrcweir WNDCLASS aWc = { 0, &TwainWndProc, 0, sizeof( WNDCLASS ), GetModuleHandle( NULL ), 150cdf0e10cSrcweir NULL, NULL, NULL, NULL, "TwainClass" }; 151cdf0e10cSrcweir 152cdf0e10cSrcweir RegisterClass( &aWc ); 153cdf0e10cSrcweir hTwainWnd = CreateWindowEx( WS_EX_TOPMOST, aWc.lpszClassName, "TWAIN", 0, 0, 0, 0, 0, hParentWnd, NULL, aWc.hInstance, 0 ); 154cdf0e10cSrcweir hTwainHook = SetWindowsHookEx( WH_GETMESSAGE, &TwainMsgProc, NULL, GetCurrentThreadId() ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir #endif 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // ----------------------------------------------------------------------------- 160cdf0e10cSrcweir 161cdf0e10cSrcweir ImpTwain::~ImpTwain() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166cdf0e10cSrcweir 167cdf0e10cSrcweir void ImpTwain::Destroy() 168cdf0e10cSrcweir { 169cdf0e10cSrcweir ImplFallback( TWAIN_EVENT_NONE ); 170cdf0e10cSrcweir Application::PostUserEvent( LINK( this, ImpTwain, ImplDestroyHdl ), NULL ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir // ----------------------------------------------------------------------------- 174cdf0e10cSrcweir 175cdf0e10cSrcweir sal_Bool ImpTwain::SelectSource() 176cdf0e10cSrcweir { 177cdf0e10cSrcweir TW_UINT16 nRet = TWRC_FAILURE; 178cdf0e10cSrcweir 179cdf0e10cSrcweir if( !!aBitmap ) 180cdf0e10cSrcweir aBitmap = Bitmap(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir ImplOpenSourceManager(); 183cdf0e10cSrcweir 184cdf0e10cSrcweir if( 3 == nCurState ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir TW_IDENTITY aIdent; 187cdf0e10cSrcweir 188cdf0e10cSrcweir aIdent.Id = 0, aIdent.ProductName[ 0 ] = '\0'; 189cdf0e10cSrcweir aNotifyLink.Call( (void*) TWAIN_EVENT_SCANNING ); 190cdf0e10cSrcweir nRet = PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &aIdent ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir ImplFallback( TWAIN_EVENT_QUIT ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir return( nRet == TWRC_SUCCESS || nRet == TWRC_CANCEL ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // ----------------------------------------------------------------------------- 199cdf0e10cSrcweir 200cdf0e10cSrcweir sal_Bool ImpTwain::InitXfer() 201cdf0e10cSrcweir { 202cdf0e10cSrcweir sal_Bool bRet = sal_False; 203cdf0e10cSrcweir 204cdf0e10cSrcweir if( !!aBitmap ) 205cdf0e10cSrcweir aBitmap = Bitmap(); 206cdf0e10cSrcweir 207cdf0e10cSrcweir ImplOpenSourceManager(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir if( 3 == nCurState ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir ImplOpenSource(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir if( 4 == nCurState ) 214cdf0e10cSrcweir bRet = ImplEnableSource(); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir if( !bRet ) 218cdf0e10cSrcweir ImplFallback( TWAIN_EVENT_QUIT ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir return bRet; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir // ----------------------------------------------------------------------------- 224cdf0e10cSrcweir 225cdf0e10cSrcweir Bitmap ImpTwain::GetXferBitmap() 226cdf0e10cSrcweir { 227cdf0e10cSrcweir Bitmap aRet( aBitmap ); 228cdf0e10cSrcweir aBitmap = Bitmap(); 229cdf0e10cSrcweir return aRet; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // ----------------------------------------------------------------------------- 233cdf0e10cSrcweir 234cdf0e10cSrcweir void ImpTwain::ImplOpenSourceManager() 235cdf0e10cSrcweir { 236cdf0e10cSrcweir if( 1 == nCurState ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir pMod = new vos:: OModule (); 239cdf0e10cSrcweir 240cdf0e10cSrcweir if( pMod->load( TWAIN_LIBNAME ) ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir nCurState = 2; 243cdf0e10cSrcweir 244cdf0e10cSrcweir if( ( ( pDSM = (DSMENTRYPROC) pMod->getSymbol( TWAIN_FUNCNAME ) ) != NULL ) && 245cdf0e10cSrcweir ( PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, &hTwainWnd ) == TWRC_SUCCESS ) ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir nCurState = 3; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir else 251cdf0e10cSrcweir { 252cdf0e10cSrcweir delete pMod; 253cdf0e10cSrcweir pMod = NULL; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir // ----------------------------------------------------------------------------- 259cdf0e10cSrcweir 260cdf0e10cSrcweir void ImpTwain::ImplOpenSource() 261cdf0e10cSrcweir { 262cdf0e10cSrcweir if( 3 == nCurState ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir if( ( PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &aSrcIdent ) == TWRC_SUCCESS ) && 265cdf0e10cSrcweir ( PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &aSrcIdent ) == TWRC_SUCCESS ) ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir #ifdef OS2 268cdf0e10cSrcweir 269cdf0e10cSrcweir // negotiate capabilities 270cdf0e10cSrcweir 271cdf0e10cSrcweir #else 272cdf0e10cSrcweir 273cdf0e10cSrcweir TW_CAPABILITY aCap = { CAP_XFERCOUNT, TWON_ONEVALUE, GlobalAlloc( GHND, sizeof( TW_ONEVALUE ) ) }; 274cdf0e10cSrcweir TW_ONEVALUE* pVal = (TW_ONEVALUE*) GlobalLock( aCap.hContainer ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir pVal->ItemType = TWTY_INT16, pVal->Item = 1; 277cdf0e10cSrcweir GlobalUnlock( aCap.hContainer ); 278cdf0e10cSrcweir PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_CAPABILITY, MSG_SET, &aCap ); 279cdf0e10cSrcweir GlobalFree( aCap.hContainer ); 280cdf0e10cSrcweir #endif 281cdf0e10cSrcweir 282cdf0e10cSrcweir nCurState = 4; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir // ----------------------------------------------------------------------------- 288cdf0e10cSrcweir 289cdf0e10cSrcweir BOOL ImpTwain::ImplEnableSource() 290cdf0e10cSrcweir { 291cdf0e10cSrcweir BOOL bRet = FALSE; 292cdf0e10cSrcweir 293cdf0e10cSrcweir if( 4 == nCurState ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir TW_USERINTERFACE aUI = { TRUE, TRUE, hTwainWnd }; 296cdf0e10cSrcweir 297cdf0e10cSrcweir aNotifyLink.Call( (void*) TWAIN_EVENT_SCANNING ); 298cdf0e10cSrcweir nCurState = 5; 299cdf0e10cSrcweir 300cdf0e10cSrcweir if( PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, &aUI ) == TWRC_SUCCESS ) 301cdf0e10cSrcweir bRet = TRUE; 302cdf0e10cSrcweir else 303cdf0e10cSrcweir nCurState = 4; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir return bRet; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir // ----------------------------------------------------------------------------- 310cdf0e10cSrcweir 311cdf0e10cSrcweir BOOL ImpTwain::ImplHandleMsg( void* pMsg ) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir TW_UINT16 nRet; 314cdf0e10cSrcweir PTWAINMSG pMess = (PTWAINMSG) pMsg; 315cdf0e10cSrcweir TW_EVENT aEvt = { pMess, MSG_NULL }; 316cdf0e10cSrcweir 317cdf0e10cSrcweir nRet = PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, &aEvt ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir if( aEvt.TWMessage != MSG_NULL ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir switch( aEvt.TWMessage ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir case MSG_XFERREADY: 324cdf0e10cSrcweir { 325cdf0e10cSrcweir ULONG nEvent = TWAIN_EVENT_QUIT; 326cdf0e10cSrcweir 327cdf0e10cSrcweir if( 5 == nCurState ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir nCurState = 6; 330cdf0e10cSrcweir ImplXfer(); 331cdf0e10cSrcweir 332cdf0e10cSrcweir if( !!aBitmap ) 333cdf0e10cSrcweir nEvent = TWAIN_EVENT_XFER; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir ImplFallback( nEvent ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir break; 339cdf0e10cSrcweir 340cdf0e10cSrcweir case MSG_CLOSEDSREQ: 341cdf0e10cSrcweir ImplFallback( TWAIN_EVENT_QUIT ); 342cdf0e10cSrcweir break; 343cdf0e10cSrcweir 344cdf0e10cSrcweir default: 345cdf0e10cSrcweir break; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir } 348cdf0e10cSrcweir else 349cdf0e10cSrcweir nRet = TWRC_NOTDSEVENT; 350cdf0e10cSrcweir 351cdf0e10cSrcweir return( TWRC_DSEVENT == nRet ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir // ----------------------------------------------------------------------------- 355cdf0e10cSrcweir 356cdf0e10cSrcweir void ImpTwain::ImplXfer() 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if( nCurState == 6 ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir TW_IMAGEINFO aInfo; 361cdf0e10cSrcweir TW_UINT32 hDIB = 0; 362cdf0e10cSrcweir long nWidth = aInfo.ImageWidth; 363cdf0e10cSrcweir long nHeight = aInfo.ImageLength; 364cdf0e10cSrcweir long nXRes = FIXTOLONG( aInfo.XResolution ); 365cdf0e10cSrcweir long nYRes = FIXTOLONG( aInfo.YResolution ); 366cdf0e10cSrcweir 367cdf0e10cSrcweir if( PFUNC( &aAppIdent, &aSrcIdent, DG_IMAGE, DAT_IMAGEINFO, MSG_GET, &aInfo ) == TWRC_SUCCESS ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir nWidth = aInfo.ImageWidth; 370cdf0e10cSrcweir nHeight = aInfo.ImageLength; 371cdf0e10cSrcweir nXRes = FIXTOLONG( aInfo.XResolution ); 372cdf0e10cSrcweir nYRes = FIXTOLONG( aInfo.YResolution ); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir else 375cdf0e10cSrcweir nWidth = nHeight = nXRes = nYRes = -1L; 376cdf0e10cSrcweir 377cdf0e10cSrcweir switch( PFUNC( &aAppIdent, &aSrcIdent, DG_IMAGE, DAT_IMAGENATIVEXFER, MSG_GET, &hDIB ) ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir case( TWRC_CANCEL ): 380cdf0e10cSrcweir nCurState = 7; 381cdf0e10cSrcweir break; 382cdf0e10cSrcweir 383cdf0e10cSrcweir case( TWRC_XFERDONE ): 384cdf0e10cSrcweir { 385cdf0e10cSrcweir #ifdef OS2 386cdf0e10cSrcweir 387cdf0e10cSrcweir // get OS/2-Bitmap 388cdf0e10cSrcweir 389cdf0e10cSrcweir #else // OS2 390cdf0e10cSrcweir const ULONG nSize = GlobalSize( (HGLOBAL) hDIB ); 391cdf0e10cSrcweir char* pBuf = (char*) GlobalLock( (HGLOBAL) hDIB ); 392cdf0e10cSrcweir 393cdf0e10cSrcweir if( pBuf ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir SvMemoryStream aMemStm; 396cdf0e10cSrcweir aMemStm.SetBuffer( pBuf, nSize, FALSE, nSize ); 397cdf0e10cSrcweir aBitmap.Read( aMemStm, FALSE ); 398cdf0e10cSrcweir GlobalUnlock( (HGLOBAL) hDIB ); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir GlobalFree( (HGLOBAL) hDIB ); 402cdf0e10cSrcweir #endif // OS2 403cdf0e10cSrcweir 404cdf0e10cSrcweir // set resolution of bitmap if neccessary 405cdf0e10cSrcweir if ( ( nXRes != -1 ) && ( nYRes != - 1 ) && ( nWidth != - 1 ) && ( nHeight != - 1 ) ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir const MapMode aMapMode( MAP_100TH_INCH, Point(), Fraction( 100, nXRes ), Fraction( 100, nYRes ) ); 408cdf0e10cSrcweir aBitmap.SetPrefMapMode( aMapMode ); 409cdf0e10cSrcweir aBitmap.SetPrefSize( Size( nWidth, nHeight ) ); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir nCurState = 7; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir break; 415cdf0e10cSrcweir 416cdf0e10cSrcweir default: 417cdf0e10cSrcweir break; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } 420cdf0e10cSrcweir } 421cdf0e10cSrcweir 422cdf0e10cSrcweir // ----------------------------------------------------------------------------- 423cdf0e10cSrcweir 424cdf0e10cSrcweir void ImpTwain::ImplFallback( ULONG nEvent ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir Application::PostUserEvent( LINK( this, ImpTwain, ImplFallbackHdl ), (void*) nEvent ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir // ----------------------------------------------------------------------------- 430cdf0e10cSrcweir 431cdf0e10cSrcweir IMPL_LINK( ImpTwain, ImplFallbackHdl, void*, pData ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir const ULONG nEvent = (ULONG) pData; 434cdf0e10cSrcweir sal_Bool bFallback = sal_True; 435cdf0e10cSrcweir 436cdf0e10cSrcweir switch( nCurState ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir case( 7 ): 439cdf0e10cSrcweir case( 6 ): 440cdf0e10cSrcweir { 441cdf0e10cSrcweir TW_PENDINGXFERS aXfers; 442cdf0e10cSrcweir 443cdf0e10cSrcweir if( PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, &aXfers ) == TWRC_SUCCESS ) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir if( aXfers.Count != 0 ) 446cdf0e10cSrcweir PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, &aXfers ); 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir nCurState = 5; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir break; 452cdf0e10cSrcweir 453cdf0e10cSrcweir case( 5 ): 454cdf0e10cSrcweir { 455cdf0e10cSrcweir TW_USERINTERFACE aUI = { TRUE, TRUE, hTwainWnd }; 456cdf0e10cSrcweir 457cdf0e10cSrcweir PFUNC( &aAppIdent, &aSrcIdent, DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, &aUI ); 458cdf0e10cSrcweir nCurState = 4; 459cdf0e10cSrcweir } 460cdf0e10cSrcweir break; 461cdf0e10cSrcweir 462cdf0e10cSrcweir case( 4 ): 463cdf0e10cSrcweir { 464cdf0e10cSrcweir PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &aSrcIdent ); 465cdf0e10cSrcweir nCurState = 3; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir break; 468cdf0e10cSrcweir 469cdf0e10cSrcweir case( 3 ): 470cdf0e10cSrcweir { 471cdf0e10cSrcweir PFUNC( &aAppIdent, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, &hTwainWnd ); 472cdf0e10cSrcweir nCurState = 2; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir break; 475cdf0e10cSrcweir 476cdf0e10cSrcweir case( 2 ): 477cdf0e10cSrcweir { 478cdf0e10cSrcweir delete pMod; 479cdf0e10cSrcweir pMod = NULL; 480cdf0e10cSrcweir nCurState = 1; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir break; 483cdf0e10cSrcweir 484cdf0e10cSrcweir default: 485cdf0e10cSrcweir { 486cdf0e10cSrcweir if( nEvent != TWAIN_EVENT_NONE ) 487cdf0e10cSrcweir aNotifyLink.Call( (void*) nEvent ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir bFallback = sal_False; 490cdf0e10cSrcweir } 491cdf0e10cSrcweir break; 492cdf0e10cSrcweir } 493cdf0e10cSrcweir 494cdf0e10cSrcweir if( bFallback ) 495cdf0e10cSrcweir ImplFallback( nEvent ); 496cdf0e10cSrcweir 497cdf0e10cSrcweir return 0L; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir // ----------------------------------------------------------------------------- 501cdf0e10cSrcweir 502cdf0e10cSrcweir IMPL_LINK( ImpTwain, ImplDestroyHdl, void*, p ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir #ifdef OS2 505cdf0e10cSrcweir 506cdf0e10cSrcweir if( hWndTwain ) 507cdf0e10cSrcweir WinDestroyWindow( hWndTwain ); 508cdf0e10cSrcweir 509cdf0e10cSrcweir // unset hook 510cdf0e10cSrcweir 511cdf0e10cSrcweir #else 512cdf0e10cSrcweir 513cdf0e10cSrcweir if( hTwainWnd ) 514cdf0e10cSrcweir DestroyWindow( hTwainWnd ); 515cdf0e10cSrcweir 516cdf0e10cSrcweir if( hTwainHook ) 517cdf0e10cSrcweir UnhookWindowsHookEx( hTwainHook ); 518cdf0e10cSrcweir 519cdf0e10cSrcweir #endif 520cdf0e10cSrcweir 521cdf0e10cSrcweir delete this; 522cdf0e10cSrcweir pImpTwainInstance = NULL; 523cdf0e10cSrcweir 524cdf0e10cSrcweir return 0L; 525cdf0e10cSrcweir } 526