⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.c

📁 This source code has been tested under OpenWindows 2.0, Sun s X11/NeWS server. For Xlib programs th
💻 C
字号:
/*************************************************************************                                                                    ****  menu.c                                                            ****                                                                    ****  Text Editor -- Menubar Module                                     ****                                                                    *************************************************************************/#include <string.h>#include <Xm/RowColumn.h>#include <Xm/CascadeB.h>#include <Xm/Label.h>#include <Xm/PushB.h>#include <Xm/Separator.h>#include "textedit.h"/*************************************************************************                                                                    ****               F O R W A R D   D E F I N I T I O N S                ****                                                                    *************************************************************************/static	void	InitFileMenu();static	void	InitEditMenu();static	void	InitViewMenu();static	void	InitOptionMenu();static	void	InitHelpMenu();void	FileMenuCB();void	EditMenuCB();/*************************************************************************                                                                    ****                    L O C A L   V A R I A B L E S                   ****                                                                    *************************************************************************//*************************************************************************                                                                    ****  InitMenuBar()                                                     ****                                                                    ****  This function creates the menu bar and all pulldown menus. The    ****  menu bar is created as the child of the main window.              ****                                                                    ****  This function modifies the global "menubar", and accesses the     ****  global "mainwin".                                                 ****                                                                    *************************************************************************/void InitMenuBar(){    menubar = XmCreateMenuBar( mainwin, "MenuBar", NULL, 0 );    XtManageChild( menubar );    InitFileMenu();    InitEditMenu();    InitViewMenu();    InitOptionMenu();    InitHelpMenu();}/*************************************************************************                                                                    ****  InitFileMenu()                                                    ****                                                                    ****  Creates the File menu: cascade button, pull-down menu pane, and   ****  all menu-pane choices. Attaches callbacks to menu-pane choices.   ****                                                                    *************************************************************************/static void InitFileMenu(){    Widget	topic,		pane,		choices[6];    pane = XmCreatePulldownMenu( menubar, "FilePane", NULL, 0 );    choices[0] = XmCreatePushButton( pane, "File_New", NULL, 0 );    choices[1] = XmCreatePushButton( pane, "File_Open", NULL, 0 );    choices[2] = XmCreatePushButton( pane, "File_Save", NULL, 0 );    choices[3] = XmCreatePushButton( pane, "File_SaveAs", NULL, 0 );    choices[4] = XmCreateSeparator(  pane, "File_Sep1", NULL, 0 );    choices[5] = XmCreatePushButton( pane, "File_Exit", NULL, 0 );    XtManageChildren( choices, 6 );    XtSetArg( arglist[0], XmNsubMenuId, pane );    topic = XmCreateCascadeButton( menubar, "FileTopic", arglist, 1 );    XtManageChild( topic );    XtAddCallback( choices[0], XmNactivateCallback, FileMenuCB, "New" );    XtAddCallback( choices[1], XmNactivateCallback, FileMenuCB, "Opn" );    XtAddCallback( choices[2], XmNactivateCallback, FileMenuCB, "Sav" );    XtAddCallback( choices[3], XmNactivateCallback, FileMenuCB, "SAs" );    XtAddCallback( choices[5], XmNactivateCallback, FileMenuCB, "Ext" );}/*************************************************************************                                                                    ****  InitEditMenu()                                                    ****                                                                    ****  Creates the Edit menu: cascade button, pull-down menu pane, and   ****  all menu-pane choices. Attaches callbacks to menu-pane choices.   ****                                                                    *************************************************************************/static void InitEditMenu(){    Widget	topic,		pane,		choices[7];    pane = XmCreatePulldownMenu( menubar, "Edit_Pane", NULL, 0 );    choices[0] = XmCreatePushButton( pane, "Edit_Cut", NULL, 0 );    choices[1] = XmCreatePushButton( pane, "Edit_Copy", NULL, 0 );    choices[2] = XmCreatePushButton( pane, "Edit_Paste", NULL, 0 );    choices[3] = XmCreatePushButton( pane, "Edit_Delete", NULL, 0 );    choices[4] = XmCreateSeparator(  pane, "Edit_Sep1", NULL, 0 );    choices[5] = XmCreatePushButton( pane, "Edit_Find", NULL, 0 );    choices[6] = XmCreatePushButton( pane, "Edit_Repl", NULL, 0 );    XtManageChildren( choices, 7 );    XtSetArg( arglist[0], XmNsubMenuId, pane );    topic = XmCreateCascadeButton( menubar, "EditTopic", arglist, 1 );    XtManageChild( topic );    XtAddCallback( choices[0], XmNactivateCallback, EditMenuCB, "Cut" );    XtAddCallback( choices[1], XmNactivateCallback, EditMenuCB, "Cpy" );    XtAddCallback( choices[2], XmNactivateCallback, EditMenuCB, "Pst" );    XtAddCallback( choices[3], XmNactivateCallback, EditMenuCB, "Del" );    XtAddCallback( choices[5], XmNactivateCallback, EditMenuCB, "Fnd" );    XtAddCallback( choices[6], XmNactivateCallback, EditMenuCB, "Rpl" );    XtSetSensitive( choices[3], FALSE );    XtSetSensitive( choices[6], FALSE );}/*************************************************************************                                                                    ****  InitViewMenu()                                                    ****                                                                    ****  Creates the View menu: cascade button, pull-down menu pane, and   ****  all menu-pane choices. Attaches callbacks to menu-pane choices.   ****                                                                    *************************************************************************/static void InitViewMenu(){    Widget	topic,		pane,		choices[4];    pane = XmCreatePulldownMenu( menubar, "View_Pane", NULL, 0 );    choices[0] = XmCreatePushButton( pane, "View_Top", NULL, 0 );    choices[1] = XmCreatePushButton( pane, "View_Bot", NULL, 0 );    choices[2] = XmCreateSeparator(  pane, "View_Sep1", NULL, 0 );    choices[3] = XmCreatePushButton( pane, "View_Page", NULL, 0 );    XtManageChildren( choices, 4 );    XtSetArg( arglist[0], XmNsubMenuId, pane );    topic = XmCreateCascadeButton( menubar, "ViewTopic", arglist, 1 );    XtManageChild( topic );}/*************************************************************************                                                                    ****  InitOptionMenu()                                                  ****                                                                    ****  Creates the Option menu: cascade button, pull-down menu pane, and ****  all menu-pane choices. Attaches callbacks to menu-pane choices.   ****                                                                    *************************************************************************/static void InitOptionMenu(){    Widget	topic,		pane,		choices[1];    pane = XmCreatePulldownMenu( menubar, "Option_Pane", NULL, 0 );    choices[0] = XmCreatePushButton( pane, "Option_Font", NULL, 0 );    XtManageChildren( choices, 1 );    XtSetArg( arglist[0], XmNsubMenuId, pane );    topic = XmCreateCascadeButton( menubar, "OptionTopic", arglist, 1 );    XtManageChild( topic );}/*************************************************************************                                                                    ****  InitHelpMenu()                                                    ****                                                                    ****  Creates the Help menu: cascade button, pull-down menu pane, and   ****  all menu-pane choices. Attaches callbacks to menu-pane choices.   ****                                                                    *************************************************************************/static void InitHelpMenu(){    Widget	topic,		pane,		choices[1];    pane = XmCreatePulldownMenu( menubar, "Help_Pane", NULL, 0 );    choices[0] = XmCreateLabel( pane, "Help_Lbl", NULL, 0 );    XtManageChildren( choices, 1 );    XtSetArg( arglist[0], XmNsubMenuId, pane );    topic = XmCreateCascadeButton( menubar, "HelpTopic", arglist, 1 );    XtManageChild( topic );    XtSetArg( arglist[0], XmNmenuHelpWidget, topic );    XtSetValues( menubar, arglist, 1 );}/*************************************************************************                                                                    ****  FileMenuCB( w, client_data, call_data )                           ****                                                                    ****  Callback procedure for the "File" pull-down. This function is     ****  called when any of the file menu buttons are activated. The       ****  particular operation is identified by a string accessed by the    ****  "client_data" param.                                              ****                                                                    ****  Note: This callback is only invoked on Activate, so the call      ****        data (which describes the reason) is superfluous. It is     ****        therefore not declared as a specific type in the func hdr.  ****                                                                    *************************************************************************/static void FileMenuCB( w, client_data, call_data )    Widget	w;    char	*client_data;    caddr_t	call_data;{    if (!strcmp(client_data, "New"))	FileNew();    else if (!strcmp(client_data, "Opn"))	FileOpen();    else if (!strcmp(client_data, "Sav"))	FileSave();    else if (!strcmp(client_data, "SAs"))	FileSaveAs();    else if (!strcmp(client_data, "Ext"))        {        exit( 0 );        }}/*************************************************************************                                                                    ****  EditMenuCB( w, client_data, call_data )                           ****                                                                    ****  Callback procedure for the "Edit" pull-down. This function is     ****  called when any of the menu buttons are activated. The choice     ****  is identified by a string pointed-to by the "client_data" parm.   ****  "client_data" param.                                              ****                                                                    ****  Note: This callback is only invoked on Activate, so the call      ****        data (which describes the reason) is superfluous. It is     ****        therefore not declared as a specific type in the func hdr.  ****                                                                    *************************************************************************/static void EditMenuCB( w, client_data, call_data )    Widget		w;    char		*client_data;    XmAnyCallbackStruct	*call_data;{    XButtonEvent	*event = (XButtonEvent *)call_data->event;    if (!strcmp(client_data, "Cut"))	ClipCut( event->time );    else if (!strcmp(client_data, "Cpy"))	ClipCopy( event->time );    else if (!strcmp(client_data, "Pst"))	ClipPaste( event->time );    else if (!strcmp(client_data, "Del"))        {        }    else if (!strcmp(client_data, "Fnd"))        {	ManageFindDB();        }    else if (!strcmp(client_data, "Rpl"))        {        }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -