summaryrefslogtreecommitdiffstats
path: root/g2/menu1.c
blob: fce81fa66b2106c6bdd86780d0be0f7d29738d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <fcntl.h>
#include <vppinfra/clib.h>
#include <vppinfra/format.h>
#include <vppinfra/cpu.h>

#define foreach_x86_cpu_uarch \
 _(0x06, 0x9e, "Kaby Lake", "Kaby Lake DT/H/S/X") \
 _(0x06, 0x8e, "Kaby Lake", "Kaby Lake Y/U") \
 _(0x06, 0x8c, "Tiger Lake", "Tiger Lake U") \
 _(0x06, 0x86, "Tremont", "Elkhart Lake") \
 _(0x06, 0x85, "Knights Mill", "Knights Mill") \
 _(0x06, 0x7e, "Ice Lake", "Ice Lake U") \
 _(0x06, 0x7d, "Ice Lake", "Ice Lake Y") \
 _(0x06, 0x7a, "Goldmont Plus", "Gemini Lake") \
 _(0x06, 0x6c, "I
/* 
 *------------------------------------------------------------------
 * Copyright (c) 2006-2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <gtk/gtk.h>
#define GTK_ENABLE_BROKEN // DGMS
#include <gtk/gtktext.h>
#include <stdlib.h>
#include "g2.h"
#include <string.h>

/*
 * locals
 */
static GtkWidget *s_mainmenubar;
static GtkWidget *s_filemenu;
static GtkWidget *s_readdefs;
static GtkWidget *s_readevents;
static GtkWidget *s_readeventsclock;
static GtkWidget *s_readcpel;
static GtkWidget *s_readclib;
static GtkWidget *s_print;
static GtkWidget *s_quit;

static GtkWidget *s_mainfilemenu;
static GtkWidget *s_help_general;
static GtkWidget *s_help_about;
static GtkWidget *s_mainhelpmenu;
static GtkWidget *s_helpmenu;

static GtkWidget *s_filesel;
static GtkWidget *s_eventsel;

typedef struct md_ {
    GtkWidget *entry;
    GtkWidget *label;
    GtkWidget *dialog;
    boolean (*callback)(char *);
    char *retry_text;
} md_t;

char *general_help = "\n"
"G2 is a performance event visualization tool.\n"
"\n"
"To view CPEL-format event data:\n"
"g2 --cpel <filename>\n"
"or use the File Menu->Read CPEL file option.\n"
"\n"
"To view vppinfra-format (.../open-repo/vppinfra/vppinfra/elog.h) event data:\n"
"g2 --clib <filename>\n"
"or use the File Menu->Read clib file option.\n"
"\n"
"To toggle event detail boxes, left-mouse-click on an event.\n"
"\n"
"To zoom to an area, depress the left mouse button. Move the\n"
"mouse. Release the mouse.\n"
"\n"
"To use the time ruler, depress the right mouse button.  Move the\n"
"mouse. Release when done.\n"
"\n"
"To push a track to the bottom, <ctrl><left-mouse>\n"
"\n"
"To pull a track to the top, <shift><left-mouse>\n"
"\n"
"To selectively color/uncolor a track, <ctrl><shift><left-mouse>\n"
"\n"
"To make the mouse scrollwheel faster, press <shift>\n"
"\n"
"Hotkeys, supposedly Quake-like:\n"
"      w - zoom-in\n"
"      s - zoom-out\n"
"      a - pan-left\n"
"      d - pan-right\n"
"      r - pan-up\n"
"      f - pan-down\n"
"      t - less traces\n"
"      g - more traces\n"
"\n"
"      e - toggle summary-mode\n"
"      c - toggle color-mode\n"
"\n"
"      x - take snapshot\n"
"      z - go to next snapshot\n"
"      p - put snapshots to snapshots.g2 \n"
"      l - load snapshots from snapshots.g2\n"
"\n"
"<ctrl>q - quit\n"
"Send comments / bug reports to the \"fd.io\" mailing list.\n";

/****************************************************************************
* debug_dialog_callback
****************************************************************************/

boolean debug_dialog_callback (char *s)
{
    g_print("Dialog result: %s", s);
    return (TRUE);
}

/****************************************************************************
* get_dialog_value
****************************************************************************/

static void get_dialog_value (GtkWidget *dialog, gpointer user_data)
{
    md_t *md = (md_t *)user_data;
    char * cb_arg;
    
    cb_arg = (char *) gtk_entry_get_text(GTK_ENTRY(md->entry));

    if ((*md->callback)(cb_arg)) {
	gtk_grab_remove(md->dialog);
	gtk_widget_destroy(md->dialog);
    } else {
	gtk_label_set_text (GTK_LABEL(md->label), md->retry_text);
    }
}

/****************************************************************************
* modal_dialog
****************************************************************************/

void modal_dialog (char *label_text, char *retry_text, char *default_value, 
                   boolean (*cb)(char *))
{
    GtkWidget *dialog, *label, *ok_button, *entry;
    static md_t dlg;
    md_t *md = &dlg;

    dialog = gtk_dialog_new();
    label = gtk_label_new(label_text);

    entry = gtk_entry_new();
    if (default_value)
        gtk_entry_set_text(GTK_ENTRY(entry), default_value);

    ok_button = gtk_button_new_with_label("OK");

    md->entry = entry;
    md->label = label;
    md->retry_text = retry_text;
    md->dialog = dialog;
    if (cb)
	md->callback = cb;
    else
	md->callback = debug_dialog_callback;

    gtk_signal_connect (GTK_OBJECT (ok_button), "clicked", 
                        GTK_SIGNAL_FUNC(get_dialog_value), (gpointer) md);

    gtk_signal_connect (GTK_OBJECT (entry), "activate", 
                        GTK_SIGNAL_FUNC(get_dialog_value), (gpointer) md);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      entry);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      ok_button);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
    gtk_widget_show_all(dialog);
    gtk_widget_grab_focus(entry);
    gtk_grab_add(dialog);
}

