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