| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2006 Parisa Heidari |
| 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., 51 Franklin Street, Fifth Floor, Boston, |
| 16 | * MA 02110-1301, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
| 23 | #include <gtk/gtk.h> |
| 24 | #include <glib.h> |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <math.h> |
| 28 | |
| 29 | #include "histobuttonwidget.h" |
| 30 | #include "histodrawing.h" |
| 31 | #include "histodrawitem.h" |
| 32 | |
| 33 | extern void histogram_show(HistoControlFlowData *histocontrol_flow_data, |
| 34 | guint draw_begin, guint draw_end); |
| 35 | |
| 36 | #ifndef g_info |
| 37 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
| 38 | #endif |
| 39 | #ifndef g_debug |
| 40 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
| 41 | #endif |
| 42 | |
| 43 | /* Preallocated Size of the index_to_pixmap array */ |
| 44 | #define ALLOCATE_PROCESSES 1000 |
| 45 | |
| 46 | /***************************************************************************** |
| 47 | * * |
| 48 | *****************************************************************************/ |
| 49 | static gboolean gplus( GtkWidget *widget,gpointer user_data) |
| 50 | { |
| 51 | HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data; |
| 52 | //histo_cfd->vertical_ratio =histo_cfd->vertical_ratio * (1.0/2.0); |
| 53 | if(histo_cfd->max_height>1) |
| 54 | { |
| 55 | histo_cfd->max_height /= 2; |
| 56 | //just redraw.horizontal scale is not changed so Array's data are valid. |
| 57 | histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len); |
| 58 | } |
| 59 | else |
| 60 | g_warning("Zoom more than 1 event is impossible"); |
| 61 | |
| 62 | histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static gboolean gMinus( GtkWidget *widget, |
| 67 | gpointer user_data ) |
| 68 | { |
| 69 | HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data; |
| 70 | histo_cfd->max_height *= 2; |
| 71 | |
| 72 | //just redraw.horizontal scale is not changed so Array's data are valid. |
| 73 | histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len); |
| 74 | histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static gboolean gFit( GtkWidget *widget, |
| 79 | gpointer user_data ) |
| 80 | { |
| 81 | /*find the maximum value and put max_height equal with this maximum*/ |
| 82 | HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data; |
| 83 | gint i=1,x; |
| 84 | guint maximum; |
| 85 | maximum =g_array_index(histo_cfd->number_of_process,guint,i); |
| 86 | for (i=1; i < histo_cfd->number_of_process-> len ;i++) |
| 87 | { |
| 88 | x=g_array_index(histo_cfd->number_of_process,guint,i); |
| 89 | maximum=MAX(x,maximum); |
| 90 | } |
| 91 | if (maximum >0) |
| 92 | { |
| 93 | histo_cfd->max_height=maximum; |
| 94 | histogram_show (histo_cfd,0,histo_cfd->number_of_process->len); |
| 95 | } |
| 96 | histo_drawing_update_vertical_ruler(histo_cfd->drawing); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static GtkWidget* new_button_with_icon(const gchar *icon_name) { |
| 102 | |
| 103 | GtkWidget *button = gtk_button_new(); |
| 104 | |
| 105 | gtk_button_set_image((GtkButton *)button, |
| 106 | gtk_image_new_from_icon_name(icon_name, |
| 107 | GTK_ICON_SIZE_BUTTON)); |
| 108 | return button; |
| 109 | } |
| 110 | |
| 111 | ButtonWidget *histo_buttonwidget_construct(HistoControlFlowData *histocontrol_flow_data) |
| 112 | { |
| 113 | ButtonWidget *buttonwidget = g_new(ButtonWidget,1); |
| 114 | buttonwidget->histo_control_flow_data = histocontrol_flow_data; |
| 115 | /* Put + and - on the vbox and assign related functions to each button */ |
| 116 | buttonwidget-> vbox1 = gtk_vbox_new (FALSE, 0); |
| 117 | |
| 118 | buttonwidget->buttonP = new_button_with_icon (GTK_STOCK_ZOOM_IN); |
| 119 | buttonwidget->buttonM = new_button_with_icon (GTK_STOCK_ZOOM_OUT); |
| 120 | buttonwidget->buttonFit = new_button_with_icon (GTK_STOCK_ZOOM_FIT); |
| 121 | |
| 122 | /* Pack and show all widgets */ |
| 123 | |
| 124 | gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonP, TRUE, FALSE, 0); |
| 125 | gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonM, TRUE, FALSE, 0); |
| 126 | gtk_box_pack_end (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonFit, TRUE, FALSE, 0); |
| 127 | |
| 128 | /* When the button receives the "clicked" signal, it will call the |
| 129 | * function gplus() passing it NULL as its argument. The gplus() |
| 130 | * function is defined above . */ |
| 131 | |
| 132 | g_signal_connect (G_OBJECT (buttonwidget ->buttonP), "clicked", |
| 133 | G_CALLBACK (gplus), (gpointer)histocontrol_flow_data); |
| 134 | g_signal_connect (G_OBJECT ( buttonwidget->buttonM), "clicked", |
| 135 | G_CALLBACK (gMinus), (gpointer)histocontrol_flow_data); |
| 136 | g_signal_connect (G_OBJECT ( buttonwidget->buttonFit), "clicked", |
| 137 | G_CALLBACK (gFit), (gpointer)histocontrol_flow_data); |
| 138 | |
| 139 | gtk_widget_show (buttonwidget -> vbox1); |
| 140 | gtk_widget_show (buttonwidget ->buttonP); |
| 141 | gtk_widget_show (buttonwidget ->buttonM); |
| 142 | gtk_widget_show (buttonwidget ->buttonFit); |
| 143 | |
| 144 | return buttonwidget; |
| 145 | } |
| 146 | |
| 147 | void histo_buttonwidget_destroy(ButtonWidget *buttonwidget) |
| 148 | { |
| 149 | g_debug("buttonwidget_destroy %p", buttonwidget); |
| 150 | |
| 151 | g_free(buttonwidget); |
| 152 | g_debug("buttonwidget_destroy end"); |
| 153 | } |
| 154 | |
| 155 | GtkWidget *histo_buttonwidget_get_widget(ButtonWidget *button_widget) |
| 156 | { |
| 157 | return button_widget->vbox1; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | void histo_rectangle_pixmap (GdkGC *gc, |
| 163 | gboolean filled, gint x, gint y, gint width, gint height, |
| 164 | histoDrawing_t *value) |
| 165 | { |
| 166 | if(height == -1) |
| 167 | height = value->drawing_area->allocation.height; |
| 168 | if(width == -1) |
| 169 | height = value->drawing_area->allocation.width; |
| 170 | gdk_draw_rectangle (value->pixmap, |
| 171 | gc, |
| 172 | filled, |
| 173 | x, y, |
| 174 | width, height); |
| 175 | } |
| 176 | |
| 177 | //This could be usefull if a vertical scroll bar is added to viewer: |
| 178 | void histo_copy_pixmap_region(histoDrawing_t *drawing,GdkDrawable *dest, |
| 179 | GdkGC *gc, GdkDrawable *src, |
| 180 | gint xsrc, gint ysrc, |
| 181 | gint xdest, gint ydest, gint width, gint height) |
| 182 | { |
| 183 | |
| 184 | if(dest == NULL) |
| 185 | dest = drawing->pixmap; |
| 186 | if(src == NULL) |
| 187 | src = drawing->pixmap; |
| 188 | |
| 189 | gdk_draw_drawable (dest,gc,src,xsrc, ysrc, |
| 190 | xdest, ydest,width, height); |
| 191 | } |
| 192 | |
| 193 | void histo_update_pixmap_size(histoDrawing_t *value, |
| 194 | guint width) |
| 195 | { |
| 196 | GdkPixmap *old_pixmap = value->pixmap; |
| 197 | |
| 198 | value->pixmap = |
| 199 | gdk_pixmap_new(old_pixmap, |
| 200 | width, |
| 201 | value->height, |
| 202 | -1); |
| 203 | |
| 204 | gdk_pixmap_unref(old_pixmap); |
| 205 | } |
| 206 | |