Update FSF address
[lttv.git] / lttv / modules / gui / controlflow / test.c
CommitLineData
ce0214a6 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
b9ce0bad
YB
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
ce0214a6 17 */
f0d936c0 18
4e4d11b3 19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
f0d936c0 22
23static void destroy_cb( GtkWidget *widget,
24 gpointer data )
25{
26 gtk_main_quit ();
27}
28
29
30
31int main(int argc, char **argv)
32{
33 GtkWidget *Window;
34 GtkWidget *CF_Viewer;
35 GtkWidget *VBox_V;
36 GtkWidget *HScroll_VC;
68997a22 37 ControlFlowData *control_flow_data;
f0d936c0 38 guint ev_sel = 444 ;
39 /* Horizontal scrollbar and it's adjustment */
40 GtkWidget *VScroll_VC;
ba90bc77 41 GtkAdjustment *v_adjust ;
f0d936c0 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
68997a22 67 control_flow_data = guicontrolflow();
68 CF_Viewer = control_flow_data->scrolled_window;
f0d936c0 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
68997a22 80 //Event_Selected_Hook(control_flow_data, &ev_sel);
f0d936c0 81
82 gtk_main ();
83
84 g_critical("main loop finished");
85
4c69e0cc 86 //h_guievents_destructor(ListViewer);
f0d936c0 87
88 //g_critical("GuiEvents Destructor finished");
89 destroy();
90
91 return 0;
92}
93
94
95
68997a22 96void add_test_process(ControlFlowData *control_flow_data)
f0d936c0 97{
98 GtkTreeIter iter;
99 int i;
100 gchar *process[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
101
68997a22 102 for(i=0; i<control_flow_data->number_of_process; i++)
f0d936c0 103 {
104 /* Add a new row to the model */
f5d980bf 105 gtk_list_store_append (control_flow_data->list_store, &iter);
106 gtk_list_store_set ( control_flow_data->list_store, &iter,
fa2c4dbe 107 PROCESS_COLUMN, process[i],
108 -1);
f0d936c0 109 }
110
111}
112
113
114
115
116
117
68997a22 118void test_draw(ControlFlowData *control_flow_data)
f0d936c0 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
501d5405 126 drawingAreaInfo *drawing_Area_Info = &control_flow_data->drawing_Area_Info;
f0d936c0 127
128
129}
130
131#ifdef DEBUG
132void test_draw() {
f5d980bf 133 gint cell_height = get_cell_height(GTK_TREE_VIEW(control_flow_data->process_list_widget));
f0d936c0 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. */
501d5405 143 control_flow_data->drawing_Area_Info.width = widget->allocation.width;
f0d936c0 144
68997a22 145 test_draw(control_flow_data);
f0d936c0 146
cfe526b1 147 gdk_gc_copy(GC,widget->style->black_gc);
f0d936c0 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,
501d5405 155 // control_flow_data->drawing_Area_Info.height,
f0d936c0 156 // 0, 64 * 360);
157
158
501d5405 159 //drawing_Area_Init(control_flow_data);
f0d936c0 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
50439712 206
207/* Event_Hook.c tests */
208
501d5405 209void test_draw_item(Drawing_t *drawing,
b6db18f8 210 GdkPixmap *pixmap)
50439712 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
b6db18f8 229 draw_context.drawable = pixmap;
501d5405 230 draw_context.gc = drawing->drawing_area->style->black_gc;
50439712 231
68997a22 232 draw_context.current = &current;
233 draw_context.previous = NULL;
50439712 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 */
ba90bc77 252void send_test_drawing(ProcessList *process_list,
501d5405 253 Drawing_t *drawing,
b6db18f8 254 GdkPixmap *pixmap,
50439712 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};
f5d980bf 262 GtkTreeRowReference *row_ref;
50439712 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
b6db18f8 275 gc = gdk_gc_new(pixmap);
50439712 276 /* Sent text data */
501d5405 277 layout = gtk_widget_create_pango_layout(drawing->drawing_area,
50439712 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);
ba90bc77 291 processlist_get_process_pixels(process_list,
50439712 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(
501d5405 299 drawing, pixmap, x,
50439712 300 y+(height/2), x + width, y+(height/2),
501d5405 301 drawing->drawing_area->style->black_gc);
50439712 302
303 pango_layout_set_text(layout, "Test", -1);
501d5405 304 gdk_draw_layout(pixmap, drawing->drawing_area->style->black_gc,
50439712 305 0, y+height, layout);
306
307 birth.tv_sec = 14000;
308 birth.tv_nsec = 55500;
309
ba90bc77 310 processlist_get_process_pixels(process_list,
50439712 311 156,
312 &birth,
313 &y,
314 &height);
315
316
317 drawing_draw_line(
501d5405 318 drawing, pixmap, x,
50439712 319 y+(height/2), x + width, y+(height/2),
501d5405 320 drawing->drawing_area->style->black_gc);
50439712 321
322 g_info("y : %u, height : %u", y, height);
323
324
325
326 birth.tv_sec = 12000;
327 birth.tv_nsec = 55700;
328
ba90bc77 329 processlist_get_process_pixels(process_list,
50439712 330 10,
331 &birth,
332 &y,
333 &height);
334
335 /* Draw rectangle (background color) */
501d5405 336 gdk_gc_copy(gc, drawing->drawing_area->style->black_gc);
50439712 337 gdk_gc_set_rgb_fg_color(gc, &color);
b6db18f8 338 gdk_draw_rectangle(pixmap, gc,
50439712 339 TRUE,
340 x, y, width, height);
341
342 drawing_draw_line(
501d5405 343 drawing, pixmap, x,
50439712 344 y+(height/2), x + width, y+(height/2),
501d5405 345 drawing->drawing_area->style->black_gc);
50439712 346
347
348 /* Draw arc */
501d5405 349 gdk_draw_arc(pixmap, drawing->drawing_area->style->black_gc,
50439712 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
ba90bc77 359 processlist_get_process_pixels(process_list,
50439712 360 i,
361 &birth,
362 &y,
363 &height);
364
365
366 drawing_draw_line(
501d5405 367 drawing, pixmap, x,
50439712 368 y+(height/2), x + width, y+(height/2),
501d5405 369 drawing->drawing_area->style->black_gc);
50439712 370
371 g_critical("y : %u, height : %u", y, height);
372
373 }
374
375 birth.tv_sec = 12000;
376 birth.tv_nsec = 55600;
377
ba90bc77 378 processlist_get_process_pixels(process_list,
50439712 379 10,
380 &birth,
381 &y,
382 &height);
383
384
385 drawing_draw_line(
501d5405 386 drawing, pixmap, x,
50439712 387 y+(height/2), x + width, y+(height/2),
501d5405 388 drawing->drawing_area->style->black_gc);
50439712 389
390 g_info("y : %u, height : %u", y, height);
391
392
393 /* IMPORTANT : This action uses the cpu heavily! */
b6db18f8 394 //icon_pixmap = gdk_pixmap_create_from_xpm(pixmap, &mask, NULL,
50439712 395// "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
396 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
397
501d5405 398 // gdk_gc_set_clip_mask(drawing->drawing_area->style->black_gc, mask);
50439712 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 */
501d5405 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);
b6db18f8 408// gdk_draw_drawable(pixmap,
501d5405 409// drawing->drawing_area->style->black_gc,
50439712 410// icon_pixmap,
411// 0, 0, i, j, -1, -1);
412
413// }
414// }
415
501d5405 416 test_draw_item(drawing,pixmap);
50439712 417
501d5405 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);
50439712 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
501d5405 434void send_test_process(ProcessList *process_list, Drawing_t *drawing)
50439712 435{
436 guint height, y;
437 int i;
438 ProcessInfo Process_Info = {10000, 12000, 55600};
439 //ProcessInfo Process_Info = {156, 14000, 55500};
f5d980bf 440 GtkTreeRowReference *row_ref;
50439712 441
442 LttTime birth;
443
ba90bc77 444 if(process_list->Test_Process_Sent) return;
50439712 445
446 birth.tv_sec = 12000;
447 birth.tv_nsec = 55500;
448
ba90bc77 449 processlist_add(process_list,
50439712 450 1,
451 &birth,
452 &y);
ba90bc77 453 processlist_get_process_pixels(process_list,
50439712 454 1,
455 &birth,
456 &y,
457 &height);
501d5405 458 drawing_insert_square( drawing, y, height);
50439712 459
460 //g_critical("y : %u, height : %u", y, height);
461
462 birth.tv_sec = 14000;
463 birth.tv_nsec = 55500;
464
ba90bc77 465 processlist_add(process_list,
50439712 466 156,
467 &birth,
468 &y);
ba90bc77 469 processlist_get_process_pixels(process_list,
50439712 470 156,
471 &birth,
472 &y,
473 &height);
501d5405 474 drawing_insert_square( drawing, y, height);
50439712 475
476 //g_critical("y : %u, height : %u", y, height);
477
478 birth.tv_sec = 12000;
479 birth.tv_nsec = 55700;
480
ba90bc77 481 processlist_add(process_list,
50439712 482 10,
483 &birth,
484 &height);
ba90bc77 485 processlist_get_process_pixels(process_list,
50439712 486 10,
487 &birth,
488 &y,
489 &height);
501d5405 490 drawing_insert_square( drawing, y, height);
50439712 491
492 //g_critical("y : %u, height : %u", y, height);
493
501d5405 494 //drawing_insert_square( drawing, height, 5);
50439712 495
496 for(i=0; i<10; i++)
497 {
498 birth.tv_sec = i*12000;
499 birth.tv_nsec = i*55700;
500
ba90bc77 501 processlist_add(process_list,
50439712 502 i,
503 &birth,
504 &height);
ba90bc77 505 processlist_get_process_pixels(process_list,
50439712 506 i,
507 &birth,
508 &y,
509 &height);
501d5405 510 drawing_insert_square( drawing, y, height);
50439712 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
ba90bc77 520 processlist_add(process_list,
50439712 521 10,
522 &birth,
523 &y);
ba90bc77 524 processlist_get_process_pixels(process_list,
50439712 525 10,
526 &birth,
527 &y,
528 &height);
501d5405 529 drawing_insert_square( drawing, y, height);
50439712 530
531 //g_critical("y : %u, height : %u", y, height);
532
ba90bc77 533 processlist_add(process_list,
50439712 534 10000,
535 &birth,
536 &height);
ba90bc77 537 processlist_get_process_pixels(process_list,
50439712 538 10000,
539 &birth,
540 &y,
541 &height);
501d5405 542 drawing_insert_square( drawing, y, height);
50439712 543
544 //g_critical("y : %u, height : %u", y, height);
545
501d5405 546 //drawing_insert_square( drawing, height, 5);
50439712 547 //g_critical("height : %u", height);
548
549
ba90bc77 550 processlist_get_process_pixels(process_list,
50439712 551 10000,
552 &birth,
553 &y, &height);
ba90bc77 554 processlist_remove( process_list,
50439712 555 10000,
556 &birth);
557
501d5405 558 drawing_remove_square( drawing, y, height);
50439712 559
f5d980bf 560 if(row_ref =
50439712 561 (GtkTreeRowReference*)g_hash_table_lookup(
14963be0 562 process_list->process_hash,
50439712 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(
f5d980bf 569 (GtkTreeRowReference*)row_ref)
50439712 570 ));
571
572 }
573
ba90bc77 574 process_list->Test_Process_Sent = TRUE;
50439712 575
576}
577#endif//NOTUSE
578
This page took 0.096575 seconds and 4 git commands to generate.