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"
33 extern void histogram_show(HistoControlFlowData
*histocontrol_flow_data
,
34 guint draw_begin
, guint draw_end
);
37 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
40 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
43 /* Preallocated Size of the index_to_pixmap array */
44 #define ALLOCATE_PROCESSES 1000
46 /*****************************************************************************
48 *****************************************************************************/
49 static GtkWidget
*xpm_label_box( gchar
*xpm_filename
,
51 static gboolean
gplus( GtkWidget
*widget
,gpointer user_data
)
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)
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
);
62 g_warning("Zoom more than 1 event is impossible");
64 histo_drawing_update_vertical_ruler(histo_cfd
->drawing
);//, TimeWindow *time_window);
68 static gboolean
gMinus( GtkWidget
*widget
,
71 HistoControlFlowData
*histo_cfd
= (HistoControlFlowData
*)user_data
;
72 histo_cfd
->max_height
*= 2;
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);
80 static gboolean
gFit( GtkWidget
*widget
,
83 /*find the maximum value and put max_height equal with this maximum*/
84 HistoControlFlowData
*histo_cfd
= (HistoControlFlowData
*)user_data
;
87 maximum
=g_array_index(histo_cfd
->number_of_process
,guint
,i
);
88 for (i
=1; i
< histo_cfd
->number_of_process
-> len
;i
++)
90 x
=g_array_index(histo_cfd
->number_of_process
,guint
,i
);
91 maximum
=MAX(x
,maximum
);
95 histo_cfd
->max_height
=maximum
;
96 histogram_show (histo_cfd
,0,histo_cfd
->number_of_process
->len
);
98 histo_drawing_update_vertical_ruler(histo_cfd
->drawing
);
102 /* Create a new hbox with an image and a label packed into it
103 * and return the box. */
105 static GtkWidget
*xpm_label_box( gchar
* xpm_filename
,
114 /* Create box for image and label */
115 box
= gtk_hbox_new (FALSE
, 0);
116 gtk_container_set_border_width (GTK_CONTAINER (box
), 1);
118 /* Now on to the image stuff */
120 pixbufP
= gdk_pixbuf_new_from_xpm_data((const char **)&xpm_filename
);
121 image
= gtk_image_new_from_pixbuf(pixbufP
);
123 /* Create a label for the button */
124 label
= gtk_label_new (label_text
);
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);
130 gtk_widget_show (image
);
131 gtk_widget_show (label
);
136 ButtonWidget
*histo_buttonwidget_construct(HistoControlFlowData
*histocontrol_flow_data
)
138 GtkWidget
*boxPlus
, *boxMinus
, *boxfit
;//containing text and image for each button.
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);
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:
150 buttonwidget
->buttonP
=gtk_button_new ();
151 buttonwidget
->buttonM
=gtk_button_new ();
152 buttonwidget
->buttonFit
=gtk_button_new ();
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");
159 /* Pack and show all widgets */
160 gtk_widget_show (boxPlus
);
161 gtk_widget_show (boxMinus
);
162 gtk_widget_show (boxfit
);
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
);
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);
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 . */
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
);
183 gtk_widget_show (buttonwidget
-> vbox1
);
184 gtk_widget_show (buttonwidget
->buttonP
);
185 gtk_widget_show (buttonwidget
->buttonM
);
186 gtk_widget_show (buttonwidget
->buttonFit
);
191 void histo_buttonwidget_destroy(ButtonWidget
*buttonwidget
)
193 g_debug("buttonwidget_destroy %p", buttonwidget
);
195 g_free(buttonwidget
);
196 g_debug("buttonwidget_destroy end");
199 GtkWidget
*histo_buttonwidget_get_widget(ButtonWidget
*button_widget
)
201 return button_widget
->vbox1
;
206 void histo_rectangle_pixmap (GdkGC
*gc
,
207 gboolean filled
, gint x
, gint y
, gint width
, gint height
,
208 histoDrawing_t
*value
)
211 height
= value
->drawing_area
->allocation
.height
;
213 height
= value
->drawing_area
->allocation
.width
;
214 gdk_draw_rectangle (value
->pixmap
,
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
)
229 dest
= drawing
->pixmap
;
231 src
= drawing
->pixmap
;
233 gdk_draw_drawable (dest
,gc
,src
,xsrc
, ysrc
,
234 xdest
, ydest
,width
, height
);
237 void histo_update_pixmap_size(histoDrawing_t
*value
,
240 GdkPixmap
*old_pixmap
= value
->pixmap
;
243 gdk_pixmap_new(old_pixmap
,
248 gdk_pixmap_unref(old_pixmap
);
This page took 0.086034 seconds and 4 git commands to generate.