forked from osmocom/wireshark
Add some utilities to:
set the "activate" signal for a widget to call a routine to activate the "OK" button for a dialog box; set the "key_press_event" signal for a top-level dialog window to call a routine to activate the "Cancel" button for a dialog box if the key being pressed is the <Esc> key; to make it easier to drive dialog boxes entirely from the keyboard. Make the "Find Frame" and "Go To Frame" dialog boxes use those utilities. svn path=/trunk/; revision=1903
This commit is contained in:
parent
f3feac3b1d
commit
ebdbff44e8
|
@ -1,7 +1,7 @@
|
|||
# Makefile.am
|
||||
# Automake file for the GTK interface routines for Ethereal
|
||||
#
|
||||
# $Id: Makefile.am,v 1.25 2000/02/29 06:24:36 guy Exp $
|
||||
# $Id: Makefile.am,v 1.26 2000/05/02 08:04:28 guy Exp $
|
||||
#
|
||||
# Ethereal - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@zing.org>
|
||||
|
@ -39,6 +39,8 @@ libui_a_SOURCES = \
|
|||
column_prefs.h \
|
||||
display_opts.c \
|
||||
display_opts.h \
|
||||
dlg_utils.c \
|
||||
dlg_utils.h \
|
||||
file_dlg.c \
|
||||
file_dlg.h \
|
||||
filter_prefs.c \
|
||||
|
|
|
@ -16,6 +16,7 @@ OBJECTS=capture_dlg.obj \
|
|||
color_dlg.obj \
|
||||
column_prefs.obj \
|
||||
display_opts.obj \
|
||||
dlg_utils.obj \
|
||||
file_dlg.obj \
|
||||
filter_prefs.obj \
|
||||
find_dlg.obj \
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/* dlg_utils.c
|
||||
* Utilities to use when constructing dialogs
|
||||
*
|
||||
* $Id: dlg_utils.c,v 1.1 2000/05/02 08:04:28 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
static void
|
||||
dlg_activate (GtkWidget *widget, gpointer ok_button);
|
||||
|
||||
static gint
|
||||
dlg_key_press (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button);
|
||||
|
||||
/* Set the "activate" signal for a widget to call a routine to
|
||||
activate the "OK" button for a dialog box.
|
||||
|
||||
XXX - there should be a way to specify that a GtkEntry widget
|
||||
shouldn't itself handle the Return key, but should let it be
|
||||
passed on to the parent, so that you don't have to do this
|
||||
by hand for every GtkEntry widget in a dialog box, but, alas,
|
||||
there isn't. (Does this problem exist for other widgets?
|
||||
I.e., are there any others that seize the Return key? */
|
||||
void
|
||||
dlg_set_activate(GtkWidget *widget, GtkWidget *ok_button)
|
||||
{
|
||||
gtk_signal_connect(GTK_OBJECT(widget), "activate",
|
||||
GTK_SIGNAL_FUNC(dlg_activate), ok_button);
|
||||
}
|
||||
|
||||
static void
|
||||
dlg_activate (GtkWidget *widget, gpointer ok_button)
|
||||
{
|
||||
gtk_widget_activate(GTK_WIDGET(ok_button));
|
||||
}
|
||||
|
||||
/* Set the "key_press_event" signal for a top-level dialog window to
|
||||
call a routine to activate the "Cancel" button for a dialog box if
|
||||
the key being pressed is the <Esc> key.
|
||||
|
||||
XXX - there should be a GTK+ widget that'll do that for you, and
|
||||
let you specify a "Cancel" button. It should also not impose
|
||||
a requirement that there be a separator in the dialog box, as
|
||||
the GtkDialog widget does; the visual convention that there's
|
||||
such a separator between the rest of the dialog boxes and buttons
|
||||
such as "OK" and "Cancel" is, for better or worse, not universal
|
||||
(not even in GTK+ - look at the GtkFileSelection dialog!). */
|
||||
void
|
||||
dlg_set_cancel(GtkWidget *widget, GtkWidget *cancel_button)
|
||||
{
|
||||
gtk_signal_connect(GTK_OBJECT(widget), "key_press_event",
|
||||
GTK_SIGNAL_FUNC(dlg_key_press), cancel_button);
|
||||
}
|
||||
|
||||
static gint
|
||||
dlg_key_press (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button)
|
||||
{
|
||||
g_return_val_if_fail (widget != NULL, FALSE);
|
||||
g_return_val_if_fail (event != NULL, FALSE);
|
||||
|
||||
if (event->keyval == GDK_Escape) {
|
||||
gtk_widget_activate(GTK_WIDGET(cancel_button));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/* dlg_utils.h
|
||||
* Declarations of utilities to use when constructing dialogs
|
||||
*
|
||||
* $Id: dlg_utils.h,v 1.1 2000/05/02 08:04:29 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
void dlg_set_activate(GtkWidget *widget, GtkWidget *ok_button);
|
||||
void dlg_set_cancel(GtkWidget *widget, GtkWidget *cancel_button);
|
|
@ -1,7 +1,7 @@
|
|||
/* find_dlg.c
|
||||
* Routines for "find frame" window
|
||||
*
|
||||
* $Id: find_dlg.c,v 1.8 2000/04/01 12:03:41 guy Exp $
|
||||
* $Id: find_dlg.c,v 1.9 2000/05/02 08:04:30 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -46,6 +46,7 @@
|
|||
#include "find_dlg.h"
|
||||
#include "filter_prefs.h"
|
||||
#include "simple_dialog.h"
|
||||
#include "dlg_utils.h"
|
||||
|
||||
/* Capture callback data keys */
|
||||
#define E_FIND_FILT_KEY "find_filter_te"
|
||||
|
@ -152,6 +153,17 @@ find_frame_cb(GtkWidget *w, gpointer d)
|
|||
gtk_object_set_data(GTK_OBJECT(find_frame_w), E_FIND_FILT_KEY, filter_te);
|
||||
gtk_object_set_data(GTK_OBJECT(find_frame_w), E_FIND_BACKWARD_KEY, backward_rb);
|
||||
|
||||
/* Catch the "activate" signal on the frame number text entry, so that
|
||||
if the user types Return there, we act as if the "OK" button
|
||||
had been selected, as happens if Return is typed if some widget
|
||||
that *doesn't* handle the Return key has the input focus. */
|
||||
dlg_set_activate(filter_te, ok_bt);
|
||||
|
||||
/* Catch the "key_press_event" signal in the window, so that we can catch
|
||||
the ESC key being pressed and act as if the "Cancel" button had
|
||||
been selected. */
|
||||
dlg_set_cancel(find_frame_w, cancel_bt);
|
||||
|
||||
/* Give the initial focus to the "Filter" entry box. */
|
||||
gtk_widget_grab_focus(filter_te);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* goto_dlg.c
|
||||
* Routines for "go to frame" window
|
||||
*
|
||||
* $Id: goto_dlg.c,v 1.5 2000/03/15 08:54:24 guy Exp $
|
||||
* $Id: goto_dlg.c,v 1.6 2000/05/02 08:04:31 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -47,6 +47,7 @@
|
|||
#include "goto_dlg.h"
|
||||
#include "prefs_dlg.h"
|
||||
#include "simple_dialog.h"
|
||||
#include "dlg_utils.h"
|
||||
|
||||
/* Capture callback data keys */
|
||||
#define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
|
||||
|
@ -110,6 +111,17 @@ goto_frame_cb(GtkWidget *w, gpointer d)
|
|||
/* Attach pointers to needed widgets to the capture prefs window/object */
|
||||
gtk_object_set_data(GTK_OBJECT(goto_frame_w), E_GOTO_FNUMBER_KEY, fnumber_te);
|
||||
|
||||
/* Catch the "activate" signal on the frame number text entry, so that
|
||||
if the user types Return there, we act as if the "OK" button
|
||||
had been selected, as happens if Return is typed if some widget
|
||||
that *doesn't* handle the Return key has the input focus. */
|
||||
dlg_set_activate(fnumber_te, ok_bt);
|
||||
|
||||
/* Catch the "key_press_event" signal in the window, so that we can catch
|
||||
the ESC key being pressed and act as if the "Cancel" button had
|
||||
been selected. */
|
||||
dlg_set_cancel(goto_frame_w, cancel_bt);
|
||||
|
||||
/* Give the initial focus to the "Frame number" entry box. */
|
||||
gtk_widget_grab_focus(fnumber_te);
|
||||
|
||||
|
|
Loading…
Reference in New Issue