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