2 * GTK-related Global defines, etc.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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), (GtkSignalFunc)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, (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 #define SIGNAL_EMIT_BY_NAME gtk_signal_emit_by_name
114 #define SIGNAL_EMIT_OBJECT(object) GTK_OBJECT(object)
116 /** This function aborts a signal's current emission. It will prevent the
117 * default method from running, if the signal was GTK_RUN_LAST and you
118 * connected normally (i.e. without the "after" flag). It will print a
119 * warning if used on a signal which isn't being emitted. It will lookup the
122 * @param widget the object whose signal handlers you wish to stop
123 * @param name the signal identifier, as returned by g_signal_lookup()
125 #define SIGNAL_EMIT_STOP_BY_NAME(widget, name) \
126 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), name)
128 /** An entry for a GtkItemFactoryEntry array.
130 * @param path the path to this entry (e.g. "/File/Open")
131 * @param accelerator accelerator key (e.g. "<control>M") or NULL
132 * @param callback function to be called, when item is activated or NULL
133 * @param action the action number to use (usually 0)
134 * @param type special item type (e.g. "<Branch>", "<CheckItem>", ...) or NULL
135 * @param data data to pass to the callback function or NULL
137 #define ITEM_FACTORY_ENTRY(path, accelerator, callback, action, type, data) \
138 {path, accelerator, GTK_MENU_FUNC(callback), action, type}
140 /** Like ITEM_FACTORY_ENTRY(), but using a stock icon (as data)
141 * @param path the path to this entry (e.g. "/File/Open")
142 * @param accelerator accelerator key (e.g. "<control>M") or NULL
143 * @param callback function to be called, when item is activated or NULL
144 * @param action the action number to use (usually 0)
145 * @param data the stock item id (e.g. GTK_STOCK_OK, unused by GTK1)
147 #define ITEM_FACTORY_STOCK_ENTRY(path, accelerator, callback, action, data) \
148 {path, accelerator, GTK_MENU_FUNC(callback), action, NULL}
150 #define GTK_STOCK_APPLY "Apply"
151 #define GTK_STOCK_CANCEL "Cancel"
152 #define GTK_STOCK_CLEAR "Clear"
153 #define GTK_STOCK_CLOSE "Close"
154 #define GTK_STOCK_COPY "Copy"
155 #define GTK_STOCK_DELETE "Delete"
156 #define GTK_STOCK_FIND "Find"
157 #define GTK_STOCK_GO_BACK "Back"
158 #define GTK_STOCK_GO_DOWN "Down"
159 #define GTK_STOCK_GO_FORWARD "Next"
160 #define GTK_STOCK_GO_UP "Up"
161 #define GTK_STOCK_GOTO_BOTTOM "Bottom"
162 #define GTK_STOCK_GOTO_TOP "Top"
163 #define GTK_STOCK_HELP "Help"
164 #define GTK_STOCK_HOME "Home"
165 #define GTK_STOCK_JUMP_TO "GoTo"
166 #define GTK_STOCK_NEW "New"
167 #define GTK_STOCK_NO "No"
168 #define GTK_STOCK_OK "OK"
169 #define GTK_STOCK_OPEN "Open"
170 #define GTK_STOCK_PRINT "Print"
171 #define GTK_STOCK_PROPERTIES "Properties"
172 #define GTK_STOCK_REFRESH "Reload"
173 #define GTK_STOCK_REVERT_TO_SAVED "Revert"
174 #define GTK_STOCK_SAVE "Save"
175 #define GTK_STOCK_SAVE_AS "Save As"
176 #define GTK_STOCK_SELECT_COLOR "Color"
177 #define GTK_STOCK_SELECT_FONT "Font"
178 #define GTK_STOCK_STOP "Stop"
179 #define GTK_STOCK_YES "Yes"
180 #define GTK_STOCK_ZOOM_IN "Zoom In"
181 #define GTK_STOCK_ZOOM_OUT "Zoom Out"
182 #define GTK_STOCK_ZOOM_100 "Zoom 100%"
185 #define WIRESHARK_STOCK_CAPTURE_INTERFACES "Interfaces"
186 #define WIRESHARK_STOCK_CAPTURE_AIRPCAP "Airpcap"
187 #define WIRESHARK_STOCK_CAPTURE_OPTIONS "Options"
188 #define WIRESHARK_STOCK_CAPTURE_START "Start"
189 #define WIRESHARK_STOCK_CAPTURE_STOP "Stop"
190 #define WIRESHARK_STOCK_CAPTURE_RESTART "Restart"
191 #define WIRESHARK_STOCK_CAPTURE_FILTER "CFilter"
192 #define WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY "Capture Filter:"
193 #define WIRESHARK_STOCK_CAPTURE_DETAILS "Details"
195 #define WIRESHARK_STOCK_DISPLAY_FILTER "Filter"
196 #define WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY "Filter:"
197 #define WIRESHARK_STOCK_PREFS "Prefs"
198 #define WIRESHARK_STOCK_BROWSE "Browse"
199 #define WIRESHARK_STOCK_CREATE_STAT "Create Stat"
200 #define WIRESHARK_STOCK_EXPORT "Export..."
201 #define WIRESHARK_STOCK_IMPORT "Import..."
202 #define WIRESHARK_STOCK_EDIT "Edit..."
203 #define WIRESHARK_STOCK_ADD_EXPRESSION "Add Expression..."
204 #define WIRESHARK_STOCK_DONT_SAVE "Continue without Saving"
205 #define WIRESHARK_STOCK_ABOUT "About"
206 #define WIRESHARK_STOCK_COLORIZE "Colorize"
207 #define WIRESHARK_STOCK_AUTOSCROLL "Auto Scroll"
208 #define WIRESHARK_STOCK_RESIZE_COLUMNS "Resize Columns"
209 #define WIRESHARK_STOCK_TIME "Time"
210 #define WIRESHARK_STOCK_INTERNET "Internet"
211 #define WIRESHARK_STOCK_WEB_SUPPORT "Web Support"
212 #define WIRESHARK_STOCK_WIKI "Wiki"
213 #define WIRESHARK_STOCK_CONVERSATIONS "Conversations"
214 #define WIRESHARK_STOCK_ENDPOINTS "Endpoints"
215 #define WIRESHARK_STOCK_GRAPHS "Graphs"
216 #define WIRESHARK_STOCK_TELEPHONY "Telephony"
217 #define WIRESHARK_STOCK_DECODE_AS "Decode As"
218 #define WIRESHARK_STOCK_CHECKBOX "Checkbox"
219 #define WIRESHARK_STOCK_FILE_SET_LIST "List Files"
220 #define WIRESHARK_STOCK_FILE_SET_NEXT "Next File"
221 #define WIRESHARK_STOCK_FILE_SET_PREVIOUS "Previous File"
222 #define WIRESHARK_STOCK_FILTER_OUT_STREAM "Filter Out This Stream"
224 /** Create a stock button. Will create a "normal" button for GTK1.
226 * @param stock_id the stock id for this button (e.g. GTK_STOCK_OK)
227 * @return the new button
229 #define BUTTON_NEW_FROM_STOCK(stock_id) \
230 gtk_button_new_with_label(stock_id);
232 /** Create a check button.
234 * @param label_text the text to display
235 * @param accel_group accelerator group (GTK1 only)
236 * @return the new check button
238 #define CHECK_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
239 dlg_check_button_new_with_label_with_mnemonic(label_text, accel_group)
241 /** Create a radio button.
243 * @param radio_group group the radio buttons (another radio button or NULL for first one)
244 * @param label_text the text to display
245 * @param accel_group accelerator group (GTK1 only)
246 * @return the new radio button
248 #define RADIO_BUTTON_NEW_WITH_MNEMONIC(radio_group, label_text, accel_group) \
249 dlg_radio_button_new_with_label_with_mnemonic( \
250 radio_group ? gtk_radio_button_group(GTK_RADIO_BUTTON(radio_group)) : NULL, \
251 label_text, accel_group)
253 /** Create a radio button.
255 * @param radio_group group the radio buttons (another radio button or NULL for first one)
256 * @param label_text the text to display
257 * @return the new radio button
259 #define RADIO_BUTTON_NEW_WITH_LABEL(radio_group, label_text) \
260 gtk_radio_button_new_with_label ( \
261 radio_group ? gtk_radio_button_group(GTK_RADIO_BUTTON(radio_group)) : NULL, \
264 /** Create a toggle button.
266 * @param label_text the text to display
267 * @param accel_group accelerator group (GTK1 only)
268 * @return the new toggle button
270 #define TOGGLE_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
271 dlg_toggle_button_new_with_label_with_mnemonic(label_text, accel_group)
273 /** tag(s) start for first row of simple_dialog (and others). */
274 #define PRIMARY_TEXT_START ""
275 /** tag(s) end for first row of simple_dialog (and others). */
276 #define PRIMARY_TEXT_END ""
278 #define FONT_TYPE GdkFont
280 /*************************************************************************/
282 #else /* GTK_MAJOR_VERSION >= 2 */
284 #define SIGNAL_CONNECT(widget, name, callback, arg) \
285 g_signal_connect(G_OBJECT(widget), name, G_CALLBACK(callback), \
288 #define SIGNAL_CONNECT_OBJECT(widget, name, callback, arg) \
289 g_signal_connect_swapped(G_OBJECT(widget), name, G_CALLBACK(callback), \
292 #define SIGNAL_DISCONNECT_BY_FUNC(object, func, data) \
293 g_signal_handlers_disconnect_by_func(G_OBJECT(object), func, data)
295 #define OBJECT_SET_DATA(widget, key, data) \
296 g_object_set_data(G_OBJECT(widget), key, (data))
298 #define OBJECT_GET_DATA(widget, key) \
299 g_object_get_data(G_OBJECT(widget), key)
301 /* WIDGET_SET_SIZE would better be named WIDGET_SET_MIN_SIZE. */
302 /* don't use WIDGET_SET_SIZE() to set the size of a dialog, */
303 /* use gtk_window_set_default_size() for that purpose! */
304 #define WIDGET_SET_SIZE(widget, width, height) \
305 gtk_widget_set_size_request(GTK_WIDGET(widget), width, height)
307 #define SIGNAL_EMIT_BY_NAME g_signal_emit_by_name
308 #define SIGNAL_EMIT_OBJECT(object) G_OBJECT(object)
310 #define SIGNAL_EMIT_STOP_BY_NAME(widget, name) \
311 g_signal_stop_emission_by_name(G_OBJECT(widget), name)
313 #define ITEM_FACTORY_ENTRY(path, accelerator, callback, action, type, data) \
314 {path, accelerator, GTK_MENU_FUNC(callback), action, type, data}
316 #define ITEM_FACTORY_STOCK_ENTRY(path, accelerator, callback, action, data) \
317 {path, accelerator, GTK_MENU_FUNC(callback), action, "<StockItem>", data}
320 #define WIRESHARK_STOCK_LABEL_CAPTURE_INTERFACES "_Interfaces"
321 #define WIRESHARK_STOCK_LABEL_CAPTURE_AIRPCAP "_Wireless"
322 #define WIRESHARK_STOCK_LABEL_CAPTURE_OPTIONS "_Options"
323 #define WIRESHARK_STOCK_LABEL_CAPTURE_START "_Start"
324 #define WIRESHARK_STOCK_LABEL_CAPTURE_STOP "S_top"
325 #define WIRESHARK_STOCK_LABEL_CAPTURE_RESTART "_Restart"
326 #define WIRESHARK_STOCK_LABEL_CAPTURE_FILTER "_CFilter"
327 #define WIRESHARK_STOCK_LABEL_CAPTURE_FILTER_ENTRY "_Capture Filter:"
328 #define WIRESHARK_STOCK_LABEL_CAPTURE_DETAILS "_Details"
330 #define WIRESHARK_STOCK_LABEL_DISPLAY_FILTER "_Filter"
331 #define WIRESHARK_STOCK_LABEL_DISPLAY_FILTER_ENTRY "_Filter:"
332 #define WIRESHARK_STOCK_LABEL_PREFS "_Prefs"
333 #define WIRESHARK_STOCK_LABEL_BROWSE "_Browse..."
334 #define WIRESHARK_STOCK_LABEL_CREATE_STAT "Create _Stat"
335 #define WIRESHARK_STOCK_LABEL_EXPORT "_Export..."
336 #define WIRESHARK_STOCK_LABEL_IMPORT "_Import..."
337 #define WIRESHARK_STOCK_LABEL_EDIT "_Edit..."
338 #define WIRESHARK_STOCK_LABEL_ADD_EXPRESSION "_Expression..." /* plus sign coming from icon */
339 #define WIRESHARK_STOCK_LABEL_DONT_SAVE "Continue _without Saving"
340 #define WIRESHARK_STOCK_LABEL_ABOUT "_About"
341 #define WIRESHARK_STOCK_LABEL_COLORIZE "_Colorize"
342 #define WIRESHARK_STOCK_LABEL_AUTOSCROLL "_Auto Scroll in Live Capture"
343 #define WIRESHARK_STOCK_LABEL_RESIZE_COLUMNS "Resize Columns"
344 #define WIRESHARK_STOCK_LABEL_TIME "Time"
345 #define WIRESHARK_STOCK_LABEL_INTERNET "Internet"
346 #define WIRESHARK_STOCK_LABEL_WEB_SUPPORT "Web Support"
347 #define WIRESHARK_STOCK_LABEL_WIKI "Wiki"
348 #define WIRESHARK_STOCK_LABEL_CONVERSATIONS "Conversations"
349 #define WIRESHARK_STOCK_LABEL_ENDPOINTS "Endpoints"
350 #define WIRESHARK_STOCK_LABEL_GRAPHS "Graphs"
351 #define WIRESHARK_STOCK_LABEL_TELEPHONY "Telephony"
352 #define WIRESHARK_STOCK_LABEL_DECODE_AS "Decode As"
353 #define WIRESHARK_STOCK_LABEL_CHECKBOX "Checkbox"
354 #define WIRESHARK_STOCK_LABEL_FILE_SET_LIST "List Files"
355 #define WIRESHARK_STOCK_LABEL_FILE_SET_NEXT "Next File"
356 #define WIRESHARK_STOCK_LABEL_FILE_SET_PREVIOUS "Previous File"
357 #define WIRESHARK_STOCK_LABEL_FILTER_OUT_STREAM "Filter Out This Stream"
360 #define WIRESHARK_STOCK_CAPTURE_INTERFACES "Wireshark_Stock_CaptureInterfaces"
361 #define WIRESHARK_STOCK_CAPTURE_AIRPCAP "Wireshark_Stock_CaptureAirpcap"
362 #define WIRESHARK_STOCK_CAPTURE_OPTIONS "Wireshark_Stock_CaptureOptionss"
363 #define WIRESHARK_STOCK_CAPTURE_START "Wireshark_Stock_CaptureStart"
364 #define WIRESHARK_STOCK_CAPTURE_STOP "Wireshark_Stock_CaptureStop"
365 #define WIRESHARK_STOCK_CAPTURE_RESTART "Wireshark_Stock_CaptureRestart"
366 #define WIRESHARK_STOCK_CAPTURE_FILTER "Wireshark_Stock_CaptureFilter"
367 #define WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY "Wireshark_Stock_CaptureFilter_Entry"
368 #define WIRESHARK_STOCK_CAPTURE_DETAILS "Wireshark_Stock_CaptureDetails"
370 #define WIRESHARK_STOCK_DISPLAY_FILTER "Wireshark_Stock_DisplayFilter"
371 #define WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY "Wireshark_Stock_DisplayFilter_Entry"
372 #define WIRESHARK_STOCK_PREFS "Wireshark_Stock_Prefs"
373 #define WIRESHARK_STOCK_BROWSE "Wireshark_Stock_Browse"
374 #define WIRESHARK_STOCK_CREATE_STAT "Wireshark_Stock_CreateStat"
375 #define WIRESHARK_STOCK_EXPORT "Wireshark_Stock_Export"
376 #define WIRESHARK_STOCK_IMPORT "Wireshark_Stock_Import"
377 #define WIRESHARK_STOCK_EDIT "Wireshark_Stock_Edit"
378 #define WIRESHARK_STOCK_ADD_EXPRESSION "Wireshark_Stock_Edit_Add_Expression"
379 #define WIRESHARK_STOCK_DONT_SAVE "Wireshark_Stock_Continue_without_Saving"
380 #define WIRESHARK_STOCK_ABOUT "Wireshark_Stock_About"
381 #define WIRESHARK_STOCK_COLORIZE "Wireshark_Stock_Colorize"
382 #define WIRESHARK_STOCK_AUTOSCROLL "Wireshark_Stock_Autoscroll"
383 #define WIRESHARK_STOCK_RESIZE_COLUMNS "Wireshark_Stock_Resize_Columns"
384 #define WIRESHARK_STOCK_TIME "Wireshark_Stock_Time"
385 #define WIRESHARK_STOCK_INTERNET "Wireshark_Stock_Internet"
386 #define WIRESHARK_STOCK_WEB_SUPPORT "Wireshark_Stock_Web_Support"
387 #define WIRESHARK_STOCK_WIKI "Wireshark_Stock_Wiki"
388 #define WIRESHARK_STOCK_CONVERSATIONS "Wireshark_Stock_Conversations"
389 #define WIRESHARK_STOCK_ENDPOINTS "Wireshark_Stock_Endpoints"
390 #define WIRESHARK_STOCK_GRAPHS "Wireshark_Stock_Graphs"
391 #define WIRESHARK_STOCK_TELEPHONY "Wireshark_Stock_Telephony"
392 #define WIRESHARK_STOCK_DECODE_AS "Wireshark_Stock_DecodeAs"
393 #define WIRESHARK_STOCK_CHECKBOX "Wireshark_Stock_Checkbox"
394 #define WIRESHARK_STOCK_FILE_SET_LIST "Wireshark_Stock_File_Set_List"
395 #define WIRESHARK_STOCK_FILE_SET_NEXT "Wireshark_Stock_File_Set_Next"
396 #define WIRESHARK_STOCK_FILE_SET_PREVIOUS "Wireshark_Stock_File_Set_Previous"
397 #define WIRESHARK_STOCK_FILTER_OUT_STREAM "Wireshark_Stock_Filter_Out_This_Stream"
399 #define BUTTON_NEW_FROM_STOCK(stock_id) \
400 gtk_button_new_from_stock(stock_id);
402 #define CHECK_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
403 gtk_check_button_new_with_mnemonic(label_text)
405 #define RADIO_BUTTON_NEW_WITH_MNEMONIC(radio_group, label_text, accel_group) \
406 gtk_radio_button_new_with_mnemonic_from_widget( \
407 radio_group ? GTK_RADIO_BUTTON(radio_group) : NULL, label_text)
409 #define RADIO_BUTTON_NEW_WITH_LABEL(radio_group, label_text) \
410 gtk_radio_button_new_with_label_from_widget( \
411 radio_group ? GTK_RADIO_BUTTON(radio_group) : NULL, label_text)
413 #define TOGGLE_BUTTON_NEW_WITH_MNEMONIC(label_text, accel_group) \
414 gtk_toggle_button_new_with_mnemonic(label_text)
416 /* for details, see "Pango Text Attribute Markup" */
417 #define PRIMARY_TEXT_START "<span weight=\"bold\" size=\"larger\">"
418 #define PRIMARY_TEXT_END "</span>"
420 #define FONT_TYPE PangoFontDescription
422 #endif /* GTK_MAJOR_VERSION */
424 #endif /* __COMPAT_MACROS_H__ */