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
|
<!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="tqfiledialog.html">TQFileDialog</a> and <a href="ntqmessagebox.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="tqfiledialog.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="ntqapplication.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="tqfiledialog.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="tqfiledialog.html#getSaveFileName">TQFileDialog::getSaveFileName</a>().
<p> <pre></pre>
<p> ... and the <tt>Open()</tt> function to use <a href="tqfiledialog.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="tqfiledialog.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 required 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="ntqmessagebox.html#information">TQMessageBox::information</a>().
<p> First, we need to make sure we include the proper header for
<a href="ntqmessagebox.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 required 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="ntqmessagebox.html#warning">TQMessageBox::warning</a>().
<p> First, we need to make sure we include the proper header for <a href="ntqmessagebox.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>
|