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_menu.c,v 8.26 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_menu.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 #include <X11/Intrinsic.h>
2484d9c625SLionel Sambuc #include <X11/StringDefs.h>
2584d9c625SLionel Sambuc #include <Xm/PushB.h>
2684d9c625SLionel Sambuc #include <Xm/CascadeB.h>
2784d9c625SLionel Sambuc #include <Xm/RowColumn.h>
2884d9c625SLionel Sambuc #include <Xm/Separator.h>
2984d9c625SLionel Sambuc #include <Xm/FileSB.h>
3084d9c625SLionel Sambuc #include <Xm/SelectioB.h>
3184d9c625SLionel Sambuc
3284d9c625SLionel Sambuc #include <bitstring.h>
3384d9c625SLionel Sambuc #include <stdio.h>
3484d9c625SLionel Sambuc
3584d9c625SLionel Sambuc #undef LOCK_SUCCESS
3684d9c625SLionel Sambuc #include "../common/common.h"
3784d9c625SLionel Sambuc #include "../ipc/ip.h"
3884d9c625SLionel Sambuc #include "m_motif.h"
3984d9c625SLionel Sambuc
4084d9c625SLionel Sambuc extern int vi_ofd;
4184d9c625SLionel Sambuc
4284d9c625SLionel Sambuc /* save this for creation of children */
4384d9c625SLionel Sambuc static Widget main_widget = NULL;
4484d9c625SLionel Sambuc
4584d9c625SLionel Sambuc /* This module defines the menu structure for vi. Each menu
4684d9c625SLionel Sambuc * item has an action routine associated with it. For the most
4784d9c625SLionel Sambuc * part, those actions will simply call vi_send with vi commands.
4884d9c625SLionel Sambuc * others will pop up file selection dialogs and use them for
4984d9c625SLionel Sambuc * vi commands, and other will have to have special actions.
5084d9c625SLionel Sambuc *
5184d9c625SLionel Sambuc * Future:
5284d9c625SLionel Sambuc * vi core will have to let us know when to be sensitive
5384d9c625SLionel Sambuc * change VI_STRING to VI_COMMAND so that menu actions cannot
5484d9c625SLionel Sambuc * be confusing when in insert mode
5584d9c625SLionel Sambuc * need VI_CUT, VI_COPY, and VI_PASTE to perform the appropriate
5684d9c625SLionel Sambuc * operations on the visible text of yank buffer. VI_COPY
5784d9c625SLionel Sambuc * is likely a NOP, but it will make users happy
5884d9c625SLionel Sambuc * add mnemonics
5984d9c625SLionel Sambuc * add accelerators
6084d9c625SLionel Sambuc * implement file selection dialog boxes
6184d9c625SLionel Sambuc * implement string prompt dialog boxes (e.g. for 'find')
6284d9c625SLionel Sambuc *
6384d9c625SLionel Sambuc * Interface:
6484d9c625SLionel Sambuc * Widget create_menubar( Widget parent ) creates and returns the
6584d9c625SLionel Sambuc * X menu structure. The caller can place this
6684d9c625SLionel Sambuc * anywhere in the widget heirarchy.
6784d9c625SLionel Sambuc */
6884d9c625SLionel Sambuc
6984d9c625SLionel Sambuc #define BufferSize 1024
7084d9c625SLionel Sambuc
7184d9c625SLionel Sambuc /*
7284d9c625SLionel Sambuc * __vi_send_command_string --
7384d9c625SLionel Sambuc * Utility: Send a menu command to vi
7484d9c625SLionel Sambuc *
7584d9c625SLionel Sambuc * Future:
7684d9c625SLionel Sambuc * Change VI_STRING to VI_COMMAND so that menu actions cannot be confusing
7784d9c625SLionel Sambuc * when in insert mode.
7884d9c625SLionel Sambuc *
7984d9c625SLionel Sambuc * XXX
8084d9c625SLionel Sambuc * THIS SHOULD GO AWAY -- WE SHOULDN'T SEND UNINTERPRETED STRINGS TO THE
8184d9c625SLionel Sambuc * CORE.
8284d9c625SLionel Sambuc *
8384d9c625SLionel Sambuc * PUBLIC: void __vi_send_command_string __P((String));
8484d9c625SLionel Sambuc */
8584d9c625SLionel Sambuc void
__vi_send_command_string(String str)8684d9c625SLionel Sambuc __vi_send_command_string(String str)
8784d9c625SLionel Sambuc {
8884d9c625SLionel Sambuc IP_BUF ipb;
8984d9c625SLionel Sambuc char buffer[BufferSize];
9084d9c625SLionel Sambuc
9184d9c625SLionel Sambuc /* Future: Need VI_COMMAND so vi knows this is not text to insert
9284d9c625SLionel Sambuc * At that point, appending a cr/lf will not be necessary. For now,
9384d9c625SLionel Sambuc * append iff we are a colon or slash command. Of course, if we are in
9484d9c625SLionel Sambuc * insert mode, all bets are off.
9584d9c625SLionel Sambuc */
9684d9c625SLionel Sambuc strcpy( buffer, str );
9784d9c625SLionel Sambuc switch ( *str ) {
9884d9c625SLionel Sambuc case ':':
9984d9c625SLionel Sambuc case '/':
10084d9c625SLionel Sambuc strcat( buffer, "\n" );
10184d9c625SLionel Sambuc break;
10284d9c625SLionel Sambuc }
10384d9c625SLionel Sambuc
10484d9c625SLionel Sambuc ipb.code = VI_STRING;
10584d9c625SLionel Sambuc ipb.str1 = buffer;
10684d9c625SLionel Sambuc ipb.len1 = strlen(buffer);
10784d9c625SLionel Sambuc vi_send(vi_ofd, "a", &ipb);
10884d9c625SLionel Sambuc }
10984d9c625SLionel Sambuc
11084d9c625SLionel Sambuc
11184d9c625SLionel Sambuc /* Utility: beep for unimplemented command */
11284d9c625SLionel Sambuc
11384d9c625SLionel Sambuc #if defined(__STDC__)
send_beep(Widget w)11484d9c625SLionel Sambuc static void send_beep( Widget w )
11584d9c625SLionel Sambuc #else
11684d9c625SLionel Sambuc static void send_beep( w )
11784d9c625SLionel Sambuc Widget w;
11884d9c625SLionel Sambuc #endif
11984d9c625SLionel Sambuc {
12084d9c625SLionel Sambuc XBell( XtDisplay(w), 0 );
12184d9c625SLionel Sambuc }
12284d9c625SLionel Sambuc
12384d9c625SLionel Sambuc
12484d9c625SLionel Sambuc /*
12584d9c625SLionel Sambuc * __vi_cancel_cb --
12684d9c625SLionel Sambuc * Utility: make a dialog box go Modal
12784d9c625SLionel Sambuc *
12884d9c625SLionel Sambuc * PUBLIC: void __vi_cancel_cb __P((Widget, XtPointer, XtPointer));
12984d9c625SLionel Sambuc */
13084d9c625SLionel Sambuc static Bool have_answer;
13184d9c625SLionel Sambuc void
__vi_cancel_cb(Widget w,XtPointer client_data,XtPointer call_data)13284d9c625SLionel Sambuc __vi_cancel_cb(Widget w, XtPointer client_data, XtPointer call_data)
13384d9c625SLionel Sambuc {
13484d9c625SLionel Sambuc have_answer = True;
13584d9c625SLionel Sambuc }
13684d9c625SLionel Sambuc
13784d9c625SLionel Sambuc /*
13884d9c625SLionel Sambuc * PUBLIC: void __vi_modal_dialog __P((Widget));
13984d9c625SLionel Sambuc */
14084d9c625SLionel Sambuc void
__vi_modal_dialog(Widget db)14184d9c625SLionel Sambuc __vi_modal_dialog(Widget db)
14284d9c625SLionel Sambuc {
14384d9c625SLionel Sambuc XtAppContext ctx;
14484d9c625SLionel Sambuc
14584d9c625SLionel Sambuc /* post the dialog */
14684d9c625SLionel Sambuc XtManageChild( db );
14784d9c625SLionel Sambuc XtPopup( XtParent(db), XtGrabExclusive );
14884d9c625SLionel Sambuc
14984d9c625SLionel Sambuc /* wait for a response */
15084d9c625SLionel Sambuc ctx = XtWidgetToApplicationContext(db);
15184d9c625SLionel Sambuc XtAddGrab( XtParent(db), TRUE, FALSE );
15284d9c625SLionel Sambuc for ( have_answer = False; ! have_answer; )
15384d9c625SLionel Sambuc XtAppProcessEvent( ctx, XtIMAll );
15484d9c625SLionel Sambuc
15584d9c625SLionel Sambuc /* done with db */
15684d9c625SLionel Sambuc XtPopdown( XtParent(db) );
15784d9c625SLionel Sambuc XtRemoveGrab( XtParent(db) );
15884d9c625SLionel Sambuc }
15984d9c625SLionel Sambuc
16084d9c625SLionel Sambuc
16184d9c625SLionel Sambuc /* Utility: Get a file (using standard File Selection Dialog Box) */
16284d9c625SLionel Sambuc
16384d9c625SLionel Sambuc static String file_name;
16484d9c625SLionel Sambuc
16584d9c625SLionel Sambuc
16684d9c625SLionel Sambuc #if defined(__STDC__)
ok_file_name(Widget w,XtPointer client_data,XtPointer call_data)16784d9c625SLionel Sambuc static void ok_file_name( Widget w,
16884d9c625SLionel Sambuc XtPointer client_data,
16984d9c625SLionel Sambuc XtPointer call_data
17084d9c625SLionel Sambuc )
17184d9c625SLionel Sambuc #else
17284d9c625SLionel Sambuc static void ok_file_name( w, client_data, call_data )
17384d9c625SLionel Sambuc Widget w;
17484d9c625SLionel Sambuc XtPointer client_data;
17584d9c625SLionel Sambuc XtPointer call_data;
17684d9c625SLionel Sambuc #endif
17784d9c625SLionel Sambuc {
17884d9c625SLionel Sambuc XmFileSelectionBoxCallbackStruct *cbs;
17984d9c625SLionel Sambuc
18084d9c625SLionel Sambuc cbs = (XmFileSelectionBoxCallbackStruct *) call_data;
18184d9c625SLionel Sambuc XmStringGetLtoR( cbs->value, XmSTRING_DEFAULT_CHARSET, &file_name );
18284d9c625SLionel Sambuc
18384d9c625SLionel Sambuc have_answer = True;
18484d9c625SLionel Sambuc }
18584d9c625SLionel Sambuc
18684d9c625SLionel Sambuc
18784d9c625SLionel Sambuc #if defined(__STDC__)
get_file(Widget w,String prompt)18884d9c625SLionel Sambuc static String get_file( Widget w, String prompt )
18984d9c625SLionel Sambuc #else
19084d9c625SLionel Sambuc static String get_file( w, prompt )
19184d9c625SLionel Sambuc Widget w;
19284d9c625SLionel Sambuc String prompt;
19384d9c625SLionel Sambuc #endif
19484d9c625SLionel Sambuc {
19584d9c625SLionel Sambuc /* make it static so we can reuse it */
19684d9c625SLionel Sambuc static Widget db;
19784d9c625SLionel Sambuc
19884d9c625SLionel Sambuc /* our return parameter */
19984d9c625SLionel Sambuc if ( file_name != NULL ) {
20084d9c625SLionel Sambuc XtFree( file_name );
20184d9c625SLionel Sambuc file_name = NULL;
20284d9c625SLionel Sambuc }
20384d9c625SLionel Sambuc
20484d9c625SLionel Sambuc /* create one? */
20584d9c625SLionel Sambuc if ( db == NULL ){
20684d9c625SLionel Sambuc db = XmCreateFileSelectionDialog( main_widget, "file", NULL, 0 );
20784d9c625SLionel Sambuc XtAddCallback( db, XmNokCallback, ok_file_name, NULL );
20884d9c625SLionel Sambuc XtAddCallback( db, XmNcancelCallback, __vi_cancel_cb, NULL );
20984d9c625SLionel Sambuc }
21084d9c625SLionel Sambuc
21184d9c625SLionel Sambuc /* use the title as a prompt */
21284d9c625SLionel Sambuc XtVaSetValues( XtParent(db), XmNtitle, prompt, 0 );
21384d9c625SLionel Sambuc
21484d9c625SLionel Sambuc /* wait for a response */
21584d9c625SLionel Sambuc __vi_modal_dialog( db );
21684d9c625SLionel Sambuc
21784d9c625SLionel Sambuc /* done */
21884d9c625SLionel Sambuc return file_name;
21984d9c625SLionel Sambuc }
22084d9c625SLionel Sambuc
22184d9c625SLionel Sambuc
22284d9c625SLionel Sambuc /*
22384d9c625SLionel Sambuc * file_command --
22484d9c625SLionel Sambuc * Get a file name and send it with the command to the core.
22584d9c625SLionel Sambuc */
22684d9c625SLionel Sambuc static void
file_command(Widget w,int code,String prompt)22784d9c625SLionel Sambuc file_command(Widget w, int code, String prompt)
22884d9c625SLionel Sambuc {
22984d9c625SLionel Sambuc IP_BUF ipb;
23084d9c625SLionel Sambuc char *file;
23184d9c625SLionel Sambuc
23284d9c625SLionel Sambuc if ((file = get_file(w, prompt)) != NULL) {
23384d9c625SLionel Sambuc ipb.code = code;
23484d9c625SLionel Sambuc ipb.str1 = file;
23584d9c625SLionel Sambuc ipb.len1 = strlen(file);
23684d9c625SLionel Sambuc vi_send(vi_ofd, "a", &ipb);
23784d9c625SLionel Sambuc }
23884d9c625SLionel Sambuc }
23984d9c625SLionel Sambuc
24084d9c625SLionel Sambuc
24184d9c625SLionel Sambuc /*
24284d9c625SLionel Sambuc * Menu action routines (one per menu entry)
24384d9c625SLionel Sambuc *
24484d9c625SLionel Sambuc * These are in the order in which they appear in the menu structure.
24584d9c625SLionel Sambuc */
24684d9c625SLionel Sambuc static void
ma_edit_file(Widget w,XtPointer call_data,XtPointer client_data)24784d9c625SLionel Sambuc ma_edit_file(Widget w, XtPointer call_data, XtPointer client_data)
24884d9c625SLionel Sambuc {
24984d9c625SLionel Sambuc file_command(w, VI_EDIT, "Edit");
25084d9c625SLionel Sambuc }
25184d9c625SLionel Sambuc
25284d9c625SLionel Sambuc static void
ma_split(Widget w,XtPointer call_data,XtPointer client_data)25384d9c625SLionel Sambuc ma_split(Widget w, XtPointer call_data, XtPointer client_data)
25484d9c625SLionel Sambuc {
25584d9c625SLionel Sambuc file_command(w, VI_EDITSPLIT, "Edit");
25684d9c625SLionel Sambuc }
25784d9c625SLionel Sambuc
25884d9c625SLionel Sambuc static void
ma_save(Widget w,XtPointer call_data,XtPointer client_data)25984d9c625SLionel Sambuc ma_save(Widget w, XtPointer call_data, XtPointer client_data)
26084d9c625SLionel Sambuc {
26184d9c625SLionel Sambuc IP_BUF ipb;
26284d9c625SLionel Sambuc
26384d9c625SLionel Sambuc ipb.code = VI_WRITE;
26484d9c625SLionel Sambuc (void)vi_send(vi_ofd, NULL, &ipb);
26584d9c625SLionel Sambuc }
26684d9c625SLionel Sambuc
26784d9c625SLionel Sambuc static void
ma_save_as(Widget w,XtPointer call_data,XtPointer client_data)26884d9c625SLionel Sambuc ma_save_as(Widget w, XtPointer call_data, XtPointer client_data)
26984d9c625SLionel Sambuc {
27084d9c625SLionel Sambuc file_command(w, VI_WRITEAS, "Save As");
27184d9c625SLionel Sambuc }
27284d9c625SLionel Sambuc
27384d9c625SLionel Sambuc static void
ma_wq(Widget w,XtPointer call_data,XtPointer client_data)27484d9c625SLionel Sambuc ma_wq(Widget w, XtPointer call_data, XtPointer client_data)
27584d9c625SLionel Sambuc {
27684d9c625SLionel Sambuc IP_BUF ipb;
27784d9c625SLionel Sambuc
27884d9c625SLionel Sambuc ipb.code = VI_WQ;
27984d9c625SLionel Sambuc (void)vi_send(vi_ofd, NULL, &ipb);
28084d9c625SLionel Sambuc }
28184d9c625SLionel Sambuc
28284d9c625SLionel Sambuc static void
ma_quit(Widget w,XtPointer call_data,XtPointer client_data)28384d9c625SLionel Sambuc ma_quit(Widget w, XtPointer call_data, XtPointer client_data)
28484d9c625SLionel Sambuc {
28584d9c625SLionel Sambuc IP_BUF ipb;
28684d9c625SLionel Sambuc
28784d9c625SLionel Sambuc ipb.code = VI_QUIT;
28884d9c625SLionel Sambuc (void)vi_send(vi_ofd, NULL, &ipb);
28984d9c625SLionel Sambuc }
29084d9c625SLionel Sambuc
29184d9c625SLionel Sambuc static void
ma_undo(Widget w,XtPointer call_data,XtPointer client_data)29284d9c625SLionel Sambuc ma_undo(Widget w, XtPointer call_data, XtPointer client_data)
29384d9c625SLionel Sambuc {
29484d9c625SLionel Sambuc IP_BUF ipb;
29584d9c625SLionel Sambuc
29684d9c625SLionel Sambuc ipb.code = VI_UNDO;
29784d9c625SLionel Sambuc (void)vi_send(vi_ofd, NULL, &ipb);
29884d9c625SLionel Sambuc }
29984d9c625SLionel Sambuc
30084d9c625SLionel Sambuc #if defined(__STDC__)
ma_cut(Widget w,XtPointer call_data,XtPointer client_data)30184d9c625SLionel Sambuc static void ma_cut( Widget w,
30284d9c625SLionel Sambuc XtPointer call_data,
30384d9c625SLionel Sambuc XtPointer client_data
30484d9c625SLionel Sambuc )
30584d9c625SLionel Sambuc #else
30684d9c625SLionel Sambuc static void ma_cut( w, call_data, client_data )
30784d9c625SLionel Sambuc Widget w;
30884d9c625SLionel Sambuc XtPointer call_data;
30984d9c625SLionel Sambuc XtPointer client_data;
31084d9c625SLionel Sambuc #endif
31184d9c625SLionel Sambuc {
31284d9c625SLionel Sambuc /* future */
31384d9c625SLionel Sambuc send_beep( w );
31484d9c625SLionel Sambuc }
31584d9c625SLionel Sambuc
31684d9c625SLionel Sambuc
31784d9c625SLionel Sambuc #if defined(__STDC__)
ma_copy(Widget w,XtPointer call_data,XtPointer client_data)31884d9c625SLionel Sambuc static void ma_copy( Widget w,
31984d9c625SLionel Sambuc XtPointer call_data,
32084d9c625SLionel Sambuc XtPointer client_data
32184d9c625SLionel Sambuc )
32284d9c625SLionel Sambuc #else
32384d9c625SLionel Sambuc static void ma_copy( w, call_data, client_data )
32484d9c625SLionel Sambuc Widget w;
32584d9c625SLionel Sambuc XtPointer call_data;
32684d9c625SLionel Sambuc XtPointer client_data;
32784d9c625SLionel Sambuc #endif
32884d9c625SLionel Sambuc {
32984d9c625SLionel Sambuc /* future */
33084d9c625SLionel Sambuc send_beep( w );
33184d9c625SLionel Sambuc }
33284d9c625SLionel Sambuc
33384d9c625SLionel Sambuc
33484d9c625SLionel Sambuc #if defined(__STDC__)
ma_paste(Widget w,XtPointer call_data,XtPointer client_data)33584d9c625SLionel Sambuc static void ma_paste( Widget w,
33684d9c625SLionel Sambuc XtPointer call_data,
33784d9c625SLionel Sambuc XtPointer client_data
33884d9c625SLionel Sambuc )
33984d9c625SLionel Sambuc #else
34084d9c625SLionel Sambuc static void ma_paste( w, call_data, client_data )
34184d9c625SLionel Sambuc Widget w;
34284d9c625SLionel Sambuc XtPointer call_data;
34384d9c625SLionel Sambuc XtPointer client_data;
34484d9c625SLionel Sambuc #endif
34584d9c625SLionel Sambuc {
34684d9c625SLionel Sambuc /* future */
34784d9c625SLionel Sambuc send_beep( w );
34884d9c625SLionel Sambuc }
34984d9c625SLionel Sambuc
35084d9c625SLionel Sambuc static void
ma_find(Widget w,XtPointer call_data,XtPointer client_data)35184d9c625SLionel Sambuc ma_find(Widget w, XtPointer call_data, XtPointer client_data)
35284d9c625SLionel Sambuc {
35384d9c625SLionel Sambuc __vi_show_search_dialog( main_widget, "Find" );
35484d9c625SLionel Sambuc }
35584d9c625SLionel Sambuc
35684d9c625SLionel Sambuc static void
ma_find_next(Widget w,XtPointer call_data,XtPointer client_data)35784d9c625SLionel Sambuc ma_find_next(Widget w, XtPointer call_data, XtPointer client_data)
35884d9c625SLionel Sambuc {
35984d9c625SLionel Sambuc __vi_search( w );
36084d9c625SLionel Sambuc }
36184d9c625SLionel Sambuc
36284d9c625SLionel Sambuc static void
ma_tags(Widget w,XtPointer call_data,XtPointer client_data)36384d9c625SLionel Sambuc ma_tags(Widget w, XtPointer call_data, XtPointer client_data)
36484d9c625SLionel Sambuc {
36584d9c625SLionel Sambuc __vi_show_tags_dialog( main_widget, "Tag Stack" );
36684d9c625SLionel Sambuc }
36784d9c625SLionel Sambuc
36884d9c625SLionel Sambuc static void
ma_tagpop(Widget w,XtPointer call_data,XtPointer client_data)36984d9c625SLionel Sambuc ma_tagpop(Widget w, XtPointer call_data, XtPointer client_data)
37084d9c625SLionel Sambuc {
37184d9c625SLionel Sambuc __vi_send_command_string( "\024" );
37284d9c625SLionel Sambuc }
37384d9c625SLionel Sambuc
37484d9c625SLionel Sambuc static void
ma_tagtop(Widget w,XtPointer call_data,XtPointer client_data)37584d9c625SLionel Sambuc ma_tagtop(Widget w, XtPointer call_data, XtPointer client_data)
37684d9c625SLionel Sambuc {
37784d9c625SLionel Sambuc __vi_send_command_string( ":tagtop" );
37884d9c625SLionel Sambuc }
37984d9c625SLionel Sambuc
38084d9c625SLionel Sambuc #if defined(__STDC__)
ma_preferences(Widget w,XtPointer call_data,XtPointer client_data)38184d9c625SLionel Sambuc static void ma_preferences( Widget w,
38284d9c625SLionel Sambuc XtPointer call_data,
38384d9c625SLionel Sambuc XtPointer client_data
38484d9c625SLionel Sambuc )
38584d9c625SLionel Sambuc #else
38684d9c625SLionel Sambuc static void ma_preferences( w, call_data, client_data )
38784d9c625SLionel Sambuc Widget w;
38884d9c625SLionel Sambuc XtPointer call_data;
38984d9c625SLionel Sambuc XtPointer client_data;
39084d9c625SLionel Sambuc #endif
39184d9c625SLionel Sambuc {
39284d9c625SLionel Sambuc __vi_show_options_dialog( main_widget, "Preferences" );
39384d9c625SLionel Sambuc }
39484d9c625SLionel Sambuc
39584d9c625SLionel Sambuc
39684d9c625SLionel Sambuc /* Menu construction routines */
39784d9c625SLionel Sambuc
39884d9c625SLionel Sambuc typedef struct {
39984d9c625SLionel Sambuc String title;
40084d9c625SLionel Sambuc void (*action)();
40184d9c625SLionel Sambuc String accel; /* for Motif */
40284d9c625SLionel Sambuc String accel_text; /* for the user */
40384d9c625SLionel Sambuc } pull_down;
40484d9c625SLionel Sambuc
40584d9c625SLionel Sambuc typedef struct {
40684d9c625SLionel Sambuc char mnemonic;
40784d9c625SLionel Sambuc String title;
40884d9c625SLionel Sambuc pull_down *actions;
40984d9c625SLionel Sambuc } menu_bar;
41084d9c625SLionel Sambuc
41184d9c625SLionel Sambuc static pull_down file_menu[] = {
41284d9c625SLionel Sambuc { "Edit File...", ma_edit_file, "Alt<Key>e", "Alt+E" },
41384d9c625SLionel Sambuc { "", NULL, NULL, NULL },
41484d9c625SLionel Sambuc { "Split Window...", ma_split, NULL, NULL },
41584d9c625SLionel Sambuc { "", NULL, NULL, NULL },
41684d9c625SLionel Sambuc { "Save ", ma_save, "Alt<Key>s", "Alt+S" },
41784d9c625SLionel Sambuc { "Save As...", ma_save_as, "Shift Alt<Key>s", "Shift+Alt+S" },
41884d9c625SLionel Sambuc { "", NULL, NULL, NULL },
41984d9c625SLionel Sambuc { "Write and Quit", ma_wq, "Shift Alt<Key>q", "Shift+Alt+Q" },
42084d9c625SLionel Sambuc { "Quit", ma_quit, "Alt<Key>q", "Alt+Q" },
42184d9c625SLionel Sambuc { NULL, NULL, NULL, NULL },
42284d9c625SLionel Sambuc };
42384d9c625SLionel Sambuc
42484d9c625SLionel Sambuc static pull_down edit_menu[] = {
42584d9c625SLionel Sambuc { "Undo", ma_undo, NULL, NULL },
42684d9c625SLionel Sambuc { "", NULL, NULL, NULL },
42784d9c625SLionel Sambuc { "Cut", ma_cut, "Alt<Key>x", "Alt+X" },
42884d9c625SLionel Sambuc { "Copy", ma_copy, "Alt<Key>c", "Alt+C" },
42984d9c625SLionel Sambuc { "Paste", ma_paste, "Alt<Key>v", "Alt+V" },
43084d9c625SLionel Sambuc { "", NULL, NULL, NULL },
43184d9c625SLionel Sambuc { "Find", ma_find, "Alt<Key>f", "Alt+F" },
43284d9c625SLionel Sambuc { "Find Next", ma_find_next, "Alt<Key>g", "Alt+G" },
43384d9c625SLionel Sambuc { NULL, NULL, NULL, NULL },
43484d9c625SLionel Sambuc };
43584d9c625SLionel Sambuc
43684d9c625SLionel Sambuc static pull_down options_menu[] = {
43784d9c625SLionel Sambuc { "Preferences", ma_preferences, NULL, NULL },
43884d9c625SLionel Sambuc { "Command Mode Maps", NULL, NULL, NULL },
43984d9c625SLionel Sambuc { "Insert Mode Maps", NULL, NULL, NULL },
44084d9c625SLionel Sambuc { NULL, NULL, NULL, NULL },
44184d9c625SLionel Sambuc };
44284d9c625SLionel Sambuc
44384d9c625SLionel Sambuc static pull_down tag_menu[] = {
44484d9c625SLionel Sambuc { "Show Tag Stack", ma_tags, "Alt<Key>t", "Alt+T" },
44584d9c625SLionel Sambuc { "", NULL, NULL, NULL },
44684d9c625SLionel Sambuc { "Pop Tag", ma_tagpop, NULL, NULL },
44784d9c625SLionel Sambuc { "Clear Stack", ma_tagtop, NULL, NULL },
44884d9c625SLionel Sambuc { NULL, NULL, NULL, NULL },
44984d9c625SLionel Sambuc };
45084d9c625SLionel Sambuc
45184d9c625SLionel Sambuc static pull_down help_menu[] = {
45284d9c625SLionel Sambuc { NULL, NULL, NULL, NULL },
45384d9c625SLionel Sambuc };
45484d9c625SLionel Sambuc
45584d9c625SLionel Sambuc static menu_bar main_menu[] = {
45684d9c625SLionel Sambuc { 'F', "File", file_menu },
45784d9c625SLionel Sambuc { 'E', "Edit", edit_menu },
45884d9c625SLionel Sambuc { 'O', "Options", options_menu },
45984d9c625SLionel Sambuc { 'T', "Tag", tag_menu },
46084d9c625SLionel Sambuc { 'H', "Help", help_menu },
46184d9c625SLionel Sambuc { 0, NULL, NULL },
46284d9c625SLionel Sambuc };
46384d9c625SLionel Sambuc
46484d9c625SLionel Sambuc
46584d9c625SLionel Sambuc #if defined(__STDC__)
add_entries(Widget parent,pull_down * actions)46684d9c625SLionel Sambuc static void add_entries( Widget parent, pull_down *actions )
46784d9c625SLionel Sambuc #else
46884d9c625SLionel Sambuc static void add_entries( parent, actions )
46984d9c625SLionel Sambuc Widget parent;
47084d9c625SLionel Sambuc pull_down *actions;
47184d9c625SLionel Sambuc #endif
47284d9c625SLionel Sambuc {
47384d9c625SLionel Sambuc Widget w;
47484d9c625SLionel Sambuc XmString str;
47584d9c625SLionel Sambuc
47684d9c625SLionel Sambuc for ( ; actions->title != NULL; actions++ ) {
47784d9c625SLionel Sambuc
47884d9c625SLionel Sambuc /* a separator? */
47984d9c625SLionel Sambuc if ( *actions->title != '\0' ) {
48084d9c625SLionel Sambuc w = XmCreatePushButton( parent, actions->title, NULL, 0 );
48184d9c625SLionel Sambuc if ( actions->action == NULL )
48284d9c625SLionel Sambuc XtSetSensitive( w, False );
48384d9c625SLionel Sambuc else
48484d9c625SLionel Sambuc XtAddCallback( w,
48584d9c625SLionel Sambuc XmNactivateCallback,
48684d9c625SLionel Sambuc (XtCallbackProc) actions->action,
48784d9c625SLionel Sambuc actions
48884d9c625SLionel Sambuc );
48984d9c625SLionel Sambuc if ( actions->accel != NULL ) {
49084d9c625SLionel Sambuc str = XmStringCreateSimple( actions->accel_text );
49184d9c625SLionel Sambuc XtVaSetValues( w,
49284d9c625SLionel Sambuc XmNaccelerator, actions->accel,
49384d9c625SLionel Sambuc XmNacceleratorText, str,
49484d9c625SLionel Sambuc 0
49584d9c625SLionel Sambuc );
49684d9c625SLionel Sambuc XmStringFree( str );
49784d9c625SLionel Sambuc }
49884d9c625SLionel Sambuc }
49984d9c625SLionel Sambuc else {
50084d9c625SLionel Sambuc w = XmCreateSeparator( parent, "separator", NULL, 0 );
50184d9c625SLionel Sambuc }
50284d9c625SLionel Sambuc
50384d9c625SLionel Sambuc XtManageChild( w );
50484d9c625SLionel Sambuc
50584d9c625SLionel Sambuc }
50684d9c625SLionel Sambuc }
50784d9c625SLionel Sambuc
50884d9c625SLionel Sambuc /*
50984d9c625SLionel Sambuc * vi_create_menubar --
51084d9c625SLionel Sambuc *
51184d9c625SLionel Sambuc * PUBLIC: Widget vi_create_menubar __P((Widget));
51284d9c625SLionel Sambuc */
51384d9c625SLionel Sambuc Widget
vi_create_menubar(Widget parent)51484d9c625SLionel Sambuc vi_create_menubar(Widget parent)
51584d9c625SLionel Sambuc {
51684d9c625SLionel Sambuc Widget menu, pull, button;
51784d9c625SLionel Sambuc menu_bar *ptr;
51884d9c625SLionel Sambuc
51984d9c625SLionel Sambuc /* save this for creation of children */
52084d9c625SLionel Sambuc main_widget = parent;
52184d9c625SLionel Sambuc
52284d9c625SLionel Sambuc menu = XmCreateMenuBar( parent, "Menu", NULL, 0 );
52384d9c625SLionel Sambuc
52484d9c625SLionel Sambuc for ( ptr=main_menu; ptr->title != NULL; ptr++ ) {
52584d9c625SLionel Sambuc
52684d9c625SLionel Sambuc pull = XmCreatePulldownMenu( menu, "pull", NULL, 0 );
52784d9c625SLionel Sambuc add_entries( pull, ptr->actions );
52884d9c625SLionel Sambuc button = XmCreateCascadeButton( menu, ptr->title, NULL, 0 );
52984d9c625SLionel Sambuc XtVaSetValues( button, XmNsubMenuId, pull, 0 );
53084d9c625SLionel Sambuc
53184d9c625SLionel Sambuc if ( strcmp( ptr->title, "Help" ) == 0 )
53284d9c625SLionel Sambuc XtVaSetValues( menu, XmNmenuHelpWidget, button, 0 );
53384d9c625SLionel Sambuc
53484d9c625SLionel Sambuc #if 0
53584d9c625SLionel Sambuc /* These screw up accelerator processing. Punt for now */
53684d9c625SLionel Sambuc if ( ptr->mnemonic )
53784d9c625SLionel Sambuc XtVaSetValues( button, XmNmnemonic, ptr->mnemonic, 0 );
53884d9c625SLionel Sambuc #endif
53984d9c625SLionel Sambuc
54084d9c625SLionel Sambuc XtManageChild( button );
54184d9c625SLionel Sambuc }
54284d9c625SLionel Sambuc
54384d9c625SLionel Sambuc return menu;
54484d9c625SLionel Sambuc }
545