initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / mainerror.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 "bcdisplayinfo.h"
23 #include "bcsignals.h"
24 #include "language.h"
25 #include "mainerror.h"
26 #include "mainsession.h"
27 #include "mutex.h"
28 #include "mwindow.h"
29
30 #include <string.h>
31
32
33
34
35 MainError* MainError::main_error = 0;
36
37
38
39
40
41
42 MainErrorGUI::MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y)
43  : BC_Window(PROGRAM_NAME ": Errors",
44         x,
45         y,
46         mwindow->session->ewindow_w,
47         mwindow->session->ewindow_h,
48         50,
49         50,
50         1,
51         0,
52         1,
53         -1,
54         "",
55         1)
56 {
57         this->mwindow = mwindow;
58         this->thread = thread;
59 }
60
61 MainErrorGUI::~MainErrorGUI()
62 {
63 }
64
65 void MainErrorGUI::create_objects()
66 {
67         lock_window("MainErrorGUI::create_objects");
68 SET_TRACE
69
70         BC_Button *button;
71         add_subwindow(button = new BC_OKButton(this));
72         int x = 10, y = 10;
73 SET_TRACE
74         add_subwindow(title = new BC_Title(x, y, _("The following errors occurred:")));
75         y += title->get_h() + 5;
76 SET_TRACE
77         add_subwindow(list = new BC_ListBox(x,
78                 y,
79                 get_w() - 20,
80                 button->get_y() - y - 5,
81                 LISTBOX_TEXT,                   // Display text list or icons
82                 &thread->errors, // Each column has an ArrayList of BC_ListBoxItems.
83                 0,             // Titles for columns.  Set to 0 for no titles
84                 0,                // width of each column
85                 1,                      // Total columns.  Only 1 in icon mode
86                 0,                    // Pixel of top of window.
87                 0,                     // If this listbox is a popup window with a button
88                 LISTBOX_SINGLE,  // Select one item or multiple items
89                 ICON_LEFT,        // Position of icon relative to text of each item
90                 0));
91 SET_TRACE
92         show_window();
93 SET_TRACE
94         unlock_window();
95 }
96
97 int MainErrorGUI::resize_event(int w, int h)
98 {
99         title->reposition_window(title->get_x(), title->get_y());
100         int list_h = h - 
101                 list->get_y() - 
102                 (get_h() - list->get_y() - list->get_h());
103         int list_w = w - 
104                 list->get_x() - 
105                 (get_w() - list->get_x() - list->get_w());
106         list->reposition_window(list->get_x(),
107                 list->get_y(),
108                 list_w,
109                 list_h);
110         mwindow->session->ewindow_w = w;
111         mwindow->session->ewindow_h = h;
112         return 1;
113 }
114
115
116
117
118
119
120 MainError::MainError(MWindow *mwindow)
121  : BC_DialogThread()
122 {
123         this->mwindow = mwindow;
124         errors_lock = new Mutex("MainError::errors_lock");
125         main_error = this;
126 }
127
128 MainError::~MainError()
129 {
130         delete errors_lock;
131 }
132
133 BC_Window* MainError::new_gui()
134 {
135         BC_DisplayInfo display_info;
136         int x = display_info.get_abs_cursor_x();
137         int y = display_info.get_abs_cursor_y();
138
139         MainErrorGUI *gui = new MainErrorGUI(mwindow, this, x, y);
140         gui->create_objects();
141         return gui;
142 }
143
144 void MainError::append_error(const char *string)
145 {
146         char *in_ptr = (char*)string;
147         char string2[BCTEXTLEN];
148         int first_line = 1;
149         while(*in_ptr)
150         {
151                 char *out_ptr = string2;
152 // Indent remaining lines
153                 if(!first_line)
154                 {
155                         *out_ptr++ = ' ';
156                         *out_ptr++ = ' ';
157                 }
158
159                 while(*in_ptr != '\n' &&
160                         *in_ptr)
161                 {
162                         *out_ptr++ = *in_ptr++;
163                 }
164                 *out_ptr++ = 0;
165
166                 errors.append(new BC_ListBoxItem(string2));
167
168                 if(*in_ptr == '\n')
169                 {
170                         in_ptr++;
171                         first_line = 0;
172                 }
173         }
174 }
175
176 void MainError::show_error_local(const char *string)
177 {
178 SET_TRACE
179 // assume user won't get to closing the GUI here
180         lock_window("MainError::show_error_local");
181 SET_TRACE
182         if(get_gui())
183         {
184 SET_TRACE
185                 MainErrorGUI *gui = (MainErrorGUI*)get_gui();
186                 gui->lock_window("MainError::show_error_local");
187 SET_TRACE
188                 append_error(string);
189 SET_TRACE
190                 gui->list->update(&errors,
191                         0,
192                         0,
193                         1,
194                         gui->list->get_xposition(),
195                         gui->list->get_yposition(),
196                         gui->list->get_highlighted_item(),  // Flat index of item cursor is over
197                         0,     // set all autoplace flags to 1
198                         1);
199 SET_TRACE
200                 gui->unlock_window();
201                 unlock_window();
202 SET_TRACE
203                 start();
204 SET_TRACE
205         }
206         else
207         {
208                 unlock_window();
209 SET_TRACE
210                 errors.remove_all_objects();
211 SET_TRACE
212                 append_error(string);
213 SET_TRACE
214                 start();
215 SET_TRACE
216         }
217 }
218
219
220 void MainError::show_error(const char *string)
221 {
222         if(main_error)
223                 main_error->show_error_local(string);
224         else
225         {
226                 printf("%s", string);
227                 if(string[strlen(string) - 1] != '\n')
228                         printf("\n");
229         }
230 }
231
232
233
234
235
236
237