subtitle upgrades, textbox fixes/upgrades
[goodguy/history.git] / cinelerra-5.1 / guicast / bctextbox.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 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 #ifndef BCTEXTBOX_H
23 #define BCTEXTBOX_H
24
25 #include "bclistbox.h"
26 #include "bcsubwindow.h"
27 #include "bctumble.h"
28 #include "fonts.h"
29 #include "bctextbox.inc"
30 #include "bctimer.inc"
31
32 #define BCCURSORW 2
33
34
35
36
37 class BC_TextBoxSuggestions;
38 class BC_ScrollTextBoxYScroll;
39
40
41 class BC_TextBox : public BC_SubWindow
42 {
43         char *text;
44         wchar_t *wtext;
45 public:
46         BC_TextBox(int x, int y, int w, int rows, int size, char *text,
47                 int has_border=1, int font=MEDIUMFONT);
48         BC_TextBox(int x, int y, int w, int rows, int size, wchar_t *wtext,
49                 int has_border=1, int font=MEDIUMFONT);
50         BC_TextBox(int x, int y, int w, int rows, const char *text,
51                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
52         BC_TextBox(int x, int y, int w, int rows, const wchar_t *wtext,
53                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
54         BC_TextBox(int x, int y, int w, int rows, int64_t text,
55                 int has_border=1, int font=MEDIUMFONT);
56         BC_TextBox(int x, int y, int w, int rows, float text,
57                 int has_border=1, int font=MEDIUMFONT, int precision=4);
58         BC_TextBox(int x, int y, int w, int rows,
59                 int text, int has_border=1, int font=MEDIUMFONT);
60         virtual ~BC_TextBox();
61
62
63         friend class BC_TextBoxSuggestions;
64
65
66 // Whenever the contents of the text change
67         virtual int handle_event() { return 0; };
68 // Whenever the position of the text changes
69         virtual int motion_event() { return 0; };
70         void set_selection(int char1, int char2, int ibeam);
71         void wset_selection(int char1, int char2, int ibeam);
72         int update(const char *text);
73         int update(const wchar_t *wtext);
74         int update(int64_t value);
75         int update(float value);
76         void disable();
77         void enable();
78         int get_enabled();
79         int get_rows();
80
81         int initialize();
82
83         int focus_in_event();
84         int focus_out_event();
85         int cursor_enter_event();
86         int cursor_leave_event();
87         int cursor_motion_event();
88         virtual int button_press_event();
89         int button_release_event();
90         int repeat_event(int64_t repeat_id);
91         int keypress_event();
92         int activate();
93         int deactivate();
94         const char* get_text();
95         const wchar_t* get_wtext();
96         void set_text(char *text, int isz);
97         int get_text_rows();
98 // Set top left of text view
99         void set_text_row(int row);
100         int get_text_row();
101
102         int reposition_window(int x, int y, int w = -1, int rows = -1);
103         int uses_text();
104         static int calculate_h(BC_WindowBase *gui, int font, int has_border, int rows);
105         static int calculate_row_h(int rows, BC_WindowBase *parent_window, int has_border = 1, int font = MEDIUMFONT);
106         static int pixels_to_rows(BC_WindowBase *window, int font, int pixels);
107         static int wcpos(const char *text, const char *ep);
108
109         void set_precision(int precision);
110 // Whether to draw every time there is a keypress or rely on user to
111 // follow up every keypress with an update().
112         void set_keypress_draw(int value);
113         int get_ibeam_letter();
114         void set_ibeam_letter(int number, int redraw = 1);
115 // Used for custom formatting text boxes
116         int get_last_keypress();
117 // Table of separators to skip.  Used by time textboxes
118 // The separator format is "0000:0000".  Things not alnum are considered
119 // separators.  The alnums are replaced by user text.
120         void set_separators(const char *separators);
121
122 // 1 - selects text, -1 - deselects, 0 - do nothing
123 // in all cases it returns text_selected after the operation
124         int select_whole_text(int select);
125
126 // Compute suggestions for a path
127 // If entries is null, just search absolute paths
128         int calculate_suggestions(ArrayList<BC_ListBoxItem*> *entries);
129
130
131 // User computes suggestions after handle_event.
132 // The array is copied to a local variable.
133 // A highlighted extension is added if 1 suggestion or a popup appears
134 // if multiple suggestions.
135 // column - starting column to replace
136         void set_suggestions(ArrayList<char*> *suggestions, int column);
137         BC_ScrollTextBoxYScroll *yscroll;
138
139 private:
140         int reset_parameters(int rows, int has_border, int font, int size);
141         void draw(int flush);
142         void draw_border();
143         void draw_cursor();
144         void copy_selection(int clipboard_num);
145         void paste_selection(int clipboard_num);
146         void delete_selection(int letter1, int letter2, int text_len);
147         void insert_text(const wchar_t *wcp, int len=-1);
148 // Reformat text according to separators.
149 // ibeam_left causes the ibeam to move left.
150         int is_separator(const char *txt, int i);
151         void do_separators(int ibeam_left);
152         void get_ibeam_position(int &x, int &y);
153         void find_ibeam(int dispatch_event);
154         void select_word(int &letter1, int &letter2, int ibeam_letter);
155         void select_line(int &letter1, int &letter2, int ibeam_letter);
156         int get_cursor_letter(int cursor_x, int cursor_y);
157         int get_cursor_letter2(int cursor_x, int cursor_y);
158         int get_row_h(int rows);
159         void default_keypress(int &dispatch_event, int &result);
160         int tstrlen();
161         int tstrcmp(const char *cp);
162         char *tstrcpy(const char *cp);
163         char *tstrcat(const char *cp);
164         int text_update(const wchar_t *wcp, int wsz, char *tcp, int tsz);
165         int wtext_update();
166
167 // Top left of text relative to window
168         int text_x, text_y;
169 // Top left of cursor relative to text
170         int ibeam_x, ibeam_y;
171
172         int ibeam_letter;
173         int highlight_letter1, highlight_letter2;
174         int highlight_letter3, highlight_letter4;
175         int text_x1, text_start, text_end;
176         int text_selected, word_selected, line_selected;
177         int text_ascent, text_descent, text_height;
178         int left_margin, right_margin, top_margin, bottom_margin;
179         int has_border;
180         int font;
181         int rows;
182         int highlighted;
183         int high_color, back_color;
184         int background_color;
185         int size, tsize, dirty;
186         int wlen, wsize, *positions, plen;
187         char temp_string[KEYPRESSLEN];
188         int is_utf8;
189         int active;
190         int enabled;
191         int precision;
192         int keypress_draw;
193 // Cause the repeater to skip a cursor refresh if a certain event happened
194 // within a certain time of the last repeat event
195         Timer *skip_cursor;
196 // Used for custom formatting text boxes
197         int last_keypress;
198         const char *separators;
199         ArrayList<BC_ListBoxItem*> *suggestions;
200         BC_TextBoxSuggestions *suggestions_popup;
201         int suggestion_column;
202 };
203
204
205
206 class BC_TextBoxSuggestions : public BC_ListBox
207 {
208 public:
209         BC_TextBoxSuggestions(BC_TextBox *text_box, int x, int y);
210         virtual ~BC_TextBoxSuggestions();
211
212         int selection_changed();
213         int handle_event();
214
215
216         BC_TextBox *text_box;
217 };
218
219
220
221 class BC_ScrollTextBoxText;
222 class BC_ScrollTextBoxYScroll;
223
224
225 class BC_ScrollTextBox
226 {
227 public:
228         BC_ScrollTextBox(BC_WindowBase *parent_window,
229                 int x, int y, int w, int rows,
230                 const char *default_text, int default_size=BCTEXTLEN);
231         BC_ScrollTextBox(BC_WindowBase *parent_window,
232                 int x, int y, int w, int rows,
233                 const wchar_t *default_wtext, int default_size=BCTEXTLEN);
234         virtual ~BC_ScrollTextBox();
235         void create_objects();
236         virtual int handle_event();
237
238         const char* get_text();
239         const wchar_t* get_wtext();
240         void set_text(char *text, int isz);
241         int set_text_row(int n);
242         void update(const char *text);
243         void update(const wchar_t *wtext);
244         void set_selection(int char1, int char2, int ibeam);
245         void wset_selection(int char1, int char2, int ibeam);
246         void reposition_window(int x, int y, int w, int rows);
247         int get_x();
248         int get_y();
249         int get_w();
250         int get_h();
251 // Visible rows for resizing
252         int get_rows();
253         int get_ibeam_letter();
254
255         friend class BC_ScrollTextBoxText;
256         friend class BC_ScrollTextBoxYScroll;
257
258 private:
259         BC_ScrollTextBoxText *text;
260         BC_ScrollTextBoxYScroll *yscroll;
261         BC_WindowBase *parent_window;
262         const char *default_text;
263         const wchar_t *default_wtext;
264         int default_size;
265         int x, y, w, rows;
266 };
267
268 class BC_ScrollTextBoxText : public BC_TextBox
269 {
270 public:
271         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const char *text);
272         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const wchar_t *wtext);
273         virtual ~BC_ScrollTextBoxText();
274         int handle_event();
275         int motion_event();
276         BC_ScrollTextBox *gui;
277 };
278
279 class BC_ScrollTextBoxYScroll : public BC_ScrollBar
280 {
281 public:
282         BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui);
283         virtual ~BC_ScrollTextBoxYScroll();
284         int handle_event();
285         BC_ScrollTextBox *gui;
286 };
287
288
289
290
291 class BC_PopupTextBoxText;
292 class BC_PopupTextBoxList;
293
294 class BC_PopupTextBox
295 {
296 public:
297         BC_PopupTextBox(BC_WindowBase *parent_window,
298                 ArrayList<BC_ListBoxItem*> *list_items,
299                 const char *default_text, int x, int y,
300                 int text_w, int list_h, int list_format = LISTBOX_TEXT);
301         virtual ~BC_PopupTextBox();
302         int create_objects();
303         virtual int handle_event();
304         const char* get_text();
305         const wchar_t* get_wtext();
306         int get_number();
307         int get_x();
308         int get_y();
309         int get_w();
310         int get_h();
311         void update(const char *text);
312         void update_list(ArrayList<BC_ListBoxItem*> *data);
313         void reposition_window(int x, int y);
314
315         friend class BC_PopupTextBoxText;
316         friend class BC_PopupTextBoxList;
317
318 private:
319         int x, y, text_w, list_h;
320         int list_format;
321         const char *default_text;
322         const wchar_t *default_wtext;
323         ArrayList<BC_ListBoxItem*> *list_items;
324         BC_PopupTextBoxText *textbox;
325         BC_PopupTextBoxList *listbox;
326         BC_WindowBase *parent_window;
327 };
328
329 class BC_PopupTextBoxText : public BC_TextBox
330 {
331 public:
332         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const char *text);
333         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const wchar_t *wtext);
334         virtual ~BC_PopupTextBoxText();
335         int handle_event();
336         BC_PopupTextBox *popup;
337 };
338
339 class BC_PopupTextBoxList : public BC_ListBox
340 {
341 public:
342         BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y);
343         int handle_event();
344         BC_PopupTextBox *popup;
345 };
346
347
348 class BC_TumbleTextBoxText;
349 class BC_TumbleTextBoxTumble;
350
351 class BC_TumbleTextBox
352 {
353 public:
354         BC_TumbleTextBox(BC_WindowBase *parent_window,
355                 int64_t default_value,
356                 int64_t min,
357                 int64_t max,
358                 int x,
359                 int y,
360                 int text_w);
361         BC_TumbleTextBox(BC_WindowBase *parent_window,
362                 int default_value,
363                 int min,
364                 int max,
365                 int x,
366                 int y,
367                 int text_w);
368         BC_TumbleTextBox(BC_WindowBase *parent_window,
369                 float default_value,
370                 float min,
371                 float max,
372                 int x,
373                 int y,
374                 int text_w);
375         virtual ~BC_TumbleTextBox();
376
377         int create_objects();
378         void reset();
379         virtual int handle_event();
380         const char* get_text();
381         const wchar_t* get_wtext();
382         BC_TextBox* get_textbox();
383         int update(const char *value);
384         int update(int64_t value);
385         int update(float value);
386         int get_x();
387         int get_y();
388         int get_w();
389         int get_h();
390         void disable();
391         void enable();
392         int get_enabled();
393         void reposition_window(int x, int y);
394         void set_boundaries(int64_t min, int64_t max);
395         void set_boundaries(float min, float max);
396         void set_precision(int precision);
397         void set_increment(float value);
398         void set_log_floatincrement(int value);
399
400         friend class BC_TumbleTextBoxText;
401         friend class BC_TumbleTextBoxTumble;
402
403 private:
404         int x, y, text_w;
405         int64_t default_value, min, max;
406         float default_value_f, min_f, max_f;
407         int use_float;
408         int precision;
409         float increment;
410         int log_floatincrement;
411         BC_TumbleTextBoxText *textbox;
412         BC_Tumbler *tumbler;
413         BC_WindowBase *parent_window;
414 };
415
416 class BC_TumbleTextBoxText : public BC_TextBox
417 {
418 public:
419         BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
420                 int64_t default_value,
421                 int64_t min,
422                 int64_t max,
423                 int x,
424                 int y);
425         BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
426                 float default_value,
427                 float min,
428                 float max,
429                 int x,
430                 int y);
431         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, int x, int y);
432         virtual ~BC_TumbleTextBoxText();
433         int handle_event();
434         int button_press_event();
435         BC_TumbleTextBox *popup;
436 };
437
438
439 #endif