6 #include "bclistboxitem.h"
7 #include "bcrecentlist.h"
9 // NOTE: textbox can be NULL if no textbox is associated
10 BC_RecentList::BC_RecentList(const char *type, BC_Hash *defaults,
11 BC_TextBox *textbox, int max,
12 int x, int y, int w, int h)
13 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, 0, 0, 0, 1, 0, 1)
16 this->defaults = defaults;
17 this->textbox = textbox;
18 set_tooltip("Choose from recently used");
21 BC_RecentList::BC_RecentList(const char *type, BC_Hash *defaults,
23 : BC_ListBox(textbox->get_x() + textbox->get_w(), textbox->get_y(),
24 textbox->get_w(), RECENT_POPUP_HEIGHT,
25 LISTBOX_TEXT, 0, 0, 0, 1, 0, 1)
28 this->defaults = defaults;
29 this->textbox = textbox;
30 set_tooltip("Choose from recently used");
33 BC_RecentList::BC_RecentList(const char *type, BC_Hash *defaults)
34 : BC_ListBox(-1, -1, -1, -1, LISTBOX_TEXT, 0, 0, 0, 1, 0, 1)
37 this->defaults = defaults;
41 BC_RecentList::~BC_RecentList() {
42 items.remove_all_objects();
45 int BC_RecentList::handle_event() {
46 BC_ListBoxItem *item = get_selection(0, 0);
47 if (item < 0) return 0;
48 char *text = item->get_text();
49 if (text && textbox) {
50 // change the text in the textbox
51 textbox->update(text);
52 // tell the textbox to deal with it
53 textbox->handle_event();
59 int BC_RecentList::load_items(const char *prefix) {
61 if (! prefix) prefix = "ANY";
63 if (items.total > 0) {
64 items.remove_all_objects();
68 for (count = 0; count < RECENT_MAX_ITEMS; count++) {
71 sprintf(save, "RECENT_%s_%s_%d", prefix, type, count);
73 defaults->get(save, text);
74 if (strlen(text) == 0) break;
75 items.append(new BC_ListBoxItem(text));
78 // only update if we are part of a window
79 if (textbox) update(&items, 0, 0, 1);
85 int BC_RecentList::add_item(const char *prefix, char *text) {
87 if (! prefix) prefix = "ANY";
89 // remove an old item if it matches the new text
90 for (int i = 0; i < items.total; i++) {
91 BC_ListBoxItem *item = items.values[i];
92 if (strcmp(text, item->get_text()) == 0) {
93 items.remove_object(item);
97 // make a new item and put it at the top of the list
98 items.insert(new BC_ListBoxItem(text), 0);
100 // save up to maximum items of the list for future use
103 count < RECENT_MAX_ITEMS && count < items.total;
105 BC_ListBoxItem *item = items.values[count];
106 char save[BCTEXTLEN];
107 sprintf(save, "RECENT_%s_%s_%d", prefix, type, count);
108 defaults->update(save, item->get_text());