56514cad4e6c6df0d3df9402f86531081f62e33c
[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         void get_ibeam_position(int &x, int &y);
162         void find_ibeam(int dispatch_event);
163         void select_word(int &letter1, int &letter2, int ibeam_letter);
164         void select_line(int &letter1, int &letter2, int ibeam_letter);
165         int get_cursor_letter(int cursor_x, int cursor_y);
166         int get_cursor_letter2(int cursor_x, int cursor_y);
167         int get_row_h(int rows);
168         void default_keypress(int &dispatch_event, int &result);
169         int tstrlen();
170         int tstrcmp(const char *cp);
171         char *tstrcpy(const char *cp);
172         char *tstrcat(const char *cp);
173         int text_update(const wchar_t *wcp, int wsz, char *tcp, int tsz);
174         int wtext_update();
175
176 // Top left of text relative to window
177         int text_x, text_y;
178 // Top left of cursor relative to text
179         int ibeam_x, ibeam_y;
180
181         int ibeam_letter, unicode_active;
182         int highlight_letter1, highlight_letter2;
183         int highlight_letter3, highlight_letter4;
184         int text_x1, text_start, text_end;
185         int text_selected, word_selected, line_selected;
186         int text_ascent, text_descent, text_height;
187         int left_margin, right_margin, top_margin, bottom_margin;
188         int has_border;
189         int font;
190         int rows;
191         int highlighted;
192         int high_color, back_color;
193         int background_color;
194         int size, tsize, dirty;
195         int wlen, wsize, *positions, plen;
196         char temp_string[KEYPRESSLEN];
197         int is_utf8;
198         int active;
199         int enabled;
200         int precision;
201         int keypress_draw;
202 // Cause the repeater to skip a cursor refresh if a certain event happened
203 // within a certain time of the last repeat event
204         Timer *skip_cursor;
205 // Used for custom formatting text boxes
206         int last_keypress;
207         const char *separators;
208         ArrayList<BC_ListBoxItem*> *suggestions;
209         BC_TextBoxSuggestions *suggestions_popup;
210         int suggestion_column;
211 };
212
213
214
215 class BC_TextBoxSuggestions : public BC_ListBox
216 {
217 public:
218         BC_TextBoxSuggestions(BC_TextBox *text_box, int x, int y);
219         virtual ~BC_TextBoxSuggestions();
220
221         int handle_event();
222
223         BC_TextBox *text_box;
224 };
225
226
227
228 class BC_ScrollTextBoxText;
229 class BC_ScrollTextBoxYScroll;
230
231
232 class BC_ScrollTextBox
233 {
234 public:
235         BC_ScrollTextBox(BC_WindowBase *parent_window,
236                 int x, int y, int w, int rows,
237                 const char *default_text, int default_size=BCTEXTLEN);
238         BC_ScrollTextBox(BC_WindowBase *parent_window,
239                 int x, int y, int w, int rows,
240                 const wchar_t *default_wtext, int default_size=BCTEXTLEN);
241         virtual ~BC_ScrollTextBox();
242         void create_objects();
243         virtual int handle_event();
244
245         const char* get_text();
246         const wchar_t* get_wtext();
247         void set_text(char *text, int isz);
248         int set_text_row(int n);
249         void update(const char *text);
250         void update(const wchar_t *wtext);
251         void set_selection(int char1, int char2, int ibeam);
252         void wset_selection(int char1, int char2, int ibeam);
253         void reposition_window(int x, int y, int w, int rows);
254         int get_x();
255         int get_y();
256         int get_w();
257         int get_h();
258 // Visible rows for resizing
259         int get_rows();
260         int get_ibeam_letter();
261
262         friend class BC_ScrollTextBoxText;
263         friend class BC_ScrollTextBoxYScroll;
264
265 private:
266         BC_ScrollTextBoxText *text;
267         BC_ScrollTextBoxYScroll *yscroll;
268         BC_WindowBase *parent_window;
269         const char *default_text;
270         const wchar_t *default_wtext;
271         int default_size;
272         int x, y, w, rows;
273 };
274
275 class BC_ScrollTextBoxText : public BC_TextBox
276 {
277 public:
278         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const char *text);
279         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const wchar_t *wtext);
280         virtual ~BC_ScrollTextBoxText();
281         int handle_event();
282         int motion_event();
283         BC_ScrollTextBox *gui;
284 };
285
286 class BC_ScrollTextBoxYScroll : public BC_ScrollBar
287 {
288 public:
289         BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui);
290         virtual ~BC_ScrollTextBoxYScroll();
291         int handle_event();
292         BC_ScrollTextBox *gui;
293 };
294
295
296
297
298 class BC_PopupTextBoxText;
299 class BC_PopupTextBoxList;
300
301 class BC_PopupTextBox
302 {
303 public:
304         BC_PopupTextBox(BC_WindowBase *parent_window,
305                 ArrayList<BC_ListBoxItem*> *list_items,
306                 const char *default_text, int x, int y,
307                 int text_w, int list_h, int list_format = LISTBOX_TEXT);
308         virtual ~BC_PopupTextBox();
309         int create_objects();
310         virtual int handle_event();
311         const char* get_text();
312         const wchar_t* get_wtext();
313         int get_number();
314         int get_x();
315         int get_y();
316         int get_w();
317         int get_h();
318         void update(const char *text);
319         void update_list(ArrayList<BC_ListBoxItem*> *data);
320         void reposition_window(int x, int y);
321
322         friend class BC_PopupTextBoxText;
323         friend class BC_PopupTextBoxList;
324
325 private:
326         int x, y, text_w, list_h;
327         int list_format;
328         const char *default_text;
329         const wchar_t *default_wtext;
330         ArrayList<BC_ListBoxItem*> *list_items;
331         BC_PopupTextBoxText *textbox;
332         BC_PopupTextBoxList *listbox;
333         BC_WindowBase *parent_window;
334 };
335
336 class BC_PopupTextBoxText : public BC_TextBox
337 {
338 public:
339         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const char *text);
340         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const wchar_t *wtext);
341         virtual ~BC_PopupTextBoxText();
342         int handle_event();
343         BC_PopupTextBox *popup;
344 };
345
346 class BC_PopupTextBoxList : public BC_ListBox
347 {
348 public:
349         BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y);
350         int handle_event();
351         BC_PopupTextBox *popup;
352 };
353
354
355 class BC_TumbleTextBoxText;
356 class BC_TumbleTextBoxTumble;
357
358 class BC_TumbleTextBox
359 {
360 public:
361         BC_TumbleTextBox(BC_WindowBase *parent_window,
362                 int64_t default_value,
363                 int64_t min,
364                 int64_t max,
365                 int x,
366                 int y,
367                 int text_w);
368         BC_TumbleTextBox(BC_WindowBase *parent_window,
369                 int default_value,
370                 int min,
371                 int max,
372                 int x,
373                 int y,
374                 int text_w);
375         BC_TumbleTextBox(BC_WindowBase *parent_window,
376                 float default_value,
377                 float min,
378                 float max,
379                 int x,
380                 int y,
381                 int text_w);
382         virtual ~BC_TumbleTextBox();
383
384         int create_objects();
385         void reset();
386         virtual int handle_event();
387         const char* get_text();
388         const wchar_t* get_wtext();
389         BC_TextBox* get_textbox();
390         int update(const char *value);
391         int update(int64_t value);
392         int update(float value);
393         int get_x();
394         int get_y();
395         int get_w();
396         int get_h();
397         void disable(int hide_text=0);
398         void enable();
399         int get_enabled();
400         void reposition_window(int x, int y);
401         void set_boundaries(int64_t min, int64_t max);
402         void set_boundaries(float min, float max);
403         void set_precision(int precision);
404         void set_increment(float value);
405         void set_log_floatincrement(int value);
406
407         friend class BC_TumbleTextBoxText;
408         friend class BC_TumbleTextBoxTumble;
409
410 private:
411         int x, y, text_w;
412         int64_t default_value, min, max;
413         float default_value_f, min_f, max_f;
414         int use_float;
415         int precision;
416         float increment;
417         int log_floatincrement;
418         BC_TumbleTextBoxText *textbox;
419         BC_Tumbler *tumbler;
420         BC_WindowBase *parent_window;
421 };
422
423 class BC_TumbleTextBoxText : public BC_TextBox
424 {
425 public:
426         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, int64_t default_value, int x, int y);
427         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, float default_value, int x, int y);
428         virtual ~BC_TumbleTextBoxText();
429         int handle_event();
430         int button_press_event();
431         BC_TumbleTextBox *popup;
432 };
433
434
435 #endif