1 /* $XConsortium: term.c /main/3 1995/10/27 10:40:51 rswiston $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
6 * (c) Copyright 1993, 1994 Novell, Inc.
13 * Example code for DtTerm widget
15 * Create a terminal widget running a shell and provide
16 * push button shortcuts for shell commands. Regular shell
17 * commands can be entered also.
23 #include <Xm/MessageB.h>
29 static Widget toplevel;
31 static void CreateTerm(Widget, char *);
32 static void SendCommandCb(Widget, XtPointer, XtPointer);
33 static void AddCommandButton(Widget, char *, char *);
35 main(int argc, char **argv)
37 XtAppContext appContext;
42 Widget mainWindow, termContainer, termTitle;
44 /* Initialize DtTerm widget library */
48 toplevel = XtAppInitialize(&appContext, "Term", NULL, 0, &argc, argv,
52 XtSetArg(args[n], XmNdialogType, XmDIALOG_TEMPLATE); n++;
53 mainWindow = XmCreateMessageBox(toplevel, "mainWindow", args, n);
54 XtManageChild(mainWindow);
57 XtSetArg(args[n], XmNmarginWidth, 10); n++;
58 XtSetArg(args[n], XmNmarginHeight, 10); n++;
59 termContainer = XmCreateFrame(mainWindow, "termContainer", args, n);
60 XtManageChild(termContainer);
62 labelString = XmStringCreateLocalized("DtTerm with date and time shortcuts");
64 XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
65 XtSetArg(args[n], XmNlabelString, labelString); n++;
66 termTitle = XmCreateLabel(termContainer, "termTitle", args, n);
67 XtManageChild(termTitle);
68 XmStringFree(labelString);
70 /* Create the terminal widget */
72 CreateTerm(termContainer, "/bin/sh");
74 /* Add shortcut buttons to the message box */
76 AddCommandButton(mainWindow, "Today", "date\n");
77 AddCommandButton(mainWindow, "Month", "cal\n");
78 AddCommandButton(mainWindow, "1994", "clear;cal 1994\n");
79 AddCommandButton(mainWindow, "1995", "clear;cal 1995\n");
80 AddCommandButton(mainWindow, "1996", "clear;cal 1996\n");
81 AddCommandButton(mainWindow, "1997", "clear;cal 1997\n");
82 AddCommandButton(mainWindow, "1998", "clear;cal 1998\n");
83 AddCommandButton(mainWindow, "1999", "clear;cal 1999\n");
84 AddCommandButton(mainWindow, "2000", "clear;cal 2000\n");
86 XtRealizeWidget(toplevel);
87 XtAppMainLoop(appContext);
95 static void CreateTerm(Widget parent, char *cmd)
102 * Create a DtTerm widget.
103 * Pass the command to execute.
104 * Configure the window to fit a calendar year.
108 XtSetArg(args[n], DtNsubprocessCmd, cmd); n++;
109 XtSetArg(args[n], DtNrows, 46); n++;
110 XtSetArg(args[n], DtNcolumns, 80); n++;
111 term = DtCreateTerm(parent, "term", args, n);
115 static void AddCommandButton(Widget parent, char *label, char *cmd)
117 XmString labelString;
121 /* Create a pushbutton which will send a command to the terminal */
123 labelString = XmStringCreateLocalized(label);
124 XtSetArg(args[0], XmNlabelString, labelString);
125 button = XmCreatePushButton(parent, label, args, 1);
126 XtManageChild(button);
127 XmStringFree(labelString);
128 XtAddCallback(button, XmNactivateCallback, SendCommandCb, (XtPointer)cmd);
131 static void SendCommandCb(Widget w, XtPointer cd, XtPointer cb)
133 Widget term = XtNameToWidget(toplevel, "*term");
134 unsigned char *cmd = (unsigned char*)cd;
136 /* send the pushbutton command to the terminal widget */
138 DtTermSubprocSend(term, cmd, strlen((char*)cmd));