|
From: <jim...@us...> - 2009-06-10 02:02:39
|
Revision: 34
http://twain-samples.svn.sourceforge.net/twain-samples/?rev=34&view=rev
Author: jim0watters
Date: 2009-06-09 14:43:26 +0000 (Tue, 09 Jun 2009)
Log Message:
-----------
Mark read only caps in displayed list with 'r'
use fewer globals
Modified Paths:
--------------
trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp
trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.h
trunk/TWAIN-Samples/Twain_App_sample01/src/main.cpp
trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfc.rc
trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.cpp
trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.h
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp 2009-06-09 14:43:26 UTC (rev 34)
@@ -124,6 +124,7 @@
: m_DSMState(1)
, m_pDataSource(NULL)
, m_pExtImageInfo(NULL)
+, m_DSMessage(-1)
{
// fill our identity structure
fillIdentity(m_MyInfo);
@@ -227,8 +228,8 @@
if(!LoadDSMLib(kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME))
{
- printError(0, "The DSM could not be opened. Please ensure that it is installed into a directory that is in the library path:");
- printError(0, kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME);
+ PrintCMDMessage("The DSM could not be opened. Please ensure that it is installed into a directory that is in the library path:");
+ PrintCMDMessage(kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME);
return;
}
else
@@ -452,7 +453,14 @@
// Transition application to state 4
m_DSMState = 4;
- callback.CallBackProc = (TW_MEMREF)DSMCallback;
+ callback.CallBackProc = (TW_MEMREF)DSMCallback;
+ /* RefCon, On 32bit Could be used to store a pointer to this class to help
+ passing the message on to be processed. But RefCon is too small to store
+ a pointer on 64bit. For 64bit RefCon could storing an index to some
+ global memory array. But if there is only one instance of the Application
+ Class connecting to the DSM then the single global pointer to the
+ application class can be used, and the RefCon can be ignored as we do here. */
+ callback.RefCon = 0;
if(TWRC_SUCCESS != (twrc = DSM_Entry(DG_CONTROL, DAT_CALLBACK, MSG_REGISTER_CALLBACK, (TW_MEMREF)&callback)))
{
@@ -1455,7 +1463,50 @@
return CondCode;
}
+//////////////////////////////////////////////////////////////////////////////
+TW_INT16 TwainApp::QuerySupport_CAP(TW_UINT16 _cap, TW_UINT32 &_QS)
+{
+ if(m_DSMState < 4)
+ {
+ PrintCMDMessage("You need to open a data source first.\n");
+ return TWCC_SEQERROR;
+ }
+ TW_CAPABILITY cap = {0};
+ cap.Cap = _cap;
+ cap.hContainer = 0;
+ cap.ConType = TWON_ONEVALUE;
+ _QS = 0;
+ // capability structure is set, make the call to the source now
+ TW_UINT16 twrc = DSM_Entry( DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, (TW_MEMREF)&cap);
+
+ switch(twrc)
+ {
+ case TWRC_FAILURE:
+ default:
+ {
+ string strErr = "Failed to querry support the capability: [";
+ strErr += convertCAP_toString(_cap);
+ strErr += "]";
+
+ printError(m_pDataSource, strErr);
+ }
+ break;
+
+ case TWRC_SUCCESS:
+ if(cap.ConType == TWON_ONEVALUE)
+ {
+ pTW_ONEVALUE pVal = (pTW_ONEVALUE)_DSM_LockMemory(cap.hContainer);
+ _QS = pVal->Item;
+ _DSM_UnlockMemory(cap.hContainer);
+ }
+ _DSM_Free(cap.hContainer);
+ break;
+ }
+
+ return twrc;
+}
+
//////////////////////////////////////////////////////////////////////////////
TW_UINT16 TwainApp::set_CapabilityOneValue(TW_UINT16 Cap, const int _value, TW_UINT16 _type)
{
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.h
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.h 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.h 2009-06-09 14:43:26 UTC (rev 34)
@@ -254,6 +254,14 @@
TW_INT16 get_CAP(TW_CAPABILITY& _cap);
/**
+* Query Support messages of the capability.
+* @param[in] _cap the capability id to lookup.
+* @param[out] _QS the Query Support of the cap
+* @return a valid TWRC_xxxx return code
+*/
+ TW_INT16 QuerySupport_CAP(TW_UINT16 _cap, TW_UINT32 &_QS);
+
+/**
* Returns a pointer to the applications identity structure.
* @return a TW_IDENTITY pointer to the applications identity struct.
*/
@@ -302,6 +310,7 @@
void updateEXIMAGEINFO();
int m_DSMState; /**< The current TWAIN state of the dsm (2-7) */
+ TW_UINT16 m_DSMessage; /**< Statis to indicate if we are waiting for DS */
protected:
/**
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/main.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/main.cpp 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/main.cpp 2009-06-09 14:43:26 UTC (rev 34)
@@ -61,7 +61,6 @@
//////////////////////////////////////////////////////////////////////////////
// Global Variables
-TW_UINT16 gDSMessage; /**< global statis to indicate if we are waiting for DS */
TwainAppCMD *gpTwainApplicationCMD; /**< The main application */
extern bool gUSE_CALLBACKS; // defined in TwainApp.cpp
@@ -263,7 +262,7 @@
*/
void EnableDS()
{
- gDSMessage = 0;
+ gpTwainApplicationCMD->m_DSMessage = 0;
// -Enable the data source. This puts us in state 5 which means that we
// have to wait for the data source to tell us to move to state 6 and
@@ -277,7 +276,7 @@
}
// now we have to wait until we hear something back from the DS.
- while(!gDSMessage)
+ while(!gpTwainApplicationCMD->m_DSMessage)
{
// If we are using callbacks, there is nothing to do here except sleep
@@ -309,7 +308,7 @@
case MSG_CLOSEDSREQ:
case MSG_CLOSEDSOK:
case MSG_NULL:
- gDSMessage = twEvent.TWMessage;
+ gpTwainApplicationCMD->m_DSMessage = twEvent.TWMessage;
break;
default:
@@ -329,7 +328,7 @@
// At this point the source has sent us a callback saying that it is ready to
// transfer the image.
- if(gDSMessage == MSG_XFERREADY)
+ if(gpTwainApplicationCMD->m_DSMessage == MSG_XFERREADY)
{
// move to state 6 as a result of the data source. We can start a scan now.
gpTwainApplicationCMD->m_DSMState = 6;
@@ -379,7 +378,7 @@
case MSG_CLOSEDSREQ:
case MSG_CLOSEDSOK:
case MSG_NULL:
- gDSMessage = _MSG;
+ gpTwainApplicationCMD->m_DSMessage = _MSG;
break;
default:
Modified: trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfc.rc
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfc.rc 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfc.rc 2009-06-09 14:43:26 UTC (rev 34)
@@ -129,8 +129,8 @@
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 2,0,5,0
- PRODUCTVERSION 2,0,5,0
+ FILEVERSION 2,0,6,0
+ PRODUCTVERSION 2,0,6,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -147,12 +147,12 @@
BEGIN
VALUE "CompanyName", "TWAIN Working Group"
VALUE "FileDescription", "Sample TWAIN Application"
- VALUE "FileVersion", "2.0.5.0"
+ VALUE "FileVersion", "2.0.6.0"
VALUE "InternalName", "SampleApp.exe"
VALUE "LegalCopyright", "(c) TWAIN Working Group. All rights reserved."
VALUE "OriginalFilename", "SampleApp.exe"
VALUE "ProductName", "SampleApp"
- VALUE "ProductVersion", "2.0.5.0"
+ VALUE "ProductVersion", "2.0.6.0"
END
END
BLOCK "VarFileInfo"
Modified: trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.cpp 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.cpp 2009-06-09 14:43:26 UTC (rev 34)
@@ -40,8 +40,6 @@
#include "mfc.h"
#include "mfcDlgConfigure.h"
-#include "CommonTWAIN.h"
-#include "..\src\twainapp.h"
#include "..\src\dsminterface.h"
#include "TwainString.h"
#include ".\TW_Array_Dlg.h"
@@ -56,7 +54,6 @@
*/
TwainApp *g_pTWAINApp = NULL;
extern bool gUSE_CALLBACKS; // defined in TwainApp.cpp
-TW_UINT16 gDSMessage; /**< global statis to indicate if we are waiting for DS */
//////////////////////////////////////////////////////////////////////////////
/**
@@ -73,30 +70,35 @@
TW_UINT16 _MSG,
TW_MEMREF _pData)
{
- TW_UINT16 twrc = TWRC_SUCCESS;
+ TW_UINT16 twrc = TWRC_FAILURE;
+ // _pData stores the RefCon from the when the callback was registered
+ // RefCon is a TW_INT32 and can not store a pointer for 64bit
// we are only waiting for callbacks from our datasource, so validate
// that the originator.
- if( 0 == _pOrigin ||
- _pOrigin->Id != g_pTWAINApp->getDataSource()->Id )
+ if( 0 != _pOrigin
+ && 0 != g_pTWAINApp
+ && g_pTWAINApp->getDataSource()
+ && _pOrigin->Id == g_pTWAINApp->getDataSource()->Id )
{
- return TWRC_FAILURE;
+ switch (_MSG)
+ {
+ case MSG_XFERREADY:
+ case MSG_CLOSEDSREQ:
+ case MSG_CLOSEDSOK:
+ case MSG_NULL:
+ g_pTWAINApp->m_DSMessage = _MSG;
+ twrc = TWRC_SUCCESS;
+ break;
+
+ default:
+ TRACE("Error - Unknown message in callback routine");
+ g_pTWAINApp->m_DSMessage = MSG_NULL;
+ twrc = TWRC_FAILURE;
+ break;
+ }
}
-
- switch (_MSG)
- {
- case MSG_XFERREADY:
- case MSG_CLOSEDSREQ:
- case MSG_CLOSEDSOK:
- case MSG_NULL:
- gDSMessage = _MSG;
- break;
- default:
- TRACE("Error - Unknown message in callback routine");
- twrc = TWRC_FAILURE;
- break;
- }
return twrc;
}
@@ -228,6 +230,7 @@
TW_UINT32 nCount = 0;
TW_CAPABILITY CapSupportedCaps;
pTW_ARRAY_UINT16 pCapSupCaps = 0;
+ pTW_IDENTITY pID = g_pTWAINApp->getDataSource();
m_lst_Caps.ResetContent();
@@ -255,11 +258,14 @@
// we are not listing these CAPABILITIES
if(pCapSupCaps->ItemList[i] != CAP_SUPPORTEDCAPS)
{
- TW_CAPABILITY Cap;
+ TW_UINT32 QS = 0;
+ bool bReadOnly = false;
+ TW_CAPABILITY Cap = {0};
// get the capability that is supported
Cap.Cap = pCapSupCaps->ItemList[i];
Cap.hContainer = 0;
+ Cap.ConType = TWON_DONTCARE16;
name = convertCAP_toString(Cap.Cap);
sz = pDC->GetTextExtent(name);
@@ -269,6 +275,7 @@
}
TW_UINT16 CondCode = g_pTWAINApp->get_CAP(Cap);
+ g_pTWAINApp->QuerySupport_CAP(Cap.Cap, QS);
if(CondCode==TWCC_SUCCESS)
{
@@ -281,7 +288,6 @@
TW_UINT16 type = pCap->ItemType;
_DSM_UnlockMemory(Cap.hContainer);
-
switch(type)
{
case TWTY_INT8:
@@ -334,7 +340,8 @@
break;
}
}
- str.Format("%s:\t%s", name, value);
+ bReadOnly = ( QS && !(QS & TWQC_SET) )? true : false;
+ str.Format("%s:\t%s %c", name, value, bReadOnly?'r':' ');
int index = m_lst_Caps.InsertString( -1, str );
if(LB_ERR != index)
{
@@ -507,7 +514,13 @@
switch(pCapPT->ItemType)
{
+ case TWTY_INT8:
+ case TWTY_INT16:
+ case TWTY_INT32:
+ case TWTY_UINT8:
case TWTY_UINT16:
+ case TWTY_UINT32:
+ case TWTY_BOOL:
{
for(TW_UINT32 x=0; x<pCapPT->NumItems; ++x)
{
@@ -519,6 +532,23 @@
}
break;
+ case TWTY_STR32:
+ case TWTY_STR64:
+ case TWTY_STR128:
+ case TWTY_STR255:
+ {
+ string sVal;
+ for(TW_UINT32 x=0; x<pCapPT->NumItems; ++x)
+ {
+ getcurrent(pCap, sVal);
+ str = sVal.c_str();
+ pDlg->m_itemString.Add(str);
+ pDlg->m_itemData.Add(x);
+ }
+ pDlg->m_SelectionData = pCapPT->CurrentIndex;
+ break;
+ }
+
case TWTY_FIX32:
{
float valf;
@@ -549,7 +579,6 @@
{
pDlg->m_SelectionData = pCapPT->Item? FALSE:TRUE;
nResponse = IDOK;
-
}
break;
@@ -566,7 +595,7 @@
void Cmfc32DlgConfigure::OnBnClickedScan()
{
- gDSMessage = 0;
+ g_pTWAINApp->m_DSMessage = (TW_UINT16)-1;
UpdateData(true);
@@ -582,7 +611,7 @@
}
// now we have to wait until we hear something back from the DS.
- while(!gDSMessage)
+ while((TW_UINT16)-1 == g_pTWAINApp->m_DSMessage)
{
// If we are using callbacks, there is nothing to do here except sleep
@@ -614,7 +643,7 @@
case MSG_CLOSEDSREQ:
case MSG_CLOSEDSOK:
case MSG_NULL:
- gDSMessage = twEvent.TWMessage;
+ g_pTWAINApp->m_DSMessage = twEvent.TWMessage;
break;
default:
@@ -632,7 +661,7 @@
// At this point the source has sent us a callback saying that it is ready to
// transfer the image.
- if(gDSMessage == MSG_XFERREADY)
+ if(g_pTWAINApp->m_DSMessage == MSG_XFERREADY)
{
// move to state 6 as a result of the data source. We can start a scan now.
g_pTWAINApp->m_DSMState = 6;
@@ -672,7 +701,7 @@
switch ( (TW_UINT16)mech )
{
case TWSX_NATIVE:
- g_pTWAINApp->initiateTransfer_Native();
+ g_pTWAINApp->initiateTransfer_Native();
break;
case TWSX_FILE:
Modified: trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.h
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.h 2009-05-12 15:12:09 UTC (rev 33)
+++ trunk/TWAIN-Samples/Twain_App_sample01/visual_studio_mfc/mfcDlgConfigure.h 2009-06-09 14:43:26 UTC (rev 34)
@@ -43,6 +43,7 @@
#endif
#include "CommonTWAIN.h"
+#include "..\src\twainapp.h"
class CTW_Array_Dlg;
@@ -69,8 +70,8 @@
// Implementation
protected:
- HICON m_hIcon;
- int m_nIndex;
+ HICON m_hIcon;
+ int m_nIndex;
// Generated message map functions
virtual BOOL OnInitDialog();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|