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,
20 static void destroy_cb( GtkWidget
*widget
,
28 int main(int argc
, char **argv
)
33 GtkWidget
*HScroll_VC
;
34 ControlFlowData
*control_flow_data
;
36 /* Horizontal scrollbar and it's adjustment */
37 GtkWidget
*VScroll_VC
;
38 GtkAdjustment
*v_adjust
;
40 /* Initialize i18n support */
43 /* Initialize the widget set */
44 gtk_init (&argc
, &argv
);
48 Window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
49 gtk_window_set_title (GTK_WINDOW (Window
), ("Test Window"));
51 g_signal_connect (G_OBJECT (Window
), "destroy",
52 G_CALLBACK (destroy_cb
), NULL
);
55 VBox_V
= gtk_vbox_new(0, 0);
56 gtk_container_add (GTK_CONTAINER (Window
), VBox_V
);
58 //ListViewer = hGuiEvents(Window);
59 //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, TRUE, TRUE, 0);
61 //ListViewer = hGuiEvents(Window);
62 //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, FALSE, TRUE, 0);
64 control_flow_data
= guicontrolflow();
65 CF_Viewer
= control_flow_data
->scrolled_window
;
66 gtk_box_pack_start(GTK_BOX(VBox_V
), CF_Viewer
, TRUE
, TRUE
, 0);
68 /* Create horizontal scrollbar and pack it */
69 HScroll_VC
= gtk_hscrollbar_new(NULL
);
70 gtk_box_pack_start(GTK_BOX(VBox_V
), HScroll_VC
, FALSE
, TRUE
, 0);
73 gtk_widget_show (HScroll_VC
);
74 gtk_widget_show (VBox_V
);
75 gtk_widget_show (Window
);
77 //Event_Selected_Hook(control_flow_data, &ev_sel);
81 g_critical("main loop finished");
83 //h_guievents_destructor(ListViewer);
85 //g_critical("GuiEvents Destructor finished");
93 void add_test_process(ControlFlowData
*control_flow_data
)
97 gchar
*process
[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
99 for(i
=0; i
<control_flow_data
->number_of_process
; i
++)
101 /* Add a new row to the model */
102 gtk_list_store_append (control_flow_data
->list_store
, &iter
);
103 gtk_list_store_set ( control_flow_data
->list_store
, &iter
,
104 PROCESS_COLUMN
, process
[i
],
115 void test_draw(ControlFlowData
*control_flow_data
)
117 /* Draw event states using available height, Number of process, cell height
118 * (don't forget to remove two pixels at beginning and end).
119 * For horizontal : use width, Time_Begin, Time_End.
120 * This function calls the reading library to get the draw_hook called
121 * for the desired period of time. */
123 drawingAreaInfo
*drawing_Area_Info
= &control_flow_data
->drawing_Area_Info
;
130 gint cell_height
= get_cell_height(GTK_TREE_VIEW(control_flow_data
->process_list_widget
));
131 GdkGC
*GC
= gdk_gc_new(widget
->window
);
132 GdkColor color
= CF_Colors
[GREEN
];
134 gdk_color_alloc (gdk_colormap_get_system () , &color
);
136 g_critical("expose");
138 /* When redrawing, use widget->allocation.width to get the width of
140 control_flow_data
->drawing_Area_Info
.width
= widget
->allocation
.width
;
142 test_draw(control_flow_data
);
144 gdk_gc_copy(GC
,widget
->style
->black_gc
);
145 gdk_gc_set_foreground(GC
,&color
);
147 //gdk_draw_arc (widget->window,
148 // widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
150 // //0, 0, widget->allocation.width, widget->allocation.height,
151 // 0, 0, widget->allocation.width,
152 // control_flow_data->drawing_Area_Info.height,
156 //drawing_Area_Init(control_flow_data);
158 // 2 pixels for the box around the drawing area, 1 pixel for off-by-one
160 //gdk_gc_copy (&GC, widget->style->fg_gc[GTK_WIDGET_STATE (widget)]);
162 gdk_gc_set_line_attributes(GC
,12, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
,GDK_JOIN_MITER
);
164 gdk_draw_line (widget
->window
,
166 0, (cell_height
-1)/2,
167 widget
->allocation
.width
, (cell_height
-1)/2);
169 color
= CF_Colors
[BLUE
];
171 gdk_color_alloc (gdk_colormap_get_system () , &color
);
173 gdk_gc_set_foreground(GC
,&color
);
176 gdk_gc_set_line_attributes(GC
,3, GDK_LINE_SOLID
, GDK_CAP_NOT_LAST
,GDK_JOIN_MITER
);
178 gdk_draw_line (widget
->window
,
180 0, (cell_height
-1)/2,
181 widget
->allocation
.width
,(cell_height
-1)/2);
190 //gdk_colormap_alloc_colors(gdk_colormap_get_system(), TRUE,
192 //gdk_gc_set_line_attributes(GC,5, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,GDK_JOIN_MITER);
193 //gdk_gc_set_foreground(GC,
195 //gdk_draw_line (widget->window,
197 // 0, (2*cell_height)-2-1,
198 // 50, (2*cell_height)-2-1);
204 /* Event_Hook.c tests */
206 void test_draw_item(Drawing_t
*drawing
,
209 PropertiesIcon properties_icon
;
210 DrawContext draw_context
;
212 DrawInfo current
, previous
;
213 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
217 //for(i=0; i<1024;i=i+15)
219 // for(j=0;j<768;j=j+15)
224 current
.modify_over
= &over
;
226 draw_context
.drawable
= pixmap
;
227 draw_context
.gc
= drawing
->drawing_area
->style
->black_gc
;
229 draw_context
.current
= ¤t
;
230 draw_context
.previous
= NULL
;
232 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
233 strncpy(properties_icon
.icon_name
,
234 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
236 properties_icon
.width
= -1;
237 properties_icon
.height
= -1;
238 properties_icon
.position
= OVER
;
239 draw_icon(&properties_icon
, &draw_context
);
240 g_free(properties_icon
.icon_name
);
247 /* NOTE : no drawing data should be sent there, since the drawing widget
248 * has not been initialized */
249 void send_test_drawing(ProcessList
*process_list
,
252 gint x
, gint y
, // y not used here?
254 gint height
) // height won't be used here ?
257 ProcessInfo Process_Info
= {10000, 12000, 55600};
258 //ProcessInfo Process_Info = {156, 14000, 55500};
259 GtkTreeRowReference
*row_ref
;
260 PangoContext
*context
;
262 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
266 //GdkBitmap *mask = g_new(GdkBitmap, 1);
267 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
270 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
272 gc
= gdk_gc_new(pixmap
);
274 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
,
276 context
= pango_layout_get_context(layout
);
277 FontDesc
= pango_context_get_font_description(context
);
278 Font_Size
= pango_font_description_get_size(FontDesc
);
279 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
285 birth
.tv_sec
= 12000;
286 birth
.tv_nsec
= 55500;
287 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
288 processlist_get_process_pixels(process_list
,
294 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
297 y
+(height
/2), x
+ width
, y
+(height
/2),
298 drawing
->drawing_area
->style
->black_gc
);
300 pango_layout_set_text(layout
, "Test", -1);
301 gdk_draw_layout(pixmap
, drawing
->drawing_area
->style
->black_gc
,
302 0, y
+height
, layout
);
304 birth
.tv_sec
= 14000;
305 birth
.tv_nsec
= 55500;
307 processlist_get_process_pixels(process_list
,
316 y
+(height
/2), x
+ width
, y
+(height
/2),
317 drawing
->drawing_area
->style
->black_gc
);
319 g_info("y : %u, height : %u", y
, height
);
323 birth
.tv_sec
= 12000;
324 birth
.tv_nsec
= 55700;
326 processlist_get_process_pixels(process_list
,
332 /* Draw rectangle (background color) */
333 gdk_gc_copy(gc
, drawing
->drawing_area
->style
->black_gc
);
334 gdk_gc_set_rgb_fg_color(gc
, &color
);
335 gdk_draw_rectangle(pixmap
, gc
,
337 x
, y
, width
, height
);
341 y
+(height
/2), x
+ width
, y
+(height
/2),
342 drawing
->drawing_area
->style
->black_gc
);
346 gdk_draw_arc(pixmap
, drawing
->drawing_area
->style
->black_gc
,
347 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
349 g_info("y : %u, height : %u", y
, height
);
353 birth
.tv_sec
= i
*12000;
354 birth
.tv_nsec
= i
*55700;
356 processlist_get_process_pixels(process_list
,
365 y
+(height
/2), x
+ width
, y
+(height
/2),
366 drawing
->drawing_area
->style
->black_gc
);
368 g_critical("y : %u, height : %u", y
, height
);
372 birth
.tv_sec
= 12000;
373 birth
.tv_nsec
= 55600;
375 processlist_get_process_pixels(process_list
,
384 y
+(height
/2), x
+ width
, y
+(height
/2),
385 drawing
->drawing_area
->style
->black_gc
);
387 g_info("y : %u, height : %u", y
, height
);
390 /* IMPORTANT : This action uses the cpu heavily! */
391 //icon_pixmap = gdk_pixmap_create_from_xpm(pixmap, &mask, NULL,
392 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
393 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
395 // gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, mask);
397 // for(i=x;i<x+width;i=i+15)
399 // for(j=0;j<height*20;j=j+15)
403 //gdk_gc_copy(gc, drawing->drawing_area->style->black_gc);
404 // gdk_gc_set_clip_origin(drawing->drawing_area->style->black_gc, i, j);
405 // gdk_draw_drawable(pixmap,
406 // drawing->drawing_area->style->black_gc,
408 // 0, 0, i, j, -1, -1);
413 test_draw_item(drawing
,pixmap
);
415 //gdk_gc_set_clip_origin(drawing->drawing_area->style->black_gc, 0, 0);
416 //gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, NULL);
418 //g_free(icon_pixmap);
426 pango_font_description_set_size(FontDesc
, Font_Size
);
427 g_object_unref(layout
);
431 void send_test_process(ProcessList
*process_list
, Drawing_t
*drawing
)
435 ProcessInfo Process_Info
= {10000, 12000, 55600};
436 //ProcessInfo Process_Info = {156, 14000, 55500};
437 GtkTreeRowReference
*row_ref
;
441 if(process_list
->Test_Process_Sent
) return;
443 birth
.tv_sec
= 12000;
444 birth
.tv_nsec
= 55500;
446 processlist_add(process_list
,
450 processlist_get_process_pixels(process_list
,
455 drawing_insert_square( drawing
, y
, height
);
457 //g_critical("y : %u, height : %u", y, height);
459 birth
.tv_sec
= 14000;
460 birth
.tv_nsec
= 55500;
462 processlist_add(process_list
,
466 processlist_get_process_pixels(process_list
,
471 drawing_insert_square( drawing
, y
, height
);
473 //g_critical("y : %u, height : %u", y, height);
475 birth
.tv_sec
= 12000;
476 birth
.tv_nsec
= 55700;
478 processlist_add(process_list
,
482 processlist_get_process_pixels(process_list
,
487 drawing_insert_square( drawing
, y
, height
);
489 //g_critical("y : %u, height : %u", y, height);
491 //drawing_insert_square( drawing, height, 5);
495 birth
.tv_sec
= i
*12000;
496 birth
.tv_nsec
= i
*55700;
498 processlist_add(process_list
,
502 processlist_get_process_pixels(process_list
,
507 drawing_insert_square( drawing
, y
, height
);
509 // g_critical("y : %u, height : %u", y, height);
512 //g_critical("height : %u", height);
514 birth
.tv_sec
= 12000;
515 birth
.tv_nsec
= 55600;
517 processlist_add(process_list
,
521 processlist_get_process_pixels(process_list
,
526 drawing_insert_square( drawing
, y
, height
);
528 //g_critical("y : %u, height : %u", y, height);
530 processlist_add(process_list
,
534 processlist_get_process_pixels(process_list
,
539 drawing_insert_square( drawing
, y
, height
);
541 //g_critical("y : %u, height : %u", y, height);
543 //drawing_insert_square( drawing, height, 5);
544 //g_critical("height : %u", height);
547 processlist_get_process_pixels(process_list
,
551 processlist_remove( process_list
,
555 drawing_remove_square( drawing
, y
, height
);
558 (GtkTreeRowReference
*)g_hash_table_lookup(
559 process_list
->process_hash
,
562 g_critical("key found");
563 g_critical("position in the list : %s",
564 gtk_tree_path_to_string (
565 gtk_tree_row_reference_get_path(
566 (GtkTreeRowReference
*)row_ref
)
571 process_list
->Test_Process_Sent
= TRUE
;