4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bclistboxitem.h"
24 #include "bcresources.h"
25 #include "bcwindowbase.h"
30 // ====================================================== item
32 BC_ListBoxItem::BC_ListBoxItem()
36 color = BC_WindowBase::get_resources()->listbox_text;
37 this->text = new char[1];
42 BC_ListBoxItem::BC_ListBoxItem(const char *text,
48 if(color == -1) color = BC_WindowBase::get_resources()->listbox_text;
49 this->text = new char[strlen(text) + 1];
52 strcpy(this->text, text);
57 BC_ListBoxItem::BC_ListBoxItem(const char *text, int color)
61 if(color == -1) color = BC_WindowBase::get_resources()->listbox_text;
62 this->text = new char[strlen(text) + 1];
63 strcpy(this->text, text);
68 BC_ListBoxItem::~BC_ListBoxItem()
70 if(text) delete [] text;
73 for(int i = 0; i < columns; i++)
74 sublist[i].remove_all_objects();
79 int BC_ListBoxItem::initialize()
101 int BC_ListBoxItem::get_icon_w() { return !icon ? 0 : icon->get_w(); }
102 int BC_ListBoxItem::get_icon_h() { return !icon ? 0 : icon->get_h(); }
104 BC_Pixmap* BC_ListBoxItem::get_icon()
110 void BC_ListBoxItem::set_text(const char *new_text)
112 if(this->text) delete [] this->text;
115 text = new char[strlen(new_text) + 1];
116 strcpy(this->text, new_text);
120 text_w = text_h = -1;
124 void BC_ListBoxItem::copy_from(BC_ListBoxItem *item)
126 if(item->text) set_text(item->text);
128 text_x = item->text_x; text_y = item->text_y;
129 text_w = item->text_w; text_h = item->text_h;
130 baseline = item->baseline; in_view = -1;
131 icon_x = item->icon_x;
132 icon_y = item->icon_y;
133 selectable = item->selectable;
134 columns = item->columns;
137 sublist = new ArrayList<BC_ListBoxItem*>[columns];
138 for(int i = 0; i < columns; i++)
140 ArrayList<BC_ListBoxItem*> *list = &item->get_sublist()[i];
142 for(int j = 0; j < list->total; j++)
144 BC_ListBoxItem *new_item = new BC_ListBoxItem;
145 BC_ListBoxItem *old_item = list->values[j];
146 sublist[i].append(new_item);
147 new_item->copy_from(old_item);
153 ArrayList<BC_ListBoxItem*>* BC_ListBoxItem::new_sublist(int columns)
155 sublist = new ArrayList<BC_ListBoxItem*>[columns];
156 this->columns = columns;
160 int BC_ListBoxItem::compare_item_text(const void *a, const void *b)
162 BC_ListBoxItem *ap = *(BC_ListBoxItem**)a, *bp = *(BC_ListBoxItem**)b;
163 return strcmp(ap->text, bp->text);
166 void BC_ListBoxItem::sort_items(ArrayList<BC_ListBoxItem*> &items)
168 qsort(&items[0], items.size(), sizeof(items[0]), compare_item_text);