diff options
Diffstat (limited to 'doc/html/motif-walkthrough-3.html')
-rw-r--r-- | doc/html/motif-walkthrough-3.html | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/doc/html/motif-walkthrough-3.html b/doc/html/motif-walkthrough-3.html new file mode 100644 index 000000000..2c0cdba3f --- /dev/null +++ b/doc/html/motif-walkthrough-3.html @@ -0,0 +1,178 @@ +<!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/motif/doc/walkthrough.doc:334 --> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Using TQt Standard Dialogs</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>Using TQt Standard Dialogs</h1> + + + +[ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ] +[ <a href="motif-walkthrough.html">Home</a> ] +[ <a href="motif-walkthrough-4.html">Next: Using Custom TQDialogs</a> ] +<p> We start by using two of the <a href="dialogs.html">TQt Standard +Dialogs</a>: <a href="qfiledialog.html">TQFileDialog</a> and <a href="qmessagebox.html">TQMessageBox</a>. Both of these classes +provide useful static convenience functions. +<p> <center><table cellpadding="4" cellspacing="2" border="0"> +<tr bgcolor="#f0f0f0"> <td valign="top">TQFileDialog::getOpenFileName() <td valign="top">replacement for the <em>Open</em> dialog +<tr bgcolor="#d0d0d0"> <td valign="top">TQFileDialog::getSaveFileName() <td valign="top">replacement for the <em>Save As</em> dialog +<tr bgcolor="#f0f0f0"> <td valign="top">TQMessageBox::information() <td valign="top">replacement for <em>Page Delete</em> dialog +<tr bgcolor="#d0d0d0"> <td valign="top">TQMessageBox::warning() <td valign="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 <a href="qmotifwidget.html">TQMotifWidget</a> create our <tt>XmMainWindow</tt>, and we +can then use this class as the parent for both <a href="motif-extension.html#Motif">Motif</a> dialogs and TQt +dialogs. +<p> We need to include the appropriate headers for TQMotifWidget and +<a href="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 <a href="qmotif.html">TQMotif</a> can do this for us. +We also let <a href="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 <a href="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> +<a name="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 <a href="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 +<a href="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 +<a href="qfiledialog.html#getSaveFileName">TQFileDialog::getSaveFileName</a>(). +<p> <pre></pre> +<p> ... and the <tt>Open()</tt> function to use <a href="qfiledialog.html#getOpenFileName">TQFileDialog::getOpenFileName</a>(). +<p> <pre></pre> +<p> After we build the project, the application runs and operates as +expected. The difference is that the <em>Open</em> and <em>Save As</em> dialogs +now use <a href="qfiledialog.html">TQFileDialog</a>. +<p> <h2> Replacing the <em>Page Delete</em> and <em>IO Error</em> Dialogs +</h2> +<a name="2"></a><p> The <em>Page Delete</em> dialog is created and used in <tt>actions.c</tt>. We +need to migrate this file to C++. We rename it to <tt>actions.cpp</tt>, +modify the project file and regenerate the <tt>Makefile</tt>. +<p> The changes retquired to make <tt>actions.cpp</tt> compile are minimal. We +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 +<a href="qmessagebox.html#information">TQMessageBox::information</a>(). +<p> First, we need to make sure we include the proper header for +<a href="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 <a href="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>. +<p> The changes retquired to make <tt>io.cpp</tt> compile are minimal. We 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>ReadDB()</tt> and <tt>SaveDB()</tt> functions +so that the compiler generates the correct symbols for these +functions. +<p> <pre></pre> +<p> The <tt>ParseNewLines()</tt> function needs to be converted to proper C++. +<p> <pre></pre> +<p> The <tt>PrintWithNewLines()</tt> function also needs to be converted to proper +C++. +<p> <pre></pre> +<p> We can now change the <tt>ReadDB()</tt> and <tt>SaveDB()</tt> functions to use +<a href="qmessagebox.html#warning">TQMessageBox::warning</a>(). +<p> First, we need to make sure we include the proper header for <a href="qmessagebox.html">TQMessageBox</a>. +<p> + +<pre></pre> +<p> The code for <tt>ReadDB()</tt> looks like this: +<p> <pre></pre><pre> + ... +</pre> + +<p> The code for <tt>SaveDB()</tt> looks like this: +<p> <pre></pre><pre> + ... +</pre> + +<p> After we build the project, the application runs and operates as +expected. The difference is that the <em>Page Delete</em> and <em>IO Error</em> dialogs now use TQMessageBox. +<p> [ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ] +[ <a href="motif-walkthrough.html">Home</a> ] +[ <a href="motif-walkthrough-4.html">Next: Using Custom TQDialogs</a> ] +<p> +<!-- 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> |