1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/motif/doc/walkthrough.doc:661 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Using Existing Dialogs with QMotifDialog</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Using Existing Dialogs with QMotifDialog</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | [ <a href="motif-walkthrough-4.html">Previous: Using Custom QDialogs</a> ]
|
---|
37 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
38 | [ <a href="motif-walkthrough-6.html">Next: Using Qt Main Window Classes</a> ]
|
---|
39 | <p> As mentioned earlier, the <em>Print</em> dialog cannot be replaced until we
|
---|
40 | have converted the <em>View</em> widget. The <em>Print</em> dialog will be
|
---|
41 | removed once we have finished our migration, since we will use
|
---|
42 | <a href="qprinter.html">QPrinter</a> instead. Based on this information, we decide that it is not
|
---|
43 | worth replacing the <em>Print</em> dialog with a custom <a href="qdialog.html">QDialog</a> replacement.
|
---|
44 | Instead, we will keep the <a href="motif-extension.html#Motif">Motif</a> based dialog and use <a href="qmotifdialog.html">QMotifDialog</a> to
|
---|
45 | integrate the dialog with the application.
|
---|
46 | <p> <h2> Modality Requirements
|
---|
47 | </h2>
|
---|
48 | <a name="1"></a><p> Modality with QDialog is different from Motif. The <a href="qdialog.html#exec">QDialog::exec</a>()
|
---|
49 | function does not return until the dialog is finished. In Motif,
|
---|
50 | modality is simply a property of the shell, and the application
|
---|
51 | programmer must write QDialog::exec() style functionality if they
|
---|
52 | want that behavior.
|
---|
53 | <p> Since we will be using QMotifDialog (which is a QDialog subclass), we
|
---|
54 | will need to have an <em>accept</em> and a <em>reject</em> callback for each
|
---|
55 | dialog we integrate with QMotifDialog. The predefined Motif dialogs
|
---|
56 | have these already: the <tt>XmNokCallback</tt> and <tt>XmNcancelCallback</tt>
|
---|
57 | callbacks. However, the <em>Print</em> dialog only has an <em>accept</em> callback
|
---|
58 | (the <tt>XmdNprintCallback</tt>), but it does not have a <em>reject</em> callback.
|
---|
59 | We need to add this.
|
---|
60 | <p> This is easily done. We add an <tt>XtCallbackList</tt> for the <tt>XmNcancelCallback</tt> callback in <tt>Xmd/PrintP.h</tt>:
|
---|
61 | <p>
|
---|
62 |
|
---|
63 | <pre></pre>
|
---|
64 | <p> We add the <tt>XmNcancelCallback</tt> callback to the list of resources for
|
---|
65 | the <tt>XmdPrint</tt> widget class in <tt>Xmd/Print.c</tt>:
|
---|
66 | <p>
|
---|
67 |
|
---|
68 | <pre></pre>
|
---|
69 | <p> We need to activate this callback whenever we unmanage the widget and
|
---|
70 | do not activate the <em>print</em> callback, which is in the <tt>do_help_cb()</tt>
|
---|
71 | function:
|
---|
72 | <p> <pre></pre>
|
---|
73 | <p> ... and in the unmanage_cb() function:
|
---|
74 | <p> <pre></pre>
|
---|
75 | <p> <h2> Integrating the <em>Print</em> Dialog
|
---|
76 | </h2>
|
---|
77 | <a name="2"></a><p> Now that the <em>Print</em> dialog has the appropriate <em>accept</em> and <em>reject</em> callbacks, we can use <a href="qmotifdialog.html">QMotifDialog</a>. First we need to include
|
---|
78 | the QMotifDialog header in <tt>todo.cpp</tt>.
|
---|
79 | <p>
|
---|
80 |
|
---|
81 | <p> <pre></pre>
|
---|
82 | <p> We add a <tt>ShowPrintDialog()</tt> function which will create and execute the
|
---|
83 | print dialog.
|
---|
84 | <p> <pre></pre>
|
---|
85 | <p> We change the <em>Print</em> menu item callback to call the new <tt>ShowPrintDialog()</tt> function. We pass the top-level <a href="qmotifwidget.html">QMotifWidget</a>, which
|
---|
86 | we will use as the parent for the dialog.
|
---|
87 | <p> <pre></pre>
|
---|
88 | <p> The <tt>ShowPrintDialog()</tt> function creates the <em>Print</em> dialog and
|
---|
89 | executes it. We use the <tt>XmdNprintCallback</tt> callback to accept the
|
---|
90 | dialog and the <tt>XmNcancelCallback</tt> callback to reject the dialog. We
|
---|
91 | can do this easily by using the <a href="qmotifdialog.html#acceptCallback">QMotifDialog::acceptCallback</a>() and
|
---|
92 | <a href="qmotifdialog.html#rejectCallback">QMotifDialog::rejectCallback</a>() functions, respectively. We also
|
---|
93 | ensure that the <em>print</em> callback continues to call the <tt>Print()</tt> function as before.
|
---|
94 | <p> <pre></pre>
|
---|
95 | <p> After we build the project, the application runs and operates as
|
---|
96 | expected. There is no visual or behavioral difference, even though
|
---|
97 | the <em>Print</em> dialog is using <a href="qmotifdialog.html">QMotifDialog</a>.
|
---|
98 | <p> [ <a href="motif-walkthrough-4.html">Previous: Using Custom QDialogs</a> ]
|
---|
99 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
100 | [ <a href="motif-walkthrough-6.html">Next: Using Qt Main Window Classes</a> ]
|
---|
101 | <p>
|
---|
102 | <!-- eof -->
|
---|
103 | <p><address><hr><div align=center>
|
---|
104 | <table width=100% cellspacing=0 border=0><tr>
|
---|
105 | <td>Copyright © 2007
|
---|
106 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
107 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
108 | </table></div></address></body>
|
---|
109 | </html>
|
---|