dtchat: add the T2.1 main window and layout

programs/dtchat: a Motif XmForm with File/Edit/View/Conversation/Help, a horizontal paned window (roster left, chat right), a read-only scrolled transcript, a three-line input, a Send button and a status line. --smoke-test maps the window, checks IsViewable and exits 0/1. Wired into configure.ac and programs/Makefile.am; only Xt/Xm/X11 are linked until T2.7 brings DtInitialize. Built smoke PASS; screenshot build/mcde-shots/dtchat-t21.png (760x540); PSS 5.5 MB (RSS 18.6 MB with the shared Xft Motif).
This commit is contained in:
lotherk committed 2026-11-16 18:13:23 +00:00
1 parent fa6b5cdfa4
commit 72e129de04
6 files changed
+505 -1

No files matched your search

+1
View File
@@ -951,6 +951,7 @@ programs/dtnetutility/Makefile
programs/dtimage/Makefile
programs/dtactivity/Makefile
programs/dtscreenshot/Makefile
programs/dtchat/Makefile
programs/dtcmprefs/Makefile
programs/dtpaint/Makefile
programs/dttoolbox/Makefile
+1 -1
View File
@@ -6,7 +6,7 @@ SUBDIRS = backdrops icons dsdm dtmail dtpad dtfile dterror dtwm dtlogin \
palettes dtappintegrate dtprintegrate dtconfig \
dtcreate dtprintinfo fontaliases dtdspmsg dtimsstart \
dtpdm dtsr dtpdmd dtinfo types tttypes util dtopen localized \
dthelp dtdocbook dtlaunch dtbar dtsystemsettings dtdiskutility dtbackup dtappscan dtkeys dtthemesync dtphoto dtpaint dttoolbox mcdesoundd dtconsole dtnetutility dtimage dtcmprefs dtactivity dtscreenshot dtcursor cursors fonts
dthelp dtdocbook dtlaunch dtbar dtsystemsettings dtdiskutility dtbackup dtappscan dtkeys dtthemesync dtphoto dtpaint dttoolbox mcdesoundd dtconsole dtnetutility dtimage dtcmprefs dtactivity dtscreenshot dtchat dtcursor cursors fonts
# The application builder and ttsnoop, its demonstration, need dtcodegen, a
# program the build runs: not in a cross build (--disable-appbuilder; the native
+15
View File
@@ -0,0 +1,15 @@
MAINTAINERCLEANFILES = Makefile.in
bin_PROGRAMS = dtchat
dtchat_CPPFLAGS = -I$(top_srcdir)/include \
-DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\"
# T2.1 needs only Motif/Xt/Xlib; DtInitialize and DTCLIENTLIBS come with T2.7.
dtchat_LDADD = $(XTOOLLIB)
dtchat_SOURCES = main.c ui_main.c ui_main.h
if SOLARIS
dtchat_LDADD += -lintl
endif
+93
View File
@@ -0,0 +1,93 @@
/*
* main.c -- dtchat's entry point and the --smoke-test
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* T2.1 is the shell: the main window, the menu bar, the roster/chat panes and
* the status line. The model, accounts and protocols are wired in T2.2-T2.6.
*/
#define _POSIX_C_SOURCE 200809L
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include "ui_main.h"
static XtAppContext app;
static Widget toplevel;
static int smoke_failed;
static void
smoke_check(XtPointer client, XtIntervalId *id)
{
DtChatUi *ui = client;
(void)id;
XSync(XtDisplay(toplevel), False);
if (dtchat_ui_is_viewable(ui)) {
printf("dtchat smoke: PASS\n");
} else {
printf("dtchat smoke: FAIL window not viewable\n");
smoke_failed = 1;
}
XtAppSetExitFlag(app);
}
int
main(int argc, char **argv)
{
static String fallback[] = {
"*fontList: fixed",
"Dtchat*roster.fontList: fixed",
"Dtchat*transcript.fontList: fixed",
"Dtchat*input.fontList: fixed",
"Dtchat*status.fontList: fixed",
"Dtchat*menuBar.fontList: fixed",
NULL
};
DtChatUi *ui;
int smoke = 0;
int i;
/*
* Xt does not know --smoke-test; remove it before XtVaAppInitialize
* so it is not mistaken for a file argument.
*/
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--smoke-test") == 0) {
smoke = 1;
memmove(&argv[i], &argv[i + 1],
(size_t)(argc - i) * sizeof(argv[0]));
argc--;
i--;
}
}
setlocale(LC_ALL, "");
XtSetLanguageProc(NULL, NULL, NULL);
toplevel = XtVaAppInitialize(&app, "Dtchat", NULL, 0, &argc, argv,
fallback,
XmNtitle, "dtchat",
XmNwidth, 760,
XmNheight, 540,
NULL);
ui = dtchat_ui_create(toplevel);
if (ui == NULL) {
fprintf(stderr, "dtchat: out of memory\n");
return 1;
}
XtRealizeWidget(toplevel);
if (smoke) {
XMapRaised(XtDisplay(toplevel), XtWindow(toplevel));
XtAppAddTimeOut(app, 800, smoke_check, ui);
}
XtAppMainLoop(app);
dtchat_ui_destroy(ui);
return smoke_failed ? 1 : 0;
}
+373
View File
@@ -0,0 +1,373 @@
/*
* ui_main.c -- the T2.1 main window of dtchat
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* The shell is one Motif form: menu bar, a horizontal paned window with the
* roster on the left and the chat on the right, and a status line at the
* bottom. T2.2-T2.6 replace the placeholders with the model, the accounts,
* the transcript binding and the demo adapter; T2.1 only has to be a real,
* viewable window with the right geometry.
*/
#define _POSIX_C_SOURCE 200809L
#include "ui_main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <Xm/CascadeB.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/List.h>
#include <Xm/PanedW.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/ScrolledW.h>
#include <Xm/Separator.h>
#include <Xm/Text.h>
#include <Xm/Xm.h>
struct DtChatUi {
Widget shell;
Widget roster;
Widget transcript;
Widget input;
Widget status;
};
typedef struct {
DtChatUi *ui;
const char *what;
} NotImpl;
static XmString
xs(const char *s)
{
return XmStringCreateLocalized((char *)s);
}
static void
set_status(DtChatUi *ui, const char *text)
{
XmString x = xs(text);
XtVaSetValues(ui->status, XmNlabelString, x, NULL);
XmStringFree(x);
}
static void
quit_cb(Widget w, XtPointer client, XtPointer call)
{
(void)client;
(void)call;
XtAppSetExitFlag(XtWidgetToApplicationContext(w));
}
static void
not_implemented_cb(Widget w, XtPointer client, XtPointer call)
{
NotImpl *ni = client;
char line[160];
(void)w;
(void)call;
snprintf(line, sizeof(line), "%s is not implemented yet", ni->what);
set_status(ni->ui, line);
}
static XtPointer
not_impl(DtChatUi *ui, const char *what)
{
NotImpl *ni = malloc(sizeof(*ni));
if (ni == NULL)
return NULL;
ni->ui = ui;
ni->what = what;
return ni;
}
static void
clear_cb(Widget w, XtPointer client, XtPointer call)
{
DtChatUi *ui = client;
(void)w;
(void)call;
XmTextSetString(ui->transcript, "");
set_status(ui, "transcript cleared");
}
static void
about_cb(Widget w, XtPointer client, XtPointer call)
{
DtChatUi *ui = client;
(void)w;
(void)call;
set_status(ui, "dtchat 0.1 - MCDE chat (T2.1 shell)");
}
static void
send_cb(Widget w, XtPointer client, XtPointer call)
{
DtChatUi *ui = client;
char *text;
char *line;
size_t len;
(void)w;
(void)call;
text = XmTextGetString(ui->input);
if (text == NULL || *text == '\0') {
XtFree(text);
return;
}
len = strlen(text) + 8;
line = malloc(len);
if (line != NULL) {
snprintf(line, len, "[me] %s\n", text);
XmTextInsert(ui->transcript,
XmTextGetLastPosition(ui->transcript), line);
XmTextShowPosition(ui->transcript,
XmTextGetLastPosition(ui->transcript));
free(line);
}
XmTextSetString(ui->input, "");
set_status(ui, "demo: no account connected");
XtFree(text);
}
static Widget
make_menu(Widget bar, const char *label)
{
static int menu_no;
char menu_name[32], cascade_name[32];
Widget menu, cascade;
XmString x;
snprintf(menu_name, sizeof(menu_name), "menu%d", ++menu_no);
snprintf(cascade_name, sizeof(cascade_name), "cascade%d", menu_no);
menu = XmCreatePulldownMenu(bar, menu_name, NULL, 0);
cascade = XmCreateCascadeButton(bar, cascade_name, NULL, 0);
x = xs(label);
XtVaSetValues(cascade, XmNlabelString, x, XmNsubMenuId, menu, NULL);
XmStringFree(x);
XtManageChild(cascade);
return menu;
}
static Widget
make_item(Widget menu, const char *label, XtCallbackProc cb, XtPointer data)
{
static int item_no;
char name[32];
Widget item;
XmString x;
snprintf(name, sizeof(name), "item%d", ++item_no);
item = XmCreatePushButton(menu, name, NULL, 0);
x = xs(label);
XtVaSetValues(item, XmNlabelString, x, NULL);
XmStringFree(x);
if (cb != NULL)
XtAddCallback(item, XmNactivateCallback, cb, data);
XtManageChild(item);
return item;
}
static void
make_separator(Widget menu)
{
static int sep_no;
char name[32];
Widget sep;
snprintf(name, sizeof(name), "sep%d", ++sep_no);
sep = XmCreateSeparator(menu, name, NULL, 0);
XtManageChild(sep);
}
static void
make_menu_bar(DtChatUi *ui, Widget form, Widget *bar_out)
{
Widget bar = XmCreateMenuBar(form, "menuBar", NULL, 0);
Widget file, edit, view, conversation, help;
XtVaSetValues(bar, XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
XtManageChild(bar);
*bar_out = bar;
file = make_menu(bar, "File");
(void)make_item(file, "New Conversation", not_implemented_cb,
not_impl(ui, "New conversation"));
(void)make_item(file, "Add Account", not_implemented_cb,
not_impl(ui, "Add account"));
make_separator(file);
(void)make_item(file, "Quit", quit_cb, NULL);
edit = make_menu(bar, "Edit");
(void)make_item(edit, "Cut", not_implemented_cb,
not_impl(ui, "Cut"));
(void)make_item(edit, "Copy", not_implemented_cb,
not_impl(ui, "Copy"));
(void)make_item(edit, "Paste", not_implemented_cb,
not_impl(ui, "Paste"));
make_separator(edit);
(void)make_item(edit, "Clear Transcript", clear_cb, ui);
view = make_menu(bar, "View");
(void)make_item(view, "Show Offline", not_implemented_cb,
not_impl(ui, "Show offline"));
(void)make_item(view, "Timestamps", not_implemented_cb,
not_impl(ui, "Timestamps"));
conversation = make_menu(bar, "Conversation");
(void)make_item(conversation, "Join Channel", not_implemented_cb,
not_impl(ui, "Join a channel"));
(void)make_item(conversation, "Send File", not_implemented_cb,
not_impl(ui, "Send a file"));
(void)make_item(conversation, "Call", not_implemented_cb,
not_impl(ui, "Call"));
help = make_menu(bar, "Help");
(void)make_item(help, "About dtchat", about_cb, ui);
}
DtChatUi *
dtchat_ui_create(Widget shell)
{
DtChatUi *ui = calloc(1, sizeof(*ui));
Widget form, bar, paned, roster_parent, chat;
Widget transcript_parent, input_parent, send;
XmString x;
if (ui == NULL)
return NULL;
ui->shell = shell;
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, shell,
XmNwidth, 760, XmNheight, 540,
XmNmarginWidth, 2, XmNmarginHeight, 2, NULL);
make_menu_bar(ui, form, &bar);
ui->status = XmCreateLabel(form, "status", NULL, 0);
x = xs("offline - no accounts");
XtVaSetValues(ui->status, XmNlabelString, x,
XmNalignment, XmALIGNMENT_BEGINNING,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNheight, 22, XmNmarginWidth, 4, NULL);
XmStringFree(x);
XtManageChild(ui->status);
paned = XtVaCreateManagedWidget("paned", xmPanedWindowWidgetClass,
form, XmNorientation, XmHORIZONTAL,
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, bar,
XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, ui->status,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNsashWidth, 4, XmNsashHeight, 4, XmNspacing, 0, NULL);
ui->roster = XmCreateScrolledList(paned, "roster", NULL, 0);
roster_parent = XtParent(ui->roster);
XtVaSetValues(roster_parent, XmNwidth, 230, NULL);
XtVaSetValues(ui->roster, XmNvisibleItemCount, 20,
XmNselectionPolicy, XmBROWSE_SELECT, NULL);
XmListAddItemUnselected(ui->roster, xs("Nearby"), 0);
XmListAddItemUnselected(ui->roster, xs(" (no peers yet)"), 0);
XmListAddItemUnselected(ui->roster, xs("Accounts"), 0);
XmListAddItemUnselected(ui->roster, xs(" (no accounts yet)"), 0);
XtManageChild(ui->roster);
chat = XtVaCreateManagedWidget("chat", xmFormWidgetClass, paned,
NULL);
ui->transcript = XmCreateScrolledText(chat, "transcript", NULL, 0);
transcript_parent = XtParent(ui->transcript);
ui->input = XmCreateScrolledText(chat, "input", NULL, 0);
input_parent = XtParent(ui->input);
send = XmCreatePushButton(chat, "send", NULL, 0);
XtVaSetValues(ui->transcript, XmNrows, 16, XmNcolumns, 60,
XmNeditable, False, XmNeditMode, XmMULTI_LINE_EDIT,
XmNwordWrap, True, XmNscrollHorizontal, False,
XmNcursorPositionVisible, False, XmNmarginWidth, 6,
XmNmarginHeight, 6, NULL);
XtVaSetValues(ui->input, XmNrows, 3, XmNcolumns, 40,
XmNeditMode, XmMULTI_LINE_EDIT, XmNwordWrap, True,
XmNmarginWidth, 4, XmNmarginHeight, 4, NULL);
x = xs("Send");
XtVaSetValues(send, XmNlabelString, x,
XmNwidth, 84, XmNheight, 30, NULL);
XmStringFree(x);
XtVaSetValues(transcript_parent,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, input_parent, NULL);
XtVaSetValues(input_parent,
XmNleftAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, send, NULL);
XtVaSetValues(send,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM, NULL);
XtManageChild(ui->transcript);
XtManageChild(ui->input);
XtAddCallback(send, XmNactivateCallback, send_cb, ui);
XtManageChild(send);
dtchat_ui_append_system(ui,
"dtchat T2.1 - the shell is ready (no account connected)");
XtManageChild(chat);
return ui;
}
void
dtchat_ui_destroy(DtChatUi *ui)
{
free(ui);
}
int
dtchat_ui_is_viewable(DtChatUi *ui)
{
XWindowAttributes attr;
if (ui == NULL || !XtIsRealized(ui->shell))
return 0;
if (!XGetWindowAttributes(XtDisplay(ui->shell), XtWindow(ui->shell),
&attr))
return 0;
return attr.map_state == IsViewable;
}
void
dtchat_ui_append_system(DtChatUi *ui, const char *text)
{
char *line;
size_t len;
if (ui == NULL || text == NULL)
return;
len = strlen(text) + 7;
line = malloc(len);
if (line == NULL)
return;
snprintf(line, len, "-- %s\n", text);
XmTextInsert(ui->transcript, XmTextGetLastPosition(ui->transcript),
line);
XmTextShowPosition(ui->transcript,
XmTextGetLastPosition(ui->transcript));
free(line);
}
+22
View File
@@ -0,0 +1,22 @@
/*
* ui_main.h -- the T2.1 shell of dtchat
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*/
#ifndef _Dtchat_ui_main_h
#define _Dtchat_ui_main_h
#include <X11/Intrinsic.h>
typedef struct DtChatUi DtChatUi;
DtChatUi *dtchat_ui_create(Widget shell);
void dtchat_ui_destroy(DtChatUi *ui);
/* True when the shell is realized and its map state is IsViewable. */
int dtchat_ui_is_viewable(DtChatUi *ui);
/* Append a system line to the transcript (used by the smoke/demo path). */
void dtchat_ui_append_system(DtChatUi *ui, const char *text);
#endif /* _Dtchat_ui_main_h */