You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
9.0 KiB
207 lines
9.0 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/activeqt/examples/opengl/opengl.doc:33 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>TQt' OpenGL widgets as an ActiveX (executable)</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQt' OpenGL widgets as an ActiveX (executable)</h1>
|
|
|
|
|
|
|
|
The ActiveX control in this example uses the TQGlWidget class in
|
|
TQt to render an OpenGL scene in an ActiveX. The control exposes a few
|
|
methods to change the scene. The example is based on the
|
|
<a href="opengl-box-example.html">"box" example</a> from the standard
|
|
TQt distribution.
|
|
<p> The example demonstrates the use of the default factory and
|
|
<a href="qaxfactory.html#isServer">TQAxFactory::isServer</a>(), and the implementation of an additional COM
|
|
interface using <a href="qaxbindable.html">TQAxBindable</a> and <a href="qaxaggregated.html">TQAxAggregated</a>. The server executable
|
|
can run both as an ActiveX server and as a stand alone application.
|
|
<p>
|
|
|
|
The application uses the default factory as provided by the
|
|
<a href="qaxfactory.html#TQAXFACTORY_DEFAULT">TQAXFACTORY_DEFAULT</a> macro to expose the <tt>GLBox</tt> widget as an ActiveX
|
|
control.
|
|
<pre> #include <<a href="qaxfactory-h.html">qaxfactory.h</a>>
|
|
|
|
TQAXFACTORY_DEFAULT( GLBox,
|
|
"{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}",
|
|
"{33b051af-bb25-47cf-a390-5cfd2987d26a}",
|
|
"{8c996c29-eafa-46ac-a6f9-901951e765b5}",
|
|
"{2c3c183a-eeda-41a4-896e-3d9c12c3577d}",
|
|
"{83e16271-6480-45d5-aaf1-3f40b7661ae4}"
|
|
)
|
|
</pre>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">TQApplication</a> object,
|
|
and uses <a href="qaxfactory.html#isServer">TQAxFactory::isServer</a>() to determine whether or not it is
|
|
appropriate to create and show the application interface.
|
|
<pre> /*
|
|
The main program is here.
|
|
*/
|
|
|
|
int main( int argc, char **argv )
|
|
{
|
|
<a name="x2732"></a> TQApplication::<a href="qapplication.html#setColorSpec">setColorSpec</a>( TQApplication::CustomColor );
|
|
<a href="qapplication.html">TQApplication</a> a(argc,argv);
|
|
|
|
if ( !TQGLFormat::hasOpenGL() ) {
|
|
<a href="qapplication.html#qWarning">qWarning</a>( "This system has no OpenGL support. Exiting." );
|
|
return -1;
|
|
}
|
|
|
|
if ( !TQAxFactory::isServer() ) {
|
|
GLObjectWindow w;
|
|
w.<a href="qwidget.html#resize">resize</a>( 400, 350 );
|
|
<a name="x2733"></a> a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &w );
|
|
w.<a href="qwidget.html#show">show</a>();
|
|
return a.<a href="qapplication.html#exec">exec</a>();
|
|
}
|
|
<a name="x2731"></a> return a.<a href="qapplication.html#exec">exec</a>();
|
|
}
|
|
</pre>
|
|
<p>
|
|
|
|
The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">TQGLWidget</a> class to be able
|
|
to render OpenGL, and from <a href="qaxbindable.html">TQAxBindable</a>.
|
|
<pre> #include <<a href="qaxbindable-h.html">qaxbindable.h</a>>
|
|
|
|
class GLBox : public <a href="qglwidget.html">TQGLWidget</a>,
|
|
public TQAxBindable
|
|
{
|
|
<a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
|
</pre>The class reimplements the <a href="qaxbindable.html#createAggregate">TQAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">TQAxBindable</a>
|
|
to return the pointer to a <a href="qaxaggregated.html">TQAxAggregated</a> object.
|
|
<pre> public:
|
|
|
|
GLBox( <a href="qwidget.html">TQWidget</a>* parent, const char* name );
|
|
~GLBox();
|
|
|
|
<a href="qaxaggregated.html">TQAxAggregated</a> *createAggregate();
|
|
|
|
public slots:
|
|
|
|
void setXRotation( int degrees );
|
|
</pre>The rest of the class declaration and the implementation of the OpenGL
|
|
rendering is identical to the original "box" example.
|
|
<p>
|
|
|
|
The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt>
|
|
system header, in which the <tt>IObjectSafety</tt> COM interface is defined.
|
|
<pre> #include <objsafe.h>
|
|
</pre>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance
|
|
to subclass the <a href="qaxaggregated.html">TQAxAggregated</a> class, and to implement the IObjectSafety
|
|
interface.
|
|
<pre> class ObjectSafetyImpl : public <a href="qaxaggregated.html">TQAxAggregated</a>,
|
|
public IObjectSafety
|
|
{
|
|
public:
|
|
</pre>The class declares a default constructor, and implements the queryInterface
|
|
function to support the IObjectSafety interface.
|
|
<pre> ObjectSafetyImpl() {}
|
|
|
|
long queryInterface( const <a href="quuid.html">TQUuid</a> &iid, void **iface )
|
|
{
|
|
*iface = 0;
|
|
if ( iid == IID_IObjectSafety )
|
|
*iface = (IObjectSafety*)this;
|
|
else
|
|
return E_NOINTERFACE;
|
|
|
|
AddRef();
|
|
return S_OK;
|
|
}
|
|
</pre>Since every COM interface inherits <tt>IUnknown</tt> the <tt>TQAXAGG_IUNKNOWN</tt> macro
|
|
is used to provide the default implementation of the <tt>IUnknown</tt> interface.
|
|
The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt>
|
|
and <tt>Release</tt> to the interface returned by the controllingUnknown() function.
|
|
<pre> TQAXAGG_IUNKNOWN;
|
|
</pre>The implementation of the <tt>IObjectSafety</tt> interface provides the caller
|
|
with information about supported and enabled safety options, and returns
|
|
<tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.
|
|
<pre> HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
|
|
{
|
|
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
|
|
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
|
|
return S_OK;
|
|
}
|
|
HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
|
|
{
|
|
return S_OK;
|
|
}
|
|
};
|
|
</pre>The implementation of the <tt>createAggregate()</tt> function just returns a new
|
|
<tt>ObjectSafetyImpl</tt> object.
|
|
<pre> TQAxAggregated *GLBox::createAggregate()
|
|
{
|
|
return new ObjectSafetyImpl();
|
|
}
|
|
</pre>
|
|
<p> To build the example you must first build the <a href="qaxserver.html">TQAxServer</a> library. Then run qmake and your make tool in
|
|
<tt>examples/wrapper</tt>.
|
|
<p> <hr>
|
|
<p> The <a href="qaxserver-demo-opengl.html">demonstration</a> retquires your
|
|
WebBrowser to support ActiveX controls, and scripting to be enabled.
|
|
<p> In contrast to the other TQAxServer examples Internet Explorer will not
|
|
open a dialog box to ask the user whether or not the scripting of the GLBox
|
|
control should be allowed (the exact browser behaviour depends on the security
|
|
settings in the Internet Options dialog).
|
|
<p>
|
|
|
|
<pre> <SCRIPT LANGUAGE=JavaScript>
|
|
function setRot( form )
|
|
{
|
|
GLBox.setXRotation( form.XEdit.value );
|
|
GLBox.setYRotation( form.YEdit.value );
|
|
GLBox.setZRotation( form.ZEdit.value );
|
|
}
|
|
</SCRIPT>
|
|
|
|
<p>
|
|
An OpenGL scene:<br>
|
|
<object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
|
|
CODEBASE=http://www.trolltech.com/demos/openglax.cab>
|
|
[Object not available! Did you forget to build and register the server?]
|
|
</object><br>
|
|
|
|
<form>
|
|
Rotate the scene:<br>
|
|
X:<input type="edit" ID="XEdit" value="0"><br>
|
|
Y:<input type="edit" name="YEdit" value="0"><br>
|
|
Z:<input type="edit" name="ZEdit" value="0"><br>
|
|
<input type="button" value="Set" onClick="setRot(this.form)">
|
|
</form>
|
|
</pre><p>See also <a href="qaxserver-examples.html">The TQAxServer Examples</a>.
|
|
|
|
<!-- eof -->
|
|
<p><address><hr><div align=center>
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
<td>Copyright © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|