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