/****************************************************************************
* get_eventdef_name
****************************************************************************/

static void get_eventdef_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_event_definitions(filename);
    set_window_title(filename);
}

/****************************************************************************
* read_eventdef_callback
****************************************************************************/

static void read_eventdef_callback(GtkToggleButton *item, gpointer data)
{
    
    s_filesel = gtk_file_selection_new("Read Event Definitions From...");
    
    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel), 
				    "../h/elog.h");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked", 
                        GTK_SIGNAL_FUNC(get_eventdef_name), NULL);
                            
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* get_events_name
****************************************************************************/

static void get_events_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_eventsel));
    read_events(filename);
    view1_display_when_idle();
}


/****************************************************************************
* get_ticks_per_ns
****************************************************************************/

static boolean get_ticks_per_ns (char *value)
{
    double rv;

    rv = atof (value);

    if (rv == 0.0 || rv > 100000)
	return(FALSE);

    ticks_per_ns = rv;
    ticks_per_ns_set = TRUE;

    gtk_widget_show(s_eventsel);
    return(TRUE);
}

/****************************************************************************
* read_events_callback
****************************************************************************/

static void read_events_callback(GtkToggleButton *item, gpointer data)
{
    char tmpbuf [32];

    s_eventsel = gtk_file_selection_new("Read Events From...");
    
    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->ok_button),
                        "clicked", 
                        GTK_SIGNAL_FUNC(get_events_name), NULL);
                            
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->ok_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_eventsel);
    
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_eventsel)->cancel_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_eventsel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_eventsel));

    if (ticks_per_ns_set)
	gtk_widget_show (s_eventsel);
    else {
	sprintf(tmpbuf, "%.3f", ticks_per_ns);
	modal_dialog ("Please enter clock ticks per nanosecond",
		      "Invalid: Please enter clock ticks per nanosecond",
		      tmpbuf, get_ticks_per_ns);
    }
}

/****************************************************************************
* read_eventclock_callback
****************************************************************************/

