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