summaryrefslogtreecommitdiffstats
path: root/doc/html/qaxserver-example-opengl.html
blob: 1f062284b66382c71b67052bede85d9921c17517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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 &lt;<a href="qaxfactory-h.html">qaxfactory.h</a>&gt;

    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="ntqapplication.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="ntqapplication.html#setColorSpec">setColorSpec</a>( TQApplication::CustomColor );
        <a href="ntqapplication.html">TQApplication</a> a(argc,argv);

        if ( !TQGLFormat::hasOpenGL() ) {
            <a href="ntqapplication.html#qWarning">tqWarning</a>( "This system has no OpenGL support. Exiting." );
            return -1;
        }

        if ( !TQAxFactory::isServer() ) {
            GLObjectWindow w;
            w.<a href="ntqwidget.html#resize">resize</a>( 400, 350 );
    <a name="x2733"></a>        a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &amp;w );
            w.<a href="ntqwidget.html#show">show</a>();
            return a.<a href="ntqapplication.html#exec">exec</a>();
        }
    <a name="x2731"></a>    return a.<a href="ntqapplication.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 &lt;<a href="qaxbindable-h.html">qaxbindable.h</a>&gt;

    class GLBox : public <a href="qglwidget.html">TQGLWidget</a>,
                  public TQAxBindable
    {
        <a href="metaobjects.html#TQ_OBJECT">TQ_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="ntqwidget.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 &lt;objsafe.h&gt;
</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="ntquuid.html">TQUuid</a> &amp;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> requires 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>    &lt;SCRIPT LANGUAGE=JavaScript&gt;
    function setRot( form )
    {
        GLBox.setXRotation( form.XEdit.value );
        GLBox.setYRotation( form.YEdit.value );
        GLBox.setZRotation( form.ZEdit.value );
    }
    &lt;/SCRIPT&gt;

    &lt;p&gt;
    An OpenGL scene:&lt;br&gt;
    &lt;object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
    CODEBASE=http://www.trolltech.com/demos/openglax.cab&gt;
    [Object not available! Did you forget to build and register the server?]
    &lt;/object&gt;&lt;br&gt;

    &lt;form&gt;
    Rotate the scene:&lt;br&gt;
    X:&lt;input type="edit" ID="XEdit" value="0"&gt;&lt;br&gt;
    Y:&lt;input type="edit" name="YEdit" value="0"&gt;&lt;br&gt;
    Z:&lt;input type="edit" name="ZEdit" value="0"&gt;&lt;br&gt;
    &lt;input type="button" value="Set" onClick="setRot(this.form)"&gt;
    &lt;/form&gt;
</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 &copy; 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>