xref: /minix3/external/bsd/nvi/dist/motif_l/m_search.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
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_search.c,v 8.14 2003/11/05 17:10:00 skimo Exp  (Berkeley) Date: 2003/11/05 17:10:00 ";
1684d9c625SLionel Sambuc #endif /* not lint */
17*0a6a1f1dSLionel Sambuc #else
18*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: m_search.c,v 1.2 2014/01/26 21:43:45 christos Exp $");
19*0a6a1f1dSLionel Sambuc #endif
2084d9c625SLionel Sambuc 
2184d9c625SLionel Sambuc #include <sys/queue.h>
2284d9c625SLionel Sambuc 
2384d9c625SLionel Sambuc /* context */
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/Label.h>
2984d9c625SLionel Sambuc #include <Xm/PushBG.h>
3084d9c625SLionel Sambuc #include <Xm/TextF.h>
3184d9c625SLionel Sambuc #include <Xm/ToggleB.h>
3284d9c625SLionel Sambuc #include <Xm/RowColumn.h>
3384d9c625SLionel Sambuc 
3484d9c625SLionel Sambuc #include <bitstring.h>
3584d9c625SLionel Sambuc #include <stdio.h>
3684d9c625SLionel Sambuc #include <stdlib.h>
3784d9c625SLionel Sambuc 
3884d9c625SLionel Sambuc #undef LOCK_SUCCESS
3984d9c625SLionel Sambuc #include "../common/common.h"
4084d9c625SLionel Sambuc #include "../ipc/ip.h"
4184d9c625SLionel Sambuc #include "m_motif.h"
4284d9c625SLionel Sambuc 
4384d9c625SLionel Sambuc extern int vi_ofd;
4484d9c625SLionel Sambuc 
4584d9c625SLionel Sambuc 
4684d9c625SLionel Sambuc /* types */
4784d9c625SLionel Sambuc 
4884d9c625SLionel Sambuc typedef struct sds {
4984d9c625SLionel Sambuc     struct sds	*next;
5084d9c625SLionel Sambuc     Widget	shell;
5184d9c625SLionel Sambuc } save_dialog;
5284d9c625SLionel Sambuc 
5384d9c625SLionel Sambuc static	save_dialog	*dialogs = NULL;
5484d9c625SLionel Sambuc 
5584d9c625SLionel Sambuc typedef struct	{
5684d9c625SLionel Sambuc     String	name;
5784d9c625SLionel Sambuc     void	(*cb)();
5884d9c625SLionel Sambuc } ButtonData;
5984d9c625SLionel Sambuc 
6084d9c625SLionel Sambuc 
6184d9c625SLionel Sambuc /* globals and constants */
6284d9c625SLionel Sambuc 
6384d9c625SLionel Sambuc static	String	PatternWidget = "text";
6484d9c625SLionel Sambuc static	String	pattern = NULL;
6584d9c625SLionel Sambuc 
6684d9c625SLionel Sambuc static optData  search_toggles[] = {
6784d9c625SLionel Sambuc 	{ optToggle,	"extended",	NULL,	VI_SEARCH_EXT	},
6884d9c625SLionel Sambuc 	{ optToggle,	"iclower",	NULL,	VI_SEARCH_ICL	},
6984d9c625SLionel Sambuc 	{ optToggle,	"ignorecase",	NULL,	VI_SEARCH_IC	},
7084d9c625SLionel Sambuc 	{ optToggle,	"literal",	NULL,	VI_SEARCH_LIT	},
7184d9c625SLionel Sambuc 	{ optToggle,	"searchincr",	NULL,	VI_SEARCH_INCR	},
7284d9c625SLionel Sambuc 	{ optToggle,	"wrapscan",	NULL,	VI_SEARCH_WR	},
7384d9c625SLionel Sambuc 	{ optTerminator,		},
7484d9c625SLionel Sambuc };
7584d9c625SLionel Sambuc 
7684d9c625SLionel Sambuc static void done_func __P((Widget));
7784d9c625SLionel Sambuc static void next_func __P((Widget));
7884d9c625SLionel Sambuc static void prev_func __P((Widget));
7984d9c625SLionel Sambuc static void search __P((Widget, int));
8084d9c625SLionel Sambuc 
8184d9c625SLionel Sambuc static	ButtonData button_data[] = {
8284d9c625SLionel Sambuc     { "Next",		next_func	},
8384d9c625SLionel Sambuc     { "Previous", 	prev_func	},
8484d9c625SLionel Sambuc     { "Cancel", 	done_func	}	/* always last */
8584d9c625SLionel Sambuc };
8684d9c625SLionel Sambuc 
8784d9c625SLionel Sambuc 
8884d9c625SLionel Sambuc /* Xt utilities */
8984d9c625SLionel Sambuc 
9084d9c625SLionel Sambuc #if defined(__STDC__)
get_child_widget(Widget parent,String name)9184d9c625SLionel Sambuc static	Widget	get_child_widget( Widget parent, String name )
9284d9c625SLionel Sambuc #else
9384d9c625SLionel Sambuc static	Widget	get_child_widget( parent, name )
9484d9c625SLionel Sambuc 	Widget	parent;
9584d9c625SLionel Sambuc 	String	name;
9684d9c625SLionel Sambuc #endif
9784d9c625SLionel Sambuc {
9884d9c625SLionel Sambuc     char buffer[1024];
9984d9c625SLionel Sambuc 
10084d9c625SLionel Sambuc     strcpy( buffer, "*" );
10184d9c625SLionel Sambuc     strcat( buffer, name );
10284d9c625SLionel Sambuc     return XtNameToWidget( parent, buffer );
10384d9c625SLionel Sambuc }
10484d9c625SLionel Sambuc 
10584d9c625SLionel Sambuc 
10684d9c625SLionel Sambuc /* sync the global state */
10784d9c625SLionel Sambuc 
10884d9c625SLionel Sambuc #if defined(__STDC__)
get_state(Widget w)10984d9c625SLionel Sambuc static	void	get_state( Widget w )
11084d9c625SLionel Sambuc #else
11184d9c625SLionel Sambuc static	void	get_state( w )
11284d9c625SLionel Sambuc 	Widget	w;
11384d9c625SLionel Sambuc #endif
11484d9c625SLionel Sambuc {
11584d9c625SLionel Sambuc #if defined(SelfTest)
11684d9c625SLionel Sambuc     int		i;
11784d9c625SLionel Sambuc #endif
11884d9c625SLionel Sambuc     Widget	shell = w;
11984d9c625SLionel Sambuc 
12084d9c625SLionel Sambuc     /* get all the data from the root of the widget tree */
12184d9c625SLionel Sambuc     while ( ! XtIsShell(shell) ) shell = XtParent(shell);
12284d9c625SLionel Sambuc 
12384d9c625SLionel Sambuc #if defined(SelfTest)
12484d9c625SLionel Sambuc     /* which flags? */
12584d9c625SLionel Sambuc     for (i=0; i<XtNumber(toggle_data); i++) {
12684d9c625SLionel Sambuc 	if (( w = get_child_widget( shell, toggle_data[i].name )) != NULL ) {
12784d9c625SLionel Sambuc 	    XtVaGetValues( w, XmNset, &toggle_data[i].value, 0 );
12884d9c625SLionel Sambuc 	}
12984d9c625SLionel Sambuc     }
13084d9c625SLionel Sambuc #endif
13184d9c625SLionel Sambuc 
13284d9c625SLionel Sambuc     /* what's the pattern? */
13384d9c625SLionel Sambuc     if (( w = get_child_widget( shell, PatternWidget )) != NULL ) {
13484d9c625SLionel Sambuc 	if ( pattern != NULL ) XtFree( pattern );
13584d9c625SLionel Sambuc 	pattern = XmTextFieldGetString( w );
13684d9c625SLionel Sambuc     }
13784d9c625SLionel Sambuc }
13884d9c625SLionel Sambuc 
13984d9c625SLionel Sambuc 
14084d9c625SLionel Sambuc /* Translate the user's actions into nvi commands */
14184d9c625SLionel Sambuc /*
14284d9c625SLionel Sambuc  * next_func --
14384d9c625SLionel Sambuc  *	Action for next button.
14484d9c625SLionel Sambuc  */
14584d9c625SLionel Sambuc static void
next_func(Widget w)14684d9c625SLionel Sambuc next_func(Widget w)
14784d9c625SLionel Sambuc {
14884d9c625SLionel Sambuc 	search(w, 0);
14984d9c625SLionel Sambuc }
15084d9c625SLionel Sambuc 
15184d9c625SLionel Sambuc /*
15284d9c625SLionel Sambuc  * prev_func --
15384d9c625SLionel Sambuc  *	Action for previous button.
15484d9c625SLionel Sambuc  */
15584d9c625SLionel Sambuc static void
prev_func(Widget w)15684d9c625SLionel Sambuc prev_func(Widget w)
15784d9c625SLionel Sambuc {
15884d9c625SLionel Sambuc 	search(w, VI_SEARCH_REV);
15984d9c625SLionel Sambuc }
16084d9c625SLionel Sambuc 
16184d9c625SLionel Sambuc /*
16284d9c625SLionel Sambuc  * search --
16384d9c625SLionel Sambuc  *	Perform the search.
16484d9c625SLionel Sambuc  */
16584d9c625SLionel Sambuc static void
search(Widget w,int flags)16684d9c625SLionel Sambuc search(Widget w, int flags)
16784d9c625SLionel Sambuc {
16884d9c625SLionel Sambuc 	IP_BUF ipb;
16984d9c625SLionel Sambuc 	optData *opt;
17084d9c625SLionel Sambuc 	Widget shell;
17184d9c625SLionel Sambuc 
17284d9c625SLionel Sambuc 	shell = w;
17384d9c625SLionel Sambuc 	while ( ! XtIsShell(shell) ) shell = XtParent(shell);
17484d9c625SLionel Sambuc 
17584d9c625SLionel Sambuc 	/* Get current data from the root of the widget tree?
17684d9c625SLionel Sambuc 	 * Do it if we are a child of a dialog shell (assume we
17784d9c625SLionel Sambuc 	 * are a 'Find' dialog).  Otherwise don't (we are the child
17884d9c625SLionel Sambuc 	 * of a menu and being invoked via accelerator)
17984d9c625SLionel Sambuc 	 */
18084d9c625SLionel Sambuc 	if (XmIsDialogShell(shell))
18184d9c625SLionel Sambuc 		get_state(w);
18284d9c625SLionel Sambuc 
18384d9c625SLionel Sambuc 	/* no pattern? probably, we haven't posted a search dialog yet.
18484d9c625SLionel Sambuc 	 * there ought to be a better thing to do here.
18584d9c625SLionel Sambuc 	 */
18684d9c625SLionel Sambuc 	if ( pattern == NULL ) {
18784d9c625SLionel Sambuc 	    vi_info_message( w, "No previous string specified" );
18884d9c625SLionel Sambuc 	    return;
18984d9c625SLionel Sambuc 	}
19084d9c625SLionel Sambuc 
19184d9c625SLionel Sambuc 	ipb.str1 = pattern;
19284d9c625SLionel Sambuc 	ipb.len1 = strlen(pattern);
19384d9c625SLionel Sambuc 
19484d9c625SLionel Sambuc 	/* Initialize the search flags based on the buttons. */
19584d9c625SLionel Sambuc 	ipb.val1 = flags;
19684d9c625SLionel Sambuc 	for (opt = search_toggles; opt->kind != optTerminator; ++opt)
19784d9c625SLionel Sambuc 		if (opt->value != NULL)
19884d9c625SLionel Sambuc 			ipb.val1 |= opt->flags;
19984d9c625SLionel Sambuc 
20084d9c625SLionel Sambuc 	ipb.code = VI_C_SEARCH;
20184d9c625SLionel Sambuc 	vi_send(vi_ofd, "a1", &ipb);
20284d9c625SLionel Sambuc }
20384d9c625SLionel Sambuc 
20484d9c625SLionel Sambuc #if defined(__STDC__)
done_func(Widget w)20584d9c625SLionel Sambuc static	void	done_func( Widget w )
20684d9c625SLionel Sambuc #else
20784d9c625SLionel Sambuc static	void	done_func( w )
20884d9c625SLionel Sambuc 	Widget	w;
20984d9c625SLionel Sambuc #endif
21084d9c625SLionel Sambuc {
21184d9c625SLionel Sambuc     save_dialog	*ptr;
21284d9c625SLionel Sambuc 
21384d9c625SLionel Sambuc #if defined(SelfTest)
21484d9c625SLionel Sambuc     puts( XtName(w) );
21584d9c625SLionel Sambuc #endif
21684d9c625SLionel Sambuc 
21784d9c625SLionel Sambuc     while ( ! XtIsShell(w) ) w = XtParent(w);
21884d9c625SLionel Sambuc     XtPopdown( w );
21984d9c625SLionel Sambuc 
22084d9c625SLionel Sambuc     /* save it for later */
22184d9c625SLionel Sambuc     ptr		= (save_dialog *) malloc( sizeof(save_dialog) );
22284d9c625SLionel Sambuc     ptr->next	= dialogs;
22384d9c625SLionel Sambuc     ptr->shell	= w;
22484d9c625SLionel Sambuc     dialogs	= ptr;
22584d9c625SLionel Sambuc }
22684d9c625SLionel Sambuc 
22784d9c625SLionel Sambuc 
22884d9c625SLionel Sambuc /* create a set of push buttons */
22984d9c625SLionel Sambuc 
23084d9c625SLionel Sambuc #define	SpacingRatio	4	/* 3:1 button to spaces */
23184d9c625SLionel Sambuc 
23284d9c625SLionel Sambuc #if defined(__STDC__)
create_push_buttons(Widget parent,ButtonData * data,int count)23384d9c625SLionel Sambuc static	Widget	create_push_buttons( Widget parent,
23484d9c625SLionel Sambuc 				     ButtonData *data,
23584d9c625SLionel Sambuc 				     int count
23684d9c625SLionel Sambuc 				    )
23784d9c625SLionel Sambuc #else
23884d9c625SLionel Sambuc static	Widget	create_push_buttons( parent, data, count )
23984d9c625SLionel Sambuc     Widget	parent;
24084d9c625SLionel Sambuc     ButtonData	*data;
24184d9c625SLionel Sambuc     int		count;
24284d9c625SLionel Sambuc #endif
24384d9c625SLionel Sambuc {
24484d9c625SLionel Sambuc     Widget	w, form;
24584d9c625SLionel Sambuc     int		pos = 1, base;
24684d9c625SLionel Sambuc 
24784d9c625SLionel Sambuc     base = SpacingRatio*count + 1;
24884d9c625SLionel Sambuc     form = XtVaCreateManagedWidget( "buttons",
24984d9c625SLionel Sambuc 				    xmFormWidgetClass,
25084d9c625SLionel Sambuc 				    parent,
25184d9c625SLionel Sambuc 				    XmNleftAttachment,	XmATTACH_FORM,
25284d9c625SLionel Sambuc 				    XmNrightAttachment,	XmATTACH_FORM,
25384d9c625SLionel Sambuc 				    XmNfractionBase,	base,
25484d9c625SLionel Sambuc 				    XmNshadowType,	XmSHADOW_ETCHED_IN,
25584d9c625SLionel Sambuc 				    XmNshadowThickness,	2,
25684d9c625SLionel Sambuc 				    XmNverticalSpacing,	4,
25784d9c625SLionel Sambuc 				    0
25884d9c625SLionel Sambuc 				    );
25984d9c625SLionel Sambuc 
26084d9c625SLionel Sambuc     while ( count-- > 0 ) {
26184d9c625SLionel Sambuc 	w = XtVaCreateManagedWidget(data->name,
26284d9c625SLionel Sambuc 				    xmPushButtonGadgetClass,
26384d9c625SLionel Sambuc 				    form,
26484d9c625SLionel Sambuc 				    XmNtopAttachment,	XmATTACH_FORM,
26584d9c625SLionel Sambuc 				    XmNbottomAttachment,XmATTACH_FORM,
26684d9c625SLionel Sambuc 				    XmNleftAttachment,	XmATTACH_POSITION,
26784d9c625SLionel Sambuc 				    XmNleftPosition,	pos,
26884d9c625SLionel Sambuc 				    XmNshowAsDefault,	False,
26984d9c625SLionel Sambuc 				    XmNrightAttachment,	XmATTACH_POSITION,
27084d9c625SLionel Sambuc 				    XmNrightPosition,	pos+SpacingRatio-1,
27184d9c625SLionel Sambuc 				    0
27284d9c625SLionel Sambuc 				    );
27384d9c625SLionel Sambuc 	XtAddCallback( w, XmNactivateCallback, data->cb, 0 );
27484d9c625SLionel Sambuc 	pos += SpacingRatio;
27584d9c625SLionel Sambuc 	data++;
27684d9c625SLionel Sambuc     }
27784d9c625SLionel Sambuc 
27884d9c625SLionel Sambuc     /* last button is 'cancel' */
27984d9c625SLionel Sambuc     XtVaSetValues( XtParent(form), XmNcancelButton, w, 0 );
28084d9c625SLionel Sambuc 
28184d9c625SLionel Sambuc     return form;
28284d9c625SLionel Sambuc }
28384d9c625SLionel Sambuc 
28484d9c625SLionel Sambuc 
28584d9c625SLionel Sambuc /* create a set of check boxes */
28684d9c625SLionel Sambuc 
28784d9c625SLionel Sambuc #if defined(SelfTest)
28884d9c625SLionel Sambuc 
28984d9c625SLionel Sambuc #if defined(__STDC__)
create_check_boxes(Widget parent,ToggleData * toggles,int count)29084d9c625SLionel Sambuc static	Widget	create_check_boxes( Widget parent,
29184d9c625SLionel Sambuc 				    ToggleData *toggles,
29284d9c625SLionel Sambuc 				    int count
29384d9c625SLionel Sambuc 				    )
29484d9c625SLionel Sambuc #else
29584d9c625SLionel Sambuc static	Widget	create_check_boxes( parent, toggles, count )
29684d9c625SLionel Sambuc 	Widget	parent;
29784d9c625SLionel Sambuc 	ToggleData *toggles;
29884d9c625SLionel Sambuc 	int	count;
29984d9c625SLionel Sambuc #endif
30084d9c625SLionel Sambuc {
30184d9c625SLionel Sambuc     Widget	form;
30284d9c625SLionel Sambuc     int		pos = 1, base;
30384d9c625SLionel Sambuc 
30484d9c625SLionel Sambuc     base = SpacingRatio*count +1;
30584d9c625SLionel Sambuc     form = XtVaCreateManagedWidget( "toggles",
30684d9c625SLionel Sambuc 				    xmFormWidgetClass,
30784d9c625SLionel Sambuc 				    parent,
30884d9c625SLionel Sambuc 				    XmNleftAttachment,	XmATTACH_FORM,
30984d9c625SLionel Sambuc 				    XmNrightAttachment,	XmATTACH_FORM,
31084d9c625SLionel Sambuc 				    XmNfractionBase,	base,
31184d9c625SLionel Sambuc 				    XmNverticalSpacing,	4,
31284d9c625SLionel Sambuc 				    0
31384d9c625SLionel Sambuc 				    );
31484d9c625SLionel Sambuc 
31584d9c625SLionel Sambuc     while ( count-- > 0 ) {
31684d9c625SLionel Sambuc 	XtVaCreateManagedWidget(toggles->name,
31784d9c625SLionel Sambuc 				xmToggleButtonWidgetClass,
31884d9c625SLionel Sambuc 				form,
31984d9c625SLionel Sambuc 				XmNtopAttachment,	XmATTACH_FORM,
32084d9c625SLionel Sambuc 				XmNbottomAttachment,	XmATTACH_FORM,
32184d9c625SLionel Sambuc 				XmNleftAttachment,	XmATTACH_POSITION,
32284d9c625SLionel Sambuc 				XmNleftPosition,	pos,
32384d9c625SLionel Sambuc 				XmNrightAttachment,	XmATTACH_POSITION,
32484d9c625SLionel Sambuc 				XmNrightPosition,	pos+SpacingRatio-1,
32584d9c625SLionel Sambuc 				0
32684d9c625SLionel Sambuc 				);
32784d9c625SLionel Sambuc 	pos += SpacingRatio;
32884d9c625SLionel Sambuc 	++toggles;
32984d9c625SLionel Sambuc     }
33084d9c625SLionel Sambuc 
33184d9c625SLionel Sambuc     return form;
33284d9c625SLionel Sambuc }
33384d9c625SLionel Sambuc 
33484d9c625SLionel Sambuc #endif
33584d9c625SLionel Sambuc 
33684d9c625SLionel Sambuc 
33784d9c625SLionel Sambuc /* Routines to handle the text field widget */
33884d9c625SLionel Sambuc 
33984d9c625SLionel Sambuc /* when the user hits 'CR' in a text widget, fire the default pushbutton */
34084d9c625SLionel Sambuc #if defined(__STDC__)
text_cr(Widget w,void * ptr,void * ptr2)34184d9c625SLionel Sambuc static	void	text_cr( Widget w, void *ptr, void *ptr2 )
34284d9c625SLionel Sambuc #else
34384d9c625SLionel Sambuc static	void	text_cr( w, ptr, ptr2 )
34484d9c625SLionel Sambuc 	Widget	w;
34584d9c625SLionel Sambuc 	void	*ptr;
34684d9c625SLionel Sambuc 	void	*ptr2;
34784d9c625SLionel Sambuc #endif
34884d9c625SLionel Sambuc {
34984d9c625SLionel Sambuc     next_func( w );
35084d9c625SLionel Sambuc }
35184d9c625SLionel Sambuc 
35284d9c625SLionel Sambuc 
35384d9c625SLionel Sambuc #ifdef notdef
35484d9c625SLionel Sambuc /*
35584d9c625SLionel Sambuc  * when the user hits any other character, if we are doing incremental
35684d9c625SLionel Sambuc  * search, send the updated string to nvi
35784d9c625SLionel Sambuc  *
35884d9c625SLionel Sambuc  * XXX
35984d9c625SLionel Sambuc  * I don't currently see any way to make this work -- incremental search
36084d9c625SLionel Sambuc  * is going to be really nasty.  What makes it worse is that the dialog
36184d9c625SLionel Sambuc  * box almost certainly obscured a chunk of the text file, so there's no
36284d9c625SLionel Sambuc  * way to use it even if it works.
36384d9c625SLionel Sambuc  */
36484d9c625SLionel Sambuc #if defined(__STDC__)
value_changed(Widget w,void * ptr,void * ptr2)36584d9c625SLionel Sambuc static	void	value_changed( Widget w, void *ptr, void *ptr2 )
36684d9c625SLionel Sambuc #else
36784d9c625SLionel Sambuc static	void	value_changed( w, ptr, ptr2 )
36884d9c625SLionel Sambuc 	Widget	w;
36984d9c625SLionel Sambuc 	void	*ptr;
37084d9c625SLionel Sambuc 	void	*ptr2;
37184d9c625SLionel Sambuc #endif
37284d9c625SLionel Sambuc {
37384d9c625SLionel Sambuc     /* get all the data from the root of the widget tree */
37484d9c625SLionel Sambuc     get_state( w );
37584d9c625SLionel Sambuc 
37684d9c625SLionel Sambuc     /* send it along? */
37784d9c625SLionel Sambuc #if defined(SelfTest)
37884d9c625SLionel Sambuc     if ( incremental_search ) send_command( w );
37984d9c625SLionel Sambuc #else
38084d9c625SLionel Sambuc     if ( __vi_incremental_search() ) send_command( w );
38184d9c625SLionel Sambuc #endif
38284d9c625SLionel Sambuc }
38384d9c625SLionel Sambuc #endif /* notdef */
38484d9c625SLionel Sambuc 
38584d9c625SLionel Sambuc 
38684d9c625SLionel Sambuc /* Draw and display a dialog the describes nvi search capability */
38784d9c625SLionel Sambuc 
38884d9c625SLionel Sambuc #if defined(__STDC__)
create_search_dialog(Widget parent,String title)38984d9c625SLionel Sambuc static	Widget	create_search_dialog( Widget parent, String title )
39084d9c625SLionel Sambuc #else
39184d9c625SLionel Sambuc static	Widget	create_search_dialog( parent, title )
39284d9c625SLionel Sambuc 	Widget	parent;
39384d9c625SLionel Sambuc 	String	title;
39484d9c625SLionel Sambuc #endif
39584d9c625SLionel Sambuc {
39684d9c625SLionel Sambuc     Widget	box, form, label, text, checks, buttons, form2;
39784d9c625SLionel Sambuc     save_dialog	*ptr;
39884d9c625SLionel Sambuc 
39984d9c625SLionel Sambuc     /* use an existing one? */
40084d9c625SLionel Sambuc     if ( dialogs != NULL ) {
40184d9c625SLionel Sambuc 	box = dialogs->shell;
40284d9c625SLionel Sambuc 	ptr = dialogs->next;
40384d9c625SLionel Sambuc 	free( dialogs );
40484d9c625SLionel Sambuc 	dialogs = ptr;
40584d9c625SLionel Sambuc 	return box;
40684d9c625SLionel Sambuc     }
40784d9c625SLionel Sambuc 
40884d9c625SLionel Sambuc     box = XtVaCreatePopupShell( title,
40984d9c625SLionel Sambuc 				xmDialogShellWidgetClass,
41084d9c625SLionel Sambuc 				parent,
41184d9c625SLionel Sambuc 				XmNtitle,		title,
41284d9c625SLionel Sambuc 				XmNallowShellResize,	False,
41384d9c625SLionel Sambuc 				0
41484d9c625SLionel Sambuc 				);
41584d9c625SLionel Sambuc 
41684d9c625SLionel Sambuc     form = XtVaCreateWidget( "form",
41784d9c625SLionel Sambuc 				xmFormWidgetClass,
41884d9c625SLionel Sambuc 				box,
41984d9c625SLionel Sambuc 				XmNverticalSpacing,	4,
42084d9c625SLionel Sambuc 				XmNhorizontalSpacing,	4,
42184d9c625SLionel Sambuc 				0
42284d9c625SLionel Sambuc 				);
42384d9c625SLionel Sambuc 
42484d9c625SLionel Sambuc     form2 = XtVaCreateManagedWidget( "form",
42584d9c625SLionel Sambuc 				xmFormWidgetClass,
42684d9c625SLionel Sambuc 				form,
42784d9c625SLionel Sambuc 				XmNtopAttachment,	XmATTACH_FORM,
42884d9c625SLionel Sambuc 				XmNleftAttachment,	XmATTACH_FORM,
42984d9c625SLionel Sambuc 				XmNrightAttachment,	XmATTACH_FORM,
43084d9c625SLionel Sambuc 				0
43184d9c625SLionel Sambuc 				);
43284d9c625SLionel Sambuc 
43384d9c625SLionel Sambuc     label = XtVaCreateManagedWidget( "Pattern:",
43484d9c625SLionel Sambuc 				    xmLabelWidgetClass,
43584d9c625SLionel Sambuc 				    form2,
43684d9c625SLionel Sambuc 				    XmNtopAttachment,	XmATTACH_FORM,
43784d9c625SLionel Sambuc 				    XmNbottomAttachment,XmATTACH_FORM,
43884d9c625SLionel Sambuc 				    XmNleftAttachment,	XmATTACH_FORM,
43984d9c625SLionel Sambuc 				    0
44084d9c625SLionel Sambuc 				    );
44184d9c625SLionel Sambuc 
44284d9c625SLionel Sambuc     text = XtVaCreateManagedWidget( PatternWidget,
44384d9c625SLionel Sambuc 				    xmTextFieldWidgetClass,
44484d9c625SLionel Sambuc 				    form2,
44584d9c625SLionel Sambuc 				    XmNtopAttachment,	XmATTACH_FORM,
44684d9c625SLionel Sambuc 				    XmNbottomAttachment,XmATTACH_FORM,
44784d9c625SLionel Sambuc 				    XmNleftAttachment,	XmATTACH_WIDGET,
44884d9c625SLionel Sambuc 				    XmNleftWidget,	label,
44984d9c625SLionel Sambuc 				    XmNrightAttachment,	XmATTACH_FORM,
45084d9c625SLionel Sambuc 				    0
45184d9c625SLionel Sambuc 				    );
45284d9c625SLionel Sambuc #ifdef notdef
45384d9c625SLionel Sambuc     XtAddCallback( text, XmNvalueChangedCallback, value_changed, 0 );
45484d9c625SLionel Sambuc #endif
45584d9c625SLionel Sambuc     XtAddCallback( text, XmNactivateCallback, text_cr, 0 );
45684d9c625SLionel Sambuc 
45784d9c625SLionel Sambuc     buttons = create_push_buttons( form, button_data, XtNumber(button_data) );
45884d9c625SLionel Sambuc     XtVaSetValues( buttons,
45984d9c625SLionel Sambuc 		   XmNbottomAttachment,	XmATTACH_FORM,
46084d9c625SLionel Sambuc 		   0
46184d9c625SLionel Sambuc 		   );
46284d9c625SLionel Sambuc 
46384d9c625SLionel Sambuc #if defined(SelfTest)
46484d9c625SLionel Sambuc     checks = create_check_boxes( form, toggle_data, XtNumber(toggle_data) );
46584d9c625SLionel Sambuc #else
46684d9c625SLionel Sambuc     checks = (Widget) __vi_create_search_toggles( form, search_toggles );
46784d9c625SLionel Sambuc #endif
46884d9c625SLionel Sambuc     XtVaSetValues( checks,
46984d9c625SLionel Sambuc 		   XmNtopAttachment,	XmATTACH_WIDGET,
47084d9c625SLionel Sambuc 		   XmNtopWidget,	form2,
47184d9c625SLionel Sambuc 		   XmNbottomAttachment,	XmATTACH_WIDGET,
47284d9c625SLionel Sambuc 		   XmNbottomWidget,	buttons,
47384d9c625SLionel Sambuc 		   0
47484d9c625SLionel Sambuc 		   );
47584d9c625SLionel Sambuc 
47684d9c625SLionel Sambuc     XtManageChild( form );
47784d9c625SLionel Sambuc     return box;
47884d9c625SLionel Sambuc }
47984d9c625SLionel Sambuc 
48084d9c625SLionel Sambuc 
48184d9c625SLionel Sambuc /* Module interface to the outside world
48284d9c625SLionel Sambuc  *
48384d9c625SLionel Sambuc  *	xip_show_search_dialog( parent, title )
48484d9c625SLionel Sambuc  *	pops up a search dialog
48584d9c625SLionel Sambuc  *
48684d9c625SLionel Sambuc  *	xip_next_search()
48784d9c625SLionel Sambuc  *	simulates a 'next' assuming that a search has been done
48884d9c625SLionel Sambuc  */
48984d9c625SLionel Sambuc 
49084d9c625SLionel Sambuc #if defined(__STDC__)
__vi_show_search_dialog(Widget parent,String title)49184d9c625SLionel Sambuc void 	__vi_show_search_dialog( Widget parent, String title )
49284d9c625SLionel Sambuc #else
49384d9c625SLionel Sambuc void	__vi_show_search_dialog( parent, data, cbs )
49484d9c625SLionel Sambuc Widget	parent;
49584d9c625SLionel Sambuc String	title;
49684d9c625SLionel Sambuc #endif
49784d9c625SLionel Sambuc {
49884d9c625SLionel Sambuc     Widget 	db = create_search_dialog( parent, title );
49984d9c625SLionel Sambuc     Dimension	height;
50084d9c625SLionel Sambuc 
50184d9c625SLionel Sambuc     /* we can handle getting taller and wider or narrower, but not shorter */
50284d9c625SLionel Sambuc     XtVaGetValues( db, XmNheight, &height, 0 );
50384d9c625SLionel Sambuc     XtVaSetValues( db, XmNmaxHeight, height, XmNminHeight, height, 0 );
50484d9c625SLionel Sambuc 
50584d9c625SLionel Sambuc     /* post the dialog */
50684d9c625SLionel Sambuc     XtPopup( db, XtGrabNone );
50784d9c625SLionel Sambuc 
50884d9c625SLionel Sambuc     /* request initial focus to the text widget */
50984d9c625SLionel Sambuc     XmProcessTraversal( get_child_widget( db, PatternWidget ),
51084d9c625SLionel Sambuc 			XmTRAVERSE_CURRENT
51184d9c625SLionel Sambuc 			);
51284d9c625SLionel Sambuc }
51384d9c625SLionel Sambuc 
51484d9c625SLionel Sambuc 
51584d9c625SLionel Sambuc /*
51684d9c625SLionel Sambuc  * __vi_search --
51784d9c625SLionel Sambuc  *
51884d9c625SLionel Sambuc  * PUBLIC: void __vi_search __P((Widget));
51984d9c625SLionel Sambuc  */
52084d9c625SLionel Sambuc void
__vi_search(Widget w)52184d9c625SLionel Sambuc __vi_search(Widget w)
52284d9c625SLionel Sambuc {
52384d9c625SLionel Sambuc     next_func( w );
52484d9c625SLionel Sambuc }
52584d9c625SLionel Sambuc 
52684d9c625SLionel Sambuc 
52784d9c625SLionel Sambuc #if defined(SelfTest)
52884d9c625SLionel Sambuc 
52984d9c625SLionel Sambuc #if defined(__STDC__)
show_search(Widget w,XtPointer data,XtPointer cbs)53084d9c625SLionel Sambuc static void show_search( Widget w, XtPointer data, XtPointer cbs )
53184d9c625SLionel Sambuc #else
53284d9c625SLionel Sambuc static void show_search( w, data, cbs )
53384d9c625SLionel Sambuc Widget w;
53484d9c625SLionel Sambuc XtPointer	data;
53584d9c625SLionel Sambuc XtPointer	cbs;
53684d9c625SLionel Sambuc #endif
53784d9c625SLionel Sambuc {
53884d9c625SLionel Sambuc     __vi_show_search_dialog( data, "Search" );
53984d9c625SLionel Sambuc }
54084d9c625SLionel Sambuc 
main(int argc,char * argv[])54184d9c625SLionel Sambuc main( int argc, char *argv[] )
54284d9c625SLionel Sambuc {
54384d9c625SLionel Sambuc     XtAppContext	ctx;
54484d9c625SLionel Sambuc     Widget		top_level, rc, button;
54584d9c625SLionel Sambuc     extern		exit();
54684d9c625SLionel Sambuc 
54784d9c625SLionel Sambuc     /* create a top-level shell for the window manager */
54884d9c625SLionel Sambuc     top_level = XtVaAppInitialize( &ctx,
54984d9c625SLionel Sambuc 				   argv[0],
55084d9c625SLionel Sambuc 				   NULL, 0,	/* options */
55184d9c625SLionel Sambuc 				   (ArgcType) &argc,
55284d9c625SLionel Sambuc 				   argv,	/* might get modified */
55384d9c625SLionel Sambuc 				   NULL,
55484d9c625SLionel Sambuc 				   NULL
55584d9c625SLionel Sambuc 				   );
55684d9c625SLionel Sambuc 
55784d9c625SLionel Sambuc     rc = XtVaCreateManagedWidget( "rc",
55884d9c625SLionel Sambuc 				  xmRowColumnWidgetClass,
55984d9c625SLionel Sambuc 				  top_level,
56084d9c625SLionel Sambuc 				  0
56184d9c625SLionel Sambuc 				  );
56284d9c625SLionel Sambuc 
56384d9c625SLionel Sambuc     button = XtVaCreateManagedWidget( "Pop up search dialog",
56484d9c625SLionel Sambuc 				      xmPushButtonGadgetClass,
56584d9c625SLionel Sambuc 				      rc,
56684d9c625SLionel Sambuc 				      0
56784d9c625SLionel Sambuc 				      );
56884d9c625SLionel Sambuc     XtAddCallback( button, XmNactivateCallback, show_search, rc );
56984d9c625SLionel Sambuc 
57084d9c625SLionel Sambuc     button = XtVaCreateManagedWidget( "Quit",
57184d9c625SLionel Sambuc 				      xmPushButtonGadgetClass,
57284d9c625SLionel Sambuc 				      rc,
57384d9c625SLionel Sambuc 				      0
57484d9c625SLionel Sambuc 				      );
57584d9c625SLionel Sambuc     XtAddCallback( button, XmNactivateCallback, exit, 0 );
57684d9c625SLionel Sambuc 
57784d9c625SLionel Sambuc     XtRealizeWidget(top_level);
57884d9c625SLionel Sambuc     XtAppMainLoop(ctx);
57984d9c625SLionel Sambuc }
58084d9c625SLionel Sambuc #endif
581