Qt 4.8
Public Functions | Protected Functions | Properties | List of all members
QAxScriptSite Class Reference
Inheritance diagram for QAxScriptSite:

Public Functions

ULONG WINAPI AddRef ()
 
HRESULT WINAPI EnableModeless (BOOL fEnable)
 
HRESULT WINAPI GetDocVersionString (BSTR *pbstrVersion)
 
HRESULT WINAPI GetItemInfo (LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
 
HRESULT WINAPI GetLCID (LCID *plcid)
 
HRESULT WINAPI GetWindow (HWND *phwnd)
 
HRESULT WINAPI OnEnterScript ()
 
HRESULT WINAPI OnLeaveScript ()
 
HRESULT WINAPI OnScriptError (IActiveScriptError *pscripterror)
 
HRESULT WINAPI OnScriptTerminate (const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
 
HRESULT WINAPI OnStateChange (SCRIPTSTATE ssScriptState)
 
 QAxScriptSite (QAxScript *script)
 
HRESULT WINAPI QueryInterface (REFIID iid, void **ppvObject)
 
ULONG WINAPI Release ()
 

Protected Functions

QWidgetwindow () const
 

Properties

LONG ref
 
QAxScriptscript
 

Detailed Description

Definition at line 89 of file qaxscript.cpp.

Constructors and Destructors

◆ QAxScriptSite()

QAxScriptSite::QAxScriptSite ( QAxScript script)

Definition at line 122 of file qaxscript.cpp.

123 : script(s), ref(1)
124 {
125 }
QAxScript * script
Definition: qaxscript.cpp:115

Functions

◆ AddRef()

ULONG WINAPI QAxScriptSite::AddRef ( )

Definition at line 130 of file qaxscript.cpp.

Referenced by QueryInterface().

131 {
132  return InterlockedIncrement(&ref);
133 }

◆ EnableModeless()

HRESULT WINAPI QAxScriptSite::EnableModeless ( BOOL  fEnable)

Definition at line 359 of file qaxscript.cpp.

360 {
361  QWidget *w = window();
362  if (!w)
363  return E_FAIL;
364 
365  EnableWindow(w->winId(), fEnable);
366  return S_OK;
367 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * window() const
Definition: qaxscript.cpp:316
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

◆ GetDocVersionString()

HRESULT WINAPI QAxScriptSite::GetDocVersionString ( BSTR *  pbstrVersion)

Definition at line 217 of file qaxscript.cpp.

218 {
219  return E_NOTIMPL;
220 }

◆ GetItemInfo()

HRESULT WINAPI QAxScriptSite::GetItemInfo ( LPCOLESTR  pstrName,
DWORD  dwReturnMask,
IUnknown **  ppiunkItem,
ITypeInfo **  ppti 
)

Definition at line 182 of file qaxscript.cpp.

183 {
184  if (item)
185  *item = 0;
186  else if (mask & SCRIPTINFO_IUNKNOWN)
187  return E_POINTER;
188 
189  if (type)
190  *type = 0;
191  else if (mask & SCRIPTINFO_ITYPEINFO)
192  return E_POINTER;
193 
194  QAxBase *object = script->findObject(QString::fromWCharArray(pstrName));
195  if (!object)
196  return TYPE_E_ELEMENTNOTFOUND;
197 
198  if (mask & SCRIPTINFO_IUNKNOWN)
199  object->queryInterface(IID_IUnknown, (void**)item);
200  if (mask & SCRIPTINFO_ITYPEINFO) {
201  IProvideClassInfo *classInfo = 0;
202  object->queryInterface(IID_IProvideClassInfo, (void**)&classInfo);
203  if (classInfo) {
204  classInfo->GetClassInfo(type);
205  classInfo->Release();
206  }
207  }
208  return S_OK;
209 }
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...
Definition: qstring.cpp:1019
int type
Definition: qmetatype.cpp:239
QAxScript * script
Definition: qaxscript.cpp:115
QAxBase * findObject(const QString &name)
Returns the object name registered with the manager.
Definition: qaxscript.cpp:848
long queryInterface(const QUuid &, void **) const
Requests the interface uuid from the COM object and sets the value of iface to the provided interface...
Definition: qaxbase.cpp:1479
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66

◆ GetLCID()

HRESULT WINAPI QAxScriptSite::GetLCID ( LCID *  plcid)

Definition at line 171 of file qaxscript.cpp.

172 {
173  return E_NOTIMPL;
174 }

◆ GetWindow()

HRESULT WINAPI QAxScriptSite::GetWindow ( HWND *  phwnd)

Definition at line 339 of file qaxscript.cpp.

340 {
341  if (!phwnd)
342  return E_POINTER;
343 
344  *phwnd = 0;
345  QWidget *w = window();
346  if (!w)
347  return E_FAIL;
348 
349  *phwnd = w->winId();
350  return S_OK;
351 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * window() const
Definition: qaxscript.cpp:316
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

◆ OnEnterScript()

HRESULT WINAPI QAxScriptSite::OnEnterScript ( )

Definition at line 249 of file qaxscript.cpp.

250 {
251  emit script->entered();
252  return S_OK;
253 }
QAxScript * script
Definition: qaxscript.cpp:115
#define emit
Definition: qobjectdefs.h:76
void entered()
This signal is emitted when a script engine has started executing code.

◆ OnLeaveScript()

HRESULT WINAPI QAxScriptSite::OnLeaveScript ( )

Definition at line 261 of file qaxscript.cpp.

262 {
263  emit script->finished();
264  return S_OK;
265 }
void finished()
This signal is emitted when a script engine has finished executing code.
QAxScript * script
Definition: qaxscript.cpp:115
#define emit
Definition: qobjectdefs.h:76

◆ OnScriptError()

HRESULT WINAPI QAxScriptSite::OnScriptError ( IActiveScriptError *  pscripterror)

Definition at line 273 of file qaxscript.cpp.

274 {
275  EXCEPINFO exception;
276  memset(&exception, 0, sizeof(exception));
277  DWORD context;
278  ULONG lineNumber;
279  LONG charPos;
280  BSTR bstrLineText;
281  QString lineText;
282 
283  error->GetExceptionInfo(&exception);
284  error->GetSourcePosition(&context, &lineNumber, &charPos);
285  HRESULT hres = error->GetSourceLineText(&bstrLineText);
286  if (hres == S_OK) {
287  lineText = QString::fromWCharArray(bstrLineText);
288  SysFreeString(bstrLineText);
289  }
290  SysFreeString(exception.bstrSource);
291  SysFreeString(exception.bstrDescription);
292  SysFreeString(exception.bstrHelpFile);
293 
294  emit script->error(exception.wCode, QString::fromWCharArray(exception.bstrDescription), lineNumber, lineText);
295 
296  return S_OK;
297 }
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...
Definition: qstring.cpp:1019
#define error(msg)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QAxScript * script
Definition: qaxscript.cpp:115
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.
#define emit
Definition: qobjectdefs.h:76
long HRESULT

◆ OnScriptTerminate()

HRESULT WINAPI QAxScriptSite::OnScriptTerminate ( const VARIANT *  pvarResult,
const EXCEPINFO *  pexcepinfo 
)

Definition at line 228 of file qaxscript.cpp.

229 {
230  emit script->finished();
231 
232  if (result && result->vt != VT_EMPTY)
233  emit script->finished(VARIANTToQVariant(*result, 0));
234  if (exception)
235  emit script->finished(exception->wCode,
236  QString::fromWCharArray(exception->bstrSource),
237  QString::fromWCharArray(exception->bstrDescription),
238  QString::fromWCharArray(exception->bstrHelpFile)
239  );
240  return S_OK;
241 }
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...
Definition: qstring.cpp:1019
void finished()
This signal is emitted when a script engine has finished executing code.
QAxScript * script
Definition: qaxscript.cpp:115
#define emit
Definition: qobjectdefs.h:76
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
Returns arg as a QVariant of type type.
Definition: qaxtypes.cpp:919

◆ OnStateChange()

HRESULT WINAPI QAxScriptSite::OnStateChange ( SCRIPTSTATE  ssScriptState)

Definition at line 305 of file qaxscript.cpp.

306 {
307  emit script->stateChanged(ssScriptState);
308  return S_OK;
309 }
QAxScript * script
Definition: qaxscript.cpp:115
#define emit
Definition: qobjectdefs.h:76
void stateChanged(int state)
This signal is emitted when a script engine changes state.

◆ QueryInterface()

HRESULT WINAPI QAxScriptSite::QueryInterface ( REFIID  iid,
void **  ppvObject 
)

Definition at line 150 of file qaxscript.cpp.

151 {
152  *ppvObject = 0;
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;
159  else
160  return E_NOINTERFACE;
161 
162  AddRef();
163  return S_OK;
164 }
ULONG WINAPI AddRef()
Definition: qaxscript.cpp:130

◆ Release()

ULONG WINAPI QAxScriptSite::Release ( )

Definition at line 138 of file qaxscript.cpp.

Referenced by QAxScript::~QAxScript().

139 {
140  LONG refCount = InterlockedDecrement(&ref);
141  if (!refCount)
142  delete this;
143 
144  return refCount;
145 }

◆ window()

QWidget * QAxScriptSite::window ( ) const
protected

Definition at line 316 of file qaxscript.cpp.

Referenced by EnableModeless(), and GetWindow().

317 {
318  QWidget *w = 0;
319  QObject *p = script->parent();
320  while (!w && p) {
321  w = qobject_cast<QWidget*>(p);
322  p = p->parent();
323  }
324 
325  if (w)
326  w = w->window();
327  if (!w && qApp)
328  w = qApp->activeWindow();
329 
330  return w;
331 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QAxScript * script
Definition: qaxscript.cpp:115
#define qApp
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492

Properties

◆ ref

LONG QAxScriptSite::ref
private

Definition at line 116 of file qaxscript.cpp.

Referenced by AddRef(), and Release().

◆ script

QAxScript* QAxScriptSite::script
private

The documentation for this class was generated from the following file: