version update
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / test9.C
1 #include "bcsignals.h"
2 #include "guicast.h"
3 #include "pys_icon_png.h"
4
5 class TestList : public BC_ListBox
6 {
7 public:
8         TestList(int x, int y, int w, int h, 
9                 ArrayList<BC_ListBoxItem*> *items);
10         int handle_event();
11         int selection_changed();
12 };
13
14 TestList::TestList(int x, int y, int w, int h, 
15                 ArrayList<BC_ListBoxItem*> *items)
16  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, items,
17         0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0)
18 {
19 }
20
21 int TestList::handle_event()
22 {
23         printf("handle_event\n");
24         return 1;
25 }
26
27 int TestList::selection_changed()
28 {
29         BC_ListBoxItem *item = get_selection(0, 0);
30         printf("selection_changed %s\n", !item ? "<nul>" : item->get_text());
31         return 1;
32 }
33
34 class TestWindow : public BC_Window
35 {
36 public:
37         TestWindow() : BC_Window("Test9", 0, 0, 320, 240) {};
38         void create_objects();
39         int keypress_event();
40         BC_ListBox *list;
41         ArrayList<BC_ListBoxItem*> items;
42 };
43
44 void TestWindow::create_objects()
45 {
46         lock_window("AWindowRemovePluginGUI::create_objects");
47         set_color(BLACK);
48         set_font(LARGEFONT);
49         int x = 10, y = 20;
50         draw_text(x, y, "Hello world");
51         y += 25;
52         BC_Button *ok_button = new BC_OKButton(this);
53         add_subwindow(ok_button);
54         BC_Button *cancel_button = new BC_CancelButton(this);
55         add_subwindow(cancel_button);
56         BC_ListBoxItem *thing;
57         ArrayList<BC_ListBoxItem*> *sublist;
58         items.append(thing = new BC_ListBoxItem("thing 1"));
59         VFrame *pys_icon = new VFramePng(pys_icon_png);
60         thing->set_icon_vframe(pys_icon);
61         int pw = pys_icon->get_w(), ph = pys_icon->get_h();
62         BC_Pixmap *pys_picon = new BC_Pixmap(this, pw, ph);
63         pys_picon->draw_vframe(pys_icon, 0, 0, pw, pw, 0, 0);
64         thing->set_icon(pys_picon);
65         sublist = thing->new_sublist(1);
66         BC_ListBoxItem *fish, *cat, *hat;
67         sublist->append(fish = new BC_ListBoxItem("fish"));
68         ArrayList<BC_ListBoxItem*> *fish_list = fish->new_sublist(1);
69         fish_list->append(new BC_ListBoxItem("green"));
70         fish_list->append(new BC_ListBoxItem("eggs"));
71         fish_list->append(new BC_ListBoxItem("ham"));
72         sublist->append(cat = new BC_ListBoxItem("cat"));
73         ArrayList<BC_ListBoxItem*> *cat_list = cat->new_sublist(1);
74         cat_list->append(new BC_ListBoxItem("videos"));
75         sublist->append(hat = new BC_ListBoxItem("hat"));
76         ArrayList<BC_ListBoxItem*> *hat_list = hat->new_sublist(1);
77         hat_list->append(new BC_ListBoxItem("bonnet"));
78         hat_list->append(new BC_ListBoxItem("cap"));
79         hat_list->append(new BC_ListBoxItem("sombrero"));
80         items.append(thing = new BC_ListBoxItem("thing 2"));
81         int lw = get_w()-x-10, lh = ok_button->get_y() - y - 5;
82         add_subwindow(list = new TestList(x, y, lw, lh, &items));
83         show_window();
84         unlock_window();
85 }
86
87 int TestWindow::keypress_event()
88 {
89         switch( get_keypress() ) {
90         case 'v':
91                 switch( list->get_format() ) {
92                 case LISTBOX_TEXT:
93                         list->update_format(LISTBOX_ICONS, 1);
94                         break;
95                 case LISTBOX_ICONS:
96                         list->update_format(LISTBOX_ICONS_PACKED, 1);
97                         break;
98                 case LISTBOX_ICONS_PACKED:
99                         list->update_format(LISTBOX_ICON_LIST, 1);
100                         break;
101                 case LISTBOX_ICON_LIST:
102                         list->update_format(LISTBOX_TEXT, 1);
103                         break;
104                 }
105                 break;
106         }
107         return 1;
108 }
109
110 int main()
111 {
112         new BC_Signals;
113         TestWindow window;
114         window.create_objects();
115         window.run_window();
116 }
117