2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: ttsample1.c /main/3 1995/10/23 09:46:53 rswiston $ */
29 * ttsample1 -- dynamic pattern, procedural notification
33 #include <sys/param.h>
34 #include <sys/types.h>
42 #include <Xm/MwmUtil.h>
46 Widget toplevel, base_frame, controls, slider, gauge, button;
49 void broadcast_value();
50 void receive_tt_message();
51 void create_ui_components();
64 * Initialize Motif and create ui components
66 toplevel = XtVaAppInitialize(&app, "ttsample1", NULL, 0,
67 &argc, argv, NULL, NULL);
68 XtVaSetValues(toplevel, XmNtitle, "ToolTalk Sample 1", 0);
69 create_ui_components();
72 * Initialize ToolTalk, using the initial default session, and
73 * obtain the file descriptor that will become active whenever
74 * ToolTalk has a message for this process.
77 my_procid = tt_open();
81 * Arrange for Motif to call receive_tt_message when the ToolTalk
82 * file descriptor becomes active.
85 XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
86 receive_tt_message, 0);
89 * Create and register a pattern so ToolTalk knows we are interested
90 * in "ttsample1_value" messages within the session we join.
93 pat = tt_pattern_create();
94 tt_pattern_category_set(pat, TT_OBSERVE);
95 tt_pattern_scope_add(pat, TT_SESSION);
96 tt_pattern_op_add(pat, "ttsample1_value");
97 tt_pattern_register(pat);
100 * Join the default session
103 tt_session_join(tt_default_session());
106 * Turn control over to Motif.
108 XtRealizeWidget(toplevel);
112 * Before leaving, allow ToolTalk to clean up.
121 * When the button is pressed, broadcast the new slider value.
124 broadcast_value(widget, client_data, call_data)
126 XtPointer client_data, call_data;
132 * Create and send a ToolTalk notice message
133 * ttsample1_value(in int <new value)
136 XtVaGetValues(slider, XmNvalue, &slider_value, 0);
137 msg_out = tt_pnotice_create(TT_SESSION, "ttsample1_value");
138 tt_message_arg_add(msg_out, TT_IN, "integer", NULL);
139 tt_message_arg_ival_set(msg_out, 0, slider_value);
140 tt_message_send(msg_out);
143 * Since this message is a notice, we don't expect a reply, so
144 * there's no reason to keep a handle for the message.
147 tt_message_destroy(msg_out);
151 * When a ToolTalk message is available, receive it; if it's a
152 * ttsample1_value message, update the gauge with the new value.
155 receive_tt_message(client_data, fid, id)
156 XtPointer client_data;
166 msg_in = tt_message_receive();
169 * It's possible that the file descriptor would become active
170 * even though ToolTalk doesn't really have a message for us.
171 * The returned message handle is NULL in this case.
174 if (msg_in == NULL) return;
178 * Get a storage mark so we can easily free all the data
179 * ToolTalk returns to us.
184 op = tt_message_op(msg_in);
185 err = tt_ptr_error(op);
186 if (err > TT_WRN_LAST) {
187 printf( "tt_message_op(): %s\n", tt_status_message(err));
188 } else if (op != 0) {
189 if (0==strcmp("ttsample1_value", tt_message_op(msg_in))) {
190 tt_message_arg_ival(msg_in, 0, &val_in);
191 XtVaSetValues(gauge, XmNvalue, val_in, 0);
195 tt_message_destroy(msg_in);
201 * Straight Motif calls for creating the ui elements. No
202 * ToolTalk-specific code here.
205 create_ui_components()
208 Widget glabel, slabel;
211 base_frame = XtVaCreateManagedWidget("base_frame",
212 xmMainWindowWidgetClass, toplevel,
216 XtVaGetValues(base_frame, XmNmwmDecorations, &decor, 0);
217 decor &= ~MWM_DECOR_RESIZEH;
218 XtVaSetValues(base_frame, XmNmwmDecorations, &decor, 0);
220 controls = XtVaCreateManagedWidget("controls",
221 xmFormWidgetClass, base_frame, NULL, 0, 0);
223 slabel = XtVaCreateManagedWidget("Send:",
224 xmLabelWidgetClass, controls,
228 slider = XtVaCreateManagedWidget("slider",
229 xmScaleWidgetClass, controls,
230 XmNleftAttachment, XmATTACH_WIDGET,
231 XmNleftWidget, slabel,
232 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
233 XmNtopWidget, slabel,
238 XmNorientation, XmHORIZONTAL,
241 glabel = XtVaCreateManagedWidget("Received:",
242 xmLabelWidgetClass, controls,
246 gauge = XtVaCreateManagedWidget("gauge",
247 xmScaleWidgetClass, controls,
248 XmNleftAttachment, XmATTACH_WIDGET,
249 XmNleftWidget, glabel,
250 XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
251 XmNtopWidget, glabel,
252 XmNorientation, XmHORIZONTAL,
260 label = XmStringCreateSimple("Broadcast");
261 button = XtVaCreateManagedWidget("button",
262 xmPushButtonWidgetClass, controls,
267 XmNlabelString, label,
270 XtAddCallback(button, XmNactivateCallback, broadcast_value, 0);