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