| 1 |
/* $XConsortium: hellomotif.c /main/5 1995/07/15 20:47:36 drk $ */ |
| 2 |
/* |
| 3 |
* Motif |
| 4 |
* |
| 5 |
* Copyright (c) 1987-2012, The Open Group. All rights reserved. |
| 6 |
* |
| 7 |
* These libraries and programs are free software; you can |
| 8 |
* redistribute them and/or modify them under the terms of the GNU |
| 9 |
* Lesser General Public License as published by the Free Software |
| 10 |
* Foundation; either version 2 of the License, or (at your option) |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* These libraries and programs are distributed in the hope that |
| 14 |
* they will be useful, but WITHOUT ANY WARRANTY; without even the |
| 15 |
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE. See the GNU Lesser General Public License for more |
| 17 |
* details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU Lesser General Public |
| 20 |
* License along with these librararies and programs; if not, write |
| 21 |
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth |
| 22 |
* Floor, Boston, MA 02110-1301 USA |
| 23 |
* |
| 24 |
*/ |
| 25 |
/* |
| 26 |
* HISTORY |
| 27 |
*/ |
| 28 |
#include <stdlib.h> |
| 29 |
#include <Xm/XmAll.h> |
| 30 |
|
| 31 |
#define APP_CLASS "XmdHelloMotif" |
| 32 |
|
| 33 |
/* Although it's really bad to hardcode Positions, keep this for |
| 34 |
a close hellomotif_in_c equivalence to the uil version */ |
| 35 |
#define NEW_BUTTON_X 11 |
| 36 |
/* not mentioning hardcoding labels... */ |
| 37 |
#define NEW_BUTTON_LABEL "Goodbye\nWorld!" |
| 38 |
|
| 39 |
|
| 40 |
static void Activate( |
| 41 |
Widget widget, |
| 42 |
XtPointer tag, |
| 43 |
XtPointer data); |
| 44 |
|
| 45 |
|
| 46 |
/* |
| 47 |
* Fallbacks: font, label and position go together in this demo |
| 48 |
*/ |
| 49 |
static String fallbacks[] = { |
| 50 |
"hellomotif_in_c.allowShellResize: True", |
| 51 |
"hellomotif_in_c*fontList: fixed", |
| 52 |
"*helloworld_label.labelString:Press button once\\nto change label;\\ntwice to exit.", |
| 53 |
"*helloworld_button.x: 15", |
| 54 |
"*helloworld_button.y: 60", |
| 55 |
"*helloworld_button.labelString:Hello\nWorld!", |
| 56 |
NULL |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
/* |
| 61 |
* Main program: create a shell, a pure bb with a label and a button |
| 62 |
* underneath it. Attach a callback to the button. |
| 63 |
*/ |
| 64 |
int main(int argc, char *argv[]) |
| 65 |
{ |
| 66 |
XtAppContext app_context; |
| 67 |
Widget top_level, helloworld_main, |
| 68 |
helloworld_label, helloworld_button ; |
| 69 |
|
| 70 |
/* |
| 71 |
* Initialize Xt and create a resizable shell |
| 72 |
*/ |
| 73 |
|
| 74 |
top_level = XtVaAppInitialize(&app_context, APP_CLASS, |
| 75 |
NULL, 0, &argc, argv, fallbacks, NULL); |
| 76 |
|
| 77 |
/* |
| 78 |
* Create the widget tree: first the bb parent. |
| 79 |
*/ |
| 80 |
|
| 81 |
helloworld_main = XtVaCreateManagedWidget ("helloworld_main", |
| 82 |
xmBulletinBoardWidgetClass, |
| 83 |
top_level, NULL); |
| 84 |
|
| 85 |
/* the label */ |
| 86 |
helloworld_label = XtVaCreateManagedWidget ("helloworld_label", |
| 87 |
xmLabelWidgetClass, |
| 88 |
helloworld_main, |
| 89 |
NULL); |
| 90 |
|
| 91 |
/* the button underneath the label */ |
| 92 |
helloworld_button = XtVaCreateManagedWidget ("helloworld_button", |
| 93 |
xmPushButtonWidgetClass, |
| 94 |
helloworld_main, |
| 95 |
NULL); |
| 96 |
/* add the callback to change the button label */ |
| 97 |
XtAddCallback(helloworld_button, XmNactivateCallback, Activate, NULL); |
| 98 |
|
| 99 |
/* |
| 100 |
* Realize the toplevel widget. This will cause the entire "managed" |
| 101 |
* widget hierarchy to be displayed |
| 102 |
*/ |
| 103 |
|
| 104 |
XtRealizeWidget(top_level); |
| 105 |
|
| 106 |
/* |
| 107 |
* Loop and process events |
| 108 |
*/ |
| 109 |
|
| 110 |
XtAppMainLoop(app_context); |
| 111 |
|
| 112 |
/* UNREACHABLE */ |
| 113 |
return (0); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
static void |
| 118 |
Activate( |
| 119 |
Widget widget, |
| 120 |
XtPointer tag, |
| 121 |
XtPointer data) |
| 122 |
|
| 123 |
{ |
| 124 |
static Boolean first_time = True ; |
| 125 |
|
| 126 |
/* First click: change the pushbutton label and recenter */ |
| 127 |
if (first_time) { |
| 128 |
XmString new_button_label = XmStringGenerate(NEW_BUTTON_LABEL, |
| 129 |
NULL, |
| 130 |
XmCHARSET_TEXT, NULL); |
| 131 |
XtVaSetValues(widget, |
| 132 |
XmNx, NEW_BUTTON_X, |
| 133 |
XmNlabelString, new_button_label, |
| 134 |
NULL); |
| 135 |
|
| 136 |
XmStringFree(new_button_label); |
| 137 |
first_time = False ; |
| 138 |
} else { |
| 139 |
exit(0); |
| 140 |
} |
| 141 |
} |