fix opengl transform translate (again), update shell btns, tweak lv2-blacklist, Makef...
[goodguy/cinelerra.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 "bcmenuitem.h"
27 #include "bcpopupmenu.h"
28 #include "bcsubwindow.h"
29 #include "bctumble.h"
30 #include "fonts.h"
31 #include "bctextbox.inc"
32 #include "bctimer.inc"
33
34 #define BCCURSORW 2
35
36
37
38
39 class BC_TextBoxSuggestions;
40
41 class BC_ScrollTextBoxXScroll;
42 class BC_ScrollTextBoxYScroll;
43 class BC_ScrollTextBoxText;
44 class BC_TextMenu;
45
46 class BC_TextBox : public BC_SubWindow
47 {
48         static inline int nib(int ch) {
49                 if( ch >= '0' && ch <= '9' ) ch -= '0';
50                 else if( ch >= 'A' && ch <= 'F' ) ch -= 'A'-10;
51                 else if( ch >= 'a' && ch <= 'f' ) ch -= 'a'-10;
52                 else ch = -1;
53                 return ch;
54         }
55 // may be local fixed/dynamic, or shared fixed ref via set_text
56         char *text;
57 // always local dynamic
58         wchar_t *wtext;
59 public:
60 // size > 0: fixed buffer, size == 0: dynamic buffer
61 // size < 0: fixed shared buffer via set_text
62         BC_TextBox(int x, int y, int w, int rows, int size, char *text,
63                 int has_border=1, int font=MEDIUMFONT);
64         BC_TextBox(int x, int y, int w, int rows, int size, wchar_t *wtext,
65                 int has_border=1, int font=MEDIUMFONT);
66         BC_TextBox(int x, int y, int w, int rows, const char *text,
67                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
68         BC_TextBox(int x, int y, int w, int rows, const wchar_t *wtext,
69                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
70         BC_TextBox(int x, int y, int w, int rows, int64_t text,
71                 int has_border=1, int font=MEDIUMFONT);
72         BC_TextBox(int x, int y, int w, int rows, float text,
73                 int has_border=1, int font=MEDIUMFONT, int precision=4);
74         BC_TextBox(int x, int y, int w, int rows,
75                 int text, int has_border=1, int font=MEDIUMFONT);
76         virtual ~BC_TextBox();
77
78
79         friend class BC_TextBoxSuggestions;
80         friend class BC_ScrollTextBox;
81
82
83 // Whenever the contents of the text change
84         virtual int handle_event() { return 0; };
85 // Whenever the position of the text changes
86         virtual int motion_event() { return 0; };
87         void set_selection(int char1, int char2, int ibeam);
88         void wset_selection(int char1, int char2, int ibeam);
89         int update(const char *text);
90         int update(const wchar_t *wtext);
91         int update(int64_t value);
92         int update(float value);
93         void disable();
94         void enable();
95         int get_enabled();
96         int get_rows();
97
98         int initialize();
99
100         int focus_in_event();
101         int focus_out_event();
102         int cursor_enter_event();
103         int cursor_leave_event();
104         int cursor_motion_event();
105         virtual int button_press_event();
106         int button_release_event();
107         int repeat_event(int64_t repeat_id);
108         int keypress_event();
109         int selection_clear_event();
110         int activate();
111         int deactivate();
112         const char* get_text();
113         const wchar_t* get_wtext();
114         void set_text(char *text, int isz);
115         int wdemand(int len);
116         int tdemand(int len);
117         int get_text_rows();
118 // Set top left of text view
119         void set_text_row(int row);
120         int get_text_row();
121         int get_text_x();
122         int get_text_y();
123         void set_text_x(int v);
124         void set_text_y(int v);
125         int get_back_color();
126         void set_back_color(int v);
127
128         int reposition_window(int x, int y, int w = -1, int rows = -1);
129         int uses_text();
130         int cut(int do_update);
131         int copy(int do_update);
132         int paste(int do_update);
133         
134         static int calculate_h(BC_WindowBase *gui, int font, int has_border, int rows);
135         static int calculate_row_h(int rows, BC_WindowBase *parent_window, int has_border = 1, int font = MEDIUMFONT);
136         static int pixels_to_rows(BC_WindowBase *window, int font, int pixels);
137         static int wcpos(const char *text, const char *ep);
138
139         void set_precision(int precision);
140 // Whether to draw every time there is a keypress or rely on user to
141 // follow up every keypress with an update().
142         void set_keypress_draw(int value);
143         int get_ibeam_letter();
144         void set_ibeam_letter(int number, int redraw = 1);
145 // Used for custom formatting text boxes
146         int get_last_keypress();
147 // Table of separators to skip.  Used by time textboxes
148 // The separator format is "0000:0000".  Things not alnum are considered
149 // separators.  The alnums are replaced by user text.
150         void set_separators(const char *separators);
151
152 // 1 - selects text, -1 - deselects, 0 - do nothing
153 // in all cases it returns text_selected after the operation
154         int select_whole_text(int select);
155
156 // Compute suggestions for a path
157 // If entries is null, just search absolute paths
158         int calculate_suggestions(ArrayList<BC_ListBoxItem*> *entries=0, const char *filter=0);
159
160
161 // User computes suggestions after handle_event.
162 // The array is copied to a local variable.
163 // A highlighted extension is added if 1 suggestion or a popup appears
164 // if multiple suggestions.
165 // column - starting column to replace
166         void no_suggestions();
167         void set_suggestions(ArrayList<char*> *suggestions, int column);
168
169         BC_ScrollTextBoxXScroll *xscroll;
170         BC_ScrollTextBoxYScroll *yscroll;
171 private:
172         int reset_parameters(int rows, int has_border, int font, int size);
173         BC_TextMenu *menu;
174         void draw(int flush);
175         void draw_border();
176         void draw_cursor();
177         void copy_selection(int clipboard_num);
178         void paste_selection(int clipboard_num);
179         void delete_selection(int letter1, int letter2, int text_len);
180         void insert_text(const wchar_t *wcp, int len=-1);
181 // Reformat text according to separators.
182 // ibeam_left causes the ibeam to move left.
183         int is_separator(const char *txt, int i);
184         void do_separators(int ibeam_left);
185         int get_x_position(int i, int start=0);
186         void get_ibeam_position(int &x, int &y);
187         void find_ibeam(int dispatch_event);
188         void select_word(int &letter1, int &letter2, int ibeam_letter);
189         void select_line(int &letter1, int &letter2, int ibeam_letter);
190         int get_cursor_letter(int cursor_x, int cursor_y);
191         int get_cursor_letter2(int cursor_x, int cursor_y);
192         int get_row_h(int rows);
193         void default_keypress(int &dispatch_event, int &result);
194         int tstrlen();
195         int tstrcmp(const char *cp);
196         char *tstrcpy(const char *cp);
197         char *tstrcat(const char *cp);
198         int text_update(const wchar_t *wcp, int wsz, char *tcp, int tsz);
199         int wtext_update();
200
201 // Top left of text relative to window
202         int text_x, text_y;
203 // Top left of cursor relative to text
204         int ibeam_x, ibeam_y;
205
206         int ibeam_letter, unicode_active;
207         int highlight_letter1, highlight_letter2;
208         int highlight_letter3, highlight_letter4;
209         int text_x1, text_start, text_end;
210         int text_selected, word_selected, line_selected;
211         int text_ascent, text_descent, text_height;
212         int left_margin, right_margin, top_margin, bottom_margin;
213         int has_border;
214         int font;
215         int rows;
216         int highlighted;
217         int high_color, back_color;
218         int background_color;
219         int size, tsize, dirty;
220         int wlen, wsize;
221         char temp_string[KEYPRESSLEN];
222         int is_utf8;
223         int active;
224         int enabled;
225         int precision;
226         int keypress_draw;
227 // Cause the repeater to skip a cursor refresh if a certain event happened
228 // within a certain time of the last repeat event
229         Timer *skip_cursor;
230 // Used for custom formatting text boxes
231         int last_keypress;
232         const char *separators;
233         ArrayList<BC_ListBoxItem*> *suggestions;
234         BC_TextBoxSuggestions *suggestions_popup;
235         int suggestion_column;
236         int selection_active;
237 };
238
239
240
241 class BC_TextBoxSuggestions : public BC_ListBox
242 {
243 public:
244         BC_TextBoxSuggestions(BC_TextBox *text_box, int x, int y);
245         virtual ~BC_TextBoxSuggestions();
246
247         int handle_event();
248
249         BC_TextBox *text_box;
250 };
251
252
253 class BC_ScrollTextBox
254 {
255         BC_ScrollTextBoxText *text;
256         BC_ScrollTextBoxXScroll *xscroll;
257         BC_ScrollTextBoxYScroll *yscroll;
258         BC_WindowBase *parent_window;
259         const char *default_text;
260         const wchar_t *default_wtext;
261         int default_size;
262         int x, y, w, rows;
263
264         friend class BC_ScrollTextBoxText;
265         friend class BC_ScrollTextBoxXScroll;
266         friend class BC_ScrollTextBoxYScroll;
267 public:
268         BC_ScrollTextBox(BC_WindowBase *parent_window,
269                 int x, int y, int w, int rows,
270                 const char *default_text, int default_size=BCTEXTLEN);
271         BC_ScrollTextBox(BC_WindowBase *parent_window,
272                 int x, int y, int w, int rows,
273                 const wchar_t *default_wtext, int default_size=BCTEXTLEN);
274         virtual ~BC_ScrollTextBox();
275         void create_objects();
276
277         virtual int handle_event() { return 1; }
278         virtual int button_press_event();
279         virtual int button_release_event();
280
281         void set_text(char *text, int isz);
282         int set_text_row(int n);
283         void update(const char *text);
284         void update(const wchar_t *wtext);
285         void reposition_window(int x, int y, int w, int rows);
286         void update_scrollbars();
287 // accessors
288         int get_x() { return x; }
289         int get_y() { return y; }
290         int get_w() { return w; }
291 // Visible rows for resizing
292         int get_rows() { return rows; }
293         int get_x_pos();
294         void set_x_pos(int x);
295 // forward functions
296         int get_h();
297         const char *get_text();
298         const wchar_t *get_wtext();
299         int get_buttonpress();
300         void wset_selection(int char1, int char2, int ibeam);
301         void set_selection(int char1, int char2, int ibeam);
302         int get_ibeam_letter();
303 };
304
305 class BC_ScrollTextBoxText : public BC_TextBox
306 {
307 public:
308         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const char *text);
309         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const wchar_t *wtext);
310         virtual ~BC_ScrollTextBoxText();
311         int handle_event();
312         int motion_event();
313         BC_ScrollTextBox *gui;
314         int button_press_event() { return gui->button_press_event(); }
315         int button_release_event() { return gui->button_release_event(); }
316 };
317
318 class BC_ScrollTextBoxXScroll : public BC_ScrollBar
319 {
320 public:
321         BC_ScrollTextBoxXScroll(BC_ScrollTextBox *gui);
322         virtual ~BC_ScrollTextBoxXScroll();
323         int handle_event();
324         BC_ScrollTextBox *gui;
325 };
326
327 class BC_ScrollTextBoxYScroll : public BC_ScrollBar
328 {
329 public:
330         BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui);
331         virtual ~BC_ScrollTextBoxYScroll();
332         int handle_event();
333         BC_ScrollTextBox *gui;
334 };
335
336
337
338
339 class BC_PopupTextBoxText;
340 class BC_PopupTextBoxList;
341
342 class BC_PopupTextBox
343 {
344 public:
345         BC_PopupTextBox(BC_WindowBase *parent_window,
346                 ArrayList<BC_ListBoxItem*> *list_items,
347                 const char *default_text, int x, int y,
348                 int text_w, int list_h, int list_format = LISTBOX_TEXT);
349         virtual ~BC_PopupTextBox();
350         int create_objects();
351         virtual int handle_event();
352         const char* get_text();
353         const wchar_t* get_wtext();
354         int get_number();
355         int get_x();
356         int get_y();
357         int get_w();
358         int get_h();
359         int get_show_query();
360         void set_show_query(int v);
361
362         void update(const char *text);
363         void update_list(ArrayList<BC_ListBoxItem*> *data);
364         void reposition_window(int x, int y);
365
366         friend class BC_PopupTextBoxText;
367         friend class BC_PopupTextBoxList;
368
369 private:
370         int x, y, text_w, list_h;
371         int list_format;
372         const char *default_text;
373         const wchar_t *default_wtext;
374         ArrayList<BC_ListBoxItem*> *list_items;
375         BC_PopupTextBoxText *textbox;
376         BC_PopupTextBoxList *listbox;
377         BC_WindowBase *parent_window;
378 };
379
380 class BC_PopupTextBoxText : public BC_TextBox
381 {
382 public:
383         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const char *text);
384         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const wchar_t *wtext);
385         virtual ~BC_PopupTextBoxText();
386         int handle_event();
387         BC_PopupTextBox *popup;
388 };
389
390 class BC_PopupTextBoxList : public BC_ListBox
391 {
392 public:
393         BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y);
394         int handle_event();
395         BC_PopupTextBox *popup;
396 };
397
398
399 class BC_TumbleTextBox;
400 class BC_TumbleTextBoxText;
401 class BC_FTextTumbler;
402 class BC_ITextTumbler;
403
404
405 class BC_TumbleTextBox
406 {
407 public:
408         BC_TumbleTextBox(BC_WindowBase *parent_window,
409                 int64_t default_value, int64_t min, int64_t max,
410                 int x, int y, int text_w);
411         BC_TumbleTextBox(BC_WindowBase *parent_window,
412                 int default_value, int min, int max,
413                 int x, int y, int text_w);
414         BC_TumbleTextBox(BC_WindowBase *parent_window,
415                 float default_value, float min, float max,
416                 int x, int y, int text_w, int precision=4);
417         virtual ~BC_TumbleTextBox();
418
419         int create_objects();
420         void reset();
421         virtual int handle_event();
422         virtual int handle_up_event();
423         virtual int handle_down_event();
424         const char* get_text();
425         const wchar_t* get_wtext();
426         BC_TextBox* get_textbox();
427         int update(const char *value);
428         int update(int64_t value);
429         int update(float value);
430         int get_x();
431         int get_y();
432         int get_w();
433         int get_h();
434         void disable(int hide_text=0);
435         void enable();
436         int get_enabled();
437         void reposition_window(int x, int y);
438         void set_boundaries(int64_t min, int64_t max);
439         void set_boundaries(float min, float max);
440         void set_precision(int precision);
441         void set_increment(float value);
442         void set_log_floatincrement(int value);
443         void set_tooltip(const char *text);
444
445         friend class BC_TumbleTextBoxText;
446         friend class BC_FTextTumbler;
447         friend class BC_ITextTumbler;
448
449 private:
450         int x, y, text_w;
451         int64_t default_value, min, max;
452         float default_value_f, min_f, max_f;
453         int use_float;
454         int precision;
455         float increment;
456         int log_floatincrement;
457         BC_TumbleTextBoxText *textbox;
458         BC_Tumbler *tumbler;
459         BC_WindowBase *parent_window;
460 };
461
462 class BC_TumbleTextBoxText : public BC_TextBox
463 {
464 public:
465         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, int64_t default_value, int x, int y);
466         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, float default_value, int x, int y, int precision);
467         virtual ~BC_TumbleTextBoxText();
468         int handle_event();
469         int button_press_event();
470         BC_TumbleTextBox *popup;
471 };
472
473 class BC_FTextTumbler : public BC_FTumbler
474 {
475 public:
476         BC_FTextTumbler(BC_TumbleTextBox *tumble_text,
477                         float min_f, float max_f, int x, int y)
478          : BC_FTumbler(tumble_text->textbox, min_f, max_f, x, y) {
479                 this->tumble_text = tumble_text;
480         }
481         ~BC_FTextTumbler() {}
482         int handle_up_event() { return tumble_text->handle_up_event(); }
483         int handle_down_event() { return tumble_text->handle_down_event(); }
484
485         BC_TumbleTextBox *tumble_text;
486 };
487
488 class BC_ITextTumbler : public BC_ITumbler
489 {
490 public:
491         BC_ITextTumbler(BC_TumbleTextBox *tumble_text,
492                         int64_t min, int64_t max, int x, int y)
493          : BC_ITumbler(tumble_text->textbox, min, max, x, y) {
494                 this->tumble_text = tumble_text;
495         }
496         ~BC_ITextTumbler() {}
497         int handle_up_event() { return tumble_text->handle_up_event(); }
498         int handle_down_event() { return tumble_text->handle_down_event(); }
499
500         BC_TumbleTextBox *tumble_text;
501 };
502
503
504 class BC_TextMenu : public BC_PopupMenu
505 {
506 public:
507         BC_TextMenu(BC_TextBox *textbox);
508         ~BC_TextMenu();
509         
510         void create_objects();
511         
512         BC_TextBox *textbox;
513 };
514
515 class BC_TextMenuCut : public BC_MenuItem
516 {
517 public:
518         BC_TextMenuCut(BC_TextMenu *menu);
519         int handle_event();
520         BC_TextMenu *menu;
521 };
522
523 class BC_TextMenuCopy : public BC_MenuItem
524 {
525 public:
526         BC_TextMenuCopy(BC_TextMenu *menu);
527         int handle_event();
528         BC_TextMenu *menu;
529 };
530
531 class BC_TextMenuPaste : public BC_MenuItem
532 {
533 public:
534         BC_TextMenuPaste(BC_TextMenu *menu);
535         int handle_event();
536         BC_TextMenu *menu;
537 };
538
539
540 #endif