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 /* $XConsortium: term.c /main/3 1995/10/27 10:40:51 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994 Novell, Inc.
35 * Example code for DtTerm widget
37 * Create a terminal widget running a shell and provide
38 * push button shortcuts for shell commands. Regular shell
39 * commands can be entered also.
45 #include <Xm/MessageB.h>
51 static Widget toplevel;
53 static void CreateTerm(Widget, char *);
54 static void SendCommandCb(Widget, XtPointer, XtPointer);
55 static void AddCommandButton(Widget, char *, char *);
57 main(int argc, char **argv)
59 XtAppContext appContext;
64 Widget mainWindow, termContainer, termTitle;
66 /* Initialize DtTerm widget library */
70 toplevel = XtAppInitialize(&appContext, "Term", NULL, 0, &argc, argv,
74 XtSetArg(args[n], XmNdialogType, XmDIALOG_TEMPLATE); n++;
75 mainWindow = XmCreateMessageBox(toplevel, "mainWindow", args, n);
76 XtManageChild(mainWindow);
79 XtSetArg(args[n], XmNmarginWidth, 10); n++;
80 XtSetArg(args[n], XmNmarginHeight, 10); n++;
81 termContainer = XmCreateFrame(mainWindow, "termContainer", args, n);
82 XtManageChild(termContainer);
84 labelString = XmStringCreateLocalized("DtTerm with date and time shortcuts");
86 XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
87 XtSetArg(args[n], XmNlabelString, labelString); n++;
88 termTitle = XmCreateLabel(termContainer, "termTitle", args, n);
89 XtManageChild(termTitle);
90 XmStringFree(labelString);
92 /* Create the terminal widget */
94 CreateTerm(termContainer, "/bin/sh");
96 /* Add shortcut buttons to the message box */
98 AddCommandButton(mainWindow, "Today", "date\n");
99 AddCommandButton(mainWindow, "Month", "cal\n");
100 AddCommandButton(mainWindow, "1994", "clear;cal 1994\n");
101 AddCommandButton(mainWindow, "1995", "clear;cal 1995\n");
102 AddCommandButton(mainWindow, "1996", "clear;cal 1996\n");
103 AddCommandButton(mainWindow, "1997", "clear;cal 1997\n");
104 AddCommandButton(mainWindow, "1998", "clear;cal 1998\n");
105 AddCommandButton(mainWindow, "1999", "clear;cal 1999\n");
106 AddCommandButton(mainWindow, "2000", "clear;cal 2000\n");
108 XtRealizeWidget(toplevel);
109 XtAppMainLoop(appContext);
117 static void CreateTerm(Widget parent, char *cmd)
124 * Create a DtTerm widget.
125 * Pass the command to execute.
126 * Configure the window to fit a calendar year.
130 XtSetArg(args[n], DtNsubprocessCmd, cmd); n++;
131 XtSetArg(args[n], DtNrows, 46); n++;
132 XtSetArg(args[n], DtNcolumns, 80); n++;
133 term = DtCreateTerm(parent, "term", args, n);
137 static void AddCommandButton(Widget parent, char *label, char *cmd)
139 XmString labelString;
143 /* Create a pushbutton which will send a command to the terminal */
145 labelString = XmStringCreateLocalized(label);
146 XtSetArg(args[0], XmNlabelString, labelString);
147 button = XmCreatePushButton(parent, label, args, 1);
148 XtManageChild(button);
149 XmStringFree(labelString);
150 XtAddCallback(button, XmNactivateCallback, SendCommandCb, (XtPointer)cmd);
153 static void SendCommandCb(Widget w, XtPointer cd, XtPointer cb)
155 Widget term = XtNameToWidget(toplevel, "*term");
156 unsigned char *cmd = (unsigned char*)cd;
158 /* send the pushbutton command to the terminal widget */
160 DtTermSubprocSend(term, cmd, strlen((char*)cmd));