184d9c625SLionel Sambuc /*-
284d9c625SLionel Sambuc * Copyright (c) 1996
384d9c625SLionel Sambuc * Rob Zimmermann. All rights reserved.
484d9c625SLionel Sambuc * Copyright (c) 1996
584d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
684d9c625SLionel Sambuc *
784d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
884d9c625SLionel Sambuc */
984d9c625SLionel Sambuc
1084d9c625SLionel Sambuc #include "config.h"
1184d9c625SLionel Sambuc
12*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
13*0a6a1f1dSLionel Sambuc #if 0
1484d9c625SLionel Sambuc #ifndef lint
1584d9c625SLionel Sambuc static const char sccsid[] = "Id: m_options.c,v 8.22 2003/11/05 17:09:59 skimo Exp (Berkeley) Date: 2003/11/05 17:09:59 ";
1684d9c625SLionel Sambuc #endif /* not lint */
17*0a6a1f1dSLionel Sambuc #else
18*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: m_options.c,v 1.2 2014/01/26 21:43:45 christos Exp $");
19*0a6a1f1dSLionel Sambuc #endif
2084d9c625SLionel Sambuc
2184d9c625SLionel Sambuc #include <sys/types.h>
2284d9c625SLionel Sambuc #include <sys/queue.h>
2384d9c625SLionel Sambuc
2484d9c625SLionel Sambuc #include <X11/X.h>
2584d9c625SLionel Sambuc #include <X11/Intrinsic.h>
2684d9c625SLionel Sambuc #include <Xm/DialogS.h>
2784d9c625SLionel Sambuc #include <Xm/Form.h>
2884d9c625SLionel Sambuc #include <Xm/Frame.h>
2984d9c625SLionel Sambuc #include <Xm/LabelG.h>
3084d9c625SLionel Sambuc #include <Xm/PushBG.h>
3184d9c625SLionel Sambuc #include <Xm/TextF.h>
3284d9c625SLionel Sambuc #include <Xm/ToggleBG.h>
3384d9c625SLionel Sambuc #include <Xm/RowColumn.h>
3484d9c625SLionel Sambuc
3584d9c625SLionel Sambuc #include <bitstring.h>
3684d9c625SLionel Sambuc #include <stdio.h>
3784d9c625SLionel Sambuc #include <stdlib.h>
3884d9c625SLionel Sambuc #include <string.h>
3984d9c625SLionel Sambuc
4084d9c625SLionel Sambuc #undef LOCK_SUCCESS
4184d9c625SLionel Sambuc #include "../common/common.h"
4284d9c625SLionel Sambuc #include "../ipc/ip.h"
4384d9c625SLionel Sambuc #include "m_motif.h"
4484d9c625SLionel Sambuc
4584d9c625SLionel Sambuc extern int vi_ofd;
4684d9c625SLionel Sambuc
4784d9c625SLionel Sambuc static void set_opt __P((Widget, XtPointer, XtPointer));
4884d9c625SLionel Sambuc
4984d9c625SLionel Sambuc
5084d9c625SLionel Sambuc /* constants */
5184d9c625SLionel Sambuc
5284d9c625SLionel Sambuc #if defined(SelfTest)
5384d9c625SLionel Sambuc
5484d9c625SLionel Sambuc /* in production, get these from the resource list */
5584d9c625SLionel Sambuc
5684d9c625SLionel Sambuc #define toggleColumns 6
5784d9c625SLionel Sambuc
5884d9c625SLionel Sambuc #endif
5984d9c625SLionel Sambuc
6084d9c625SLionel Sambuc
6184d9c625SLionel Sambuc /*
6284d9c625SLionel Sambuc * global data
6384d9c625SLionel Sambuc */
6484d9c625SLionel Sambuc
6584d9c625SLionel Sambuc static Widget preferences = NULL;
6684d9c625SLionel Sambuc
6784d9c625SLionel Sambuc static optData display[] = {
6884d9c625SLionel Sambuc { optToggle, "comment", },
6984d9c625SLionel Sambuc { optToggle, "flash", },
7084d9c625SLionel Sambuc { optToggle, "leftright", },
7184d9c625SLionel Sambuc { optToggle, "list", },
7284d9c625SLionel Sambuc { optToggle, "number", },
7384d9c625SLionel Sambuc { optToggle, "octal", },
7484d9c625SLionel Sambuc { optToggle, "ruler", },
7584d9c625SLionel Sambuc { optToggle, "showmode", },
7684d9c625SLionel Sambuc { optToggle, "slowopen", },
7784d9c625SLionel Sambuc { optToggle, "verbose", },
7884d9c625SLionel Sambuc { optToggle, "windowname", },
7984d9c625SLionel Sambuc { optTerminator, },
8084d9c625SLionel Sambuc }, display_int[] = {
8184d9c625SLionel Sambuc { optInteger, "report", },
8284d9c625SLionel Sambuc { optInteger, "scroll", },
8384d9c625SLionel Sambuc { optInteger, "shiftwidth", },
8484d9c625SLionel Sambuc { optInteger, "sidescroll", },
8584d9c625SLionel Sambuc { optInteger, "tabstop", },
8684d9c625SLionel Sambuc { optInteger, "window", },
8784d9c625SLionel Sambuc { optTerminator, },
8884d9c625SLionel Sambuc }, display_str[] = {
8984d9c625SLionel Sambuc { optString, "noprint", },
9084d9c625SLionel Sambuc { optString, "print", },
9184d9c625SLionel Sambuc { optTerminator, },
9284d9c625SLionel Sambuc }, files[] = {
9384d9c625SLionel Sambuc { optToggle, "autowrite", },
9484d9c625SLionel Sambuc { optToggle, "lock", },
9584d9c625SLionel Sambuc { optToggle, "readonly", },
9684d9c625SLionel Sambuc { optToggle, "writeany", },
9784d9c625SLionel Sambuc { optTerminator, },
9884d9c625SLionel Sambuc }, files_str[] = {
9984d9c625SLionel Sambuc { optString, "backup", },
10084d9c625SLionel Sambuc { optString, "path", },
10184d9c625SLionel Sambuc { optTerminator, },
10284d9c625SLionel Sambuc }, general[] = {
10384d9c625SLionel Sambuc { optToggle, "exrc", },
10484d9c625SLionel Sambuc { optToggle, "lisp", },
10584d9c625SLionel Sambuc { optToggle, "modeline", },
10684d9c625SLionel Sambuc { optToggle, "sourceany", },
10784d9c625SLionel Sambuc { optToggle, "tildeop", },
10884d9c625SLionel Sambuc { optTerminator, },
10984d9c625SLionel Sambuc }, general_int[] = {
11084d9c625SLionel Sambuc { optInteger, "taglength", },
11184d9c625SLionel Sambuc { optTerminator, },
11284d9c625SLionel Sambuc }, general_str[] = {
11384d9c625SLionel Sambuc { optString, "cdpath", },
11484d9c625SLionel Sambuc { optString, "directory", },
11584d9c625SLionel Sambuc { optString, "msgcat", },
11684d9c625SLionel Sambuc { optString, "recdir", },
11784d9c625SLionel Sambuc { optString, "shell", },
11884d9c625SLionel Sambuc { optString, "shellmeta", },
11984d9c625SLionel Sambuc { optString, "tags", },
12084d9c625SLionel Sambuc { optTerminator, },
12184d9c625SLionel Sambuc }, input[] = {
12284d9c625SLionel Sambuc { optToggle, "altwerase", },
12384d9c625SLionel Sambuc { optToggle, "autoindent", },
12484d9c625SLionel Sambuc { optToggle, "remap", },
12584d9c625SLionel Sambuc { optToggle, "showmatch", },
12684d9c625SLionel Sambuc { optToggle, "ttywerase", },
12784d9c625SLionel Sambuc { optTerminator, },
12884d9c625SLionel Sambuc }, input_int[] = {
12984d9c625SLionel Sambuc { optInteger, "escapetime", },
13084d9c625SLionel Sambuc { optInteger, "keytime", },
13184d9c625SLionel Sambuc { optInteger, "matchtime", },
13284d9c625SLionel Sambuc { optInteger, "timeout", },
13384d9c625SLionel Sambuc { optInteger, "wraplen", },
13484d9c625SLionel Sambuc { optInteger, "wrapmargin", },
13584d9c625SLionel Sambuc { optTerminator, },
13684d9c625SLionel Sambuc }, input_str[] = {
13784d9c625SLionel Sambuc { optString, "cedit", },
13884d9c625SLionel Sambuc { optString, "filec", },
13984d9c625SLionel Sambuc { optTerminator, },
14084d9c625SLionel Sambuc }, search[] = {
14184d9c625SLionel Sambuc { optToggle, "extended", },
14284d9c625SLionel Sambuc { optToggle, "iclower", },
14384d9c625SLionel Sambuc { optToggle, "ignorecase", },
14484d9c625SLionel Sambuc { optToggle, "magic", },
14584d9c625SLionel Sambuc { optToggle, "searchincr", },
14684d9c625SLionel Sambuc { optToggle, "wrapscan", },
14784d9c625SLionel Sambuc { optTerminator, },
14884d9c625SLionel Sambuc }, search_str[] = {
14984d9c625SLionel Sambuc { optString, "paragraphs", },
15084d9c625SLionel Sambuc { optString, "sections", },
15184d9c625SLionel Sambuc { optTerminator, },
15284d9c625SLionel Sambuc };
15384d9c625SLionel Sambuc
15484d9c625SLionel Sambuc /* ********* NOTE ***********
15584d9c625SLionel Sambuc * Sheet 0 will always be shown first. It does not matter to the Xt code
15684d9c625SLionel Sambuc * which sheet that is, so it ought to be the one users interact with most.
15784d9c625SLionel Sambuc * Best guess is that's general editor options, but it might be Search/re.
15884d9c625SLionel Sambuc * ********* NOTE ***********
15984d9c625SLionel Sambuc */
16084d9c625SLionel Sambuc static optSheet sheets[] = {
16184d9c625SLionel Sambuc { "Display",
16284d9c625SLionel Sambuc "These options control how text is displayed on the screen",
16384d9c625SLionel Sambuc NULL,
16484d9c625SLionel Sambuc display,
16584d9c625SLionel Sambuc display_int,
16684d9c625SLionel Sambuc display_str,
16784d9c625SLionel Sambuc },
16884d9c625SLionel Sambuc { "Files",
16984d9c625SLionel Sambuc "These options control how the editor handles files",
17084d9c625SLionel Sambuc NULL,
17184d9c625SLionel Sambuc files,
17284d9c625SLionel Sambuc NULL,
17384d9c625SLionel Sambuc files_str,
17484d9c625SLionel Sambuc },
17584d9c625SLionel Sambuc { "Input",
17684d9c625SLionel Sambuc "These options control text input behavior",
17784d9c625SLionel Sambuc NULL,
17884d9c625SLionel Sambuc input,
17984d9c625SLionel Sambuc input_int,
18084d9c625SLionel Sambuc input_str,
18184d9c625SLionel Sambuc },
18284d9c625SLionel Sambuc { "Search/RE",
18384d9c625SLionel Sambuc "These options control searching and Regular Expression behavior",
18484d9c625SLionel Sambuc NULL,
18584d9c625SLionel Sambuc search,
18684d9c625SLionel Sambuc NULL,
18784d9c625SLionel Sambuc search_str,
18884d9c625SLionel Sambuc },
18984d9c625SLionel Sambuc { "Editor",
19084d9c625SLionel Sambuc "These options control general editor configuration",
19184d9c625SLionel Sambuc NULL,
19284d9c625SLionel Sambuc general,
19384d9c625SLionel Sambuc general_int,
19484d9c625SLionel Sambuc general_str,
19584d9c625SLionel Sambuc },
19684d9c625SLionel Sambuc };
19784d9c625SLionel Sambuc
19884d9c625SLionel Sambuc
19984d9c625SLionel Sambuc /* callbacks */
20084d9c625SLionel Sambuc
20184d9c625SLionel Sambuc #if defined(SelfTest)
__vi_cancel_cb()20284d9c625SLionel Sambuc void __vi_cancel_cb()
20384d9c625SLionel Sambuc {
20484d9c625SLionel Sambuc puts( "cancelled" );
20584d9c625SLionel Sambuc }
20684d9c625SLionel Sambuc #endif
20784d9c625SLionel Sambuc
20884d9c625SLionel Sambuc
destroyed(void)20984d9c625SLionel Sambuc static void destroyed(void)
21084d9c625SLionel Sambuc {
21184d9c625SLionel Sambuc int i;
21284d9c625SLionel Sambuc
21384d9c625SLionel Sambuc puts( "destroyed" );
21484d9c625SLionel Sambuc
21584d9c625SLionel Sambuc /* some window managers destroy us upon popdown */
21684d9c625SLionel Sambuc for (i=0; i<XtNumber(sheets); i++) {
21784d9c625SLionel Sambuc sheets[i].holder = NULL;
21884d9c625SLionel Sambuc }
21984d9c625SLionel Sambuc preferences = NULL;
22084d9c625SLionel Sambuc }
22184d9c625SLionel Sambuc
22284d9c625SLionel Sambuc
window_unmapped(Widget w,XtPointer ptr,XEvent * ev,Boolean * cont)22384d9c625SLionel Sambuc static void window_unmapped(Widget w, XtPointer ptr, XEvent *ev, Boolean *cont)
22484d9c625SLionel Sambuc {
22584d9c625SLionel Sambuc if ( ev->type == UnmapNotify ) {
22684d9c625SLionel Sambuc #if defined(SelfTest)
22784d9c625SLionel Sambuc puts( "unmapped" );
22884d9c625SLionel Sambuc #endif
22984d9c625SLionel Sambuc XtPopdown( XtParent( preferences ) );
23084d9c625SLionel Sambuc }
23184d9c625SLionel Sambuc }
23284d9c625SLionel Sambuc
23384d9c625SLionel Sambuc /*
23484d9c625SLionel Sambuc * __vi_editopt --
23584d9c625SLionel Sambuc * Set an edit option based on a core message.
23684d9c625SLionel Sambuc *
23784d9c625SLionel Sambuc * PUBLIC: int __vi_editopt __P((IPVI *, const char *, u_int32_t, const char *, u_int32_t, u_int32_t));
23884d9c625SLionel Sambuc */
23984d9c625SLionel Sambuc int
__vi_editopt(IPVI * ipvi,const char * str1,u_int32_t len1,const char * str2,u_int32_t len2,u_int32_t val1)24084d9c625SLionel Sambuc __vi_editopt(IPVI *ipvi, const char *str1, u_int32_t len1, const char *str2, u_int32_t len2, u_int32_t val1)
24184d9c625SLionel Sambuc {
24284d9c625SLionel Sambuc optData *opt;
24384d9c625SLionel Sambuc
24484d9c625SLionel Sambuc #undef NSEARCH
24584d9c625SLionel Sambuc #define NSEARCH(list) { \
24684d9c625SLionel Sambuc for (opt = list; opt->kind != optTerminator; ++opt) \
24784d9c625SLionel Sambuc if (!strcmp(opt->name, str1)) \
24884d9c625SLionel Sambuc goto found; \
24984d9c625SLionel Sambuc }
25084d9c625SLionel Sambuc
25184d9c625SLionel Sambuc NSEARCH(display);
25284d9c625SLionel Sambuc NSEARCH(display_int);
25384d9c625SLionel Sambuc NSEARCH(display_str);
25484d9c625SLionel Sambuc NSEARCH(files);
25584d9c625SLionel Sambuc NSEARCH(files_str);
25684d9c625SLionel Sambuc NSEARCH(general);
25784d9c625SLionel Sambuc NSEARCH(general_int);
25884d9c625SLionel Sambuc NSEARCH(general_str);
25984d9c625SLionel Sambuc NSEARCH(input);
26084d9c625SLionel Sambuc NSEARCH(input_int);
26184d9c625SLionel Sambuc NSEARCH(input_str);
26284d9c625SLionel Sambuc NSEARCH(search);
26384d9c625SLionel Sambuc NSEARCH(search_str);
26484d9c625SLionel Sambuc
26584d9c625SLionel Sambuc return (0);
26684d9c625SLionel Sambuc
26784d9c625SLionel Sambuc found: switch (opt->kind) {
26884d9c625SLionel Sambuc case optToggle:
26984d9c625SLionel Sambuc opt->value = (void *)val1;
27084d9c625SLionel Sambuc break;
27184d9c625SLionel Sambuc case optInteger:
27284d9c625SLionel Sambuc if (opt->value != NULL)
27384d9c625SLionel Sambuc free(opt->value);
27484d9c625SLionel Sambuc if ((opt->value = malloc(8)) != NULL)
27584d9c625SLionel Sambuc (void)snprintf(opt->value,
27684d9c625SLionel Sambuc 8, "%lu", (u_long)val1);
27784d9c625SLionel Sambuc break;
27884d9c625SLionel Sambuc case optString:
27984d9c625SLionel Sambuc case optFile:
28084d9c625SLionel Sambuc if (opt->value != NULL)
28184d9c625SLionel Sambuc free(opt->value);
28284d9c625SLionel Sambuc if ((opt->value = malloc(len2)) != NULL)
28384d9c625SLionel Sambuc memcpy(opt->value, str2, len2);
28484d9c625SLionel Sambuc break;
28584d9c625SLionel Sambuc case optTerminator:
28684d9c625SLionel Sambuc abort();
28784d9c625SLionel Sambuc }
28884d9c625SLionel Sambuc return (0);
28984d9c625SLionel Sambuc }
29084d9c625SLionel Sambuc
29184d9c625SLionel Sambuc /*
29284d9c625SLionel Sambuc * set_opt --
29384d9c625SLionel Sambuc * Send a set-edit-option message to core.
29484d9c625SLionel Sambuc */
29584d9c625SLionel Sambuc static void
set_opt(Widget w,XtPointer closure,XtPointer call_data)29684d9c625SLionel Sambuc set_opt(Widget w, XtPointer closure, XtPointer call_data)
29784d9c625SLionel Sambuc {
29884d9c625SLionel Sambuc optData *opt;
29984d9c625SLionel Sambuc Boolean set;
30084d9c625SLionel Sambuc IP_BUF ipb;
30184d9c625SLionel Sambuc String str;
30284d9c625SLionel Sambuc extern IPVI ipvi_motif;
30384d9c625SLionel Sambuc
30484d9c625SLionel Sambuc opt = closure;
30584d9c625SLionel Sambuc
30684d9c625SLionel Sambuc ipb.code = VI_EDITOPT;
30784d9c625SLionel Sambuc ipb.str1 = opt->name;
30884d9c625SLionel Sambuc ipb.len1 = strlen(opt->name);
30984d9c625SLionel Sambuc
31084d9c625SLionel Sambuc switch (opt->kind) {
31184d9c625SLionel Sambuc case optToggle:
31284d9c625SLionel Sambuc XtVaGetValues(w, XmNset, &set, 0);
31384d9c625SLionel Sambuc ipb.val1 = set;
31484d9c625SLionel Sambuc ipb.len2 = 0;
31584d9c625SLionel Sambuc
31684d9c625SLionel Sambuc vi_wsend(&ipvi_motif, "ab1", &ipb);
31784d9c625SLionel Sambuc if (ipb.val1) {
31884d9c625SLionel Sambuc opt->value = (void *)!set;
31984d9c625SLionel Sambuc /*
32084d9c625SLionel Sambuc * RAZ:
32184d9c625SLionel Sambuc * How do we turn off the button? We don't want to
32284d9c625SLionel Sambuc * go recursive where we set it and it calls set_opt
32384d9c625SLionel Sambuc * to tell the core. Is that possible?
32484d9c625SLionel Sambuc */
32584d9c625SLionel Sambuc XtVaSetValues(w, XmNset, &set, 0);
32684d9c625SLionel Sambuc break;
32784d9c625SLionel Sambuc }
32884d9c625SLionel Sambuc
32984d9c625SLionel Sambuc if (strcmp(opt->name, "ruler") == 0)
33084d9c625SLionel Sambuc if (set)
33184d9c625SLionel Sambuc __vi_show_text_ruler_dialog(
33284d9c625SLionel Sambuc __vi_screen->area, "Ruler");
33384d9c625SLionel Sambuc else
33484d9c625SLionel Sambuc __vi_clear_text_ruler_dialog();
33584d9c625SLionel Sambuc break;
33684d9c625SLionel Sambuc case optInteger:
33784d9c625SLionel Sambuc str = XmTextFieldGetString(w);
33884d9c625SLionel Sambuc ipb.val1 = atoi(str);
33984d9c625SLionel Sambuc ipb.len2 = 0;
34084d9c625SLionel Sambuc vi_send(vi_ofd, "ab1", &ipb);
34184d9c625SLionel Sambuc break;
34284d9c625SLionel Sambuc case optFile:
34384d9c625SLionel Sambuc case optString:
34484d9c625SLionel Sambuc ipb.str2 = XmTextFieldGetString(w);
34584d9c625SLionel Sambuc ipb.len2 = strlen(ipb.str2);
34684d9c625SLionel Sambuc vi_send(vi_ofd, "ab1", &ipb);
34784d9c625SLionel Sambuc break;
34884d9c625SLionel Sambuc case optTerminator:
34984d9c625SLionel Sambuc abort();
35084d9c625SLionel Sambuc }
35184d9c625SLionel Sambuc }
35284d9c625SLionel Sambuc
35384d9c625SLionel Sambuc
35484d9c625SLionel Sambuc /* add toggles to the property sheet */
35584d9c625SLionel Sambuc
35684d9c625SLionel Sambuc #if defined(__STDC__)
add_toggle(Widget parent,optData * option)35784d9c625SLionel Sambuc static void add_toggle( Widget parent, optData *option )
35884d9c625SLionel Sambuc #else
35984d9c625SLionel Sambuc static void add_toggle( parent, option )
36084d9c625SLionel Sambuc Widget parent;
36184d9c625SLionel Sambuc optData *option;
36284d9c625SLionel Sambuc #endif
36384d9c625SLionel Sambuc {
36484d9c625SLionel Sambuc Widget w;
36584d9c625SLionel Sambuc
36684d9c625SLionel Sambuc w = XtVaCreateManagedWidget( option->name,
36784d9c625SLionel Sambuc xmToggleButtonGadgetClass,
36884d9c625SLionel Sambuc parent,
36984d9c625SLionel Sambuc XmNset, (Boolean) option->value,
37084d9c625SLionel Sambuc 0
37184d9c625SLionel Sambuc );
37284d9c625SLionel Sambuc XtAddCallback( w, XmNvalueChangedCallback, set_opt, option );
37384d9c625SLionel Sambuc }
37484d9c625SLionel Sambuc
37584d9c625SLionel Sambuc
create_toggles(Widget outer,optData * toggles)37684d9c625SLionel Sambuc static Widget create_toggles(Widget outer, optData *toggles)
37784d9c625SLionel Sambuc {
37884d9c625SLionel Sambuc Widget inner;
37984d9c625SLionel Sambuc int i;
38084d9c625SLionel Sambuc
38184d9c625SLionel Sambuc inner = XtVaCreateWidget( "toggleOptions",
38284d9c625SLionel Sambuc xmRowColumnWidgetClass,
38384d9c625SLionel Sambuc outer,
38484d9c625SLionel Sambuc XmNpacking, XmPACK_COLUMN,
38584d9c625SLionel Sambuc XmNnumColumns, 4,
38684d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_FORM,
38784d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_FORM,
38884d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_FORM,
38984d9c625SLionel Sambuc 0
39084d9c625SLionel Sambuc );
39184d9c625SLionel Sambuc
39284d9c625SLionel Sambuc /* first the booleans */
39384d9c625SLionel Sambuc for (i=0; toggles[i].kind != optTerminator; i++) {
39484d9c625SLionel Sambuc add_toggle( inner, &toggles[i] );
39584d9c625SLionel Sambuc }
39684d9c625SLionel Sambuc XtManageChild( inner );
39784d9c625SLionel Sambuc
39884d9c625SLionel Sambuc return inner;
39984d9c625SLionel Sambuc }
40084d9c625SLionel Sambuc
40184d9c625SLionel Sambuc
40284d9c625SLionel Sambuc /* draw text fields and their labels */
40384d9c625SLionel Sambuc
40484d9c625SLionel Sambuc #if defined(__STDC__)
add_string_options(Widget parent,optData * options)40584d9c625SLionel Sambuc static void add_string_options( Widget parent,
40684d9c625SLionel Sambuc optData *options
40784d9c625SLionel Sambuc )
40884d9c625SLionel Sambuc #else
40984d9c625SLionel Sambuc static void add_string_options( parent, options )
41084d9c625SLionel Sambuc Widget parent;
41184d9c625SLionel Sambuc optData *options;
41284d9c625SLionel Sambuc #endif
41384d9c625SLionel Sambuc {
41484d9c625SLionel Sambuc int i;
41584d9c625SLionel Sambuc Widget f, w;
41684d9c625SLionel Sambuc
41784d9c625SLionel Sambuc for ( i=0; options[i].kind != optTerminator; i++ ) {
41884d9c625SLionel Sambuc
41984d9c625SLionel Sambuc f = XtVaCreateWidget( "form",
42084d9c625SLionel Sambuc xmFormWidgetClass,
42184d9c625SLionel Sambuc parent,
42284d9c625SLionel Sambuc 0
42384d9c625SLionel Sambuc );
42484d9c625SLionel Sambuc
42584d9c625SLionel Sambuc XtVaCreateManagedWidget( options[i].name,
42684d9c625SLionel Sambuc xmLabelGadgetClass,
42784d9c625SLionel Sambuc f,
42884d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_FORM,
42984d9c625SLionel Sambuc XmNbottomAttachment, XmATTACH_FORM,
43084d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_FORM,
43184d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_POSITION,
43284d9c625SLionel Sambuc XmNrightPosition, 20,
43384d9c625SLionel Sambuc XmNalignment, XmALIGNMENT_END,
43484d9c625SLionel Sambuc 0
43584d9c625SLionel Sambuc );
43684d9c625SLionel Sambuc
43784d9c625SLionel Sambuc w = XtVaCreateManagedWidget( "text",
43884d9c625SLionel Sambuc xmTextFieldWidgetClass,
43984d9c625SLionel Sambuc f,
44084d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_FORM,
44184d9c625SLionel Sambuc XmNbottomAttachment, XmATTACH_FORM,
44284d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_FORM,
44384d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_POSITION,
44484d9c625SLionel Sambuc XmNleftPosition, 20,
44584d9c625SLionel Sambuc 0
44684d9c625SLionel Sambuc );
44784d9c625SLionel Sambuc
44884d9c625SLionel Sambuc XmTextFieldSetString( w, (char *) options[i].value );
44984d9c625SLionel Sambuc XtAddCallback( w, XmNactivateCallback, set_opt, &options[i] );
45084d9c625SLionel Sambuc XtManageChild( f );
45184d9c625SLionel Sambuc }
45284d9c625SLionel Sambuc }
45384d9c625SLionel Sambuc
45484d9c625SLionel Sambuc
45584d9c625SLionel Sambuc /* draw and display a single page of properties */
45684d9c625SLionel Sambuc
45784d9c625SLionel Sambuc #if defined(__STDC__)
create_sheet(Widget parent,optSheet * sheet)45884d9c625SLionel Sambuc static Widget create_sheet( Widget parent, optSheet *sheet )
45984d9c625SLionel Sambuc #else
46084d9c625SLionel Sambuc static Widget create_sheet( parent, sheet )
46184d9c625SLionel Sambuc Widget parent;
46284d9c625SLionel Sambuc optSheet *sheet;
46384d9c625SLionel Sambuc #endif
46484d9c625SLionel Sambuc {
46584d9c625SLionel Sambuc Widget outer, inner, frame;
46684d9c625SLionel Sambuc Dimension height;
46784d9c625SLionel Sambuc XmString str;
46884d9c625SLionel Sambuc
46984d9c625SLionel Sambuc outer = XtVaCreateWidget( sheet->name,
47084d9c625SLionel Sambuc xmFormWidgetClass,
47184d9c625SLionel Sambuc parent,
47284d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_FORM,
47384d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_FORM,
47484d9c625SLionel Sambuc XmNbottomAttachment, XmATTACH_FORM,
47584d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_FORM,
47684d9c625SLionel Sambuc XmNshadowType, XmSHADOW_ETCHED_IN,
47784d9c625SLionel Sambuc XmNshadowThickness, 2,
47884d9c625SLionel Sambuc XmNverticalSpacing, 4,
47984d9c625SLionel Sambuc XmNhorizontalSpacing, 4,
48084d9c625SLionel Sambuc 0
48184d9c625SLionel Sambuc );
48284d9c625SLionel Sambuc
48384d9c625SLionel Sambuc /* add descriptive text */
48484d9c625SLionel Sambuc frame = XtVaCreateManagedWidget( "frame",
48584d9c625SLionel Sambuc xmFrameWidgetClass,
48684d9c625SLionel Sambuc outer,
48784d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_FORM,
48884d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_FORM,
48984d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_FORM,
49084d9c625SLionel Sambuc 0
49184d9c625SLionel Sambuc );
49284d9c625SLionel Sambuc str = XmStringCreateLtoR( sheet->description, XmSTRING_DEFAULT_CHARSET );
49384d9c625SLionel Sambuc XtVaCreateManagedWidget( "description",
49484d9c625SLionel Sambuc xmLabelGadgetClass,
49584d9c625SLionel Sambuc frame,
49684d9c625SLionel Sambuc XmNlabelString, str,
49784d9c625SLionel Sambuc 0
49884d9c625SLionel Sambuc );
49984d9c625SLionel Sambuc XmStringFree( str );
50084d9c625SLionel Sambuc
50184d9c625SLionel Sambuc /* Add the toggles. */
50284d9c625SLionel Sambuc inner = create_toggles( outer, sheet->toggles );
50384d9c625SLionel Sambuc XtVaSetValues( inner,
50484d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_WIDGET,
50584d9c625SLionel Sambuc XmNtopWidget, frame,
50684d9c625SLionel Sambuc 0
50784d9c625SLionel Sambuc );
50884d9c625SLionel Sambuc
50984d9c625SLionel Sambuc /* the string options go here */
51084d9c625SLionel Sambuc inner = XtVaCreateWidget( "otherOptions",
51184d9c625SLionel Sambuc xmRowColumnWidgetClass,
51284d9c625SLionel Sambuc outer,
51384d9c625SLionel Sambuc XmNpacking, XmPACK_COLUMN,
51484d9c625SLionel Sambuc XmNtopAttachment, XmATTACH_WIDGET,
51584d9c625SLionel Sambuc XmNtopWidget, inner,
51684d9c625SLionel Sambuc XmNrightAttachment, XmATTACH_FORM,
51784d9c625SLionel Sambuc XmNbottomAttachment, XmATTACH_FORM,
51884d9c625SLionel Sambuc XmNleftAttachment, XmATTACH_FORM,
51984d9c625SLionel Sambuc 0
52084d9c625SLionel Sambuc );
52184d9c625SLionel Sambuc
52284d9c625SLionel Sambuc /* Optionally, the ints. */
52384d9c625SLionel Sambuc if ( sheet->ints != NULL )
52484d9c625SLionel Sambuc add_string_options( inner, sheet->ints );
52584d9c625SLionel Sambuc
52684d9c625SLionel Sambuc /* Optionally, the rest. */
52784d9c625SLionel Sambuc if ( sheet->others != NULL )
52884d9c625SLionel Sambuc add_string_options( inner, sheet->others );
52984d9c625SLionel Sambuc
53084d9c625SLionel Sambuc XtManageChild( inner );
53184d9c625SLionel Sambuc
53284d9c625SLionel Sambuc /* finally, force resize of the parent */
53384d9c625SLionel Sambuc XtVaGetValues( outer, XmNheight, &height, 0 );
53484d9c625SLionel Sambuc XtVaSetValues( parent, XmNheight, height, 0 );
53584d9c625SLionel Sambuc
53684d9c625SLionel Sambuc return outer;
53784d9c625SLionel Sambuc }
53884d9c625SLionel Sambuc
53984d9c625SLionel Sambuc
54084d9c625SLionel Sambuc /* change preferences to another sheet */
54184d9c625SLionel Sambuc
change_sheet(Widget parent,int current)54284d9c625SLionel Sambuc static void change_sheet(Widget parent, int current)
54384d9c625SLionel Sambuc {
54484d9c625SLionel Sambuc static int current_sheet = -1;
54584d9c625SLionel Sambuc
54684d9c625SLionel Sambuc /* create a new one? */
54784d9c625SLionel Sambuc if ( sheets[current].holder == NULL )
54884d9c625SLionel Sambuc sheets[current].holder = create_sheet( parent, &sheets[current] );
54984d9c625SLionel Sambuc
55084d9c625SLionel Sambuc /* done with the old one? */
55184d9c625SLionel Sambuc if ( current_sheet != -1 && sheets[current_sheet].holder != NULL )
55284d9c625SLionel Sambuc XtUnmanageChild( sheets[current_sheet].holder );
55384d9c625SLionel Sambuc
55484d9c625SLionel Sambuc current_sheet = current;
55584d9c625SLionel Sambuc XtManageChild( sheets[current].holder );
55684d9c625SLionel Sambuc XtManageChild( parent );
55784d9c625SLionel Sambuc }
55884d9c625SLionel Sambuc
55984d9c625SLionel Sambuc
56084d9c625SLionel Sambuc /* Draw and display a dialog the describes vi options */
56184d9c625SLionel Sambuc
56284d9c625SLionel Sambuc #if defined(__STDC__)
create_options_dialog(Widget parent,String title)56384d9c625SLionel Sambuc static Widget create_options_dialog( Widget parent, String title )
56484d9c625SLionel Sambuc #else
56584d9c625SLionel Sambuc static Widget create_options_dialog( parent, title )
56684d9c625SLionel Sambuc Widget parent;
56784d9c625SLionel Sambuc String title;
56884d9c625SLionel Sambuc #endif
56984d9c625SLionel Sambuc {
57084d9c625SLionel Sambuc Widget box, form, inner;
57184d9c625SLionel Sambuc int i;
57284d9c625SLionel Sambuc char buffer[1024];
57384d9c625SLionel Sambuc
57484d9c625SLionel Sambuc /* already built? */
57584d9c625SLionel Sambuc if ( preferences != NULL ) return preferences;
57684d9c625SLionel Sambuc
57784d9c625SLionel Sambuc box = XtVaCreatePopupShell( title,
57884d9c625SLionel Sambuc xmDialogShellWidgetClass,
57984d9c625SLionel Sambuc parent,
58084d9c625SLionel Sambuc XmNtitle, title,
58184d9c625SLionel Sambuc XmNallowShellResize, False,
58284d9c625SLionel Sambuc 0
58384d9c625SLionel Sambuc );
58484d9c625SLionel Sambuc XtAddCallback( box, XmNpopdownCallback, __vi_cancel_cb, 0 );
58584d9c625SLionel Sambuc XtAddCallback( box, XmNdestroyCallback, destroyed, 0 );
58684d9c625SLionel Sambuc XtAddEventHandler( box,
58784d9c625SLionel Sambuc SubstructureNotifyMask,
58884d9c625SLionel Sambuc False,
58984d9c625SLionel Sambuc window_unmapped,
59084d9c625SLionel Sambuc NULL
59184d9c625SLionel Sambuc );
59284d9c625SLionel Sambuc
59384d9c625SLionel Sambuc form = XtVaCreateWidget( "options",
59484d9c625SLionel Sambuc xmFormWidgetClass,
59584d9c625SLionel Sambuc box,
59684d9c625SLionel Sambuc 0
59784d9c625SLionel Sambuc );
59884d9c625SLionel Sambuc
59984d9c625SLionel Sambuc /* copy the pointers to the sheet names */
60084d9c625SLionel Sambuc *buffer = '\0';
60184d9c625SLionel Sambuc for (i=0; i<XtNumber(sheets); i++) {
60284d9c625SLionel Sambuc strcat( buffer, "|" );
60384d9c625SLionel Sambuc strcat( buffer, sheets[i].name );
60484d9c625SLionel Sambuc }
60584d9c625SLionel Sambuc
60684d9c625SLionel Sambuc inner = __vi_CreateTabbedFolder( "tabs",
60784d9c625SLionel Sambuc form,
60884d9c625SLionel Sambuc buffer,
60984d9c625SLionel Sambuc XtNumber(sheets),
61084d9c625SLionel Sambuc change_sheet
61184d9c625SLionel Sambuc );
61284d9c625SLionel Sambuc
61384d9c625SLionel Sambuc /* build the property sheets early */
61484d9c625SLionel Sambuc for ( i=0; i<XtNumber(sheets); i++ )
61584d9c625SLionel Sambuc change_sheet( inner, i );
61684d9c625SLionel Sambuc
61784d9c625SLionel Sambuc /* manage all of the sheets right now */
61884d9c625SLionel Sambuc for ( i=0; i<XtNumber(sheets); i++ )
61984d9c625SLionel Sambuc XtManageChild( sheets[i].holder );
62084d9c625SLionel Sambuc XtManageChild( form );
62184d9c625SLionel Sambuc
62284d9c625SLionel Sambuc /* remove all but the first one */
62384d9c625SLionel Sambuc for ( i=0; i<XtNumber(sheets); i++ )
62484d9c625SLionel Sambuc XtUnmanageChild( sheets[i].holder );
62584d9c625SLionel Sambuc change_sheet( inner, 0 ); /* show first sheet first */
62684d9c625SLionel Sambuc
62784d9c625SLionel Sambuc /* keep this global, we might destroy it later */
62884d9c625SLionel Sambuc preferences = form;
62984d9c625SLionel Sambuc
63084d9c625SLionel Sambuc /* done */
63184d9c625SLionel Sambuc return form;
63284d9c625SLionel Sambuc }
63384d9c625SLionel Sambuc
63484d9c625SLionel Sambuc
63584d9c625SLionel Sambuc
63684d9c625SLionel Sambuc /*
63784d9c625SLionel Sambuc * module entry point
63884d9c625SLionel Sambuc *
63984d9c625SLionel Sambuc * __vi_show_options_dialog --
64084d9c625SLionel Sambuc *
64184d9c625SLionel Sambuc *
64284d9c625SLionel Sambuc * PUBLIC: void __vi_show_options_dialog __P((Widget, String));
64384d9c625SLionel Sambuc */
64484d9c625SLionel Sambuc void
__vi_show_options_dialog(Widget parent,String title)64584d9c625SLionel Sambuc __vi_show_options_dialog(Widget parent, String title)
64684d9c625SLionel Sambuc {
64784d9c625SLionel Sambuc Widget db = create_options_dialog( parent, title );
64884d9c625SLionel Sambuc #if defined(SelfTest)
64984d9c625SLionel Sambuc Widget shell = XtParent( db );
65084d9c625SLionel Sambuc #endif
65184d9c625SLionel Sambuc
65284d9c625SLionel Sambuc XtManageChild( db );
65384d9c625SLionel Sambuc
65484d9c625SLionel Sambuc #if defined(SelfTest)
65584d9c625SLionel Sambuc /* wait until it goes away */
65684d9c625SLionel Sambuc XtPopup( shell, XtGrabNone );
65784d9c625SLionel Sambuc #else
65884d9c625SLionel Sambuc /* wait until it goes away */
65984d9c625SLionel Sambuc __vi_modal_dialog( db );
66084d9c625SLionel Sambuc #endif
66184d9c625SLionel Sambuc }
66284d9c625SLionel Sambuc
66384d9c625SLionel Sambuc
66484d9c625SLionel Sambuc
66584d9c625SLionel Sambuc /* module entry point
66684d9c625SLionel Sambuc * Utilities for the search dialog
66784d9c625SLionel Sambuc *
66884d9c625SLionel Sambuc * __vi_toggle --
66984d9c625SLionel Sambuc * Returns the current value of a toggle.
67084d9c625SLionel Sambuc *
67184d9c625SLionel Sambuc * PUBLIC: int __vi_toggle __P((char *));
67284d9c625SLionel Sambuc */
67384d9c625SLionel Sambuc int
__vi_toggle(char * name)67484d9c625SLionel Sambuc __vi_toggle(char *name)
67584d9c625SLionel Sambuc {
67684d9c625SLionel Sambuc optData *opt;
67784d9c625SLionel Sambuc
67884d9c625SLionel Sambuc #undef NSEARCH
67984d9c625SLionel Sambuc #define NSEARCH(list) { \
68084d9c625SLionel Sambuc for (opt = list; opt->kind != optTerminator; ++opt) \
68184d9c625SLionel Sambuc if (!strcmp(opt->name, name)) \
68284d9c625SLionel Sambuc return ((int)opt->value); \
68384d9c625SLionel Sambuc }
68484d9c625SLionel Sambuc NSEARCH(display);
68584d9c625SLionel Sambuc NSEARCH(files);
68684d9c625SLionel Sambuc NSEARCH(general);
68784d9c625SLionel Sambuc NSEARCH(input);
68884d9c625SLionel Sambuc NSEARCH(search);
68984d9c625SLionel Sambuc
69084d9c625SLionel Sambuc return (0);
69184d9c625SLionel Sambuc }
69284d9c625SLionel Sambuc
69384d9c625SLionel Sambuc /*
69484d9c625SLionel Sambuc * __vi_create_search_toggles --
69584d9c625SLionel Sambuc * Creates the search toggles. This is so the options and search widgets
69684d9c625SLionel Sambuc * share their appearance.
69784d9c625SLionel Sambuc *
69884d9c625SLionel Sambuc * PUBLIC: Widget __vi_create_search_toggles __P((Widget, optData[]));
69984d9c625SLionel Sambuc */
70084d9c625SLionel Sambuc Widget
__vi_create_search_toggles(Widget parent,optData * list)70184d9c625SLionel Sambuc __vi_create_search_toggles(Widget parent, optData *list)
70284d9c625SLionel Sambuc {
70384d9c625SLionel Sambuc optData *opt;
70484d9c625SLionel Sambuc
70584d9c625SLionel Sambuc /*
70684d9c625SLionel Sambuc * Copy current options information into the search table.
70784d9c625SLionel Sambuc *
70884d9c625SLionel Sambuc * XXX
70984d9c625SLionel Sambuc * This is an O(M*N) loop, but I don't think it matters.
71084d9c625SLionel Sambuc */
71184d9c625SLionel Sambuc for (opt = list; opt->kind != optTerminator; ++opt)
71284d9c625SLionel Sambuc opt->value = (void *)__vi_toggle(opt->name);
71384d9c625SLionel Sambuc
71484d9c625SLionel Sambuc return (create_toggles(parent, list));
71584d9c625SLionel Sambuc }
71684d9c625SLionel Sambuc
71784d9c625SLionel Sambuc
71884d9c625SLionel Sambuc #if defined(SelfTest)
71984d9c625SLionel Sambuc
72084d9c625SLionel Sambuc #if defined(__STDC__)
show_options(Widget w,XtPointer data,XtPointer cbs)72184d9c625SLionel Sambuc static void show_options( Widget w, XtPointer data, XtPointer cbs )
72284d9c625SLionel Sambuc #else
72384d9c625SLionel Sambuc static void show_options( w, data, cbs )
72484d9c625SLionel Sambuc Widget w;
72584d9c625SLionel Sambuc XtPointer data;
72684d9c625SLionel Sambuc XtPointer cbs;
72784d9c625SLionel Sambuc #endif
72884d9c625SLionel Sambuc {
72984d9c625SLionel Sambuc __vi_show_options_dialog( data, "Preferences" );
73084d9c625SLionel Sambuc }
73184d9c625SLionel Sambuc
main(int argc,char * argv[])73284d9c625SLionel Sambuc main( int argc, char *argv[] )
73384d9c625SLionel Sambuc {
73484d9c625SLionel Sambuc XtAppContext ctx;
73584d9c625SLionel Sambuc Widget top_level, rc, button;
73684d9c625SLionel Sambuc extern exit();
73784d9c625SLionel Sambuc
73884d9c625SLionel Sambuc /* create a top-level shell for the window manager */
73984d9c625SLionel Sambuc top_level = XtVaAppInitialize( &ctx,
74084d9c625SLionel Sambuc argv[0],
74184d9c625SLionel Sambuc NULL, 0, /* options */
74284d9c625SLionel Sambuc (ArgcType) &argc,
74384d9c625SLionel Sambuc argv, /* might get modified */
74484d9c625SLionel Sambuc NULL,
74584d9c625SLionel Sambuc NULL
74684d9c625SLionel Sambuc );
74784d9c625SLionel Sambuc
74884d9c625SLionel Sambuc rc = XtVaCreateManagedWidget( "rc",
74984d9c625SLionel Sambuc xmRowColumnWidgetClass,
75084d9c625SLionel Sambuc top_level,
75184d9c625SLionel Sambuc 0
75284d9c625SLionel Sambuc );
75384d9c625SLionel Sambuc
75484d9c625SLionel Sambuc button = XtVaCreateManagedWidget( "Pop up options dialog",
75584d9c625SLionel Sambuc xmPushButtonGadgetClass,
75684d9c625SLionel Sambuc rc,
75784d9c625SLionel Sambuc 0
75884d9c625SLionel Sambuc );
75984d9c625SLionel Sambuc XtAddCallback( button, XmNactivateCallback, show_options, rc );
76084d9c625SLionel Sambuc
76184d9c625SLionel Sambuc button = XtVaCreateManagedWidget( "Quit",
76284d9c625SLionel Sambuc xmPushButtonGadgetClass,
76384d9c625SLionel Sambuc rc,
76484d9c625SLionel Sambuc 0
76584d9c625SLionel Sambuc );
76684d9c625SLionel Sambuc XtAddCallback( button, XmNactivateCallback, exit, 0 );
76784d9c625SLionel Sambuc
76884d9c625SLionel Sambuc XtRealizeWidget(top_level);
76984d9c625SLionel Sambuc XtAppMainLoop(ctx);
77084d9c625SLionel Sambuc }
77184d9c625SLionel Sambuc #endif
772