static void read_eventsclock_callback(GtkToggleButton *item, gpointer data)
{
    ticks_per_ns_set = FALSE;
    read_events_callback(item, data);
}

/****************************************************************************
* infobox_size_request
****************************************************************************/

void infobox_size_request (GtkWidget *widget, GtkRequisition *req,
                           gpointer user_data)
{
    char *text = (char *)user_data;
    char *cp;
    int widest_line_in_chars;
    int w;
    int nlines;
    
    /*
     * You'd think that the string extent function would work here.
     * You'd be wrong. 
     */
    nlines = w = widest_line_in_chars = 0;
    for (cp = text; *cp; cp++) {
        if (*cp == '\n') {
            if (w > widest_line_in_chars) {
                widest_line_in_chars = w;
            }
            w = 0;
            nlines++;
        }
        w++;
    }

    nlines++;

    req->width = (widest_line_in_chars * 8) + 20;
    req->height = (nlines * 13) + 10;
}

/****************************************************************************
* infobox
****************************************************************************/

void infobox(char *label_text, char *text)
{
    GtkWidget *dialog, *label, *ok_button, *entry;
    GtkWidget *box;

    dialog = gtk_dialog_new();
    label = gtk_label_new(label_text);

    entry = gtk_text_new(NULL, NULL);

    gtk_signal_connect (GTK_OBJECT (entry), "size-request", 
                        GTK_SIGNAL_FUNC(infobox_size_request), 
                        (gpointer) text);

    gtk_text_insert(GTK_TEXT(entry), g_font, &fg_black, &bg_white,
                    text, -1);

    gtk_text_set_editable(GTK_TEXT(entry), FALSE);

    ok_button = gtk_button_new_with_label("OK");

    gtk_signal_connect_object (GTK_OBJECT (ok_button), "clicked", 
                               GTK_SIGNAL_FUNC(gtk_widget_destroy), 
                               (gpointer) GTK_OBJECT(dialog));

    box = gtk_vbox_new(FALSE, 5);


    gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(box), ok_button, FALSE, FALSE, 0);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
		      box);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
    gtk_widget_show_all(dialog);
}

/****************************************************************************
* help_general_callback
****************************************************************************/

static void help_general_callback(GtkToggleButton *item, gpointer data)
{
    infobox("General Help", general_help);
}

/****************************************************************************
* help_about_callback
****************************************************************************/

static void help_about_callback(GtkToggleButton *item, gpointer data)
{
    char tmpbuf [1024];
    sprintf (tmpbuf, "G2 -- Graphical Event Viewer\n\n");
    view1_about(tmpbuf);
    pointsel_about(tmpbuf);
    events_about(tmpbuf);
    sprintf (tmpbuf+strlen(tmpbuf), "\n%s\n", version_string);
    sprintf (tmpbuf+strlen(tmpbuf), "%s\n", minor_v_string);
    infobox("About", tmpbuf);
}


/****************************************************************************
* get_cpel_name
****************************************************************************/

static void get_cpel_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *)gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_cpel_file(filename);
    set_window_title(filename);
}

/****************************************************************************
* get_clib_name
****************************************************************************/

static void get_clib_name (GtkFileSelection *sel, gpointer user_data)
{
    char *filename = (char *) gtk_file_selection_get_filename (
        GTK_FILE_SELECTION(s_filesel));
    read_clib_file(filename);
    set_window_title(filename);
}

/****************************************************************************
* read_cpel_callback
****************************************************************************/

static void read_cpel_callback(GtkToggleButton *item, gpointer data)
{
    
    s_filesel = gtk_file_selection_new("Read CPEL data from...");
    
    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel), 
				    "cpel.out");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked", 
                        GTK_SIGNAL_FUNC(get_cpel_name), NULL);
                            
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* read_clib_callback
****************************************************************************/

