update compat
[lttv.git] / tags / lttv-0.11.3-23102008 / lttv / modules / gui / histogram / histobuttonwidget.c
CommitLineData
13ab9fcb 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#include "stock_zoom_in_24.xpm"
33#include "stock_zoom_out_24.xpm"
34#include "stock_zoom_fit_24.xpm"
35
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)
38
39/* Preallocated Size of the index_to_pixmap array */
40#define ALLOCATE_PROCESSES 1000
41
42/*****************************************************************************
43 * *
44 *****************************************************************************/
45static GtkWidget *xpm_label_box( gchar *xpm_filename,
46 gchar *label_text );
47static gboolean gplus( GtkWidget *widget,gpointer user_data)
48{
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)
52 {
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);
56 }
57 else
58 g_warning("Zoom more than 1 event is impossible");
59
60 histo_drawing_update_vertical_ruler(histo_cfd->drawing);//, TimeWindow *time_window);
61 return 0;
62}
63
64static gboolean gMinus( GtkWidget *widget,
65 gpointer user_data )
66{
67 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
68 histo_cfd->max_height *= 2;
69
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);
73 return 0;
74}
75
76static gboolean gFit( GtkWidget *widget,
77 gpointer user_data )
78{
79 /*find the maximum value and put max_height equal with this maximum*/
80 HistoControlFlowData *histo_cfd = (HistoControlFlowData *)user_data;
81 gint i=1,x;
82 guint maximum;
83 maximum =g_array_index(histo_cfd->number_of_process,guint,i);
84 for (i=1; i < histo_cfd->number_of_process-> len ;i++)
85 {
86 x=g_array_index(histo_cfd->number_of_process,guint,i);
87 maximum=MAX(x,maximum);
88 }
89 if (maximum >0)
90 {
91 histo_cfd->max_height=maximum;
92 histogram_show (histo_cfd,0,histo_cfd->number_of_process->len);
93 }
94 histo_drawing_update_vertical_ruler(histo_cfd->drawing);
95
96 return 0;
97}
98/* Create a new hbox with an image and a label packed into it
99 * and return the box. */
100
101static GtkWidget *xpm_label_box( gchar* xpm_filename,
102 gchar *label_text )
103{
104 GtkWidget *box;
105 GtkWidget *label;
106 GtkWidget *image;
107
108 GdkPixbuf *pixbufP;
109 //GError **error;
110 /* Create box for image and label */
111 box = gtk_hbox_new (FALSE, 0);
112 gtk_container_set_border_width (GTK_CONTAINER (box), 1);
113
114 /* Now on to the image stuff */
115
116 pixbufP = gdk_pixbuf_new_from_xpm_data((const char*)xpm_filename);
117 image = gtk_image_new_from_pixbuf(pixbufP);
118
119 /* Create a label for the button */
120 label = gtk_label_new (label_text);
121
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);
125
126 gtk_widget_show (image);
127 gtk_widget_show (label);
128
129 return box;
130}
131
132ButtonWidget *histo_buttonwidget_construct(HistoControlFlowData *histocontrol_flow_data)
133{
134 GtkWidget *boxPlus, *boxMinus , *boxfit;//containing text and image for each button.
135
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);
140
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:
145
146 buttonwidget ->buttonP =gtk_button_new ();
147 buttonwidget ->buttonM =gtk_button_new ();
148 buttonwidget ->buttonFit =gtk_button_new ();
149
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");
154
155/* Pack and show all widgets */
156 gtk_widget_show (boxPlus);
157 gtk_widget_show (boxMinus);
158 gtk_widget_show (boxfit);
159
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);
163
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);
167
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 . */
171
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);
178
179 gtk_widget_show (buttonwidget -> vbox1);
180 gtk_widget_show (buttonwidget ->buttonP);
181 gtk_widget_show (buttonwidget ->buttonM);
182 gtk_widget_show (buttonwidget ->buttonFit);
183
184 return buttonwidget;
185}
186
187void histo_buttonwidget_destroy(ButtonWidget *buttonwidget)
188{
189 g_debug("buttonwidget_destroy %p", buttonwidget);
190
191 g_free(buttonwidget);
192 g_debug("buttonwidget_destroy end");
193}
194
195GtkWidget *histo_buttonwidget_get_widget(ButtonWidget *button_widget)
196{
197 return button_widget->vbox1;
198}
199
200
201
202void histo_rectangle_pixmap (GdkGC *gc,
203 gboolean filled, gint x, gint y, gint width, gint height,
204 histoDrawing_t *value)
205{
206 if(height == -1)
207 height = value->drawing_area->allocation.height;
208 if(width == -1)
209 height = value->drawing_area->allocation.width;
210 gdk_draw_rectangle (value->pixmap,
211 gc,
212 filled,
213 x, y,
214 width, height);
215}
216
217//This could be usefull if a vertical scroll bar is added to viewer:
218void 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)
222{
223
224 if(dest == NULL)
225 dest = drawing->pixmap;
226 if(src == NULL)
227 src = drawing->pixmap;
228
229 gdk_draw_drawable (dest,gc,src,xsrc, ysrc,
230 xdest, ydest,width, height);
231}
232
233void histo_update_pixmap_size(histoDrawing_t *value,
234 guint width)
235{
236 GdkPixmap *old_pixmap = value->pixmap;
237
238 value->pixmap =
239 gdk_pixmap_new(old_pixmap,
240 width,
241 value->height,
242 -1);
243
244 gdk_pixmap_unref(old_pixmap);
245}
246
This page took 0.030765 seconds and 4 git commands to generate.