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