Files
lotherkandClaude Sonnet 5.5 cc770d000e dtfile: a mount no longer freezes the window; Connecting dialog, Cancel, Dtfile*connectTimeout (t0080 item 4)
mcde_sys_net_mount ran in the Xt callback and waited for sshfs/mount_afp
without a limit: a server that is gone froze the window for as long as the
tool lived (measured: the call returns after 20.0 s with a tool that sleeps
20 s; with one that never ends, never).

McdeSys: mcde_sys_net_mount_start/_job_fd/_job_finish/_job_cancel.  The tool
runs under a runner process (its own process group) that writes the answer
to a pipe: dtfile sets SIGCHLD to SIG_IGN (Main.c), where waitpid gives no
status.  mcde_sys_net_mount and _start share one plan (MountPlanFor).
test_job (make check, 5 of 5 pass) covers success, failure, a missing tool,
a password on stdin, and cancel with the tool AND what it started gone, with
SIGCHLD default and ignored; without the group kill it fails (mutant run).

dtfile: _McdeNetMount (NetView.c) for all three mounts (network view,
Connect to Server, column view): a modal "Connecting ..." dialog with Cancel
(also close button and Escape), the descriptor as Xt input (no timer
polling), one time-out, Dtfile*connectTimeout, 20 s, 3..600 (app-defaults,
man page).

