2 * GTK-related Global defines, etc.
4 * $Id: compat_macros.h,v 1.20 2004/06/17 16:35:23 ulfl Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #ifndef __COMPAT_MACROS_H__
26 #define __COMPAT_MACROS_H__
31 * Helper macros for gtk1.x / gtk2.x compatibility. Use these macros instead of the GTK deprecated functions,
32 * to keep compatibility between GTK 1.x and 2.x.
33 * For example in gtk2.x, gtk_signal_xxx is deprecated in favor of g_signal_xxx,
34 * gtk_object_xxx is deprecated in favor of g_object_xxx,
35 * gtk_widget_set_usize is deprecated in favor of
36 * gtk_widget_set_size_request, ...
39 #if GTK_MAJOR_VERSION < 2
41 /** Connect a signal handler to a particular object.
43 * @param widget the widget to connect to
44 * @param name name of the signal
45 * @param callback function pointer to attach to the signal
46 * @param arg value to pass to your function
47 * @return the connection id
49 #define SIGNAL_CONNECT(widget, name, callback, arg) \
50 gtk_signal_connect(GTK_OBJECT(widget), name, GTK_SIGNAL_FUNC(callback), \
53 /** This function is for registering a callback that will call another object's callback.
54 * That is, instead of passing the object which is responsible for the event as the first
55 * parameter of the callback, it is switched with the user data (so the object which emits
56 * the signal will be the last parameter, which is where the user data usually is).
58 * @param widget the widget to connect to
59 * @param name name of the signal
60 * @param callback function pointer to attach to the signal
61 * @param arg the object to pass as the first parameter to func
62 * @return the connection id
64 #define SIGNAL_CONNECT_OBJECT(widget, name, callback, arg) \
65 gtk_signal_connect_object(GTK_OBJECT(widget), name, GTK_SIGNAL_FUNC(callback), \
68 /** Destroys all connections for a particular object, with the given
69 * function-pointer and user-data.
71 * @param object the object which emits the signal
72 * @param func the function pointer to search for
73 * @param data the user data to search for
75 #define SIGNAL_DISCONNECT_BY_FUNC(object, func, data) \
76 gtk_signal_disconnect_by_func(GTK_OBJECT(object), func, data)
78 /** Each object carries around a table of associations from strings to pointers,
79 * this function lets you set an association. If the object already had an
80 * association with that name, the old association will be destroyed.
82 * @param widget object containing the associations
83 * @param key name of the key
84 * @param data data to associate with that key
86 #define OBJECT_SET_DATA(widget, key, data) \
87 gtk_object_set_data(GTK_OBJECT(widget), key, (gpointer)data)
89 /** Get a named field from the object's table of associations (the object_data).
91 * @param widget object containing the associations
92 * @param key name of the key
93 * @return the data if found, or NULL if no such data exists
95 #define OBJECT_GET_DATA(widget, key) \
96 gtk_object_get_data(GTK_OBJECT(widget), key)
98 /** Sets the size of a widget. This will be useful to set the size of
99 * e.g. a GtkEntry. Don't use WIDGET_SET_SIZE() to set the size of a dialog
100 * or window, use gtk_window_set_default_size() for that purpose!
102 * @param widget a GtkWidget
103 * @param width new width, or -1 to unset
104 * @param height new height, or -1 to unset
105 * @todo WIDGET_SET_SIZE would better be named WIDGET_SET_MIN_SIZE
107 #define WIDGET_SET_SIZE(widget, width, height) \
108 gtk_widget_set_usize(GTK_WIDGET(widget), width, height)
110 /** Emits a signal. This causes the default handler and user-connected
111 * handlers to be run.
113 * @param widget the object that emits the signal
114 * @param name the name of the signal
115 * @param arg value to pass to the handlers or NULL
117 #define SIGNAL_EMIT_BY_NAME(widget, name, arg) \
118 gtk_signal_emit_by_name(GTK_OBJECT(widget), name, arg)
120 /** This function aborts a signal's current emission. It will prevent the
121 * default method from running, if the signal was GTK_RUN_LAST and you
122 * connected normally (i.e. without the "after" flag). It will print a
123 * warning if used on a signal which isn't being emitted. It will lookup the
126 * @param widget the object whose signal handlers you wish to stop
127 * @param name the signal identifier, as returned by g_signal_lookup()
129 #define SIGNAL_EMIT_STOP_BY_NAME(widget, name) \
130 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), name)
132 /** An entry for a GtkItemFactoryEntry array.
134 * @param path the path to this entry (e.g. "/File/Open")
135 * @param accelerator accelerator key (e.g. "<control>M") or NULL
136 * @param callback function to be called, when item is activated or NULL
137 * @param action the action number to use (usually 0)
138 * @param type special item type (e.g. "<Branch>", "<CheckItem>", ...) or NULL
139 * @param data data to pass to the callback function or NULL
141 #define ITEM_FACTORY_ENTRY(path, accelerator, callback, action, type, data) \
142 {path, accelerator, GTK_MENU_FUNC(callback), action, type}
144 /** Like ITEM_FACTORY_ENTRY(), but using a stock icon (as data)
145 * @param path the path to this entry (e.g. "/File/Open")
146 * @param accelerator accelerator key (e.g. "<control>M") or NULL
147 * @param callback function to be called, when item is activated or NULL
148 * @param action the action number to use (usually 0)
149 * @param data the stock item id (e.g. GTK_STOCK_OK, unused by GTK1)
151 #define ITEM_FACTORY_STOCK_ENTRY(path, accelerator, callback, action, data) \
152 {path, accelerator, GTK_MENU_FUNC(callback), action, NULL}
154 #define GTK_STOCK_APPLY "Apply"
155 #define GTK_STOCK_CANCEL "Cancel"
156 #define GTK_STOCK_CLEAR "Clear"
157 #define GTK_STOCK_CLOSE "Close"
158 #define GTK_STOCK_COPY "Copy"
159 #define GTK_STOCK_DELETE "Delete"
160 #define GTK_STOCK_FIND "Find"
161 #define GTK_STOCK_GO_BACK "Back"
162 #define GTK_STOCK_GO_DOWN "Down"
163 #define GTK_STOCK_GO_FORWARD "Next"
164 #define GTK_STOCK_GO_UP "Up"
165 #define GTK_STOCK_GOTO_BOTTOM "Bottom"
166 #define GTK_STOCK_GOTO_TOP "Top"
167 #define GTK_STOCK_HELP "Help"
168 #define GTK_STOCK_JUMP_TO "GoTo"
169 #define GTK_STOCK_NEW "New"
170 #define GTK_STOCK_NO "No"
171 #define GTK_STOCK_OK "OK"
172 #define GTK_STOCK_OPEN "Open"
173 #define GTK_STOCK_PRINT "Print"
174 #define GTK_STOCK_PROPERTIES "Properties"
175 #define GTK_STOCK_REFRESH "Reload"
176 #define GTK_STOCK_REVERT_TO_SAVED "Revert"
177 #define GTK_STOCK_SAVE "Save"
178 #define GTK_STOCK_SAVE_AS "Save As"
179 #define GTK_STOCK_SELECT_COLOR "Color"
180 #define GTK_STOCK_SELECT_FONT "Font"
181 #define GTK_STOCK_STOP "Stop"
182 #define GTK_STOCK_YES "Yes"
183 #define GTK_STOCK_ZOOM_IN "Zoom In"
184 #define GTK_STOCK_ZOOM_OUT "Zoom Out"
185 #define GTK_STOCK_ZOOM_100 "Zoom 100%"
188 #define ETHEREAL_STOCK_CAPTURE_START "New"
189 #define ETHEREAL_STOCK_CAPTURE_FILTER "CFilter"
190 #define ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY "Capture Filter:"
192 #define ETHEREAL_STOCK_DISPLAY_FILTER "Filter"
193 #define ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY "Filter:"
194 #define ETHEREAL_STOCK_PREFS "Prefs"
195 #define ETHEREAL_STOCK_BROWSE "Browse"
196 #define ETHEREAL_STOCK_CREATE_STAT "Create Stat"
197 #define ETHEREAL_STOCK_EXPORT "Export..."
198 #define ETHEREAL_STOCK_IMPORT "Import..."
199 #define ETHEREAL_STOCK_EDIT "Edit..."
200 #define ETHEREAL_STOCK_ADD_EXPRESSION "Add Expression..."
202 /** Create a stock button. Will create a "normal" button for GTK1.
204 * @param stock_id the stock id for this button (e.g. GTK_STOCK_OK)
205 * @return the new button
207 #define BUTTON_NEW_FROM_STOCK(stock_id) \
208 gtk_button_new_with_label(stock_id);
210 /** Create a check button.
212 * @param label_text the text to display
213 * @param accel_group accelerator group (GTK1 only)
214 * @return the new check button
216 #define CHECK_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
217 dlg_check_button_new_with_label_with_mnemonic(label_text, accel_group)
219 /** Create a radio button.
221 * @param radio_group group the radio buttons (another radio button or NULL for first one)
222 * @param label_text the text to display
223 * @param accel_group accelerator group (GTK1 only)
224 * @return the new radio button
226 #define RADIO_BUTTON_NEW_WITH_MNEMONIC(radio_group, label_text, accel_group) \
227 dlg_radio_button_new_with_label_with_mnemonic( \
228 radio_group ? gtk_radio_button_group(GTK_RADIO_BUTTON(radio_group)) : NULL, \
229 label_text, accel_group)
231 /** Create a toggle button.
233 * @param label_text the text to display
234 * @param accel_group accelerator group (GTK1 only)
235 * @return the new toggle button
237 #define TOGGLE_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
238 dlg_toggle_button_new_with_label_with_mnemonic(label_text, accel_group)
240 /** tag(s) start for first row of simple_dialog (and others). */
241 #define PRIMARY_TEXT_START ""
242 /** tag(s) end for first row of simple_dialog (and others). */
243 #define PRIMARY_TEXT_END ""
245 #define FONT_TYPE GdkFont
247 /*************************************************************************/
249 #else /* GTK_MAJOR_VERSION >= 2 */
251 #define SIGNAL_CONNECT(widget, name, callback, arg) \
252 g_signal_connect(G_OBJECT(widget), name, G_CALLBACK(callback), \
255 #define SIGNAL_CONNECT_OBJECT(widget, name, callback, arg) \
256 g_signal_connect_swapped(G_OBJECT(widget), name, G_CALLBACK(callback), \
259 #define SIGNAL_DISCONNECT_BY_FUNC(object, func, data) \
260 g_signal_handlers_disconnect_by_func(G_OBJECT(object), func, data)
262 #define OBJECT_SET_DATA(widget, key, data) \
263 g_object_set_data(G_OBJECT(widget), key, (gpointer)data)
265 #define OBJECT_GET_DATA(widget, key) \
266 g_object_get_data(G_OBJECT(widget), key)
268 /* WIDGET_SET_SIZE would better be named WIDGET_SET_MIN_SIZE. */
269 /* don't use WIDGET_SET_SIZE() to set the size of a dialog, */
270 /* use gtk_window_set_default_size() for that purpose! */
271 #define WIDGET_SET_SIZE(widget, width, height) \
272 gtk_widget_set_size_request(GTK_WIDGET(widget), width, height)
274 #define SIGNAL_EMIT_BY_NAME(widget, name, arg) \
275 g_signal_emit_by_name(G_OBJECT(widget), name, arg)
277 #define SIGNAL_EMIT_STOP_BY_NAME(widget, name) \
278 g_signal_stop_emission_by_name(G_OBJECT(widget), name)
280 #define ITEM_FACTORY_ENTRY(path, accelerator, callback, action, type, data) \
281 {path, accelerator, GTK_MENU_FUNC(callback), action, type, data}
283 #define ITEM_FACTORY_STOCK_ENTRY(path, accelerator, callback, action, data) \
284 {path, accelerator, GTK_MENU_FUNC(callback), action, "<StockItem>", data}
287 #define ETHEREAL_STOCK_LABEL_CAPTURE_START "_New"
288 #define ETHEREAL_STOCK_LABEL_CAPTURE_FILTER "_CFilter"
289 #define ETHEREAL_STOCK_LABEL_CAPTURE_FILTER_ENTRY "_Capture Filter:"
291 #define ETHEREAL_STOCK_LABEL_DISPLAY_FILTER "_Filter"
292 #define ETHEREAL_STOCK_LABEL_DISPLAY_FILTER_ENTRY "_Filter:"
293 #define ETHEREAL_STOCK_LABEL_PREFS "_Prefs"
294 #define ETHEREAL_STOCK_LABEL_BROWSE "" /* icon only */
295 #define ETHEREAL_STOCK_LABEL_CREATE_STAT "Create _Stat"
296 #define ETHEREAL_STOCK_LABEL_EXPORT "_Export..."
297 #define ETHEREAL_STOCK_LABEL_IMPORT "_Import..."
298 #define ETHEREAL_STOCK_LABEL_EDIT "_Edit..."
299 #define ETHEREAL_STOCK_LABEL_ADD_EXPRESSION "_Expression..." /* plus sign coming from icon */
302 #define ETHEREAL_STOCK_CAPTURE_START "Ethereal_Stock_CaptureStart"
303 #define ETHEREAL_STOCK_CAPTURE_FILTER "Ethereal_Stock_CaptureFilter"
304 #define ETHEREAL_STOCK_CAPTURE_FILTER_ENTRY "Ethereal_Stock_CaptureFilter_Entry"
306 #define ETHEREAL_STOCK_DISPLAY_FILTER "Ethereal_Stock_DisplayFilter"
307 #define ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY "Ethereal_Stock_DisplayFilter_Entry"
308 #define ETHEREAL_STOCK_PREFS "Ethereal_Stock_Prefs"
309 #define ETHEREAL_STOCK_BROWSE "Ethereal_Stock_Browse"
310 #define ETHEREAL_STOCK_CREATE_STAT "Ethereal_Stock_CreateStat"
311 #define ETHEREAL_STOCK_EXPORT "Ethereal_Stock_Export"
312 #define ETHEREAL_STOCK_IMPORT "Ethereal_Stock_Import"
313 #define ETHEREAL_STOCK_EDIT "Ethereal_Stock_Edit"
314 #define ETHEREAL_STOCK_ADD_EXPRESSION "Ethereal_Stock_Edit_Add_Expression"
316 #define BUTTON_NEW_FROM_STOCK(stock_id) \
317 gtk_button_new_from_stock(stock_id);
319 #define CHECK_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
320 gtk_check_button_new_with_mnemonic(label_text)
322 #define RADIO_BUTTON_NEW_WITH_MNEMONIC(radio_group, label_text, accel_group) \
323 gtk_radio_button_new_with_mnemonic_from_widget( \
324 radio_group ? GTK_RADIO_BUTTON(radio_group) : NULL, label_text)
326 #define TOGGLE_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
327 gtk_toggle_button_new_with_mnemonic(label_text)
329 #define PRIMARY_TEXT_START "<span weight=\"bold\" size=\"larger\">"
330 #define PRIMARY_TEXT_END "</span>"
332 #define FONT_TYPE PangoFontDescription
334 #endif /* GTK_MAJOR_VERSION */
336 #endif /* __COMPAT_MACROS_H__ */