00001 #include "bclistboxitem.h" 00002 #include "bcpixmap.h" 00003 #include "bcresources.h" 00004 #include "bcwindowbase.h" 00005 00006 #include <string.h> 00007 00008 00009 // ====================================================== item 00010 00011 BC_ListBoxItem::BC_ListBoxItem() 00012 { 00013 initialize(); 00014 00015 color = BC_WindowBase::get_resources()->listbox_text; 00016 this->text = new char[1]; 00017 text[0] = 0; 00018 selectable = 1; 00019 } 00020 00021 BC_ListBoxItem::BC_ListBoxItem(char *text, 00022 BC_Pixmap *icon, 00023 int color) 00024 { 00025 initialize(); 00026 00027 if(color == -1) color = BC_WindowBase::get_resources()->listbox_text; 00028 this->text = new char[strlen(text) + 1]; 00029 this->icon = icon; 00030 00031 strcpy(this->text, text); 00032 this->color = color; 00033 selectable = 1; 00034 } 00035 00036 BC_ListBoxItem::BC_ListBoxItem(char *text, int color) 00037 { 00038 initialize(); 00039 00040 if(color == -1) color = BC_WindowBase::get_resources()->listbox_text; 00041 this->text = new char[strlen(text) + 1]; 00042 strcpy(this->text, text); 00043 this->color = color; 00044 selectable = 1; 00045 } 00046 00047 BC_ListBoxItem::~BC_ListBoxItem() 00048 { 00049 if(text) delete [] text; 00050 if(sublist) 00051 { 00052 for(int i = 0; i < columns; i++) 00053 sublist[i].remove_all_objects(); 00054 delete sublist; 00055 } 00056 } 00057 00058 int BC_ListBoxItem::initialize() 00059 { 00060 autoplace_icon = 1; 00061 autoplace_text = 1; 00062 text = 0; 00063 color = BLACK; 00064 selected = 0; 00065 icon = 0; 00066 icon_vframe = 0; 00067 text_x = -1; 00068 text_y = -1; 00069 icon_x = -1; 00070 icon_y = -1; 00071 searchable = 1; 00072 sublist = 0; 00073 columns = 0; 00074 expand = 0; 00075 return 0; 00076 } 00077 00078 int BC_ListBoxItem::get_icon_x() 00079 { 00080 return icon_x; 00081 } 00082 00083 int BC_ListBoxItem::get_icon_y() 00084 { 00085 return icon_y; 00086 } 00087 00088 int BC_ListBoxItem::get_text_x() 00089 { 00090 return text_x; 00091 } 00092 00093 int BC_ListBoxItem::get_text_y() 00094 { 00095 return text_y; 00096 } 00097 00098 int BC_ListBoxItem::set_autoplace_icon(int value) 00099 { 00100 autoplace_icon = value; 00101 return 0; 00102 } 00103 00104 int BC_ListBoxItem::set_autoplace_text(int value) 00105 { 00106 autoplace_text = value; 00107 return 0; 00108 } 00109 00110 void BC_ListBoxItem::set_icon_x(int x) 00111 { 00112 icon_x = x; 00113 autoplace_icon = 0; 00114 } 00115 00116 void BC_ListBoxItem::set_icon_y(int y) 00117 { 00118 icon_y = y; 00119 autoplace_icon = 0; 00120 } 00121 00122 void BC_ListBoxItem::set_selected(int value) 00123 { 00124 this->selected = value; 00125 } 00126 00127 void BC_ListBoxItem::set_searchable(int value) 00128 { 00129 this->searchable = value; 00130 } 00131 00132 void BC_ListBoxItem::set_selectable(int value) 00133 { 00134 this->selectable = value; 00135 } 00136 00137 int BC_ListBoxItem::get_selectable() 00138 { 00139 return selectable; 00140 } 00141 00142 00143 00144 void BC_ListBoxItem::set_text_x(int x) 00145 { 00146 text_x = x; 00147 autoplace_text = 0; 00148 } 00149 void BC_ListBoxItem::set_text_y(int y) 00150 { 00151 text_y = y; 00152 autoplace_text = 0; 00153 } 00154 00155 int BC_ListBoxItem::get_icon_w() 00156 { 00157 return icon->get_w(); 00158 } 00159 00160 int BC_ListBoxItem::get_icon_h() 00161 { 00162 return icon->get_h(); 00163 } 00164 00165 void BC_ListBoxItem::set_text(char *new_text) 00166 { 00167 if(this->text) delete [] this->text; 00168 this->text = 0; 00169 00170 if(new_text) 00171 { 00172 this->text = new char[strlen(new_text) + 1]; 00173 strcpy(this->text, new_text); 00174 } 00175 } 00176 00177 char* BC_ListBoxItem::get_text() 00178 { 00179 return text; 00180 } 00181 00182 void BC_ListBoxItem::set_icon(BC_Pixmap *icon) 00183 { 00184 this->icon = icon; 00185 } 00186 00187 void BC_ListBoxItem::set_icon_vframe(VFrame *icon_vframe) 00188 { 00189 this->icon_vframe = icon_vframe; 00190 } 00191 00192 void BC_ListBoxItem::set_color(int color) 00193 { 00194 this->color = color; 00195 } 00196 00197 int BC_ListBoxItem::get_color() 00198 { 00199 return color; 00200 } 00201 00202 00203 BC_ListBoxItem& BC_ListBoxItem::operator=(BC_ListBoxItem& item) 00204 { 00205 copy_from(&item); 00206 return *this; 00207 } 00208 00209 void BC_ListBoxItem::copy_from(BC_ListBoxItem *item) 00210 { 00211 if(item->text) set_text(item->text); 00212 color = item->color; 00213 text_x = item->text_x; 00214 text_y = item->text_y; 00215 icon_x = item->icon_x; 00216 icon_y = item->icon_y; 00217 selectable = item->selectable; 00218 columns = item->columns; 00219 if(item->sublist) 00220 { 00221 sublist = new ArrayList<BC_ListBoxItem*>[columns]; 00222 for(int i = 0; i < columns; i++) 00223 { 00224 ArrayList<BC_ListBoxItem*> *list = &item->get_sublist()[i]; 00225 00226 for(int j = 0; j < list->total; j++) 00227 { 00228 BC_ListBoxItem *new_item = new BC_ListBoxItem; 00229 BC_ListBoxItem *old_item = list->values[j]; 00230 sublist[i].append(new_item); 00231 new_item->copy_from(old_item); 00232 } 00233 } 00234 } 00235 } 00236 00237 ArrayList<BC_ListBoxItem*>* BC_ListBoxItem::new_sublist(int columns) 00238 { 00239 sublist = new ArrayList<BC_ListBoxItem*>[columns]; 00240 this->columns = columns; 00241 return sublist; 00242 } 00243 00244 ArrayList<BC_ListBoxItem*>* BC_ListBoxItem::get_sublist() 00245 { 00246 return sublist; 00247 } 00248 00249 int BC_ListBoxItem::get_columns() 00250 { 00251 return columns; 00252 } 00253 00254 int BC_ListBoxItem::get_expand() 00255 { 00256 return expand; 00257 } 00258 00259 void BC_ListBoxItem::set_expand(int value) 00260 { 00261 expand = value; 00262 } 00263 00264 00265 00266
1.5.5