static void read_clib_callback(GtkToggleButton *item, gpointer data)
{
    
    s_filesel = gtk_file_selection_new("Read clib data From...");
    
    gtk_file_selection_set_filename(GTK_FILE_SELECTION(s_filesel), 
				    "clib.out");

    gtk_signal_connect (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                        "clicked", 
                        GTK_SIGNAL_FUNC(get_clib_name), NULL);
                            
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->ok_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    
    gtk_signal_connect_object (GTK_OBJECT (
        GTK_FILE_SELECTION(s_filesel)->cancel_button),
                               "clicked", 
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               (gpointer) s_filesel);
    gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(s_filesel));
    gtk_widget_show (s_filesel);
}

/****************************************************************************
* menu1_init
****************************************************************************/

void menu1_init(void)
{

    s_filemenu = gtk_menu_new();

    s_readcpel = gtk_menu_item_new_with_label 
	("Read CPEL file");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readcpel);
    gtk_signal_connect(GTK_OBJECT(s_readcpel), "activate", 
                       GTK_SIGNAL_FUNC(read_cpel_callback), 0);

    s_readclib = gtk_menu_item_new_with_label 
	("Read CLIB file");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readclib);
    gtk_signal_connect(GTK_OBJECT(s_readclib), "activate", 
                       GTK_SIGNAL_FUNC(read_clib_callback), 0);
    
    s_readdefs = gtk_menu_item_new_with_label ("Read Event Definitions");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readdefs);
    gtk_signal_connect(GTK_OBJECT(s_readdefs), "activate", 
                       GTK_SIGNAL_FUNC(read_eventdef_callback), 0);
    
    s_readevents = gtk_menu_item_new_with_label ("Read Event Log");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readevents);
    gtk_signal_connect(GTK_OBJECT(s_readevents), "activate", 
                       GTK_SIGNAL_FUNC(read_events_callback), 0);
    
    s_readeventsclock = gtk_menu_item_new_with_label 
	("Read Event Log with Different Clock Rate");
    gtk_menu_append(GTK_MENU(s_filemenu), s_readeventsclock);
    gtk_signal_connect(GTK_OBJECT(s_readeventsclock), "activate", 
                       GTK_SIGNAL_FUNC(read_eventsclock_callback), 0);

    s_print = gtk_menu_item_new_with_label ("Print");
    gtk_menu_append(GTK_MENU(s_filemenu), s_print);
    gtk_signal_connect(GTK_OBJECT(s_print), "activate", 
                       GTK_SIGNAL_FUNC(view1_print_callback), 0);
    
    s_quit = gtk_menu_item_new_with_label ("Exit");
    gtk_menu_append(GTK_MENU(s_filemenu), s_quit);
    gtk_signal_connect(GTK_OBJECT(s_quit), "activate", 
                       GTK_SIGNAL_FUNC(gtk_main_quit), 0);

    s_mainfilemenu = gtk_menu_item_new_with_label("File");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s_mainfilemenu), s_filemenu);

    s_helpmenu = gtk_menu_new();

    s_help_general = gtk_menu_item_new_with_label ("General");
    gtk_menu_append(GTK_MENU(s_helpmenu), s_help_general);
    gtk_signal_connect(GTK_OBJECT(s_help_general), "activate", 
                       GTK_SIGNAL_FUNC(help_general_callback), 0);

    s_help_about = gtk_menu_item_new_with_label ("About");
    gtk_menu_append(GTK_MENU(s_helpmenu), s_help_about);
    gtk_signal_connect(GTK_OBJECT(s_help_about), "activate", 
                       GTK_SIGNAL_FUNC(help_about_callback), 0);

    s_mainhelpmenu = gtk_menu_item_new_with_label("Help");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(s_mainhelpmenu), s_helpmenu);

    s_mainmenubar = gtk_menu_bar_new();
    gtk_menu_bar_append(GTK_MENU_BAR(s_mainmenubar), s_mainfilemenu);
    gtk_menu_bar_append(GTK_MENU_BAR(s_mainmenubar), s_mainhelpmenu);
    gtk_widget_show_all(s_mainmenubar);

    gtk_box_pack_start(GTK_BOX(g_mainvbox), s_mainmenubar, FALSE, FALSE, 0);
}