2005-08-20 19:49:22 +00:00
|
|
|
/* gui_utils.c
|
|
|
|
* UI utility routines, some GTK+-specific (declared in gtk/gui_utils.h)
|
|
|
|
* and some with GUI-independent APIs, with this file containing the GTK+
|
|
|
|
* implementations of them (declared in ui_util.h)
|
2005-08-20 14:02:00 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-08-20 14:02:00 +00:00
|
|
|
* 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 <string.h>
|
2009-03-06 17:16:56 +00:00
|
|
|
#include <locale.h>
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include "epan/epan.h"
|
2008-04-13 01:54:20 +00:00
|
|
|
|
2009-07-31 07:02:02 +00:00
|
|
|
#include <epan/packet_info.h>
|
2005-08-20 14:02:00 +00:00
|
|
|
#include "../ui_util.h"
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2008-04-13 01:54:20 +00:00
|
|
|
#include "gtk/gtkglobals.h"
|
|
|
|
#include "gtk/gui_utils.h"
|
2009-12-01 21:24:48 +00:00
|
|
|
#include "gtk/font_utils.h"
|
2008-04-13 01:54:20 +00:00
|
|
|
#include "gtk/recent.h"
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2006-06-02 05:43:38 +00:00
|
|
|
#include "image/wsicon16.xpm"
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-08-07 14:37:37 +00:00
|
|
|
#include "../version_info.h"
|
|
|
|
|
2008-10-24 00:42:09 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
#define WINDOW_GEOM_KEY "window_geom"
|
|
|
|
|
|
|
|
|
|
|
|
/* load the geometry values for a window from previously saved values */
|
|
|
|
static gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set our window icon. The GDK documentation doesn't provide any
|
|
|
|
actual documentation for gdk_window_set_icon(), so we'll steal
|
|
|
|
libgimp/gimpdialog.c:gimp_dialog_realize_callback() from the Gimp
|
|
|
|
sources and assume it's safe.
|
|
|
|
|
|
|
|
XXX - The current icon size is fixed at 16x16 pixels, which looks fine
|
|
|
|
with kwm (KDE 1.x's window manager), Sawfish (the "default" window
|
|
|
|
manager for GNOME?), and under Windows with Exceed putting X windows
|
|
|
|
on the Windows desktop, using Exceed as the window manager, as those
|
|
|
|
window managers put a 16x16 icon on the title bar.
|
|
|
|
|
|
|
|
The window managers in some windowing environments (e.g. dtwm in CDE)
|
|
|
|
and some stand-alone window managers have larger icon sizes (many window
|
|
|
|
managers put the window icon on the desktop, in the Windows 3.x style,
|
|
|
|
rather than in the titlebar, in the Windows 4.x style), so we need to
|
|
|
|
find a way to size our icon appropriately.
|
|
|
|
|
|
|
|
The X11 Inter-Client Communications Conventions Manual, Version 1.1,
|
|
|
|
in X11R5, specifies that "a window manager that wishes to place
|
|
|
|
constraints on the sizes of icon pixmaps and/or windows should
|
|
|
|
place a property called WM_ICON_SIZE on the root"; that property
|
|
|
|
contains minimum width and height, maximum width and height, and
|
|
|
|
width and height increment values. "XGetIconSizes()" retrieves
|
|
|
|
that property; unfortunately, I've yet to find a window manager
|
|
|
|
that sets it on the root window (kwm, AfterStep, and Exceed don't
|
|
|
|
appear to set it).
|
|
|
|
|
|
|
|
The X Desktop Group's Window Manager Standard specifies, in the section
|
|
|
|
on Application Window Properties, an _NET_WM_ICON property, presumably
|
|
|
|
set by the window manager, which is an array of possible icon sizes
|
|
|
|
for the client. There's no API in GTK+ 1.2[.x] for this; there may
|
|
|
|
eventually be one either in GTK+ 2.0 or GNOME 2.0.
|
|
|
|
|
|
|
|
Some window managers can be configured to take the window name
|
|
|
|
specified by the WM_NAME property of a window or the resource
|
|
|
|
or class name specified by the WM_CLASS property and base the
|
|
|
|
choice of icon for the window on one of those; WM_CLASS for
|
2006-06-06 23:11:31 +00:00
|
|
|
Wireshark's windows has a resource name of "wireshark" and a class
|
2006-05-31 19:12:15 +00:00
|
|
|
name of "Wireshark". However, the way that's done is window-manager-
|
2005-08-20 14:02:00 +00:00
|
|
|
specific, and there's no way to determine what size a particular
|
|
|
|
window manager would want, so there's no way to automate this as
|
2006-05-22 07:29:40 +00:00
|
|
|
part of the installation of Wireshark.
|
2005-08-20 14:02:00 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
window_icon_realize_cb (GtkWidget *win, gpointer data _U_)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
2010-07-28 13:34:41 +00:00
|
|
|
static GdkPixmap *icon_pmap = NULL;
|
|
|
|
static GdkBitmap *icon_mask = NULL;
|
|
|
|
GtkStyle *style;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
style = gtk_widget_get_style (win);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
if (icon_pmap == NULL) {
|
|
|
|
icon_pmap = gdk_pixmap_create_from_xpm_d (win->window,
|
|
|
|
&icon_mask, &style->bg[GTK_STATE_NORMAL],
|
|
|
|
(gchar **) wsicon16_xpm);
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gdk_window_set_icon (win->window, NULL, icon_pmap, icon_mask);
|
2005-08-20 14:02:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new window, of the specified type, with the specified title
|
2006-05-22 07:29:40 +00:00
|
|
|
(if any) and the Wireshark icon. */
|
2005-08-20 14:02:00 +00:00
|
|
|
GtkWidget *
|
|
|
|
window_new(GtkWindowType type, const gchar *title)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkWidget *win;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
win = gtk_window_new(type);
|
|
|
|
if (title != NULL)
|
|
|
|
gtk_window_set_title(GTK_WINDOW(win), title);
|
|
|
|
g_signal_connect(win, "realize", G_CALLBACK(window_icon_realize_cb), NULL);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* XXX - which one is the correct default policy? or use a preference for this? */
|
|
|
|
/* GTK_WIN_POS_NONE, GTK_WIN_POS_CENTER or GTK_WIN_POS_MOUSE */
|
|
|
|
/* a lot of people dislike GTK_WIN_POS_MOUSE */
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* set the initial position (must be done, before show is called!) */
|
2005-08-20 14:02:00 +00:00
|
|
|
/* gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER_ON_PARENT);*/
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_NONE);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
return win;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-08 21:26:39 +00:00
|
|
|
/* Same as window_new(), but will keep its geometry values (size, position, ...).
|
2005-08-20 14:02:00 +00:00
|
|
|
* Be sure to use window_present() and window_destroy() appropriately! */
|
|
|
|
GtkWidget *
|
|
|
|
window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
window_geometry_t geom;
|
|
|
|
GtkWidget *win = window_new(type, title);
|
|
|
|
|
|
|
|
g_object_set_data(G_OBJECT(win), WINDOW_GEOM_KEY, (gpointer)g_strdup(geom_name));
|
|
|
|
|
|
|
|
/* do we have a previously saved size and position of this window? */
|
|
|
|
if(geom_name) {
|
|
|
|
/* It's a good idea to set the position and size of the window already here,
|
|
|
|
* as it's still invisible and won't "flicker the screen" while initially resizing. */
|
|
|
|
if(window_geom_load(geom_name, &geom)) {
|
|
|
|
/* XXX - use prefs to select which values to set? */
|
|
|
|
geom.set_pos = TRUE;
|
|
|
|
geom.set_size = TRUE;
|
|
|
|
geom.set_maximized = FALSE; /* don't maximize until window is shown */
|
|
|
|
window_set_geometry(win, &geom);
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
return win;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 21:13:58 +00:00
|
|
|
/* Create a new window for a splash screen; it's a main window, without decoration,
|
2005-08-20 14:02:00 +00:00
|
|
|
positioned in the center of the screen. */
|
|
|
|
GtkWidget *
|
|
|
|
splash_window_new(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkWidget *win;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
win = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark");
|
|
|
|
gtk_window_set_decorated(GTK_WINDOW(win), FALSE);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* set the initial position (must be done, before show is called!) */
|
|
|
|
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
return win;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Present the created window on the screen. */
|
|
|
|
void
|
|
|
|
window_present(GtkWidget *win)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
window_geometry_t geom;
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
/* present this window */
|
|
|
|
gtk_window_present(GTK_WINDOW(win));
|
|
|
|
|
|
|
|
/* do we have a previously saved size and position of this window? */
|
|
|
|
name = g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY);
|
|
|
|
if(name) {
|
|
|
|
if(window_geom_load(name, &geom)) {
|
|
|
|
/* XXX - use prefs to select which values to set? */
|
|
|
|
geom.set_pos = TRUE;
|
|
|
|
geom.set_size = TRUE;
|
|
|
|
geom.set_maximized = TRUE;
|
|
|
|
window_set_geometry(win, &geom);
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-30 12:41:56 +00:00
|
|
|
static gboolean
|
2005-08-20 14:02:00 +00:00
|
|
|
window_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
if (event->keyval == GDK_Escape) {
|
|
|
|
gtk_widget_activate(GTK_WIDGET(cancel_button));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
return FALSE;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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!). */
|
|
|
|
static void
|
|
|
|
window_set_cancel(GtkWidget *widget, GtkWidget *cancel_button)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
g_signal_connect(widget, "key_press_event", G_CALLBACK(window_key_press_cb), cancel_button);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set the actions needed for the cancel "Close"/"Ok"/"Cancel" button that closes the window */
|
|
|
|
void window_set_cancel_button(GtkWidget *win, GtkWidget *bt, window_cancel_button_fct cb)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
if(cb)
|
|
|
|
g_signal_connect(bt, "clicked", G_CALLBACK(cb), win);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_widget_grab_default(bt);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
window_set_cancel(win, bt);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* default callback handler for cancel button "clicked" signal */
|
|
|
|
void window_cancel_button_cb(GtkWidget *w _U_, gpointer data)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
window_destroy(GTK_WIDGET(data));
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* default callback handler: the window managers X of the window was clicked (delete_event) */
|
|
|
|
gboolean
|
|
|
|
window_delete_event_cb(GtkWidget *win, GdkEvent *event _U_, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
window_destroy(win);
|
|
|
|
|
|
|
|
/* event handled, don't do anything else */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the geometry of a window from window_new() */
|
|
|
|
void
|
|
|
|
window_get_geometry(GtkWidget *widget, window_geometry_t *geom)
|
|
|
|
{
|
2009-12-01 01:40:37 +00:00
|
|
|
gint desk_x, desk_y;
|
2005-08-20 14:02:00 +00:00
|
|
|
GdkWindowState state;
|
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
/* Try to grab our geometry.
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
GTK+ provides two routines to get a window's position relative
|
|
|
|
to the X root window. If I understand the documentation correctly,
|
|
|
|
gdk_window_get_deskrelative_origin applies mainly to Enlightenment
|
|
|
|
and gdk_window_get_root_origin applies for all other WMs.
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
The code below tries both routines, and picks the one that returns
|
|
|
|
the upper-left-most coordinates.
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
More info at:
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
http://mail.gnome.org/archives/gtk-devel-list/2001-March/msg00289.html
|
|
|
|
http://www.gtk.org/faq/#AEN606
|
|
|
|
*/
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
gdk_window_get_root_origin(widget->window,
|
2006-11-26 20:26:09 +00:00
|
|
|
&geom->x,
|
2005-08-20 14:02:00 +00:00
|
|
|
&geom->y);
|
2009-12-01 01:40:37 +00:00
|
|
|
if (gdk_window_get_deskrelative_origin(widget->window,
|
2010-07-28 13:34:41 +00:00
|
|
|
&desk_x, &desk_y)) {
|
2009-12-01 01:40:37 +00:00
|
|
|
if (desk_x <= geom->x &&
|
2005-08-20 14:02:00 +00:00
|
|
|
desk_y <= geom->y)
|
|
|
|
{
|
2009-12-01 01:40:37 +00:00
|
|
|
geom->x = desk_x;
|
|
|
|
geom->y = desk_y;
|
|
|
|
}
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2009-12-01 01:40:37 +00:00
|
|
|
/* XXX - Is this the "approved" method? */
|
|
|
|
gdk_window_get_size(widget->window,
|
2006-11-26 20:26:09 +00:00
|
|
|
&geom->width,
|
2005-08-20 14:02:00 +00:00
|
|
|
&geom->height);
|
|
|
|
|
|
|
|
state = gdk_window_get_state(widget->window);
|
|
|
|
geom->maximized = (state == GDK_WINDOW_STATE_MAXIMIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set the geometry of a window from window_new() */
|
|
|
|
void
|
|
|
|
window_set_geometry(GtkWidget *widget, window_geometry_t *geom)
|
|
|
|
{
|
2010-09-27 20:02:54 +00:00
|
|
|
GdkScreen *default_screen;
|
|
|
|
GdkRectangle viewable_area;
|
|
|
|
gint monitor_num;
|
|
|
|
|
2005-08-20 14:02:00 +00:00
|
|
|
/* as we now have the geometry from the recent file, set it */
|
2006-08-12 22:02:37 +00:00
|
|
|
/* if the window was minimized, x and y are -32000 (at least on Win32) */
|
|
|
|
if (geom->set_pos && geom->x != -32000 && geom->y != -32000) {
|
2010-09-27 21:23:29 +00:00
|
|
|
/* Per Wireshark bug #553, GTK has a problem on MS Windows
|
|
|
|
* where the upper-left corner of the window may appear off
|
|
|
|
* screen when when a single desktop spans multiple monitors
|
|
|
|
* of different resolutions and positions relative to each
|
|
|
|
* other.
|
2010-09-27 20:02:54 +00:00
|
|
|
*
|
|
|
|
* If the requested (x,y) position isn't within the monitor's
|
|
|
|
* viewable area, change it to the viewable area's (0,0). */
|
|
|
|
|
|
|
|
default_screen = gdk_screen_get_default();
|
2010-09-27 21:23:29 +00:00
|
|
|
monitor_num = gdk_screen_get_monitor_at_point(default_screen,
|
|
|
|
geom->x, geom->y);
|
|
|
|
gdk_screen_get_monitor_geometry(default_screen, monitor_num,
|
|
|
|
&viewable_area);
|
2010-09-27 20:02:54 +00:00
|
|
|
|
|
|
|
if(geom->x < viewable_area.x || geom->x > viewable_area.width)
|
|
|
|
geom->x = viewable_area.x;
|
|
|
|
|
|
|
|
if(geom->y < viewable_area.y || geom->y > viewable_area.height)
|
|
|
|
geom->y = viewable_area.y;
|
|
|
|
|
2006-05-01 10:59:06 +00:00
|
|
|
gtk_window_move(GTK_WINDOW(widget),
|
|
|
|
geom->x,
|
|
|
|
geom->y);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (geom->set_size) {
|
|
|
|
gtk_window_resize(GTK_WINDOW(widget),
|
2008-04-11 20:31:05 +00:00
|
|
|
/*gtk_widget_set_size_request(widget,*/
|
2005-08-20 14:02:00 +00:00
|
|
|
geom->width,
|
|
|
|
geom->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(geom->set_maximized) {
|
|
|
|
if (geom->maximized) {
|
|
|
|
gdk_window_maximize(widget->window);
|
|
|
|
} else {
|
|
|
|
gdk_window_unmaximize(widget->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the geometry hashtable for all known window classes,
|
|
|
|
* the window name is the key, and the geometry struct is the value */
|
2010-10-12 17:39:44 +00:00
|
|
|
static GHashTable *window_geom_hash = NULL;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* save the window and it's current geometry into the geometry hashtable */
|
|
|
|
static void
|
|
|
|
window_geom_save(const gchar *name, window_geometry_t *geom)
|
|
|
|
{
|
|
|
|
gchar *key;
|
|
|
|
window_geometry_t *work;
|
|
|
|
|
|
|
|
/* init hashtable, if not already done */
|
|
|
|
if(!window_geom_hash) {
|
|
|
|
window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
/* if we have an old one, remove and free it first */
|
|
|
|
work = g_hash_table_lookup(window_geom_hash, name);
|
|
|
|
if(work) {
|
|
|
|
g_hash_table_remove(window_geom_hash, name);
|
|
|
|
g_free(work->key);
|
|
|
|
g_free(work);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* g_malloc and insert the new one */
|
|
|
|
work = g_malloc(sizeof(*geom));
|
|
|
|
*work = *geom;
|
|
|
|
key = g_strdup(name);
|
|
|
|
work->key = key;
|
|
|
|
g_hash_table_insert(window_geom_hash, key, work);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* load the desired geometry for this window from the geometry hashtable */
|
|
|
|
static gboolean
|
|
|
|
window_geom_load(const gchar *name, window_geometry_t *geom)
|
|
|
|
{
|
|
|
|
window_geometry_t *p;
|
|
|
|
|
|
|
|
/* init hashtable, if not already done */
|
|
|
|
if(!window_geom_hash) {
|
|
|
|
window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = g_hash_table_lookup(window_geom_hash, name);
|
|
|
|
if(p) {
|
|
|
|
*geom = *p;
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read in a single key value pair from the recent file into the geometry hashtable */
|
|
|
|
void
|
|
|
|
window_geom_recent_read_pair(const char *name, const char *key, const char *value)
|
|
|
|
{
|
|
|
|
window_geometry_t geom;
|
|
|
|
|
|
|
|
|
|
|
|
/* find window geometry maybe already in hashtable */
|
|
|
|
if(!window_geom_load(name, &geom)) {
|
|
|
|
/* not in table, init geom with "basic" values */
|
2009-03-08 22:57:39 +00:00
|
|
|
geom.key = NULL; /* Will be set in window_geom_save () */
|
2005-08-20 14:02:00 +00:00
|
|
|
geom.set_pos = FALSE;
|
|
|
|
geom.x = -1;
|
|
|
|
geom.y = -1;
|
|
|
|
geom.set_size = FALSE;
|
|
|
|
geom.width = -1;
|
|
|
|
geom.height = -1;
|
|
|
|
|
|
|
|
geom.set_maximized = FALSE;/* this is valid in GTK2 only */
|
|
|
|
geom.maximized = FALSE; /* this is valid in GTK2 only */
|
|
|
|
}
|
2006-11-26 20:26:09 +00:00
|
|
|
|
2005-08-20 14:02:00 +00:00
|
|
|
if (strcmp(key, "x") == 0) {
|
|
|
|
geom.x = strtol(value, NULL, 10);
|
|
|
|
geom.set_pos = TRUE;
|
|
|
|
} else if (strcmp(key, "y") == 0) {
|
|
|
|
geom.y = strtol(value, NULL, 10);
|
|
|
|
geom.set_pos = TRUE;
|
|
|
|
} else if (strcmp(key, "width") == 0) {
|
|
|
|
geom.width = strtol(value, NULL, 10);
|
|
|
|
geom.set_size = TRUE;
|
|
|
|
} else if (strcmp(key, "height") == 0) {
|
|
|
|
geom.height = strtol(value, NULL, 10);
|
|
|
|
geom.set_size = TRUE;
|
|
|
|
} else if (strcmp(key, "maximized") == 0) {
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
if (g_ascii_strcasecmp(value, "true") == 0) {
|
2005-08-20 14:02:00 +00:00
|
|
|
geom.maximized = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
geom.maximized = FALSE;
|
|
|
|
}
|
|
|
|
geom.set_maximized = TRUE;
|
|
|
|
} else {
|
2007-10-20 02:34:41 +00:00
|
|
|
/*
|
|
|
|
* Silently ignore the bogus key. We shouldn't abort here,
|
|
|
|
* as this could be due to a corrupt recent file.
|
|
|
|
*
|
|
|
|
* XXX - should we print a message about this?
|
|
|
|
*/
|
|
|
|
return;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* save / replace geometry in hashtable */
|
|
|
|
window_geom_save(name, &geom);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* write all geometry values of all windows from the hashtable to the recent file */
|
|
|
|
void
|
|
|
|
window_geom_recent_write_all(gpointer rf)
|
|
|
|
{
|
|
|
|
/* init hashtable, if not already done */
|
|
|
|
if(!window_geom_hash) {
|
|
|
|
window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
window_destroy(GtkWidget *win)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
window_geometry_t geom;
|
|
|
|
const gchar *name;
|
2010-05-20 19:03:13 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
if (!win)
|
|
|
|
return;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* get_geometry must be done *before* destroy is running, as the window geometry
|
|
|
|
* cannot be retrieved at destroy time (so don't use event "destroy" for this) */
|
|
|
|
/* ...and don't do this at all, if we currently have no GdkWindow (e.g. if the
|
|
|
|
* GtkWidget is hidden) */
|
|
|
|
if(!GTK_WIDGET_NO_WINDOW(win) && GTK_WIDGET_VISIBLE(win)) {
|
|
|
|
window_get_geometry(win, &geom);
|
|
|
|
|
|
|
|
name = g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY);
|
|
|
|
if(name) {
|
|
|
|
window_geom_save(name, &geom);
|
|
|
|
g_free((gpointer)name);
|
|
|
|
}
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_widget_destroy(win);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert an xpm to a GtkWidget, using the window settings from it's parent */
|
|
|
|
/* (be sure that the parent window is already being displayed) */
|
|
|
|
GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm) {
|
|
|
|
GdkPixbuf * pixbuf;
|
|
|
|
GdkPixmap * pixmap;
|
|
|
|
GdkBitmap * bitmap;
|
|
|
|
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_xpm_data(xpm);
|
|
|
|
gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf, gtk_widget_get_colormap(parent), &pixmap, &bitmap, 128);
|
|
|
|
|
|
|
|
return gtk_image_new_from_pixmap (pixmap, bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert an xpm to a GtkWidget, using the top_level window settings */
|
|
|
|
/* (be sure that the top_level window is already being displayed) */
|
|
|
|
GtkWidget *xpm_to_widget(const char ** xpm) {
|
|
|
|
return xpm_to_widget_from_parent(top_level, xpm);
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:38 +00:00
|
|
|
/* Convert an pixbuf data to a GtkWidget */
|
|
|
|
/* Data should be created with "gdk-pixbuf-csource --raw" */
|
|
|
|
GtkWidget *pixbuf_to_widget(const char * pb_data) {
|
|
|
|
GdkPixbuf *pixbuf;
|
2010-07-28 13:34:41 +00:00
|
|
|
|
2009-11-04 21:16:38 +00:00
|
|
|
pixbuf = gdk_pixbuf_new_from_inline (-1, pb_data, FALSE, NULL);
|
|
|
|
return gtk_image_new_from_pixbuf(pixbuf);
|
|
|
|
}
|
|
|
|
|
2007-05-22 02:21:01 +00:00
|
|
|
/*
|
|
|
|
* Key to attach the "un-decorated" title to the window, so that if the
|
|
|
|
* user-specified decoration changes, we can correctly update the
|
|
|
|
* window title.
|
|
|
|
*/
|
2010-07-28 13:34:41 +00:00
|
|
|
#define MAIN_WINDOW_NAME_KEY "main_window_name"
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-08-20 22:12:55 +00:00
|
|
|
/* Set the name of the top level main_window_name with the specified string and call
|
2010-08-07 14:37:37 +00:00
|
|
|
update_main_window_title() to construct the full title and display it in the main window
|
|
|
|
and its icon title. */
|
2005-08-20 14:02:00 +00:00
|
|
|
void
|
2007-05-25 19:13:49 +00:00
|
|
|
set_main_window_name(const gchar *window_name)
|
2005-08-20 14:02:00 +00:00
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
gchar *old_window_name;
|
2007-05-22 02:21:01 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* Attach the new un-decorated window name to the window. */
|
|
|
|
old_window_name = g_object_get_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY);
|
|
|
|
g_free(old_window_name);
|
|
|
|
g_object_set_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY, g_strdup(window_name));
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-08-08 21:26:39 +00:00
|
|
|
update_main_window_title();
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-07 14:37:37 +00:00
|
|
|
/* Construct the main window's title with the current main_window_name, optionally appended
|
|
|
|
with the user-specified title and/or wireshark version. Display the result in the main
|
2010-08-20 22:12:55 +00:00
|
|
|
window title bar and in its icon title.
|
2010-08-07 14:37:37 +00:00
|
|
|
NOTE: The name was changed from '_name' to '_title' because main_window_name is actually
|
|
|
|
set in set_main_window_name() and is only one of the components of the title. */
|
2007-05-22 02:21:01 +00:00
|
|
|
void
|
2010-08-07 14:37:37 +00:00
|
|
|
update_main_window_title(void)
|
2007-05-22 02:21:01 +00:00
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
gchar *window_name;
|
|
|
|
gchar *title;
|
|
|
|
|
2010-08-07 14:37:37 +00:00
|
|
|
/* Get the current filename or other title set in set_main_window_name */
|
2010-07-28 13:34:41 +00:00
|
|
|
window_name = g_object_get_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY);
|
|
|
|
if (window_name != NULL) {
|
2010-08-08 21:26:39 +00:00
|
|
|
/* Optionally append the user-defined window title */
|
|
|
|
title = create_user_window_title(window_name);
|
|
|
|
|
|
|
|
/* Optionally append the version */
|
|
|
|
if (prefs.gui_version_in_start_page) {
|
2010-08-20 22:12:55 +00:00
|
|
|
gchar *old_title = title;
|
2010-08-08 21:26:39 +00:00
|
|
|
title = g_strdup_printf("%s [Wireshark %s %s]", title, VERSION, wireshark_svnversion);
|
2010-08-20 22:12:55 +00:00
|
|
|
g_free(old_title);
|
|
|
|
}
|
2010-08-08 21:26:39 +00:00
|
|
|
gtk_window_set_title(GTK_WINDOW(top_level), title);
|
|
|
|
g_free(title);
|
|
|
|
}
|
2007-05-22 02:21:01 +00:00
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
/* update the main window */
|
|
|
|
void main_window_update(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
while (gtk_events_pending()) gtk_main_iteration();
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* exit the main window */
|
|
|
|
void main_window_exit(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
exit(0);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
2007-02-01 08:36:35 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
2005-08-20 14:02:00 +00:00
|
|
|
/* quit a nested main window */
|
|
|
|
void main_window_nested_quit(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
if (gtk_main_level() > 0)
|
|
|
|
gtk_main_quit();
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* quit the main window */
|
|
|
|
void main_window_quit(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_main_quit();
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct pipe_input_tag {
|
|
|
|
gint source;
|
|
|
|
gpointer user_data;
|
|
|
|
int *child_process;
|
|
|
|
pipe_input_cb_t input_cb;
|
|
|
|
guint pipe_input_id;
|
2010-05-11 08:36:16 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#else
|
|
|
|
GIOChannel *channel;
|
2010-07-28 13:34:41 +00:00
|
|
|
#endif
|
2005-08-20 14:02:00 +00:00
|
|
|
} pipe_input_t;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* The timer has expired, see if there's stuff to read from the pipe,
|
|
|
|
if so, do the callback */
|
2008-07-08 02:25:30 +00:00
|
|
|
static gboolean
|
2005-08-20 14:02:00 +00:00
|
|
|
pipe_timer_cb(gpointer data)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
HANDLE handle;
|
|
|
|
DWORD avail = 0;
|
|
|
|
gboolean result, result1;
|
|
|
|
DWORD childstatus;
|
|
|
|
pipe_input_t *pipe_input = data;
|
|
|
|
gint iterations = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* try to read data from the pipe only 5 times, to avoid blocking */
|
|
|
|
while(iterations < 5) {
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: new iteration");*/
|
|
|
|
|
|
|
|
/* Oddly enough although Named pipes don't work on win9x,
|
|
|
|
PeekNamedPipe does !!! */
|
|
|
|
handle = (HANDLE) _get_osfhandle (pipe_input->source);
|
|
|
|
result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
|
|
|
|
|
|
|
|
/* Get the child process exit status */
|
|
|
|
result1 = GetExitCodeProcess((HANDLE)*(pipe_input->child_process),
|
|
|
|
&childstatus);
|
|
|
|
|
|
|
|
/* If the Peek returned an error, or there are bytes to be read
|
|
|
|
or the childwatcher thread has terminated then call the normal
|
|
|
|
callback */
|
|
|
|
if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
|
|
|
|
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: data avail");*/
|
|
|
|
|
|
|
|
if(pipe_input->pipe_input_id != 0) {
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: stop timer");*/
|
|
|
|
/* avoid reentrancy problems and stack overflow */
|
|
|
|
g_source_remove(pipe_input->pipe_input_id);
|
|
|
|
pipe_input->pipe_input_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And call the real handler */
|
|
|
|
if (!pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
|
|
|
g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: input pipe closed, iterations: %u", iterations);
|
|
|
|
/* pipe closed, return false so that the old timer is not run again */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: no data avail");*/
|
|
|
|
/* No data, stop now */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iterations++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pipe_input->pipe_input_id == 0) {
|
|
|
|
/* restore pipe handler */
|
|
|
|
pipe_input->pipe_input_id = g_timeout_add(200, pipe_timer_cb, data);
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, new timer", iterations);*/
|
|
|
|
|
|
|
|
/* Return false so that the old timer is not run again */
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_timer_cb: finished with iterations: %u, old timer", iterations);*/
|
|
|
|
|
|
|
|
/* we didn't stopped the old timer, so let it run */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
|
|
/* There's stuff to read from the sync pipe, meaning the child has sent
|
|
|
|
us a message, or the sync pipe has closed, meaning the child has
|
|
|
|
closed it (perhaps because it exited). */
|
2010-05-11 08:36:16 +00:00
|
|
|
static gboolean
|
|
|
|
pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
|
|
|
|
gpointer data)
|
2005-08-20 14:02:00 +00:00
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
pipe_input_t *pipe_input = data;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* avoid reentrancy problems and stack overflow */
|
|
|
|
g_source_remove(pipe_input->pipe_input_id);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
|
|
|
|
/* restore pipe handler */
|
|
|
|
pipe_input->pipe_input_id = g_io_add_watch_full (pipe_input->channel,
|
|
|
|
G_PRIORITY_HIGH,
|
|
|
|
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
|
|
|
pipe_input_cb,
|
|
|
|
pipe_input,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
|
|
|
|
{
|
|
|
|
static pipe_input_t pipe_input;
|
|
|
|
|
|
|
|
pipe_input.source = source;
|
|
|
|
pipe_input.child_process = child_process;
|
|
|
|
pipe_input.user_data = user_data;
|
|
|
|
pipe_input.input_cb = input_cb;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Tricky to use pipes in win9x, as no concept of wait. NT can
|
|
|
|
do this but that doesn't cover all win32 platforms. GTK can do
|
|
|
|
this but doesn't seem to work over processes. Attempt to do
|
|
|
|
something similar here, start a timer and check for data on every
|
|
|
|
timeout. */
|
2010-07-28 13:34:41 +00:00
|
|
|
/*g_log(NULL, G_LOG_LEVEL_DEBUG, "pipe_input_set_handler: new");*/
|
2008-07-08 02:25:30 +00:00
|
|
|
pipe_input.pipe_input_id = g_timeout_add(200, pipe_timer_cb, &pipe_input);
|
2005-08-20 14:02:00 +00:00
|
|
|
#else
|
2010-05-11 08:36:16 +00:00
|
|
|
pipe_input.channel = g_io_channel_unix_new(source);
|
|
|
|
g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
|
|
|
|
pipe_input.pipe_input_id = g_io_add_watch_full(pipe_input.channel,
|
2010-07-28 13:34:41 +00:00
|
|
|
G_PRIORITY_HIGH,
|
|
|
|
G_IO_IN|G_IO_ERR|G_IO_HUP,
|
|
|
|
pipe_input_cb,
|
|
|
|
&pipe_input,
|
|
|
|
NULL);
|
2005-08-20 14:02:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBPCAP */
|
|
|
|
|
|
|
|
/* Given a pointer to a GtkWidget for a top-level window, raise it and
|
|
|
|
de-iconify it. This routine is used if the user has done something to
|
|
|
|
ask that a window of a certain type be popped up when there can be only
|
|
|
|
one such window and such a window has already been popped up - we
|
|
|
|
pop up the existing one rather than creating a new one.
|
|
|
|
|
|
|
|
XXX - we should request that it be given the input focus, too. Alas,
|
|
|
|
GDK has nothing to do that, e.g. by calling "XSetInputFocus()" in a
|
|
|
|
window in X. Besides, using "XSetInputFocus()" doesn't work anyway,
|
|
|
|
apparently due to the way GTK+/GDK manages the input focus.
|
|
|
|
|
|
|
|
The X Desktop Group's Window Manager Standard specifies, in the section
|
|
|
|
on Root Window Properties, an _NET_ACTIVE_WINDOW client message that
|
|
|
|
can be sent to the root window, containing the window ID of the
|
|
|
|
window to activate; I infer that this might be the way to give the
|
|
|
|
window the input focus - I assume that means it's also de-iconified,
|
|
|
|
but I wouldn't assume it'd raise it.
|
|
|
|
|
|
|
|
XXX - will this do the right thing on window systems other than X? */
|
|
|
|
void
|
|
|
|
reactivate_window(GtkWidget *win)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
gdk_window_show(win->window);
|
|
|
|
gdk_window_raise(win->window);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* List of all GtkScrolledWindows, so we can globally set the scrollbar
|
|
|
|
placement of all of them. */
|
|
|
|
static GList *scrolled_windows;
|
|
|
|
|
|
|
|
static void setup_scrolled_window(GtkWidget *scrollw);
|
|
|
|
static void forget_scrolled_window(GtkWidget *scrollw, gpointer data);
|
|
|
|
static void set_scrollbar_placement_scrollw(GtkWidget *scrollw);
|
|
|
|
|
|
|
|
/* Create a GtkScrolledWindow, set its scrollbar placement appropriately,
|
|
|
|
and remember it. */
|
|
|
|
GtkWidget *
|
|
|
|
scrolled_window_new(GtkAdjustment *hadjustment, GtkAdjustment *vadjustment)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkWidget *scrollw;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
scrollw = gtk_scrolled_window_new(hadjustment, vadjustment);
|
|
|
|
setup_scrolled_window(scrollw);
|
|
|
|
return scrollw;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a GtkScrolledWindow's scrollbar placement and add it to the list
|
|
|
|
of GtkScrolledWindows. */
|
|
|
|
static void
|
|
|
|
setup_scrolled_window(GtkWidget *scrollw)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
set_scrollbar_placement_scrollw(scrollw);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollw),
|
2005-08-20 14:02:00 +00:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
scrolled_windows = g_list_append(scrolled_windows, scrollw);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* Catch the "destroy" event on the widget, so that we remove it from
|
|
|
|
the list when it's destroyed. */
|
|
|
|
g_signal_connect(scrollw, "destroy", G_CALLBACK(forget_scrolled_window), NULL);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a GtkScrolledWindow from the list of GtkScrolledWindows. */
|
|
|
|
static void
|
|
|
|
forget_scrolled_window(GtkWidget *scrollw, gpointer data _U_)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
scrolled_windows = g_list_remove(scrolled_windows, scrollw);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the scrollbar placement of a GtkScrolledWindow based upon user
|
|
|
|
preference. */
|
|
|
|
static void
|
|
|
|
set_scrollbar_placement_scrollw(GtkWidget *scrollw)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
if (prefs.gui_scrollbar_on_right) {
|
|
|
|
gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scrollw),
|
|
|
|
GTK_CORNER_TOP_LEFT);
|
|
|
|
} else {
|
|
|
|
gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scrollw),
|
|
|
|
GTK_CORNER_TOP_RIGHT);
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_scrollbar_placement_cb(gpointer data, gpointer user_data _U_)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
set_scrollbar_placement_scrollw((GtkWidget *)data);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the scrollbar placement of all GtkScrolledWindows based on
|
|
|
|
user preference. */
|
|
|
|
void
|
|
|
|
set_scrollbar_placement_all(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
g_list_foreach(scrolled_windows, set_scrollbar_placement_cb, NULL);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* List of all CTrees/TreeViews, so we can globally set the line and
|
|
|
|
* expander style of all of them. */
|
|
|
|
static GList *trees;
|
|
|
|
|
|
|
|
static void setup_tree(GtkWidget *tree);
|
|
|
|
static void forget_tree(GtkWidget *tree, gpointer data);
|
|
|
|
static void set_tree_styles(GtkWidget *tree);
|
2010-07-30 12:41:56 +00:00
|
|
|
static gboolean tree_view_key_pressed_cb(GtkWidget *tree, GdkEventKey *event, gpointer user_data _U_);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
/* Create a Tree, give it the right styles, and remember it. */
|
|
|
|
GtkWidget *
|
|
|
|
tree_view_new(GtkTreeModel *model)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkWidget *tree;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
tree = gtk_tree_view_new_with_model(model);
|
|
|
|
setup_tree(tree);
|
|
|
|
return tree;
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a Tree's styles and add it to the list of Trees. */
|
|
|
|
static void
|
|
|
|
setup_tree(GtkWidget *tree)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
set_tree_styles(tree);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
trees = g_list_append(trees, tree);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* Catch the "destroy" event on the widget, so that we remove it from
|
|
|
|
the list when it's destroyed. */
|
|
|
|
g_signal_connect(tree, "destroy", G_CALLBACK(forget_tree), NULL);
|
|
|
|
g_signal_connect(tree, "key-press-event", G_CALLBACK(tree_view_key_pressed_cb), NULL );
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a Tree from the list of Trees. */
|
|
|
|
static void
|
|
|
|
forget_tree(GtkWidget *tree, gpointer data _U_)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
trees = g_list_remove(trees, tree);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the styles of a Tree based upon user preferences. */
|
|
|
|
static void
|
|
|
|
set_tree_styles(GtkWidget *tree)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
g_assert(prefs.gui_altern_colors >= 0 && prefs.gui_altern_colors <= 1);
|
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree),
|
|
|
|
prefs.gui_altern_colors);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_tree_styles_cb(gpointer data, gpointer user_data _U_)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
set_tree_styles((GtkWidget *)data);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the styles of all Trees based upon style values. */
|
|
|
|
void
|
|
|
|
set_tree_styles_all(void)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
g_list_foreach(trees, set_tree_styles_cb, NULL);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 22:33:51 +00:00
|
|
|
/* Move the currently-selected item in a list store up or down one position. */
|
|
|
|
gboolean
|
|
|
|
tree_view_list_store_move_selection(GtkTreeView *tree, gboolean move_up)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkTreeIter from, to;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreePath *path_from, *path_to;
|
2010-04-30 22:33:51 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
sel = gtk_tree_view_get_selection(tree);
|
|
|
|
if (! gtk_tree_selection_get_selected(sel, &model, &from)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
path_from = gtk_tree_model_get_path(model, &from);
|
|
|
|
if (!path_from) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-30 22:33:51 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
path_to = gtk_tree_path_copy(path_from);
|
|
|
|
/* XXX - Why does one return void and the other return a gboolean? */
|
|
|
|
if (move_up) {
|
|
|
|
gtk_tree_path_prev(path_to);
|
|
|
|
} else {
|
|
|
|
gtk_tree_path_next(path_to);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gtk_tree_path_compare(path_from, path_to) == 0) {
|
|
|
|
gtk_tree_path_free(path_from);
|
|
|
|
gtk_tree_path_free(path_to);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-30 22:33:51 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_tree_model_get_iter(model, &to, path_to);
|
|
|
|
gtk_list_store_swap(GTK_LIST_STORE(model), &from, &to);
|
2010-04-30 22:33:51 +00:00
|
|
|
gtk_tree_path_free(path_from);
|
|
|
|
gtk_tree_path_free(path_to);
|
2010-07-28 13:34:41 +00:00
|
|
|
return TRUE;
|
2010-04-30 22:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the selected row number in a list store. */
|
|
|
|
gint
|
|
|
|
tree_view_list_store_get_selected_row(GtkTreeView *tree) {
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gchar *path_str;
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(tree);
|
|
|
|
if (! gtk_tree_selection_get_selected(sel, &model, &iter)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path(model, &iter);
|
|
|
|
if (!path) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_str = gtk_tree_path_to_string(path);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
|
|
|
|
row = (gint) strtol(path_str, NULL, 10);
|
|
|
|
g_free(path_str);
|
|
|
|
|
|
|
|
return row;
|
2010-04-30 22:33:51 +00:00
|
|
|
}
|
2005-08-20 14:02:00 +00:00
|
|
|
|
|
|
|
/* append a row to the simple list */
|
|
|
|
/* use it like: simple_list_append(list, 0, "first", 1, "second", -1) */
|
|
|
|
void
|
|
|
|
simple_list_append(GtkWidget *list, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
va_start(ap, list);
|
|
|
|
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set_valist(store, &iter, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a simple list widget */
|
|
|
|
GtkWidget *
|
|
|
|
simple_list_new(gint cols, const gchar **titles) {
|
|
|
|
GtkWidget *plugins_list;
|
|
|
|
int i;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
|
|
|
|
|
|
|
g_assert(cols <= 10);
|
|
|
|
store = gtk_list_store_new(cols,
|
|
|
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
plugins_list = tree_view_new(GTK_TREE_MODEL(store));
|
|
|
|
g_object_unref(G_OBJECT(store));
|
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(plugins_list), (titles != NULL));
|
|
|
|
for(i=0; i<cols; i++) {
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
column = gtk_tree_view_column_new_with_attributes(titles ? titles[i] : "", renderer,
|
|
|
|
"text", i, NULL);
|
|
|
|
gtk_tree_view_column_set_sort_column_id(column, i);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(plugins_list), column);
|
|
|
|
}
|
|
|
|
|
|
|
|
return plugins_list;
|
|
|
|
}
|
|
|
|
|
2008-04-13 17:48:47 +00:00
|
|
|
void render_as_url(GtkCellRenderer *cell)
|
|
|
|
{
|
|
|
|
g_object_set(cell, "foreground", "blue", NULL);
|
|
|
|
g_object_set(cell, "foreground-set", TRUE, NULL);
|
|
|
|
|
|
|
|
g_object_set(cell, "underline", PANGO_UNDERLINE_SINGLE, NULL);
|
|
|
|
g_object_set(cell, "underline-set", TRUE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void simple_list_url_col(GtkWidget *list, gint col)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkTreeViewColumn *ul_column;
|
|
|
|
GList *renderers_list;
|
|
|
|
GtkCellRenderer *ul_renderer;
|
2008-04-13 17:48:47 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* make the column look like a link ... */
|
|
|
|
ul_column = gtk_tree_view_get_column(GTK_TREE_VIEW(list), col);
|
2008-04-13 17:48:47 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
renderers_list = gtk_tree_view_column_get_cell_renderers(ul_column);
|
2008-04-13 17:48:47 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
if(renderers_list != NULL) {
|
|
|
|
/* it is simple list - there should be only one renderer */
|
|
|
|
ul_renderer = (GtkCellRenderer*)renderers_list->data;
|
2008-04-13 17:48:47 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
render_as_url(ul_renderer);
|
2008-04-13 17:48:47 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
g_list_free(renderers_list);
|
|
|
|
}
|
2008-04-13 17:48:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-08-20 14:02:00 +00:00
|
|
|
void
|
2006-11-26 20:26:09 +00:00
|
|
|
copy_to_clipboard(GString *str)
|
2005-08-20 14:02:00 +00:00
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
GtkClipboard *cb;
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
|
|
|
|
gtk_clipboard_set_text(cb, str->str, -1); /* Copy the byte data into the clipboard */
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 02:49:50 +00:00
|
|
|
|
|
|
|
typedef struct _copy_binary_t {
|
|
|
|
guint8* data;
|
|
|
|
int len;
|
|
|
|
} copy_binary_t;
|
|
|
|
|
|
|
|
static
|
|
|
|
copy_binary_t* create_copy_binary_t(const guint8* data, int len)
|
|
|
|
{
|
|
|
|
copy_binary_t* copy_data;
|
|
|
|
|
|
|
|
g_assert(len > 0);
|
|
|
|
copy_data = g_new(copy_binary_t,1);
|
|
|
|
copy_data->data = g_new(guint8,len);
|
|
|
|
copy_data->len = len;
|
|
|
|
memcpy(copy_data->data,data,len * sizeof(guint8));
|
|
|
|
return copy_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_copy_binary_t(copy_binary_t* copy_data) {
|
|
|
|
g_free(copy_data->data);
|
|
|
|
g_free(copy_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void copy_binary_free_cb(GtkClipboard *clipboard _U_, gpointer user_data_or_owner)
|
|
|
|
{
|
|
|
|
copy_binary_t* copy_data;
|
|
|
|
copy_data = user_data_or_owner;
|
|
|
|
destroy_copy_binary_t(copy_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void copy_binary_get_cb(GtkClipboard *clipboard _U_, GtkSelectionData *selection_data, guint info _U_, gpointer user_data_or_owner)
|
|
|
|
{
|
|
|
|
copy_binary_t* copy_data;
|
|
|
|
|
|
|
|
copy_data = user_data_or_owner;
|
|
|
|
|
|
|
|
/* Just do a dumb set as binary data */
|
|
|
|
gtk_selection_data_set(selection_data, GDK_NONE, 8, copy_data->data, copy_data->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy_binary_to_clipboard(const guint8* data_p, int len)
|
|
|
|
{
|
|
|
|
static GtkTargetEntry target_entry[] = {
|
2007-04-04 12:18:10 +00:00
|
|
|
{"application/octet_stream", 0, 0}}; /* XXX - this not understood by most applications,
|
2007-01-28 02:49:50 +00:00
|
|
|
* but can be pasted into the better hex editors - is
|
|
|
|
* there something better that we can do?
|
|
|
|
*/
|
|
|
|
|
|
|
|
GtkClipboard *cb;
|
|
|
|
copy_binary_t* copy_data;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
if(len <= 0) {
|
|
|
|
return; /* XXX would it be better to clear the clipboard? */
|
|
|
|
}
|
|
|
|
cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
|
|
|
|
copy_data = create_copy_binary_t(data_p,len);
|
|
|
|
|
|
|
|
ret = gtk_clipboard_set_with_data(cb,target_entry,1,
|
|
|
|
copy_binary_get_cb, copy_binary_free_cb,copy_data);
|
|
|
|
|
|
|
|
if(!ret) {
|
|
|
|
destroy_copy_binary_t(copy_data);
|
2007-04-04 12:18:10 +00:00
|
|
|
}
|
2007-01-28 02:49:50 +00:00
|
|
|
}
|
|
|
|
|
2005-08-20 14:02:00 +00:00
|
|
|
/*
|
|
|
|
* Create a new window title string with user-defined title preference.
|
|
|
|
* (Or ignore it if unspecified).
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
create_user_window_title(const gchar *caption)
|
|
|
|
{
|
2010-07-28 13:34:41 +00:00
|
|
|
/* fail-safe */
|
|
|
|
if (caption == NULL)
|
|
|
|
return g_strdup("");
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/* no user-defined title specified */
|
|
|
|
if ((prefs.gui_window_title == NULL) || (*prefs.gui_window_title == '\0'))
|
|
|
|
return g_strdup(caption);
|
2005-08-20 14:02:00 +00:00
|
|
|
|
2010-08-07 14:37:37 +00:00
|
|
|
return g_strdup_printf("%s [%s]", caption, prefs.gui_window_title);
|
2005-08-20 14:02:00 +00:00
|
|
|
}
|
2006-11-26 20:26:09 +00:00
|
|
|
|
|
|
|
/* XXX move toggle_tree over from proto_draw.c to handle GTK+ 1 */
|
2010-03-28 20:22:09 +00:00
|
|
|
/*
|
2010-07-28 13:34:41 +00:00
|
|
|
* This callback is invoked when keyboard focus is within either
|
|
|
|
* the packetlist view or the detail view. The keystrokes processed
|
|
|
|
* within this callback are attempting to modify the detail view.
|
|
|
|
* Within the detail view we special case the Left Arrow, Backspace
|
2010-03-28 20:22:09 +00:00
|
|
|
* and Enter keys depending on the state of the expander (if any)
|
|
|
|
* for the item in focus.
|
|
|
|
*
|
2010-07-28 13:34:41 +00:00
|
|
|
* Returning FALSE allows processing of the original key_press_event
|
2010-03-28 20:22:09 +00:00
|
|
|
* by other callbacks. Left/Right scrolling of the packetlist
|
|
|
|
* view and expanding/collapsing of the detail view lists is
|
|
|
|
* handled by the default GtkTreeView key-press-event call back.
|
|
|
|
*
|
|
|
|
* XXX - Would an improved version of this callback test to see which
|
2010-07-28 13:34:41 +00:00
|
|
|
* of the two GtkTreeView lists has focus? Left/Right scrolling of
|
|
|
|
* the packetlist is currently not optimal. It will take several
|
|
|
|
* right or left keypress events before the packetlist responds.
|
2010-03-28 20:22:09 +00:00
|
|
|
* The problem appears to be that the focus is on a particular cell
|
|
|
|
* within the highlighted row cell (like a spreadsheet). Scrolling
|
2010-07-28 13:34:41 +00:00
|
|
|
* of the view right or left will not occur until the focus is
|
|
|
|
* moved to a cell off the left or right edge of the packet list
|
|
|
|
* view. Also TAB/SHIFT-TAB events can move keyboard focus to
|
2010-03-28 20:22:09 +00:00
|
|
|
* the packetlist header where there is currently visual hint
|
|
|
|
* a header cell has focus.
|
|
|
|
*/
|
2010-07-30 12:41:56 +00:00
|
|
|
static gboolean
|
2006-11-26 20:26:09 +00:00
|
|
|
tree_view_key_pressed_cb(GtkWidget *tree, GdkEventKey *event, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
GtkTreeSelection* selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter parent;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreePath* path;
|
2010-05-25 23:55:33 +00:00
|
|
|
gboolean expanded, expandable;
|
2010-03-28 20:22:09 +00:00
|
|
|
int rc = FALSE;
|
2006-11-26 20:26:09 +00:00
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
|
|
|
|
if(!selection) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!gtk_tree_selection_get_selected (selection, &model, &iter)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path(model, &iter);
|
|
|
|
if(!path) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-28 13:34:41 +00:00
|
|
|
|
2010-05-25 23:55:33 +00:00
|
|
|
/* Always FALSE when we're in the packet list (at least until we add sub-packets) */
|
2006-11-26 20:26:09 +00:00
|
|
|
expanded = gtk_tree_view_row_expanded(GTK_TREE_VIEW(tree), path);
|
2010-05-25 23:55:33 +00:00
|
|
|
expandable = gtk_tree_model_iter_has_child(model, &iter);
|
2006-11-26 20:26:09 +00:00
|
|
|
|
|
|
|
switch (event->keyval) {
|
|
|
|
case GDK_Left:
|
|
|
|
if(expanded) {
|
2010-05-25 23:55:33 +00:00
|
|
|
/* Subtree is expanded. Collapse it. */
|
|
|
|
gtk_tree_view_collapse_row(GTK_TREE_VIEW(tree), path);
|
|
|
|
rc = TRUE;
|
2010-07-28 13:34:41 +00:00
|
|
|
break;
|
2006-11-26 20:26:09 +00:00
|
|
|
}
|
|
|
|
/* No break - fall through to jumping to the parent */
|
|
|
|
case GDK_BackSpace:
|
|
|
|
if (!expanded) {
|
|
|
|
/* subtree is already collapsed, jump to parent node */
|
|
|
|
if(! gtk_tree_model_iter_parent(model, &parent, &iter)) {
|
2010-03-28 20:22:09 +00:00
|
|
|
rc = FALSE;
|
2010-07-28 13:34:41 +00:00
|
|
|
break;
|
2006-11-26 20:26:09 +00:00
|
|
|
}
|
2009-02-22 21:28:13 +00:00
|
|
|
gtk_tree_path_free(path);
|
2006-11-26 20:26:09 +00:00
|
|
|
path = gtk_tree_model_get_path(model, &parent);
|
|
|
|
if(!path) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree), path,
|
|
|
|
NULL /* focus_column */,
|
|
|
|
FALSE /* !start_editing */);
|
2010-03-28 20:22:09 +00:00
|
|
|
rc = TRUE;
|
2010-07-28 13:34:41 +00:00
|
|
|
break;
|
2006-11-26 20:26:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-25 23:55:33 +00:00
|
|
|
case GDK_Right:
|
2010-07-28 13:34:41 +00:00
|
|
|
if (expandable) {
|
|
|
|
/* We have a subtree. Try to expand it. */
|
|
|
|
gtk_tree_view_expand_row(GTK_TREE_VIEW(tree), path, FALSE /* !open_all */);
|
|
|
|
rc = TRUE;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-26 20:26:09 +00:00
|
|
|
case GDK_Return:
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
/* Reverse the current state. */
|
|
|
|
if (expanded)
|
|
|
|
gtk_tree_view_collapse_row(GTK_TREE_VIEW(tree), path);
|
|
|
|
else
|
|
|
|
gtk_tree_view_expand_row(GTK_TREE_VIEW(tree), path, FALSE /* !open_all */);
|
2010-03-28 20:22:09 +00:00
|
|
|
rc = TRUE;
|
2010-07-28 13:34:41 +00:00
|
|
|
break;
|
2006-11-26 20:26:09 +00:00
|
|
|
}
|
|
|
|
|
2010-03-28 20:22:09 +00:00
|
|
|
if(path) {
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
|
|
|
return rc;
|
2006-11-26 20:26:09 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 08:52:36 +00:00
|
|
|
void
|
|
|
|
switch_to_fixed_col(GtkTreeView *view)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
GtkTreeViewColumn *column;
|
2010-07-28 13:34:41 +00:00
|
|
|
GList *columns, *list;
|
2009-10-09 08:52:36 +00:00
|
|
|
|
|
|
|
columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
|
2009-10-09 09:06:22 +00:00
|
|
|
list = columns;
|
2009-10-09 08:52:36 +00:00
|
|
|
while(columns) {
|
|
|
|
column = columns->data;
|
|
|
|
size = gtk_tree_view_column_get_width (column);
|
|
|
|
gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_FIXED);
|
|
|
|
if (size > gtk_tree_view_column_get_fixed_width(column))
|
|
|
|
gtk_tree_view_column_set_fixed_width(column, size);
|
|
|
|
columns = g_list_next(columns);
|
|
|
|
}
|
2009-10-09 09:06:22 +00:00
|
|
|
g_list_free(list);
|
2010-07-28 13:34:41 +00:00
|
|
|
|
2009-10-09 08:52:36 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,6,0)
|
|
|
|
gtk_tree_view_set_fixed_height_mode(view, TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
gint
|
2009-10-09 08:52:36 +00:00
|
|
|
get_default_col_size(GtkWidget *view, const gchar *str)
|
|
|
|
{
|
|
|
|
PangoLayout *layout;
|
2009-12-01 21:24:48 +00:00
|
|
|
gint col_width;
|
2009-10-09 08:52:36 +00:00
|
|
|
|
|
|
|
layout = gtk_widget_create_pango_layout(view, str);
|
2010-07-28 13:34:41 +00:00
|
|
|
pango_layout_get_pixel_size(layout,
|
2009-12-01 01:37:52 +00:00
|
|
|
&col_width, /* width */
|
|
|
|
NULL); /* height */
|
2009-10-09 08:52:36 +00:00
|
|
|
g_object_unref(G_OBJECT(layout));
|
2009-12-01 21:30:30 +00:00
|
|
|
/* Add a single character's width to get some spacing between columns */
|
2009-12-01 21:24:48 +00:00
|
|
|
return col_width + (pango_font_description_get_size(user_font_get_regular()) / PANGO_SCALE);
|
2009-10-09 08:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/*
|
2009-03-06 17:16:56 +00:00
|
|
|
* This function can be called from gtk_tree_view_column_set_cell_data_func()
|
|
|
|
* the user data must be the colum number.
|
2010-07-28 13:34:41 +00:00
|
|
|
* Present floats with two decimals
|
2009-03-06 17:16:56 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
float_data_func (GtkTreeViewColumn *column _U_,
|
2009-12-01 01:37:52 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gfloat float_val;
|
|
|
|
gchar buf[20];
|
|
|
|
char *savelocale;
|
|
|
|
|
|
|
|
/* the col to get data from is in userdata */
|
|
|
|
gint float_col = GPOINTER_TO_INT(user_data);
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, iter, float_col, &float_val, -1);
|
|
|
|
|
|
|
|
/* save the current locale */
|
|
|
|
savelocale = setlocale(LC_NUMERIC, NULL);
|
|
|
|
/* switch to "C" locale to avoid problems with localized decimal separators
|
|
|
|
* in g_snprintf("%f") functions
|
|
|
|
*/
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
|
|
|
g_snprintf(buf, sizeof(buf), "%.2f", float_val);
|
|
|
|
/* restore previous locale setting */
|
|
|
|
setlocale(LC_NUMERIC, savelocale);
|
|
|
|
|
|
|
|
g_object_set(renderer, "text", buf, NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/*
|
2009-03-16 18:01:25 +00:00
|
|
|
* This function can be called from gtk_tree_view_column_set_cell_data_func()
|
|
|
|
* the user data must be the colum number.
|
2010-07-28 13:34:41 +00:00
|
|
|
* Present value as hexadecimal.
|
2009-03-16 18:01:25 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
present_as_hex_func (GtkTreeViewColumn *column _U_,
|
2009-12-01 01:37:52 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
guint val;
|
|
|
|
gchar buf[35];
|
2009-03-16 18:01:25 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
/* the col to get data from is in userdata */
|
|
|
|
gint col = GPOINTER_TO_INT(user_data);
|
2009-03-16 18:01:25 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
gtk_tree_model_get(model, iter, col, &val, -1);
|
2009-03-16 18:01:25 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
g_snprintf(buf, sizeof(buf), "0x%02x", val);
|
2009-03-16 18:01:25 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
g_object_set(renderer, "text", buf, NULL);
|
|
|
|
}
|
2006-11-26 20:26:09 +00:00
|
|
|
|
2009-10-09 08:52:36 +00:00
|
|
|
void
|
|
|
|
u64_data_func (GtkTreeViewColumn *column _U_,
|
2009-12-01 01:37:52 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
guint64 val;
|
|
|
|
int i = 0;
|
|
|
|
gchar *bp;
|
|
|
|
gchar buf[35];
|
|
|
|
|
|
|
|
/* the col to get data from is in userdata */
|
|
|
|
gint col = GPOINTER_TO_INT(user_data);
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, iter, col, &val, -1);
|
|
|
|
|
|
|
|
bp = &buf[34];
|
|
|
|
*bp = 0;
|
|
|
|
do {
|
2009-10-09 08:52:36 +00:00
|
|
|
*--bp = (gchar)(val % 10) +'0';
|
|
|
|
if (!(++i % 3)) {
|
|
|
|
*--bp = ' ';
|
|
|
|
}
|
2009-12-01 01:37:52 +00:00
|
|
|
} while ((val /= 10) != 0 && bp > buf);
|
|
|
|
g_object_set(renderer, "text", bp, NULL);
|
|
|
|
}
|
2009-10-09 08:52:36 +00:00
|
|
|
|
2010-07-28 13:34:41 +00:00
|
|
|
/*
|
2009-08-27 05:34:06 +00:00
|
|
|
* This function can be called from gtk_tree_view_column_set_cell_data_func()
|
2010-07-28 13:34:41 +00:00
|
|
|
* The user data must be the column number.
|
|
|
|
* Renders the const static string whose pointer is stored.
|
2009-08-27 05:34:06 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
str_ptr_data_func (GtkTreeViewColumn *column _U_,
|
2009-12-01 01:37:52 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
2010-07-28 13:34:41 +00:00
|
|
|
{
|
2009-12-01 01:37:52 +00:00
|
|
|
const gchar *str = NULL;
|
2009-08-27 05:34:06 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
/* The col to get data from is in userdata */
|
|
|
|
gint data_column = GPOINTER_TO_INT(user_data);
|
2009-08-27 05:34:06 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
gtk_tree_model_get(model, iter, data_column, &str, -1);
|
|
|
|
/* XXX should we check that str is non NULL and print a warning or do assert? */
|
2009-08-27 05:34:06 +00:00
|
|
|
|
2009-12-01 01:37:52 +00:00
|
|
|
g_object_set(renderer, "text", str, NULL);
|
|
|
|
}
|
2009-08-27 05:34:06 +00:00
|
|
|
|
2009-08-27 06:57:53 +00:00
|
|
|
gint
|
|
|
|
str_ptr_sort_func(GtkTreeModel *model,
|
2009-12-01 01:37:52 +00:00
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer user_data)
|
2009-08-27 06:57:53 +00:00
|
|
|
{
|
2009-12-01 01:37:52 +00:00
|
|
|
const gchar *str_a = NULL;
|
|
|
|
const gchar *str_b = NULL;
|
|
|
|
gint ret = 0;
|
|
|
|
|
|
|
|
/* The col to get data from is in userdata */
|
|
|
|
gint data_column = GPOINTER_TO_INT(user_data);
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, a, data_column, &str_a, -1);
|
|
|
|
gtk_tree_model_get(model, b, data_column, &str_b, -1);
|
|
|
|
|
|
|
|
if (str_a == str_b) {
|
|
|
|
/* it's worth testing because a lot of rows point to the same data */
|
|
|
|
return 0;
|
2010-07-28 13:34:41 +00:00
|
|
|
}
|
2009-12-01 01:37:52 +00:00
|
|
|
else if (str_a == NULL || str_b == NULL) {
|
|
|
|
ret = (str_a == NULL) ? -1 : 1;
|
2010-07-28 13:34:41 +00:00
|
|
|
}
|
2009-12-01 01:37:52 +00:00
|
|
|
else {
|
|
|
|
ret = g_ascii_strcasecmp(str_a,str_b);
|
|
|
|
}
|
|
|
|
return ret;
|
2009-08-27 06:57:53 +00:00
|
|
|
}
|
2010-02-22 18:39:55 +00:00
|
|
|
|
2010-07-15 15:05:39 +00:00
|
|
|
/** --------------------------------------------------
|
2010-07-13 00:17:08 +00:00
|
|
|
* ws_combo_box_text_and_pointer convenience functions
|
|
|
|
* (Code adapted from GtkComboBox.c)
|
|
|
|
*/
|
|
|
|
|
2010-02-22 18:39:55 +00:00
|
|
|
/**
|
2010-07-20 14:30:41 +00:00
|
|
|
* ws_combo_box_new_text_and_pointer_full:
|
2010-02-22 18:39:55 +00:00
|
|
|
*
|
|
|
|
* Convenience function which constructs a new "text and pointer" combo box, which
|
2010-07-28 13:34:41 +00:00
|
|
|
* is a #GtkComboBox just displaying strings and storing a pointer associated with
|
|
|
|
* each combo_box entry; The pointer can be retrieved when an entry is selected.
|
2010-07-20 14:30:41 +00:00
|
|
|
* Also: optionally returns the cell renderer for the combo box.
|
2010-02-22 18:39:55 +00:00
|
|
|
* If you use this function to create a text_and_pointer combo_box,
|
|
|
|
* you should only manipulate its data source with the
|
2010-07-15 15:05:39 +00:00
|
|
|
* following convenience functions:
|
|
|
|
* ws_combo_box_append_text_and_pointer()
|
|
|
|
* ws_combo_box_append_text_and_pointer_full()
|
2010-02-22 18:39:55 +00:00
|
|
|
*
|
2010-07-20 14:30:41 +00:00
|
|
|
* @param cell_p pointer to return the 'GtkCellRenderer *' for the combo box (or NULL).
|
2010-02-22 18:39:55 +00:00
|
|
|
* @return A pointer to a new text_and_pointer combo_box.
|
|
|
|
*/
|
2010-07-20 14:30:41 +00:00
|
|
|
|
|
|
|
/* Note:
|
|
|
|
* GtkComboBox style property: "appears-as-list":
|
|
|
|
* Default: 0: ie: displays as menus
|
|
|
|
* Wireshark Windows gtkrc: 1: ie: displays as lists (treeview)
|
|
|
|
*/
|
2010-02-22 18:39:55 +00:00
|
|
|
GtkWidget *
|
2010-07-20 14:30:41 +00:00
|
|
|
ws_combo_box_new_text_and_pointer_full(GtkCellRenderer **cell_p) {
|
2010-02-22 18:39:55 +00:00
|
|
|
GtkWidget *combo_box;
|
|
|
|
GtkCellRenderer *cell;
|
2010-07-15 15:05:39 +00:00
|
|
|
GtkTreeStore *store;
|
2010-02-22 18:39:55 +00:00
|
|
|
|
2010-07-15 15:05:39 +00:00
|
|
|
/* The Tree store for the GtkComboBox has 3 columns:
|
2010-07-13 00:17:08 +00:00
|
|
|
0: text string for display in GtkComboBox list;
|
|
|
|
1: pointer (data) associated with the entry;
|
|
|
|
2: True/False depending upon whether this entry is selectable ("sensitive" attribute).
|
|
|
|
*/
|
2010-07-15 15:05:39 +00:00
|
|
|
|
|
|
|
store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
|
2010-02-22 18:39:55 +00:00
|
|
|
combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref(store);
|
|
|
|
cell = gtk_cell_renderer_text_new();
|
|
|
|
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), cell,
|
2010-07-13 00:17:08 +00:00
|
|
|
"text", 0, "sensitive", 2,
|
2010-02-22 18:39:55 +00:00
|
|
|
NULL);
|
2010-07-20 14:30:41 +00:00
|
|
|
if (cell_p != NULL) {
|
|
|
|
*cell_p = cell;
|
|
|
|
}
|
2010-02-22 18:39:55 +00:00
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
2010-07-20 14:30:41 +00:00
|
|
|
/**
|
|
|
|
* ws_combo_box_new_text_and_pointer:
|
|
|
|
*
|
|
|
|
* Convenience function which constructs a new "text and pointer" combo box, which
|
2010-07-28 13:34:41 +00:00
|
|
|
* is a #GtkComboBox just displaying strings and storing a pointer associated with
|
|
|
|
* each combo_box entry; The pointer can be retrieved when an entry is selected.
|
2010-07-20 14:30:41 +00:00
|
|
|
* If you use this function to create a text_and_pointer combo_box,
|
|
|
|
* you should only manipulate its data source with the
|
|
|
|
* following convenience functions:
|
|
|
|
* ws_combo_box_append_text_and_pointer()
|
|
|
|
* ws_combo_box_append_text_and_pointer_full()
|
|
|
|
*
|
|
|
|
* @return A pointer to a new text_and_pointer combo_box.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
ws_combo_box_new_text_and_pointer(void) {
|
|
|
|
return ws_combo_box_new_text_and_pointer_full(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-22 18:39:55 +00:00
|
|
|
/**
|
|
|
|
* ws_combo_box_clear_text_and_pointer:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
|
|
|
*
|
|
|
|
* Clears all the text_and_pointer entries in the text_and_pointer combo_box.
|
2010-07-28 13:34:41 +00:00
|
|
|
* Note: A "changed" signal will be emitted after the clear if there was
|
2010-02-24 01:21:09 +00:00
|
|
|
* an active (selected) entry before the clear.
|
2010-02-22 18:39:55 +00:00
|
|
|
* You should use this function only with combo boxes constructed with
|
|
|
|
* ws_combo_box_new_text_and_pointer().
|
|
|
|
*/
|
2010-07-15 15:05:39 +00:00
|
|
|
void
|
|
|
|
ws_combo_box_clear_text_and_pointer(GtkComboBox *combo_box)
|
2010-02-22 18:39:55 +00:00
|
|
|
{
|
2010-07-15 15:05:39 +00:00
|
|
|
gtk_tree_store_clear(GTK_TREE_STORE(gtk_combo_box_get_model(combo_box)));
|
2010-02-22 18:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 15:05:39 +00:00
|
|
|
* ws_combo_box_append_text_and_pointer_full:
|
2010-02-22 18:39:55 +00:00
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
2010-07-28 13:34:41 +00:00
|
|
|
* @param parent_iter Parent row for apending; NULL if appending to tree top-level;
|
2010-02-22 18:39:55 +00:00
|
|
|
* @param text A string to be displayed as an entry in the dropdown list of the combo_box
|
|
|
|
* @param ptr A pointer to be associated with this entry of the combo_box
|
2010-07-13 00:17:08 +00:00
|
|
|
* @param sensitive TRUE/FALSE to set sensitivity of the entry
|
2010-07-15 15:05:39 +00:00
|
|
|
* @return A GtkTreeIter pointing to the appended GtkVomboBox entry.
|
2010-02-22 18:39:55 +00:00
|
|
|
*
|
2010-07-13 00:17:08 +00:00
|
|
|
* Appends text and ptr to the list of strings and pointers stored in combo_box.
|
2010-07-15 15:05:39 +00:00
|
|
|
* The text and ptr can be appended to any existing level of the tree_store.
|
|
|
|
* The sensitivity of the row will be set as requested.
|
|
|
|
* Note that you can only use this function with combo boxes constructed with
|
2010-02-22 18:39:55 +00:00
|
|
|
* ws_combo_box_new_text_and_pointer().
|
|
|
|
*/
|
2010-07-15 15:05:39 +00:00
|
|
|
GtkTreeIter
|
|
|
|
ws_combo_box_append_text_and_pointer_full(GtkComboBox *combo_box,
|
|
|
|
GtkTreeIter *parent_iter,
|
|
|
|
const gchar *text,
|
|
|
|
const gpointer ptr,
|
|
|
|
const gboolean sensitive)
|
2010-02-22 18:39:55 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2010-07-15 15:05:39 +00:00
|
|
|
GtkTreeStore *store;
|
2010-02-22 18:39:55 +00:00
|
|
|
|
2010-07-15 15:05:39 +00:00
|
|
|
store = GTK_TREE_STORE(gtk_combo_box_get_model(combo_box));
|
2010-02-22 18:39:55 +00:00
|
|
|
|
2010-07-15 15:05:39 +00:00
|
|
|
gtk_tree_store_append(store, &iter, parent_iter);
|
|
|
|
gtk_tree_store_set(store, &iter, 0, text, 1, ptr, 2, sensitive, -1);
|
|
|
|
|
|
|
|
return iter;
|
2010-02-22 18:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 00:17:08 +00:00
|
|
|
/**
|
|
|
|
* ws_combo_box_append_text_and_pointer:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
|
|
|
* @param text A string to be displayed as an entry in the dropdown list of the combo_box
|
|
|
|
* @param ptr A pointer to be associated with this entry of the combo_box
|
2010-07-15 15:05:39 +00:00
|
|
|
* @return A GtkTreeIter pointing to the appended GtkComboBox entry.
|
2010-07-13 00:17:08 +00:00
|
|
|
*
|
|
|
|
* Appends text and ptr to the list of strings and pointers stored in combo_box. Note that
|
|
|
|
* you can only use this function with combo boxes constructed with
|
|
|
|
* ws_combo_box_new_text_and_pointer().
|
|
|
|
*/
|
2010-07-15 15:05:39 +00:00
|
|
|
GtkTreeIter
|
|
|
|
ws_combo_box_append_text_and_pointer(GtkComboBox *combo_box,
|
|
|
|
const gchar *text,
|
|
|
|
const gpointer ptr)
|
2010-07-13 00:17:08 +00:00
|
|
|
{
|
2010-07-15 15:05:39 +00:00
|
|
|
return ws_combo_box_append_text_and_pointer_full(combo_box, NULL, text, ptr, TRUE);
|
2010-07-13 00:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-22 18:39:55 +00:00
|
|
|
/**
|
|
|
|
* ws_combo_box_get_active_pointer:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
|
|
|
* @param ptr A pointer to a location in which to store the pointer associated with the active entry
|
|
|
|
* @return TRUE if an entry is selected (i.e: an active entry exists); FALSE otherwise
|
|
|
|
*
|
|
|
|
* You can only use this function with combo boxes constructed with
|
|
|
|
* ws_combo_box_new_text_and_pointer().
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ws_combo_box_get_active_pointer(GtkComboBox *combo_box, gpointer *ptr)
|
|
|
|
{
|
2010-07-15 15:05:39 +00:00
|
|
|
GtkTreeStore *store;
|
2010-02-22 18:39:55 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
*ptr = NULL;
|
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter(combo_box, &iter)) {
|
2010-07-15 15:05:39 +00:00
|
|
|
store = GTK_TREE_STORE(gtk_combo_box_get_model(combo_box));
|
2010-07-28 13:34:41 +00:00
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
|
2010-02-22 18:39:55 +00:00
|
|
|
1, ptr, -1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ws_combo_box_get_active:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
|
|
|
* @return Index of the active entry; -1 if no entry is selected;
|
2010-07-15 15:05:39 +00:00
|
|
|
* Note: If the active item is not an immediate child of root of the tree then
|
|
|
|
* the index returned is that of the top-level for the acftive entry.
|
2010-02-22 18:39:55 +00:00
|
|
|
*/
|
|
|
|
gint
|
2010-07-28 13:34:41 +00:00
|
|
|
ws_combo_box_get_active(GtkComboBox *combo_box)
|
2010-02-22 18:39:55 +00:00
|
|
|
{
|
|
|
|
return gtk_combo_box_get_active(combo_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ws_combo_box_set_active:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
2010-08-29 13:18:58 +00:00
|
|
|
* @param idx of the entry which is to be set as active (ie: selected).
|
2010-07-15 15:05:39 +00:00
|
|
|
* Index refers to the immediate children of the tree.
|
2010-02-22 18:39:55 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ws_combo_box_set_active(GtkComboBox *combo_box, gint idx)
|
|
|
|
{
|
|
|
|
gtk_combo_box_set_active(combo_box, idx);
|
|
|
|
}
|
2010-07-15 15:05:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ws_combo_box_set_active_iter:
|
|
|
|
* @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
|
|
|
|
* @param iter of the entry which is to be set as active (ie: selected).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ws_combo_box_set_active_iter(GtkComboBox *combo_box, GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
gtk_combo_box_set_active_iter(combo_box, iter);
|
|
|
|
}
|