198fb2b38916283b79309c871fb8bdfc199d3ac5
[gd/wireshark/.git] / ui / gtk / gui_utils.h
1 /* gui_utils.h
2  * Declarations of GTK+-specific UI utility routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __GUI_UTILS_H__
24 #define __GUI_UTILS_H__
25
26 #include "ui/ui_util.h"
27
28 /** @defgroup windows_group Windows
29  *
30  * There are the following toplevel windows:
31  *
32  * - @ref main_window_group
33  * - Statistic Windows (several different statistic windows)
34  *
35  * See: @ref howto_window_page for details.
36  *
37  */
38
39 /** @page howto_window_page How to develop a window / dialog
40  *
41  * Windows and dialogs are related to each other. Dialogs are special kind of windows, but they behave
42  * slightly different. A dialog sticks on its parent window; A normal window will be much more independent
43  * from its parent window. Dialogs should be used to ask or tell the user something, while windows should
44  * show data which is independent of the main window.
45  * Dialogs are created by calling dlg_window_new() which in turn will call window_new().
46  * After that, dialogs can be developed the same way as windows; all window related functions in gui_utils.h
47  * can be used for both.
48  *
49  * @section window_create Create a window
50  *
51  * A typical window / dialog will be created by the following calls:
52  *
53  * - window_new() will create a new window with default position and size,
54  *     use dlg_window_new() if you need a dialog (transient to the main window)
55  * - gtk_window_set_default_size() will set the default size of the window. Only
56  *     needed, if the initial size is not appropriate, e.g. when a scrolled_window_new() is used.
57  * - g_signal_connect(my_win, "destroy", my_destroy_cb, NULL) will create a callback if some cleanup
58  *     needs to be done after the window is destroyed, e.g. free up memory, or set the window pointer
59  *   of a singleton window (only one instance allowed, e.g. about dialog) back to zero
60  * - create and fill in the content and button widgets
61  * - gtk_widget_show_all() shows all the widgets in the window
62  * - window_present() will present the window on screen and
63  *     (if available) set previously saved position and size
64  *
65  * @section window_events Events
66  *
67  * The following events are usually interesting:
68  *
69  * - "delete_event": the window manager's "X" (e.g. upper right edge) of the window
70  *     was clicked; the default handler will call gtk_widget_destroy()
71  * - "destroy": everything is already gone; only cleanup of left over resources
72  *     can/should be done now
73  *
74  * @section window_hints Hints
75  *
76  * If you want to save size and position, be sure to call window_destroy() instead of only
77  *   gtk_widget_destroy(), so you will probably have to g_signal_connect() to the "delete_event"!
78  *
79  * Don't use gtk_widget_set_size_request() to set the size of a window;
80  *   use gtk_window_set_default_size() for that purpose!
81  *
82  * Be sure to call window_present() / window_destroy() appropriately, if you
83  *   want to have size and position of the window handled by ui_util.
84  *
85  */
86
87 /** @file
88  * Utilities for Windows and other user interface functions. See: @ref howto_window_page for details.
89  * @ingroup dialog_group
90  * @ingroup windows_group
91  */
92
93 /** @name Window Functions
94  *  @todo Move these window functions to a new file win_utils.h?
95  *  @{ */
96
97 /** Create a new window with the Wireshark icon.
98  *  If you want to create a dialog, use dlg_window_new() instead.
99  *
100  * @param type window type, typical GTK_WINDOW_TOPLEVEL
101  * @param title the title for the new window
102  * @return the newly created window
103  */
104 extern GtkWidget *window_new(GtkWindowType type, const gchar *title);
105
106 /** Same as window_new(), but will keep its geometry values (size, position, ...).
107  *  Be sure to use window_present() and window_destroy() appropriately!
108  *
109  * @param type window type, typical GTK_WINDOW_TOPLEVEL
110  * @param title the title for the new window
111  * @param geom_name the name to distinguish this window; will also be used for the recent file (don't use special chars)
112  * @param pos the initial position of the window if a previously saved geometry was not saved or found.
113  *     If the initial position does not matter, specify GTK_WIN_POS_NONE.
114  * @return the newly created window
115  */
116 extern GtkWidget *window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name, GtkWindowPosition pos);
117
118 /** Create a new splash window, with no icon or title bar.
119  *
120  * @return the newly created window
121  */
122 extern GtkWidget *splash_window_new(void);
123
124 /** Present the created window on the top of the screen. This will put the window on top and
125  * (if available) set previously saved position and size.
126  *
127  * @param win the window from window_new()
128  */
129 extern void window_present(GtkWidget *win);
130
131 /** callback function for window_set_cancel_button() */
132 typedef void (*window_cancel_button_fct) (GtkWidget *w, gpointer data);
133
134 /** Register the default cancel button "Cancel"/"Close"/"Ok" of this window.
135  *  This will set the callback function for this button, grab this button as the default one and
136  *  set the "ESC" key handler to call the callback function if key is pressed.
137  *
138  * @param win the window from window_new()
139  * @param bt the default button of this window
140  * @param cb callback function to be called, when this button is pressed
141  */
142 extern void window_set_cancel_button(GtkWidget *win, GtkWidget *bt, window_cancel_button_fct cb);
143
144 /** Remember the current window position / size and then destroy the window.
145  *  It's important to call this instead of gtk_widget_destroy() when using window_new_with_geom().
146  *
147  * @param win the window from window_new()
148  */
149 extern void window_destroy(GtkWidget *win);
150
151 /** Default callback handler for cancel button "clicked" signal.
152  *  Use this for window_set_cancel_button(), if no user specific functionality required,
153  *  will simply call window_destroy()
154  */
155 extern void window_cancel_button_cb(GtkWidget *w _U_, gpointer data);
156
157 /** Default callback handler if the window manager's X of the window was clicked (delete_event).
158  *  Use this for g_signal_connect(), if no user specific functionality required,
159  *  will simply call window_destroy()
160  */
161 extern gboolean window_delete_event_cb(GtkWidget *win, GdkEvent *event _U_, gpointer user_data _U_);
162
163 /** Get the geometry of a window.
164  *
165  * @param win the window from window_new()
166  * @param geom the current geometry values of the window; the set_xy values will not be used
167  * @todo if main uses the window_new_with_geom() to save size and such, make this function static
168  */
169 extern void window_get_geometry(GtkWidget *win, window_geometry_t *geom);
170
171 /** Set the geometry of a window.
172  *
173  * @param win the window from window_new()
174  * @param geom the new geometry values of the window
175  * @todo if main uses the window_new_with_geom() to save size and such, make this function static
176  */
177 extern void window_set_geometry(GtkWidget *win, window_geometry_t *geom);
178
179 /** Raise a top-level window and de-iconify it.
180  *  This routine is used if the user has done something to
181  *  ask that a window of a certain type be popped up when there can be only
182  *  one such window and such a window has already been popped up - we
183  *  pop up the existing one rather than creating a new one.
184  *
185  * @param win the window from window_new() to be reactivated
186  */
187 extern void reactivate_window(GtkWidget *win);
188
189 /** @} */
190
191 /** Alert box for an invalid display filter expression.
192  *
193  * @param parent parent window from which the display filter came
194  * @param dftext text of the display filter
195  * @param err_msg text of the error message for the filter
196  */
197 extern void bad_dfilter_alert_box(GtkWidget *parent, const char *dftext, gchar *err_msg);
198
199 /** Create a GtkScrolledWindow, set its scrollbar placement appropriately,
200  *  and remember it.
201  *
202  * @param hadjustment horizontal adjustment
203  * @param vadjustment vertical adjustment
204  * @return the new scrolled window
205  */
206 extern GtkWidget *scrolled_window_new(GtkAdjustment *hadjustment,
207                                GtkAdjustment *vadjustment);
208
209 /** Create a GtkTreeView, give it the right styles, and remember it.
210  *
211  * @param model The model (the data) of this tree view.
212  */
213 extern GtkWidget *tree_view_new(GtkTreeModel *model);
214
215 /** Move the currently-selected item in a list store up or down one position.
216  *
217  * @param tree GtkTreeView using a GtkListStore.
218  * @param move_up TRUE to move the selected item up or FALSE to move it down.
219  * @return TRUE if successful, FALSE otherwise.
220  */
221 extern gboolean tree_view_list_store_move_selection(GtkTreeView *tree, gboolean move_up);
222
223 /** Find the selected row in a list store.
224  *
225  * @param tree GtkTreeView using a GtkListStore.
226  * @return The selected row number or -1 if no row is selected.
227  */
228 extern gint tree_view_list_store_get_selected_row(GtkTreeView *tree);
229
230 /** Create a simple list widget.
231  *
232  * @param cols number of columns
233  * @param titles the titles of all columns
234  * @return the new simple list widget
235  */
236 extern GtkWidget *simple_list_new(gint cols, const gchar **titles);
237 /** Append a row to the simple list.
238  *
239  * @param list the list from simple_list_new()
240  * @param ... row and title, finished by -1 (e.g.: 0, "first", 1, "second", -1).
241  */
242 extern void simple_list_append(GtkWidget *list, ...);
243
244 /*** Make a column look like a url
245  *
246  * @param list the list from simple_list_new()
247  * @param col the column to make the values lookk like urls
248  */
249 extern void simple_list_url_col(GtkWidget *list, gint col);
250
251 /*** Make a cell underline to look like links
252  *
253  * @param cell the cell renderer that will show the text as a link
254  */
255
256 extern void render_as_url(GtkCellRenderer *cell);
257
258 /** Set the styles of all Trees based upon user preferences. */
259 extern void set_tree_styles_all(void);
260
261 /** Convert an xpm picture into a GtkWidget showing it.
262  * Beware: Wireshark's main window must already be visible!
263  *
264  * @param xpm the character array containing the picture
265  * @return a newly created GtkWidget showing the picture
266  */
267 extern GtkWidget *xpm_to_widget(const char ** xpm);
268
269 #if 0
270 /** Convert an xpm picture into a GtkWidget showing it.
271  * Beware: the given parent window must already be visible!
272  *
273  * @param parent the parent window of to widget to be generated
274  * @param xpm the character array containing the picture
275  * @return a newly created GtkWidget showing the picture
276  */
277 extern GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm);
278 #endif
279
280 #ifdef HAVE_GDK_GRESOURCE
281 /** Convert pixbuf data to a GtkWidget
282  *
283  * @param pb_path GResource pixbuf path.
284  */
285 extern GtkWidget *pixbuf_to_widget(const char *pb_path);
286
287 #define PIXBUF_TO_WIDGET(pb, path) \
288   pixbuf_to_widget(path)
289 #else
290  /** Convert an pixbuf data to a GtkWidget
291   *
292   * @param pb_data Inline pixbuf data. This should be created with "gdk-pixbuf-csource --raw"
293   */
294 extern GtkWidget *pixbuf_to_widget(const guint8 * pb_data);
295
296 #define PIXBUF_TO_WIDGET(pb, path) \
297   pixbuf_to_widget(pb)
298 #endif /* HAVE_GDK_GRESOURCE */
299
300 /** Copy a GString to the clipboard.
301  *
302  * @param str GString that is to be copied to the clipboard.
303  */
304 extern void copy_to_clipboard(GString *str);
305
306 /** Copy an array of bytes to the clipboard.
307  * Copies as mime-type application/octet-stream in GTK 2.
308  *
309  * @param data_p Pointer to data to be copied.
310  * @param len Number of bytes in the data to be copied.
311  */
312 extern void copy_binary_to_clipboard(const guint8* data_p, int len);
313
314 /** Create a new window title that includes user-defined preference string.
315  *
316  * @param caption string you want included in title (appended to user-defined string)
317  * @return a newly created title string including user-defined preference (if specified)
318  */
319 extern gchar *create_user_window_title(const gchar *caption);
320
321 /** Set the title of a window based on a supplied caption and the
322  * display name for the capture file.
323  *
324  * @param win the window whose title is to be set
325  * @param caption caption string for the window
326  */
327 extern void set_window_title(GtkWidget *win, const gchar *caption);
328
329 /** Collapses tree item and his expanded children
330  *
331  * @param tree_view A GtkTreeView
332  * @param path Path to the field
333  */
334 extern void tree_collapse_path_all(GtkTreeView *tree_view, GtkTreePath *path);
335
336 /** Renders a float with two decimals precission, called from gtk_tree_view_column_set_cell_data_func().
337  * the user data must be the column number.
338  * Present floats with two decimals
339  *
340  * @param column A GtkTreeColumn
341  * @param renderer The GtkCellRenderer that is being rendered by tree_column
342  * @param model The GtkTreeModel being rendered
343  * @param iter A GtkTreeIter of the current row rendered
344  * @param user_data must be the column number to fetch the data from
345  */
346 void float_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
347
348 /** Renders a unsinged integer as a hexadecimal value, called from gtk_tree_view_column_set_cell_data_func()
349  * The user data must be the column number.
350  * Present value as hexadecimal.
351  * @param column A GtkTreeColumn
352  * @param renderer The GtkCellRenderer that is being rendered by tree_column
353  * @param model The GtkTreeModel being rendered
354  * @param iter A GtkTreeIter of the current row rendered
355  * @param user_data must be the column number to fetch the data from
356  */
357 void present_as_hex_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
358
359 /** Renders an unsigned 64 bits integer with space as thousand separator, called from gtk_tree_view_column_set_cell_data_func()
360  * The user data must be the column number.
361  * Present value as hexadecimal.
362  * @param column A GtkTreeColumn
363  * @param renderer The GtkCellRenderer that is being rendered by tree_column
364  * @param model The GtkTreeModel being rendered
365  * @param iter A GtkTreeIter of the current row rendered
366  * @param user_data must be the column number to fetch the data from
367  */
368 void u64_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
369
370 /** This function can be called from gtk_tree_view_column_set_cell_data_func()
371  * the user data must be the column number.
372  * Present value as hexadecimal.
373  * @param column A GtkTreeColumn
374  * @param renderer The GtkCellRenderer that is being rendered by tree_column
375  * @param model The GtkTreeModel being rendered
376  * @param iter A GtkTreeIter of the current row rendered
377  * @param user_data must be the column number to fetch the data from
378  */
379 void str_ptr_data_func(GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
380
381 /** This function can be called from gtk_tree_sortable_set_sort_func()
382  * the user data must be the column number.
383  * Used together with str_ptr_data_func to sort the corresponding column.
384  * @param model The GtkTreeModel the comparison is within
385  * @param a A GtkTreeIter in model
386  * @param b Another GtkTreeIter in model
387  * @param user_data must be the column number to fetch the data from
388  */
389
390 gint str_ptr_sort_func(GtkTreeModel *model,
391                        GtkTreeIter  *a,
392                        GtkTreeIter  *b,
393                        gpointer      user_data);
394
395 /** Switch a GtkTReeView to fixed columns (speed optimization)
396  * @param view A GtkTreeView
397  */
398 void switch_to_fixed_col(GtkTreeView *view);
399
400 /** Return the size in pixels of a string displayed with the GtkWidget's font.
401  * @param view A GtkWidget
402  * @param str UTF8 string
403  */
404 gint get_default_col_size(GtkWidget *view, const gchar *str);
405
406
407 /** --------------------------------------------------
408  * ws_combo_box_text_and_pointer convenience functions
409  *  (Code adapted from GtkComboBox.c)
410  */
411
412 /**
413  * ws_combo_box_new_text_and_pointer_full:
414  *
415  * Convenience function which constructs a new "text and pointer" combo box, which
416  * is a #GtkComboBox just displaying strings and storing a pointer associated with
417  * each combo_box entry; The pointer can be retrieved when an entry is selected.
418  * Also: optionally returns the cell renderer for the combo box.
419  * If you use this function to create a text_and_pointer combo_box,
420  * you should only manipulate its data source with the
421  * following convenience functions:
422  *   ws_combo_box_append_text_and_pointer()
423  *   ws_combo_box_append_text_and_pointer_full()
424  *
425  * @param cell_p  pointer to return the 'GtkCellRenderer *' for the combo box (or NULL).
426  * @return A pointer to a new text_and_pointer combo_box.
427  */
428 GtkWidget *ws_combo_box_new_text_and_pointer_full(GtkCellRenderer **cell_p);
429
430 /**
431  * ws_combo_box_new_text_and_pointer:
432  *
433  * Convenience function which constructs a new "text and pointer" combo box, which
434  * is a #GtkComboBox just displaying strings and storing a pointer associated with
435  * each combo_box entry; The pointer can be retrieved when an entry is selected.
436  * If you use this function to create a text_and_pointer combo_box,
437  * you should only manipulate its data source with the
438  * following convenience functions:
439  *   ws_combo_box_append_text_and_pointer()
440  *   ws_combo_box_append_text_and_pointer_full()
441  *
442  * @return A pointer to a new text_and_pointer combo_box.
443  */
444 GtkWidget *ws_combo_box_new_text_and_pointer(void);
445
446 /**
447  * ws_combo_box_clear_text_and_pointer:
448  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
449  *
450  * Clears all the text_and_pointer entries in the text_and_pointer combo_box.
451  * Note: A "changed" signal will be emitted after the clear if there was
452  * an active (selected) entry before the clear.
453  * You should use this function only with combo boxes constructed with
454  * ws_combo_box_new_text_and_pointer().
455  */
456 void ws_combo_box_clear_text_and_pointer(GtkComboBox *combo_box);
457
458 /**
459  * ws_combo_box_append_text_and_pointer_full:
460  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
461  * @param parent_iter Parent row for apending; NULL if appending to tree top-level;
462  * @param text A string to be displayed as an entry in the dropdown list of the combo_box
463  * @param ptr  A pointer to be associated with this entry of the combo_box
464  * @param sensitive TRUE/FALSE to set sensitivity of the entry
465  * @return A GtkTreeIter pointing to the appended GtkVomboBox entry.
466  *
467  * Appends text and ptr to the list of strings and pointers stored in combo_box.
468  * The text and ptr can be appended to any existing level of the tree_store.
469  * The sensitivity of the row will be set as requested.
470  * Note that you can only use this function with combo boxes constructed with
471  * ws_combo_box_new_text_and_pointer().
472  */
473 GtkTreeIter
474 ws_combo_box_append_text_and_pointer_full(GtkComboBox   *combo_box,
475                                           GtkTreeIter   *parent_iter,
476                                           const gchar   *text,
477                                           gconstpointer  ptr,
478                                           gboolean       sensitive);
479
480 /**
481  * ws_combo_box_append_text_and_pointer:
482  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
483  * @param text A string to be displayed as an entry in the dropdown list of the combo_box
484  * @param ptr  A pointer to be associated with this entry of the combo_box
485  * @return A GtkTreeIter pointing to the appended GtkComboBox entry.
486  *
487  * Appends text and ptr to the list of strings and pointers stored in combo_box. Note that
488  * you can only use this function with combo boxes constructed with
489  * ws_combo_box_new_text_and_pointer().
490  */
491 GtkTreeIter
492 ws_combo_box_append_text_and_pointer(GtkComboBox    *combo_box,
493                                      const gchar    *text,
494                                      gconstpointer   ptr);
495
496 /**
497  * ws_combo_box_get_active_pointer:
498  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
499  * @param ptr  A pointer to a location in which to store the pointer associated with the active entry
500  * @return TRUE if an entry is selected (i.e: an active entry exists); FALSE otherwise
501  *
502  * You can only use this function with combo boxes constructed with
503  * ws_combo_box_new_text_and_pointer().
504  */
505 gboolean ws_combo_box_get_active_pointer(GtkComboBox *combo_box, gpointer *ptr);
506
507 /**
508  * ws_combo_box_get_active:
509  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
510  * @return Index of the active entry; -1 if no entry is selected;
511  *         Note: If the active item is not an immediate child of root of the tree then
512  *          the index returned is that of the top-level for the acftive entry.
513  */
514 gint ws_combo_box_get_active(GtkComboBox *combo_box);
515
516 /**
517  * ws_combo_box_set_active:
518  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
519  * @param idx Index of the entry which is to be set as active (ie: selected).
520  *        Index refers to the immediate children of the tree.
521  */
522 void ws_combo_box_set_active(GtkComboBox *combo_box, gint idx);
523
524 /**
525  * ws_combo_box_set_active_iter:
526  * @param combo_box A #GtkComboBox constructed using ws_combo_box_new_text_and_pointer()
527  * @param iter of the entry which is to be set as active (ie: selected).
528  */
529 void
530 ws_combo_box_set_active_iter(GtkComboBox *combo_box, GtkTreeIter *iter);
531
532 #ifdef HAVE_GDK_GRESOURCE
533 /**
534  * ws_gdk_pixbuf_new_from_resource:
535  * @param path A GResource path
536  * @return The GdkPixbuf object
537  */
538 GdkPixbuf *
539 ws_gdk_pixbuf_new_from_resource(const char *path);
540 #endif /* HAVE_GDK_GRESOURCE */
541
542 #if GTK_CHECK_VERSION(2,22,0)
543 #if !GTK_CHECK_VERSION(3,0,0)
544 GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
545                                         gint             src_x,
546                                         gint             src_y,
547                                         gint             width,
548                                         gint             height);
549 #endif /* GTK_CHECK_VERSION(3,0,0) */
550 #endif /* GTK_CHECK_VERSION(2,22,0) */
551
552 /**
553  * ws_gtk_box_new:
554  * @param orientation the box's orientation
555  * @param spacing the number of pixels to put between children
556  * @param homogeneous a boolean value, TRUE to create equal allotments, FALSE for variable allotments
557  */
558 GtkWidget * ws_gtk_box_new(GtkOrientation orientation, gint spacing, gboolean homogeneous);
559
560 #if !GTK_CHECK_VERSION(3,0,0)
561 typedef struct {
562   gdouble red;
563   gdouble green;
564   gdouble blue;
565   gdouble alpha;
566 } GdkRGBA;
567
568 GtkWidget * gtk_button_box_new(GtkOrientation orientation);
569 GtkWidget * gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment *adjustment);
570 GtkWidget * gtk_paned_new(GtkOrientation orientation);
571 GtkWidget * gtk_separator_new (GtkOrientation orientation);
572 void gdk_cairo_set_source_rgba(cairo_t *cr, const GdkRGBA *rgba);
573 #endif /* GTK_CHECK_VERSION(3,0,0) */
574
575 /** Create a new frame with no border and a bold title on appropriate platforms.
576  *
577  * @param title The title for the new frame
578  * @return The newly created window
579  */
580 extern GtkWidget *frame_new(const gchar *title);
581
582
583 /* GtkTable is deprecated in Gtk3 ...
584  *
585  * ws_gtk_grid...() wrapper functions & macros matching basic GtkGrid functions
586  *   have been created which can be used both on Gtk2 and Gtk3.
587  *
588  *   The functionality provided matches the fairly simple Wireshatk
589  *   Gtk2 GtkTable usage and is intended to replace same.
590  *
591  *   The ws_gtk_grid...() functionality is implemented as follows:
592  *    Gtk2: macros which effect calls to GtkTable functions
593  *          (with GTK_GRID typedef'd as GTK_TABLE & etc).
594  *    Gtk3: wrapper functions and macros which effect calls to gtk_grid...()
595  *          and other Gtk3 functions as needed.
596  *
597  *   The args to the ws_gtk_grid...() functions are identical to the corresponding
598  *    Gtk3 gtk_grid...() functions (other than ws_gtk_attach_defaults() and
599  *    ws_gtk_attach_extended() which have no gtk_grid...() equivalent).
600  *
601  *     ws_gtk_grid_new()               ;; gtk_table_new()
602  *
603  *     ws_gtk_grid_attach()            ;; gtk_table_attach( , , , , , ,0, 0, 0, 0)
604  *                                     ;;   that is: same as gtk_grid_attach()
605  *                                     ;;   Gt2/Gtk3: [h|v]expand = FALSE; (FILL ignored)
606  *
607  *     ws_gtk_grid_attach_defaults()   ;; gtk_table_attach_defaults()
608  *                                     ;;   Gtk3: sets GTK_EXPAND/GTK_FILL as default;
609  *                                     ;;         That is, the defaults used by gtk_table_attach_defaults()
610  *     ws_gtk_grid_attach_extended()   ;; gtk_table_attach()
611  *                                     ;;   Essentially gtk_grid_attach() with eadditional args
612  *                                     ;;   to specify 'options' and 'padding' [as used in gtk_table_attach()];
613  *                                     ;;   Gtk3: sets GTK_EXPAND/GTK_FILL & margins on child widgit
614  *                                     ;;         as specified.
615  *                                     ;;   (See below for declaration).
616  *     ws_gtk_grid_set_homogeneous()   ;; gtk_table_set_homogeneous()
617  *                                     ;;   Gtk3 grid: sets both 'row-homogeneous' and 'column-homogeneous'
618  *     ws_gtk_set_row_spacing()        ;; gtk_table_set_row_spacings()
619  *     ws_gtk_set_column_spacing()     ;; gtk_table_set_col_spacings()
620  *
621  *   Example: Existing Wireshark Gtk2 code:
622  *     gtk_table_attach_defaults(GTK_TABLE(foo_tb), child, col, col+1, row, row+1)
623  *
624  *   should be converted to:
625  *     ws_gtk_grid_attach_defaults(GTK_GRID(foo_grid), child, col, row, 1, 1);
626  */
627
628 #if !GTK_CHECK_VERSION(3,0,0)
629
630 typedef GtkTable GtkGrid;
631 #define GTK_GRID(x) GTK_TABLE(x)
632
633 #define ws_gtk_grid_new() \
634     gtk_table_new(0, 0, FALSE)
635
636 #define ws_gtk_grid_attach(grid, child, left, top, width, height) \
637     gtk_table_attach(grid, child, left, left+width, top, top+height, (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0)
638
639 #define ws_gtk_grid_attach_defaults(grid, child, left, top, width, height) \
640     gtk_table_attach_defaults(grid, child, left, left+width, top, top+height)
641
642 #define ws_gtk_grid_attach_extended(grid, child, left, top, width, height, xoptions, yoptions, xpadding, ypadding) \
643     gtk_table_attach(grid, child, left, left+width, top, top+height, xoptions, yoptions, xpadding, ypadding)
644
645 #define ws_gtk_grid_set_homogeneous(grid, homogeneous) \
646     gtk_table_set_homogeneous(grid, homogeneous)
647
648 #define ws_gtk_grid_set_row_spacing(grid, spacing) \
649     gtk_table_set_row_spacings(grid, spacing)
650
651 #define ws_gtk_grid_set_column_spacing(grid, spacing) \
652     gtk_table_set_col_spacings(grid, spacing)
653
654
655 #else
656 #define ws_gtk_grid_new() \
657     gtk_grid_new()
658
659
660 #define ws_gtk_grid_attach(grid, child, left, top, width, height) \
661     gtk_grid_attach(grid, child, left, top, width, height)
662
663 extern void ws_gtk_grid_attach_defaults(GtkGrid *grid, GtkWidget *child,
664                                         gint left, gint top, gint width, gint height);
665
666 extern void ws_gtk_grid_attach_extended(GtkGrid *grid, GtkWidget *child,
667                                         gint left, gint top, gint width, gint height,
668                                         GtkAttachOptions xoptions, GtkAttachOptions yoptions,
669                                         guint xpadding, guint ypadding);
670
671 extern void ws_gtk_grid_set_homogeneous(GtkGrid *grid, gboolean homogeneous);
672
673 #define ws_gtk_grid_set_row_spacing(grid, spacing) \
674     gtk_grid_set_row_spacing(grid, spacing)
675
676 #define ws_gtk_grid_set_column_spacing(grid, spacing) \
677     gtk_grid_set_column_spacing(grid, spacing)
678
679 #endif /* GTK_CHECK_VERSION(3,0,0) */
680
681
682 #endif /* __GUI_UTIL_H__ */