merge_all_tap_menus() has been moved to menus.c.
[obnox/wireshark/wip.git] / gtk / gui_utils.h
index 289118ca22d1e3ba00e88476bb3f2130e9376739..9720a2a0d6dc95260ec9683564d63b3fa51f6266 100644 (file)
@@ -22,8 +22,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-#ifndef __GTKGUIUI_UTIL_H__
-#define __GTKGUIUI_UTIL_H__
+#ifndef __GUI_UTILS_H__
+#define __GUI_UTILS_H__
 
 /** @defgroup windows_group Windows
  *
@@ -230,10 +230,25 @@ extern void set_scrollbar_placement_all(void);
 
 /** Create a GtkTreeView, give it the right styles, and remember it.
  *
- * @param model the model (the data) of this tree view
+ * @param model The model (the data) of this tree view.
  */
 extern GtkWidget *tree_view_new(GtkTreeModel *model);
 
+/** Move the currently-selected item in a list store up or down one position.
+ *
+ * @param tree GtkTreeView using a GtkListStore.
+ * @param move_up TRUE to move the selected item up or FALSE to move it down.
+ * @return TRUE if successful, FALSE otherwise.
+ */
+extern gboolean tree_view_list_store_move_selection(GtkTreeView *tree, gboolean move_up);
+
+/** Find the selected row in a list store.
+ *
+ * @param tree GtkTreeView using a GtkListStore.
+ * @return The selected row number or -1 if no row is selected.
+ */
+extern gint tree_view_list_store_get_selected_row(GtkTreeView *tree);
+
 /** Create a simple list widget.
  *
  * @param cols number of columns
@@ -280,7 +295,13 @@ extern GtkWidget *xpm_to_widget(const char ** xpm);
  * @param xpm the character array containing the picture
  * @return a newly created GtkWidget showing the picture
  */
-extern GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm);
+/*extern GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm);*/
+
+/** Convert an pixbuf data to a GtkWidget
+ *
+ * @param pb_data Inline pixbuf data. This should be created with "gdk-pixbuf-csource --raw"
+ */
+extern GtkWidget *pixbuf_to_widget(const char * pb_data);
 
 /** Copy a GString to the clipboard.
  *
@@ -303,6 +324,12 @@ extern void copy_binary_to_clipboard(const guint8* data_p, int len);
  */
 extern gchar *create_user_window_title(const gchar *caption);
 
+/** 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 window's title bar and in its icon title
+ */
+extern void update_main_window_title(void);
+
 /** Renders a float with two decimals precission, called from gtk_tree_view_column_set_cell_data_func().
  * the user data must be the colum number.
  * Present floats with two decimals 
@@ -326,6 +353,17 @@ void float_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkT
  */
 void present_as_hex_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
 
+/** Renders an unsigned 64 bits integer with space as thousand separator, called from gtk_tree_view_column_set_cell_data_func()
+ * The user data must be the colum number.
+ * Present value as hexadecimal. 
+ * @param column A GtkTreeColumn 
+ * @param renderer The GtkCellRenderer that is being rendered by tree_column 
+ * @param model The GtkTreeModel being rendered 
+ * @param iter A GtkTreeIter of the current row rendered 
+ * @param user_data must be the colum number to fetch the data from
+ */
+void u64_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
+
 /** This function can be called from gtk_tree_view_column_set_cell_data_func()
  * the user data must be the colum number.
  * Present value as hexadecimal. 
@@ -347,10 +385,154 @@ void str_ptr_data_func(GtkTreeViewColumn *column, GtkCellRenderer *renderer, Gtk
  */
 
 gint str_ptr_sort_func(GtkTreeModel *model,
-                                                       GtkTreeIter *a,
-                                                       GtkTreeIter *b,
-                                                       gpointer user_data);
-
-
-
-#endif /* __GTKGUIUI_UTIL_H__ */
+                       GtkTreeIter  *a,
+                       GtkTreeIter  *b,
+                       gpointer      user_data);
+
+/** Switch a GtkTReeView to fixed columns (speed optimization)
+ * @param view A GtkTreeView 
+ */
+void switch_to_fixed_col(GtkTreeView *view);
+
+/** Return the size in pixels of a string displayed with the GtkWidget's font.
+ * @param view A GtkWidget
+ * @param str UTF8 string 
+ */
+gint get_default_col_size(GtkWidget *view, const gchar *str);
+
+
+/** --------------------------------------------------
+ * ws_combo_box_text_and_pointer convenience functions
+ *  (Code adapted from GtkComboBox.c)
+ */
+
+/**
+ * ws_combo_box_new_text_and_pointer_full:
+ *
+ * Convenience function which constructs a new "text and pointer" combo box, which
+ * 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. 
+ * Also: optionally returns the cell renderer for the combo box.
+ * 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()
+ *
+ * @param cell_p  pointer to return the 'GtkCellRenderer *' for the combo box (or NULL).
+ * @return A pointer to a new text_and_pointer combo_box.
+ */
+GtkWidget *ws_combo_box_new_text_and_pointer_full(GtkCellRenderer **cell_p);
+
+/**
+ * ws_combo_box_new_text_and_pointer:
+ *
+ * Convenience function which constructs a new "text and pointer" combo box, which
+ * 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. 
+ * 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);
+
+/**
+ * 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.
+ * Note: A "changed" signal will be emitted after the clear if there was 
+ * an active (selected) entry before the clear.
+ * You should use this function only with combo boxes constructed with
+ * ws_combo_box_new_text_and_pointer().
+ */
+void ws_combo_box_clear_text_and_pointer(GtkComboBox *combo_box);
+
+/**
+ * ws_combo_box_append_text_and_pointer_full:
+ * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
+ * @param parent_iter Parent row for apending; NULL if appending to tree top-level; 
+ * @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
+ * @param sensitive TRUE/FALSE to set sensitivity of the entry
+ * @return A GtkTreeIter pointing to the appended GtkVomboBox entry.
+ *
+ * Appends text and ptr to the list of strings and pointers stored in combo_box.
+ * 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
+ * ws_combo_box_new_text_and_pointer().
+ */
+GtkTreeIter
+ws_combo_box_append_text_and_pointer_full(GtkComboBox   *combo_box,
+                                          GtkTreeIter   *parent_iter,
+                                          const gchar   *text,
+                                          const gpointer ptr,
+                                          const gboolean sensitive);
+
+/**
+ * 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
+ * @return A GtkTreeIter pointing to the appended GtkComboBox entry.
+ *
+ * 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().
+ */
+GtkTreeIter
+ws_combo_box_append_text_and_pointer(GtkComboBox    *combo_box,
+                                     const gchar    *text,
+                                     const gpointer  ptr);
+
+/**
+ * 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);
+
+/**
+ * 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;
+ *         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.
+ */
+gint ws_combo_box_get_active(GtkComboBox *combo_box);
+
+/**
+ * ws_combo_box_set_active:
+ * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
+ * @param idx Index of the entry which is to be set as active (ie: selected).
+ *        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_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);
+
+#if GTK_CHECK_VERSION(2,22,0)
+#if !GTK_CHECK_VERSION(3,0,0)
+GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
+                                        gint             src_x,
+                                        gint             src_y,
+                                        gint             width,
+                                        gint             height);
+#endif
+#endif
+#endif /* __GUI_UTIL__H__ */