Measured (real dtfile on Xvfb, fake sshfs that sleeps 40 s, connectTimeout
4): the dialog shows and repaints when moved; the time-out gives "Could not
connect: The server did not answer within 4 seconds.", Escape gives
"Could not connect: Cancelled."; sleep processes while connecting 1, after
the time-out 0, after Escape 0; no dialog left.  One first run showed a 40 s
stall of the whole session after Return (import blocked too); not
reproduced in three further runs, cause unknown.  Cross compile for NetBSD
(x86_64--netbsd-gcc, the build's flags): netmount.c and NetView.c without a
warning; common.c's old settimeofday declaration warning is not new.  Not
done: the NFS and AFP tools (only sshfs was faked), the afp://10.255.255.1/
case of the task with a real mount_afp.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 00:28:27 +00:00

761 lines
21 KiB
C

/*
* Columns.c -- MCDE: the column view of the file manager window
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* A fourth view beside CDE's icons, small icons and list (Navigation.c): one
* column for each folder from the place it lies in (Home, or the Computer)
* down to the folder shown, and on the right what is chosen -- its icon,
* name, kind, size and date. A folder chosen in a column opens the next
* column and becomes the window's folder through dtfile's own
* ChangeDirectoryToParent (_McdeNavGoTo), so title, history and the other
* views follow; a file is opened with a double click by the first action
* of its data type, as dtfile runs a default action (Command.c,
* DtActionInvoke).
*
* The columns replace the work area while the view is on: they are a
* sibling of CDE's work frame with the same attachments. As many columns
* as fit are shown, the deepest ones.
*
* C99, POSIX and Motif (ext/src/mcde/AGENTS.md).
*/
#include <ctype.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/List.h>
#include <Xm/RowColumn.h>
#include <Dt/Action.h>
#include <Dt/Dts.h>
#include <Dt/SharedProcs.h>
#include <Mcde/McdeSys.h>
#include <Mcde/Sound.h> /* McdeSoundEvent, used on a launch */
#include "Encaps.h"
#include "SharedProcs.h"
#include "FileMgr.h"
#include "Navigation.h"
#include "Peek.h"
#define COLUMN_WIDTH 180
#define PREVIEW_WIDTH 210
#define MAX_COLUMNS 32
typedef struct {
char *dir; /* the folder the column shows */
char **names; /* its entries, sorted */
char **proto; /* "smb"/"nfs" for a share, NULL otherwise */
int n;
Widget list; /* the scrolled list */
} Column;
/* the columns of one window; kept here, not in FileMgrRec, whose fields are
* CDE's, beside one widget (rec->mcde_columns) */
#define MAX_WINDOWS 32
static struct {
FileMgrRec *rec;
Column col[MAX_COLUMNS];
int ncol;
Widget preview, picon, pname, pinfo;
} wins[MAX_WINDOWS];
static int
WinOf(FileMgrRec *rec, Boolean make)
{
int i;
for (i = 0; i < MAX_WINDOWS; i++)
if (wins[i].rec == rec)
return i;
if (!make)
return -1;
for (i = 0; i < MAX_WINDOWS; i++)
if (wins[i].rec == NULL) {
memset(&wins[i], 0, sizeof wins[i]);
wins[i].rec = rec;
return i;
}
return -1;
}
static int
NameCompare(const void *a, const void *b)
{
return strcasecmp(*(char *const *)a, *(char *const *)b);
}
static Boolean
IsDir(const char *path)
{
struct stat st;
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
}
static char *
Join(const char *dir, const char *name)
{
size_t n = strlen(dir) + strlen(name) + 2;
char *p = XtMalloc((Cardinal)n);
(void)snprintf(p, n, "%s%s%s", dir,
strcmp(dir, "/") == 0 ? "" : "/", name);
return p;
}
static void
SetLabel(Widget w, const char *text)
{
XmString s = XmStringCreateLocalized((char *)text);
XtVaSetValues(w, XmNlabelString, s, NULL);
XmStringFree(s);
}
/* ---- the preview -------------------------------------------------------- */
static void
Preview(int k, const char *path)
{
Widget form = wins[k].preview;
char info[512], when[64], kind[160], *type = NULL, *label = NULL;
char *mime = NULL, *icon = NULL;
const char *name = strrchr(path, '/');
struct stat st;
Pixmap pm = XmUNSPECIFIED_PIXMAP;
name = name != NULL && name[1] != '\0' ? name + 1 : path;
if (stat(path, &st) != 0) {
SetLabel(wins[k].pname, name);
SetLabel(wins[k].pinfo, "");
return;
}
type = DtDtsFileToDataType((char *)path);
if (type != NULL) {
label = DtDtsDataTypeToAttributeValue(type, "TYPE_LABEL", NULL);
mime = DtDtsDataTypeToAttributeValue(type, "MIME_TYPE", NULL);
icon = DtDtsDataTypeToAttributeValue(type, DtDTS_DA_ICON, NULL);
}
/* the kind, short: the type's label ("TEXTFILE", "TRASH_FOLDER") read
* as words, and its MIME type; the DESCRIPTION is a paragraph */
{
const char *l = label != NULL ? label : (type != NULL ? type :
(S_ISDIR(st.st_mode) ? "FOLDER" : "FILE"));
size_t i, n = 0;
for (i = 0; l[i] != '\0' && n + 1 < sizeof kind; i++)
kind[n++] = l[i] == '_' ? ' ' : (char)(i == 0 ?
toupper((unsigned char)l[i]) :
tolower((unsigned char)l[i]));
kind[n] = '\0';
if (mime != NULL && mime[0] != '\0')
(void)snprintf(kind + n, sizeof kind - n, " (%s)", mime);
}
/* the large icon of the type, as CDE names them (NAME.l.pm) */
if (icon != NULL) {
static const char *const sizes[] = { ".l.pm", ".m.pm", ".l.bm" };
char buf[256];
size_t i;
Pixel fg, bg;
XtVaGetValues(form, XmNforeground, &fg, XmNbackground, &bg, NULL);
/* by Motif's icon search path first, then in CDE's own
* directory (a session without XMICONSEARCHPATH) */
for (i = 0; i < sizeof sizes / sizeof sizes[0] &&
pm == XmUNSPECIFIED_PIXMAP; i++) {
(void)snprintf(buf, sizeof buf, "%s%s", icon, sizes[i]);
pm = XmGetPixmap(XtScreen(form), buf, fg, bg);
if (pm == XmUNSPECIFIED_PIXMAP) {
(void)snprintf(buf, sizeof buf,
"%s/appconfig/icons/C/%s%s",
CDE_INSTALLATION_TOP, icon, sizes[i]);
pm = XmGetPixmap(XtScreen(form), buf, fg, bg);
}
}
}
/* the icon label is made anew: Motif takes a label's pixmap reliably
* only when the label is created (measured in dtsystemsettings) */
if (wins[k].picon != NULL)
XtDestroyWidget(wins[k].picon);
wins[k].picon = XtVaCreateManagedWidget("mcdePreviewIcon",
xmLabelWidgetClass, form,
XmNlabelType, pm != XmUNSPECIFIED_PIXMAP ? XmPIXMAP : XmSTRING,
XmNlabelPixmap, pm, XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 16, XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
if (pm == XmUNSPECIFIED_PIXMAP)
SetLabel(wins[k].picon, "");
XtVaSetValues(wins[k].pname, XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wins[k].picon, XmNtopOffset, 12, NULL);
SetLabel(wins[k].pname, name);
(void)strftime(when, sizeof when, "%e %b %Y, %H:%M",
localtime(&st.st_mtime));
if (S_ISDIR(st.st_mode))
(void)snprintf(info, sizeof info, "Kind: %s\nModified: %s",
kind, when);
else
(void)snprintf(info, sizeof info,
"Kind: %s\nSize: %.1f KB (%lld bytes)\nModified: %s",
kind, (double)st.st_size / 1024.0, (long long)st.st_size,
when);
SetLabel(wins[k].pinfo, info);
if (label != NULL)
DtDtsFreeAttributeValue(label);
if (mime != NULL)
DtDtsFreeAttributeValue(mime);
if (icon != NULL)
DtDtsFreeAttributeValue(icon);
if (type != NULL)
DtDtsFreeDataType(type);
}
/* ---- the columns -------------------------------------------------------- */
static void ColumnChosen(Widget w, XtPointer client, XtPointer call);
static void ColumnOpen(Widget w, XtPointer client, XtPointer call);
static void
FreeColumn(Column *c)
{
int i;
for (i = 0; i < c->n; i++) {
XtFree(c->names[i]);
if (c->proto != NULL)
XtFree(c->proto[i]);
}
XtFree((char *)c->names);
XtFree((char *)c->proto);
XtFree(c->dir);
if (c->list != NULL)
XtDestroyWidget(XtParent(c->list));
memset(c, 0, sizeof *c);
}
/* how many columns fit beside the preview */
static int
Fitting(FileMgrRec *rec)
{
Dimension w = 0;
int n;
XtVaGetValues(rec->mcde_columns, XmNwidth, &w, NULL);
n = ((int)w - PREVIEW_WIDTH) / COLUMN_WIDTH;
return n < 1 ? 1 : n;
}
/* attach the shown columns left to right, the deepest ones that fit */
static void
Layout(int k)
{
FileMgrRec *rec = wins[k].rec;
int fit = Fitting(rec), first = wins[k].ncol - fit, i;
Widget left = NULL;
if (first < 0)
first = 0;
for (i = 0; i < wins[k].ncol; i++) {
Widget sw = XtParent(wins[k].col[i].list);
if (i < first) {
XtUnmanageChild(sw);
continue;
}
XtVaSetValues(sw, XmNleftAttachment,
left != NULL ? XmATTACH_WIDGET : XmATTACH_FORM,
XmNleftWidget, left, NULL);
XtManageChild(sw);
left = sw;
}
}
/* ~/Network is the network: the hosts found there and their shares, as the
* network view shows them (NetView.c), here as folders one walks into */
static const char *
NetRoot(void)
{
static char path[1024];
const char *home = getenv("HOME");
if (home == NULL)
return NULL;
(void)snprintf(path, sizeof path, "%s/Network", home);
return path;
}
static Boolean
IsNetRoot(const char *dir)
{
const char *root = NetRoot();
return root != NULL && strcmp(dir, root) == 0;
}
/* DIR is ~/Network/HOST: the host into HOST and 1 */
static int
NetHost(const char *dir, char *host, size_t len)
{
const char *root = NetRoot(), *h;
size_t n;
if (root == NULL)
return 0;
n = strlen(root);
if (strncmp(dir, root, n) != 0 || dir[n] != '/' || dir[n + 1] == '\0')
return 0;
h = dir + n + 1;
if (strchr(h, '/') != NULL) /* a share's own folder */
return 0;
(void)snprintf(host, len, "%s", h);
return 1;
}
static Boolean
IsNetHostPath(const char *dir)
{
char host[256];
return NetHost(dir, host, sizeof host) != 0;
}
/* the hosts of the network; each is a column of its shares */
static void
NetAddHosts(Column *c)
{
McdeSysNetHost hosts[32];
int n = mcde_sys_net_browse(hosts, 32, 1500), i;
for (i = 0; i < n; i++) {
const char *name = hosts[i].name[0] != '\0' ? hosts[i].name :
hosts[i].host;
c->names = (char **)XtRealloc((char *)c->names,
(Cardinal)((c->n + 1) * sizeof(char *)));
if (c->proto != NULL)
c->proto = (char **)XtRealloc((char *)c->proto,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->names[c->n] = XtNewString(name);
if (c->proto != NULL)
c->proto[c->n] = NULL;
c->n++;
}
}
/* what HOST shares: its NFS exports and its SMB shares */
static void
NetAddShares(Column *c, const char *host)
{
static char names[256][256];
int n, i, kind;
for (kind = 0; kind < 2; kind++) {
n = mcde_sys_net_shares(host, kind == 0 ? MCDE_NET_HAS_NFS :
MCDE_NET_HAS_SMB, names, 256);
if (n < 0)
continue;
for (i = 0; i < n; i++) {
c->names = (char **)XtRealloc((char *)c->names,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->proto = (char **)XtRealloc((char *)c->proto,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->names[c->n] = XtNewString(names[i]);
c->proto[c->n] = XtNewString(kind == 0 ? "nfs" :
"smb");
c->n++;
}
}
}
static void
AddColumn(int k, const char *dir)
{
FileMgrRec *rec = wins[k].rec;
Column *c;
DIR *d;
struct dirent *de;
Arg args[10];
int n = 0, cap = 0, i;
if (wins[k].ncol >= MAX_COLUMNS)
return;
c = &wins[k].col[wins[k].ncol];
memset(c, 0, sizeof *c);
c->dir = XtNewString(dir);
{
char host[256];
if (IsNetRoot(dir)) {
NetAddHosts(c);
d = NULL;
} else if (NetHost(dir, host, sizeof host)) {
NetAddShares(c, host);
d = NULL;
} else
d = opendir(dir);
}
if (d != NULL) {
while ((de = readdir(d)) != NULL) {
if (de->d_name[0] == '.')
continue; /* hidden, as dtfile hides them */
if (c->n == cap) {
cap = cap ? 2 * cap : 64;
c->names = (char **)XtRealloc((char *)c->names,
(Cardinal)(cap * sizeof(char *)));
}
c->names[c->n++] = XtNewString(de->d_name);
}
closedir(d);
}
if (c->n > 0)
qsort(c->names, (size_t)c->n, sizeof(char *), NameCompare);
XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNwidth, COLUMN_WIDTH); n++;
XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++;
XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++;
c->list = XmCreateScrolledList(rec->mcde_columns, "mcdeColumn",
args, n);
XtVaSetValues(XtParent(c->list), XmNwidth, COLUMN_WIDTH, NULL);
for (i = 0; i < c->n; i++) {
char *path = Join(dir, c->names[i]), label[600];
XmString s;
/* a folder says so: it leads on; a host too */
(void)snprintf(label, sizeof label, "%s%s", c->names[i],
IsDir(path) || IsNetHostPath(path) ? " >" : "");
XtFree(path);
s = XmStringCreateLocalized(label);
XmListAddItemUnselected(c->list, s, 0);
XmStringFree(s);
}
XtAddCallback(c->list, XmNbrowseSelectionCallback, ColumnChosen,
(XtPointer)rec);
XtAddCallback(c->list, XmNdefaultActionCallback, ColumnOpen,
(XtPointer)rec);
/* MCDE: Space and Escape mean the same here as in the work area, which
* the list has taken the focus from (Peek.c) */
{
char trans[256];
(void)snprintf(trans, sizeof trans,
"<Key>space:McdeKey(%p,peek)\n"
"<Key>osfCancel:McdeKey(%p,peekesc)", (void *)rec,
(void *)rec);
XtOverrideTranslations(c->list,
XtParseTranslationTable(trans));
}
XtManageChild(c->list);
wins[k].ncol++;
}
static int Chosen(int k, Widget list, int *entry);
/* MCDE: the entry the column view has chosen, the deepest one; the space
* key of the window previews it (Peek.c). The caller frees the string. */
char *
_McdeColumnsChosen(FileMgrRec *rec)
{
int k = WinOf(rec, False), ci, entry;
if (k < 0 || !rec->mcde_columns_on)
return NULL;
for (ci = wins[k].ncol - 1; ci >= 0; ci--) {
if (Chosen(k, wins[k].col[ci].list, &entry) == ci)
return Join(wins[k].col[ci].dir,
wins[k].col[ci].names[entry]);
}
return NULL;
}
/* the column of LIST, and the entry chosen in it; -1 if none */
static int
Chosen(int k, Widget list, int *entry)
{
int i, *pos = NULL, n = 0;
for (i = 0; i < wins[k].ncol; i++)
if (wins[k].col[i].list == list)
break;
if (i == wins[k].ncol)
return -1;
*entry = -1;
if (XmListGetSelectedPos(list, &pos, &n) && n > 0)
*entry = pos[0] - 1;
XtFree((char *)pos);
return *entry >= 0 && *entry < wins[k].col[i].n ? i : -1;
}
static void
ColumnChosen(Widget w, XtPointer client, XtPointer call)
{
FileMgrRec *rec = (FileMgrRec *)client;
int k = WinOf(rec, False), ci, entry;
char *path;
(void)call;
if (k < 0 || (ci = Chosen(k, w, &entry)) < 0)
return;
path = Join(wins[k].col[ci].dir, wins[k].col[ci].names[entry]);
/* a share of a host: mounted on ~/Network/HOST/NAME, then shown */
{
char host[256];
if (NetHost(wins[k].col[ci].dir, host, sizeof host) &&
wins[k].col[ci].proto != NULL &&
wins[k].col[ci].proto[entry] != NULL) {
char mp[1300], url[700], *p, *slash;
(void)snprintf(mp, sizeof mp, "%s/%s/%s",
NetRoot(), host, wins[k].col[ci].names[entry]);
(void)snprintf(url, sizeof url, "%s://%s/%s",
wins[k].col[ci].proto[entry], host,
wins[k].col[ci].names[entry]);
/* the folders down to it */
(void)snprintf(mp, sizeof mp, "%s/%s",
NetRoot(), host);
for (p = mp + 1; (slash = strchr(p, '/')) != NULL;
p = slash + 1) {
*slash = '\0';
(void)mkdir(mp, 0755);
*slash = '/';
}
(void)mkdir(mp, 0755);
(void)snprintf(mp, sizeof mp, "%s/%s/%s",
NetRoot(), host, wins[k].col[ci].names[entry]);
(void)mkdir(mp, 0755);
if (_McdeNetMount(rec->shell, url, mp, NULL) ==
MCDE_SYS_OK && IsDir(mp)) {
while (wins[k].ncol > ci + 1)
FreeColumn(&wins[k].col[--wins[k].ncol]);
Preview(k, mp);
AddColumn(k, mp);
Layout(k);
_McdeNavGoTo(rec, mp);
} else {
char msg[1200];
(void)snprintf(msg, sizeof msg, "Could not "
"connect to %s: %s", url, mcde_sys_error());
_DtMessage(rec->shell, (char *) "Network", msg,
NULL, NULL);
}
XtFree(path);
return;
}
}
/* what lay behind this column goes */
while (wins[k].ncol > ci + 1)
FreeColumn(&wins[k].col[--wins[k].ncol]);
Preview(k, path);
/* MCDE: the preview window, if it is up, follows the column */
_McdePeekPath(rec, path);
if (IsDir(path) || IsNetHostPath(path)) {
AddColumn(k, path);
Layout(k);
/* the window's folder follows (a host is no folder); the
* columns are found again by _McdeColumnsFollow */
if (IsDir(path))
_McdeNavGoTo(rec, path);
} else
Layout(k);
XtFree(path);
}
/* a double click: a folder is already open; a file runs the first action
* of its type, as a double click on its icon does */
static void
ColumnOpen(Widget w, XtPointer client, XtPointer call)
{
FileMgrRec *rec = (FileMgrRec *)client;
int k = WinOf(rec, False), ci, entry;
char *path, *type, *actions, *first, *end;
DtActionArg arg;
(void)call;
if (k < 0 || (ci = Chosen(k, w, &entry)) < 0)
return;
path = Join(wins[k].col[ci].dir, wins[k].col[ci].names[entry]);
if (IsDir(path) || (type = DtDtsFileToDataType(path)) == NULL) {
XtFree(path);
return;
}
actions = DtDtsDataTypeToAttributeValue(type, DtDTS_DA_ACTION_LIST,
NULL);
first = actions != NULL ? XtNewString(actions) : XtNewString("Open");
if ((end = strchr(first, ',')) != NULL)
*end = '\0';
memset(&arg, 0, sizeof arg);
arg.argClass = DtACTION_FILE;
arg.u.file.name = path;
(void)McdeSoundEvent(XtDisplay(w), "Launch");
(void)DtActionInvoke(w, first, &arg, 1, NULL, NULL,
wins[k].col[ci].dir, True, NULL, NULL);
XtFree(first);
if (actions != NULL)
DtDtsFreeAttributeValue(actions);
DtDtsFreeDataType(type);
XtFree(path);
}
/* the columns from the place DIR lies in down to DIR */
static void
Build(int k, const char *dir)
{
const char *home = getenv("HOME");
char *root, *p, *path;
size_t rl;
while (wins[k].ncol > 0)
FreeColumn(&wins[k].col[--wins[k].ncol]);
if (home != NULL && home[0] == '/' &&
strncmp(dir, home, strlen(home)) == 0 &&
(dir[strlen(home)] == '/' || dir[strlen(home)] == '\0'))
root = XtNewString(home);
else
root = XtNewString("/");
AddColumn(k, root);
rl = strlen(root);
path = XtNewString(dir);
/* every folder below the root, each one more column, its entry
* selected in the column before */
for (p = path + rl; p != NULL && *p != '\0'; ) {
char *slash, save, *name;
int i;
while (*p == '/')
p++;
if (*p == '\0')
break;
slash = strchr(p, '/');
save = slash != NULL ? *slash : '\0';
if (slash != NULL)
*slash = '\0';
name = strrchr(path, '/') + 1;
{
Column *c = &wins[k].col[wins[k].ncol - 1];
for (i = 0; i < c->n; i++)
if (strcmp(c->names[i], name) == 0) {
XmListSelectPos(c->list, i + 1, False);
XmListSetPos(c->list,
i > 5 ? i - 5 : 1);
break;
}
}
AddColumn(k, path);
if (slash != NULL)
*slash = save;
p = slash;
}
XtFree(path);
XtFree(root);
Layout(k);
Preview(k, dir);
}
/* ---- the view ----------------------------------------------------------- */
void
_McdeColumnsCreate(FileMgrRec *rec, Widget parent, Widget work)
{
Widget form, frame, preview;
int k = WinOf(rec, True);
Arg args[8];
int n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, work); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
XtSetArg(args[n], XmNleftWidget, work); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
form = XmCreateForm(parent, "mcdeColumns", args, n);
rec->mcde_columns = form;
if (k < 0)
return;
frame = XtVaCreateManagedWidget("mcdePreviewFrame", xmFrameWidgetClass,
form, XmNshadowType, XmSHADOW_IN, XmNwidth, PREVIEW_WIDTH,
XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
preview = XtVaCreateManagedWidget("mcdePreview", xmFormWidgetClass,
frame, NULL);
wins[k].preview = preview;
wins[k].picon = NULL;
wins[k].pname = XtVaCreateManagedWidget("mcdePreviewName",
xmLabelWidgetClass, preview, XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 90, XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
wins[k].pinfo = XtVaCreateManagedWidget("mcdePreviewInfo",
xmLabelWidgetClass, preview, XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wins[k].pname, XmNtopOffset, 12,
XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 8,
XmNalignment, XmALIGNMENT_BEGINNING, NULL);
SetLabel(wins[k].pname, "");
SetLabel(wins[k].pinfo, "");
/* the columns end at the preview */
XtVaSetValues(form, XmNwidth, 3 * COLUMN_WIDTH + PREVIEW_WIDTH, NULL);
}
/* the view on (the columns for DIR in place of WORK) or off */
void
_McdeColumnsShow(FileMgrRec *rec, Widget work, const char *dir, Boolean on)
{
int k = WinOf(rec, False);
if (k < 0 || rec->mcde_columns == NULL)
return;
/* the form around keeps its size while one part replaces the other:
* unmanaging the first made it ask the window for less (measured) */
XtVaSetValues(XtParent(work), XmNresizePolicy, XmRESIZE_NONE, NULL);
if (!on) {
XtManageChild(work);
XtUnmanageChild(rec->mcde_columns);
return;
}
/* the size of the work area: the form would ask the window for its
* own, smaller one, and the window shrank (measured) */
{
Dimension w = 0, h = 0;
XtVaGetValues(work, XmNwidth, &w, XmNheight, &h, NULL);
XtVaSetValues(rec->mcde_columns, XmNwidth, w, XmNheight, h,
XmNresizePolicy, XmRESIZE_NONE, NULL);
}
XtManageChild(rec->mcde_columns);
XtUnmanageChild(work);
Build(k, dir);
}
/* the window went to DIR (ShowNewDirectory): the columns follow, unless
* they lead there already */
void
_McdeColumnsFollow(FileMgrRec *rec, const char *dir)
{
int k = WinOf(rec, False);
if (k < 0 || rec->mcde_columns == NULL ||
!XtIsManaged(rec->mcde_columns))
return;
if (wins[k].ncol > 0 &&
strcmp(wins[k].col[wins[k].ncol - 1].dir, dir) == 0)
return;
Build(k, dir);
}