1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2006 Parisa Heidari
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;
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.
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,
29 #include "histobuttonwidget.h"
30 #include "histodrawing.h"
31 #include "histodrawitem.h"
32 #include "stock_zoom_in_24.xpm"
33 #include "stock_zoom_out_24.xpm"
34 #include "stock_zoom_fit_24.xpm"
36 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
37 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
39 /* Preallocated Size of the index_to_pixmap array */
40 #define ALLOCATE_PROCESSES 1000
42 /*****************************************************************************
44 *****************************************************************************/
45 static GtkWidget *xpm_label_box( gchar *xpm_filename,
47 static gboolean gplus( GtkWidget *widget,gpointer user_data)
49 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
50 //histo_cfd->vertical_ratio =histo_cfd->vertical_ratio * (1.0/2.0);
51 if(histo_cfd->max_height>1)
53 histo_cfd->max_height /= 2;
54 //just redraw.horizontal scale is not changed so Array's data are valid.
55 histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len);
58 g_warning("Zoom more than 1 event is impossible");
60 histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window);
64 static gboolean gMinus( GtkWidget *widget,
67 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
68 histo_cfd->max_height *= 2;
70 //just redraw.horizontal scale is not changed so Array's data are valid.
71 histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len);
72 histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window);
76 static gboolean gFit( GtkWidget *widget,
79 /*find the maximum value and put max_height equal with this maximum*/
80 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
83 maximum =g_array_index(histo_cfd->number_of_process,guint,i);
84 for (i=1; i < histo_cfd->number_of_process-> len ;i++)
86 x=g_array_index(histo_cfd->number_of_process,guint,i);
87 maximum=MAX(x,maximum);
91 histo_cfd->max_height=maximum;
92 histogram_show (histo_cfd,0,histo_cfd->number_of_process->len);
94 histo_drawing_update_vertical_ruler(histo_cfd->drawing);
98 /* Create a new hbox with an image and a label packed into it
99 * and return the box. */
101 static GtkWidget *xpm_label_box( gchar* xpm_filename,
110 /* Create box for image and label */
111 box = gtk_hbox_new (FALSE, 0);
112 gtk_container_set_border_width (GTK_CONTAINER (box), 1);
114 /* Now on to the image stuff */
116 pixbufP = gdk_pixbuf_new_from_xpm_data((const char*)xpm_filename);
117 image = gtk_image_new_from_pixbuf(pixbufP);
119 /* Create a label for the button */
120 label = gtk_label_new (label_text);
122 /* Pack the image and label into the box */
123 gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 1);
124 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 1);
126 gtk_widget_show (image);
127 gtk_widget_show (label);
132 ButtonWidget *histo_buttonwidget_construct(HistoControlFlowData *histocontrol_flow_data)
134 GtkWidget *boxPlus, *boxMinus , *boxfit;//containing text and image for each button.
136 ButtonWidget *buttonwidget = g_new(ButtonWidget,1);
137 buttonwidget->histo_control_flow_data = histocontrol_flow_data;
138 /* Put + and - on the vbox and assign related functions to each button */
139 buttonwidget-> vbox1 = gtk_vbox_new (FALSE, 0);
141 // Add 2 buttons on the vbox
142 // buttonwidget ->buttonP = gtk_button_new_with_mnemonic ("+");
143 // buttonwidget->buttonM = gtk_button_new_with_mnemonic ("-");
144 // Instead, add 2 button with image and text:
146 buttonwidget ->buttonP =gtk_button_new ();
147 buttonwidget ->buttonM =gtk_button_new ();
148 buttonwidget ->buttonFit =gtk_button_new ();
150 /* This calls our box creating function */
151 boxPlus = xpm_label_box (stock_zoom_in_24, "vertical");
152 boxMinus = xpm_label_box (stock_zoom_out_24, "vertical");
153 boxfit = xpm_label_box (stock_zoom_fit_24, "vertical");
155 /* Pack and show all widgets */
156 gtk_widget_show (boxPlus);
157 gtk_widget_show (boxMinus);
158 gtk_widget_show (boxfit);
160 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonP), boxPlus);
161 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonM), boxMinus);
162 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonFit), boxfit);
164 gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonP, TRUE, FALSE, 0);
165 gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonM, TRUE, FALSE, 0);
166 gtk_box_pack_end (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonFit, TRUE, FALSE, 0);
168 /* When the button receives the "clicked" signal, it will call the
169 * function gplus() passing it NULL as its argument. The gplus()
170 * function is defined above . */
172 g_signal_connect (G_OBJECT (buttonwidget ->buttonP), "clicked",
173 G_CALLBACK (gplus), (gpointer)histocontrol_flow_data);
174 g_signal_connect (G_OBJECT ( buttonwidget->buttonM), "clicked",
175 G_CALLBACK (gMinus), (gpointer)histocontrol_flow_data);
176 g_signal_connect (G_OBJECT ( buttonwidget->buttonFit), "clicked",
177 G_CALLBACK (gFit), (gpointer)histocontrol_flow_data);
179 gtk_widget_show (buttonwidget -> vbox1);
180 gtk_widget_show (buttonwidget ->buttonP);
181 gtk_widget_show (buttonwidget ->buttonM);
182 gtk_widget_show (buttonwidget ->buttonFit);
187 void histo_buttonwidget_destroy(ButtonWidget *buttonwidget)
189 g_debug("buttonwidget_destroy %p", buttonwidget);
191 g_free(buttonwidget);
192 g_debug("buttonwidget_destroy end");
195 GtkWidget *histo_buttonwidget_get_widget(ButtonWidget *button_widget)
197 return button_widget->vbox1;
202 void histo_rectangle_pixmap (GdkGC *gc,
203 gboolean filled, gint x, gint y, gint width, gint height,
204 histoDrawing_t *value)
207 height = value->drawing_area->allocation.height;
209 height = value->drawing_area->allocation.width;
210 gdk_draw_rectangle (value->pixmap,
217 //This could be usefull if a vertical scroll bar is added to viewer:
218 void histo_copy_pixmap_region(histoDrawing_t *drawing,GdkDrawable *dest,
219 GdkGC *gc, GdkDrawable *src,
220 gint xsrc, gint ysrc,
221 gint xdest, gint ydest, gint width, gint height)
225 dest = drawing->pixmap;
227 src = drawing->pixmap;
229 gdk_draw_drawable (dest,gc,src,xsrc, ysrc,
230 xdest, ydest,width, height);
233 void histo_update_pixmap_size(histoDrawing_t *value,
236 GdkPixmap *old_pixmap = value->pixmap;
239 gdk_pixmap_new(old_pixmap,
244 gdk_pixmap_unref(old_pixmap);