a3ee04ff69c41f64d7f3b19339c10f125749f14b
[metze/wireshark/wip.git] / ui / gtk / stock_icons.c
1 /* stock_icons.c
2  * Wireshark specific stock icons
3  * Copyright 2003-2008, Ulf Lamping <ulf.lamping@web.de>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <gtk/gtk.h>
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "ui/gtk/stock_icons.h"
32 #include "ui/gtk/toolbar_icons.h"
33 #include "ui/gtk/wsicon.h"
34
35 #include "ui/utf8_entities.h"
36
37 /* these icons are derived from the original stock icons */
38 #include "../../image/toolbar/capture_filter_24.xpm"
39 #include "../../image/toolbar/capture_details_24.xpm"
40 #include "../../image/toolbar/display_filter_24.xpm"
41 #include "../../image/toolbar/colorize_24.xpm"
42 #include "../../image/toolbar/autoscroll_24.xpm"
43 #include "../../image/toolbar/resize_columns_24.xpm"
44 #include "../../image/toolbar/time_24.xpm"
45 #include "../../image/toolbar/internet_24.xpm"
46 #include "../../image/toolbar/web_support_24.xpm"
47 #include "../../image/toolbar/conversations_16.xpm"
48 #include "../../image/toolbar/endpoints_16.xpm"
49 #include "../../image/toolbar/expert_info_16.xpm"
50 #include "../../image/toolbar/flow_graph_16.xpm"
51 #include "../../image/toolbar/graphs_16.xpm"
52 #include "../../image/toolbar/telephony_16.xpm"
53 #include "../../image/toolbar/decode_as_16.xpm"
54 #include "../../image/toolbar/checkbox_16.xpm"
55 #include "../../image/toolbar/file_set_list_16.xpm"
56 #include "../../image/toolbar/file_set_next_16.xpm"
57 #include "../../image/toolbar/file_set_previous_16.xpm"
58 #include "../../image/toolbar/icon_color_1.xpm"
59 #include "../../image/toolbar/icon_color_2.xpm"
60 #include "../../image/toolbar/icon_color_3.xpm"
61 #include "../../image/toolbar/icon_color_4.xpm"
62 #include "../../image/toolbar/icon_color_5.xpm"
63 #include "../../image/toolbar/icon_color_6.xpm"
64 #include "../../image/toolbar/icon_color_7.xpm"
65 #include "../../image/toolbar/icon_color_8.xpm"
66 #include "../../image/toolbar/icon_color_9.xpm"
67 #include "../../image/toolbar/icon_color_0.xpm"
68 #include "../../image/toolbar/decode_24.xpm"
69 #include "../../image/toolbar/audio_player_24.xpm"
70 #include "../../image/toolbar/voip_flow_24.xpm"
71 #include "../../image/toolbar/telephone_16.xpm"
72 #include "../../image/toolbar/analyze_24.xpm"
73
74 typedef struct stock_item_tag {
75     const char * name;
76     const char * icon;
77     const char * label;
78 } stock_item_t;
79
80 typedef struct stock_pixmap_tag{
81     const char *    name;
82     const char **   xpm_data;
83     const guint     size;
84 } stock_pixmap_t;
85
86 typedef struct stock_pixbuf_tag{
87     const char    * name;
88     const guint8 * pb_data16; /* Optional */
89     const guint8 * pb_data24; /* Mandatory */
90 } stock_pixbuf_t;
91
92 /*
93  * Register non-standard pixmaps with the gtk-stock engine.
94  * Most of the icon names match the item name here.
95  * Use default stock icons for Wireshark specifics where the icon metapher makes sense.
96  * PLEASE DON'T REUSE STOCK ICONS IF THEY ARE USUALLY USED FOR SOME DIFFERENT MEANING!!!)
97  */
98 static stock_item_t ws_stock_items[] = {
99     {(char *)WIRESHARK_STOCK_CAPTURE_INTERFACES,    (char *)WIRESHARK_STOCK_CAPTURE_INTERFACES,     (char *)"_Interfaces"},
100     {(char *)WIRESHARK_STOCK_CAPTURE_OPTIONS,       (char *)WIRESHARK_STOCK_CAPTURE_OPTIONS,        (char *)"_Options"},
101     {(char *)WIRESHARK_STOCK_CAPTURE_START,         (char *)WIRESHARK_STOCK_CAPTURE_START,          (char *)"_Start"},
102     {(char *)WIRESHARK_STOCK_CAPTURE_STOP,          (char *)WIRESHARK_STOCK_CAPTURE_STOP,           (char *)"S_top"},
103     {(char *)WIRESHARK_STOCK_CAPTURE_RESTART,       (char *)WIRESHARK_STOCK_CAPTURE_RESTART,        (char *)"_Restart"},
104     {(char *)WIRESHARK_STOCK_CAPTURE_FILTER,        (char *)WIRESHARK_STOCK_CAPTURE_FILTER,         (char *)"_Capture Filter"},
105     {(char *)WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY,  (char *)WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY,   (char *)"_Capture Filter:"},
106     {(char *)WIRESHARK_STOCK_CAPTURE_DETAILS,       (char *)WIRESHARK_STOCK_CAPTURE_DETAILS,        (char *)"_Details"},
107     #ifdef HAVE_GEOIP
108     {(char *)WIRESHARK_STOCK_MAP,                   (char *)WIRESHARK_STOCK_MAP,                    (char *)"Map"},
109     #endif
110     {(char *)WIRESHARK_STOCK_GRAPH_A_B,             (char *)WIRESHARK_STOCK_GRAPH_A_B,              (char *)"Graph A" UTF8_RIGHTWARDS_ARROW "B"},
111     {(char *)WIRESHARK_STOCK_GRAPH_B_A,             (char *)WIRESHARK_STOCK_GRAPH_B_A,              (char *)"Graph A" UTF8_LEFTWARDS_ARROW  "B"},
112     {(char *)WIRESHARK_STOCK_FOLLOW_STREAM,         (char *)WIRESHARK_STOCK_FOLLOW_STREAM,          (char *)"Follow Stream"},
113     {(char *)WIRESHARK_STOCK_DISPLAY_FILTER,        (char *)WIRESHARK_STOCK_DISPLAY_FILTER,         (char *)"Display _Filter"},
114     {(char *)WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY,  (char *)WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY,   (char *)"F_ilter:"},
115     {(char *)WIRESHARK_STOCK_BROWSE,                (char *)GTK_STOCK_OPEN,                         (char *)"_Browse..."},
116     {(char *)WIRESHARK_STOCK_CREATE_STAT,           (char *)GTK_STOCK_OK,                           (char *)"Create _Stat"},
117     {(char *)WIRESHARK_STOCK_EXPORT,                (char *)GTK_STOCK_SAVE,                         (char *)"_Export..."}, /* XXX: needs a better icon */
118     {(char *)WIRESHARK_STOCK_IMPORT,                (char *)GTK_STOCK_OPEN,                         (char *)"_Import..."}, /* XXX: needs a better icon */
119     {(char *)WIRESHARK_STOCK_EDIT,                  (char *)GTK_STOCK_PROPERTIES,                   (char *)"_Edit..."},
120     {(char *)WIRESHARK_STOCK_ADD_EXPRESSION,        (char *)GTK_STOCK_ADD,                          (char *)"E_xpression..." }, /* plus sign coming from icon */
121     {(char *)WIRESHARK_STOCK_CLEAR_EXPRESSION,      (char *)GTK_STOCK_CLEAR,                        (char *)"Clea_r" },
122     {(char *)WIRESHARK_STOCK_APPLY_EXPRESSION,      (char *)GTK_STOCK_APPLY,                        (char *)"App_ly" },
123     {(char *)WIRESHARK_STOCK_SAVE_ALL,              (char *)GTK_STOCK_SAVE,                        (char *)"Save A_ll"}, /* XXX: needs a better icon */
124     {(char *)WIRESHARK_STOCK_DONT_SAVE,             (char *)GTK_STOCK_CLEAR,                        (char *)"Continue _without Saving"},
125     {(char *)WIRESHARK_STOCK_QUIT_DONT_SAVE,        (char *)GTK_STOCK_CLEAR,                        (char *)"Quit _without Saving"},
126     {(char *)WIRESHARK_STOCK_STOP_DONT_SAVE,        (char *)GTK_STOCK_CLEAR,                        (char *)"Stop and Continue _without Saving"},
127     {(char *)WIRESHARK_STOCK_STOP_QUIT_DONT_SAVE,   (char *)GTK_STOCK_CLEAR,                        (char *)"Stop and Quit _without Saving"},
128     {(char *)WIRESHARK_STOCK_STOP_SAVE,             (char *)GTK_STOCK_SAVE,                         (char *)"Stop and Save"},
129     {(char *)WIRESHARK_STOCK_ABOUT,                 (char *)WIRESHARK_STOCK_ABOUT,                  (char *)"_About"},
130     {(char *)WIRESHARK_STOCK_COLORIZE,              (char *)WIRESHARK_STOCK_COLORIZE,               (char *)"_Colorize"},
131     {(char *)WIRESHARK_STOCK_AUTOSCROLL,            (char *)WIRESHARK_STOCK_AUTOSCROLL,             (char *)"_Auto Scroll"},
132     {(char *)WIRESHARK_STOCK_RESIZE_COLUMNS,        (char *)WIRESHARK_STOCK_RESIZE_COLUMNS,         (char *)"Resize Columns"},
133     {(char *)WIRESHARK_STOCK_TIME,                  (char *)WIRESHARK_STOCK_TIME,                   (char *)"Time"},
134     {(char *)WIRESHARK_STOCK_INTERNET,              (char *)WIRESHARK_STOCK_INTERNET,               (char *)"Internet"},
135     {(char *)WIRESHARK_STOCK_WEB_SUPPORT,           (char *)WIRESHARK_STOCK_WEB_SUPPORT,            (char *)"Web Support"},
136     {(char *)WIRESHARK_STOCK_WIKI,                  (char *)WIRESHARK_STOCK_WIKI,                   (char *)"Wiki"},
137     {(char *)WIRESHARK_STOCK_CONVERSATIONS,         (char *)WIRESHARK_STOCK_CONVERSATIONS,          (char *)"Conversations"},
138     {(char *)WIRESHARK_STOCK_ENDPOINTS,             (char *)WIRESHARK_STOCK_ENDPOINTS,              (char *)"Endpoints"},
139     {(char *)WIRESHARK_STOCK_EXPERT_INFO,           (char *)WIRESHARK_STOCK_EXPERT_INFO,            (char *)"Expert Info"},
140     {(char *)WIRESHARK_STOCK_GRAPHS,                (char *)WIRESHARK_STOCK_GRAPHS,                 (char *)"Graphs"},
141     {(char *)WIRESHARK_STOCK_FLOW_GRAPH,            (char *)WIRESHARK_STOCK_FLOW_GRAPH,             (char *)"Flow Graph"},
142     {(char *)WIRESHARK_STOCK_TELEPHONY,             (char *)WIRESHARK_STOCK_TELEPHONY,              (char *)"Telephony"},
143     {(char *)WIRESHARK_STOCK_DECODE_AS,             (char *)WIRESHARK_STOCK_DECODE_AS,              (char *)"Decode As"},
144     {(char *)WIRESHARK_STOCK_CHECKBOX,              (char *)WIRESHARK_STOCK_CHECKBOX,               (char *)"Checkbox"},
145     {(char *)WIRESHARK_STOCK_FILE_SET_LIST,         (char *)WIRESHARK_STOCK_FILE_SET_LIST,          (char *)"List Files"},
146     {(char *)WIRESHARK_STOCK_FILE_SET_NEXT,         (char *)WIRESHARK_STOCK_FILE_SET_NEXT,          (char *)"Next File"},
147     {(char *)WIRESHARK_STOCK_FILE_SET_PREVIOUS,     (char *)WIRESHARK_STOCK_FILE_SET_PREVIOUS,      (char *)"Previous File"},
148     {(char *)WIRESHARK_STOCK_FILTER_OUT_STREAM,     (char *)WIRESHARK_STOCK_FILTER_OUT_STREAM,      (char *)"Filter Out This Stream"},
149     {(char *)WIRESHARK_STOCK_ENABLE,                (char *)WIRESHARK_STOCK_ENABLE,                 (char *)"Enable"},
150     {(char *)WIRESHARK_STOCK_DISABLE,               (char *)GTK_STOCK_CLOSE,                        (char *)"Disable"},
151     {(char *)WIRESHARK_STOCK_COLOR1,                (char *)WIRESHARK_STOCK_COLOR1,                 (char *)"Color 1"},
152     {(char *)WIRESHARK_STOCK_COLOR2,                (char *)WIRESHARK_STOCK_COLOR2,                 (char *)"Color 2"},
153     {(char *)WIRESHARK_STOCK_COLOR3,                (char *)WIRESHARK_STOCK_COLOR3,                 (char *)"Color 3"},
154     {(char *)WIRESHARK_STOCK_COLOR4,                (char *)WIRESHARK_STOCK_COLOR4,                 (char *)"Color 4"},
155     {(char *)WIRESHARK_STOCK_COLOR5,                (char *)WIRESHARK_STOCK_COLOR5,                 (char *)"Color 5"},
156     {(char *)WIRESHARK_STOCK_COLOR6,                (char *)WIRESHARK_STOCK_COLOR6,                 (char *)"Color 6"},
157     {(char *)WIRESHARK_STOCK_COLOR7,                (char *)WIRESHARK_STOCK_COLOR7,                 (char *)"Color 7"},
158     {(char *)WIRESHARK_STOCK_COLOR8,                (char *)WIRESHARK_STOCK_COLOR8,                 (char *)"Color 8"},
159     {(char *)WIRESHARK_STOCK_COLOR9,                (char *)WIRESHARK_STOCK_COLOR9,                 (char *)"Color 9"},
160     {(char *)WIRESHARK_STOCK_COLOR0,                (char *)WIRESHARK_STOCK_COLOR0,                 (char *)"Color 10"},
161     {(char *)WIRESHARK_STOCK_DECODE,                (char *)WIRESHARK_STOCK_DECODE,                 (char *)"Decode"},
162     {(char *)WIRESHARK_STOCK_AUDIO_PLAYER,          (char *)WIRESHARK_STOCK_AUDIO_PLAYER,           (char *)"Player"},
163     {(char *)WIRESHARK_STOCK_VOIP_FLOW,             (char *)WIRESHARK_STOCK_VOIP_FLOW,              (char *)"Flow"},
164     {(char *)WIRESHARK_STOCK_TELEPHONE,             (char *)WIRESHARK_STOCK_TELEPHONE,              (char *)"Telephone"},
165     {(char *)WIRESHARK_STOCK_PREPARE_FILTER,        (char *)WIRESHARK_STOCK_PREPARE_FILTER,         (char *)"Prepare Filter"},
166     {(char *)WIRESHARK_STOCK_ANALYZE,               (char *)WIRESHARK_STOCK_ANALYZE,                (char *)"Analyze"},
167     {(char *)WIRESHARK_STOCK_SAVE,                  (char *)WIRESHARK_STOCK_SAVE,                   (char *)"Save"}
168 };
169
170 static stock_item_t gtk_stock_items[] = {
171     {(char *)GTK_STOCK_ABOUT,                         (char *)"help-about",                (char *)"_About"},
172     {(char *)GTK_STOCK_ADD,                           (char *)"list-add",                  (char *)"_Add"},
173     {(char *)GTK_STOCK_APPLY,                         NULL,                                (char *)"_Apply"},
174     {(char *)GTK_STOCK_BOLD,                          (char *)"format-text-bold",          (char *)"_Bold"},
175     {(char *)GTK_STOCK_CANCEL,                        NULL,                                (char *)"_Cancel"},
176 #ifdef GTK_STOCK_CAPS_LOCK_WARNING
177     {(char *)GTK_STOCK_CAPS_LOCK_WARNING,             NULL,                                NULL},
178 #endif
179     {(char *)GTK_STOCK_CDROM,                         (char *)"media-optical",             (char *)"_CD-ROM"},
180     {(char *)GTK_STOCK_CLEAR,                         (char *)"edit-clear",                (char *)"_Clear"},
181     {(char *)GTK_STOCK_CLOSE,                         (char *)"window-close",              (char *)"_Close"},
182     {(char *)GTK_STOCK_COLOR_PICKER,                  NULL,                                NULL},
183     {(char *)GTK_STOCK_CONNECT,                       NULL,                                (char *)"C_onnect"},
184     {(char *)GTK_STOCK_CONVERT,                       NULL,                                (char *)"_Convert"},
185     {(char *)GTK_STOCK_COPY,                          (char *)"edit-copy",                 (char *)"_Copy"},
186     {(char *)GTK_STOCK_CUT,                           (char *)"edit-cut",                  (char *)"Cu_t"},
187     {(char *)GTK_STOCK_DELETE,                        (char *)"edit-delete",               (char *)"_Delete"},
188     {(char *)GTK_STOCK_DIALOG_AUTHENTICATION,         (char *)"dialog-password",           NULL},
189     {(char *)GTK_STOCK_DIALOG_INFO,                   (char *)"dialog-information",        (char *)"Information"},
190     {(char *)GTK_STOCK_DIALOG_WARNING,                (char *)"dialog-warning",            (char *)"Warning"},
191     {(char *)GTK_STOCK_DIALOG_ERROR,                  (char *)"dialog-error",              (char *)"Error"},
192     {(char *)GTK_STOCK_DIALOG_QUESTION,               (char *)"dialog-question",           (char *)"Question"},
193     {(char *)GTK_STOCK_DIRECTORY,                     (char *)"folder",                    NULL},
194     {(char *)GTK_STOCK_DISCARD,                       NULL,                                (char *)"_Discard"},
195     {(char *)GTK_STOCK_DISCONNECT,                    NULL,                                (char *)"_Disconnect"},
196     {(char *)GTK_STOCK_DND,                           NULL,                                NULL},
197     {(char *)GTK_STOCK_DND_MULTIPLE,                  NULL,                                NULL},
198     {(char *)GTK_STOCK_EDIT,                          NULL,                                (char *)"_Edit"},
199     {(char *)GTK_STOCK_EXECUTE,                       (char *)"system-run",                (char *)"_Execute"},
200     {(char *)GTK_STOCK_FILE,                          (char *)"text-x-generic",            (char *)"_File"},
201     {(char *)GTK_STOCK_FIND,                          (char *)"edit-find",                 (char *)"_Find"},
202     {(char *)GTK_STOCK_FIND_AND_REPLACE,              (char *)"edit-find-replace",         (char *)"Find     and _Replace"},
203     {(char *)GTK_STOCK_FLOPPY,                        (char *)"media-floppy",              (char *)"_Floppy"},
204     {(char *)GTK_STOCK_FULLSCREEN,                    (char *)"view-fullscreen",           (char *)"_Fullscreen"},
205     {(char *)GTK_STOCK_GOTO_BOTTOM,                   (char *)"go-bottom",                 (char *)"_Bottom"},
206     {(char *)GTK_STOCK_GOTO_FIRST,                    (char *)"go-first",                  (char *)"_First"},
207     {(char *)GTK_STOCK_GOTO_LAST,                     (char *)"go-last",                   (char *)"_Last"},
208     {(char *)GTK_STOCK_GOTO_TOP,                      (char *)"go-top",                    (char *)"_Top"},
209     {(char *)GTK_STOCK_GO_BACK,                       (char *)"go-previous",               (char *)"_Back"},
210     {(char *)GTK_STOCK_GO_DOWN,                       (char *)"go-down",                   (char *)"_Down"},
211     {(char *)GTK_STOCK_GO_FORWARD,                    (char *)"go-next",                   (char *)"_Forward"},
212     {(char *)GTK_STOCK_GO_UP,                         (char *)"go-up",                     (char *)"_Up"},
213     {(char *)GTK_STOCK_HARDDISK,                      (char *)"drive-harddisk",            (char *)"_Hard    Disk"},
214     {(char *)GTK_STOCK_HELP,                          (char *)"help-browser",              (char *)"_Help"},
215     {(char *)GTK_STOCK_HOME,                          (char *)"go-home",                   (char *)"_Home"},
216     {(char *)GTK_STOCK_INDEX,                         NULL,                                (char *)"_Index"},
217     {(char *)GTK_STOCK_INDENT,                        (char *)"format-indent-more",        (char *)"Increase Indent"},
218     {(char *)GTK_STOCK_INFO,                          (char *)"dialog-information",        (char *)"_Information"},
219     {(char *)GTK_STOCK_ITALIC,                        (char *)"format-text-italic",        (char *)"_Italic"},
220     {(char *)GTK_STOCK_JUMP_TO,                       (char *)"go-jump",                   (char *)"_Jump    to"},
221     {(char *)GTK_STOCK_JUSTIFY_CENTER,                (char *)"format-justify-center",     (char *)"_Center"},
222     {(char *)GTK_STOCK_JUSTIFY_FILL,                  (char *)"format-justify-fill",       (char *)"_Fill"},
223     {(char *)GTK_STOCK_JUSTIFY_LEFT,                  (char *)"format-justify-left",       (char *)"_Left"},
224     {(char *)GTK_STOCK_JUSTIFY_RIGHT,                 (char *)"format-justify-right",      (char *)"_Right"},
225     {(char *)GTK_STOCK_LEAVE_FULLSCREEN,              (char *)"view-restore",              (char *)"_Leave   Fullscreen"},
226     {(char *)GTK_STOCK_MISSING_IMAGE,                 (char *)"image-missing",             NULL},
227     {(char *)GTK_STOCK_MEDIA_FORWARD,                 (char *)"media-seek-forward",        (char *)"_Forward"},
228     {(char *)GTK_STOCK_MEDIA_NEXT,                    (char *)"media-skip-forward",        (char *)"_Next"},
229     {(char *)GTK_STOCK_MEDIA_PAUSE,                   (char *)"media-playback-pause",      (char *)"P_ause"},
230     {(char *)GTK_STOCK_MEDIA_PLAY,                    (char *)"media-playback-start",      (char *)"_Play"},
231     {(char *)GTK_STOCK_MEDIA_PREVIOUS,                (char *)"media-skip-backward",       (char *)"Pre_vious"},
232     {(char *)GTK_STOCK_MEDIA_RECORD,                  (char *)"media-record",              (char *)"_Record"},
233     {(char *)GTK_STOCK_MEDIA_REWIND,                  (char *)"media-seek-backward",       (char *)"R_ewind"},
234     {(char *)GTK_STOCK_MEDIA_STOP,                    (char *)"media-playback-stop",       (char *)"_Stop"},
235     {(char *)GTK_STOCK_NETWORK,                       (char *)"network-workgroup",         (char *)"_Network"},
236     {(char *)GTK_STOCK_NEW,                           (char *)"document-new",              (char *)"_New"},
237     {(char *)GTK_STOCK_NO,                            NULL,                                (char *)"_No"},
238     {(char *)GTK_STOCK_OK,                            NULL,                                (char *)"_OK"},
239     {(char *)GTK_STOCK_OPEN,                          (char *)"document-open",             (char *)"_Open"},
240     {(char *)GTK_STOCK_ORIENTATION_PORTRAIT,          (char *)"?",                         (char *)"Portrait"},
241     {(char *)GTK_STOCK_ORIENTATION_LANDSCAPE,         (char *)"?",                         (char *)"Landscape"},
242     {(char *)GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE, (char *)"?",                         (char *)"Reverse  landscape"},
243     {(char *)GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT,  (char *)"?",                         (char *)"Reverse  portrait"},
244 #ifdef GTK_STOCK_PAGE_SETUP
245     {(char *)GTK_STOCK_PAGE_SETUP,                    (char *)"document-page-setup",       (char *)"Page     Set_up"},
246 #endif
247     {(char *)GTK_STOCK_PASTE,                         (char *)"edit-paste",                (char *)"_Paste"},
248     {(char *)GTK_STOCK_PREFERENCES,                   (char *)"preferences-system",        (char *)"_Preferences"},
249     {(char *)GTK_STOCK_PRINT,                         (char *)"document-print",            (char *)"_Print"},
250 #ifdef GTK_STOCK_PRINT_ERROR
251     {(char *)GTK_STOCK_PRINT_ERROR,                   (char *)"printer-error",             NULL},
252 #endif
253 #ifdef GTK_STOCK_PRINT_PAUSED
254     {(char *)GTK_STOCK_PRINT_PAUSED,                  NULL,                                NULL},
255 #endif
256     {(char *)GTK_STOCK_PRINT_PREVIEW,                 NULL,                                (char *)"Print Pre_view"},
257 #ifdef GTK_STOCK_PRINT_REPORT
258     {(char *)GTK_STOCK_PRINT_REPORT,                  NULL,                                NULL},
259 #endif
260 #ifdef GTK_STOCK_PRINT_WARNING
261     {(char *)GTK_STOCK_PRINT_WARNING,                 NULL,                                NULL},
262 #endif
263     {(char *)GTK_STOCK_PROPERTIES,                    (char *)"document-properties",       (char *)"_Properties"},
264     {(char *)GTK_STOCK_QUIT,                          (char *)"application-exit",          (char *)"_Quit"},
265     {(char *)GTK_STOCK_REDO,                          (char *)"edit-redo",                 (char *)"_Redo"},
266     {(char *)GTK_STOCK_REFRESH,                       (char *)"view-refresh",              (char *)"_Refresh"},
267     {(char *)GTK_STOCK_REMOVE,                        (char *)"list-remove",               (char *)"_Remove"},
268     {(char *)GTK_STOCK_REVERT_TO_SAVED,               (char *)"document-revert",           (char *)"_Revert"},
269     {(char *)GTK_STOCK_SAVE,                          (char *)"document-save",             (char *)"_Save"},
270     {(char *)GTK_STOCK_SAVE_AS,                       (char *)"document-save-as",          (char *)"Save     _As"},
271     {(char *)GTK_STOCK_SELECT_ALL,                    (char *)"edit-select-all",           (char *)"Select   _All"},
272     {(char *)GTK_STOCK_SELECT_COLOR,                  NULL,                                (char *)"_Color"},
273     {(char *)GTK_STOCK_SELECT_FONT,                   NULL,                                (char *)"_Font"},
274     {(char *)GTK_STOCK_SORT_ASCENDING,                (char *)"view-sort-ascending",       (char *)"_Ascending"},
275     {(char *)GTK_STOCK_SORT_DESCENDING,               (char *)"view-sort-descending",      (char *)"_Descending"},
276     {(char *)GTK_STOCK_SPELL_CHECK,                   (char *)"tools-check-spelling",      (char *)"_Spell   Check"},
277     {(char *)GTK_STOCK_STOP,                          (char *)"process-stop",              (char *)"_Stop"},
278     {(char *)GTK_STOCK_STRIKETHROUGH,                 (char *)"format-text-strikethrough", (char *)"_Strikethrough"},
279     {(char *)GTK_STOCK_UNDELETE,                      NULL,                                (char *)"_Undelete"},
280     {(char *)GTK_STOCK_UNDERLINE,                     (char *)"format-text-underline",     (char *)"_Underline"},
281     {(char *)GTK_STOCK_UNDO,                          (char *)"edit-undo",                 (char *)"_Undo"},
282     {(char *)GTK_STOCK_UNINDENT,                      (char *)"format-indent-less",        NULL},
283     {(char *)GTK_STOCK_YES,                           NULL,                                (char *)"_Yes"},
284     {(char *)GTK_STOCK_ZOOM_100,                      (char *)"zoom-original",             (char *)"_Normal  Size"},
285     {(char *)GTK_STOCK_ZOOM_FIT,                      (char *)"zoom-fit-best",             (char *)"Best     _Fit"},
286     {(char *)GTK_STOCK_ZOOM_IN,                       (char *)"zoom-in",                   (char *)"Zoom     _In"},
287     {(char *)GTK_STOCK_ZOOM_OUT,                      (char *)"zoom-out",                  (char *)"Zoom     _Out"},
288 };
289
290 /**
291  * Compare two stock items by name.
292  */
293 static int si_cmp(const stock_item_t * a, const stock_item_t * b) {
294     return strcmp(a->name, b->name);
295 }
296
297
298 #define BS(item, arr) (stock_item_t *)bsearch((void*)(((char*)&item) - offsetof(stock_item_t, name)), \
299                                               (void*)arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), \
300                                               (int (*)(const void *, const void *))si_cmp)
301
302 /* generate application specific stock items */
303 void stock_icons_init(void) {
304     guint32 i;
305 #if !GTK_CHECK_VERSION(3, 10, 0)
306     GtkIconFactory * factory;
307     GtkIconSet *icon_set;
308     GtkIconSource *source16;
309 #endif
310
311     static const stock_pixbuf_t pixbufs[] = {
312         { WIRESHARK_STOCK_ABOUT,              wsicon_16_pb_data, wsicon_24_pb_data },
313         { WIRESHARK_STOCK_CAPTURE_INTERFACES, capture_interfaces_16_pb_data, capture_interfaces_24_pb_data },
314         { WIRESHARK_STOCK_CAPTURE_OPTIONS,    capture_options_alt1_16_pb_data, capture_options_alt1_24_pb_data },
315         { WIRESHARK_STOCK_CAPTURE_RESTART,    capture_restart_16_pb_data, capture_restart_24_pb_data },
316         { WIRESHARK_STOCK_CAPTURE_START,      capture_start_16_pb_data, capture_start_24_pb_data },
317         { WIRESHARK_STOCK_CAPTURE_STOP,       capture_stop_16_pb_data, capture_stop_24_pb_data },
318         { WIRESHARK_STOCK_SAVE,               toolbar_wireshark_file_16_pb_data, toolbar_wireshark_file_24_pb_data},
319         { WIRESHARK_STOCK_WIKI,               gnome_emblem_web_16_pb_data, gnome_emblem_web_24_pb_data },
320         { NULL, NULL, NULL }
321     };
322
323     /* New images should be PNGs + pixbufs above. Please don't add to this list. */
324     static const stock_pixmap_t pixmaps[] = {
325         { WIRESHARK_STOCK_CAPTURE_FILTER,       capture_filter_24_xpm,    24},
326         { WIRESHARK_STOCK_CAPTURE_FILTER_ENTRY, capture_filter_24_xpm,    24},
327         { WIRESHARK_STOCK_CAPTURE_DETAILS,      capture_details_24_xpm,   24},
328 #ifdef HAVE_GEOIP
329         { WIRESHARK_STOCK_MAP,                  internet_24_xpm,          24},
330 #endif
331         { WIRESHARK_STOCK_DISPLAY_FILTER,       display_filter_24_xpm,    24},
332         { WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY, display_filter_24_xpm,    24},
333         { WIRESHARK_STOCK_COLORIZE,             colorize_24_xpm,          24},
334         { WIRESHARK_STOCK_AUTOSCROLL,           autoscroll_24_xpm,        24},
335         { WIRESHARK_STOCK_RESIZE_COLUMNS,       resize_columns_24_xpm,    24},
336         { WIRESHARK_STOCK_TIME,                 time_24_xpm,              24},
337         { WIRESHARK_STOCK_INTERNET,             internet_24_xpm,          24},
338         { WIRESHARK_STOCK_WEB_SUPPORT,          web_support_24_xpm,       24},
339         { WIRESHARK_STOCK_CONVERSATIONS,        conversations_16_xpm,     16},
340         { WIRESHARK_STOCK_ENDPOINTS,            endpoints_16_xpm,         16},
341         { WIRESHARK_STOCK_EXPERT_INFO,          expert_info_16_xpm,       16},
342         { WIRESHARK_STOCK_GRAPHS,               graphs_16_xpm,            16},
343         { WIRESHARK_STOCK_FLOW_GRAPH,           flow_graph_16_xpm,        16},
344         { WIRESHARK_STOCK_TELEPHONY,            telephony_16_xpm,         16},
345         { WIRESHARK_STOCK_DECODE_AS,            decode_as_16_xpm,         16},
346         { WIRESHARK_STOCK_CHECKBOX,             checkbox_16_xpm,          16},
347         { WIRESHARK_STOCK_FILE_SET_LIST,        file_set_list_16_xpm,     16},
348         { WIRESHARK_STOCK_FILE_SET_NEXT,        file_set_next_16_xpm,     16},
349         { WIRESHARK_STOCK_FILE_SET_PREVIOUS,    file_set_previous_16_xpm, 16},
350         { WIRESHARK_STOCK_FILTER_OUT_STREAM,    display_filter_24_xpm,    24},
351         { WIRESHARK_STOCK_ENABLE,               checkbox_16_xpm,          16},
352         { WIRESHARK_STOCK_COLOR1,               icon_color_1_xpm,         24},
353         { WIRESHARK_STOCK_COLOR2,               icon_color_2_xpm,         24},
354         { WIRESHARK_STOCK_COLOR3,               icon_color_3_xpm,         24},
355         { WIRESHARK_STOCK_COLOR4,               icon_color_4_xpm,         24},
356         { WIRESHARK_STOCK_COLOR5,               icon_color_5_xpm,         24},
357         { WIRESHARK_STOCK_COLOR6,               icon_color_6_xpm,         24},
358         { WIRESHARK_STOCK_COLOR7,               icon_color_7_xpm,         24},
359         { WIRESHARK_STOCK_COLOR8,               icon_color_8_xpm,         24},
360         { WIRESHARK_STOCK_COLOR9,               icon_color_9_xpm,         24},
361         { WIRESHARK_STOCK_COLOR0,               icon_color_0_xpm,         24},
362         { WIRESHARK_STOCK_DECODE,               decode_24_xpm,            24},
363         { WIRESHARK_STOCK_AUDIO_PLAYER,         audio_player_24_xpm,      24},
364         { WIRESHARK_STOCK_VOIP_FLOW,            voip_flow_24_xpm,         24},
365         { WIRESHARK_STOCK_TELEPHONE,            telephone_16_xpm,         16},
366         { WIRESHARK_STOCK_PREPARE_FILTER,       display_filter_24_xpm,    24},
367         { WIRESHARK_STOCK_ANALYZE,              analyze_24_xpm,           24},
368         { NULL,                                 NULL,                     0}
369     };
370
371     /* sort lookup arrays */
372     qsort(ws_stock_items, sizeof(ws_stock_items)/sizeof(ws_stock_items[0]),
373           sizeof(ws_stock_items[0]), (int (*)(const void *, const void *))si_cmp);
374     qsort(gtk_stock_items, sizeof(gtk_stock_items)/sizeof(gtk_stock_items[0]),
375           sizeof(gtk_stock_items[0]), (int (*)(const void *, const void *))si_cmp);
376
377 #if !GTK_CHECK_VERSION(3, 10, 0)
378     for (i = 0; i < (sizeof(ws_stock_items) / sizeof(ws_stock_items[0])) ; i++) {
379         GtkStockItem stock_item =
380                 {(char *)ws_stock_items[i].name,
381                  (char *)ws_stock_items[i].label,
382                  (GdkModifierType)0, 0, NULL};
383         gtk_stock_add(&stock_item, 1);
384     }
385     /* Add our custom icon factory to the list of defaults */
386     factory = gtk_icon_factory_new();
387     gtk_icon_factory_add_default(factory);
388 #endif
389
390     /* Add pixmaps as builtin theme icons */
391     /* Please use pixbufs (below) for new icons */
392     for (i = 0; pixmaps[i].name != NULL; i++) {
393         /* The default icon */
394         GdkPixbuf * pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) (pixmaps[i].xpm_data));
395         g_assert(pixbuf);
396 #if !GTK_CHECK_VERSION(3, 10, 0)
397         icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
398         gtk_icon_factory_add (factory, pixmaps[i].name, icon_set);
399         gtk_icon_set_unref (icon_set);
400 #endif
401         gtk_icon_theme_add_builtin_icon(pixmaps[i].name, pixmaps[i].size, pixbuf);
402         g_object_unref (G_OBJECT (pixbuf));
403     }
404
405     /* Add pixbufs as builtin theme icons */
406     for (i = 0; pixbufs[i].name != NULL; i++) {
407         GdkPixbuf * pixbuf24 = gdk_pixbuf_new_from_inline(-1, pixbufs[i].pb_data24, FALSE, NULL);
408         g_assert(pixbuf24);
409 #if !GTK_CHECK_VERSION(3, 10, 0)
410         icon_set = gtk_icon_set_new_from_pixbuf(pixbuf24);
411         gtk_icon_factory_add (factory, pixbufs[i].name, icon_set);
412         gtk_icon_set_unref (icon_set);
413 #endif
414         /* Default image */
415         gtk_icon_theme_add_builtin_icon(pixbufs[i].name, 24, pixbuf24);
416
417
418         if (pixbufs[i].pb_data16) {
419             GdkPixbuf * pixbuf16 = gdk_pixbuf_new_from_inline(-1, pixbufs[i].pb_data16, FALSE, NULL);
420             g_assert(pixbuf16);
421 #if !GTK_CHECK_VERSION(3, 10, 0)
422             source16 = gtk_icon_source_new();
423             gtk_icon_source_set_pixbuf(source16, pixbuf16);
424             gtk_icon_source_set_size_wildcarded(source16, FALSE);
425             gtk_icon_source_set_size(source16, GTK_ICON_SIZE_MENU);
426
427             /* Twice? Really? Seriously? */
428             source16 = gtk_icon_source_new();
429             gtk_icon_source_set_pixbuf(source16, pixbuf16);
430             gtk_icon_source_set_size_wildcarded(source16, FALSE);
431             gtk_icon_source_set_size(source16, GTK_ICON_SIZE_SMALL_TOOLBAR);
432 #else
433             gtk_icon_theme_add_builtin_icon(pixbufs[i].name, 16, pixbuf16);
434 #endif
435             g_object_unref (G_OBJECT (pixbuf16));
436         }
437         g_object_unref (G_OBJECT (pixbuf24));
438     }
439 #if !GTK_CHECK_VERSION(3, 10, 0)
440     /* use default stock icons for Wireshark specifics where the icon metapher makes sense */
441     /* PLEASE DON'T REUSE STOCK ICONS IF THEY ARE USUALLY USED FOR SOME DIFFERENT MEANING!!!) */
442
443     for (i = 0; i < (sizeof(ws_stock_items) / sizeof(ws_stock_items[0])) ; i++) {
444         stock_item_t * fallback_item = NULL;
445         if (NULL != (fallback_item = BS(ws_stock_items[i].icon, gtk_stock_items))) {
446             icon_set = gtk_icon_factory_lookup_default(fallback_item->name);
447             gtk_icon_factory_add(factory, ws_stock_items[i].name, icon_set);
448         }
449     }
450 #endif
451 }
452
453 GtkWidget * ws_gtk_button_new_from_stock(const gchar *stock_id) {
454 #if !GTK_CHECK_VERSION(3, 10, 0)
455         return gtk_button_new_from_stock(stock_id);
456 #else
457     GtkWidget * b;
458     stock_item_t * i = NULL;
459     if (NULL != (i = BS(stock_id, gtk_stock_items))) {
460         /* GTK stock item*/
461         return gtk_button_new_with_mnemonic(i->label);
462     } else if (NULL != (i = BS(stock_id, ws_stock_items))) {
463         /* Wireshark stock item*/
464         stock_item_t * fallback_item;
465         if (NULL != (fallback_item = BS(i->icon, gtk_stock_items))) {
466             /* Wireshark fallback item uses a GTK stock icon*/
467             b = gtk_button_new_from_icon_name(fallback_item->icon, GTK_ICON_SIZE_BUTTON);
468         } else {
469             b = gtk_button_new_from_icon_name(i->icon, GTK_ICON_SIZE_BUTTON);
470         }
471         gtk_button_set_label(GTK_BUTTON(b), i->label);
472         gtk_button_set_use_underline(GTK_BUTTON(b), TRUE);
473         return b;
474     }
475     return NULL;
476 #endif
477 }
478
479 #define LBL_UNDERLINE(type, tb, lbl_item)                    \
480     gtk_tool_button_set_label(type(tb), (lbl_item)->label);  \
481     gtk_tool_button_set_use_underline(type(tb), TRUE);
482
483 GtkToolItem * ws_gtk_tool_button_new_from_stock(const gchar *stock_id) {
484 #if !GTK_CHECK_VERSION(3, 10, 0)
485     return gtk_tool_button_new_from_stock(stock_id);
486 #else
487     GtkToolItem * b = NULL;
488     stock_item_t * i = NULL;
489     if (NULL != (i = BS(stock_id, gtk_stock_items))) {
490         /* GTK stock item*/
491         b = gtk_tool_button_new(NULL, i->label);
492         gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(b), TRUE);
493         gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (b), i->icon);
494     } else if (NULL != (i = BS(stock_id, ws_stock_items))) {
495         /* Wireshark stock item*/
496         stock_item_t * fallback_item;
497         if (NULL != (fallback_item = BS(i->icon, gtk_stock_items))) {
498             /* Wireshark fallback item uses a GTK stock icon*/
499             b = gtk_tool_button_new(NULL, i->label);
500             gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(b), TRUE);
501             gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(b), fallback_item->icon);
502         } else {
503             b = gtk_tool_button_new(NULL, i->label);
504             gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(b), i->icon);
505         }
506     }
507     return b;
508 #endif
509 }
510
511 GtkToolItem * ws_gtk_toggle_tool_button_new_from_stock(const gchar *stock_id) {
512 #if !GTK_CHECK_VERSION(3, 10, 0)
513     return gtk_toggle_tool_button_new_from_stock(stock_id);
514 #else
515     GtkToolItem * b = NULL;
516     stock_item_t * i = NULL;
517     if (NULL != (i = BS(stock_id, gtk_stock_items))) {
518         /* GTK stock item*/
519         b = gtk_toggle_tool_button_new();
520         gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (b), i->icon);
521         LBL_UNDERLINE(GTK_TOOL_BUTTON, b, i);
522     } else if (NULL != (i = BS(stock_id, ws_stock_items))) {
523         /* Wireshark stock item*/
524         stock_item_t * fallback_item;
525         if (NULL != (fallback_item = BS(i->icon, gtk_stock_items))) {
526             /* Wireshark fallback item uses a GTK stock icon*/
527             b = gtk_toggle_tool_button_new();
528             gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (b), fallback_item->icon);
529             LBL_UNDERLINE(GTK_TOOL_BUTTON, b, i);
530         } else {
531             b = gtk_toggle_tool_button_new();
532             gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (b), i->icon);
533             LBL_UNDERLINE(GTK_TOOL_BUTTON, b, i);
534         }
535     }
536     return b;
537 #endif
538 }
539
540 GtkWidget * ws_gtk_image_new_from_stock(const gchar *stock_id, GtkIconSize size) {
541 #if !GTK_CHECK_VERSION(3, 10, 0)
542         return gtk_image_new_from_stock(stock_id, size);
543 #else
544     stock_item_t * i = NULL;
545     if (NULL != (i = BS(stock_id, gtk_stock_items))) {
546         /* GTK stock item*/
547         return gtk_image_new_from_icon_name(i->icon, size);
548     } else if (NULL != (i = BS(stock_id, ws_stock_items))) {
549         /* Wireshark stock item*/
550         stock_item_t * fallback_item;
551         if (NULL != (fallback_item = BS(i->icon, gtk_stock_items))) {
552             /* Wireshark fallback item uses a GTK stock icon*/
553             return gtk_image_new_from_icon_name(fallback_item->icon, size);
554         } else {
555             return gtk_image_new_from_icon_name(i->icon, size);
556         }
557     }
558     return NULL;
559 #endif
560 }
561
562 /*
563  * Editor modelines
564  *
565  * Local Variables:
566  * c-basic-offset: 4
567  * tab-width: 8
568  * indent-tabs-mode: nil
569  * End:
570  *
571  * ex: set shiftwidth=4 tabstop=8 expandtab:
572  * :indentSize=4:tabSize=8:noTabs=true:
573  */