<tdalign="right"valign="center"><imgsrc="logo32.png"align="right"width="64"height="32"border="0"></td></tr></table><h1align=center>Using TQt Standard Dialogs</h1>
[ <ahref="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ]
[ <ahref="motif-walkthrough.html">Home</a> ]
[ <ahref="motif-walkthrough-4.html">Next: Using Custom TQDialogs</a> ]
<p> We start by using two of the <ahref="dialogs.html">TQt Standard
Dialogs</a>: <ahref="qfiledialog.html">TQFileDialog</a> and <ahref="qmessagebox.html">TQMessageBox</a>. Both of these classes
<trbgcolor="#f0f0f0"><tdvalign="top">TQFileDialog::getOpenFileName() <tdvalign="top">replacement for the <em>Open</em> dialog
<trbgcolor="#d0d0d0"><tdvalign="top">TQFileDialog::getSaveFileName() <tdvalign="top">replacement for the <em>Save As</em> dialog
<trbgcolor="#f0f0f0"><tdvalign="top">TQMessageBox::information() <tdvalign="top">replacement for <em>Page Delete</em> dialog
<trbgcolor="#d0d0d0"><tdvalign="top">TQMessageBox::warning() <tdvalign="top">replacement for <em>IO Error</em> dialog.
</table></center>
<p> Each of these functions takes a <em>TQWidget *parent</em> argument. If we
pass zero as the <em>parent</em> argument, then we will have dialogs that
are centered on the screen, instead of being centered over our main
window. We can have <ahref="qmotifwidget.html">TQMotifWidget</a> create our <tt>XmMainWindow</tt>, and we
can then use this class as the parent for both <ahref="motif-extension.html#Motif">Motif</a> dialogs and TQt
dialogs.
<p> We need to include the appropriate headers for TQMotifWidget and
<ahref="qfiledialog.html">TQFileDialog</a> in <tt>todo.cpp</tt>.
<p>
<pre></pre>
<p> Next, we make a few modifications to how the application is
initialized. We could initialize Xt/Motif and create the <tt>XtAppContext</tt> ourselves, but <ahref="qmotif.html">TQMotif</a> can do this for us.
We also let <ahref="qapplication.html">TQApplication</a> open the connection to the X server. Next,
we create a TQMotifWidget, passing <tt>xmMainWindowWidgetClass</tt> as the <em>widgetclass</em> argument. We can now use the <ahref="qmotifwidget.html#motifWidget">TQMotifWidget::motifWidget</a>()
function to access the Motif widget. The shell widget is created
automatically by TQMotifWidget. We use <tt>XtParent()</tt> to access it.
The top-level window is now a TQMotifWidget, which means we can use it
as the parent for the TQt Standard Dialogs.
<p><pre></pre>
<p><h2> Replacing the <em>Open</em> and <em>Save As</em> Dialogs
</h2>
<aname="1"></a><p> First, we completely remove all use of the existing Motif file
selection dialog. We remove the <tt>Xm/FileSB.h</tt> include, the global <tt>file_dialog</tt> variable, and the code to create the dialog. We also
remove the <tt>PresentFDialog()</tt> callback function. None of this code
is needed to use <ahref="qfiledialog.html">TQFileDialog</a>.
<p> After removing the <tt>PresentFDialog()</tt> callback function, we need to
make <em>Open</em> and <em>Save As</em> popup-menu callbacks call the <tt>Open()</tt>
and <tt>Save()</tt> functions.
<p> First we must change the declaration of these two functions.
<p>
<p><pre></pre>
<p> We also change the arguments to the callbacks. We pass the top-level
<ahref="qmotifwidget.html">TQMotifWidget</a> as the <tt>client_data</tt> to these functions, since we will
be using it as the parent for the TQFileDialog.
<p><pre></pre>
<p><pre>
...
</pre>
<p><pre></pre>
<p> Next, we modify the <tt>Save()</tt> function to use
need to wrap more C header files and global variables in an <tt>extern "C"</tt> block.
<p>
<p><pre></pre>
<p> We need to forward declare the <tt>NewPage()</tt>, <tt>DeletePage()</tt>, <tt>EditPage()</tt> and <tt>SaveIt()</tt> functions so that the compiler generates
the correct symbols for these functions.
<p><pre></pre>
<p> We need to fix a single invalid pointer cast.
<p><pre></pre>
<p> And we need to change the variable named <em>new</em> to <em>newstr</em> in the <tt>Trim()</tt> function.
<p> We can now change the <tt>DeletePage()</tt> function to use
<p> First, we need to make sure we include the proper header for
<ahref="qmessagebox.html">TQMessageBox</a>.
<p>
<pre></pre>
<p> The code for <tt>DeletePage()</tt> looks like this:
<p><pre></pre>
<p> At this point in the code, the page should be deleted. The code to do
this is in the <tt>DoDeletePage()</tt> function. We move the contents of <tt>DoDeletePage()</tt> to this point and remove the <tt>DoDeletePage()</tt> function
completely.
<p> Next, we change <tt>todo.cpp</tt> to pass the top-level <ahref="qmotifwidget.html">TQMotifWidget</a> as the
<tt>client_data</tt> tot he <tt>DeletePage()</tt> function.
<p>
<p><pre></pre>
<p> The <em>IO Error</em> dialog is created and used in <tt>io.c</tt>. We need to
migrate this file to C++. We rename it to <tt>io.cpp</tt>, modify the
project file and regenerate the <tt>Makefile</tt>.