1 /* $XConsortium: interface.c /main/4 1995/07/15 20:40:00 drk $ */
2 /*
3  * Motif
4  *
5  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6  *
7  * These libraries and programs are free software; you can
8  * redistribute them and/or modify them under the terms of the GNU
9  * Lesser General Public License as published by the Free Software
10  * Foundation; either version 2 of the License, or (at your option)
11  * any later version.
12  *
13  * These libraries and programs are distributed in the hope that
14  * they will be useful, but WITHOUT ANY WARRANTY; without even the
15  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU Lesser General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with these librararies and programs; if not, write
21  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22  * Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 /*
26  * HISTORY
27  */
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <Xm/XmAll.h>
31 
32 void CreateMenus(Widget);
33 void HelpCB(Widget, XtPointer, XtPointer);
34 void QuitCB(Widget, XtPointer, XtPointer);
35 extern Widget top_level;
36 
37 /**************************************************************************
38 CreateMenus: This function generates the menu bar and the submenus.
39 **************************************************************************/
40 void
CreateMenus(Widget parent_of_menu_bar)41 CreateMenus(Widget parent_of_menu_bar)
42 {
43  XmString   file, help;
44  Widget     menubar, FilePullDown, HelpPullDown;
45  Widget     overview, quit, Help1;
46 
47  /* Create the menubar itself. */
48    file = XmStringCreateSimple("File");
49    help = XmStringCreateSimple("Help");
50 
51    menubar      = (Widget)XmCreateMenuBar(parent_of_menu_bar, "menubar",
52                                           NULL, 0);
53    FilePullDown = (Widget)XmCreatePulldownMenu(menubar, "FilePullDown",
54                                                NULL, 0);
55    HelpPullDown = (Widget)XmCreatePulldownMenu(menubar, "HelpPullDown",
56                                                  NULL, 0);
57 
58  /******************************FILE*********************************/
59     XtVaCreateManagedWidget("File", xmCascadeButtonWidgetClass, menubar,
60                              XmNlabelString, file,
61                              XmNmnemonic, 'F',
62                              XmNsubMenuId, FilePullDown,
63                              NULL);
64     quit = XtVaCreateManagedWidget("Quit", xmPushButtonGadgetClass,
65                                     FilePullDown, NULL);
66     XtAddCallback(quit, XmNactivateCallback, QuitCB, NULL);
67 
68 
69  /******************************HELP*********************************/
70     Help1 = XtVaCreateManagedWidget("Help", xmCascadeButtonWidgetClass,
71                              menubar,
72                              XmNlabelString, help,
73                              XmNmnemonic, 'H',
74                              XmNsubMenuId, HelpPullDown,
75                              NULL);
76     XtVaSetValues(menubar, XmNmenuHelpWidget, Help1, NULL);
77     overview = XtVaCreateManagedWidget("Overview", xmPushButtonGadgetClass,
78                                     HelpPullDown, NULL);
79     XtAddCallback(overview, XmNactivateCallback, HelpCB, (XtPointer)1);
80 
81     XmStringFree(file);
82     XmStringFree(help);
83 
84     XtManageChild(menubar);
85 }
86 
87 
88 
89 /*********************************************************************
90 HelpCB: This function is called when the user requests help.  This
91         function displays a Message DialogBox.
92 *********************************************************************/
93 void
HelpCB(Widget w,XtPointer cd,XtPointer cb)94 HelpCB(Widget   w,
95        XtPointer cd,
96        XtPointer cb
97       )
98 {
99  int       what_kind_of_help = (int)cd;
100  char      help_string[400];
101  XmString  hs_as_cs;
102  Widget    dialog_general_help;
103  Arg       arg[3];
104 
105  sprintf(help_string,
106 "This program demonstrates how to use an XmNotebook in an application.\n\
107 You can turn the pages of the notebook by \n\
108   * clicking on the page scroller arrows \n\
109   * clicking on one of the major tab buttons (fruits or vegetables) \n\
110   * clicking on one of the minor tab buttons (green or orange) \n\
111 A status area appears when the current page number is 2.");
112 
113    hs_as_cs = XmStringCreateLtoR(help_string,
114                                  XmFONTLIST_DEFAULT_TAG);
115 
116    XtSetArg(arg[0], XmNmessageString, hs_as_cs);
117    dialog_general_help = (Widget)XmCreateMessageDialog(top_level,
118                                              "message", arg, 1);
119    XmStringFree(hs_as_cs);
120 
121    switch (what_kind_of_help)  {
122      case 1: XtManageChild(dialog_general_help);
123              break;
124      default: /* no other help */
125              break;
126    }
127 
128 }
129 
130 
131 
132 /*******************************************************************************
133 QuitCB: Exit
134 *******************************************************************************/
135 void
QuitCB(Widget w,XtPointer cd,XtPointer cb)136 QuitCB(Widget w, XtPointer cd, XtPointer cb)
137 {
138   exit(1);
139 }
140