9e01e6d4 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Mathieu Desnoyers |
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 | static void destroy_cb( GtkWidget *widget, |
24 | gpointer data ) |
25 | { |
26 | gtk_main_quit (); |
27 | } |
28 | |
29 | |
30 | |
31 | int main(int argc, char **argv) |
32 | { |
33 | GtkWidget *Window; |
34 | GtkWidget *CF_Viewer; |
35 | GtkWidget *VBox_V; |
36 | GtkWidget *HScroll_VC; |
37 | ControlFlowData *control_flow_data; |
38 | guint ev_sel = 444 ; |
39 | /* Horizontal scrollbar and it's adjustment */ |
40 | GtkWidget *VScroll_VC; |
41 | GtkAdjustment *v_adjust ; |
42 | |
43 | /* Initialize i18n support */ |
44 | gtk_set_locale (); |
45 | |
46 | /* Initialize the widget set */ |
47 | gtk_init (&argc, &argv); |
48 | |
49 | init(); |
50 | |
51 | Window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
52 | gtk_window_set_title (GTK_WINDOW (Window), ("Test Window")); |
53 | |
54 | g_signal_connect (G_OBJECT (Window), "destroy", |
55 | G_CALLBACK (destroy_cb), NULL); |
56 | |
57 | |
58 | VBox_V = gtk_vbox_new(0, 0); |
59 | gtk_container_add (GTK_CONTAINER (Window), VBox_V); |
60 | |
61 | //ListViewer = hGuiEvents(Window); |
62 | //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, TRUE, TRUE, 0); |
63 | |
64 | //ListViewer = hGuiEvents(Window); |
65 | //gtk_box_pack_start(GTK_BOX(VBox_V), ListViewer, FALSE, TRUE, 0); |
66 | |
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); |
70 | |
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); |
74 | |
75 | |
76 | gtk_widget_show (HScroll_VC); |
77 | gtk_widget_show (VBox_V); |
78 | gtk_widget_show (Window); |
79 | |
80 | //Event_Selected_Hook(control_flow_data, &ev_sel); |
81 | |
82 | gtk_main (); |
83 | |
84 | g_critical("main loop finished"); |
85 | |
86 | //h_guievents_destructor(ListViewer); |
87 | |
88 | //g_critical("GuiEvents Destructor finished"); |
89 | destroy(); |
90 | |
91 | return 0; |
92 | } |
93 | |
94 | |
95 | |
96 | void add_test_process(ControlFlowData *control_flow_data) |
97 | { |
98 | GtkTreeIter iter; |
99 | int i; |
100 | gchar *process[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; |
101 | |
102 | for(i=0; i<control_flow_data->number_of_process; i++) |
103 | { |
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], |
108 | -1); |
109 | } |
110 | |
111 | } |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | void test_draw(ControlFlowData *control_flow_data) |
119 | { |
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. */ |
125 | |
126 | drawingAreaInfo *drawing_Area_Info = &control_flow_data->drawing_Area_Info; |
127 | |
128 | |
129 | } |
130 | |
131 | #ifdef DEBUG |
132 | void test_draw() { |
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]; |
136 | |
137 | gdk_color_alloc (gdk_colormap_get_system () , &color); |
138 | |
139 | g_critical("expose"); |
140 | |
141 | /* When redrawing, use widget->allocation.width to get the width of |
142 | * drawable area. */ |
143 | control_flow_data->drawing_Area_Info.width = widget->allocation.width; |
144 | |
145 | test_draw(control_flow_data); |
146 | |
147 | gdk_gc_copy(GC,widget->style->black_gc); |
148 | gdk_gc_set_foreground(GC,&color); |
149 | |
150 | //gdk_draw_arc (widget->window, |
151 | // widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
152 | // TRUE, |
153 | // //0, 0, widget->allocation.width, widget->allocation.height, |
154 | // 0, 0, widget->allocation.width, |
155 | // control_flow_data->drawing_Area_Info.height, |
156 | // 0, 64 * 360); |
157 | |
158 | |
159 | //drawing_Area_Init(control_flow_data); |
160 | |
161 | // 2 pixels for the box around the drawing area, 1 pixel for off-by-one |
162 | // (starting from 0) |
163 | //gdk_gc_copy (&GC, widget->style->fg_gc[GTK_WIDGET_STATE (widget)]); |
164 | |
165 | gdk_gc_set_line_attributes(GC,12, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,GDK_JOIN_MITER); |
166 | |
167 | gdk_draw_line (widget->window, |
168 | GC, |
169 | 0, (cell_height-1)/2, |
170 | widget->allocation.width, (cell_height-1)/2); |
171 | |
172 | color = CF_Colors[BLUE]; |
173 | |
174 | gdk_color_alloc (gdk_colormap_get_system () , &color); |
175 | |
176 | gdk_gc_set_foreground(GC,&color); |
177 | |
178 | |
179 | gdk_gc_set_line_attributes(GC,3, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,GDK_JOIN_MITER); |
180 | |
181 | gdk_draw_line (widget->window, |
182 | GC, |
183 | 0, (cell_height-1)/2, |
184 | widget->allocation.width,(cell_height-1)/2); |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | g_object_unref(GC); |
192 | |
193 | //gdk_colormap_alloc_colors(gdk_colormap_get_system(), TRUE, |
194 | |
195 | //gdk_gc_set_line_attributes(GC,5, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,GDK_JOIN_MITER); |
196 | //gdk_gc_set_foreground(GC, |
197 | |
198 | //gdk_draw_line (widget->window, |
199 | // GC, |
200 | // 0, (2*cell_height)-2-1, |
201 | // 50, (2*cell_height)-2-1); |
202 | |
203 | } |
204 | #endif //DEBUG |
205 | |
206 | |
207 | /* Event_Hook.c tests */ |
208 | |
209 | void test_draw_item(Drawing_t *drawing, |
210 | GdkPixmap *pixmap) |
211 | { |
212 | PropertiesIcon properties_icon; |
213 | DrawContext draw_context; |
214 | |
215 | DrawInfo current, previous; |
216 | ItemInfo over, middle, under, modify_over, modify_middle, modify_under; |
217 | |
218 | int i=0,j=0; |
219 | |
220 | //for(i=0; i<1024;i=i+15) |
221 | { |
222 | // for(j=0;j<768;j=j+15) |
223 | { |
224 | over.x = i; |
225 | over.y = j; |
226 | |
227 | current.modify_over = &over; |
228 | |
229 | draw_context.drawable = pixmap; |
230 | draw_context.gc = drawing->drawing_area->style->black_gc; |
231 | |
232 | draw_context.current = ¤t; |
233 | draw_context.previous = NULL; |
234 | |
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", |
238 | MAX_PATH_LEN); |
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); |
244 | } |
245 | } |
246 | |
247 | } |
248 | |
249 | #ifdef NOTUSE |
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, |
253 | Drawing_t *drawing, |
254 | GdkPixmap *pixmap, |
255 | gint x, gint y, // y not used here? |
256 | gint width, |
257 | gint height) // height won't be used here ? |
258 | { |
259 | int i,j; |
260 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
261 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
262 | GtkTreeRowReference *row_ref; |
263 | PangoContext *context; |
264 | PangoLayout *layout; |
265 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
266 | gint Font_Size; |
267 | |
268 | //icon |
269 | //GdkBitmap *mask = g_new(GdkBitmap, 1); |
270 | //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1); |
271 | GdkGC * gc; |
272 | // rectangle |
273 | GdkColor color = { 0, 0xffff, 0x0000, 0x0000 }; |
274 | |
275 | gc = gdk_gc_new(pixmap); |
276 | /* Sent text data */ |
277 | layout = gtk_widget_create_pango_layout(drawing->drawing_area, |
278 | NULL); |
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); |
283 | |
284 | |
285 | |
286 | |
287 | LttTime birth; |
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, |
292 | 1, |
293 | &birth, |
294 | &y, |
295 | &height); |
296 | |
297 | g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
298 | drawing_draw_line( |
299 | drawing, pixmap, x, |
300 | y+(height/2), x + width, y+(height/2), |
301 | drawing->drawing_area->style->black_gc); |
302 | |
303 | pango_layout_set_text(layout, "Test", -1); |
304 | gdk_draw_layout(pixmap, drawing->drawing_area->style->black_gc, |
305 | 0, y+height, layout); |
306 | |
307 | birth.tv_sec = 14000; |
308 | birth.tv_nsec = 55500; |
309 | |
310 | processlist_get_process_pixels(process_list, |
311 | 156, |
312 | &birth, |
313 | &y, |
314 | &height); |
315 | |
316 | |
317 | drawing_draw_line( |
318 | drawing, pixmap, x, |
319 | y+(height/2), x + width, y+(height/2), |
320 | drawing->drawing_area->style->black_gc); |
321 | |
322 | g_info("y : %u, height : %u", y, height); |
323 | |
324 | |
325 | |
326 | birth.tv_sec = 12000; |
327 | birth.tv_nsec = 55700; |
328 | |
329 | processlist_get_process_pixels(process_list, |
330 | 10, |
331 | &birth, |
332 | &y, |
333 | &height); |
334 | |
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, |
339 | TRUE, |
340 | x, y, width, height); |
341 | |
342 | drawing_draw_line( |
343 | drawing, pixmap, x, |
344 | y+(height/2), x + width, y+(height/2), |
345 | drawing->drawing_area->style->black_gc); |
346 | |
347 | |
348 | /* Draw arc */ |
349 | gdk_draw_arc(pixmap, drawing->drawing_area->style->black_gc, |
350 | TRUE, 100, y, height/2, height/2, 0, 360*64); |
351 | |
352 | g_info("y : %u, height : %u", y, height); |
353 | |
354 | for(i=0; i<10; i++) |
355 | { |
356 | birth.tv_sec = i*12000; |
357 | birth.tv_nsec = i*55700; |
358 | |
359 | processlist_get_process_pixels(process_list, |
360 | i, |
361 | &birth, |
362 | &y, |
363 | &height); |
364 | |
365 | |
366 | drawing_draw_line( |
367 | drawing, pixmap, x, |
368 | y+(height/2), x + width, y+(height/2), |
369 | drawing->drawing_area->style->black_gc); |
370 | |
371 | g_critical("y : %u, height : %u", y, height); |
372 | |
373 | } |
374 | |
375 | birth.tv_sec = 12000; |
376 | birth.tv_nsec = 55600; |
377 | |
378 | processlist_get_process_pixels(process_list, |
379 | 10, |
380 | &birth, |
381 | &y, |
382 | &height); |
383 | |
384 | |
385 | drawing_draw_line( |
386 | drawing, pixmap, x, |
387 | y+(height/2), x + width, y+(height/2), |
388 | drawing->drawing_area->style->black_gc); |
389 | |
390 | g_info("y : %u, height : %u", y, height); |
391 | |
392 | |
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"); |
397 | |
398 | // gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, mask); |
399 | |
400 | // for(i=x;i<x+width;i=i+15) |
401 | // { |
402 | // for(j=0;j<height*20;j=j+15) |
403 | // { |
404 | |
405 | /* Draw icon */ |
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, |
410 | // icon_pixmap, |
411 | // 0, 0, i, j, -1, -1); |
412 | |
413 | // } |
414 | // } |
415 | |
416 | test_draw_item(drawing,pixmap); |
417 | |
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); |
420 | |
421 | //g_free(icon_pixmap); |
422 | //g_free(mask); |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | pango_font_description_set_size(FontDesc, Font_Size); |
430 | g_object_unref(layout); |
431 | g_free(gc); |
432 | } |
433 | |
434 | void send_test_process(ProcessList *process_list, Drawing_t *drawing) |
435 | { |
436 | guint height, y; |
437 | int i; |
438 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
439 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
440 | GtkTreeRowReference *row_ref; |
441 | |
442 | LttTime birth; |
443 | |
444 | if(process_list->Test_Process_Sent) return; |
445 | |
446 | birth.tv_sec = 12000; |
447 | birth.tv_nsec = 55500; |
448 | |
449 | processlist_add(process_list, |
450 | 1, |
451 | &birth, |
452 | &y); |
453 | processlist_get_process_pixels(process_list, |
454 | 1, |
455 | &birth, |
456 | &y, |
457 | &height); |
458 | drawing_insert_square( drawing, y, height); |
459 | |
460 | //g_critical("y : %u, height : %u", y, height); |
461 | |
462 | birth.tv_sec = 14000; |
463 | birth.tv_nsec = 55500; |
464 | |
465 | processlist_add(process_list, |
466 | 156, |
467 | &birth, |
468 | &y); |
469 | processlist_get_process_pixels(process_list, |
470 | 156, |
471 | &birth, |
472 | &y, |
473 | &height); |
474 | drawing_insert_square( drawing, y, height); |
475 | |
476 | //g_critical("y : %u, height : %u", y, height); |
477 | |
478 | birth.tv_sec = 12000; |
479 | birth.tv_nsec = 55700; |
480 | |
481 | processlist_add(process_list, |
482 | 10, |
483 | &birth, |
484 | &height); |
485 | processlist_get_process_pixels(process_list, |
486 | 10, |
487 | &birth, |
488 | &y, |
489 | &height); |
490 | drawing_insert_square( drawing, y, height); |
491 | |
492 | //g_critical("y : %u, height : %u", y, height); |
493 | |
494 | //drawing_insert_square( drawing, height, 5); |
495 | |
496 | for(i=0; i<10; i++) |
497 | { |
498 | birth.tv_sec = i*12000; |
499 | birth.tv_nsec = i*55700; |
500 | |
501 | processlist_add(process_list, |
502 | i, |
503 | &birth, |
504 | &height); |
505 | processlist_get_process_pixels(process_list, |
506 | i, |
507 | &birth, |
508 | &y, |
509 | &height); |
510 | drawing_insert_square( drawing, y, height); |
511 | |
512 | // g_critical("y : %u, height : %u", y, height); |
513 | |
514 | } |
515 | //g_critical("height : %u", height); |
516 | |
517 | birth.tv_sec = 12000; |
518 | birth.tv_nsec = 55600; |
519 | |
520 | processlist_add(process_list, |
521 | 10, |
522 | &birth, |
523 | &y); |
524 | processlist_get_process_pixels(process_list, |
525 | 10, |
526 | &birth, |
527 | &y, |
528 | &height); |
529 | drawing_insert_square( drawing, y, height); |
530 | |
531 | //g_critical("y : %u, height : %u", y, height); |
532 | |
533 | processlist_add(process_list, |
534 | 10000, |
535 | &birth, |
536 | &height); |
537 | processlist_get_process_pixels(process_list, |
538 | 10000, |
539 | &birth, |
540 | &y, |
541 | &height); |
542 | drawing_insert_square( drawing, y, height); |
543 | |
544 | //g_critical("y : %u, height : %u", y, height); |
545 | |
546 | //drawing_insert_square( drawing, height, 5); |
547 | //g_critical("height : %u", height); |
548 | |
549 | |
550 | processlist_get_process_pixels(process_list, |
551 | 10000, |
552 | &birth, |
553 | &y, &height); |
554 | processlist_remove( process_list, |
555 | 10000, |
556 | &birth); |
557 | |
558 | drawing_remove_square( drawing, y, height); |
559 | |
560 | if(row_ref = |
561 | (GtkTreeRowReference*)g_hash_table_lookup( |
562 | process_list->process_hash, |
563 | &Process_Info)) |
564 | { |
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) |
570 | )); |
571 | |
572 | } |
573 | |
574 | process_list->Test_Process_Sent = TRUE; |
575 | |
576 | } |
577 | #endif//NOTUSE |
578 | |