43 #ifndef QT_NO_WIN_ACTIVEQT 46 # define QT_NO_QAXSCRIPT 47 #elif defined(Q_CC_BOR) && __BORLANDC__ < 0x560 48 # define QT_NO_QAXSCRIPT 59 #ifndef QT_NO_QAXSCRIPT 64 #include "../shared/qaxtypes.h" 87 #ifndef QT_NO_QAXSCRIPT 89 class QAxScriptSite :
public IActiveScriptSite,
public IActiveScriptSiteWindow
94 ULONG WINAPI AddRef();
96 HRESULT WINAPI QueryInterface(REFIID iid,
void **ppvObject);
98 HRESULT WINAPI GetLCID(LCID *plcid);
99 HRESULT WINAPI GetItemInfo(LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti);
100 HRESULT WINAPI GetDocVersionString(BSTR *pbstrVersion);
102 HRESULT WINAPI OnScriptTerminate(
const VARIANT *pvarResult,
const EXCEPINFO *pexcepinfo);
103 HRESULT WINAPI OnStateChange(SCRIPTSTATE ssScriptState);
104 HRESULT WINAPI OnScriptError(IActiveScriptError *pscripterror);
105 HRESULT WINAPI OnEnterScript();
106 HRESULT WINAPI OnLeaveScript();
108 HRESULT WINAPI GetWindow(HWND *phwnd);
109 HRESULT WINAPI EnableModeless(BOOL fEnable);
132 return InterlockedIncrement(&
ref);
140 LONG refCount = InterlockedDecrement(&
ref);
153 if (iid == IID_IUnknown)
154 *ppvObject = (IUnknown*)(IActiveScriptSite*)
this;
155 else if (iid == IID_IActiveScriptSite)
156 *ppvObject = (IActiveScriptSite*)
this;
157 else if (iid == IID_IActiveScriptSiteWindow)
158 *ppvObject = (IActiveScriptSiteWindow*)
this;
160 return E_NOINTERFACE;
186 else if (mask & SCRIPTINFO_IUNKNOWN)
191 else if (mask & SCRIPTINFO_ITYPEINFO)
196 return TYPE_E_ELEMENTNOTFOUND;
198 if (mask & SCRIPTINFO_IUNKNOWN)
200 if (mask & SCRIPTINFO_ITYPEINFO) {
201 IProvideClassInfo *classInfo = 0;
202 object->queryInterface(IID_IProvideClassInfo, (
void**)&classInfo);
204 classInfo->GetClassInfo(type);
205 classInfo->Release();
232 if (result && result->vt != VT_EMPTY)
276 memset(&exception, 0,
sizeof(exception));
283 error->GetExceptionInfo(&exception);
284 error->GetSourcePosition(&context, &lineNumber, &charPos);
285 HRESULT hres = error->GetSourceLineText(&bstrLineText);
288 SysFreeString(bstrLineText);
290 SysFreeString(exception.bstrSource);
291 SysFreeString(exception.bstrDescription);
292 SysFreeString(exception.bstrHelpFile);
328 w =
qApp->activeWindow();
365 EnableWindow(w->
winId(), fEnable);
369 #endif //QT_NO_QAXSCRIPT 422 :
QAxObject(script), script_code(script), engine(0), script_language(language)
424 #ifdef QT_CHECK_STATE 426 qWarning(
"QAxScriptEngine: created without language");
429 qWarning(
"QAxScriptEngine: created without script");
442 #ifndef QT_NO_QAXSCRIPT 444 engine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
467 #ifndef QT_NO_QAXSCRIPT 476 CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER, IID_IActiveScript, (
void**)&
engine);
480 IActiveScriptParse *parser = 0;
481 engine->QueryInterface(IID_IActiveScriptParse, (
void**)&parser);
493 if (parser->InitNew() != S_OK) {
502 hres = parser->ParseScriptText(bstrCode, 0, 0, 0, DWORDLONG(
this), 0, SCRIPTTEXT_ISVISIBLE, 0, 0);
504 hres = parser->ParseScriptText(bstrCode, 0, 0, 0, DWORD(
this), 0, SCRIPTTEXT_ISVISIBLE, 0, 0);
506 SysFreeString(bstrCode);
513 if (engine->SetScriptState(SCRIPTSTATE_CONNECTED) != S_OK) {
518 IDispatch *scriptDispatch = 0;
519 engine->GetScriptDispatch(0, &scriptDispatch);
520 if (scriptDispatch) {
521 scriptDispatch->QueryInterface(IID_IUnknown, (
void**)ptr);
522 scriptDispatch->Release();
548 IDispatch *scriptDispatch = 0;
554 HRESULT hres = scriptDispatch->GetTypeInfoCount(&tic);
555 scriptDispatch->Release();
556 return hres == S_OK && tic > 0;
573 #ifndef QT_NO_QAXSCRIPT 574 return engine->QueryInterface(uuid, iface);
589 #ifndef QT_NO_QAXSCRIPT 591 engine->GetScriptState(&state);
604 #ifndef QT_NO_QAXSCRIPT 608 engine->SetScriptState((SCRIPTSTATE)st);
620 #ifndef QT_NO_QAXSCRIPT 624 engine->AddNamedItem((
wchar_t*)name.
utf16(), SCRIPTITEM_ISSOURCE|SCRIPTITEM_ISVISIBLE);
677 :
QObject(manager), script_name(name), script_manager(manager),
686 #ifndef QT_NO_QAXSCRIPT 701 #ifndef QT_NO_QAXSCRIPT 732 for (it = engines.
begin(); it != engines.
end(); ++
it) {
775 functions << slotname;
777 functions << slotname.left(slotname.indexOf(
QLatin1Char(
'(')));
1015 scripts << scriptIt.
key();
1042 QObject *obj =
object->qObject();
1086 if (script->
load(code, language))
1128 for (it = engines.
begin(); it != engines.
end(); ++
it) {
1134 language = engine.
name;
1144 if (script->
load(contents, language))
1188 #ifdef QT_CHECK_STATE 1189 qWarning(
"QAxScriptManager::call: No script provides function %s, or this function\n" 1190 "\tis provided through an engine that does not support introspection",
function.latin1());
1195 return s->
call(
function, var1, var2, var3, var4, var5, var6, var7, var8);
1210 #ifdef QT_CHECK_STATE 1211 qWarning(
"QAxScriptManager::call: No script provides function %s, or this function\n" 1212 "\tis provided through an engine that does not support introspection",
function.latin1());
1218 return s->
call(
function, args);
1235 HRESULT hres = CLSIDFromProgID((
wchar_t*)name.
utf16(), &clsid);
1256 ";;JavaScript Files (*.js)");
1259 for (it = engines.
begin(); it != engines.
end(); ++
it) {
1269 return allFiles + specialFiles +
QLatin1String(
";;All Files (*.*)");
1351 emit error(source, code, desc, spos, stext);
1355 #endif // QT_NO_WIN_ACTIVEQT The QVariant class acts like a union for the most common Qt data types.
HRESULT WINAPI EnableModeless(BOOL fEnable)
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
T qobject_cast(QObject *object)
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
void finished()
This signal is emitted when a script engine has finished executing code.
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
QStringList functions(QAxScript::FunctionFlags=QAxScript::FunctionNames) const
Returns a list with all the functions that are available.
#define QT_END_NAMESPACE
This macro expands to.
QVariant dynamicCall(const char *name, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant())
Calls the COM object's method function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8, and returns the value returned by the method, or an invalid QVariant if the method does not return a value or when the function call failed.
#define it(className, varName)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
HRESULT WINAPI OnEnterScript()
QString objectName
the name of this object
FunctionFlags
This FunctionFlags enum describes formatting for function introspection.
The QByteArray class provides an array of bytes.
void disableClassInfo()
Disables the class info generation for this ActiveX container.
HRESULT WINAPI GetItemInfo(LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
QAxScriptSite(QAxScript *script)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void addItem(const QString &name)
Registers an item with the script engine.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
The QHash class is a template class that provides a hash-table-based dictionary.
The QAxObject class provides a QObject that wraps a COM object.
void updateScript(QAxScript *)
The QObject class is the base class of all Qt objects.
QStringList scriptNames() const
Returns a list with the names of all the scripts.
~QAxScriptEngine()
Destroys the QAxScriptEngine object, releasing all allocated resources.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
HRESULT WINAPI OnLeaveScript()
const T value(const Key &key) const
Returns the value associated with the key.
const QMetaObject * metaObject() const
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
void setObjectName(const QString &name)
const Key & key() const
Returns the current item's key.
bool isValid() const
Returns true if the script engine has been initialized correctly; otherwise returns false...
QAxScriptManager * script_manager
void error(int code, const QString &description, int sourcePosition, const QString &sourceText)
This signal is emitted when an execution error occurred while running a script.
void addObject(QAxBase *object)
Adds object to the manager.
QLocale::Language language
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool load(const QString &code, const QString &language=QString())
Loads the script source code written in language language into the script engine. ...
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
bool hasIntrospection() const
Returns true if the script engine supports introspection; otherwise returns false.
QAxScriptManagerPrivate * d
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
static QList< QAxEngineDescriptor > engines
QAxScriptEngine * scriptEngine() const
Returns a pointer to the script engine.
void scriptError(int code, const QString &description, int sourcePosition, const QString &sourceText)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
QVariant call(const QString &function, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant())
Calls function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8 as arg...
void prepend(const T &t)
Inserts value at the beginning of the list.
void entered()
This signal is emitted when a script engine has started executing code.
The QStringList class provides a list of strings.
HRESULT WINAPI OnScriptError(IActiveScriptError *pscripterror)
const T & value() const
Returns the current item's value.
Q_CORE_EXPORT void qWarning(const char *,...)
HRESULT WINAPI OnStateChange(SCRIPTSTATE ssScriptState)
QAxBase * findObject(const QString &name)
Returns the object name registered with the manager.
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QAxScript * script(const QString &name) const
Returns the script called name.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
State
The State enumeration defines the different states a script engine can be in.
const T * ptr(const T &t)
The QAxScriptManager class provides a bridge between application objects and script code...
The State element defines configurations of objects and properties.
QAxScriptSite * script_site
void setState(State st)
Sets the state of the script engine to st.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QAxScript * load(const QString &code, const QString &name, const QString &language)
Loads the script source code using the script engine for language.
HRESULT WINAPI GetDocVersionString(BSTR *pbstrVersion)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
QAxScriptEngine(const QString &language, QAxScript *script)
Constructs a QAxScriptEngine object interpreting script code in language provided by the code in scri...
State state() const
Returns the state of the script engine.
void objectDestroyed(QObject *o)
The QFile class provides an interface for reading from and writing to files.
friend class QAxScriptEngine
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
HRESULT WINAPI OnScriptTerminate(const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
void error(QAxScript *script, int code, const QString &description, int sourcePosition, const QString &sourceText)
This signal is emitted when an execution error occurred while running script.
QObject * parent() const
Returns a pointer to the parent object.
static bool registerEngine(const QString &name, const QString &extension, const QString &code=QString())
Registers the script engine called name and returns true if the engine was found; otherwise does noth...
~QAxScriptManager()
Destroys the objects, releasing all allocated resources.
#define st(var, type, card)
static BSTR QStringToBSTR(const QString &str)
QAxScriptEngine * script_engine
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
int size() const
Returns the number of bytes in this byte array.
void disableEventSink()
Disables the event sink implementation for this ActiveX container.
QAxScript * scriptForFunction(const QString &function) const
Returns a pointer to the first QAxScript that knows about function, or 0 if this function is unknown...
QAxScriptManager(QObject *parent=0)
Creates a QAxScriptManager object.
QVariant call(const QString &function, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant())
Calls function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8 as arg...
bool initialize(IUnknown **ptr)
Reimplemented Function
static QString scriptFileFilter()
Returns a file filter listing all the supported script languages.
friend class QAxScriptSite
HRESULT WINAPI QueryInterface(REFIID iid, void **ppvObject)
HRESULT WINAPI GetWindow(HWND *phwnd)
QHash< QString, QAxBase * > objectDict
QHash< QString, QAxScript * > scriptDict
The QAxScript class provides a wrapper around script code.
void stateChanged(int state)
This signal is emitted when a script engine changes state.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
long queryInterface(const QUuid &, void **) const
Requests the interface uuid from the script engine object and sets the value of iface to the provided...
long queryInterface(const QUuid &, void **) const
Requests the interface uuid from the COM object and sets the value of iface to the provided interface...
void updateObjects()
Registers all objects in the manager with the script engine.
virtual void close()
Calls QFile::flush() and closes the file.
QAxScript(const QString &name, QAxScriptManager *manager)
Constructs a QAxScript object called name and registers it with the QAxScriptManager manager...
The QAxScriptEngine class provides a wrapper around a script engine.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
~QAxScript()
Destroys the object, releasing all allocated resources.
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
QStringList functions(FunctionFlags=FunctionNames) const
Returns a list of all the functions in this script if the respective script engine supports introspec...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
HRESULT WINAPI GetLCID(LCID *plcid)
The QUuid class stores a Universally Unique Identifier (UUID).
The QList class is a template class that provides lists.
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
QString scriptCode() const
Returns the script's code, or the null-string if no code has been loaded yet.