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