[190] | 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/examples/dialog/dialog.doc:1 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>A Motif Dialog</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>A Motif Dialog</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | <p>
|
---|
| 37 | <p> <hr>
|
---|
| 38 | <p> Header
|
---|
| 39 | <p> <pre>#ifndef MAINWINDOW_H
|
---|
| 40 | #define MAINWINDOW_H
|
---|
| 41 |
|
---|
| 42 | #include <<a href="qmotifwidget-h.html">qmotifwidget.h</a>>
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | class MainWindow : public <a href="qmotifwidget.html">QMotifWidget</a>
|
---|
| 46 | {
|
---|
| 47 | public:
|
---|
| 48 | MainWindow();
|
---|
| 49 |
|
---|
| 50 | void showMotifDialog();
|
---|
| 51 | void showQtDialog();
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | #endif // MAINWINDOW_H
|
---|
| 55 | </pre>
|
---|
| 56 |
|
---|
| 57 | <p> <hr>
|
---|
| 58 | <p> Implementation:
|
---|
| 59 | <p> <pre>#include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 60 | #include <<a href="qmotif-h.html">qmotif.h</a>>
|
---|
| 61 |
|
---|
| 62 | #include "mainwindow.h"
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | int main( int argc, char **argv )
|
---|
| 66 | {
|
---|
| 67 | XtSetLanguageProc( NULL, NULL, NULL );
|
---|
| 68 |
|
---|
| 69 | <a href="qmotif.html">QMotif</a> integrator( "dialog" );
|
---|
| 70 | <a href="qapplication.html">QApplication</a> app( argc, argv );
|
---|
| 71 |
|
---|
| 72 | MainWindow *mainwindow = new MainWindow;
|
---|
| 73 | app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( mainwindow );
|
---|
| 74 | mainwindow-><a href="qwidget.html#show">show</a>();
|
---|
| 75 |
|
---|
| 76 | return app.<a href="qapplication.html#exec">exec</a>();
|
---|
| 77 | }
|
---|
| 78 | </pre>
|
---|
| 79 |
|
---|
| 80 | <p> <pre>#include "mainwindow.h"
|
---|
| 81 | #include "dialog.h"
|
---|
| 82 |
|
---|
| 83 | #include <Xm/MainW.h>
|
---|
| 84 | #include <Xm/RowColumn.h>
|
---|
| 85 | #include <Xm/CascadeB.h>
|
---|
| 86 | #include <Xm/PushB.h>
|
---|
| 87 | #include <Xm/PushBG.h>
|
---|
| 88 | #include <Xm/SeparatoG.h>
|
---|
| 89 | #include <Xm/Text.h>
|
---|
| 90 | #include <Xm/MessageB.h>
|
---|
| 91 | #include <Xm/Form.h>
|
---|
| 92 | #include <Xm/LabelG.h>
|
---|
| 93 |
|
---|
| 94 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | static void motifDialogCallback( Widget, XtPointer client_data, XtPointer )
|
---|
| 98 | {
|
---|
| 99 | MainWindow *mw = (MainWindow *) client_data;
|
---|
| 100 | mw->showMotifDialog();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | static void qtDialogCallback( Widget, XtPointer client_data, XtPointer )
|
---|
| 104 | {
|
---|
| 105 | MainWindow *mw = (MainWindow *) client_data;
|
---|
| 106 | mw->showQtDialog();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | static void quitCallback( Widget, XtPointer client_data, XtPointer )
|
---|
| 110 | {
|
---|
| 111 | MainWindow *mw = (MainWindow *) client_data;
|
---|
| 112 | <a name="x2708"></a> mw-><a href="qwidget.html#close">close</a>();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | <a name="f560"></a>MainWindow::MainWindow()
|
---|
| 117 | : <a href="qmotifwidget.html">QMotifWidget</a>( 0, xmMainWindowWidgetClass, NULL, 0, "mainwindow" )
|
---|
| 118 | {
|
---|
| 119 | Widget menubar = XmCreateMenuBar( <a href="qmotifwidget.html#motifWidget">motifWidget</a>(), "menubar", NULL, 0 );
|
---|
| 120 | Widget filemenu = XmCreatePulldownMenu( menubar, "filemenu", NULL, 0 );
|
---|
| 121 | Widget item;
|
---|
| 122 |
|
---|
| 123 | item = XtVaCreateManagedWidget( "Motif Dialog...",
|
---|
| 124 | xmPushButtonGadgetClass, filemenu,
|
---|
| 125 | XmNmnemonic, 'C',
|
---|
| 126 | NULL );
|
---|
| 127 | XtAddCallback( item, XmNactivateCallback, motifDialogCallback, this );
|
---|
| 128 |
|
---|
| 129 | item = XtVaCreateManagedWidget( "Qt Dialog...",
|
---|
| 130 | xmPushButtonGadgetClass, filemenu,
|
---|
| 131 | XmNmnemonic, 'Q',
|
---|
| 132 | NULL );
|
---|
| 133 | XtAddCallback( item, XmNactivateCallback, qtDialogCallback, this );
|
---|
| 134 |
|
---|
| 135 | item = XtVaCreateManagedWidget( "sep",
|
---|
| 136 | xmSeparatorGadgetClass, filemenu,
|
---|
| 137 | NULL );
|
---|
| 138 |
|
---|
| 139 | item = XtVaCreateManagedWidget( "Exit",
|
---|
| 140 | xmPushButtonGadgetClass, filemenu,
|
---|
| 141 | XmNmnemonic, 'x',
|
---|
| 142 | NULL );
|
---|
| 143 | XtAddCallback( item, XmNactivateCallback, quitCallback, this );
|
---|
| 144 |
|
---|
| 145 | XmString str = XmStringCreateLocalized( "File" );
|
---|
| 146 | item = XtVaCreateManagedWidget( "File",
|
---|
| 147 | xmCascadeButtonWidgetClass, menubar,
|
---|
| 148 | XmNlabelString, str,
|
---|
| 149 | XmNmnemonic, 'F',
|
---|
| 150 | XmNsubMenuId, filemenu,
|
---|
| 151 | NULL );
|
---|
| 152 | XmStringFree( str );
|
---|
| 153 |
|
---|
| 154 | Arg args[2];
|
---|
| 155 | XtSetArg( args[0], XmNeditMode, XmMULTI_LINE_EDIT );
|
---|
| 156 | Widget texteditor =
|
---|
| 157 | XmCreateScrolledText( <a href="qmotifwidget.html#motifWidget">motifWidget</a>(), "texteditor",
|
---|
| 158 | args, 1 );
|
---|
| 159 |
|
---|
| 160 | XtManageChild( menubar );
|
---|
| 161 | XtManageChild( texteditor );
|
---|
| 162 |
|
---|
| 163 | // pick a nice default size
|
---|
| 164 | XtVaSetValues( <a href="qmotifwidget.html#motifWidget">motifWidget</a>(),
|
---|
| 165 | XmNwidth, 400,
|
---|
| 166 | XmNheight, 300,
|
---|
| 167 | NULL );
|
---|
| 168 |
|
---|
| 169 | <a href="qwidget.html#setCaption">setCaption</a>( <a href="qobject.html#tr">tr</a>("QMotif Dialog Example") );
|
---|
| 170 |
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | void <a name="f561"></a>MainWindow::showMotifDialog()
|
---|
| 174 | {
|
---|
| 175 | <a href="qmotifdialog.html">QMotifDialog</a> dialog( this, "custom dialog", TRUE );
|
---|
| 176 | dialog.<a href="qwidget.html#setCaption">setCaption</a>( <a href="qobject.html#tr">tr</a>("Custom <a href="motif-extension.html#Motif">Motif</a> Dialog") );
|
---|
| 177 |
|
---|
| 178 | <a name="x2707"></a> Widget form = XmCreateForm( dialog.<a href="qmotifdialog.html#shell">shell</a>(), "custom motif dialog", NULL, 0 );
|
---|
| 179 |
|
---|
| 180 | XmString str;
|
---|
| 181 | Arg args[9];
|
---|
| 182 |
|
---|
| 183 | str = XmStringCreateLocalized( "Close" );
|
---|
| 184 | XtSetArg( args[0], XmNlabelString, str );
|
---|
| 185 | XtSetArg( args[1], XmNshowAsDefault, True );
|
---|
| 186 | XtSetArg( args[2], XmNleftAttachment, XmATTACH_POSITION );
|
---|
| 187 | XtSetArg( args[3], XmNleftPosition, 40 );
|
---|
| 188 | XtSetArg( args[4], XmNrightAttachment, XmATTACH_POSITION );
|
---|
| 189 | XtSetArg( args[5], XmNrightPosition, 60 );
|
---|
| 190 | XtSetArg( args[7], XmNbottomAttachment, XmATTACH_FORM );
|
---|
| 191 | XtSetArg( args[6], XmNtopOffset, 10 );
|
---|
| 192 | XtSetArg( args[8], XmNbottomOffset, 10 );
|
---|
| 193 | Widget button = XmCreatePushButton( form, "Close", args, 9 );
|
---|
| 194 | XmStringFree( str );
|
---|
| 195 |
|
---|
| 196 | str =
|
---|
| 197 | XmStringCreateLocalized( "This is a custom Motif-based dialog using\n"
|
---|
| 198 | "QMotifDialog with a QWidget-based parent." );
|
---|
| 199 | XtSetArg( args[0], XmNlabelString, str );
|
---|
| 200 | XtSetArg( args[1], XmNleftAttachment, XmATTACH_FORM );
|
---|
| 201 | XtSetArg( args[2], XmNrightAttachment, XmATTACH_FORM );
|
---|
| 202 | XtSetArg( args[3], XmNtopAttachment, XmATTACH_FORM );
|
---|
| 203 | XtSetArg( args[4], XmNbottomAttachment, XmATTACH_WIDGET );
|
---|
| 204 | XtSetArg( args[5], XmNbottomWidget, button );
|
---|
| 205 | XtSetArg( args[6], XmNtopOffset, 10 );
|
---|
| 206 | XtSetArg( args[7], XmNbottomOffset, 10 );
|
---|
| 207 | Widget label = XmCreateLabelGadget( form, "label", args, 8 );
|
---|
| 208 | XmStringFree( str );
|
---|
| 209 |
|
---|
| 210 | XtManageChild( button );
|
---|
| 211 | XtManageChild( label );
|
---|
| 212 | XtManageChild( form );
|
---|
| 213 |
|
---|
| 214 | XtAddCallback( button, XmNactivateCallback,
|
---|
| 215 | (XtCallbackProc) QMotifDialog::acceptCallback, &dialog );
|
---|
| 216 |
|
---|
| 217 | <a name="x2706"></a> dialog.<a href="qdialog.html#exec">exec</a>();
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | void <a name="f562"></a>MainWindow::showQtDialog()
|
---|
| 221 | {
|
---|
| 222 | // custom Qt-based dialog using a Motif-based parent
|
---|
| 223 | CustomDialog customdialog( <a href="qmotifwidget.html#motifWidget">motifWidget</a>(), "custom dialog", TRUE );
|
---|
| 224 | customdialog.<a href="qdialog.html#exec">exec</a>();
|
---|
| 225 | }
|
---|
| 226 | </pre>
|
---|
| 227 |
|
---|
| 228 | <p> <p>See also <a href="motif-examples.html">QMotif Support Extension</a>.
|
---|
| 229 |
|
---|
| 230 | <!-- eof -->
|
---|
| 231 | <p><address><hr><div align=center>
|
---|
| 232 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 233 | <td>Copyright © 2007
|
---|
| 234 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 235 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 236 | </table></div></address></body>
|
---|
| 237 | </html>
|
---|