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