improve delays created by vicon drawing locks, reset_cache segv fix, gang track toolt...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bclistboxitem.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bclistboxitem.h"
23 #include "bcpixmap.h"
24 #include "bcresources.h"
25 #include "bcwindowbase.h"
26
27 #include <string.h>
28
29
30 // ====================================================== item
31
32 BC_ListBoxItem::BC_ListBoxItem()
33 {
34         initialize();
35
36         color = BC_WindowBase::get_resources()->listbox_text;
37         this->text = new char[1];
38         text[0] = 0;
39         selectable = 1;
40 }
41
42 BC_ListBoxItem::BC_ListBoxItem(const char *text,
43         BC_Pixmap *icon,
44         int color)
45 {
46         initialize();
47
48         if(color == -1) color = BC_WindowBase::get_resources()->listbox_text;
49         this->text = new char[strlen(text) + 1];
50         this->icon = icon;
51
52         strcpy(this->text, text);
53         this->color = color;
54         selectable = 1;
55 }
56
57 BC_ListBoxItem::BC_ListBoxItem(const char *text, int color)
58 {
59         initialize();
60
61         if(color == -1) color = BC_WindowBase::get_resources()->listbox_text;
62         this->text = new char[strlen(text) + 1];
63         strcpy(this->text, text);
64         this->color = color;
65         selectable = 1;
66 }
67
68 BC_ListBoxItem::~BC_ListBoxItem()
69 {
70         if(text) delete [] text;
71         if(sublist)
72         {
73                 for(int i = 0; i < columns; i++)
74                         sublist[i].remove_all_objects();
75                 delete [] sublist;
76         }
77 }
78
79 int BC_ListBoxItem::initialize()
80 {
81         autoplace_icon = 1;
82         autoplace_text = 1;
83         text = 0;
84         color = BLACK;
85         selected = 0;
86         icon = 0;
87         icon_vframe = 0;
88         text_x = text_y = -1;
89         text_w = text_h = -1;
90         baseline = -1;
91         icon_x = -1;
92         icon_y = -1;
93         searchable = 1;
94         in_view = -1;
95         sublist = 0;
96         columns = 0;
97         expand = 0;
98         return 0;
99 }
100
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(); }
103
104 BC_Pixmap* BC_ListBoxItem::get_icon()
105 {
106         return icon;
107 }
108
109
110 void BC_ListBoxItem::set_text(const char *new_text)
111 {
112         if(this->text) delete [] this->text;
113
114         if(new_text) {
115                 text = new char[strlen(new_text) + 1];
116                 strcpy(this->text, new_text);
117         }
118         else
119                 text = 0;
120         text_w = text_h = -1;
121         baseline = -1;
122 }
123
124 void BC_ListBoxItem::copy_from(BC_ListBoxItem *item)
125 {
126         if(item->text) set_text(item->text);
127         color = item->color;
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;
135         if(item->sublist)
136         {
137                 sublist = new ArrayList<BC_ListBoxItem*>[columns];
138                 for(int i = 0; i < columns; i++)
139                 {
140                         ArrayList<BC_ListBoxItem*> *list = &item->get_sublist()[i];
141
142                         for(int j = 0; j < list->total; j++)
143                         {
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);
148                         }
149                 }
150         }
151 }
152
153 ArrayList<BC_ListBoxItem*>* BC_ListBoxItem::new_sublist(int columns)
154 {
155         sublist = new ArrayList<BC_ListBoxItem*>[columns];
156         this->columns = columns;
157         return sublist;
158 }
159
160 int BC_ListBoxItem::compare_item_text(const void *a, const void *b)
161 {
162         BC_ListBoxItem *ap = *(BC_ListBoxItem**)a, *bp = *(BC_ListBoxItem**)b;
163         return strcmp(ap->text, bp->text);
164 }
165
166 void BC_ListBoxItem::sort_items(ArrayList<BC_ListBoxItem*> &items)
167 {
168         qsort(&items[0], items.size(), sizeof(items[0]), compare_item_text);
169 }
170
171