1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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,
23 static void destroy_cb( GtkWidget
*widget
,
31 int main(int argc
, char **argv
)
36 GtkWidget
*HScroll_VC
;
37 ControlFlowData
*control_flow_data
;
39 /* Horizontal scrollbar and it's adjustment */
40 GtkWidget
*VScroll_VC
;
41 GtkAdjustment
*v_adjust
;
43 /* Initialize i18n support */
46 /* Initialize the widget set */
47 gtk_init (&argc
, &argv
);
51 Window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
52 gtk_window_set_title (GTK_WINDOW (Window
), ("Test Window"));
54 g_signal_connect (G_OBJECT (Window
), "destroy",
55 G_CALLBACK (destroy_cb
), NULL
);
58 VBox_V
= gtk_vbox_new(0, 0);
59 gtk_container_add (GTK_CONTAINER (Window
), VBox_V
);
61 //ListViewer = hGuiEvents(Window);
62 //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, TRUE, TRUE, 0);
64 //ListViewer = hGuiEvents(Window);
65 //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, FALSE, TRUE, 0);
67 control_flow_data
= guicontrolflow();
68 CF_Viewer
= control_flow_data
->scrolled_window
;
69 gtk_box_pack_start(GTK_BOX(VBox_V
), CF_Viewer
, TRUE
, TRUE
, 0);
71 /* Create horizontal scrollbar and pack it */
72 HScroll_VC
= gtk_hscrollbar_new(NULL
);
73 gtk_box_pack_start(GTK_BOX(VBox_V
), HScroll_VC
, FALSE
, TRUE
, 0);
76 gtk_widget_show (HScroll_VC
);
77 gtk_widget_show (VBox_V
);
78 gtk_widget_show (Window
);
80 //Event_Selected_Hook(control_flow_data, &ev_sel);
84 g_critical("main loop finished");
86 //h_guievents_destructor(ListViewer);
88 //g_critical("GuiEvents Destructor finished");
96 void add_test_process(ControlFlowData
*control_flow_data
)
100 gchar
*process
[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
102 for(i
=0; i
<control_flow_data
->number_of_process
; i
++)
104 /* Add a new row to the model */
105 gtk_list_store_append (control_flow_data
->list_store
, &iter
);
106 gtk_list_store_set ( control_flow_data
->list_store
, &iter
,
107 PROCESS_COLUMN
, process
[i
],
118 void test_draw(ControlFlowData
*control_flow_data
)
120 /* Draw event states using available height, Number of process, cell height
121 * (don't forget to remove two pixels at beginning and end).
122 * For horizontal : use width, Time_Begin, Time_End.
123 * This function calls the reading library to get the draw_hook called
124 * for the desired period of time. */
126 drawingAreaInfo
*drawing_Area_Info
= &control_flow_data
->drawing_Area_Info
;
133 gint cell_height
= get_cell_height(GTK_TREE_VIEW(control_flow_data
->process_list_widget
));
134 GdkGC
*GC
= gdk_gc_new(widget
->window
);
135 GdkColor color
= CF_Colors
[GREEN
];
137 gdk_color_alloc (gdk_colormap_get_system () , &color
);
139 g_critical("expose");
141 /* When redrawing, use widget->allocation.width to get the width of
143 control_flow_data
->drawing_Area_Info
.width
= widget
->allocation
.width
;
145 test_draw(control_flow_data
);
147 gdk_gc_copy(GC
,widget
->style
->black_gc
);
148 gdk_gc_set_foreground(GC
,&color
);
150 //gdk_draw_arc (widget->window,
151 // widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
153 // //0, 0, widget->allocation.width, widget->allocation.height,
154 // 0, 0, widget->allocation.width,
155 // control_flow_data->drawing_Area_Info.height,
159 //drawing_Area_Init(control_flow_data);
161 // 2 pixels for the box around the drawing area, 1 pixel for off-by-one
163 //gdk_gc_copy (&GC, widget->style->fg_gc[GTK_WIDGET_STATE (widget)]);
165 gdk_gc_set_line_attributes(GC
,12, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
,GDK_JOIN_MITER
);
167 gdk_draw_line (widget
->window
,
169 0, (cell_height
-1)/2,
170 widget
->allocation
.width
, (cell_height
-1)/2);
172 color
= CF_Colors
[BLUE
];
174 gdk_color_alloc (gdk_colormap_get_system () , &color
);
176 gdk_gc_set_foreground(GC
,&color
);
179 gdk_gc_set_line_attributes(GC
,3, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
,GDK_JOIN_MITER
);
181 gdk_draw_line (widget
->window
,
183 0, (cell_height
-1)/2,
184 widget
->allocation
.width
,(cell_height
-1)/2);
193 //gdk_colormap_alloc_colors(gdk_colormap_get_system(), TRUE,
195 //gdk_gc_set_line_attributes(GC,5, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,GDK_JOIN_MITER);
196 //gdk_gc_set_foreground(GC,
198 //gdk_draw_line (widget->window,
200 // 0, (2*cell_height)-2-1,
201 // 50, (2*cell_height)-2-1);
207 /* Event_Hook.c tests */
209 void test_draw_item(Drawing_t
*drawing
,
212 PropertiesIcon properties_icon
;
213 DrawContext draw_context
;
215 DrawInfo current
, previous
;
216 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
220 //for(i=0; i<1024;i=i+15)
222 // for(j=0;j<768;j=j+15)
227 current
.modify_over
= &over
;
229 draw_context
.drawable
= pixmap
;
230 draw_context
.gc
= drawing
->drawing_area
->style
->black_gc
;
232 draw_context
.current
= ¤t
;
233 draw_context
.previous
= NULL
;
235 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
236 strncpy(properties_icon
.icon_name
,
237 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
239 properties_icon
.width
= -1;
240 properties_icon
.height
= -1;
241 properties_icon
.position
= OVER
;
242 draw_icon(&properties_icon
, &draw_context
);
243 g_free(properties_icon
.icon_name
);
250 /* NOTE : no drawing data should be sent there, since the drawing widget
251 * has not been initialized */
252 void send_test_drawing(ProcessList
*process_list
,
255 gint x
, gint y
, // y not used here?
257 gint height
) // height won't be used here ?
260 ProcessInfo Process_Info
= {10000, 12000, 55600};
261 //ProcessInfo Process_Info = {156, 14000, 55500};
262 GtkTreeRowReference
*row_ref
;
263 PangoContext
*context
;
265 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
269 //GdkBitmap *mask = g_new(GdkBitmap, 1);
270 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
273 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
275 gc
= gdk_gc_new(pixmap
);
277 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
,
279 context
= pango_layout_get_context(layout
);
280 FontDesc
= pango_context_get_font_description(context
);
281 Font_Size
= pango_font_description_get_size(FontDesc
);
282 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
288 birth
.tv_sec
= 12000;
289 birth
.tv_nsec
= 55500;
290 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
291 processlist_get_process_pixels(process_list
,
297 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
300 y
+(height
/2), x
+ width
, y
+(height
/2),
301 drawing
->drawing_area
->style
->black_gc
);
303 pango_layout_set_text(layout
, "Test", -1);
304 gdk_draw_layout(pixmap
, drawing
->drawing_area
->style
->black_gc
,
305 0, y
+height
, layout
);
307 birth
.tv_sec
= 14000;
308 birth
.tv_nsec
= 55500;
310 processlist_get_process_pixels(process_list
,
319 y
+(height
/2), x
+ width
, y
+(height
/2),
320 drawing
->drawing_area
->style
->black_gc
);
322 g_info("y : %u, height : %u", y
, height
);
326 birth
.tv_sec
= 12000;
327 birth
.tv_nsec
= 55700;
329 processlist_get_process_pixels(process_list
,
335 /* Draw rectangle (background color) */
336 gdk_gc_copy(gc
, drawing
->drawing_area
->style
->black_gc
);
337 gdk_gc_set_rgb_fg_color(gc
, &color
);
338 gdk_draw_rectangle(pixmap
, gc
,
340 x
, y
, width
, height
);
344 y
+(height
/2), x
+ width
, y
+(height
/2),
345 drawing
->drawing_area
->style
->black_gc
);
349 gdk_draw_arc(pixmap
, drawing
->drawing_area
->style
->black_gc
,
350 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
352 g_info("y : %u, height : %u", y
, height
);
356 birth
.tv_sec
= i
*12000;
357 birth
.tv_nsec
= i
*55700;
359 processlist_get_process_pixels(process_list
,
368 y
+(height
/2), x
+ width
, y
+(height
/2),
369 drawing
->drawing_area
->style
->black_gc
);
371 g_critical("y : %u, height : %u", y
, height
);
375 birth
.tv_sec
= 12000;
376 birth
.tv_nsec
= 55600;
378 processlist_get_process_pixels(process_list
,
387 y
+(height
/2), x
+ width
, y
+(height
/2),
388 drawing
->drawing_area
->style
->black_gc
);
390 g_info("y : %u, height : %u", y
, height
);
393 /* IMPORTANT : This action uses the cpu heavily! */
394 //icon_pixmap = gdk_pixmap_create_from_xpm(pixmap, &mask, NULL,
395 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
396 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
398 // gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, mask);
400 // for(i=x;i<x+width;i=i+15)
402 // for(j=0;j<height*20;j=j+15)
406 //gdk_gc_copy(gc, drawing->drawing_area->style->black_gc);
407 // gdk_gc_set_clip_origin(drawing->drawing_area->style->black_gc, i, j);
408 // gdk_draw_drawable(pixmap,
409 // drawing->drawing_area->style->black_gc,
411 // 0, 0, i, j, -1, -1);
416 test_draw_item(drawing
,pixmap
);
418 //gdk_gc_set_clip_origin(drawing->drawing_area->style->black_gc, 0, 0);
419 //gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, NULL);
421 //g_free(icon_pixmap);
429 pango_font_description_set_size(FontDesc
, Font_Size
);
430 g_object_unref(layout
);
434 void send_test_process(ProcessList
*process_list
, Drawing_t
*drawing
)
438 ProcessInfo Process_Info
= {10000, 12000, 55600};
439 //ProcessInfo Process_Info = {156, 14000, 55500};
440 GtkTreeRowReference
*row_ref
;
444 if(process_list
->Test_Process_Sent
) return;
446 birth
.tv_sec
= 12000;
447 birth
.tv_nsec
= 55500;
449 processlist_add(process_list
,
453 processlist_get_process_pixels(process_list
,
458 drawing_insert_square( drawing
, y
, height
);
460 //g_critical("y : %u, height : %u", y, height);
462 birth
.tv_sec
= 14000;
463 birth
.tv_nsec
= 55500;
465 processlist_add(process_list
,
469 processlist_get_process_pixels(process_list
,
474 drawing_insert_square( drawing
, y
, height
);
476 //g_critical("y : %u, height : %u", y, height);
478 birth
.tv_sec
= 12000;
479 birth
.tv_nsec
= 55700;
481 processlist_add(process_list
,
485 processlist_get_process_pixels(process_list
,
490 drawing_insert_square( drawing
, y
, height
);
492 //g_critical("y : %u, height : %u", y, height);
494 //drawing_insert_square( drawing, height, 5);
498 birth
.tv_sec
= i
*12000;
499 birth
.tv_nsec
= i
*55700;
501 processlist_add(process_list
,
505 processlist_get_process_pixels(process_list
,
510 drawing_insert_square( drawing
, y
, height
);
512 // g_critical("y : %u, height : %u", y, height);
515 //g_critical("height : %u", height);
517 birth
.tv_sec
= 12000;
518 birth
.tv_nsec
= 55600;
520 processlist_add(process_list
,
524 processlist_get_process_pixels(process_list
,
529 drawing_insert_square( drawing
, y
, height
);
531 //g_critical("y : %u, height : %u", y, height);
533 processlist_add(process_list
,
537 processlist_get_process_pixels(process_list
,
542 drawing_insert_square( drawing
, y
, height
);
544 //g_critical("y : %u, height : %u", y, height);
546 //drawing_insert_square( drawing, height, 5);
547 //g_critical("height : %u", height);
550 processlist_get_process_pixels(process_list
,
554 processlist_remove( process_list
,
558 drawing_remove_square( drawing
, y
, height
);
561 (GtkTreeRowReference
*)g_hash_table_lookup(
562 process_list
->process_hash
,
565 g_critical("key found");
566 g_critical("position in the list : %s",
567 gtk_tree_path_to_string (
568 gtk_tree_row_reference_get_path(
569 (GtkTreeRowReference
*)row_ref
)
574 process_list
->Test_Process_Sent
= TRUE
;