<tdalign="right"valign="center"><imgsrc="logo32.png"align="right"width="64"height="32"border="0"></td></tr></table><h1align=center>Using TQt Main Window Classes</h1>
[ <ahref="motif-walkthrough-5.html">Previous: Using Existing Dialogs with TQMotifDialog</a> ]
<trbgcolor="#a2c511"><thvalign="top"colspan="3"rowspan="1"> File menu
<trbgcolor="#f0f0f0"><tdvalign="top">New <tdvalign="top"><tt>MainWindow::fileNew()</tt><tdvalign="top">calls the <tt>New()</tt> callback
<trbgcolor="#d0d0d0"><tdvalign="top">Open <tdvalign="top"><tt>MainWindow::fileOpen()</tt><tdvalign="top">calls the <tt>Open()</tt> callback
<trbgcolor="#f0f0f0"><tdvalign="top">Save <tdvalign="top"><tt>MainWindow::fileSave()</tt><tdvalign="top">calls the <tt>SaveIt()</tt> callback
<trbgcolor="#d0d0d0"><tdvalign="top">Save As <tdvalign="top"><tt>MainWindow::fileSaveAs()</tt><tdvalign="top">calls the <tt>Save()</tt> callback
<trbgcolor="#f0f0f0"><tdvalign="top">Print <tdvalign="top"><tt>MainWindow::filePrint()</tt><tdvalign="top">calls the <tt>ShowPrintDialog()</tt> callback
<trbgcolor="#a2c511"><thvalign="top"colspan="3"rowspan="1"> Selected menu
<trbgcolor="#f0f0f0"><tdvalign="top">Properties <tdvalign="top"><tt>MainWindow::selProperties()</tt><tdvalign="top">calls the <tt>EditPage()</tt> callback
<trbgcolor="#d0d0d0"><tdvalign="top">New <tdvalign="top"><tt>MainWindow::selNewPage()</tt><tdvalign="top">calls the <tt>NewPage()</tt> callback
<trbgcolor="#f0f0f0"><tdvalign="top">Delete to Trash <tdvalign="top"><tt>MainWindow::selDeletePage()</tt><tdvalign="top">calls the <tt>DeletePage()</tt> callback
</table></center>
<p> We need to add forward declarations for these callbacks before we can
use them.
<p><pre></pre>
<p> Each of the existing callback functions takes three arguments. We pass
<em>NULL</em> to all of the arguments in this example (with a few exceptions,
see below). The existing code does not rely on any of the arguments.
Each slot implementation is a single line calling the related callback
function. The code is not very interesting and would just take up
space, so we've omitted it.
<p> There are four exceptions to the above. The <tt>Open()</tt>, <tt>Save()</tt>, <tt>EditPage()</tt> and <tt>DeletePage()</tt> callbacks accept a pointer to the
toplevel <ahref="qwidget.html">TQWidget</a> as argument 2 (the <em>client_data</em> argument). For
these four functions, we pass <em>this</em> as the second argument, which is
a toplevel <tt>MainWindow</tt> derived from <ahref="qmainwindow.html">TQMainWindow</a>.
<p><h2> Replacing the <em>Main Window</em>
</h2>
<aname="2"></a><p> The next step is to use the new <em>Main Window</em> in our application.
The changes needed in <tt>todo.cpp</tt> are large due to the large amount of
code being removed.
<p> First, we add the include for our new <em>Main Window</em>.
<p>
<p><pre></pre>
<p> We can cleanup the Motif includes, since many of them are no longer
needed.
<p><pre></pre><pre></pre><pre></pre>
<p> The <tt>QuitAppl()</tt> and <tt>manageCB()</tt> callbacks are not needed any more,
so we remove them. We do not need the global <tt>shell</tt> variable
either. We remove it and all references to it in the <tt>New()</tt>, <tt>Save()</tt> and <tt>Open()</tt> callbacks.
<p> In <tt>main()</tt>, we make the large changes. First, we use our new <tt>MainWindow</tt> instead of <ahref="qmotifwidget.html">TQMotifWidget</a> with <tt>XmMainWindow</tt>.
<p>
<p><pre></pre>
<p> We will now use TQMotifWidget to create the <tt>XmNotebook</tt> widget.
<p><pre></pre>
<p> We remove all of the code used to create the Motif menus. The
remaining code in <tt>main()</tt> is self-explanatory.
<p><pre></pre>
<p> Our application is now using <ahref="qmainwindow.html">TQMainWindow</a> instead of <tt>XmMainWindow</tt>.
After we build the project, the application runs and operates as
expected.
<p> [ <ahref="motif-walkthrough-5.html">Previous: Using Existing Dialogs with TQMotifDialog</a> ]