| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 XangXiu Yang |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <lttv/lttv.h> |
| 20 | #include <lttvwindow/toolbar.h> |
| 21 | |
| 22 | inline LttvToolbars *lttv_toolbars_new() { |
| 23 | return g_array_new(FALSE, FALSE, sizeof(LttvToolbarClosure)); |
| 24 | } |
| 25 | |
| 26 | /* MD: delete elements of the array also, but don't free pointed addresses |
| 27 | * (functions). |
| 28 | */ |
| 29 | inline void lttv_toolbars_destroy(LttvToolbars *h) { |
| 30 | g_debug("lttv_toolbars_destroy"); |
| 31 | g_array_free(h, TRUE); |
| 32 | } |
| 33 | |
| 34 | inline LttvToolbarClosure lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap, GtkWidget *widget) |
| 35 | { |
| 36 | LttvToolbarClosure c; |
| 37 | |
| 38 | /* if h is null, do nothing, or popup a warning message */ |
| 39 | if(h == NULL)return; |
| 40 | |
| 41 | c.con = f; |
| 42 | c.tooltip = tooltip; |
| 43 | c.pixmap = pixmap; |
| 44 | c.widget = widget; |
| 45 | g_array_append_val(h,c); |
| 46 | |
| 47 | return c; |
| 48 | } |
| 49 | |
| 50 | GtkWidget *lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f) |
| 51 | { |
| 52 | LttvToolbarClosure * tmp; |
| 53 | gint i; |
| 54 | GtkWidget *widget; |
| 55 | |
| 56 | for(i=0;i<h->len;i++){ |
| 57 | tmp = & g_array_index(h, LttvToolbarClosure, i); |
| 58 | if(tmp->con == f) { |
| 59 | widget = tmp->widget; |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | if(i<h->len){ |
| 64 | g_array_remove_index(h, i); |
| 65 | return widget; |
| 66 | }else return NULL; |
| 67 | } |
| 68 | |
| 69 | unsigned lttv_toolbars_number(LttvToolbars *h) |
| 70 | { |
| 71 | return h->len; |
| 72 | } |
| 73 | |
| 74 | |