Mercurial > dwindows
comparison dwtest.c @ 304:c28c0a804442
Added extra notebook page for a container example.
Added "correct" callbacks for events on trees and containers.
Added status lines to the tree and container pages to display results of
the callback events.
Changed the tab name to reflect the widgets in the notebook pages.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 29 Mar 2003 03:26:50 +0000 |
parents | 4559a2fd2db2 |
children | 32ad8a0dc06b |
comparison
equal
deleted
inserted
replaced
303:464b5e46b313 | 304:c28c0a804442 |
---|---|
34 lbbox, | 34 lbbox, |
35 notebookbox, | 35 notebookbox, |
36 notebookbox1, | 36 notebookbox1, |
37 notebookbox2, | 37 notebookbox2, |
38 notebookbox3, | 38 notebookbox3, |
39 notebookbox4, | |
39 notebook, | 40 notebook, |
40 vscrollbar, | 41 vscrollbar, |
41 hscrollbar, | 42 hscrollbar, |
42 status, status1, | 43 status, status1, |
44 container_status, | |
45 tree_status, | |
43 stext, | 46 stext, |
44 tree, | 47 tree, |
48 container, | |
45 pagebox, | 49 pagebox, |
46 treebox, | 50 treebox, |
51 containerbox, | |
47 textbox1, textbox2, textboxA, | 52 textbox1, textbox2, textboxA, |
48 gap_box, | 53 gap_box, |
49 buttonbox; | 54 buttonbox; |
50 | 55 |
51 HPIXMAP text1pm,text2pm; | 56 HPIXMAP text1pm,text2pm; |
57 unsigned long fileicon,foldericon; | |
52 | 58 |
53 int font_width = 8; | 59 int font_width = 8; |
54 int font_height=12; | 60 int font_height=12; |
55 int font_gap = 2; | 61 int font_gap = 2; |
56 int rows=100,width1=6,cols=80; | 62 int rows=100,width1=6,cols=80; |
338 /* Redraw the window */ | 344 /* Redraw the window */ |
339 draw_file( current_row, current_col); | 345 draw_file( current_row, current_col); |
340 return TRUE; | 346 return TRUE; |
341 } | 347 } |
342 | 348 |
349 int DWSIGNAL container_select_cb( HWND window, char *text, void *data ) | |
350 { | |
351 char buf[100]; | |
352 HWND statline = (HWND)data; | |
353 | |
354 sprintf(buf,"container-select: Window: %d Text: %s", window, text ); | |
355 dw_window_set_text( statline, buf); | |
356 return 0; | |
357 } | |
358 | |
359 int DWSIGNAL container_context_cb( HWND window, char *text, int x, int y, void *data ) | |
360 { | |
361 char buf[100]; | |
362 HWND statline = (HWND)data; | |
363 | |
364 sprintf(buf,"container-context: Window: %d Text: %s x: %d y: %d", window, text, x, y ); | |
365 dw_window_set_text( statline, buf); | |
366 return 0; | |
367 } | |
368 | |
369 int DWSIGNAL tree_context_cb( HWND window, char *text, int x, int y, void *data, void *itemdata ) | |
370 { | |
371 char buf[100]; | |
372 HWND statline = (HWND)data; | |
373 | |
374 sprintf(buf,"tree-context: Window: %d Text: %s x: %d y: %d", window, text, x, y ); | |
375 dw_window_set_text( statline, buf); | |
376 return 0; | |
377 } | |
378 | |
379 int DWSIGNAL item_select_cb( HWND window, int item, void *data ) | |
380 { | |
381 char buf[100]; | |
382 HWND statline = (HWND)data; | |
383 | |
384 sprintf(buf,"item-seelct: Window: %d Item: %d", window, item ); | |
385 dw_window_set_text( statline, buf); | |
386 return 0; | |
387 } | |
388 | |
389 int DWSIGNAL tree_select_cb( HWND window, HWND item, char *text, void *itemdata, void *data ) | |
390 { | |
391 char buf[100]; | |
392 HWND statline = (HWND)data; | |
393 | |
394 sprintf(buf,"tree-select: Window: %d Item: %d Text: %s", window, item, text ); | |
395 dw_window_set_text( statline, buf); | |
396 return 0; | |
397 } | |
398 | |
343 void archive_add(void) | 399 void archive_add(void) |
344 { | 400 { |
345 HWND browsebutton, browsebox; | 401 HWND browsebutton, browsebox; |
346 | 402 |
347 lbbox = dw_box_new(BOXVERT, 10); | 403 lbbox = dw_box_new(BOXVERT, 10); |
454 dw_signal_connect(mainwindow, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), NULL); | 510 dw_signal_connect(mainwindow, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), NULL); |
455 } | 511 } |
456 | 512 |
457 void tree_add(void) | 513 void tree_add(void) |
458 { | 514 { |
459 HWND t1,t2,t3; | 515 HWND t1,t2,t3,t4,t5,t6; |
460 int depth = dw_color_depth(); | |
461 unsigned long fileicon,foldericon; | |
462 | 516 |
463 /* create a box to pack into the notebook page */ | 517 /* create a box to pack into the notebook page */ |
464 treebox = dw_box_new(BOXHORZ, 2); | 518 treebox = dw_box_new(BOXHORZ, 2); |
465 dw_box_pack_start( notebookbox3, treebox, 500, 200, TRUE, TRUE, 0); | 519 dw_box_pack_start( notebookbox3, treebox, 500, 200, TRUE, TRUE, 0); |
466 | 520 |
467 /* now a tree area under this box */ | 521 /* now a tree area under this box */ |
468 tree = dw_tree_new(0); | 522 tree = dw_tree_new(0); |
469 dw_box_pack_start( notebookbox3, tree, 500, 200, TRUE, FALSE, 1); | 523 dw_box_pack_start( notebookbox3, tree, 500, 200, TRUE, FALSE, 1); |
470 | 524 |
525 /* and a status area to see whats going on */ | |
526 tree_status = dw_status_text_new("", 0); | |
527 dw_box_pack_start( notebookbox3, tree_status, 100, 20, TRUE, FALSE, 1); | |
528 | |
471 foldericon = dw_icon_load_from_file( FOLDER_ICON_NAME ); | 529 foldericon = dw_icon_load_from_file( FOLDER_ICON_NAME ); |
472 fileicon = dw_icon_load_from_file( FILE_ICON_NAME ); | 530 fileicon = dw_icon_load_from_file( FILE_ICON_NAME ); |
473 | 531 |
474 t1 = dw_tree_insert(tree, "tree item 1", foldericon, NULL, NULL ); | 532 t1 = dw_tree_insert(tree, "tree folder 1", foldericon, NULL, NULL ); |
475 t2 = dw_tree_insert(tree, "tree item 2", foldericon, NULL, NULL ); | 533 t2 = dw_tree_insert(tree, "tree folder 2", foldericon, NULL, NULL ); |
476 t3 = dw_tree_insert(tree, "tree item 3", fileicon, t2, NULL ); | 534 t3 = dw_tree_insert(tree, "tree file 1", fileicon, t1, NULL ); |
477 | 535 t4 = dw_tree_insert(tree, "tree file 2", fileicon, t1, NULL ); |
478 /* | 536 t5 = dw_tree_insert(tree, "tree file 3", fileicon, t2, NULL ); |
479 dw_signal_connect(textbox1, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); | 537 t6 = dw_tree_insert(tree, "tree file 4", fileicon, t2, NULL ); |
480 dw_signal_connect(textbox2, "expose_event", DW_SIGNAL_FUNC(text_expose), NULL); | 538 |
481 dw_signal_connect(textbox2, "configure_event", DW_SIGNAL_FUNC(configure_event), text2pm); | 539 /* set up our signal trappers... */ |
482 dw_signal_connect(hscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); | 540 /* looks odd, we use a container-context signal on a tree widget! */ |
483 dw_signal_connect(vscrollbar, "value_changed", DW_SIGNAL_FUNC(scrollbar_valuechanged), (void *)status); | 541 dw_signal_connect(tree, "container-context", DW_SIGNAL_FUNC(container_context_cb), tree_status); |
484 dw_signal_connect(textbox1, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text1pm); | 542 dw_signal_connect(tree, "tree-select", DW_SIGNAL_FUNC(tree_select_cb), tree_status); |
485 dw_signal_connect(textbox2, "key_press_event", DW_SIGNAL_FUNC(keypress_callback), text2pm); | 543 /* also odd; the tree-context doesn't seem to do anything. In fact GTK complains that |
486 */ | 544 * tree-context is invalid in a tree widget |
545 */ | |
546 dw_signal_connect(tree, "tree-context", DW_SIGNAL_FUNC(tree_context_cb), tree_status); | |
547 } | |
548 | |
549 void container_add(void) | |
550 { | |
551 char *titles[3]; | |
552 char buffer[100]; | |
553 unsigned long flags[3] = { DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, | |
554 DW_CFA_TIME | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR, | |
555 DW_CFA_DATE | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR }; | |
556 void *containerinfo; | |
557 int z; | |
558 CTIME time; | |
559 CDATE date; | |
560 unsigned long size, thisicon; | |
561 | |
562 /* create a box to pack into the notebook page */ | |
563 containerbox = dw_box_new(BOXHORZ, 2); | |
564 dw_box_pack_start( notebookbox4, containerbox, 500, 200, TRUE, TRUE, 0); | |
565 | |
566 /* now a container area under this box */ | |
567 container = dw_container_new(0); | |
568 dw_box_pack_start( notebookbox4, container, 500, 200, TRUE, FALSE, 1); | |
569 | |
570 /* and a status area to see whats going on */ | |
571 container_status = dw_status_text_new("", 0); | |
572 dw_box_pack_start( notebookbox4, container_status, 100, 20, TRUE, FALSE, 1); | |
573 | |
574 titles[0] = "Size"; | |
575 titles[1] = "Time"; | |
576 titles[2] = "Date"; | |
577 | |
578 dw_filesystem_setup(container, flags, titles, 3); | |
579 containerinfo = dw_container_alloc(container, 3); | |
580 | |
581 for(z=0;z<3;z++) | |
582 { | |
583 size = z+100; | |
584 sprintf(buffer, "Filename %d",z+1); | |
585 if (z == 0 ) thisicon = foldericon; | |
586 else thisicon = fileicon; | |
587 dw_filesystem_set_file(container, containerinfo, z, buffer, thisicon); | |
588 dw_filesystem_set_item(container, containerinfo, 0, z, &size); | |
589 | |
590 time.seconds = z+10; | |
591 time.minutes = z+10; | |
592 time.hours = z+10; | |
593 dw_filesystem_set_item(container, containerinfo, 1, z, &time); | |
594 | |
595 date.day = z+10; | |
596 date.month = z+10; | |
597 date.year = z+2000; | |
598 dw_filesystem_set_item(container, containerinfo, 2, z, &date); | |
599 | |
600 dw_container_set_row_title(containerinfo, z, buffer); | |
601 } | |
602 | |
603 dw_container_insert(container, containerinfo, 3); | |
604 dw_container_optimize(container); | |
605 | |
606 /* connect our event trappers... */ | |
607 dw_signal_connect(container, "container-select", DW_SIGNAL_FUNC(container_select_cb), container_status); | |
608 dw_signal_connect(container, "container-context", DW_SIGNAL_FUNC(container_context_cb), container_status); | |
609 /* NOTE that even though we are trapping a tree-select on a container, we have to set | |
610 * a container-select callback handler, otherwise dwindows will crash, because | |
611 * the prototypes for tree-select and container-select callback handlers are different | |
612 */ | |
613 dw_signal_connect(container, "tree-select", DW_SIGNAL_FUNC(container_select_cb), container_status); | |
487 } | 614 } |
488 | 615 |
489 /* Beep every second */ | 616 /* Beep every second */ |
490 int DWSIGNAL timer_callback(void *data) | 617 int DWSIGNAL timer_callback(void *data) |
491 { | 618 { |
501 int main(int argc, char *argv[]) | 628 int main(int argc, char *argv[]) |
502 { | 629 { |
503 ULONG notebookpage1; | 630 ULONG notebookpage1; |
504 ULONG notebookpage2; | 631 ULONG notebookpage2; |
505 ULONG notebookpage3; | 632 ULONG notebookpage3; |
633 ULONG notebookpage4; | |
506 | 634 |
507 dw_init(TRUE, argc, argv); | 635 dw_init(TRUE, argc, argv); |
508 | 636 |
509 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); | 637 mainwindow = dw_window_new( HWND_DESKTOP, "dwindows test", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX ); |
510 | 638 |
515 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0); | 643 dw_box_pack_start( notebookbox, notebook, 100, 100, TRUE, TRUE, 0); |
516 | 644 |
517 notebookbox1 = dw_box_new( BOXVERT, 5 ); | 645 notebookbox1 = dw_box_new( BOXVERT, 5 ); |
518 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE ); | 646 notebookpage1 = dw_notebook_page_new( notebook, 0, TRUE ); |
519 dw_notebook_pack( notebook, notebookpage1, notebookbox1 ); | 647 dw_notebook_pack( notebook, notebookpage1, notebookbox1 ); |
520 dw_notebook_page_set_text( notebook, notebookpage1, "first page"); | 648 dw_notebook_page_set_text( notebook, notebookpage1, "buttons and entry"); |
521 archive_add(); | 649 archive_add(); |
522 | 650 |
523 notebookbox2 = dw_box_new( BOXVERT, 5 ); | 651 notebookbox2 = dw_box_new( BOXVERT, 5 ); |
524 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE ); | 652 notebookpage2 = dw_notebook_page_new( notebook, 1, FALSE ); |
525 dw_notebook_pack( notebook, notebookpage2, notebookbox2 ); | 653 dw_notebook_pack( notebook, notebookpage2, notebookbox2 ); |
526 dw_notebook_page_set_text( notebook, notebookpage2, "second page"); | 654 dw_notebook_page_set_text( notebook, notebookpage2, "render"); |
527 text_add(); | 655 text_add(); |
528 | 656 |
529 notebookbox3 = dw_box_new( BOXVERT, 5 ); | 657 notebookbox3 = dw_box_new( BOXVERT, 5 ); |
530 notebookpage3 = dw_notebook_page_new( notebook, 1, FALSE ); | 658 notebookpage3 = dw_notebook_page_new( notebook, 1, FALSE ); |
531 dw_notebook_pack( notebook, notebookpage3, notebookbox3 ); | 659 dw_notebook_pack( notebook, notebookpage3, notebookbox3 ); |
532 dw_notebook_page_set_text( notebook, notebookpage3, "third page"); | 660 dw_notebook_page_set_text( notebook, notebookpage3, "tree"); |
533 tree_add(); | 661 tree_add(); |
662 | |
663 notebookbox4 = dw_box_new( BOXVERT, 5 ); | |
664 notebookpage4 = dw_notebook_page_new( notebook, 1, FALSE ); | |
665 dw_notebook_pack( notebook, notebookpage4, notebookbox4 ); | |
666 dw_notebook_page_set_text( notebook, notebookpage4, "container"); | |
667 container_add(); | |
534 | 668 |
535 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow); | 669 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(exit_callback), (void *)mainwindow); |
536 timerid = dw_timer_connect(1000, DW_SIGNAL_FUNC(timer_callback), 0); | 670 timerid = dw_timer_connect(1000, DW_SIGNAL_FUNC(timer_callback), 0); |
537 dw_window_set_usize(mainwindow, 640, 480); | 671 dw_window_set_usize(mainwindow, 640, 480); |
538 dw_window_show(mainwindow); | 672 dw_window_show(mainwindow); |