15dfecf96Smrg/*
25dfecf96Smrg * Copyright (c) 1999 by The XFree86 Project, Inc.
35dfecf96Smrg *
45dfecf96Smrg * Permission is hereby granted, free of charge, to any person obtaining a
55dfecf96Smrg * copy of this software and associated documentation files (the "Software"),
65dfecf96Smrg * to deal in the Software without restriction, including without limitation
75dfecf96Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
85dfecf96Smrg * and/or sell copies of the Software, and to permit persons to whom the
95dfecf96Smrg * Software is furnished to do so, subject to the following conditions:
105dfecf96Smrg *
115dfecf96Smrg * The above copyright notice and this permission notice shall be included in
125dfecf96Smrg * all copies or substantial portions of the Software.
135dfecf96Smrg *
145dfecf96Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155dfecf96Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
165dfecf96Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
175dfecf96Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
185dfecf96Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
195dfecf96Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
205dfecf96Smrg * SOFTWARE.
215dfecf96Smrg *
225dfecf96Smrg * Except as contained in this notice, the name of the XFree86 Project shall
235dfecf96Smrg * not be used in advertising or otherwise to promote the sale, use or other
245dfecf96Smrg * dealings in this Software without prior written authorization from the
255dfecf96Smrg * XFree86 Project.
265dfecf96Smrg *
275dfecf96Smrg * Author: Paulo César Pereira de Andrade
285dfecf96Smrg */
295dfecf96Smrg
305dfecf96Smrg/* $XFree86: xc/programs/xedit/options.c,v 1.13 2002/09/22 07:09:05 paulo Exp $ */
315dfecf96Smrg
325dfecf96Smrg#include <stdio.h>
335dfecf96Smrg#include <stdlib.h>
345dfecf96Smrg#include "xedit.h"
355dfecf96Smrg
365dfecf96Smrg#include <X11/Xaw/SmeBSB.h>
375dfecf96Smrg#include <X11/Xaw/SimpleMenu.h>
385dfecf96Smrg
395dfecf96Smrg/*
405dfecf96Smrg * Prototypes
415dfecf96Smrg */
425dfecf96Smrgstatic void SetColumns(Widget, XEvent*, String*, Cardinal*);
435dfecf96Smrgstatic void ChangeField(Widget, XEvent*, String*, Cardinal*);
445dfecf96Smrgstatic void EditCallback(Widget, XtPointer, XtPointer);
455dfecf96Smrgstatic void PopupColumnsCallback(Widget, XtPointer, XtPointer);
465dfecf96Smrgstatic void CreateColumnsShell(void);
475dfecf96Smrgstatic void ProcessColumnsCallback(Widget, XtPointer, XtPointer);
485dfecf96Smrg
495dfecf96Smrg/*
505dfecf96Smrg * Initialization
515dfecf96Smrg */
525dfecf96Smrgextern Widget texts[3];
535dfecf96Smrg
545dfecf96Smrgstatic Widget edit_popup, wrap_popup, justify_popup, scroll_popup,
555dfecf96Smrg	      columns_shell, left_text, right_text;
565dfecf96Smrg
575dfecf96Smrgstatic XFontStruct *fonts[3];
585dfecf96Smrgstatic Pixel foregrounds[3], backgrounds[3];
595dfecf96Smrg
605dfecf96Smrgstatic XtActionsRec actions[] = {
615dfecf96Smrg    {"set-columns", SetColumns},
625dfecf96Smrg    {"change-field", ChangeField},
635dfecf96Smrg};
645dfecf96Smrg
655dfecf96Smrg#define WRAP_NEVER	1
665dfecf96Smrg#define WRAP_LINE	2
675dfecf96Smrg#define WRAP_WORD	3
685dfecf96Smrg#define	AUTO_FILL	4
695dfecf96Smrg#define JUST_LEFT	5
705dfecf96Smrg#define JUST_RIGHT	6
715dfecf96Smrg#define JUST_CENTER	7
725dfecf96Smrg#define JUST_FULL	8
735dfecf96Smrg#define SCROLL_VERT	9
745dfecf96Smrg#define SCROLL_HORIZ	10
755dfecf96Smrg
765dfecf96Smrgstatic Widget autoFill, wrapNever, wrapLine, wrapWord,
775dfecf96Smrg	      justifyLeft, justifyRight, justifyCenter, justifyFull,
785dfecf96Smrg	      breakColumns, scrollVert, scrollHoriz;
795dfecf96Smrg
805dfecf96Smrgvoid
815dfecf96SmrgCreateEditPopup(void)
825dfecf96Smrg{
835dfecf96Smrg    Arg args[1];
845dfecf96Smrg
855dfecf96Smrg    edit_popup		= XtCreatePopupShell("editMenu", simpleMenuWidgetClass,
865dfecf96Smrg					     topwindow, NULL, 0);
875dfecf96Smrg    XtRealizeWidget(edit_popup);
885dfecf96Smrg
895dfecf96Smrg    wrap_popup		= XtCreatePopupShell("wrapMenu", simpleMenuWidgetClass,
905dfecf96Smrg					     edit_popup, NULL, 0);
915dfecf96Smrg    XtRealizeWidget(wrap_popup);
925dfecf96Smrg
935dfecf96Smrg    XtSetArg(args[0], XtNmenuName, "wrapMenu");
945dfecf96Smrg    XtCreateManagedWidget("wrapMenuItem", smeBSBObjectClass, edit_popup, args, 1);
955dfecf96Smrg
965dfecf96Smrg    wrapNever		= XtCreateManagedWidget("never", smeBSBObjectClass,
975dfecf96Smrg						wrap_popup, NULL, 0);
985dfecf96Smrg    XtAddCallback(wrapNever, XtNcallback, EditCallback, (XtPointer)WRAP_NEVER);
995dfecf96Smrg    wrapLine		= XtCreateManagedWidget("line", smeBSBObjectClass,
1005dfecf96Smrg						wrap_popup, NULL, 0);
1015dfecf96Smrg    XtAddCallback(wrapLine, XtNcallback, EditCallback, (XtPointer)WRAP_LINE);
1025dfecf96Smrg    wrapWord		= XtCreateManagedWidget("word", smeBSBObjectClass,
1035dfecf96Smrg						wrap_popup, NULL, 0);
1045dfecf96Smrg    XtAddCallback(wrapWord, XtNcallback, EditCallback, (XtPointer)WRAP_WORD);
1055dfecf96Smrg
1065dfecf96Smrg    autoFill		= XtCreateManagedWidget("autoFill", smeBSBObjectClass,
1075dfecf96Smrg						edit_popup, NULL, 0);
1085dfecf96Smrg    XtAddCallback(autoFill, XtNcallback, EditCallback, (XtPointer)AUTO_FILL);
1095dfecf96Smrg
1105dfecf96Smrg    justify_popup	= XtCreatePopupShell("justifyMenu", simpleMenuWidgetClass,
1115dfecf96Smrg					     edit_popup, NULL, 0);
1125dfecf96Smrg    XtRealizeWidget(justify_popup);
1135dfecf96Smrg
1145dfecf96Smrg    XtSetArg(args[0], XtNmenuName, "justifyMenu");
1155dfecf96Smrg    XtCreateManagedWidget("justifyMenuItem", smeBSBObjectClass, edit_popup, args, 1);
1165dfecf96Smrg
1175dfecf96Smrg    justifyLeft		= XtCreateManagedWidget("left", smeBSBObjectClass,
1185dfecf96Smrg						justify_popup, NULL, 0);
1195dfecf96Smrg    XtAddCallback(justifyLeft, XtNcallback, EditCallback, (XtPointer)JUST_LEFT);
1205dfecf96Smrg    justifyRight	= XtCreateManagedWidget("right", smeBSBObjectClass,
1215dfecf96Smrg						justify_popup, NULL, 0);
1225dfecf96Smrg    XtAddCallback(justifyRight, XtNcallback, EditCallback, (XtPointer)JUST_RIGHT);
1235dfecf96Smrg    justifyCenter	= XtCreateManagedWidget("center", smeBSBObjectClass,
1245dfecf96Smrg						justify_popup, NULL, 0);
1255dfecf96Smrg    XtAddCallback(justifyCenter, XtNcallback, EditCallback, (XtPointer)JUST_CENTER);
1265dfecf96Smrg    justifyFull		= XtCreateManagedWidget("full", smeBSBObjectClass,
1275dfecf96Smrg						justify_popup, NULL, 0);
1285dfecf96Smrg    XtAddCallback(justifyFull, XtNcallback, EditCallback, (XtPointer)JUST_FULL);
1295dfecf96Smrg
1305dfecf96Smrg    breakColumns	= XtCreateManagedWidget("breakColumns", smeBSBObjectClass,
1315dfecf96Smrg						edit_popup, NULL, 0);
1325dfecf96Smrg    XtAddCallback(breakColumns, XtNcallback, PopupColumnsCallback, NULL);
1335dfecf96Smrg
1345dfecf96Smrg    scroll_popup	= XtCreatePopupShell("scrollMenu", simpleMenuWidgetClass,
1355dfecf96Smrg					     edit_popup, NULL, 0);
1365dfecf96Smrg    XtRealizeWidget(scroll_popup);
1375dfecf96Smrg
1385dfecf96Smrg    XtSetArg(args[0], XtNmenuName, "scrollMenu");
1395dfecf96Smrg    XtCreateManagedWidget("scrollMenuItem", smeBSBObjectClass, edit_popup, args, 1);
1405dfecf96Smrg
1415dfecf96Smrg    scrollVert		= XtCreateManagedWidget("vertical", smeBSBObjectClass,
1425dfecf96Smrg						scroll_popup, NULL, 0);
1435dfecf96Smrg    XtAddCallback(scrollVert, XtNcallback, EditCallback, (XtPointer)SCROLL_VERT);
1445dfecf96Smrg    scrollHoriz		= XtCreateManagedWidget("horizontal", smeBSBObjectClass,
1455dfecf96Smrg						scroll_popup, NULL, 0);
1465dfecf96Smrg    XtAddCallback(scrollHoriz, XtNcallback, EditCallback, (XtPointer)SCROLL_HORIZ);
1475dfecf96Smrg
1485dfecf96Smrg    CreateEditModePopup(edit_popup);
1495dfecf96Smrg}
1505dfecf96Smrg
1515dfecf96Smrgvoid
1525dfecf96SmrgSetEditMenu(void)
1535dfecf96Smrg{
1545dfecf96Smrg    Arg args[7];
1555dfecf96Smrg    Cardinal num_args;
1565dfecf96Smrg    Boolean auto_fill;
1575dfecf96Smrg    XawTextWrapMode wrap_mode;
1585dfecf96Smrg    XawTextJustifyMode justify;
1595dfecf96Smrg    XawTextScrollMode vscroll, hscroll;
1605dfecf96Smrg    short left, right;
1615dfecf96Smrg
1625dfecf96Smrg    num_args = 0;
1635dfecf96Smrg    XtSetArg(args[num_args], XtNwrap, &wrap_mode);		++num_args;
1645dfecf96Smrg    XtSetArg(args[num_args], XtNautoFill, &auto_fill);		++num_args;
1655dfecf96Smrg    XtSetArg(args[num_args], XtNjustifyMode, &justify);		++num_args;
1665dfecf96Smrg    XtSetArg(args[num_args], XtNleftColumn, &left);		++num_args;
1675dfecf96Smrg    XtSetArg(args[num_args], XtNrightColumn, &right);		++num_args;
1685dfecf96Smrg    XtSetArg(args[num_args], XtNscrollVertical, &vscroll);	++num_args;
1695dfecf96Smrg    XtSetArg(args[num_args], XtNscrollHorizontal, &hscroll);	++num_args;
1705dfecf96Smrg    XtGetValues(textwindow, args, num_args);
1715dfecf96Smrg
1725dfecf96Smrg    if (flist.pixmap) {
1735dfecf96Smrg	XtSetArg(args[0], XtNleftBitmap, None);
1745dfecf96Smrg	XtSetArg(args[1], XtNleftBitmap, flist.pixmap);
1755dfecf96Smrg	if (!auto_fill)
1765dfecf96Smrg	    XtSetValues(autoFill, &args[0], 1);
1775dfecf96Smrg	else
1785dfecf96Smrg	    XtSetValues(autoFill, &args[1], 1);
1795dfecf96Smrg	switch (wrap_mode) {
1805dfecf96Smrg	    case XawtextWrapNever:
1815dfecf96Smrg		XtSetValues(wrapLine, &args[0], 1);
1825dfecf96Smrg		XtSetValues(wrapWord, &args[0], 1);
1835dfecf96Smrg		XtSetValues(wrapNever, &args[1], 1);
1845dfecf96Smrg		break;
1855dfecf96Smrg	    case XawtextWrapLine:
1865dfecf96Smrg		XtSetValues(wrapNever, &args[0], 1);
1875dfecf96Smrg		XtSetValues(wrapWord, &args[0], 1);
1885dfecf96Smrg		XtSetValues(wrapLine, &args[1], 1);
1895dfecf96Smrg		break;
1905dfecf96Smrg	    case XawtextWrapWord:
1915dfecf96Smrg		XtSetValues(wrapNever, &args[0], 1);
1925dfecf96Smrg		XtSetValues(wrapLine, &args[0], 1);
1935dfecf96Smrg		XtSetValues(wrapWord, &args[1], 1);
1945dfecf96Smrg		break;
1955dfecf96Smrg	}
1965dfecf96Smrg	switch (justify) {
1975dfecf96Smrg	    case XawjustifyLeft:
1985dfecf96Smrg		XtSetValues(justifyRight, &args[0], 1);
1995dfecf96Smrg		XtSetValues(justifyCenter, &args[0], 1);
2005dfecf96Smrg		XtSetValues(justifyFull, &args[0], 1);
2015dfecf96Smrg		XtSetValues(justifyLeft, &args[1], 1);
2025dfecf96Smrg		break;
2035dfecf96Smrg	    case XawjustifyRight:
2045dfecf96Smrg		XtSetValues(justifyLeft, &args[0], 1);
2055dfecf96Smrg		XtSetValues(justifyCenter, &args[0], 1);
2065dfecf96Smrg		XtSetValues(justifyFull, &args[0], 1);
2075dfecf96Smrg		XtSetValues(justifyRight, &args[1], 1);
2085dfecf96Smrg		break;
2095dfecf96Smrg	    case XawjustifyCenter:
2105dfecf96Smrg		XtSetValues(justifyLeft, &args[0], 1);
2115dfecf96Smrg		XtSetValues(justifyRight, &args[0], 1);
2125dfecf96Smrg		XtSetValues(justifyFull, &args[0], 1);
2135dfecf96Smrg		XtSetValues(justifyCenter, &args[1], 1);
2145dfecf96Smrg		break;
2155dfecf96Smrg	    case XawjustifyFull:
2165dfecf96Smrg		XtSetValues(justifyLeft, &args[0], 1);
2175dfecf96Smrg		XtSetValues(justifyRight, &args[0], 1);
2185dfecf96Smrg		XtSetValues(justifyCenter, &args[0], 1);
2195dfecf96Smrg		XtSetValues(justifyFull, &args[1], 1);
2205dfecf96Smrg		break;
2215dfecf96Smrg	}
2225dfecf96Smrg	if (!vscroll)
2235dfecf96Smrg	    XtSetValues(scrollVert, &args[0], 1);
2245dfecf96Smrg	else
2255dfecf96Smrg	    XtSetValues(scrollVert, &args[1], 1);
2265dfecf96Smrg	if (!hscroll)
2275dfecf96Smrg	    XtSetValues(scrollHoriz, &args[0], 1);
2285dfecf96Smrg	else
2295dfecf96Smrg	    XtSetValues(scrollHoriz, &args[1], 1);
2305dfecf96Smrg    }
2315dfecf96Smrg    if (!auto_fill) {
2325dfecf96Smrg	XtSetSensitive(wrapNever, True);
2335dfecf96Smrg	XtSetSensitive(wrapLine, True);
2345dfecf96Smrg	XtSetSensitive(wrapWord, True);
2355dfecf96Smrg
2365dfecf96Smrg	XtSetSensitive(justifyLeft, False);
2375dfecf96Smrg	XtSetSensitive(justifyRight, False);
2385dfecf96Smrg	XtSetSensitive(justifyCenter, False);
2395dfecf96Smrg	XtSetSensitive(justifyFull, False);
2405dfecf96Smrg	XtSetSensitive(breakColumns, False);
2415dfecf96Smrg    }
2425dfecf96Smrg    else {
2435dfecf96Smrg	XtSetSensitive(wrapNever, False);
2445dfecf96Smrg	XtSetSensitive(wrapLine, False);
2455dfecf96Smrg	XtSetSensitive(wrapWord, False);
2465dfecf96Smrg
2475dfecf96Smrg	XtSetSensitive(justifyLeft, left < right);
2485dfecf96Smrg	XtSetSensitive(justifyRight, left < right);
2495dfecf96Smrg	XtSetSensitive(justifyCenter, left < right);
2505dfecf96Smrg	XtSetSensitive(justifyFull, left < right);
2515dfecf96Smrg	XtSetSensitive(breakColumns, True);
2525dfecf96Smrg    }
2535dfecf96Smrg
2545dfecf96Smrg    SetEditModeMenu();
2555dfecf96Smrg}
2565dfecf96Smrg
2575dfecf96Smrg/*ARGSUSED*/
2585dfecf96Smrgstatic void
2595dfecf96SmrgEditCallback(Widget sme, XtPointer client_data, XtPointer call_data)
2605dfecf96Smrg{
2615dfecf96Smrg    Arg args[1];
2625dfecf96Smrg    Boolean auto_fill;
2635dfecf96Smrg    XawTextScrollMode scroll;
2645dfecf96Smrg    xedit_flist_item *item = FindTextSource(XawTextGetSource(textwindow), NULL);
2655dfecf96Smrg    Bool foreach = False;
2665dfecf96Smrg
2675dfecf96Smrg    switch ((long)client_data) {
2685dfecf96Smrg	case WRAP_NEVER:
2695dfecf96Smrg	    XtSetArg(args[0], XtNwrap, XawtextWrapNever);
2705dfecf96Smrg	    if (item) {
2715dfecf96Smrg		item->flags |= WRAP_BIT;
2725dfecf96Smrg		item->wrap = XawtextWrapNever;
2735dfecf96Smrg		foreach = True;
2745dfecf96Smrg	    }
2755dfecf96Smrg	    break;
2765dfecf96Smrg	case WRAP_LINE:
2775dfecf96Smrg	    XtSetArg(args[0], XtNwrap, XawtextWrapLine);
2785dfecf96Smrg	    if (item) {
2795dfecf96Smrg		item->flags |= WRAP_BIT;
2805dfecf96Smrg		item->wrap = XawtextWrapLine;
2815dfecf96Smrg		foreach = True;
2825dfecf96Smrg	    }
2835dfecf96Smrg	    break;
2845dfecf96Smrg	case WRAP_WORD:
2855dfecf96Smrg	    XtSetArg(args[0], XtNwrap, XawtextWrapWord);
2865dfecf96Smrg	    if (item) {
2875dfecf96Smrg		item->flags |= WRAP_BIT;
2885dfecf96Smrg		item->wrap = XawtextWrapWord;
2895dfecf96Smrg		foreach = True;
2905dfecf96Smrg	    }
2915dfecf96Smrg	    break;
2925dfecf96Smrg	case AUTO_FILL:
2935dfecf96Smrg	    XtSetArg(args[0], XtNautoFill, &auto_fill);
2945dfecf96Smrg	    XtGetValues(textwindow, args, 1);
2955dfecf96Smrg	    XtSetArg(args[0], XtNautoFill, !auto_fill);
2965dfecf96Smrg	    break;
2975dfecf96Smrg	case JUST_LEFT:
2985dfecf96Smrg	    XtSetArg(args[0], XtNjustifyMode, XawjustifyLeft);
2995dfecf96Smrg	    break;
3005dfecf96Smrg	case JUST_RIGHT:
3015dfecf96Smrg	    XtSetArg(args[0], XtNjustifyMode, XawjustifyRight);
3025dfecf96Smrg	    break;
3035dfecf96Smrg	case JUST_CENTER:
3045dfecf96Smrg	    XtSetArg(args[0], XtNjustifyMode, XawjustifyCenter);
3055dfecf96Smrg	    break;
3065dfecf96Smrg	case JUST_FULL:
3075dfecf96Smrg	    XtSetArg(args[0], XtNjustifyMode, XawjustifyFull);
3085dfecf96Smrg	    break;
3095dfecf96Smrg	case SCROLL_VERT:
3105dfecf96Smrg	    XtSetArg(args[0], XtNscrollVertical, &scroll);
3115dfecf96Smrg	    XtGetValues(textwindow, args, 1);
3125dfecf96Smrg	    XtSetArg(args[0], XtNscrollVertical, scroll == XawtextScrollNever ?
3135dfecf96Smrg		     XawtextScrollAlways : XawtextScrollNever);
3145dfecf96Smrg	    break;
3155dfecf96Smrg	case SCROLL_HORIZ:
3165dfecf96Smrg	    XtSetArg(args[0], XtNscrollHorizontal, &scroll);
3175dfecf96Smrg	    XtGetValues(textwindow, args, 1);
3185dfecf96Smrg	    XtSetArg(args[0], XtNscrollHorizontal, scroll == XawtextScrollNever ?
3195dfecf96Smrg		     XawtextScrollAlways : XawtextScrollNever);
3205dfecf96Smrg	    break;
3215dfecf96Smrg    }
3225dfecf96Smrg
3235dfecf96Smrg    if (foreach) {
3245dfecf96Smrg	int i;
3255dfecf96Smrg
3265dfecf96Smrg	for (i = 0; i < 3; i++)
3275dfecf96Smrg	    XtSetValues(texts[i], args, 1);
3285dfecf96Smrg    }
3295dfecf96Smrg    else
3305dfecf96Smrg	XtSetValues(textwindow, args, 1);
3315dfecf96Smrg}
3325dfecf96Smrg
3335dfecf96Smrgstatic void
3345dfecf96SmrgCreateColumnsShell(void)
3355dfecf96Smrg{
3365dfecf96Smrg    Atom delete_window;
3375dfecf96Smrg    Widget form, ok, cancel;
3385dfecf96Smrg
3395dfecf96Smrg    if (columns_shell)
3405dfecf96Smrg	return;
3415dfecf96Smrg
3425dfecf96Smrg    XtAppAddActions(XtWidgetToApplicationContext(topwindow),
3435dfecf96Smrg		    actions, XtNumber(actions));
3445dfecf96Smrg
3455dfecf96Smrg    columns_shell	= XtCreatePopupShell("columns", transientShellWidgetClass,
3465dfecf96Smrg					     topwindow, NULL, 0);
3475dfecf96Smrg    form		= XtCreateManagedWidget("form", formWidgetClass,
3485dfecf96Smrg						columns_shell, NULL, 0);
3495dfecf96Smrg    XtCreateManagedWidget("leftLabel", labelWidgetClass, form, NULL, 0);
3505dfecf96Smrg    left_text		= XtVaCreateManagedWidget("left", asciiTextWidgetClass,
3515dfecf96Smrg						  form, XtNeditType, XawtextEdit,
3525dfecf96Smrg						  NULL);
3535dfecf96Smrg    XtCreateManagedWidget("rightLabel", labelWidgetClass, form, NULL, 0);
3545dfecf96Smrg    right_text		= XtVaCreateManagedWidget("right", asciiTextWidgetClass,
3555dfecf96Smrg						  form, XtNeditType, XawtextEdit,
3565dfecf96Smrg						  NULL);
3575dfecf96Smrg    ok			= XtCreateManagedWidget("ok", commandWidgetClass,
3585dfecf96Smrg						form, NULL, 0);
3595dfecf96Smrg    XtAddCallback(ok, XtNcallback, ProcessColumnsCallback, (XtPointer)True);
3605dfecf96Smrg    cancel		= XtCreateManagedWidget("cancel", commandWidgetClass,
3615dfecf96Smrg						form, NULL, 0);
3625dfecf96Smrg    XtAddCallback(cancel, XtNcallback, ProcessColumnsCallback, (XtPointer)False);
3635dfecf96Smrg
3645dfecf96Smrg    XtRealizeWidget(columns_shell);
3655dfecf96Smrg    delete_window = XInternAtom(XtDisplay(columns_shell), "WM_DELETE_WINDOW", False);
3665dfecf96Smrg    XSetWMProtocols(XtDisplay(columns_shell), XtWindow(columns_shell), &delete_window, 1);
3675dfecf96Smrg
3685dfecf96Smrg    XtSetKeyboardFocus(columns_shell, left_text);
3695dfecf96Smrg}
3705dfecf96Smrg
3715dfecf96Smrg/*ARGSUSED*/
3725dfecf96Smrgstatic void
3735dfecf96SmrgPopupColumnsCallback(Widget w, XtPointer client_data, XtPointer call_data)
3745dfecf96Smrg{
3755dfecf96Smrg    Arg args[3];
3765dfecf96Smrg    char sleft[6], sright[6];
3775dfecf96Smrg    short left, right;
3785dfecf96Smrg    Dimension width, height, b_width;
3795dfecf96Smrg    Window r, c;
3805dfecf96Smrg    int x, y, wx, wy, max_x, max_y;
3815dfecf96Smrg    unsigned mask;
3825dfecf96Smrg
3835dfecf96Smrg    CreateColumnsShell();
3845dfecf96Smrg
3855dfecf96Smrg    XQueryPointer(XtDisplay(columns_shell), XtWindow(columns_shell),
3865dfecf96Smrg		  &r, &c, &x, &y, &wx, &wy, &mask);
3875dfecf96Smrg
3885dfecf96Smrg    XtSetArg(args[0], XtNwidth, &width);
3895dfecf96Smrg    XtSetArg(args[1], XtNheight, &height);
3905dfecf96Smrg    XtSetArg(args[2], XtNborderWidth, &b_width);
3915dfecf96Smrg    XtGetValues(columns_shell, args, 3);
3925dfecf96Smrg
3935dfecf96Smrg    width += b_width << 1;
3945dfecf96Smrg    height += b_width << 1;
3955dfecf96Smrg
3965dfecf96Smrg    x -= (Position)(width >> 1);
3975dfecf96Smrg    if (x < 0)
3985dfecf96Smrg	x = 0;
3995dfecf96Smrg    if (x > (max_x = (Position)(XtScreen(columns_shell)->width - width)))
4005dfecf96Smrg	x = max_x;
4015dfecf96Smrg
4025dfecf96Smrg    y -= (Position)(height >> 1);
4035dfecf96Smrg    if (y < 0)
4045dfecf96Smrg	y = 0;
4055dfecf96Smrg    if (y > (max_y = (Position)(XtScreen(columns_shell)->height - height)))
4065dfecf96Smrg	y = max_y;
4075dfecf96Smrg
4085dfecf96Smrg    XtSetArg(args[0], XtNx, x);
4095dfecf96Smrg    XtSetArg(args[1], XtNy, y);
4105dfecf96Smrg    XtSetValues(columns_shell, args, 2);
4115dfecf96Smrg
4125dfecf96Smrg    XtSetArg(args[0], XtNleftColumn, &left);
4135dfecf96Smrg    XtSetArg(args[1], XtNrightColumn, &right);
4145dfecf96Smrg    XtGetValues(textwindow, args, 2);
4155dfecf96Smrg    XmuSnprintf(sleft, sizeof(sleft), "%d", left);
4165dfecf96Smrg    XmuSnprintf(sright, sizeof(sright), "%d", right);
4175dfecf96Smrg    XtSetArg(args[0], XtNstring, sleft);
4185dfecf96Smrg    XtSetValues(left_text, args, 1);
4195dfecf96Smrg    XtSetArg(args[0], XtNstring, sright);
4205dfecf96Smrg    XtSetValues(right_text, args, 1);
4215dfecf96Smrg    XtPopup(columns_shell, XtGrabExclusive);
4225dfecf96Smrg}
4235dfecf96Smrg
4245dfecf96Smrg/*ARGSUSED*/
4255dfecf96Smrgstatic void
4265dfecf96SmrgProcessColumnsCallback(Widget w, XtPointer client_data, XtPointer call_data)
4275dfecf96Smrg{
4285dfecf96Smrg    if (client_data) {
4295dfecf96Smrg	Arg args[2];
4305dfecf96Smrg	char *left, *right;
4315dfecf96Smrg	short leftc, rightc;
4325dfecf96Smrg
4335dfecf96Smrg	left = GetString(left_text);
4345dfecf96Smrg	right = GetString(right_text);
4355dfecf96Smrg
4365dfecf96Smrg	leftc = atoi(left);
4375dfecf96Smrg	rightc = atoi(right);
4385dfecf96Smrg	XtSetArg(args[0], XtNleftColumn, leftc);
4395dfecf96Smrg	XtSetArg(args[1], XtNrightColumn, rightc);
4405dfecf96Smrg
4415dfecf96Smrg	XtSetValues(textwindow, args, 2);
4425dfecf96Smrg    }
4435dfecf96Smrg
4445dfecf96Smrg    XtPopdown(columns_shell);
4455dfecf96Smrg}
4465dfecf96Smrg
4475dfecf96Smrg/*ARGSUSED*/
4485dfecf96Smrgstatic void
4495dfecf96SmrgSetColumns(Widget w, XEvent *event, String *params, Cardinal *num_params)
4505dfecf96Smrg{
4515dfecf96Smrg    Bool ok = False;
4525dfecf96Smrg
4535dfecf96Smrg    if (*num_params &&
4545dfecf96Smrg	(params[0][0] == 'o' || params[0][0] == 'O'))
4555dfecf96Smrg	ok = True;
4565dfecf96Smrg
4575dfecf96Smrg    ProcessColumnsCallback(w, (XtPointer)(long)ok, NULL);
4585dfecf96Smrg}
4595dfecf96Smrg
4605dfecf96Smrg/*ARGSUSED*/
4615dfecf96Smrgstatic void
4625dfecf96SmrgChangeField(Widget w, XEvent *event, String *params, Cardinal *num_params)
4635dfecf96Smrg{
4645dfecf96Smrg    Widget focus = XtGetKeyboardFocusWidget(columns_shell);
4655dfecf96Smrg
4665dfecf96Smrg    XtSetKeyboardFocus(columns_shell,
4675dfecf96Smrg		       focus == left_text ? right_text : left_text);
4685dfecf96Smrg}
4695dfecf96Smrg
4705dfecf96Smrgvoid
4715dfecf96SmrgUpdateTextProperties(int force)
4725dfecf96Smrg{
4735dfecf96Smrg    Arg args[4];
4745dfecf96Smrg    Cardinal num_args;
4755dfecf96Smrg    xedit_flist_item *item;
4765dfecf96Smrg    XawTextPropertyList *prop;
4775dfecf96Smrg    Widget text, source, sink;
4785dfecf96Smrg    int i;
4795dfecf96Smrg
4805dfecf96Smrg    /* save default information */
4815dfecf96Smrg    if (fonts[0] == NULL) {
4825dfecf96Smrg	for (i = 0; i < 3; i++) {
4835dfecf96Smrg	    num_args = 0;
4845dfecf96Smrg	    XtSetArg(args[num_args], XtNfont, &fonts[i]);	      ++num_args;
4855dfecf96Smrg	    XtSetArg(args[num_args], XtNforeground, &foregrounds[i]); ++num_args;
4865dfecf96Smrg	    XtSetArg(args[num_args], XtNbackground, &backgrounds[i]); ++num_args;
4875dfecf96Smrg	    XtGetValues(XawTextGetSink(texts[i]), args, num_args);
4885dfecf96Smrg	}
4895dfecf96Smrg    }
4905dfecf96Smrg
4915dfecf96Smrg    for (i = 0; i < 3; i++) {
4925dfecf96Smrg	text = texts[i];
4935dfecf96Smrg	source = XawTextGetSource(text);
4945dfecf96Smrg	sink = XawTextGetSink(text);
4955dfecf96Smrg	item = FindTextSource(source, NULL);
4965dfecf96Smrg
4975dfecf96Smrg	XtSetArg(args[0], XawNtextProperties, &prop);
4985dfecf96Smrg	XtGetValues(sink, args, 1);
4995dfecf96Smrg
5005dfecf96Smrg	if (item == NULL || (!force && prop == item->properties))
5015dfecf96Smrg	    continue;
5025dfecf96Smrg
5035dfecf96Smrg	XtSetArg(args[0], XawNtextProperties, item->properties);
5045dfecf96Smrg	num_args = 1;
5055dfecf96Smrg	if (item->properties == NULL) {
5065dfecf96Smrg	    XtSetArg(args[num_args], XtNfont, fonts[i]);	     ++num_args;
5075dfecf96Smrg	    XtSetArg(args[num_args], XtNforeground, foregrounds[i]); ++num_args;
5085dfecf96Smrg	    XtSetArg(args[num_args], XtNbackground, backgrounds[i]); ++num_args;
5095dfecf96Smrg	}
5105dfecf96Smrg	XtSetValues(sink, args, num_args);
5115dfecf96Smrg
5125dfecf96Smrg	if (text == textwindow) {
5135dfecf96Smrg	    XtSetArg(args[0], XtNdisplayCaret, False);
5145dfecf96Smrg	    XtSetValues(text, args, 1);
5155dfecf96Smrg	}
5165dfecf96Smrg	_XawTextBuildLineTable((TextWidget)text,
5175dfecf96Smrg			       XawTextTopPosition(text), True);
5185dfecf96Smrg	XawTextDisplay(text);
5195dfecf96Smrg	if (text == textwindow) {
5205dfecf96Smrg	    XtSetArg(args[0], XtNdisplayCaret, True);
5215dfecf96Smrg	    XtSetValues(text, args, 1);
5225dfecf96Smrg	}
5235dfecf96Smrg    }
5245dfecf96Smrg}
525