* and some with GUI-independent APIs, with this file containing the GTK+
* implementations of them (declared in ui_util.h)
*
- * $Id$
- *
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
+#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include "ui/gtk/gtkglobals.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/font_utils.h"
+#include "ui/gtk/color_utils.h"
#include "ui/gtk/old-gtk-compat.h"
-#include "image/wsicon16.xpm"
-#include "image/wsicon32.xpm"
-#include "image/wsicon48.xpm"
-#include "image/wsicon64.xpm"
+#include "ui/gtk/wsicon.h"
#ifdef _WIN32
#include <windows.h>
#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
part of the installation of Wireshark.
*/
static void
-window_icon_realize_cb (GtkWidget *win, gpointer data _U_)
+window_icon_realize_cb(GtkWidget *win,
+ gpointer data _U_)
{
#ifndef _WIN32
- GList *ws_icon_list=NULL;
- GdkPixbuf *icon;
-
- icon = gdk_pixbuf_new_from_xpm_data ((const char **) wsicon16_xpm);
- ws_icon_list = g_list_append (ws_icon_list, icon);
- icon = gdk_pixbuf_new_from_xpm_data ((const char **) wsicon32_xpm);
- ws_icon_list = g_list_append (ws_icon_list, icon);
- icon = gdk_pixbuf_new_from_xpm_data ((const char **) wsicon48_xpm);
- ws_icon_list = g_list_append (ws_icon_list, icon);
- icon = gdk_pixbuf_new_from_xpm_data ((const char **) wsicon64_xpm);
- ws_icon_list = g_list_append (ws_icon_list, icon);
+ GList *ws_icon_list = NULL;
+ GdkPixbuf *icon;
+
+ icon = gdk_pixbuf_new_from_inline(-1, wsicon_16_pb_data, FALSE, NULL);
+ ws_icon_list = g_list_append(ws_icon_list, icon);
+ icon = gdk_pixbuf_new_from_inline(-1, wsicon_32_pb_data, FALSE, NULL);
+ ws_icon_list = g_list_append(ws_icon_list, icon);
+ icon = gdk_pixbuf_new_from_inline(-1, wsicon_48_pb_data, FALSE, NULL);
+ ws_icon_list = g_list_append(ws_icon_list, icon);
+ icon = gdk_pixbuf_new_from_inline(-1, wsicon_64_pb_data, FALSE, NULL);
+ ws_icon_list = g_list_append(ws_icon_list, icon);
gtk_window_set_icon_list(GTK_WINDOW(win), ws_icon_list);
- g_list_foreach(ws_icon_list, (GFunc) g_object_unref, NULL);
+ g_list_foreach(ws_icon_list, (GFunc)g_object_unref, NULL);
g_list_free(ws_icon_list);
/* set icon by name, this allows us to use even SVG icon if it is present */
/* Create a new window, of the specified type, with the specified title
(if any) and the Wireshark icon. */
GtkWidget *
-window_new(GtkWindowType type, const gchar *title)
+window_new(GtkWindowType type,
+ const gchar *title)
{
GtkWidget *win;
/* a lot of people dislike GTK_WIN_POS_MOUSE */
/* set the initial position (must be done, before show is called!) */
-/* gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER_ON_PARENT);*/
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_NONE);
+ if (top_level) {
+ GdkScreen *default_screen;
+ gint x, y, n;
+
+ /* Ideally, new windows would open on the same monitor where the main
+ * window is located, but this doesn't happen when the main window is
+ * not located on the primary monitor. So, if there's more than 1
+ * monitor and Wireshark's main window isn't located on the primary
+ * one, attempt to improve the situation by at least displaying the new
+ * window somewhere on the same monitor, even if it won't be positioned
+ * the same way as it would be when it's on the primary monitor. Don't
+ * attempt to influence the placement on the primary monitor though,
+ * because that's probably the preferred placement strategy. But how
+ * to make window placement behave the same way on any monitor?
+ */
+ default_screen = gdk_screen_get_default();
+ n = gdk_screen_get_n_monitors(default_screen);
+ if (n > 1) {
+ gtk_window_get_position(GTK_WINDOW(top_level), &x, &y);
+ n = gdk_screen_get_monitor_at_point(default_screen, x, y);
+ if (n > 0)
+ gtk_window_move(GTK_WINDOW(win), x + 40, y + 30);
+ }
+ }
+
return win;
}
/* Same as window_new(), but will keep its geometry values (size, position, ...).
* Be sure to use window_present() and window_destroy() appropriately! */
GtkWidget *
-window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name)
+window_new_with_geom(GtkWindowType type,
+ const gchar *title,
+ const gchar *geom_name,
+ GtkWindowPosition pos)
{
window_geometry_t geom;
GtkWidget *win = window_new(type, title);
geom.set_size = TRUE;
geom.set_maximized = FALSE; /* don't maximize until window is shown */
window_set_geometry(win, &geom);
+ } else if (pos != GTK_WIN_POS_NONE) {
+#ifdef _WIN32
+ /* Testing using GTK+ 2.24.10 shows that
+ * GTK_WIN_POS_CENTER_ON_PARENT doesn't seem to work on Windows, so
+ * use the next best thing. Is this a problem for all OS's though,
+ * or just Windows? Unknown. (Tested with Windows XP SP3 32-bit)
+ */
+ if (pos == GTK_WIN_POS_CENTER_ON_PARENT)
+ pos = GTK_WIN_POS_CENTER;
+#endif
+ gtk_window_set_position(GTK_WINDOW(win), pos);
}
}
void
window_present(GtkWidget *win)
{
- window_geometry_t geom;
- const gchar *name;
+ 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);
+ name = (const gchar *)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? */
static gboolean
-window_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button)
+window_key_press_cb(GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer cancel_button)
{
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
+ 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));
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)
+window_set_cancel(GtkWidget *widget,
+ GtkWidget *cancel_button)
{
g_signal_connect(widget, "key_press_event", G_CALLBACK(window_key_press_cb), cancel_button);
}
/* 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)
+void
+window_set_cancel_button(GtkWidget *win,
+ GtkWidget *bt,
+ window_cancel_button_fct cb)
{
if(cb)
g_signal_connect(bt, "clicked", G_CALLBACK(cb), win);
/* default callback handler for cancel button "clicked" signal */
-void window_cancel_button_cb(GtkWidget *w _U_, gpointer data)
+void
+window_cancel_button_cb(GtkWidget *w _U_,
+ gpointer data)
{
window_destroy(GTK_WIDGET(data));
}
/* 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_delete_event_cb(GtkWidget *win,
+ GdkEvent *event _U_,
+ gpointer user_data _U_)
{
window_destroy(win);
/* get the geometry of a window from window_new() */
void
-window_get_geometry(GtkWidget *widget, window_geometry_t *geom)
+window_get_geometry(GtkWidget *widget,
+ window_geometry_t *geom)
{
GdkWindowState state;
GdkWindow *widget_window;
As gdk_window_get_deskrelative_origin() is deprecated it has been removed 2011-07-24.
*/
- memset (geom, 0, sizeof (window_geometry_t));
+ memset(geom, 0, sizeof(window_geometry_t));
widget_window = gtk_widget_get_window(widget);
/* XXX - Is this the "approved" method? */
#if GTK_CHECK_VERSION(2,24,0)
geom->width = gdk_window_get_width(widget_window);
- geom->height = gdk_window_get_height (widget_window);
+ geom->height = gdk_window_get_height(widget_window);
#else
gdk_drawable_get_size(widget_window,
&geom->width,
&geom->height);
#endif
state = gdk_window_get_state(widget_window);
- geom->maximized = (state == GDK_WINDOW_STATE_MAXIMIZED);
+ geom->maximized = ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0);
}
+#ifdef _WIN32
+/* Ensure Wireshark isn't obscured by the system taskbar (or other desktop toolbars).
+ * Resolves https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3034 */
+static void
+window_adjust_if_obscured(window_geometry_t *geom)
+{
+ MONITORINFO MonitorInfo;
+ HMONITOR hMonitor;
+ POINT pt, vs;
+ DWORD dwFlags = MONITOR_DEFAULTTONEAREST; /* MONITOR_DEFAULTTOPRIMARY? */
+
+ /*
+ * Get the virtual screen's top-left coordinates so we can reliably
+ * determine which monitor we're dealing with. See also:
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/dd145136%28v=vs.85%29.aspx
+ */
+ vs.x = GetSystemMetrics(SM_XVIRTUALSCREEN);
+ vs.y = GetSystemMetrics(SM_YVIRTUALSCREEN);
+ pt.x = geom->x + vs.x;
+ pt.y = geom->y + vs.y;
+ MonitorInfo.cbSize = sizeof(MONITORINFO);
+ hMonitor = MonitorFromPoint(pt, dwFlags);
+ if (GetMonitorInfo(hMonitor, &MonitorInfo)) {
+ if (pt.x < MonitorInfo.rcWork.left)
+ geom->x += MonitorInfo.rcWork.left - pt.x;
+ if (pt.y < MonitorInfo.rcWork.top)
+ geom->y += MonitorInfo.rcWork.top - pt.y;
+ }
+}
+#endif
+
/* set the geometry of a window from window_new() */
void
-window_set_geometry(GtkWidget *widget, window_geometry_t *geom)
+window_set_geometry(GtkWidget *widget,
+ window_geometry_t *geom)
{
GdkScreen *default_screen;
GdkRectangle viewable_area;
* other.
*
* If the requested (x,y) position isn't within the monitor's
- * viewable area, change it to the viewable area's (0,0). */
-
+ * viewable area, change it to the viewable area's (x,y). */
default_screen = gdk_screen_get_default();
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);
-
- if(geom->x < viewable_area.x || geom->x > viewable_area.width)
+ if(geom->x < viewable_area.x || geom->x > (viewable_area.x + viewable_area.width))
geom->x = viewable_area.x;
- if(geom->y < viewable_area.y || geom->y > viewable_area.height)
+ if(geom->y < viewable_area.y || geom->y > (viewable_area.y + viewable_area.height))
geom->y = viewable_area.y;
+ #ifdef _WIN32
+ window_adjust_if_obscured(geom);
+ #endif
+
gtk_window_move(GTK_WINDOW(widget),
geom->x,
geom->y);
}
}
-
-/* the geometry hashtable for all known window classes,
- * the window name is the key, and the geometry struct is the value */
-static GHashTable *window_geom_hash = NULL;
-
-
-/* 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 */
- geom.key = NULL; /* Will be set in window_geom_save () */
- 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 */
- }
-
- 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) {
- if (g_ascii_strcasecmp(value, "true") == 0) {
- geom.maximized = TRUE;
- }
- else {
- geom.maximized = FALSE;
- }
- geom.set_maximized = TRUE;
- } else {
- /*
- * 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;
- }
-
- /* 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)
{
- window_geometry_t geom;
- const gchar *name;
+ window_geometry_t geom;
+ const gchar *name;
if (!win)
return;
* 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_get_has_window (win) && gtk_widget_get_visible(win)) {
+ if(gtk_widget_get_has_window(win) && gtk_widget_get_visible(win)) {
window_get_geometry(win, &geom);
- name = g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY);
+ name = (const gchar *)g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY);
if(name) {
window_geom_save(name, &geom);
g_free((gpointer)name);
gtk_widget_destroy(win);
}
-#if 0
-/* Do we need this one ? */
-/* 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);
+static GtkWidget *
+_gtk_image_new_from_pixbuf_unref(GdkPixbuf *pixbuf) {
+ GtkWidget *widget;
- return gtk_image_new_from_pixmap (pixmap, bitmap);
+ widget = gtk_image_new_from_pixbuf(pixbuf);
+ g_object_unref(pixbuf);
+ return widget;
}
-#endif
/* convert an xpm to a GtkWidget */
-GtkWidget *xpm_to_widget(const char ** xpm) {
+GtkWidget *
+xpm_to_widget(const char **xpm) {
GdkPixbuf *pixbuf;
pixbuf = gdk_pixbuf_new_from_xpm_data(xpm);
- return gtk_image_new_from_pixbuf(pixbuf);
+ return _gtk_image_new_from_pixbuf_unref(pixbuf);
}
/* Convert an pixbuf data to a GtkWidget */
/* Data should be created with "gdk-pixbuf-csource --raw" */
-GtkWidget *pixbuf_to_widget(const char * pb_data) {
+GtkWidget *
+pixbuf_to_widget(const guint8 *pb_data) {
GdkPixbuf *pixbuf;
- pixbuf = gdk_pixbuf_new_from_inline (-1, pb_data, FALSE, NULL);
- return gtk_image_new_from_pixbuf(pixbuf);
+ pixbuf = gdk_pixbuf_new_from_inline(-1, pb_data, FALSE, NULL);
+ return _gtk_image_new_from_pixbuf_unref(pixbuf);
}
/*
* help?
*/
void
-bad_dfilter_alert_box(GtkWidget *parent, const char *dftext)
+bad_dfilter_alert_box(GtkWidget *parent,
+ const char *dftext,
+ gchar *err_msg)
{
GtkWidget *msg_dialog;
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"The filter expression \"%s\" isn't a valid display filter. (%s)",
- dftext, dfilter_error_msg);
+ dftext, err_msg);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
"See the help for a description of the display filter syntax.");
gtk_dialog_run(GTK_DIALOG(msg_dialog));
}
/* update the main window */
-void main_window_update(void)
-{
- while (gtk_events_pending()) gtk_main_iteration();
-}
-
-/* exit the main window */
-void main_window_exit(void)
+void
+main_window_update(void)
{
- exit(0);
+ while (gtk_events_pending())
+ gtk_main_iteration();
}
#ifdef HAVE_LIBPCAP
/* quit a nested main window */
-void main_window_nested_quit(void)
+void
+main_window_nested_quit(void)
{
if (gtk_main_level() > 0)
gtk_main_quit();
}
/* quit the main window */
-void main_window_quit(void)
+void
+main_window_quit(void)
{
gtk_main_quit();
}
-
-
typedef struct pipe_input_tag {
- gint source;
- gpointer user_data;
- int *child_process;
- pipe_input_cb_t input_cb;
- guint pipe_input_id;
+ gint source;
+ gpointer user_data;
+ ws_process_id *child_process;
+ pipe_input_cb_t input_cb;
+ guint pipe_input_id;
#ifdef _WIN32
#else
- GIOChannel *channel;
+ GIOChannel *channel;
#endif
} pipe_input_t;
static gboolean
pipe_timer_cb(gpointer data)
{
- HANDLE handle;
- DWORD avail = 0;
- gboolean result, result1;
- DWORD childstatus;
+ HANDLE handle;
+ DWORD avail = 0;
+ gboolean result;
+ DWORD childstatus;
pipe_input_t *pipe_input = data;
- gint iterations = 0;
+ gint iterations = 0;
/* try to read data from the pipe only 5 times, to avoid blocking */
/* Oddly enough although Named pipes don't work on win9x,
PeekNamedPipe does !!! */
- handle = (HANDLE) _get_osfhandle (pipe_input->source);
+ 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);
+ 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
us a message, or the sync pipe has closed, meaning the child has
closed it (perhaps because it exited). */
static gboolean
-pipe_input_cb(GIOChannel *source _U_, GIOCondition condition _U_,
- gpointer data)
+pipe_input_cb(GIOChannel *source _U_,
+ GIOCondition condition _U_,
+ gpointer data)
{
- pipe_input_t *pipe_input = data;
+ pipe_input_t *pipe_input = (pipe_input_t *)data;
/* avoid reentrancy problems and stack overflow */
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);
+ pipe_input->pipe_input_id = g_io_add_watch_full(pipe_input->channel,
+ G_PRIORITY_HIGH,
+ (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP),
+ pipe_input_cb,
+ pipe_input,
+ NULL);
}
return TRUE;
}
#endif
-void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
+void
+pipe_input_set_handler(gint source,
+ gpointer user_data,
+ ws_process_id *child_process,
+ pipe_input_cb_t input_cb)
{
static pipe_input_t pipe_input;
g_io_channel_set_encoding(pipe_input.channel, NULL, NULL);
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,
+ (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP),
pipe_input_cb,
&pipe_input,
NULL);
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)
+scrolled_window_new(GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment)
{
GtkWidget *scrollw;
static void
setup_scrolled_window(GtkWidget *scrollw)
{
- set_scrollbar_placement_scrollw(scrollw);
-
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
/* Remove a GtkScrolledWindow from the list of GtkScrolledWindows. */
static void
-forget_scrolled_window(GtkWidget *scrollw, gpointer data _U_)
+forget_scrolled_window(GtkWidget *scrollw,
+ gpointer data _U_)
{
scrolled_windows = g_list_remove(scrolled_windows, scrollw);
}
-/* Set the scrollbar placement of a GtkScrolledWindow based upon user
- preference. */
-static void
-set_scrollbar_placement_scrollw(GtkWidget *scrollw)
-{
- 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);
- }
-}
-
-static void
-set_scrollbar_placement_cb(gpointer data, gpointer user_data _U_)
-{
- set_scrollbar_placement_scrollw((GtkWidget *)data);
-}
-
-/* Set the scrollbar placement of all GtkScrolledWindows based on
- user preference. */
-void
-set_scrollbar_placement_all(void)
-{
- g_list_foreach(scrolled_windows, set_scrollbar_placement_cb, NULL);
-}
-
/* List of all CTrees/TreeViews, so we can globally set the line and
* expander style of all of them. */
static GList *trees;
/* Remove a Tree from the list of Trees. */
static void
-forget_tree(GtkWidget *tree, gpointer data _U_)
+forget_tree(GtkWidget *tree,
+ gpointer data _U_)
{
trees = g_list_remove(trees, tree);
}
}
static void
-set_tree_styles_cb(gpointer data, gpointer user_data _U_)
+set_tree_styles_cb(gpointer data,
+ gpointer user_data _U_)
{
set_tree_styles((GtkWidget *)data);
}
/* 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)
+tree_view_list_store_move_selection(GtkTreeView *tree,
+ gboolean move_up)
{
GtkTreeIter from, to;
GtkTreeModel *model;
GtkTreePath *path_from, *path_to;
sel = gtk_tree_view_get_selection(tree);
- if (! gtk_tree_selection_get_selected(sel, &model, &from)) {
+ if (!gtk_tree_selection_get_selected(sel, &model, &from)) {
return FALSE;
}
gint row;
sel = gtk_tree_view_get_selection(tree);
- if (! gtk_tree_selection_get_selected(sel, &model, &iter)) {
+ if (!gtk_tree_selection_get_selected(sel, &model, &iter)) {
return -1;
}
path_str = gtk_tree_path_to_string(path);
gtk_tree_path_free(path);
- row = (gint) strtol(path_str, NULL, 10);
+ row = (gint)strtol(path_str, NULL, 10);
g_free(path_str);
return row;
/* 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, ...)
+simple_list_append(GtkWidget *list,
+ ...)
{
va_list ap;
- GtkTreeIter iter;
+ GtkTreeIter iter;
GtkListStore *store;
va_start(ap, list);
/* create a simple list widget */
GtkWidget *
-simple_list_new(gint cols, const gchar **titles) {
- GtkWidget *plugins_list;
- int i;
- GtkListStore *store;
- GtkCellRenderer *renderer;
+simple_list_new(gint cols,
+ const gchar **titles) {
+ GtkWidget *plugins_list;
+ int i;
+ GtkListStore *store;
+ GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
return plugins_list;
}
-void render_as_url(GtkCellRenderer *cell)
+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-set", TRUE, NULL);
}
-void simple_list_url_col(GtkWidget *list, gint col)
+void
+simple_list_url_col(GtkWidget *list,
+ gint col)
{
GtkTreeViewColumn *ul_column;
GList *renderers_list;
void
copy_to_clipboard(GString *str)
{
- GtkClipboard *cb;
+ GtkClipboard *cb;
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 */
typedef struct _copy_binary_t {
- guint8* data;
- int len;
+ guint8 *data;
+ int len;
} copy_binary_t;
-static
-copy_binary_t* create_copy_binary_t(const guint8* data, int len)
+static copy_binary_t *
+create_copy_binary_t(const guint8 *data,
+ int len)
{
copy_binary_t* copy_data;
return copy_data;
}
-static void destroy_copy_binary_t(copy_binary_t* 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)
+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);
+ destroy_copy_binary_t((copy_binary_t*)user_data_or_owner);
}
-static
-void copy_binary_get_cb(GtkClipboard *clipboard _U_, GtkSelectionData *selection_data, guint info _U_, gpointer user_data_or_owner)
+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;
+ copy_data = (copy_binary_t*)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)
+void
+copy_binary_to_clipboard(const guint8 *data_p,
+ int len)
{
static GtkTargetEntry target_entry[] = {
- {"application/octet_stream", 0, 0}}; /* XXX - this not understood by most applications,
- * but can be pasted into the better hex editors - is
- * there something better that we can do?
- */
+ {(char *)"application/octet-stream", 0, 0}};
+ /* XXX - this is not understood by most applications,
+ * 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;
+ GtkClipboard *cb;
+ copy_binary_t *copy_data;
+ gboolean ret;
if(len <= 0) {
return; /* XXX would it be better to clear the clipboard? */
* XXX - should this include the user preference as well?
*/
void
-set_window_title(GtkWidget *win, const gchar *caption)
+set_window_title(GtkWidget *win,
+ const gchar *caption)
{
char *title;
char *display_name;
g_free(title);
}
+/*
+ * Collapse row and his children
+ */
+static void
+tree_collapse_row_with_children(GtkTreeView *tree_view, GtkTreeModel *model, GtkTreePath *path,
+ GtkTreeIter *iter)
+{
+ GtkTreeIter child;
+
+ if (gtk_tree_view_row_expanded(tree_view, path)) {
+ if (gtk_tree_model_iter_children(model, &child, iter)) {
+ gtk_tree_path_down(path);
+
+ do {
+
+ if (gtk_tree_view_row_expanded(tree_view, path)) {
+ tree_collapse_row_with_children(tree_view, model, path, &child);
+ }
+
+ gtk_tree_path_next(path);
+ } while (gtk_tree_model_iter_next(model, &child));
+
+ gtk_tree_path_up(path);
+
+ gtk_tree_view_collapse_row(tree_view, path);
+ }
+ }
+}
+
+void
+tree_collapse_path_all(GtkTreeView *tree_view, GtkTreePath *path)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ model = gtk_tree_view_get_model(tree_view);
+ gtk_tree_model_get_iter(model, &iter, path);
+
+ tree_collapse_row_with_children(tree_view, model, path, &iter);
+}
+
/*
* This callback is invoked when keyboard focus is within either
* the packetlist view or the detail view. The keystrokes processed
* a header cell has focus.
*/
static gboolean
-tree_view_key_pressed_cb(GtkWidget *tree, GdkEventKey *event, gpointer user_data _U_)
+tree_view_key_pressed_cb(GtkWidget *tree,
+ GdkEventKey *event,
+ gpointer user_data _U_)
{
- GtkTreeSelection* selection;
+ GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreeIter parent;
- GtkTreeModel* model;
- GtkTreePath* path;
+ GtkTreeModel *model;
+ GtkTreePath *path;
gboolean expanded, expandable;
int rc = FALSE;
return FALSE;
}
- if(!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ if(!gtk_tree_selection_get_selected(selection, &model, &iter)) {
return FALSE;
}
case GDK_Left:
if(expanded) {
/* Subtree is expanded. Collapse it. */
- gtk_tree_view_collapse_row(GTK_TREE_VIEW(tree), path);
+ if (event->state & GDK_SHIFT_MASK)
+ {
+ tree_collapse_row_with_children(GTK_TREE_VIEW(tree), model, path, &iter);
+ }
+ else
+ gtk_tree_view_collapse_row(GTK_TREE_VIEW(tree), path);
rc = TRUE;
break;
}
columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
list = columns;
while(columns) {
- column = columns->data;
- size = gtk_tree_view_column_get_width (column);
+ column = (GtkTreeViewColumn *)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);
}
gint
-get_default_col_size(GtkWidget *view, const gchar *str)
+get_default_col_size(GtkWidget *view,
+ const gchar *str)
{
PangoLayout *layout;
gint col_width;
/*
* This function can be called from gtk_tree_view_column_set_cell_data_func()
- * the user data must be the colum number.
+ * the user data must be the column number.
* Present floats with two decimals
*/
void
-float_data_func (GtkTreeViewColumn *column _U_,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
+float_data_func(GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
gfloat float_val;
gchar buf[20];
gtk_tree_model_get(model, iter, float_col, &float_val, -1);
/* save the current locale */
- savelocale = setlocale(LC_NUMERIC, NULL);
+ savelocale = g_strdup(setlocale(LC_NUMERIC, NULL));
/* switch to "C" locale to avoid problems with localized decimal separators
* in g_snprintf("%f") functions
*/
g_snprintf(buf, sizeof(buf), "%.2f", float_val);
/* restore previous locale setting */
setlocale(LC_NUMERIC, savelocale);
+ g_free(savelocale);
g_object_set(renderer, "text", buf, NULL);
}
/*
* This function can be called from gtk_tree_view_column_set_cell_data_func()
- * the user data must be the colum number.
+ * the user data must be the column number.
* Present value as hexadecimal.
*/
void
-present_as_hex_func (GtkTreeViewColumn *column _U_,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
+present_as_hex_func(GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
guint val;
gchar buf[35];
}
void
-u64_data_func (GtkTreeViewColumn *column _U_,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
+u64_data_func(GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
guint64 val;
int i = 0;
* Renders the const static string whose pointer is stored.
*/
void
-str_ptr_data_func (GtkTreeViewColumn *column _U_,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
+str_ptr_data_func(GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
const gchar *str = NULL;
gint
str_ptr_sort_func(GtkTreeModel *model,
- GtkTreeIter *a,
- GtkTreeIter *b,
- gpointer user_data)
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data)
{
const gchar *str_a = NULL;
const gchar *str_b = NULL;
*/
store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
- combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL (store));
+ 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);
* 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
+ * @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)
+ws_combo_box_get_active_pointer(GtkComboBox *combo_box,
+ gpointer *ptr)
{
GtkTreeStore *store;
GtkTreeIter iter;
* Index refers to the immediate children of the tree.
*/
void
-ws_combo_box_set_active(GtkComboBox *combo_box, gint idx)
+ws_combo_box_set_active(GtkComboBox *combo_box,
+ gint idx)
{
gtk_combo_box_set_active(combo_box, idx);
}
#if GTK_CHECK_VERSION(2,22,0)
#if !GTK_CHECK_VERSION(3,0,0)
static cairo_format_t
-gdk_cairo_format_for_content (cairo_content_t content)
+gdk_cairo_format_for_content(cairo_content_t content)
{
- switch (content)
+ switch (content)
{
case CAIRO_CONTENT_COLOR:
- return CAIRO_FORMAT_RGB24;
+ return CAIRO_FORMAT_RGB24;
case CAIRO_CONTENT_ALPHA:
- return CAIRO_FORMAT_A8;
+ return CAIRO_FORMAT_A8;
case CAIRO_CONTENT_COLOR_ALPHA:
default:
- return CAIRO_FORMAT_ARGB32;
+ return CAIRO_FORMAT_ARGB32;
}
}
static cairo_surface_t *
-gdk_cairo_surface_coerce_to_image (cairo_surface_t *surface,
- cairo_content_t content,
- int src_x,
- int src_y,
- int width,
- int height)
+gdk_cairo_surface_coerce_to_image(cairo_surface_t *surface,
+ cairo_content_t content,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
{
- cairo_surface_t *copy;
- cairo_t *cr;
+ cairo_surface_t *copy;
+ cairo_t *cr;
- copy = cairo_image_surface_create (gdk_cairo_format_for_content (content),
- width,
- height);
+ copy = cairo_image_surface_create(gdk_cairo_format_for_content(content),
+ width,
+ height);
- cr = cairo_create (copy);
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_surface (cr, surface, -src_x, -src_y);
- cairo_paint (cr);
- cairo_destroy (cr);
+ cr = cairo_create(copy);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_surface(cr, surface, -src_x, -src_y);
+ cairo_paint(cr);
+ cairo_destroy(cr);
- return copy;
+ return copy;
}
static void
-convert_alpha (guchar *dest_data,
- int dest_stride,
- guchar *src_data,
- int src_stride,
- int src_x,
- int src_y,
- int width,
- int height)
-{
- int x, y;
-
- src_data += src_stride * src_y + src_x * 4;
-
- for (y = 0; y < height; y++) {
- guint32 *src = (guint32 *) src_data;
-
- for (x = 0; x < width; x++) {
- guint alpha = src[x] >> 24;
-
- if (alpha == 0)
- {
- dest_data[x * 4 + 0] = 0;
- dest_data[x * 4 + 1] = 0;
- dest_data[x * 4 + 2] = 0;
- }
- else
- {
- dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
- dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
- dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+convert_alpha(guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ int x, y;
+
+ src_data += src_stride * src_y + src_x * 4;
+
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *)src_data;
+
+ for (x = 0; x < width; x++) {
+ guint alpha = src[x] >> 24;
+
+ if (alpha == 0)
+ {
+ dest_data[x * 4 + 0] = 0;
+ dest_data[x * 4 + 1] = 0;
+ dest_data[x * 4 + 2] = 0;
+ }
+ else
+ {
+ dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ }
+ dest_data[x * 4 + 3] = alpha;
}
- dest_data[x * 4 + 3] = alpha;
- }
- src_data += src_stride;
- dest_data += dest_stride;
- }
+ src_data += src_stride;
+ dest_data += dest_stride;
+ }
}
static void
-convert_no_alpha (guchar *dest_data,
- int dest_stride,
- guchar *src_data,
- int src_stride,
- int src_x,
- int src_y,
- int width,
- int height)
-{
- int x, y;
-
- src_data += src_stride * src_y + src_x * 4;
-
- for (y = 0; y < height; y++) {
- guint32 *src = (guint32 *) src_data;
-
- for (x = 0; x < width; x++) {
- dest_data[x * 3 + 0] = src[x] >> 16;
- dest_data[x * 3 + 1] = src[x] >> 8;
- dest_data[x * 3 + 2] = src[x];
- }
+convert_no_alpha(guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ int x, y;
+
+ src_data += src_stride * src_y + src_x * 4;
+
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *)src_data;
+
+ for (x = 0; x < width; x++) {
+ dest_data[x * 3 + 0] = src[x] >> 16;
+ dest_data[x * 3 + 1] = src[x] >> 8;
+ dest_data[x * 3 + 2] = src[x];
+ }
- src_data += src_stride;
- dest_data += dest_stride;
- }
+ src_data += src_stride;
+ dest_data += dest_stride;
+ }
}
/**
* count of 1, or %NULL on error
*/
GdkPixbuf *
-gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
- gint src_x,
- gint src_y,
- gint width,
- gint height)
-{
- cairo_content_t content;
- GdkPixbuf *dest;
-
- /* General sanity checks */
- g_return_val_if_fail (surface != NULL, NULL);
- g_return_val_if_fail (width > 0 && height > 0, NULL);
-
- content = cairo_surface_get_content (surface) | CAIRO_CONTENT_COLOR;
- dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
- !!(content & CAIRO_CONTENT_ALPHA),
- 8,
- width, height);
-
- surface = gdk_cairo_surface_coerce_to_image (surface, content,
- src_x, src_y,
- width, height);
- cairo_surface_flush (surface);
- if (cairo_surface_status (surface) || dest == NULL)
+gdk_pixbuf_get_from_surface(cairo_surface_t *surface,
+ gint src_x,
+ gint src_y,
+ gint width,
+ gint height)
+{
+ cairo_content_t content;
+ GdkPixbuf *dest;
+
+ /* General sanity checks */
+ g_return_val_if_fail(surface != NULL, NULL);
+ g_return_val_if_fail(width > 0 && height > 0, NULL);
+
+ content = (cairo_content_t)(cairo_surface_get_content(surface) | CAIRO_CONTENT_COLOR);
+ dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+ !!(content & CAIRO_CONTENT_ALPHA),
+ 8,
+ width, height);
+
+ surface = gdk_cairo_surface_coerce_to_image(surface, content,
+ src_x, src_y,
+ width, height);
+ cairo_surface_flush(surface);
+ if (cairo_surface_status(surface) || dest == NULL)
{
- cairo_surface_destroy (surface);
- return NULL;
+ cairo_surface_destroy(surface);
+ return NULL;
}
- if (gdk_pixbuf_get_has_alpha (dest))
- convert_alpha (gdk_pixbuf_get_pixels (dest),
- gdk_pixbuf_get_rowstride (dest),
- cairo_image_surface_get_data (surface),
- cairo_image_surface_get_stride (surface),
- 0, 0,
- width, height);
- else
- convert_no_alpha (gdk_pixbuf_get_pixels (dest),
- gdk_pixbuf_get_rowstride (dest),
- cairo_image_surface_get_data (surface),
- cairo_image_surface_get_stride (surface),
+ if (gdk_pixbuf_get_has_alpha(dest))
+ convert_alpha(gdk_pixbuf_get_pixels(dest),
+ gdk_pixbuf_get_rowstride(dest),
+ cairo_image_surface_get_data(surface),
+ cairo_image_surface_get_stride(surface),
0, 0,
width, height);
+ else
+ convert_no_alpha(gdk_pixbuf_get_pixels(dest),
+ gdk_pixbuf_get_rowstride(dest),
+ cairo_image_surface_get_data(surface),
+ cairo_image_surface_get_stride(surface),
+ 0, 0,
+ width, height);
- cairo_surface_destroy (surface);
- return dest;
+ cairo_surface_destroy(surface);
+ return dest;
}
#endif /* !GTK_CHECK_VERSION(3,0,0) */
#endif /* GTK_CHECK_VERSION(2,22,0) */
-GtkWidget * ws_gtk_box_new(GtkOrientation orientation, gint spacing, gboolean homogeneous)
+GtkWidget *
+ws_gtk_box_new(GtkOrientation orientation,
+ gint spacing,
+ gboolean homogeneous)
{
#if !GTK_CHECK_VERSION(3,0,0)
if (orientation == GTK_ORIENTATION_HORIZONTAL)
}
#if !GTK_CHECK_VERSION(3,0,0)
-GtkWidget * gtk_button_box_new(GtkOrientation orientation)
+GtkWidget *
+gtk_button_box_new(GtkOrientation orientation)
{
- if (orientation == GTK_ORIENTATION_HORIZONTAL){
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
return gtk_hbutton_box_new();
- }else{
+ } else {
return gtk_vbutton_box_new();
}
}
-GtkWidget * gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment *adjustment)
+GtkWidget *
+gtk_scrollbar_new(GtkOrientation orientation,
+ GtkAdjustment *adjustment)
{
- if (orientation == GTK_ORIENTATION_HORIZONTAL){
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
return gtk_hscrollbar_new(adjustment);
- }else{
+ } else {
return gtk_vscrollbar_new(adjustment);
}
}
-GtkWidget * gtk_paned_new(GtkOrientation orientation)
+GtkWidget *
+gtk_paned_new(GtkOrientation orientation)
{
- if (orientation == GTK_ORIENTATION_HORIZONTAL){
+ if(orientation == GTK_ORIENTATION_HORIZONTAL) {
return gtk_hpaned_new();
- }else{
+ } else {
return gtk_vpaned_new();
}
}
-GtkWidget * gtk_separator_new (GtkOrientation orientation)
+GtkWidget *
+gtk_separator_new(GtkOrientation orientation)
{
- if (orientation == GTK_ORIENTATION_HORIZONTAL){
- return gtk_hseparator_new ();
- }else{
- return gtk_vseparator_new ();
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ return gtk_hseparator_new();
+ } else {
+ return gtk_vseparator_new();
}
}
#endif /* GTK_CHECK_VERSION(3,0,0) */
+
+GtkWidget *
+frame_new(const gchar *title) {
+ GtkWidget *frame, *frame_lb;
+ GString *mu_title = g_string_new("");
+
+ frame = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
+ if (title) {
+#if defined(_WIN32) || defined(__APPLE__)
+ g_string_printf(mu_title, "%s", title);
+#else
+ g_string_printf(mu_title, "<b>%s</b>", title);
+#endif
+ frame_lb = gtk_label_new(NULL);
+ gtk_label_set_markup(GTK_LABEL(frame_lb), mu_title->str);
+ gtk_frame_set_label_widget(GTK_FRAME(frame), frame_lb);
+ }
+ g_string_free(mu_title, TRUE);
+
+ return frame;
+}
+
+
+/* ---------------------------------
+ * ws_gtk_grid...() wrappers
+ * See gui_utils.h
+ */
+
+#if !GTK_CHECK_VERSION(3,0,0)
+#else /* GTK3 */
+
+void
+ws_gtk_grid_attach_defaults(GtkGrid *grid, GtkWidget *child, gint left, gint top, gint width, gint height)
+{
+ /* Use defaults for [x|y]options and [x|y]padding which match those for gtk_table_attach_defaults() */
+ ws_gtk_grid_attach_extended(grid, child, left, top, width, height,
+ (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0);
+}
+
+void
+ws_gtk_grid_attach_extended(GtkGrid *grid, GtkWidget *child,
+ gint left, gint top, gint width, gint height,
+ GtkAttachOptions xoptions, GtkAttachOptions yoptions,
+ guint xpadding, guint ypadding)
+{
+ gtk_grid_attach(grid, child, left, top, width, height);
+
+ /* XXX: On Gtk3, there's Some trickyness about EXPAND which I probably don't
+ * really understand.
+ * It seems that:
+ * Default for EXPAND is "not set".
+ * In this case "computed expand" based on any child(ren) of this widget will
+ * affect this widget.
+ * If EXPAND is set (either TRUE or FALSE) then the value overrides any effect
+ * from children.
+ */
+
+ /* Note: widget defaults are FALSE */
+ if (xoptions & GTK_EXPAND)
+ gtk_widget_set_hexpand(child, TRUE);
+ if (yoptions & GTK_EXPAND)
+ gtk_widget_set_vexpand(child, TRUE);
+
+ /* Note: widget default is GTK_FILL */
+ /* XXX: Is an 'align' ignored if the corresponding 'fill; is FALSE ? */
+ /* XXX: don't set FILL(since is dedault) but just clear if not set ?? */
+ /* ToDo: review effect of explicit set/clear vs explict clear only */
+ gtk_widget_set_halign(child, (xoptions & GTK_FILL) ? GTK_ALIGN_FILL : GTK_ALIGN_CENTER);
+ gtk_widget_set_valign(child, (yoptions & GTK_FILL) ? GTK_ALIGN_FILL : GTK_ALIGN_CENTER);
+
+ if (xpadding != 0) {
+ gtk_widget_set_margin_left(child, xpadding);
+ gtk_widget_set_margin_right(child, xpadding);
+ }
+ if (ypadding != 0) {
+ gtk_widget_set_margin_top(child, ypadding);
+ gtk_widget_set_margin_bottom(child, ypadding);
+ }
+}
+
+void
+ws_gtk_grid_set_homogeneous(GtkGrid *grid, gboolean homogeneous)
+{
+ gtk_grid_set_row_homogeneous(grid, homogeneous);
+ gtk_grid_set_column_homogeneous(grid, homogeneous);
+}
+#endif /* !GTK_CHECK_VERSION(3,0,0) */
+
+/*
+ * Wrap gdk_cairo_set_source_color() with the GTK 3 equivalent
+ * to be used in GTK2
+ */
+#if !GTK_CHECK_VERSION(3,0,0)
+void
+gdk_cairo_set_source_rgba(cairo_t *cr, const GdkRGBA *rgba)
+{
+ GdkColor color;
+
+ gdkRGBAcolor_to_GdkColor(&color, rgba);
+
+ gdk_cairo_set_source_color(cr, &color);
+
+}
+#endif /* GTK_CHECK_VERSION(3,0,0) */
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */