3 * Copyright (C) 2018-2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include "bcsignals.h"
24 #include "pys_icon_png.h"
26 class TestList : public BC_ListBox
29 TestList(int x, int y, int w, int h,
30 ArrayList<BC_ListBoxItem*> *items);
32 int selection_changed();
35 TestList::TestList(int x, int y, int w, int h,
36 ArrayList<BC_ListBoxItem*> *items)
37 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, items,
38 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0)
42 int TestList::handle_event()
44 printf("handle_event\n");
48 int TestList::selection_changed()
50 BC_ListBoxItem *item = get_selection(0, 0);
51 printf("selection_changed %s\n", !item ? "<nul>" : item->get_text());
55 class TestWindow : public BC_Window
58 TestWindow() : BC_Window("Test9", 0, 0, 320, 240) {};
59 void create_objects();
62 ArrayList<BC_ListBoxItem*> items;
65 void TestWindow::create_objects()
67 lock_window("AWindowRemovePluginGUI::create_objects");
71 draw_text(x, y, "Hello world");
73 BC_Button *ok_button = new BC_OKButton(this);
74 add_subwindow(ok_button);
75 BC_Button *cancel_button = new BC_CancelButton(this);
76 add_subwindow(cancel_button);
77 BC_ListBoxItem *thing;
78 ArrayList<BC_ListBoxItem*> *sublist;
79 items.append(thing = new BC_ListBoxItem("thing 1"));
80 VFrame *pys_icon = new VFramePng(pys_icon_png);
81 thing->set_icon_vframe(pys_icon);
82 int pw = pys_icon->get_w(), ph = pys_icon->get_h();
83 BC_Pixmap *pys_picon = new BC_Pixmap(this, pw, ph);
84 pys_picon->draw_vframe(pys_icon, 0, 0, pw, pw, 0, 0);
85 thing->set_icon(pys_picon);
86 sublist = thing->new_sublist(1);
87 BC_ListBoxItem *fish, *cat, *hat;
88 sublist->append(fish = new BC_ListBoxItem("fish"));
89 ArrayList<BC_ListBoxItem*> *fish_list = fish->new_sublist(1);
90 fish_list->append(new BC_ListBoxItem("green"));
91 fish_list->append(new BC_ListBoxItem("eggs"));
92 fish_list->append(new BC_ListBoxItem("ham"));
93 sublist->append(cat = new BC_ListBoxItem("cat"));
94 ArrayList<BC_ListBoxItem*> *cat_list = cat->new_sublist(1);
95 cat_list->append(new BC_ListBoxItem("videos"));
96 sublist->append(hat = new BC_ListBoxItem("hat"));
97 ArrayList<BC_ListBoxItem*> *hat_list = hat->new_sublist(1);
98 hat_list->append(new BC_ListBoxItem("bonnet"));
99 hat_list->append(new BC_ListBoxItem("cap"));
100 hat_list->append(new BC_ListBoxItem("sombrero"));
101 items.append(thing = new BC_ListBoxItem("thing 2"));
102 int lw = get_w()-x-10, lh = ok_button->get_y() - y - 5;
103 add_subwindow(list = new TestList(x, y, lw, lh, &items));
108 int TestWindow::keypress_event()
110 switch( get_keypress() ) {
112 switch( list->get_format() ) {
114 list->update_format(LISTBOX_ICONS, 1);
117 list->update_format(LISTBOX_ICONS_PACKED, 1);
119 case LISTBOX_ICONS_PACKED:
120 list->update_format(LISTBOX_ICON_LIST, 1);
122 case LISTBOX_ICON_LIST:
123 list->update_format(LISTBOX_TEXT, 1);
135 window.create_objects();