<tdalign="right"valign="center"><imgsrc="logo32.png"align="right"width="64"height="32"border="0"></td></tr></table><h1align=center>Using Existing Dialogs with TQMotifDialog</h1>
[ <ahref="motif-walkthrough-4.html">Previous: Using Custom TQDialogs</a> ]
[ <ahref="motif-walkthrough.html">Home</a> ]
[ <ahref="motif-walkthrough-6.html">Next: Using TQt Main Window Classes</a> ]
<p> As mentioned earlier, the <em>Print</em> dialog cannot be replaced until we
have converted the <em>View</em> widget. The <em>Print</em> dialog will be
removed once we have finished our migration, since we will use
function does not return until the dialog is finished. In Motif,
modality is simply a property of the shell, and the application
programmer must write TQDialog::exec() style functionality if they
want that behavior.
<p> Since we will be using TQMotifDialog (which is a TQDialog subclass), we
will need to have an <em>accept</em> and a <em>reject</em> callback for each
dialog we integrate with TQMotifDialog. The predefined Motif dialogs
have these already: the <tt>XmNokCallback</tt> and <tt>XmNcancelCallback</tt>
callbacks. However, the <em>Print</em> dialog only has an <em>accept</em> callback
(the <tt>XmdNprintCallback</tt>), but it does not have a <em>reject</em> callback.
We need to add this.
<p> This is easily done. We add an <tt>XtCallbackList</tt> for the <tt>XmNcancelCallback</tt> callback in <tt>Xmd/PrintP.h</tt>:
<p>
<pre></pre>
<p> We add the <tt>XmNcancelCallback</tt> callback to the list of resources for
the <tt>XmdPrint</tt> widget class in <tt>Xmd/Print.c</tt>:
<p>
<pre></pre>
<p> We need to activate this callback whenever we unmanage the widget and
do not activate the <em>print</em> callback, which is in the <tt>do_help_cb()</tt>
function:
<p><pre></pre>
<p> ... and in the unmanage_cb() function:
<p><pre></pre>
<p><h2> Integrating the <em>Print</em> Dialog
</h2>
<aname="2"></a><p> Now that the <em>Print</em> dialog has the appropriate <em>accept</em> and <em>reject</em> callbacks, we can use <ahref="qmotifdialog.html">TQMotifDialog</a>. First we need to include
the TQMotifDialog header in <tt>todo.cpp</tt>.
<p>
<p><pre></pre>
<p> We add a <tt>ShowPrintDialog()</tt> function which will create and execute the
print dialog.
<p><pre></pre>
<p> We change the <em>Print</em> menu item callback to call the new <tt>ShowPrintDialog()</tt> function. We pass the top-level <ahref="qmotifwidget.html">TQMotifWidget</a>, which
we will use as the parent for the dialog.
<p><pre></pre>
<p> The <tt>ShowPrintDialog()</tt> function creates the <em>Print</em> dialog and
executes it. We use the <tt>XmdNprintCallback</tt> callback to accept the
dialog and the <tt>XmNcancelCallback</tt> callback to reject the dialog. We
can do this easily by using the <ahref="qmotifdialog.html#acceptCallback">TQMotifDialog::acceptCallback</a>() and
<ahref="qmotifdialog.html#rejectCallback">TQMotifDialog::rejectCallback</a>() functions, respectively. We also
ensure that the <em>print</em> callback continues to call the <tt>Print()</tt> function as before.
<p><pre></pre>
<p> After we build the project, the application runs and operates as
expected. There is no visual or behavioral difference, even though
the <em>Print</em> dialog is using <ahref="qmotifdialog.html">TQMotifDialog</a>.
<p> [ <ahref="motif-walkthrough-4.html">Previous: Using Custom TQDialogs</a> ]
[ <ahref="motif-walkthrough.html">Home</a> ]
[ <ahref="motif-walkthrough-6.html">Next: Using TQt Main Window Classes</a> ]