d4a87f51789a6b07bc5b4e6144bc12465874c7cb
[lttv.git] / lttv / modules / gui / histogram / histobuttonwidget.c
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., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, 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 GtkWidget *xpm_label_box( gchar *xpm_filename,
50 gchar *label_text );
51 static gboolean gplus( GtkWidget *widget,gpointer user_data)
52 {
53 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
54 //histo_cfd->vertical_ratio =histo_cfd->vertical_ratio * (1.0/2.0);
55 if(histo_cfd->max_height>1)
56 {
57 histo_cfd->max_height /= 2;
58 //just redraw.horizontal scale is not changed so Array's data are valid.
59 histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len);
60 }
61 else
62 g_warning("Zoom more than 1 event is impossible");
63
64 histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window);
65 return 0;
66 }
67
68 static gboolean gMinus( GtkWidget *widget,
69 gpointer user_data )
70 {
71 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
72 histo_cfd->max_height *= 2;
73
74 //just redraw.horizontal scale is not changed so Array's data are valid.
75 histogram_show(histo_cfd ,0,histo_cfd->number_of_process->len);
76 histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window);
77 return 0;
78 }
79
80 static gboolean gFit( GtkWidget *widget,
81 gpointer user_data )
82 {
83 /*find the maximum value and put max_height equal with this maximum*/
84 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
85 gint i=1,x;
86 guint maximum;
87 maximum =g_array_index(histo_cfd->number_of_process,guint,i);
88 for (i=1; i < histo_cfd->number_of_process-> len ;i++)
89 {
90 x=g_array_index(histo_cfd->number_of_process,guint,i);
91 maximum=MAX(x,maximum);
92 }
93 if (maximum >0)
94 {
95 histo_cfd->max_height=maximum;
96 histogram_show (histo_cfd,0,histo_cfd->number_of_process->len);
97 }
98 histo_drawing_update_vertical_ruler(histo_cfd->drawing);
99
100 return 0;
101 }
102 /* Create a new hbox with an image and a label packed into it
103 * and return the box. */
104
105 static GtkWidget *xpm_label_box( gchar* xpm_filename,
106 gchar *label_text )
107 {
108 GtkWidget *box;
109 GtkWidget *label;
110 GtkWidget *image;
111
112 GdkPixbuf *pixbufP;
113 //GError **error;
114 /* Create box for image and label */
115 box = gtk_hbox_new (FALSE, 0);
116 gtk_container_set_border_width (GTK_CONTAINER (box), 1);
117
118 /* Now on to the image stuff */
119
120 pixbufP = gdk_pixbuf_new_from_xpm_data((const char **)&xpm_filename);
121 image = gtk_image_new_from_pixbuf(pixbufP);
122
123 /* Create a label for the button */
124 label = gtk_label_new (label_text);
125
126 /* Pack the image and label into the box */
127 gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 1);
128 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 1);
129
130 gtk_widget_show (image);
131 gtk_widget_show (label);
132
133 return box;
134 }
135
136 ButtonWidget *histo_buttonwidget_construct(HistoControlFlowData *histocontrol_flow_data)
137 {
138 GtkWidget *boxPlus, *boxMinus , *boxfit;//containing text and image for each button.
139
140 ButtonWidget *buttonwidget = g_new(ButtonWidget,1);
141 buttonwidget->histo_control_flow_data = histocontrol_flow_data;
142 /* Put + and - on the vbox and assign related functions to each button */
143 buttonwidget-> vbox1 = gtk_vbox_new (FALSE, 0);
144
145 // Add 2 buttons on the vbox
146 // buttonwidget ->buttonP = gtk_button_new_with_mnemonic ("+");
147 // buttonwidget->buttonM = gtk_button_new_with_mnemonic ("-");
148 // Instead, add 2 button with image and text:
149
150 buttonwidget ->buttonP =gtk_button_new ();
151 buttonwidget ->buttonM =gtk_button_new ();
152 buttonwidget ->buttonFit =gtk_button_new ();
153
154 /* This calls our box creating function */
155 boxPlus = xpm_label_box ("stock_zoom_in_24.xpm", "vertical");
156 boxMinus = xpm_label_box ("stock_zoom_out_24.xpm", "vertical");
157 boxfit = xpm_label_box ("stock_zoom_fit_24.xpm", "vertical");
158
159 /* Pack and show all widgets */
160 gtk_widget_show (boxPlus);
161 gtk_widget_show (boxMinus);
162 gtk_widget_show (boxfit);
163
164 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonP), boxPlus);
165 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonM), boxMinus);
166 gtk_container_add (GTK_CONTAINER (buttonwidget -> buttonFit), boxfit);
167
168 gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonP, TRUE, FALSE, 0);
169 gtk_box_pack_start (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonM, TRUE, FALSE, 0);
170 gtk_box_pack_end (GTK_BOX (buttonwidget->vbox1),buttonwidget->buttonFit, TRUE, FALSE, 0);
171
172 /* When the button receives the "clicked" signal, it will call the
173 * function gplus() passing it NULL as its argument. The gplus()
174 * function is defined above . */
175
176 g_signal_connect (G_OBJECT (buttonwidget ->buttonP), "clicked",
177 G_CALLBACK (gplus), (gpointer)histocontrol_flow_data);
178 g_signal_connect (G_OBJECT ( buttonwidget->buttonM), "clicked",
179 G_CALLBACK (gMinus), (gpointer)histocontrol_flow_data);
180 g_signal_connect (G_OBJECT ( buttonwidget->buttonFit), "clicked",
181 G_CALLBACK (gFit), (gpointer)histocontrol_flow_data);
182
183 gtk_widget_show (buttonwidget -> vbox1);
184 gtk_widget_show (buttonwidget ->buttonP);
185 gtk_widget_show (buttonwidget ->buttonM);
186 gtk_widget_show (buttonwidget ->buttonFit);
187
188 return buttonwidget;
189 }
190
191 void histo_buttonwidget_destroy(ButtonWidget *buttonwidget)
192 {
193 g_debug("buttonwidget_destroy %p", buttonwidget);
194
195 g_free(buttonwidget);
196 g_debug("buttonwidget_destroy end");
197 }
198
199 GtkWidget *histo_buttonwidget_get_widget(ButtonWidget *button_widget)
200 {
201 return button_widget->vbox1;
202 }
203
204
205
206 void histo_rectangle_pixmap (GdkGC *gc,
207 gboolean filled, gint x, gint y, gint width, gint height,
208 histoDrawing_t *value)
209 {
210 if(height == -1)
211 height = value->drawing_area->allocation.height;
212 if(width == -1)
213 height = value->drawing_area->allocation.width;
214 gdk_draw_rectangle (value->pixmap,
215 gc,
216 filled,
217 x, y,
218 width, height);
219 }
220
221 //This could be usefull if a vertical scroll bar is added to viewer:
222 void histo_copy_pixmap_region(histoDrawing_t *drawing,GdkDrawable *dest,
223 GdkGC *gc, GdkDrawable *src,
224 gint xsrc, gint ysrc,
225 gint xdest, gint ydest, gint width, gint height)
226 {
227
228 if(dest == NULL)
229 dest = drawing->pixmap;
230 if(src == NULL)
231 src = drawing->pixmap;
232
233 gdk_draw_drawable (dest,gc,src,xsrc, ysrc,
234 xdest, ydest,width, height);
235 }
236
237 void histo_update_pixmap_size(histoDrawing_t *value,
238 guint width)
239 {
240 GdkPixmap *old_pixmap = value->pixmap;
241
242 value->pixmap =
243 gdk_pixmap_new(old_pixmap,
244 width,
245 value->height,
246 -1);
247
248 gdk_pixmap_unref(old_pixmap);
249 }
250
This page took 0.034001 seconds and 3 git commands to generate.