Update of /cvsroot/pywin32/pywin32/com/win32comext/axcontrol/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28869
Modified Files:
AXControl.cpp PyIOleCommandTarget.cpp
Log Message:
Complete support for OLECMD in IOleCommandTarget, and add some relevant
constants. Thanks to Leonard Ritter and Robert Förtsch for their
example/test code for this.
Index: PyIOleCommandTarget.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/axcontrol/src/PyIOleCommandTarget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PyIOleCommandTarget.cpp 3 Dec 2005 03:46:15 -0000 1.1
--- PyIOleCommandTarget.cpp 13 Feb 2006 12:20:40 -0000 1.2
***************
*** 5,8 ****
--- 5,25 ----
#include "PyIOleCommandTarget.h"
+ static BOOL FillOLECMDsWithSequence(OLECMD *pCmds, UINT ncmds, PyObject *obCmds)
+ {
+ for (UINT i=0;i<ncmds;i++) {
+ OLECMD *pThis = pCmds + i;
+ PyObject *sub = PySequence_GetItem(obCmds, i);
+ if (!sub)
+ return FALSE;
+ if (!PyArg_ParseTuple(sub, "ii", &pThis->cmdID, &pThis->cmdf)) {
+ PyErr_Format(PyExc_TypeError, "Element %d of command buffer was not a tuple of 2 integers", i);
+ Py_DECREF(sub);
+ return FALSE;
+ }
+ Py_DECREF(sub);
+ }
+ return TRUE;
+ }
+
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
***************
*** 51,55 ****
int ncmds = PySequence_Length(obCmds);
- int i;
HRESULT hr;
// From here, exit via 'goto done'
--- 68,71 ----
***************
*** 67,82 ****
goto done;
}
! for (i=0;i<ncmds;i++) {
! OLECMD *pThis = pCmds + i;
! PyObject *sub = PySequence_GetItem(obCmds, i);
! if (!sub)
! goto done;
! if (!PyArg_ParseTuple(sub, "ii", &pThis->cmdID, &pThis->cmdf)) {
! PyErr_Format(PyExc_TypeError, "Element %d of command buffer was not a tuple of 2 integers", i);
! Py_DECREF(sub);
! goto done;
! }
! Py_DECREF(sub);
! }
{ // scope to prevent goto warning.
PY_INTERFACE_PRECALL;
--- 83,88 ----
goto done;
}
! if (!FillOLECMDsWithSequence(pCmds, ncmds, obCmds))
! goto done;
{ // scope to prevent goto warning.
PY_INTERFACE_PRECALL;
***************
*** 183,191 ****
Py_BuildValue("ll", prgCmds[i].cmdID, prgCmds[i].cmdf));
}
! PyObject *obTest = Py_None; // tbd
PyObject *result;
! HRESULT hr=InvokeViaPolicy("QueryStatus", &result, "NNO", obGUID, cmds, obTest);
if (FAILED(hr)) return hr;
Py_DECREF(result);
return hr;
}
--- 189,239 ----
Py_BuildValue("ll", prgCmds[i].cmdID, prgCmds[i].cmdf));
}
! PyObject *obText;
! if (!pCmdText) {
! obText = Py_None;
! Py_INCREF(Py_None);
! } else
! obText = PyInt_FromLong(pCmdText->cmdtextf);
PyObject *result;
! HRESULT hr=InvokeViaPolicy("QueryStatus", &result, "NNN", obGUID, cmds, obText);
if (FAILED(hr)) return hr;
+
+ BOOL ok = PyArg_ParseTuple(result, "OO", &cmds, &obText);
+ if (ok) {
+ if (pCmdText == NULL) {
+ if (obText != Py_None) {
+ PyErr_SetString(PyExc_ValueError,
+ "String value returned but caller didn't request it (check the 3rd param!)");
+ ok = FALSE;
+ }
+ } else {
+ PyWin_AutoFreeBstr tempString;
+ ok = PyWinObject_AsAutoFreeBstr(obText, &tempString);
+ if (ok) {
+ UINT strLen = SysStringLen(tempString);
+ UINT nwrite = min(strLen, pCmdText->cwBuf);
+ wcsncpy(pCmdText->rgwz, (WCHAR *)(BSTR)tempString,
+ nwrite);
+ pCmdText->cwActual = nwrite;
+ }
+ }
+ }
+ if (ok) {
+ if (!PySequence_Check(cmds)) {
+ PyErr_SetString(PyExc_TypeError, "OLECMD objects must be a sequence");
+ ok = FALSE;
+ }
+ if (ok && (UINT)PySequence_Length(cmds) != cCmds) {
+ PyErr_Format(PyExc_ValueError, "Sequence must have %d items (got %d)",
+ cCmds, PySequence_Length(cmds));
+ ok = FALSE;
+
+ }
+ if (ok)
+ ok = FillOLECMDsWithSequence(prgCmds, cCmds, cmds);
+ }
Py_DECREF(result);
+ if (!ok)
+ hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("QueryStatus");
return hr;
}
***************
*** 210,214 ****
HRESULT hr=InvokeViaPolicy("Exec", &result, "NllN", obGUID, nCmdID, nCmdexecopt, obpvaIn);
if (FAILED(hr)) return hr;
! hr = PyCom_VariantFromPyObject(result, pvaOut);
Py_DECREF(result);
return hr;
--- 258,262 ----
HRESULT hr=InvokeViaPolicy("Exec", &result, "NllN", obGUID, nCmdID, nCmdexecopt, obpvaIn);
if (FAILED(hr)) return hr;
! hr = pvaOut ? PyCom_VariantFromPyObject(result, pvaOut) : S_OK;
Py_DECREF(result);
return hr;
Index: AXControl.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/axcontrol/src/AXControl.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AXControl.cpp 3 Dec 2005 03:46:15 -0000 1.5
--- AXControl.cpp 13 Feb 2006 12:20:40 -0000 1.6
***************
*** 352,355 ****
ADD_CONSTANT(OLECLOSE_SAVEIFDIRTY); // @const axcontrol|OLECLOSE_SAVEIFDIRTY|The object should be saved if it is dirty.
ADD_CONSTANT(OLECLOSE_NOSAVE); // @const axcontrol|OLECLOSE_NOSAVE|The object should not be saved, even if it is dirty. This flag is typically used when an object is being deleted.
! ADD_CONSTANT(OLECLOSE_PROMPTSAVE); // @const axcontrol|OLECLOSE_PROMPTSAVE|If the object is dirty, the <om PyIOleObject.Close> implementation should display a dialog box to let the end user determine whether to save the object. However, if the object is in the running state but its user interface is invisible, the end user should not be prompted, and the close should be handled as if OLECLOSE_SAVEIFDIRTY had been specified.
}
--- 352,365 ----
ADD_CONSTANT(OLECLOSE_SAVEIFDIRTY); // @const axcontrol|OLECLOSE_SAVEIFDIRTY|The object should be saved if it is dirty.
ADD_CONSTANT(OLECLOSE_NOSAVE); // @const axcontrol|OLECLOSE_NOSAVE|The object should not be saved, even if it is dirty. This flag is typically used when an object is being deleted.
! ADD_CONSTANT(OLECLOSE_PROMPTSAVE); // @const axcontrol|OLECLOSE_PROMPTSAVE|If the object is dirty, the <om PyIOleObject.Close> implementation should display a dialog box to let the end user determine whether to save the object. However, if the object is in the running state but its user interface is invisible, the end user should not be prompted, and the close should be handled as if OLECLOSE_SAVEIFDIRTY had been specified.
!
! ADD_CONSTANT(OLECMDTEXTF_NONE); // @const axcontrol|OLECMDTEXTF_NONE|
! ADD_CONSTANT(OLECMDTEXTF_NAME); // @const axcontrol|OLECMDTEXTF_NAME|
! ADD_CONSTANT(OLECMDTEXTF_STATUS); // @const axcontrol|OLECMDTEXTF_STATUS|
!
! ADD_CONSTANT(OLECMDF_SUPPORTED); // @const axcontrol|OLECMDF_SUPPORTED|
! ADD_CONSTANT(OLECMDF_ENABLED); // @const axcontrol|OLECMDF_ENABLED|
! ADD_CONSTANT(OLECMDF_LATCHED); // @const axcontrol|OLECMDF_LATCHED|
! ADD_CONSTANT(OLECMDF_NINCHED); // @const axcontrol|OLECMDF_NINCHED|
!
}
|